1 /* GStreamer encoding bin
2 * Copyright (C) 2009 Edward Hervey <edward.hervey@collabora.co.uk>
3 * (C) 2009 Nokia Corporation
4 * Copyright (C) 2020 Thibault Saunier <tsaunier@igalia.com>
5 * (C) 2020 Igalia S.L
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
16 *
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
21 */
22
23 /**
24 * SECTION:element-encodebin
25 * @title: encodebin
26 *
27 * EncodeBin provides a bin for encoding/muxing various streams according to
28 * a specified #GstEncodingProfile.
29 *
30 * Based on the profile that was set (via the #GstEncodeBaseBin:profile property),
31 * EncodeBin will internally select and configure the required elements
32 * (encoders, muxers, but also audio and video converters) so that you can
33 * provide it raw or pre-encoded streams of data in input and have your
34 * encoded/muxed/converted stream in output.
35 *
36 * ## Features
37 *
38 * * Automatic encoder and muxer selection based on elements available on the
39 * system.
40 *
41 * * Conversion of raw audio/video streams (scaling, framerate conversion,
42 * colorspace conversion, samplerate conversion) to conform to the profile
43 * output format.
44 *
45 * * Variable number of streams. If the presence property for a stream encoding
46 * profile is 0, you can request any number of sink pads for it via the
47 * standard request pad gstreamer API or the #GstEncodeBaseBin::request-pad action
48 * signal.
49 *
50 * * Avoid reencoding (passthrough). If the input stream is already encoded and is
51 * compatible with what the #GstEncodingProfile expects, then the stream won't
52 * be re-encoded but just passed through downstream to the muxer or the output.
53 *
54 * * Mix pre-encoded and raw streams as input. In addition to the passthrough
55 * feature above, you can feed both raw audio/video *AND* already-encoded data
56 * to a pad. #GstEncodeBaseBin will take care of passing through the compatible
57 * segments and re-encoding the segments of media that need encoding.
58 *
59 * * Standard behaviour is to use a #GstEncodingContainerProfile to have both
60 * encoding and muxing performed. But you can also provide a single stream
61 * profile (like #GstEncodingAudioProfile) to only have the encoding done and
62 * handle the encoded output yourself.
63 *
64 * * Audio imperfection corrections. Incoming audio streams can have non perfect
65 * timestamps (jitter), like the streams coming from ASF files. #GstEncodeBaseBin
66 * will automatically fix those imperfections for you. See
67 * #GstEncodeBaseBin:audio-jitter-tolerance for more details.
68 *
69 * * Variable or Constant video framerate. If your #GstEncodingVideoProfile has
70 * the variableframerate property deactivated (default), then the incoming
71 * raw video stream will be retimestampped in order to produce a constant
72 * framerate.
73 *
74 * * Cross-boundary re-encoding. When feeding compatible pre-encoded streams that
75 * fall on segment boundaries, and for supported formats (right now only H263),
76 * the GOP will be decoded/reencoded when needed to produce an encoded output
77 * that fits exactly within the request GstSegment.
78 *
79 * * Missing plugin support. If a #GstElement is missing to encode/mux to the
80 * request profile formats, a missing-plugin #GstMessage will be posted on the
81 * #GstBus, allowing systems that support the missing-plugin system to offer the
82 * user a way to install the missing element.
83 *
84 */
85
86 #include "gstencodingelements.h"
87 #include "gstencodebin.h"
88
89 struct _GstEncodeBin
90 {
91 GstEncodeBaseBin parent;
92 };
93
94 G_DEFINE_TYPE (GstEncodeBin, gst_encode_bin, GST_TYPE_ENCODE_BASE_BIN);
95 GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (encodebin, "encodebin", GST_RANK_NONE,
96 gst_encode_bin_get_type (), encoding_element_init (plugin));
97
98 static GstStaticPadTemplate muxer_src_template =
99 GST_STATIC_PAD_TEMPLATE ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
100 GST_STATIC_CAPS_ANY);
101
102 static void
gst_encode_bin_class_init(GstEncodeBinClass * klass)103 gst_encode_bin_class_init (GstEncodeBinClass * klass)
104 {
105 GstElementClass *gstelement_klass = (GstElementClass *) klass;
106
107 gst_element_class_add_static_pad_template (gstelement_klass,
108 &muxer_src_template);
109
110 gst_element_class_set_static_metadata (gstelement_klass,
111 "Encoder Bin",
112 "Generic/Bin/Encoder",
113 "Convenience encoding/muxing element",
114 "Edward Hervey <edward.hervey@collabora.co.uk>");
115 }
116
117 static void
gst_encode_bin_init(GstEncodeBin * encode_bin)118 gst_encode_bin_init (GstEncodeBin * encode_bin)
119 {
120 GstEncodeBaseBin *encode_base_bin = (GstEncodeBaseBin *) (encode_bin);
121 GstPadTemplate *tmpl;
122
123 tmpl = gst_static_pad_template_get (&muxer_src_template);
124
125 encode_base_bin->srcpad =
126 gst_ghost_pad_new_no_target_from_template ("src", tmpl);
127 gst_object_unref (tmpl);
128 gst_pad_set_active (encode_base_bin->srcpad, TRUE);
129 gst_element_add_pad (GST_ELEMENT_CAST (encode_base_bin),
130 encode_base_bin->srcpad);
131 }
132