Modify video and audio encoder's interface module 69/18569/1
authorKitae Kim <kt920.kim@samsung.com>
Wed, 19 Mar 2014 11:08:20 +0000 (20:08 +0900)
committerKitae Kim <kt920.kim@samsung.com>
Thu, 20 Mar 2014 11:31:01 +0000 (20:31 +0900)
Modify interface module as libav on qemu side, which gives codec information
to this plugin, has been upgraded into 9.8.
In addition to this, use gstreamer logging methods instead of printf

Change-Id: I1c3e9a0be81f01dc15807df52ea9100f36ee214e
Signed-off-by: Kitae Kim <kt920.kim@samsung.com>
src/gstmaru.c
src/gstmaru.h
src/gstmarudec.c
src/gstmaruenc.c
src/gstmaruinterface.c
src/gstmarumem.c
src/gstmaruutils.c

index bb24845..5c692f0 100644 (file)
@@ -61,11 +61,10 @@ static GMutex gst_maru_mutex;
 static gboolean
 gst_maru_codec_element_init ()
 {
-  int fd = 0;
-  int version = 0;
+  int fd = 0, version = 0;
   int i, elem_cnt = 0;
   uint32_t data_length = 0;
-  void *buffer = NULL;
+  void *buffer = MAP_FAILED;
   CodecElement *elem = NULL;
 
   CODEC_LOG (DEBUG, "enter: %s\n", __func__);
@@ -74,44 +73,51 @@ gst_maru_codec_element_init ()
 
   fd = open (CODEC_DEV, O_RDWR);
   if (fd < 0) {
-    perror ("[gst-maru] failed to open codec device");
+    // perror ("[gst-maru] failed to open codec device");
+    GST_ERROR ("failed to open codec device");
     return FALSE;
   }
 
   ioctl (fd, CODEC_CMD_GET_VERSION, &version);
   if (version != CODEC_VER) {
-    CODEC_LOG (INFO, "version conflict between device: %d, plugin: %d\n",
-              version, CODEC_VER);
+    // CODEC_LOG (INFO, "version conflict between device: %d, plugin: %d\n", version, CODEC_VER);
+    GST_LOG ("version conflict between device: %d, plugin: %d", version, CODEC_VER);
     close (fd);
     return FALSE;
   }
 
   buffer = mmap (NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
-  if (!buffer) {
-    perror ("[gst-maru] failure memory mapping.");
+  if (buffer == MAP_FAILED) {
+    // perror ("[gst-maru] failure memory mapping.");
+    GST_ERROR ("memory mapping failure");
     close (fd);
     return FALSE;
   }
 
-  CODEC_LOG (DEBUG, "request a device to get codec element.\n");
+  // CODEC_LOG (DEBUG, "request a device to get codec element.\n");
+  GST_DEBUG ("request a device to get codec element");
   if (ioctl(fd, CODEC_CMD_GET_ELEMENT, &data_length) < 0) {
-    perror ("[gst-maru] failed to get codec elements");
+    // perror ("[gst-maru] failed to get codec elements");
+    GST_ERROR ("failed to get codec elements");
     munmap (buffer, 4096);
     close (fd);
     return FALSE;
   }
 
-  CODEC_LOG (DEBUG, "sizeof codec elements. %d\n", data_length);
+  // CODEC_LOG (DEBUG, "sizeof codec elements. %d\n", data_length);
+  GST_DEBUG ("total size of codec elements %d", data_length);
   elem = g_malloc0 (data_length);
   if (!elem) {
-    CODEC_LOG (ERR, "Failed to allocate memory.\n");
+    // CODEC_LOG (ERR, "Failed to allocate memory.\n");
+    GST_ERROR ("failed to allocate memory for codec elements");
     munmap (buffer, 4096);
     close (fd);
     return FALSE;
   }
 
   if (ioctl(fd, CODEC_CMD_GET_ELEMENT_DATA, elem) < 0) {
-    CODEC_LOG (ERR, "failed to get codec elements\n");
+    // CODEC_LOG (ERR, "failed to get codec elements\n");
+    GST_ERROR ("failed to get codec elements");
     munmap (buffer, 4096);
     close (fd);
     return FALSE;
@@ -177,8 +183,8 @@ GST_PLUGIN_DEFINE (
   "tizen-emul",
   "Codecs for Tizen Emulator",
   plugin_init,
-  "0.2.2",
+  "0.2.7",
   "LGPL",
   "gst-plugins-emulator",
-  "http://tizen.org"
+  "http://www.tizen.org"
 )
index 8827f4e..b9d9f83 100644 (file)
@@ -116,7 +116,7 @@ typedef struct _AudioData {
   int32_t channels, sample_rate;
   int32_t block_align, depth;
   int32_t sample_fmt, frame_size;
-  int32_t bits_per_sample_fmt;
+  int32_t bits_per_sample_fmt, reserved;
   int64_t channel_layout;
 } AudioData;
 
@@ -169,13 +169,19 @@ enum CODEC_TYPE {
   CODEC_TYPE_ENCODE,
 };
 
-enum SAMPLT_FORMAT {
+enum AUDIO_SAMPLE_FORMAT {
   SAMPLE_FMT_NONE = -1,
   SAMPLE_FMT_U8,
   SAMPLE_FMT_S16,
   SAMPLE_FMT_S32,
   SAMPLE_FMT_FLT,
   SAMPLE_FMT_DBL,
+
+  SAMPLE_FMT_U8P,
+  SAMPLE_FMT_S16P,
+  SAMPLE_FMT_S32P,
+  SAMPLE_FMT_FLTP,
+  SAMPLE_FMT_DBLP,
   SAMPLE_FMT_NB
 };
 
index 26f60f4..ba397ec 100644 (file)
@@ -209,7 +209,7 @@ flush_queued (GstMaruDec *marudec)
 {
   GstFlowReturn res = GST_FLOW_OK;
 
-  CODEC_LOG (DEBUG, "flush queued\n");
+  GST_DEBUG_OBJECT (marudec, "flush queued");
 
   while (marudec->queued) {
     GstBuffer *buf = GST_BUFFER_CAST (marudec->queued->data);
@@ -238,7 +238,7 @@ gst_marudec_drain (GstMaruDec *marudec)
   oclass = (GstMaruDecClass *) (G_OBJECT_GET_CLASS (marudec));
 #endif
 
-  CODEC_LOG (DEBUG, "drain frame\n");
+  GST_DEBUG_OBJECT (marudec, "drain frame");
   {
     gint have_data, len, try = 0;
 
@@ -255,7 +255,7 @@ gst_marudec_drain (GstMaruDec *marudec)
   }
 
   if (marudec->segment.rate < 0.0) {
-    CODEC_LOG (DEBUG, "reverse playback\n");
+    GST_DEBUG_OBJECT (marudec, "reverse playback");
     flush_queued (marudec);
   }
 }
@@ -380,7 +380,7 @@ gst_marudec_init (GstMaruDec *marudec)
 
   marudec->dev = g_malloc0 (sizeof(CodecDevice));
   if (!marudec->dev) {
-    CODEC_LOG (ERR, "failed to allocate memory.\n");
+    GST_ERROR_OBJECT (marudec, "failed to allocate memory for CodecDevice");
   }
 }
 
@@ -872,7 +872,7 @@ get_output_buffer (GstMaruDec *marudec, GstBuffer **outbuf)
     return GST_FLOW_ERROR;
   }
 
-  CODEC_LOG (DEBUG, "outbuf size of decoded video: %d\n", pict_size);
+  GST_DEBUG_OBJECT (marudec, "outbuf size of decoded video %d", pict_size);
 
   gst_pad_set_element_private(GST_PAD_PEER(marudec->srcpad), (gpointer)marudec);
 
@@ -978,9 +978,8 @@ gst_marudec_video_frame (GstMaruDec *marudec, guint8 *data, guint size,
   const GstTSInfo *out_info;
 
   decode = gst_marudec_do_qos (marudec, dec_info->timestamp, &mode_switch);
-  CODEC_LOG (DEBUG, "decode: %d\n", decode);
 
-  CODEC_LOG (DEBUG, "decode video: input buffer size: %d\n", size);
+  GST_DEBUG_OBJECT (marudec, "decode video: input buffer size %d", size);
   len =
     codec_decode_video (marudec->context, data, size,
                           dec_info->idx, in_offset, outbuf,
@@ -1008,11 +1007,6 @@ gst_marudec_video_frame (GstMaruDec *marudec, guint8 *data, guint size,
 //  if (len < 0) { // have_data <= 0) {
     GST_DEBUG_OBJECT (marudec, "return flow %d, out %p, len %d",
       *ret, *outbuf, len);
-
-    CODEC_LOG (DEBUG,
-      "return flow %d, out %p, len %d, have_data: %d\n",
-      *ret, *outbuf, len, have_data);
-
     return len;
   }
 
@@ -1145,7 +1139,7 @@ gst_marudec_audio_frame (GstMaruDec *marudec, CodecElement *codec,
       new_aligned_buffer (FF_MAX_AUDIO_FRAME_SIZE,
           GST_PAD_CAPS (marudec->srcpad));
 
-  CODEC_LOG (DEBUG, "decode audio, input buffer size: %d\n", size);
+  GST_DEBUG_OBJECT (marudec, "decode audio, input buffer size %d", size);
 
   len = codec_decode_audio (marudec->context,
       (int16_t *) GST_BUFFER_DATA (*outbuf), &have_data,
@@ -1165,7 +1159,8 @@ gst_marudec_audio_frame (GstMaruDec *marudec, CodecElement *codec,
       return len;
     }
 
-    GST_BUFFER_SIZE (*outbuf) = have_data;
+    // GST_BUFFER_SIZE (*outbuf) = have_data;
+    GST_BUFFER_SIZE (*outbuf) = len;
 
     if (GST_CLOCK_TIME_IS_VALID (dec_info->timestamp)) {
       out_timestamp = dec_info->timestamp;
index 8e4e64c..f13884b 100644 (file)
@@ -707,16 +707,18 @@ gst_maruenc_chain_video (GstPad *pad, GstBuffer *buffer)
 #if 0
   ret = ioctl(maruenc->dev->fd, CODEC_CMD_RELEASE_BUFFER, &mem_offset);
   if (ret < 0) {
-    CODEC_LOG (ERR, "failed to release used buffer\n");
+    GST_ERROR_OBJECT (maruenc, "failed to release used buffer");
   }
 #endif
 
   if (coded_frame) {
     if (!is_keyframe) {
       GST_DEBUG_OBJECT (maruenc, "this frame is not a keyframe");
+
+      /* GST_BUFFER_FLAG_DELTA_UNIT
+       * - this unit cannot be decoded independently.
+       */
       GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DELTA_UNIT);
-      // GST_BUFFER_FLAG_DELTA_UNIT
-      // - this unit cannot be decoded independently.
     }
   } else {
     GST_WARNING_OBJECT (maruenc, "codec did not provide keyframe info");
index afd8107..63e860a 100644 (file)
@@ -307,6 +307,7 @@ codec_decode_audio (CodecContext *ctx, int16_t *samples,
                     int in_size, CodecDevice *dev)
 {
   int len = 0, ret = 0;
+  int outbuf_size = 0;
   gpointer buffer = NULL;
   CodecBufferId opaque;
 
@@ -327,7 +328,7 @@ codec_decode_audio (CodecContext *ctx, int16_t *samples,
 
   opaque.buffer_index = ctx->index;
   opaque.buffer_size = SMALLDATA;
-  // FIXME: how can we know output data size ?
+
   ret = ioctl (dev->fd, CODEC_CMD_PUT_DATA_INTO_BUFFER, &opaque);
   if (ret < 0) {
     return -1;
@@ -336,8 +337,7 @@ codec_decode_audio (CodecContext *ctx, int16_t *samples,
   CODEC_LOG (DEBUG, "after decode_audio. ctx_id: %d, buffer = 0x%x\n",
             ctx->index, device_mem + opaque.buffer_size);
 
-  len =
-      codec_decode_audio_data_from (have_data, samples,
+  len =  codec_decode_audio_data_from (have_data, samples,
                                    &ctx->audio, device_mem + opaque.buffer_size);
 
   CODEC_LOG (DEBUG, "decode_audio. ctx_id: %d len: %d\n", ctx->index, len);
index 749ae64..5f76da8 100644 (file)
@@ -171,16 +171,19 @@ codec_decode_audio_data_from (int *have_data, int16_t *samples,
                               AudioData *audio, gpointer buffer)
 {
   int len = 0, size = 0;
+  int resample_size = 0;
 
   memcpy (&len, buffer, sizeof(len));
   size = sizeof(len);
   memcpy (have_data, buffer + size, sizeof(*have_data));
   size += sizeof(*have_data);
 
-  CODEC_LOG (DEBUG, "decode_audio. len %d, have_data %d\n",
-            len, (*have_data));
+  GST_DEBUG ("decode_audio. len %d, have_data %d", len, (*have_data));
 
   if (*have_data) {
+    memcpy (&audio->sample_fmt, buffer + size, sizeof(audio->sample_fmt));
+    size += sizeof(audio->sample_fmt);
+
     memcpy (&audio->sample_rate, buffer + size, sizeof(audio->sample_rate));
     size += sizeof(audio->sample_rate);
 
@@ -190,12 +193,16 @@ codec_decode_audio_data_from (int *have_data, int16_t *samples,
     memcpy (&audio->channel_layout, buffer + size, sizeof(audio->channel_layout));
     size += sizeof(audio->channel_layout);
 
-    CODEC_LOG (DEBUG, "decode_audio. sample_rate %d, channels %d, ch_layout %lld\n", audio->sample_rate, audio->channels, audio->channel_layout);
+    GST_DEBUG ("decode_audio. sample_fmt %d sample_rate %d, channels %d, ch_layout %lld",
+      audio->sample_fmt, audio->sample_rate, audio->channels, audio->channel_layout);
 
-    memcpy (samples, buffer + size, (*have_data));
+    memcpy (&resample_size, buffer + size, sizeof(resample_size));
+    size += sizeof(resample_size);
+    memcpy (samples, buffer + size, resample_size);
   }
 
-  return len;
+//  return len;
+  return resample_size;
 }
 
 void
index 9919535..787aaa7 100644 (file)
@@ -39,16 +39,21 @@ gst_maru_smpfmt_depth (int smp_fmt)
 
   switch (smp_fmt) {
   case SAMPLE_FMT_U8:
+  case SAMPLE_FMT_U8P:
     depth = 1;
     break;
   case SAMPLE_FMT_S16:
+  case SAMPLE_FMT_S16P:
     depth = 2;
     break;
   case SAMPLE_FMT_S32:
   case SAMPLE_FMT_FLT:
+  case SAMPLE_FMT_S32P:
+  case SAMPLE_FMT_FLTP:
     depth = 4;
     break;
   case SAMPLE_FMT_DBL:
+  case SAMPLE_FMT_DBLP:
     depth = 8;
     break;
   default:
@@ -905,18 +910,22 @@ gst_maru_smpfmt_to_caps (int8_t sample_fmt, CodecContext *ctx, const char *name)
 
   switch (sample_fmt) {
   case SAMPLE_FMT_S16:
+  case SAMPLE_FMT_S16P:
     signedness = TRUE;
     bpp = 16;
     break;
   case SAMPLE_FMT_S32:
+  case SAMPLE_FMT_S32P:
     signedness = TRUE;
     bpp = 32;
     break;
   case SAMPLE_FMT_FLT:
+  case SAMPLE_FMT_FLTP:
     integer = FALSE;
     bpp = 32;
     break;
   case SAMPLE_FMT_DBL:
+  case SAMPLE_FMT_DBLP:
     integer = FALSE;
     bpp = 64;
     break;
@@ -924,6 +933,8 @@ gst_maru_smpfmt_to_caps (int8_t sample_fmt, CodecContext *ctx, const char *name)
     break;
   }
 
+  GST_DEBUG ("sample format: %d", sample_fmt);
+
   if (bpp) {
     if (integer) {
       caps = gst_maru_audio_caps_new (ctx, name, "audio/x-raw-int",