]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - glsdk/gst-plugin-ducati.git/blobdiff - src/gstducatih264enc.c
ducatividdec: remove another leftover -strided caps remnant
[glsdk/gst-plugin-ducati.git] / src / gstducatih264enc.c
index f17ee493d6b0368153ffe0d0b797ebf1bf373e67..7006c082ed0397398fe1edc81db3843a9ff50a33 100644 (file)
 #define DEFAULT_QP_MIN_I 10
 /* 2 x targetBitRate for VBR Rate Control */
 #define DEFAULT_HRD_BUFFER_SIZE 40960000
+#define DEFAULT_INTER_INTERVAL 4
 
 #define GST_TYPE_DUCATI_H264ENC_PROFILE (gst_ducati_h264enc_profile_get_type ())
 #define GST_TYPE_DUCATI_H264ENC_LEVEL (gst_ducati_h264enc_level_get_type ())
 #define GST_TYPE_DUCATI_H264ENC_RCPP (gst_ducati_h264enc_get_rate_control_params_preset_type ())
 #define GST_TYPE_DUCATI_H264ENC_RATE_CONTROL_ALGO (gst_ducati_h264enc_get_rate_control_algo_type ())
 #define GST_TYPE_DUCATI_H264ENC_ENTROPY_CODING_MODE (gst_ducati_h264enc_get_entropy_coding_mode_type ())
+#define GST_TYPE_DUCATI_H264ENC_SLICE_MODE (gst_ducati_h264enc_get_slice_mode_type ())
 
 
 enum
@@ -65,6 +67,8 @@ enum
   PROP_QP_MIN_I,
   PROP_HRD_BUFFER_SIZE,
   PROP_ENTROPY_CODING_MODE,
+  PROP_INTER_INTERVAL,
+  PROP_SLICE_MODE,
 };
 
 static void gst_ducati_h264enc_set_property (GObject * object, guint prop_id,
@@ -76,6 +80,8 @@ static gboolean gst_ducati_h264enc_allocate_params (GstDucatiVidEnc *
     self, gint params_sz, gint dynparams_sz, gint status_sz, gint inargs_sz,
     gint outargs_sz);
 static gboolean gst_ducati_h264enc_configure (GstDucatiVidEnc * self);
+static gboolean gst_ducati_h264enc_is_sync_point (GstDucatiVidEnc * enc,
+    int type);
 
 
 static GstStaticPadTemplate gst_ducati_h264enc_sink_template =
@@ -248,6 +254,32 @@ gst_ducati_h264enc_get_entropy_coding_mode_type (void)
   return type;
 }
 
+static GType
+gst_ducati_h264enc_get_slice_mode_type (void)
+{
+  static GType type = 0;
+
+  if (!type) {
+    static const GEnumValue vals[] = {
+      {IH264_SLICEMODE_NONE, "No slice mode", "none"},
+      {IH264_SLICEMODE_DEFAULT, "Default slice coding mode is MB based",
+          "default"},
+      {IH264_SLICEMODE_MBUNIT,
+          "Slices are controlled based upon number of Macroblocks", "mbunit"},
+      {IH264_SLICEMODE_BYTES,
+          "Slices are controlled based upon number of bytes", "bytes"},
+      {IH264_SLICEMODE_OFFSET,
+            "Slices are controlled based upon user defined offset unit of Row",
+          "offset"},
+      {0, NULL, NULL},
+    };
+
+    type = g_enum_register_static ("GstDucatiSliceMode", vals);
+  }
+
+  return type;
+}
+
 static void
 gst_ducati_h264enc_base_init (gpointer g_class)
 {
@@ -281,6 +313,7 @@ gst_ducati_h264enc_class_init (GstDucatiH264EncClass * klass)
 
   videnc_class->allocate_params = gst_ducati_h264enc_allocate_params;
   videnc_class->configure = gst_ducati_h264enc_configure;
+  videnc_class->is_sync_point = gst_ducati_h264enc_is_sync_point;
 
   g_object_class_install_property (gobject_class, PROP_PROFILE,
       g_param_spec_enum ("profile", "H.264 Profile", "H.264 Profile",
@@ -290,6 +323,11 @@ gst_ducati_h264enc_class_init (GstDucatiH264EncClass * klass)
       g_param_spec_enum ("level", "H.264 Level", "H.264 Level",
           GST_TYPE_DUCATI_H264ENC_LEVEL, DEFAULT_LEVEL, G_PARAM_READWRITE));
 
+  g_object_class_install_property (gobject_class, PROP_INTER_INTERVAL,
+      g_param_spec_uint ("inter-interval", "Inter-frame interval",
+          "Max inter frame interval (B frames are allowed between them if > 1)",
+          1, 31, DEFAULT_INTER_INTERVAL, G_PARAM_READWRITE));
+
   g_object_class_install_property (gobject_class,
       PROP_RATE_CONTROL_PARAMS_PRESET,
       g_param_spec_enum ("rate-control-params-preset",
@@ -339,6 +377,13 @@ gst_ducati_h264enc_class_init (GstDucatiH264EncClass * klass)
           GST_TYPE_DUCATI_H264ENC_ENTROPY_CODING_MODE,
           IH264_ENTROPYCODING_DEFAULT, G_PARAM_READWRITE));
 
+  g_object_class_install_property (gobject_class, PROP_SLICE_MODE,
+      g_param_spec_enum ("slice-mode", "H.264 slice mode",
+          "This defines the control mechanism to split a picture in slices."
+          " It can be either MB based or bytes based",
+          GST_TYPE_DUCATI_H264ENC_SLICE_MODE,
+          IH264_SLICEMODE_DEFAULT, G_PARAM_READWRITE));
+
 }
 
 static void
@@ -354,6 +399,7 @@ gst_ducati_h264enc_init (GstDucatiH264Enc * self, GstDucatiH264EncClass * klass)
   self->qp_min_i = DEFAULT_QP_MIN_I;
   self->qp_max_i = DEFAULT_QP_MAX_I;
   self->hrd_buffer_size = DEFAULT_HRD_BUFFER_SIZE;
+  self->inter_interval = DEFAULT_INTER_INTERVAL;
 }
 
 static void
@@ -415,6 +461,12 @@ gst_ducati_h264enc_set_property (GObject * object, guint prop_id,
     case PROP_ENTROPY_CODING_MODE:
       self->entropy_coding_mode = g_value_get_enum (value);
       break;
+    case PROP_SLICE_MODE:
+      self->slice_mode = g_value_get_enum (value);
+      break;
+    case PROP_INTER_INTERVAL:
+      self->inter_interval = g_value_get_uint (value);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
   }
@@ -452,16 +504,84 @@ gst_ducati_h264enc_get_property (GObject * object, guint prop_id,
       g_value_set_int (value, self->qp_max_i);
       break;
     case PROP_HRD_BUFFER_SIZE:
-      g_value_set_int (value, self->hrd_buffer_size);
+      g_value_set_uint (value, self->hrd_buffer_size);
       break;
     case PROP_ENTROPY_CODING_MODE:
       g_value_set_enum (value, self->entropy_coding_mode);
       break;
+    case PROP_SLICE_MODE:
+      g_value_set_enum (value, self->slice_mode);
+      break;
+    case PROP_INTER_INTERVAL:
+      g_value_set_uint (value, self->inter_interval);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
   }
 }
 
+static const char *
+get_profile_name (guint profile)
+{
+  switch (profile) {
+    case GST_DUCATI_H264ENC_PROFILE_BASELINE:
+      return "baseline";
+    case GST_DUCATI_H264ENC_PROFILE_MAIN:
+      return "main";
+    case GST_DUCATI_H264ENC_PROFILE_EXTENDED:
+      return "extended";
+    case GST_DUCATI_H264ENC_PROFILE_HIGH:
+      return "high";
+    case GST_DUCATI_H264ENC_PROFILE_HIGH_10:
+      return "high-10";
+    case GST_DUCATI_H264ENC_PROFILE_HIGH_422:
+      return "high-422";
+    default:
+      return NULL;
+  }
+}
+
+static const char *
+get_level_name (guint level)
+{
+  switch (level) {
+    case GST_DUCATI_H264ENC_LEVEL_10:
+      return "1";
+    case GST_DUCATI_H264ENC_LEVEL_1b:
+      return "1b";
+    case GST_DUCATI_H264ENC_LEVEL_11:
+      return "1.1";
+    case GST_DUCATI_H264ENC_LEVEL_12:
+      return "1.2";
+    case GST_DUCATI_H264ENC_LEVEL_13:
+      return "1.3";
+    case GST_DUCATI_H264ENC_LEVEL_20:
+      return "2";
+    case GST_DUCATI_H264ENC_LEVEL_21:
+      return "2.1";
+    case GST_DUCATI_H264ENC_LEVEL_22:
+      return "2.2";
+    case GST_DUCATI_H264ENC_LEVEL_30:
+      return "3";
+    case GST_DUCATI_H264ENC_LEVEL_31:
+      return "3.1";
+    case GST_DUCATI_H264ENC_LEVEL_32:
+      return "3.2";
+    case GST_DUCATI_H264ENC_LEVEL_40:
+      return "4";
+    case GST_DUCATI_H264ENC_LEVEL_41:
+      return "4.1";
+    case GST_DUCATI_H264ENC_LEVEL_42:
+      return "4.2";
+    case GST_DUCATI_H264ENC_LEVEL_50:
+      return "5";
+    case GST_DUCATI_H264ENC_LEVEL_51:
+      return "5.1";
+    default:
+      return NULL;
+  }
+}
+
 static gboolean
 gst_ducati_h264enc_configure (GstDucatiVidEnc * videnc)
 {
@@ -469,16 +589,31 @@ gst_ducati_h264enc_configure (GstDucatiVidEnc * videnc)
   IH264ENC_Params *params;
   IH264ENC_DynamicParams *dynParams;
   gboolean ret;
+  const char *s;
+  const GstVideoState *state;
+  GstCaps *caps;
+  int inter_interval;
+
+  ret = GST_DUCATIVIDENC_CLASS (parent_class)->configure (videnc);
+  if (!ret)
+    return FALSE;
 
   videnc->params->profile = self->profile;
   videnc->params->level = self->level;
 
+  inter_interval = self->inter_interval;
+  if (self->profile == GST_DUCATI_H264ENC_PROFILE_BASELINE)
+    inter_interval = 1;
+  else if (videnc->rate_preset == IVIDEO_LOW_DELAY)
+    inter_interval = 1;
+
   params = (IH264ENC_Params *) videnc->params;
   /* this is the only non-base field strictly required */
   params->maxIntraFrameInterval = 0x7fffffff;
   params->IDRFrameInterval = 1;
   params->numTemporalLayer = 1;
   params->entropyCodingMode = self->entropy_coding_mode;
+  videnc->params->maxInterFrameInterval = inter_interval;
 
   /* Dynamic params */
   dynParams = (IH264ENC_DynamicParams *) videnc->dynParams;
@@ -489,21 +624,25 @@ gst_ducati_h264enc_configure (GstDucatiVidEnc * videnc)
   dynParams->rateControlParams.qpMaxI = self->qp_max_i;
   dynParams->rateControlParams.qpMinI = self->qp_min_i;
   dynParams->rateControlParams.HRDBufferSize = self->hrd_buffer_size;
-
-  ret = GST_DUCATIVIDENC_CLASS (parent_class)->configure (videnc);
-  if (ret) {
-    const GstVideoState *state =
-        gst_base_video_encoder_get_state (GST_BASE_VIDEO_ENCODER (videnc));
-    GstCaps *caps = gst_caps_new_simple ("video/x-h264",
-        "width", G_TYPE_INT, videnc->rect.w,
-        "height", G_TYPE_INT, videnc->rect.h,
-        "framerate", GST_TYPE_FRACTION, state->fps_n, state->fps_d,
-        "pixel-aspect-ratio", GST_TYPE_FRACTION, state->par_n, state->par_d,
-        "stream-format", G_TYPE_STRING, "byte-stream",
-        "align", G_TYPE_STRING, "au",
-        NULL);
-    ret = gst_pad_set_caps (GST_BASE_VIDEO_CODEC_SRC_PAD (self), caps);
-  }
+  dynParams->sliceCodingParams.sliceMode = self->slice_mode;
+  videnc->dynParams->interFrameInterval = inter_interval;
+
+  state = gst_base_video_encoder_get_state (GST_BASE_VIDEO_ENCODER (videnc));
+  caps = gst_caps_new_simple ("video/x-h264",
+      "width", G_TYPE_INT, videnc->rect.w,
+      "height", G_TYPE_INT, videnc->rect.h,
+      "framerate", GST_TYPE_FRACTION, state->fps_n, state->fps_d,
+      "pixel-aspect-ratio", GST_TYPE_FRACTION, state->par_n, state->par_d,
+      "stream-format", G_TYPE_STRING, "byte-stream",
+      "align", G_TYPE_STRING, "au",
+      "num-reorder-frames", G_TYPE_INT, inter_interval - 1, NULL);
+  s = get_profile_name (self->profile);
+  if (s)
+    gst_caps_set_simple (caps, "profile", G_TYPE_STRING, s, NULL);
+  s = get_level_name (self->level);
+  if (s)
+    gst_caps_set_simple (caps, "level", G_TYPE_STRING, s, NULL);
+  ret = gst_pad_set_caps (GST_BASE_VIDEO_CODEC_SRC_PAD (self), caps);
 
   return ret;
 }
@@ -531,7 +670,14 @@ gst_ducati_h264enc_allocate_params (GstDucatiVidEnc *
     dynParams->rateControlParams.qpMaxI = self->qp_max_i;
     dynParams->rateControlParams.qpMinI = self->qp_min_i;
     dynParams->rateControlParams.HRDBufferSize = self->hrd_buffer_size;
+    dynParams->sliceCodingParams.sliceMode = self->slice_mode;
   }
 
   return ret;
 }
+
+static gboolean
+gst_ducati_h264enc_is_sync_point (GstDucatiVidEnc * enc, int type)
+{
+  return type == IVIDEO_IDR_FRAME;
+}