ducatih264enc: fix B frames being disabled
[glsdk/gst-plugin-ducati.git] / src / gstducatih264enc.c
1 /* GStreamer
2  * Copyright (c) 2011, Texas Instruments Incorporated
3  * Copyright (c) 2011, Collabora Ltd.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  *
20  * Author: Alessandro Decina <alessandro.decina@collabora.com>
21  */
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
27 #include "gstducati.h"
28 #include "gstducatih264enc.h"
30 #include <string.h>
32 #include <math.h>
34 #define GST_CAT_DEFAULT gst_ducati_debug
36 #define DEFAULT_PROFILE GST_DUCATI_H264ENC_PROFILE_HIGH
37 #define DEFAULT_LEVEL GST_DUCATI_H264ENC_LEVEL_40
38 #define DEFAULT_QPI 28
39 #define DEFAULT_QP_MAX_I 36
40 #define DEFAULT_QP_MIN_I 10
41 /* 2 x targetBitRate for VBR Rate Control */
42 #define DEFAULT_HRD_BUFFER_SIZE 40960000
43 #define DEFAULT_INTER_INTERVAL 4
45 #define GST_TYPE_DUCATI_H264ENC_PROFILE (gst_ducati_h264enc_profile_get_type ())
46 #define GST_TYPE_DUCATI_H264ENC_LEVEL (gst_ducati_h264enc_level_get_type ())
47 #define GST_TYPE_DUCATI_H264ENC_RCPP (gst_ducati_h264enc_get_rate_control_params_preset_type ())
48 #define GST_TYPE_DUCATI_H264ENC_RATE_CONTROL_ALGO (gst_ducati_h264enc_get_rate_control_algo_type ())
49 #define GST_TYPE_DUCATI_H264ENC_ENTROPY_CODING_MODE (gst_ducati_h264enc_get_entropy_coding_mode_type ())
50 #define GST_TYPE_DUCATI_H264ENC_SLICE_MODE (gst_ducati_h264enc_get_slice_mode_type ())
53 enum
54 {
55   LAST_SIGNAL
56 };
58 enum
59 {
60   PROP_0,
61   PROP_PROFILE,
62   PROP_LEVEL,
63   PROP_RATE_CONTROL_PARAMS_PRESET,
64   PROP_RATE_CONTROL_ALGO,
65   PROP_QPI,
66   PROP_QP_MAX_I,
67   PROP_QP_MIN_I,
68   PROP_HRD_BUFFER_SIZE,
69   PROP_ENTROPY_CODING_MODE,
70   PROP_INTER_INTERVAL,
71   PROP_SLICE_MODE,
72 };
74 static void gst_ducati_h264enc_set_property (GObject * object, guint prop_id,
75     const GValue * value, GParamSpec * pspec);
76 static void gst_ducati_h264enc_get_property (GObject * object, guint prop_id,
77     GValue * value, GParamSpec * pspec);
79 static gboolean gst_ducati_h264enc_allocate_params (GstDucatiVidEnc *
80     self, gint params_sz, gint dynparams_sz, gint status_sz, gint inargs_sz,
81     gint outargs_sz);
82 static gboolean gst_ducati_h264enc_configure (GstDucatiVidEnc * self);
83 static gboolean gst_ducati_h264enc_is_sync_point (GstDucatiVidEnc * enc,
84     int type);
87 static GstStaticPadTemplate gst_ducati_h264enc_sink_template =
88 GST_STATIC_PAD_TEMPLATE ("sink",
89     GST_PAD_SINK,
90     GST_PAD_ALWAYS,
91     GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("NV12"))
92     );
94 static GstStaticPadTemplate gst_ducati_h264enc_src_template =
95 GST_STATIC_PAD_TEMPLATE ("src",
96     GST_PAD_SRC,
97     GST_PAD_ALWAYS,
98     GST_STATIC_CAPS
99     ("video/x-h264, alignment=(string)au, stream-format=(string)byte-stream")
100     );
102 GST_BOILERPLATE (GstDucatiH264Enc, gst_ducati_h264enc, GstDucatiVidEnc,
103     GST_TYPE_DUCATIVIDENC);
106 /* the values for the following enums are taken from the codec */
108 enum
110   GST_DUCATI_H264ENC_PROFILE_BASELINE = 66,            /**< BaseLine Profile   */
111   GST_DUCATI_H264ENC_PROFILE_MAIN = 77,                /**< Main Profile       */
112   GST_DUCATI_H264ENC_PROFILE_EXTENDED = 88,            /**< Extended Profile   */
113   GST_DUCATI_H264ENC_PROFILE_HIGH = 100,               /**< High Profile       */
114   GST_DUCATI_H264ENC_PROFILE_HIGH_10 = 110,             /**< High 10 Profile    */
115   GST_DUCATI_H264ENC_PROFILE_HIGH_422 = 122             /**< High 4:2:2 Profile */
116 };
118 enum
120   GST_DUCATI_H264ENC_LEVEL_10 = 10, /**<  Level 1.0  */
121   GST_DUCATI_H264ENC_LEVEL_1b = 9,  /**<  Level 1.b  */
122   GST_DUCATI_H264ENC_LEVEL_11 = 11, /**<  Level 1.1  */
123   GST_DUCATI_H264ENC_LEVEL_12 = 12, /**<  Level 1.2  */
124   GST_DUCATI_H264ENC_LEVEL_13 = 13, /**<  Level 1.3  */
125   GST_DUCATI_H264ENC_LEVEL_20 = 20, /**<  Level 2.0  */
126   GST_DUCATI_H264ENC_LEVEL_21 = 21, /**<  Level 2.1  */
127   GST_DUCATI_H264ENC_LEVEL_22 = 22, /**<  Level 2.2  */
128   GST_DUCATI_H264ENC_LEVEL_30 = 30, /**<  Level 3.0  */
129   GST_DUCATI_H264ENC_LEVEL_31 = 31, /**<  Level 3.1  */
130   GST_DUCATI_H264ENC_LEVEL_32 = 32, /**<  Level 3.2  */
131   GST_DUCATI_H264ENC_LEVEL_40 = 40, /**<  Level 4.0  */
132   GST_DUCATI_H264ENC_LEVEL_41 = 41, /**<  Level 4.1  */
133   GST_DUCATI_H264ENC_LEVEL_42 = 42, /**<  Level 4.2  */
134   GST_DUCATI_H264ENC_LEVEL_50 = 50, /**<  Level 5.0  */
135   GST_DUCATI_H264ENC_LEVEL_51 = 51 /**<  Level 5.1  */
136 };
138 static GType
139 gst_ducati_h264enc_profile_get_type (void)
141   static GType type = 0;
143   if (!type) {
144     static const GEnumValue vals[] = {
145       {GST_DUCATI_H264ENC_PROFILE_BASELINE, "Base Profile", "baseline"},
146       {GST_DUCATI_H264ENC_PROFILE_MAIN, "Main Profile", "main"},
147       {GST_DUCATI_H264ENC_PROFILE_EXTENDED, "Extended Profile", "extended"},
148       {GST_DUCATI_H264ENC_PROFILE_HIGH, "High Profile", "high"},
149       {GST_DUCATI_H264ENC_PROFILE_HIGH_10, "High 10 Profile", "high-10"},
150       {GST_DUCATI_H264ENC_PROFILE_HIGH_422, "High 4:2:2 Profile", "high-422"},
151       {0, NULL, NULL},
152     };
154     type = g_enum_register_static ("GstDucatiH264EncProfile", vals);
155   }
157   return type;
160 static GType
161 gst_ducati_h264enc_get_rate_control_params_preset_type (void)
163   static GType type = 0;
165   if (!type) {
166     static const GEnumValue vals[] = {
167       {IH264_RATECONTROLPARAMS_DEFAULT, "Rate Control params preset default",
168           "rate-control-params-preset-default"},
169       {IH264_RATECONTROLPARAMS_USERDEFINED, "User defined rate control",
170           "rate-control-params-preset-user-defined"},
171       {IH264_RATECONTROLPARAMS_EXISTING, "Existing rate control params",
172           "rate-control-params-preset-existing"},
173       {IH264_RATECONTROLPARAMS_MAX, "Max rate control",
174           "rate-control-params-preset-control"},
175       {0, NULL, NULL},
176     };
178     type = g_enum_register_static ("GstDucatiH264EncRateControlParams", vals);
179   }
181   return type;
184 static GType
185 gst_ducati_h264enc_get_rate_control_algo_type (void)
187   static GType type = 0;
189   if (!type) {
190     static const GEnumValue vals[] = {
191       {IH264_RATECONTROL_PRC, "Perceptual rate control",
192           "perceptual-rate-control"},
193       {IH264_RATECONTROL_PRC_LOW_DELAY, "Low delay rate control",
194           "low-delay-rate-control"},
195       {IH264_RATECONTROL_DEFAULT, "Default rcAlgo (PRC)",
196           "default-rate-control"},
197       {0, NULL, NULL},
198     };
200     type = g_enum_register_static ("GstDucatiH264EncRateControlAlgo", vals);
201   }
203   return type;
206 static GType
207 gst_ducati_h264enc_level_get_type (void)
209   static GType type = 0;
211   if (!type) {
212     static const GEnumValue vals[] = {
213       {GST_DUCATI_H264ENC_LEVEL_10, "Level 1", "level-1"},
214       {GST_DUCATI_H264ENC_LEVEL_1b, "Level 1b", "level-1b"},
215       {GST_DUCATI_H264ENC_LEVEL_11, "Level 11", "level-11"},
216       {GST_DUCATI_H264ENC_LEVEL_12, "Level 12", "level-12"},
217       {GST_DUCATI_H264ENC_LEVEL_13, "Level 13", "level-13"},
218       {GST_DUCATI_H264ENC_LEVEL_20, "Level 2", "level-2"},
219       {GST_DUCATI_H264ENC_LEVEL_21, "Level 21", "level-21"},
220       {GST_DUCATI_H264ENC_LEVEL_22, "Level 22", "level-22"},
221       {GST_DUCATI_H264ENC_LEVEL_30, "Level 3", "level-3"},
222       {GST_DUCATI_H264ENC_LEVEL_31, "Level 31", "level-31"},
223       {GST_DUCATI_H264ENC_LEVEL_32, "Level 32", "level-32"},
224       {GST_DUCATI_H264ENC_LEVEL_40, "Level 4", "level-4"},
225       {GST_DUCATI_H264ENC_LEVEL_41, "Level 41", "level-41"},
226       {GST_DUCATI_H264ENC_LEVEL_42, "Level 42", "level-42"},
227       {GST_DUCATI_H264ENC_LEVEL_50, "Level 5", "level-5"},
228       {GST_DUCATI_H264ENC_LEVEL_51, "Level 51", "level-51"},
229       {0, NULL, NULL},
230     };
232     type = g_enum_register_static ("GstDucatiH264EncLevel", vals);
233   }
235   return type;
238 static GType
239 gst_ducati_h264enc_get_entropy_coding_mode_type (void)
241   static GType type = 0;
243   if (!type) {
244     static const GEnumValue vals[] = {
245       {IH264_ENTROPYCODING_CAVLC, "CAVLC coding type", "cavlc"},
246       {IH264_ENTROPYCODING_DEFAULT, "Default coding type (cavlc)", "default"},
247       {IH264_ENTROPYCODING_CABAC, "Cabac coding mode", "cabac"},
248       {0, NULL, NULL},
249     };
251     type = g_enum_register_static ("GstDucatiEntropyCodingMode", vals);
252   }
254   return type;
257 static GType
258 gst_ducati_h264enc_get_slice_mode_type (void)
260   static GType type = 0;
262   if (!type) {
263     static const GEnumValue vals[] = {
264       {IH264_SLICEMODE_NONE, "No slice mode", "none"},
265       {IH264_SLICEMODE_DEFAULT, "Default slice coding mode is MB based",
266           "default"},
267       {IH264_SLICEMODE_MBUNIT,
268           "Slices are controlled based upon number of Macroblocks", "mbunit"},
269       {IH264_SLICEMODE_BYTES,
270           "Slices are controlled based upon number of bytes", "bytes"},
271       {IH264_SLICEMODE_OFFSET,
272             "Slices are controlled based upon user defined offset unit of Row",
273           "offset"},
274       {0, NULL, NULL},
275     };
277     type = g_enum_register_static ("GstDucatiSliceMode", vals);
278   }
280   return type;
283 static void
284 gst_ducati_h264enc_base_init (gpointer g_class)
287   GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
289   gst_element_class_add_pad_template (element_class,
290       gst_static_pad_template_get (&gst_ducati_h264enc_src_template));
291   gst_element_class_add_pad_template (element_class,
292       gst_static_pad_template_get (&gst_ducati_h264enc_sink_template));
294   gst_element_class_set_details_simple (element_class, "H264 Encoder",
295       "Codec/Encoder/Video",
296       "Encode raw video into H264 stream",
297       "Alessandro Decina <alessandro.decina@collabora.com>");
299   GST_DUCATIVIDENC_CLASS (element_class)->codec_name = "ivahd_h264enc";
302 static void
303 gst_ducati_h264enc_class_init (GstDucatiH264EncClass * klass)
305   GObjectClass *gobject_class;
306   GstDucatiVidEncClass *videnc_class;
308   gobject_class = G_OBJECT_CLASS (klass);
309   videnc_class = GST_DUCATIVIDENC_CLASS (klass);
311   gobject_class->set_property = gst_ducati_h264enc_set_property;
312   gobject_class->get_property = gst_ducati_h264enc_get_property;
314   videnc_class->allocate_params = gst_ducati_h264enc_allocate_params;
315   videnc_class->configure = gst_ducati_h264enc_configure;
316   videnc_class->is_sync_point = gst_ducati_h264enc_is_sync_point;
318   g_object_class_install_property (gobject_class, PROP_PROFILE,
319       g_param_spec_enum ("profile", "H.264 Profile", "H.264 Profile",
320           GST_TYPE_DUCATI_H264ENC_PROFILE, DEFAULT_PROFILE, G_PARAM_READWRITE));
322   g_object_class_install_property (gobject_class, PROP_LEVEL,
323       g_param_spec_enum ("level", "H.264 Level", "H.264 Level",
324           GST_TYPE_DUCATI_H264ENC_LEVEL, DEFAULT_LEVEL, G_PARAM_READWRITE));
326   g_object_class_install_property (gobject_class, PROP_INTER_INTERVAL,
327       g_param_spec_uint ("inter-interval", "Inter-frame interval",
328           "Max inter frame interval (B frames are allowed between them if > 1)",
329           1, 31, DEFAULT_INTER_INTERVAL, G_PARAM_READWRITE));
331   g_object_class_install_property (gobject_class,
332       PROP_RATE_CONTROL_PARAMS_PRESET,
333       g_param_spec_enum ("rate-control-params-preset",
334           "H.264 rate control params preset",
335           "This preset controls the USER_DEFINED versus "
336           "DEFAULT mode. If you are not aware about the "
337           "fields, it should be set as IH264_RATECONTROLPARAMS_DEFAULT",
338           GST_TYPE_DUCATI_H264ENC_RCPP, IH264_RATECONTROLPARAMS_DEFAULT,
339           G_PARAM_READWRITE));
341   g_object_class_install_property (gobject_class, PROP_RATE_CONTROL_ALGO,
342       g_param_spec_enum ("rate-control-algo", "H.264 rate control algorithm",
343           "This defines the rate control algorithm to be used. Only useful if "
344           " 'rate-control-params-preset' is set as "
345           "'rate-control-params-preset-user-defined'",
346           GST_TYPE_DUCATI_H264ENC_RATE_CONTROL_ALGO, IH264_RATECONTROL_DEFAULT,
347           G_PARAM_READWRITE));
349   g_object_class_install_property (gobject_class, PROP_QPI,
350       g_param_spec_int ("qpi", "Initial quantization parameter",
351           "Initial quantization parameter for I/IDR frames.", -1, 51,
352           DEFAULT_QPI, G_PARAM_READWRITE));
354   g_object_class_install_property (gobject_class, PROP_QP_MIN_I,
355       g_param_spec_int ("qp-min-i", "Minimum quantization parameter",
356           "Minimum quantization parameter for I/IDR frames.", 0, 51,
357           DEFAULT_QP_MIN_I, G_PARAM_READWRITE));
359   g_object_class_install_property (gobject_class, PROP_QP_MAX_I,
360       g_param_spec_int ("qp-max-i", "Maximum quantization parameter",
361           "Maximum quantization parameter for I/IDR frames.", 0, 51,
362           DEFAULT_QP_MAX_I, G_PARAM_READWRITE));
364   g_object_class_install_property (gobject_class, PROP_HRD_BUFFER_SIZE,
365       g_param_spec_uint ("hrd-buffer-size",
366           "Hypothetical reference decoder buffer size",
367           "Hypothetical reference decoder buffer size. This "
368           "size controls the frame skip logic of the encoder. "
369           "For low delay applications this size should be "
370           "small. This size is in bits. Maximum Value is level "
371           "dependant and min value is 4096",
372           4096, G_MAXUINT, DEFAULT_HRD_BUFFER_SIZE, G_PARAM_READWRITE));
374   g_object_class_install_property (gobject_class, PROP_ENTROPY_CODING_MODE,
375       g_param_spec_enum ("entropy-coding-mode", "H.264 entropy coding mode",
376           "Controls the entropy coding type.",
377           GST_TYPE_DUCATI_H264ENC_ENTROPY_CODING_MODE,
378           IH264_ENTROPYCODING_DEFAULT, G_PARAM_READWRITE));
380   g_object_class_install_property (gobject_class, PROP_SLICE_MODE,
381       g_param_spec_enum ("slice-mode", "H.264 slice mode",
382           "This defines the control mechanism to split a picture in slices."
383           " It can be either MB based or bytes based",
384           GST_TYPE_DUCATI_H264ENC_SLICE_MODE,
385           IH264_SLICEMODE_DEFAULT, G_PARAM_READWRITE));
389 static void
390 gst_ducati_h264enc_init (GstDucatiH264Enc * self, GstDucatiH264EncClass * klass)
392   GST_DEBUG ("gst_ducati_h264enc_init");
394   self->profile = DEFAULT_PROFILE;
395   self->level = DEFAULT_LEVEL;
396   self->rate_control_params_preset = IH264_RATECONTROLPARAMS_DEFAULT;
397   self->rate_control_algo = IH264_RATECONTROL_DEFAULT;
398   self->qpi = DEFAULT_QPI;
399   self->qp_min_i = DEFAULT_QP_MIN_I;
400   self->qp_max_i = DEFAULT_QP_MAX_I;
401   self->hrd_buffer_size = DEFAULT_HRD_BUFFER_SIZE;
402   self->inter_interval = DEFAULT_INTER_INTERVAL;
405 static void
406 gst_ducati_h264enc_set_property (GObject * object, guint prop_id,
407     const GValue * value, GParamSpec * pspec)
409   GstDucatiH264Enc *self = GST_DUCATIH264ENC (object);
410   GstDucatiVidEnc *venc = GST_DUCATIVIDENC (object);
411   IH264ENC_DynamicParams *dynParams =
412       (IH264ENC_DynamicParams *) venc->dynParams;
414   self = GST_DUCATIH264ENC (object);
416   switch (prop_id) {
417     case PROP_PROFILE:
418       self->profile = g_value_get_enum (value);
419       break;
420     case PROP_LEVEL:
421       self->level = g_value_get_enum (value);
422       break;
423     case PROP_RATE_CONTROL_PARAMS_PRESET:
424       self->rate_control_params_preset = g_value_get_enum (value);
425       if (dynParams)
426         dynParams->rateControlParams.rateControlParamsPreset =
427             self->rate_control_params_preset;
428       break;
429     case PROP_RATE_CONTROL_ALGO:
430       self->rate_control_algo = g_value_get_enum (value);
432       if (self->rate_control_params_preset !=
433           IH264_RATECONTROLPARAMS_USERDEFINED)
434         GST_INFO_OBJECT (self,
435             "Setting rcAlgo but rateControlParamsPreset not "
436             "'rate-control-params-preset-user-defined' config won't be taken "
437             "into account");
439       if (dynParams)
440         dynParams->rateControlParams.rcAlgo = self->rate_control_algo;
441       break;
442     case PROP_QPI:
443       self->qpi = g_value_get_int (value);
444       if (dynParams)
445         dynParams->rateControlParams.qpI = self->qpi;
447       break;
448     case PROP_QP_MIN_I:
449       self->qp_min_i = g_value_get_int (value);
450       if (dynParams)
451         dynParams->rateControlParams.qpMinI = self->qp_min_i;
452       break;
453     case PROP_QP_MAX_I:
454       self->qp_max_i = g_value_get_int (value);
455       if (dynParams)
456         dynParams->rateControlParams.qpMaxI = self->qp_max_i;
457       break;
458     case PROP_HRD_BUFFER_SIZE:
459       self->hrd_buffer_size = g_value_get_uint (value);
460       break;
461     case PROP_ENTROPY_CODING_MODE:
462       self->entropy_coding_mode = g_value_get_enum (value);
463       break;
464     case PROP_SLICE_MODE:
465       self->slice_mode = g_value_get_enum (value);
466       break;
467     case PROP_INTER_INTERVAL:
468       self->inter_interval = g_value_get_uint (value);
469       break;
470     default:
471       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
472   }
475 static void
476 gst_ducati_h264enc_get_property (GObject * object, guint prop_id,
477     GValue * value, GParamSpec * pspec)
479   GstDucatiH264Enc *self = GST_DUCATIH264ENC (object);
481   g_return_if_fail (GST_IS_DUCATIH264ENC (object));
482   self = GST_DUCATIH264ENC (object);
484   switch (prop_id) {
485     case PROP_PROFILE:
486       g_value_set_enum (value, self->profile);
487       break;
488     case PROP_LEVEL:
489       g_value_set_enum (value, self->level);
490       break;
491     case PROP_RATE_CONTROL_PARAMS_PRESET:
492       g_value_set_enum (value, self->rate_control_params_preset);
493       break;
494     case PROP_RATE_CONTROL_ALGO:
495       g_value_set_enum (value, self->rate_control_algo);
496       break;
497     case PROP_QPI:
498       g_value_set_int (value, self->qpi);
499       break;
500     case PROP_QP_MIN_I:
501       g_value_set_int (value, self->qp_min_i);
502       break;
503     case PROP_QP_MAX_I:
504       g_value_set_int (value, self->qp_max_i);
505       break;
506     case PROP_HRD_BUFFER_SIZE:
507       g_value_set_uint (value, self->hrd_buffer_size);
508       break;
509     case PROP_ENTROPY_CODING_MODE:
510       g_value_set_enum (value, self->entropy_coding_mode);
511       break;
512     case PROP_SLICE_MODE:
513       g_value_set_enum (value, self->slice_mode);
514       break;
515     case PROP_INTER_INTERVAL:
516       g_value_set_uint (value, self->inter_interval);
517       break;
518     default:
519       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
520   }
523 static const char *
524 get_profile_name (guint profile)
526   switch (profile) {
527     case GST_DUCATI_H264ENC_PROFILE_BASELINE:
528       return "baseline";
529     case GST_DUCATI_H264ENC_PROFILE_MAIN:
530       return "main";
531     case GST_DUCATI_H264ENC_PROFILE_EXTENDED:
532       return "extended";
533     case GST_DUCATI_H264ENC_PROFILE_HIGH:
534       return "high";
535     case GST_DUCATI_H264ENC_PROFILE_HIGH_10:
536       return "high-10";
537     case GST_DUCATI_H264ENC_PROFILE_HIGH_422:
538       return "high-422";
539     default:
540       return NULL;
541   }
544 static const char *
545 get_level_name (guint level)
547   switch (level) {
548     case GST_DUCATI_H264ENC_LEVEL_10:
549       return "1";
550     case GST_DUCATI_H264ENC_LEVEL_1b:
551       return "1b";
552     case GST_DUCATI_H264ENC_LEVEL_11:
553       return "1.1";
554     case GST_DUCATI_H264ENC_LEVEL_12:
555       return "1.2";
556     case GST_DUCATI_H264ENC_LEVEL_13:
557       return "1.3";
558     case GST_DUCATI_H264ENC_LEVEL_20:
559       return "2";
560     case GST_DUCATI_H264ENC_LEVEL_21:
561       return "2.1";
562     case GST_DUCATI_H264ENC_LEVEL_22:
563       return "2.2";
564     case GST_DUCATI_H264ENC_LEVEL_30:
565       return "3";
566     case GST_DUCATI_H264ENC_LEVEL_31:
567       return "3.1";
568     case GST_DUCATI_H264ENC_LEVEL_32:
569       return "3.2";
570     case GST_DUCATI_H264ENC_LEVEL_40:
571       return "4";
572     case GST_DUCATI_H264ENC_LEVEL_41:
573       return "4.1";
574     case GST_DUCATI_H264ENC_LEVEL_42:
575       return "4.2";
576     case GST_DUCATI_H264ENC_LEVEL_50:
577       return "5";
578     case GST_DUCATI_H264ENC_LEVEL_51:
579       return "5.1";
580     default:
581       return NULL;
582   }
585 static gboolean
586 gst_ducati_h264enc_configure (GstDucatiVidEnc * videnc)
588   GstDucatiH264Enc *self = GST_DUCATIH264ENC (videnc);
589   IH264ENC_Params *params;
590   IH264ENC_DynamicParams *dynParams;
591   gboolean ret;
592   const char *s;
593   const GstVideoState *state;
594   GstCaps *caps;
596   ret = GST_DUCATIVIDENC_CLASS (parent_class)->configure (videnc);
597   if (!ret)
598     return FALSE;
600   videnc->params->profile = self->profile;
601   videnc->params->level = self->level;
603   params = (IH264ENC_Params *) videnc->params;
604   /* this is the only non-base field strictly required */
605   params->maxIntraFrameInterval = 0x7fffffff;
606   params->IDRFrameInterval = 1;
607   params->numTemporalLayer = 1;
608   params->entropyCodingMode = self->entropy_coding_mode;
609   videnc->params->maxInterFrameInterval = self->inter_interval;
611   /* Dynamic params */
612   dynParams = (IH264ENC_DynamicParams *) videnc->dynParams;
613   dynParams->rateControlParams.rateControlParamsPreset =
614       self->rate_control_params_preset;
615   dynParams->rateControlParams.rcAlgo = self->rate_control_algo;
616   dynParams->rateControlParams.qpI = self->qpi;
617   dynParams->rateControlParams.qpMaxI = self->qp_max_i;
618   dynParams->rateControlParams.qpMinI = self->qp_min_i;
619   dynParams->rateControlParams.HRDBufferSize = self->hrd_buffer_size;
620   dynParams->sliceCodingParams.sliceMode = self->slice_mode;
621   videnc->dynParams->interFrameInterval = self->inter_interval;
623   state = gst_base_video_encoder_get_state (GST_BASE_VIDEO_ENCODER (videnc));
624   caps = gst_caps_new_simple ("video/x-h264",
625       "width", G_TYPE_INT, videnc->rect.w,
626       "height", G_TYPE_INT, videnc->rect.h,
627       "framerate", GST_TYPE_FRACTION, state->fps_n, state->fps_d,
628       "pixel-aspect-ratio", GST_TYPE_FRACTION, state->par_n, state->par_d,
629       "stream-format", G_TYPE_STRING, "byte-stream",
630       "align", G_TYPE_STRING, "au", NULL);
631   s = get_profile_name (self->profile);
632   if (s)
633     gst_caps_set_simple (caps, "profile", G_TYPE_STRING, s, NULL);
634   s = get_level_name (self->level);
635   if (s)
636     gst_caps_set_simple (caps, "level", G_TYPE_STRING, s, NULL);
637   ret = gst_pad_set_caps (GST_BASE_VIDEO_CODEC_SRC_PAD (self), caps);
639   return ret;
642 static gboolean
643 gst_ducati_h264enc_allocate_params (GstDucatiVidEnc *
644     videnc, gint params_sz, gint dynparams_sz, gint status_sz, gint inargs_sz,
645     gint outargs_sz)
647   gboolean ret = GST_DUCATIVIDENC_CLASS (parent_class)->allocate_params (videnc,
648       sizeof (IH264ENC_Params), sizeof (IH264ENC_DynamicParams),
649       sizeof (IVIDENC2_Status), sizeof (IVIDENC2_InArgs),
650       sizeof (IVIDENC2_OutArgs));
652   GstDucatiH264Enc *self = GST_DUCATIH264ENC (videnc);
654   if (ret == TRUE) {
655     IH264ENC_DynamicParams *dynParams =
656         (IH264ENC_DynamicParams *) videnc->dynParams;
658     dynParams->rateControlParams.rateControlParamsPreset =
659         self->rate_control_params_preset;
660     dynParams->rateControlParams.rcAlgo = self->rate_control_algo;
661     dynParams->rateControlParams.qpI = self->qpi;
662     dynParams->rateControlParams.qpMaxI = self->qp_max_i;
663     dynParams->rateControlParams.qpMinI = self->qp_min_i;
664     dynParams->rateControlParams.HRDBufferSize = self->hrd_buffer_size;
665     dynParams->sliceCodingParams.sliceMode = self->slice_mode;
666   }
668   return ret;
671 static gboolean
672 gst_ducati_h264enc_is_sync_point (GstDucatiVidEnc * enc, int type)
674   return type == IVIDEO_IDR_FRAME;