Skip to content

Commit

Permalink
Fix frame indexing in master sample to handle SRTP connection not rea…
Browse files Browse the repository at this point in the history
…dy yet (#1833)

* Add fix to kvsWebRTCClientMaster.c

* Change printf-s to DLOG-s

* Add log for frame drop due to srtp not ready yet

* Add missing sample prefix to log lines

* Semicolon

* CLANG

* Remove \n from logs

* " "

* CLANG
  • Loading branch information
stefankiesz authored Oct 24, 2023
1 parent 1c8c72a commit 2059edf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
6 changes: 6 additions & 0 deletions samples/kvsWebRTCClientMaster.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ PVOID sendVideoPackets(PVOID args)
if (status != STATUS_SUCCESS) {
DLOGV("writeFrame() failed with 0x%08x", status);
}
} else {
// Reset file index to ensure first frame sent upon SRTP ready is a key frame.
fileIndex = 0;
}
}
MUTEX_UNLOCK(pSampleConfiguration->streamingSessionListReadLock);
Expand Down Expand Up @@ -232,6 +235,9 @@ PVOID sendAudioPackets(PVOID args)
PROFILE_WITH_START_TIME(pSampleConfiguration->sampleStreamingSessionList[i]->offerReceiveTime, "Time to first frame");
pSampleConfiguration->sampleStreamingSessionList[i]->firstFrame = FALSE;
}
} else {
// Reset file index to stay in sync with video frames.
fileIndex = 0;
}
}
MUTEX_UNLOCK(pSampleConfiguration->streamingSessionListReadLock);
Expand Down
23 changes: 12 additions & 11 deletions samples/kvsWebrtcClientMasterGstSample.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,13 @@ GstFlowReturn on_new_sample(GstElement* sink, gpointer data, UINT64 trackid)
status = writeFrame(pRtcRtpTransceiver, &frame);
if (status != STATUS_SRTP_NOT_READY_YET && status != STATUS_SUCCESS) {
#ifdef VERBOSE
DLOGE("writeFrame() failed with 0x%08x", status);
DLOGE("[KVS GStreamer Master] writeFrame() failed with 0x%08x", status);
#endif
} else if (status == STATUS_SUCCESS && pSampleStreamingSession->firstFrame) {
PROFILE_WITH_START_TIME(pSampleStreamingSession->offerReceiveTime, "Time to first frame");
pSampleStreamingSession->firstFrame = FALSE;
} else if (status == STATUS_SRTP_NOT_READY_YET) {
DLOGI("[KVS GStreamer Master] SRTP not ready yet, dropping frame");
}
}
MUTEX_UNLOCK(pSampleConfiguration->streamingSessionListReadLock);
Expand Down Expand Up @@ -180,7 +182,7 @@ PVOID sendGstreamerAudioVideo(PVOID args)
pSampleConfiguration->rtspUri);

if (stringOutcome > RTSP_PIPELINE_MAX_CHAR_COUNT) {
printf("[KVS GStreamer Master] ERROR: rtsp uri entered exceeds maximum allowed length set by RTSP_PIPELINE_MAX_CHAR_COUNT\n");
DLOGE("[KVS GStreamer Master] ERROR: rtsp uri entered exceeds maximum allowed length set by RTSP_PIPELINE_MAX_CHAR_COUNT");
goto CleanUp;
}
pipeline = gst_parse_launch(rtspPipeLineBuffer, &error);
Expand Down Expand Up @@ -226,7 +228,7 @@ PVOID sendGstreamerAudioVideo(PVOID args)
pSampleConfiguration->rtspUri);

if (stringOutcome > RTSP_PIPELINE_MAX_CHAR_COUNT) {
printf("[KVS GStreamer Master] ERROR: rtsp uri entered exceeds maximum allowed length set by RTSP_PIPELINE_MAX_CHAR_COUNT\n");
DLOGE("[KVS GStreamer Master] ERROR: rtsp uri entered exceeds maximum allowed length set by RTSP_PIPELINE_MAX_CHAR_COUNT");
goto CleanUp;
}
pipeline = gst_parse_launch(rtspPipeLineBuffer, &error);
Expand All @@ -243,8 +245,7 @@ PVOID sendGstreamerAudioVideo(PVOID args)
appsinkAudio = gst_bin_get_by_name(GST_BIN(pipeline), "appsink-audio");

if (!(appsinkVideo != NULL || appsinkAudio != NULL)) {
printf("[KVS GStreamer Master] sendGstreamerAudioVideo(): cant find appsink, operation returned status code: 0x%08x \n",
STATUS_INTERNAL_ERROR);
DLOGE("[KVS GStreamer Master] sendGstreamerAudioVideo(): cant find appsink, operation returned status code: 0x%08x", STATUS_INTERNAL_ERROR);
goto CleanUp;
}

Expand Down Expand Up @@ -281,7 +282,7 @@ PVOID sendGstreamerAudioVideo(PVOID args)
CleanUp:

if (error != NULL) {
DLOGE("%s", error->message);
DLOGE("[KVS GStreamer Master] %s", error->message);
g_clear_error(&error);
}

Expand Down Expand Up @@ -377,7 +378,7 @@ PVOID receiveGstreamerAudioVideo(PVOID args)

CleanUp:
if (error != NULL) {
DLOGE("%s", error->message);
DLOGE("[KVS GStreamer Master] %s", error->message);
g_clear_error(&error);
}

Expand Down Expand Up @@ -438,9 +439,9 @@ INT32 main(INT32 argc, CHAR* argv[])
} else if (STRCMP(argv[3], "rtspsrc") == 0) {
DLOGI("[KVS GStreamer Master] Using RTSP source in GStreamer");
if (argc < 5) {
printf("[KVS GStreamer Master] No RTSP source URI included. Defaulting to device source");
printf("[KVS GStreamer Master] Usage: ./kvsWebrtcClientMasterGstSample <channel name> audio-video rtspsrc rtsp://<rtsp uri>\n"
"or ./kvsWebrtcClientMasterGstSample <channel name> video-only rtspsrc <rtsp://<rtsp uri>");
DLOGI("[KVS GStreamer Master] No RTSP source URI included. Defaulting to device source");
DLOGI("[KVS GStreamer Master] Usage: ./kvsWebrtcClientMasterGstSample <channel name> audio-video rtspsrc rtsp://<rtsp uri>"
"or ./kvsWebrtcClientMasterGstSample <channel name> video-only rtspsrc <rtsp://<rtsp uri>");
pSampleConfiguration->srcType = DEVICE_SOURCE;
} else {
pSampleConfiguration->srcType = RTSP_SOURCE;
Expand All @@ -450,7 +451,7 @@ INT32 main(INT32 argc, CHAR* argv[])
DLOGI("[KVS Gstreamer Master] Unrecognized source type. Defaulting to device source in GStreamer");
}
} else {
printf("[KVS GStreamer Master] Using device source in GStreamer\n");
DLOGI("[KVS GStreamer Master] Using device source in GStreamer");
}

switch (pSampleConfiguration->mediaType) {
Expand Down

0 comments on commit 2059edf

Please sign in to comment.