]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/h263dec.c
h263dec: disable coded dimensions = 0 handling
[ffmpeg] / libavcodec / h263dec.c
index 6c01e00a571ade588bd208dd7500f3f59076557a..ef1b6ed62c682cd9c3de249b583f9ccd5e51caf1 100644 (file)
@@ -47,6 +47,7 @@
 av_cold int ff_h263_decode_init(AVCodecContext *avctx)
 {
     MpegEncContext *s = avctx->priv_data;
+    int ret;
 
     s->avctx = avctx;
     s->out_format = FMT_H263;
@@ -110,15 +111,15 @@ av_cold int ff_h263_decode_init(AVCodecContext *avctx)
         s->h263_flv = 1;
         break;
     default:
-        return -1;
+        return AVERROR(EINVAL);
     }
     s->codec_id= avctx->codec->id;
     avctx->hwaccel= ff_find_hwaccel(avctx->codec->id, avctx->pix_fmt);
 
     /* for h263, we allocate the images after having read the header */
     if (avctx->codec->id != AV_CODEC_ID_H263 && avctx->codec->id != AV_CODEC_ID_H263P && avctx->codec->id != AV_CODEC_ID_MPEG4)
-        if (ff_MPV_common_init(s) < 0)
-            return -1;
+        if ((ret = ff_MPV_common_init(s)) < 0)
+            return ret;
 
         ff_h263_decode_init_vlc(s);
 
@@ -157,6 +158,8 @@ static int get_consumed_bytes(MpegEncContext *s, int buf_size){
 static int decode_slice(MpegEncContext *s){
     const int part_mask= s->partitioned_frame ? (ER_AC_END|ER_AC_ERROR) : 0x7F;
     const int mb_size= 16>>s->avctx->lowres;
+    int ret;
+
     s->last_resync_gb= s->gb;
     s->first_slice_line= 1;
 
@@ -176,8 +179,8 @@ static int decode_slice(MpegEncContext *s){
         const int qscale= s->qscale;
 
         if(CONFIG_MPEG4_DECODER && s->codec_id==AV_CODEC_ID_MPEG4){
-            if(ff_mpeg4_decode_partitions(s) < 0)
-                return -1;
+            if ((ret = ff_mpeg4_decode_partitions(s)) < 0)
+                return ret;
         }
 
         /* restore variables which were modified */
@@ -246,12 +249,12 @@ static int decode_slice(MpegEncContext *s){
                 }else if(ret==SLICE_NOEND){
                     av_log(s->avctx, AV_LOG_ERROR, "Slice mismatch at MB: %d\n", xy);
                     ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x+1, s->mb_y, ER_MB_END&part_mask);
-                    return -1;
+                    return AVERROR_INVALIDDATA;
                 }
                 av_log(s->avctx, AV_LOG_ERROR, "Error at MB: %d\n", xy);
                 ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, ER_MB_ERROR&part_mask);
 
-                return -1;
+                return AVERROR_INVALIDDATA;
             }
 
             ff_MPV_decode_mb(s, s->block);
@@ -339,7 +342,7 @@ static int decode_slice(MpegEncContext *s){
 
     ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, ER_MB_END&part_mask);
 
-    return -1;
+    return AVERROR_INVALIDDATA;
 }
 
 int ff_h263_decode_frame(AVCodecContext *avctx,
@@ -382,7 +385,7 @@ uint64_t time= rdtsc();
             next= ff_h263_find_frame_end(&s->parse_context, buf, buf_size);
         }else{
             av_log(s->avctx, AV_LOG_ERROR, "this codec does not support truncated bitstreams\n");
-            return -1;
+            return AVERROR(EINVAL);
         }
 
         if( ff_combine_frame(&s->parse_context, next, (const uint8_t **)&buf, &buf_size) < 0 )
@@ -411,8 +414,8 @@ retry:
     s->bitstream_buffer_size=0;
 
     if (!s->context_initialized) {
-        if (ff_MPV_common_init(s) < 0) //we need the idct permutaton for reading a custom matrix
-            return -1;
+        if ((ret = ff_MPV_common_init(s)) < 0) //we need the idct permutaton for reading a custom matrix
+            return ret;
     }
 
     /* We need to set current_picture_ptr before reading the header,
@@ -458,16 +461,7 @@ retry:
     /* skip if the header was thrashed */
     if (ret < 0){
         av_log(s->avctx, AV_LOG_ERROR, "header damaged\n");
-        return -1;
-    } else if ((s->width  != avctx->coded_width  ||
-                s->height != avctx->coded_height ||
-                (s->width  + 15) >> 4 != s->mb_width ||
-                (s->height + 15) >> 4 != s->mb_height) &&
-               (HAVE_THREADS && (s->avctx->active_thread_type & FF_THREAD_FRAME))) {
-        av_log_missing_feature(s->avctx, "Width/height/bit depth/chroma idc changing with threads is", 0);
-        s->width = avctx->coded_width;
-        s->height= avctx->coded_height;
-        return AVERROR_PATCHWELCOME;   // width / height changed during parallelized decoding
+        return ret;
     }
 
     avctx->has_b_frames= !s->low_delay;
@@ -604,21 +598,29 @@ retry:
         /* FIXME: By the way H263 decoder is evolving it should have */
         /* an H263EncContext                                         */
 
-    if (   s->width  != avctx->coded_width
-        || s->height != avctx->coded_height) {
-        /* H.263 could change picture size any time */
+    if ((!avctx->coded_width || !avctx->coded_height) && 0) {
         ParseContext pc= s->parse_context; //FIXME move these demuxng hack to avformat
 
         s->parse_context.buffer=0;
         ff_MPV_common_end(s);
         s->parse_context= pc;
-    }
-    if (!s->context_initialized) {
         avcodec_set_dimensions(avctx, s->width, s->height);
 
         goto retry;
     }
 
+    if (s->width  != avctx->coded_width  ||
+        s->height != avctx->coded_height ||
+        s->context_reinit) {
+        /* H.263 could change picture size any time */
+        s->context_reinit = 0;
+
+        avcodec_set_dimensions(avctx, s->width, s->height);
+
+        if ((ret = ff_MPV_common_frame_size_change(s)))
+            return ret;
+    }
+
     if((s->codec_id==AV_CODEC_ID_H263 || s->codec_id==AV_CODEC_ID_H263P || s->codec_id == AV_CODEC_ID_H263I))
         s->gob_index = ff_h263_get_gob_height(s);
 
@@ -651,8 +653,8 @@ retry:
         s->me.qpel_avg= s->dsp.avg_qpel_pixels_tab;
     }
 
-    if(ff_MPV_frame_start(s, avctx) < 0)
-        return -1;
+    if ((ret = ff_MPV_frame_start(s, avctx)) < 0)
+        return ret;
 
     if (!s->divx_packed) ff_thread_finish_setup(avctx);
 
@@ -662,8 +664,8 @@ retry:
     }
 
     if (avctx->hwaccel) {
-        if (avctx->hwaccel->start_frame(avctx, s->gb.buffer, s->gb.buffer_end - s->gb.buffer) < 0)
-            return -1;
+        if ((ret = avctx->hwaccel->start_frame(avctx, s->gb.buffer, s->gb.buffer_end - s->gb.buffer)) < 0)
+            return ret;
     }
 
     ff_er_frame_start(s);
@@ -737,8 +739,8 @@ intrax8_decoded:
     ff_er_frame_end(s);
 
     if (avctx->hwaccel) {
-        if (avctx->hwaccel->end_frame(avctx) < 0)
-            return -1;
+        if ((ret = avctx->hwaccel->end_frame(avctx)) < 0)
+            return ret;
     }
 
     ff_MPV_frame_end(s);