2852e1b06e003bc9045b6a3a5f018436d909fc05
[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
44 #define GST_TYPE_DUCATI_H264ENC_PROFILE (gst_ducati_h264enc_profile_get_type ())
45 #define GST_TYPE_DUCATI_H264ENC_LEVEL (gst_ducati_h264enc_level_get_type ())
46 #define GST_TYPE_DUCATI_H264ENC_RCPP (gst_ducati_h264enc_get_rate_control_params_preset_type ())
47 #define GST_TYPE_DUCATI_H264ENC_RATE_CONTROL_ALGO (gst_ducati_h264enc_get_rate_control_algo_type ())
48 #define GST_TYPE_DUCATI_H264ENC_ENTROPY_CODING_MODE (gst_ducati_h264enc_get_entropy_coding_mode_type ())
49 #define GST_TYPE_DUCATI_H264ENC_SLICE_MODE (gst_ducati_h264enc_get_slice_mode_type ())
52 enum
53 {
54   LAST_SIGNAL
55 };
57 enum
58 {
59   PROP_0,
60   PROP_PROFILE,
61   PROP_LEVEL,
62   PROP_RATE_CONTROL_PARAMS_PRESET,
63   PROP_RATE_CONTROL_ALGO,
64   PROP_QPI,
65   PROP_QP_MAX_I,
66   PROP_QP_MIN_I,
67   PROP_HRD_BUFFER_SIZE,
68   PROP_ENTROPY_CODING_MODE,
69   PROP_SLICE_MODE,
70 };
72 static void gst_ducati_h264enc_set_property (GObject * object, guint prop_id,
73     const GValue * value, GParamSpec * pspec);
74 static void gst_ducati_h264enc_get_property (GObject * object, guint prop_id,
75     GValue * value, GParamSpec * pspec);
77 static gboolean gst_ducati_h264enc_allocate_params (GstDucatiVidEnc *
78     self, gint params_sz, gint dynparams_sz, gint status_sz, gint inargs_sz,
79     gint outargs_sz);
80 static gboolean gst_ducati_h264enc_configure (GstDucatiVidEnc * self);
81 static gboolean gst_ducati_h264enc_is_sync_point (GstDucatiVidEnc * enc,
82     int type);
85 static GstStaticPadTemplate gst_ducati_h264enc_sink_template =
86 GST_STATIC_PAD_TEMPLATE ("sink",
87     GST_PAD_SINK,
88     GST_PAD_ALWAYS,
89     GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("NV12"))
90     );
92 static GstStaticPadTemplate gst_ducati_h264enc_src_template =
93 GST_STATIC_PAD_TEMPLATE ("src",
94     GST_PAD_SRC,
95     GST_PAD_ALWAYS,
96     GST_STATIC_CAPS
97     ("video/x-h264, alignment=(string)au, stream-format=(string)byte-stream")
98     );
100 GST_BOILERPLATE (GstDucatiH264Enc, gst_ducati_h264enc, GstDucatiVidEnc,
101     GST_TYPE_DUCATIVIDENC);
104 /* the values for the following enums are taken from the codec */
106 enum
108   GST_DUCATI_H264ENC_PROFILE_BASELINE = 66,            /**< BaseLine Profile   */
109   GST_DUCATI_H264ENC_PROFILE_MAIN = 77,                /**< Main Profile       */
110   GST_DUCATI_H264ENC_PROFILE_EXTENDED = 88,            /**< Extended Profile   */
111   GST_DUCATI_H264ENC_PROFILE_HIGH = 100,               /**< High Profile       */
112   GST_DUCATI_H264ENC_PROFILE_HIGH_10 = 110,             /**< High 10 Profile    */
113   GST_DUCATI_H264ENC_PROFILE_HIGH_422 = 122             /**< High 4:2:2 Profile */
114 };
116 enum
118   GST_DUCATI_H264ENC_LEVEL_10 = 10, /**<  Level 1.0  */
119   GST_DUCATI_H264ENC_LEVEL_1b = 9,  /**<  Level 1.b  */
120   GST_DUCATI_H264ENC_LEVEL_11 = 11, /**<  Level 1.1  */
121   GST_DUCATI_H264ENC_LEVEL_12 = 12, /**<  Level 1.2  */
122   GST_DUCATI_H264ENC_LEVEL_13 = 13, /**<  Level 1.3  */
123   GST_DUCATI_H264ENC_LEVEL_20 = 20, /**<  Level 2.0  */
124   GST_DUCATI_H264ENC_LEVEL_21 = 21, /**<  Level 2.1  */
125   GST_DUCATI_H264ENC_LEVEL_22 = 22, /**<  Level 2.2  */
126   GST_DUCATI_H264ENC_LEVEL_30 = 30, /**<  Level 3.0  */
127   GST_DUCATI_H264ENC_LEVEL_31 = 31, /**<  Level 3.1  */
128   GST_DUCATI_H264ENC_LEVEL_32 = 32, /**<  Level 3.2  */
129   GST_DUCATI_H264ENC_LEVEL_40 = 40, /**<  Level 4.0  */
130   GST_DUCATI_H264ENC_LEVEL_41 = 41, /**<  Level 4.1  */
131   GST_DUCATI_H264ENC_LEVEL_42 = 42, /**<  Level 4.2  */
132   GST_DUCATI_H264ENC_LEVEL_50 = 50, /**<  Level 5.0  */
133   GST_DUCATI_H264ENC_LEVEL_51 = 51 /**<  Level 5.1  */
134 };
136 static GType
137 gst_ducati_h264enc_profile_get_type (void)
139   static GType type = 0;
141   if (!type) {
142     static const GEnumValue vals[] = {
143       {GST_DUCATI_H264ENC_PROFILE_BASELINE, "Base Profile", "baseline"},
144       {GST_DUCATI_H264ENC_PROFILE_MAIN, "Main Profile", "main"},
145       {GST_DUCATI_H264ENC_PROFILE_EXTENDED, "Extended Profile", "extended"},
146       {GST_DUCATI_H264ENC_PROFILE_HIGH, "High Profile", "high"},
147       {GST_DUCATI_H264ENC_PROFILE_HIGH_10, "High 10 Profile", "high-10"},
148       {GST_DUCATI_H264ENC_PROFILE_HIGH_422, "High 4:2:2 Profile", "high-422"},
149       {0, NULL, NULL},
150     };
152     type = g_enum_register_static ("GstDucatiH264EncProfile", vals);
153   }
155   return type;
158 static GType
159 gst_ducati_h264enc_get_rate_control_params_preset_type (void)
161   static GType type = 0;
163   if (!type) {
164     static const GEnumValue vals[] = {
165       {IH264_RATECONTROLPARAMS_DEFAULT, "Rate Control params preset default",
166           "rate-control-params-preset-default"},
167       {IH264_RATECONTROLPARAMS_USERDEFINED, "User defined rate control",
168           "rate-control-params-preset-user-defined"},
169       {IH264_RATECONTROLPARAMS_EXISTING, "Existing rate control params",
170           "rate-control-params-preset-existing"},
171       {IH264_RATECONTROLPARAMS_MAX, "Max rate control",
172           "rate-control-params-preset-control"},
173       {0, NULL, NULL},
174     };
176     type = g_enum_register_static ("GstDucatiH264EncRateControlParams", vals);
177   }
179   return type;
182 static GType
183 gst_ducati_h264enc_get_rate_control_algo_type (void)
185   static GType type = 0;
187   if (!type) {
188     static const GEnumValue vals[] = {
189       {IH264_RATECONTROL_PRC, "Perceptual rate control",
190           "perceptual-rate-control"},
191       {IH264_RATECONTROL_PRC_LOW_DELAY, "Low delay rate control",
192           "low-delay-rate-control"},
193       {IH264_RATECONTROL_DEFAULT, "Default rcAlgo (PRC)",
194           "default-rate-control"},
195       {0, NULL, NULL},
196     };
198     type = g_enum_register_static ("GstDucatiH264EncRateControlAlgo", vals);
199   }
201   return type;
204 static GType
205 gst_ducati_h264enc_level_get_type (void)
207   static GType type = 0;
209   if (!type) {
210     static const GEnumValue vals[] = {
211       {GST_DUCATI_H264ENC_LEVEL_10, "Level 1", "level-1"},
212       {GST_DUCATI_H264ENC_LEVEL_1b, "Level 1b", "level-1b"},
213       {GST_DUCATI_H264ENC_LEVEL_11, "Level 11", "level-11"},
214       {GST_DUCATI_H264ENC_LEVEL_12, "Level 12", "level-12"},
215       {GST_DUCATI_H264ENC_LEVEL_13, "Level 13", "level-13"},
216       {GST_DUCATI_H264ENC_LEVEL_20, "Level 2", "level-2"},
217       {GST_DUCATI_H264ENC_LEVEL_21, "Level 21", "level-21"},
218       {GST_DUCATI_H264ENC_LEVEL_22, "Level 22", "level-22"},
219       {GST_DUCATI_H264ENC_LEVEL_30, "Level 3", "level-3"},
220       {GST_DUCATI_H264ENC_LEVEL_31, "Level 31", "level-31"},
221       {GST_DUCATI_H264ENC_LEVEL_32, "Level 32", "level-32"},
222       {GST_DUCATI_H264ENC_LEVEL_40, "Level 4", "level-4"},
223       {GST_DUCATI_H264ENC_LEVEL_41, "Level 41", "level-41"},
224       {GST_DUCATI_H264ENC_LEVEL_42, "Level 42", "level-42"},
225       {GST_DUCATI_H264ENC_LEVEL_50, "Level 5", "level-5"},
226       {GST_DUCATI_H264ENC_LEVEL_51, "Level 51", "level-51"},
227       {0, NULL, NULL},
228     };
230     type = g_enum_register_static ("GstDucatiH264EncLevel", vals);
231   }
233   return type;
236 static GType
237 gst_ducati_h264enc_get_entropy_coding_mode_type (void)
239   static GType type = 0;
241   if (!type) {
242     static const GEnumValue vals[] = {
243       {IH264_ENTROPYCODING_CAVLC, "CAVLC coding type", "cavlc"},
244       {IH264_ENTROPYCODING_DEFAULT, "Default coding type (cavlc)", "default"},
245       {IH264_ENTROPYCODING_CABAC, "Cabac coding mode", "cabac"},
246       {0, NULL, NULL},
247     };
249     type = g_enum_register_static ("GstDucatiEntropyCodingMode", vals);
250   }
252   return type;
255 static GType
256 gst_ducati_h264enc_get_slice_mode_type (void)
258   static GType type = 0;
260   if (!type) {
261     static const GEnumValue vals[] = {
262       {IH264_SLICEMODE_NONE, "No slice mode", "none"},
263       {IH264_SLICEMODE_DEFAULT, "Default slice coding mode is MB based",
264           "default"},
265       {IH264_SLICEMODE_MBUNIT,
266           "Slices are controlled based upon number of Macroblocks", "mbunit"},
267       {IH264_SLICEMODE_BYTES,
268           "Slices are controlled based upon number of bytes", "bytes"},
269       {IH264_SLICEMODE_OFFSET,
270             "Slices are controlled based upon user defined offset unit of Row",
271           "offset"},
272       {0, NULL, NULL},
273     };
275     type = g_enum_register_static ("GstDucatiSliceMode", vals);
276   }
278   return type;
281 static void
282 gst_ducati_h264enc_base_init (gpointer g_class)
285   GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
287   gst_element_class_add_pad_template (element_class,
288       gst_static_pad_template_get (&gst_ducati_h264enc_src_template));
289   gst_element_class_add_pad_template (element_class,
290       gst_static_pad_template_get (&gst_ducati_h264enc_sink_template));
292   gst_element_class_set_details_simple (element_class, "H264 Encoder",
293       "Codec/Encoder/Video",
294       "Encode raw video into H264 stream",
295       "Alessandro Decina <alessandro.decina@collabora.com>");
297   GST_DUCATIVIDENC_CLASS (element_class)->codec_name = "ivahd_h264enc";
300 static void
301 gst_ducati_h264enc_class_init (GstDucatiH264EncClass * klass)
303   GObjectClass *gobject_class;
304   GstDucatiVidEncClass *videnc_class;
306   gobject_class = G_OBJECT_CLASS (klass);
307   videnc_class = GST_DUCATIVIDENC_CLASS (klass);
309   gobject_class->set_property = gst_ducati_h264enc_set_property;
310   gobject_class->get_property = gst_ducati_h264enc_get_property;
312   videnc_class->allocate_params = gst_ducati_h264enc_allocate_params;
313   videnc_class->configure = gst_ducati_h264enc_configure;
314   videnc_class->is_sync_point = gst_ducati_h264enc_is_sync_point;
316   g_object_class_install_property (gobject_class, PROP_PROFILE,
317       g_param_spec_enum ("profile", "H.264 Profile", "H.264 Profile",
318           GST_TYPE_DUCATI_H264ENC_PROFILE, DEFAULT_PROFILE, G_PARAM_READWRITE));
320   g_object_class_install_property (gobject_class, PROP_LEVEL,
321       g_param_spec_enum ("level", "H.264 Level", "H.264 Level",
322           GST_TYPE_DUCATI_H264ENC_LEVEL, DEFAULT_LEVEL, G_PARAM_READWRITE));
324   g_object_class_install_property (gobject_class,
325       PROP_RATE_CONTROL_PARAMS_PRESET,
326       g_param_spec_enum ("rate-control-params-preset",
327           "H.264 rate control params preset",
328           "This preset controls the USER_DEFINED versus "
329           "DEFAULT mode. If you are not aware about the "
330           "fields, it should be set as IH264_RATECONTROLPARAMS_DEFAULT",
331           GST_TYPE_DUCATI_H264ENC_RCPP, IH264_RATECONTROLPARAMS_DEFAULT,
332           G_PARAM_READWRITE));
334   g_object_class_install_property (gobject_class, PROP_RATE_CONTROL_ALGO,
335       g_param_spec_enum ("rate-control-algo", "H.264 rate control algorithm",
336           "This defines the rate control algorithm to be used. Only useful if "
337           " 'rate-control-params-preset' is set as "
338           "'rate-control-params-preset-user-defined'",
339           GST_TYPE_DUCATI_H264ENC_RATE_CONTROL_ALGO, IH264_RATECONTROL_DEFAULT,
340           G_PARAM_READWRITE));
342   g_object_class_install_property (gobject_class, PROP_QPI,
343       g_param_spec_int ("qpi", "Initial quantization parameter",
344           "Initial quantization parameter for I/IDR frames.", -1, 51,
345           DEFAULT_QPI, G_PARAM_READWRITE));
347   g_object_class_install_property (gobject_class, PROP_QP_MIN_I,
348       g_param_spec_int ("qp-min-i", "Minimum quantization parameter",
349           "Minimum quantization parameter for I/IDR frames.", 0, 51,
350           DEFAULT_QP_MIN_I, G_PARAM_READWRITE));
352   g_object_class_install_property (gobject_class, PROP_QP_MAX_I,
353       g_param_spec_int ("qp-max-i", "Maximum quantization parameter",
354           "Maximum quantization parameter for I/IDR frames.", 0, 51,
355           DEFAULT_QP_MAX_I, G_PARAM_READWRITE));
357   g_object_class_install_property (gobject_class, PROP_HRD_BUFFER_SIZE,
358       g_param_spec_uint ("hrd-buffer-size",
359           "Hypothetical reference decoder buffer size",
360           "Hypothetical reference decoder buffer size. This "
361           "size controls the frame skip logic of the encoder. "
362           "For low delay applications this size should be "
363           "small. This size is in bits. Maximum Value is level "
364           "dependant and min value is 4096",
365           4096, G_MAXUINT, DEFAULT_HRD_BUFFER_SIZE, G_PARAM_READWRITE));
367   g_object_class_install_property (gobject_class, PROP_ENTROPY_CODING_MODE,
368       g_param_spec_enum ("entropy-coding-mode", "H.264 entropy coding mode",
369           "Controls the entropy coding type.",
370           GST_TYPE_DUCATI_H264ENC_ENTROPY_CODING_MODE,
371           IH264_ENTROPYCODING_DEFAULT, G_PARAM_READWRITE));
373   g_object_class_install_property (gobject_class, PROP_SLICE_MODE,
374       g_param_spec_enum ("slice-mode", "H.264 slice mode",
375           "This defines the control mechanism to split a picture in slices."
376           " It can be either MB based or bytes based",
377           GST_TYPE_DUCATI_H264ENC_SLICE_MODE,
378           IH264_SLICEMODE_DEFAULT, G_PARAM_READWRITE));
382 static void
383 gst_ducati_h264enc_init (GstDucatiH264Enc * self, GstDucatiH264EncClass * klass)
385   GST_DEBUG ("gst_ducati_h264enc_init");
387   self->profile = DEFAULT_PROFILE;
388   self->level = DEFAULT_LEVEL;
389   self->rate_control_params_preset = IH264_RATECONTROLPARAMS_DEFAULT;
390   self->rate_control_algo = IH264_RATECONTROL_DEFAULT;
391   self->qpi = DEFAULT_QPI;
392   self->qp_min_i = DEFAULT_QP_MIN_I;
393   self->qp_max_i = DEFAULT_QP_MAX_I;
394   self->hrd_buffer_size = DEFAULT_HRD_BUFFER_SIZE;
397 static void
398 gst_ducati_h264enc_set_property (GObject * object, guint prop_id,
399     const GValue * value, GParamSpec * pspec)
401   GstDucatiH264Enc *self = GST_DUCATIH264ENC (object);
402   GstDucatiVidEnc *venc = GST_DUCATIVIDENC (object);
403   IH264ENC_DynamicParams *dynParams =
404       (IH264ENC_DynamicParams *) venc->dynParams;
406   self = GST_DUCATIH264ENC (object);
408   switch (prop_id) {
409     case PROP_PROFILE:
410       self->profile = g_value_get_enum (value);
411       break;
412     case PROP_LEVEL:
413       self->level = g_value_get_enum (value);
414       break;
415     case PROP_RATE_CONTROL_PARAMS_PRESET:
416       self->rate_control_params_preset = g_value_get_enum (value);
417       if (dynParams)
418         dynParams->rateControlParams.rateControlParamsPreset =
419             self->rate_control_params_preset;
420       break;
421     case PROP_RATE_CONTROL_ALGO:
422       self->rate_control_algo = g_value_get_enum (value);
424       if (self->rate_control_params_preset !=
425           IH264_RATECONTROLPARAMS_USERDEFINED)
426         GST_INFO_OBJECT (self,
427             "Setting rcAlgo but rateControlParamsPreset not "
428             "'rate-control-params-preset-user-defined' config won't be taken "
429             "into account");
431       if (dynParams)
432         dynParams->rateControlParams.rcAlgo = self->rate_control_algo;
433       break;
434     case PROP_QPI:
435       self->qpi = g_value_get_int (value);
436       if (dynParams)
437         dynParams->rateControlParams.qpI = self->qpi;
439       break;
440     case PROP_QP_MIN_I:
441       self->qp_min_i = g_value_get_int (value);
442       if (dynParams)
443         dynParams->rateControlParams.qpMinI = self->qp_min_i;
444       break;
445     case PROP_QP_MAX_I:
446       self->qp_max_i = g_value_get_int (value);
447       if (dynParams)
448         dynParams->rateControlParams.qpMaxI = self->qp_max_i;
449       break;
450     case PROP_HRD_BUFFER_SIZE:
451       self->hrd_buffer_size = g_value_get_uint (value);
452       break;
453     case PROP_ENTROPY_CODING_MODE:
454       self->entropy_coding_mode = g_value_get_enum (value);
455       break;
456     case PROP_SLICE_MODE:
457       self->slice_mode = g_value_get_enum (value);
458       break;
459     default:
460       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
461   }
464 static void
465 gst_ducati_h264enc_get_property (GObject * object, guint prop_id,
466     GValue * value, GParamSpec * pspec)
468   GstDucatiH264Enc *self = GST_DUCATIH264ENC (object);
470   g_return_if_fail (GST_IS_DUCATIH264ENC (object));
471   self = GST_DUCATIH264ENC (object);
473   switch (prop_id) {
474     case PROP_PROFILE:
475       g_value_set_enum (value, self->profile);
476       break;
477     case PROP_LEVEL:
478       g_value_set_enum (value, self->level);
479       break;
480     case PROP_RATE_CONTROL_PARAMS_PRESET:
481       g_value_set_enum (value, self->rate_control_params_preset);
482       break;
483     case PROP_RATE_CONTROL_ALGO:
484       g_value_set_enum (value, self->rate_control_algo);
485       break;
486     case PROP_QPI:
487       g_value_set_int (value, self->qpi);
488       break;
489     case PROP_QP_MIN_I:
490       g_value_set_int (value, self->qp_min_i);
491       break;
492     case PROP_QP_MAX_I:
493       g_value_set_int (value, self->qp_max_i);
494       break;
495     case PROP_HRD_BUFFER_SIZE:
496       g_value_set_uint (value, self->hrd_buffer_size);
497       break;
498     case PROP_ENTROPY_CODING_MODE:
499       g_value_set_enum (value, self->entropy_coding_mode);
500       break;
501     case PROP_SLICE_MODE:
502       g_value_set_enum (value, self->slice_mode);
503       break;
504     default:
505       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
506   }
509 static const char *
510 get_profile_name (guint profile)
512   switch (profile) {
513     case GST_DUCATI_H264ENC_PROFILE_BASELINE:
514       return "baseline";
515     case GST_DUCATI_H264ENC_PROFILE_MAIN:
516       return "main";
517     case GST_DUCATI_H264ENC_PROFILE_EXTENDED:
518       return "extended";
519     case GST_DUCATI_H264ENC_PROFILE_HIGH:
520       return "high";
521     case GST_DUCATI_H264ENC_PROFILE_HIGH_10:
522       return "high-10";
523     case GST_DUCATI_H264ENC_PROFILE_HIGH_422:
524       return "high-422";
525     default:
526       return NULL;
527   }
530 static const char *
531 get_level_name (guint level)
533   switch (level) {
534     case GST_DUCATI_H264ENC_LEVEL_10:
535       return "1";
536     case GST_DUCATI_H264ENC_LEVEL_1b:
537       return "1b";
538     case GST_DUCATI_H264ENC_LEVEL_11:
539       return "1.1";
540     case GST_DUCATI_H264ENC_LEVEL_12:
541       return "1.2";
542     case GST_DUCATI_H264ENC_LEVEL_13:
543       return "1.3";
544     case GST_DUCATI_H264ENC_LEVEL_20:
545       return "2";
546     case GST_DUCATI_H264ENC_LEVEL_21:
547       return "2.1";
548     case GST_DUCATI_H264ENC_LEVEL_22:
549       return "2.2";
550     case GST_DUCATI_H264ENC_LEVEL_30:
551       return "3";
552     case GST_DUCATI_H264ENC_LEVEL_31:
553       return "3.1";
554     case GST_DUCATI_H264ENC_LEVEL_32:
555       return "3.2";
556     case GST_DUCATI_H264ENC_LEVEL_40:
557       return "4";
558     case GST_DUCATI_H264ENC_LEVEL_41:
559       return "4.1";
560     case GST_DUCATI_H264ENC_LEVEL_42:
561       return "4.2";
562     case GST_DUCATI_H264ENC_LEVEL_50:
563       return "5";
564     case GST_DUCATI_H264ENC_LEVEL_51:
565       return "5.1";
566     default:
567       return NULL;
568   }
571 static gboolean
572 gst_ducati_h264enc_configure (GstDucatiVidEnc * videnc)
574   GstDucatiH264Enc *self = GST_DUCATIH264ENC (videnc);
575   IH264ENC_Params *params;
576   IH264ENC_DynamicParams *dynParams;
577   gboolean ret;
578   const char *s;
580   videnc->params->profile = self->profile;
581   videnc->params->level = self->level;
583   params = (IH264ENC_Params *) videnc->params;
584   /* this is the only non-base field strictly required */
585   params->maxIntraFrameInterval = 0x7fffffff;
586   params->IDRFrameInterval = 1;
587   params->numTemporalLayer = 1;
588   params->entropyCodingMode = self->entropy_coding_mode;
590   /* Dynamic params */
591   dynParams = (IH264ENC_DynamicParams *) videnc->dynParams;
592   dynParams->rateControlParams.rateControlParamsPreset =
593       self->rate_control_params_preset;
594   dynParams->rateControlParams.rcAlgo = self->rate_control_algo;
595   dynParams->rateControlParams.qpI = self->qpi;
596   dynParams->rateControlParams.qpMaxI = self->qp_max_i;
597   dynParams->rateControlParams.qpMinI = self->qp_min_i;
598   dynParams->rateControlParams.HRDBufferSize = self->hrd_buffer_size;
599   dynParams->sliceCodingParams.sliceMode = self->slice_mode;
601   ret = GST_DUCATIVIDENC_CLASS (parent_class)->configure (videnc);
602   if (ret) {
603     const GstVideoState *state =
604         gst_base_video_encoder_get_state (GST_BASE_VIDEO_ENCODER (videnc));
605     GstCaps *caps = gst_caps_new_simple ("video/x-h264",
606         "width", G_TYPE_INT, videnc->rect.w,
607         "height", G_TYPE_INT, videnc->rect.h,
608         "framerate", GST_TYPE_FRACTION, state->fps_n, state->fps_d,
609         "pixel-aspect-ratio", GST_TYPE_FRACTION, state->par_n, state->par_d,
610         "stream-format", G_TYPE_STRING, "byte-stream",
611         "align", G_TYPE_STRING, "au",
612         NULL);
613     s = get_profile_name (self->profile);
614     if (s)
615       gst_caps_set_simple (caps, "profile", G_TYPE_STRING, s, NULL);
616     s = get_level_name (self->level);
617     if (s)
618       gst_caps_set_simple (caps, "level", G_TYPE_STRING, s, NULL);
619     ret = gst_pad_set_caps (GST_BASE_VIDEO_CODEC_SRC_PAD (self), caps);
620   }
622   return ret;
625 static gboolean
626 gst_ducati_h264enc_allocate_params (GstDucatiVidEnc *
627     videnc, gint params_sz, gint dynparams_sz, gint status_sz, gint inargs_sz,
628     gint outargs_sz)
630   gboolean ret = GST_DUCATIVIDENC_CLASS (parent_class)->allocate_params (videnc,
631       sizeof (IH264ENC_Params), sizeof (IH264ENC_DynamicParams),
632       sizeof (IVIDENC2_Status), sizeof (IVIDENC2_InArgs),
633       sizeof (IVIDENC2_OutArgs));
635   GstDucatiH264Enc *self = GST_DUCATIH264ENC (videnc);
637   if (ret == TRUE) {
638     IH264ENC_DynamicParams *dynParams =
639         (IH264ENC_DynamicParams *) videnc->dynParams;
641     dynParams->rateControlParams.rateControlParamsPreset =
642         self->rate_control_params_preset;
643     dynParams->rateControlParams.rcAlgo = self->rate_control_algo;
644     dynParams->rateControlParams.qpI = self->qpi;
645     dynParams->rateControlParams.qpMaxI = self->qp_max_i;
646     dynParams->rateControlParams.qpMinI = self->qp_min_i;
647     dynParams->rateControlParams.HRDBufferSize = self->hrd_buffer_size;
648     dynParams->sliceCodingParams.sliceMode = self->slice_mode;
649   }
651   return ret;
654 static gboolean
655 gst_ducati_h264enc_is_sync_point (GstDucatiVidEnc * enc, int type)
657   return type == IVIDEO_IDR_FRAME;