changeset 1639:3e2b774edce4 libavcodec

rv20 decoder
author michael
date Sun, 30 Nov 2003 14:35:35 +0000
parents e389d57db630
children 3bc71266e644
files allcodecs.c avcodec.h h263.c h263data.h h263dec.c mpegvideo.h rv10.c
diffstat 7 files changed, 169 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/allcodecs.c	Sat Nov 29 08:44:33 2003 +0000
+++ b/allcodecs.c	Sun Nov 30 14:35:35 2003 +0000
@@ -90,6 +90,7 @@
     register_avcodec(&h263i_decoder);
     register_avcodec(&flv_decoder);
     register_avcodec(&rv10_decoder);
+    register_avcodec(&rv20_decoder);
     register_avcodec(&svq1_decoder);
     register_avcodec(&svq3_decoder);
     register_avcodec(&wmav1_decoder);
--- a/avcodec.h	Sat Nov 29 08:44:33 2003 +0000
+++ b/avcodec.h	Sun Nov 30 14:35:35 2003 +0000
@@ -33,6 +33,7 @@
     CODEC_ID_MPEG2VIDEO_XVMC,
     CODEC_ID_H263,
     CODEC_ID_RV10,
+    CODEC_ID_RV20,
     CODEC_ID_MP2,
     CODEC_ID_MP3, /* prefered ID for MPEG Audio layer 1, 2 or3 decoding */
     CODEC_ID_VORBIS,
@@ -1502,6 +1503,7 @@
 extern AVCodec h263p_encoder;
 extern AVCodec flv_encoder;
 extern AVCodec rv10_encoder;
+extern AVCodec rv20_encoder;
 extern AVCodec mjpeg_encoder;
 extern AVCodec ljpeg_encoder;
 extern AVCodec mpeg4_encoder;
@@ -1532,6 +1534,7 @@
 extern AVCodec h263i_decoder;
 extern AVCodec flv_decoder;
 extern AVCodec rv10_decoder;
+extern AVCodec rv20_decoder;
 extern AVCodec svq1_decoder;
 extern AVCodec svq3_decoder;
 extern AVCodec dvvideo_decoder;
--- a/h263.c	Sat Nov 29 08:44:33 2003 +0000
+++ b/h263.c	Sun Nov 30 14:35:35 2003 +0000
@@ -185,7 +185,7 @@
 
       if(s->h263_aic){
         s->y_dc_scale_table= 
-          s->c_dc_scale_table= h263_aic_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;
@@ -288,7 +288,7 @@
 
     if(s->h263_aic){
          s->y_dc_scale_table= 
-         s->c_dc_scale_table= h263_aic_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;
@@ -1139,11 +1139,12 @@
         }
     } else {
         int li = s->h263_aic ? 0 : 1;
+        assert(s->mb_intra);
         
         cbp = 0;
         for(i=0; i<6; i++) {
             /* Predict DC */
-            if (s->h263_aic && s->mb_intra) {
+            if (s->h263_aic) {
                 int16_t level = block[i][0];
             
                 pred_dc = h263_pred_dc(s, i, &dc_ptr[i]);
@@ -1286,7 +1287,7 @@
     /* find prediction */
     if (n < 4) {
         x = 2 * s->mb_x + 1 + (n & 1);
-        y = 2 * s->mb_y + 1 + ((n & 2) >> 1);
+        y = 2 * s->mb_y + 1 + (n>> 1);
         wrap = s->mb_width * 2 + 2;
         dc_val = s->dc_val[0];
         ac_val = s->ac_val[0][0];
@@ -1310,10 +1311,13 @@
     c = dc_val[(x) + (y - 1) * wrap];
     
     /* No prediction outside GOB boundary */
-    if (s->first_slice_line && ((n < 2) || (n > 3)))
-        c = 1024;
-    pred_dc = 1024;
+    if(s->first_slice_line && n!=3){
+        if(n!=2) c= 1024;
+        if(n!=1 && s->mb_x == s->resync_mb_x) a= 1024;
+    }
+    
     if (s->ac_pred) {
+        pred_dc = 1024;
         if (s->h263_aic_dir) {
             /* left prediction */
             if (a != 1024) {
@@ -1348,8 +1352,8 @@
     
     if (block[0] < 0)
         block[0] = 0;
-    else if (!(block[0] & 1))
-        block[0]++;
+    else 
+        block[0] |= 1;
     
     /* Update AC/DC tables */
     dc_val[(x) + (y) * wrap] = block[0];
@@ -3517,7 +3521,14 @@
         
         cbp = (cbpc & 3) | (cbpy << 2);
         if (dquant) {
-            change_qscale(s, quant_tab[get_bits(&s->gb, 2)]);
+            if(s->modified_quant){
+                if(get_bits1(&s->gb))
+                    s->qscale= modified_quant_tab[get_bits1(&s->gb)][ s->qscale ];
+                else
+                    s->qscale= get_bits(&s->gb, 5);
+            }else
+                s->qscale += quant_tab[get_bits(&s->gb, 2)];
+            change_qscale(s, 0);
         }
         if((!s->progressive_sequence) && (cbp || (s->workaround_bugs&FF_BUG_XVID_ILACE)))
             s->interlaced_dct= get_bits1(&s->gb);
@@ -3772,7 +3783,14 @@
         }
         cbp = (cbpc & 3) | (cbpy << 2);
         if (dquant) {
-            change_qscale(s, quant_tab[get_bits(&s->gb, 2)]);
+            if(s->modified_quant){
+                if(get_bits1(&s->gb))
+                    s->qscale= modified_quant_tab[get_bits1(&s->gb)][ s->qscale ];
+                else
+                    s->qscale= get_bits(&s->gb, 5);
+            }else
+                s->qscale += quant_tab[get_bits(&s->gb, 2)];
+            change_qscale(s, 0);
         }
         
         if(!s->progressive_sequence)
@@ -4459,9 +4477,7 @@
                 av_log(s->avctx, AV_LOG_ERROR, "Independent Segment Decoding not supported\n");
             }
             s->alt_inter_vlc= get_bits1(&s->gb);
-            if (get_bits1(&s->gb) != 0) {
-                av_log(s->avctx, AV_LOG_ERROR, "Modified Quantization not supported\n");
-            }
+            s->modified_quant= get_bits1(&s->gb);
             
             skip_bits(&s->gb, 1); /* Prevent start code emulation */
 
@@ -4532,14 +4548,14 @@
     
     if(s->h263_aic){
          s->y_dc_scale_table= 
-         s->c_dc_scale_table= h263_aic_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;
     }
 
      if(s->avctx->debug&FF_DEBUG_PICT_INFO){
-         av_log(s->avctx, AV_LOG_DEBUG, "qp:%d %c size:%d rnd:%d%s%s%s%s%s%s\n", 
+         av_log(s->avctx, AV_LOG_DEBUG, "qp:%d %c size:%d rnd:%d%s%s%s%s%s%s%s\n", 
          s->qscale, av_get_pict_type_char(s->pict_type),
          s->gb.size_in_bits, 1-s->no_rounding,
          s->obmc ? " AP" : "",
@@ -4547,7 +4563,8 @@
          s->h263_long_vectors ? " LONG" : "",
          s->h263_plus ? " +" : "",
          s->h263_aic ? " AIC" : "",
-         s->alt_inter_vlc ? " AIV" : ""
+         s->alt_inter_vlc ? " AIV" : "",
+         s->modified_quant ? " MQ" : ""
          ); 
      }
 #if 1
--- a/h263data.h	Sat Nov 29 08:44:33 2003 +0000
+++ b/h263data.h	Sun Nov 30 14:35:35 2003 +0000
@@ -208,8 +208,29 @@
     { 1408, 1152 },
 };
 
-static uint8_t h263_aic_dc_scale_table[32]={
+uint8_t ff_aic_dc_scale_table[32]={
 //  0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
     0, 2, 4, 6, 8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62
 };
 
+static const uint8_t modified_quant_tab[2][32]={
+//  0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
+{
+    0, 3, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9,10,11,12,13,14,15,16,17,18,18,19,20,21,22,23,24,25,26,27,28
+},{
+    0, 2, 3, 4, 5, 6, 7, 8, 9,10,11,13,14,15,16,17,18,19,20,21,22,24,25,26,27,28,29,30,31,31,31,26
+}   
+};
+
+static const uint8_t chroma_qscale_tab[32]={
+//  0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
+    0, 1, 2, 3, 4, 5, 6, 6, 7, 8, 9, 9,10,10,11,11,12,12,12,13,13,13,14,14,14,14,14,15,15,15,15,15
+};
+
+const uint16_t ff_mba_max[6]={
+     47,  98, 395,1583,6335,9215
+};
+
+const uint8_t ff_mba_length[6]={
+      6,   7,   9,  11,  13,  14
+};
--- a/h263dec.c	Sat Nov 29 08:44:33 2003 +0000
+++ b/h263dec.c	Sun Nov 30 14:35:35 2003 +0000
@@ -52,6 +52,7 @@
     switch(avctx->codec->id) {
     case CODEC_ID_H263:
         s->gob_number = 0;
+        s->unrestricted_mv= 0;
         break;
     case CODEC_ID_MPEG4:
         s->time_increment_bits = 4; /* default value for broken headers */
--- a/mpegvideo.h	Sat Nov 29 08:44:33 2003 +0000
+++ b/mpegvideo.h	Sun Nov 30 14:35:35 2003 +0000
@@ -526,6 +526,7 @@
     int h263_aic;                   ///< Advanded INTRA Coding (AIC) 
     int h263_aic_dir;               ///< AIC direction: 0 = left, 1 = top 
     int alt_inter_vlc;              ///< alternative inter vlc
+    int modified_quant;
     
     /* mpeg4 specific */
     int time_increment_resolution;
@@ -814,8 +815,12 @@
 
 extern uint8_t ff_mpeg4_y_dc_scale_table[32];
 extern uint8_t ff_mpeg4_c_dc_scale_table[32];
+extern uint8_t ff_aic_dc_scale_table[32];
 extern const int16_t ff_mpeg4_default_intra_matrix[64];
 extern const int16_t ff_mpeg4_default_non_intra_matrix[64];
+extern const uint16_t ff_mba_max[6];
+extern const uint8_t ff_mba_length[6];
+
 int ff_h263_decode_init(AVCodecContext *avctx);
 int ff_h263_decode_frame(AVCodecContext *avctx, 
                              void *data, int *data_size,
--- a/rv10.c	Sat Nov 29 08:44:33 2003 +0000
+++ b/rv10.c	Sun Nov 30 14:35:35 2003 +0000
@@ -337,6 +337,55 @@
     return mb_count;
 }
 
+static int rv20_decode_picture_header(MpegEncContext *s)
+{
+    int pb_frame, seq, mb_pos;
+    int i;
+
+    if (get_bits(&s->gb, 1))
+        s->pict_type = P_TYPE;
+    else
+        s->pict_type = I_TYPE;
+
+    pb_frame = get_bits(&s->gb, 2); 
+
+    if (pb_frame){
+        av_log(s->avctx, AV_LOG_ERROR, "pb frame not supported\n");
+        return -1;
+    }
+
+    s->qscale = get_bits(&s->gb, 5);
+    if(s->qscale==0){
+        av_log(s->avctx, AV_LOG_ERROR, "error, qscale:0\n");
+        return -1;
+    }
+    
+    seq= get_bits(&s->gb, 8);
+
+    for(i=0; i<6; i++){
+        if(s->mb_width*s->mb_height < ff_mba_max[i]) break;
+    }
+    mb_pos= get_bits(&s->gb, ff_mba_length[i]);
+    s->mb_x= mb_pos % s->mb_width;
+    s->mb_y= mb_pos / s->mb_width;
+    s->no_rounding= get_bits1(&s->gb);
+    
+    s->f_code = 1;
+    s->unrestricted_mv = 1;
+    s->h263_aic= s->pict_type == I_TYPE;
+//    s->alt_inter_vlc=1;
+//    s->obmc=1;
+//    s->umvplus=1;
+//    s->modified_quant=1;
+    
+    if(s->avctx->debug & FF_DEBUG_PICT_INFO){
+            av_log(s->avctx, AV_LOG_INFO, "num:%3d x:%2d y:%2d type:%d qscale:%2d rnd:%d\n", 
+                   seq, s->mb_x, s->mb_y, s->pict_type, s->qscale, s->no_rounding);
+    }
+
+    return s->mb_width*s->mb_height - mb_pos;
+}
+
 static int rv10_decode_init(AVCodecContext *avctx)
 {
     MpegEncContext *s = avctx->priv_data;
@@ -348,20 +397,26 @@
     s->width = avctx->width;
     s->height = avctx->height;
 
-    s->h263_rv10 = 1;
     switch(avctx->sub_id){
     case 0x10000000:
         s->rv10_version= 0;
         s->h263_long_vectors=0;
+        s->h263_rv10 = 1;
         break;
     case 0x10003000:
         s->rv10_version= 3;
         s->h263_long_vectors=1;
+        s->h263_rv10 = 1;
         break;
     case 0x10003001:
         s->rv10_version= 3;
         s->h263_long_vectors=0;
+        s->h263_rv10 = 1;
         break;
+    case 0x20001000:
+    case 0x20100001:
+    case 0x20200002:
+    case 0x20101001: //added
     default:
         av_log(s->avctx, AV_LOG_ERROR, "unknown header %X\n", avctx->sub_id);
     }
@@ -373,8 +428,6 @@
 
     h263_decode_init_vlc(s);
 
-    s->y_dc_scale_table=
-    s->c_dc_scale_table= ff_mpeg1_dc_scale_table;
     s->progressive_sequence=1;
 
     /* init rv vlc */
@@ -408,8 +461,16 @@
     int i, mb_count, mb_pos, left;
 
     init_get_bits(&s->gb, buf, buf_size*8);
-    
-    mb_count = rv10_decode_picture_header(s);
+#if 0
+    for(i=0; i<buf_size*8 && i<100; i++)
+        printf("%d", get_bits1(&s->gb));
+    printf("\n");
+    return 0;
+#endif
+    if(s->codec_id ==CODEC_ID_RV10)
+        mb_count = rv10_decode_picture_header(s);
+    else
+        mb_count = rv20_decode_picture_header(s);
     if (mb_count < 0) {
         av_log(s->avctx, AV_LOG_ERROR, "HEADER ERROR\n");
         return -1;
@@ -426,6 +487,7 @@
         av_log(s->avctx, AV_LOG_ERROR, "COUNT ERROR\n");
         return -1;
     }
+//if(s->pict_type == P_TYPE) return 0;
 
     if (s->mb_x == 0 && s->mb_y == 0) {
         if(MPV_frame_start(s, avctx) < 0)
@@ -437,14 +499,27 @@
 #endif
 
     /* default quantization values */
-    s->y_dc_scale = 8;
-    s->c_dc_scale = 8;
+    if(s->codec_id== CODEC_ID_RV10){
+        if(s->mb_y==0) s->first_slice_line=1;
+    }else{
+        s->first_slice_line=1;    
+        s->resync_mb_x= s->mb_x;
+        s->resync_mb_y= s->mb_y;
+    }
+    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;
+    }
+    s->y_dc_scale= s->y_dc_scale_table[ s->qscale ];
+    s->c_dc_scale= s->c_dc_scale_table[ s->qscale ];
+    
     s->rv10_first_dc_coded[0] = 0;
     s->rv10_first_dc_coded[1] = 0;
     s->rv10_first_dc_coded[2] = 0;
 
-    if(s->mb_y==0) s->first_slice_line=1;
-    
     s->block_wrap[0]=
     s->block_wrap[1]=
     s->block_wrap[2]=
@@ -454,6 +529,7 @@
     ff_init_block_index(s);
     /* decode each macroblock */
     for(i=0;i<mb_count;i++) {
+        int ret;
         ff_update_block_index(s);
 #ifdef DEBUG
         printf("**mb x=%d y=%d\n", s->mb_x, s->mb_y);
@@ -462,7 +538,9 @@
 	s->dsp.clear_blocks(s->block[0]);
         s->mv_dir = MV_DIR_FORWARD;
         s->mv_type = MV_TYPE_16X16; 
-        if (ff_h263_decode_mb(s, s->block) == SLICE_ERROR) {
+        ret=ff_h263_decode_mb(s, s->block);
+
+        if (ret == SLICE_ERROR) {
             av_log(s->avctx, AV_LOG_ERROR, "ERROR at MB %d %d\n", s->mb_x, s->mb_y);
             return -1;
         }
@@ -472,8 +550,10 @@
             s->mb_x = 0;
             s->mb_y++;
             ff_init_block_index(s);
+        }
+        if(s->mb_x == s->resync_mb_x)
             s->first_slice_line=0;
-        }
+        if(ret == SLICE_END) break;
     }
 
     return buf_size;
@@ -539,3 +619,15 @@
     rv10_decode_frame,
     CODEC_CAP_DR1
 };
+
+AVCodec rv20_decoder = {
+    "rv20",
+    CODEC_TYPE_VIDEO,
+    CODEC_ID_RV20,
+    sizeof(MpegEncContext),
+    rv10_decode_init,
+    NULL,
+    rv10_decode_end,
+    rv10_decode_frame,
+    CODEC_CAP_DR1
+};