1 /* GStreamer mplex (mjpegtools) wrapper
2 * (c) 2003 Ronald Bultje <rbultje@ronald.bitfreak.net>
3 *
4 * gstmplexjob.hh: gstreamer/mplex multiplex-job wrapper
5 *
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.
10 *
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.
15 *
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.
20 */
21
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
25
26 #include "gstmplexjob.hh"
27
28
29 enum
30 {
31 ARG_0,
32 ARG_FORMAT,
33 ARG_MUX_BITRATE,
34 ARG_VBR,
35 ARG_SYSTEM_HEADERS,
36 ARG_SPLIT_SEQUENCE,
37 ARG_SEGMENT_SIZE,
38 ARG_PACKETS_PER_PACK,
39 ARG_SECTOR_SIZE,
40 ARG_BUFSIZE
41 /* FILL ME */
42 };
43
44 #define DEFAULT_FORMAT MPEG_FORMAT_DVD
45 /*
46 * Property enumeration types.
47 */
48
49 #define GST_TYPE_MPLEX_FORMAT \
50 (gst_mplex_format_get_type ())
51
52 static GType
gst_mplex_format_get_type(void)53 gst_mplex_format_get_type (void)
54 {
55 static GType mplex_format_type = 0;
56
57 if (!mplex_format_type) {
58 static const GEnumValue mplex_formats[] = {
59 {MPEG_FORMAT_MPEG1, "Generic MPEG-1", "mpeg-1"},
60 {MPEG_FORMAT_VCD, "Standard VCD", "vcd"},
61 {MPEG_FORMAT_VCD_NSR, "User VCD", "vcd-nsr"},
62 {MPEG_FORMAT_MPEG2, "Generic MPEG-2", "mpeg-2"},
63 {MPEG_FORMAT_SVCD, "Standard SVCD", "svcd"},
64 {MPEG_FORMAT_SVCD_NSR, "User SVCD", "svcd-nsr"},
65 {MPEG_FORMAT_VCD_STILL, "VCD Stills sequences", "vcd-still"},
66 {MPEG_FORMAT_SVCD_STILL, "SVCD Stills sequences", "svcd-still"},
67 {MPEG_FORMAT_DVD_NAV, "DVD MPEG-2 for dvdauthor", "dvd-nav"},
68 {MPEG_FORMAT_DVD, "DVD MPEG-2", "dvd"},
69 {MPEG_FORMAT_ATSC480i, "ATSC 480i", "atsc-480i"},
70 {MPEG_FORMAT_ATSC480p, "ATSC 480p", "atsc-480p"},
71 {MPEG_FORMAT_ATSC720p, "ATSC 720p", "atsc-720p"},
72 {MPEG_FORMAT_ATSC1080i, "ATSC 1080i", "atsc-1080i"},
73 {0, NULL, NULL},
74 };
75
76 mplex_format_type =
77 g_enum_register_static ("GstMplexFormat", mplex_formats);
78 }
79
80 return mplex_format_type;
81 }
82
83 /*
84 * Class init functions.
85 */
86
GstMplexJob(void)87 GstMplexJob::GstMplexJob (void):
88 MultiplexJob ()
89 {
90 /* blabla */
91 bufsize = 0;
92 }
93
94 /*
95 * GObject properties.
96 */
97
98 void
initProperties(GObjectClass * klass)99 GstMplexJob::initProperties (GObjectClass * klass)
100 {
101 /* encoding profile */
102 g_object_class_install_property (klass, ARG_FORMAT,
103 g_param_spec_enum ("format", "Format", "Encoding profile format",
104 GST_TYPE_MPLEX_FORMAT, DEFAULT_FORMAT,
105 (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
106
107 /* total stream datarate. Normally, this shouldn't be needed, but
108 * some DVD/VCD/SVCD players really need strict values to handle
109 * the created files correctly. */
110 g_object_class_install_property (klass, ARG_MUX_BITRATE,
111 g_param_spec_int ("mux-bitrate", "Mux. bitrate",
112 "Bitrate of output stream in kbps (0 = autodetect)",
113 0, 15 * 1024, 0,
114 (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
115
116 /* override decode buffer size otherwise determined by format */
117 g_object_class_install_property (klass, ARG_BUFSIZE,
118 g_param_spec_int ("bufsize", "Decoder buf. size",
119 "Target decoders video buffer size (kB) "
120 "[default determined by format if not explicitly set]",
121 20, 4000, 46,
122 (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
123
124 /* some boolean stuff for headers */
125 g_object_class_install_property (klass, ARG_VBR,
126 g_param_spec_boolean ("vbr", "VBR",
127 "Whether the input video stream is variable bitrate",
128 FALSE,
129 (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
130 g_object_class_install_property (klass, ARG_SYSTEM_HEADERS,
131 g_param_spec_boolean ("system-headers", "System headers",
132 "Create system header in every pack for generic formats",
133 FALSE,
134 (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
135 #if 0 /* not supported */
136 g_object_class_install_property (klass, ARG_SPLIT_SEQUENCE,
137 g_param_spec_boolean ("split-sequence", "Split sequence",
138 "Simply split a sequence across files "
139 "(rather than building run-out/run-in)",
140 FALSE,
141 (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
142
143 /* size of a segment */
144 g_object_class_install_property (klass, ARG_SEGMENT_SIZE,
145 g_param_spec_int ("max-segment-size", "Max. segment size",
146 "Max. size per segment/file in MB (0 = unlimited)",
147 0, 10 * 1024, 0,
148 (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
149 #endif
150
151 /* packets per pack (generic formats) */
152 g_object_class_install_property (klass, ARG_PACKETS_PER_PACK,
153 g_param_spec_int ("packets-per-pack", "Packets per pack",
154 "Number of packets per pack for generic formats",
155 1, 100, 1,
156 (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
157
158 /* size of one sector */
159 g_object_class_install_property (klass, ARG_SECTOR_SIZE,
160 g_param_spec_int ("sector-size", "Sector size",
161 "Specify sector size in bytes for generic formats",
162 256, 16384, 2048,
163 (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
164 }
165
166 /*
167 * set/get gobject properties.
168 */
169
170 void
getProperty(guint prop_id,GValue * value)171 GstMplexJob::getProperty (guint prop_id, GValue * value)
172 {
173 switch (prop_id) {
174 case ARG_FORMAT:
175 g_value_set_enum (value, mux_format);
176 break;
177 case ARG_MUX_BITRATE:
178 /* convert from bytes back to bits */
179 g_value_set_int (value, (data_rate * 8) / 1000);
180 break;
181 case ARG_VBR:
182 g_value_set_boolean (value, VBR);
183 break;
184 case ARG_SYSTEM_HEADERS:
185 g_value_set_boolean (value, always_system_headers);
186 break;
187 case ARG_SPLIT_SEQUENCE:
188 g_value_set_boolean (value, multifile_segment);
189 break;
190 case ARG_SEGMENT_SIZE:
191 g_value_set_int (value, max_segment_size);
192 break;
193 case ARG_PACKETS_PER_PACK:
194 g_value_set_int (value, packets_per_pack);
195 break;
196 case ARG_SECTOR_SIZE:
197 g_value_set_int (value, sector_size);
198 break;
199 case ARG_BUFSIZE:
200 g_value_set_int (value, bufsize);
201 break;
202 default:
203 break;
204 }
205 }
206
207 void
setProperty(guint prop_id,const GValue * value)208 GstMplexJob::setProperty (guint prop_id, const GValue * value)
209 {
210 switch (prop_id) {
211 case ARG_FORMAT:
212 mux_format = g_value_get_enum (value);
213 break;
214 case ARG_MUX_BITRATE:
215 /* data_rate expects bytes (don't ask me why the property itself is
216 * in bits, I'm just staying compatible to mjpegtools options), and
217 * rounded up to 50-bytes. */
218 data_rate = ((g_value_get_int (value) * 1000 / 8 + 49) / 50) * 50;
219 break;
220 case ARG_VBR:
221 VBR = g_value_get_boolean (value);
222 break;
223 case ARG_SYSTEM_HEADERS:
224 always_system_headers = g_value_get_boolean (value);
225 break;
226 case ARG_SPLIT_SEQUENCE:
227 multifile_segment = g_value_get_boolean (value);
228 break;
229 case ARG_SEGMENT_SIZE:
230 max_segment_size = g_value_get_int (value);
231 break;
232 case ARG_PACKETS_PER_PACK:
233 packets_per_pack = g_value_get_int (value);
234 break;
235 case ARG_SECTOR_SIZE:
236 sector_size = g_value_get_int (value);
237 break;
238 case ARG_BUFSIZE:
239 bufsize = g_value_get_int (value);
240 break;
241 default:
242 break;
243 }
244 }
245