From 0dfd33c3f115b95e016e8d6f0ffc3513f3b22182 Mon Sep 17 00:00:00 2001
From: Michael Niedermayer <michaelni@gmx.at>
Date: Sat, 26 Jun 2004 02:20:38 +0000
Subject: [PATCH] support skiping of mb rows during decoding

Originally committed as revision 3253 to svn://svn.ffmpeg.org/ffmpeg/trunk
---
 libavcodec/avcodec.h          | 16 +++++++++++++++-
 libavcodec/error_resilience.c |  7 ++++---
 libavcodec/mpeg12.c           |  5 +++++
 3 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index dae92e903d4..6d2922444ff 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -17,7 +17,7 @@ extern "C" {
 
 #define FFMPEG_VERSION_INT     0x000408
 #define FFMPEG_VERSION         "0.4.8"
-#define LIBAVCODEC_BUILD       4716
+#define LIBAVCODEC_BUILD       4717
 
 #define LIBAVCODEC_VERSION_INT FFMPEG_VERSION_INT
 #define LIBAVCODEC_VERSION     FFMPEG_VERSION
@@ -1605,6 +1605,20 @@ typedef struct AVCodecContext {
      * - decoding: unused
      */
      int nsse_weight;
+
+    /**
+     * number of macroblock rows at the top which are skiped.
+     * - encoding: unused
+     * - decoding: set by user
+     */
+     int skip_top;
+
+    /**
+     * number of macroblock rows at the bottom which are skiped.
+     * - encoding: unused
+     * - decoding: set by user
+     */
+     int skip_bottom;
 } AVCodecContext;
 
 
diff --git a/libavcodec/error_resilience.c b/libavcodec/error_resilience.c
index b7aeebddfcb..c18d775bb6f 100644
--- a/libavcodec/error_resilience.c
+++ b/libavcodec/error_resilience.c
@@ -652,7 +652,7 @@ void ff_er_add_slice(MpegEncContext *s, int startx, int starty, int endx, int en
  
     s->error_status_table[start_xy] |= VP_START;
 
-    if(start_xy > 0 && s->avctx->thread_count <= 1){
+    if(start_xy > 0 && s->avctx->thread_count <= 1 && s->avctx->skip_top*s->mb_width < start_i){
         int prev_status= s->error_status_table[ s->mb_index2xy[start_i - 1] ];
         
         prev_status &= ~ VP_START;
@@ -667,9 +667,10 @@ void ff_er_frame_end(MpegEncContext *s){
     int threshold= 50;
     int is_intra_likely;
     
-    if(!s->error_resilience || s->error_count==0) return;
+    if(!s->error_resilience || s->error_count==0 || 
+       s->error_count==3*s->mb_width*(s->avctx->skip_top + s->avctx->skip_bottom)) return;
 
-    av_log(s->avctx, AV_LOG_INFO, "concealing errors\n");
+    av_log(s->avctx, AV_LOG_INFO, "concealing %d errors\n", s->error_count);
     
     if(s->current_picture.motion_val[0] == NULL){
         int size = s->b8_stride * 2 * s->mb_height;
diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c
index f235a199b04..ff96bff4afc 100644
--- a/libavcodec/mpeg12.c
+++ b/libavcodec/mpeg12.c
@@ -2869,6 +2869,11 @@ static int mpeg_decode_frame(AVCodecContext *avctx,
                         if(avctx->hurry_up>=5) break;
                         
                         if (!s->mpeg_enc_ctx_allocated) break;
+
+                        if(s2->codec_id == CODEC_ID_MPEG2VIDEO){
+                            if(mb_y < avctx->skip_top || mb_y >= s2->mb_height - avctx->skip_bottom)
+                                break;
+                        }
                         
                         if(s2->first_slice){
                             s2->first_slice=0;
-- 
GitLab