[FFmpeg-devel] [PATCH 2/3] libutvideo: Misc fixes

Derek Buitenhuis derek.buitenhuis at gmail.com
Mon Nov 7 05:51:48 CET 2011


A few misc fixes:
    - Fix a typo or two.
    - Add missing checks.
    - Replace a silly 4*4 with an actual sizeof()
    - Remove the lossless flag for the capabilities,
      as this is a decoder.
    - Make buf_size local instead of in
      UtVideoContext.
    - w and h don't need to be unsigned.

Signed-off-by: Derek Buitenhuis <derek.buitenhuis at gmail.com>
---
 libavcodec/libutvideo.cpp |   31 ++++++++++++++++++++-----------
 1 files changed, 20 insertions(+), 11 deletions(-)

diff --git a/libavcodec/libutvideo.cpp b/libavcodec/libutvideo.cpp
index 3c78f45..f27af7e 100644
--- a/libavcodec/libutvideo.cpp
+++ b/libavcodec/libutvideo.cpp
@@ -37,13 +37,12 @@ extern "C" {
 typedef struct {
     uint32_t version;
     uint32_t original_format;
-    uint32_t stripes;
+    uint32_t info_size;
     uint32_t flags;
 } UtVideoExtra;
 
 typedef struct {
     CCodec *codec;
-    unsigned int buf_size;
     uint8_t *output;
 } UtVideoContext;
 
@@ -52,8 +51,10 @@ static av_cold int utvideo_decode_init(AVCodecContext *avctx)
     UtVideoContext *utv = (UtVideoContext *)avctx->priv_data;
     UtVideoExtra info;
     int format;
+    int begin_ret;
+    unsigned int buf_size;
 
-    if(avctx->extradata_size != 4*4)
+    if(avctx->extradata_size != sizeof(UtVideoExtra))
     {
         av_log(avctx, AV_LOG_ERROR, "Extradata size mismatch.\n");
         return -1;
@@ -61,8 +62,8 @@ static av_cold int utvideo_decode_init(AVCodecContext *avctx)
 
     /* Read extradata */
     info.version = AV_RL32(avctx->extradata);
-    info.original_format = AV_RL32(avctx->extradata + 4);
-    info.stripes = AV_RL32(avctx->extradata + 8);
+    info.original_format = AV_RB32(avctx->extradata + 4);
+    info.info_size = AV_RL32(avctx->extradata + 8);
     info.flags = AV_RL32(avctx->extradata + 12);
 
     /* Pick format based on FOURCC */
@@ -91,8 +92,8 @@ static av_cold int utvideo_decode_init(AVCodecContext *avctx)
     }
 
     /* Only allocate the buffer once */
-    utv->buf_size = avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height);
-    utv->output = (uint8_t *)av_malloc(utv->buf_size * sizeof(uint8_t));
+    buf_size = avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height);
+    utv->output = (uint8_t *)av_malloc(buf_size * sizeof(uint8_t));
 
     if(utv->output == NULL)
     {
@@ -100,7 +101,7 @@ static av_cold int utvideo_decode_init(AVCodecContext *avctx)
         return -1;
     }
 
-    /* Allocate the output frame  */
+    /* Allocate the output frame */
     avctx->coded_frame = avcodec_alloc_frame();
 
     /* Ut Video only supports 8-bit */
@@ -119,9 +120,17 @@ static av_cold int utvideo_decode_init(AVCodecContext *avctx)
     utv->codec = CCodec::CreateInstance(UNFCC(avctx->codec_tag), "libavcodec");
 
     /* Initialize Decoding */
-    utv->codec->DecodeBegin(format, avctx->width, avctx->height,
+    begin_ret = utv->codec->DecodeBegin(format, avctx->width, avctx->height,
                             CBGROSSWIDTH_WINDOWS, &info, sizeof(UtVideoExtra));
 
+    /* Check to see if the decoder initlized properly */
+    if(begin_ret != 0)
+    {
+        av_log(avctx, AV_LOG_ERROR,
+               "Could not initialize decoder: %d\n", begin_ret);
+        return -1;
+    }
+
     return 0;
 }
 
@@ -130,7 +139,7 @@ static int utvideo_decode_frame(AVCodecContext *avctx, void *data,
 {
     UtVideoContext *utv = (UtVideoContext *)avctx->priv_data;
     AVFrame *pic = avctx->coded_frame;
-    unsigned int w = avctx->width, h = avctx->height;
+    int w = avctx->width, h = avctx->height;
 
     /* Set flags */
     pic->reference = 0;
@@ -192,7 +201,7 @@ AVCodec ff_libutvideo_decoder = {
     NULL,
     utvideo_decode_close,
     utvideo_decode_frame,
-    CODEC_CAP_LOSSLESS,
+    NULL,
     NULL,
     NULL,
     NULL,
-- 
1.7.7.1



More information about the ffmpeg-devel mailing list