encodebin2: Fix support for rendering to stream without muxer

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5914>
This commit is contained in:
Thibault Saunier 2024-01-10 12:42:21 -03:00 committed by GStreamer Marge Bot
parent 56f2c47400
commit 147eb44149
3 changed files with 45 additions and 15 deletions

View file

@ -929,6 +929,7 @@ validate.test.clock_sync.video_1fps
validate.test.clock_sync.video_30fps validate.test.clock_sync.video_30fps
validate.test.dash.seek_with_stop_between_fragments validate.test.dash.seek_with_stop_between_fragments
validate.test.decryptor.cenc_audio_esds_property_overrides validate.test.decryptor.cenc_audio_esds_property_overrides
validate.test.encodebin.encode_no_muxer
validate.test.flow.simple_test validate.test.flow.simple_test
validate.test.flvdemux.audio_only.play_15s validate.test.flvdemux.audio_only.play_15s
validate.test.flvdemux.seek_with_stop validate.test.flvdemux.seek_with_stop

View file

@ -0,0 +1,6 @@
meta,
args = {
"videotestsrc num-buffers=1 ! encodebin2 profile=jpegenc ! filesink location=\"$(TMPDIR)/test.jpg\"",
}

View file

@ -1452,6 +1452,29 @@ err:
goto done; goto done;
} }
static gboolean
gst_encode_base_bin_create_src_pad (GstEncodeBaseBin * ebin, GstPad * target)
{
GstPadTemplate *template =
gst_element_get_pad_template (GST_ELEMENT (ebin), "src_%u");
gchar *name;
GstPad *pad;
GST_OBJECT_LOCK (ebin);
name = g_strdup_printf ("src_%u", GST_ELEMENT (ebin)->numsrcpads);
GST_OBJECT_UNLOCK (ebin);
pad = gst_ghost_pad_new_from_template (name, target, template);
g_free (name);
if (!pad)
return FALSE;
gst_element_add_pad (GST_ELEMENT (ebin), pad);
return TRUE;
}
/* FIXME : Add handling of streams that don't require conversion elements */ /* FIXME : Add handling of streams that don't require conversion elements */
/* /*
* Create the elements, StreamGroup, add the sink pad, link it to the muxer * Create the elements, StreamGroup, add the sink pad, link it to the muxer
@ -1538,7 +1561,15 @@ _create_stream_group (GstEncodeBaseBin * ebin, GstEncodingProfile * sprof,
} }
gst_object_unref (muxerpad); gst_object_unref (muxerpad);
} else { } else {
if (ebin->srcpad) {
gst_ghost_pad_set_target (GST_GHOST_PAD (ebin->srcpad), srcpad); gst_ghost_pad_set_target (GST_GHOST_PAD (ebin->srcpad), srcpad);
} else {
if (!gst_encode_base_bin_create_src_pad (ebin, srcpad)) {
gst_object_unref (srcpad);
goto cant_add_src_pad;
}
}
} }
gst_object_unref (srcpad); gst_object_unref (srcpad);
srcpad = NULL; srcpad = NULL;
@ -1915,6 +1946,10 @@ splitter_encoding_failure:
GST_ERROR_OBJECT (ebin, "Error linking splitter to encoding stream"); GST_ERROR_OBJECT (ebin, "Error linking splitter to encoding stream");
goto cleanup; goto cleanup;
cant_add_src_pad:
GST_ERROR_OBJECT (ebin, "Couldn't add srcpad to encodebin");
goto cleanup;
no_muxer_pad: no_muxer_pad:
GST_ERROR_OBJECT (ebin, GST_ERROR_OBJECT (ebin,
"Couldn't find a compatible muxer pad to link encoder to"); "Couldn't find a compatible muxer pad to link encoder to");
@ -2243,22 +2278,10 @@ create_elements_and_pads (GstEncodeBaseBin * ebin)
gst_object_unref (muxerpad); gst_object_unref (muxerpad);
} else if (muxerpad) { } else if (muxerpad) {
GstPadTemplate *template = if (!gst_encode_base_bin_create_src_pad (ebin, muxerpad)) {
gst_element_get_pad_template (GST_ELEMENT (ebin), "src_%u");
gchar *name;
GstPad *pad;
GST_OBJECT_LOCK (ebin);
name = g_strdup_printf ("src_%u", GST_ELEMENT (ebin)->numsrcpads);
GST_OBJECT_UNLOCK (ebin);
pad = gst_ghost_pad_new_from_template (name, muxerpad, template);
g_free (name);
if (!pad)
goto no_muxer_ghost_pad; goto no_muxer_ghost_pad;
}
gst_object_unref (muxerpad); gst_object_unref (muxerpad);
gst_element_add_pad (GST_ELEMENT (ebin), pad);
} }
/* Activate fixed presence streams */ /* Activate fixed presence streams */