• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* GStreamer mpeg2enc (mjpegtools) wrapper
2  * (c) 2003 Ronald Bultje <rbultje@ronald.bitfreak.net>
3  *
4  * gstmpeg2encoptions.cc: gobject/mpeg2enc option wrapping class
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 "gstmpeg2encoptions.hh"
27 #ifdef WIN32
28 #  include <windows.h> //For GetSystemInfo
29 #endif
30 
31 #include <gst/gst.h>
32 
33 /*
34  * Property enumeration.
35  */
36 
37 enum
38 {
39   ARG_0,
40   ARG_FORMAT,
41   ARG_FRAMERATE,
42   ARG_ASPECT,
43   ARG_INTERLACE_MODE,
44   ARG_BITRATE,
45   ARG_NONVIDEO_BITRATE,
46   ARG_QUANTISATION,
47   ARG_VCD_STILL_SIZE,
48   ARG_MOTION_SEARCH_RADIUS,
49   ARG_REDUCTION_4_4,
50   ARG_REDUCTION_2_2,
51   ARG_UNIT_COEFF_ELIM,
52   ARG_MIN_GOP_SIZE,
53   ARG_MAX_GOP_SIZE,
54   ARG_CLOSED_GOP,
55   ARG_FORCE_B_B_P,
56   ARG_B_PER_REFFRAME,
57   ARG_QUANTISATION_REDUCTION,
58   ARG_QUANT_REDUCTION_MAX_VAR,
59   ARG_INTRA_DC_PRECISION,
60   ARG_REDUCE_HF,
61   ARG_KEEP_HF,
62   ARG_QUANTISATION_MATRIX,
63   ARG_BUFSIZE,
64   ARG_VIDEO_NORM,
65   ARG_SEQUENCE_LENGTH,
66   ARG_3_2_PULLDOWN,
67   ARG_SEQUENCE_HEADER_EVERY_GOP,
68   ARG_PLAYBACK_FIELD_ORDER,
69   ARG_DUMMY_SVCD_SOF,
70   ARG_CORRECT_SVCD_HDS,
71   ARG_ALTSCAN_MPEG2,
72   ARG_CONSTRAINTS,
73   ARG_DUALPRIME_MPEG2,
74   ARG_DISABLE_ENCODE_RETRIES,
75       /* FILL ME */
76 };
77 
78 /* MPEG1 VCD bitrate is used as default (also by mpeg2enc) */
79 #define DEFAULT_BITRATE  1125
80 
81 /*
82  * Property enumeration types.
83  */
84 
85 /* FIXME: nick/name perhaps to be reversed (?) */
86 
87 #define GST_TYPE_MPEG2ENC_FORMAT \
88   (gst_mpeg2enc_format_get_type ())
89 
90 static GType
gst_mpeg2enc_format_get_type(void)91 gst_mpeg2enc_format_get_type (void)
92 {
93   static GType mpeg2enc_format_type = 0;
94 
95   if (!mpeg2enc_format_type) {
96     static const GEnumValue mpeg2enc_formats[] = {
97       {MPEG_FORMAT_MPEG1, "Generic MPEG-1", "0"},
98       {MPEG_FORMAT_VCD, "Standard VCD", "1"},
99       {MPEG_FORMAT_VCD_NSR, "User VCD", "2"},
100       {MPEG_FORMAT_MPEG2, "Generic MPEG-2", "3"},
101       {MPEG_FORMAT_SVCD, "Standard SVCD", "4"},
102       {MPEG_FORMAT_SVCD_NSR, "User SVCD", "5"},
103       {MPEG_FORMAT_VCD_STILL, "VCD Stills sequences", "6"},
104       {MPEG_FORMAT_SVCD_STILL, "SVCD Stills sequences", "7"},
105       {MPEG_FORMAT_DVD_NAV, "DVD MPEG-2 for dvdauthor", "8"},
106       {MPEG_FORMAT_DVD, "DVD MPEG-2", "9"},
107 #ifdef MPEG_FORMAT_ATSC1080i
108       {MPEG_FORMAT_ATSC480i, "ATSC 480i", "10"},
109       {MPEG_FORMAT_ATSC480p, "ATSC 480p", "11"},
110       {MPEG_FORMAT_ATSC720p, "ATSC 720p", "12"},
111       {MPEG_FORMAT_ATSC1080i, "ATSC 1080i", "13"},
112 #endif
113       {0, NULL, NULL},
114     };
115 
116     mpeg2enc_format_type =
117         g_enum_register_static ("GstMpeg2encFormat", mpeg2enc_formats);
118   }
119 
120   return mpeg2enc_format_type;
121 }
122 
123 #define GST_TYPE_MPEG2ENC_FRAMERATE \
124   (gst_mpeg2enc_framerate_get_type ())
125 
126 static GType
gst_mpeg2enc_framerate_get_type(void)127 gst_mpeg2enc_framerate_get_type (void)
128 {
129   static GType mpeg2enc_framerate_type = 0;
130 
131   if (!mpeg2enc_framerate_type) {
132     static const GEnumValue mpeg2enc_framerates[] = {
133       {0, "Same as input", "0"},
134       {1, "24/1.001 (NTSC 3:2 pulldown converted film)", "1"},
135       {2, "24 (native film)", "2"},
136       {3, "25 (PAL/SECAM video)", "3"},
137       {4, "30/1.001 (NTSC video)", "4"},
138       {5, "30", "5"},
139       {6, "50 (PAL/SECAM fields)", "6"},
140       {7, "60/1.001 (NTSC fields)", "7"},
141       {8, "60", "8"},
142       {0, NULL, NULL},
143     };
144 
145     mpeg2enc_framerate_type =
146         g_enum_register_static ("GstMpeg2encFramerate", mpeg2enc_framerates);
147   }
148 
149   return mpeg2enc_framerate_type;
150 }
151 
152 #define GST_TYPE_MPEG2ENC_ASPECT \
153   (gst_mpeg2enc_aspect_get_type ())
154 
155 static GType
gst_mpeg2enc_aspect_get_type(void)156 gst_mpeg2enc_aspect_get_type (void)
157 {
158   static GType mpeg2enc_aspect_type = 0;
159 
160   if (!mpeg2enc_aspect_type) {
161     static const GEnumValue mpeg2enc_aspects[] = {
162       {0, "Deduce from input", "0"},
163       {1, "1:1", "1"},
164       {2, "4:3", "2"},
165       {3, "16:9", "3"},
166       {4, "2.21:1", "4"},
167       {0, NULL, NULL},
168     };
169 
170     mpeg2enc_aspect_type =
171         g_enum_register_static ("GstMpeg2encAspect", mpeg2enc_aspects);
172   }
173 
174   return mpeg2enc_aspect_type;
175 }
176 
177 #define GST_TYPE_MPEG2ENC_INTERLACE_MODE \
178   (gst_mpeg2enc_interlace_mode_get_type ())
179 
180 static GType
gst_mpeg2enc_interlace_mode_get_type(void)181 gst_mpeg2enc_interlace_mode_get_type (void)
182 {
183   static GType mpeg2enc_interlace_mode_type = 0;
184 
185   if (!mpeg2enc_interlace_mode_type) {
186     static const GEnumValue mpeg2enc_interlace_modes[] = {
187       {-1, "Format default mode", "-1"},
188       {0, "Progressive", "0"},
189       {1, "Interlaced, per-frame encoding", "1"},
190       {2, "Interlaced, per-field-encoding", "2"},
191       {0, NULL, NULL},
192     };
193 
194     mpeg2enc_interlace_mode_type =
195         g_enum_register_static ("GstMpeg2encInterlaceMode",
196         mpeg2enc_interlace_modes);
197   }
198 
199   return mpeg2enc_interlace_mode_type;
200 }
201 
202 #define GST_TYPE_MPEG2ENC_QUANTISATION_MATRIX \
203   (gst_mpeg2enc_quantisation_matrix_get_type ())
204 
205 #define GST_MPEG2ENC_QUANTISATION_MATRIX_DEFAULT 0
206 #define GST_MPEG2ENC_QUANTISATION_MATRIX_HI_RES  1
207 #define GST_MPEG2ENC_QUANTISATION_MATRIX_KVCD    2
208 #define GST_MPEG2ENC_QUANTISATION_MATRIX_TMPGENC 3
209 
210 static GType
gst_mpeg2enc_quantisation_matrix_get_type(void)211 gst_mpeg2enc_quantisation_matrix_get_type (void)
212 {
213   static GType mpeg2enc_quantisation_matrix_type = 0;
214 
215   if (!mpeg2enc_quantisation_matrix_type) {
216     static const GEnumValue mpeg2enc_quantisation_matrixes[] = {
217       {GST_MPEG2ENC_QUANTISATION_MATRIX_DEFAULT,
218           "Default", "9"},
219       {GST_MPEG2ENC_QUANTISATION_MATRIX_HI_RES,
220           "High resolution", "1"},
221       {GST_MPEG2ENC_QUANTISATION_MATRIX_KVCD,
222           "KVCD", "2"},
223       {GST_MPEG2ENC_QUANTISATION_MATRIX_TMPGENC,
224           "TMPGEnc", "3"},
225       {0, NULL, NULL},
226     };
227 
228     mpeg2enc_quantisation_matrix_type =
229         g_enum_register_static ("GstMpeg2encQuantisationMatrix",
230         mpeg2enc_quantisation_matrixes);
231   }
232 
233   return mpeg2enc_quantisation_matrix_type;
234 }
235 
236 #define GST_TYPE_MPEG2ENC_VIDEO_NORM \
237   (gst_mpeg2enc_video_norm_get_type ())
238 
239 static GType
gst_mpeg2enc_video_norm_get_type(void)240 gst_mpeg2enc_video_norm_get_type (void)
241 {
242   static GType mpeg2enc_video_norm_type = 0;
243 
244   if (!mpeg2enc_video_norm_type) {
245     static const GEnumValue mpeg2enc_video_norms[] = {
246       {0, "Unspecified", "0"},
247       {'p', "PAL", "p"},
248       {'n', "NTSC", "n"},
249       {'s', "SECAM", "s"},
250       {0, NULL, NULL},
251     };
252 
253     mpeg2enc_video_norm_type =
254         g_enum_register_static ("GstMpeg2encVideoNorm", mpeg2enc_video_norms);
255   }
256 
257   return mpeg2enc_video_norm_type;
258 }
259 
260 #define GST_TYPE_MPEG2ENC_PLAYBACK_FIELD_ORDER \
261   (gst_mpeg2enc_playback_field_order_get_type ())
262 
263 static GType
gst_mpeg2enc_playback_field_order_get_type(void)264 gst_mpeg2enc_playback_field_order_get_type (void)
265 {
266   static GType mpeg2enc_playback_field_order_type = 0;
267 
268   if (!mpeg2enc_playback_field_order_type) {
269     static const GEnumValue mpeg2enc_playback_field_orders[] = {
270       {Y4M_UNKNOWN, "Unspecified", "0"},
271       {Y4M_ILACE_TOP_FIRST, "Top-field first", "1"},
272       {Y4M_ILACE_BOTTOM_FIRST, "Bottom-field first", "2"},
273       {0, NULL, NULL},
274     };
275 
276     mpeg2enc_playback_field_order_type =
277         g_enum_register_static ("GstMpeg2encPlaybackFieldOrders",
278         mpeg2enc_playback_field_orders);
279   }
280 
281   return mpeg2enc_playback_field_order_type;
282 }
283 
284 /*
285  * Class init stuff.
286  */
287 
GstMpeg2EncOptions()288 GstMpeg2EncOptions::GstMpeg2EncOptions ():
289 MPEG2EncOptions ()
290 {
291   /* autodetect number of CPUs */
292 #ifndef WIN32
293   num_cpus = sysconf (_SC_NPROCESSORS_ONLN);
294 #else
295   SYSTEM_INFO si;
296   GetSystemInfo(&si);
297   num_cpus = si.dwNumberOfProcessors;
298 #endif
299   if (num_cpus < 0)
300     num_cpus = 1;
301   if (num_cpus > 32)
302     num_cpus = 32;
303 
304   /* set some default(s) not set in base class */
305   bitrate = DEFAULT_BITRATE * 1000;
306   disable_encode_retries = FALSE;
307 }
308 
309 /*
310  * Init properties (call once).
311  */
312 
313 void
initProperties(GObjectClass * klass)314 GstMpeg2EncOptions::initProperties (GObjectClass * klass)
315 {
316   /* encoding profile */
317   g_object_class_install_property (klass, ARG_FORMAT,
318       g_param_spec_enum ("format", "Format", "Encoding profile format",
319           GST_TYPE_MPEG2ENC_FORMAT, 0,
320           (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
321 
322   /* input/output stream overrides */
323   g_object_class_install_property (klass, ARG_FRAMERATE,
324       g_param_spec_enum ("framerate", "Framerate", "Output framerate",
325           GST_TYPE_MPEG2ENC_FRAMERATE, 0,
326           (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
327   g_object_class_install_property (klass, ARG_ASPECT,
328       g_param_spec_enum ("aspect", "Aspect", "Display aspect ratio",
329           GST_TYPE_MPEG2ENC_ASPECT, 0,
330           (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
331   g_object_class_install_property (klass, ARG_INTERLACE_MODE,
332       g_param_spec_enum ("interlace-mode", "Interlace mode",
333           "MPEG-2 motion estimation and encoding modes",
334           GST_TYPE_MPEG2ENC_INTERLACE_MODE, 0,
335           (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
336 
337   /* general encoding stream options */
338   g_object_class_install_property (klass, ARG_BITRATE,
339       g_param_spec_int ("bitrate", "Bitrate", "Compressed video bitrate (kbps)",
340           0, 40 * 1000, DEFAULT_BITRATE,
341           (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
342   g_object_class_install_property (klass, ARG_NONVIDEO_BITRATE,
343       g_param_spec_int ("non-video-bitrate", "Non-video bitrate",
344           "Assumed bitrate of non-video for sequence splitting (kbps)",
345           0, 10 * 1000, 0,
346           (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
347   g_object_class_install_property (klass, ARG_QUANTISATION,
348       g_param_spec_int ("quantisation", "Quantisation",
349           "Quantisation factor (-1=cbr, 0=default, 1=best, 31=worst)",
350           -1, 31, 0,
351           (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
352 
353   /* stills options */
354   g_object_class_install_property (klass, ARG_VCD_STILL_SIZE,
355       g_param_spec_int ("vcd-still-size", "VCD stills size",
356           "Size of VCD stills (in KB)",
357           0, 512, 0,
358           (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
359 
360   /* motion estimation options */
361   g_object_class_install_property (klass, ARG_MOTION_SEARCH_RADIUS,
362       g_param_spec_int ("motion-search-radius", "Motion search radius",
363           "Motion compensation search radius",
364           0, 32, 16,
365           (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
366   g_object_class_install_property (klass, ARG_REDUCTION_4_4,
367       g_param_spec_int ("reduction-4x4", "4x4 reduction",
368           "Reduction factor for 4x4 subsampled candidate motion estimates"
369           " (1=max. quality, 4=max. speed)",
370           1, 4, 2,
371           (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
372   g_object_class_install_property (klass, ARG_REDUCTION_2_2,
373       g_param_spec_int ("reduction-2x2", "2x2 reduction",
374           "Reduction factor for 2x2 subsampled candidate motion estimates"
375           " (1=max. quality, 4=max. speed)",
376           1, 4, 3,
377           (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
378   g_object_class_install_property (klass, ARG_UNIT_COEFF_ELIM,
379       g_param_spec_int ("unit-coeff-elim", "Unit coefficience elimination",
380           "How aggressively small-unit picture blocks should be skipped",
381           -40, 40, 0,
382           (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
383 
384   /* GOP options */
385   g_object_class_install_property (klass, ARG_MIN_GOP_SIZE,
386       g_param_spec_int ("min-gop-size", "Min. GOP size",
387           "Minimal size per Group-of-Pictures (-1=default)",
388           -1, 250, -1,
389           (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
390   g_object_class_install_property (klass, ARG_MAX_GOP_SIZE,
391       g_param_spec_int ("max-gop-size", "Max. GOP size",
392           "Maximal size per Group-of-Pictures (-1=default)",
393           -1, 250, -1,
394           (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
395   g_object_class_install_property (klass, ARG_CLOSED_GOP,
396       g_param_spec_boolean ("closed-gop", "Closed GOP",
397           "All Group-of-Pictures are closed (for multi-angle DVDs)",
398           FALSE,
399           (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
400   g_object_class_install_property (klass, ARG_FORCE_B_B_P,
401       g_param_spec_boolean ("force-b-b-p", "Force B-B-P",
402           "Force two B frames between I/P frames when closing GOP boundaries",
403           FALSE,
404           (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
405   g_object_class_install_property (klass, ARG_B_PER_REFFRAME,
406       g_param_spec_int ("b-per-refframe", "B per ref. frame",
407           "Number of B frames between each I/P frame",
408           0, 2, 0,
409           (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
410 
411   /* quantisation options */
412   g_object_class_install_property (klass, ARG_QUANTISATION_REDUCTION,
413       g_param_spec_float ("quantisation-reduction", "Quantisation reduction",
414           "Max. quantisation reduction for highly active blocks",
415           -4., 10., 0.,
416           (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
417   g_object_class_install_property (klass, ARG_QUANT_REDUCTION_MAX_VAR,
418       g_param_spec_float ("quant-reduction-max-var",
419           "Max. quant. reduction variance",
420           "Maximal luma variance below which quantisation boost is used",
421           0., 2500., 100.,
422           (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
423   g_object_class_install_property (klass, ARG_INTRA_DC_PRECISION,
424       g_param_spec_int ("intra-dc-prec", "Intra. DC precision",
425           "Number of bits precision for DC (base colour) in MPEG-2 blocks",
426           8, 11, 9,
427           (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
428   g_object_class_install_property (klass, ARG_REDUCE_HF,
429       g_param_spec_float ("reduce-hf", "Reduce HF",
430           "How much to reduce high-frequency resolution (by increasing quantisation)",
431           0., 2., 0.,
432           (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
433   g_object_class_install_property (klass, ARG_KEEP_HF,
434       g_param_spec_boolean ("keep-hf", "Keep HF",
435           "Maximize high-frequency resolution (for high-quality sources)",
436           FALSE,
437           (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
438   g_object_class_install_property (klass, ARG_QUANTISATION_MATRIX,
439       g_param_spec_enum ("quant-matrix", "Quant. matrix",
440           "Quantisation matrix to use for encoding",
441           GST_TYPE_MPEG2ENC_QUANTISATION_MATRIX, 0,
442           (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
443 
444   /* general options */
445   g_object_class_install_property (klass, ARG_BUFSIZE,
446       g_param_spec_int ("bufsize", "Decoder buf. size",
447           "Target decoders video buffer size (kB) (default depends on format)",
448           20, 4000, 46,
449           (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
450 
451   /* header flag settings */
452   g_object_class_install_property (klass, ARG_VIDEO_NORM,
453       g_param_spec_enum ("norm", "Norm",
454           "Tag output for specific video norm",
455           GST_TYPE_MPEG2ENC_VIDEO_NORM, 0,
456           (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
457   g_object_class_install_property (klass, ARG_SEQUENCE_LENGTH,
458       g_param_spec_int ("sequence-length", "Sequence length",
459           "Place a sequence boundary after each <num> MB (0=disable)",
460           0, 10 * 1024, 0,
461           (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
462   g_object_class_install_property (klass, ARG_3_2_PULLDOWN,
463       g_param_spec_boolean ("pulldown-3-2", "3-2 pull down",
464           "Generate header flags for 3-2 pull down 24fps movies",
465           FALSE,
466           (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
467   g_object_class_install_property (klass, ARG_SEQUENCE_HEADER_EVERY_GOP,
468       g_param_spec_boolean ("sequence-header-every-gop",
469           "Sequence hdr. every GOP",
470           "Include a sequence header in every GOP",
471           FALSE,
472           (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
473   g_object_class_install_property (klass, ARG_DUMMY_SVCD_SOF,
474       g_param_spec_boolean ("dummy-svcd-sof", "Dummy SVCD SOF",
475           "Generate dummy SVCD scan-data (for vcdimager)",
476           TRUE,
477           (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
478   g_object_class_install_property (klass, ARG_PLAYBACK_FIELD_ORDER,
479       g_param_spec_enum ("playback-field-order", "Playback field order",
480           "Force specific playback field order",
481           GST_TYPE_MPEG2ENC_PLAYBACK_FIELD_ORDER, Y4M_UNKNOWN,
482           (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
483   g_object_class_install_property (klass, ARG_CORRECT_SVCD_HDS,
484       g_param_spec_boolean ("correct-svcd-hds", "Correct SVCD hor. size",
485           "Force SVCD width to 480 instead of 540/720",
486           FALSE,
487           (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
488   g_object_class_install_property (klass, ARG_ALTSCAN_MPEG2,
489       g_param_spec_boolean ("altscan-mpeg2", "Alt. MPEG-2 scan",
490           "Alternate MPEG-2 block scanning. Disabling this might "
491           "make buggy players play SVCD streams",
492           TRUE,
493           (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
494 
495   /* dangerous/experimental stuff */
496   g_object_class_install_property (klass, ARG_CONSTRAINTS,
497       g_param_spec_boolean ("constraints", "Constraints",
498           "Use strict video resolution and bitrate checks",
499           TRUE, (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
500   g_object_class_install_property (klass, ARG_DUALPRIME_MPEG2,
501       g_param_spec_boolean ("dualprime", "Dual Prime Motion Estimation",
502           "Dual Prime Motion Estimation Mode for MPEG-2 I/P-frame only "
503           "streams.  Quite some players do not support this.",
504           FALSE, (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
505 
506   /**
507    * mpeg2enc:disable-encode-retries:
508    *
509    * Prevent the encoder from reencoding pictures in a second pass.
510    *
511    * This can vastly improve performance, but potentially affect reaching
512    * bitrate targets.
513    *
514    * See https://sourceforge.net/p/mjpeg/bugs/141/ for some background.
515    *
516    * Since: 1.18
517    */
518   g_object_class_install_property (klass, ARG_DISABLE_ENCODE_RETRIES,
519       g_param_spec_boolean ("disable-encode-retries", "Disable encode retries",
520           "Prevent the encoder from reencoding pictures in a second pass."
521           " This can vastly improve performance, but potentially affect reaching"
522           " bitrate targets.",
523           FALSE, (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
524 
525   gst_type_mark_as_plugin_api (GST_TYPE_MPEG2ENC_ASPECT, (GstPluginAPIFlags) 0);
526   gst_type_mark_as_plugin_api (GST_TYPE_MPEG2ENC_FORMAT, (GstPluginAPIFlags) 0);
527   gst_type_mark_as_plugin_api (GST_TYPE_MPEG2ENC_FRAMERATE, (GstPluginAPIFlags) 0);
528   gst_type_mark_as_plugin_api (GST_TYPE_MPEG2ENC_INTERLACE_MODE, (GstPluginAPIFlags) 0);
529   gst_type_mark_as_plugin_api (GST_TYPE_MPEG2ENC_VIDEO_NORM, (GstPluginAPIFlags) 0);
530   gst_type_mark_as_plugin_api (GST_TYPE_MPEG2ENC_PLAYBACK_FIELD_ORDER, (GstPluginAPIFlags) 0);
531   gst_type_mark_as_plugin_api (GST_TYPE_MPEG2ENC_QUANTISATION_MATRIX, (GstPluginAPIFlags) 0);
532 }
533 
534 /*
535  * GObject property foo, C++ style.
536  */
537 
538 void
getProperty(guint prop_id,GValue * value)539 GstMpeg2EncOptions::getProperty (guint prop_id, GValue * value)
540 {
541   switch (prop_id) {
542     case ARG_FORMAT:
543       g_value_set_enum (value, format);
544       break;
545     case ARG_FRAMERATE:
546       g_value_set_enum (value, frame_rate);
547       break;
548     case ARG_ASPECT:
549       g_value_set_enum (value, aspect_ratio);
550       break;
551     case ARG_INTERLACE_MODE:
552       g_value_set_enum (value, fieldenc);
553       break;
554     case ARG_BITRATE:
555       g_value_set_int (value, bitrate / 1000);
556       break;
557     case ARG_NONVIDEO_BITRATE:
558       g_value_set_int (value, nonvid_bitrate);
559       break;
560     case ARG_QUANTISATION:
561       g_value_set_int (value, force_cbr ? -1 : quant);
562       break;
563     case ARG_VCD_STILL_SIZE:
564       g_value_set_int (value, still_size / 1024);
565       break;
566     case ARG_MOTION_SEARCH_RADIUS:
567       g_value_set_int (value, searchrad);
568       break;
569     case ARG_REDUCTION_4_4:
570       g_value_set_int (value, me44_red);
571       break;
572     case ARG_REDUCTION_2_2:
573       g_value_set_int (value, me22_red);
574       break;
575     case ARG_UNIT_COEFF_ELIM:
576       g_value_set_int (value, unit_coeff_elim);
577       break;
578     case ARG_MIN_GOP_SIZE:
579       g_value_set_int (value, min_GOP_size);
580       break;
581     case ARG_MAX_GOP_SIZE:
582       g_value_set_int (value, max_GOP_size);
583       break;
584     case ARG_CLOSED_GOP:
585       g_value_set_boolean (value, closed_GOPs);
586       break;
587     case ARG_FORCE_B_B_P:
588       g_value_set_boolean (value, preserve_B);
589       break;
590     case ARG_B_PER_REFFRAME:
591       g_value_set_int (value, Bgrp_size - 1);
592       break;
593     case ARG_QUANTISATION_REDUCTION:
594       g_value_set_float (value, act_boost);
595       break;
596     case ARG_QUANT_REDUCTION_MAX_VAR:
597       g_value_set_float (value, boost_var_ceil);
598       break;
599     case ARG_INTRA_DC_PRECISION:
600       g_value_set_int (value, mpeg2_dc_prec + 8);
601       break;
602     case ARG_REDUCE_HF:
603       g_value_set_float (value, hf_q_boost);
604       break;
605     case ARG_KEEP_HF:
606       g_value_set_boolean (value, hf_quant == 2);
607       break;
608     case ARG_QUANTISATION_MATRIX:
609       switch (hf_quant) {
610         case 0:
611           g_value_set_enum (value, GST_MPEG2ENC_QUANTISATION_MATRIX_DEFAULT);
612           break;
613         case 2:
614           g_value_set_enum (value, GST_MPEG2ENC_QUANTISATION_MATRIX_HI_RES);
615           break;
616         case 3:
617           g_value_set_enum (value, GST_MPEG2ENC_QUANTISATION_MATRIX_KVCD);
618           break;
619         case 4:
620           g_value_set_enum (value, GST_MPEG2ENC_QUANTISATION_MATRIX_TMPGENC);
621           break;
622       }
623       break;
624     case ARG_BUFSIZE:
625       g_value_set_int (value, video_buffer_size);
626       break;
627     case ARG_VIDEO_NORM:
628       g_value_set_enum (value, norm);
629       break;
630     case ARG_SEQUENCE_LENGTH:
631       g_value_set_int (value, seq_length_limit);
632       break;
633     case ARG_3_2_PULLDOWN:
634       g_value_set_boolean (value, vid32_pulldown);
635       break;
636     case ARG_SEQUENCE_HEADER_EVERY_GOP:
637       g_value_set_boolean (value, seq_hdr_every_gop);
638       break;
639     case ARG_DUMMY_SVCD_SOF:
640       g_value_set_boolean (value, svcd_scan_data);
641       break;
642     case ARG_PLAYBACK_FIELD_ORDER:
643       g_value_set_enum (value, force_interlacing);
644       break;
645     case ARG_CORRECT_SVCD_HDS:
646       g_value_set_boolean (value, !hack_svcd_hds_bug);
647       break;
648     case ARG_ALTSCAN_MPEG2:
649       g_value_set_boolean (value, !hack_altscan_bug);
650       break;
651     case ARG_CONSTRAINTS:
652       g_value_set_boolean (value, !ignore_constraints);
653       break;
654     case ARG_DUALPRIME_MPEG2:
655       g_value_set_boolean (value, hack_dualprime);
656       break;
657     case ARG_DISABLE_ENCODE_RETRIES:
658       g_value_set_boolean (value, disable_encode_retries);
659       break;
660     default:
661       break;
662   }
663 }
664 
665 void
setProperty(guint prop_id,const GValue * value)666 GstMpeg2EncOptions::setProperty (guint prop_id, const GValue * value)
667 {
668   switch (prop_id) {
669     case ARG_FORMAT:
670       format = g_value_get_enum (value);
671       break;
672     case ARG_FRAMERATE:
673       frame_rate = g_value_get_enum (value);
674       break;
675     case ARG_ASPECT:
676       aspect_ratio = g_value_get_enum (value);
677       break;
678     case ARG_INTERLACE_MODE:
679       fieldenc = g_value_get_enum (value);
680       break;
681     case ARG_BITRATE:
682       bitrate = g_value_get_int (value) * 1000;
683       if (bitrate % 400 != 0) {
684         bitrate = (bitrate / 400 + 1) * 400;
685         GST_INFO ("MPEG bitrate must be a multiple of 400"
686             " - rounded up to bitrate %d", bitrate / 1000);
687       }
688       break;
689     case ARG_NONVIDEO_BITRATE:
690       nonvid_bitrate = g_value_get_int (value);
691       break;
692     case ARG_QUANTISATION:
693       quant = g_value_get_int (value);
694       if (quant < 0) {
695         force_cbr = 1;
696         quant = 0;
697       }
698       break;
699     case ARG_VCD_STILL_SIZE:
700       still_size = g_value_get_int (value) * 1024;
701       break;
702     case ARG_MOTION_SEARCH_RADIUS:
703       searchrad = g_value_get_int (value);
704       break;
705     case ARG_REDUCTION_4_4:
706       me44_red = g_value_get_int (value);
707       break;
708     case ARG_REDUCTION_2_2:
709       me22_red = g_value_get_int (value);
710       break;
711     case ARG_UNIT_COEFF_ELIM:
712       unit_coeff_elim = g_value_get_int (value);
713       break;
714     case ARG_MIN_GOP_SIZE:
715       min_GOP_size = g_value_get_int (value);
716       break;
717     case ARG_MAX_GOP_SIZE:
718       max_GOP_size = g_value_get_int (value);
719       break;
720     case ARG_CLOSED_GOP:
721       closed_GOPs = g_value_get_boolean (value);
722       break;
723     case ARG_FORCE_B_B_P:
724       preserve_B = g_value_get_boolean (value);
725       break;
726     case ARG_B_PER_REFFRAME:
727       Bgrp_size = g_value_get_int (value) + 1;
728       break;
729     case ARG_QUANTISATION_REDUCTION:
730       act_boost = g_value_get_float (value);
731       break;
732     case ARG_QUANT_REDUCTION_MAX_VAR:
733       boost_var_ceil = g_value_get_float (value);
734       break;
735     case ARG_INTRA_DC_PRECISION:
736       mpeg2_dc_prec = g_value_get_int (value) - 8;
737       break;
738     case ARG_REDUCE_HF:
739       hf_q_boost = g_value_get_float (value);
740       if (hf_quant == 0 && hf_q_boost != 0.)
741         hf_quant = 1;
742       break;
743     case ARG_KEEP_HF:
744       hf_quant = g_value_get_boolean (value) ? 2 : 0;
745       break;
746     case ARG_QUANTISATION_MATRIX:
747       switch (g_value_get_enum (value)) {
748         case GST_MPEG2ENC_QUANTISATION_MATRIX_DEFAULT:
749           hf_quant = 0;
750           hf_q_boost = 0;
751           break;
752         case GST_MPEG2ENC_QUANTISATION_MATRIX_HI_RES:
753           hf_quant = 2;
754           break;
755         case GST_MPEG2ENC_QUANTISATION_MATRIX_KVCD:
756           hf_quant = 3;
757           break;
758         case GST_MPEG2ENC_QUANTISATION_MATRIX_TMPGENC:
759           hf_quant = 4;
760           break;
761       }
762       break;
763     case ARG_BUFSIZE:
764       video_buffer_size = g_value_get_int (value);
765       break;
766     case ARG_VIDEO_NORM:
767       norm = g_value_get_enum (value);
768       break;
769     case ARG_SEQUENCE_LENGTH:
770       seq_length_limit = g_value_get_int (value);
771       break;
772     case ARG_3_2_PULLDOWN:
773       vid32_pulldown = g_value_get_boolean (value);
774       break;
775     case ARG_SEQUENCE_HEADER_EVERY_GOP:
776       seq_hdr_every_gop = g_value_get_boolean (value);
777       break;
778     case ARG_DUMMY_SVCD_SOF:
779       svcd_scan_data = g_value_get_boolean (value);
780       break;
781     case ARG_PLAYBACK_FIELD_ORDER:
782       force_interlacing = g_value_get_enum (value);
783       break;
784     case ARG_CORRECT_SVCD_HDS:
785       hack_svcd_hds_bug = !g_value_get_boolean (value);
786       break;
787     case ARG_ALTSCAN_MPEG2:
788       hack_altscan_bug = !g_value_get_boolean (value);
789       break;
790     case ARG_CONSTRAINTS:
791       ignore_constraints = !g_value_get_boolean (value);
792       break;
793     case ARG_DUALPRIME_MPEG2:
794       hack_dualprime = g_value_get_boolean (value);
795       break;
796     case ARG_DISABLE_ENCODE_RETRIES:
797       disable_encode_retries = g_value_get_boolean (value);
798       break;
799     default:
800       break;
801   }
802 }
803