[FFmpeg-devel] [PATCH] lavc/mpeg12: return more meaningful error codes

Stefano Sabatini stefasab at gmail.com
Sat Jun 30 00:07:56 CEST 2012


Perform partial error code cleanup, still returning -1 in many places and
there are still missing error code checks in other.
---
 libavcodec/mpeg12.c |   33 +++++++++++++++++----------------
 1 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c
index 697eebb..e248728 100644
--- a/libavcodec/mpeg12.c
+++ b/libavcodec/mpeg12.c
@@ -144,7 +144,7 @@ static inline int mpeg1_decode_block_intra(MpegEncContext *s, DCTELEM *block, in
             }
             if (i > 63) {
                 av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y);
-                return -1;
+                return AVERROR_INVALIDDATA;
             }
 
             block[j] = level;
@@ -219,7 +219,7 @@ static inline int mpeg1_decode_block_inter(MpegEncContext *s, DCTELEM *block, in
             }
             if (i > 63) {
                 av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y);
-                return -1;
+                return AVERROR_INVALIDDATA;
             }
 
             block[j] = level;
@@ -367,7 +367,7 @@ static inline int mpeg2_decode_block_non_intra(MpegEncContext *s, DCTELEM *block
             }
             if (i > 63) {
                 av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y);
-                return -1;
+                return AVERROR_INVALIDDATA;
             }
 
             mismatch ^= level;
@@ -512,7 +512,7 @@ static inline int mpeg2_decode_block_intra(MpegEncContext *s, DCTELEM *block, in
             }
             if (i > 63) {
                 av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y);
-                return -1;
+                return AVERROR_INVALIDDATA;
             }
 
             mismatch ^= level;
@@ -1244,6 +1244,7 @@ static int mpeg_decode_postinit(AVCodecContext *avctx)
     Mpeg1Context *s1 = avctx->priv_data;
     MpegEncContext *s = &s1->mpeg_enc_ctx;
     uint8_t old_permutation[64];
+    int ret;
 
     if ((s1->mpeg_enc_ctx_allocated == 0) ||
         avctx->coded_width  != s->width   ||
@@ -1263,7 +1264,7 @@ static int mpeg_decode_postinit(AVCodecContext *avctx)
         }
 
         if ((s->width == 0) || (s->height == 0))
-            return -2;
+            return AVERROR_INVALIDDATA;
 
         avcodec_set_dimensions(avctx, s->width, s->height);
         avctx->bit_rate          = s->bit_rate;
@@ -1335,8 +1336,8 @@ static int mpeg_decode_postinit(AVCodecContext *avctx)
          * if DCT permutation is changed. */
         memcpy(old_permutation, s->dsp.idct_permutation, 64 * sizeof(uint8_t));
 
-        if (ff_MPV_common_init(s) < 0)
-            return -2;
+        if ((ret = ff_MPV_common_init(s)) < 0)
+            return ret;
 
         quant_matrix_rebuild(s->intra_matrix,        old_permutation, s->dsp.idct_permutation);
         quant_matrix_rebuild(s->inter_matrix,        old_permutation, s->dsp.idct_permutation);
@@ -1695,7 +1696,7 @@ static int mpeg_decode_slice(MpegEncContext *s, int mb_y,
 
     if (s->qscale == 0) {
         av_log(s->avctx, AV_LOG_ERROR, "qscale == 0\n");
-        return -1;
+        return AVERROR(EINVAL);
     }
 
     /* extra slice info */
@@ -1712,7 +1713,7 @@ static int mpeg_decode_slice(MpegEncContext *s, int mb_y,
             int code = get_vlc2(&s->gb, mbincr_vlc.table, MBINCR_VLC_BITS, 2);
             if (code < 0) {
                 av_log(s->avctx, AV_LOG_ERROR, "first mb_incr damaged\n");
-                return -1;
+                return AVERROR_INVALIDDATA;
             }
             if (code >= 33) {
                 if (code == 33) {
@@ -1728,7 +1729,7 @@ static int mpeg_decode_slice(MpegEncContext *s, int mb_y,
 
     if (s->mb_x >= (unsigned)s->mb_width) {
         av_log(s->avctx, AV_LOG_ERROR, "initial skip overflow\n");
-        return -1;
+        return AVERROR_INVALIDDATA;
     }
 
     if (avctx->hwaccel) {
@@ -1766,7 +1767,7 @@ static int mpeg_decode_slice(MpegEncContext *s, int mb_y,
             ff_xvmc_init_block(s); // set s->block
 
         if (mpeg_decode_mb(s, s->block) < 0)
-            return -1;
+            return AVERROR_INVALIDDATA;
 
         if (s->current_picture.f.motion_val[0] && !s->encoding) { // note motion_val is normally NULL unless we want to extract the MVs
             const int wrap = s->b8_stride;
@@ -1823,7 +1824,7 @@ static int mpeg_decode_slice(MpegEncContext *s, int mb_y,
                 if (left < 0 || (left && show_bits(&s->gb, FFMIN(left, 23)) && !is_d10)
                     || ((avctx->err_recognition & (AV_EF_BITSTREAM | AV_EF_AGGRESSIVE)) && left > 8)) {
                     av_log(avctx, AV_LOG_ERROR, "end mismatch left=%d %0X\n", left, show_bits(&s->gb, FFMIN(left, 23)));
-                    return -1;
+                    return AVERROR_INVALIDDATA;
                 } else
                     goto eos;
             }
@@ -1847,7 +1848,7 @@ static int mpeg_decode_slice(MpegEncContext *s, int mb_y,
                     } else if (code == 35) {
                         if (s->mb_skip_run != 0 || show_bits(&s->gb, 15) != 0) {
                             av_log(s->avctx, AV_LOG_ERROR, "slice mismatch\n");
-                            return -1;
+                            return AVERROR_INVALIDDATA;
                         }
                         goto eos; /* end of slice */
                     }
@@ -1861,7 +1862,7 @@ static int mpeg_decode_slice(MpegEncContext *s, int mb_y,
                 int i;
                 if (s->pict_type == AV_PICTURE_TYPE_I) {
                     av_log(s->avctx, AV_LOG_ERROR, "skipped MB in I frame at %d %d\n", s->mb_x, s->mb_y);
-                    return -1;
+                    return AVERROR_INVALIDDATA;
                 }
 
                 /* skip mb */
@@ -2460,7 +2461,7 @@ static int decode_chunks(AVCodecContext *avctx,
 
                 if (mb_y >= s2->mb_height) {
                     av_log(s2->avctx, AV_LOG_ERROR, "slice below image (%d >= %d)\n", mb_y, s2->mb_height);
-                    return -1;
+                    return AVERROR_INVALIDDATA;
                 }
 
                 if (s2->last_picture_ptr == NULL) {
@@ -2499,7 +2500,7 @@ static int decode_chunks(AVCodecContext *avctx,
                 if (s2->first_slice) {
                     s2->first_slice = 0;
                     if (mpeg_field_start(s2, buf, buf_size) < 0)
-                        return -1;
+                        return AVERROR_INVALIDDATA;
                 }
                 if (!s2->current_picture_ptr) {
                     av_log(avctx, AV_LOG_ERROR, "current_picture not initialized\n");
-- 
1.7.5.4



More information about the ffmpeg-devel mailing list