added flush_buffer routine in decoder. 26/11826/1
authorKitae Kim <kt920.kim@samsung.com>
Fri, 18 Oct 2013 02:51:26 +0000 (11:51 +0900)
committerKitae Kim <kt920.kim@samsung.com>
Wed, 6 Nov 2013 02:02:03 +0000 (11:02 +0900)
As flushing buffer while decoding video, it makes internal buffers of avcodec flush.
If it is not used properly, it might cause an error during seeking operation.

Change-Id: I967e566527bc5d18c88b91f0cfcc0e58cc1e120d
Signed-off-by: Kitae Kim <kt920.kim@samsung.com>
packaging/gst-plugins-emulator.changes
packaging/gst-plugins-emulator.spec
src/gstmaru.h
src/gstmarudec.c
src/gstmaruinterface.c
src/gstmaruinterface.h

index 22417e5..ffd4dc2 100644 (file)
@@ -1,3 +1,6 @@
+* Fri Oct 18 02:41:49 UTC 2013 Kitae Kim <kt920.kim@samsung.com>
+- added flush_buffer routine in decoder.
+
 * Tue Oct 15 04:51:30 UTC 2013 Kitae Kim <kt920.kim@samsung.com>
 - fixed prevent issues.
 
index df46504..a8d88be 100644 (file)
@@ -1,5 +1,5 @@
 Name: gst-plugins-emulator
-Version: 0.1.10
+Version: 0.1.11
 Release: 2 
 Summary: GStreamer Streaming-media framework plug-in for Tizen emulator.
 Group: TO_BE/FILLED_IN
index e7ab644..7075a69 100644 (file)
@@ -144,27 +144,9 @@ enum CODEC_FUNC_TYPE {
   CODEC_ENCODE_AUDIO,
   CODEC_PICTURE_COPY,
   CODEC_DEINIT,
+  CODEC_FLUSH_BUFFERS,
 };
 
-#if 0
-enum CODEC_IO_CMD {
-  CODEC_CMD_COPY_TO_DEVICE_MEM = 5,
-  CODEC_CMD_COPY_FROM_DEVICE_MEM,
-  CODEC_CMD_GET_VERSION = 20,
-  CODEC_CMD_GET_ELEMENT,
-  CODEC_CMD_GET_CONTEXT_INDEX,
-  CODEC_CMD_SECURE_MEMORY = 30,
-  CODEC_CMD_RELEASE_MEMORY,
-  CODEC_CMD_USE_DEVICE_MEM,
-  CODEC_CMD_REQ_FROM_SMALL_MEMORY,
-  CODEC_CMD_REQ_FROM_MEDIUM_MEMORY,
-  CODEC_CMD_REQ_FROM_LARGE_MEMORY,
-  CODEC_CMD_S_SECURE_BUFFER,
-  CODEC_CMD_M_SECURE_BUFFER,
-  CODEC_CMD_L_SECURE_BUFFER,
-};
-#endif
-
 enum CODEC_IO_CMD {
   CODEC_CMD_GET_VERSION = 20,
   CODEC_CMD_GET_ELEMENT,
@@ -179,7 +161,6 @@ enum CODEC_IO_CMD {
   CODEC_CMD_RELEASE_BUFFER,
 };
 
-
 enum CODEC_MEDIA_TYPE {
   AVMEDIA_TYPE_UNKNOWN = -1,
   AVMEDIA_TYPE_VIDEO,
index 0798ff4..b7d5430 100644 (file)
@@ -231,8 +231,11 @@ gst_marudec_do_qos (GstMaruDec *marudec, GstClockTime timestamp,
 //      if (marudec->waiting_for_key) {
       if (0) {
         res = FALSE;
-      } else {
       }
+#if 0
+      else {
+      }
+#endif
 
       GstClockTime stream_time, jitter;
       GstMessage *qos_msg;
@@ -299,7 +302,7 @@ gst_marudec_drain (GstMaruDec *marudec)
 
   oclass = (GstMaruDecClass *) (G_OBJECT_GET_CLASS (marudec));
 
-  // TODO: drain
+  CODEC_LOG (DEBUG, "drain frame\n");
 #if 1
   {
     gint have_data, len, try = 0;
@@ -512,12 +515,10 @@ gst_marudec_sink_event (GstPad *pad, GstEvent *event)
     break;
   case GST_EVENT_FLUSH_STOP:
   {
-#if 0
     if (marudec->opened) {
-        // TODO: what does avcodec_flush_buffers do?
-        maru_avcodec_flush_buffers (marudec->context, marudec->dev);
+      codec_flush_buffers (marudec->context, marudec->dev);
     }
-#endif
+
     gst_marudec_reset_ts (marudec);
     gst_marudec_reset_qos (marudec);
 #if 0
@@ -937,18 +938,18 @@ get_output_buffer (GstMaruDec *marudec, GstBuffer **outbuf)
     return GST_FLOW_ERROR;
   }
 
-       CODEC_LOG (DEBUG, "outbuf size of decoded video: %d\n", pict_size);
+  CODEC_LOG (DEBUG, "outbuf size of decoded video: %d\n", pict_size);
 
-       if (pict_size < (256 * 1024)) {
-  /* GstPadBufferAllocFunction is mostly overridden by elements that can
-   * provide a hardware buffer in order to avoid additional memcpy operations.
-   */
+  if (pict_size < (256 * 1024)) {
+    /* GstPadBufferAllocFunction is mostly overridden by elements that can
+     * provide a hardware buffer in order to avoid additional memcpy operations.
+     */
     gst_pad_set_bufferalloc_function(
       GST_PAD_PEER(marudec->srcpad),
       (GstPadBufferAllocFunction) codec_buffer_alloc);
-       } else {
-    CODEC_LOG (DEBUG, "request a large size of memory\n");
-       }
+  } else {
+    CODEC_LOG (DEBUG, "request large size of memory. pict_size: %d\n", pict_size);
+  }
 
   ret = gst_pad_alloc_buffer_and_set_caps (marudec->srcpad,
     GST_BUFFER_OFFSET_NONE, pict_size,
@@ -1061,11 +1062,11 @@ gst_marudec_video_frame (GstMaruDec *marudec, guint8 *data, guint size,
     codec_decode_video (marudec->context, data, size,
                           dec_info->idx, in_offset, outbuf,
                           &have_data, marudec->dev);
-
+#if 0
+  // skip_frame
   if (!decode) {
-    // skip_frame
   }
-
+#endif
   GST_DEBUG_OBJECT (marudec, "after decode: len %d, have_data %d",
     len, have_data);
 
@@ -1081,8 +1082,14 @@ gst_marudec_video_frame (GstMaruDec *marudec, guint8 *data, guint size,
 #endif
 
   if (len < 0 || have_data <= 0) {
+//  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;
   }
 
@@ -1402,12 +1409,12 @@ gst_marudec_chain (GstPad *pad, GstBuffer *buffer)
 
   discont = GST_BUFFER_IS_DISCONT (buffer);
 
-// FIXME
+  // FIXME
   if (G_UNLIKELY (discont)) {
     GST_DEBUG_OBJECT (marudec, "received DISCONT");
     gst_marudec_drain (marudec);
 //    gst_marudec_flush_pcache (marudec);
-//    maru_avcodec_flush buffers (marudec->context, marudec->dev);
+    codec_flush_buffers (marudec->context, marudec->dev);
     marudec->discont = TRUE;
     gst_marudec_reset_ts (marudec);
   }
index f86394f..a9cba6c 100644 (file)
@@ -75,13 +75,17 @@ _codec_write_to_qemu (int32_t ctx_index, int32_t api_index,
 {
   CodecIOParams ioparam;
 
+  CODEC_LOG (DEBUG, "enter: %s\n", __func__);
+
   memset(&ioparam, 0, sizeof(ioparam));
   ioparam.api_index = api_index;
   ioparam.ctx_index = ctx_index;
   ioparam.mem_offset = mem_offset;
   if (write (fd, &ioparam, 1) < 0) {
-    fprintf (stderr, "%s, failed to write copy data.\n", __func__);
+    CODEC_LOG (ERR, "failed to write input data\n");
   }
+
+  CODEC_LOG (DEBUG, "leave: %s\n", __func__);
 }
 
 static struct mem_info
@@ -129,7 +133,7 @@ secure_device_mem (guint buf_size)
 static void
 release_device_mem (gpointer start)
 {
-  int ret;     
+  int ret;
   uint32_t offset = start - device_mem;
 
   CODEC_LOG (DEBUG, "enter: %s\n", __func__);
@@ -270,6 +274,32 @@ codec_deinit (CodecContext *ctx, CodecDevice *dev)
   CODEC_LOG (DEBUG, "leave: %s\n", __func__);
 }
 
+void
+codec_flush_buffers (CodecContext *ctx, CodecDevice *dev)
+{
+  int fd;
+  void *mmapbuf = NULL;
+
+  CODEC_LOG (DEBUG, "enter: %s\n", __func__);
+
+  fd = dev->fd;
+  if (fd < 0) {
+    GST_ERROR ("failed to get %s fd.\n", CODEC_DEV);
+    return;
+  }
+
+  mmapbuf = dev->buf;
+  if (!mmapbuf) {
+    GST_ERROR ("failed to get mmaped memory address.\n");
+    return;
+  }
+
+  CODEC_LOG (DEBUG, "flush buffers. context index: %d\n", ctx->index);
+  _codec_write_to_qemu (ctx->index, CODEC_FLUSH_BUFFERS, 0, fd);
+
+  CODEC_LOG (DEBUG, "leave: %s\n", __func__);
+}
+
 int
 codec_decode_video (CodecContext *ctx, uint8_t *in_buf, int in_size,
                     gint idx, gint64 in_offset, GstBuffer **out_buf,
@@ -311,6 +341,7 @@ codec_decode_video (CodecContext *ctx, uint8_t *in_buf, int in_size,
   _codec_decode_video_inbuf (in_buf, in_size, mmapbuf + mem_offset);
 
   dev->mem_info.offset = mem_offset;
+
   _codec_write_to_qemu (ctx->index, CODEC_DECODE_VIDEO, mem_offset, fd);
 
   // after decoding video, no need to get outbuf.
@@ -345,7 +376,6 @@ codec_picture_copy (CodecContext *ctx, uint8_t *pict,
 
   CODEC_LOG (DEBUG, "pict_size: %d\n",  pict_size);
 
-//     if (pict_size < MEDIUM_BUFFER) {
   if (pict_size < (SMALL_BUFFER)) {
     dev->mem_info.offset = (uint32_t)pict - (uint32_t)mmapbuf;
     CODEC_LOG (DEBUG, "pict: %p , device_mem: %p\n",  pict, mmapbuf);
@@ -354,17 +384,16 @@ codec_picture_copy (CodecContext *ctx, uint8_t *pict,
 
   _codec_write_to_qemu (ctx->index, CODEC_PICTURE_COPY,
                         dev->mem_info.offset, fd);
-//     if (pict_size < MEDIUM_BUFFER) {
   if (pict_size < SMALL_BUFFER) {
     CODEC_LOG (DEBUG,
       "set the mem_offset as outbuf: 0x%x\n",  dev->mem_info.offset);
     ret = ioctl (fd, CODEC_CMD_USE_DEVICE_MEM, &(dev->mem_info.offset));
     if (ret < 0) {
-      // FIXME:
+    // FIXME:
     }
   } else if (pict_size < MEDIUM_BUFFER) {
     uint32_t mem_offset = 0;
-    CODEC_LOG (DEBUG, "require to use medium size of memory\n");
+    CODEC_LOG (DEBUG, "need to use medium size of memory\n");
 
     ret = ioctl (fd, CODEC_CMD_GET_DATA_FROM_MEDIUM_BUFFER, &mem_offset);
     if (ret < 0) {
@@ -376,11 +405,11 @@ codec_picture_copy (CodecContext *ctx, uint8_t *pict,
 
     ret = ioctl(fd, CODEC_CMD_RELEASE_BUFFER, &mem_offset);
     if (ret < 0) {
-      CODEC_LOG (ERR, "failed release used memory\n");
+      CODEC_LOG (ERR, "failed to release used memory\n");
     }
   } else {
     uint32_t mem_offset = 0;
-    CODEC_LOG (DEBUG, "require to use large size of memory\n");
+    CODEC_LOG (DEBUG, "need to use large size of memory\n");
 
     ret = ioctl (fd, CODEC_CMD_GET_DATA_FROM_LARGE_BUFFER, &mem_offset);
     if (ret < 0) {
@@ -392,7 +421,7 @@ codec_picture_copy (CodecContext *ctx, uint8_t *pict,
 
     ret = ioctl(fd, CODEC_CMD_RELEASE_BUFFER, &mem_offset);
     if (ret < 0) {
-      CODEC_LOG (ERR, "failed release used memory\n");
+      CODEC_LOG (ERR, "failed to release used memory\n");
     }
   }
 
index 522bf50..0a0758e 100644 (file)
@@ -65,6 +65,9 @@ void
 codec_picture_copy (CodecContext *ctx, uint8_t *pict,
                 uint32_t pict_size, CodecDevice *dev);
 
+void
+codec_flush_buffers (CodecContext *ctx, CodecDevice *dev);
+
 GstFlowReturn
 codec_buffer_alloc (GstPad *pad, guint64 offset,
                     guint size, GstCaps *caps, GstBuffer **buf);