awslabs / amazon-kinesis-video-streams-webrtc-sdk-c

Amazon Kinesis Video Streams Webrtc SDK is for developers to install and customize realtime communication between devices and enable secure streaming of video, audio to Kinesis Video Streams.
https://awslabs.github.io/amazon-kinesis-video-streams-webrtc-sdk-c/group__PublicMemberFunctions.html
Apache License 2.0
1.03k stars 307 forks source link

[QUESTION] KVS Client Sample Viewer sending the first signaling message takes 10 seconds on Windows #1856

Closed mehmetcy84 closed 7 months ago

mehmetcy84 commented 9 months ago

Environment: Latest unmodified Kinesis repo 1.9 built on Windows 10 64 bit. Built with build_windows_openssl.bat.

Issue: The first signalling message sent from the client takes up to 10 seconds irrespective of its content/size. Using the unmodified kvsWebRTCClientViewer.exe against the WebRTC Test Page running as master.

The first signalling message ever sent from the client to the master takes 10 seconds. This is the case if I enabled or disabled useTURN, or TrickleICE. For all 4 combinations for these 2 parameters, independent from whatever signaling message goes first, the first and only the first signalling message being sent always takes 10 seconds, and the following signalling messages, if there are any, takes negligible time in comparison.

After testing the default, I modified the TURN, and TrickleICE boolean flags passed to the createSampleConfiguration function in samples/Common.c for test: CHK_STATUS(createSampleConfiguration(pChannelName, SIGNALING_CHANNEL_ROLE_TYPE_VIEWER, TRUE, TRUE, logLevel, &pSampleConfiguration));

Here are all the logs for these cases:

TrickleICE=TRUE, UseTURN=TRUE (unmodified default) TrickleICE=TRUE, UseTURN=FALSE TrickleICE=FALSE, UseTURN=TRUE TrickleICE=FALSE, UseTURN=FALSE TrickleICE_OFF-TURN_OFF.txt TrickleICE_OFF-TURN_ON.txt TrickleICE_ON-TURN_OFF.txt TrickleICE_ON-TURN_ON.txt

Here is a portion of logs from the default case: ... 2023-11-27 14:21:25.837 PROFILE iceAgentStartGathering(): [Relay candidates setup time] Time taken: 0 ms 2023-11-27 14:21:25.837 INFO main(): [KVS Viewer] Completed setting local description 2023-11-27 14:21:25.838 INFO main(): [KVS Viewer] Offer creation successful 2023-11-27 14:21:25.838 INFO main(): [KVS Viewer] Generating JSON of session description.... 2023-11-27 14:21:25.838 VERBOSE signalingClientSendMessageSync(): Signaling Client Sending Message Sync 2023-11-27 14:21:25.839 DEBUG sendLwsMessage(): SDP_OFFER ... 2023-11-27 14:21:35.724 INFO main(): [KVS Viewer] Creating data channel...completed 2023-11-27 14:21:35.724 VERBOSE lwsWssCallbackRoutine(): WSS callback with reason 10 2023-11-27 14:21:35.724 DEBUG lwsWssCallbackRoutine(): Client is writable 2023-11-27 14:21:35.724 INFO main(): [KVS Viewer] Data Channel open now...

And this is a portion from the TURN=OFF TrickleICE=OFF case: ... 2023-11-27 15:40:29.387 INFO main(): [KVS Viewer] Candidate collection completed 2023-11-27 15:40:29.388 INFO main(): [KVS Viewer] Offer creation successful 2023-11-27 15:40:29.388 INFO main(): [KVS Viewer] Generating JSON of session description.... 2023-11-27 15:40:29.388 VERBOSE signalingClientSendMessageSync(): Signaling Client Sending Message Sync ... 2023-11-27 15:40:39.195 DEBUG lwsWssCallbackRoutine(): Client is writable 2023-11-27 15:40:39.195 INFO main(): [KVS Viewer] Creating data channel...completed 2023-11-27 15:40:39.195 INFO main(): [KVS Viewer] Data Channel open now... 2023-11-27 15:40:39.195 VERBOSE lwsWssCallbackRoutine(): WSS callback with reason 10 2023-11-27 15:40:39.196 DEBUG lwsWssCallbackRoutine(): Client is writable

stefankiesz commented 8 months ago

Hi, can you check whether this delay persists when using the latest develop branch.

mehmetcy84 commented 7 months ago

Hi I have checked out the latest develop but the build fails with the following error:

E:\webrtc\src\source\Ice\TurnConnection.c(18): error C2065: 'MAX_STATE_MACHINE_NAME_LENGTH': undeclared identifier E:\webrtc\src\source\Ice\TurnConnection.c(18): error C2057: expected constant expression E:\webrtc\src\source\Ice\TurnConnection.c(18): error C2466: cannot allocate an array of constant size 0 E:\webrtc\src\source\Ice\TurnConnection.c(18): error C2133: 'turnStateMachineName': unknown size E:\webrtc\src\source\Ice\TurnConnection.c(65): error C2065: 'MAX_STATE_MACHINE_NAME_LENGTH': undeclared identifier

If I manually add a definition for MAX_STATE_MACHINE_NAME_LENGTH, and rebuild, the build still fails with the following:

kvsWebrtcClient.lib(IceAgent.c.obj) : error LNK2019: unresolved external symbol createStateMachineWithName referenced in function createIceAgent kvsWebrtcClient.lib(TurnConnection.c.obj) : error LNK2001: unresolved external symbol createStateMachineWithName kvsWebrtcSignalingClient.lib(Signaling.c.obj) : error LNK2001: unresolved external symbol createStateMachineWithName kvsWebrtcClient.lib(IceAgentStateMachine.c.obj) : error LNK2019: unresolved external symbol checkForStateTransition referenced in function checkIceAgentStateMachine kvsWebrtcClient.lib(TurnConnectionStateMachine.c.obj) : error LNK2001: unresolved external symbol checkForStateTransition kvsWebrtcClient.lib(IceAgentStateMachine.c.obj) : error LNK2019: unresolved external symbol timerQueueKick referenced in function checkIceAgentStateMachine kvsWebrtcClient.lib(TurnConnectionStateMachine.c.obj) : error LNK2001: unresolved external symbol timerQueueKick kvsWebrtcClientMaster.exe : fatal error LNK1120: 3 unresolved externals

I checked older commits, and found that this commit introduced the createStateMachineWithName call: SHA-1: a03c26c77232810cd56f9d47a1b3e5da6480225d (10/16/2023)

So, the latest develop commit that builds for me is: SHA-1: 3ba7c054a7024e00e88a51d3d3aadb8f51b6933a (10/13/2023) And all the later ones are failing during the build.

I built this version: SHA-1: 3ba7c054a7024e00e88a51d3d3aadb8f51b6933a (10/13/2023), and the 10 seconds delay is still there. And I couldn't test any of the later commits.

disa6302 commented 7 months ago

@mehmetcy84 ,

You would have to clean build. The createStateMachineWithName is a PIC definition which does not exist in the past release.

mehmetcy84 commented 7 months ago

I deleted build and open-source folders. Ran build_windows_openssl.bat again, this time build fails at this step:

[ 36%] Building C object lib/CMakeFiles/websockets.dir/roles/ws/client-parser-ws.c.obj client-parser-ws.c E:\webrtc\open-source\libwebsockets\build\src\project_libwebsockets\lib\roles\ws\client-parser-ws.c(480): error C2220: warning treated as error - no 'object' file generated E:\webrtc\open-source\libwebsockets\build\src\project_libwebsockets\lib\roles\ws\client-parser-ws.c(480): warning C4003: not enough arguments for function-like macro invocation 'lwsl_hexdump_wsi' E:\webrtc\open-source\libwebsockets\build\src\project_libwebsockets\lib\roles\ws\client-parser-ws.c(480): error C2059: syntax error: ')' E:\webrtc\open-source\libwebsockets\build\src\project_libwebsockets\lib\roles\ws\client-parser-ws.c(598): warning C4003: not enough arguments for function-like macro invocation 'lwsl_hexdump_wsi' E:\webrtc\open-source\libwebsockets\build\src\project_libwebsockets\lib\roles\ws\client-parser-ws.c(598): error C2059: syntax error: ')' NMAKE : fatal error U1077: '"C:\Program Files\CMake\bin\cmake.exe"' : return code '0x2' Stop. NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.16.27023\bin\HostX64\x64\nmake.exe"' : return code '0x2' Stop. NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.16.27023\bin\HostX64\x64\nmake.exe"' : return code '0x2' Stop. NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.16.27023\bin\HostX64\x64\nmake.exe"' : return code '0x2' Stop. NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.16.27023\bin\HostX64\x64\nmake.exe"' : return code '0x2' Stop. NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.16.27023\bin\HostX64\x64\nmake.exe"' : return code '0x2' Stop. CMake Error at CMake/Utilities.cmake:75 (message): CMake step for libwebsockets failed: 2 Call Stack (most recent call first): CMakeLists.txt:186 (build_dependency)

niyatim23 commented 7 months ago

Hi @mehmetcy84, I just tried this on a Windows EC2 instance and I do not see it taking 10 seconds:

PS C:\Users\Administrator\Desktop\w\build\samples> .\kvsWebrtcClientViewer.exe ninja
2024-02-06 18:29:11.277 PROFILE createRtcCertificate(): [Certificate creation time] Time taken: 0 ms
2024-02-06 18:29:11.658 VERBOSE signalingClientStateChanged(): Signaling client state changed to 9 - 'Connected'

This seems like it could be specific to your configuration somehow. Please let us know if anything has changed for you since the last comment