brillcodec: enhance exception handling 65/26565/2
authorSeokYeon Hwang <syeon.hwang@samsung.com>
Tue, 26 Aug 2014 09:24:42 +0000 (18:24 +0900)
committerSeokYeon Hwang <syeon.hwang@samsung.com>
Thu, 28 Aug 2014 03:50:06 +0000 (12:50 +0900)
Enhance exception handling if no picture was got.
Fix bug when using old decode API.

Change-Id: I6ea97ead1c0be7c672fa478c5f4bd971cfb6e3f9
Signed-off-by: SeokYeon Hwang <syeon.hwang@samsung.com>
tizen/src/hw/pci/maru_brillcodec.c
tizen/src/hw/pci/maru_brillcodec_plugin.h
tizen/src/hw/pci/maru_brillcodec_vaapi.c

index 4bd4308..c0fc77f 100644 (file)
@@ -164,12 +164,13 @@ static DataHandler default_data_handler = {
 static void copy_picture(void *dst, void *opaque, size_t size)
 {
     DataContainer *dc = (DataContainer *)opaque;
+
     if (dc->len_data_buffer) {
         memcpy(dst, dc->data_buffer, dc->len_data_buffer);
     }
     if (dc->frame) {
-        avpicture_layout((AVPicture *)dc->frame, PIX_FMT_YUV420P, dc->frame->width, dc->frame->height,
-                dst + OFFSET_PICTURE_BUFFER, size - OFFSET_PICTURE_BUFFER); // FIXME
+        avpicture_layout((AVPicture *)dc->frame, dc->pix_fmt, dc->frame->width, dc->frame->height,
+                dst + dc->picture_buffer_offset, size - dc->picture_buffer_offset); // FIXME
     }
 }
 
@@ -1213,37 +1214,42 @@ static bool codec_decode_video2(MaruBrillCodecState *s, int ctx_id, void *data_b
         memcpy(tempbuf + size, &got_picture, sizeof(got_picture));
         size += sizeof(got_picture);
         if (avctx) {
-            avctx->pix_fmt = AV_PIX_FMT_YUV420P; // FIXME
             deserialize_video_data(avctx, &video);
             memcpy(tempbuf + size, &video, sizeof(struct video_data));
         }
     }
 
-    TRACE("decoded image. pix_fmt: %d width: %d, height: %d\n",
-            avctx->pix_fmt, avctx->width, avctx->height);
-    int pict_size = avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height);
+    TRACE("decoded image. len: %d got_picture: %d pix_fmt: %d width: %d, height: %d\n",
+            len, got_picture, avctx->pix_fmt, avctx->width, avctx->height);
+
+    int pict_size = 0;
     bool ret = true;
 
-    if ((pict_size) < 0) {
-        ERR("picture size: %d\n", pict_size);
-        ret = false;
-    } else {
-        TRACE("picture size: %d\n", pict_size);
+    DataContainer *dc = g_malloc0(sizeof(DataContainer));
+    dc->data_buffer = tempbuf;
+    dc->len_data_buffer = tempbuf_size;
+    dc->picture_buffer_offset = OFFSET_PICTURE_BUFFER;
 
-        DataContainer *dc = g_malloc0(sizeof(DataContainer));
-        dc->data_buffer = tempbuf;
-        dc->len_data_buffer = tempbuf_size;
-        if (got_picture) {
-            dc->frame = picture;
-        }
+    if (got_picture) {
+        pict_size = avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height);
 
-        if (CONTEXT(s, ctx_id)->is_hwaccel) {
-            brillcodec_push_write_queue(s, dc, OFFSET_PICTURE_BUFFER + pict_size, ctx_id, s->hwaccel_plugin->video_decode_data_handler);
+        if ((pict_size) < 0) {
+            ERR("picture size: %d\n", pict_size);
+            ret = false;
         } else {
-            brillcodec_push_write_queue(s, dc, OFFSET_PICTURE_BUFFER + pict_size, ctx_id, &default_video_decode_data_handler);
+            TRACE("picture size: %d\n", pict_size);
+
+            dc->frame = picture;
+            dc->pix_fmt = avctx->pix_fmt;
         }
     }
 
+    if (CONTEXT(s, ctx_id)->is_hwaccel) {
+        brillcodec_push_write_queue(s, dc, dc->picture_buffer_offset + pict_size, ctx_id, s->hwaccel_plugin->video_decode_data_handler);
+    } else {
+        brillcodec_push_write_queue(s, dc, dc->picture_buffer_offset + pict_size, ctx_id, &default_video_decode_data_handler);
+    }
+
     TRACE("leave: %s\n", __func__);
 
     return ret;
@@ -1328,7 +1334,6 @@ static bool codec_decode_video(MaruBrillCodecState *s, int ctx_id, void *data_bu
         memcpy(tempbuf + size, &got_picture, sizeof(got_picture));
         size += sizeof(got_picture);
         if (avctx) {
-            avctx->pix_fmt = AV_PIX_FMT_YUV420P; // FIXME
             deserialize_video_data(avctx, &video);
             memcpy(tempbuf + size, &video, sizeof(struct video_data));
         }
@@ -1377,6 +1382,7 @@ static bool codec_picture_copy (MaruBrillCodecState *s, int ctx_id, void *elem)
 
             DataContainer *dc = g_malloc0(sizeof(DataContainer));
             dc->frame = frame;
+            dc->pix_fmt = avctx->pix_fmt;
 
             if (CONTEXT(s, ctx_id)->is_hwaccel) {
                 brillcodec_push_write_queue(s, dc, pict_size, ctx_id, s->hwaccel_plugin->video_decode_data_handler);
index 4133c91..dc6c2cd 100644 (file)
 typedef struct DataContainer {
     void *data_buffer;
     size_t len_data_buffer;
+    size_t picture_buffer_offset;
 
     AVFrame *frame;
+    enum AVPixelFormat pix_fmt;
 } DataContainer;
 
 typedef struct DataHandler {
index c6e16f4..56a7223 100644 (file)
@@ -304,7 +304,7 @@ static void vaapi_extract(void *dst, void *opaque, size_t size)
         memcpy(dst, dc->data_buffer, dc->len_data_buffer);
     }
     if (dc->frame) {
-        extract(dc->frame, dst + OFFSET_PICTURE_BUFFER, size - OFFSET_PICTURE_BUFFER);
+        extract(dc->frame, dst + dc->picture_buffer_offset, size - dc->picture_buffer_offset);
     }
 }