brillcodec: fix encoding video routine 19/17319/1
authorKitae Kim <kt920.kim@samsung.com>
Wed, 19 Feb 2014 03:26:35 +0000 (12:26 +0900)
committerKitae Kim <kt920.kim@samsung.com>
Thu, 6 Mar 2014 09:44:03 +0000 (18:44 +0900)
Checking the length of encoded video was wrong.
It causes that emulator gets SEGV when encoding video.

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

index 35262f5..6b6bfd4 100644 (file)
@@ -1468,15 +1468,16 @@ static bool codec_encode_video(MaruBrillCodecState *s, int ctx_id, void *data_bu
     } else if (!avctx->codec) {
         ERR("%d of AVCodec is NULL.\n", ctx_id);
     } else {
-        TRACE("pixel format: %d inbuf: %p, picture data: %p\n",
-            avctx->pix_fmt, inbuf, pict->data[0]);
-
         ret =
             maru_brill_codec_get_picture_size((AVPicture *)pict, inbuf,
                                             avctx->pix_fmt, avctx->width,
                                             avctx->height, true);
+
+        TRACE("pixel format %d inbuf %p, picture data %p pict_size %d\n",
+            avctx->pix_fmt, inbuf, pict->data[0], ret);
+
         if (ret < 0) {
-            ERR("after avpicture_fill, ret:%d\n", ret);
+            ERR("invalid picture size\n");
         } else {
             if (avctx->time_base.num == 0) {
                 pict->pts = AV_NOPTS_VALUE;
@@ -1493,19 +1494,19 @@ static bool codec_encode_video(MaruBrillCodecState *s, int ctx_id, void *data_bu
             if (!outbuf) {
                 ERR("failed to allocate a buffer of encoding video.\n");
             } else {
-                TRACE("before encode video, ticks_per_frame:%d, pts:%lld\n",
+                TRACE("encode video 1. ticks_per_frame:%d, pts:%lld\n",
                     avctx->ticks_per_frame, pict->pts);
 
                 len = avcodec_encode_video(avctx, outbuf, outbuf_size, pict);
 
-                TRACE("encode video. len %d pts %lld  outbuf size %d\n",
+                TRACE("encode video 2. len %d pts %lld  outbuf size %d\n",
                     len, pict->pts, outbuf, outbuf_size);
                 // TODO: check requested_close ?
             }
         }
     }
 
-    tempbuf_size = sizeof(len) + len;
+    tempbuf_size = sizeof(len);
     if (len < 0) {
         ERR("failed to encode audio. ctx_id: %d len: %d\n", ctx_id, len);
     } else {
@@ -1519,7 +1520,7 @@ static bool codec_encode_video(MaruBrillCodecState *s, int ctx_id, void *data_bu
     } else {
         memcpy(tempbuf, &len, sizeof(len));
         size = sizeof(len);
-        if (len && outbuf) {
+        if ((len > 0) && outbuf) {
             memcpy(tempbuf + size, outbuf, len);
         }
     }
@@ -1595,7 +1596,7 @@ static bool codec_encode_audio(MaruBrillCodecState *s, int ctx_id, void *data_bu
     } else {
         memcpy(tempbuf, &len, sizeof(len));
         size = sizeof(len);
-        if (len && outbuf) {
+        if ((len > 0) && outbuf) {
             memcpy(tempbuf + size, outbuf, len);
         }
     }