diff --git a/samples/Common.c b/samples/Common.c index c1a62509d9..229908368a 100644 --- a/samples/Common.c +++ b/samples/Common.c @@ -1,9 +1,6 @@ #define LOG_CLASS "WebRtcSamples" #include "Samples.h" -#define KVS_DEFAULT_MEDIA_SENDER_THREAD_STACK_SIZE 64 * 1024 -#define KVS_MINIMUM_THREAD_STACK_SIZE 16 * 1024 - PSampleConfiguration gSampleConfiguration = NULL; VOID sigintHandler(INT32 sigNum) @@ -54,8 +51,8 @@ VOID onConnectionStateChange(UINT64 customData, RTC_PEER_CONNECTION_STATE newSta CHK_STATUS(peerConnectionGetMetrics(pSampleStreamingSession->pPeerConnection, &pSampleStreamingSession->peerConnectionMetrics)); CHK_STATUS(iceAgentGetMetrics(pSampleStreamingSession->pPeerConnection, &pSampleStreamingSession->iceMetrics)); - if (pSampleConfiguration->enableIceStats) { - CHK_LOG_ERR(logSelectedIceCandidatesInformation(pSampleStreamingSession)); + if (STATUS_FAILED(retStatus = logSelectedIceCandidatesInformation(pSampleStreamingSession))) { + DLOGW("Failed to get information about selected Ice candidates: 0x%08x", retStatus); } break; case RTC_PEER_CONNECTION_STATE_FAILED: @@ -117,13 +114,13 @@ STATUS logSelectedIceCandidatesInformation(PSampleStreamingSession pSampleStream CHK(pSampleStreamingSession != NULL, STATUS_NULL_ARG); rtcMetrics.requestedTypeOfStats = RTC_STATS_TYPE_LOCAL_CANDIDATE; CHK_STATUS(rtcPeerConnectionGetMetrics(pSampleStreamingSession->pPeerConnection, NULL, &rtcMetrics)); - DLOGI("Local Candidate IP Address: %s", rtcMetrics.rtcStatsObject.localIceCandidateStats.address); - DLOGI("Local Candidate type: %s", rtcMetrics.rtcStatsObject.localIceCandidateStats.candidateType); - DLOGI("Local Candidate port: %d", rtcMetrics.rtcStatsObject.localIceCandidateStats.port); - DLOGI("Local Candidate priority: %d", rtcMetrics.rtcStatsObject.localIceCandidateStats.priority); - DLOGI("Local Candidate transport protocol: %s", rtcMetrics.rtcStatsObject.localIceCandidateStats.protocol); - DLOGI("Local Candidate relay protocol: %s", rtcMetrics.rtcStatsObject.localIceCandidateStats.relayProtocol); - DLOGI("Local Candidate Ice server source: %s", rtcMetrics.rtcStatsObject.localIceCandidateStats.url); + DLOGD("Local Candidate IP Address: %s", rtcMetrics.rtcStatsObject.localIceCandidateStats.address); + DLOGD("Local Candidate type: %s", rtcMetrics.rtcStatsObject.localIceCandidateStats.candidateType); + DLOGD("Local Candidate port: %d", rtcMetrics.rtcStatsObject.localIceCandidateStats.port); + DLOGD("Local Candidate priority: %d", rtcMetrics.rtcStatsObject.localIceCandidateStats.priority); + DLOGD("Local Candidate transport protocol: %s", rtcMetrics.rtcStatsObject.localIceCandidateStats.protocol); + DLOGD("Local Candidate relay protocol: %s", rtcMetrics.rtcStatsObject.localIceCandidateStats.relayProtocol); + DLOGD("Local Candidate Ice server source: %s", rtcMetrics.rtcStatsObject.localIceCandidateStats.url); rtcMetrics.requestedTypeOfStats = RTC_STATS_TYPE_REMOTE_CANDIDATE; CHK_STATUS(rtcPeerConnectionGetMetrics(pSampleStreamingSession->pPeerConnection, NULL, &rtcMetrics)); @@ -141,12 +138,12 @@ STATUS handleAnswer(PSampleConfiguration pSampleConfiguration, PSampleStreamingS { UNUSED_PARAM(pSampleConfiguration); STATUS retStatus = STATUS_SUCCESS; - PRtcSessionDescriptionInit pAnswerSessionDescriptionInit = NULL; + RtcSessionDescriptionInit answerSessionDescriptionInit; - pAnswerSessionDescriptionInit = (PRtcSessionDescriptionInit) MEMCALLOC(1, SIZEOF(RtcSessionDescriptionInit)); + MEMSET(&answerSessionDescriptionInit, 0x00, SIZEOF(RtcSessionDescriptionInit)); - CHK_STATUS(deserializeSessionDescriptionInit(pSignalingMessage->payload, pSignalingMessage->payloadLen, pAnswerSessionDescriptionInit)); - CHK_STATUS(setRemoteDescription(pSampleStreamingSession->pPeerConnection, pAnswerSessionDescriptionInit)); + CHK_STATUS(deserializeSessionDescriptionInit(pSignalingMessage->payload, pSignalingMessage->payloadLen, &answerSessionDescriptionInit)); + CHK_STATUS(setRemoteDescription(pSampleStreamingSession->pPeerConnection, &answerSessionDescriptionInit)); // The audio video receive routine should be per streaming session if (pSampleConfiguration->receiveAudioVideoSource != NULL) { @@ -177,13 +174,11 @@ PVOID mediaSenderRoutine(PVOID customData) CHK(!ATOMIC_LOAD_BOOL(&pSampleConfiguration->appTerminateFlag), retStatus); if (pSampleConfiguration->videoSource != NULL) { - THREAD_CREATE_WITH_PARAMS(&pSampleConfiguration->videoSenderTid, pSampleConfiguration->videoSource, - KVS_DEFAULT_MEDIA_SENDER_THREAD_STACK_SIZE, (PVOID) pSampleConfiguration); + THREAD_CREATE(&pSampleConfiguration->videoSenderTid, pSampleConfiguration->videoSource, (PVOID) pSampleConfiguration); } if (pSampleConfiguration->audioSource != NULL) { - THREAD_CREATE_WITH_PARAMS(&pSampleConfiguration->audioSenderTid, pSampleConfiguration->audioSource, - KVS_DEFAULT_MEDIA_SENDER_THREAD_STACK_SIZE, (PVOID) pSampleConfiguration); + THREAD_CREATE(&pSampleConfiguration->audioSenderTid, pSampleConfiguration->audioSource, (PVOID) pSampleConfiguration); } if (pSampleConfiguration->videoSenderTid != INVALID_TID_VALUE) { @@ -204,17 +199,17 @@ PVOID mediaSenderRoutine(PVOID customData) STATUS handleOffer(PSampleConfiguration pSampleConfiguration, PSampleStreamingSession pSampleStreamingSession, PSignalingMessage pSignalingMessage) { STATUS retStatus = STATUS_SUCCESS; - PRtcSessionDescriptionInit pOfferSessionDescriptionInit = NULL; + RtcSessionDescriptionInit offerSessionDescriptionInit; NullableBool canTrickle; BOOL mediaThreadStarted; CHK(pSampleConfiguration != NULL && pSignalingMessage != NULL, STATUS_NULL_ARG); - pOfferSessionDescriptionInit = (PRtcSessionDescriptionInit) MEMCALLOC(1, SIZEOF(RtcSessionDescriptionInit)); + MEMSET(&offerSessionDescriptionInit, 0x00, SIZEOF(RtcSessionDescriptionInit)); MEMSET(&pSampleStreamingSession->answerSessionDescriptionInit, 0x00, SIZEOF(RtcSessionDescriptionInit)); DLOGD("**offer:%s", pSignalingMessage->payload); - CHK_STATUS(deserializeSessionDescriptionInit(pSignalingMessage->payload, pSignalingMessage->payloadLen, pOfferSessionDescriptionInit)); - CHK_STATUS(setRemoteDescription(pSampleStreamingSession->pPeerConnection, pOfferSessionDescriptionInit)); + CHK_STATUS(deserializeSessionDescriptionInit(pSignalingMessage->payload, pSignalingMessage->payloadLen, &offerSessionDescriptionInit)); + CHK_STATUS(setRemoteDescription(pSampleStreamingSession->pPeerConnection, &offerSessionDescriptionInit)); canTrickle = canTrickleIceCandidates(pSampleStreamingSession->pPeerConnection); /* cannot be null after setRemoteDescription */ CHECK(!NULLABLE_CHECK_EMPTY(canTrickle)); @@ -231,8 +226,7 @@ STATUS handleOffer(PSampleConfiguration pSampleConfiguration, PSampleStreamingSe mediaThreadStarted = ATOMIC_EXCHANGE_BOOL(&pSampleConfiguration->mediaThreadStarted, TRUE); if (!mediaThreadStarted) { - THREAD_CREATE_WITH_PARAMS(&pSampleConfiguration->mediaSenderTid, mediaSenderRoutine, KVS_MINIMUM_THREAD_STACK_SIZE, - (PVOID) pSampleConfiguration); + THREAD_CREATE(&pSampleConfiguration->mediaSenderTid, mediaSenderRoutine, (PVOID) pSampleConfiguration); } // The audio video receive routine should be per streaming session @@ -371,7 +365,6 @@ STATUS initializePeerConnection(PSampleConfiguration pSampleConfiguration, PRtcP // Set the ICE mode explicitly configuration.iceTransportPolicy = ICE_TRANSPORT_POLICY_ALL; - configuration.kvsRtcConfiguration.enableIceStats = pSampleConfiguration->enableIceStats; // Set the STUN server PCHAR pKinesisVideoStunUrlPostFix = KINESIS_VIDEO_STUN_URL_POSTFIX; // If region is in CN, add CN region uri postfix @@ -918,9 +911,6 @@ STATUS createSampleConfiguration(PCHAR channelName, SIGNALING_CHANNEL_ROLE_TYPE pSampleConfiguration->pregenerateCertTimerId = MAX_UINT32; pSampleConfiguration->signalingClientMetrics.version = SIGNALING_CLIENT_METRICS_CURRENT_VERSION; - // Flag to enable SDK to calculate selected ice server, local, remote and candidate pair stats. - pSampleConfiguration->enableIceStats = FALSE; - // Flag to enable/disable TWCC pSampleConfiguration->enableTwcc = TRUE; @@ -1237,8 +1227,9 @@ STATUS freeSampleConfiguration(PSampleConfiguration* ppSampleConfiguration) } for (i = 0; i < pSampleConfiguration->streamingSessionCount; ++i) { - if (pSampleConfiguration->enableIceStats) { - CHK_LOG_ERR(gatherIceServerStats(pSampleConfiguration->sampleStreamingSessionList[i])); + retStatus = gatherIceServerStats(pSampleConfiguration->sampleStreamingSessionList[i]); + if (STATUS_FAILED(retStatus)) { + DLOGW("Failed to ICE Server Stats for streaming session %d: %08x", i, retStatus); } freeSampleStreamingSession(&pSampleConfiguration->sampleStreamingSessionList[i]); } @@ -1570,7 +1561,7 @@ STATUS signalingMessageReceived(UINT64 customData, PReceivedSignalingMessage pRe MUTEX_UNLOCK(pSampleConfiguration->sampleConfigurationObjLock); locked = FALSE; - if (pSampleConfiguration->enableIceStats && startStats && + if (startStats && STATUS_FAILED(retStatus = timerQueueAddTimer(pSampleConfiguration->timerQueueHandle, SAMPLE_STATS_DURATION, SAMPLE_STATS_DURATION, getIceCandidatePairStatsCallback, (UINT64) pSampleConfiguration, &pSampleConfiguration->iceCandidatePairStatsTimerId))) { @@ -1887,4 +1878,4 @@ VOID onDataChannel(UINT64 customData, PRtcDataChannel pRtcDataChannel) DLOGI("New DataChannel has been opened %s \n", pRtcDataChannel->name); dataChannelOnMessage(pRtcDataChannel, customData, onDataChannelMessage); } -#endif \ No newline at end of file +#endif diff --git a/samples/kvsWebRTCClientMaster.c b/samples/kvsWebRTCClientMaster.c index 0ae2d8cf90..d034431d05 100644 --- a/samples/kvsWebRTCClientMaster.c +++ b/samples/kvsWebRTCClientMaster.c @@ -30,10 +30,8 @@ INT32 main(INT32 argc, CHAR* argv[]) CHK_STATUS(createSampleConfiguration(pChannelName, SIGNALING_CHANNEL_ROLE_TYPE_MASTER, TRUE, TRUE, logLevel, &pSampleConfiguration)); if (argc > 3) { - if (!STRCMP(argv[3], AUDIO_CODEC_NAME_AAC)) { - audioCodec = RTC_CODEC_AAC; - } else { - DLOGI("[KVS Master] Defaulting to opus as the specified codec's sample frames may not be available"); + if (!STRCMP(argv[3], AUDIO_CODEC_NAME_OPUS)) { + audioCodec = RTC_CODEC_OPUS; } } @@ -75,9 +73,6 @@ INT32 main(INT32 argc, CHAR* argv[]) if (audioCodec == RTC_CODEC_OPUS) { CHK_STATUS(readFrameFromDisk(NULL, &frameSize, "./opusSampleFrames/sample-001.opus")); DLOGI("[KVS Master] Checked Opus sample audio frame availability....available"); - } else if (audioCodec == RTC_CODEC_AAC) { - CHK_STATUS(readFrameFromDisk(NULL, &frameSize, "./aacSampleFrames/sample-001.aac")); - DLOGI("[KVS Master] Checked AAC sample audio frame availability....available"); } // Initialize KVS WebRTC. This must be done before anything else, and must only be done once. @@ -129,8 +124,8 @@ INT32 main(INT32 argc, CHAR* argv[]) DLOGI("[KVS Master] Cleanup done"); CHK_LOG_ERR(retStatus); - retStatus = RESET_INSTRUMENTED_ALLOCATORS(); - DLOGI("All SDK allocations freed? %s..0x%08x", retStatus == STATUS_SUCCESS ? "Yes" : "No", retStatus); + RESET_INSTRUMENTED_ALLOCATORS(); + // https://www.gnu.org/software/libc/manual/html_node/Exit-Status.html // We can only return with 0 - 127. Some platforms treat exit code >= 128 // to be a success code, which might give an unintended behaviour. @@ -253,9 +248,7 @@ PVOID sendAudioPackets(PVOID args) while (!ATOMIC_LOAD_BOOL(&pSampleConfiguration->appTerminateFlag)) { fileIndex = fileIndex % NUMBER_OF_OPUS_FRAME_FILES + 1; - if (pSampleConfiguration->audioCodec == RTC_CODEC_AAC) { - SNPRINTF(filePath, MAX_PATH_LEN, "./aacSampleFrames/sample-%03d.aac", fileIndex); - } else if (pSampleConfiguration->audioCodec == RTC_CODEC_OPUS) { + if (pSampleConfiguration->audioCodec == RTC_CODEC_OPUS) { SNPRINTF(filePath, MAX_PATH_LEN, "./opusSampleFrames/sample-%03d.opus", fileIndex); } @@ -310,4 +303,4 @@ PVOID sampleReceiveAudioVideoFrame(PVOID args) CleanUp: return (PVOID) (ULONG_PTR) retStatus; -} \ No newline at end of file +} diff --git a/samples/kvsWebRTCClientViewer.c b/samples/kvsWebRTCClientViewer.c index bc60e12cad..a4730d06b1 100644 --- a/samples/kvsWebRTCClientViewer.c +++ b/samples/kvsWebRTCClientViewer.c @@ -60,8 +60,8 @@ INT32 main(INT32 argc, CHAR* argv[]) #endif if (argc > 2) { - if (!STRCMP(argv[2], AUDIO_CODEC_NAME_AAC)) { - audioCodec = RTC_CODEC_AAC; + if (!STRCMP(argv[2], AUDIO_CODEC_NAME_OPUS)) { + audioCodec = RTC_CODEC_OPUS; } else if (!STRCMP(argv[2], AUDIO_CODEC_NAME_ALAW)) { audioCodec = RTC_CODEC_ALAW; } else if (!STRCMP(argv[2], AUDIO_CODEC_NAME_MULAW)) { diff --git a/samples/kvsWebRTCClientViewerGstSample.c b/samples/kvsWebRTCClientViewerGstSample.c index b6c7e47184..d31676d1db 100644 --- a/samples/kvsWebRTCClientViewerGstSample.c +++ b/samples/kvsWebRTCClientViewerGstSample.c @@ -60,8 +60,8 @@ INT32 main(INT32 argc, CHAR* argv[]) #endif if (argc > 3) { - if (!STRCMP(argv[3], AUDIO_CODEC_NAME_AAC)) { - audioCodec = RTC_CODEC_AAC; + if (!STRCMP(argv[3], AUDIO_CODEC_NAME_OPUS)) { + audioCodec = RTC_CODEC_OPUS; } else { DLOGI("[KVS Gstreamer Viewer] Defaulting to Opus audio codec"); } @@ -216,4 +216,4 @@ INT32 main(INT32 argc, CHAR* argv[]) // Some platforms also treat 1 or 0 differently, so it's better to use // EXIT_FAILURE and EXIT_SUCCESS macros for portability. return STATUS_FAILED(retStatus) ? EXIT_FAILURE : EXIT_SUCCESS; -} \ No newline at end of file +} diff --git a/samples/kvsWebrtcClientMasterGstSample.c b/samples/kvsWebrtcClientMasterGstSample.c index b27ea64006..bb5036db8a 100644 --- a/samples/kvsWebrtcClientMasterGstSample.c +++ b/samples/kvsWebrtcClientMasterGstSample.c @@ -171,17 +171,6 @@ PVOID sendGstreamerAudioVideo(PVOID args) * vp8enc error-resilient=partitions keyframe-max-dist=10 auto-alt-ref=true cpu-used=5 deadline=1 ! * appsink sync=TRUE emit-signals=TRUE name=appsink-video * - * For H265/AAC - * pipeline = - * gst_parse_launch("videotestsrc pattern=ball is-live=TRUE ! timeoverlay ! queue ! videoconvert ! - * "video/x-raw,format=I420,width=1280,height=720,framerate=25/1 ! " "queue ! " - * "x265enc speed-preset=veryfast bitrate=512 tune=zerolatency ! " - * "video/x-h265,stream-format=byte-stream,alignment=au,profile=main ! appsink sync=TRUE " - * "emit-signals=TRUE name=appsink-video audiotestsrc wave=triangle is-live=TRUE ! " - * "queue leaky=2 max-size-buffers=400 ! audioconvert ! audioresample ! faac ! " - * "capsfilter caps=audio/mpeg,mpegversion=4,stream-format=adts,base-profile=lc,channels=2,rate=48000 ! " - * "appsink sync=TRUE emit-signals=TRUE name=appsink-audio", - * &error); * * Raspberry Pi Hardware Encode Example * "v4l2src device=\"/dev/video0\" ! queue ! v4l2convert ! " @@ -387,8 +376,8 @@ INT32 main(INT32 argc, CHAR* argv[]) if (argc > 3 && STRCMP(argv[3], "testsrc") == 0) { if (argc > 4) { - if (!STRCMP(argv[4], AUDIO_CODEC_NAME_AAC)) { - audioCodec = RTC_CODEC_AAC; + if (!STRCMP(argv[4], AUDIO_CODEC_NAME_OPUS)) { + audioCodec = RTC_CODEC_OPUS; } } @@ -515,4 +504,4 @@ INT32 main(INT32 argc, CHAR* argv[]) // Some platforms also treat 1 or 0 differently, so it's better to use // EXIT_FAILURE and EXIT_SUCCESS macros for portability. return STATUS_FAILED(retStatus) ? EXIT_FAILURE : EXIT_SUCCESS; -} \ No newline at end of file +}