aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Niedermayer2003-09-26 22:18:25 +0000
committerMichael Niedermayer2003-09-26 22:18:25 +0000
commit7af75e6c65027c12a5fbd6755fadda985b6be886 (patch)
treee54fa3985230190c054ebbe52860342b6af69be6
parentd42f74b85e93690b332fdefe2a1625534cfe16fb (diff)
h263 stuffing decode fix
Originally committed as revision 2304 to svn://svn.ffmpeg.org/ffmpeg/trunk
-rw-r--r--libavcodec/h263.c52
-rw-r--r--libavcodec/h263data.h40
2 files changed, 43 insertions, 49 deletions
diff --git a/libavcodec/h263.c b/libavcodec/h263.c
index fb9eeb2545..093aaedc80 100644
--- a/libavcodec/h263.c
+++ b/libavcodec/h263.c
@@ -40,7 +40,7 @@
//#include <assert.h>
#define INTRA_MCBPC_VLC_BITS 6
-#define INTER_MCBPC_VLC_BITS 6
+#define INTER_MCBPC_VLC_BITS 7
#define CBPY_VLC_BITS 6
#define MV_VLC_BITS 9
#define DC_VLC_BITS 9
@@ -2428,10 +2428,10 @@ void h263_decode_init_vlc(MpegEncContext *s)
if (!done) {
done = 1;
- init_vlc(&intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 8,
+ init_vlc(&intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 9,
intra_MCBPC_bits, 1, 1,
intra_MCBPC_code, 1, 1);
- init_vlc(&inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 25,
+ init_vlc(&inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 28,
inter_MCBPC_bits, 1, 1,
inter_MCBPC_code, 1, 1);
init_vlc(&cbpy_vlc, CBPY_VLC_BITS, 16,
@@ -2871,12 +2871,14 @@ static int mpeg4_decode_partition_a(MpegEncContext *s){
return mb_num-1;
}
- cbpc = get_vlc2(&s->gb, intra_MCBPC_vlc.table, INTRA_MCBPC_VLC_BITS, 1);
- if (cbpc < 0){
+ do{
+ cbpc = get_vlc2(&s->gb, intra_MCBPC_vlc.table, INTRA_MCBPC_VLC_BITS, 2);
+ if (cbpc < 0){
+ fprintf(stderr, "cbpc corrupted at %d %d\n", s->mb_x, s->mb_y);
+ return -1;
+ }
+ }while(cbpc == 8);
- fprintf(stderr, "cbpc corrupted at %d %d\n", s->mb_x, s->mb_y);
- return -1;
- }
s->cbp_table[xy]= cbpc & 3;
s->current_picture.mb_type[xy]= MB_TYPE_INTRA;
s->mb_intra = 1;
@@ -2903,6 +2905,7 @@ static int mpeg4_decode_partition_a(MpegEncContext *s){
int16_t * const mot_val= s->motion_val[s->block_index[0]];
const int stride= s->block_wrap[0]*2;
+ do{
bits= show_bits(&s->gb, 17);
if(bits==MOTION_MARKER){
return mb_num-1;
@@ -2927,15 +2930,14 @@ static int mpeg4_decode_partition_a(MpegEncContext *s){
ff_clean_intra_table_entries(s);
continue;
}
+
cbpc = get_vlc2(&s->gb, inter_MCBPC_vlc.table, INTER_MCBPC_VLC_BITS, 2);
if (cbpc < 0){
fprintf(stderr, "cbpc corrupted at %d %d\n", s->mb_x, s->mb_y);
return -1;
}
- if (cbpc > 20)
- cbpc+=3;
- else if (cbpc == 20)
- fprintf(stderr, "Stuffing !");
+ }while(cbpc == 20);
+
s->cbp_table[xy]= cbpc&(8+3); //8 is dquant
s->mb_intra = ((cbpc & 4) != 0);
@@ -3234,6 +3236,7 @@ int ff_h263_decode_mb(MpegEncContext *s,
const int xy= s->mb_x + s->mb_y * s->mb_stride;
if (s->pict_type == P_TYPE || s->pict_type==S_TYPE) {
+ do{
if (get_bits1(&s->gb)) {
/* skip mb */
s->mb_intra = 0;
@@ -3259,12 +3262,11 @@ int ff_h263_decode_mb(MpegEncContext *s,
}
cbpc = get_vlc2(&s->gb, inter_MCBPC_vlc.table, INTER_MCBPC_VLC_BITS, 2);
//fprintf(stderr, "\tCBPC: %d", cbpc);
- if (cbpc < 0)
+ if (cbpc < 0){
+ fprintf(stderr, "cbpc damaged at %d %d\n", s->mb_x, s->mb_y);
return -1;
- if (cbpc > 20)
- cbpc+=3;
- else if (cbpc == 20)
- fprintf(stderr, "Stuffing !");
+ }
+ }while(cbpc == 20);
dquant = cbpc & 8;
s->mb_intra = ((cbpc & 4) != 0);
@@ -3501,9 +3503,14 @@ int ff_h263_decode_mb(MpegEncContext *s,
}
s->current_picture.mb_type[xy]= mb_type;
} else { /* I-Frame */
- cbpc = get_vlc2(&s->gb, intra_MCBPC_vlc.table, INTRA_MCBPC_VLC_BITS, 1);
- if (cbpc < 0)
- return -1;
+ do{
+ cbpc = get_vlc2(&s->gb, intra_MCBPC_vlc.table, INTRA_MCBPC_VLC_BITS, 2);
+ if (cbpc < 0){
+ fprintf(stderr, "I cbpc damaged at %d %d\n", s->mb_x, s->mb_y);
+ return -1;
+ }
+ }while(cbpc == 8);
+
dquant = cbpc & 4;
s->mb_intra = 1;
intra:
@@ -3520,7 +3527,10 @@ intra:
s->ac_pred = 0;
cbpy = get_vlc2(&s->gb, cbpy_vlc.table, CBPY_VLC_BITS, 1);
- if(cbpy<0) return -1;
+ if(cbpy<0){
+ fprintf(stderr, "I cbpy damaged at %d %d\n", s->mb_x, s->mb_y);
+ return -1;
+ }
cbp = (cbpc & 3) | (cbpy << 2);
if (dquant) {
change_qscale(s, quant_tab[get_bits(&s->gb, 2)]);
diff --git a/libavcodec/h263data.h b/libavcodec/h263data.h
index 132ed98a9b..809b10da29 100644
--- a/libavcodec/h263data.h
+++ b/libavcodec/h263data.h
@@ -5,46 +5,30 @@
/* intra MCBPC, mb_type = (intra), then (intraq) */
-const uint8_t intra_MCBPC_code[8] = { 1, 1, 2, 3, 1, 1, 2, 3 };
-const uint8_t intra_MCBPC_bits[8] = { 1, 3, 3, 3, 4, 6, 6, 6 };
+const uint8_t intra_MCBPC_code[9] = { 1, 1, 2, 3, 1, 1, 2, 3, 1 };
+const uint8_t intra_MCBPC_bits[9] = { 1, 3, 3, 3, 4, 6, 6, 6, 9 };
/* inter MCBPC, mb_type = (inter), (intra), (interq), (intraq), (inter4v) */
/* Changed the tables for interq and inter4v+q, following the standard ** Juanjo ** */
-const uint8_t inter_MCBPC_code[25] = {
+const uint8_t inter_MCBPC_code[28] = {
1, 3, 2, 5,
3, 4, 3, 3,
3, 7, 6, 5,
4, 4, 3, 2,
2, 5, 4, 5,
- 1, /* Stuffing */
+ 1, 0, 0, 0, /* Stuffing */
2, 12, 14, 15,
};
-const uint8_t inter_MCBPC_bits[25] = {
- 1, 4, 4, 6,
- 5, 8, 8, 7,
- 3, 7, 7, 9,
- 6, 9, 9, 9,
- 3, 7, 7, 8,
- 9, /* Stuffing */
- 11, 13, 13, 13,
+const uint8_t inter_MCBPC_bits[28] = {
+ 1, 4, 4, 6, /* inter */
+ 5, 8, 8, 7, /* intra */
+ 3, 7, 7, 9, /* interQ */
+ 6, 9, 9, 9, /* intraQ */
+ 3, 7, 7, 8, /* inter4 */
+ 9, 0, 0, 0, /* Stuffing */
+ 11, 13, 13, 13,/* inter4Q*/
};
-/* This is the old table
-static const uint8_t inter_MCBPC_code[20] = {
- 1, 3, 2, 5,
- 3, 4, 3, 3,
- 0, 1, 2, 3,
- 4, 4, 3, 2,
- 2, 5, 4, 5,
-};
-static const uint8_t inter_MCBPC_bits[20] = {
- 1, 4, 4, 6,
- 5, 8, 8, 7,
- 12, 12, 12, 12,
- 6, 9, 9, 9,
- 3, 7, 7, 8,
-};*/
-
const uint8_t cbpy_tab[16][2] =
{
{3,4}, {5,5}, {4,5}, {9,4}, {3,5}, {7,4}, {2,6}, {11,4},