brillcodec: added flush_buffer routine during decoding. 30/11730/1
authorKitae Kim <kt920.kim@samsung.com>
Mon, 4 Nov 2013 05:43:17 +0000 (14:43 +0900)
committerKitae Kim <kt920.kim@samsung.com>
Mon, 4 Nov 2013 05:43:17 +0000 (14:43 +0900)
avcodec_flush_buffers is required to reset the internal decoder state and flush internal buffers.
If there is no flush routine, decoding functions do not return picture or audio frame during seek operation.

Change-Id: I4dfbc92d82348294176b17e1c9c1238cea9146da
Signed-off-by: Kitae Kim <kt920.kim@samsung.com>
tizen/src/hw/maru_brill_codec.c
tizen/src/hw/maru_brill_codec.h

index c4da6589a812e0cd1c8c72789748e70b0ed72e78..1dd3812ac0f06d00158e9536dc4046b84547b534 100644 (file)
@@ -107,6 +107,7 @@ static bool codec_encode_video(MaruBrillCodecState *s, int ctx_id, int f_id);
 static bool codec_decode_audio(MaruBrillCodecState *s, int ctx_id, int f_id);
 static bool codec_encode_audio(MaruBrillCodecState *s, int ctx_id, int f_id);
 static bool codec_picture_copy(MaruBrillCodecState *s, int ctx_id, int f_id);
+static bool codec_flush_buffers(MaruBrillCodecState *s, int ctx_id, int f_id);
 
 typedef bool (*CodecFuncEntry)(MaruBrillCodecState *, int, int);
 static CodecFuncEntry codec_func_handler[] = {
@@ -117,6 +118,7 @@ static CodecFuncEntry codec_func_handler[] = {
     codec_encode_audio,
     codec_picture_copy,
     codec_deinit,
+    codec_flush_buffers,
 };
 
 static AVCodecParserContext *maru_brill_codec_parser_init(AVCodecContext *avctx);
@@ -233,6 +235,8 @@ static void maru_brill_codec_wakeup_threads(MaruBrillCodecState *s, int api_inde
     }
     qemu_cond_signal(&s->threadpool.cond);
     qemu_mutex_unlock(&s->context_mutex);
+
+    TRACE("after sending conditional signal\n");
 }
 
 static void *maru_brill_codec_threads(void *opaque)
@@ -1110,7 +1114,8 @@ static bool codec_init(MaruBrillCodecState *s, int ctx_id, int f_id)
             INFO("avcodec_open done: %d\n", ret);
 
             s->context[ctx_id].opened = true;
-            s->context[ctx_id].parser_ctx = maru_brill_codec_parser_init(avctx);
+            s->context[ctx_id].parser_ctx =
+                maru_brill_codec_parser_init(avctx);
         } else {
             ERR("failed to find codec.\n");
         }
@@ -1195,6 +1200,27 @@ static bool codec_deinit(MaruBrillCodecState *s, int ctx_id, int f_id)
     return true;
 }
 
+//
+static bool codec_flush_buffers(MaruBrillCodecState *s, int ctx_id, int f_id)
+{
+    AVCodecContext *avctx = NULL;
+
+    TRACE("enter: %s\n", __func__);
+
+    avctx = s->context[ctx_id].avctx;
+    if (!avctx) {
+        ERR("%d of AVCodecContext is NULL.\n", ctx_id);
+        return false;
+    } else {
+        avcodec_flush_buffers(avctx);
+        TRACE("flush %d context of buffers.\n", ctx_id);
+    }
+
+    TRACE("leave: %s\n", __func__);
+
+    return true;
+}
+
 static bool codec_decode_video(MaruBrillCodecState *s, int ctx_id, int f_id)
 {
     AVCodecContext *avctx = NULL;
@@ -1219,7 +1245,7 @@ static bool codec_decode_video(MaruBrillCodecState *s, int ctx_id, int f_id)
     size += sizeof(idx);
     memcpy(&in_offset, meta_buf + size, sizeof(in_offset));
     size += sizeof(in_offset);
-    TRACE("input buffer size: %d\n", inbuf_size);
+    TRACE("decode_video. input buffer size: %d\n", inbuf_size);
 
     elem = get_device_mem_ptr(s, f_id);
     if (elem && elem->buf) {
@@ -1247,15 +1273,18 @@ static bool codec_decode_video(MaruBrillCodecState *s, int ctx_id, int f_id)
         ERR("%d of AVCodec is NULL.\n", ctx_id);
         len = -1;
     } else {
+        // in case of skipping frames
+        picture->pict_type = -1;
+
         len = avcodec_decode_video2(avctx, picture, &got_pic_ptr, &avpkt);
         if (len < 0) {
             ERR("failed to decode video.\n");
         }
     }
 
-    TRACE("after decoding video. len: %d, have_data: %d\n", len);
+    TRACE("after decoding video. len: %d, have_data: %d\n", len, got_pic_ptr);
     if (inbuf) {
-        TRACE("decode_video input bufffer.\n");
+        TRACE("decode_video input buffer.\n");
         g_free(inbuf);
         g_free(elem);
     }
index f1bb99eca859f35c7784cfdd3d5157fb78ed3e77..313e77c29cd2bc713569d1901f17c8a29640ac19 100644 (file)
@@ -137,6 +137,7 @@ enum codec_api_type {
     CODEC_ENCODE_AUDIO,
     CODEC_PICTURE_COPY,
     CODEC_DEINIT,
+    CODEC_FLUSH_BUFFERS,
  };
 
 enum codec_type {