Browse code

H261 fixing and cleaning: -corrected wrong value in mv data -set correct mb_type after adjusting index -don't use H263 loop filter when the loop filter flag is set but when using the H261 encoder -use the same unquantizer as H263 (which is optimized btw) -removed unused members in H261Context patch by (Maarten Daniels <maarten.daniels >at< luc >dot< ac >dot< be>)

regression test checksum update by me

Originally committed as revision 3669 to svn://svn.ffmpeg.org/ffmpeg/trunk

Maarten Daniels authored on 2004/11/12 10:21:34
Showing 5 changed files
... ...
@@ -53,8 +53,6 @@ typedef struct H261Context{
53 53
     int current_mv_x;
54 54
     int current_mv_y;
55 55
     int gob_number;
56
-    int bits_left; //8 - nr of bits left of the following frame in the last byte in this frame
57
-    int last_bits; //bits left of the following frame in the last byte in this frame
58 56
     int gob_start_code_skipped; // 1 if gob start code is already read before gob header is read
59 57
 }H261Context;
60 58
 
... ...
@@ -176,7 +174,7 @@ static void h261_encode_motion(H261Context * h, int val){
176 176
         put_bits(&s->pb,h261_mv_tab[code][1],h261_mv_tab[code][0]);
177 177
     } 
178 178
     else{
179
-        if(val > 16)
179
+        if(val > 15)
180 180
             val -=32;
181 181
         if(val < -16)
182 182
             val+=32;
... ...
@@ -847,24 +845,12 @@ static int h261_decode_gob(H261Context *h){
847 847
 }
848 848
 
849 849
 static int h261_find_frame_end(ParseContext *pc, AVCodecContext* avctx, const uint8_t *buf, int buf_size){
850
-    int vop_found, i, j, bits_left, last_bits;
850
+    int vop_found, i, j;
851 851
     uint32_t state;
852 852
 
853
-    H261Context *h = avctx->priv_data;
854
-
855
-    if(h){
856
-        bits_left = h->bits_left;
857
-        last_bits = h->last_bits;
858
-    }
859
-    else{
860
-        bits_left = 0;
861
-        last_bits = 0;
862
-    }
863
-
864 853
     vop_found= pc->frame_start_found;
865 854
     state= pc->state;
866
-    if(bits_left!=0 && !vop_found)
867
-        state = state << (8-bits_left) | last_bits;
855
+   
868 856
     i=0;
869 857
     if(!vop_found){
870 858
         for(i=0; i<buf_size; i++){
... ...
@@ -67,7 +67,7 @@ const uint8_t h261_mv_tab[17][2] = {
67 67
 
68 68
 static const int mvmap[17] =
69 69
 {
70
-    0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15, 16
70
+    0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15, -16
71 71
 };
72 72
 
73 73
 //H.261 VLC table for coded block pattern
... ...
@@ -53,10 +53,6 @@ static void dct_unquantize_h263_intra_c(MpegEncContext *s,
53 53
                                   DCTELEM *block, int n, int qscale);
54 54
 static void dct_unquantize_h263_inter_c(MpegEncContext *s, 
55 55
                                   DCTELEM *block, int n, int qscale);
56
-static void dct_unquantize_h261_intra_c(MpegEncContext *s, 
57
-                                  DCTELEM *block, int n, int qscale);
58
-static void dct_unquantize_h261_inter_c(MpegEncContext *s, 
59
-                                  DCTELEM *block, int n, int qscale);
60 56
 static void draw_edges_c(uint8_t *buf, int wrap, int width, int height, int w);
61 57
 #ifdef CONFIG_ENCODERS
62 58
 static int dct_quantize_c(MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow);
... ...
@@ -219,8 +215,6 @@ int DCT_common_init(MpegEncContext *s)
219 219
 {
220 220
     s->dct_unquantize_h263_intra = dct_unquantize_h263_intra_c;
221 221
     s->dct_unquantize_h263_inter = dct_unquantize_h263_inter_c;
222
-    s->dct_unquantize_h261_intra = dct_unquantize_h261_intra_c;
223
-    s->dct_unquantize_h261_inter = dct_unquantize_h261_inter_c;
224 222
     s->dct_unquantize_mpeg1_intra = dct_unquantize_mpeg1_intra_c;
225 223
     s->dct_unquantize_mpeg1_inter = dct_unquantize_mpeg1_inter_c;
226 224
     s->dct_unquantize_mpeg2_intra = dct_unquantize_mpeg2_intra_c;
... ...
@@ -1482,12 +1476,9 @@ alloc:
1482 1482
     if(s->mpeg_quant || s->codec_id == CODEC_ID_MPEG2VIDEO){
1483 1483
         s->dct_unquantize_intra = s->dct_unquantize_mpeg2_intra;
1484 1484
         s->dct_unquantize_inter = s->dct_unquantize_mpeg2_inter;
1485
-    }else if(s->out_format == FMT_H263){
1485
+    }else if(s->out_format == FMT_H263 || s->out_format == FMT_H261){
1486 1486
         s->dct_unquantize_intra = s->dct_unquantize_h263_intra;
1487 1487
         s->dct_unquantize_inter = s->dct_unquantize_h263_inter;
1488
-    }else if(s->out_format == FMT_H261){
1489
-        s->dct_unquantize_intra = s->dct_unquantize_h261_intra;
1490
-        s->dct_unquantize_inter = s->dct_unquantize_h261_inter;
1491 1488
     }else{
1492 1489
         s->dct_unquantize_intra = s->dct_unquantize_mpeg1_intra;
1493 1490
         s->dct_unquantize_inter = s->dct_unquantize_mpeg1_inter;
... ...
@@ -4517,6 +4508,7 @@ static int encode_thread(AVCodecContext *c, void *arg){
4517 4517
             if(s->codec_id == CODEC_ID_H261){
4518 4518
                 ff_h261_reorder_mb_index(s);
4519 4519
                 xy= s->mb_y*s->mb_stride + s->mb_x;
4520
+                mb_type= s->mb_type[xy];
4520 4521
             }
4521 4522
 
4522 4523
             /* write gob / video packet header  */
... ...
@@ -4990,8 +4982,10 @@ static int encode_thread(AVCodecContext *c, void *arg){
4990 4990
                     s, s->new_picture    .data[2] + s->mb_x*8  + s->mb_y*s->uvlinesize*8,
4991 4991
                     s->dest[2], w>>1, h>>1, s->uvlinesize);
4992 4992
             }
4993
-            if(s->loop_filter)
4994
-                ff_h263_loop_filter(s);
4993
+            if(s->loop_filter){
4994
+                if(s->out_format == FMT_H263)
4995
+                    ff_h263_loop_filter(s);
4996
+            }
4995 4997
 //printf("MB %d %d bits\n", s->mb_x+s->mb_y*s->mb_stride, put_bits_count(&s->pb));
4996 4998
         }
4997 4999
     }
... ...
@@ -6250,59 +6244,6 @@ static void dct_unquantize_h263_inter_c(MpegEncContext *s,
6250 6250
     }
6251 6251
 }
6252 6252
 
6253
-static void dct_unquantize_h261_intra_c(MpegEncContext *s, 
6254
-                                  DCTELEM *block, int n, int qscale)
6255
-{
6256
-    int i, level, even;
6257
-    int nCoeffs;
6258
-    
6259
-    assert(s->block_last_index[n]>=0);
6260
-    
6261
-    if (n < 4) 
6262
-        block[0] = block[0] * s->y_dc_scale;
6263
-    else
6264
-        block[0] = block[0] * s->c_dc_scale;
6265
-    even = (qscale & 1)^1;
6266
-    nCoeffs= s->inter_scantable.raster_end[ s->block_last_index[n] ];
6267
-
6268
-    for(i=1; i<=nCoeffs; i++){
6269
-        level = block[i];
6270
-        if (level){
6271
-            if (level < 0){
6272
-                level = qscale * ((level << 1) - 1) + even;
6273
-            }else{
6274
-                level = qscale * ((level << 1) + 1) - even;
6275
-            }
6276
-        }
6277
-        block[i] = level;
6278
-    }
6279
-}
6280
-
6281
-static void dct_unquantize_h261_inter_c(MpegEncContext *s, 
6282
-                                  DCTELEM *block, int n, int qscale)
6283
-{
6284
-    int i, level, even;
6285
-    int nCoeffs;
6286
-    
6287
-    assert(s->block_last_index[n]>=0);
6288
-
6289
-    even = (qscale & 1)^1;
6290
-    
6291
-    nCoeffs= s->inter_scantable.raster_end[ s->block_last_index[n] ];
6292
-
6293
-    for(i=0; i<=nCoeffs; i++){
6294
-        level = block[i];
6295
-        if (level){
6296
-            if (level < 0){
6297
-                level = qscale * ((level << 1) - 1) + even;
6298
-            }else{
6299
-                level = qscale * ((level << 1) + 1) - even;
6300
-            }
6301
-        }
6302
-        block[i] = level;
6303
-    }
6304
-}
6305
-
6306 6253
 static const AVOption mpeg4_options[] =
6307 6254
 {
6308 6255
     AVOPTION_CODEC_INT("bitrate", "desired video bitrate", bit_rate, 4, 240000000, 800000),
... ...
@@ -35,10 +35,10 @@ a5bd577163968edab00058f2c8d5efab *./data/a-wmv2.avi
35 35
 682132 ./data/a-wmv2.avi
36 36
 09253222ab4eb95628c931a86006a2b1 *./data/out.yuv
37 37
 stddev:  8.02 PSNR:30.04 bytes:7602176
38
-c12437d78325d6634ff77a49bf1869e8 *./data/a-h261.avi
39
-779222 ./data/a-h261.avi
40
-1dd0be7be463c1a338d1b848e926a0b8 *./data/out.yuv
41
-stddev:  9.17 PSNR:28.87 bytes:7602176
38
+bcf34887269746ac7973f88cde336609 *./data/a-h261.avi
39
+735098 ./data/a-h261.avi
40
+0a6e6dd4f09df9fe77ff29581c1a39c3 *./data/out.yuv
41
+stddev:  9.14 PSNR:28.90 bytes:7602176
42 42
 fa556e599181bf9328a811a1ce9aa022 *./data/a-h263.avi
43 43
 682226 ./data/a-h263.avi
44 44
 f2b7fcff9de17f5aecfeb1090fe1963b *./data/out.yuv
... ...
@@ -35,10 +35,10 @@ stddev:  5.33 PSNR:33.58 bytes:7602176
35 35
 129214 ./data/a-wmv2.avi
36 36
 f80d2809e79af3ebcfe831deab9af03c *./data/out.yuv
37 37
 stddev:  5.33 PSNR:33.58 bytes:7602176
38
-41050f885f7ea9594643e5dbf8ea30da *./data/a-h261.avi
39
-193452 ./data/a-h261.avi
40
-c74fbf0b0faf1124e172413c059ab45a *./data/out.yuv
41
-stddev:  6.40 PSNR:31.99 bytes:7602176
38
+631f4daabb4f639e8dec18bbb58dae79 *./data/a-h261.avi
39
+191124 ./data/a-h261.avi
40
+452714d0883f555e831888de0be1fc49 *./data/out.yuv
41
+stddev:  6.39 PSNR:32.00 bytes:7602176
42 42
 ef053b1fec77a49eb8a27510b81e4041 *./data/a-h263.avi
43 43
 159596 ./data/a-h263.avi
44 44
 7ec66fb7dd4e5dddd3820c668d6636aa *./data/out.yuv