From dba3bdd0cf68d7e441ee670281c1a6bf16715f88 Mon Sep 17 00:00:00 2001 From: Seungha Yang Date: Fri, 7 Mar 2025 01:09:23 +0900 Subject: [PATCH] h264ccextractor,h265ccextractor: Do not resend caps per output buffer Send caps event only when it's required Fixes: https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/4281 Part-of: --- .../ext/closedcaption/gsth264ccextractor.c | 16 ++++++++++++++-- .../ext/closedcaption/gsth265ccextractor.c | 16 ++++++++++++++-- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/subprojects/gst-plugins-bad/ext/closedcaption/gsth264ccextractor.c b/subprojects/gst-plugins-bad/ext/closedcaption/gsth264ccextractor.c index 17b44f7900..d7a57bc7a2 100644 --- a/subprojects/gst-plugins-bad/ext/closedcaption/gsth264ccextractor.c +++ b/subprojects/gst-plugins-bad/ext/closedcaption/gsth264ccextractor.c @@ -96,6 +96,7 @@ struct _GstH264CCExtractor gboolean on_eos; gint fps_n; gint fps_d; + gboolean need_negotiate; }; #define gst_h264_cc_extractor_parent_class parent_class @@ -199,6 +200,8 @@ gst_h264_cc_extractor_set_format (GstVideoDecoder * decoder, GstCaps *caps; gboolean ret; + self->need_negotiate = TRUE; + /* Assume caption type is cea708 raw which is common cc type * embedded in SEI */ if (self->caption_type == GST_VIDEO_CAPTION_TYPE_UNKNOWN) @@ -225,7 +228,12 @@ static gboolean gst_h264_cc_extractor_negotiate (GstVideoDecoder * decoder) { GstH264CCExtractor *self = GST_H264_CC_EXTRACTOR (decoder); - GstCaps *caps = gst_video_caption_type_to_caps (self->caption_type); + GstCaps *caps; + + if (!self->need_negotiate) + return TRUE; + + caps = gst_video_caption_type_to_caps (self->caption_type); gst_caps_set_simple (caps, "framerate", GST_TYPE_FRACTION, self->fps_n, self->fps_d, NULL); @@ -233,6 +241,8 @@ gst_h264_cc_extractor_negotiate (GstVideoDecoder * decoder) gst_pad_set_caps (decoder->srcpad, caps); gst_caps_unref (caps); + self->need_negotiate = FALSE; + return TRUE; } @@ -425,8 +435,10 @@ gst_h264_cc_extractor_output_picture (GstH264Decoder * decoder, } } - if (updated) + if (updated) { + self->need_negotiate = TRUE; gst_video_decoder_negotiate (videodec); + } gst_h264_picture_unref (picture); diff --git a/subprojects/gst-plugins-bad/ext/closedcaption/gsth265ccextractor.c b/subprojects/gst-plugins-bad/ext/closedcaption/gsth265ccextractor.c index 9a0dc90020..054101e009 100644 --- a/subprojects/gst-plugins-bad/ext/closedcaption/gsth265ccextractor.c +++ b/subprojects/gst-plugins-bad/ext/closedcaption/gsth265ccextractor.c @@ -93,6 +93,7 @@ struct _GstH265CCExtractor gboolean on_eos; gint fps_n; gint fps_d; + gboolean need_negotiate; }; #define gst_h265_cc_extractor_parent_class parent_class @@ -194,6 +195,8 @@ gst_h265_cc_extractor_set_format (GstVideoDecoder * decoder, GstCaps *caps; gboolean ret; + self->need_negotiate = TRUE; + /* Assume caption type is cea708 raw which is common cc type * embedded in SEI */ if (self->caption_type == GST_VIDEO_CAPTION_TYPE_UNKNOWN) @@ -220,7 +223,12 @@ static gboolean gst_h265_cc_extractor_negotiate (GstVideoDecoder * decoder) { GstH265CCExtractor *self = GST_H265_CC_EXTRACTOR (decoder); - GstCaps *caps = gst_video_caption_type_to_caps (self->caption_type); + GstCaps *caps; + + if (!self->need_negotiate) + return TRUE; + + caps = gst_video_caption_type_to_caps (self->caption_type); gst_caps_set_simple (caps, "framerate", GST_TYPE_FRACTION, self->fps_n, self->fps_d, NULL); @@ -228,6 +236,8 @@ gst_h265_cc_extractor_negotiate (GstVideoDecoder * decoder) gst_pad_set_caps (decoder->srcpad, caps); gst_caps_unref (caps); + self->need_negotiate = FALSE; + return TRUE; } @@ -399,8 +409,10 @@ gst_h265_cc_extractor_output_picture (GstH265Decoder * decoder, } } - if (updated) + if (updated) { + self->need_negotiate = TRUE; gst_video_decoder_negotiate (videodec); + } gst_h265_picture_unref (picture);