Skip to content

Commit

Permalink
ONEM-36369: Update caps in decoder when receiving key frames
Browse files Browse the repository at this point in the history
The resolution in WebRTC does change
update caps when _encodeWidth and height are non-zero
Those caps are also used by GStreamerVideoFrameLibWebRTC
and later by LibWebRTCStatsCollector
  • Loading branch information
jacek-manko-red authored and suresh-khurdiya-infosys committed Dec 10, 2024
1 parent c57c096 commit 87a2a48
Showing 1 changed file with 23 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class GStreamerWebRTCVideoDecoder : public webrtc::VideoDecoder {
auto capsfilter = CreateFilter();
auto decoder = makeElement("decodebin");

updateCapsFromImageSize(codecSettings.max_render_resolution().Width(), codecSettings.max_render_resolution().Height());
UpdateCaps(codecSettings.max_render_resolution().Width(), codecSettings.max_render_resolution().Height());

m_pipeline = makeElement("pipeline");
connectSimpleBusMessageCallback(m_pipeline.get());
Expand Down Expand Up @@ -211,13 +211,8 @@ class GStreamerWebRTCVideoDecoder : public webrtc::VideoDecoder {
return WEBRTC_VIDEO_CODEC_UNINITIALIZED;
}

if (inputImage._encodedWidth && inputImage._encodedHeight)
updateCapsFromImageSize(inputImage._encodedWidth, inputImage._encodedHeight);

if (UNLIKELY(!m_caps)) {
GST_ERROR("Encoded image caps not set");
ASSERT_NOT_REACHED();
return WEBRTC_VIDEO_CODEC_UNINITIALIZED;
if (inputImage._encodedWidth > 0 && inputImage._encodedHeight > 0) {
UpdateCaps(inputImage._encodedWidth, inputImage._encodedHeight);
}

// FIXME: Use a GstBufferPool.
Expand All @@ -227,8 +222,7 @@ class GStreamerWebRTCVideoDecoder : public webrtc::VideoDecoder {
gst_buffer_add_reference_timestamp_meta(buffer.get(), m_rtpTimestampCaps.get(), inputImage.RtpTimestamp(), GST_CLOCK_TIME_NONE);

auto sample = adoptGRef(gst_sample_new(buffer.get(), m_caps.get(), nullptr, nullptr));

switch (gst_app_src_push_sample(GST_APP_SRC(m_src), sample.get())) {
switch (gst_app_src_push_sample(GST_APP_SRC(m_src), sample.get())) {
case GST_FLOW_OK:
break;
case GST_FLOW_FLUSHING:
Expand Down Expand Up @@ -256,14 +250,16 @@ class GStreamerWebRTCVideoDecoder : public webrtc::VideoDecoder {
return WEBRTC_VIDEO_CODEC_OK;
}

virtual void updateCapsFromImageSize(int width, int height)
virtual void UpdateCaps(gint width, gint height)
{
if (m_width == width && m_height == height)
return;

m_width = width;
m_height = height;
m_caps = adoptGRef(gst_caps_new_simple(Caps(), "width", G_TYPE_INT, width, "height", G_TYPE_INT, height, nullptr));
if (m_width != width || m_height != height) {
m_width = width;
m_height = height;
m_caps = adoptGRef(gst_caps_new_simple(Caps(),
"width", G_TYPE_INT, width,
"height", G_TYPE_INT, height,
nullptr));
}
}

void AddDecoderIfSupported(std::vector<webrtc::SdpVideoFormat>& codecList)
Expand Down Expand Up @@ -330,15 +326,17 @@ class H264Decoder : public GStreamerWebRTCVideoDecoder {
return GStreamerWebRTCVideoDecoder::Configure(codecSettings);
}

void updateCapsFromImageSize(int width, int height) final
void UpdateCaps(gint width, gint height) final
{
if (m_width == width && m_height == height)
return;

m_width = width;
m_height = height;
m_caps = adoptGRef(gst_caps_new_simple(Caps(), "width", G_TYPE_INT, width, "height", G_TYPE_INT, height,
"alignment", G_TYPE_STRING, "au", nullptr));
if (m_width != width || m_height != height) {
m_width = width;
m_height = height;
m_caps = adoptGRef(gst_caps_new_simple(Caps(),
"width", G_TYPE_INT, width,
"height", G_TYPE_INT, height,
"alignment", G_TYPE_STRING, "au",
nullptr));
}
}
const gchar* Caps() final { return "video/x-h264"; }
const gchar* Name() final { return cricket::kH264CodecName; }
Expand Down

0 comments on commit 87a2a48

Please sign in to comment.