From 5950fc1aae40291a2b032aa85b8a687a795e1d45 Mon Sep 17 00:00:00 2001 From: Thibault Saunier Date: Mon, 7 Dec 2020 11:23:49 -0300 Subject: [PATCH] encodebasebin: Ensure that parsers are compatible with selected encoders See https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/-/issues/845 Part-of: --- gst/encoding/gstencodebasebin.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/gst/encoding/gstencodebasebin.c b/gst/encoding/gstencodebasebin.c index dab651f384..0a686279d8 100644 --- a/gst/encoding/gstencodebasebin.c +++ b/gst/encoding/gstencodebasebin.c @@ -815,14 +815,25 @@ no_stream_group: /* Create a parser for the given stream profile */ static inline GstElement * -_get_parser (GstEncodeBaseBin * ebin, GstEncodingProfile * sprof) +_get_parser (GstEncodeBaseBin * ebin, GstEncodingProfile * sprof, + GstElement * encoder) { GList *parsers1, *parsers, *tmp; GstElement *parser = NULL; GstElementFactory *parserfact = NULL; - GstCaps *format; + GstCaps *format = NULL; - format = gst_encoding_profile_get_format (sprof); + if (encoder) { + GstPadTemplate *template = gst_element_get_pad_template (encoder, "src"); + + if (template) + format = gst_pad_template_get_caps (template); + } + + if (!format || gst_caps_is_any (format)) { + gst_clear_caps (&format); + format = gst_encoding_profile_get_format (sprof); + } GST_DEBUG ("Getting list of parsers for format %" GST_PTR_FORMAT, format); @@ -1227,7 +1238,7 @@ setup_smart_encoder (GstEncodeBaseBin * ebin, GstEncodingProfile * sprof, goto err; } - parser = _get_parser (ebin, sprof); + parser = _get_parser (ebin, sprof, encoder); sgroup->smart_capsfilter = gst_element_factory_make ("capsfilter", NULL); reencoder_bin = gst_bin_new (NULL); g_object_set (sgroup->smart_capsfilter, "caps", format, NULL); @@ -1412,9 +1423,8 @@ _create_stream_group (GstEncodeBaseBin * ebin, GstEncodingProfile * sprof, goto outfilter_link_failure; last = sgroup->outfilter; - - sgroup->parser = _get_parser (ebin, sprof); - + sgroup->encoder = _get_encoder (ebin, sprof); + sgroup->parser = _get_parser (ebin, sgroup->profile, sgroup->encoder); if (sgroup->parser != NULL) { GST_DEBUG ("Got a parser %s", GST_ELEMENT_NAME (sgroup->parser)); gst_bin_add (GST_BIN (ebin), sgroup->parser); @@ -1523,8 +1533,7 @@ _create_stream_group (GstEncodeBaseBin * ebin, GstEncodingProfile * sprof, /* 1. Create the encoder */ GST_LOG ("Adding encoder"); - sgroup->encoder = _get_encoder (ebin, sprof); - if (sgroup->encoder != NULL) { + if (sgroup->encoder) { gst_bin_add ((GstBin *) ebin, sgroup->encoder); tosync = g_list_append (tosync, sgroup->encoder);