]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/rv10.c
Optimize filter_mb_mbaff_edge*()
[ffmpeg] / libavcodec / rv10.c
index 6a6bf507e1e942aa9e547bcea71d7556a15b01ea..7b58aa8ef9381b1e71dc90546f4ac1d52fabaf96 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * RV10 codec
+ * RV10/RV20 decoder
  * Copyright (c) 2000,2001 Fabrice Bellard
  * Copyright (c) 2002-2004 Michael Niedermayer
  *
 
 /**
  * @file libavcodec/rv10.c
- * RV10 codec.
+ * RV10/RV20 decoder
  */
 
 #include "avcodec.h"
 #include "dsputil.h"
 #include "mpegvideo.h"
+#include "h263.h"
 
 //#define DEBUG
 
@@ -229,67 +230,6 @@ int rv_decode_dc(MpegEncContext *s, int n)
     return -code;
 }
 
-
-#if CONFIG_RV10_ENCODER || CONFIG_RV20_ENCODER
-/* write RV 1.0 compatible frame header */
-void rv10_encode_picture_header(MpegEncContext *s, int picture_number)
-{
-    int full_frame= 0;
-
-    align_put_bits(&s->pb);
-
-    put_bits(&s->pb, 1, 1);     /* marker */
-
-    put_bits(&s->pb, 1, (s->pict_type == FF_P_TYPE));
-
-    put_bits(&s->pb, 1, 0);     /* not PB frame */
-
-    put_bits(&s->pb, 5, s->qscale);
-
-    if (s->pict_type == FF_I_TYPE) {
-        /* specific MPEG like DC coding not used */
-    }
-    /* if multiple packets per frame are sent, the position at which
-       to display the macroblocks is coded here */
-    if(!full_frame){
-        put_bits(&s->pb, 6, 0); /* mb_x */
-        put_bits(&s->pb, 6, 0); /* mb_y */
-        put_bits(&s->pb, 12, s->mb_width * s->mb_height);
-    }
-
-    put_bits(&s->pb, 3, 0);     /* ignored */
-}
-
-void rv20_encode_picture_header(MpegEncContext *s, int picture_number){
-    put_bits(&s->pb, 2, s->pict_type); //I 0 vs. 1 ?
-    put_bits(&s->pb, 1, 0);     /* unknown bit */
-    put_bits(&s->pb, 5, s->qscale);
-
-    put_sbits(&s->pb, 8, picture_number); //FIXME wrong, but correct is not known
-    s->mb_x= s->mb_y= 0;
-    ff_h263_encode_mba(s);
-
-    put_bits(&s->pb, 1, s->no_rounding);
-
-    assert(s->f_code == 1);
-    assert(s->unrestricted_mv == 1);
-    assert(s->alt_inter_vlc == 0);
-    assert(s->umvplus == 0);
-    assert(s->modified_quant==1);
-    assert(s->loop_filter==1);
-
-    s->h263_aic= s->pict_type == FF_I_TYPE;
-    if(s->h263_aic){
-        s->y_dc_scale_table=
-        s->c_dc_scale_table= ff_aic_dc_scale_table;
-    }else{
-        s->y_dc_scale_table=
-        s->c_dc_scale_table= ff_mpeg1_dc_scale_table;
-    }
-}
-
-#endif /* CONFIG_RV10_ENCODER || CONFIG_RV20_ENCODER */
-
 /* read RV 1.0 compatible frame header */
 static int rv10_decode_picture_header(MpegEncContext *s)
 {
@@ -423,16 +363,17 @@ static int rv20_decode_picture_header(MpegEncContext *s)
             new_w= 4*((uint8_t*)s->avctx->extradata)[6+2*f];
             new_h= 4*((uint8_t*)s->avctx->extradata)[7+2*f];
         }else{
-            new_w= s->width; //FIXME wrong we of course must save the original in the context
-            new_h= s->height;
+            new_w= s->orig_width ;
+            new_h= s->orig_height;
         }
         if(new_w != s->width || new_h != s->height){
             av_log(s->avctx, AV_LOG_DEBUG, "attempting to change resolution to %dx%d\n", new_w, new_h);
-            if (avcodec_check_dimensions(s->avctx, new_h, new_w) < 0)
+            if (avcodec_check_dimensions(s->avctx, new_w, new_h) < 0)
                 return -1;
             MPV_common_end(s);
-            s->width  = s->avctx->width = new_w;
-            s->height = s->avctx->height= new_h;
+            avcodec_set_dimensions(s->avctx, new_w, new_h);
+            s->width  = new_w;
+            s->height = new_h;
             if (MPV_common_init(s) < 0)
                 return -1;
         }
@@ -513,8 +454,8 @@ static av_cold int rv10_decode_init(AVCodecContext *avctx)
     s->out_format = FMT_H263;
     s->codec_id= avctx->codec_id;
 
-    s->width = avctx->coded_width;
-    s->height = avctx->coded_height;
+    s->orig_width = s->width  = avctx->coded_width;
+    s->orig_height= s->height = avctx->coded_height;
 
     s->h263_long_vectors= ((uint8_t*)avctx->extradata)[3] & 1;
     avctx->sub_id= AV_RB32((uint8_t*)avctx->extradata + 4);
@@ -580,7 +521,7 @@ static av_cold int rv10_decode_end(AVCodecContext *avctx)
 }
 
 static int rv10_decode_packet(AVCodecContext *avctx,
-                             const uint8_t *buf, int buf_size)
+                             const uint8_t *buf, int buf_size, int buf_size2)
 {
     MpegEncContext *s = avctx->priv_data;
     int mb_count, mb_pos, left, start_mb_x;
@@ -663,6 +604,12 @@ static int rv10_decode_packet(AVCodecContext *avctx,
         s->mv_type = MV_TYPE_16X16;
         ret=ff_h263_decode_mb(s, s->block);
 
+        if (ret != SLICE_ERROR && s->gb.size_in_bits < get_bits_count(&s->gb) && 8*buf_size2 >= get_bits_count(&s->gb)){
+            av_log(avctx, AV_LOG_DEBUG, "update size from %d to %d\n", s->gb.size_in_bits, 8*buf_size2);
+            s->gb.size_in_bits= 8*buf_size2;
+            ret= SLICE_OK;
+        }
+
         if (ret == SLICE_ERROR || s->gb.size_in_bits < get_bits_count(&s->gb)) {
             av_log(s->avctx, AV_LOG_ERROR, "ERROR at MB %d %d\n", s->mb_x, s->mb_y);
             return -1;
@@ -685,7 +632,7 @@ static int rv10_decode_packet(AVCodecContext *avctx,
 
     ff_er_add_slice(s, start_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, AC_END|DC_END|MV_END);
 
-    return buf_size;
+    return s->gb.size_in_bits;
 }
 
 static int get_slice_offset(AVCodecContext *avctx, const uint8_t *buf, int n)
@@ -722,14 +669,20 @@ static int rv10_decode_frame(AVCodecContext *avctx,
 
     for(i=0; i<slice_count; i++){
         int offset= get_slice_offset(avctx, slices_hdr, i);
-        int size;
+        int size, size2;
 
         if(i+1 == slice_count)
             size= buf_size - offset;
         else
             size= get_slice_offset(avctx, slices_hdr, i+1) - offset;
 
-        rv10_decode_packet(avctx, buf+offset, size);
+        if(i+2 >= slice_count)
+            size2= buf_size - offset;
+        else
+            size2= get_slice_offset(avctx, slices_hdr, i+2) - offset;
+
+        if(rv10_decode_packet(avctx, buf+offset, size, size2) > 8*size)
+            i++;
     }
 
     if(s->current_picture_ptr != NULL && s->mb_y>=s->mb_height){
@@ -780,4 +733,3 @@ AVCodec rv20_decoder = {
     .long_name = NULL_IF_CONFIG_SMALL("RealVideo 2.0"),
     .pix_fmts= ff_pixfmt_list_420,
 };
-