encodebasebin: Ensure that parsers are compatible with selected encoders

See https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/-/issues/845

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/-/merge_requests/963>
This commit is contained in:
Thibault Saunier 2020-12-07 11:23:49 -03:00 committed by GStreamer Merge Bot
parent f573d91237
commit 5950fc1aae

View 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);