encodebasebin: Ensure that parsers are compatible with selected encoders
authorThibault Saunier <tsaunier@igalia.com>
Mon, 7 Dec 2020 14:23:49 +0000 (11:23 -0300)
committerGStreamer Merge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Thu, 7 Jan 2021 20:36:30 +0000 (20:36 +0000)
See https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/-/issues/845

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/-/merge_requests/963>

gst/encoding/gstencodebasebin.c

index dab651f..0a68627 100644 (file)
@@ -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);