]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - glsdk/gst-plugin-ducati.git/blobdiff - src/gstducatimpeg4dec.c
Realigned code on new Ducati header files
[glsdk/gst-plugin-ducati.git] / src / gstducatimpeg4dec.c
index cee2515d2958b05be74b0c4161faaa6a09b4fa86..212a4b88211796d6493eef41b04e99c88fb67ada 100644 (file)
@@ -54,19 +54,11 @@ GST_BOILERPLATE (GstDucatiMpeg4Dec, gst_ducati_mpeg4dec, GstDucatiVidDec,
 static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
     GST_PAD_SINK,
     GST_PAD_ALWAYS,
-    GST_STATIC_CAPS (
-        "video/mpeg, "
-          "mpegversion = (int)4, "
-          "systemstream = (boolean)false, "
-          MPEG4DEC_SINKCAPS_COMMON ";"
-        "video/x-divx, "
-          "divxversion = (int)[4, 5], "  /* TODO check this */
-          MPEG4DEC_SINKCAPS_COMMON ";"
+    GST_STATIC_CAPS ("video/mpeg, " "mpegversion = (int)4, " "systemstream = (boolean)false, " MPEG4DEC_SINKCAPS_COMMON ";" "video/x-divx, " "divxversion = (int)[4, 5], "      /* TODO check this */
+        MPEG4DEC_SINKCAPS_COMMON ";"
         "video/x-xvid, "
-          MPEG4DEC_SINKCAPS_COMMON ";"
-        "video/x-3ivx, "
-          MPEG4DEC_SINKCAPS_COMMON ";"
-        )
+        MPEG4DEC_SINKCAPS_COMMON ";"
+        "video/x-3ivx, " MPEG4DEC_SINKCAPS_COMMON ";")
     );
 
 /* GstDucatiVidDec vmethod implementations */
@@ -99,25 +91,26 @@ gst_ducati_mpeg4dec_allocate_params (GstDucatiVidDec * self, gint params_sz,
     self->dynParams->lateAcquireArg = -1;
     params->outloopDeBlocking = FALSE;
     params->sorensonSparkStream = FALSE;
-    params->ErrorConcealmentON = FALSE;
+    params->errorConcealmentEnable = FALSE;
   }
 
   return ret;
 }
 
-#define VOS_START_CODE    0xb0    /* + visual object sequence */
+#define VOS_START_CODE    0xb0  /* + visual object sequence */
 #define VOS_END_CODE      0xb1
-#define UD_START_CODE     0xb2    /* user data */
-#define GVOP_START_CODE   0xb3    /* + group of VOP */
+#define UD_START_CODE     0xb2  /* user data */
+#define GVOP_START_CODE   0xb3  /* + group of VOP */
 #define VS_ERROR_CODE     0xb4
-#define VO_START_CODE     0xb5    /* visual object */
-#define VOP_START_CODE    0xb6    /* + */
+#define VO_START_CODE     0xb5  /* visual object */
+#define VOP_START_CODE    0xb6  /* + */
+
+static const guint8 sc[] = { 0x00, 0x00, 0x01 };        /* start code */
 
-static const guint8 sc[] = {0x00, 0x00, 0x01};  /* start code */
 #define SC_SZ                G_N_ELEMENTS (sc)  /* start code size */
 
 static GstBitReader *
-get_bit_reader (GstDucatiMpeg4Dec *self, const guint8 * data, guint size)
+get_bit_reader (GstDucatiMpeg4Dec * self, const guint8 * data, guint size)
 {
   if (self->br) {
     gst_bit_reader_init (self->br, data, size);
@@ -128,48 +121,48 @@ get_bit_reader (GstDucatiMpeg4Dec *self, const guint8 * data, guint size)
 }
 
 static void
-decode_vol_header (GstDucatiMpeg4Dec *self, const guint8 * data, guint size)
+decode_vol_header (GstDucatiMpeg4Dec * self, const guint8 * data, guint size)
 {
   GstBitReader *br = get_bit_reader (self, data, size);
   guint32 is_oli = 0, vc_param = 0, vbv_param = 0;
   guint32 ar_info = 0, vop_tir = 0;
 
-  gst_bit_reader_skip (br, 1);         /* random_accessible_vol */
-  gst_bit_reader_skip (br, 8);         /* video_object_type_indication */
+  gst_bit_reader_skip (br, 1);  /* random_accessible_vol */
+  gst_bit_reader_skip (br, 8);  /* video_object_type_indication */
 
-  gst_bit_reader_get_bits_uint32 (br,  /* is_object_layer_identifier */
+  gst_bit_reader_get_bits_uint32 (br,   /* is_object_layer_identifier */
       &is_oli, 1);
   if (is_oli) {
-    gst_bit_reader_skip (br, 4);       /* video_object_layer_verid */
-    gst_bit_reader_skip (br, 3);       /* video_object_layer_priority */
+    gst_bit_reader_skip (br, 4);        /* video_object_layer_verid */
+    gst_bit_reader_skip (br, 3);        /* video_object_layer_priority */
   }
 
-  gst_bit_reader_get_bits_uint32 (br,  /* aspect_ratio_info */
+  gst_bit_reader_get_bits_uint32 (br,   /* aspect_ratio_info */
       &ar_info, 4);
   if (ar_info == 0xf) {
-    gst_bit_reader_skip (br, 8);       /* par_width */
-    gst_bit_reader_skip (br, 8);       /* par_height */
+    gst_bit_reader_skip (br, 8);        /* par_width */
+    gst_bit_reader_skip (br, 8);        /* par_height */
   }
 
-  gst_bit_reader_get_bits_uint32 (br,  /* vol_control_parameters */
+  gst_bit_reader_get_bits_uint32 (br,   /* vol_control_parameters */
       &vc_param, 1);
   if (vc_param) {
-    gst_bit_reader_skip (br, 2);       /* chroma_format */
-    gst_bit_reader_skip (br, 1);       /* low_delay */
-    gst_bit_reader_get_bits_uint32 (   /* vbv_parameters */
+    gst_bit_reader_skip (br, 2);        /* chroma_format */
+    gst_bit_reader_skip (br, 1);        /* low_delay */
+    gst_bit_reader_get_bits_uint32 (    /* vbv_parameters */
         br, &vbv_param, 1);
     if (vbv_param) {
-      gst_bit_reader_skip (br, 79);    /* don't care */
+      gst_bit_reader_skip (br, 79);     /* don't care */
     }
   }
 
-  gst_bit_reader_skip (br, 2);         /* video_object_layer_shape */
-  gst_bit_reader_skip (br, 1);         /* marker_bit */
-  gst_bit_reader_get_bits_uint32 (br,  /* vop_time_increment_resolution */
+  gst_bit_reader_skip (br, 2);  /* video_object_layer_shape */
+  gst_bit_reader_skip (br, 1);  /* marker_bit */
+  gst_bit_reader_get_bits_uint32 (br,   /* vop_time_increment_resolution */
       &vop_tir, 16);
-  gst_bit_reader_skip (br, 1);         /* marker_bit */
+  gst_bit_reader_skip (br, 1);  /* marker_bit */
 
-  self->time_increment_bits = (guint32)log2((double)(vop_tir - 1)) + 1;
+  self->time_increment_bits = (guint32) log2 ((double) (vop_tir - 1)) + 1;
 
   GST_DEBUG_OBJECT (self, "vop_tir=%d, time_increment_bits=%d",
       vop_tir, self->time_increment_bits);
@@ -181,17 +174,17 @@ decode_vol_header (GstDucatiMpeg4Dec *self, const guint8 * data, guint size)
 }
 
 static void
-decode_user_data (GstDucatiMpeg4Dec *self, const guint8 * data, guint size)
+decode_user_data (GstDucatiMpeg4Dec * self, const guint8 * data, guint size)
 {
   GstDucatiVidDec *vdec = GST_DUCATIVIDDEC (self);
-  const char *buf = (const char *)data;
+  const char *buf = (const char *) data;
   int n, ver, build;
   char c;
 
   /* divx detection: */
-  n = sscanf(buf, "DivX%dBuild%d%c", &ver, &build, &c);
+  n = sscanf (buf, "DivX%dBuild%d%c", &ver, &build, &c);
   if (n < 2)
-    n = sscanf(buf, "DivX%db%d%c", &ver, &build, &c);
+    n = sscanf (buf, "DivX%db%d%c", &ver, &build, &c);
   if (n >= 2) {
     GST_INFO_OBJECT (self, "DivX: version %d, build %d", ver, build);
     if ((n == 3) && (c == 'p')) {
@@ -202,7 +195,7 @@ decode_user_data (GstDucatiMpeg4Dec *self, const guint8 * data, guint size)
   }
 
   /* xvid detection: */
-  n = sscanf(buf, "XviD%d", &build);
+  n = sscanf (buf, "XviD%d", &build);
   if (n == 1) {
     GST_INFO_OBJECT (self, "XviD: build %d", build);
     /* I believe we only get this in avi container, which means
@@ -213,23 +206,22 @@ decode_user_data (GstDucatiMpeg4Dec *self, const guint8 * data, guint size)
 }
 
 static gboolean
-is_vop_coded (GstDucatiMpeg4Dec *self, const guint8 * data, guint size)
+is_vop_coded (GstDucatiMpeg4Dec * self, const guint8 * data, guint size)
 {
-  GstBitReader *br =
-      get_bit_reader (self, data, size);
+  GstBitReader *br = get_bit_reader (self, data, size);
   guint32 b = 0;
 
-  gst_bit_reader_skip (br, 2);         /* vop_coding_type */
+  gst_bit_reader_skip (br, 2);  /* vop_coding_type */
 
-  do {                                 /* modulo_time_base */
+  do {                          /* modulo_time_base */
     gst_bit_reader_get_bits_uint32 (br, &b, 1);
   } while (b != 0);
 
-  gst_bit_reader_skip (br, 1);         /* marker_bit */
-  gst_bit_reader_skip (br,             /* vop_time_increment */
+  gst_bit_reader_skip (br, 1);  /* marker_bit */
+  gst_bit_reader_skip (br,      /* vop_time_increment */
       self->time_increment_bits);
-  gst_bit_reader_skip (br, 1);         /* marker_bit */
-  gst_bit_reader_get_bits_uint32 (br,  /* vop_coded */
+  gst_bit_reader_skip (br, 1);  /* marker_bit */
+  gst_bit_reader_get_bits_uint32 (br,   /* vop_coded */
       &b, 1);
 
   return b;
@@ -241,7 +233,7 @@ gst_ducati_mpeg4dec_push_input (GstDucatiVidDec * vdec, GstBuffer * buf)
   GstDucatiMpeg4Dec *self = GST_DUCATIMPEG4DEC (vdec);
   GstBuffer *remaining = NULL;
   gint insize = GST_BUFFER_SIZE (buf);
-  const guint8 *in  = GST_BUFFER_DATA (buf);
+  const guint8 *in = GST_BUFFER_DATA (buf);
   gint size = 0;
   guint8 last_start_code = 0xff;
 
@@ -259,10 +251,7 @@ gst_ducati_mpeg4dec_push_input (GstDucatiVidDec * vdec, GstBuffer * buf)
 
     if (size > 0) {
       /* check if we've found a potential start of frame: */
-      if ((start_code == VOS_START_CODE) ||
-          (start_code == GVOP_START_CODE) ||
-          (start_code == VOP_START_CODE) ||
-          (start_code <= 0x1f)) { /* 00->0f is video_object_start_code */
+      if ((start_code == VOS_START_CODE) || (start_code == GVOP_START_CODE) || (start_code == VOP_START_CODE) || (start_code <= 0x1f)) {        /* 00->0f is video_object_start_code */
         /* if last was a VOP, or if this is first VOP, then what follows
          * must be the next frame:
          */
@@ -278,8 +267,7 @@ gst_ducati_mpeg4dec_push_input (GstDucatiVidDec * vdec, GstBuffer * buf)
 
     last_start_code = start_code;
 
-    nal_size = SC_SZ +
-        find_start_code (sc, SC_SZ, in + SC_SZ, insize - SC_SZ);
+    nal_size = SC_SZ + find_start_code (sc, SC_SZ, in + SC_SZ, insize - SC_SZ);
 
     if ((start_code == VOP_START_CODE) && (nal_size < 20)) {
       /* suspiciously small nal..  check for !vop_coded and filter
@@ -290,10 +278,10 @@ gst_ducati_mpeg4dec_push_input (GstDucatiVidDec * vdec, GstBuffer * buf)
        * are all 7 bytes but need to come up with some sane
        * threshold
        */
-      skip = ! is_vop_coded (self, in + SC_SZ + 1, insize - SC_SZ - 1);
+      skip = !is_vop_coded (self, in + SC_SZ + 1, insize - SC_SZ - 1);
       if (skip)
         GST_DEBUG_OBJECT (self, "skipping non-coded VOP");
-    } else if (start_code == UD_START_CODE){
+    } else if (start_code == UD_START_CODE) {
       decode_user_data (self, in + SC_SZ + 1, nal_size - SC_SZ - 1);
     }
 
@@ -344,8 +332,7 @@ gst_ducati_mpeg4dec_base_init (gpointer gclass)
   gst_element_class_set_details_simple (element_class,
       "DucatiMpeg4Dec",
       "Codec/Decoder/Video",
-      "Decodes video in MPEG-4 format with ducati",
-      "Rob Clark <rob@ti.com>");
+      "Decodes video in MPEG-4 format with ducati", "Rob Clark <rob@ti.com>");
 
   gst_element_class_add_pad_template (element_class,
       gst_static_pad_template_get (&sink_factory));
@@ -357,20 +344,46 @@ gst_ducati_mpeg4dec_class_init (GstDucatiMpeg4DecClass * klass)
   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
   GstDucatiVidDecClass *bclass = GST_DUCATIVIDDEC_CLASS (klass);
 
-  gobject_class->finalize =
-      GST_DEBUG_FUNCPTR (gst_ducati_mpeg4dec_finalize);
+  gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_ducati_mpeg4dec_finalize);
 
   bclass->codec_name = "ivahd_mpeg4dec";
   bclass->update_buffer_size =
       GST_DEBUG_FUNCPTR (gst_ducati_mpeg4dec_update_buffer_size);
   bclass->allocate_params =
       GST_DEBUG_FUNCPTR (gst_ducati_mpeg4dec_allocate_params);
-  bclass->push_input =
-      GST_DEBUG_FUNCPTR (gst_ducati_mpeg4dec_push_input);
+  bclass->push_input = GST_DEBUG_FUNCPTR (gst_ducati_mpeg4dec_push_input);
 }
 
 static void
 gst_ducati_mpeg4dec_init (GstDucatiMpeg4Dec * self,
     GstDucatiMpeg4DecClass * gclass)
 {
+#ifndef GST_DISABLE_GST_DEBUG
+  GstDucatiVidDec *dec = GST_DUCATIVIDDEC (self);
+
+  dec->error_strings[0] = "no video object sequence found";
+  dec->error_strings[1] = "incorrect video object type";
+  dec->error_strings[2] = "error in video object layer";
+  dec->error_strings[3] = "error parsing group of video";
+  dec->error_strings[4] = "error parsing video object plane";
+  dec->error_strings[5] = "error in short header parsing";
+  dec->error_strings[6] = "error in GOB parsing";
+  dec->error_strings[7] = "error in video packet parsing";
+  dec->error_strings[16] = "error in MB data parsing";
+  dec->error_strings[17] = "invalid parameter";
+  dec->error_strings[18] = "unsupported feature";
+  dec->error_strings[19] = "stream end";
+  dec->error_strings[20] = "valid header not found";
+  dec->error_strings[21] = "unsupported resolution";
+  dec->error_strings[22] = "stream buffer underflow";
+  dec->error_strings[23] = "invalid mbox message";
+  dec->error_strings[24] = "no frame to flush";
+  dec->error_strings[25] = "given vop is not codec";
+  dec->error_strings[26] = "start code not present";
+  dec->error_strings[27] = "unsupported time increment resolution";
+  dec->error_strings[28] = "resolution change";
+  dec->error_strings[29] = "unsupported H263 annex";
+  dec->error_strings[30] = "bad HDVICP2 state";
+  dec->error_strings[31] = "frame dropped";
+#endif
 }