Skip to content

Commit

Permalink
Revert unrelated sample changes
Browse files Browse the repository at this point in the history
  • Loading branch information
stefankiesz committed Nov 9, 2024
1 parent 0c84069 commit 6122d17
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 66 deletions.
59 changes: 25 additions & 34 deletions samples/Common.c
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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));
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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));
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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]);
}
Expand Down Expand Up @@ -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))) {
Expand Down Expand Up @@ -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
#endif
19 changes: 6 additions & 13 deletions samples/kvsWebRTCClientMaster.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -310,4 +303,4 @@ PVOID sampleReceiveAudioVideoFrame(PVOID args)
CleanUp:

return (PVOID) (ULONG_PTR) retStatus;
}
}
4 changes: 2 additions & 2 deletions samples/kvsWebRTCClientViewer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
6 changes: 3 additions & 3 deletions samples/kvsWebRTCClientViewerGstSample.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down Expand Up @@ -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;
}
}
17 changes: 3 additions & 14 deletions samples/kvsWebrtcClientMasterGstSample.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 ! "
Expand Down Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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;
}
}

0 comments on commit 6122d17

Please sign in to comment.