bc0fd316169e981f37310a09edc5d4f01cd46435
[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);
83 static GstStaticPadTemplate gst_ducati_h264enc_sink_template =
84 GST_STATIC_PAD_TEMPLATE ("sink",
85     GST_PAD_SINK,
86     GST_PAD_ALWAYS,
87     GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("NV12"))
88     );
90 static GstStaticPadTemplate gst_ducati_h264enc_src_template =
91 GST_STATIC_PAD_TEMPLATE ("src",
92     GST_PAD_SRC,
93     GST_PAD_ALWAYS,
94     GST_STATIC_CAPS
95     ("video/x-h264, alignment=(string)au, stream-format=(string)byte-stream")
96     );
98 GST_BOILERPLATE (GstDucatiH264Enc, gst_ducati_h264enc, GstDucatiVidEnc,
99     GST_TYPE_DUCATIVIDENC);
102 /* the values for the following enums are taken from the codec */
104 enum
106   GST_DUCATI_H264ENC_PROFILE_BASELINE = 66,            /**< BaseLine Profile   */
107   GST_DUCATI_H264ENC_PROFILE_MAIN = 77,                /**< Main Profile       */
108   GST_DUCATI_H264ENC_PROFILE_EXTENDED = 88,            /**< Extended Profile   */
109   GST_DUCATI_H264ENC_PROFILE_HIGH = 100,               /**< High Profile       */
110   GST_DUCATI_H264ENC_PROFILE_HIGH_10 = 110,             /**< High 10 Profile    */
111   GST_DUCATI_H264ENC_PROFILE_HIGH_422 = 122             /**< High 4:2:2 Profile */
112 };
114 enum
116   GST_DUCATI_H264ENC_LEVEL_10 = 10, /**<  Level 1.0  */
117   GST_DUCATI_H264ENC_LEVEL_1b = 9,  /**<  Level 1.b  */
118   GST_DUCATI_H264ENC_LEVEL_11 = 11, /**<  Level 1.1  */
119   GST_DUCATI_H264ENC_LEVEL_12 = 12, /**<  Level 1.2  */
120   GST_DUCATI_H264ENC_LEVEL_13 = 13, /**<  Level 1.3  */
121   GST_DUCATI_H264ENC_LEVEL_20 = 20, /**<  Level 2.0  */
122   GST_DUCATI_H264ENC_LEVEL_21 = 21, /**<  Level 2.1  */
123   GST_DUCATI_H264ENC_LEVEL_22 = 22, /**<  Level 2.2  */
124   GST_DUCATI_H264ENC_LEVEL_30 = 30, /**<  Level 3.0  */
125   GST_DUCATI_H264ENC_LEVEL_31 = 31, /**<  Level 3.1  */
126   GST_DUCATI_H264ENC_LEVEL_32 = 32, /**<  Level 3.2  */
127   GST_DUCATI_H264ENC_LEVEL_40 = 40, /**<  Level 4.0  */
128   GST_DUCATI_H264ENC_LEVEL_41 = 41, /**<  Level 4.1  */
129   GST_DUCATI_H264ENC_LEVEL_42 = 42, /**<  Level 4.2  */
130   GST_DUCATI_H264ENC_LEVEL_50 = 50, /**<  Level 5.0  */
131   GST_DUCATI_H264ENC_LEVEL_51 = 51 /**<  Level 5.1  */
132 };
134 static GType
135 gst_ducati_h264enc_profile_get_type (void)
137   static GType type = 0;
139   if (!type) {
140     static const GEnumValue vals[] = {
141       {GST_DUCATI_H264ENC_PROFILE_BASELINE, "Base Profile", "baseline"},
142       {GST_DUCATI_H264ENC_PROFILE_MAIN, "Main Profile", "main"},
143       {GST_DUCATI_H264ENC_PROFILE_EXTENDED, "Extended Profile", "extended"},
144       {GST_DUCATI_H264ENC_PROFILE_HIGH, "High Profile", "high"},
145       {GST_DUCATI_H264ENC_PROFILE_HIGH_10, "High 10 Profile", "high-10"},
146       {GST_DUCATI_H264ENC_PROFILE_HIGH_422, "High 4:2:2 Profile", "high-422"},
147       {0, NULL, NULL},
148     };
150     type = g_enum_register_static ("GstDucatiH264EncProfile", vals);
151   }
153   return type;
156 static GType
157 gst_ducati_h264enc_get_rate_control_params_preset_type (void)
159   static GType type = 0;
161   if (!type) {
162     static const GEnumValue vals[] = {
163       {IH264_RATECONTROLPARAMS_DEFAULT, "Rate Control params preset default",
164           "rate-control-params-preset-default"},
165       {IH264_RATECONTROLPARAMS_USERDEFINED, "User defined rate control",
166           "rate-control-params-preset-user-defined"},
167       {IH264_RATECONTROLPARAMS_EXISTING, "Existing rate control params",
168           "rate-control-params-preset-existing"},
169       {IH264_RATECONTROLPARAMS_MAX, "Max rate control",
170           "rate-control-params-preset-control"},
171       {0, NULL, NULL},
172     };
174     type = g_enum_register_static ("GstDucatiH264EncRateControlParams", vals);
175   }
177   return type;
180 static GType
181 gst_ducati_h264enc_get_rate_control_algo_type (void)
183   static GType type = 0;
185   if (!type) {
186     static const GEnumValue vals[] = {
187       {IH264_RATECONTROL_PRC, "Perceptual rate control",
188           "perceptual-rate-control"},
189       {IH264_RATECONTROL_PRC_LOW_DELAY, "Low delay rate control",
190           "low-delay-rate-control"},
191       {IH264_RATECONTROL_DEFAULT, "Default rcAlgo (PRC)",
192           "default-rate-control"},
193       {0, NULL, NULL},
194     };
196     type = g_enum_register_static ("GstDucatiH264EncRateControlAlgo", vals);
197   }
199   return type;
202 static GType
203 gst_ducati_h264enc_level_get_type (void)
205   static GType type = 0;
207   if (!type) {
208     static const GEnumValue vals[] = {
209       {GST_DUCATI_H264ENC_LEVEL_10, "Level 1", "level-1"},
210       {GST_DUCATI_H264ENC_LEVEL_1b, "Level 1b", "level-1b"},
211       {GST_DUCATI_H264ENC_LEVEL_11, "Level 11", "level-11"},
212       {GST_DUCATI_H264ENC_LEVEL_12, "Level 12", "level-12"},
213       {GST_DUCATI_H264ENC_LEVEL_13, "Level 13", "level-13"},
214       {GST_DUCATI_H264ENC_LEVEL_20, "Level 2", "level-2"},
215       {GST_DUCATI_H264ENC_LEVEL_21, "Level 21", "level-21"},
216       {GST_DUCATI_H264ENC_LEVEL_22, "Level 22", "level-22"},
217       {GST_DUCATI_H264ENC_LEVEL_30, "Level 3", "level-3"},
218       {GST_DUCATI_H264ENC_LEVEL_31, "Level 31", "level-31"},
219       {GST_DUCATI_H264ENC_LEVEL_32, "Level 32", "level-32"},
220       {GST_DUCATI_H264ENC_LEVEL_40, "Level 4", "level-4"},
221       {GST_DUCATI_H264ENC_LEVEL_41, "Level 41", "level-41"},
222       {GST_DUCATI_H264ENC_LEVEL_42, "Level 42", "level-42"},
223       {GST_DUCATI_H264ENC_LEVEL_50, "Level 5", "level-5"},
224       {GST_DUCATI_H264ENC_LEVEL_51, "Level 51", "level-51"},
225       {0, NULL, NULL},
226     };
228     type = g_enum_register_static ("GstDucatiH264EncLevel", vals);
229   }
231   return type;
234 static GType
235 gst_ducati_h264enc_get_entropy_coding_mode_type (void)
237   static GType type = 0;
239   if (!type) {
240     static const GEnumValue vals[] = {
241       {IH264_ENTROPYCODING_CAVLC, "CAVLC coding type", "cavlc"},
242       {IH264_ENTROPYCODING_DEFAULT, "Default coding type (cavlc)", "default"},
243       {IH264_ENTROPYCODING_CABAC, "Cabac coding mode", "cabac"},
244       {0, NULL, NULL},
245     };
247     type = g_enum_register_static ("GstDucatiEntropyCodingMode", vals);
248   }
250   return type;
253 static GType
254 gst_ducati_h264enc_get_slice_mode_type (void)
256   static GType type = 0;
258   if (!type) {
259     static const GEnumValue vals[] = {
260       {IH264_SLICEMODE_NONE, "No slice mode", "none"},
261       {IH264_SLICEMODE_DEFAULT, "Default slice coding mode is MB based",
262           "default"},
263       {IH264_SLICEMODE_MBUNIT,
264           "Slices are controlled based upon number of Macroblocks", "mbunit"},
265       {IH264_SLICEMODE_BYTES,
266           "Slices are controlled based upon number of bytes", "bytes"},
267       {IH264_SLICEMODE_OFFSET,
268             "Slices are controlled based upon user defined offset unit of Row",
269           "offset"},
270       {0, NULL, NULL},
271     };
273     type = g_enum_register_static ("GstDucatiSliceMode", vals);
274   }
276   return type;
279 static void
280 gst_ducati_h264enc_base_init (gpointer g_class)
283   GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
285   gst_element_class_add_pad_template (element_class,
286       gst_static_pad_template_get (&gst_ducati_h264enc_src_template));
287   gst_element_class_add_pad_template (element_class,
288       gst_static_pad_template_get (&gst_ducati_h264enc_sink_template));
290   gst_element_class_set_details_simple (element_class, "H264 Encoder",
291       "Codec/Encoder/Video",
292       "Encode raw video into H264 stream",
293       "Alessandro Decina <alessandro.decina@collabora.com>");
295   GST_DUCATIVIDENC_CLASS (element_class)->codec_name = "ivahd_h264enc";
298 static void
299 gst_ducati_h264enc_class_init (GstDucatiH264EncClass * klass)
301   GObjectClass *gobject_class;
302   GstDucatiVidEncClass *videnc_class;
304   gobject_class = G_OBJECT_CLASS (klass);
305   videnc_class = GST_DUCATIVIDENC_CLASS (klass);
307   gobject_class->set_property = gst_ducati_h264enc_set_property;
308   gobject_class->get_property = gst_ducati_h264enc_get_property;
310   videnc_class->allocate_params = gst_ducati_h264enc_allocate_params;
311   videnc_class->configure = gst_ducati_h264enc_configure;
313   g_object_class_install_property (gobject_class, PROP_PROFILE,
314       g_param_spec_enum ("profile", "H.264 Profile", "H.264 Profile",
315           GST_TYPE_DUCATI_H264ENC_PROFILE, DEFAULT_PROFILE, G_PARAM_READWRITE));
317   g_object_class_install_property (gobject_class, PROP_LEVEL,
318       g_param_spec_enum ("level", "H.264 Level", "H.264 Level",
319           GST_TYPE_DUCATI_H264ENC_LEVEL, DEFAULT_LEVEL, G_PARAM_READWRITE));
321   g_object_class_install_property (gobject_class,
322       PROP_RATE_CONTROL_PARAMS_PRESET,
323       g_param_spec_enum ("rate-control-params-preset",
324           "H.264 rate control params preset",
325           "This preset controls the USER_DEFINED versus "
326           "DEFAULT mode. If you are not aware about the "
327           "fields, it should be set as IH264_RATECONTROLPARAMS_DEFAULT",
328           GST_TYPE_DUCATI_H264ENC_RCPP, IH264_RATECONTROLPARAMS_DEFAULT,
329           G_PARAM_READWRITE));
331   g_object_class_install_property (gobject_class, PROP_RATE_CONTROL_ALGO,
332       g_param_spec_enum ("rate-control-algo", "H.264 rate control algorithm",
333           "This defines the rate control algorithm to be used. Only useful if "
334           " 'rate-control-params-preset' is set as "
335           "'rate-control-params-preset-user-defined'",
336           GST_TYPE_DUCATI_H264ENC_RATE_CONTROL_ALGO, IH264_RATECONTROL_DEFAULT,
337           G_PARAM_READWRITE));
339   g_object_class_install_property (gobject_class, PROP_QPI,
340       g_param_spec_int ("qpi", "Initial quantization parameter",
341           "Initial quantization parameter for I/IDR frames.", -1, 51,
342           DEFAULT_QPI, G_PARAM_READWRITE));
344   g_object_class_install_property (gobject_class, PROP_QP_MIN_I,
345       g_param_spec_int ("qp-min-i", "Minimum quantization parameter",
346           "Minimum quantization parameter for I/IDR frames.", 0, 51,
347           DEFAULT_QP_MIN_I, G_PARAM_READWRITE));
349   g_object_class_install_property (gobject_class, PROP_QP_MAX_I,
350       g_param_spec_int ("qp-max-i", "Maximum quantization parameter",
351           "Maximum quantization parameter for I/IDR frames.", 0, 51,
352           DEFAULT_QP_MAX_I, G_PARAM_READWRITE));
354   g_object_class_install_property (gobject_class, PROP_HRD_BUFFER_SIZE,
355       g_param_spec_uint ("hrd-buffer-size",
356           "Hypothetical reference decoder buffer size",
357           "Hypothetical reference decoder buffer size. This "
358           "size controls the frame skip logic of the encoder. "
359           "For low delay applications this size should be "
360           "small. This size is in bits. Maximum Value is level "
361           "dependant and min value is 4096",
362           4096, G_MAXUINT, DEFAULT_HRD_BUFFER_SIZE, G_PARAM_READWRITE));
364   g_object_class_install_property (gobject_class, PROP_ENTROPY_CODING_MODE,
365       g_param_spec_enum ("entropy-coding-mode", "H.264 entropy coding mode",
366           "Controls the entropy coding type.",
367           GST_TYPE_DUCATI_H264ENC_ENTROPY_CODING_MODE,
368           IH264_ENTROPYCODING_DEFAULT, G_PARAM_READWRITE));
370   g_object_class_install_property (gobject_class, PROP_SLICE_MODE,
371       g_param_spec_enum ("slice-mode", "H.264 slice mode",
372           "This defines the control mechanism to split a picture in slices."
373           " It can be either MB based or bytes based",
374           GST_TYPE_DUCATI_H264ENC_SLICE_MODE,
375           IH264_SLICEMODE_DEFAULT, G_PARAM_READWRITE));
379 static void
380 gst_ducati_h264enc_init (GstDucatiH264Enc * self, GstDucatiH264EncClass * klass)
382   GST_DEBUG ("gst_ducati_h264enc_init");
384   self->profile = DEFAULT_PROFILE;
385   self->level = DEFAULT_LEVEL;
386   self->rate_control_params_preset = IH264_RATECONTROLPARAMS_DEFAULT;
387   self->rate_control_algo = IH264_RATECONTROL_DEFAULT;
388   self->qpi = DEFAULT_QPI;
389   self->qp_min_i = DEFAULT_QP_MIN_I;
390   self->qp_max_i = DEFAULT_QP_MAX_I;
391   self->hrd_buffer_size = DEFAULT_HRD_BUFFER_SIZE;
394 static void
395 gst_ducati_h264enc_set_property (GObject * object, guint prop_id,
396     const GValue * value, GParamSpec * pspec)
398   GstDucatiH264Enc *self = GST_DUCATIH264ENC (object);
399   GstDucatiVidEnc *venc = GST_DUCATIVIDENC (object);
400   IH264ENC_DynamicParams *dynParams =
401       (IH264ENC_DynamicParams *) venc->dynParams;
403   self = GST_DUCATIH264ENC (object);
405   switch (prop_id) {
406     case PROP_PROFILE:
407       self->profile = g_value_get_enum (value);
408       break;
409     case PROP_LEVEL:
410       self->level = g_value_get_enum (value);
411       break;
412     case PROP_RATE_CONTROL_PARAMS_PRESET:
413       self->rate_control_params_preset = g_value_get_enum (value);
414       if (dynParams)
415         dynParams->rateControlParams.rateControlParamsPreset =
416             self->rate_control_params_preset;
417       break;
418     case PROP_RATE_CONTROL_ALGO:
419       self->rate_control_algo = g_value_get_enum (value);
421       if (self->rate_control_params_preset !=
422           IH264_RATECONTROLPARAMS_USERDEFINED)
423         GST_INFO_OBJECT (self,
424             "Setting rcAlgo but rateControlParamsPreset not "
425             "'rate-control-params-preset-user-defined' config won't be taken "
426             "into account");
428       if (dynParams)
429         dynParams->rateControlParams.rcAlgo = self->rate_control_algo;
430       break;
431     case PROP_QPI:
432       self->qpi = g_value_get_int (value);
433       if (dynParams)
434         dynParams->rateControlParams.qpI = self->qpi;
436       break;
437     case PROP_QP_MIN_I:
438       self->qp_min_i = g_value_get_int (value);
439       if (dynParams)
440         dynParams->rateControlParams.qpMinI = self->qp_min_i;
441       break;
442     case PROP_QP_MAX_I:
443       self->qp_max_i = g_value_get_int (value);
444       if (dynParams)
445         dynParams->rateControlParams.qpMaxI = self->qp_max_i;
446       break;
447     case PROP_HRD_BUFFER_SIZE:
448       self->hrd_buffer_size = g_value_get_uint (value);
449       break;
450     case PROP_ENTROPY_CODING_MODE:
451       self->entropy_coding_mode = g_value_get_enum (value);
452       break;
453     case PROP_SLICE_MODE:
454       self->slice_mode = g_value_get_enum (value);
455       break;
456     default:
457       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
458   }
461 static void
462 gst_ducati_h264enc_get_property (GObject * object, guint prop_id,
463     GValue * value, GParamSpec * pspec)
465   GstDucatiH264Enc *self = GST_DUCATIH264ENC (object);
467   g_return_if_fail (GST_IS_DUCATIH264ENC (object));
468   self = GST_DUCATIH264ENC (object);
470   switch (prop_id) {
471     case PROP_PROFILE:
472       g_value_set_enum (value, self->profile);
473       break;
474     case PROP_LEVEL:
475       g_value_set_enum (value, self->level);
476       break;
477     case PROP_RATE_CONTROL_PARAMS_PRESET:
478       g_value_set_enum (value, self->rate_control_params_preset);
479       break;
480     case PROP_RATE_CONTROL_ALGO:
481       g_value_set_enum (value, self->rate_control_algo);
482       break;
483     case PROP_QPI:
484       g_value_set_int (value, self->qpi);
485       break;
486     case PROP_QP_MIN_I:
487       g_value_set_int (value, self->qp_min_i);
488       break;
489     case PROP_QP_MAX_I:
490       g_value_set_int (value, self->qp_max_i);
491       break;
492     case PROP_HRD_BUFFER_SIZE:
493       g_value_set_int (value, self->hrd_buffer_size);
494       break;
495     case PROP_ENTROPY_CODING_MODE:
496       g_value_set_enum (value, self->entropy_coding_mode);
497       break;
498     case PROP_SLICE_MODE:
499       g_value_set_enum (value, self->slice_mode);
500       break;
501     default:
502       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
503   }
506 static const char *
507 get_profile_name (guint profile)
509   switch (profile) {
510     case GST_DUCATI_H264ENC_PROFILE_BASELINE:
511       return "baseline";
512     case GST_DUCATI_H264ENC_PROFILE_MAIN:
513       return "main";
514     case GST_DUCATI_H264ENC_PROFILE_EXTENDED:
515       return "extended";
516     case GST_DUCATI_H264ENC_PROFILE_HIGH:
517       return "high";
518     case GST_DUCATI_H264ENC_PROFILE_HIGH_10:
519       return "high-10";
520     case GST_DUCATI_H264ENC_PROFILE_HIGH_422:
521       return "high-422";
522     default:
523       return NULL;
524   }
527 static const char *
528 get_level_name (guint level)
530   switch (level) {
531     case GST_DUCATI_H264ENC_LEVEL_10:
532       return "1";
533     case GST_DUCATI_H264ENC_LEVEL_1b:
534       return "1b";
535     case GST_DUCATI_H264ENC_LEVEL_11:
536       return "1.1";
537     case GST_DUCATI_H264ENC_LEVEL_12:
538       return "1.2";
539     case GST_DUCATI_H264ENC_LEVEL_13:
540       return "1.3";
541     case GST_DUCATI_H264ENC_LEVEL_20:
542       return "2";
543     case GST_DUCATI_H264ENC_LEVEL_21:
544       return "2.1";
545     case GST_DUCATI_H264ENC_LEVEL_22:
546       return "2.2";
547     case GST_DUCATI_H264ENC_LEVEL_30:
548       return "3";
549     case GST_DUCATI_H264ENC_LEVEL_31:
550       return "3.1";
551     case GST_DUCATI_H264ENC_LEVEL_32:
552       return "3.2";
553     case GST_DUCATI_H264ENC_LEVEL_40:
554       return "4";
555     case GST_DUCATI_H264ENC_LEVEL_41:
556       return "4.1";
557     case GST_DUCATI_H264ENC_LEVEL_42:
558       return "4.2";
559     case GST_DUCATI_H264ENC_LEVEL_50:
560       return "5";
561     case GST_DUCATI_H264ENC_LEVEL_51:
562       return "5.1";
563     default:
564       return NULL;
565   }
568 static gboolean
569 gst_ducati_h264enc_configure (GstDucatiVidEnc * videnc)
571   GstDucatiH264Enc *self = GST_DUCATIH264ENC (videnc);
572   IH264ENC_Params *params;
573   IH264ENC_DynamicParams *dynParams;
574   gboolean ret;
575   const char *s;
577   videnc->params->profile = self->profile;
578   videnc->params->level = self->level;
580   params = (IH264ENC_Params *) videnc->params;
581   /* this is the only non-base field strictly required */
582   params->maxIntraFrameInterval = 0x7fffffff;
583   params->IDRFrameInterval = 1;
584   params->numTemporalLayer = 1;
585   params->entropyCodingMode = self->entropy_coding_mode;
587   /* Dynamic params */
588   dynParams = (IH264ENC_DynamicParams *) videnc->dynParams;
589   dynParams->rateControlParams.rateControlParamsPreset =
590       self->rate_control_params_preset;
591   dynParams->rateControlParams.rcAlgo = self->rate_control_algo;
592   dynParams->rateControlParams.qpI = self->qpi;
593   dynParams->rateControlParams.qpMaxI = self->qp_max_i;
594   dynParams->rateControlParams.qpMinI = self->qp_min_i;
595   dynParams->rateControlParams.HRDBufferSize = self->hrd_buffer_size;
596   dynParams->sliceCodingParams.sliceMode = self->slice_mode;
598   ret = GST_DUCATIVIDENC_CLASS (parent_class)->configure (videnc);
599   if (ret) {
600     const GstVideoState *state =
601         gst_base_video_encoder_get_state (GST_BASE_VIDEO_ENCODER (videnc));
602     GstCaps *caps = gst_caps_new_simple ("video/x-h264",
603         "width", G_TYPE_INT, videnc->rect.w,
604         "height", G_TYPE_INT, videnc->rect.h,
605         "framerate", GST_TYPE_FRACTION, state->fps_n, state->fps_d,
606         "pixel-aspect-ratio", GST_TYPE_FRACTION, state->par_n, state->par_d,
607         "stream-format", G_TYPE_STRING, "byte-stream",
608         "align", G_TYPE_STRING, "au",
609         NULL);
610     s = get_profile_name (self->profile);
611     if (s)
612       gst_caps_set_simple (caps, "profile", G_TYPE_STRING, s, NULL);
613     s = get_level_name (self->level);
614     if (s)
615       gst_caps_set_simple (caps, "level", G_TYPE_STRING, s, NULL);
616     ret = gst_pad_set_caps (GST_BASE_VIDEO_CODEC_SRC_PAD (self), caps);
617   }
619   return ret;
622 static gboolean
623 gst_ducati_h264enc_allocate_params (GstDucatiVidEnc *
624     videnc, gint params_sz, gint dynparams_sz, gint status_sz, gint inargs_sz,
625     gint outargs_sz)
627   gboolean ret = GST_DUCATIVIDENC_CLASS (parent_class)->allocate_params (videnc,
628       sizeof (IH264ENC_Params), sizeof (IH264ENC_DynamicParams),
629       sizeof (IVIDENC2_Status), sizeof (IVIDENC2_InArgs),
630       sizeof (IVIDENC2_OutArgs));
632   GstDucatiH264Enc *self = GST_DUCATIH264ENC (videnc);
634   if (ret == TRUE) {
635     IH264ENC_DynamicParams *dynParams =
636         (IH264ENC_DynamicParams *) videnc->dynParams;
638     dynParams->rateControlParams.rateControlParamsPreset =
639         self->rate_control_params_preset;
640     dynParams->rateControlParams.rcAlgo = self->rate_control_algo;
641     dynParams->rateControlParams.qpI = self->qpi;
642     dynParams->rateControlParams.qpMaxI = self->qp_max_i;
643     dynParams->rateControlParams.qpMinI = self->qp_min_i;
644     dynParams->rateControlParams.HRDBufferSize = self->hrd_buffer_size;
645     dynParams->sliceCodingParams.sliceMode = self->slice_mode;
646   }
648   return ret;