fix encoding audio routine 26/20126/1
authorKitae Kim <kt920.kim@samsung.com>
Mon, 28 Apr 2014 08:56:38 +0000 (17:56 +0900)
committerKitae Kim <kt920.kim@samsung.com>
Mon, 28 Apr 2014 08:56:38 +0000 (17:56 +0900)
Unlike decoding, extradata has to be given from device in case of encoding.
In addition to this, chanage logging methods into gstreamer APIs.

Change-Id: I47d76ec8a2fc758ab12325c2774c22f1d119f738
Signed-off-by: Kitae Kim <kt920.kim@samsung.com>
src/gstmaru.c
src/gstmaruinterface.c
src/gstmarumem.c

index 5c692f0..e12d2b7 100644 (file)
@@ -183,7 +183,7 @@ GST_PLUGIN_DEFINE (
   "tizen-emul",
   "Codecs for Tizen Emulator",
   plugin_init,
-  "0.2.7",
+  "0.2.8",
   "LGPL",
   "gst-plugins-emulator",
   "http://www.tizen.org"
index 63e860a..27b4143 100644 (file)
@@ -68,7 +68,7 @@ _codec_invoke_qemu (int32_t ctx_index, int32_t api_index,
   ioparam.ctx_index = ctx_index;
   ioparam.mem_offset = mem_offset;
   if (ioctl (fd, CODEC_CMD_INVOKE_API_AND_RELEASE_BUFFER, &ioparam) < 0) {
-    CODEC_LOG (ERR, "failed to invoke codec APIs\n");
+    GST_ERROR ("failed to invoke codec APIs");
   }
 
   CODEC_LOG (DEBUG, "leave: %s\n", __func__);
@@ -89,7 +89,7 @@ secure_device_mem (int fd, guint ctx_id, guint buf_size, gpointer* buffer)
    *  - sets device memory offset into opaque.buffer_size
    */
   *buffer = (gpointer)((uint32_t)device_mem + opaque.buffer_size);
-  CODEC_LOG (DEBUG, "buffer: 0x%x\n", (int)buffer);
+  GST_DEBUG ("device_mem %p, offset_size 0x%x", device_mem, opaque.buffer_size);
 
   CODEC_LOG (DEBUG, "leave: %s\n", __func__);
 
@@ -104,10 +104,10 @@ release_device_mem (int fd, gpointer start)
 
   CODEC_LOG (DEBUG, "enter: %s\n", __func__);
 
-  CODEC_LOG (DEBUG, "release device_mem start: %p, offset: 0x%x\n", start, offset);
+  GST_DEBUG ("release device_mem start: %p, offset: 0x%x", start, offset);
   ret = ioctl (fd, CODEC_CMD_RELEASE_BUFFER, &offset);
   if (ret < 0) {
-    CODEC_LOG (ERR, "failed to release buffer\n");
+    GST_ERROR ("failed to release buffer\n");
   }
 
   CODEC_LOG (DEBUG, "leave: %s\n", __func__);
@@ -141,14 +141,13 @@ codec_buffer_alloc_and_copy (GstPad *pad, guint64 offset, guint size,
   opaque.buffer_index = marudec->context->index;
   opaque.buffer_size = size;
 
-  CODEC_LOG (DEBUG, "buffer_and_copy. ctx_id: %d\n", marudec->context->index);
-  _codec_invoke_qemu (marudec->context->index, CODEC_PICTURE_COPY,
-                        0, marudec->dev->fd);
+  GST_DEBUG ("buffer_and_copy. ctx_id: %d", marudec->context->index);
+  _codec_invoke_qemu (marudec->context->index, CODEC_PICTURE_COPY, 0, marudec->dev->fd);
 
   ret = ioctl (marudec->dev->fd, CODEC_CMD_PUT_DATA_INTO_BUFFER, &opaque);
 
   if (ret < 0) {
-    CODEC_LOG (DEBUG, "failed to get available buffer\n");
+    GST_DEBUG ("failed to get available buffer");
   } else if (ret == 1) {
     // FIXME: we must aligned buffer offset.
     info.start = g_malloc (size);
@@ -159,7 +158,7 @@ codec_buffer_alloc_and_copy (GstPad *pad, guint64 offset, guint size,
     memcpy (info.start, device_mem + opaque.buffer_size, size);
     release_device_mem(marudec->dev->fd, device_mem + opaque.buffer_size);
 
-    CODEC_LOG (DEBUG, "we secured last buffer, so we will use heap buffer\n");
+    GST_DEBUG ("secured last buffer!! Use heap buffer");
   } else {
     // address of "device_mem" and "opaque" is aleady aligned.
     info.start = (gpointer)(device_mem + opaque.buffer_size);
@@ -167,7 +166,7 @@ codec_buffer_alloc_and_copy (GstPad *pad, guint64 offset, guint size,
 
     GST_BUFFER_FREE_FUNC (*buf) = codec_buffer_free;
 
-    CODEC_LOG (DEBUG, "device memory start: 0x%p, offset 0x%x\n", info.start, info.offset);
+    GST_DEBUG ("device memory start: 0x%p, offset 0x%x", info.start, info.offset);
   }
 
   GST_BUFFER_DATA (*buf) = GST_BUFFER_MALLOCDATA (*buf) = info.start;
@@ -193,18 +192,16 @@ codec_init (CodecContext *ctx, CodecElement *codec, CodecDevice *dev)
   CODEC_LOG (DEBUG, "enter: %s\n", __func__);
 
   if (ioctl(dev->fd, CODEC_CMD_GET_CONTEXT_INDEX, &ctx->index) < 0) {
-    CODEC_LOG (ERR,
-      "[%s] failed to get a context index\n", __func__);
+    GST_ERROR ("failed to get a context index");
     return -1;
   }
-  CODEC_LOG (DEBUG, "get context index: %d\n", ctx->index);
+  GST_DEBUG ("get context index: %d", ctx->index);
 
   /* buffer size is 0. It means that this function is required to
    * use small size.
   */
   if (secure_device_mem(dev->fd, ctx->index, 0, &buffer) < 0) {
-    CODEC_LOG (ERR,
-      "[%s] failed to get a memory block\n", __func__);
+    GST_ERROR ("failed to get a memory block");
     return -1;
   }
 
@@ -217,8 +214,7 @@ codec_init (CodecContext *ctx, CodecElement *codec, CodecDevice *dev)
   opaque.buffer_size = SMALLDATA;
 
   if (ioctl (dev->fd, CODEC_CMD_PUT_DATA_INTO_BUFFER, &opaque) < 0) {
-    CODEC_LOG (ERR,
-      "[%s] failed to accquire a memory block\n", __func__);
+    GST_ERROR ("failed to accquire a memory block");
     return -1;
   }
 
@@ -226,7 +222,7 @@ codec_init (CodecContext *ctx, CodecElement *codec, CodecDevice *dev)
     codec_init_data_from (ctx, codec->media_type, device_mem + opaque.buffer_size);
 
   if (opened < 0) {
-    CODEC_LOG (ERR, "failed to open Context for %s\n", codec->name);
+    GST_ERROR ("failed to open Context for %s", codec->name);
   } else {
     ctx->codec = codec;
   }
@@ -243,7 +239,7 @@ codec_deinit (CodecContext *ctx, CodecDevice *dev)
 {
   CODEC_LOG (DEBUG, "enter: %s\n", __func__);
 
-  CODEC_LOG (INFO, "close. context index: %d\n", ctx->index);
+  GST_INFO ("close context %d", ctx->index);
   _codec_invoke_qemu (ctx->index, CODEC_DEINIT, 0, dev->fd);
 
   CODEC_LOG (DEBUG, "leave: %s\n", __func__);
@@ -254,7 +250,7 @@ codec_flush_buffers (CodecContext *ctx, CodecDevice *dev)
 {
   CODEC_LOG (DEBUG, "enter: %s\n", __func__);
 
-  CODEC_LOG (DEBUG, "flush buffers. context index: %d\n", ctx->index);
+  GST_DEBUG ("flush buffers of context: %d", ctx->index);
   _codec_invoke_qemu (ctx->index, CODEC_FLUSH_BUFFERS, 0, dev->fd);
 
   CODEC_LOG (DEBUG, "leave: %s\n", __func__);
@@ -273,8 +269,7 @@ codec_decode_video (CodecContext *ctx, uint8_t *in_buf, int in_size,
 
   ret = secure_device_mem(dev->fd, ctx->index, in_size, &buffer);
   if (ret < 0) {
-    CODEC_LOG (ERR,
-      "decode_video. failed to get available memory to write inbuf\n");
+    GST_ERROR ("failed to get available memory to write inbuf");
     return -1;
   }
 
@@ -287,8 +282,7 @@ codec_decode_video (CodecContext *ctx, uint8_t *in_buf, int in_size,
   opaque.buffer_size = SMALLDATA;
 
   if (ioctl (dev->fd, CODEC_CMD_PUT_DATA_INTO_BUFFER, &opaque) < 0) {
-    CODEC_LOG (ERR,
-      "[%s] failed to accquire a memory block\n", __func__);
+    GST_ERROR ("failed to accquire a memory block");
     return -1;
   }
 
@@ -307,7 +301,6 @@ 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;
 
@@ -315,12 +308,11 @@ codec_decode_audio (CodecContext *ctx, int16_t *samples,
 
   ret = secure_device_mem(dev->fd, ctx->index, in_size, &buffer);
   if (ret < 0) {
-    CODEC_LOG (ERR,
-      "decode_audio. failed to get available memory to write inbuf\n");
+    GST_ERROR ("failed to get available memory to write inbuf");
     return -1;
   }
 
-  CODEC_LOG (DEBUG, "decode_audio. in_buffer size %d\n", in_size);
+  GST_DEBUG ("decode_audio 1. in_buffer size %d", in_size);
   codec_decode_audio_data_to (in_size, in_buf, buffer);
 
   dev->mem_info.offset = GET_OFFSET(buffer);
@@ -334,13 +326,13 @@ codec_decode_audio (CodecContext *ctx, int16_t *samples,
     return -1;
   }
 
-  CODEC_LOG (DEBUG, "after decode_audio. ctx_id: %d, buffer = 0x%x\n",
-            ctx->index, device_mem + opaque.buffer_size);
+  GST_DEBUG ("decode_audio 2. ctx_id: %d, buffer = 0x%x",
+    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);
+  GST_DEBUG ("decode_audio 3. ctx_id: %d len: %d", ctx->index, len);
 
   release_device_mem(dev->fd, device_mem + opaque.buffer_size);
 
@@ -364,7 +356,7 @@ codec_encode_video (CodecContext *ctx, uint8_t *out_buf,
 
   ret = secure_device_mem(dev->fd, ctx->index, in_size, &buffer);
   if (ret < 0) {
-    CODEC_LOG (ERR, "failed to small size of buffer.\n");
+    GST_ERROR ("failed to small size of buffer");
     return -1;
   }
 
@@ -380,7 +372,7 @@ codec_encode_video (CodecContext *ctx, uint8_t *out_buf,
   if (ret < 0) {
     return -1;
   }
-  CODEC_LOG (DEBUG, "encode_video. mem_offset = 0x%x\n", opaque.buffer_size);
+  GST_DEBUG ("encode_video. mem_offset = 0x%x", opaque.buffer_size);
 
   len = codec_encode_video_data_from (out_buf, coded_frame, is_keyframe, device_mem + opaque.buffer_size);
   dev->mem_info.offset = opaque.buffer_size;
@@ -415,13 +407,13 @@ codec_encode_audio (CodecContext *ctx, uint8_t *out_buf,
 
   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;
   }
 
-  CODEC_LOG (DEBUG, "encode_video. mem_offset = 0x%x\n", opaque.buffer_size);
+  GST_DEBUG ("encode_audio. mem_offset = 0x%x", opaque.buffer_size);
 
   len = codec_encode_audio_data_from (out_buf, device_mem + opaque.buffer_size);
 
index 5f76da8..0e1e01a 100644 (file)
@@ -40,7 +40,8 @@ _codec_info_data (CodecElement *codec, gpointer buffer)
 
   CODEC_LOG (DEBUG, "enter, %s\n", __func__);
 
-  CODEC_LOG (DEBUG, "type: %d, name: %s\n", codec->codec_type, codec->name);
+  GST_INFO ("type: %d, name: %s", codec->codec_type, codec->name);
+
   memcpy (buffer + size, &codec->codec_type, sizeof(codec->codec_type));
   size += sizeof(codec->codec_type);
 
@@ -61,8 +62,8 @@ codec_init_data_to (CodecContext *ctx, CodecElement *codec, gpointer buffer)
 
   size = _codec_info_data (codec, buffer);
 
-  CODEC_LOG (INFO, "context_id: %d, name: %s, media type: %s\n",
-    ctx->index, codec->name, codec->media_type ? "AUDIO" : "VIDEO");
+  GST_INFO ("context_id: %d, name: %s, media type: %s",
+    ctx->index, codec->name, codec->media_type ? "audio" : "video");
 
   memcpy (buffer + size, ctx, sizeof(CodecContext) - 12);
   size += (sizeof(CodecContext) - 12);
@@ -81,8 +82,6 @@ codec_init_data_from (CodecContext *ctx, int media_type, gpointer buffer)
 {
   int ret = 0, size = 0;
 
-  CODEC_LOG (DEBUG, "after init. read data from device.\n");
-
   memcpy (&ret, buffer, sizeof(ret));
   size = sizeof(ret);
   if (ret < 0) {
@@ -96,15 +95,21 @@ codec_init_data_from (CodecContext *ctx, int media_type, gpointer buffer)
       size += sizeof(ctx->audio.frame_size);
 
       memcpy(&ctx->audio.bits_per_sample_fmt, buffer + size, sizeof(ctx->audio.bits_per_sample_fmt));
-#if 0
-      // TODO: check!!
-      memcpy (&ctx->audio, buffer + size, sizeof(ctx->audio));
-#endif
-    } else {
-      CODEC_LOG (DEBUG, "video type\n");
+      size += sizeof(ctx->audio.bits_per_sample_fmt);
     }
   }
 
+#if 1
+  memcpy(&ctx->codecdata_size, buffer + size, sizeof(ctx->codecdata_size));
+  size += sizeof(ctx->codecdata_size);
+
+  GST_DEBUG ("codec_init. extradata_size %d", ctx->codecdata_size);
+  if (ctx->codecdata_size > 0) {
+    ctx->codecdata = g_malloc(ctx->codecdata_size);
+    memcpy(ctx->codecdata, buffer + size, ctx->codecdata_size);
+  }
+#endif
+
   return ret;
 }
 
@@ -144,7 +149,7 @@ codec_decode_video_data_from (int *got_picture_ptr, VideoData *video, gpointer b
   size += sizeof(*got_picture_ptr);
   memcpy (video, buffer + size, sizeof(VideoData));
 
-  CODEC_LOG (DEBUG, "decode_video. len: %d, have_data: %d\n", len, *got_picture_ptr);
+  GST_DEBUG ("decode_video. len: %d, have_data: %d", len, *got_picture_ptr);
 
   return len;
 }
@@ -233,7 +238,8 @@ codec_encode_video_data_from (uint8_t *out_buf, int *coded_frame, int *is_keyfra
   memcpy (&len, buffer, sizeof(len));
   size = sizeof(len);
 
-  CODEC_LOG (DEBUG, "encode_video. outbuf size: %d\n", len);
+  GST_DEBUG ("encode_video. outbuf size: %d", len);
+
   if (len > 0) {
     memcpy (coded_frame, buffer + size, sizeof(int));
     size += sizeof(int);
@@ -278,7 +284,7 @@ codec_encode_audio_data_from (uint8_t *out_buf, gpointer buffer)
     memcpy (out_buf, buffer + size, len);
   }
 
-  CODEC_LOG (DEBUG, "encode_audio. outbuf size: %d\n", len);
+  GST_DEBUG ("encode_audio. outbuf size: %d", len);
 
   return len;
 }