[FFmpeg-cvslog] nuv: return meaningful error codes.

Anton Khirnov git at videolan.org
Mon Nov 4 19:06:57 CET 2013


ffmpeg | branch: release/0.10 | Anton Khirnov <anton at khirnov.net> | Sat Nov 17 18:07:42 2012 +0100| [d2eddcfc833fc55dfa447376f4c30e46851c3242] | committer: Luca Barbato

nuv: return meaningful error codes.

(cherry picked from commit 3344f5cb747bb1f54cc34878b66dc0536f194720)
Signed-off-by: Luca Barbato <lu_zero at gentoo.org>

Conflicts:
	libavcodec/nuv.c

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=d2eddcfc833fc55dfa447376f4c30e46851c3242
---

 libavcodec/nuv.c |   30 +++++++++++++++++-------------
 1 file changed, 17 insertions(+), 13 deletions(-)

diff --git a/libavcodec/nuv.c b/libavcodec/nuv.c
index 459fd27..9b275e8 100644
--- a/libavcodec/nuv.c
+++ b/libavcodec/nuv.c
@@ -84,7 +84,7 @@ static int get_quant(AVCodecContext *avctx, NuvContext *c,
     int i;
     if (size < 2 * 64 * 4) {
         av_log(avctx, AV_LOG_ERROR, "insufficient rtjpeg quant data\n");
-        return -1;
+        return AVERROR_INVALIDDATA;
     }
     for (i = 0; i < 64; i++, buf += 4)
         c->lq[i] = AV_RL32(buf);
@@ -107,25 +107,27 @@ static void get_quant_quality(NuvContext *c, int quality) {
 
 static int codec_reinit(AVCodecContext *avctx, int width, int height, int quality) {
     NuvContext *c = avctx->priv_data;
+    int ret;
+
     width  = FFALIGN(width,  2);
     height = FFALIGN(height, 2);
     if (quality >= 0)
         get_quant_quality(c, quality);
     if (width != c->width || height != c->height) {
-        if (av_image_check_size(height, width, 0, avctx) < 0)
-            return 0;
+        if ((ret = av_image_check_size(height, width, 0, avctx)) < 0)
+            return ret;
         avctx->width = c->width = width;
         avctx->height = c->height = height;
         av_fast_malloc(&c->decomp_buf, &c->decomp_size, c->height * c->width * 3 / 2 +
                        FF_INPUT_BUFFER_PADDING_SIZE);
         if (!c->decomp_buf) {
             av_log(avctx, AV_LOG_ERROR, "Can't allocate decompression buffer.\n");
-            return 0;
+            return AVERROR(ENOMEM);
         }
         rtjpeg_decode_init(&c->rtj, &c->dsp, c->width, c->height, c->lq, c->cq);
     } else if (quality != c->quality)
         rtjpeg_decode_init(&c->rtj, &c->dsp, c->width, c->height, c->lq, c->cq);
-    return 1;
+    return 0;
 }
 
 static int decode_frame(AVCodecContext *avctx, void *data, int *data_size,
@@ -143,7 +145,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size,
 
     if (buf_size < 12) {
         av_log(avctx, AV_LOG_ERROR, "coded frame too small\n");
-        return -1;
+        return AVERROR_INVALIDDATA;
     }
 
     // codec data (rtjpeg quant tables)
@@ -161,7 +163,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size,
 
     if (buf[0] != 'V' || buf_size < 12) {
         av_log(avctx, AV_LOG_ERROR, "not a nuv video frame\n");
-        return -1;
+        return AVERROR_INVALIDDATA;
     }
     comptype = buf[1];
     switch (comptype) {
@@ -196,8 +198,8 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size,
         w = AV_RL16(&buf[6]);
         h = AV_RL16(&buf[8]);
         q = buf[10];
-        if (!codec_reinit(avctx, w, h, q))
-            return -1;
+        if ((result = codec_reinit(avctx, w, h, q)) < 0)
+            return result;
         buf = &buf[RTJPEG_HEADER_SIZE];
         buf_size -= RTJPEG_HEADER_SIZE;
     }
@@ -210,7 +212,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size,
     result = avctx->reget_buffer(avctx, &c->pic);
     if (result < 0) {
         av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
-        return -1;
+        return result;
     }
 
     c->pic.pict_type = keyframe ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P;
@@ -244,7 +246,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size,
         }
         default:
             av_log(avctx, AV_LOG_ERROR, "unknown compression\n");
-            return -1;
+            return AVERROR_INVALIDDATA;
     }
 
     *picture = c->pic;
@@ -254,6 +256,8 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size,
 
 static av_cold int decode_init(AVCodecContext *avctx) {
     NuvContext *c = avctx->priv_data;
+    int ret;
+
     avctx->pix_fmt = PIX_FMT_YUV420P;
     c->pic.data[0] = NULL;
     c->decomp_buf = NULL;
@@ -264,8 +268,8 @@ static av_cold int decode_init(AVCodecContext *avctx) {
     if (avctx->extradata_size)
         get_quant(avctx, c, avctx->extradata, avctx->extradata_size);
     dsputil_init(&c->dsp, avctx);
-    if (!codec_reinit(avctx, avctx->width, avctx->height, -1))
-        return 1;
+    if ((ret = codec_reinit(avctx, avctx->width, avctx->height, -1)) < 0)
+        return ret;
     return 0;
 }
 



More information about the ffmpeg-cvslog mailing list