2 * Copyright (C) 2019 Thibault Saunier <tsaunier@igalia.com>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
25 #include "gsttranscoding.h"
26 #include "gsttranscodeelements.h"
27 #include <gst/gst-i18n-plugin.h>
28 #include <gst/pbutils/pbutils.h>
30 #include <gst/pbutils/missing-plugins.h>
35 * GstTranscodeBin!sink_%u:
37 * Extra sinkpads for the parallel transcoding of auxiliary streams.
41 static GstStaticPadTemplate transcode_bin_sinks_template =
42 GST_STATIC_PAD_TEMPLATE ("sink_%u",
47 static GstStaticPadTemplate transcode_bin_sink_template =
48 GST_STATIC_PAD_TEMPLATE ("sink",
54 * GstTranscodeBin!src_%u:
56 * The sometimes source pad, it will be exposed depending on the
57 * #transcodebin:profile in use.
59 * Note: in GStreamer 1.18 it was a static
60 * srcpad but in the the 1.20 cycle it was decided that we should make it a
61 * sometimes pad as part of the development of #encodebin2.
65 static GstStaticPadTemplate transcode_bin_src_template =
66 GST_STATIC_PAD_TEMPLATE ("src_%u",
73 const gchar *stream_id;
75 GstPad *encodebin_pad;
78 static TranscodingStream *
79 transcoding_stream_new (GstStream * stream, GstPad * encodebin_pad)
81 TranscodingStream *tstream = g_new0 (TranscodingStream, 1);
83 tstream->stream_id = gst_stream_get_stream_id (stream);
84 tstream->stream = gst_object_ref (stream);
85 tstream->encodebin_pad = encodebin_pad;
91 transcoding_stream_free (TranscodingStream * tstream)
93 gst_object_unref (tstream->stream);
94 gst_object_unref (tstream->encodebin_pad);
101 GstElement *decodebin;
102 GstElement *encodebin;
104 GstEncodingProfile *profile;
105 gboolean avoid_reencoding;
108 GstElement *audio_filter;
109 GstElement *video_filter;
111 GPtrArray *transcoding_streams;
118 } GstTranscodeBinClass;
121 #define GST_TYPE_TRANSCODE_BIN (gst_transcode_bin_get_type ())
122 #define GST_TRANSCODE_BIN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_TRANSCODE_BIN, GstTranscodeBin))
124 #define DEFAULT_AVOID_REENCODING FALSE
126 G_DEFINE_TYPE (GstTranscodeBin, gst_transcode_bin, GST_TYPE_BIN);
127 GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (transcodebin, "transcodebin", GST_RANK_NONE,
128 GST_TYPE_TRANSCODE_BIN, transcodebin_element_init (plugin));
134 PROP_AVOID_REENCODING,
141 post_missing_plugin_error (GstElement * dec, const gchar * element_name)
145 msg = gst_missing_element_message_new (dec, element_name);
146 gst_element_post_message (dec, msg);
148 GST_ELEMENT_ERROR (dec, CORE, MISSING_PLUGIN,
149 ("Missing element '%s' - check your GStreamer installation.",
150 element_name), (NULL));
155 filter_handles_any (GstElement * filter)
159 for (tmp = gst_element_get_pad_template_list (filter); tmp; tmp = tmp->next) {
160 GstPadTemplate *tmpl = tmp->data;
161 GstCaps *caps = gst_pad_template_get_caps (tmpl);
163 if (!gst_caps_is_any (caps)) {
164 gst_caps_unref (caps);
168 gst_caps_unref (caps);
171 return gst_element_get_pad_template_list (filter) != NULL;
175 _insert_filter (GstTranscodeBin * self, GstPad * sinkpad, GstPad * pad,
178 GstPad *filter_src = NULL, *filter_sink = NULL, *convert_sink, *convert_src;
179 GstElement *filter = NULL, *convert;
180 GstObject *filter_parent;
181 const gchar *media_type;
182 gboolean audio = TRUE;
184 media_type = gst_structure_get_name (gst_caps_get_structure (caps, 0));
186 if (self->video_filter && g_str_has_prefix (media_type, "video")) {
189 if (!g_strcmp0 (media_type, "video/x-raw")
190 || filter_handles_any (self->video_filter))
191 filter = self->video_filter;
193 GST_ERROR_OBJECT (pad, "decodebin pad does not produce raw data (%"
194 GST_PTR_FORMAT "), cannot add video filter '%s'", caps,
195 GST_ELEMENT_NAME (self->video_filter));
196 } else if (self->audio_filter && g_str_has_prefix (media_type, "audio")) {
197 if (!g_strcmp0 (media_type, "audio/x-raw")
198 || filter_handles_any (self->audio_filter))
199 filter = self->audio_filter;
201 GST_ERROR_OBJECT (pad, "decodebin pad does not produce raw data (%"
202 GST_PTR_FORMAT "), cannot add audio filter '%s'", caps,
203 GST_ELEMENT_NAME (self->audio_filter));
209 filter_parent = gst_object_get_parent (GST_OBJECT (filter));
210 if (filter_parent != GST_OBJECT_CAST (self)) {
211 GST_WARNING_OBJECT (self,
212 "Filter already in use (inside %" GST_PTR_FORMAT ").", filter_parent);
213 GST_FIXME_OBJECT (self,
214 "Handle transcoding several streams of a same kind.");
215 gst_object_unref (filter_parent);
220 gst_object_unref (filter_parent);
221 /* We are guaranteed filters only have 1 unique sinkpad and srcpad */
222 GST_OBJECT_LOCK (filter);
223 filter_sink = filter->sinkpads->data;
224 filter_src = filter->srcpads->data;
225 GST_OBJECT_UNLOCK (filter);
227 if (filter_handles_any (filter))
228 convert = gst_element_factory_make ("identity", NULL);
230 convert = gst_element_factory_make ("audioconvert", NULL);
232 convert = gst_element_factory_make ("videoconvert", NULL);
235 GST_ELEMENT_ERROR (self, CORE, MISSING_PLUGIN,
236 (_("Missing element '%s' - check your GStreamer installation."),
237 audio ? "audioconvert" : "videoconvert"),
238 ("Cannot add filter as %s element is missing",
239 audio ? "audioconvert" : "videoconvert"));
243 gst_bin_add_many (GST_BIN (self), convert, NULL);
245 convert_sink = gst_element_get_static_pad (convert, "sink");
246 g_assert (convert_sink);
248 if (G_UNLIKELY (gst_pad_link (pad, convert_sink) != GST_PAD_LINK_OK)) {
249 GstCaps *othercaps = gst_pad_get_pad_template_caps (convert_sink);
250 caps = gst_pad_get_current_caps (pad);
252 GST_ELEMENT_ERROR (self, CORE, PAD,
254 ("Couldn't link pads \n\n %" GST_PTR_FORMAT ": %" GST_PTR_FORMAT
255 "\n\n and \n\n %" GST_PTR_FORMAT ": %" GST_PTR_FORMAT
256 "\n\n", pad, caps, convert_sink, othercaps));
258 gst_object_unref (convert_sink);
259 gst_caps_unref (caps);
260 gst_caps_unref (othercaps);
263 gst_object_unref (convert_sink);
265 convert_src = gst_element_get_static_pad (convert, "src");
266 g_assert (convert_src);
268 if (G_UNLIKELY (gst_pad_link (convert_src, filter_sink) != GST_PAD_LINK_OK)) {
269 GstCaps *othercaps = gst_pad_get_pad_template_caps (filter_sink);
270 caps = gst_pad_get_pad_template_caps (convert_src);
272 GST_ELEMENT_ERROR (self, CORE, PAD,
274 ("Couldn't link pads \n\n %" GST_PTR_FORMAT ": %" GST_PTR_FORMAT
275 "\n\n and \n\n %" GST_PTR_FORMAT ": %" GST_PTR_FORMAT
276 "\n\n", convert_src, caps, filter_sink, othercaps));
278 gst_object_unref (convert_src);
279 gst_caps_unref (caps);
280 gst_caps_unref (othercaps);
283 gst_object_unref (convert_src);
285 gst_element_sync_state_with_parent (convert);
286 gst_element_sync_state_with_parent (filter);
288 GST_DEBUG_OBJECT (self, "added %s filter '%s'",
289 audio ? "audio" : "video", GST_ELEMENT_NAME (filter));
294 static TranscodingStream *
295 find_stream (GstTranscodeBin * self, const gchar * stream_id, GstPad * pad)
298 TranscodingStream *res = NULL;
300 GST_OBJECT_LOCK (self);
301 for (i = 0; i < self->transcoding_streams->len; i = i + 1) {
302 TranscodingStream *s = self->transcoding_streams->pdata[i];
304 if (stream_id && !g_strcmp0 (s->stream_id, stream_id)) {
307 } else if (pad && s->encodebin_pad == pad) {
314 GST_OBJECT_UNLOCK (self);
320 gst_transcode_bin_link_encodebin_pad (GstTranscodeBin * self, GstPad * pad,
321 const gchar * stream_id)
324 GstPadLinkReturn lret;
325 TranscodingStream *stream = find_stream (self, stream_id, NULL);
328 GST_ERROR_OBJECT (self, "%s -> Got not stream, decodebin3 bug?", stream_id);
332 caps = gst_pad_query_caps (pad, NULL);
333 pad = _insert_filter (self, stream->encodebin_pad, pad, caps);
334 lret = gst_pad_link (pad, stream->encodebin_pad);
336 case GST_PAD_LINK_OK:
338 case GST_PAD_LINK_WAS_LINKED:
339 GST_FIXME_OBJECT (self, "Pad %" GST_PTR_FORMAT " was already linked",
340 stream->encodebin_pad);
344 GstCaps *othercaps = gst_pad_query_caps (stream->encodebin_pad, NULL);
345 caps = gst_pad_get_current_caps (pad);
348 caps = gst_pad_query_caps (pad, NULL);
350 GST_ELEMENT_ERROR_WITH_DETAILS (self, CORE, PAD,
352 ("Couldn't link pads:\n %" GST_PTR_FORMAT ": %" GST_PTR_FORMAT
354 " %" GST_PTR_FORMAT ": %" GST_PTR_FORMAT "\n\n Error: %s\n",
355 pad, caps, stream->encodebin_pad, othercaps,
356 gst_pad_link_get_name (lret)),
357 ("linking-error", GST_TYPE_PAD_LINK_RETURN, lret,
358 "source-pad", GST_TYPE_PAD, pad,
359 "source-caps", GST_TYPE_CAPS, caps,
360 "sink-pad", GST_TYPE_PAD, stream->encodebin_pad,
361 "sink-caps", GST_TYPE_CAPS, othercaps, NULL));
363 gst_clear_caps (&caps);
365 gst_caps_unref (othercaps);
370 static GstPadProbeReturn
371 wait_stream_start_probe (GstPad * pad,
372 GstPadProbeInfo * info, GstTranscodeBin * self)
374 const gchar *stream_id;
376 if (GST_EVENT_TYPE (info->data) != GST_EVENT_STREAM_START)
377 return GST_PAD_PROBE_OK;
379 gst_event_parse_stream_start (info->data, &stream_id);
380 GST_INFO_OBJECT (self, "Got pad %" GST_PTR_FORMAT " with stream ID: %s",
382 gst_transcode_bin_link_encodebin_pad (self, pad, stream_id);
384 return GST_PAD_PROBE_REMOVE;
388 decodebin_pad_added_cb (GstElement * decodebin, GstPad * pad,
389 GstTranscodeBin * self)
391 const gchar *stream_id;
392 GstEvent *sstart_event;
394 if (GST_PAD_IS_SINK (pad))
397 sstart_event = gst_pad_get_sticky_event (pad, GST_EVENT_STREAM_START, -1);
399 gst_event_parse_stream_start (sstart_event, &stream_id);
400 GST_INFO_OBJECT (self, "Got pad %" GST_PTR_FORMAT " with stream ID: %s",
402 gst_transcode_bin_link_encodebin_pad (self, pad, stream_id);
406 GST_INFO_OBJECT (self, "Waiting for stream ID for pad %" GST_PTR_FORMAT, pad);
407 gst_pad_add_probe (pad, GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM,
408 (GstPadProbeCallback) wait_stream_start_probe, self, NULL);
412 encodebin_pad_added_cb (GstElement * encodebin, GstPad * pad, GstElement * self)
414 GstPadTemplate *template;
418 if (!GST_PAD_IS_SRC (pad))
421 template = gst_element_get_pad_template (self, "src_%u");
423 GST_OBJECT_LOCK (self);
424 name = g_strdup_printf ("src_%u", GST_ELEMENT (self)->numsrcpads);
425 GST_OBJECT_UNLOCK (self);
426 new_pad = gst_ghost_pad_new_from_template (name, pad, template);
428 GST_DEBUG_OBJECT (self, "Encodebin exposed srcpad: %" GST_PTR_FORMAT, pad);
430 gst_element_add_pad (self, new_pad);
434 make_encodebin (GstTranscodeBin * self)
436 GST_INFO_OBJECT (self, "making new encodebin");
441 self->encodebin = gst_element_factory_make ("encodebin2", NULL);
442 if (!self->encodebin)
445 gst_bin_add (GST_BIN (self), self->encodebin);
447 g_signal_connect (self->encodebin, "pad-added",
448 G_CALLBACK (encodebin_pad_added_cb), self);
450 g_object_set (self->encodebin, "profile", self->profile, NULL);
452 return gst_element_sync_state_with_parent (self->encodebin);
457 post_missing_plugin_error (GST_ELEMENT_CAST (self), "encodebin");
459 GST_ELEMENT_ERROR (self, CORE, MISSING_PLUGIN, (NULL),
460 ("No encodebin element, check your installation"));
467 GST_ELEMENT_ERROR (self, CORE, MISSING_PLUGIN, (NULL),
468 ("No GstEncodingProfile set, can not run."));
475 get_encodebin_pad_for_caps (GstTranscodeBin * self, GstCaps * srccaps)
479 gboolean done = FALSE;
480 GValue paditem = { 0, };
482 if (G_UNLIKELY (srccaps == NULL))
485 pads = gst_element_iterate_sink_pads (self->encodebin);
487 GST_DEBUG_OBJECT (self, "srccaps %" GST_PTR_FORMAT, srccaps);
490 switch (gst_iterator_next (pads, &paditem)) {
491 case GST_ITERATOR_OK:
493 GstPad *testpad = g_value_get_object (&paditem);
495 if (!gst_pad_is_linked (testpad) && !find_stream (self, NULL, testpad)) {
496 GstCaps *sinkcaps = gst_pad_query_caps (testpad, NULL);
498 GST_DEBUG_OBJECT (self, "sinkccaps %" GST_PTR_FORMAT, sinkcaps);
500 if (gst_caps_can_intersect (srccaps, sinkcaps)) {
501 res = gst_object_ref (testpad);
504 gst_caps_unref (sinkcaps);
506 g_value_reset (&paditem);
509 case GST_ITERATOR_DONE:
510 case GST_ITERATOR_ERROR:
513 case GST_ITERATOR_RESYNC:
514 gst_iterator_resync (pads);
518 g_value_reset (&paditem);
519 gst_iterator_free (pads);
522 g_signal_emit_by_name (self->encodebin, "request-pad", srccaps, &res);
528 GST_DEBUG_OBJECT (self, "No caps, can't do anything");
534 caps_is_raw (GstCaps * caps, GstStreamType stype)
536 const gchar *media_type;
538 if (!caps || !gst_caps_get_size (caps))
541 media_type = gst_structure_get_name (gst_caps_get_structure (caps, 0));
542 if (stype == GST_STREAM_TYPE_VIDEO)
543 return !g_strcmp0 (media_type, "video/x-raw");
544 else if (stype == GST_STREAM_TYPE_AUDIO)
545 return !g_strcmp0 (media_type, "audio/x-raw");
546 /* FIXME: Handle more types ? */
552 get_encodebin_pad_from_stream (GstTranscodeBin * self,
553 GstEncodingProfile * profile, GstStream * stream)
555 GstCaps *caps = gst_stream_get_caps (stream);
556 GstPad *sinkpad = get_encodebin_pad_for_caps (self, caps);
558 if (!sinkpad && !caps_is_raw (caps, gst_stream_get_stream_type (stream))) {
559 gst_clear_caps (&caps);
560 switch (gst_stream_get_stream_type (stream)) {
561 case GST_STREAM_TYPE_AUDIO:
562 caps = gst_caps_from_string ("audio/x-raw");
564 case GST_STREAM_TYPE_VIDEO:
565 caps = gst_caps_from_string ("video/x-raw");
568 GST_INFO_OBJECT (self, "Unsupported stream type: %" GST_PTR_FORMAT,
572 sinkpad = get_encodebin_pad_for_caps (self, caps);
579 select_stream_cb (GstElement * decodebin,
580 GstStreamCollection * collection, GstStream * stream,
581 GstTranscodeBin * self)
584 gboolean transcode_stream = FALSE;
587 GST_OBJECT_LOCK (self);
588 len = self->transcoding_streams->len;
589 GST_OBJECT_UNLOCK (self);
593 find_stream (self, gst_stream_get_stream_id (stream), NULL) != NULL;
594 if (transcode_stream)
598 for (i = 0; i < gst_stream_collection_get_size (collection); i++) {
599 GstStream *tmpstream = gst_stream_collection_get_stream (collection, i);
600 GstPad *encodebin_pad =
601 get_encodebin_pad_from_stream (self, self->profile, tmpstream);
604 if (stream == tmpstream)
605 transcode_stream = TRUE;
607 GST_INFO_OBJECT (self,
608 "Going to transcode stream %s (encodebin pad: %" GST_PTR_FORMAT,
609 gst_stream_get_stream_id (tmpstream), encodebin_pad);
611 GST_OBJECT_LOCK (self);
612 g_ptr_array_add (self->transcoding_streams,
613 transcoding_stream_new (tmpstream, encodebin_pad));
614 GST_OBJECT_UNLOCK (self);
618 GST_OBJECT_LOCK (self);
619 len = self->transcoding_streams->len;
620 GST_OBJECT_UNLOCK (self);
624 find_stream (self, gst_stream_get_stream_id (stream), NULL) != NULL;
628 if (!transcode_stream)
629 GST_INFO_OBJECT (self, "Discarding stream: %" GST_PTR_FORMAT, stream);
631 return transcode_stream;
634 /* Called with OBJECT_LOCK */
636 _setup_avoid_reencoding (GstTranscodeBin * self)
641 if (!self->avoid_reencoding)
644 if (!GST_IS_ENCODING_CONTAINER_PROFILE (self->profile))
647 g_object_get (self->decodebin, "caps", &decodecaps, NULL);
648 decodecaps = gst_caps_make_writable (decodecaps);
650 gst_encoding_container_profile_get_profiles
651 (GST_ENCODING_CONTAINER_PROFILE (self->profile));
652 for (; tmp; tmp = tmp->next) {
653 GstEncodingProfile *profile = tmp->data;
654 GstCaps *restrictions, *encodecaps;
655 GstElement *filter = NULL;
657 restrictions = gst_encoding_profile_get_restriction (profile);
659 if (restrictions && gst_caps_is_any (restrictions)) {
660 gst_caps_unref (restrictions);
664 encodecaps = gst_encoding_profile_get_format (profile);
667 /* Filter operates on raw data so don't allow decodebin to produce
668 * encoded data if one is defined. */
669 if (GST_IS_ENCODING_VIDEO_PROFILE (profile) && self->video_filter)
670 filter = self->video_filter;
671 else if (GST_IS_ENCODING_AUDIO_PROFILE (profile)
672 && self->audio_filter)
673 filter = self->audio_filter;
675 if (!filter || filter_handles_any (filter)) {
676 GST_DEBUG_OBJECT (self,
677 "adding %" GST_PTR_FORMAT " as output caps to decodebin", encodecaps);
678 gst_caps_append (decodecaps, encodecaps);
682 GST_OBJECT_UNLOCK (self);
684 g_object_set (self->decodebin, "caps", decodecaps, NULL);
685 gst_caps_unref (decodecaps);
687 GST_OBJECT_LOCK (self);
691 make_decodebin (GstTranscodeBin * self)
694 GST_INFO_OBJECT (self, "making new decodebin");
696 self->decodebin = gst_element_factory_make ("decodebin3", NULL);
698 g_signal_connect (self->decodebin, "pad-added",
699 G_CALLBACK (decodebin_pad_added_cb), self);
700 g_signal_connect (self->decodebin, "select-stream",
701 G_CALLBACK (select_stream_cb), self);
703 gst_bin_add (GST_BIN (self), self->decodebin);
704 pad = gst_element_get_static_pad (self->decodebin, "sink");
705 if (!gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (self->sinkpad), pad)) {
707 gst_object_unref (pad);
708 GST_ERROR_OBJECT (self, "Could not ghost %" GST_PTR_FORMAT " sinkpad",
714 gst_object_unref (pad);
721 remove_all_children (GstTranscodeBin * self)
723 if (self->encodebin) {
724 gst_element_set_state (self->encodebin, GST_STATE_NULL);
725 gst_bin_remove (GST_BIN (self), self->encodebin);
726 self->encodebin = NULL;
729 if (self->video_filter && GST_OBJECT_PARENT (self->video_filter)) {
730 gst_element_set_state (self->video_filter, GST_STATE_NULL);
731 gst_bin_remove (GST_BIN (self), self->video_filter);
734 if (self->audio_filter && GST_OBJECT_PARENT (self->audio_filter)) {
735 gst_element_set_state (self->audio_filter, GST_STATE_NULL);
736 gst_bin_remove (GST_BIN (self), self->audio_filter);
740 static GstStateChangeReturn
741 gst_transcode_bin_change_state (GstElement * element, GstStateChange transition)
743 GstStateChangeReturn ret;
744 GstTranscodeBin *self = GST_TRANSCODE_BIN (element);
746 switch (transition) {
747 case GST_STATE_CHANGE_READY_TO_PAUSED:
749 if (!self->decodebin) {
750 post_missing_plugin_error (GST_ELEMENT_CAST (self), "decodebin3");
751 GST_ELEMENT_ERROR (self, CORE, MISSING_PLUGIN, (NULL),
752 ("No decodebin element, check your installation"));
757 if (!make_encodebin (self))
766 GST_ELEMENT_CLASS (gst_transcode_bin_parent_class)->change_state (element,
768 if (ret == GST_STATE_CHANGE_FAILURE)
771 switch (transition) {
772 case GST_STATE_CHANGE_PAUSED_TO_READY:
773 GST_OBJECT_LOCK (self);
774 g_ptr_array_remove_range (self->transcoding_streams, 0,
775 self->transcoding_streams->len);
776 GST_OBJECT_UNLOCK (self);
778 g_signal_handlers_disconnect_by_data (self->decodebin, self);
780 remove_all_children (self);
790 remove_all_children (self);
791 return GST_STATE_CHANGE_FAILURE;
795 gst_transcode_bin_dispose (GObject * object)
797 GstTranscodeBin *self = (GstTranscodeBin *) object;
799 g_clear_object (&self->video_filter);
800 g_clear_object (&self->audio_filter);
801 g_clear_pointer (&self->transcoding_streams, g_ptr_array_unref);
803 G_OBJECT_CLASS (gst_transcode_bin_parent_class)->dispose (object);
807 gst_transcode_bin_get_property (GObject * object,
808 guint prop_id, GValue * value, GParamSpec * pspec)
810 GstTranscodeBin *self = GST_TRANSCODE_BIN (object);
814 GST_OBJECT_LOCK (self);
815 g_value_set_object (value, self->profile);
816 GST_OBJECT_UNLOCK (self);
818 case PROP_AVOID_REENCODING:
819 GST_OBJECT_LOCK (self);
820 g_value_set_boolean (value, self->avoid_reencoding);
821 GST_OBJECT_UNLOCK (self);
823 case PROP_AUDIO_FILTER:
824 GST_OBJECT_LOCK (self);
825 g_value_set_object (value, self->audio_filter);
826 GST_OBJECT_UNLOCK (self);
828 case PROP_VIDEO_FILTER:
829 GST_OBJECT_LOCK (self);
830 g_value_set_object (value, self->video_filter);
831 GST_OBJECT_UNLOCK (self);
834 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
839 gst_transcode_bin_request_pad (GstElement * element, GstPadTemplate * temp,
840 const gchar * name, const GstCaps * caps)
842 GstTranscodeBin *self = (GstTranscodeBin *) element;
843 GstPad *gpad, *decodebin_pad =
844 gst_element_request_pad_simple (self->decodebin, "sink_%u");
846 if (!decodebin_pad) {
847 GST_ERROR_OBJECT (element,
848 "Could not request decodebin3 pad for %" GST_PTR_FORMAT, caps);
853 gpad = gst_ghost_pad_new_from_template (name, decodebin_pad, temp);
854 gst_element_add_pad (element, GST_PAD (gpad));
855 gst_object_unref (decodebin_pad);
861 _set_filter (GstTranscodeBin * self, GstElement * filter, GstElement ** mfilter)
864 GST_OBJECT_LOCK (filter);
865 if (filter->numsinkpads != 1) {
866 GST_ERROR_OBJECT (self, "Can not use %" GST_PTR_FORMAT
867 " as filter as it does not have "
868 " one and only one sinkpad", filter);
870 } else if (filter->numsrcpads != 1) {
871 GST_ERROR_OBJECT (self, "Can not use %" GST_PTR_FORMAT
872 " as filter as it does not have " " one and only one srcpad", filter);
875 GST_OBJECT_UNLOCK (filter);
877 gst_bin_add (GST_BIN (self), gst_object_ref (filter));
880 GST_OBJECT_LOCK (self);
882 GST_OBJECT_UNLOCK (self);
887 GST_OBJECT_UNLOCK (filter);
891 _set_profile (GstTranscodeBin * self, GstEncodingProfile * profile)
893 GST_OBJECT_LOCK (self);
894 self->profile = profile;
895 _setup_avoid_reencoding (self);
896 GST_OBJECT_UNLOCK (self);
900 gst_transcode_bin_set_property (GObject * object,
901 guint prop_id, const GValue * value, GParamSpec * pspec)
903 GstTranscodeBin *self = GST_TRANSCODE_BIN (object);
907 _set_profile (self, g_value_dup_object (value));
909 case PROP_AVOID_REENCODING:
910 GST_OBJECT_LOCK (self);
911 self->avoid_reencoding = g_value_get_boolean (value);
912 _setup_avoid_reencoding (self);
913 GST_OBJECT_UNLOCK (self);
915 case PROP_AUDIO_FILTER:
916 _set_filter (self, g_value_dup_object (value), &self->audio_filter);
918 case PROP_VIDEO_FILTER:
919 _set_filter (self, g_value_dup_object (value), &self->video_filter);
922 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
927 gst_transcode_bin_class_init (GstTranscodeBinClass * klass)
929 GObjectClass *object_class = G_OBJECT_CLASS (klass);
930 GstElementClass *gstelement_klass;
932 object_class->dispose = gst_transcode_bin_dispose;
933 object_class->get_property = gst_transcode_bin_get_property;
934 object_class->set_property = gst_transcode_bin_set_property;
936 gstelement_klass = (GstElementClass *) klass;
937 gstelement_klass->change_state =
938 GST_DEBUG_FUNCPTR (gst_transcode_bin_change_state);
939 gstelement_klass->request_new_pad =
940 GST_DEBUG_FUNCPTR (gst_transcode_bin_request_pad);
942 gst_element_class_add_pad_template (gstelement_klass,
943 gst_static_pad_template_get (&transcode_bin_sink_template));
944 gst_element_class_add_pad_template (gstelement_klass,
945 gst_static_pad_template_get (&transcode_bin_sinks_template));
946 gst_element_class_add_pad_template (gstelement_klass,
947 gst_static_pad_template_get (&transcode_bin_src_template));
949 gst_element_class_set_static_metadata (gstelement_klass,
950 "Transcode Bin", "Generic/Bin/Encoding",
951 "Autoplug and transcoder a stream",
952 "Thibault Saunier <tsaunier@igalia.com>");
955 * GstTranscodeBin:profile:
957 * The #GstEncodingProfile to use. This property must be set before going
958 * to %GST_STATE_PAUSED or higher.
960 g_object_class_install_property (object_class, PROP_PROFILE,
961 g_param_spec_object ("profile", "Profile",
962 "The GstEncodingProfile to use", GST_TYPE_ENCODING_PROFILE,
963 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS |
964 GST_PARAM_MUTABLE_READY));
967 * GstTranscodeBin:avoid-reencoding:
969 * See #encodebin:avoid-reencoding
971 g_object_class_install_property (object_class, PROP_AVOID_REENCODING,
972 g_param_spec_boolean ("avoid-reencoding", "Avoid re-encoding",
973 "Whether to re-encode portions of compatible video streams that lay on segment boundaries",
974 DEFAULT_AVOID_REENCODING,
975 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS |
976 GST_PARAM_MUTABLE_READY));
979 * GstTranscodeBin:video-filter:
981 * Set the video filter element/bin to use.
983 g_object_class_install_property (object_class, PROP_VIDEO_FILTER,
984 g_param_spec_object ("video-filter", "Video filter",
985 "the video filter(s) to apply, if possible",
986 GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS |
987 GST_PARAM_MUTABLE_READY));
989 * GstTranscodeBin:audio-filter:
991 * Set the audio filter element/bin to use.
993 g_object_class_install_property (object_class, PROP_AUDIO_FILTER,
994 g_param_spec_object ("audio-filter", "Audio filter",
995 "the audio filter(s) to apply, if possible",
996 GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS |
997 GST_PARAM_MUTABLE_READY));
1001 gst_transcode_bin_init (GstTranscodeBin * self)
1003 GstPadTemplate *pad_tmpl;
1005 pad_tmpl = gst_static_pad_template_get (&transcode_bin_sink_template);
1006 self->sinkpad = gst_ghost_pad_new_no_target_from_template ("sink", pad_tmpl);
1007 gst_pad_set_active (self->sinkpad, TRUE);
1008 gst_element_add_pad (GST_ELEMENT (self), self->sinkpad);
1010 gst_object_unref (pad_tmpl);
1012 self->transcoding_streams =
1013 g_ptr_array_new_with_free_func ((GDestroyNotify) transcoding_stream_free);
1015 make_decodebin (self);