amazon-kinesis-video-streams-webrtc-sdk-c icon indicating copy to clipboard operation
amazon-kinesis-video-streams-webrtc-sdk-c copied to clipboard

[QUESTION] KVS Webrtc startup delay about 20s on Raspberry Pi4

Open gharbit opened this issue 2 years ago • 17 comments

Hello guys,

I installed KVS Webrtc C SDK 1.7.3 on RPI4 (4Go RAM). I'm running the Gst Master example on it. I developed a web viewer based on the JS SDK example.

Actually, I get a startup delay of ~20 seconds to get the video on the viewer side. After that, the latency is very low. Still the same thing with the console playback.

How can I reduce this startup delay? 1- In the bench folder, we mention this note : Optimize startup latency from ~9s to ~80ms (only for the first viewer). How to implement that?

2- In the wiki page, we mention that we could use a pre-generated certificates to reduce the startup latency. I already generated an openssl certificate through this command: openssl req -x509 -sha256 -nodes -days 365 -newkey rsa:2048 -keyout privateKey.key -out certificate.crt Then I hardcoded the key and crt values and I pointed to them in the initializePeerConnection() function in Common.c as mentioned in the wiki. configuration.certificates[0].pCertificate = pSampleConfiguration->certificates[0].pCertificate; configuration.certificates[0].pPrivateKey = pSampleConfiguration->certificates[0].pPrivateKey;

It doesn't work.

3- Is it essentiel to use AWS IoT certificate to get a better performance?

Any help please? Thanks.

gharbit avatar Jul 07 '22 03:07 gharbit

Hello, Any update about this thread?

gharbit avatar Jul 12 '22 12:07 gharbit

Have you looked at the verbose logging output to see where it seems to be stuck for that time? If you post them here (both master and viewer side is ideal), attach as a file please don't dump the contents in the comment then I can take a look and see what's going on.

hassanctech avatar Jul 12 '22 14:07 hassanctech

Closing due to no response.

niyatim23 avatar Jul 25 '22 03:07 niyatim23

Hello @hassanctech, Sorry, I was on vacation. I see that @niyatim23 closed this issue. Can I reopen it or I have to open a new thread?

gharbit avatar Aug 03 '22 12:08 gharbit

Reopening

niyatim23 avatar Aug 03 '22 14:08 niyatim23

hello @hassanctech

AWS Region: Paris (UE-WEST-3)

Master: - HW: based on RPI4 (4Go RAM) with a custom camera (Digitized PAL video). It's connected to a 4G router which acts as an OpenVPN client. The ping between the client and the VPN server is 50ms. - OS: Buster 10, Kernel: Linux 5.10.103
- SW: KVS Webrtc C SDK 1.7.3 based on Gstreamer example (Modified file is attached kvsWebRTCClientMasterGstreamerSample.txt), pipeline: "-e autovideosrc ! queue ! videoconvert ! videorate ! video/x-raw ! \ x264enc bframes=0 speed-preset=veryfast byte-stream=TRUE tune=zerolatency ! \ video/x-h264,stream-format=byte-stream,alignment=au,profile=baseline ! tee name=t ! queue leaky=1 ! \ appsink sync=TRUE emit-signals=TRUE name=appsink-video t. ! queue leaky=1 ! filesink location= file.mkv t. ! queue leaky=1 ! h264parse ! rtph264pay pt=96 ! udpsink port=5080 host=10.8.0.1" - APPLICATION: Record video locally on the equipment, stream webRTC for displaying, stream UDP to the server for recording (even when streaming only, the issues still the same)

Viewer: Viewer 1: Web application (Angular/Javascript) based on amazon-kinesis-video-streams-webrtc-sdk-js example.
Viewer 2: KVS WebRTC test page Viewer

ISSUE 1: Startup delay During the tests: Master -> Viewer 1: Startup: 16 secs => TEST1 FILES Master -> Viewer 2: Startup: 22 secs => TEST2 FILES

ISSUE 2: Sometimes, the stream is not sent from the Master to the Viewer => TEST3 FILE

Thanks for your support. kvsWebRTCClientMasterGstreamerSample.txt

test1_viewer.txt

test1_master.txt

test2_viewer.txt

test2_master.txt

test3_no_video.txt

gharbit avatar Aug 03 '22 18:08 gharbit

Hello AWS, Any update please?

gharbit avatar Aug 05 '22 14:08 gharbit

Any update?

gharbit avatar Aug 10 '22 09:08 gharbit

Hello, Still no response. How to get an official support from AWS?

gharbit avatar Aug 12 '22 17:08 gharbit

Hello @gharbit , Going through your logs, particularly in test3_no_video.txt it appears that you're connecting the signaling client very closely to when you're sending the sdp offer from the viewer. The design of the signaling client is that it should always be connected to reduce latency and avoid missing sdp offers. Is your master always connected to the signaling service?

jdelapla avatar Aug 18 '22 17:08 jdelapla

Hi @jdelapla, Actually, I have a flag in my system, when it turns on, a trigger is sent to the viewer to start, and immediatly the whole kvsWebRTCClientMasterGstreamerSample is executed.

For the first issue (startup delay), I see that initializePeerConnection takes more than 5 seconds and the whole display between 10 and 20 seconds. In wiki page, it's described how to reduce that. I generated certifcates but it doesn't work.

For the second issue (stream not sent to the viewer), I did multiple capture tests, and the problem is that master doesn't receive the offer SDP and candidates from viewer. I described the issue here with log files: https://github.com/awslabs/amazon-kinesis-video-streams-webrtc-sdk-js/issues/148

gharbit avatar Aug 18 '22 18:08 gharbit

Is the SDP offer being missed because the UDP packet is being dropped? Or because the SDK is tossing the SDP offer? If the UDP packet is being erroneously dropped because of network than that is a condition outside our scope.

jdelapla avatar Aug 18 '22 21:08 jdelapla

Additionally, from your VERBOSE logs we see that several debug messages (very noisy ones) are missing, and you may not actually be on 1.7.3

jdelapla avatar Aug 18 '22 21:08 jdelapla

I installed the SDK master branch on June, The 1.7.3 was merged with master on May. For your question: Is the SDP offer being missed because the UDP packet is being dropped? Or because the SDK is tossing the SDP offer?

I don't know, that's why I opened this thread. I don't think that's a network issue, because I have another running UDP sockets and I receive 100% of packets without any errors.

How to further debug this issue? Is it possible to synchronize the SDP offer send/receive between master/viewer or to send it twice?

gharbit avatar Aug 18 '22 21:08 gharbit

Hi, I checked the logs shared in the issue in the JS SDK as well as here, it seems like the Master (WebRTC SDK) is working as intended. To debug further, please check if the viewer's connection is working. Use chrome://webrtc-internals/ on Chrome. Look for connectionstatechange after starting the master and the viewer. If the state is not connected when your master and viewer are both running, it means your viewer was not able to connect to your master and that is why the master does not receive the offer that your viewer sends

niyatim23 avatar Aug 18 '22 23:08 niyatim23

@gharbit ,

Anything to add or updates?

disa6302 avatar Aug 29 '22 16:08 disa6302

I am also facing the same issue sometimes master is not receiving the sdp offer from the viewer, tried sending multiple sdp offer in an interval of 2 secs to just check whether any sdp offer is reached but all retry attempts fails, any solution or fix for the same?

vishalkb avatar Sep 02 '22 11:09 vishalkb

A few suggestions:

  1. Make sure the master and viewer are in the same region.
  2. Check if the network is stable to receive the offer.

disa6302 avatar Jan 16 '23 15:01 disa6302