Mercurial > libavcodec.hg
annotate h263.c @ 10782:7061be6d8e96 libavcodec
Simplify h263_get_picture_format().
author | michael |
---|---|
date | Thu, 07 Jan 2010 03:36:46 +0000 |
parents | 35e175942ee2 |
children | 610b00f28aef |
rev | line source |
---|---|
0 | 1 /* |
2 * H263/MPEG4 backend for ffmpeg encoder and decoder | |
8629
04423b2f6e0b
cosmetics: Remove pointless period after copyright statement non-sentences.
diego
parents:
8627
diff
changeset
|
3 * Copyright (c) 2000,2001 Fabrice Bellard |
78 | 4 * H263+ support. |
8629
04423b2f6e0b
cosmetics: Remove pointless period after copyright statement non-sentences.
diego
parents:
8627
diff
changeset
|
5 * Copyright (c) 2001 Juan J. Sierralta P |
1739
07a484280a82
copyright year update of the files i touched and remembered, things look annoyingly unmaintained otherwise
michael
parents:
1708
diff
changeset
|
6 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at> |
0 | 7 * |
5214 | 8 * ac prediction encoding, B-frame support, error resilience, optimizations, |
9 * qpel decoding, gmc decoding, interlaced decoding | |
10 * by Michael Niedermayer <michaelni@gmx.at> | |
11 * | |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3791
diff
changeset
|
12 * This file is part of FFmpeg. |
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3791
diff
changeset
|
13 * |
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3791
diff
changeset
|
14 * FFmpeg is free software; you can redistribute it and/or |
429 | 15 * modify it under the terms of the GNU Lesser General Public |
16 * License as published by the Free Software Foundation; either | |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3791
diff
changeset
|
17 * version 2.1 of the License, or (at your option) any later version. |
0 | 18 * |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3791
diff
changeset
|
19 * FFmpeg is distributed in the hope that it will be useful, |
0 | 20 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
429 | 21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
22 * Lesser General Public License for more details. | |
0 | 23 * |
429 | 24 * You should have received a copy of the GNU Lesser General Public |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3791
diff
changeset
|
25 * License along with FFmpeg; if not, write to the Free Software |
3036
0b546eab515d
Update licensing information: The FSF changed postal address.
diego
parents:
3024
diff
changeset
|
26 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 27 */ |
1034 | 28 |
29 /** | |
8718
e9d9d946f213
Use full internal pathname in doxygen @file directives.
diego
parents:
8691
diff
changeset
|
30 * @file libavcodec/h263.c |
1106 | 31 * h263/mpeg4 codec. |
1034 | 32 */ |
2967 | 33 |
355 | 34 //#define DEBUG |
1490
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
35 #include <limits.h> |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
36 |
0 | 37 #include "dsputil.h" |
38 #include "avcodec.h" | |
39 #include "mpegvideo.h" | |
40 #include "h263data.h" | |
41 #include "mpeg4data.h" | |
8627
d6bab465b82c
moves mid_pred() into mathops.h (with arch specific code split by directory)
aurel
parents:
8612
diff
changeset
|
42 #include "mathops.h" |
9103
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
43 #include "unary.h" |
0 | 44 |
690
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
676
diff
changeset
|
45 //#undef NDEBUG |
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
676
diff
changeset
|
46 //#include <assert.h> |
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
676
diff
changeset
|
47 |
544 | 48 #define INTRA_MCBPC_VLC_BITS 6 |
1482 | 49 #define INTER_MCBPC_VLC_BITS 7 |
544 | 50 #define CBPY_VLC_BITS 6 |
51 #define MV_VLC_BITS 9 | |
52 #define DC_VLC_BITS 9 | |
53 #define SPRITE_TRAJ_VLC_BITS 6 | |
54 #define MB_TYPE_B_VLC_BITS 4 | |
55 #define TEX_VLC_BITS 9 | |
1655 | 56 #define H263_MBTYPE_B_VLC_BITS 6 |
57 #define CBPC_B_VLC_BITS 3 | |
544 | 58 |
8590 | 59 #if CONFIG_ENCODERS |
1064 | 60 static uint8_t uni_DCtab_lum_len[512]; |
61 static uint8_t uni_DCtab_chrom_len[512]; | |
62 static uint16_t uni_DCtab_lum_bits[512]; | |
63 static uint16_t uni_DCtab_chrom_bits[512]; | |
815
78accc54493b
put a few large tables under #ifdef CONFIG_ENCODERS or dynamically allocate them
michaelni
parents:
770
diff
changeset
|
64 |
4655 | 65 static uint8_t mv_penalty[MAX_FCODE+1][MAX_MV*2+1]; |
1064 | 66 static uint8_t fcode_tab[MAX_MV*2+1]; |
67 static uint8_t umv_fcode_tab[MAX_MV*2+1]; | |
815
78accc54493b
put a few large tables under #ifdef CONFIG_ENCODERS or dynamically allocate them
michaelni
parents:
770
diff
changeset
|
68 |
945 | 69 static uint32_t uni_mpeg4_intra_rl_bits[64*64*2*2]; |
70 static uint8_t uni_mpeg4_intra_rl_len [64*64*2*2]; | |
71 static uint32_t uni_mpeg4_inter_rl_bits[64*64*2*2]; | |
72 static uint8_t uni_mpeg4_inter_rl_len [64*64*2*2]; | |
2253 | 73 static uint8_t uni_h263_intra_aic_rl_len [64*64*2*2]; |
74 static uint8_t uni_h263_inter_rl_len [64*64*2*2]; | |
945 | 75 //#define UNI_MPEG4_ENC_INDEX(last,run,level) ((last)*128 + (run)*256 + (level)) |
648
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
76 //#define UNI_MPEG4_ENC_INDEX(last,run,level) ((last)*128*64 + (run) + (level)*64) |
945 | 77 #define UNI_MPEG4_ENC_INDEX(last,run,level) ((last)*128*64 + (run)*128 + (level)) |
648
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
78 |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
79 /* mpeg4 |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
80 inter |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
81 max level: 24/6 |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
82 max run: 53/63 |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
83 |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
84 intra |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
85 max level: 53/16 |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
86 max run: 29/41 |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
87 */ |
815
78accc54493b
put a few large tables under #ifdef CONFIG_ENCODERS or dynamically allocate them
michaelni
parents:
770
diff
changeset
|
88 #endif |
78accc54493b
put a few large tables under #ifdef CONFIG_ENCODERS or dynamically allocate them
michaelni
parents:
770
diff
changeset
|
89 |
4672 | 90 static uint8_t static_rl_table_store[5][2][2*MAX_RUN + MAX_LEVEL + 3]; |
91 | |
2646
c735e3e60ca7
Even More spelling errors. patch by (Kevin Baragona <kevinmb500 gawab com)
michael
parents:
2639
diff
changeset
|
92 #if 0 //3IV1 is quite rare and it slows things down a tiny bit |
8612 | 93 #define IS_3IV1 s->codec_tag == AV_RL32("3IV1") |
2967 | 94 #else |
1271
42ea05e4a391
improving 3IV1 support (still far from perfect) note, disabled as it requires some checks in the inner loops which would slow things down a tiny bit
michaelni
parents:
1261
diff
changeset
|
95 #define IS_3IV1 0 |
42ea05e4a391
improving 3IV1 support (still far from perfect) note, disabled as it requires some checks in the inner loops which would slow things down a tiny bit
michaelni
parents:
1261
diff
changeset
|
96 #endif |
293 | 97 |
0 | 98 int h263_get_picture_format(int width, int height) |
99 { | |
100 if (width == 128 && height == 96) | |
10782 | 101 return 1; |
0 | 102 else if (width == 176 && height == 144) |
10782 | 103 return 2; |
0 | 104 else if (width == 352 && height == 288) |
10782 | 105 return 3; |
0 | 106 else if (width == 704 && height == 576) |
10782 | 107 return 4; |
0 | 108 else if (width == 1408 && height == 1152) |
10782 | 109 return 5; |
0 | 110 else |
10782 | 111 return 7; |
0 | 112 } |
113 | |
5403 | 114 static void show_pict_info(MpegEncContext *s){ |
115 av_log(s->avctx, AV_LOG_DEBUG, "qp:%d %c size:%d rnd:%d%s%s%s%s%s%s%s%s%s %d/%d\n", | |
116 s->qscale, av_get_pict_type_char(s->pict_type), | |
117 s->gb.size_in_bits, 1-s->no_rounding, | |
118 s->obmc ? " AP" : "", | |
119 s->umvplus ? " UMV" : "", | |
120 s->h263_long_vectors ? " LONG" : "", | |
121 s->h263_plus ? " +" : "", | |
122 s->h263_aic ? " AIC" : "", | |
123 s->alt_inter_vlc ? " AIV" : "", | |
124 s->modified_quant ? " MQ" : "", | |
125 s->loop_filter ? " LOOP" : "", | |
126 s->h263_slice_structured ? " SS" : "", | |
127 s->avctx->time_base.den, s->avctx->time_base.num | |
128 ); | |
129 } | |
130 | |
8590 | 131 #if CONFIG_ENCODERS |
1070
6da5ae9ee199
more #ifdef CONFIG_ENCODERS patch by (Wolfgang Hesseler <qv at multimediaware dot com>) with modifications by me (s/WOLFGANG/CONFIG_ENCODERS/ and some other fixes)
michaelni
parents:
1068
diff
changeset
|
132 |
1548 | 133 static void aspect_to_info(MpegEncContext * s, AVRational aspect){ |
887 | 134 int i; |
135 | |
1548 | 136 if(aspect.num==0) aspect= (AVRational){1,1}; |
137 | |
887 | 138 for(i=1; i<6; i++){ |
1548 | 139 if(av_cmp_q(pixel_aspect[i], aspect) == 0){ |
887 | 140 s->aspect_ratio_info=i; |
141 return; | |
142 } | |
143 } | |
2967 | 144 |
887 | 145 s->aspect_ratio_info= FF_ASPECT_EXTENDED; |
880 | 146 } |
147 | |
1354 | 148 void ff_flv_encode_picture_header(MpegEncContext * s, int picture_number) |
0 | 149 { |
1354 | 150 int format; |
151 | |
152 align_put_bits(&s->pb); | |
153 | |
1353
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
154 put_bits(&s->pb, 17, 1); |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
155 put_bits(&s->pb, 5, (s->h263_flv-1)); /* 0: h263 escape codes 1: 11-bit escape codes */ |
2637 | 156 put_bits(&s->pb, 8, (((int64_t)s->picture_number * 30 * s->avctx->time_base.num) / //FIXME use timestamp |
157 s->avctx->time_base.den) & 0xff); /* TemporalReference */ | |
1353
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
158 if (s->width == 352 && s->height == 288) |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
159 format = 2; |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
160 else if (s->width == 176 && s->height == 144) |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
161 format = 3; |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
162 else if (s->width == 128 && s->height == 96) |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
163 format = 4; |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
164 else if (s->width == 320 && s->height == 240) |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
165 format = 5; |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
166 else if (s->width == 160 && s->height == 120) |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
167 format = 6; |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
168 else if (s->width <= 255 && s->height <= 255) |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
169 format = 0; /* use 1 byte width & height */ |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
170 else |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
171 format = 1; /* use 2 bytes width & height */ |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
172 put_bits(&s->pb, 3, format); /* PictureSize */ |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
173 if (format == 0) { |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
174 put_bits(&s->pb, 8, s->width); |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
175 put_bits(&s->pb, 8, s->height); |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
176 } else if (format == 1) { |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
177 put_bits(&s->pb, 16, s->width); |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
178 put_bits(&s->pb, 16, s->height); |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
179 } |
6481 | 180 put_bits(&s->pb, 2, s->pict_type == FF_P_TYPE); /* PictureType */ |
1390
39d07c0263de
patch for flv deblocking by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1389
diff
changeset
|
181 put_bits(&s->pb, 1, 1); /* DeblockingFlag: on */ |
1353
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
182 put_bits(&s->pb, 5, s->qscale); /* Quantizer */ |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
183 put_bits(&s->pb, 1, 0); /* ExtraInformation */ |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
184 |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
185 if(s->h263_aic){ |
2967 | 186 s->y_dc_scale_table= |
1639 | 187 s->c_dc_scale_table= ff_aic_dc_scale_table; |
1353
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
188 }else{ |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
189 s->y_dc_scale_table= |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
190 s->c_dc_scale_table= ff_mpeg1_dc_scale_table; |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
191 } |
1354 | 192 } |
193 | |
194 void h263_encode_picture_header(MpegEncContext * s, int picture_number) | |
195 { | |
1872 | 196 int format, coded_frame_rate, coded_frame_rate_base, i, temp_ref; |
197 int best_clock_code=1; | |
198 int best_divisor=60; | |
199 int best_error= INT_MAX; | |
2967 | 200 |
1872 | 201 if(s->h263_plus){ |
202 for(i=0; i<2; i++){ | |
203 int div, error; | |
2637 | 204 div= (s->avctx->time_base.num*1800000LL + 500LL*s->avctx->time_base.den) / ((1000LL+i)*s->avctx->time_base.den); |
5075
33d50e0e1823
Correct the parameter order for the call to "av_clip".
takis
parents:
4984
diff
changeset
|
205 div= av_clip(div, 1, 127); |
4001 | 206 error= FFABS(s->avctx->time_base.num*1800000LL - (1000LL+i)*s->avctx->time_base.den*div); |
1872 | 207 if(error < best_error){ |
208 best_error= error; | |
209 best_divisor= div; | |
210 best_clock_code= i; | |
211 } | |
212 } | |
213 } | |
214 s->custom_pcf= best_clock_code!=1 || best_divisor!=60; | |
215 coded_frame_rate= 1800000; | |
216 coded_frame_rate_base= (1000+best_clock_code)*best_divisor; | |
1354 | 217 |
218 align_put_bits(&s->pb); | |
1353
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
219 |
231 | 220 /* Update the pointer to last GOB */ |
9431 | 221 s->ptr_lastgob = put_bits_ptr(&s->pb); |
231 | 222 put_bits(&s->pb, 22, 0x20); /* PSC */ |
2637 | 223 temp_ref= s->picture_number * (int64_t)coded_frame_rate * s->avctx->time_base.num / //FIXME use timestamp |
224 (coded_frame_rate_base * (int64_t)s->avctx->time_base.den); | |
7260
3ec34b551aae
bitstream: move put_sbits() from flacenc.c to bitstream.h and use it
ramiro
parents:
7098
diff
changeset
|
225 put_sbits(&s->pb, 8, temp_ref); /* TemporalReference */ |
0 | 226 |
2979 | 227 put_bits(&s->pb, 1, 1); /* marker */ |
228 put_bits(&s->pb, 1, 0); /* h263 id */ | |
229 put_bits(&s->pb, 1, 0); /* split screen off */ | |
230 put_bits(&s->pb, 1, 0); /* camera off */ | |
231 put_bits(&s->pb, 1, 0); /* freeze picture release off */ | |
2967 | 232 |
78 | 233 format = h263_get_picture_format(s->width, s->height); |
0 | 234 if (!s->h263_plus) { |
235 /* H.263v1 */ | |
236 put_bits(&s->pb, 3, format); | |
6481 | 237 put_bits(&s->pb, 1, (s->pict_type == FF_P_TYPE)); |
0 | 238 /* By now UMV IS DISABLED ON H.263v1, since the restrictions |
239 of H.263v1 UMV implies to check the predicted MV after | |
240 calculation of the current MB to see if we're on the limits */ | |
2979 | 241 put_bits(&s->pb, 1, 0); /* Unrestricted Motion Vector: off */ |
242 put_bits(&s->pb, 1, 0); /* SAC: off */ | |
243 put_bits(&s->pb, 1, s->obmc); /* Advanced Prediction */ | |
244 put_bits(&s->pb, 1, 0); /* only I/P frames, no PB frame */ | |
0 | 245 put_bits(&s->pb, 5, s->qscale); |
2979 | 246 put_bits(&s->pb, 1, 0); /* Continuous Presence Multipoint mode: off */ |
0 | 247 } else { |
1872 | 248 int ufep=1; |
0 | 249 /* H.263v2 */ |
250 /* H.263 Plus PTYPE */ | |
2967 | 251 |
0 | 252 put_bits(&s->pb, 3, 7); |
1872 | 253 put_bits(&s->pb,3,ufep); /* Update Full Extended PTYPE */ |
78 | 254 if (format == 7) |
255 put_bits(&s->pb,3,6); /* Custom Source Format */ | |
256 else | |
257 put_bits(&s->pb, 3, format); | |
2967 | 258 |
1872 | 259 put_bits(&s->pb,1, s->custom_pcf); |
1661 | 260 put_bits(&s->pb,1, s->umvplus); /* Unrestricted Motion Vector */ |
0 | 261 put_bits(&s->pb,1,0); /* SAC: off */ |
1633 | 262 put_bits(&s->pb,1,s->obmc); /* Advanced Prediction Mode */ |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
263 put_bits(&s->pb,1,s->h263_aic); /* Advanced Intra Coding */ |
1644 | 264 put_bits(&s->pb,1,s->loop_filter); /* Deblocking Filter */ |
1661 | 265 put_bits(&s->pb,1,s->h263_slice_structured); /* Slice Structured */ |
0 | 266 put_bits(&s->pb,1,0); /* Reference Picture Selection: off */ |
267 put_bits(&s->pb,1,0); /* Independent Segment Decoding: off */ | |
1637 | 268 put_bits(&s->pb,1,s->alt_inter_vlc); /* Alternative Inter VLC */ |
1644 | 269 put_bits(&s->pb,1,s->modified_quant); /* Modified Quantization: */ |
0 | 270 put_bits(&s->pb,1,1); /* "1" to prevent start code emulation */ |
271 put_bits(&s->pb,3,0); /* Reserved */ | |
2967 | 272 |
6481 | 273 put_bits(&s->pb, 3, s->pict_type == FF_P_TYPE); |
2967 | 274 |
0 | 275 put_bits(&s->pb,1,0); /* Reference Picture Resampling: off */ |
276 put_bits(&s->pb,1,0); /* Reduced-Resolution Update: off */ | |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
277 put_bits(&s->pb,1,s->no_rounding); /* Rounding Type */ |
0 | 278 put_bits(&s->pb,2,0); /* Reserved */ |
279 put_bits(&s->pb,1,1); /* "1" to prevent start code emulation */ | |
2967 | 280 |
0 | 281 /* This should be here if PLUSPTYPE */ |
2979 | 282 put_bits(&s->pb, 1, 0); /* Continuous Presence Multipoint mode: off */ |
283 | |
284 if (format == 7) { | |
78 | 285 /* Custom Picture Format (CPFMT) */ |
1548 | 286 aspect_to_info(s, s->avctx->sample_aspect_ratio); |
880 | 287 |
288 put_bits(&s->pb,4,s->aspect_ratio_info); | |
78 | 289 put_bits(&s->pb,9,(s->width >> 2) - 1); |
290 put_bits(&s->pb,1,1); /* "1" to prevent start code emulation */ | |
291 put_bits(&s->pb,9,(s->height >> 2)); | |
1548 | 292 if (s->aspect_ratio_info == FF_ASPECT_EXTENDED){ |
293 put_bits(&s->pb, 8, s->avctx->sample_aspect_ratio.num); | |
294 put_bits(&s->pb, 8, s->avctx->sample_aspect_ratio.den); | |
2979 | 295 } |
78 | 296 } |
1872 | 297 if(s->custom_pcf){ |
298 if(ufep){ | |
299 put_bits(&s->pb, 1, best_clock_code); | |
300 put_bits(&s->pb, 7, best_divisor); | |
301 } | |
7260
3ec34b551aae
bitstream: move put_sbits() from flacenc.c to bitstream.h and use it
ramiro
parents:
7098
diff
changeset
|
302 put_sbits(&s->pb, 2, temp_ref>>8); |
1872 | 303 } |
2967 | 304 |
0 | 305 /* Unlimited Unrestricted Motion Vectors Indicator (UUI) */ |
79
82e579c37bc3
Moved some H.263+ variables to MpegEncContext to be thread-safe.
pulento
parents:
78
diff
changeset
|
306 if (s->umvplus) |
1089 | 307 // put_bits(&s->pb,1,1); /* Limited according tables of Annex D */ |
1644 | 308 //FIXME check actual requested range |
1089 | 309 put_bits(&s->pb,2,1); /* unlimited */ |
1661 | 310 if(s->h263_slice_structured) |
311 put_bits(&s->pb,2,0); /* no weird submodes */ | |
1089 | 312 |
0 | 313 put_bits(&s->pb, 5, s->qscale); |
314 } | |
315 | |
2979 | 316 put_bits(&s->pb, 1, 0); /* no PEI */ |
498 | 317 |
1670 | 318 if(s->h263_slice_structured){ |
319 put_bits(&s->pb, 1, 1); | |
2967 | 320 |
1670 | 321 assert(s->mb_x == 0 && s->mb_y == 0); |
322 ff_h263_encode_mba(s); | |
323 | |
324 put_bits(&s->pb, 1, 1); | |
325 } | |
326 | |
498 | 327 if(s->h263_aic){ |
2967 | 328 s->y_dc_scale_table= |
1639 | 329 s->c_dc_scale_table= ff_aic_dc_scale_table; |
498 | 330 }else{ |
331 s->y_dc_scale_table= | |
332 s->c_dc_scale_table= ff_mpeg1_dc_scale_table; | |
333 } | |
0 | 334 } |
335 | |
766 | 336 /** |
337 * Encodes a group of blocks header. | |
338 */ | |
1661 | 339 void h263_encode_gob_header(MpegEncContext * s, int mb_line) |
162 | 340 { |
1661 | 341 put_bits(&s->pb, 17, 1); /* GBSC */ |
342 | |
343 if(s->h263_slice_structured){ | |
344 put_bits(&s->pb, 1, 1); | |
345 | |
346 ff_h263_encode_mba(s); | |
347 | |
348 if(s->mb_num > 1583) | |
349 put_bits(&s->pb, 1, 1); | |
350 put_bits(&s->pb, 5, s->qscale); /* GQUANT */ | |
351 put_bits(&s->pb, 1, 1); | |
6481 | 352 put_bits(&s->pb, 2, s->pict_type == FF_I_TYPE); /* GFID */ |
1661 | 353 }else{ |
354 int gob_number= mb_line / s->gob_index; | |
355 | |
356 put_bits(&s->pb, 5, gob_number); /* GN */ | |
6481 | 357 put_bits(&s->pb, 2, s->pict_type == FF_I_TYPE); /* GFID */ |
1661 | 358 put_bits(&s->pb, 5, s->qscale); /* GQUANT */ |
359 } | |
162 | 360 } |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
361 |
1492 | 362 static inline int get_block_rate(MpegEncContext * s, DCTELEM block[64], int block_last_index, uint8_t scantable[64]){ |
363 int last=0; | |
364 int j; | |
365 int rate=0; | |
366 | |
367 for(j=1; j<=block_last_index; j++){ | |
368 const int index= scantable[j]; | |
369 int level= block[index]; | |
370 if(level){ | |
371 level+= 64; | |
372 if((level&(~127)) == 0){ | |
373 if(j<block_last_index) rate+= s->intra_ac_vlc_length [UNI_AC_ENC_INDEX(j-last-1, level)]; | |
374 else rate+= s->intra_ac_vlc_last_length[UNI_AC_ENC_INDEX(j-last-1, level)]; | |
375 }else | |
376 rate += s->ac_esc_length; | |
377 | |
378 last= j; | |
379 } | |
380 } | |
2967 | 381 |
1492 | 382 return rate; |
383 } | |
384 | |
385 static inline int decide_ac_pred(MpegEncContext * s, DCTELEM block[6][64], int dir[6], uint8_t *st[6], int zigzag_last_index[6]) | |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
386 { |
1492 | 387 int score= 0; |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
388 int i, n; |
903 | 389 int8_t * const qscale_table= s->current_picture.qscale_table; |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
390 |
1492 | 391 memcpy(zigzag_last_index, s->block_last_index, sizeof(int)*6); |
2967 | 392 |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
393 for(n=0; n<6; n++){ |
1064 | 394 int16_t *ac_val, *ac_val1; |
2967 | 395 |
1492 | 396 score -= get_block_rate(s, block[n], s->block_last_index[n], s->intra_scantable.permutated); |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
397 |
266 | 398 ac_val = s->ac_val[0][0] + s->block_index[n] * 16; |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
399 ac_val1= ac_val; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
400 if(dir[n]){ |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
401 const int xy= s->mb_x + s->mb_y*s->mb_stride - s->mb_stride; |
692
852b5a416161
fixing ac prediction encoding with adaptive quantization
michaelni
parents:
690
diff
changeset
|
402 /* top prediction */ |
266 | 403 ac_val-= s->block_wrap[n]*16; |
903 | 404 if(s->mb_y==0 || s->qscale == qscale_table[xy] || n==2 || n==3){ |
692
852b5a416161
fixing ac prediction encoding with adaptive quantization
michaelni
parents:
690
diff
changeset
|
405 /* same qscale */ |
852b5a416161
fixing ac prediction encoding with adaptive quantization
michaelni
parents:
690
diff
changeset
|
406 for(i=1; i<8; i++){ |
1092 | 407 const int level= block[n][s->dsp.idct_permutation[i ]]; |
1492 | 408 block[n][s->dsp.idct_permutation[i ]] = level - ac_val[i+8]; |
1092 | 409 ac_val1[i ]= block[n][s->dsp.idct_permutation[i<<3]]; |
692
852b5a416161
fixing ac prediction encoding with adaptive quantization
michaelni
parents:
690
diff
changeset
|
410 ac_val1[i+8]= level; |
852b5a416161
fixing ac prediction encoding with adaptive quantization
michaelni
parents:
690
diff
changeset
|
411 } |
852b5a416161
fixing ac prediction encoding with adaptive quantization
michaelni
parents:
690
diff
changeset
|
412 }else{ |
852b5a416161
fixing ac prediction encoding with adaptive quantization
michaelni
parents:
690
diff
changeset
|
413 /* different qscale, we must rescale */ |
852b5a416161
fixing ac prediction encoding with adaptive quantization
michaelni
parents:
690
diff
changeset
|
414 for(i=1; i<8; i++){ |
1092 | 415 const int level= block[n][s->dsp.idct_permutation[i ]]; |
1492 | 416 block[n][s->dsp.idct_permutation[i ]] = level - ROUNDED_DIV(ac_val[i + 8]*qscale_table[xy], s->qscale); |
1092 | 417 ac_val1[i ]= block[n][s->dsp.idct_permutation[i<<3]]; |
692
852b5a416161
fixing ac prediction encoding with adaptive quantization
michaelni
parents:
690
diff
changeset
|
418 ac_val1[i+8]= level; |
852b5a416161
fixing ac prediction encoding with adaptive quantization
michaelni
parents:
690
diff
changeset
|
419 } |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
420 } |
1492 | 421 st[n]= s->intra_h_scantable.permutated; |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
422 }else{ |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
423 const int xy= s->mb_x-1 + s->mb_y*s->mb_stride; |
692
852b5a416161
fixing ac prediction encoding with adaptive quantization
michaelni
parents:
690
diff
changeset
|
424 /* left prediction */ |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
425 ac_val-= 16; |
903 | 426 if(s->mb_x==0 || s->qscale == qscale_table[xy] || n==1 || n==3){ |
692
852b5a416161
fixing ac prediction encoding with adaptive quantization
michaelni
parents:
690
diff
changeset
|
427 /* same qscale */ |
852b5a416161
fixing ac prediction encoding with adaptive quantization
michaelni
parents:
690
diff
changeset
|
428 for(i=1; i<8; i++){ |
1092 | 429 const int level= block[n][s->dsp.idct_permutation[i<<3]]; |
1492 | 430 block[n][s->dsp.idct_permutation[i<<3]]= level - ac_val[i]; |
692
852b5a416161
fixing ac prediction encoding with adaptive quantization
michaelni
parents:
690
diff
changeset
|
431 ac_val1[i ]= level; |
1092 | 432 ac_val1[i+8]= block[n][s->dsp.idct_permutation[i ]]; |
692
852b5a416161
fixing ac prediction encoding with adaptive quantization
michaelni
parents:
690
diff
changeset
|
433 } |
852b5a416161
fixing ac prediction encoding with adaptive quantization
michaelni
parents:
690
diff
changeset
|
434 }else{ |
852b5a416161
fixing ac prediction encoding with adaptive quantization
michaelni
parents:
690
diff
changeset
|
435 /* different qscale, we must rescale */ |
852b5a416161
fixing ac prediction encoding with adaptive quantization
michaelni
parents:
690
diff
changeset
|
436 for(i=1; i<8; i++){ |
1092 | 437 const int level= block[n][s->dsp.idct_permutation[i<<3]]; |
1492 | 438 block[n][s->dsp.idct_permutation[i<<3]]= level - ROUNDED_DIV(ac_val[i]*qscale_table[xy], s->qscale); |
692
852b5a416161
fixing ac prediction encoding with adaptive quantization
michaelni
parents:
690
diff
changeset
|
439 ac_val1[i ]= level; |
1092 | 440 ac_val1[i+8]= block[n][s->dsp.idct_permutation[i ]]; |
692
852b5a416161
fixing ac prediction encoding with adaptive quantization
michaelni
parents:
690
diff
changeset
|
441 } |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
442 } |
1492 | 443 st[n]= s->intra_v_scantable.permutated; |
444 } | |
445 | |
446 for(i=63; i>0; i--) //FIXME optimize | |
447 if(block[n][ st[n][i] ]) break; | |
448 s->block_last_index[n]= i; | |
449 | |
450 score += get_block_rate(s, block[n], s->block_last_index[n], st[n]); | |
451 } | |
452 | |
453 return score < 0; | |
454 } | |
455 | |
456 static inline void restore_ac_coeffs(MpegEncContext * s, DCTELEM block[6][64], int dir[6], uint8_t *st[6], int zigzag_last_index[6]) | |
457 { | |
458 int i, n; | |
459 memcpy(s->block_last_index, zigzag_last_index, sizeof(int)*6); | |
460 | |
461 for(n=0; n<6; n++){ | |
462 int16_t *ac_val = s->ac_val[0][0] + s->block_index[n] * 16; | |
463 | |
464 st[n]= s->intra_scantable.permutated; | |
465 if(dir[n]){ | |
466 /* top prediction */ | |
467 for(i=1; i<8; i++){ | |
468 block[n][s->dsp.idct_permutation[i ]] = ac_val[i+8]; | |
469 } | |
470 }else{ | |
471 /* left prediction */ | |
472 for(i=1; i<8; i++){ | |
473 block[n][s->dsp.idct_permutation[i<<3]]= ac_val[i ]; | |
474 } | |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
475 } |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
476 } |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
477 } |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
478 |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
479 /** |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
480 * modify qscale so that encoding is acually possible in h263 (limit difference to -2..2) |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
481 */ |
695 | 482 void ff_clean_h263_qscales(MpegEncContext *s){ |
690
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
676
diff
changeset
|
483 int i; |
903 | 484 int8_t * const qscale_table= s->current_picture.qscale_table; |
2967 | 485 |
4316 | 486 ff_init_qscale_tab(s); |
487 | |
690
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
676
diff
changeset
|
488 for(i=1; i<s->mb_num; i++){ |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
489 if(qscale_table[ s->mb_index2xy[i] ] - qscale_table[ s->mb_index2xy[i-1] ] >2) |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
490 qscale_table[ s->mb_index2xy[i] ]= qscale_table[ s->mb_index2xy[i-1] ]+2; |
690
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
676
diff
changeset
|
491 } |
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
676
diff
changeset
|
492 for(i=s->mb_num-2; i>=0; i--){ |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
493 if(qscale_table[ s->mb_index2xy[i] ] - qscale_table[ s->mb_index2xy[i+1] ] >2) |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
494 qscale_table[ s->mb_index2xy[i] ]= qscale_table[ s->mb_index2xy[i+1] ]+2; |
690
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
676
diff
changeset
|
495 } |
1983 | 496 |
497 if(s->codec_id != CODEC_ID_H263P){ | |
498 for(i=1; i<s->mb_num; i++){ | |
499 int mb_xy= s->mb_index2xy[i]; | |
2967 | 500 |
1983 | 501 if(qscale_table[mb_xy] != qscale_table[s->mb_index2xy[i-1]] && (s->mb_type[mb_xy]&CANDIDATE_MB_TYPE_INTER4V)){ |
502 s->mb_type[mb_xy]|= CANDIDATE_MB_TYPE_INTER; | |
503 } | |
504 } | |
505 } | |
695 | 506 } |
507 | |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
508 /** |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
509 * modify mb_type & qscale so that encoding is acually possible in mpeg4 |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
510 */ |
695 | 511 void ff_clean_mpeg4_qscales(MpegEncContext *s){ |
512 int i; | |
903 | 513 int8_t * const qscale_table= s->current_picture.qscale_table; |
514 | |
695 | 515 ff_clean_h263_qscales(s); |
2967 | 516 |
6481 | 517 if(s->pict_type== FF_B_TYPE){ |
690
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
676
diff
changeset
|
518 int odd=0; |
2646
c735e3e60ca7
Even More spelling errors. patch by (Kevin Baragona <kevinmb500 gawab com)
michael
parents:
2639
diff
changeset
|
519 /* ok, come on, this isn't funny anymore, there's more code for handling this mpeg4 mess than for the actual adaptive quantization */ |
2967 | 520 |
690
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
676
diff
changeset
|
521 for(i=0; i<s->mb_num; i++){ |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
522 int mb_xy= s->mb_index2xy[i]; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
523 odd += qscale_table[mb_xy]&1; |
690
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
676
diff
changeset
|
524 } |
2967 | 525 |
690
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
676
diff
changeset
|
526 if(2*odd > s->mb_num) odd=1; |
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
676
diff
changeset
|
527 else odd=0; |
2967 | 528 |
690
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
676
diff
changeset
|
529 for(i=0; i<s->mb_num; i++){ |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
530 int mb_xy= s->mb_index2xy[i]; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
531 if((qscale_table[mb_xy]&1) != odd) |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
532 qscale_table[mb_xy]++; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
533 if(qscale_table[mb_xy] > 31) |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
534 qscale_table[mb_xy]= 31; |
2967 | 535 } |
536 | |
690
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
676
diff
changeset
|
537 for(i=1; i<s->mb_num; i++){ |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
538 int mb_xy= s->mb_index2xy[i]; |
1708 | 539 if(qscale_table[mb_xy] != qscale_table[s->mb_index2xy[i-1]] && (s->mb_type[mb_xy]&CANDIDATE_MB_TYPE_DIRECT)){ |
540 s->mb_type[mb_xy]|= CANDIDATE_MB_TYPE_BIDIR; | |
690
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
676
diff
changeset
|
541 } |
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
676
diff
changeset
|
542 } |
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
676
diff
changeset
|
543 } |
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
676
diff
changeset
|
544 } |
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
676
diff
changeset
|
545 |
1070
6da5ae9ee199
more #ifdef CONFIG_ENCODERS patch by (Wolfgang Hesseler <qv at multimediaware dot com>) with modifications by me (s/WOLFGANG/CONFIG_ENCODERS/ and some other fixes)
michaelni
parents:
1068
diff
changeset
|
546 #endif //CONFIG_ENCODERS |
3247 | 547 |
8042 | 548 #define tab_size ((signed)FF_ARRAY_ELEMS(s->direct_scale_mv[0])) |
3255
183e3eb0824a
100l to loren. at least this fixes the compile error, but the code is still broken (decoding buggy/crashing)
rfelker
parents:
3247
diff
changeset
|
549 #define tab_bias (tab_size/2) |
183e3eb0824a
100l to loren. at least this fixes the compile error, but the code is still broken (decoding buggy/crashing)
rfelker
parents:
3247
diff
changeset
|
550 |
3791
b1d5ef809e11
fix rv20 b frames (broke since r5264 Mon Apr 3 07:52:24 2006 UTC 2x faster ff_mpeg4_set_direct_mv)
michael
parents:
3781
diff
changeset
|
551 void ff_mpeg4_init_direct_mv(MpegEncContext *s){ |
3247 | 552 int i; |
553 for(i=0; i<tab_size; i++){ | |
554 s->direct_scale_mv[0][i] = (i-tab_bias)*s->pb_time/s->pp_time; | |
555 s->direct_scale_mv[1][i] = (i-tab_bias)*(s->pb_time-s->pp_time)/s->pp_time; | |
556 } | |
557 } | |
558 | |
559 static inline void ff_mpeg4_set_one_direct_mv(MpegEncContext *s, int mx, int my, int i){ | |
560 int xy= s->block_index[i]; | |
561 uint16_t time_pp= s->pp_time; | |
562 uint16_t time_pb= s->pb_time; | |
563 int p_mx, p_my; | |
564 | |
565 p_mx= s->next_picture.motion_val[0][xy][0]; | |
566 if((unsigned)(p_mx + tab_bias) < tab_size){ | |
567 s->mv[0][i][0] = s->direct_scale_mv[0][p_mx + tab_bias] + mx; | |
568 s->mv[1][i][0] = mx ? s->mv[0][i][0] - p_mx | |
569 : s->direct_scale_mv[1][p_mx + tab_bias]; | |
570 }else{ | |
571 s->mv[0][i][0] = p_mx*time_pb/time_pp + mx; | |
572 s->mv[1][i][0] = mx ? s->mv[0][i][0] - p_mx | |
573 : p_mx*(time_pb - time_pp)/time_pp; | |
574 } | |
575 p_my= s->next_picture.motion_val[0][xy][1]; | |
576 if((unsigned)(p_my + tab_bias) < tab_size){ | |
577 s->mv[0][i][1] = s->direct_scale_mv[0][p_my + tab_bias] + my; | |
578 s->mv[1][i][1] = my ? s->mv[0][i][1] - p_my | |
579 : s->direct_scale_mv[1][p_my + tab_bias]; | |
580 }else{ | |
581 s->mv[0][i][1] = p_my*time_pb/time_pp + my; | |
582 s->mv[1][i][1] = my ? s->mv[0][i][1] - p_my | |
583 : p_my*(time_pb - time_pp)/time_pp; | |
584 } | |
585 } | |
586 | |
3255
183e3eb0824a
100l to loren. at least this fixes the compile error, but the code is still broken (decoding buggy/crashing)
rfelker
parents:
3247
diff
changeset
|
587 #undef tab_size |
183e3eb0824a
100l to loren. at least this fixes the compile error, but the code is still broken (decoding buggy/crashing)
rfelker
parents:
3247
diff
changeset
|
588 #undef tab_bias |
183e3eb0824a
100l to loren. at least this fixes the compile error, but the code is still broken (decoding buggy/crashing)
rfelker
parents:
3247
diff
changeset
|
589 |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
590 /** |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
591 * |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
592 * @return the mb_type |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
593 */ |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
594 int ff_mpeg4_set_direct_mv(MpegEncContext *s, int mx, int my){ |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
595 const int mb_index= s->mb_x + s->mb_y*s->mb_stride; |
1708 | 596 const int colocated_mb_type= s->next_picture.mb_type[mb_index]; |
9484
fb240cb99bcf
Remove useless init from ff_mpeg4_set_direct_mv() found by CSA.
michael
parents:
9481
diff
changeset
|
597 uint16_t time_pp; |
fb240cb99bcf
Remove useless init from ff_mpeg4_set_direct_mv() found by CSA.
michael
parents:
9481
diff
changeset
|
598 uint16_t time_pb; |
936 | 599 int i; |
2967 | 600 |
936 | 601 //FIXME avoid divides |
3247 | 602 // try special case with shifts for 1 and 3 B-frames? |
2967 | 603 |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
604 if(IS_8X8(colocated_mb_type)){ |
936 | 605 s->mv_type = MV_TYPE_8X8; |
606 for(i=0; i<4; i++){ | |
3247 | 607 ff_mpeg4_set_one_direct_mv(s, mx, my, i); |
936 | 608 } |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
609 return MB_TYPE_DIRECT2 | MB_TYPE_8x8 | MB_TYPE_L0L1; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
610 } else if(IS_INTERLACED(colocated_mb_type)){ |
936 | 611 s->mv_type = MV_TYPE_FIELD; |
612 for(i=0; i<2; i++){ | |
1948 | 613 int field_select= s->next_picture.ref_index[0][s->block_index[2*i]]; |
3205 | 614 s->field_select[0][i]= field_select; |
615 s->field_select[1][i]= i; | |
936 | 616 if(s->top_field_first){ |
1948 | 617 time_pp= s->pp_field_time - field_select + i; |
618 time_pb= s->pb_field_time - field_select + i; | |
936 | 619 }else{ |
1948 | 620 time_pp= s->pp_field_time + field_select - i; |
621 time_pb= s->pb_field_time + field_select - i; | |
936 | 622 } |
1708 | 623 s->mv[0][i][0] = s->p_field_mv_table[i][0][mb_index][0]*time_pb/time_pp + mx; |
624 s->mv[0][i][1] = s->p_field_mv_table[i][0][mb_index][1]*time_pb/time_pp + my; | |
625 s->mv[1][i][0] = mx ? s->mv[0][i][0] - s->p_field_mv_table[i][0][mb_index][0] | |
626 : s->p_field_mv_table[i][0][mb_index][0]*(time_pb - time_pp)/time_pp; | |
2967 | 627 s->mv[1][i][1] = my ? s->mv[0][i][1] - s->p_field_mv_table[i][0][mb_index][1] |
1708 | 628 : s->p_field_mv_table[i][0][mb_index][1]*(time_pb - time_pp)/time_pp; |
936 | 629 } |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
630 return MB_TYPE_DIRECT2 | MB_TYPE_16x8 | MB_TYPE_L0L1 | MB_TYPE_INTERLACED; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
631 }else{ |
3247 | 632 ff_mpeg4_set_one_direct_mv(s, mx, my, 0); |
633 s->mv[0][1][0] = s->mv[0][2][0] = s->mv[0][3][0] = s->mv[0][0][0]; | |
634 s->mv[0][1][1] = s->mv[0][2][1] = s->mv[0][3][1] = s->mv[0][0][1]; | |
635 s->mv[1][1][0] = s->mv[1][2][0] = s->mv[1][3][0] = s->mv[1][0][0]; | |
636 s->mv[1][1][1] = s->mv[1][2][1] = s->mv[1][3][1] = s->mv[1][0][1]; | |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
637 if((s->avctx->workaround_bugs & FF_BUG_DIRECT_BLOCKSIZE) || !s->quarter_sample) |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
638 s->mv_type= MV_TYPE_16X16; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
639 else |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
640 s->mv_type= MV_TYPE_8X8; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
641 return MB_TYPE_DIRECT2 | MB_TYPE_16x16 | MB_TYPE_L0L1; //Note see prev line |
936 | 642 } |
643 } | |
644 | |
1389 | 645 void ff_h263_update_motion_val(MpegEncContext * s){ |
646 const int mb_xy = s->mb_y * s->mb_stride + s->mb_x; | |
2646
c735e3e60ca7
Even More spelling errors. patch by (Kevin Baragona <kevinmb500 gawab com)
michael
parents:
2639
diff
changeset
|
647 //FIXME a lot of that is only needed for !low_delay |
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1936
diff
changeset
|
648 const int wrap = s->b8_stride; |
1389 | 649 const int xy = s->block_index[0]; |
2967 | 650 |
651 s->current_picture.mbskip_table[mb_xy]= s->mb_skipped; | |
1389 | 652 |
653 if(s->mv_type != MV_TYPE_8X8){ | |
654 int motion_x, motion_y; | |
655 if (s->mb_intra) { | |
656 motion_x = 0; | |
657 motion_y = 0; | |
658 } else if (s->mv_type == MV_TYPE_16X16) { | |
659 motion_x = s->mv[0][0][0]; | |
660 motion_y = s->mv[0][0][1]; | |
661 } else /*if (s->mv_type == MV_TYPE_FIELD)*/ { | |
662 int i; | |
663 motion_x = s->mv[0][0][0] + s->mv[0][1][0]; | |
664 motion_y = s->mv[0][0][1] + s->mv[0][1][1]; | |
665 motion_x = (motion_x>>1) | (motion_x&1); | |
666 for(i=0; i<2; i++){ | |
1708 | 667 s->p_field_mv_table[i][0][mb_xy][0]= s->mv[0][i][0]; |
668 s->p_field_mv_table[i][0][mb_xy][1]= s->mv[0][i][1]; | |
1389 | 669 } |
1948 | 670 s->current_picture.ref_index[0][xy ]= |
671 s->current_picture.ref_index[0][xy + 1]= s->field_select[0][0]; | |
672 s->current_picture.ref_index[0][xy + wrap ]= | |
673 s->current_picture.ref_index[0][xy + wrap + 1]= s->field_select[0][1]; | |
1389 | 674 } |
1948 | 675 |
1389 | 676 /* no update if 8X8 because it has been done during parsing */ |
1668
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1666
diff
changeset
|
677 s->current_picture.motion_val[0][xy][0] = motion_x; |
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1666
diff
changeset
|
678 s->current_picture.motion_val[0][xy][1] = motion_y; |
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1666
diff
changeset
|
679 s->current_picture.motion_val[0][xy + 1][0] = motion_x; |
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1666
diff
changeset
|
680 s->current_picture.motion_val[0][xy + 1][1] = motion_y; |
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1666
diff
changeset
|
681 s->current_picture.motion_val[0][xy + wrap][0] = motion_x; |
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1666
diff
changeset
|
682 s->current_picture.motion_val[0][xy + wrap][1] = motion_y; |
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1666
diff
changeset
|
683 s->current_picture.motion_val[0][xy + 1 + wrap][0] = motion_x; |
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1666
diff
changeset
|
684 s->current_picture.motion_val[0][xy + 1 + wrap][1] = motion_y; |
1389 | 685 } |
686 | |
687 if(s->encoding){ //FIXME encoding MUST be cleaned up | |
2967 | 688 if (s->mv_type == MV_TYPE_8X8) |
1389 | 689 s->current_picture.mb_type[mb_xy]= MB_TYPE_L0 | MB_TYPE_8x8; |
1633 | 690 else if(s->mb_intra) |
691 s->current_picture.mb_type[mb_xy]= MB_TYPE_INTRA; | |
1389 | 692 else |
693 s->current_picture.mb_type[mb_xy]= MB_TYPE_L0 | MB_TYPE_16x16; | |
694 } | |
695 } | |
696 | |
10754
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
697 /** |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
698 * predicts the dc. |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
699 * encoding quantized level -> quantized diff |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
700 * decoding quantized diff -> quantized level |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
701 * @param n block index (0-3 are luma, 4-5 are chroma) |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
702 * @param dir_ptr pointer to an integer where the prediction direction will be stored |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
703 */ |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
704 static inline int ff_mpeg4_pred_dc(MpegEncContext * s, int n, int level, int *dir_ptr, int encoding) |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
705 { |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
706 int a, b, c, wrap, pred, scale, ret; |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
707 int16_t *dc_val; |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
708 |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
709 /* find prediction */ |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
710 if (n < 4) { |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
711 scale = s->y_dc_scale; |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
712 } else { |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
713 scale = s->c_dc_scale; |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
714 } |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
715 if(IS_3IV1) |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
716 scale= 8; |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
717 |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
718 wrap= s->block_wrap[n]; |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
719 dc_val = s->dc_val[0] + s->block_index[n]; |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
720 |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
721 /* B C |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
722 * A X |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
723 */ |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
724 a = dc_val[ - 1]; |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
725 b = dc_val[ - 1 - wrap]; |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
726 c = dc_val[ - wrap]; |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
727 |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
728 /* outside slice handling (we can't do that by memset as we need the dc for error resilience) */ |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
729 if(s->first_slice_line && n!=3){ |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
730 if(n!=2) b=c= 1024; |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
731 if(n!=1 && s->mb_x == s->resync_mb_x) b=a= 1024; |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
732 } |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
733 if(s->mb_x == s->resync_mb_x && s->mb_y == s->resync_mb_y+1){ |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
734 if(n==0 || n==4 || n==5) |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
735 b=1024; |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
736 } |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
737 |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
738 if (abs(a - b) < abs(b - c)) { |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
739 pred = c; |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
740 *dir_ptr = 1; /* top */ |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
741 } else { |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
742 pred = a; |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
743 *dir_ptr = 0; /* left */ |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
744 } |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
745 /* we assume pred is positive */ |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
746 pred = FASTDIV((pred + (scale >> 1)), scale); |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
747 |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
748 if(encoding){ |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
749 ret = level - pred; |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
750 }else{ |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
751 level += pred; |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
752 ret= level; |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
753 if(s->error_recognition>=3){ |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
754 if(level<0){ |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
755 av_log(s->avctx, AV_LOG_ERROR, "dc<0 at %dx%d\n", s->mb_x, s->mb_y); |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
756 return -1; |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
757 } |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
758 if(level*scale > 2048 + scale){ |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
759 av_log(s->avctx, AV_LOG_ERROR, "dc overflow at %dx%d\n", s->mb_x, s->mb_y); |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
760 return -1; |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
761 } |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
762 } |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
763 } |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
764 level *=scale; |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
765 if(level&(~2047)){ |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
766 if(level<0) |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
767 level=0; |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
768 else if(!(s->workaround_bugs&FF_BUG_DC_CLIP)) |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
769 level=2047; |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
770 } |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
771 dc_val[0]= level; |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
772 |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
773 return ret; |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
774 } |
15144b93a64f
10l: Move ff_mpeg4_pred_dc() to an appropriate place.
diego
parents:
10753
diff
changeset
|
775 |
8590 | 776 #if CONFIG_ENCODERS |
1490
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
777 |
10755
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
778 /** |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
779 * encodes the dc value. |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
780 * @param n block index (0-3 are luma, 4-5 are chroma) |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
781 */ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
782 static inline void mpeg4_encode_dc(PutBitContext * s, int level, int n) |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
783 { |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
784 #if 1 |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
785 level+=256; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
786 if (n < 4) { |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
787 /* luminance */ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
788 put_bits(s, uni_DCtab_lum_len[level], uni_DCtab_lum_bits[level]); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
789 } else { |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
790 /* chrominance */ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
791 put_bits(s, uni_DCtab_chrom_len[level], uni_DCtab_chrom_bits[level]); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
792 } |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
793 #else |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
794 int size, v; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
795 /* find number of bits */ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
796 size = 0; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
797 v = abs(level); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
798 while (v) { |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
799 v >>= 1; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
800 size++; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
801 } |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
802 |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
803 if (n < 4) { |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
804 /* luminance */ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
805 put_bits(&s->pb, DCtab_lum[size][1], DCtab_lum[size][0]); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
806 } else { |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
807 /* chrominance */ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
808 put_bits(&s->pb, DCtab_chrom[size][1], DCtab_chrom[size][0]); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
809 } |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
810 |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
811 /* encode remaining bits */ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
812 if (size > 0) { |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
813 if (level < 0) |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
814 level = (-level) ^ ((1 << size) - 1); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
815 put_bits(&s->pb, size, level); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
816 if (size > 8) |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
817 put_bits(&s->pb, 1, 1); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
818 } |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
819 #endif |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
820 } |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
821 |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
822 static inline int mpeg4_get_dc_length(int level, int n){ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
823 if (n < 4) { |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
824 return uni_DCtab_lum_len[level + 256]; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
825 } else { |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
826 return uni_DCtab_chrom_len[level + 256]; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
827 } |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
828 } |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
829 |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
830 /** |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
831 * encodes a 8x8 block |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
832 * @param n block index (0-3 are luma, 4-5 are chroma) |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
833 */ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
834 static inline void mpeg4_encode_block(MpegEncContext * s, DCTELEM * block, int n, int intra_dc, |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
835 uint8_t *scan_table, PutBitContext *dc_pb, PutBitContext *ac_pb) |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
836 { |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
837 int i, last_non_zero; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
838 #if 0 //variables for the outcommented version |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
839 int code, sign, last; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
840 #endif |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
841 const RLTable *rl; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
842 uint32_t *bits_tab; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
843 uint8_t *len_tab; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
844 const int last_index = s->block_last_index[n]; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
845 |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
846 if (s->mb_intra) { //Note gcc (3.2.1 at least) will optimize this away |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
847 /* mpeg4 based DC predictor */ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
848 mpeg4_encode_dc(dc_pb, intra_dc, n); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
849 if(last_index<1) return; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
850 i = 1; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
851 rl = &rl_intra; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
852 bits_tab= uni_mpeg4_intra_rl_bits; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
853 len_tab = uni_mpeg4_intra_rl_len; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
854 } else { |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
855 if(last_index<0) return; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
856 i = 0; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
857 rl = &rl_inter; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
858 bits_tab= uni_mpeg4_inter_rl_bits; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
859 len_tab = uni_mpeg4_inter_rl_len; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
860 } |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
861 |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
862 /* AC coefs */ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
863 last_non_zero = i - 1; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
864 #if 1 |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
865 for (; i < last_index; i++) { |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
866 int level = block[ scan_table[i] ]; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
867 if (level) { |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
868 int run = i - last_non_zero - 1; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
869 level+=64; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
870 if((level&(~127)) == 0){ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
871 const int index= UNI_MPEG4_ENC_INDEX(0, run, level); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
872 put_bits(ac_pb, len_tab[index], bits_tab[index]); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
873 }else{ //ESC3 |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
874 put_bits(ac_pb, 7+2+1+6+1+12+1, (3<<23)+(3<<21)+(0<<20)+(run<<14)+(1<<13)+(((level-64)&0xfff)<<1)+1); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
875 } |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
876 last_non_zero = i; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
877 } |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
878 } |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
879 /*if(i<=last_index)*/{ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
880 int level = block[ scan_table[i] ]; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
881 int run = i - last_non_zero - 1; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
882 level+=64; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
883 if((level&(~127)) == 0){ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
884 const int index= UNI_MPEG4_ENC_INDEX(1, run, level); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
885 put_bits(ac_pb, len_tab[index], bits_tab[index]); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
886 }else{ //ESC3 |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
887 put_bits(ac_pb, 7+2+1+6+1+12+1, (3<<23)+(3<<21)+(1<<20)+(run<<14)+(1<<13)+(((level-64)&0xfff)<<1)+1); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
888 } |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
889 } |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
890 #else |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
891 for (; i <= last_index; i++) { |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
892 const int slevel = block[ scan_table[i] ]; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
893 if (slevel) { |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
894 int level; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
895 int run = i - last_non_zero - 1; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
896 last = (i == last_index); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
897 sign = 0; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
898 level = slevel; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
899 if (level < 0) { |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
900 sign = 1; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
901 level = -level; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
902 } |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
903 code = get_rl_index(rl, last, run, level); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
904 put_bits(ac_pb, rl->table_vlc[code][1], rl->table_vlc[code][0]); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
905 if (code == rl->n) { |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
906 int level1, run1; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
907 level1 = level - rl->max_level[last][run]; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
908 if (level1 < 1) |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
909 goto esc2; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
910 code = get_rl_index(rl, last, run, level1); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
911 if (code == rl->n) { |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
912 esc2: |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
913 put_bits(ac_pb, 1, 1); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
914 if (level > MAX_LEVEL) |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
915 goto esc3; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
916 run1 = run - rl->max_run[last][level] - 1; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
917 if (run1 < 0) |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
918 goto esc3; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
919 code = get_rl_index(rl, last, run1, level); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
920 if (code == rl->n) { |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
921 esc3: |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
922 /* third escape */ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
923 put_bits(ac_pb, 1, 1); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
924 put_bits(ac_pb, 1, last); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
925 put_bits(ac_pb, 6, run); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
926 put_bits(ac_pb, 1, 1); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
927 put_sbits(ac_pb, 12, slevel); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
928 put_bits(ac_pb, 1, 1); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
929 } else { |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
930 /* second escape */ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
931 put_bits(ac_pb, 1, 0); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
932 put_bits(ac_pb, rl->table_vlc[code][1], rl->table_vlc[code][0]); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
933 put_bits(ac_pb, 1, sign); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
934 } |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
935 } else { |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
936 /* first escape */ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
937 put_bits(ac_pb, 1, 0); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
938 put_bits(ac_pb, rl->table_vlc[code][1], rl->table_vlc[code][0]); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
939 put_bits(ac_pb, 1, sign); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
940 } |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
941 } else { |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
942 put_bits(ac_pb, 1, sign); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
943 } |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
944 last_non_zero = i; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
945 } |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
946 } |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
947 #endif |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
948 } |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
949 |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
950 static int mpeg4_get_block_length(MpegEncContext * s, DCTELEM * block, int n, int intra_dc, |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
951 uint8_t *scan_table) |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
952 { |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
953 int i, last_non_zero; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
954 uint8_t *len_tab; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
955 const int last_index = s->block_last_index[n]; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
956 int len=0; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
957 |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
958 if (s->mb_intra) { //Note gcc (3.2.1 at least) will optimize this away |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
959 /* mpeg4 based DC predictor */ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
960 len += mpeg4_get_dc_length(intra_dc, n); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
961 if(last_index<1) return len; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
962 i = 1; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
963 len_tab = uni_mpeg4_intra_rl_len; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
964 } else { |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
965 if(last_index<0) return 0; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
966 i = 0; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
967 len_tab = uni_mpeg4_inter_rl_len; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
968 } |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
969 |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
970 /* AC coefs */ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
971 last_non_zero = i - 1; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
972 for (; i < last_index; i++) { |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
973 int level = block[ scan_table[i] ]; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
974 if (level) { |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
975 int run = i - last_non_zero - 1; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
976 level+=64; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
977 if((level&(~127)) == 0){ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
978 const int index= UNI_MPEG4_ENC_INDEX(0, run, level); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
979 len += len_tab[index]; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
980 }else{ //ESC3 |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
981 len += 7+2+1+6+1+12+1; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
982 } |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
983 last_non_zero = i; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
984 } |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
985 } |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
986 /*if(i<=last_index)*/{ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
987 int level = block[ scan_table[i] ]; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
988 int run = i - last_non_zero - 1; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
989 level+=64; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
990 if((level&(~127)) == 0){ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
991 const int index= UNI_MPEG4_ENC_INDEX(1, run, level); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
992 len += len_tab[index]; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
993 }else{ //ESC3 |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
994 len += 7+2+1+6+1+12+1; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
995 } |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
996 } |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
997 |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
998 return len; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
999 } |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
1000 |
2502 | 1001 static inline int h263_get_motion_length(MpegEncContext * s, int val, int f_code){ |
1002 int l, bit_size, code; | |
1003 | |
1004 if (val == 0) { | |
1005 return mvtab[0][1]; | |
1006 } else { | |
1007 bit_size = f_code - 1; | |
1008 /* modulo encoding */ | |
1009 l= INT_BIT - 6 - bit_size; | |
1010 val = (val<<l)>>l; | |
1011 val--; | |
1012 code = (val >> bit_size) + 1; | |
1013 | |
1014 return mvtab[code][1] + 1 + bit_size; | |
1015 } | |
1016 } | |
1017 | |
1018 static inline void ff_h263_encode_motion_vector(MpegEncContext * s, int x, int y, int f_code){ | |
1019 if(s->flags2 & CODEC_FLAG2_NO_OUTPUT){ | |
2967 | 1020 skip_put_bits(&s->pb, |
2502 | 1021 h263_get_motion_length(s, x, f_code) |
1022 +h263_get_motion_length(s, y, f_code)); | |
1023 }else{ | |
1024 ff_h263_encode_motion(s, x, f_code); | |
1025 ff_h263_encode_motion(s, y, f_code); | |
1026 } | |
1027 } | |
1028 | |
1490
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1029 static inline int get_p_cbp(MpegEncContext * s, |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1030 DCTELEM block[6][64], |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1031 int motion_x, int motion_y){ |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1032 int cbp, i; |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1033 |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1034 if(s->flags & CODEC_FLAG_CBP_RD){ |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1035 int best_cbpy_score= INT_MAX; |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1036 int best_cbpc_score= INT_MAX; |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
1037 int cbpc = (-1), cbpy= (-1); |
1490
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1038 const int offset= (s->mv_type==MV_TYPE_16X16 ? 0 : 16) + (s->dquant ? 8 : 0); |
1505
010f76d07a27
use lagrange multipler instead of qp for ratecontrol, this may break some things, tell me ASAP if u notice anything broken
michaelni
parents:
1492
diff
changeset
|
1039 const int lambda= s->lambda2 >> (FF_LAMBDA_SHIFT - 6); |
1490
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1040 |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1041 for(i=0; i<4; i++){ |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1042 int score= inter_MCBPC_bits[i + offset] * lambda; |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1043 if(i&1) score += s->coded_score[5]; |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1044 if(i&2) score += s->coded_score[4]; |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1045 |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1046 if(score < best_cbpc_score){ |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1047 best_cbpc_score= score; |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1048 cbpc= i; |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1049 } |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1050 } |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1051 |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1052 for(i=0; i<16; i++){ |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1053 int score= cbpy_tab[i ^ 0xF][1] * lambda; |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1054 if(i&1) score += s->coded_score[3]; |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1055 if(i&2) score += s->coded_score[2]; |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1056 if(i&4) score += s->coded_score[1]; |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1057 if(i&8) score += s->coded_score[0]; |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1058 |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1059 if(score < best_cbpy_score){ |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1060 best_cbpy_score= score; |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1061 cbpy= i; |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1062 } |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1063 } |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1064 cbp= cbpc + 4*cbpy; |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1065 if ((motion_x | motion_y | s->dquant) == 0 && s->mv_type==MV_TYPE_16X16){ |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1066 if(best_cbpy_score + best_cbpc_score + 2*lambda >= 0) |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1067 cbp= 0; |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1068 } |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1069 |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1070 for (i = 0; i < 6; i++) { |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1071 if (s->block_last_index[i] >= 0 && ((cbp >> (5 - i))&1)==0 ){ |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1072 s->block_last_index[i]= -1; |
8288 | 1073 s->dsp.clear_block(s->block[i]); |
1490
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1074 } |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1075 } |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1076 }else{ |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1077 cbp= 0; |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1078 for (i = 0; i < 6; i++) { |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1079 if (s->block_last_index[i] >= 0) |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1080 cbp |= 1 << (5 - i); |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1081 } |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1082 } |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1083 return cbp; |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1084 } |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1085 |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1086 static inline int get_b_cbp(MpegEncContext * s, DCTELEM block[6][64], |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1087 int motion_x, int motion_y, int mb_type){ |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1088 int cbp=0, i; |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1089 |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1090 if(s->flags & CODEC_FLAG_CBP_RD){ |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1091 int score=0; |
1505
010f76d07a27
use lagrange multipler instead of qp for ratecontrol, this may break some things, tell me ASAP if u notice anything broken
michaelni
parents:
1492
diff
changeset
|
1092 const int lambda= s->lambda2 >> (FF_LAMBDA_SHIFT - 6); |
2967 | 1093 |
1490
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1094 for(i=0; i<6; i++){ |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1095 if(s->coded_score[i] < 0){ |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1096 score += s->coded_score[i]; |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1097 cbp |= 1 << (5 - i); |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1098 } |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1099 } |
2967 | 1100 |
1490
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1101 if(cbp){ |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1102 int zero_score= -6; |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1103 if ((motion_x | motion_y | s->dquant | mb_type) == 0){ |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1104 zero_score-= 4; //2*MV + mb_type + cbp bit |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1105 } |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1106 |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1107 zero_score*= lambda; |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1108 if(zero_score <= score){ |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1109 cbp=0; |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1110 } |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1111 } |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1112 |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1113 for (i = 0; i < 6; i++) { |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1114 if (s->block_last_index[i] >= 0 && ((cbp >> (5 - i))&1)==0 ){ |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1115 s->block_last_index[i]= -1; |
8288 | 1116 s->dsp.clear_block(s->block[i]); |
1490
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1117 } |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1118 } |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1119 }else{ |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1120 for (i = 0; i < 6; i++) { |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1121 if (s->block_last_index[i] >= 0) |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1122 cbp |= 1 << (5 - i); |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1123 } |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1124 } |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1125 return cbp; |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1126 } |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1127 |
2967 | 1128 static inline void mpeg4_encode_blocks(MpegEncContext * s, DCTELEM block[6][64], int intra_dc[6], |
2502 | 1129 uint8_t **scan_table, PutBitContext *dc_pb, PutBitContext *ac_pb){ |
1130 int i; | |
2967 | 1131 |
2502 | 1132 if(scan_table){ |
1133 if(s->flags2 & CODEC_FLAG2_NO_OUTPUT){ | |
1134 for (i = 0; i < 6; i++) { | |
1135 skip_put_bits(&s->pb, mpeg4_get_block_length(s, block[i], i, intra_dc[i], scan_table[i])); | |
1136 } | |
1137 }else{ | |
1138 /* encode each block */ | |
1139 for (i = 0; i < 6; i++) { | |
1140 mpeg4_encode_block(s, block[i], i, intra_dc[i], scan_table[i], dc_pb, ac_pb); | |
1141 } | |
1142 } | |
1143 }else{ | |
1144 if(s->flags2 & CODEC_FLAG2_NO_OUTPUT){ | |
1145 for (i = 0; i < 6; i++) { | |
1146 skip_put_bits(&s->pb, mpeg4_get_block_length(s, block[i], i, 0, s->intra_scantable.permutated)); | |
1147 } | |
1148 }else{ | |
1149 /* encode each block */ | |
1150 for (i = 0; i < 6; i++) { | |
1151 mpeg4_encode_block(s, block[i], i, 0, s->intra_scantable.permutated, dc_pb, ac_pb); | |
1152 } | |
1153 } | |
1154 } | |
1155 } | |
1156 | |
8644 | 1157 static const int dquant_code[5]= {1,0,9,2,3}; |
1158 | |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1159 void mpeg4_encode_mb(MpegEncContext * s, |
2979 | 1160 DCTELEM block[6][64], |
1161 int motion_x, int motion_y) | |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1162 { |
1057 | 1163 int cbpc, cbpy, pred_x, pred_y; |
453 | 1164 PutBitContext * const pb2 = s->data_partitioning ? &s->pb2 : &s->pb; |
6481 | 1165 PutBitContext * const tex_pb = s->data_partitioning && s->pict_type!=FF_B_TYPE ? &s->tex_pb : &s->pb; |
1166 PutBitContext * const dc_pb = s->data_partitioning && s->pict_type!=FF_I_TYPE ? &s->pb2 : &s->pb; | |
453 | 1167 const int interleaved_stats= (s->flags&CODEC_FLAG_PASS1) && !s->data_partitioning ? 1 : 0; |
2967 | 1168 |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1169 if (!s->mb_intra) { |
1490
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1170 int i, cbp; |
2967 | 1171 |
6481 | 1172 if(s->pict_type==FF_B_TYPE){ |
5445
5581a40c673a
exchange the values of MV_DIR_FORWARD and MV_DIR_BACKWARD (this is more sane,
michael
parents:
5405
diff
changeset
|
1173 static const int mb_type_table[8]= {-1, 3, 2, 1,-1,-1,-1, 0}; /* convert from mv_dir to type */ |
324 | 1174 int mb_type= mb_type_table[s->mv_dir]; |
1708 | 1175 |
324 | 1176 if(s->mb_x==0){ |
1708 | 1177 for(i=0; i<2; i++){ |
2967 | 1178 s->last_mv[i][0][0]= |
1179 s->last_mv[i][0][1]= | |
1180 s->last_mv[i][1][0]= | |
1708 | 1181 s->last_mv[i][1][1]= 0; |
1182 } | |
324 | 1183 } |
2967 | 1184 |
690
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
676
diff
changeset
|
1185 assert(s->dquant>=-2 && s->dquant<=2); |
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
676
diff
changeset
|
1186 assert((s->dquant&1)==0); |
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
676
diff
changeset
|
1187 assert(mb_type>=0); |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1188 |
2628
511e3afc43e1
Ministry of English Composition, reporting for duty (and the word is "skipped", not "skiped"; "skiped" would rhyme with "hyped")
melanson
parents:
2615
diff
changeset
|
1189 /* nothing to do if this MB was skipped in the next P Frame */ |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
1190 if(s->next_picture.mbskip_table[s->mb_y * s->mb_stride + s->mb_x]){ //FIXME avoid DCT & ... |
324 | 1191 s->skip_count++; |
2967 | 1192 s->mv[0][0][0]= |
1193 s->mv[0][0][1]= | |
1194 s->mv[1][0][0]= | |
324 | 1195 s->mv[1][0][1]= 0; |
2646
c735e3e60ca7
Even More spelling errors. patch by (Kevin Baragona <kevinmb500 gawab com)
michael
parents:
2639
diff
changeset
|
1196 s->mv_dir= MV_DIR_FORWARD; //doesn't matter |
690
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
676
diff
changeset
|
1197 s->qscale -= s->dquant; |
2628
511e3afc43e1
Ministry of English Composition, reporting for duty (and the word is "skipped", not "skiped"; "skiped" would rhyme with "hyped")
melanson
parents:
2615
diff
changeset
|
1198 // s->mb_skipped=1; |
903 | 1199 |
324 | 1200 return; |
1201 } | |
2967 | 1202 |
1490
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1203 cbp= get_b_cbp(s, block, motion_x, motion_y, mb_type); |
2967 | 1204 |
324 | 1205 if ((cbp | motion_x | motion_y | mb_type) ==0) { |
1206 /* direct MB with MV={0,0} */ | |
690
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
676
diff
changeset
|
1207 assert(s->dquant==0); |
2967 | 1208 |
324 | 1209 put_bits(&s->pb, 1, 1); /* mb not coded modb1=1 */ |
453 | 1210 |
1211 if(interleaved_stats){ | |
1212 s->misc_bits++; | |
1213 s->last_bits++; | |
1214 } | |
324 | 1215 s->skip_count++; |
1216 return; | |
1217 } | |
2967 | 1218 |
2979 | 1219 put_bits(&s->pb, 1, 0); /* mb coded modb1=0 */ |
324 | 1220 put_bits(&s->pb, 1, cbp ? 0 : 1); /* modb2 */ //FIXME merge |
2646
c735e3e60ca7
Even More spelling errors. patch by (Kevin Baragona <kevinmb500 gawab com)
michael
parents:
2639
diff
changeset
|
1221 put_bits(&s->pb, mb_type+1, 1); // this table is so simple that we don't need it :) |
324 | 1222 if(cbp) put_bits(&s->pb, 6, cbp); |
2967 | 1223 |
690
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
676
diff
changeset
|
1224 if(cbp && mb_type){ |
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
676
diff
changeset
|
1225 if(s->dquant) |
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
676
diff
changeset
|
1226 put_bits(&s->pb, 2, (s->dquant>>2)+3); |
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
676
diff
changeset
|
1227 else |
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
676
diff
changeset
|
1228 put_bits(&s->pb, 1, 0); |
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
676
diff
changeset
|
1229 }else |
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
676
diff
changeset
|
1230 s->qscale -= s->dquant; |
2967 | 1231 |
697 | 1232 if(!s->progressive_sequence){ |
1233 if(cbp) | |
1234 put_bits(&s->pb, 1, s->interlaced_dct); | |
2646
c735e3e60ca7
Even More spelling errors. patch by (Kevin Baragona <kevinmb500 gawab com)
michael
parents:
2639
diff
changeset
|
1235 if(mb_type) // not direct mode |
1708 | 1236 put_bits(&s->pb, 1, s->mv_type == MV_TYPE_FIELD); |
697 | 1237 } |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1238 |
453 | 1239 if(interleaved_stats){ |
1164 | 1240 s->misc_bits+= get_bits_diff(s); |
453 | 1241 } |
295 | 1242 |
1708 | 1243 if(mb_type == 0){ |
1244 assert(s->mv_dir & MV_DIRECT); | |
2502 | 1245 ff_h263_encode_motion_vector(s, motion_x, motion_y, 1); |
656
e47fa3e3f2d5
statistics for forw & back p-MBs instead of just one counter for both
michaelni
parents:
654
diff
changeset
|
1246 s->b_count++; |
e47fa3e3f2d5
statistics for forw & back p-MBs instead of just one counter for both
michaelni
parents:
654
diff
changeset
|
1247 s->f_count++; |
1708 | 1248 }else{ |
1249 assert(mb_type > 0 && mb_type < 4); | |
1250 if(s->mv_type != MV_TYPE_FIELD){ | |
1251 if(s->mv_dir & MV_DIR_FORWARD){ | |
2502 | 1252 ff_h263_encode_motion_vector(s, s->mv[0][0][0] - s->last_mv[0][0][0], |
1253 s->mv[0][0][1] - s->last_mv[0][0][1], s->f_code); | |
1708 | 1254 s->last_mv[0][0][0]= s->last_mv[0][1][0]= s->mv[0][0][0]; |
1255 s->last_mv[0][0][1]= s->last_mv[0][1][1]= s->mv[0][0][1]; | |
1256 s->f_count++; | |
1257 } | |
1258 if(s->mv_dir & MV_DIR_BACKWARD){ | |
2502 | 1259 ff_h263_encode_motion_vector(s, s->mv[1][0][0] - s->last_mv[1][0][0], |
1260 s->mv[1][0][1] - s->last_mv[1][0][1], s->b_code); | |
1708 | 1261 s->last_mv[1][0][0]= s->last_mv[1][1][0]= s->mv[1][0][0]; |
1262 s->last_mv[1][0][1]= s->last_mv[1][1][1]= s->mv[1][0][1]; | |
1263 s->b_count++; | |
1264 } | |
1265 }else{ | |
1266 if(s->mv_dir & MV_DIR_FORWARD){ | |
1267 put_bits(&s->pb, 1, s->field_select[0][0]); | |
1268 put_bits(&s->pb, 1, s->field_select[0][1]); | |
1269 } | |
1270 if(s->mv_dir & MV_DIR_BACKWARD){ | |
1271 put_bits(&s->pb, 1, s->field_select[1][0]); | |
1272 put_bits(&s->pb, 1, s->field_select[1][1]); | |
1273 } | |
1274 if(s->mv_dir & MV_DIR_FORWARD){ | |
1275 for(i=0; i<2; i++){ | |
2502 | 1276 ff_h263_encode_motion_vector(s, s->mv[0][i][0] - s->last_mv[0][i][0] , |
1277 s->mv[0][i][1] - s->last_mv[0][i][1]/2, s->f_code); | |
1708 | 1278 s->last_mv[0][i][0]= s->mv[0][i][0]; |
1279 s->last_mv[0][i][1]= s->mv[0][i][1]*2; | |
1280 } | |
1281 s->f_count++; | |
1282 } | |
1283 if(s->mv_dir & MV_DIR_BACKWARD){ | |
1284 for(i=0; i<2; i++){ | |
2502 | 1285 ff_h263_encode_motion_vector(s, s->mv[1][i][0] - s->last_mv[1][i][0] , |
1286 s->mv[1][i][1] - s->last_mv[1][i][1]/2, s->b_code); | |
1708 | 1287 s->last_mv[1][i][0]= s->mv[1][i][0]; |
1288 s->last_mv[1][i][1]= s->mv[1][i][1]*2; | |
1289 } | |
1290 s->b_count++; | |
1291 } | |
1292 } | |
324 | 1293 } |
453 | 1294 |
1295 if(interleaved_stats){ | |
1164 | 1296 s->mv_bits+= get_bits_diff(s); |
453 | 1297 } |
295 | 1298 |
2502 | 1299 mpeg4_encode_blocks(s, block, NULL, NULL, NULL, &s->pb); |
453 | 1300 |
1301 if(interleaved_stats){ | |
1164 | 1302 s->p_tex_bits+= get_bits_diff(s); |
453 | 1303 } |
1708 | 1304 |
6481 | 1305 }else{ /* s->pict_type==FF_B_TYPE */ |
1490
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1306 cbp= get_p_cbp(s, block, motion_x, motion_y); |
2967 | 1307 |
690
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
676
diff
changeset
|
1308 if ((cbp | motion_x | motion_y | s->dquant) == 0 && s->mv_type==MV_TYPE_16X16) { |
2967 | 1309 /* check if the B frames can skip it too, as we must skip it if we skip here |
2646
c735e3e60ca7
Even More spelling errors. patch by (Kevin Baragona <kevinmb500 gawab com)
michael
parents:
2639
diff
changeset
|
1310 why didn't they just compress the skip-mb bits instead of reusing them ?! */ |
331 | 1311 if(s->max_b_frames>0){ |
1312 int i; | |
364
6b6332e7008a
segfault fix for b-frame encoding with height%16!=0
michaelni
parents:
360
diff
changeset
|
1313 int x,y, offset; |
6b6332e7008a
segfault fix for b-frame encoding with height%16!=0
michaelni
parents:
360
diff
changeset
|
1314 uint8_t *p_pic; |
6b6332e7008a
segfault fix for b-frame encoding with height%16!=0
michaelni
parents:
360
diff
changeset
|
1315 |
6b6332e7008a
segfault fix for b-frame encoding with height%16!=0
michaelni
parents:
360
diff
changeset
|
1316 x= s->mb_x*16; |
6b6332e7008a
segfault fix for b-frame encoding with height%16!=0
michaelni
parents:
360
diff
changeset
|
1317 y= s->mb_y*16; |
6b6332e7008a
segfault fix for b-frame encoding with height%16!=0
michaelni
parents:
360
diff
changeset
|
1318 if(x+16 > s->width) x= s->width-16; |
6b6332e7008a
segfault fix for b-frame encoding with height%16!=0
michaelni
parents:
360
diff
changeset
|
1319 if(y+16 > s->height) y= s->height-16; |
6b6332e7008a
segfault fix for b-frame encoding with height%16!=0
michaelni
parents:
360
diff
changeset
|
1320 |
6b6332e7008a
segfault fix for b-frame encoding with height%16!=0
michaelni
parents:
360
diff
changeset
|
1321 offset= x + y*s->linesize; |
903 | 1322 p_pic= s->new_picture.data[0] + offset; |
2967 | 1323 |
2628
511e3afc43e1
Ministry of English Composition, reporting for duty (and the word is "skipped", not "skiped"; "skiped" would rhyme with "hyped")
melanson
parents:
2615
diff
changeset
|
1324 s->mb_skipped=1; |
331 | 1325 for(i=0; i<s->max_b_frames; i++){ |
339 | 1326 uint8_t *b_pic; |
1327 int diff; | |
903 | 1328 Picture *pic= s->reordered_input_picture[i+1]; |
1329 | |
6481 | 1330 if(pic==NULL || pic->pict_type!=FF_B_TYPE) break; |
903 | 1331 |
3068 | 1332 b_pic= pic->data[0] + offset; |
1333 if(pic->type != FF_BUFFER_TYPE_SHARED) | |
1334 b_pic+= INPLACE_OFFSET; | |
2979 | 1335 diff= s->dsp.sad[0](NULL, p_pic, b_pic, s->linesize, 16); |
364
6b6332e7008a
segfault fix for b-frame encoding with height%16!=0
michaelni
parents:
360
diff
changeset
|
1336 if(diff>s->qscale*70){ //FIXME check that 70 is optimal |
2628
511e3afc43e1
Ministry of English Composition, reporting for duty (and the word is "skipped", not "skiped"; "skiped" would rhyme with "hyped")
melanson
parents:
2615
diff
changeset
|
1337 s->mb_skipped=0; |
331 | 1338 break; |
1339 } | |
1340 } | |
1341 }else | |
2967 | 1342 s->mb_skipped=1; |
2628
511e3afc43e1
Ministry of English Composition, reporting for duty (and the word is "skipped", not "skiped"; "skiped" would rhyme with "hyped")
melanson
parents:
2615
diff
changeset
|
1343 |
511e3afc43e1
Ministry of English Composition, reporting for duty (and the word is "skipped", not "skiped"; "skiped" would rhyme with "hyped")
melanson
parents:
2615
diff
changeset
|
1344 if(s->mb_skipped==1){ |
331 | 1345 /* skip macroblock */ |
1346 put_bits(&s->pb, 1, 1); | |
453 | 1347 |
1348 if(interleaved_stats){ | |
1349 s->misc_bits++; | |
1350 s->last_bits++; | |
1351 } | |
331 | 1352 s->skip_count++; |
2967 | 1353 |
331 | 1354 return; |
1355 } | |
295 | 1356 } |
364
6b6332e7008a
segfault fix for b-frame encoding with height%16!=0
michaelni
parents:
360
diff
changeset
|
1357 |
2979 | 1358 put_bits(&s->pb, 1, 0); /* mb coded */ |
1633 | 1359 cbpc = cbp & 3; |
1360 cbpy = cbp >> 2; | |
1361 cbpy ^= 0xf; | |
324 | 1362 if(s->mv_type==MV_TYPE_16X16){ |
690
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
676
diff
changeset
|
1363 if(s->dquant) cbpc+= 8; |
324 | 1364 put_bits(&s->pb, |
1365 inter_MCBPC_bits[cbpc], | |
1366 inter_MCBPC_code[cbpc]); | |
690
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
676
diff
changeset
|
1367 |
453 | 1368 put_bits(pb2, cbpy_tab[cbpy][1], cbpy_tab[cbpy][0]); |
690
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
676
diff
changeset
|
1369 if(s->dquant) |
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
676
diff
changeset
|
1370 put_bits(pb2, 2, dquant_code[s->dquant+2]); |
697 | 1371 |
1372 if(!s->progressive_sequence){ | |
1373 if(cbp) | |
1374 put_bits(pb2, 1, s->interlaced_dct); | |
1708 | 1375 put_bits(pb2, 1, 0); |
697 | 1376 } |
2967 | 1377 |
453 | 1378 if(interleaved_stats){ |
1164 | 1379 s->misc_bits+= get_bits_diff(s); |
453 | 1380 } |
324 | 1381 |
1382 /* motion vectors: 16x16 mode */ | |
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1936
diff
changeset
|
1383 h263_pred_motion(s, 0, 0, &pred_x, &pred_y); |
2967 | 1384 |
2502 | 1385 ff_h263_encode_motion_vector(s, motion_x - pred_x, |
1386 motion_y - pred_y, s->f_code); | |
1708 | 1387 }else if(s->mv_type==MV_TYPE_FIELD){ |
1388 if(s->dquant) cbpc+= 8; | |
1389 put_bits(&s->pb, | |
1390 inter_MCBPC_bits[cbpc], | |
1391 inter_MCBPC_code[cbpc]); | |
1392 | |
1393 put_bits(pb2, cbpy_tab[cbpy][1], cbpy_tab[cbpy][0]); | |
1394 if(s->dquant) | |
1395 put_bits(pb2, 2, dquant_code[s->dquant+2]); | |
1396 | |
1397 assert(!s->progressive_sequence); | |
1398 if(cbp) | |
1399 put_bits(pb2, 1, s->interlaced_dct); | |
1400 put_bits(pb2, 1, 1); | |
2967 | 1401 |
1708 | 1402 if(interleaved_stats){ |
1403 s->misc_bits+= get_bits_diff(s); | |
1404 } | |
1405 | |
1406 /* motion vectors: 16x8 interlaced mode */ | |
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1936
diff
changeset
|
1407 h263_pred_motion(s, 0, 0, &pred_x, &pred_y); |
1708 | 1408 pred_y /=2; |
2967 | 1409 |
1708 | 1410 put_bits(&s->pb, 1, s->field_select[0][0]); |
1411 put_bits(&s->pb, 1, s->field_select[0][1]); | |
2967 | 1412 |
2502 | 1413 ff_h263_encode_motion_vector(s, s->mv[0][0][0] - pred_x, |
1414 s->mv[0][0][1] - pred_y, s->f_code); | |
1415 ff_h263_encode_motion_vector(s, s->mv[0][1][0] - pred_x, | |
1416 s->mv[0][1][1] - pred_y, s->f_code); | |
324 | 1417 }else{ |
1708 | 1418 assert(s->mv_type==MV_TYPE_8X8); |
324 | 1419 put_bits(&s->pb, |
1633 | 1420 inter_MCBPC_bits[cbpc+16], |
1421 inter_MCBPC_code[cbpc+16]); | |
453 | 1422 put_bits(pb2, cbpy_tab[cbpy][1], cbpy_tab[cbpy][0]); |
1423 | |
757 | 1424 if(!s->progressive_sequence){ |
1425 if(cbp) | |
1426 put_bits(pb2, 1, s->interlaced_dct); | |
1427 } | |
2967 | 1428 |
453 | 1429 if(interleaved_stats){ |
1164 | 1430 s->misc_bits+= get_bits_diff(s); |
453 | 1431 } |
324 | 1432 |
1433 for(i=0; i<4; i++){ | |
1434 /* motion vectors: 8x8 mode*/ | |
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1936
diff
changeset
|
1435 h263_pred_motion(s, i, 0, &pred_x, &pred_y); |
324 | 1436 |
2502 | 1437 ff_h263_encode_motion_vector(s, s->current_picture.motion_val[0][ s->block_index[i] ][0] - pred_x, |
1438 s->current_picture.motion_val[0][ s->block_index[i] ][1] - pred_y, s->f_code); | |
324 | 1439 } |
1440 } | |
453 | 1441 |
2967 | 1442 if(interleaved_stats){ |
1164 | 1443 s->mv_bits+= get_bits_diff(s); |
453 | 1444 } |
324 | 1445 |
2502 | 1446 mpeg4_encode_blocks(s, block, NULL, NULL, NULL, tex_pb); |
453 | 1447 |
1448 if(interleaved_stats){ | |
1164 | 1449 s->p_tex_bits+= get_bits_diff(s); |
453 | 1450 } |
656
e47fa3e3f2d5
statistics for forw & back p-MBs instead of just one counter for both
michaelni
parents:
654
diff
changeset
|
1451 s->f_count++; |
295 | 1452 } |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1453 } else { |
324 | 1454 int cbp; |
2967 | 1455 int dc_diff[6]; //dc values with the dc prediction subtracted |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1456 int dir[6]; //prediction direction |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1457 int zigzag_last_index[6]; |
2979 | 1458 uint8_t *scan_table[6]; |
1057 | 1459 int i; |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1460 |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1461 for(i=0; i<6; i++){ |
2003 | 1462 dc_diff[i]= ff_mpeg4_pred_dc(s, i, block[i][0], &dir[i], 1); |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1463 } |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1464 |
1492 | 1465 if(s->flags & CODEC_FLAG_AC_PRED){ |
1466 s->ac_pred= decide_ac_pred(s, block, dir, scan_table, zigzag_last_index); | |
1467 if(!s->ac_pred) | |
1468 restore_ac_coeffs(s, block, dir, scan_table, zigzag_last_index); | |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1469 }else{ |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1470 for(i=0; i<6; i++) |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
702
diff
changeset
|
1471 scan_table[i]= s->intra_scantable.permutated; |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1472 } |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1473 |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1474 /* compute cbp */ |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1475 cbp = 0; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1476 for (i = 0; i < 6; i++) { |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1477 if (s->block_last_index[i] >= 1) |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1478 cbp |= 1 << (5 - i); |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1479 } |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1480 |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1481 cbpc = cbp & 3; |
6481 | 1482 if (s->pict_type == FF_I_TYPE) { |
690
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
676
diff
changeset
|
1483 if(s->dquant) cbpc+=4; |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1484 put_bits(&s->pb, |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1485 intra_MCBPC_bits[cbpc], |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1486 intra_MCBPC_code[cbpc]); |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1487 } else { |
690
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
676
diff
changeset
|
1488 if(s->dquant) cbpc+=8; |
2979 | 1489 put_bits(&s->pb, 1, 0); /* mb coded */ |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1490 put_bits(&s->pb, |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1491 inter_MCBPC_bits[cbpc + 4], |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1492 inter_MCBPC_code[cbpc + 4]); |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1493 } |
453 | 1494 put_bits(pb2, 1, s->ac_pred); |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1495 cbpy = cbp >> 2; |
453 | 1496 put_bits(pb2, cbpy_tab[cbpy][1], cbpy_tab[cbpy][0]); |
690
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
676
diff
changeset
|
1497 if(s->dquant) |
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
676
diff
changeset
|
1498 put_bits(dc_pb, 2, dquant_code[s->dquant+2]); |
453 | 1499 |
697 | 1500 if(!s->progressive_sequence){ |
1501 put_bits(dc_pb, 1, s->interlaced_dct); | |
1502 } | |
1503 | |
453 | 1504 if(interleaved_stats){ |
1164 | 1505 s->misc_bits+= get_bits_diff(s); |
453 | 1506 } |
286 | 1507 |
2502 | 1508 mpeg4_encode_blocks(s, block, dc_diff, scan_table, dc_pb, tex_pb); |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1509 |
453 | 1510 if(interleaved_stats){ |
1164 | 1511 s->i_tex_bits+= get_bits_diff(s); |
453 | 1512 } |
286 | 1513 s->i_count++; |
1514 | |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1515 /* restore ac coeffs & last_index stuff if we messed them up with the prediction */ |
1492 | 1516 if(s->ac_pred) |
1517 restore_ac_coeffs(s, block, dir, scan_table, zigzag_last_index); | |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1518 } |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1519 } |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1520 |
10752
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1521 /** |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1522 * encodes a 8x8 block. |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1523 * @param block the 8x8 block |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1524 * @param n block index (0-3 are luma, 4-5 are chroma) |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1525 */ |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1526 static void h263_encode_block(MpegEncContext * s, DCTELEM * block, int n) |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1527 { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1528 int level, run, last, i, j, last_index, last_non_zero, sign, slevel, code; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1529 RLTable *rl; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1530 |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1531 rl = &rl_inter; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1532 if (s->mb_intra && !s->h263_aic) { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1533 /* DC coef */ |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1534 level = block[0]; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1535 /* 255 cannot be represented, so we clamp */ |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1536 if (level > 254) { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1537 level = 254; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1538 block[0] = 254; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1539 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1540 /* 0 cannot be represented also */ |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1541 else if (level < 1) { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1542 level = 1; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1543 block[0] = 1; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1544 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1545 if (level == 128) //FIXME check rv10 |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1546 put_bits(&s->pb, 8, 0xff); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1547 else |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1548 put_bits(&s->pb, 8, level); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1549 i = 1; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1550 } else { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1551 i = 0; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1552 if (s->h263_aic && s->mb_intra) |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1553 rl = &rl_intra_aic; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1554 |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1555 if(s->alt_inter_vlc && !s->mb_intra){ |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1556 int aic_vlc_bits=0; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1557 int inter_vlc_bits=0; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1558 int wrong_pos=-1; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1559 int aic_code; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1560 |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1561 last_index = s->block_last_index[n]; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1562 last_non_zero = i - 1; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1563 for (; i <= last_index; i++) { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1564 j = s->intra_scantable.permutated[i]; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1565 level = block[j]; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1566 if (level) { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1567 run = i - last_non_zero - 1; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1568 last = (i == last_index); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1569 |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1570 if(level<0) level= -level; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1571 |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1572 code = get_rl_index(rl, last, run, level); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1573 aic_code = get_rl_index(&rl_intra_aic, last, run, level); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1574 inter_vlc_bits += rl->table_vlc[code][1]+1; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1575 aic_vlc_bits += rl_intra_aic.table_vlc[aic_code][1]+1; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1576 |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1577 if (code == rl->n) { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1578 inter_vlc_bits += 1+6+8-1; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1579 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1580 if (aic_code == rl_intra_aic.n) { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1581 aic_vlc_bits += 1+6+8-1; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1582 wrong_pos += run + 1; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1583 }else |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1584 wrong_pos += wrong_run[aic_code]; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1585 last_non_zero = i; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1586 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1587 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1588 i = 0; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1589 if(aic_vlc_bits < inter_vlc_bits && wrong_pos > 63) |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1590 rl = &rl_intra_aic; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1591 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1592 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1593 |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1594 /* AC coefs */ |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1595 last_index = s->block_last_index[n]; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1596 last_non_zero = i - 1; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1597 for (; i <= last_index; i++) { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1598 j = s->intra_scantable.permutated[i]; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1599 level = block[j]; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1600 if (level) { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1601 run = i - last_non_zero - 1; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1602 last = (i == last_index); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1603 sign = 0; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1604 slevel = level; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1605 if (level < 0) { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1606 sign = 1; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1607 level = -level; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1608 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1609 code = get_rl_index(rl, last, run, level); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1610 put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1611 if (code == rl->n) { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1612 if(s->h263_flv <= 1){ |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1613 put_bits(&s->pb, 1, last); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1614 put_bits(&s->pb, 6, run); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1615 |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1616 assert(slevel != 0); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1617 |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1618 if(level < 128) |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1619 put_sbits(&s->pb, 8, slevel); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1620 else{ |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1621 put_bits(&s->pb, 8, 128); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1622 put_sbits(&s->pb, 5, slevel); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1623 put_sbits(&s->pb, 6, slevel>>5); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1624 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1625 }else{ |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1626 if(level < 64) { // 7-bit level |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1627 put_bits(&s->pb, 1, 0); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1628 put_bits(&s->pb, 1, last); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1629 put_bits(&s->pb, 6, run); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1630 |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1631 put_sbits(&s->pb, 7, slevel); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1632 } else { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1633 /* 11-bit level */ |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1634 put_bits(&s->pb, 1, 1); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1635 put_bits(&s->pb, 1, last); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1636 put_bits(&s->pb, 6, run); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1637 |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1638 put_sbits(&s->pb, 11, slevel); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1639 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1640 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1641 } else { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1642 put_bits(&s->pb, 1, sign); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1643 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1644 last_non_zero = i; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1645 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1646 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1647 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1648 |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1649 /* Encode MV differences on H.263+ with Unrestricted MV mode */ |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1650 static void h263p_encode_umotion(MpegEncContext * s, int val) |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1651 { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1652 short sval = 0; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1653 short i = 0; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1654 short n_bits = 0; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1655 short temp_val; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1656 int code = 0; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1657 int tcode; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1658 |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1659 if ( val == 0) |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1660 put_bits(&s->pb, 1, 1); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1661 else if (val == 1) |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1662 put_bits(&s->pb, 3, 0); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1663 else if (val == -1) |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1664 put_bits(&s->pb, 3, 2); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1665 else { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1666 |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1667 sval = ((val < 0) ? (short)(-val):(short)val); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1668 temp_val = sval; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1669 |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1670 while (temp_val != 0) { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1671 temp_val = temp_val >> 1; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1672 n_bits++; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1673 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1674 |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1675 i = n_bits - 1; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1676 while (i > 0) { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1677 tcode = (sval & (1 << (i-1))) >> (i-1); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1678 tcode = (tcode << 1) | 1; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1679 code = (code << 2) | tcode; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1680 i--; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1681 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1682 code = ((code << 1) | (val < 0)) << 1; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1683 put_bits(&s->pb, (2*n_bits)+1, code); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1684 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1685 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1686 |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1687 static int h263_pred_dc(MpegEncContext * s, int n, int16_t **dc_val_ptr) |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1688 { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1689 int x, y, wrap, a, c, pred_dc; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1690 int16_t *dc_val; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1691 |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1692 /* find prediction */ |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1693 if (n < 4) { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1694 x = 2 * s->mb_x + (n & 1); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1695 y = 2 * s->mb_y + ((n & 2) >> 1); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1696 wrap = s->b8_stride; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1697 dc_val = s->dc_val[0]; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1698 } else { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1699 x = s->mb_x; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1700 y = s->mb_y; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1701 wrap = s->mb_stride; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1702 dc_val = s->dc_val[n - 4 + 1]; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1703 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1704 /* B C |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1705 * A X |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1706 */ |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1707 a = dc_val[(x - 1) + (y) * wrap]; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1708 c = dc_val[(x) + (y - 1) * wrap]; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1709 |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1710 /* No prediction outside GOB boundary */ |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1711 if(s->first_slice_line && n!=3){ |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1712 if(n!=2) c= 1024; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1713 if(n!=1 && s->mb_x == s->resync_mb_x) a= 1024; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1714 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1715 /* just DC prediction */ |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1716 if (a != 1024 && c != 1024) |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1717 pred_dc = (a + c) >> 1; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1718 else if (a != 1024) |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1719 pred_dc = a; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1720 else |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1721 pred_dc = c; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1722 |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1723 /* we assume pred is positive */ |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1724 *dc_val_ptr = &dc_val[x + y * wrap]; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1725 return pred_dc; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1726 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1727 |
0 | 1728 void h263_encode_mb(MpegEncContext * s, |
2979 | 1729 DCTELEM block[6][64], |
1730 int motion_x, int motion_y) | |
0 | 1731 { |
1732 int cbpc, cbpy, i, cbp, pred_x, pred_y; | |
1064 | 1733 int16_t pred_dc; |
1734 int16_t rec_intradc[6]; | |
3781 | 1735 int16_t *dc_ptr[6]; |
1353
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
1736 const int interleaved_stats= (s->flags&CODEC_FLAG_PASS1); |
2967 | 1737 |
324 | 1738 if (!s->mb_intra) { |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
1739 /* compute cbp */ |
1490
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1740 cbp= get_p_cbp(s, block, motion_x, motion_y); |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
1741 |
1789 | 1742 if ((cbp | motion_x | motion_y | s->dquant | (s->mv_type - MV_TYPE_16X16)) == 0) { |
324 | 1743 /* skip macroblock */ |
1744 put_bits(&s->pb, 1, 1); | |
1353
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
1745 if(interleaved_stats){ |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
1746 s->misc_bits++; |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
1747 s->last_bits++; |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
1748 } |
1757
3906ddbaffec
optimization & bugfix extracted from the 4k line diff between ffmpeg 0.4.7 and http://www.alicestreet.com/ffh263.html
michael
parents:
1752
diff
changeset
|
1749 s->skip_count++; |
3906ddbaffec
optimization & bugfix extracted from the 4k line diff between ffmpeg 0.4.7 and http://www.alicestreet.com/ffh263.html
michael
parents:
1752
diff
changeset
|
1750 |
324 | 1751 return; |
1752 } | |
2979 | 1753 put_bits(&s->pb, 1, 0); /* mb coded */ |
2967 | 1754 |
324 | 1755 cbpc = cbp & 3; |
1637 | 1756 cbpy = cbp >> 2; |
1757 if(s->alt_inter_vlc==0 || cbpc!=3) | |
1758 cbpy ^= 0xF; | |
695 | 1759 if(s->dquant) cbpc+= 8; |
1633 | 1760 if(s->mv_type==MV_TYPE_16X16){ |
1761 put_bits(&s->pb, | |
1762 inter_MCBPC_bits[cbpc], | |
1763 inter_MCBPC_code[cbpc]); | |
1764 | |
1765 put_bits(&s->pb, cbpy_tab[cbpy][1], cbpy_tab[cbpy][0]); | |
1766 if(s->dquant) | |
1767 put_bits(&s->pb, 2, dquant_code[s->dquant+2]); | |
2967 | 1768 |
1633 | 1769 if(interleaved_stats){ |
1770 s->misc_bits+= get_bits_diff(s); | |
1771 } | |
1772 | |
1773 /* motion vectors: 16x16 mode */ | |
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1936
diff
changeset
|
1774 h263_pred_motion(s, 0, 0, &pred_x, &pred_y); |
2967 | 1775 |
1776 if (!s->umvplus) { | |
2502 | 1777 ff_h263_encode_motion_vector(s, motion_x - pred_x, |
1778 motion_y - pred_y, 1); | |
1633 | 1779 } |
1780 else { | |
1781 h263p_encode_umotion(s, motion_x - pred_x); | |
1782 h263p_encode_umotion(s, motion_y - pred_y); | |
1783 if (((motion_x - pred_x) == 1) && ((motion_y - pred_y) == 1)) | |
1784 /* To prevent Start Code emulation */ | |
1785 put_bits(&s->pb,1,1); | |
1786 } | |
1787 }else{ | |
1788 put_bits(&s->pb, | |
1789 inter_MCBPC_bits[cbpc+16], | |
1790 inter_MCBPC_code[cbpc+16]); | |
1791 put_bits(&s->pb, cbpy_tab[cbpy][1], cbpy_tab[cbpy][0]); | |
1792 if(s->dquant) | |
1793 put_bits(&s->pb, 2, dquant_code[s->dquant+2]); | |
1794 | |
1795 if(interleaved_stats){ | |
1796 s->misc_bits+= get_bits_diff(s); | |
1797 } | |
1798 | |
1799 for(i=0; i<4; i++){ | |
1800 /* motion vectors: 8x8 mode*/ | |
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1936
diff
changeset
|
1801 h263_pred_motion(s, i, 0, &pred_x, &pred_y); |
1633 | 1802 |
1668
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1666
diff
changeset
|
1803 motion_x= s->current_picture.motion_val[0][ s->block_index[i] ][0]; |
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1666
diff
changeset
|
1804 motion_y= s->current_picture.motion_val[0][ s->block_index[i] ][1]; |
2967 | 1805 if (!s->umvplus) { |
2502 | 1806 ff_h263_encode_motion_vector(s, motion_x - pred_x, |
1807 motion_y - pred_y, 1); | |
1633 | 1808 } |
1809 else { | |
1810 h263p_encode_umotion(s, motion_x - pred_x); | |
1811 h263p_encode_umotion(s, motion_y - pred_y); | |
1812 if (((motion_x - pred_x) == 1) && ((motion_y - pred_y) == 1)) | |
1813 /* To prevent Start Code emulation */ | |
1814 put_bits(&s->pb,1,1); | |
1815 } | |
1816 } | |
324 | 1817 } |
1353
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
1818 |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
1819 if(interleaved_stats){ |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
1820 s->mv_bits+= get_bits_diff(s); |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
1821 } |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
1822 } else { |
1639 | 1823 assert(s->mb_intra); |
2967 | 1824 |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
1825 cbp = 0; |
1666 | 1826 if (s->h263_aic) { |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
1827 /* Predict DC */ |
1666 | 1828 for(i=0; i<6; i++) { |
1064 | 1829 int16_t level = block[i][0]; |
1666 | 1830 int scale; |
2967 | 1831 |
1666 | 1832 if(i<4) scale= s->y_dc_scale; |
1833 else scale= s->c_dc_scale; | |
1834 | |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
1835 pred_dc = h263_pred_dc(s, i, &dc_ptr[i]); |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
1836 level -= pred_dc; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
1837 /* Quant */ |
1666 | 1838 if (level >= 0) |
1839 level = (level + (scale>>1))/scale; | |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
1840 else |
1666 | 1841 level = (level - (scale>>1))/scale; |
2967 | 1842 |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
1843 /* AIC can change CBP */ |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
1844 if (level == 0 && s->block_last_index[i] == 0) |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
1845 s->block_last_index[i] = -1; |
1666 | 1846 |
1847 if(!s->modified_quant){ | |
1848 if (level < -127) | |
1849 level = -127; | |
1850 else if (level > 127) | |
1851 level = 127; | |
1852 } | |
1853 | |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
1854 block[i][0] = level; |
2967 | 1855 /* Reconstruction */ |
1666 | 1856 rec_intradc[i] = scale*level + pred_dc; |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
1857 /* Oddify */ |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
1858 rec_intradc[i] |= 1; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
1859 //if ((rec_intradc[i] % 2) == 0) |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
1860 // rec_intradc[i]++; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
1861 /* Clipping */ |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
1862 if (rec_intradc[i] < 0) |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
1863 rec_intradc[i] = 0; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
1864 else if (rec_intradc[i] > 2047) |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
1865 rec_intradc[i] = 2047; |
2967 | 1866 |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
1867 /* Update AC/DC tables */ |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
1868 *dc_ptr[i] = rec_intradc[i]; |
1666 | 1869 if (s->block_last_index[i] >= 0) |
1870 cbp |= 1 << (5 - i); | |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
1871 } |
1666 | 1872 }else{ |
1873 for(i=0; i<6; i++) { | |
1874 /* compute cbp */ | |
1875 if (s->block_last_index[i] >= 1) | |
1876 cbp |= 1 << (5 - i); | |
1877 } | |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
1878 } |
0 | 1879 |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
1880 cbpc = cbp & 3; |
6481 | 1881 if (s->pict_type == FF_I_TYPE) { |
695 | 1882 if(s->dquant) cbpc+=4; |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
1883 put_bits(&s->pb, |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
1884 intra_MCBPC_bits[cbpc], |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
1885 intra_MCBPC_code[cbpc]); |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
1886 } else { |
695 | 1887 if(s->dquant) cbpc+=8; |
2979 | 1888 put_bits(&s->pb, 1, 0); /* mb coded */ |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
1889 put_bits(&s->pb, |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
1890 inter_MCBPC_bits[cbpc + 4], |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
1891 inter_MCBPC_code[cbpc + 4]); |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
1892 } |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
1893 if (s->h263_aic) { |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
1894 /* XXX: currently, we do not try to use ac prediction */ |
2979 | 1895 put_bits(&s->pb, 1, 0); /* no AC prediction */ |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
1896 } |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
1897 cbpy = cbp >> 2; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
1898 put_bits(&s->pb, cbpy_tab[cbpy][1], cbpy_tab[cbpy][0]); |
695 | 1899 if(s->dquant) |
1900 put_bits(&s->pb, 2, dquant_code[s->dquant+2]); | |
1353
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
1901 |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
1902 if(interleaved_stats){ |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
1903 s->misc_bits+= get_bits_diff(s); |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
1904 } |
0 | 1905 } |
1906 | |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
1907 for(i=0; i<6; i++) { |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
1908 /* encode each block */ |
1354 | 1909 h263_encode_block(s, block[i], i); |
2967 | 1910 |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
1911 /* Update INTRADC for decoding */ |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
1912 if (s->h263_aic && s->mb_intra) { |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
1913 block[i][0] = rec_intradc[i]; |
2967 | 1914 |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
1915 } |
0 | 1916 } |
1353
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
1917 |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
1918 if(interleaved_stats){ |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
1919 if (!s->mb_intra) { |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
1920 s->p_tex_bits+= get_bits_diff(s); |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
1921 s->f_count++; |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
1922 }else{ |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
1923 s->i_tex_bits+= get_bits_diff(s); |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
1924 s->i_count++; |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
1925 } |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
1926 } |
0 | 1927 } |
815
78accc54493b
put a few large tables under #ifdef CONFIG_ENCODERS or dynamically allocate them
michaelni
parents:
770
diff
changeset
|
1928 #endif |
0 | 1929 |
1656 | 1930 void ff_h263_loop_filter(MpegEncContext * s){ |
1644 | 1931 int qp_c; |
1932 const int linesize = s->linesize; | |
1933 const int uvlinesize= s->uvlinesize; | |
1934 const int xy = s->mb_y * s->mb_stride + s->mb_x; | |
1935 uint8_t *dest_y = s->dest[0]; | |
1936 uint8_t *dest_cb= s->dest[1]; | |
1937 uint8_t *dest_cr= s->dest[2]; | |
2967 | 1938 |
6481 | 1939 // if(s->pict_type==FF_B_TYPE && !s->readable) return; |
1644 | 1940 |
1941 /* | |
1942 Diag Top | |
1943 Left Center | |
1944 */ | |
1945 if(!IS_SKIP(s->current_picture.mb_type[xy])){ | |
1946 qp_c= s->qscale; | |
1947 s->dsp.h263_v_loop_filter(dest_y+8*linesize , linesize, qp_c); | |
1948 s->dsp.h263_v_loop_filter(dest_y+8*linesize+8, linesize, qp_c); | |
1949 }else | |
1950 qp_c= 0; | |
1951 | |
1952 if(s->mb_y){ | |
8297
20e0f0809b27
s/qp_t/qp_tt/ to avoid bad examples that could lead to issues with reserved
michael
parents:
8288
diff
changeset
|
1953 int qp_dt, qp_tt, qp_tc; |
1644 | 1954 |
1955 if(IS_SKIP(s->current_picture.mb_type[xy-s->mb_stride])) | |
8297
20e0f0809b27
s/qp_t/qp_tt/ to avoid bad examples that could lead to issues with reserved
michael
parents:
8288
diff
changeset
|
1956 qp_tt=0; |
2967 | 1957 else |
8297
20e0f0809b27
s/qp_t/qp_tt/ to avoid bad examples that could lead to issues with reserved
michael
parents:
8288
diff
changeset
|
1958 qp_tt= s->current_picture.qscale_table[xy-s->mb_stride]; |
1644 | 1959 |
2967 | 1960 if(qp_c) |
1644 | 1961 qp_tc= qp_c; |
1962 else | |
8297
20e0f0809b27
s/qp_t/qp_tt/ to avoid bad examples that could lead to issues with reserved
michael
parents:
8288
diff
changeset
|
1963 qp_tc= qp_tt; |
2967 | 1964 |
1644 | 1965 if(qp_tc){ |
1966 const int chroma_qp= s->chroma_qscale_table[qp_tc]; | |
1967 s->dsp.h263_v_loop_filter(dest_y , linesize, qp_tc); | |
1968 s->dsp.h263_v_loop_filter(dest_y+8, linesize, qp_tc); | |
2967 | 1969 |
1644 | 1970 s->dsp.h263_v_loop_filter(dest_cb , uvlinesize, chroma_qp); |
1971 s->dsp.h263_v_loop_filter(dest_cr , uvlinesize, chroma_qp); | |
1972 } | |
2967 | 1973 |
8297
20e0f0809b27
s/qp_t/qp_tt/ to avoid bad examples that could lead to issues with reserved
michael
parents:
8288
diff
changeset
|
1974 if(qp_tt) |
20e0f0809b27
s/qp_t/qp_tt/ to avoid bad examples that could lead to issues with reserved
michael
parents:
8288
diff
changeset
|
1975 s->dsp.h263_h_loop_filter(dest_y-8*linesize+8 , linesize, qp_tt); |
2967 | 1976 |
1644 | 1977 if(s->mb_x){ |
8297
20e0f0809b27
s/qp_t/qp_tt/ to avoid bad examples that could lead to issues with reserved
michael
parents:
8288
diff
changeset
|
1978 if(qp_tt || IS_SKIP(s->current_picture.mb_type[xy-1-s->mb_stride])) |
20e0f0809b27
s/qp_t/qp_tt/ to avoid bad examples that could lead to issues with reserved
michael
parents:
8288
diff
changeset
|
1979 qp_dt= qp_tt; |
1644 | 1980 else |
1981 qp_dt= s->current_picture.qscale_table[xy-1-s->mb_stride]; | |
2967 | 1982 |
1644 | 1983 if(qp_dt){ |
1984 const int chroma_qp= s->chroma_qscale_table[qp_dt]; | |
1985 s->dsp.h263_h_loop_filter(dest_y -8*linesize , linesize, qp_dt); | |
1986 s->dsp.h263_h_loop_filter(dest_cb-8*uvlinesize, uvlinesize, chroma_qp); | |
2178 | 1987 s->dsp.h263_h_loop_filter(dest_cr-8*uvlinesize, uvlinesize, chroma_qp); |
1644 | 1988 } |
1989 } | |
1990 } | |
1991 | |
1992 if(qp_c){ | |
1993 s->dsp.h263_h_loop_filter(dest_y +8, linesize, qp_c); | |
1994 if(s->mb_y + 1 == s->mb_height) | |
1995 s->dsp.h263_h_loop_filter(dest_y+8*linesize+8, linesize, qp_c); | |
1996 } | |
2967 | 1997 |
1644 | 1998 if(s->mb_x){ |
1999 int qp_lc; | |
2000 if(qp_c || IS_SKIP(s->current_picture.mb_type[xy-1])) | |
2001 qp_lc= qp_c; | |
2002 else | |
2003 qp_lc= s->current_picture.qscale_table[xy-1]; | |
2967 | 2004 |
1644 | 2005 if(qp_lc){ |
2006 s->dsp.h263_h_loop_filter(dest_y, linesize, qp_lc); | |
2007 if(s->mb_y + 1 == s->mb_height){ | |
2008 const int chroma_qp= s->chroma_qscale_table[qp_lc]; | |
2009 s->dsp.h263_h_loop_filter(dest_y +8* linesize, linesize, qp_lc); | |
2010 s->dsp.h263_h_loop_filter(dest_cb , uvlinesize, chroma_qp); | |
2011 s->dsp.h263_h_loop_filter(dest_cr , uvlinesize, chroma_qp); | |
2012 } | |
2013 } | |
2014 } | |
2015 } | |
2016 | |
1057 | 2017 static void h263_pred_acdc(MpegEncContext * s, DCTELEM *block, int n) |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
2018 { |
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
2019 int x, y, wrap, a, c, pred_dc, scale, i; |
3781 | 2020 int16_t *dc_val, *ac_val, *ac_val1; |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
2021 |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
2022 /* find prediction */ |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
2023 if (n < 4) { |
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1936
diff
changeset
|
2024 x = 2 * s->mb_x + (n & 1); |
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1936
diff
changeset
|
2025 y = 2 * s->mb_y + (n>> 1); |
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1936
diff
changeset
|
2026 wrap = s->b8_stride; |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
2027 dc_val = s->dc_val[0]; |
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
2028 ac_val = s->ac_val[0][0]; |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
2029 scale = s->y_dc_scale; |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
2030 } else { |
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1936
diff
changeset
|
2031 x = s->mb_x; |
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1936
diff
changeset
|
2032 y = s->mb_y; |
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1936
diff
changeset
|
2033 wrap = s->mb_stride; |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
2034 dc_val = s->dc_val[n - 4 + 1]; |
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
2035 ac_val = s->ac_val[n - 4 + 1][0]; |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
2036 scale = s->c_dc_scale; |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
2037 } |
2967 | 2038 |
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
2039 ac_val += ((y) * wrap + (x)) * 16; |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
2040 ac_val1 = ac_val; |
2967 | 2041 |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
2042 /* B C |
2967 | 2043 * A X |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
2044 */ |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
2045 a = dc_val[(x - 1) + (y) * wrap]; |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
2046 c = dc_val[(x) + (y - 1) * wrap]; |
2967 | 2047 |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
2048 /* No prediction outside GOB boundary */ |
1639 | 2049 if(s->first_slice_line && n!=3){ |
2050 if(n!=2) c= 1024; | |
2051 if(n!=1 && s->mb_x == s->resync_mb_x) a= 1024; | |
2052 } | |
2967 | 2053 |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
2054 if (s->ac_pred) { |
1639 | 2055 pred_dc = 1024; |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
2056 if (s->h263_aic_dir) { |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
2057 /* left prediction */ |
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
2058 if (a != 1024) { |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
2059 ac_val -= 16; |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
2060 for(i=1;i<8;i++) { |
1092 | 2061 block[s->dsp.idct_permutation[i<<3]] += ac_val[i]; |
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
2062 } |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
2063 pred_dc = a; |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
2064 } |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
2065 } else { |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
2066 /* top prediction */ |
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
2067 if (c != 1024) { |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
2068 ac_val -= 16 * wrap; |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
2069 for(i=1;i<8;i++) { |
1092 | 2070 block[s->dsp.idct_permutation[i ]] += ac_val[i + 8]; |
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
2071 } |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
2072 pred_dc = c; |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
2073 } |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
2074 } |
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
2075 } else { |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
2076 /* just DC prediction */ |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
2077 if (a != 1024 && c != 1024) |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
2078 pred_dc = (a + c) >> 1; |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
2079 else if (a != 1024) |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
2080 pred_dc = a; |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
2081 else |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
2082 pred_dc = c; |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
2083 } |
2967 | 2084 |
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
2085 /* we assume pred is positive */ |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
2086 block[0]=block[0]*scale + pred_dc; |
2967 | 2087 |
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
2088 if (block[0] < 0) |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
2089 block[0] = 0; |
2967 | 2090 else |
1639 | 2091 block[0] |= 1; |
2967 | 2092 |
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
2093 /* Update AC/DC tables */ |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
2094 dc_val[(x) + (y) * wrap] = block[0]; |
2967 | 2095 |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
2096 /* left copy */ |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
2097 for(i=1;i<8;i++) |
1092 | 2098 ac_val1[i ] = block[s->dsp.idct_permutation[i<<3]]; |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
2099 /* top copy */ |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
2100 for(i=1;i<8;i++) |
1092 | 2101 ac_val1[8 + i] = block[s->dsp.idct_permutation[i ]]; |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
2102 } |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
2103 |
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1936
diff
changeset
|
2104 int16_t *h263_pred_motion(MpegEncContext * s, int block, int dir, |
0 | 2105 int *px, int *py) |
2106 { | |
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1936
diff
changeset
|
2107 int wrap; |
1655 | 2108 int16_t *A, *B, *C, (*mot_val)[2]; |
2109 static const int off[4]= {2, 1, 1, -1}; | |
2110 | |
2111 wrap = s->b8_stride; | |
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1936
diff
changeset
|
2112 mot_val = s->current_picture.motion_val[dir] + s->block_index[block]; |
1655 | 2113 |
2114 A = mot_val[ - 1]; | |
2115 /* special case for first (slice) line */ | |
2116 if (s->first_slice_line && block<3) { | |
2646
c735e3e60ca7
Even More spelling errors. patch by (Kevin Baragona <kevinmb500 gawab com)
michael
parents:
2639
diff
changeset
|
2117 // we can't just change some MVs to simulate that as we need them for the B frames (and ME) |
1655 | 2118 // and if we ever support non rectangular objects than we need to do a few ifs here anyway :( |
2119 if(block==0){ //most common case | |
2120 if(s->mb_x == s->resync_mb_x){ //rare | |
2121 *px= *py = 0; | |
2122 }else if(s->mb_x + 1 == s->resync_mb_x && s->h263_pred){ //rare | |
2123 C = mot_val[off[block] - wrap]; | |
2124 if(s->mb_x==0){ | |
2125 *px = C[0]; | |
2126 *py = C[1]; | |
2127 }else{ | |
2128 *px = mid_pred(A[0], 0, C[0]); | |
2129 *py = mid_pred(A[1], 0, C[1]); | |
2130 } | |
2131 }else{ | |
2132 *px = A[0]; | |
2133 *py = A[1]; | |
2134 } | |
2135 }else if(block==1){ | |
2136 if(s->mb_x + 1 == s->resync_mb_x && s->h263_pred){ //rare | |
2137 C = mot_val[off[block] - wrap]; | |
2138 *px = mid_pred(A[0], 0, C[0]); | |
2139 *py = mid_pred(A[1], 0, C[1]); | |
2140 }else{ | |
2141 *px = A[0]; | |
2142 *py = A[1]; | |
2143 } | |
2144 }else{ /* block==2*/ | |
2145 B = mot_val[ - wrap]; | |
2146 C = mot_val[off[block] - wrap]; | |
2147 if(s->mb_x == s->resync_mb_x) //rare | |
2148 A[0]=A[1]=0; | |
2967 | 2149 |
1655 | 2150 *px = mid_pred(A[0], B[0], C[0]); |
2151 *py = mid_pred(A[1], B[1], C[1]); | |
2152 } | |
2153 } else { | |
2154 B = mot_val[ - wrap]; | |
2155 C = mot_val[off[block] - wrap]; | |
2156 *px = mid_pred(A[0], B[0], C[0]); | |
2157 *py = mid_pred(A[1], B[1], C[1]); | |
2158 } | |
2159 return *mot_val; | |
2160 } | |
2161 | |
8590 | 2162 #if CONFIG_ENCODERS |
10755
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2163 |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2164 /***************************************************/ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2165 /** |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2166 * add mpeg4 stuffing bits (01...1) |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2167 */ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2168 void ff_mpeg4_stuffing(PutBitContext * pbc) |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2169 { |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2170 int length; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2171 put_bits(pbc, 1, 0); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2172 length= (-put_bits_count(pbc))&7; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2173 if(length) put_bits(pbc, length, (1<<length)-1); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2174 } |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2175 |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2176 /* must be called before writing the header */ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2177 void ff_set_mpeg4_time(MpegEncContext * s){ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2178 if(s->pict_type==FF_B_TYPE){ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2179 ff_mpeg4_init_direct_mv(s); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2180 }else{ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2181 s->last_time_base= s->time_base; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2182 s->time_base= s->time/s->avctx->time_base.den; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2183 } |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2184 } |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2185 |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2186 static void mpeg4_encode_gop_header(MpegEncContext * s){ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2187 int hours, minutes, seconds; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2188 int64_t time; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2189 |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2190 put_bits(&s->pb, 16, 0); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2191 put_bits(&s->pb, 16, GOP_STARTCODE); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2192 |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2193 time= s->current_picture_ptr->pts; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2194 if(s->reordered_input_picture[1]) |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2195 time= FFMIN(time, s->reordered_input_picture[1]->pts); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2196 time= time*s->avctx->time_base.num; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2197 |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2198 seconds= time/s->avctx->time_base.den; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2199 minutes= seconds/60; seconds %= 60; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2200 hours= minutes/60; minutes %= 60; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2201 hours%=24; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2202 |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2203 put_bits(&s->pb, 5, hours); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2204 put_bits(&s->pb, 6, minutes); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2205 put_bits(&s->pb, 1, 1); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2206 put_bits(&s->pb, 6, seconds); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2207 |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2208 put_bits(&s->pb, 1, !!(s->flags&CODEC_FLAG_CLOSED_GOP)); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2209 put_bits(&s->pb, 1, 0); //broken link == NO |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2210 |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2211 s->last_time_base= time / s->avctx->time_base.den; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2212 |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2213 ff_mpeg4_stuffing(&s->pb); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2214 } |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2215 |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2216 static void mpeg4_encode_visual_object_header(MpegEncContext * s){ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2217 int profile_and_level_indication; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2218 int vo_ver_id; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2219 |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2220 if(s->avctx->profile != FF_PROFILE_UNKNOWN){ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2221 profile_and_level_indication = s->avctx->profile << 4; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2222 }else if(s->max_b_frames || s->quarter_sample){ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2223 profile_and_level_indication= 0xF0; // adv simple |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2224 }else{ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2225 profile_and_level_indication= 0x00; // simple |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2226 } |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2227 |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2228 if(s->avctx->level != FF_LEVEL_UNKNOWN){ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2229 profile_and_level_indication |= s->avctx->level; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2230 }else{ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2231 profile_and_level_indication |= 1; //level 1 |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2232 } |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2233 |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2234 if(profile_and_level_indication>>4 == 0xF){ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2235 vo_ver_id= 5; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2236 }else{ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2237 vo_ver_id= 1; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2238 } |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2239 |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2240 //FIXME levels |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2241 |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2242 put_bits(&s->pb, 16, 0); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2243 put_bits(&s->pb, 16, VOS_STARTCODE); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2244 |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2245 put_bits(&s->pb, 8, profile_and_level_indication); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2246 |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2247 put_bits(&s->pb, 16, 0); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2248 put_bits(&s->pb, 16, VISUAL_OBJ_STARTCODE); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2249 |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2250 put_bits(&s->pb, 1, 1); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2251 put_bits(&s->pb, 4, vo_ver_id); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2252 put_bits(&s->pb, 3, 1); //priority |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2253 |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2254 put_bits(&s->pb, 4, 1); //visual obj type== video obj |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2255 |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2256 put_bits(&s->pb, 1, 0); //video signal type == no clue //FIXME |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2257 |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2258 ff_mpeg4_stuffing(&s->pb); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2259 } |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2260 |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2261 static void mpeg4_encode_vol_header(MpegEncContext * s, int vo_number, int vol_number) |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2262 { |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2263 int vo_ver_id; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2264 |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2265 if (!CONFIG_MPEG4_ENCODER) return; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2266 |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2267 if(s->max_b_frames || s->quarter_sample){ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2268 vo_ver_id= 5; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2269 s->vo_type= ADV_SIMPLE_VO_TYPE; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2270 }else{ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2271 vo_ver_id= 1; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2272 s->vo_type= SIMPLE_VO_TYPE; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2273 } |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2274 |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2275 put_bits(&s->pb, 16, 0); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2276 put_bits(&s->pb, 16, 0x100 + vo_number); /* video obj */ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2277 put_bits(&s->pb, 16, 0); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2278 put_bits(&s->pb, 16, 0x120 + vol_number); /* video obj layer */ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2279 |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2280 put_bits(&s->pb, 1, 0); /* random access vol */ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2281 put_bits(&s->pb, 8, s->vo_type); /* video obj type indication */ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2282 if(s->workaround_bugs & FF_BUG_MS) { |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2283 put_bits(&s->pb, 1, 0); /* is obj layer id= no */ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2284 } else { |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2285 put_bits(&s->pb, 1, 1); /* is obj layer id= yes */ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2286 put_bits(&s->pb, 4, vo_ver_id); /* is obj layer ver id */ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2287 put_bits(&s->pb, 3, 1); /* is obj layer priority */ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2288 } |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2289 |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2290 aspect_to_info(s, s->avctx->sample_aspect_ratio); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2291 |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2292 put_bits(&s->pb, 4, s->aspect_ratio_info);/* aspect ratio info */ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2293 if (s->aspect_ratio_info == FF_ASPECT_EXTENDED){ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2294 put_bits(&s->pb, 8, s->avctx->sample_aspect_ratio.num); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2295 put_bits(&s->pb, 8, s->avctx->sample_aspect_ratio.den); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2296 } |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2297 |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2298 if(s->workaround_bugs & FF_BUG_MS) { // |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2299 put_bits(&s->pb, 1, 0); /* vol control parameters= no @@@ */ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2300 } else { |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2301 put_bits(&s->pb, 1, 1); /* vol control parameters= yes */ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2302 put_bits(&s->pb, 2, 1); /* chroma format YUV 420/YV12 */ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2303 put_bits(&s->pb, 1, s->low_delay); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2304 put_bits(&s->pb, 1, 0); /* vbv parameters= no */ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2305 } |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2306 |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2307 put_bits(&s->pb, 2, RECT_SHAPE); /* vol shape= rectangle */ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2308 put_bits(&s->pb, 1, 1); /* marker bit */ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2309 |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2310 put_bits(&s->pb, 16, s->avctx->time_base.den); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2311 if (s->time_increment_bits < 1) |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2312 s->time_increment_bits = 1; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2313 put_bits(&s->pb, 1, 1); /* marker bit */ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2314 put_bits(&s->pb, 1, 0); /* fixed vop rate=no */ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2315 put_bits(&s->pb, 1, 1); /* marker bit */ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2316 put_bits(&s->pb, 13, s->width); /* vol width */ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2317 put_bits(&s->pb, 1, 1); /* marker bit */ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2318 put_bits(&s->pb, 13, s->height); /* vol height */ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2319 put_bits(&s->pb, 1, 1); /* marker bit */ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2320 put_bits(&s->pb, 1, s->progressive_sequence ? 0 : 1); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2321 put_bits(&s->pb, 1, 1); /* obmc disable */ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2322 if (vo_ver_id == 1) { |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2323 put_bits(&s->pb, 1, s->vol_sprite_usage); /* sprite enable */ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2324 }else{ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2325 put_bits(&s->pb, 2, s->vol_sprite_usage); /* sprite enable */ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2326 } |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2327 |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2328 put_bits(&s->pb, 1, 0); /* not 8 bit == false */ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2329 put_bits(&s->pb, 1, s->mpeg_quant); /* quant type= (0=h263 style)*/ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2330 |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2331 if(s->mpeg_quant){ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2332 ff_write_quant_matrix(&s->pb, s->avctx->intra_matrix); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2333 ff_write_quant_matrix(&s->pb, s->avctx->inter_matrix); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2334 } |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2335 |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2336 if (vo_ver_id != 1) |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2337 put_bits(&s->pb, 1, s->quarter_sample); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2338 put_bits(&s->pb, 1, 1); /* complexity estimation disable */ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2339 s->resync_marker= s->rtp_mode; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2340 put_bits(&s->pb, 1, s->resync_marker ? 0 : 1);/* resync marker disable */ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2341 put_bits(&s->pb, 1, s->data_partitioning ? 1 : 0); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2342 if(s->data_partitioning){ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2343 put_bits(&s->pb, 1, 0); /* no rvlc */ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2344 } |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2345 |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2346 if (vo_ver_id != 1){ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2347 put_bits(&s->pb, 1, 0); /* newpred */ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2348 put_bits(&s->pb, 1, 0); /* reduced res vop */ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2349 } |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2350 put_bits(&s->pb, 1, 0); /* scalability */ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2351 |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2352 ff_mpeg4_stuffing(&s->pb); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2353 |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2354 /* user data */ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2355 if(!(s->flags & CODEC_FLAG_BITEXACT)){ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2356 put_bits(&s->pb, 16, 0); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2357 put_bits(&s->pb, 16, 0x1B2); /* user_data */ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2358 ff_put_string(&s->pb, LIBAVCODEC_IDENT, 0); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2359 } |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2360 } |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2361 |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2362 /* write mpeg4 VOP header */ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2363 void mpeg4_encode_picture_header(MpegEncContext * s, int picture_number) |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2364 { |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2365 int time_incr; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2366 int time_div, time_mod; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2367 |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2368 if(s->pict_type==FF_I_TYPE){ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2369 if(!(s->flags&CODEC_FLAG_GLOBAL_HEADER)){ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2370 if(s->strict_std_compliance < FF_COMPLIANCE_VERY_STRICT) //HACK, the reference sw is buggy |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2371 mpeg4_encode_visual_object_header(s); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2372 if(s->strict_std_compliance < FF_COMPLIANCE_VERY_STRICT || picture_number==0) //HACK, the reference sw is buggy |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2373 mpeg4_encode_vol_header(s, 0, 0); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2374 } |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2375 if(!(s->workaround_bugs & FF_BUG_MS)) |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2376 mpeg4_encode_gop_header(s); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2377 } |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2378 |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2379 s->partitioned_frame= s->data_partitioning && s->pict_type!=FF_B_TYPE; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2380 |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2381 put_bits(&s->pb, 16, 0); /* vop header */ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2382 put_bits(&s->pb, 16, VOP_STARTCODE); /* vop header */ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2383 put_bits(&s->pb, 2, s->pict_type - 1); /* pict type: I = 0 , P = 1 */ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2384 |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2385 assert(s->time>=0); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2386 time_div= s->time/s->avctx->time_base.den; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2387 time_mod= s->time%s->avctx->time_base.den; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2388 time_incr= time_div - s->last_time_base; |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2389 assert(time_incr >= 0); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2390 while(time_incr--) |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2391 put_bits(&s->pb, 1, 1); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2392 |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2393 put_bits(&s->pb, 1, 0); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2394 |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2395 put_bits(&s->pb, 1, 1); /* marker */ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2396 put_bits(&s->pb, s->time_increment_bits, time_mod); /* time increment */ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2397 put_bits(&s->pb, 1, 1); /* marker */ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2398 put_bits(&s->pb, 1, 1); /* vop coded */ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2399 if ( s->pict_type == FF_P_TYPE |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2400 || (s->pict_type == FF_S_TYPE && s->vol_sprite_usage==GMC_SPRITE)) { |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2401 put_bits(&s->pb, 1, s->no_rounding); /* rounding type */ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2402 } |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2403 put_bits(&s->pb, 3, 0); /* intra dc VLC threshold */ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2404 if(!s->progressive_sequence){ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2405 put_bits(&s->pb, 1, s->current_picture_ptr->top_field_first); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2406 put_bits(&s->pb, 1, s->alternate_scan); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2407 } |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2408 //FIXME sprite stuff |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2409 |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2410 put_bits(&s->pb, 5, s->qscale); |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2411 |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2412 if (s->pict_type != FF_I_TYPE) |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2413 put_bits(&s->pb, 3, s->f_code); /* fcode_for */ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2414 if (s->pict_type == FF_B_TYPE) |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2415 put_bits(&s->pb, 3, s->b_code); /* fcode_back */ |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2416 } |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
2417 |
2017 | 2418 void ff_h263_encode_motion(MpegEncContext * s, int val, int f_code) |
0 | 2419 { |
702 | 2420 int range, l, bit_size, sign, code, bits; |
0 | 2421 |
2422 if (val == 0) { | |
2423 /* zero vector */ | |
2424 code = 0; | |
2425 put_bits(&s->pb, mvtab[code][1], mvtab[code][0]); | |
2426 } else { | |
324 | 2427 bit_size = f_code - 1; |
0 | 2428 range = 1 << bit_size; |
2429 /* modulo encoding */ | |
2093 | 2430 l= INT_BIT - 6 - bit_size; |
2431 val = (val<<l)>>l; | |
702 | 2432 sign = val>>31; |
2433 val= (val^sign)-sign; | |
2434 sign&=1; | |
2093 | 2435 |
312 | 2436 val--; |
2437 code = (val >> bit_size) + 1; | |
2438 bits = val & (range - 1); | |
0 | 2439 |
2967 | 2440 put_bits(&s->pb, mvtab[code][1] + 1, (mvtab[code][0] << 1) | sign); |
0 | 2441 if (bit_size > 0) { |
2442 put_bits(&s->pb, bit_size, bits); | |
2443 } | |
2444 } | |
2445 } | |
2446 | |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
2447 static void init_mv_penalty_and_fcode(MpegEncContext *s) |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
2448 { |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
2449 int f_code; |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
2450 int mv; |
2967 | 2451 |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
2452 for(f_code=1; f_code<=MAX_FCODE; f_code++){ |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
2453 for(mv=-MAX_MV; mv<=MAX_MV; mv++){ |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
2454 int len; |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
2455 |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
2456 if(mv==0) len= mvtab[0][1]; |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
2457 else{ |
9465
9dcb191f1df3
Remove unused variable in init_mv_penalty_and_fcode() found by CSA.
michael
parents:
9458
diff
changeset
|
2458 int val, bit_size, code; |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
2459 |
1893
779bdf5063ce
1000000l (using uninitalized variable for initalizing bits per MV table)
michael
parents:
1873
diff
changeset
|
2460 bit_size = f_code - 1; |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
2461 |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
2462 val=mv; |
2967 | 2463 if (val < 0) |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
2464 val = -val; |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
2465 val--; |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
2466 code = (val >> bit_size) + 1; |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
2467 if(code<33){ |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
2468 len= mvtab[code][1] + 1 + bit_size; |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
2469 }else{ |
2985 | 2470 len= mvtab[32][1] + av_log2(code>>5) + 2 + bit_size; |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
2471 } |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
2472 } |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
2473 |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
2474 mv_penalty[f_code][mv+MAX_MV]= len; |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
2475 } |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
2476 } |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
2477 |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
2478 for(f_code=MAX_FCODE; f_code>0; f_code--){ |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
2479 for(mv=-(16<<f_code); mv<(16<<f_code); mv++){ |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
2480 fcode_tab[mv+MAX_MV]= f_code; |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
2481 } |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
2482 } |
287 | 2483 |
2484 for(mv=0; mv<MAX_MV*2+1; mv++){ | |
2485 umv_fcode_tab[mv]= 1; | |
2486 } | |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
2487 } |
1070
6da5ae9ee199
more #ifdef CONFIG_ENCODERS patch by (Wolfgang Hesseler <qv at multimediaware dot com>) with modifications by me (s/WOLFGANG/CONFIG_ENCODERS/ and some other fixes)
michaelni
parents:
1068
diff
changeset
|
2488 |
468 | 2489 static void init_uni_dc_tab(void) |
293 | 2490 { |
2491 int level, uni_code, uni_len; | |
2492 | |
312 | 2493 for(level=-256; level<256; level++){ |
293 | 2494 int size, v, l; |
2495 /* find number of bits */ | |
2496 size = 0; | |
2497 v = abs(level); | |
2498 while (v) { | |
2499 v >>= 1; | |
2979 | 2500 size++; |
293 | 2501 } |
2502 | |
2503 if (level < 0) | |
2504 l= (-level) ^ ((1 << size) - 1); | |
2505 else | |
2506 l= level; | |
2507 | |
2508 /* luminance */ | |
2509 uni_code= DCtab_lum[size][0]; | |
2510 uni_len = DCtab_lum[size][1]; | |
2511 | |
2512 if (size > 0) { | |
2513 uni_code<<=size; uni_code|=l; | |
2514 uni_len+=size; | |
2515 if (size > 8){ | |
2516 uni_code<<=1; uni_code|=1; | |
2517 uni_len++; | |
2518 } | |
2519 } | |
1013 | 2520 uni_DCtab_lum_bits[level+256]= uni_code; |
2521 uni_DCtab_lum_len [level+256]= uni_len; | |
293 | 2522 |
2523 /* chrominance */ | |
2524 uni_code= DCtab_chrom[size][0]; | |
2525 uni_len = DCtab_chrom[size][1]; | |
2967 | 2526 |
293 | 2527 if (size > 0) { |
2528 uni_code<<=size; uni_code|=l; | |
2529 uni_len+=size; | |
2530 if (size > 8){ | |
2531 uni_code<<=1; uni_code|=1; | |
2532 uni_len++; | |
2533 } | |
2534 } | |
1013 | 2535 uni_DCtab_chrom_bits[level+256]= uni_code; |
2536 uni_DCtab_chrom_len [level+256]= uni_len; | |
293 | 2537 |
2538 } | |
2539 } | |
2540 | |
1064 | 2541 static void init_uni_mpeg4_rl_tab(RLTable *rl, uint32_t *bits_tab, uint8_t *len_tab){ |
648
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2542 int slevel, run, last; |
2967 | 2543 |
648
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2544 assert(MAX_LEVEL >= 64); |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2545 assert(MAX_RUN >= 63); |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2546 |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2547 for(slevel=-64; slevel<64; slevel++){ |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2548 if(slevel==0) continue; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2549 for(run=0; run<64; run++){ |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2550 for(last=0; last<=1; last++){ |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2551 const int index= UNI_MPEG4_ENC_INDEX(last, run, slevel+64); |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2552 int level= slevel < 0 ? -slevel : slevel; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2553 int sign= slevel < 0 ? 1 : 0; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2554 int bits, len, code; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2555 int level1, run1; |
2967 | 2556 |
648
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2557 len_tab[index]= 100; |
2967 | 2558 |
648
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2559 /* ESC0 */ |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2560 code= get_rl_index(rl, last, run, level); |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2561 bits= rl->table_vlc[code][0]; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2562 len= rl->table_vlc[code][1]; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2563 bits=bits*2+sign; len++; |
2967 | 2564 |
648
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2565 if(code!=rl->n && len < len_tab[index]){ |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2566 bits_tab[index]= bits; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2567 len_tab [index]= len; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2568 } |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2569 /* ESC1 */ |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2570 bits= rl->table_vlc[rl->n][0]; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2571 len= rl->table_vlc[rl->n][1]; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2572 bits=bits*2; len++; //esc1 |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2573 level1= level - rl->max_level[last][run]; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2574 if(level1>0){ |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2575 code= get_rl_index(rl, last, run, level1); |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2576 bits<<= rl->table_vlc[code][1]; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2577 len += rl->table_vlc[code][1]; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2578 bits += rl->table_vlc[code][0]; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2579 bits=bits*2+sign; len++; |
2967 | 2580 |
648
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2581 if(code!=rl->n && len < len_tab[index]){ |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2582 bits_tab[index]= bits; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2583 len_tab [index]= len; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2584 } |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2585 } |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2586 /* ESC2 */ |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2587 bits= rl->table_vlc[rl->n][0]; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2588 len= rl->table_vlc[rl->n][1]; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2589 bits=bits*4+2; len+=2; //esc2 |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2590 run1 = run - rl->max_run[last][level] - 1; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2591 if(run1>=0){ |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2592 code= get_rl_index(rl, last, run1, level); |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2593 bits<<= rl->table_vlc[code][1]; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2594 len += rl->table_vlc[code][1]; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2595 bits += rl->table_vlc[code][0]; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2596 bits=bits*2+sign; len++; |
2967 | 2597 |
648
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2598 if(code!=rl->n && len < len_tab[index]){ |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2599 bits_tab[index]= bits; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2600 len_tab [index]= len; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2601 } |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2602 } |
2967 | 2603 /* ESC3 */ |
648
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2604 bits= rl->table_vlc[rl->n][0]; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2605 len = rl->table_vlc[rl->n][1]; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2606 bits=bits*4+3; len+=2; //esc3 |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2607 bits=bits*2+last; len++; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2608 bits=bits*64+run; len+=6; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2609 bits=bits*2+1; len++; //marker |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2610 bits=bits*4096+(slevel&0xfff); len+=12; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2611 bits=bits*2+1; len++; //marker |
2967 | 2612 |
648
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2613 if(len < len_tab[index]){ |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2614 bits_tab[index]= bits; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2615 len_tab [index]= len; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2616 } |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2617 } |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2618 } |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2619 } |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2620 } |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2621 |
2253 | 2622 static void init_uni_h263_rl_tab(RLTable *rl, uint32_t *bits_tab, uint8_t *len_tab){ |
2623 int slevel, run, last; | |
2967 | 2624 |
2253 | 2625 assert(MAX_LEVEL >= 64); |
2626 assert(MAX_RUN >= 63); | |
2627 | |
2628 for(slevel=-64; slevel<64; slevel++){ | |
2629 if(slevel==0) continue; | |
2630 for(run=0; run<64; run++){ | |
2631 for(last=0; last<=1; last++){ | |
2632 const int index= UNI_MPEG4_ENC_INDEX(last, run, slevel+64); | |
2633 int level= slevel < 0 ? -slevel : slevel; | |
2634 int sign= slevel < 0 ? 1 : 0; | |
2635 int bits, len, code; | |
2967 | 2636 |
2253 | 2637 len_tab[index]= 100; |
2967 | 2638 |
2253 | 2639 /* ESC0 */ |
2640 code= get_rl_index(rl, last, run, level); | |
2641 bits= rl->table_vlc[code][0]; | |
2642 len= rl->table_vlc[code][1]; | |
2643 bits=bits*2+sign; len++; | |
2967 | 2644 |
2253 | 2645 if(code!=rl->n && len < len_tab[index]){ |
2646 if(bits_tab) bits_tab[index]= bits; | |
2647 len_tab [index]= len; | |
2648 } | |
2649 /* ESC */ | |
2650 bits= rl->table_vlc[rl->n][0]; | |
2651 len = rl->table_vlc[rl->n][1]; | |
2652 bits=bits*2+last; len++; | |
2653 bits=bits*64+run; len+=6; | |
2654 bits=bits*256+(level&0xff); len+=8; | |
2967 | 2655 |
2253 | 2656 if(len < len_tab[index]){ |
2657 if(bits_tab) bits_tab[index]= bits; | |
2658 len_tab [index]= len; | |
2659 } | |
2660 } | |
2661 } | |
2662 } | |
2663 } | |
2664 | |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
2665 void h263_encode_init(MpegEncContext *s) |
0 | 2666 { |
2667 static int done = 0; | |
2668 | |
2669 if (!done) { | |
2670 done = 1; | |
293 | 2671 |
2672 init_uni_dc_tab(); | |
2673 | |
4668 | 2674 init_rl(&rl_inter, static_rl_table_store[0]); |
2675 init_rl(&rl_intra, static_rl_table_store[1]); | |
2676 init_rl(&rl_intra_aic, static_rl_table_store[2]); | |
2967 | 2677 |
648
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2678 init_uni_mpeg4_rl_tab(&rl_intra, uni_mpeg4_intra_rl_bits, uni_mpeg4_intra_rl_len); |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
2679 init_uni_mpeg4_rl_tab(&rl_inter, uni_mpeg4_inter_rl_bits, uni_mpeg4_inter_rl_len); |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
2680 |
2253 | 2681 init_uni_h263_rl_tab(&rl_intra_aic, NULL, uni_h263_intra_aic_rl_len); |
2682 init_uni_h263_rl_tab(&rl_inter , NULL, uni_h263_inter_rl_len); | |
2683 | |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
2684 init_mv_penalty_and_fcode(s); |
0 | 2685 } |
936 | 2686 s->me.mv_penalty= mv_penalty; //FIXME exact table for msmpeg4 & h263p |
2967 | 2687 |
2253 | 2688 s->intra_ac_vlc_length =s->inter_ac_vlc_length = uni_h263_inter_rl_len; |
2689 s->intra_ac_vlc_last_length=s->inter_ac_vlc_last_length= uni_h263_inter_rl_len + 128*64; | |
2690 if(s->h263_aic){ | |
2691 s->intra_ac_vlc_length = uni_h263_intra_aic_rl_len; | |
2692 s->intra_ac_vlc_last_length= uni_h263_intra_aic_rl_len + 128*64; | |
2693 } | |
2694 s->ac_esc_length= 7+1+6+8; | |
2695 | |
287 | 2696 // use fcodes >1 only for mpeg4 & h263 & h263p FIXME |
344 | 2697 switch(s->codec_id){ |
2698 case CODEC_ID_MPEG4: | |
2699 s->fcode_tab= fcode_tab; | |
2700 s->min_qcoeff= -2048; | |
2701 s->max_qcoeff= 2047; | |
945 | 2702 s->intra_ac_vlc_length = uni_mpeg4_intra_rl_len; |
2703 s->intra_ac_vlc_last_length= uni_mpeg4_intra_rl_len + 128*64; | |
2704 s->inter_ac_vlc_length = uni_mpeg4_inter_rl_len; | |
2705 s->inter_ac_vlc_last_length= uni_mpeg4_inter_rl_len + 128*64; | |
1013 | 2706 s->luma_dc_vlc_length= uni_DCtab_lum_len; |
2707 s->chroma_dc_vlc_length= uni_DCtab_chrom_len; | |
945 | 2708 s->ac_esc_length= 7+2+1+6+1+12+1; |
1799 | 2709 s->y_dc_scale_table= ff_mpeg4_y_dc_scale_table; |
2710 s->c_dc_scale_table= ff_mpeg4_c_dc_scale_table; | |
2711 | |
1424 | 2712 if(s->flags & CODEC_FLAG_GLOBAL_HEADER){ |
1483 | 2713 |
1424 | 2714 s->avctx->extradata= av_malloc(1024); |
1522
79dddc5cd990
removed the obsolete and unused parameters of init_put_bits
alex
parents:
1521
diff
changeset
|
2715 init_put_bits(&s->pb, s->avctx->extradata, 1024); |
2967 | 2716 |
2572
c22ad129a91b
support omiting various headers in mpeg4 as WMP seems to have difficulty with them
michael
parents:
2554
diff
changeset
|
2717 if(!(s->workaround_bugs & FF_BUG_MS)) |
c22ad129a91b
support omiting various headers in mpeg4 as WMP seems to have difficulty with them
michael
parents:
2554
diff
changeset
|
2718 mpeg4_encode_visual_object_header(s); |
1424 | 2719 mpeg4_encode_vol_header(s, 0, 0); |
2720 | |
2721 // ff_mpeg4_stuffing(&s->pb); ? | |
2722 flush_put_bits(&s->pb); | |
1786 | 2723 s->avctx->extradata_size= (put_bits_count(&s->pb)+7)>>3; |
1424 | 2724 } |
2967 | 2725 |
344 | 2726 break; |
2727 case CODEC_ID_H263P: | |
1666 | 2728 if(s->umvplus) |
2729 s->fcode_tab= umv_fcode_tab; | |
2730 if(s->modified_quant){ | |
2731 s->min_qcoeff= -2047; | |
2732 s->max_qcoeff= 2047; | |
2733 }else{ | |
2734 s->min_qcoeff= -127; | |
2735 s->max_qcoeff= 127; | |
2736 } | |
344 | 2737 break; |
2967 | 2738 //Note for mpeg4 & h263 the dc-scale table will be set per frame as needed later |
1353
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
2739 case CODEC_ID_FLV1: |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
2740 if (s->h263_flv > 1) { |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
2741 s->min_qcoeff= -1023; |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
2742 s->max_qcoeff= 1023; |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
2743 } else { |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
2744 s->min_qcoeff= -127; |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
2745 s->max_qcoeff= 127; |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
2746 } |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
2747 s->y_dc_scale_table= |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
2748 s->c_dc_scale_table= ff_mpeg1_dc_scale_table; |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
2749 break; |
2646
c735e3e60ca7
Even More spelling errors. patch by (Kevin Baragona <kevinmb500 gawab com)
michael
parents:
2639
diff
changeset
|
2750 default: //nothing needed - default table already set in mpegvideo.c |
1089 | 2751 s->min_qcoeff= -127; |
344 | 2752 s->max_qcoeff= 127; |
498 | 2753 s->y_dc_scale_table= |
2754 s->c_dc_scale_table= ff_mpeg1_dc_scale_table; | |
344 | 2755 } |
0 | 2756 } |
1070
6da5ae9ee199
more #ifdef CONFIG_ENCODERS patch by (Wolfgang Hesseler <qv at multimediaware dot com>) with modifications by me (s/WOLFGANG/CONFIG_ENCODERS/ and some other fixes)
michaelni
parents:
1068
diff
changeset
|
2757 #endif //CONFIG_ENCODERS |
6da5ae9ee199
more #ifdef CONFIG_ENCODERS patch by (Wolfgang Hesseler <qv at multimediaware dot com>) with modifications by me (s/WOLFGANG/CONFIG_ENCODERS/ and some other fixes)
michaelni
parents:
1068
diff
changeset
|
2758 |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
2759 /** |
1034 | 2760 * predicts the ac. |
2761 * @param n block index (0-3 are luma, 4-5 are chroma) | |
2762 * @param dir the ac prediction direction | |
2763 */ | |
1008 | 2764 void mpeg4_pred_ac(MpegEncContext * s, DCTELEM *block, int n, |
0 | 2765 int dir) |
2766 { | |
266 | 2767 int i; |
1064 | 2768 int16_t *ac_val, *ac_val1; |
903 | 2769 int8_t * const qscale_table= s->current_picture.qscale_table; |
0 | 2770 |
2771 /* find prediction */ | |
266 | 2772 ac_val = s->ac_val[0][0] + s->block_index[n] * 16; |
0 | 2773 ac_val1 = ac_val; |
2774 if (s->ac_pred) { | |
2775 if (dir == 0) { | |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
2776 const int xy= s->mb_x-1 + s->mb_y*s->mb_stride; |
0 | 2777 /* left prediction */ |
2778 ac_val -= 16; | |
2967 | 2779 |
903 | 2780 if(s->mb_x==0 || s->qscale == qscale_table[xy] || n==1 || n==3){ |
575 | 2781 /* same qscale */ |
2782 for(i=1;i<8;i++) { | |
1092 | 2783 block[s->dsp.idct_permutation[i<<3]] += ac_val[i]; |
575 | 2784 } |
2785 }else{ | |
2786 /* different qscale, we must rescale */ | |
2787 for(i=1;i<8;i++) { | |
1092 | 2788 block[s->dsp.idct_permutation[i<<3]] += ROUNDED_DIV(ac_val[i]*qscale_table[xy], s->qscale); |
575 | 2789 } |
0 | 2790 } |
2791 } else { | |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
2792 const int xy= s->mb_x + s->mb_y*s->mb_stride - s->mb_stride; |
0 | 2793 /* top prediction */ |
266 | 2794 ac_val -= 16 * s->block_wrap[n]; |
575 | 2795 |
903 | 2796 if(s->mb_y==0 || s->qscale == qscale_table[xy] || n==2 || n==3){ |
575 | 2797 /* same qscale */ |
2798 for(i=1;i<8;i++) { | |
1092 | 2799 block[s->dsp.idct_permutation[i]] += ac_val[i + 8]; |
575 | 2800 } |
2801 }else{ | |
2802 /* different qscale, we must rescale */ | |
2803 for(i=1;i<8;i++) { | |
1092 | 2804 block[s->dsp.idct_permutation[i]] += ROUNDED_DIV(ac_val[i + 8]*qscale_table[xy], s->qscale); |
575 | 2805 } |
0 | 2806 } |
2807 } | |
2808 } | |
2809 /* left copy */ | |
2810 for(i=1;i<8;i++) | |
1092 | 2811 ac_val1[i ] = block[s->dsp.idct_permutation[i<<3]]; |
591 | 2812 |
0 | 2813 /* top copy */ |
2814 for(i=1;i<8;i++) | |
1092 | 2815 ac_val1[8 + i] = block[s->dsp.idct_permutation[i ]]; |
591 | 2816 |
0 | 2817 } |
2818 | |
2819 /***********************************************/ | |
2820 /* decoding */ | |
2821 | |
2822 static VLC intra_MCBPC_vlc; | |
2823 static VLC inter_MCBPC_vlc; | |
2824 static VLC cbpy_vlc; | |
2825 static VLC mv_vlc; | |
2826 static VLC dc_lum, dc_chrom; | |
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2827 static VLC sprite_trajectory; |
262 | 2828 static VLC mb_type_b_vlc; |
1655 | 2829 static VLC h263_mbtype_b_vlc; |
2830 static VLC cbpc_b_vlc; | |
0 | 2831 |
2832 /* init vlcs */ | |
2833 | |
2834 /* XXX: find a better solution to handle static init */ | |
2835 void h263_decode_init_vlc(MpegEncContext *s) | |
2836 { | |
2837 static int done = 0; | |
2838 | |
2839 if (!done) { | |
2840 done = 1; | |
2841 | |
7098 | 2842 INIT_VLC_STATIC(&intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 9, |
0 | 2843 intra_MCBPC_bits, 1, 1, |
7098 | 2844 intra_MCBPC_code, 1, 1, 72); |
2845 INIT_VLC_STATIC(&inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 28, | |
0 | 2846 inter_MCBPC_bits, 1, 1, |
7098 | 2847 inter_MCBPC_code, 1, 1, 198); |
2848 INIT_VLC_STATIC(&cbpy_vlc, CBPY_VLC_BITS, 16, | |
0 | 2849 &cbpy_tab[0][1], 2, 1, |
7098 | 2850 &cbpy_tab[0][0], 2, 1, 64); |
2851 INIT_VLC_STATIC(&mv_vlc, MV_VLC_BITS, 33, | |
0 | 2852 &mvtab[0][1], 2, 1, |
7098 | 2853 &mvtab[0][0], 2, 1, 538); |
4668 | 2854 init_rl(&rl_inter, static_rl_table_store[0]); |
2855 init_rl(&rl_intra, static_rl_table_store[1]); | |
2856 init_rl(&rvlc_rl_inter, static_rl_table_store[3]); | |
2857 init_rl(&rvlc_rl_intra, static_rl_table_store[4]); | |
2858 init_rl(&rl_intra_aic, static_rl_table_store[2]); | |
6940
778ecab25dd8
Change init_vlc_rl() so it does not use *alloc_static() anymore.
michael
parents:
6918
diff
changeset
|
2859 INIT_VLC_RL(rl_inter, 554); |
778ecab25dd8
Change init_vlc_rl() so it does not use *alloc_static() anymore.
michael
parents:
6918
diff
changeset
|
2860 INIT_VLC_RL(rl_intra, 554); |
778ecab25dd8
Change init_vlc_rl() so it does not use *alloc_static() anymore.
michael
parents:
6918
diff
changeset
|
2861 INIT_VLC_RL(rvlc_rl_inter, 1072); |
778ecab25dd8
Change init_vlc_rl() so it does not use *alloc_static() anymore.
michael
parents:
6918
diff
changeset
|
2862 INIT_VLC_RL(rvlc_rl_intra, 1072); |
778ecab25dd8
Change init_vlc_rl() so it does not use *alloc_static() anymore.
michael
parents:
6918
diff
changeset
|
2863 INIT_VLC_RL(rl_intra_aic, 554); |
7098 | 2864 INIT_VLC_STATIC(&dc_lum, DC_VLC_BITS, 10 /* 13 */, |
0 | 2865 &DCtab_lum[0][1], 2, 1, |
7098 | 2866 &DCtab_lum[0][0], 2, 1, 512); |
2867 INIT_VLC_STATIC(&dc_chrom, DC_VLC_BITS, 10 /* 13 */, | |
0 | 2868 &DCtab_chrom[0][1], 2, 1, |
7098 | 2869 &DCtab_chrom[0][0], 2, 1, 512); |
2870 INIT_VLC_STATIC(&sprite_trajectory, SPRITE_TRAJ_VLC_BITS, 15, | |
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2871 &sprite_trajectory_tab[0][1], 4, 2, |
7098 | 2872 &sprite_trajectory_tab[0][0], 4, 2, 128); |
2873 INIT_VLC_STATIC(&mb_type_b_vlc, MB_TYPE_B_VLC_BITS, 4, | |
262 | 2874 &mb_type_b_tab[0][1], 2, 1, |
7098 | 2875 &mb_type_b_tab[0][0], 2, 1, 16); |
2876 INIT_VLC_STATIC(&h263_mbtype_b_vlc, H263_MBTYPE_B_VLC_BITS, 15, | |
1655 | 2877 &h263_mbtype_b_tab[0][1], 2, 1, |
7098 | 2878 &h263_mbtype_b_tab[0][0], 2, 1, 80); |
2879 INIT_VLC_STATIC(&cbpc_b_vlc, CBPC_B_VLC_BITS, 4, | |
1655 | 2880 &cbpc_b_tab[0][1], 2, 1, |
7098 | 2881 &cbpc_b_tab[0][0], 2, 1, 8); |
0 | 2882 } |
2883 } | |
2884 | |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
2885 /** |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
2886 * Get the GOB height based on picture height. |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
2887 */ |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
2888 int ff_h263_get_gob_height(MpegEncContext *s){ |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
2889 if (s->height <= 400) |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
2890 return 1; |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
2891 else if (s->height <= 800) |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
2892 return 2; |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
2893 else |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
2894 return 4; |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
2895 } |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
2896 |
1661 | 2897 int ff_h263_decode_mba(MpegEncContext *s) |
2898 { | |
2899 int i, mb_pos; | |
2900 | |
2901 for(i=0; i<6; i++){ | |
1670 | 2902 if(s->mb_num-1 <= ff_mba_max[i]) break; |
1661 | 2903 } |
2904 mb_pos= get_bits(&s->gb, ff_mba_length[i]); | |
2905 s->mb_x= mb_pos % s->mb_width; | |
2906 s->mb_y= mb_pos / s->mb_width; | |
2907 | |
2908 return mb_pos; | |
2909 } | |
2910 | |
2911 void ff_h263_encode_mba(MpegEncContext *s) | |
2912 { | |
2913 int i, mb_pos; | |
2914 | |
2915 for(i=0; i<6; i++){ | |
1670 | 2916 if(s->mb_num-1 <= ff_mba_max[i]) break; |
1661 | 2917 } |
2918 mb_pos= s->mb_x + s->mb_width*s->mb_y; | |
2919 put_bits(&s->pb, ff_mba_length[i], mb_pos); | |
2920 } | |
2921 | |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
2922 /** |
1661 | 2923 * decodes the group of blocks header or slice header. |
6524 | 2924 * @return <0 if an error occurred |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
2925 */ |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
2926 static int h263_decode_gob_header(MpegEncContext *s) |
162 | 2927 { |
1661 | 2928 unsigned int val, gfid, gob_number; |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
2929 int left; |
2967 | 2930 |
162 | 2931 /* Check for GOB Start Code */ |
2932 val = show_bits(&s->gb, 16); | |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
2933 if(val) |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
2934 return -1; |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
2935 |
162 | 2936 /* We have a GBSC probably with GSTUFF */ |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
2937 skip_bits(&s->gb, 16); /* Drop the zeros */ |
10535
95f3daa991a2
Use get_bits_left() instead of size_in_bits - get_bits_count().
rbultje
parents:
9999
diff
changeset
|
2938 left= get_bits_left(&s->gb); |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
2939 //MN: we must check the bits left or we might end in a infinite loop (or segfault) |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
2940 for(;left>13; left--){ |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
2941 if(get_bits1(&s->gb)) break; /* Seek the '1' bit */ |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
2942 } |
2967 | 2943 if(left<=13) |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
2944 return -1; |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
2945 |
1661 | 2946 if(s->h263_slice_structured){ |
2947 if(get_bits1(&s->gb)==0) | |
2948 return -1; | |
2949 | |
2950 ff_h263_decode_mba(s); | |
2951 | |
2952 if(s->mb_num > 1583) | |
2953 if(get_bits1(&s->gb)==0) | |
2954 return -1; | |
2967 | 2955 |
1661 | 2956 s->qscale = get_bits(&s->gb, 5); /* SQUANT */ |
2957 if(get_bits1(&s->gb)==0) | |
2958 return -1; | |
2959 gfid = get_bits(&s->gb, 2); /* GFID */ | |
2960 }else{ | |
2961 gob_number = get_bits(&s->gb, 5); /* GN */ | |
2962 s->mb_x= 0; | |
2963 s->mb_y= s->gob_index* gob_number; | |
2964 gfid = get_bits(&s->gb, 2); /* GFID */ | |
2965 s->qscale = get_bits(&s->gb, 5); /* GQUANT */ | |
2966 } | |
2967 | 2967 |
2968 if(s->mb_y >= s->mb_height) | |
1661 | 2969 return -1; |
2970 | |
2967 | 2971 if(s->qscale==0) |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
2972 return -1; |
1644 | 2973 |
162 | 2974 return 0; |
2975 } | |
2976 | |
290 | 2977 static inline void memsetw(short *tab, int val, int n) |
2978 { | |
2979 int i; | |
2980 for(i=0;i<n;i++) | |
2981 tab[i] = val; | |
2982 } | |
2983 | |
8590 | 2984 #if CONFIG_ENCODERS |
1070
6da5ae9ee199
more #ifdef CONFIG_ENCODERS patch by (Wolfgang Hesseler <qv at multimediaware dot com>) with modifications by me (s/WOLFGANG/CONFIG_ENCODERS/ and some other fixes)
michaelni
parents:
1068
diff
changeset
|
2985 |
453 | 2986 void ff_mpeg4_init_partitions(MpegEncContext *s) |
2987 { | |
9431 | 2988 uint8_t *start= put_bits_ptr(&s->pb); |
1799 | 2989 uint8_t *end= s->pb.buf_end; |
2990 int size= end - start; | |
9259 | 2991 int pb_size = (((intptr_t)start + size/3)&(~3)) - (intptr_t)start; |
1912 | 2992 int tex_size= (size - 2*pb_size)&(~3); |
2967 | 2993 |
1799 | 2994 set_put_bits_buffer_size(&s->pb, pb_size); |
2995 init_put_bits(&s->tex_pb, start + pb_size , tex_size); | |
1910
5c21b165abf6
ensure that the bitstream buffers for encoding partitioned frames are aligned
michael
parents:
1896
diff
changeset
|
2996 init_put_bits(&s->pb2 , start + pb_size + tex_size, pb_size); |
453 | 2997 } |
2998 | |
2999 void ff_mpeg4_merge_partitions(MpegEncContext *s) | |
290 | 3000 { |
1786 | 3001 const int pb2_len = put_bits_count(&s->pb2 ); |
3002 const int tex_pb_len= put_bits_count(&s->tex_pb); | |
3003 const int bits= put_bits_count(&s->pb); | |
453 | 3004 |
6481 | 3005 if(s->pict_type==FF_I_TYPE){ |
453 | 3006 put_bits(&s->pb, 19, DC_MARKER); |
3007 s->misc_bits+=19 + pb2_len + bits - s->last_bits; | |
3008 s->i_tex_bits+= tex_pb_len; | |
3009 }else{ | |
3010 put_bits(&s->pb, 17, MOTION_MARKER); | |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3011 s->misc_bits+=17 + pb2_len; |
453 | 3012 s->mv_bits+= bits - s->last_bits; |
3013 s->p_tex_bits+= tex_pb_len; | |
3014 } | |
3015 | |
3016 flush_put_bits(&s->pb2); | |
3017 flush_put_bits(&s->tex_pb); | |
3018 | |
1799 | 3019 set_put_bits_buffer_size(&s->pb, s->pb2.buf_end - s->pb.buf); |
3020 ff_copy_bits(&s->pb, s->pb2.buf , pb2_len); | |
3021 ff_copy_bits(&s->pb, s->tex_pb.buf, tex_pb_len); | |
1786 | 3022 s->last_bits= put_bits_count(&s->pb); |
453 | 3023 } |
3024 | |
1070
6da5ae9ee199
more #ifdef CONFIG_ENCODERS patch by (Wolfgang Hesseler <qv at multimediaware dot com>) with modifications by me (s/WOLFGANG/CONFIG_ENCODERS/ and some other fixes)
michaelni
parents:
1068
diff
changeset
|
3025 #endif //CONFIG_ENCODERS |
6da5ae9ee199
more #ifdef CONFIG_ENCODERS patch by (Wolfgang Hesseler <qv at multimediaware dot com>) with modifications by me (s/WOLFGANG/CONFIG_ENCODERS/ and some other fixes)
michaelni
parents:
1068
diff
changeset
|
3026 |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3027 int ff_mpeg4_get_video_packet_prefix_length(MpegEncContext *s){ |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3028 switch(s->pict_type){ |
6481 | 3029 case FF_I_TYPE: |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3030 return 16; |
6481 | 3031 case FF_P_TYPE: |
3032 case FF_S_TYPE: | |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3033 return s->f_code+15; |
6481 | 3034 case FF_B_TYPE: |
6655
22cca5d3173a
Implement FFMAX3(a,b,c) - maximum over three arguments.
voroshil
parents:
6524
diff
changeset
|
3035 return FFMAX3(s->f_code, s->b_code, 2) + 15; |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3036 default: |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3037 return -1; |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3038 } |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3039 } |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3040 |
8590 | 3041 #if CONFIG_ENCODERS |
1070
6da5ae9ee199
more #ifdef CONFIG_ENCODERS patch by (Wolfgang Hesseler <qv at multimediaware dot com>) with modifications by me (s/WOLFGANG/CONFIG_ENCODERS/ and some other fixes)
michaelni
parents:
1068
diff
changeset
|
3042 |
453 | 3043 void ff_mpeg4_encode_video_packet_header(MpegEncContext *s) |
3044 { | |
3045 int mb_num_bits= av_log2(s->mb_num - 1) + 1; | |
3046 | |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3047 put_bits(&s->pb, ff_mpeg4_get_video_packet_prefix_length(s), 0); |
453 | 3048 put_bits(&s->pb, 1, 1); |
2967 | 3049 |
453 | 3050 put_bits(&s->pb, mb_num_bits, s->mb_x + s->mb_y*s->mb_width); |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3051 put_bits(&s->pb, s->quant_precision, s->qscale); |
453 | 3052 put_bits(&s->pb, 1, 0); /* no HEC */ |
3053 } | |
3054 | |
1070
6da5ae9ee199
more #ifdef CONFIG_ENCODERS patch by (Wolfgang Hesseler <qv at multimediaware dot com>) with modifications by me (s/WOLFGANG/CONFIG_ENCODERS/ and some other fixes)
michaelni
parents:
1068
diff
changeset
|
3055 #endif //CONFIG_ENCODERS |
6da5ae9ee199
more #ifdef CONFIG_ENCODERS patch by (Wolfgang Hesseler <qv at multimediaware dot com>) with modifications by me (s/WOLFGANG/CONFIG_ENCODERS/ and some other fixes)
michaelni
parents:
1068
diff
changeset
|
3056 |
453 | 3057 /** |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3058 * check if the next stuff is a resync marker or the end. |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3059 * @return 0 if not |
453 | 3060 */ |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3061 static inline int mpeg4_is_resync(MpegEncContext *s){ |
4161
f81bca10a740
100l for me, iam being to stupid to read the mpeg4 spec / eat stuffing mbs a the end of the picture
michael
parents:
4155
diff
changeset
|
3062 int bits_count= get_bits_count(&s->gb); |
f81bca10a740
100l for me, iam being to stupid to read the mpeg4 spec / eat stuffing mbs a the end of the picture
michael
parents:
4155
diff
changeset
|
3063 int v= show_bits(&s->gb, 16); |
2967 | 3064 |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3065 if(s->workaround_bugs&FF_BUG_NO_PADDING){ |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3066 return 0; |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3067 } |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3068 |
4161
f81bca10a740
100l for me, iam being to stupid to read the mpeg4 spec / eat stuffing mbs a the end of the picture
michael
parents:
4155
diff
changeset
|
3069 while(v<=0xFF){ |
6481 | 3070 if(s->pict_type==FF_B_TYPE || (v>>(8-s->pict_type)!=1) || s->partitioned_frame) |
4161
f81bca10a740
100l for me, iam being to stupid to read the mpeg4 spec / eat stuffing mbs a the end of the picture
michael
parents:
4155
diff
changeset
|
3071 break; |
f81bca10a740
100l for me, iam being to stupid to read the mpeg4 spec / eat stuffing mbs a the end of the picture
michael
parents:
4155
diff
changeset
|
3072 skip_bits(&s->gb, 8+s->pict_type); |
f81bca10a740
100l for me, iam being to stupid to read the mpeg4 spec / eat stuffing mbs a the end of the picture
michael
parents:
4155
diff
changeset
|
3073 bits_count+= 8+s->pict_type; |
f81bca10a740
100l for me, iam being to stupid to read the mpeg4 spec / eat stuffing mbs a the end of the picture
michael
parents:
4155
diff
changeset
|
3074 v= show_bits(&s->gb, 16); |
f81bca10a740
100l for me, iam being to stupid to read the mpeg4 spec / eat stuffing mbs a the end of the picture
michael
parents:
4155
diff
changeset
|
3075 } |
f81bca10a740
100l for me, iam being to stupid to read the mpeg4 spec / eat stuffing mbs a the end of the picture
michael
parents:
4155
diff
changeset
|
3076 |
1025
1f9afd8b9131
GetBitContext.size is allways multiplied by 8 -> use size_in_bits to avoid useless *8 in a few inner loops
michaelni
parents:
1013
diff
changeset
|
3077 if(bits_count + 8 >= s->gb.size_in_bits){ |
4161
f81bca10a740
100l for me, iam being to stupid to read the mpeg4 spec / eat stuffing mbs a the end of the picture
michael
parents:
4155
diff
changeset
|
3078 v>>=8; |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3079 v|= 0x7F >> (7-(bits_count&7)); |
2967 | 3080 |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3081 if(v==0x7F) |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3082 return 1; |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3083 }else{ |
4161
f81bca10a740
100l for me, iam being to stupid to read the mpeg4 spec / eat stuffing mbs a the end of the picture
michael
parents:
4155
diff
changeset
|
3084 if(v == ff_mpeg4_resync_prefix[bits_count&7]){ |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3085 int len; |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3086 GetBitContext gb= s->gb; |
2967 | 3087 |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3088 skip_bits(&s->gb, 1); |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3089 align_get_bits(&s->gb); |
2967 | 3090 |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3091 for(len=0; len<32; len++){ |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3092 if(get_bits1(&s->gb)) break; |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3093 } |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3094 |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3095 s->gb= gb; |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3096 |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3097 if(len>=ff_mpeg4_get_video_packet_prefix_length(s)) |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3098 return 1; |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3099 } |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3100 } |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3101 return 0; |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3102 } |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3103 |
10753
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3104 static void mpeg4_decode_sprite_trajectory(MpegEncContext * s, GetBitContext *gb) |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3105 { |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3106 int i; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3107 int a= 2<<s->sprite_warping_accuracy; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3108 int rho= 3-s->sprite_warping_accuracy; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3109 int r=16/a; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3110 const int vop_ref[4][2]= {{0,0}, {s->width,0}, {0, s->height}, {s->width, s->height}}; // only true for rectangle shapes |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3111 int d[4][2]={{0,0}, {0,0}, {0,0}, {0,0}}; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3112 int sprite_ref[4][2]; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3113 int virtual_ref[2][2]; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3114 int w2, h2, w3, h3; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3115 int alpha=0, beta=0; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3116 int w= s->width; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3117 int h= s->height; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3118 int min_ab; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3119 |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3120 for(i=0; i<s->num_sprite_warping_points; i++){ |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3121 int length; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3122 int x=0, y=0; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3123 |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3124 length= get_vlc2(gb, sprite_trajectory.table, SPRITE_TRAJ_VLC_BITS, 3); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3125 if(length){ |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3126 x= get_xbits(gb, length); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3127 } |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3128 if(!(s->divx_version==500 && s->divx_build==413)) skip_bits1(gb); /* marker bit */ |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3129 |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3130 length= get_vlc2(gb, sprite_trajectory.table, SPRITE_TRAJ_VLC_BITS, 3); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3131 if(length){ |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3132 y=get_xbits(gb, length); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3133 } |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3134 skip_bits1(gb); /* marker bit */ |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3135 s->sprite_traj[i][0]= d[i][0]= x; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3136 s->sprite_traj[i][1]= d[i][1]= y; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3137 } |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3138 for(; i<4; i++) |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3139 s->sprite_traj[i][0]= s->sprite_traj[i][1]= 0; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3140 |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3141 while((1<<alpha)<w) alpha++; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3142 while((1<<beta )<h) beta++; // there seems to be a typo in the mpeg4 std for the definition of w' and h' |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3143 w2= 1<<alpha; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3144 h2= 1<<beta; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3145 |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3146 // Note, the 4th point isn't used for GMC |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3147 if(s->divx_version==500 && s->divx_build==413){ |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3148 sprite_ref[0][0]= a*vop_ref[0][0] + d[0][0]; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3149 sprite_ref[0][1]= a*vop_ref[0][1] + d[0][1]; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3150 sprite_ref[1][0]= a*vop_ref[1][0] + d[0][0] + d[1][0]; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3151 sprite_ref[1][1]= a*vop_ref[1][1] + d[0][1] + d[1][1]; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3152 sprite_ref[2][0]= a*vop_ref[2][0] + d[0][0] + d[2][0]; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3153 sprite_ref[2][1]= a*vop_ref[2][1] + d[0][1] + d[2][1]; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3154 } else { |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3155 sprite_ref[0][0]= (a>>1)*(2*vop_ref[0][0] + d[0][0]); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3156 sprite_ref[0][1]= (a>>1)*(2*vop_ref[0][1] + d[0][1]); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3157 sprite_ref[1][0]= (a>>1)*(2*vop_ref[1][0] + d[0][0] + d[1][0]); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3158 sprite_ref[1][1]= (a>>1)*(2*vop_ref[1][1] + d[0][1] + d[1][1]); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3159 sprite_ref[2][0]= (a>>1)*(2*vop_ref[2][0] + d[0][0] + d[2][0]); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3160 sprite_ref[2][1]= (a>>1)*(2*vop_ref[2][1] + d[0][1] + d[2][1]); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3161 } |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3162 /* sprite_ref[3][0]= (a>>1)*(2*vop_ref[3][0] + d[0][0] + d[1][0] + d[2][0] + d[3][0]); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3163 sprite_ref[3][1]= (a>>1)*(2*vop_ref[3][1] + d[0][1] + d[1][1] + d[2][1] + d[3][1]); */ |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3164 |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3165 // this is mostly identical to the mpeg4 std (and is totally unreadable because of that ...) |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3166 // perhaps it should be reordered to be more readable ... |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3167 // the idea behind this virtual_ref mess is to be able to use shifts later per pixel instead of divides |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3168 // so the distance between points is converted from w&h based to w2&h2 based which are of the 2^x form |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3169 virtual_ref[0][0]= 16*(vop_ref[0][0] + w2) |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3170 + ROUNDED_DIV(((w - w2)*(r*sprite_ref[0][0] - 16*vop_ref[0][0]) + w2*(r*sprite_ref[1][0] - 16*vop_ref[1][0])),w); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3171 virtual_ref[0][1]= 16*vop_ref[0][1] |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3172 + ROUNDED_DIV(((w - w2)*(r*sprite_ref[0][1] - 16*vop_ref[0][1]) + w2*(r*sprite_ref[1][1] - 16*vop_ref[1][1])),w); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3173 virtual_ref[1][0]= 16*vop_ref[0][0] |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3174 + ROUNDED_DIV(((h - h2)*(r*sprite_ref[0][0] - 16*vop_ref[0][0]) + h2*(r*sprite_ref[2][0] - 16*vop_ref[2][0])),h); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3175 virtual_ref[1][1]= 16*(vop_ref[0][1] + h2) |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3176 + ROUNDED_DIV(((h - h2)*(r*sprite_ref[0][1] - 16*vop_ref[0][1]) + h2*(r*sprite_ref[2][1] - 16*vop_ref[2][1])),h); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3177 |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3178 switch(s->num_sprite_warping_points) |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3179 { |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3180 case 0: |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3181 s->sprite_offset[0][0]= 0; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3182 s->sprite_offset[0][1]= 0; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3183 s->sprite_offset[1][0]= 0; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3184 s->sprite_offset[1][1]= 0; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3185 s->sprite_delta[0][0]= a; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3186 s->sprite_delta[0][1]= 0; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3187 s->sprite_delta[1][0]= 0; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3188 s->sprite_delta[1][1]= a; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3189 s->sprite_shift[0]= 0; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3190 s->sprite_shift[1]= 0; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3191 break; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3192 case 1: //GMC only |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3193 s->sprite_offset[0][0]= sprite_ref[0][0] - a*vop_ref[0][0]; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3194 s->sprite_offset[0][1]= sprite_ref[0][1] - a*vop_ref[0][1]; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3195 s->sprite_offset[1][0]= ((sprite_ref[0][0]>>1)|(sprite_ref[0][0]&1)) - a*(vop_ref[0][0]/2); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3196 s->sprite_offset[1][1]= ((sprite_ref[0][1]>>1)|(sprite_ref[0][1]&1)) - a*(vop_ref[0][1]/2); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3197 s->sprite_delta[0][0]= a; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3198 s->sprite_delta[0][1]= 0; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3199 s->sprite_delta[1][0]= 0; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3200 s->sprite_delta[1][1]= a; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3201 s->sprite_shift[0]= 0; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3202 s->sprite_shift[1]= 0; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3203 break; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3204 case 2: |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3205 s->sprite_offset[0][0]= (sprite_ref[0][0]<<(alpha+rho)) |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3206 + (-r*sprite_ref[0][0] + virtual_ref[0][0])*(-vop_ref[0][0]) |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3207 + ( r*sprite_ref[0][1] - virtual_ref[0][1])*(-vop_ref[0][1]) |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3208 + (1<<(alpha+rho-1)); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3209 s->sprite_offset[0][1]= (sprite_ref[0][1]<<(alpha+rho)) |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3210 + (-r*sprite_ref[0][1] + virtual_ref[0][1])*(-vop_ref[0][0]) |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3211 + (-r*sprite_ref[0][0] + virtual_ref[0][0])*(-vop_ref[0][1]) |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3212 + (1<<(alpha+rho-1)); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3213 s->sprite_offset[1][0]= ( (-r*sprite_ref[0][0] + virtual_ref[0][0])*(-2*vop_ref[0][0] + 1) |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3214 +( r*sprite_ref[0][1] - virtual_ref[0][1])*(-2*vop_ref[0][1] + 1) |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3215 +2*w2*r*sprite_ref[0][0] |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3216 - 16*w2 |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3217 + (1<<(alpha+rho+1))); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3218 s->sprite_offset[1][1]= ( (-r*sprite_ref[0][1] + virtual_ref[0][1])*(-2*vop_ref[0][0] + 1) |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3219 +(-r*sprite_ref[0][0] + virtual_ref[0][0])*(-2*vop_ref[0][1] + 1) |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3220 +2*w2*r*sprite_ref[0][1] |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3221 - 16*w2 |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3222 + (1<<(alpha+rho+1))); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3223 s->sprite_delta[0][0]= (-r*sprite_ref[0][0] + virtual_ref[0][0]); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3224 s->sprite_delta[0][1]= (+r*sprite_ref[0][1] - virtual_ref[0][1]); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3225 s->sprite_delta[1][0]= (-r*sprite_ref[0][1] + virtual_ref[0][1]); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3226 s->sprite_delta[1][1]= (-r*sprite_ref[0][0] + virtual_ref[0][0]); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3227 |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3228 s->sprite_shift[0]= alpha+rho; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3229 s->sprite_shift[1]= alpha+rho+2; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3230 break; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3231 case 3: |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3232 min_ab= FFMIN(alpha, beta); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3233 w3= w2>>min_ab; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3234 h3= h2>>min_ab; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3235 s->sprite_offset[0][0]= (sprite_ref[0][0]<<(alpha+beta+rho-min_ab)) |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3236 + (-r*sprite_ref[0][0] + virtual_ref[0][0])*h3*(-vop_ref[0][0]) |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3237 + (-r*sprite_ref[0][0] + virtual_ref[1][0])*w3*(-vop_ref[0][1]) |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3238 + (1<<(alpha+beta+rho-min_ab-1)); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3239 s->sprite_offset[0][1]= (sprite_ref[0][1]<<(alpha+beta+rho-min_ab)) |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3240 + (-r*sprite_ref[0][1] + virtual_ref[0][1])*h3*(-vop_ref[0][0]) |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3241 + (-r*sprite_ref[0][1] + virtual_ref[1][1])*w3*(-vop_ref[0][1]) |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3242 + (1<<(alpha+beta+rho-min_ab-1)); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3243 s->sprite_offset[1][0]= (-r*sprite_ref[0][0] + virtual_ref[0][0])*h3*(-2*vop_ref[0][0] + 1) |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3244 + (-r*sprite_ref[0][0] + virtual_ref[1][0])*w3*(-2*vop_ref[0][1] + 1) |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3245 + 2*w2*h3*r*sprite_ref[0][0] |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3246 - 16*w2*h3 |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3247 + (1<<(alpha+beta+rho-min_ab+1)); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3248 s->sprite_offset[1][1]= (-r*sprite_ref[0][1] + virtual_ref[0][1])*h3*(-2*vop_ref[0][0] + 1) |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3249 + (-r*sprite_ref[0][1] + virtual_ref[1][1])*w3*(-2*vop_ref[0][1] + 1) |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3250 + 2*w2*h3*r*sprite_ref[0][1] |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3251 - 16*w2*h3 |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3252 + (1<<(alpha+beta+rho-min_ab+1)); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3253 s->sprite_delta[0][0]= (-r*sprite_ref[0][0] + virtual_ref[0][0])*h3; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3254 s->sprite_delta[0][1]= (-r*sprite_ref[0][0] + virtual_ref[1][0])*w3; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3255 s->sprite_delta[1][0]= (-r*sprite_ref[0][1] + virtual_ref[0][1])*h3; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3256 s->sprite_delta[1][1]= (-r*sprite_ref[0][1] + virtual_ref[1][1])*w3; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3257 |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3258 s->sprite_shift[0]= alpha + beta + rho - min_ab; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3259 s->sprite_shift[1]= alpha + beta + rho - min_ab + 2; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3260 break; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3261 } |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3262 /* try to simplify the situation */ |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3263 if( s->sprite_delta[0][0] == a<<s->sprite_shift[0] |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3264 && s->sprite_delta[0][1] == 0 |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3265 && s->sprite_delta[1][0] == 0 |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3266 && s->sprite_delta[1][1] == a<<s->sprite_shift[0]) |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3267 { |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3268 s->sprite_offset[0][0]>>=s->sprite_shift[0]; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3269 s->sprite_offset[0][1]>>=s->sprite_shift[0]; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3270 s->sprite_offset[1][0]>>=s->sprite_shift[1]; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3271 s->sprite_offset[1][1]>>=s->sprite_shift[1]; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3272 s->sprite_delta[0][0]= a; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3273 s->sprite_delta[0][1]= 0; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3274 s->sprite_delta[1][0]= 0; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3275 s->sprite_delta[1][1]= a; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3276 s->sprite_shift[0]= 0; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3277 s->sprite_shift[1]= 0; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3278 s->real_sprite_warping_points=1; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3279 } |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3280 else{ |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3281 int shift_y= 16 - s->sprite_shift[0]; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3282 int shift_c= 16 - s->sprite_shift[1]; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3283 for(i=0; i<2; i++){ |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3284 s->sprite_offset[0][i]<<= shift_y; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3285 s->sprite_offset[1][i]<<= shift_c; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3286 s->sprite_delta[0][i]<<= shift_y; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3287 s->sprite_delta[1][i]<<= shift_y; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3288 s->sprite_shift[i]= 16; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3289 } |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3290 s->real_sprite_warping_points= s->num_sprite_warping_points; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3291 } |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3292 } |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3293 |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3294 /** |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3295 * decodes the next video packet. |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3296 * @return <0 if something went wrong |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3297 */ |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3298 static int mpeg4_decode_video_packet_header(MpegEncContext *s) |
453 | 3299 { |
290 | 3300 int mb_num_bits= av_log2(s->mb_num - 1) + 1; |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3301 int header_extension=0, mb_num, len; |
2967 | 3302 |
453 | 3303 /* is there enough space left for a video packet + header */ |
1025
1f9afd8b9131
GetBitContext.size is allways multiplied by 8 -> use size_in_bits to avoid useless *8 in a few inner loops
michaelni
parents:
1013
diff
changeset
|
3304 if( get_bits_count(&s->gb) > s->gb.size_in_bits-20) return -1; |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3305 |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3306 for(len=0; len<32; len++){ |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3307 if(get_bits1(&s->gb)) break; |
453 | 3308 } |
3309 | |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3310 if(len!=ff_mpeg4_get_video_packet_prefix_length(s)){ |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
3311 av_log(s->avctx, AV_LOG_ERROR, "marker does not match f_code\n"); |
453 | 3312 return -1; |
3313 } | |
2967 | 3314 |
453 | 3315 if(s->shape != RECT_SHAPE){ |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3316 header_extension= get_bits1(&s->gb); |
453 | 3317 //FIXME more stuff here |
3318 } | |
3319 | |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3320 mb_num= get_bits(&s->gb, mb_num_bits); |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3321 if(mb_num>=s->mb_num){ |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
3322 av_log(s->avctx, AV_LOG_ERROR, "illegal mb_num in video packet (%d %d) \n", mb_num, s->mb_num); |
453 | 3323 return -1; |
3324 } | |
6481 | 3325 if(s->pict_type == FF_B_TYPE){ |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
3326 while(s->next_picture.mbskip_table[ s->mb_index2xy[ mb_num ] ]) mb_num++; |
6497 | 3327 if(mb_num >= s->mb_num) return -1; // slice contains just skipped MBs which where already decoded |
1176 | 3328 } |
2967 | 3329 |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3330 s->mb_x= mb_num % s->mb_width; |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3331 s->mb_y= mb_num / s->mb_width; |
453 | 3332 |
3333 if(s->shape != BIN_ONLY_SHAPE){ | |
2967 | 3334 int qscale= get_bits(&s->gb, s->quant_precision); |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3335 if(qscale) |
1644 | 3336 s->chroma_qscale=s->qscale= qscale; |
290 | 3337 } |
3338 | |
3339 if(s->shape == RECT_SHAPE){ | |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3340 header_extension= get_bits1(&s->gb); |
290 | 3341 } |
3342 if(header_extension){ | |
453 | 3343 int time_increment; |
290 | 3344 int time_incr=0; |
453 | 3345 |
2967 | 3346 while (get_bits1(&s->gb) != 0) |
290 | 3347 time_incr++; |
3348 | |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3349 check_marker(&s->gb, "before time_increment in video packed header"); |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3350 time_increment= get_bits(&s->gb, s->time_increment_bits); |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3351 check_marker(&s->gb, "before vop_coding_type in video packed header"); |
2967 | 3352 |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3353 skip_bits(&s->gb, 2); /* vop coding type */ |
290 | 3354 //FIXME not rect stuff here |
3355 | |
3356 if(s->shape != BIN_ONLY_SHAPE){ | |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3357 skip_bits(&s->gb, 3); /* intra dc vlc threshold */ |
2646
c735e3e60ca7
Even More spelling errors. patch by (Kevin Baragona <kevinmb500 gawab com)
michael
parents:
2639
diff
changeset
|
3358 //FIXME don't just ignore everything |
6481 | 3359 if(s->pict_type == FF_S_TYPE && s->vol_sprite_usage==GMC_SPRITE){ |
1914 | 3360 mpeg4_decode_sprite_trajectory(s, &s->gb); |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
3361 av_log(s->avctx, AV_LOG_ERROR, "untested\n"); |
290 | 3362 } |
3363 | |
3364 //FIXME reduced res stuff here | |
2967 | 3365 |
6481 | 3366 if (s->pict_type != FF_I_TYPE) { |
2979 | 3367 int f_code = get_bits(&s->gb, 3); /* fcode_for */ |
660 | 3368 if(f_code==0){ |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
3369 av_log(s->avctx, AV_LOG_ERROR, "Error, video packet header damaged (f_code=0)\n"); |
290 | 3370 } |
3371 } | |
6481 | 3372 if (s->pict_type == FF_B_TYPE) { |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3373 int b_code = get_bits(&s->gb, 3); |
660 | 3374 if(b_code==0){ |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
3375 av_log(s->avctx, AV_LOG_ERROR, "Error, video packet header damaged (b_code=0)\n"); |
660 | 3376 } |
2967 | 3377 } |
290 | 3378 } |
3379 } | |
3380 //FIXME new-pred stuff | |
2967 | 3381 |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3382 return 0; |
453 | 3383 } |
3384 | |
3385 void ff_mpeg4_clean_buffers(MpegEncContext *s) | |
3386 { | |
3387 int c_wrap, c_xy, l_wrap, l_xy; | |
290 | 3388 |
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1936
diff
changeset
|
3389 l_wrap= s->b8_stride; |
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1936
diff
changeset
|
3390 l_xy= (2*s->mb_y-1)*l_wrap + s->mb_x*2 - 1; |
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1936
diff
changeset
|
3391 c_wrap= s->mb_stride; |
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1936
diff
changeset
|
3392 c_xy= (s->mb_y-1)*c_wrap + s->mb_x - 1; |
290 | 3393 |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3394 #if 0 |
290 | 3395 /* clean DC */ |
453 | 3396 memsetw(s->dc_val[0] + l_xy, 1024, l_wrap*2+1); |
3397 memsetw(s->dc_val[1] + c_xy, 1024, c_wrap+1); | |
3398 memsetw(s->dc_val[2] + c_xy, 1024, c_wrap+1); | |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3399 #endif |
290 | 3400 |
3401 /* clean AC */ | |
1064 | 3402 memset(s->ac_val[0] + l_xy, 0, (l_wrap*2+1)*16*sizeof(int16_t)); |
3403 memset(s->ac_val[1] + c_xy, 0, (c_wrap +1)*16*sizeof(int16_t)); | |
3404 memset(s->ac_val[2] + c_xy, 0, (c_wrap +1)*16*sizeof(int16_t)); | |
290 | 3405 |
3406 /* clean MV */ | |
2646
c735e3e60ca7
Even More spelling errors. patch by (Kevin Baragona <kevinmb500 gawab com)
michael
parents:
2639
diff
changeset
|
3407 // we can't clear the MVs as they might be needed by a b frame |
1064 | 3408 // memset(s->motion_val + l_xy, 0, (l_wrap*2+1)*2*sizeof(int16_t)); |
3409 // memset(s->motion_val, 0, 2*sizeof(int16_t)*(2 + s->mb_width*2)*(2 + s->mb_height*2)); | |
453 | 3410 s->last_mv[0][0][0]= |
3411 s->last_mv[0][0][1]= | |
3412 s->last_mv[1][0][0]= | |
3413 s->last_mv[1][0][1]= 0; | |
3414 } | |
3415 | |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3416 /** |
9024
2bf694251330
Add ff_h263_find_resync_marker() to find the bit position of the next resync_marker, if any.
michael
parents:
9008
diff
changeset
|
3417 * finds the next resync_marker |
2bf694251330
Add ff_h263_find_resync_marker() to find the bit position of the next resync_marker, if any.
michael
parents:
9008
diff
changeset
|
3418 * @param p pointer to buffer to scan |
2bf694251330
Add ff_h263_find_resync_marker() to find the bit position of the next resync_marker, if any.
michael
parents:
9008
diff
changeset
|
3419 * @param end pointer to the end of the buffer |
10759
2bcd7a44350f
Remove residual use of the doxygen markup which is deprecated,
stefano
parents:
10755
diff
changeset
|
3420 * @return pointer to the next resync_marker, or end if none was found |
9024
2bf694251330
Add ff_h263_find_resync_marker() to find the bit position of the next resync_marker, if any.
michael
parents:
9008
diff
changeset
|
3421 */ |
2bf694251330
Add ff_h263_find_resync_marker() to find the bit position of the next resync_marker, if any.
michael
parents:
9008
diff
changeset
|
3422 const uint8_t *ff_h263_find_resync_marker(const uint8_t *restrict p, const uint8_t * restrict end) |
2bf694251330
Add ff_h263_find_resync_marker() to find the bit position of the next resync_marker, if any.
michael
parents:
9008
diff
changeset
|
3423 { |
2bf694251330
Add ff_h263_find_resync_marker() to find the bit position of the next resync_marker, if any.
michael
parents:
9008
diff
changeset
|
3424 assert(p < end); |
2bf694251330
Add ff_h263_find_resync_marker() to find the bit position of the next resync_marker, if any.
michael
parents:
9008
diff
changeset
|
3425 |
2bf694251330
Add ff_h263_find_resync_marker() to find the bit position of the next resync_marker, if any.
michael
parents:
9008
diff
changeset
|
3426 end-=2; |
2bf694251330
Add ff_h263_find_resync_marker() to find the bit position of the next resync_marker, if any.
michael
parents:
9008
diff
changeset
|
3427 p++; |
2bf694251330
Add ff_h263_find_resync_marker() to find the bit position of the next resync_marker, if any.
michael
parents:
9008
diff
changeset
|
3428 for(;p<end; p+=2){ |
2bf694251330
Add ff_h263_find_resync_marker() to find the bit position of the next resync_marker, if any.
michael
parents:
9008
diff
changeset
|
3429 if(!*p){ |
2bf694251330
Add ff_h263_find_resync_marker() to find the bit position of the next resync_marker, if any.
michael
parents:
9008
diff
changeset
|
3430 if (!p[-1] && p[1]) return p - 1; |
2bf694251330
Add ff_h263_find_resync_marker() to find the bit position of the next resync_marker, if any.
michael
parents:
9008
diff
changeset
|
3431 else if(!p[ 1] && p[2]) return p; |
2bf694251330
Add ff_h263_find_resync_marker() to find the bit position of the next resync_marker, if any.
michael
parents:
9008
diff
changeset
|
3432 } |
2bf694251330
Add ff_h263_find_resync_marker() to find the bit position of the next resync_marker, if any.
michael
parents:
9008
diff
changeset
|
3433 } |
2bf694251330
Add ff_h263_find_resync_marker() to find the bit position of the next resync_marker, if any.
michael
parents:
9008
diff
changeset
|
3434 return end+2; |
2bf694251330
Add ff_h263_find_resync_marker() to find the bit position of the next resync_marker, if any.
michael
parents:
9008
diff
changeset
|
3435 } |
2bf694251330
Add ff_h263_find_resync_marker() to find the bit position of the next resync_marker, if any.
michael
parents:
9008
diff
changeset
|
3436 |
2bf694251330
Add ff_h263_find_resync_marker() to find the bit position of the next resync_marker, if any.
michael
parents:
9008
diff
changeset
|
3437 /** |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3438 * decodes the group of blocks / video packet header. |
8691
25aa5388fa97
Make ff_h263_resync() return the bit position of the resync_marker or
benoit
parents:
8690
diff
changeset
|
3439 * @return bit position of the resync_marker, or <0 if none was found |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3440 */ |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3441 int ff_h263_resync(MpegEncContext *s){ |
8691
25aa5388fa97
Make ff_h263_resync() return the bit position of the resync_marker or
benoit
parents:
8690
diff
changeset
|
3442 int left, pos, ret; |
2967 | 3443 |
1521 | 3444 if(s->codec_id==CODEC_ID_MPEG4){ |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3445 skip_bits1(&s->gb); |
1521 | 3446 align_get_bits(&s->gb); |
3447 } | |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3448 |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3449 if(show_bits(&s->gb, 16)==0){ |
8691
25aa5388fa97
Make ff_h263_resync() return the bit position of the resync_marker or
benoit
parents:
8690
diff
changeset
|
3450 pos= get_bits_count(&s->gb); |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3451 if(s->codec_id==CODEC_ID_MPEG4) |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3452 ret= mpeg4_decode_video_packet_header(s); |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3453 else |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3454 ret= h263_decode_gob_header(s); |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3455 if(ret>=0) |
8691
25aa5388fa97
Make ff_h263_resync() return the bit position of the resync_marker or
benoit
parents:
8690
diff
changeset
|
3456 return pos; |
453 | 3457 } |
5129 | 3458 //OK, it's not where it is supposed to be ... |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3459 s->gb= s->last_resync_gb; |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3460 align_get_bits(&s->gb); |
10535
95f3daa991a2
Use get_bits_left() instead of size_in_bits - get_bits_count().
rbultje
parents:
9999
diff
changeset
|
3461 left= get_bits_left(&s->gb); |
2967 | 3462 |
3463 for(;left>16+1+5+5; left-=8){ | |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3464 if(show_bits(&s->gb, 16)==0){ |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3465 GetBitContext bak= s->gb; |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3466 |
8691
25aa5388fa97
Make ff_h263_resync() return the bit position of the resync_marker or
benoit
parents:
8690
diff
changeset
|
3467 pos= get_bits_count(&s->gb); |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3468 if(s->codec_id==CODEC_ID_MPEG4) |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3469 ret= mpeg4_decode_video_packet_header(s); |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3470 else |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3471 ret= h263_decode_gob_header(s); |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3472 if(ret>=0) |
8691
25aa5388fa97
Make ff_h263_resync() return the bit position of the resync_marker or
benoit
parents:
8690
diff
changeset
|
3473 return pos; |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3474 |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3475 s->gb= bak; |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3476 } |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3477 skip_bits(&s->gb, 8); |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3478 } |
2967 | 3479 |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3480 return -1; |
453 | 3481 } |
3482 | |
10752
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
3483 static int h263_decode_motion(MpegEncContext * s, int pred, int f_code) |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
3484 { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
3485 int code, val, sign, shift, l; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
3486 code = get_vlc2(&s->gb, mv_vlc.table, MV_VLC_BITS, 2); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
3487 |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
3488 if (code == 0) |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
3489 return pred; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
3490 if (code < 0) |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
3491 return 0xffff; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
3492 |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
3493 sign = get_bits1(&s->gb); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
3494 shift = f_code - 1; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
3495 val = code; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
3496 if (shift) { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
3497 val = (val - 1) << shift; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
3498 val |= get_bits(&s->gb, shift); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
3499 val++; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
3500 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
3501 if (sign) |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
3502 val = -val; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
3503 val += pred; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
3504 |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
3505 /* modulo decoding */ |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
3506 if (!s->h263_long_vectors) { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
3507 l = INT_BIT - 5 - f_code; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
3508 val = (val<<l)>>l; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
3509 } else { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
3510 /* horrible h263 long vector mode */ |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
3511 if (pred < -31 && val < -63) |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
3512 val += 64; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
3513 if (pred > 32 && val > 63) |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
3514 val -= 64; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
3515 |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
3516 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
3517 return val; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
3518 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
3519 |
453 | 3520 /** |
1034 | 3521 * gets the average motion vector for a GMC MB. |
753 | 3522 * @param n either 0 for the x component or 1 for y |
3523 * @returns the average MV for a GMC MB | |
3524 */ | |
3525 static inline int get_amv(MpegEncContext *s, int n){ | |
3526 int x, y, mb_v, sum, dx, dy, shift; | |
3527 int len = 1 << (s->f_code + 4); | |
3528 const int a= s->sprite_warping_accuracy; | |
2967 | 3529 |
1997 | 3530 if(s->workaround_bugs & FF_BUG_AMV) |
3531 len >>= s->quarter_sample; | |
753 | 3532 |
3533 if(s->real_sprite_warping_points==1){ | |
3534 if(s->divx_version==500 && s->divx_build==413) | |
3535 sum= s->sprite_offset[0][n] / (1<<(a - s->quarter_sample)); | |
3536 else | |
3537 sum= RSHIFT(s->sprite_offset[0][n]<<s->quarter_sample, a); | |
3538 }else{ | |
3539 dx= s->sprite_delta[n][0]; | |
3540 dy= s->sprite_delta[n][1]; | |
3541 shift= s->sprite_shift[0]; | |
3542 if(n) dy -= 1<<(shift + a + 1); | |
3543 else dx -= 1<<(shift + a + 1); | |
3544 mb_v= s->sprite_offset[0][n] + dx*s->mb_x*16 + dy*s->mb_y*16; | |
3545 | |
3546 sum=0; | |
3547 for(y=0; y<16; y++){ | |
3548 int v; | |
2967 | 3549 |
753 | 3550 v= mb_v + dy*y; |
3551 //XXX FIXME optimize | |
3552 for(x=0; x<16; x++){ | |
3553 sum+= v>>shift; | |
3554 v+= dx; | |
3555 } | |
3556 } | |
999
74dc4105e147
average motion vector rounding like the reference says and not what the standard says
michaelni
parents:
953
diff
changeset
|
3557 sum= RSHIFT(sum, a+8-s->quarter_sample); |
753 | 3558 } |
3559 | |
3560 if (sum < -len) sum= -len; | |
3561 else if (sum >= len) sum= len-1; | |
3562 | |
3563 return sum; | |
3564 } | |
3565 | |
3566 /** | |
10753
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3567 * decodes the dc value. |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3568 * @param n block index (0-3 are luma, 4-5 are chroma) |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3569 * @param dir_ptr the prediction direction will be stored here |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3570 * @return the quantized dc |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3571 */ |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3572 static inline int mpeg4_decode_dc(MpegEncContext * s, int n, int *dir_ptr) |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3573 { |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3574 int level, code; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3575 |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3576 if (n < 4) |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3577 code = get_vlc2(&s->gb, dc_lum.table, DC_VLC_BITS, 1); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3578 else |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3579 code = get_vlc2(&s->gb, dc_chrom.table, DC_VLC_BITS, 1); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3580 if (code < 0 || code > 9 /* && s->nbit<9 */){ |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3581 av_log(s->avctx, AV_LOG_ERROR, "illegal dc vlc\n"); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3582 return -1; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3583 } |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3584 if (code == 0) { |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3585 level = 0; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3586 } else { |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3587 if(IS_3IV1){ |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3588 if(code==1) |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3589 level= 2*get_bits1(&s->gb)-1; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3590 else{ |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3591 if(get_bits1(&s->gb)) |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3592 level = get_bits(&s->gb, code-1) + (1<<(code-1)); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3593 else |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3594 level = -get_bits(&s->gb, code-1) - (1<<(code-1)); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3595 } |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3596 }else{ |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3597 level = get_xbits(&s->gb, code); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3598 } |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3599 |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3600 if (code > 8){ |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3601 if(get_bits1(&s->gb)==0){ /* marker */ |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3602 if(s->error_recognition>=2){ |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3603 av_log(s->avctx, AV_LOG_ERROR, "dc marker bit missing\n"); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3604 return -1; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3605 } |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3606 } |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3607 } |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3608 } |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3609 |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3610 return ff_mpeg4_pred_dc(s, n, level, dir_ptr, 0); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3611 } |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3612 |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3613 /** |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3614 * decodes first partition. |
6524 | 3615 * @return number of MBs decoded or <0 if an error occurred |
453 | 3616 */ |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3617 static int mpeg4_decode_partition_a(MpegEncContext *s){ |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3618 int mb_num; |
1064 | 3619 static const int8_t quant_tab[4] = { -1, -2, 1, 2 }; |
2967 | 3620 |
453 | 3621 /* decode first partition */ |
3622 mb_num=0; | |
290 | 3623 s->first_slice_line=1; |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3624 for(; s->mb_y<s->mb_height; s->mb_y++){ |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3625 ff_init_block_index(s); |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3626 for(; s->mb_x<s->mb_width; s->mb_x++){ |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
3627 const int xy= s->mb_x + s->mb_y*s->mb_stride; |
453 | 3628 int cbpc; |
3629 int dir=0; | |
2967 | 3630 |
453 | 3631 mb_num++; |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3632 ff_update_block_index(s); |
453 | 3633 if(s->mb_x == s->resync_mb_x && s->mb_y == s->resync_mb_y+1) |
3634 s->first_slice_line=0; | |
2967 | 3635 |
6481 | 3636 if(s->pict_type==FF_I_TYPE){ |
453 | 3637 int i; |
3638 | |
1482 | 3639 do{ |
1873 | 3640 if(show_bits_long(&s->gb, 19)==DC_MARKER){ |
3641 return mb_num-1; | |
3642 } | |
3643 | |
1482 | 3644 cbpc = get_vlc2(&s->gb, intra_MCBPC_vlc.table, INTRA_MCBPC_VLC_BITS, 2); |
3645 if (cbpc < 0){ | |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
3646 av_log(s->avctx, AV_LOG_ERROR, "cbpc corrupted at %d %d\n", s->mb_x, s->mb_y); |
1482 | 3647 return -1; |
3648 } | |
3649 }while(cbpc == 8); | |
2967 | 3650 |
453 | 3651 s->cbp_table[xy]= cbpc & 3; |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
3652 s->current_picture.mb_type[xy]= MB_TYPE_INTRA; |
453 | 3653 s->mb_intra = 1; |
3654 | |
3655 if(cbpc & 4) { | |
1652 | 3656 ff_set_qscale(s, s->qscale + quant_tab[get_bits(&s->gb, 2)]); |
453 | 3657 } |
903 | 3658 s->current_picture.qscale_table[xy]= s->qscale; |
453 | 3659 |
3660 s->mbintra_table[xy]= 1; | |
3661 for(i=0; i<6; i++){ | |
3662 int dc_pred_dir; | |
2967 | 3663 int dc= mpeg4_decode_dc(s, i, &dc_pred_dir); |
453 | 3664 if(dc < 0){ |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
3665 av_log(s->avctx, AV_LOG_ERROR, "DC corrupted at %d %d\n", s->mb_x, s->mb_y); |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3666 return -1; |
453 | 3667 } |
3668 dir<<=1; | |
3669 if(dc_pred_dir) dir|=1; | |
3670 } | |
3671 s->pred_dir_table[xy]= dir; | |
3672 }else{ /* P/S_TYPE */ | |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3673 int mx, my, pred_x, pred_y, bits; |
1668
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1666
diff
changeset
|
3674 int16_t * const mot_val= s->current_picture.motion_val[0][s->block_index[0]]; |
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1936
diff
changeset
|
3675 const int stride= s->b8_stride*2; |
453 | 3676 |
1873 | 3677 try_again: |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3678 bits= show_bits(&s->gb, 17); |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3679 if(bits==MOTION_MARKER){ |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3680 return mb_num-1; |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3681 } |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3682 skip_bits1(&s->gb); |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3683 if(bits&0x10000){ |
453 | 3684 /* skip mb */ |
6481 | 3685 if(s->pict_type==FF_S_TYPE && s->vol_sprite_usage==GMC_SPRITE){ |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
3686 s->current_picture.mb_type[xy]= MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_GMC | MB_TYPE_L0; |
753 | 3687 mx= get_amv(s, 0); |
3688 my= get_amv(s, 1); | |
453 | 3689 }else{ |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
3690 s->current_picture.mb_type[xy]= MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0; |
753 | 3691 mx=my=0; |
453 | 3692 } |
3693 mot_val[0 ]= mot_val[2 ]= | |
3694 mot_val[0+stride]= mot_val[2+stride]= mx; | |
3695 mot_val[1 ]= mot_val[3 ]= | |
3696 mot_val[1+stride]= mot_val[3+stride]= my; | |
3697 | |
3698 if(s->mbintra_table[xy]) | |
3699 ff_clean_intra_table_entries(s); | |
3700 continue; | |
3701 } | |
1482 | 3702 |
544 | 3703 cbpc = get_vlc2(&s->gb, inter_MCBPC_vlc.table, INTER_MCBPC_VLC_BITS, 2); |
453 | 3704 if (cbpc < 0){ |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
3705 av_log(s->avctx, AV_LOG_ERROR, "cbpc corrupted at %d %d\n", s->mb_x, s->mb_y); |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3706 return -1; |
453 | 3707 } |
1873 | 3708 if(cbpc == 20) |
3709 goto try_again; | |
1482 | 3710 |
453 | 3711 s->cbp_table[xy]= cbpc&(8+3); //8 is dquant |
2967 | 3712 |
453 | 3713 s->mb_intra = ((cbpc & 4) != 0); |
2967 | 3714 |
453 | 3715 if(s->mb_intra){ |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
3716 s->current_picture.mb_type[xy]= MB_TYPE_INTRA; |
453 | 3717 s->mbintra_table[xy]= 1; |
2967 | 3718 mot_val[0 ]= mot_val[2 ]= |
453 | 3719 mot_val[0+stride]= mot_val[2+stride]= 0; |
3720 mot_val[1 ]= mot_val[3 ]= | |
3721 mot_val[1+stride]= mot_val[3+stride]= 0; | |
3722 }else{ | |
3723 if(s->mbintra_table[xy]) | |
3724 ff_clean_intra_table_entries(s); | |
3725 | |
6481 | 3726 if(s->pict_type==FF_S_TYPE && s->vol_sprite_usage==GMC_SPRITE && (cbpc & 16) == 0) |
453 | 3727 s->mcsel= get_bits1(&s->gb); |
3728 else s->mcsel= 0; | |
2967 | 3729 |
453 | 3730 if ((cbpc & 16) == 0) { |
3731 /* 16x16 motion prediction */ | |
3732 | |
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1936
diff
changeset
|
3733 h263_pred_motion(s, 0, 0, &pred_x, &pred_y); |
753 | 3734 if(!s->mcsel){ |
3735 mx = h263_decode_motion(s, pred_x, s->f_code); | |
3736 if (mx >= 0xffff) | |
3737 return -1; | |
3738 | |
3739 my = h263_decode_motion(s, pred_y, s->f_code); | |
3740 if (my >= 0xffff) | |
3741 return -1; | |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
3742 s->current_picture.mb_type[xy]= MB_TYPE_16x16 | MB_TYPE_L0; |
753 | 3743 } else { |
3744 mx = get_amv(s, 0); | |
3745 my = get_amv(s, 1); | |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
3746 s->current_picture.mb_type[xy]= MB_TYPE_16x16 | MB_TYPE_GMC | MB_TYPE_L0; |
453 | 3747 } |
753 | 3748 |
453 | 3749 mot_val[0 ]= mot_val[2 ] = |
3750 mot_val[0+stride]= mot_val[2+stride]= mx; | |
3751 mot_val[1 ]= mot_val[3 ]= | |
3752 mot_val[1+stride]= mot_val[3+stride]= my; | |
3753 } else { | |
3754 int i; | |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
3755 s->current_picture.mb_type[xy]= MB_TYPE_8x8 | MB_TYPE_L0; |
453 | 3756 for(i=0;i<4;i++) { |
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1936
diff
changeset
|
3757 int16_t *mot_val= h263_pred_motion(s, i, 0, &pred_x, &pred_y); |
453 | 3758 mx = h263_decode_motion(s, pred_x, s->f_code); |
3759 if (mx >= 0xffff) | |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3760 return -1; |
2967 | 3761 |
453 | 3762 my = h263_decode_motion(s, pred_y, s->f_code); |
3763 if (my >= 0xffff) | |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3764 return -1; |
453 | 3765 mot_val[0] = mx; |
3766 mot_val[1] = my; | |
3767 } | |
3768 } | |
3769 } | |
3770 } | |
3771 } | |
3772 s->mb_x= 0; | |
3773 } | |
3774 | |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3775 return mb_num; |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3776 } |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3777 |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3778 /** |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3779 * decode second partition. |
6524 | 3780 * @return <0 if an error occurred |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3781 */ |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3782 static int mpeg4_decode_partition_b(MpegEncContext *s, int mb_count){ |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3783 int mb_num=0; |
1064 | 3784 static const int8_t quant_tab[4] = { -1, -2, 1, 2 }; |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3785 |
453 | 3786 s->mb_x= s->resync_mb_x; |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3787 s->first_slice_line=1; |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3788 for(s->mb_y= s->resync_mb_y; mb_num < mb_count; s->mb_y++){ |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3789 ff_init_block_index(s); |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3790 for(; mb_num < mb_count && s->mb_x<s->mb_width; s->mb_x++){ |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
3791 const int xy= s->mb_x + s->mb_y*s->mb_stride; |
453 | 3792 |
3793 mb_num++; | |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3794 ff_update_block_index(s); |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3795 if(s->mb_x == s->resync_mb_x && s->mb_y == s->resync_mb_y+1) |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3796 s->first_slice_line=0; |
2967 | 3797 |
6481 | 3798 if(s->pict_type==FF_I_TYPE){ |
453 | 3799 int ac_pred= get_bits1(&s->gb); |
544 | 3800 int cbpy = get_vlc2(&s->gb, cbpy_vlc.table, CBPY_VLC_BITS, 1); |
453 | 3801 if(cbpy<0){ |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
3802 av_log(s->avctx, AV_LOG_ERROR, "cbpy corrupted at %d %d\n", s->mb_x, s->mb_y); |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3803 return -1; |
453 | 3804 } |
2967 | 3805 |
453 | 3806 s->cbp_table[xy]|= cbpy<<2; |
2967 | 3807 s->current_picture.mb_type[xy] |= ac_pred*MB_TYPE_ACPRED; |
453 | 3808 }else{ /* P || S_TYPE */ |
2967 | 3809 if(IS_INTRA(s->current_picture.mb_type[xy])){ |
453 | 3810 int dir=0,i; |
3811 int ac_pred = get_bits1(&s->gb); | |
544 | 3812 int cbpy = get_vlc2(&s->gb, cbpy_vlc.table, CBPY_VLC_BITS, 1); |
453 | 3813 |
3814 if(cbpy<0){ | |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
3815 av_log(s->avctx, AV_LOG_ERROR, "I cbpy corrupted at %d %d\n", s->mb_x, s->mb_y); |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3816 return -1; |
453 | 3817 } |
2967 | 3818 |
453 | 3819 if(s->cbp_table[xy] & 8) { |
1652 | 3820 ff_set_qscale(s, s->qscale + quant_tab[get_bits(&s->gb, 2)]); |
453 | 3821 } |
903 | 3822 s->current_picture.qscale_table[xy]= s->qscale; |
453 | 3823 |
3824 for(i=0; i<6; i++){ | |
3825 int dc_pred_dir; | |
2967 | 3826 int dc= mpeg4_decode_dc(s, i, &dc_pred_dir); |
453 | 3827 if(dc < 0){ |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
3828 av_log(s->avctx, AV_LOG_ERROR, "DC corrupted at %d %d\n", s->mb_x, s->mb_y); |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3829 return -1; |
453 | 3830 } |
3831 dir<<=1; | |
3832 if(dc_pred_dir) dir|=1; | |
3833 } | |
3834 s->cbp_table[xy]&= 3; //remove dquant | |
3835 s->cbp_table[xy]|= cbpy<<2; | |
2967 | 3836 s->current_picture.mb_type[xy] |= ac_pred*MB_TYPE_ACPRED; |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
3837 s->pred_dir_table[xy]= dir; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
3838 }else if(IS_SKIP(s->current_picture.mb_type[xy])){ |
903 | 3839 s->current_picture.qscale_table[xy]= s->qscale; |
453 | 3840 s->cbp_table[xy]= 0; |
3841 }else{ | |
544 | 3842 int cbpy = get_vlc2(&s->gb, cbpy_vlc.table, CBPY_VLC_BITS, 1); |
453 | 3843 |
3844 if(cbpy<0){ | |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
3845 av_log(s->avctx, AV_LOG_ERROR, "P cbpy corrupted at %d %d\n", s->mb_x, s->mb_y); |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3846 return -1; |
453 | 3847 } |
2967 | 3848 |
453 | 3849 if(s->cbp_table[xy] & 8) { |
1652 | 3850 ff_set_qscale(s, s->qscale + quant_tab[get_bits(&s->gb, 2)]); |
453 | 3851 } |
903 | 3852 s->current_picture.qscale_table[xy]= s->qscale; |
453 | 3853 |
3854 s->cbp_table[xy]&= 3; //remove dquant | |
3855 s->cbp_table[xy]|= (cbpy^0xf)<<2; | |
3856 } | |
3857 } | |
3858 } | |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3859 if(mb_num >= mb_count) return 0; |
453 | 3860 s->mb_x= 0; |
3861 } | |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3862 return 0; |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3863 } |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3864 |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3865 /** |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3866 * decodes the first & second partition |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3867 * @return <0 if error (and sets error type in the error_status_table) |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3868 */ |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3869 int ff_mpeg4_decode_partitions(MpegEncContext *s) |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3870 { |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3871 int mb_num; |
6481 | 3872 const int part_a_error= s->pict_type==FF_I_TYPE ? (DC_ERROR|MV_ERROR) : MV_ERROR; |
3873 const int part_a_end = s->pict_type==FF_I_TYPE ? (DC_END |MV_END) : MV_END; | |
2967 | 3874 |
3875 mb_num= mpeg4_decode_partition_a(s); | |
1144 | 3876 if(mb_num<0){ |
3877 ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, part_a_error); | |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3878 return -1; |
1144 | 3879 } |
2967 | 3880 |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3881 if(s->resync_mb_x + s->resync_mb_y*s->mb_width + mb_num > s->mb_num){ |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
3882 av_log(s->avctx, AV_LOG_ERROR, "slice below monitor ...\n"); |
1144 | 3883 ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, part_a_error); |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3884 return -1; |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3885 } |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3886 |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3887 s->mb_num_left= mb_num; |
2967 | 3888 |
6481 | 3889 if(s->pict_type==FF_I_TYPE){ |
1873 | 3890 while(show_bits(&s->gb, 9) == 1) |
3891 skip_bits(&s->gb, 9); | |
1257 | 3892 if(get_bits_long(&s->gb, 19)!=DC_MARKER){ |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
3893 av_log(s->avctx, AV_LOG_ERROR, "marker missing after first I partition at %d %d\n", s->mb_x, s->mb_y); |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3894 return -1; |
1144 | 3895 } |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3896 }else{ |
1873 | 3897 while(show_bits(&s->gb, 10) == 1) |
3898 skip_bits(&s->gb, 10); | |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3899 if(get_bits(&s->gb, 17)!=MOTION_MARKER){ |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
3900 av_log(s->avctx, AV_LOG_ERROR, "marker missing after first P partition at %d %d\n", s->mb_x, s->mb_y); |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3901 return -1; |
1144 | 3902 } |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3903 } |
1144 | 3904 ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, part_a_end); |
2967 | 3905 |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3906 if( mpeg4_decode_partition_b(s, mb_num) < 0){ |
6481 | 3907 if(s->pict_type==FF_P_TYPE) |
1144 | 3908 ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, DC_ERROR); |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3909 return -1; |
1144 | 3910 }else{ |
6481 | 3911 if(s->pict_type==FF_P_TYPE) |
1144 | 3912 ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, DC_END); |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3913 } |
453 | 3914 |
2967 | 3915 return 0; |
453 | 3916 } |
3917 | |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
3918 /** |
10753
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3919 * decodes a block. |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3920 * @return <0 if an error occurred |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3921 */ |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3922 static inline int mpeg4_decode_block(MpegEncContext * s, DCTELEM * block, |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3923 int n, int coded, int intra, int rvlc) |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3924 { |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3925 int level, i, last, run; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3926 int dc_pred_dir; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3927 RLTable * rl; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3928 RL_VLC_ELEM * rl_vlc; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3929 const uint8_t * scan_table; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3930 int qmul, qadd; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3931 |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3932 //Note intra & rvlc should be optimized away if this is inlined |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3933 |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3934 if(intra) { |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3935 if(s->use_intra_dc_vlc){ |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3936 /* DC coef */ |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3937 if(s->partitioned_frame){ |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3938 level = s->dc_val[0][ s->block_index[n] ]; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3939 if(n<4) level= FASTDIV((level + (s->y_dc_scale>>1)), s->y_dc_scale); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3940 else level= FASTDIV((level + (s->c_dc_scale>>1)), s->c_dc_scale); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3941 dc_pred_dir= (s->pred_dir_table[s->mb_x + s->mb_y*s->mb_stride]<<n)&32; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3942 }else{ |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3943 level = mpeg4_decode_dc(s, n, &dc_pred_dir); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3944 if (level < 0) |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3945 return -1; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3946 } |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3947 block[0] = level; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3948 i = 0; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3949 }else{ |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3950 i = -1; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3951 ff_mpeg4_pred_dc(s, n, 0, &dc_pred_dir, 0); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3952 } |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3953 if (!coded) |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3954 goto not_coded; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3955 |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3956 if(rvlc){ |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3957 rl = &rvlc_rl_intra; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3958 rl_vlc = rvlc_rl_intra.rl_vlc[0]; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3959 }else{ |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3960 rl = &rl_intra; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3961 rl_vlc = rl_intra.rl_vlc[0]; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3962 } |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3963 if (s->ac_pred) { |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3964 if (dc_pred_dir == 0) |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3965 scan_table = s->intra_v_scantable.permutated; /* left */ |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3966 else |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3967 scan_table = s->intra_h_scantable.permutated; /* top */ |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3968 } else { |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3969 scan_table = s->intra_scantable.permutated; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3970 } |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3971 qmul=1; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3972 qadd=0; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3973 } else { |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3974 i = -1; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3975 if (!coded) { |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3976 s->block_last_index[n] = i; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3977 return 0; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3978 } |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3979 if(rvlc) rl = &rvlc_rl_inter; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3980 else rl = &rl_inter; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3981 |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3982 scan_table = s->intra_scantable.permutated; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3983 |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3984 if(s->mpeg_quant){ |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3985 qmul=1; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3986 qadd=0; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3987 if(rvlc){ |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3988 rl_vlc = rvlc_rl_inter.rl_vlc[0]; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3989 }else{ |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3990 rl_vlc = rl_inter.rl_vlc[0]; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3991 } |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3992 }else{ |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3993 qmul = s->qscale << 1; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3994 qadd = (s->qscale - 1) | 1; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3995 if(rvlc){ |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3996 rl_vlc = rvlc_rl_inter.rl_vlc[s->qscale]; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3997 }else{ |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3998 rl_vlc = rl_inter.rl_vlc[s->qscale]; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
3999 } |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4000 } |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4001 } |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4002 { |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4003 OPEN_READER(re, &s->gb); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4004 for(;;) { |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4005 UPDATE_CACHE(re, &s->gb); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4006 GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 0); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4007 if (level==0) { |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4008 /* escape */ |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4009 if(rvlc){ |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4010 if(SHOW_UBITS(re, &s->gb, 1)==0){ |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4011 av_log(s->avctx, AV_LOG_ERROR, "1. marker bit missing in rvlc esc\n"); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4012 return -1; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4013 }; SKIP_CACHE(re, &s->gb, 1); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4014 |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4015 last= SHOW_UBITS(re, &s->gb, 1); SKIP_CACHE(re, &s->gb, 1); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4016 run= SHOW_UBITS(re, &s->gb, 6); LAST_SKIP_CACHE(re, &s->gb, 6); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4017 SKIP_COUNTER(re, &s->gb, 1+1+6); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4018 UPDATE_CACHE(re, &s->gb); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4019 |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4020 if(SHOW_UBITS(re, &s->gb, 1)==0){ |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4021 av_log(s->avctx, AV_LOG_ERROR, "2. marker bit missing in rvlc esc\n"); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4022 return -1; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4023 }; SKIP_CACHE(re, &s->gb, 1); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4024 |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4025 level= SHOW_UBITS(re, &s->gb, 11); SKIP_CACHE(re, &s->gb, 11); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4026 |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4027 if(SHOW_UBITS(re, &s->gb, 5)!=0x10){ |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4028 av_log(s->avctx, AV_LOG_ERROR, "reverse esc missing\n"); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4029 return -1; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4030 }; SKIP_CACHE(re, &s->gb, 5); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4031 |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4032 level= level * qmul + qadd; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4033 level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); LAST_SKIP_CACHE(re, &s->gb, 1); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4034 SKIP_COUNTER(re, &s->gb, 1+11+5+1); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4035 |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4036 i+= run + 1; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4037 if(last) i+=192; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4038 }else{ |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4039 int cache; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4040 cache= GET_CACHE(re, &s->gb); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4041 |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4042 if(IS_3IV1) |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4043 cache ^= 0xC0000000; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4044 |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4045 if (cache&0x80000000) { |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4046 if (cache&0x40000000) { |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4047 /* third escape */ |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4048 SKIP_CACHE(re, &s->gb, 2); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4049 last= SHOW_UBITS(re, &s->gb, 1); SKIP_CACHE(re, &s->gb, 1); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4050 run= SHOW_UBITS(re, &s->gb, 6); LAST_SKIP_CACHE(re, &s->gb, 6); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4051 SKIP_COUNTER(re, &s->gb, 2+1+6); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4052 UPDATE_CACHE(re, &s->gb); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4053 |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4054 if(IS_3IV1){ |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4055 level= SHOW_SBITS(re, &s->gb, 12); LAST_SKIP_BITS(re, &s->gb, 12); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4056 }else{ |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4057 if(SHOW_UBITS(re, &s->gb, 1)==0){ |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4058 av_log(s->avctx, AV_LOG_ERROR, "1. marker bit missing in 3. esc\n"); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4059 return -1; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4060 }; SKIP_CACHE(re, &s->gb, 1); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4061 |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4062 level= SHOW_SBITS(re, &s->gb, 12); SKIP_CACHE(re, &s->gb, 12); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4063 |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4064 if(SHOW_UBITS(re, &s->gb, 1)==0){ |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4065 av_log(s->avctx, AV_LOG_ERROR, "2. marker bit missing in 3. esc\n"); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4066 return -1; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4067 }; LAST_SKIP_CACHE(re, &s->gb, 1); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4068 |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4069 SKIP_COUNTER(re, &s->gb, 1+12+1); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4070 } |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4071 |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4072 #if 0 |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4073 if(s->error_recognition >= FF_ER_COMPLIANT){ |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4074 const int abs_level= FFABS(level); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4075 if(abs_level<=MAX_LEVEL && run<=MAX_RUN){ |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4076 const int run1= run - rl->max_run[last][abs_level] - 1; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4077 if(abs_level <= rl->max_level[last][run]){ |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4078 av_log(s->avctx, AV_LOG_ERROR, "illegal 3. esc, vlc encoding possible\n"); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4079 return -1; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4080 } |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4081 if(s->error_recognition > FF_ER_COMPLIANT){ |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4082 if(abs_level <= rl->max_level[last][run]*2){ |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4083 av_log(s->avctx, AV_LOG_ERROR, "illegal 3. esc, esc 1 encoding possible\n"); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4084 return -1; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4085 } |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4086 if(run1 >= 0 && abs_level <= rl->max_level[last][run1]){ |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4087 av_log(s->avctx, AV_LOG_ERROR, "illegal 3. esc, esc 2 encoding possible\n"); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4088 return -1; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4089 } |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4090 } |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4091 } |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4092 } |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4093 #endif |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4094 if (level>0) level= level * qmul + qadd; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4095 else level= level * qmul - qadd; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4096 |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4097 if((unsigned)(level + 2048) > 4095){ |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4098 if(s->error_recognition > FF_ER_COMPLIANT){ |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4099 if(level > 2560 || level<-2560){ |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4100 av_log(s->avctx, AV_LOG_ERROR, "|level| overflow in 3. esc, qp=%d\n", s->qscale); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4101 return -1; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4102 } |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4103 } |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4104 level= level<0 ? -2048 : 2047; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4105 } |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4106 |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4107 i+= run + 1; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4108 if(last) i+=192; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4109 } else { |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4110 /* second escape */ |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4111 #if MIN_CACHE_BITS < 20 |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4112 LAST_SKIP_BITS(re, &s->gb, 2); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4113 UPDATE_CACHE(re, &s->gb); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4114 #else |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4115 SKIP_BITS(re, &s->gb, 2); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4116 #endif |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4117 GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 1); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4118 i+= run + rl->max_run[run>>7][level/qmul] +1; //FIXME opt indexing |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4119 level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4120 LAST_SKIP_BITS(re, &s->gb, 1); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4121 } |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4122 } else { |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4123 /* first escape */ |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4124 #if MIN_CACHE_BITS < 19 |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4125 LAST_SKIP_BITS(re, &s->gb, 1); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4126 UPDATE_CACHE(re, &s->gb); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4127 #else |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4128 SKIP_BITS(re, &s->gb, 1); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4129 #endif |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4130 GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 1); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4131 i+= run; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4132 level = level + rl->max_level[run>>7][(run-1)&63] * qmul;//FIXME opt indexing |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4133 level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4134 LAST_SKIP_BITS(re, &s->gb, 1); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4135 } |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4136 } |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4137 } else { |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4138 i+= run; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4139 level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4140 LAST_SKIP_BITS(re, &s->gb, 1); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4141 } |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4142 if (i > 62){ |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4143 i-= 192; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4144 if(i&(~63)){ |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4145 av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4146 return -1; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4147 } |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4148 |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4149 block[scan_table[i]] = level; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4150 break; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4151 } |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4152 |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4153 block[scan_table[i]] = level; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4154 } |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4155 CLOSE_READER(re, &s->gb); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4156 } |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4157 not_coded: |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4158 if (intra) { |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4159 if(!s->use_intra_dc_vlc){ |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4160 block[0] = ff_mpeg4_pred_dc(s, n, block[0], &dc_pred_dir, 0); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4161 |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4162 i -= i>>31; //if(i == -1) i=0; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4163 } |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4164 |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4165 mpeg4_pred_ac(s, block, n, dc_pred_dir); |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4166 if (s->ac_pred) { |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4167 i = 63; /* XXX: not optimal */ |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4168 } |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4169 } |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4170 s->block_last_index[n] = i; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4171 return 0; |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4172 } |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4173 |
3790420a84b6
cosmetics: Move MPEG-4 decoding functions around to avoid forward declarations.
diego
parents:
10752
diff
changeset
|
4174 /** |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
4175 * decode partition C of one MB. |
6524 | 4176 * @return <0 if an error occurred |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
4177 */ |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
4178 static int mpeg4_decode_partitioned_mb(MpegEncContext *s, DCTELEM block[6][64]) |
453 | 4179 { |
4180 int cbp, mb_type; | |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
4181 const int xy= s->mb_x + s->mb_y*s->mb_stride; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
4182 |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
4183 mb_type= s->current_picture.mb_type[xy]; |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
4184 cbp = s->cbp_table[xy]; |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
4185 |
3282 | 4186 s->use_intra_dc_vlc= s->qscale < s->intra_dc_threshold; |
4187 | |
903 | 4188 if(s->current_picture.qscale_table[xy] != s->qscale){ |
1652 | 4189 ff_set_qscale(s, s->current_picture.qscale_table[xy] ); |
453 | 4190 } |
2967 | 4191 |
6481 | 4192 if (s->pict_type == FF_P_TYPE || s->pict_type==FF_S_TYPE) { |
453 | 4193 int i; |
4194 for(i=0; i<4; i++){ | |
1668
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1666
diff
changeset
|
4195 s->mv[0][i][0] = s->current_picture.motion_val[0][ s->block_index[i] ][0]; |
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1666
diff
changeset
|
4196 s->mv[0][i][1] = s->current_picture.motion_val[0][ s->block_index[i] ][1]; |
453 | 4197 } |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
4198 s->mb_intra = IS_INTRA(mb_type); |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
4199 |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
4200 if (IS_SKIP(mb_type)) { |
453 | 4201 /* skip mb */ |
4202 for(i=0;i<6;i++) | |
4203 s->block_last_index[i] = -1; | |
4204 s->mv_dir = MV_DIR_FORWARD; | |
4205 s->mv_type = MV_TYPE_16X16; | |
6481 | 4206 if(s->pict_type==FF_S_TYPE && s->vol_sprite_usage==GMC_SPRITE){ |
453 | 4207 s->mcsel=1; |
2628
511e3afc43e1
Ministry of English Composition, reporting for duty (and the word is "skipped", not "skiped"; "skiped" would rhyme with "hyped")
melanson
parents:
2615
diff
changeset
|
4208 s->mb_skipped = 0; |
453 | 4209 }else{ |
4210 s->mcsel=0; | |
2628
511e3afc43e1
Ministry of English Composition, reporting for duty (and the word is "skipped", not "skiped"; "skiped" would rhyme with "hyped")
melanson
parents:
2615
diff
changeset
|
4211 s->mb_skipped = 1; |
453 | 4212 } |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
4213 }else if(s->mb_intra){ |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
4214 s->ac_pred = IS_ACPRED(s->current_picture.mb_type[xy]); |
453 | 4215 }else if(!s->mb_intra){ |
4216 // s->mcsel= 0; //FIXME do we need to init that | |
2967 | 4217 |
453 | 4218 s->mv_dir = MV_DIR_FORWARD; |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
4219 if (IS_8X8(mb_type)) { |
453 | 4220 s->mv_type = MV_TYPE_8X8; |
4221 } else { | |
4222 s->mv_type = MV_TYPE_16X16; | |
4223 } | |
4224 } | |
4225 } else { /* I-Frame */ | |
4226 s->mb_intra = 1; | |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
4227 s->ac_pred = IS_ACPRED(s->current_picture.mb_type[xy]); |
1132 | 4228 } |
4229 | |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
4230 if (!IS_SKIP(mb_type)) { |
1132 | 4231 int i; |
2632 | 4232 s->dsp.clear_blocks(s->block[0]); |
453 | 4233 /* decode each block */ |
4234 for (i = 0; i < 6; i++) { | |
1132 | 4235 if(mpeg4_decode_block(s, block[i], i, cbp&32, s->mb_intra, s->rvlc) < 0){ |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
4236 av_log(s->avctx, AV_LOG_ERROR, "texture corrupted at %d %d %d\n", s->mb_x, s->mb_y, s->mb_intra); |
453 | 4237 return -1; |
4238 } | |
718 | 4239 cbp+=cbp; |
453 | 4240 } |
4241 } | |
290 | 4242 |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
4243 /* per-MB end of slice check */ |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
4244 |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
4245 if(--s->mb_num_left <= 0){ |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
4246 if(mpeg4_is_resync(s)) |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
4247 return SLICE_END; |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
4248 else |
2967 | 4249 return SLICE_NOEND; |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
4250 }else{ |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
4251 if(mpeg4_is_resync(s)){ |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
4252 const int delta= s->mb_x + 1 == s->mb_width ? 2 : 1; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
4253 if(s->cbp_table[xy+delta]) |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
4254 return SLICE_END; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
4255 } |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
4256 return SLICE_OK; |
619
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
4257 } |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
4258 } |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
4259 |
10752
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4260 /* Decodes RVLC of H.263+ UMV */ |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4261 static int h263p_decode_umotion(MpegEncContext * s, int pred) |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4262 { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4263 int code = 0, sign; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4264 |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4265 if (get_bits1(&s->gb)) /* Motion difference = 0 */ |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4266 return pred; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4267 |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4268 code = 2 + get_bits1(&s->gb); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4269 |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4270 while (get_bits1(&s->gb)) |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4271 { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4272 code <<= 1; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4273 code += get_bits1(&s->gb); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4274 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4275 sign = code & 1; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4276 code >>= 1; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4277 |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4278 code = (sign) ? (pred - code) : (pred + code); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4279 dprintf(s->avctx,"H.263+ UMV Motion = %d\n", code); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4280 return code; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4281 |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4282 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4283 |
1633 | 4284 /** |
4285 * read the next MVs for OBMC. yes this is a ugly hack, feel free to send a patch :) | |
4286 */ | |
4287 static void preview_obmc(MpegEncContext *s){ | |
4288 GetBitContext gb= s->gb; | |
2967 | 4289 |
1633 | 4290 int cbpc, i, pred_x, pred_y, mx, my; |
4291 int16_t *mot_val; | |
4292 const int xy= s->mb_x + 1 + s->mb_y * s->mb_stride; | |
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1936
diff
changeset
|
4293 const int stride= s->b8_stride*2; |
2967 | 4294 |
1633 | 4295 for(i=0; i<4; i++) |
4296 s->block_index[i]+= 2; | |
4297 for(i=4; i<6; i++) | |
4298 s->block_index[i]+= 1; | |
4299 s->mb_x++; | |
2967 | 4300 |
6481 | 4301 assert(s->pict_type == FF_P_TYPE); |
1633 | 4302 |
4303 do{ | |
4304 if (get_bits1(&s->gb)) { | |
4305 /* skip mb */ | |
1668
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1666
diff
changeset
|
4306 mot_val = s->current_picture.motion_val[0][ s->block_index[0] ]; |
2967 | 4307 mot_val[0 ]= mot_val[2 ]= |
1633 | 4308 mot_val[0+stride]= mot_val[2+stride]= 0; |
4309 mot_val[1 ]= mot_val[3 ]= | |
4310 mot_val[1+stride]= mot_val[3+stride]= 0; | |
2967 | 4311 |
1633 | 4312 s->current_picture.mb_type[xy]= MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0; |
4313 goto end; | |
4314 } | |
4315 cbpc = get_vlc2(&s->gb, inter_MCBPC_vlc.table, INTER_MCBPC_VLC_BITS, 2); | |
4316 }while(cbpc == 20); | |
2967 | 4317 |
1633 | 4318 if(cbpc & 4){ |
4319 s->current_picture.mb_type[xy]= MB_TYPE_INTRA; | |
4320 }else{ | |
4321 get_vlc2(&s->gb, cbpy_vlc.table, CBPY_VLC_BITS, 1); | |
4322 if (cbpc & 8) { | |
1656 | 4323 if(s->modified_quant){ |
4324 if(get_bits1(&s->gb)) skip_bits(&s->gb, 1); | |
4325 else skip_bits(&s->gb, 5); | |
4326 }else | |
4327 skip_bits(&s->gb, 2); | |
1633 | 4328 } |
2967 | 4329 |
1633 | 4330 if ((cbpc & 16) == 0) { |
2967 | 4331 s->current_picture.mb_type[xy]= MB_TYPE_16x16 | MB_TYPE_L0; |
1633 | 4332 /* 16x16 motion prediction */ |
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1936
diff
changeset
|
4333 mot_val= h263_pred_motion(s, 0, 0, &pred_x, &pred_y); |
1633 | 4334 if (s->umvplus) |
4335 mx = h263p_decode_umotion(s, pred_x); | |
4336 else | |
1655 | 4337 mx = h263_decode_motion(s, pred_x, 1); |
2967 | 4338 |
1633 | 4339 if (s->umvplus) |
4340 my = h263p_decode_umotion(s, pred_y); | |
4341 else | |
1655 | 4342 my = h263_decode_motion(s, pred_y, 1); |
2967 | 4343 |
4344 mot_val[0 ]= mot_val[2 ]= | |
1633 | 4345 mot_val[0+stride]= mot_val[2+stride]= mx; |
4346 mot_val[1 ]= mot_val[3 ]= | |
4347 mot_val[1+stride]= mot_val[3+stride]= my; | |
4348 } else { | |
2967 | 4349 s->current_picture.mb_type[xy]= MB_TYPE_8x8 | MB_TYPE_L0; |
1633 | 4350 for(i=0;i<4;i++) { |
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1936
diff
changeset
|
4351 mot_val = h263_pred_motion(s, i, 0, &pred_x, &pred_y); |
1633 | 4352 if (s->umvplus) |
4353 mx = h263p_decode_umotion(s, pred_x); | |
4354 else | |
1655 | 4355 mx = h263_decode_motion(s, pred_x, 1); |
2967 | 4356 |
1633 | 4357 if (s->umvplus) |
4358 my = h263p_decode_umotion(s, pred_y); | |
2967 | 4359 else |
1655 | 4360 my = h263_decode_motion(s, pred_y, 1); |
1633 | 4361 if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1) |
4362 skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */ | |
4363 mot_val[0] = mx; | |
4364 mot_val[1] = my; | |
4365 } | |
4366 } | |
4367 } | |
4368 end: | |
2967 | 4369 |
1633 | 4370 for(i=0; i<4; i++) |
4371 s->block_index[i]-= 2; | |
4372 for(i=4; i<6; i++) | |
4373 s->block_index[i]-= 1; | |
4374 s->mb_x--; | |
4375 | |
4376 s->gb= gb; | |
4377 } | |
4378 | |
1656 | 4379 static void h263_decode_dquant(MpegEncContext *s){ |
4380 static const int8_t quant_tab[4] = { -1, -2, 1, 2 }; | |
4381 | |
4382 if(s->modified_quant){ | |
4383 if(get_bits1(&s->gb)) | |
4384 s->qscale= modified_quant_tab[get_bits1(&s->gb)][ s->qscale ]; | |
4385 else | |
4386 s->qscale= get_bits(&s->gb, 5); | |
4387 }else | |
4388 s->qscale += quant_tab[get_bits(&s->gb, 2)]; | |
4389 ff_set_qscale(s, s->qscale); | |
4390 } | |
4391 | |
10752
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4392 static int h263_decode_block(MpegEncContext * s, DCTELEM * block, |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4393 int n, int coded) |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4394 { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4395 int code, level, i, j, last, run; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4396 RLTable *rl = &rl_inter; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4397 const uint8_t *scan_table; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4398 GetBitContext gb= s->gb; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4399 |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4400 scan_table = s->intra_scantable.permutated; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4401 if (s->h263_aic && s->mb_intra) { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4402 rl = &rl_intra_aic; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4403 i = 0; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4404 if (s->ac_pred) { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4405 if (s->h263_aic_dir) |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4406 scan_table = s->intra_v_scantable.permutated; /* left */ |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4407 else |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4408 scan_table = s->intra_h_scantable.permutated; /* top */ |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4409 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4410 } else if (s->mb_intra) { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4411 /* DC coef */ |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4412 if(s->codec_id == CODEC_ID_RV10){ |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4413 #if CONFIG_RV10_DECODER |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4414 if (s->rv10_version == 3 && s->pict_type == FF_I_TYPE) { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4415 int component, diff; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4416 component = (n <= 3 ? 0 : n - 4 + 1); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4417 level = s->last_dc[component]; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4418 if (s->rv10_first_dc_coded[component]) { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4419 diff = rv_decode_dc(s, n); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4420 if (diff == 0xffff) |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4421 return -1; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4422 level += diff; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4423 level = level & 0xff; /* handle wrap round */ |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4424 s->last_dc[component] = level; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4425 } else { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4426 s->rv10_first_dc_coded[component] = 1; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4427 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4428 } else { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4429 level = get_bits(&s->gb, 8); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4430 if (level == 255) |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4431 level = 128; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4432 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4433 #endif |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4434 }else{ |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4435 level = get_bits(&s->gb, 8); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4436 if((level&0x7F) == 0){ |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4437 av_log(s->avctx, AV_LOG_ERROR, "illegal dc %d at %d %d\n", level, s->mb_x, s->mb_y); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4438 if(s->error_recognition >= FF_ER_COMPLIANT) |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4439 return -1; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4440 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4441 if (level == 255) |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4442 level = 128; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4443 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4444 block[0] = level; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4445 i = 1; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4446 } else { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4447 i = 0; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4448 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4449 if (!coded) { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4450 if (s->mb_intra && s->h263_aic) |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4451 goto not_coded; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4452 s->block_last_index[n] = i - 1; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4453 return 0; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4454 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4455 retry: |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4456 for(;;) { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4457 code = get_vlc2(&s->gb, rl->vlc.table, TEX_VLC_BITS, 2); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4458 if (code < 0){ |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4459 av_log(s->avctx, AV_LOG_ERROR, "illegal ac vlc code at %dx%d\n", s->mb_x, s->mb_y); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4460 return -1; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4461 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4462 if (code == rl->n) { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4463 /* escape */ |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4464 if (s->h263_flv > 1) { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4465 int is11 = get_bits1(&s->gb); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4466 last = get_bits1(&s->gb); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4467 run = get_bits(&s->gb, 6); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4468 if(is11){ |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4469 level = get_sbits(&s->gb, 11); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4470 } else { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4471 level = get_sbits(&s->gb, 7); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4472 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4473 } else { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4474 last = get_bits1(&s->gb); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4475 run = get_bits(&s->gb, 6); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4476 level = (int8_t)get_bits(&s->gb, 8); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4477 if(level == -128){ |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4478 if (s->codec_id == CODEC_ID_RV10) { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4479 /* XXX: should patch encoder too */ |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4480 level = get_sbits(&s->gb, 12); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4481 }else{ |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4482 level = get_bits(&s->gb, 5); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4483 level |= get_sbits(&s->gb, 6)<<5; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4484 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4485 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4486 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4487 } else { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4488 run = rl->table_run[code]; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4489 level = rl->table_level[code]; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4490 last = code >= rl->last; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4491 if (get_bits1(&s->gb)) |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4492 level = -level; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4493 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4494 i += run; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4495 if (i >= 64){ |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4496 if(s->alt_inter_vlc && rl == &rl_inter && !s->mb_intra){ |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4497 //Looks like a hack but no, it's the way it is supposed to work ... |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4498 rl = &rl_intra_aic; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4499 i = 0; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4500 s->gb= gb; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4501 s->dsp.clear_block(block); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4502 goto retry; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4503 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4504 av_log(s->avctx, AV_LOG_ERROR, "run overflow at %dx%d i:%d\n", s->mb_x, s->mb_y, s->mb_intra); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4505 return -1; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4506 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4507 j = scan_table[i]; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4508 block[j] = level; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4509 if (last) |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4510 break; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4511 i++; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4512 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4513 not_coded: |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4514 if (s->mb_intra && s->h263_aic) { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4515 h263_pred_acdc(s, block, n); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4516 i = 63; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4517 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4518 s->block_last_index[n] = i; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4519 return 0; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4520 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
4521 |
9103
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
4522 static int h263_skip_b_part(MpegEncContext *s, int cbp) |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
4523 { |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
4524 DECLARE_ALIGNED(16, DCTELEM, dblock[64]); |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
4525 int i, mbi; |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
4526 |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
4527 /* we have to set s->mb_intra to zero to decode B-part of PB-frame correctly |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
4528 * but real value should be restored in order to be used later (in OBMC condition) |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
4529 */ |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
4530 mbi = s->mb_intra; |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
4531 s->mb_intra = 0; |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
4532 for (i = 0; i < 6; i++) { |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
4533 if (h263_decode_block(s, dblock, i, cbp&32) < 0) |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
4534 return -1; |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
4535 cbp+=cbp; |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
4536 } |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
4537 s->mb_intra = mbi; |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
4538 return 0; |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
4539 } |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
4540 |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
4541 static int h263_get_modb(GetBitContext *gb, int pb_frame, int *cbpb) |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
4542 { |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
4543 int c, mv = 1; |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
4544 |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
4545 if (pb_frame < 3) { // h.263 Annex G and i263 PB-frame |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
4546 c = get_bits1(gb); |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
4547 if (pb_frame == 2 && c) |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
4548 mv = !get_bits1(gb); |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
4549 } else { // h.263 Annex M improved PB-frame |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
4550 mv = get_unary(gb, 0, 4) + 1; |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
4551 c = mv & 1; |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
4552 mv = !!(mv & 2); |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
4553 } |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
4554 if(c) |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
4555 *cbpb = get_bits(gb, 6); |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
4556 return mv; |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
4557 } |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
4558 |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
4559 int ff_h263_decode_mb(MpegEncContext *s, |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
4560 DCTELEM block[6][64]) |
0 | 4561 { |
4562 int cbpc, cbpy, i, cbp, pred_x, pred_y, mx, my, dquant; | |
1064 | 4563 int16_t *mot_val; |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
4564 const int xy= s->mb_x + s->mb_y * s->mb_stride; |
9103
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
4565 int cbpb = 0, pb_mv_count = 0; |
2967 | 4566 |
1649
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4567 assert(!s->h263_pred); |
2967 | 4568 |
6481 | 4569 if (s->pict_type == FF_P_TYPE) { |
1649
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4570 do{ |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4571 if (get_bits1(&s->gb)) { |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4572 /* skip mb */ |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4573 s->mb_intra = 0; |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4574 for(i=0;i<6;i++) |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4575 s->block_last_index[i] = -1; |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4576 s->mv_dir = MV_DIR_FORWARD; |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4577 s->mv_type = MV_TYPE_16X16; |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
4578 s->current_picture.mb_type[xy]= MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0; |
255 | 4579 s->mv[0][0][0] = 0; |
4580 s->mv[0][0][1] = 0; | |
2628
511e3afc43e1
Ministry of English Composition, reporting for duty (and the word is "skipped", not "skiped"; "skiped" would rhyme with "hyped")
melanson
parents:
2615
diff
changeset
|
4581 s->mb_skipped = !(s->obmc | s->loop_filter); |
1649
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4582 goto end; |
255 | 4583 } |
1649
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4584 cbpc = get_vlc2(&s->gb, inter_MCBPC_vlc.table, INTER_MCBPC_VLC_BITS, 2); |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4585 if (cbpc < 0){ |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4586 av_log(s->avctx, AV_LOG_ERROR, "cbpc damaged at %d %d\n", s->mb_x, s->mb_y); |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4587 return -1; |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4588 } |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4589 }while(cbpc == 20); |
2967 | 4590 |
2632 | 4591 s->dsp.clear_blocks(s->block[0]); |
2967 | 4592 |
0 | 4593 dquant = cbpc & 8; |
4594 s->mb_intra = ((cbpc & 4) != 0); | |
262 | 4595 if (s->mb_intra) goto intra; |
2967 | 4596 |
9103
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
4597 if(s->pb_frame && get_bits1(&s->gb)) |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
4598 pb_mv_count = h263_get_modb(&s->gb, s->pb_frame, &cbpb); |
544 | 4599 cbpy = get_vlc2(&s->gb, cbpy_vlc.table, CBPY_VLC_BITS, 1); |
2967 | 4600 |
1637 | 4601 if(s->alt_inter_vlc==0 || (cbpc & 3)!=3) |
4602 cbpy ^= 0xF; | |
2967 | 4603 |
1637 | 4604 cbp = (cbpc & 3) | (cbpy << 2); |
0 | 4605 if (dquant) { |
1656 | 4606 h263_decode_dquant(s); |
0 | 4607 } |
2967 | 4608 |
1649
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4609 s->mv_dir = MV_DIR_FORWARD; |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4610 if ((cbpc & 16) == 0) { |
2967 | 4611 s->current_picture.mb_type[xy]= MB_TYPE_16x16 | MB_TYPE_L0; |
1649
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4612 /* 16x16 motion prediction */ |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4613 s->mv_type = MV_TYPE_16X16; |
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1936
diff
changeset
|
4614 h263_pred_motion(s, 0, 0, &pred_x, &pred_y); |
1649
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4615 if (s->umvplus) |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4616 mx = h263p_decode_umotion(s, pred_x); |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4617 else |
1655 | 4618 mx = h263_decode_motion(s, pred_x, 1); |
2967 | 4619 |
1649
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4620 if (mx >= 0xffff) |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4621 return -1; |
2967 | 4622 |
1649
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4623 if (s->umvplus) |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4624 my = h263p_decode_umotion(s, pred_y); |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4625 else |
1655 | 4626 my = h263_decode_motion(s, pred_y, 1); |
2967 | 4627 |
1649
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4628 if (my >= 0xffff) |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4629 return -1; |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4630 s->mv[0][0][0] = mx; |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4631 s->mv[0][0][1] = my; |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4632 |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4633 if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1) |
2967 | 4634 skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */ |
1649
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4635 } else { |
2967 | 4636 s->current_picture.mb_type[xy]= MB_TYPE_8x8 | MB_TYPE_L0; |
1649
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4637 s->mv_type = MV_TYPE_8X8; |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4638 for(i=0;i<4;i++) { |
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1936
diff
changeset
|
4639 mot_val = h263_pred_motion(s, i, 0, &pred_x, &pred_y); |
1649
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4640 if (s->umvplus) |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4641 mx = h263p_decode_umotion(s, pred_x); |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4642 else |
1655 | 4643 mx = h263_decode_motion(s, pred_x, 1); |
1649
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4644 if (mx >= 0xffff) |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4645 return -1; |
2967 | 4646 |
1649
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4647 if (s->umvplus) |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4648 my = h263p_decode_umotion(s, pred_y); |
2967 | 4649 else |
1655 | 4650 my = h263_decode_motion(s, pred_y, 1); |
1649
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4651 if (my >= 0xffff) |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4652 return -1; |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4653 s->mv[0][i][0] = mx; |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4654 s->mv[0][i][1] = my; |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4655 if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1) |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4656 skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */ |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4657 mot_val[0] = mx; |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4658 mot_val[1] = my; |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4659 } |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4660 } |
6481 | 4661 } else if(s->pict_type==FF_B_TYPE) { |
1655 | 4662 int mb_type; |
4663 const int stride= s->b8_stride; | |
1701 | 4664 int16_t *mot_val0 = s->current_picture.motion_val[0][ 2*(s->mb_x + s->mb_y*stride) ]; |
4665 int16_t *mot_val1 = s->current_picture.motion_val[1][ 2*(s->mb_x + s->mb_y*stride) ]; | |
1655 | 4666 // const int mv_xy= s->mb_x + 1 + s->mb_y * s->mb_stride; |
4667 | |
2967 | 4668 //FIXME ugly |
4669 mot_val0[0 ]= mot_val0[2 ]= mot_val0[0+2*stride]= mot_val0[2+2*stride]= | |
4670 mot_val0[1 ]= mot_val0[3 ]= mot_val0[1+2*stride]= mot_val0[3+2*stride]= | |
4671 mot_val1[0 ]= mot_val1[2 ]= mot_val1[0+2*stride]= mot_val1[2+2*stride]= | |
1701 | 4672 mot_val1[1 ]= mot_val1[3 ]= mot_val1[1+2*stride]= mot_val1[3+2*stride]= 0; |
1655 | 4673 |
4674 do{ | |
4675 mb_type= get_vlc2(&s->gb, h263_mbtype_b_vlc.table, H263_MBTYPE_B_VLC_BITS, 2); | |
4676 if (mb_type < 0){ | |
4677 av_log(s->avctx, AV_LOG_ERROR, "b mb_type damaged at %d %d\n", s->mb_x, s->mb_y); | |
4678 return -1; | |
4679 } | |
4680 | |
4681 mb_type= h263_mb_type_b_map[ mb_type ]; | |
4682 }while(!mb_type); | |
4683 | |
4684 s->mb_intra = IS_INTRA(mb_type); | |
4685 if(HAS_CBP(mb_type)){ | |
2632 | 4686 s->dsp.clear_blocks(s->block[0]); |
1655 | 4687 cbpc = get_vlc2(&s->gb, cbpc_b_vlc.table, CBPC_B_VLC_BITS, 1); |
4688 if(s->mb_intra){ | |
4689 dquant = IS_QUANT(mb_type); | |
4690 goto intra; | |
4691 } | |
4692 | |
4693 cbpy = get_vlc2(&s->gb, cbpy_vlc.table, CBPY_VLC_BITS, 1); | |
4694 | |
4695 if (cbpy < 0){ | |
4696 av_log(s->avctx, AV_LOG_ERROR, "b cbpy damaged at %d %d\n", s->mb_x, s->mb_y); | |
4697 return -1; | |
4698 } | |
2967 | 4699 |
1655 | 4700 if(s->alt_inter_vlc==0 || (cbpc & 3)!=3) |
4701 cbpy ^= 0xF; | |
2967 | 4702 |
1655 | 4703 cbp = (cbpc & 3) | (cbpy << 2); |
4704 }else | |
4705 cbp=0; | |
2967 | 4706 |
1655 | 4707 assert(!s->mb_intra); |
4708 | |
4709 if(IS_QUANT(mb_type)){ | |
1656 | 4710 h263_decode_dquant(s); |
1655 | 4711 } |
4712 | |
4713 if(IS_DIRECT(mb_type)){ | |
4714 s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT; | |
4715 mb_type |= ff_mpeg4_set_direct_mv(s, 0, 0); | |
4716 }else{ | |
4717 s->mv_dir = 0; | |
4718 s->mv_type= MV_TYPE_16X16; | |
4719 //FIXME UMV | |
4720 | |
4721 if(USES_LIST(mb_type, 0)){ | |
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1936
diff
changeset
|
4722 int16_t *mot_val= h263_pred_motion(s, 0, 0, &mx, &my); |
1655 | 4723 s->mv_dir = MV_DIR_FORWARD; |
4724 | |
4725 mx = h263_decode_motion(s, mx, 1); | |
4726 my = h263_decode_motion(s, my, 1); | |
2967 | 4727 |
1655 | 4728 s->mv[0][0][0] = mx; |
4729 s->mv[0][0][1] = my; | |
1701 | 4730 mot_val[0 ]= mot_val[2 ]= mot_val[0+2*stride]= mot_val[2+2*stride]= mx; |
4731 mot_val[1 ]= mot_val[3 ]= mot_val[1+2*stride]= mot_val[3+2*stride]= my; | |
1655 | 4732 } |
2967 | 4733 |
1655 | 4734 if(USES_LIST(mb_type, 1)){ |
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1936
diff
changeset
|
4735 int16_t *mot_val= h263_pred_motion(s, 0, 1, &mx, &my); |
1655 | 4736 s->mv_dir |= MV_DIR_BACKWARD; |
2967 | 4737 |
1655 | 4738 mx = h263_decode_motion(s, mx, 1); |
4739 my = h263_decode_motion(s, my, 1); | |
1701 | 4740 |
1655 | 4741 s->mv[1][0][0] = mx; |
4742 s->mv[1][0][1] = my; | |
1701 | 4743 mot_val[0 ]= mot_val[2 ]= mot_val[0+2*stride]= mot_val[2+2*stride]= mx; |
4744 mot_val[1 ]= mot_val[3 ]= mot_val[1+2*stride]= mot_val[3+2*stride]= my; | |
1655 | 4745 } |
4746 } | |
2967 | 4747 |
1655 | 4748 s->current_picture.mb_type[xy]= mb_type; |
1649
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4749 } else { /* I-Frame */ |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4750 do{ |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4751 cbpc = get_vlc2(&s->gb, intra_MCBPC_vlc.table, INTRA_MCBPC_VLC_BITS, 2); |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4752 if (cbpc < 0){ |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4753 av_log(s->avctx, AV_LOG_ERROR, "I cbpc damaged at %d %d\n", s->mb_x, s->mb_y); |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4754 return -1; |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4755 } |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4756 }while(cbpc == 8); |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4757 |
2632 | 4758 s->dsp.clear_blocks(s->block[0]); |
4759 | |
1649
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4760 dquant = cbpc & 4; |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4761 s->mb_intra = 1; |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4762 intra: |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4763 s->current_picture.mb_type[xy]= MB_TYPE_INTRA; |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4764 if (s->h263_aic) { |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4765 s->ac_pred = get_bits1(&s->gb); |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4766 if(s->ac_pred){ |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4767 s->current_picture.mb_type[xy]= MB_TYPE_INTRA | MB_TYPE_ACPRED; |
2967 | 4768 |
1649
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4769 s->h263_aic_dir = get_bits1(&s->gb); |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4770 } |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4771 }else |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4772 s->ac_pred = 0; |
2967 | 4773 |
9103
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
4774 if(s->pb_frame && get_bits1(&s->gb)) |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
4775 pb_mv_count = h263_get_modb(&s->gb, s->pb_frame, &cbpb); |
1649
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4776 cbpy = get_vlc2(&s->gb, cbpy_vlc.table, CBPY_VLC_BITS, 1); |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4777 if(cbpy<0){ |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4778 av_log(s->avctx, AV_LOG_ERROR, "I cbpy damaged at %d %d\n", s->mb_x, s->mb_y); |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4779 return -1; |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4780 } |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4781 cbp = (cbpc & 3) | (cbpy << 2); |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4782 if (dquant) { |
1656 | 4783 h263_decode_dquant(s); |
1649
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4784 } |
9103
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
4785 |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
4786 pb_mv_count += !!s->pb_frame; |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
4787 } |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
4788 |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
4789 while(pb_mv_count--){ |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
4790 h263_decode_motion(s, 0, 1); |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
4791 h263_decode_motion(s, 0, 1); |
9093 | 4792 } |
4793 | |
4794 /* decode each block */ | |
4795 for (i = 0; i < 6; i++) { | |
4796 if (h263_decode_block(s, block[i], i, cbp&32) < 0) | |
4797 return -1; | |
4798 cbp+=cbp; | |
4799 } | |
4800 | |
9103
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
4801 if(s->pb_frame && h263_skip_b_part(s, cbpb) < 0) |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
4802 return -1; |
9093 | 4803 if(s->obmc && !s->mb_intra){ |
4804 if(s->pict_type == FF_P_TYPE && s->mb_x+1<s->mb_width && s->mb_num_left != 1) | |
4805 preview_obmc(s); | |
1649
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4806 } |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4807 end: |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4808 |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4809 /* per-MB end of slice check */ |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4810 { |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4811 int v= show_bits(&s->gb, 16); |
2967 | 4812 |
1649
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4813 if(get_bits_count(&s->gb) + 16 > s->gb.size_in_bits){ |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4814 v>>= get_bits_count(&s->gb) + 16 - s->gb.size_in_bits; |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4815 } |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4816 |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4817 if(v==0) |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4818 return SLICE_END; |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4819 } |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4820 |
2967 | 4821 return SLICE_OK; |
1649
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4822 } |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4823 |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4824 int ff_mpeg4_decode_mb(MpegEncContext *s, |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4825 DCTELEM block[6][64]) |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4826 { |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4827 int cbpc, cbpy, i, cbp, pred_x, pred_y, mx, my, dquant; |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4828 int16_t *mot_val; |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4829 static int8_t quant_tab[4] = { -1, -2, 1, 2 }; |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4830 const int xy= s->mb_x + s->mb_y * s->mb_stride; |
2967 | 4831 |
1649
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4832 assert(s->h263_pred); |
2967 | 4833 |
6481 | 4834 if (s->pict_type == FF_P_TYPE || s->pict_type==FF_S_TYPE) { |
1649
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4835 do{ |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4836 if (get_bits1(&s->gb)) { |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4837 /* skip mb */ |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4838 s->mb_intra = 0; |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4839 for(i=0;i<6;i++) |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4840 s->block_last_index[i] = -1; |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4841 s->mv_dir = MV_DIR_FORWARD; |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4842 s->mv_type = MV_TYPE_16X16; |
6481 | 4843 if(s->pict_type==FF_S_TYPE && s->vol_sprite_usage==GMC_SPRITE){ |
1649
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4844 s->current_picture.mb_type[xy]= MB_TYPE_SKIP | MB_TYPE_GMC | MB_TYPE_16x16 | MB_TYPE_L0; |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4845 s->mcsel=1; |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4846 s->mv[0][0][0]= get_amv(s, 0); |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4847 s->mv[0][0][1]= get_amv(s, 1); |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4848 |
2628
511e3afc43e1
Ministry of English Composition, reporting for duty (and the word is "skipped", not "skiped"; "skiped" would rhyme with "hyped")
melanson
parents:
2615
diff
changeset
|
4849 s->mb_skipped = 0; |
1649
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4850 }else{ |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4851 s->current_picture.mb_type[xy]= MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0; |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4852 s->mcsel=0; |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4853 s->mv[0][0][0] = 0; |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4854 s->mv[0][0][1] = 0; |
2628
511e3afc43e1
Ministry of English Composition, reporting for duty (and the word is "skipped", not "skiped"; "skiped" would rhyme with "hyped")
melanson
parents:
2615
diff
changeset
|
4855 s->mb_skipped = 1; |
1649
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4856 } |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4857 goto end; |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4858 } |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4859 cbpc = get_vlc2(&s->gb, inter_MCBPC_vlc.table, INTER_MCBPC_VLC_BITS, 2); |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4860 if (cbpc < 0){ |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4861 av_log(s->avctx, AV_LOG_ERROR, "cbpc damaged at %d %d\n", s->mb_x, s->mb_y); |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4862 return -1; |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4863 } |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4864 }while(cbpc == 20); |
2967 | 4865 |
2632 | 4866 s->dsp.clear_blocks(s->block[0]); |
1649
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4867 dquant = cbpc & 8; |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4868 s->mb_intra = ((cbpc & 4) != 0); |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4869 if (s->mb_intra) goto intra; |
2967 | 4870 |
6481 | 4871 if(s->pict_type==FF_S_TYPE && s->vol_sprite_usage==GMC_SPRITE && (cbpc & 16) == 0) |
1649
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4872 s->mcsel= get_bits1(&s->gb); |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4873 else s->mcsel= 0; |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4874 cbpy = get_vlc2(&s->gb, cbpy_vlc.table, CBPY_VLC_BITS, 1) ^ 0x0F; |
2967 | 4875 |
1649
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4876 cbp = (cbpc & 3) | (cbpy << 2); |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4877 if (dquant) { |
1652 | 4878 ff_set_qscale(s, s->qscale + quant_tab[get_bits(&s->gb, 2)]); |
1649
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4879 } |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
4880 if((!s->progressive_sequence) && (cbp || (s->workaround_bugs&FF_BUG_XVID_ILACE))) |
619
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
4881 s->interlaced_dct= get_bits1(&s->gb); |
2967 | 4882 |
0 | 4883 s->mv_dir = MV_DIR_FORWARD; |
4884 if ((cbpc & 16) == 0) { | |
619
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
4885 if(s->mcsel){ |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
4886 s->current_picture.mb_type[xy]= MB_TYPE_GMC | MB_TYPE_16x16 | MB_TYPE_L0; |
619
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
4887 /* 16x16 global motion prediction */ |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
4888 s->mv_type = MV_TYPE_16X16; |
753 | 4889 mx= get_amv(s, 0); |
4890 my= get_amv(s, 1); | |
619
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
4891 s->mv[0][0][0] = mx; |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
4892 s->mv[0][0][1] = my; |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
4893 }else if((!s->progressive_sequence) && get_bits1(&s->gb)){ |
2967 | 4894 s->current_picture.mb_type[xy]= MB_TYPE_16x8 | MB_TYPE_L0 | MB_TYPE_INTERLACED; |
619
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
4895 /* 16x8 field motion prediction */ |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
4896 s->mv_type= MV_TYPE_FIELD; |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
4897 |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
4898 s->field_select[0][0]= get_bits1(&s->gb); |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
4899 s->field_select[0][1]= get_bits1(&s->gb); |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
4900 |
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1936
diff
changeset
|
4901 h263_pred_motion(s, 0, 0, &pred_x, &pred_y); |
2967 | 4902 |
619
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
4903 for(i=0; i<2; i++){ |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
4904 mx = h263_decode_motion(s, pred_x, s->f_code); |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
4905 if (mx >= 0xffff) |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
4906 return -1; |
2967 | 4907 |
619
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
4908 my = h263_decode_motion(s, pred_y/2, s->f_code); |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
4909 if (my >= 0xffff) |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
4910 return -1; |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
4911 |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
4912 s->mv[0][i][0] = mx; |
661 | 4913 s->mv[0][i][1] = my; |
619
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
4914 } |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
4915 }else{ |
2967 | 4916 s->current_picture.mb_type[xy]= MB_TYPE_16x16 | MB_TYPE_L0; |
619
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
4917 /* 16x16 motion prediction */ |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
4918 s->mv_type = MV_TYPE_16X16; |
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1936
diff
changeset
|
4919 h263_pred_motion(s, 0, 0, &pred_x, &pred_y); |
1649
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4920 mx = h263_decode_motion(s, pred_x, s->f_code); |
2967 | 4921 |
619
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
4922 if (mx >= 0xffff) |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
4923 return -1; |
2967 | 4924 |
1649
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4925 my = h263_decode_motion(s, pred_y, s->f_code); |
2967 | 4926 |
619
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
4927 if (my >= 0xffff) |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
4928 return -1; |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
4929 s->mv[0][0][0] = mx; |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
4930 s->mv[0][0][1] = my; |
255 | 4931 } |
0 | 4932 } else { |
2967 | 4933 s->current_picture.mb_type[xy]= MB_TYPE_8x8 | MB_TYPE_L0; |
0 | 4934 s->mv_type = MV_TYPE_8X8; |
4935 for(i=0;i<4;i++) { | |
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1936
diff
changeset
|
4936 mot_val = h263_pred_motion(s, i, 0, &pred_x, &pred_y); |
1649
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4937 mx = h263_decode_motion(s, pred_x, s->f_code); |
0 | 4938 if (mx >= 0xffff) |
4939 return -1; | |
2967 | 4940 |
1649
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
4941 my = h263_decode_motion(s, pred_y, s->f_code); |
0 | 4942 if (my >= 0xffff) |
4943 return -1; | |
4944 s->mv[0][i][0] = mx; | |
4945 s->mv[0][i][1] = my; | |
4946 mot_val[0] = mx; | |
4947 mot_val[1] = my; | |
4948 } | |
4949 } | |
6481 | 4950 } else if(s->pict_type==FF_B_TYPE) { |
262 | 4951 int modb1; // first bit of modb |
4952 int modb2; // second bit of modb | |
4953 int mb_type; | |
4954 | |
4955 s->mb_intra = 0; //B-frames never contain intra blocks | |
4956 s->mcsel=0; // ... true gmc blocks | |
4957 | |
4958 if(s->mb_x==0){ | |
674 | 4959 for(i=0; i<2; i++){ |
2967 | 4960 s->last_mv[i][0][0]= |
4961 s->last_mv[i][0][1]= | |
4962 s->last_mv[i][1][0]= | |
674 | 4963 s->last_mv[i][1][1]= 0; |
4964 } | |
262 | 4965 } |
4966 | |
4967 /* if we skipped it in the future P Frame than skip it now too */ | |
2628
511e3afc43e1
Ministry of English Composition, reporting for duty (and the word is "skipped", not "skiped"; "skiped" would rhyme with "hyped")
melanson
parents:
2615
diff
changeset
|
4968 s->mb_skipped= s->next_picture.mbskip_table[s->mb_y * s->mb_stride + s->mb_x]; // Note, skiptab=0 if last was GMC |
511e3afc43e1
Ministry of English Composition, reporting for duty (and the word is "skipped", not "skiped"; "skiped" would rhyme with "hyped")
melanson
parents:
2615
diff
changeset
|
4969 |
511e3afc43e1
Ministry of English Composition, reporting for duty (and the word is "skipped", not "skiped"; "skiped" would rhyme with "hyped")
melanson
parents:
2615
diff
changeset
|
4970 if(s->mb_skipped){ |
262 | 4971 /* skip mb */ |
4972 for(i=0;i<6;i++) | |
4973 s->block_last_index[i] = -1; | |
4974 | |
4975 s->mv_dir = MV_DIR_FORWARD; | |
4976 s->mv_type = MV_TYPE_16X16; | |
4977 s->mv[0][0][0] = 0; | |
4978 s->mv[0][0][1] = 0; | |
4979 s->mv[1][0][0] = 0; | |
4980 s->mv[1][0][1] = 0; | |
2967 | 4981 s->current_picture.mb_type[xy]= MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0; |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
4982 goto end; |
262 | 4983 } |
4984 | |
2967 | 4985 modb1= get_bits1(&s->gb); |
666 | 4986 if(modb1){ |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
4987 mb_type= MB_TYPE_DIRECT2 | MB_TYPE_SKIP | MB_TYPE_L0L1; //like MB_TYPE_B_DIRECT but no vectors coded |
666 | 4988 cbp=0; |
4989 }else{ | |
262 | 4990 modb2= get_bits1(&s->gb); |
544 | 4991 mb_type= get_vlc2(&s->gb, mb_type_b_vlc.table, MB_TYPE_B_VLC_BITS, 1); |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
4992 if(mb_type<0){ |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
4993 av_log(s->avctx, AV_LOG_ERROR, "illegal MB_type\n"); |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
4994 return -1; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
4995 } |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
4996 mb_type= mb_type_b_map[ mb_type ]; |
666 | 4997 if(modb2) cbp= 0; |
2632 | 4998 else{ |
4999 s->dsp.clear_blocks(s->block[0]); | |
5000 cbp= get_bits(&s->gb, 6); | |
5001 } | |
666 | 5002 |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
5003 if ((!IS_DIRECT(mb_type)) && cbp) { |
262 | 5004 if(get_bits1(&s->gb)){ |
1652 | 5005 ff_set_qscale(s, s->qscale + get_bits1(&s->gb)*4 - 2); |
262 | 5006 } |
5007 } | |
664 | 5008 |
5009 if(!s->progressive_sequence){ | |
5010 if(cbp) | |
5011 s->interlaced_dct= get_bits1(&s->gb); | |
5012 | |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
5013 if(!IS_DIRECT(mb_type) && get_bits1(&s->gb)){ |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
5014 mb_type |= MB_TYPE_16x8 | MB_TYPE_INTERLACED; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
5015 mb_type &= ~MB_TYPE_16x16; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
5016 |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
5017 if(USES_LIST(mb_type, 0)){ |
667 | 5018 s->field_select[0][0]= get_bits1(&s->gb); |
5019 s->field_select[0][1]= get_bits1(&s->gb); | |
5020 } | |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
5021 if(USES_LIST(mb_type, 1)){ |
667 | 5022 s->field_select[1][0]= get_bits1(&s->gb); |
5023 s->field_select[1][1]= get_bits1(&s->gb); | |
5024 } | |
5025 } | |
666 | 5026 } |
5027 | |
667 | 5028 s->mv_dir = 0; |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
5029 if((mb_type & (MB_TYPE_DIRECT2|MB_TYPE_INTERLACED)) == 0){ |
666 | 5030 s->mv_type= MV_TYPE_16X16; |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
5031 |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
5032 if(USES_LIST(mb_type, 0)){ |
666 | 5033 s->mv_dir = MV_DIR_FORWARD; |
5034 | |
5035 mx = h263_decode_motion(s, s->last_mv[0][0][0], s->f_code); | |
5036 my = h263_decode_motion(s, s->last_mv[0][0][1], s->f_code); | |
5037 s->last_mv[0][1][0]= s->last_mv[0][0][0]= s->mv[0][0][0] = mx; | |
5038 s->last_mv[0][1][1]= s->last_mv[0][0][1]= s->mv[0][0][1] = my; | |
667 | 5039 } |
2967 | 5040 |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
5041 if(USES_LIST(mb_type, 1)){ |
666 | 5042 s->mv_dir |= MV_DIR_BACKWARD; |
5043 | |
5044 mx = h263_decode_motion(s, s->last_mv[1][0][0], s->b_code); | |
5045 my = h263_decode_motion(s, s->last_mv[1][0][1], s->b_code); | |
5046 s->last_mv[1][1][0]= s->last_mv[1][0][0]= s->mv[1][0][0] = mx; | |
5047 s->last_mv[1][1][1]= s->last_mv[1][0][1]= s->mv[1][0][1] = my; | |
5048 } | |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
5049 }else if(!IS_DIRECT(mb_type)){ |
666 | 5050 s->mv_type= MV_TYPE_FIELD; |
667 | 5051 |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
5052 if(USES_LIST(mb_type, 0)){ |
666 | 5053 s->mv_dir = MV_DIR_FORWARD; |
2967 | 5054 |
666 | 5055 for(i=0; i<2; i++){ |
5056 mx = h263_decode_motion(s, s->last_mv[0][i][0] , s->f_code); | |
5057 my = h263_decode_motion(s, s->last_mv[0][i][1]/2, s->f_code); | |
5058 s->last_mv[0][i][0]= s->mv[0][i][0] = mx; | |
5059 s->last_mv[0][i][1]= (s->mv[0][i][1] = my)*2; | |
5060 } | |
667 | 5061 } |
2967 | 5062 |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
5063 if(USES_LIST(mb_type, 1)){ |
666 | 5064 s->mv_dir |= MV_DIR_BACKWARD; |
5065 | |
5066 for(i=0; i<2; i++){ | |
5067 mx = h263_decode_motion(s, s->last_mv[1][i][0] , s->b_code); | |
5068 my = h263_decode_motion(s, s->last_mv[1][i][1]/2, s->b_code); | |
5069 s->last_mv[1][i][0]= s->mv[1][i][0] = mx; | |
5070 s->last_mv[1][i][1]= (s->mv[1][i][1] = my)*2; | |
664 | 5071 } |
5072 } | |
5073 } | |
5074 } | |
2967 | 5075 |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
5076 if(IS_DIRECT(mb_type)){ |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
5077 if(IS_SKIP(mb_type)) |
666 | 5078 mx=my=0; |
5079 else{ | |
5080 mx = h263_decode_motion(s, 0, 1); | |
5081 my = h263_decode_motion(s, 0, 1); | |
5082 } | |
2967 | 5083 |
262 | 5084 s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT; |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
5085 mb_type |= ff_mpeg4_set_direct_mv(s, mx, my); |
664 | 5086 } |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
5087 s->current_picture.mb_type[xy]= mb_type; |
262 | 5088 } else { /* I-Frame */ |
1482 | 5089 do{ |
5090 cbpc = get_vlc2(&s->gb, intra_MCBPC_vlc.table, INTRA_MCBPC_VLC_BITS, 2); | |
5091 if (cbpc < 0){ | |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
5092 av_log(s->avctx, AV_LOG_ERROR, "I cbpc damaged at %d %d\n", s->mb_x, s->mb_y); |
1482 | 5093 return -1; |
5094 } | |
5095 }while(cbpc == 8); | |
5096 | |
262 | 5097 dquant = cbpc & 4; |
5098 s->mb_intra = 1; | |
5099 intra: | |
1649
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
5100 s->ac_pred = get_bits1(&s->gb); |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
5101 if(s->ac_pred) |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
5102 s->current_picture.mb_type[xy]= MB_TYPE_INTRA | MB_TYPE_ACPRED; |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
5103 else |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
5104 s->current_picture.mb_type[xy]= MB_TYPE_INTRA; |
2967 | 5105 |
544 | 5106 cbpy = get_vlc2(&s->gb, cbpy_vlc.table, CBPY_VLC_BITS, 1); |
1482 | 5107 if(cbpy<0){ |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
5108 av_log(s->avctx, AV_LOG_ERROR, "I cbpy damaged at %d %d\n", s->mb_x, s->mb_y); |
1482 | 5109 return -1; |
5110 } | |
0 | 5111 cbp = (cbpc & 3) | (cbpy << 2); |
3282 | 5112 |
5113 s->use_intra_dc_vlc= s->qscale < s->intra_dc_threshold; | |
5114 | |
0 | 5115 if (dquant) { |
1652 | 5116 ff_set_qscale(s, s->qscale + quant_tab[get_bits(&s->gb, 2)]); |
0 | 5117 } |
2967 | 5118 |
619
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
5119 if(!s->progressive_sequence) |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
5120 s->interlaced_dct= get_bits1(&s->gb); |
575 | 5121 |
2632 | 5122 s->dsp.clear_blocks(s->block[0]); |
575 | 5123 /* decode each block */ |
1649
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
5124 for (i = 0; i < 6; i++) { |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
5125 if (mpeg4_decode_block(s, block[i], i, cbp&32, 1, 0) < 0) |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
5126 return -1; |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
5127 cbp+=cbp; |
575 | 5128 } |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
5129 goto end; |
0 | 5130 } |
5131 | |
5132 /* decode each block */ | |
1649
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
5133 for (i = 0; i < 6; i++) { |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
5134 if (mpeg4_decode_block(s, block[i], i, cbp&32, 0, 0) < 0) |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
5135 return -1; |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
5136 cbp+=cbp; |
0 | 5137 } |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
5138 end: |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
5139 |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
5140 /* per-MB end of slice check */ |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
5141 if(s->codec_id==CODEC_ID_MPEG4){ |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
5142 if(mpeg4_is_resync(s)){ |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
5143 const int delta= s->mb_x + 1 == s->mb_width ? 2 : 1; |
6481 | 5144 if(s->pict_type==FF_B_TYPE && s->next_picture.mbskip_table[xy + delta]) |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
5145 return SLICE_OK; |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
5146 return SLICE_END; |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
5147 } |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
5148 } |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
5149 |
2967 | 5150 return SLICE_OK; |
0 | 5151 } |
5152 | |
5153 /* most is hardcoded. should extend to handle all h263 streams */ | |
5154 int h263_decode_picture_header(MpegEncContext *s) | |
5155 { | |
1278
483db104bb7b
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
1273
diff
changeset
|
5156 int format, width, height, i; |
483db104bb7b
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
1273
diff
changeset
|
5157 uint32_t startcode; |
2967 | 5158 |
1278
483db104bb7b
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
1273
diff
changeset
|
5159 align_get_bits(&s->gb); |
483db104bb7b
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
1273
diff
changeset
|
5160 |
483db104bb7b
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
1273
diff
changeset
|
5161 startcode= get_bits(&s->gb, 22-8); |
483db104bb7b
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
1273
diff
changeset
|
5162 |
10535
95f3daa991a2
Use get_bits_left() instead of size_in_bits - get_bits_count().
rbultje
parents:
9999
diff
changeset
|
5163 for(i= get_bits_left(&s->gb); i>24; i-=8) { |
1278
483db104bb7b
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
1273
diff
changeset
|
5164 startcode = ((startcode << 8) | get_bits(&s->gb, 8)) & 0x003FFFFF; |
2967 | 5165 |
1278
483db104bb7b
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
1273
diff
changeset
|
5166 if(startcode == 0x20) |
483db104bb7b
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
1273
diff
changeset
|
5167 break; |
483db104bb7b
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
1273
diff
changeset
|
5168 } |
2967 | 5169 |
1278
483db104bb7b
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
1273
diff
changeset
|
5170 if (startcode != 0x20) { |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
5171 av_log(s->avctx, AV_LOG_ERROR, "Bad picture start code\n"); |
0 | 5172 return -1; |
355 | 5173 } |
5174 /* temporal reference */ | |
1865 | 5175 i = get_bits(&s->gb, 8); /* picture timestamp */ |
5176 if( (s->picture_number&~0xFF)+i < s->picture_number) | |
5177 i+= 256; | |
2886 | 5178 s->current_picture_ptr->pts= |
1865 | 5179 s->picture_number= (s->picture_number&~0xFF) + i; |
355 | 5180 |
2967 | 5181 /* PTYPE starts here */ |
355 | 5182 if (get_bits1(&s->gb) != 1) { |
5183 /* marker */ | |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
5184 av_log(s->avctx, AV_LOG_ERROR, "Bad marker\n"); |
355 | 5185 return -1; |
5186 } | |
5187 if (get_bits1(&s->gb) != 0) { | |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
5188 av_log(s->avctx, AV_LOG_ERROR, "Bad H263 id\n"); |
2979 | 5189 return -1; /* h263 id */ |
5190 } | |
5191 skip_bits1(&s->gb); /* split screen off */ | |
5192 skip_bits1(&s->gb); /* camera off */ | |
5193 skip_bits1(&s->gb); /* freeze picture release off */ | |
0 | 5194 |
5195 format = get_bits(&s->gb, 3); | |
355 | 5196 /* |
5197 0 forbidden | |
5198 1 sub-QCIF | |
5199 10 QCIF | |
2979 | 5200 7 extended PTYPE (PLUSPTYPE) |
355 | 5201 */ |
0 | 5202 |
161 | 5203 if (format != 7 && format != 6) { |
0 | 5204 s->h263_plus = 0; |
5205 /* H.263v1 */ | |
5206 width = h263_format[format][0]; | |
5207 height = h263_format[format][1]; | |
5208 if (!width) | |
5209 return -1; | |
2967 | 5210 |
6481 | 5211 s->pict_type = FF_I_TYPE + get_bits1(&s->gb); |
0 | 5212 |
2967 | 5213 s->h263_long_vectors = get_bits1(&s->gb); |
0 | 5214 |
355 | 5215 if (get_bits1(&s->gb) != 0) { |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
5216 av_log(s->avctx, AV_LOG_ERROR, "H263 SAC not supported\n"); |
2979 | 5217 return -1; /* SAC: off */ |
355 | 5218 } |
1633 | 5219 s->obmc= get_bits1(&s->gb); /* Advanced prediction mode */ |
5220 s->unrestricted_mv = s->h263_long_vectors || s->obmc; | |
2967 | 5221 |
9104 | 5222 s->pb_frame = get_bits1(&s->gb); |
1644 | 5223 s->chroma_qscale= s->qscale = get_bits(&s->gb, 5); |
2979 | 5224 skip_bits1(&s->gb); /* Continuous Presence Multipoint mode: off */ |
1393 | 5225 |
5226 s->width = width; | |
5227 s->height = height; | |
1865 | 5228 s->avctx->sample_aspect_ratio= (AVRational){12,11}; |
2637 | 5229 s->avctx->time_base= (AVRational){1001, 30000}; |
0 | 5230 } else { |
161 | 5231 int ufep; |
2967 | 5232 |
0 | 5233 /* H.263v2 */ |
161 | 5234 s->h263_plus = 1; |
5235 ufep = get_bits(&s->gb, 3); /* Update Full Extended PTYPE */ | |
355 | 5236 |
2967 | 5237 /* ufep other than 0 and 1 are reserved */ |
161 | 5238 if (ufep == 1) { |
2967 | 5239 /* OPPTYPE */ |
161 | 5240 format = get_bits(&s->gb, 3); |
4652 | 5241 dprintf(s->avctx, "ufep=1, format: %d\n", format); |
1872 | 5242 s->custom_pcf= get_bits1(&s->gb); |
5513 | 5243 s->umvplus = get_bits1(&s->gb); /* Unrestricted Motion Vector */ |
1644 | 5244 if (get_bits1(&s->gb) != 0) { |
5245 av_log(s->avctx, AV_LOG_ERROR, "Syntax-based Arithmetic Coding (SAC) not supported\n"); | |
5246 } | |
1633 | 5247 s->obmc= get_bits1(&s->gb); /* Advanced prediction mode */ |
5248 s->h263_aic = get_bits1(&s->gb); /* Advanced Intra Coding (AIC) */ | |
1644 | 5249 s->loop_filter= get_bits1(&s->gb); |
5250 s->unrestricted_mv = s->umvplus || s->obmc || s->loop_filter; | |
2967 | 5251 |
1661 | 5252 s->h263_slice_structured= get_bits1(&s->gb); |
1278
483db104bb7b
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
1273
diff
changeset
|
5253 if (get_bits1(&s->gb) != 0) { |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
5254 av_log(s->avctx, AV_LOG_ERROR, "Reference Picture Selection not supported\n"); |
1278
483db104bb7b
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
1273
diff
changeset
|
5255 } |
483db104bb7b
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
1273
diff
changeset
|
5256 if (get_bits1(&s->gb) != 0) { |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
5257 av_log(s->avctx, AV_LOG_ERROR, "Independent Segment Decoding not supported\n"); |
1278
483db104bb7b
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
1273
diff
changeset
|
5258 } |
1637 | 5259 s->alt_inter_vlc= get_bits1(&s->gb); |
1639 | 5260 s->modified_quant= get_bits1(&s->gb); |
1644 | 5261 if(s->modified_quant) |
5262 s->chroma_qscale_table= ff_h263_chroma_qscale_table; | |
2967 | 5263 |
1278
483db104bb7b
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
1273
diff
changeset
|
5264 skip_bits(&s->gb, 1); /* Prevent start code emulation */ |
355 | 5265 |
161 | 5266 skip_bits(&s->gb, 3); /* Reserved */ |
355 | 5267 } else if (ufep != 0) { |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
5268 av_log(s->avctx, AV_LOG_ERROR, "Bad UFEP type (%d)\n", ufep); |
0 | 5269 return -1; |
355 | 5270 } |
2967 | 5271 |
78 | 5272 /* MPPTYPE */ |
1655 | 5273 s->pict_type = get_bits(&s->gb, 3); |
5274 switch(s->pict_type){ | |
6481 | 5275 case 0: s->pict_type= FF_I_TYPE;break; |
5276 case 1: s->pict_type= FF_P_TYPE;break; | |
9104 | 5277 case 2: s->pict_type= FF_P_TYPE;s->pb_frame = 3;break; |
6481 | 5278 case 3: s->pict_type= FF_B_TYPE;break; |
5279 case 7: s->pict_type= FF_I_TYPE;break; //ZYGO | |
1655 | 5280 default: |
0 | 5281 return -1; |
1655 | 5282 } |
250
3449316664b5
- Bug fix on RTYPE (rounding type) not being honoured by H.263+ decoder.
pulento
parents:
249
diff
changeset
|
5283 skip_bits(&s->gb, 2); |
3449316664b5
- Bug fix on RTYPE (rounding type) not being honoured by H.263+ decoder.
pulento
parents:
249
diff
changeset
|
5284 s->no_rounding = get_bits1(&s->gb); |
3449316664b5
- Bug fix on RTYPE (rounding type) not being honoured by H.263+ decoder.
pulento
parents:
249
diff
changeset
|
5285 skip_bits(&s->gb, 4); |
2967 | 5286 |
78 | 5287 /* Get the picture dimensions */ |
161 | 5288 if (ufep) { |
5289 if (format == 6) { | |
5290 /* Custom Picture Format (CPFMT) */ | |
355 | 5291 s->aspect_ratio_info = get_bits(&s->gb, 4); |
4652 | 5292 dprintf(s->avctx, "aspect: %d\n", s->aspect_ratio_info); |
355 | 5293 /* aspect ratios: |
5294 0 - forbidden | |
5295 1 - 1:1 | |
5296 2 - 12:11 (CIF 4:3) | |
5297 3 - 10:11 (525-type 4:3) | |
5298 4 - 16:11 (CIF 16:9) | |
5299 5 - 40:33 (525-type 16:9) | |
5300 6-14 - reserved | |
5301 */ | |
161 | 5302 width = (get_bits(&s->gb, 9) + 1) * 4; |
5303 skip_bits1(&s->gb); | |
5304 height = get_bits(&s->gb, 9) * 4; | |
4652 | 5305 dprintf(s->avctx, "\nH.263+ Custom picture: %dx%d\n",width,height); |
669
b4bddbde44f3
aspect (ext. par too) support for h263 and mpeg4 (inc. build becouse of new vars)
al3x
parents:
667
diff
changeset
|
5306 if (s->aspect_ratio_info == FF_ASPECT_EXTENDED) { |
355 | 5307 /* aspected dimensions */ |
1548 | 5308 s->avctx->sample_aspect_ratio.num= get_bits(&s->gb, 8); |
5309 s->avctx->sample_aspect_ratio.den= get_bits(&s->gb, 8); | |
887 | 5310 }else{ |
1548 | 5311 s->avctx->sample_aspect_ratio= pixel_aspect[s->aspect_ratio_info]; |
355 | 5312 } |
5313 } else { | |
161 | 5314 width = h263_format[format][0]; |
5315 height = h263_format[format][1]; | |
1865 | 5316 s->avctx->sample_aspect_ratio= (AVRational){12,11}; |
161 | 5317 } |
5318 if ((width == 0) || (height == 0)) | |
5319 return -1; | |
5320 s->width = width; | |
5321 s->height = height; | |
1872 | 5322 |
5323 if(s->custom_pcf){ | |
5324 int gcd; | |
2637 | 5325 s->avctx->time_base.den= 1800000; |
5326 s->avctx->time_base.num= 1000 + get_bits1(&s->gb); | |
5327 s->avctx->time_base.num*= get_bits(&s->gb, 7); | |
5328 if(s->avctx->time_base.num == 0){ | |
1872 | 5329 av_log(s, AV_LOG_ERROR, "zero framerate\n"); |
5330 return -1; | |
5331 } | |
8611 | 5332 gcd= av_gcd(s->avctx->time_base.den, s->avctx->time_base.num); |
2637 | 5333 s->avctx->time_base.den /= gcd; |
5334 s->avctx->time_base.num /= gcd; | |
1872 | 5335 }else{ |
2637 | 5336 s->avctx->time_base= (AVRational){1001, 30000}; |
1872 | 5337 } |
5338 } | |
2967 | 5339 |
1872 | 5340 if(s->custom_pcf){ |
5341 skip_bits(&s->gb, 2); //extended Temporal reference | |
5342 } | |
5343 | |
5344 if (ufep) { | |
1089 | 5345 if (s->umvplus) { |
5346 if(get_bits1(&s->gb)==0) /* Unlimited Unrestricted Motion Vectors Indicator (UUI) */ | |
2967 | 5347 skip_bits1(&s->gb); |
161 | 5348 } |
1661 | 5349 if(s->h263_slice_structured){ |
5350 if (get_bits1(&s->gb) != 0) { | |
5351 av_log(s->avctx, AV_LOG_ERROR, "rectangular slices not supported\n"); | |
5352 } | |
5353 if (get_bits1(&s->gb) != 0) { | |
5354 av_log(s->avctx, AV_LOG_ERROR, "unordered slices not supported\n"); | |
5355 } | |
5356 } | |
78 | 5357 } |
2967 | 5358 |
0 | 5359 s->qscale = get_bits(&s->gb, 5); |
5360 } | |
1670 | 5361 |
1896
ef87d53ca87a
h.263 ssm + aic fix by (Maarten Daniels <maarten dot daniels at student dot luc dot ac dot be>)
michael
parents:
1893
diff
changeset
|
5362 s->mb_width = (s->width + 15) / 16; |
ef87d53ca87a
h.263 ssm + aic fix by (Maarten Daniels <maarten dot daniels at student dot luc dot ac dot be>)
michael
parents:
1893
diff
changeset
|
5363 s->mb_height = (s->height + 15) / 16; |
ef87d53ca87a
h.263 ssm + aic fix by (Maarten Daniels <maarten dot daniels at student dot luc dot ac dot be>)
michael
parents:
1893
diff
changeset
|
5364 s->mb_num = s->mb_width * s->mb_height; |
ef87d53ca87a
h.263 ssm + aic fix by (Maarten Daniels <maarten dot daniels at student dot luc dot ac dot be>)
michael
parents:
1893
diff
changeset
|
5365 |
9104 | 5366 if (s->pb_frame) { |
5367 skip_bits(&s->gb, 3); /* Temporal reference for B-pictures */ | |
5368 if (s->custom_pcf) | |
5369 skip_bits(&s->gb, 2); //extended Temporal reference | |
5370 skip_bits(&s->gb, 2); /* Quantization information for B-pictures */ | |
5371 } | |
5372 | |
0 | 5373 /* PEI */ |
21 | 5374 while (get_bits1(&s->gb) != 0) { |
5375 skip_bits(&s->gb, 8); | |
0 | 5376 } |
1896
ef87d53ca87a
h.263 ssm + aic fix by (Maarten Daniels <maarten dot daniels at student dot luc dot ac dot be>)
michael
parents:
1893
diff
changeset
|
5377 |
1670 | 5378 if(s->h263_slice_structured){ |
5379 if (get_bits1(&s->gb) != 1) { | |
5380 av_log(s->avctx, AV_LOG_ERROR, "SEPB1 marker missing\n"); | |
5381 return -1; | |
5382 } | |
5383 | |
5384 ff_h263_decode_mba(s); | |
5385 | |
5386 if (get_bits1(&s->gb) != 1) { | |
5387 av_log(s->avctx, AV_LOG_ERROR, "SEPB2 marker missing\n"); | |
5388 return -1; | |
5389 } | |
5390 } | |
0 | 5391 s->f_code = 1; |
2967 | 5392 |
498 | 5393 if(s->h263_aic){ |
2967 | 5394 s->y_dc_scale_table= |
1639 | 5395 s->c_dc_scale_table= ff_aic_dc_scale_table; |
498 | 5396 }else{ |
5397 s->y_dc_scale_table= | |
5398 s->c_dc_scale_table= ff_mpeg1_dc_scale_table; | |
5399 } | |
5400 | |
1278
483db104bb7b
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
1273
diff
changeset
|
5401 if(s->avctx->debug&FF_DEBUG_PICT_INFO){ |
5403 | 5402 show_pict_info(s); |
1278
483db104bb7b
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
1273
diff
changeset
|
5403 } |
8612 | 5404 if (s->pict_type == FF_I_TYPE && s->codec_tag == AV_RL32("ZYGO")){ |
1584
3615999a7284
dumping funny numbers from first zygo i frame header
michael
parents:
1583
diff
changeset
|
5405 int i,j; |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
5406 for(i=0; i<85; i++) av_log(s->avctx, AV_LOG_DEBUG, "%d", get_bits1(&s->gb)); |
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
5407 av_log(s->avctx, AV_LOG_DEBUG, "\n"); |
1584
3615999a7284
dumping funny numbers from first zygo i frame header
michael
parents:
1583
diff
changeset
|
5408 for(i=0; i<13; i++){ |
3615999a7284
dumping funny numbers from first zygo i frame header
michael
parents:
1583
diff
changeset
|
5409 for(j=0; j<3; j++){ |
3615999a7284
dumping funny numbers from first zygo i frame header
michael
parents:
1583
diff
changeset
|
5410 int v= get_bits(&s->gb, 8); |
3615999a7284
dumping funny numbers from first zygo i frame header
michael
parents:
1583
diff
changeset
|
5411 v |= get_sbits(&s->gb, 8)<<8; |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
5412 av_log(s->avctx, AV_LOG_DEBUG, " %5d", v); |
1584
3615999a7284
dumping funny numbers from first zygo i frame header
michael
parents:
1583
diff
changeset
|
5413 } |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
5414 av_log(s->avctx, AV_LOG_DEBUG, "\n"); |
1584
3615999a7284
dumping funny numbers from first zygo i frame header
michael
parents:
1583
diff
changeset
|
5415 } |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
5416 for(i=0; i<50; i++) av_log(s->avctx, AV_LOG_DEBUG, "%d", get_bits1(&s->gb)); |
1584
3615999a7284
dumping funny numbers from first zygo i frame header
michael
parents:
1583
diff
changeset
|
5417 } |
3615999a7284
dumping funny numbers from first zygo i frame header
michael
parents:
1583
diff
changeset
|
5418 |
0 | 5419 return 0; |
5420 } | |
5421 | |
942 | 5422 static int mpeg4_decode_gop_header(MpegEncContext * s, GetBitContext *gb){ |
5423 int hours, minutes, seconds; | |
5424 | |
5425 hours= get_bits(gb, 5); | |
5426 minutes= get_bits(gb, 6); | |
5427 skip_bits1(gb); | |
5428 seconds= get_bits(gb, 6); | |
5429 | |
5430 s->time_base= seconds + 60*(minutes + 60*hours); | |
5431 | |
5432 skip_bits1(gb); | |
5433 skip_bits1(gb); | |
2967 | 5434 |
942 | 5435 return 0; |
5436 } | |
5437 | |
747
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5438 static int decode_vol_header(MpegEncContext *s, GetBitContext *gb){ |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5439 int width, height, vo_ver_id; |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5440 |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5441 /* vol header */ |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5442 skip_bits(gb, 1); /* random access */ |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5443 s->vo_type= get_bits(gb, 8); |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5444 if (get_bits1(gb) != 0) { /* is_ol_id */ |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5445 vo_ver_id = get_bits(gb, 4); /* vo_ver_id */ |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5446 skip_bits(gb, 3); /* vo_priority */ |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5447 } else { |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5448 vo_ver_id = 1; |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5449 } |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5450 s->aspect_ratio_info= get_bits(gb, 4); |
2967 | 5451 if(s->aspect_ratio_info == FF_ASPECT_EXTENDED){ |
1548 | 5452 s->avctx->sample_aspect_ratio.num= get_bits(gb, 8); // par_width |
5453 s->avctx->sample_aspect_ratio.den= get_bits(gb, 8); // par_height | |
887 | 5454 }else{ |
1548 | 5455 s->avctx->sample_aspect_ratio= pixel_aspect[s->aspect_ratio_info]; |
747
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5456 } |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5457 |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5458 if ((s->vol_control_parameters=get_bits1(gb))) { /* vol control parameter */ |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5459 int chroma_format= get_bits(gb, 2); |
8690 | 5460 if(chroma_format!=CHROMA_420){ |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
5461 av_log(s->avctx, AV_LOG_ERROR, "illegal chroma format\n"); |
747
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5462 } |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5463 s->low_delay= get_bits1(gb); |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5464 if(get_bits1(gb)){ /* vbv parameters */ |
2979 | 5465 get_bits(gb, 15); /* first_half_bitrate */ |
5466 skip_bits1(gb); /* marker */ | |
5467 get_bits(gb, 15); /* latter_half_bitrate */ | |
5468 skip_bits1(gb); /* marker */ | |
5469 get_bits(gb, 15); /* first_half_vbv_buffer_size */ | |
5470 skip_bits1(gb); /* marker */ | |
5471 get_bits(gb, 3); /* latter_half_vbv_buffer_size */ | |
5472 get_bits(gb, 11); /* first_half_vbv_occupancy */ | |
5473 skip_bits1(gb); /* marker */ | |
5474 get_bits(gb, 15); /* latter_half_vbv_occupancy */ | |
5475 skip_bits1(gb); /* marker */ | |
747
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5476 } |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5477 }else{ |
2646
c735e3e60ca7
Even More spelling errors. patch by (Kevin Baragona <kevinmb500 gawab com)
michael
parents:
2639
diff
changeset
|
5478 // set low delay flag only once the smartest? low delay detection won't be overriden |
747
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5479 if(s->picture_number==0) |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5480 s->low_delay=0; |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5481 } |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5482 |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5483 s->shape = get_bits(gb, 2); /* vol shape */ |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
5484 if(s->shape != RECT_SHAPE) av_log(s->avctx, AV_LOG_ERROR, "only rectangular vol supported\n"); |
747
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5485 if(s->shape == GRAY_SHAPE && vo_ver_id != 1){ |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
5486 av_log(s->avctx, AV_LOG_ERROR, "Gray shape not supported\n"); |
747
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5487 skip_bits(gb, 4); //video_object_layer_shape_extension |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5488 } |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5489 |
1411 | 5490 check_marker(gb, "before time_increment_resolution"); |
2967 | 5491 |
2637 | 5492 s->avctx->time_base.den = get_bits(gb, 16); |
2812 | 5493 if(!s->avctx->time_base.den){ |
5494 av_log(s->avctx, AV_LOG_ERROR, "time_base.den==0\n"); | |
5495 return -1; | |
5496 } | |
2967 | 5497 |
2637 | 5498 s->time_increment_bits = av_log2(s->avctx->time_base.den - 1) + 1; |
747
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5499 if (s->time_increment_bits < 1) |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5500 s->time_increment_bits = 1; |
2967 | 5501 |
1411 | 5502 check_marker(gb, "before fixed_vop_rate"); |
747
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5503 |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5504 if (get_bits1(gb) != 0) { /* fixed_vop_rate */ |
2637 | 5505 s->avctx->time_base.num = get_bits(gb, s->time_increment_bits); |
5506 }else | |
5507 s->avctx->time_base.num = 1; | |
5508 | |
2034 | 5509 s->t_frame=0; |
747
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5510 |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5511 if (s->shape != BIN_ONLY_SHAPE) { |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5512 if (s->shape == RECT_SHAPE) { |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5513 skip_bits1(gb); /* marker */ |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5514 width = get_bits(gb, 13); |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5515 skip_bits1(gb); /* marker */ |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5516 height = get_bits(gb, 13); |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5517 skip_bits1(gb); /* marker */ |
8612 | 5518 if(width && height && !(s->width && s->codec_tag == AV_RL32("MP4S"))){ /* they should be non zero but who knows ... */ |
747
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5519 s->width = width; |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5520 s->height = height; |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5521 } |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5522 } |
2967 | 5523 |
5524 s->progressive_sequence= | |
1659 | 5525 s->progressive_frame= get_bits1(gb)^1; |
3192 | 5526 s->interlaced_dct=0; |
2967 | 5527 if(!get_bits1(gb) && (s->avctx->debug & FF_DEBUG_PICT_INFO)) |
1644 | 5528 av_log(s->avctx, AV_LOG_INFO, "MPEG4 OBMC not supported (very likely buggy encoder)\n"); /* OBMC Disable */ |
747
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5529 if (vo_ver_id == 1) { |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5530 s->vol_sprite_usage = get_bits1(gb); /* vol_sprite_usage */ |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5531 } else { |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5532 s->vol_sprite_usage = get_bits(gb, 2); /* vol_sprite_usage */ |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5533 } |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
5534 if(s->vol_sprite_usage==STATIC_SPRITE) av_log(s->avctx, AV_LOG_ERROR, "Static Sprites not supported\n"); |
747
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5535 if(s->vol_sprite_usage==STATIC_SPRITE || s->vol_sprite_usage==GMC_SPRITE){ |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5536 if(s->vol_sprite_usage==STATIC_SPRITE){ |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5537 s->sprite_width = get_bits(gb, 13); |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5538 skip_bits1(gb); /* marker */ |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5539 s->sprite_height= get_bits(gb, 13); |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5540 skip_bits1(gb); /* marker */ |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5541 s->sprite_left = get_bits(gb, 13); |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5542 skip_bits1(gb); /* marker */ |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5543 s->sprite_top = get_bits(gb, 13); |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5544 skip_bits1(gb); /* marker */ |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5545 } |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5546 s->num_sprite_warping_points= get_bits(gb, 6); |
4930
655d25351bfc
fix possibly exploitable stack overflow with num_sprite_warping_points (found by reimar)
michael
parents:
4672
diff
changeset
|
5547 if(s->num_sprite_warping_points > 3){ |
655d25351bfc
fix possibly exploitable stack overflow with num_sprite_warping_points (found by reimar)
michael
parents:
4672
diff
changeset
|
5548 av_log(s->avctx, AV_LOG_ERROR, "%d sprite_warping_points\n", s->num_sprite_warping_points); |
655d25351bfc
fix possibly exploitable stack overflow with num_sprite_warping_points (found by reimar)
michael
parents:
4672
diff
changeset
|
5549 s->num_sprite_warping_points= 0; |
655d25351bfc
fix possibly exploitable stack overflow with num_sprite_warping_points (found by reimar)
michael
parents:
4672
diff
changeset
|
5550 return -1; |
655d25351bfc
fix possibly exploitable stack overflow with num_sprite_warping_points (found by reimar)
michael
parents:
4672
diff
changeset
|
5551 } |
747
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5552 s->sprite_warping_accuracy = get_bits(gb, 2); |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5553 s->sprite_brightness_change= get_bits1(gb); |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5554 if(s->vol_sprite_usage==STATIC_SPRITE) |
2967 | 5555 s->low_latency_sprite= get_bits1(gb); |
747
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5556 } |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5557 // FIXME sadct disable bit if verid!=1 && shape not rect |
2967 | 5558 |
747
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5559 if (get_bits1(gb) == 1) { /* not_8_bit */ |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5560 s->quant_precision = get_bits(gb, 4); /* quant_precision */ |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
5561 if(get_bits(gb, 4)!=8) av_log(s->avctx, AV_LOG_ERROR, "N-bit not supported\n"); /* bits_per_pixel */ |
2628
511e3afc43e1
Ministry of English Composition, reporting for duty (and the word is "skipped", not "skiped"; "skiped" would rhyme with "hyped")
melanson
parents:
2615
diff
changeset
|
5562 if(s->quant_precision!=5) av_log(s->avctx, AV_LOG_ERROR, "quant precision %d\n", s->quant_precision); |
747
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5563 } else { |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5564 s->quant_precision = 5; |
0 | 5565 } |
2967 | 5566 |
747
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5567 // FIXME a bunch of grayscale shape things |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5568 |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5569 if((s->mpeg_quant=get_bits1(gb))){ /* vol_quant_type */ |
1057 | 5570 int i, v; |
2967 | 5571 |
747
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5572 /* load default matrixes */ |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5573 for(i=0; i<64; i++){ |
1092 | 5574 int j= s->dsp.idct_permutation[i]; |
747
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5575 v= ff_mpeg4_default_intra_matrix[i]; |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5576 s->intra_matrix[j]= v; |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5577 s->chroma_intra_matrix[j]= v; |
2967 | 5578 |
747
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5579 v= ff_mpeg4_default_non_intra_matrix[i]; |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5580 s->inter_matrix[j]= v; |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5581 s->chroma_inter_matrix[j]= v; |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5582 } |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5583 |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5584 /* load custom intra matrix */ |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5585 if(get_bits1(gb)){ |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5586 int last=0; |
2979 | 5587 for(i=0; i<64; i++){ |
1057 | 5588 int j; |
747
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5589 v= get_bits(gb, 8); |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5590 if(v==0) break; |
2967 | 5591 |
747
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5592 last= v; |
1092 | 5593 j= s->dsp.idct_permutation[ ff_zigzag_direct[i] ]; |
747
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5594 s->intra_matrix[j]= v; |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5595 s->chroma_intra_matrix[j]= v; |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5596 } |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5597 |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5598 /* replicate last value */ |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5599 for(; i<64; i++){ |
2979 | 5600 int j= s->dsp.idct_permutation[ ff_zigzag_direct[i] ]; |
1411 | 5601 s->intra_matrix[j]= last; |
5602 s->chroma_intra_matrix[j]= last; | |
747
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5603 } |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5604 } |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5605 |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5606 /* load custom non intra matrix */ |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5607 if(get_bits1(gb)){ |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5608 int last=0; |
2979 | 5609 for(i=0; i<64; i++){ |
1057 | 5610 int j; |
747
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5611 v= get_bits(gb, 8); |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5612 if(v==0) break; |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5613 |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5614 last= v; |
1092 | 5615 j= s->dsp.idct_permutation[ ff_zigzag_direct[i] ]; |
747
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5616 s->inter_matrix[j]= v; |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5617 s->chroma_inter_matrix[j]= v; |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5618 } |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5619 |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5620 /* replicate last value */ |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5621 for(; i<64; i++){ |
2979 | 5622 int j= s->dsp.idct_permutation[ ff_zigzag_direct[i] ]; |
747
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5623 s->inter_matrix[j]= last; |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5624 s->chroma_inter_matrix[j]= last; |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5625 } |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5626 } |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5627 |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5628 // FIXME a bunch of grayscale shape things |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5629 } |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5630 |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5631 if(vo_ver_id != 1) |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5632 s->quarter_sample= get_bits1(gb); |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5633 else s->quarter_sample=0; |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5634 |
8251
d256dbf74ea6
Implement complexity estimation parsing and try to detect an incorrectly set
michael
parents:
8106
diff
changeset
|
5635 if(!get_bits1(gb)){ |
d256dbf74ea6
Implement complexity estimation parsing and try to detect an incorrectly set
michael
parents:
8106
diff
changeset
|
5636 int pos= get_bits_count(gb); |
d256dbf74ea6
Implement complexity estimation parsing and try to detect an incorrectly set
michael
parents:
8106
diff
changeset
|
5637 int estimation_method= get_bits(gb, 2); |
d256dbf74ea6
Implement complexity estimation parsing and try to detect an incorrectly set
michael
parents:
8106
diff
changeset
|
5638 if(estimation_method<2){ |
d256dbf74ea6
Implement complexity estimation parsing and try to detect an incorrectly set
michael
parents:
8106
diff
changeset
|
5639 if(!get_bits1(gb)){ |
d256dbf74ea6
Implement complexity estimation parsing and try to detect an incorrectly set
michael
parents:
8106
diff
changeset
|
5640 s->cplx_estimation_trash_i += 8*get_bits1(gb); //opaque |
d256dbf74ea6
Implement complexity estimation parsing and try to detect an incorrectly set
michael
parents:
8106
diff
changeset
|
5641 s->cplx_estimation_trash_i += 8*get_bits1(gb); //transparent |
d256dbf74ea6
Implement complexity estimation parsing and try to detect an incorrectly set
michael
parents:
8106
diff
changeset
|
5642 s->cplx_estimation_trash_i += 8*get_bits1(gb); //intra_cae |
d256dbf74ea6
Implement complexity estimation parsing and try to detect an incorrectly set
michael
parents:
8106
diff
changeset
|
5643 s->cplx_estimation_trash_i += 8*get_bits1(gb); //inter_cae |
d256dbf74ea6
Implement complexity estimation parsing and try to detect an incorrectly set
michael
parents:
8106
diff
changeset
|
5644 s->cplx_estimation_trash_i += 8*get_bits1(gb); //no_update |
d256dbf74ea6
Implement complexity estimation parsing and try to detect an incorrectly set
michael
parents:
8106
diff
changeset
|
5645 s->cplx_estimation_trash_i += 8*get_bits1(gb); //upampling |
d256dbf74ea6
Implement complexity estimation parsing and try to detect an incorrectly set
michael
parents:
8106
diff
changeset
|
5646 } |
d256dbf74ea6
Implement complexity estimation parsing and try to detect an incorrectly set
michael
parents:
8106
diff
changeset
|
5647 if(!get_bits1(gb)){ |
d256dbf74ea6
Implement complexity estimation parsing and try to detect an incorrectly set
michael
parents:
8106
diff
changeset
|
5648 s->cplx_estimation_trash_i += 8*get_bits1(gb); //intra_blocks |
d256dbf74ea6
Implement complexity estimation parsing and try to detect an incorrectly set
michael
parents:
8106
diff
changeset
|
5649 s->cplx_estimation_trash_p += 8*get_bits1(gb); //inter_blocks |
d256dbf74ea6
Implement complexity estimation parsing and try to detect an incorrectly set
michael
parents:
8106
diff
changeset
|
5650 s->cplx_estimation_trash_p += 8*get_bits1(gb); //inter4v_blocks |
d256dbf74ea6
Implement complexity estimation parsing and try to detect an incorrectly set
michael
parents:
8106
diff
changeset
|
5651 s->cplx_estimation_trash_i += 8*get_bits1(gb); //not coded blocks |
d256dbf74ea6
Implement complexity estimation parsing and try to detect an incorrectly set
michael
parents:
8106
diff
changeset
|
5652 } |
d256dbf74ea6
Implement complexity estimation parsing and try to detect an incorrectly set
michael
parents:
8106
diff
changeset
|
5653 if(!check_marker(gb, "in complexity estimation part 1")){ |
d256dbf74ea6
Implement complexity estimation parsing and try to detect an incorrectly set
michael
parents:
8106
diff
changeset
|
5654 skip_bits_long(gb, pos - get_bits_count(gb)); |
d256dbf74ea6
Implement complexity estimation parsing and try to detect an incorrectly set
michael
parents:
8106
diff
changeset
|
5655 goto no_cplx_est; |
d256dbf74ea6
Implement complexity estimation parsing and try to detect an incorrectly set
michael
parents:
8106
diff
changeset
|
5656 } |
d256dbf74ea6
Implement complexity estimation parsing and try to detect an incorrectly set
michael
parents:
8106
diff
changeset
|
5657 if(!get_bits1(gb)){ |
d256dbf74ea6
Implement complexity estimation parsing and try to detect an incorrectly set
michael
parents:
8106
diff
changeset
|
5658 s->cplx_estimation_trash_i += 8*get_bits1(gb); //dct_coeffs |
d256dbf74ea6
Implement complexity estimation parsing and try to detect an incorrectly set
michael
parents:
8106
diff
changeset
|
5659 s->cplx_estimation_trash_i += 8*get_bits1(gb); //dct_lines |
d256dbf74ea6
Implement complexity estimation parsing and try to detect an incorrectly set
michael
parents:
8106
diff
changeset
|
5660 s->cplx_estimation_trash_i += 8*get_bits1(gb); //vlc_syms |
d256dbf74ea6
Implement complexity estimation parsing and try to detect an incorrectly set
michael
parents:
8106
diff
changeset
|
5661 s->cplx_estimation_trash_i += 4*get_bits1(gb); //vlc_bits |
d256dbf74ea6
Implement complexity estimation parsing and try to detect an incorrectly set
michael
parents:
8106
diff
changeset
|
5662 } |
d256dbf74ea6
Implement complexity estimation parsing and try to detect an incorrectly set
michael
parents:
8106
diff
changeset
|
5663 if(!get_bits1(gb)){ |
d256dbf74ea6
Implement complexity estimation parsing and try to detect an incorrectly set
michael
parents:
8106
diff
changeset
|
5664 s->cplx_estimation_trash_p += 8*get_bits1(gb); //apm |
d256dbf74ea6
Implement complexity estimation parsing and try to detect an incorrectly set
michael
parents:
8106
diff
changeset
|
5665 s->cplx_estimation_trash_p += 8*get_bits1(gb); //npm |
d256dbf74ea6
Implement complexity estimation parsing and try to detect an incorrectly set
michael
parents:
8106
diff
changeset
|
5666 s->cplx_estimation_trash_b += 8*get_bits1(gb); //interpolate_mc_q |
d256dbf74ea6
Implement complexity estimation parsing and try to detect an incorrectly set
michael
parents:
8106
diff
changeset
|
5667 s->cplx_estimation_trash_p += 8*get_bits1(gb); //forwback_mc_q |
d256dbf74ea6
Implement complexity estimation parsing and try to detect an incorrectly set
michael
parents:
8106
diff
changeset
|
5668 s->cplx_estimation_trash_p += 8*get_bits1(gb); //halfpel2 |
d256dbf74ea6
Implement complexity estimation parsing and try to detect an incorrectly set
michael
parents:
8106
diff
changeset
|
5669 s->cplx_estimation_trash_p += 8*get_bits1(gb); //halfpel4 |
d256dbf74ea6
Implement complexity estimation parsing and try to detect an incorrectly set
michael
parents:
8106
diff
changeset
|
5670 } |
d256dbf74ea6
Implement complexity estimation parsing and try to detect an incorrectly set
michael
parents:
8106
diff
changeset
|
5671 if(!check_marker(gb, "in complexity estimation part 2")){ |
d256dbf74ea6
Implement complexity estimation parsing and try to detect an incorrectly set
michael
parents:
8106
diff
changeset
|
5672 skip_bits_long(gb, pos - get_bits_count(gb)); |
d256dbf74ea6
Implement complexity estimation parsing and try to detect an incorrectly set
michael
parents:
8106
diff
changeset
|
5673 goto no_cplx_est; |
d256dbf74ea6
Implement complexity estimation parsing and try to detect an incorrectly set
michael
parents:
8106
diff
changeset
|
5674 } |
d256dbf74ea6
Implement complexity estimation parsing and try to detect an incorrectly set
michael
parents:
8106
diff
changeset
|
5675 if(estimation_method==1){ |
d256dbf74ea6
Implement complexity estimation parsing and try to detect an incorrectly set
michael
parents:
8106
diff
changeset
|
5676 s->cplx_estimation_trash_i += 8*get_bits1(gb); //sadct |
d256dbf74ea6
Implement complexity estimation parsing and try to detect an incorrectly set
michael
parents:
8106
diff
changeset
|
5677 s->cplx_estimation_trash_p += 8*get_bits1(gb); //qpel |
d256dbf74ea6
Implement complexity estimation parsing and try to detect an incorrectly set
michael
parents:
8106
diff
changeset
|
5678 } |
d256dbf74ea6
Implement complexity estimation parsing and try to detect an incorrectly set
michael
parents:
8106
diff
changeset
|
5679 }else |
d256dbf74ea6
Implement complexity estimation parsing and try to detect an incorrectly set
michael
parents:
8106
diff
changeset
|
5680 av_log(s->avctx, AV_LOG_ERROR, "Invalid Complexity estimation method %d\n", estimation_method); |
d256dbf74ea6
Implement complexity estimation parsing and try to detect an incorrectly set
michael
parents:
8106
diff
changeset
|
5681 }else{ |
d256dbf74ea6
Implement complexity estimation parsing and try to detect an incorrectly set
michael
parents:
8106
diff
changeset
|
5682 no_cplx_est: |
d256dbf74ea6
Implement complexity estimation parsing and try to detect an incorrectly set
michael
parents:
8106
diff
changeset
|
5683 s->cplx_estimation_trash_i= |
d256dbf74ea6
Implement complexity estimation parsing and try to detect an incorrectly set
michael
parents:
8106
diff
changeset
|
5684 s->cplx_estimation_trash_p= |
d256dbf74ea6
Implement complexity estimation parsing and try to detect an incorrectly set
michael
parents:
8106
diff
changeset
|
5685 s->cplx_estimation_trash_b= 0; |
d256dbf74ea6
Implement complexity estimation parsing and try to detect an incorrectly set
michael
parents:
8106
diff
changeset
|
5686 } |
747
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5687 |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5688 s->resync_marker= !get_bits1(gb); /* resync_marker_disabled */ |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5689 |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5690 s->data_partitioning= get_bits1(gb); |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5691 if(s->data_partitioning){ |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5692 s->rvlc= get_bits1(gb); |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5693 } |
2967 | 5694 |
747
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5695 if(vo_ver_id != 1) { |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5696 s->new_pred= get_bits1(gb); |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5697 if(s->new_pred){ |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
5698 av_log(s->avctx, AV_LOG_ERROR, "new pred not supported\n"); |
747
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5699 skip_bits(gb, 2); /* requested upstream message type */ |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5700 skip_bits1(gb); /* newpred segment type */ |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5701 } |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5702 s->reduced_res_vop= get_bits1(gb); |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
5703 if(s->reduced_res_vop) av_log(s->avctx, AV_LOG_ERROR, "reduced resolution VOP not supported\n"); |
747
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5704 } |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5705 else{ |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5706 s->new_pred=0; |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5707 s->reduced_res_vop= 0; |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5708 } |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5709 |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5710 s->scalability= get_bits1(gb); |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5711 |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5712 if (s->scalability) { |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5713 GetBitContext bak= *gb; |
751 | 5714 int ref_layer_id; |
5715 int ref_layer_sampling_dir; | |
5716 int h_sampling_factor_n; | |
5717 int h_sampling_factor_m; | |
5718 int v_sampling_factor_n; | |
5719 int v_sampling_factor_m; | |
2967 | 5720 |
751 | 5721 s->hierachy_type= get_bits1(gb); |
5722 ref_layer_id= get_bits(gb, 4); | |
5723 ref_layer_sampling_dir= get_bits1(gb); | |
5724 h_sampling_factor_n= get_bits(gb, 5); | |
5725 h_sampling_factor_m= get_bits(gb, 5); | |
5726 v_sampling_factor_n= get_bits(gb, 5); | |
5727 v_sampling_factor_m= get_bits(gb, 5); | |
747
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5728 s->enhancement_type= get_bits1(gb); |
2967 | 5729 |
5730 if( h_sampling_factor_n==0 || h_sampling_factor_m==0 | |
747
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5731 || v_sampling_factor_n==0 || v_sampling_factor_m==0){ |
10775
35e175942ee2
Add a few explanatory comments to cornercase workarounds.
diego
parents:
10759
diff
changeset
|
5732 /* illegal scalability header (VERY broken encoder), |
35e175942ee2
Add a few explanatory comments to cornercase workarounds.
diego
parents:
10759
diff
changeset
|
5733 * trying to workaround */ |
747
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5734 s->scalability=0; |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5735 *gb= bak; |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5736 }else |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
5737 av_log(s->avctx, AV_LOG_ERROR, "scalability not supported\n"); |
2967 | 5738 |
747
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5739 // bin shape stuff FIXME |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5740 } |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5741 } |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5742 return 0; |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5743 } |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5744 |
1034 | 5745 /** |
5746 * decodes the user data stuff in the header. | |
6918 | 5747 * Also initializes divx/xvid/lavc_version/build. |
1034 | 5748 */ |
747
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5749 static int decode_user_data(MpegEncContext *s, GetBitContext *gb){ |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5750 char buf[256]; |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5751 int i; |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5752 int e; |
2966
564788471dd4
bitstream related fixes from [PATCH] from DivX, Part 9: bitstream crashes by (Steve Lhomme | slhomme divxcorp com)
michael
parents:
2962
diff
changeset
|
5753 int ver = 0, build = 0, ver2 = 0, ver3 = 0; |
1145
79e8ed620b17
better non conformant divx packed bitstream detection, so unpacked (no b frames) divx MPEG4-ES streams can be read
michaelni
parents:
1144
diff
changeset
|
5754 char last; |
747
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5755 |
3615 | 5756 for(i=0; i<255 && get_bits_count(gb) < gb->size_in_bits; i++){ |
2804 | 5757 if(show_bits(gb, 23) == 0) break; |
5758 buf[i]= get_bits(gb, 8); | |
5759 } | |
5760 buf[i]=0; | |
1145
79e8ed620b17
better non conformant divx packed bitstream detection, so unpacked (no b frames) divx MPEG4-ES streams can be read
michaelni
parents:
1144
diff
changeset
|
5761 |
761 | 5762 /* divx detection */ |
1145
79e8ed620b17
better non conformant divx packed bitstream detection, so unpacked (no b frames) divx MPEG4-ES streams can be read
michaelni
parents:
1144
diff
changeset
|
5763 e=sscanf(buf, "DivX%dBuild%d%c", &ver, &build, &last); |
79e8ed620b17
better non conformant divx packed bitstream detection, so unpacked (no b frames) divx MPEG4-ES streams can be read
michaelni
parents:
1144
diff
changeset
|
5764 if(e<2) |
79e8ed620b17
better non conformant divx packed bitstream detection, so unpacked (no b frames) divx MPEG4-ES streams can be read
michaelni
parents:
1144
diff
changeset
|
5765 e=sscanf(buf, "DivX%db%d%c", &ver, &build, &last); |
79e8ed620b17
better non conformant divx packed bitstream detection, so unpacked (no b frames) divx MPEG4-ES streams can be read
michaelni
parents:
1144
diff
changeset
|
5766 if(e>=2){ |
747
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5767 s->divx_version= ver; |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5768 s->divx_build= build; |
1145
79e8ed620b17
better non conformant divx packed bitstream detection, so unpacked (no b frames) divx MPEG4-ES streams can be read
michaelni
parents:
1144
diff
changeset
|
5769 s->divx_packed= e==3 && last=='p'; |
8106
2f5101a67500
Only warn about "Invalid and inefficient vfw-avi packed B frames" once.
andoma
parents:
8042
diff
changeset
|
5770 if(s->divx_packed && !s->showed_packed_warning) { |
6893
72dafc993490
Warn about packed B-frames. (especially useful if the file in question is
michael
parents:
6655
diff
changeset
|
5771 av_log(s->avctx, AV_LOG_WARNING, "Invalid and inefficient vfw-avi packed B frames detected\n"); |
8106
2f5101a67500
Only warn about "Invalid and inefficient vfw-avi packed B frames" once.
andoma
parents:
8042
diff
changeset
|
5772 s->showed_packed_warning=1; |
2f5101a67500
Only warn about "Invalid and inefficient vfw-avi packed B frames" once.
andoma
parents:
8042
diff
changeset
|
5773 } |
0 | 5774 } |
2967 | 5775 |
761 | 5776 /* ffmpeg detection */ |
2805
55a6659fc2ee
fix user data parsing code so it suppors pre1 and cvs
michael
parents:
2804
diff
changeset
|
5777 e=sscanf(buf, "FFmpe%*[^b]b%d", &build)+3; |
747
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5778 if(e!=4) |
2967 | 5779 e=sscanf(buf, "FFmpeg v%d.%d.%d / libavcodec build: %d", &ver, &ver2, &ver3, &build); |
747
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5780 if(e!=4){ |
2814 | 5781 e=sscanf(buf, "Lavc%d.%d.%d", &ver, &ver2, &ver3)+1; |
2966
564788471dd4
bitstream related fixes from [PATCH] from DivX, Part 9: bitstream crashes by (Steve Lhomme | slhomme divxcorp com)
michael
parents:
2962
diff
changeset
|
5782 if (e>1) |
564788471dd4
bitstream related fixes from [PATCH] from DivX, Part 9: bitstream crashes by (Steve Lhomme | slhomme divxcorp com)
michael
parents:
2962
diff
changeset
|
5783 build= (ver<<16) + (ver2<<8) + ver3; |
2814 | 5784 } |
5785 if(e!=4){ | |
747
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5786 if(strcmp(buf, "ffmpeg")==0){ |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5787 s->lavc_build= 4600; |
63 | 5788 } |
747
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5789 } |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5790 if(e==4){ |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5791 s->lavc_build= build; |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5792 } |
2967 | 5793 |
6908 | 5794 /* Xvid detection */ |
761 | 5795 e=sscanf(buf, "XviD%d", &build); |
5796 if(e==1){ | |
5797 s->xvid_build= build; | |
5798 } | |
5799 | |
747
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5800 return 0; |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5801 } |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5802 |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5803 static int decode_vop_header(MpegEncContext *s, GetBitContext *gb){ |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5804 int time_incr, time_increment; |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5805 |
6481 | 5806 s->pict_type = get_bits(gb, 2) + FF_I_TYPE; /* pict type: I = 0 , P = 1 */ |
5807 if(s->pict_type==FF_B_TYPE && s->low_delay && s->vol_control_parameters==0 && !(s->flags & CODEC_FLAG_LOW_DELAY)){ | |
2628
511e3afc43e1
Ministry of English Composition, reporting for duty (and the word is "skipped", not "skiped"; "skiped" would rhyme with "hyped")
melanson
parents:
2615
diff
changeset
|
5808 av_log(s->avctx, AV_LOG_ERROR, "low_delay flag incorrectly, clearing it\n"); |
365
fdeec2834c79
there are divx5? encoded files without a userdata section but with b-frames :(
michaelni
parents:
364
diff
changeset
|
5809 s->low_delay=0; |
fdeec2834c79
there are divx5? encoded files without a userdata section but with b-frames :(
michaelni
parents:
364
diff
changeset
|
5810 } |
2967 | 5811 |
6481 | 5812 s->partitioned_frame= s->data_partitioning && s->pict_type!=FF_B_TYPE; |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
5813 if(s->partitioned_frame) |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
5814 s->decode_mb= mpeg4_decode_partitioned_mb; |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
5815 else |
1649
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
5816 s->decode_mb= ff_mpeg4_decode_mb; |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
5817 |
262 | 5818 time_incr=0; |
2967 | 5819 while (get_bits1(gb) != 0) |
0 | 5820 time_incr++; |
5821 | |
747
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5822 check_marker(gb, "before time_increment"); |
2666 | 5823 |
5824 if(s->time_increment_bits==0 || !(show_bits(gb, s->time_increment_bits+1)&1)){ | |
2628
511e3afc43e1
Ministry of English Composition, reporting for duty (and the word is "skipped", not "skiped"; "skiped" would rhyme with "hyped")
melanson
parents:
2615
diff
changeset
|
5825 av_log(s->avctx, AV_LOG_ERROR, "hmm, seems the headers are not complete, trying to guess time_increment_bits\n"); |
1068 | 5826 |
5827 for(s->time_increment_bits=1 ;s->time_increment_bits<16; s->time_increment_bits++){ | |
10664 | 5828 if ( s->pict_type == FF_P_TYPE |
5829 || (s->pict_type == FF_S_TYPE && s->vol_sprite_usage==GMC_SPRITE)) { | |
5830 if((show_bits(gb, s->time_increment_bits+6)&0x37) == 0x30) break; | |
5831 }else | |
5832 if((show_bits(gb, s->time_increment_bits+5)&0x1F) == 0x18) break; | |
1068 | 5833 } |
1396 | 5834 |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
5835 av_log(s->avctx, AV_LOG_ERROR, "my guess is %d bits ;)\n",s->time_increment_bits); |
1068 | 5836 } |
2967 | 5837 |
1411 | 5838 if(IS_3IV1) time_increment= get_bits1(gb); //FIXME investigate further |
5839 else time_increment= get_bits(gb, s->time_increment_bits); | |
2967 | 5840 |
6481 | 5841 if(s->pict_type!=FF_B_TYPE){ |
324 | 5842 s->last_time_base= s->time_base; |
262 | 5843 s->time_base+= time_incr; |
2637 | 5844 s->time= s->time_base*s->avctx->time_base.den + time_increment; |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
5845 if(s->workaround_bugs&FF_BUG_UMP4){ |
700
0fb4c66527e1
autodetect UMP4 (by adding a fourcc field to AVCodecContext)
michaelni
parents:
699
diff
changeset
|
5846 if(s->time < s->last_non_b_time){ |
10775
35e175942ee2
Add a few explanatory comments to cornercase workarounds.
diego
parents:
10759
diff
changeset
|
5847 /* header is not mpeg-4-compatible, broken encoder, |
35e175942ee2
Add a few explanatory comments to cornercase workarounds.
diego
parents:
10759
diff
changeset
|
5848 * trying to workaround */ |
700
0fb4c66527e1
autodetect UMP4 (by adding a fourcc field to AVCodecContext)
michaelni
parents:
699
diff
changeset
|
5849 s->time_base++; |
2637 | 5850 s->time+= s->avctx->time_base.den; |
700
0fb4c66527e1
autodetect UMP4 (by adding a fourcc field to AVCodecContext)
michaelni
parents:
699
diff
changeset
|
5851 } |
664 | 5852 } |
324 | 5853 s->pp_time= s->time - s->last_non_b_time; |
5854 s->last_non_b_time= s->time; | |
262 | 5855 }else{ |
2637 | 5856 s->time= (s->last_time_base + time_incr)*s->avctx->time_base.den + time_increment; |
664 | 5857 s->pb_time= s->pp_time - (s->last_non_b_time - s->time); |
5858 if(s->pp_time <=s->pb_time || s->pp_time <= s->pp_time - s->pb_time || s->pp_time<=0){ | |
10775
35e175942ee2
Add a few explanatory comments to cornercase workarounds.
diego
parents:
10759
diff
changeset
|
5859 /* messed up order, maybe after seeking? skipping current b-frame */ |
2628
511e3afc43e1
Ministry of English Composition, reporting for duty (and the word is "skipped", not "skiped"; "skiped" would rhyme with "hyped")
melanson
parents:
2615
diff
changeset
|
5860 return FRAME_SKIPPED; |
335 | 5861 } |
3247 | 5862 ff_mpeg4_init_direct_mv(s); |
2967 | 5863 |
2034 | 5864 if(s->t_frame==0) s->t_frame= s->pb_time; |
664 | 5865 if(s->t_frame==0) s->t_frame=1; // 1/0 protection |
2967 | 5866 s->pp_field_time= ( ROUNDED_DIV(s->last_non_b_time, s->t_frame) |
664 | 5867 - ROUNDED_DIV(s->last_non_b_time - s->pp_time, s->t_frame))*2; |
2967 | 5868 s->pb_field_time= ( ROUNDED_DIV(s->time, s->t_frame) |
664 | 5869 - ROUNDED_DIV(s->last_non_b_time - s->pp_time, s->t_frame))*2; |
4346 | 5870 if(!s->progressive_sequence){ |
5871 if(s->pp_field_time <= s->pb_field_time || s->pb_field_time <= 1) | |
5872 return FRAME_SKIPPED; | |
5873 } | |
262 | 5874 } |
2967 | 5875 |
2813
6fd9dbb8c385
try to check for nonsense time_base instead of setting fake one
michael
parents:
2812
diff
changeset
|
5876 if(s->avctx->time_base.num) |
6fd9dbb8c385
try to check for nonsense time_base instead of setting fake one
michael
parents:
2812
diff
changeset
|
5877 s->current_picture_ptr->pts= (s->time + s->avctx->time_base.num/2) / s->avctx->time_base.num; |
6fd9dbb8c385
try to check for nonsense time_base instead of setting fake one
michael
parents:
2812
diff
changeset
|
5878 else |
6fd9dbb8c385
try to check for nonsense time_base instead of setting fake one
michael
parents:
2812
diff
changeset
|
5879 s->current_picture_ptr->pts= AV_NOPTS_VALUE; |
942 | 5880 if(s->avctx->debug&FF_DEBUG_PTS) |
2962 | 5881 av_log(s->avctx, AV_LOG_DEBUG, "MPEG4 PTS: %"PRId64"\n", s->current_picture_ptr->pts); |
2034 | 5882 |
1068 | 5883 check_marker(gb, "before vop_coded"); |
2967 | 5884 |
0 | 5885 /* vop coded */ |
747
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5886 if (get_bits1(gb) != 1){ |
2271 | 5887 if(s->avctx->debug&FF_DEBUG_PICT_INFO) |
5888 av_log(s->avctx, AV_LOG_ERROR, "vop not coded\n"); | |
2628
511e3afc43e1
Ministry of English Composition, reporting for duty (and the word is "skipped", not "skiped"; "skiped" would rhyme with "hyped")
melanson
parents:
2615
diff
changeset
|
5889 return FRAME_SKIPPED; |
747
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5890 } |
6481 | 5891 if (s->shape != BIN_ONLY_SHAPE && ( s->pict_type == FF_P_TYPE |
5892 || (s->pict_type == FF_S_TYPE && s->vol_sprite_usage==GMC_SPRITE))) { | |
0 | 5893 /* rounding type for motion estimation */ |
2979 | 5894 s->no_rounding = get_bits1(gb); |
63 | 5895 } else { |
2979 | 5896 s->no_rounding = 0; |
0 | 5897 } |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
5898 //FIXME reduced res stuff |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
5899 |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
5900 if (s->shape != RECT_SHAPE) { |
6481 | 5901 if (s->vol_sprite_usage != 1 || s->pict_type != FF_I_TYPE) { |
63 | 5902 int width, height, hor_spat_ref, ver_spat_ref; |
2967 | 5903 |
747
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5904 width = get_bits(gb, 13); |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5905 skip_bits1(gb); /* marker */ |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5906 height = get_bits(gb, 13); |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5907 skip_bits1(gb); /* marker */ |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5908 hor_spat_ref = get_bits(gb, 13); /* hor_spat_ref */ |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5909 skip_bits1(gb); /* marker */ |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5910 ver_spat_ref = get_bits(gb, 13); /* ver_spat_ref */ |
63 | 5911 } |
747
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5912 skip_bits1(gb); /* change_CR_disable */ |
2967 | 5913 |
747
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5914 if (get_bits1(gb) != 0) { |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5915 skip_bits(gb, 8); /* constant_alpha_value */ |
63 | 5916 } |
5917 } | |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
5918 //FIXME complexity estimation stuff |
2967 | 5919 |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
5920 if (s->shape != BIN_ONLY_SHAPE) { |
8251
d256dbf74ea6
Implement complexity estimation parsing and try to detect an incorrectly set
michael
parents:
8106
diff
changeset
|
5921 skip_bits_long(gb, s->cplx_estimation_trash_i); |
d256dbf74ea6
Implement complexity estimation parsing and try to detect an incorrectly set
michael
parents:
8106
diff
changeset
|
5922 if(s->pict_type != FF_I_TYPE) |
d256dbf74ea6
Implement complexity estimation parsing and try to detect an incorrectly set
michael
parents:
8106
diff
changeset
|
5923 skip_bits_long(gb, s->cplx_estimation_trash_p); |
d256dbf74ea6
Implement complexity estimation parsing and try to detect an incorrectly set
michael
parents:
8106
diff
changeset
|
5924 if(s->pict_type == FF_B_TYPE) |
d256dbf74ea6
Implement complexity estimation parsing and try to detect an incorrectly set
michael
parents:
8106
diff
changeset
|
5925 skip_bits_long(gb, s->cplx_estimation_trash_b); |
d256dbf74ea6
Implement complexity estimation parsing and try to detect an incorrectly set
michael
parents:
8106
diff
changeset
|
5926 |
1520 | 5927 s->intra_dc_threshold= mpeg4_dc_threshold[ get_bits(gb, 3) ]; |
619
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
5928 if(!s->progressive_sequence){ |
747
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5929 s->top_field_first= get_bits1(gb); |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5930 s->alternate_scan= get_bits1(gb); |
661 | 5931 }else |
5932 s->alternate_scan= 0; | |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
5933 } |
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
5934 |
718 | 5935 if(s->alternate_scan){ |
1273 | 5936 ff_init_scantable(s->dsp.idct_permutation, &s->inter_scantable , ff_alternate_vertical_scan); |
5937 ff_init_scantable(s->dsp.idct_permutation, &s->intra_scantable , ff_alternate_vertical_scan); | |
5938 ff_init_scantable(s->dsp.idct_permutation, &s->intra_h_scantable, ff_alternate_vertical_scan); | |
5939 ff_init_scantable(s->dsp.idct_permutation, &s->intra_v_scantable, ff_alternate_vertical_scan); | |
718 | 5940 } else{ |
1273 | 5941 ff_init_scantable(s->dsp.idct_permutation, &s->inter_scantable , ff_zigzag_direct); |
5942 ff_init_scantable(s->dsp.idct_permutation, &s->intra_scantable , ff_zigzag_direct); | |
5943 ff_init_scantable(s->dsp.idct_permutation, &s->intra_h_scantable, ff_alternate_horizontal_scan); | |
5944 ff_init_scantable(s->dsp.idct_permutation, &s->intra_v_scantable, ff_alternate_vertical_scan); | |
718 | 5945 } |
2967 | 5946 |
6481 | 5947 if(s->pict_type == FF_S_TYPE && (s->vol_sprite_usage==STATIC_SPRITE || s->vol_sprite_usage==GMC_SPRITE)){ |
1914 | 5948 mpeg4_decode_sprite_trajectory(s, gb); |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
5949 if(s->sprite_brightness_change) av_log(s->avctx, AV_LOG_ERROR, "sprite_brightness_change not supported\n"); |
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
5950 if(s->vol_sprite_usage==STATIC_SPRITE) av_log(s->avctx, AV_LOG_ERROR, "static sprite not supported\n"); |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
5951 } |
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
5952 |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
5953 if (s->shape != BIN_ONLY_SHAPE) { |
1644 | 5954 s->chroma_qscale= s->qscale = get_bits(gb, s->quant_precision); |
264
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
5955 if(s->qscale==0){ |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
5956 av_log(s->avctx, AV_LOG_ERROR, "Error, header damaged or not MPEG4 header (qscale=0)\n"); |
264
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
5957 return -1; // makes no sense to continue, as there is nothing left from the image then |
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
5958 } |
2967 | 5959 |
6481 | 5960 if (s->pict_type != FF_I_TYPE) { |
2979 | 5961 s->f_code = get_bits(gb, 3); /* fcode_for */ |
264
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
5962 if(s->f_code==0){ |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
5963 av_log(s->avctx, AV_LOG_ERROR, "Error, header damaged or not MPEG4 header (f_code=0)\n"); |
264
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
5964 return -1; // makes no sense to continue, as the MV decoding will break very quickly |
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
5965 } |
582
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
5966 }else |
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
5967 s->f_code=1; |
2967 | 5968 |
6481 | 5969 if (s->pict_type == FF_B_TYPE) { |
747
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5970 s->b_code = get_bits(gb, 3); |
582
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
5971 }else |
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
5972 s->b_code=1; |
906 | 5973 |
5974 if(s->avctx->debug&FF_DEBUG_PICT_INFO){ | |
8251
d256dbf74ea6
Implement complexity estimation parsing and try to detect an incorrectly set
michael
parents:
8106
diff
changeset
|
5975 av_log(s->avctx, AV_LOG_DEBUG, "qp:%d fc:%d,%d %s size:%d pro:%d alt:%d top:%d %spel part:%d resync:%d w:%d a:%d rnd:%d vot:%d%s dc:%d ce:%d/%d/%d\n", |
2967 | 5976 s->qscale, s->f_code, s->b_code, |
6481 | 5977 s->pict_type == FF_I_TYPE ? "I" : (s->pict_type == FF_P_TYPE ? "P" : (s->pict_type == FF_B_TYPE ? "B" : "S")), |
2967 | 5978 gb->size_in_bits,s->progressive_sequence, s->alternate_scan, s->top_field_first, |
930 | 5979 s->quarter_sample ? "q" : "h", s->data_partitioning, s->resync_marker, s->num_sprite_warping_points, |
8251
d256dbf74ea6
Implement complexity estimation parsing and try to detect an incorrectly set
michael
parents:
8106
diff
changeset
|
5980 s->sprite_warping_accuracy, 1-s->no_rounding, s->vo_type, s->vol_control_parameters ? " VOLC" : " ", s->intra_dc_threshold, s->cplx_estimation_trash_i, s->cplx_estimation_trash_p, s->cplx_estimation_trash_b); |
906 | 5981 } |
5982 | |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
5983 if(!s->scalability){ |
6481 | 5984 if (s->shape!=RECT_SHAPE && s->pict_type!=FF_I_TYPE) { |
747
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5985 skip_bits1(gb); // vop shape coding type |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
5986 } |
575 | 5987 }else{ |
5988 if(s->enhancement_type){ | |
747
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5989 int load_backward_shape= get_bits1(gb); |
575 | 5990 if(load_backward_shape){ |
2646
c735e3e60ca7
Even More spelling errors. patch by (Kevin Baragona <kevinmb500 gawab com)
michael
parents:
2639
diff
changeset
|
5991 av_log(s->avctx, AV_LOG_ERROR, "load backward shape isn't supported\n"); |
575 | 5992 } |
5993 } | |
747
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
5994 skip_bits(gb, 2); //ref_select_code |
63 | 5995 } |
5996 } | |
2646
c735e3e60ca7
Even More spelling errors. patch by (Kevin Baragona <kevinmb500 gawab com)
michael
parents:
2639
diff
changeset
|
5997 /* detect buggy encoders which don't set the low_delay flag (divx4/xvid/opendivx)*/ |
c735e3e60ca7
Even More spelling errors. patch by (Kevin Baragona <kevinmb500 gawab com)
michael
parents:
2639
diff
changeset
|
5998 // note we cannot detect divx5 without b-frames easily (although it's buggy too) |
365
fdeec2834c79
there are divx5? encoded files without a userdata section but with b-frames :(
michaelni
parents:
364
diff
changeset
|
5999 if(s->vo_type==0 && s->vol_control_parameters==0 && s->divx_version==0 && s->picture_number==0){ |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
6000 av_log(s->avctx, AV_LOG_ERROR, "looks like this file was encoded with (divx4/(old)xvid/opendivx) -> forcing low_delay flag\n"); |
346
c2f789fe4945
detecting xvid/divx4/opendivx and set low_delay flag
michaelni
parents:
344
diff
changeset
|
6001 s->low_delay=1; |
c2f789fe4945
detecting xvid/divx4/opendivx and set low_delay flag
michaelni
parents:
344
diff
changeset
|
6002 } |
c2f789fe4945
detecting xvid/divx4/opendivx and set low_delay flag
michaelni
parents:
344
diff
changeset
|
6003 |
2646
c735e3e60ca7
Even More spelling errors. patch by (Kevin Baragona <kevinmb500 gawab com)
michael
parents:
2639
diff
changeset
|
6004 s->picture_number++; // better than pic number==0 always ;) |
346
c2f789fe4945
detecting xvid/divx4/opendivx and set low_delay flag
michaelni
parents:
344
diff
changeset
|
6005 |
2967 | 6006 s->y_dc_scale_table= ff_mpeg4_y_dc_scale_table; //FIXME add short header support |
498 | 6007 s->c_dc_scale_table= ff_mpeg4_c_dc_scale_table; |
6008 | |
1366
80067f8d6770
fix edge repeating bug for %16!=0 files, this fixes Quicktime mpeg4 (they arent buggy)
michaelni
parents:
1364
diff
changeset
|
6009 if(s->workaround_bugs&FF_BUG_EDGE){ |
582
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
6010 s->h_edge_pos= s->width; |
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
6011 s->v_edge_pos= s->height; |
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
6012 } |
63 | 6013 return 0; |
0 | 6014 } |
6015 | |
747
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
6016 /** |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
6017 * decode mpeg4 headers |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
6018 * @return <0 if no VOP found (or a damaged one) |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
6019 * FRAME_SKIPPED if a not coded VOP is found |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
6020 * 0 if a VOP is found |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
6021 */ |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
6022 int ff_mpeg4_decode_picture_header(MpegEncContext * s, GetBitContext *gb) |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
6023 { |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
6024 int startcode, v; |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
6025 |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
6026 /* search next start code */ |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
6027 align_get_bits(gb); |
2406 | 6028 |
8612 | 6029 if(s->codec_tag == AV_RL32("WV1F") && show_bits(gb, 24) == 0x575630){ |
2406 | 6030 skip_bits(gb, 24); |
6031 if(get_bits(gb, 8) == 0xF0) | |
8417
ad4f10287633
Move CODEC_FLAG_LOW_DELAY into ff_mpeg4_decode_picture_header().
michael
parents:
8297
diff
changeset
|
6032 goto end; |
2406 | 6033 } |
6034 | |
747
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
6035 startcode = 0xff; |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
6036 for(;;) { |
1025
1f9afd8b9131
GetBitContext.size is allways multiplied by 8 -> use size_in_bits to avoid useless *8 in a few inner loops
michaelni
parents:
1013
diff
changeset
|
6037 if(get_bits_count(gb) >= gb->size_in_bits){ |
2554
84a8f374bf63
fixing playback of xvid pretending to be divx (sample_vop_nc.avi)
michael
parents:
2522
diff
changeset
|
6038 if(gb->size_in_bits==8 && (s->divx_version || s->xvid_build)){ |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
6039 av_log(s->avctx, AV_LOG_ERROR, "frame skip %d\n", gb->size_in_bits); |
2628
511e3afc43e1
Ministry of English Composition, reporting for duty (and the word is "skipped", not "skiped"; "skiped" would rhyme with "hyped")
melanson
parents:
2615
diff
changeset
|
6040 return FRAME_SKIPPED; //divx bug |
747
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
6041 }else |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
6042 return -1; //end of stream |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
6043 } |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
6044 |
2966
564788471dd4
bitstream related fixes from [PATCH] from DivX, Part 9: bitstream crashes by (Steve Lhomme | slhomme divxcorp com)
michael
parents:
2962
diff
changeset
|
6045 /* use the bits after the test */ |
564788471dd4
bitstream related fixes from [PATCH] from DivX, Part 9: bitstream crashes by (Steve Lhomme | slhomme divxcorp com)
michael
parents:
2962
diff
changeset
|
6046 v = get_bits(gb, 8); |
564788471dd4
bitstream related fixes from [PATCH] from DivX, Part 9: bitstream crashes by (Steve Lhomme | slhomme divxcorp com)
michael
parents:
2962
diff
changeset
|
6047 startcode = ((startcode << 8) | v) & 0xffffffff; |
564788471dd4
bitstream related fixes from [PATCH] from DivX, Part 9: bitstream crashes by (Steve Lhomme | slhomme divxcorp com)
michael
parents:
2962
diff
changeset
|
6048 |
747
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
6049 if((startcode&0xFFFFFF00) != 0x100) |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
6050 continue; //no startcode |
2967 | 6051 |
942 | 6052 if(s->avctx->debug&FF_DEBUG_STARTCODE){ |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
6053 av_log(s->avctx, AV_LOG_DEBUG, "startcode: %3X ", startcode); |
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
6054 if (startcode<=0x11F) av_log(s->avctx, AV_LOG_DEBUG, "Video Object Start"); |
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
6055 else if(startcode<=0x12F) av_log(s->avctx, AV_LOG_DEBUG, "Video Object Layer Start"); |
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
6056 else if(startcode<=0x13F) av_log(s->avctx, AV_LOG_DEBUG, "Reserved"); |
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
6057 else if(startcode<=0x15F) av_log(s->avctx, AV_LOG_DEBUG, "FGS bp start"); |
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
6058 else if(startcode<=0x1AF) av_log(s->avctx, AV_LOG_DEBUG, "Reserved"); |
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
6059 else if(startcode==0x1B0) av_log(s->avctx, AV_LOG_DEBUG, "Visual Object Seq Start"); |
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
6060 else if(startcode==0x1B1) av_log(s->avctx, AV_LOG_DEBUG, "Visual Object Seq End"); |
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
6061 else if(startcode==0x1B2) av_log(s->avctx, AV_LOG_DEBUG, "User Data"); |
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
6062 else if(startcode==0x1B3) av_log(s->avctx, AV_LOG_DEBUG, "Group of VOP start"); |
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
6063 else if(startcode==0x1B4) av_log(s->avctx, AV_LOG_DEBUG, "Video Session Error"); |
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
6064 else if(startcode==0x1B5) av_log(s->avctx, AV_LOG_DEBUG, "Visual Object Start"); |
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
6065 else if(startcode==0x1B6) av_log(s->avctx, AV_LOG_DEBUG, "Video Object Plane start"); |
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
6066 else if(startcode==0x1B7) av_log(s->avctx, AV_LOG_DEBUG, "slice start"); |
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
6067 else if(startcode==0x1B8) av_log(s->avctx, AV_LOG_DEBUG, "extension start"); |
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
6068 else if(startcode==0x1B9) av_log(s->avctx, AV_LOG_DEBUG, "fgs start"); |
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
6069 else if(startcode==0x1BA) av_log(s->avctx, AV_LOG_DEBUG, "FBA Object start"); |
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
6070 else if(startcode==0x1BB) av_log(s->avctx, AV_LOG_DEBUG, "FBA Object Plane start"); |
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
6071 else if(startcode==0x1BC) av_log(s->avctx, AV_LOG_DEBUG, "Mesh Object start"); |
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
6072 else if(startcode==0x1BD) av_log(s->avctx, AV_LOG_DEBUG, "Mesh Object Plane start"); |
2628
511e3afc43e1
Ministry of English Composition, reporting for duty (and the word is "skipped", not "skiped"; "skiped" would rhyme with "hyped")
melanson
parents:
2615
diff
changeset
|
6073 else if(startcode==0x1BE) av_log(s->avctx, AV_LOG_DEBUG, "Still Texture Object start"); |
511e3afc43e1
Ministry of English Composition, reporting for duty (and the word is "skipped", not "skiped"; "skiped" would rhyme with "hyped")
melanson
parents:
2615
diff
changeset
|
6074 else if(startcode==0x1BF) av_log(s->avctx, AV_LOG_DEBUG, "Texture Spatial Layer start"); |
511e3afc43e1
Ministry of English Composition, reporting for duty (and the word is "skipped", not "skiped"; "skiped" would rhyme with "hyped")
melanson
parents:
2615
diff
changeset
|
6075 else if(startcode==0x1C0) av_log(s->avctx, AV_LOG_DEBUG, "Texture SNR Layer start"); |
511e3afc43e1
Ministry of English Composition, reporting for duty (and the word is "skipped", not "skiped"; "skiped" would rhyme with "hyped")
melanson
parents:
2615
diff
changeset
|
6076 else if(startcode==0x1C1) av_log(s->avctx, AV_LOG_DEBUG, "Texture Tile start"); |
511e3afc43e1
Ministry of English Composition, reporting for duty (and the word is "skipped", not "skiped"; "skiped" would rhyme with "hyped")
melanson
parents:
2615
diff
changeset
|
6077 else if(startcode==0x1C2) av_log(s->avctx, AV_LOG_DEBUG, "Texture Shape Layer start"); |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
6078 else if(startcode==0x1C3) av_log(s->avctx, AV_LOG_DEBUG, "stuffing start"); |
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
6079 else if(startcode<=0x1C5) av_log(s->avctx, AV_LOG_DEBUG, "reserved"); |
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
6080 else if(startcode<=0x1FF) av_log(s->avctx, AV_LOG_DEBUG, "System start"); |
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
6081 av_log(s->avctx, AV_LOG_DEBUG, " at %d\n", get_bits_count(gb)); |
942 | 6082 } |
6083 | |
1512 | 6084 if(startcode >= 0x120 && startcode <= 0x12F){ |
2967 | 6085 if(decode_vol_header(s, gb) < 0) |
1396 | 6086 return -1; |
1512 | 6087 } |
6088 else if(startcode == USER_DATA_STARTCODE){ | |
747
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
6089 decode_user_data(s, gb); |
1512 | 6090 } |
6091 else if(startcode == GOP_STARTCODE){ | |
942 | 6092 mpeg4_decode_gop_header(s, gb); |
1512 | 6093 } |
6094 else if(startcode == VOP_STARTCODE){ | |
8417
ad4f10287633
Move CODEC_FLAG_LOW_DELAY into ff_mpeg4_decode_picture_header().
michael
parents:
8297
diff
changeset
|
6095 break; |
747
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
6096 } |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
6097 |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
6098 align_get_bits(gb); |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
6099 startcode = 0xff; |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
6100 } |
8417
ad4f10287633
Move CODEC_FLAG_LOW_DELAY into ff_mpeg4_decode_picture_header().
michael
parents:
8297
diff
changeset
|
6101 end: |
ad4f10287633
Move CODEC_FLAG_LOW_DELAY into ff_mpeg4_decode_picture_header().
michael
parents:
8297
diff
changeset
|
6102 if(s->flags& CODEC_FLAG_LOW_DELAY) |
ad4f10287633
Move CODEC_FLAG_LOW_DELAY into ff_mpeg4_decode_picture_header().
michael
parents:
8297
diff
changeset
|
6103 s->low_delay=1; |
8418
f75be04312dc
Fix PTS returned by the demuxers for mpeg4 without a decoder.
michael
parents:
8417
diff
changeset
|
6104 s->avctx->has_b_frames= !s->low_delay; |
8417
ad4f10287633
Move CODEC_FLAG_LOW_DELAY into ff_mpeg4_decode_picture_header().
michael
parents:
8297
diff
changeset
|
6105 return decode_vop_header(s, gb); |
747
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
6106 } |
3d4377531f6c
mpeg4 header parser clenup (needed for parsing of VOL header in avctx->extradata)
michaelni
parents:
745
diff
changeset
|
6107 |
0 | 6108 /* don't understand why they choose a different header ! */ |
6109 int intel_h263_decode_picture_header(MpegEncContext *s) | |
6110 { | |
6111 int format; | |
6112 | |
6113 /* picture header */ | |
1257 | 6114 if (get_bits_long(&s->gb, 22) != 0x20) { |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
6115 av_log(s->avctx, AV_LOG_ERROR, "Bad picture start code\n"); |
0 | 6116 return -1; |
355 | 6117 } |
6118 s->picture_number = get_bits(&s->gb, 8); /* picture timestamp */ | |
0 | 6119 |
355 | 6120 if (get_bits1(&s->gb) != 1) { |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
6121 av_log(s->avctx, AV_LOG_ERROR, "Bad marker\n"); |
2979 | 6122 return -1; /* marker */ |
355 | 6123 } |
6124 if (get_bits1(&s->gb) != 0) { | |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
6125 av_log(s->avctx, AV_LOG_ERROR, "Bad H263 id\n"); |
2979 | 6126 return -1; /* h263 id */ |
6127 } | |
6128 skip_bits1(&s->gb); /* split screen off */ | |
6129 skip_bits1(&s->gb); /* camera off */ | |
6130 skip_bits1(&s->gb); /* freeze picture release off */ | |
0 | 6131 |
6132 format = get_bits(&s->gb, 3); | |
355 | 6133 if (format != 7) { |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
6134 av_log(s->avctx, AV_LOG_ERROR, "Intel H263 free format not supported\n"); |
0 | 6135 return -1; |
355 | 6136 } |
0 | 6137 s->h263_plus = 0; |
6138 | |
6481 | 6139 s->pict_type = FF_I_TYPE + get_bits1(&s->gb); |
2967 | 6140 |
6141 s->unrestricted_mv = get_bits1(&s->gb); | |
0 | 6142 s->h263_long_vectors = s->unrestricted_mv; |
6143 | |
355 | 6144 if (get_bits1(&s->gb) != 0) { |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
6145 av_log(s->avctx, AV_LOG_ERROR, "SAC not supported\n"); |
2979 | 6146 return -1; /* SAC: off */ |
355 | 6147 } |
5405
f15e5b4909e1
remove "Advanced Prediction Mode not supported" spam
michael
parents:
5404
diff
changeset
|
6148 s->obmc= get_bits1(&s->gb); |
9008 | 6149 s->pb_frame = get_bits1(&s->gb); |
6150 | |
6151 if(format == 7){ | |
6152 format = get_bits(&s->gb, 3); | |
6153 if(format == 0 || format == 7){ | |
6154 av_log(s->avctx, AV_LOG_ERROR, "Wrong Intel H263 format\n"); | |
6155 return -1; | |
6156 } | |
6157 if(get_bits(&s->gb, 2)) | |
6158 av_log(s->avctx, AV_LOG_ERROR, "Bad value for reserved field\n"); | |
6159 s->loop_filter = get_bits1(&s->gb); | |
6160 if(get_bits1(&s->gb)) | |
6161 av_log(s->avctx, AV_LOG_ERROR, "Bad value for reserved field\n"); | |
6162 if(get_bits1(&s->gb)) | |
6163 s->pb_frame = 2; | |
6164 if(get_bits(&s->gb, 5)) | |
6165 av_log(s->avctx, AV_LOG_ERROR, "Bad value for reserved field\n"); | |
6166 if(get_bits(&s->gb, 5) != 1) | |
6167 av_log(s->avctx, AV_LOG_ERROR, "Invalid marker\n"); | |
6168 } | |
6169 if(format == 6){ | |
6170 int ar = get_bits(&s->gb, 4); | |
6171 skip_bits(&s->gb, 9); // display width | |
6172 skip_bits1(&s->gb); | |
6173 skip_bits(&s->gb, 9); // display height | |
6174 if(ar == 15){ | |
6175 skip_bits(&s->gb, 8); // aspect ratio - width | |
6176 skip_bits(&s->gb, 8); // aspect ratio - height | |
6177 } | |
6178 } | |
0 | 6179 |
1644 | 6180 s->chroma_qscale= s->qscale = get_bits(&s->gb, 5); |
2979 | 6181 skip_bits1(&s->gb); /* Continuous Presence Multipoint mode: off */ |
0 | 6182 |
9008 | 6183 if(s->pb_frame){ |
6184 skip_bits(&s->gb, 3); //temporal reference for B-frame | |
6185 skip_bits(&s->gb, 2); //dbquant | |
6186 } | |
6187 | |
0 | 6188 /* PEI */ |
21 | 6189 while (get_bits1(&s->gb) != 0) { |
6190 skip_bits(&s->gb, 8); | |
0 | 6191 } |
6192 s->f_code = 1; | |
770
d1770a34e4f6
segfault fix patch by (Juergen Keil <jk at tools dot de>)
michaelni
parents:
766
diff
changeset
|
6193 |
d1770a34e4f6
segfault fix patch by (Juergen Keil <jk at tools dot de>)
michaelni
parents:
766
diff
changeset
|
6194 s->y_dc_scale_table= |
d1770a34e4f6
segfault fix patch by (Juergen Keil <jk at tools dot de>)
michaelni
parents:
766
diff
changeset
|
6195 s->c_dc_scale_table= ff_mpeg1_dc_scale_table; |
d1770a34e4f6
segfault fix patch by (Juergen Keil <jk at tools dot de>)
michaelni
parents:
766
diff
changeset
|
6196 |
5404 | 6197 if(s->avctx->debug&FF_DEBUG_PICT_INFO) |
6198 show_pict_info(s); | |
6199 | |
0 | 6200 return 0; |
6201 } | |
144 | 6202 |
1353
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
6203 int flv_h263_decode_picture_header(MpegEncContext *s) |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
6204 { |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
6205 int format, width, height; |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
6206 |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
6207 /* picture header */ |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
6208 if (get_bits_long(&s->gb, 17) != 1) { |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
6209 av_log(s->avctx, AV_LOG_ERROR, "Bad picture start code\n"); |
1353
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
6210 return -1; |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
6211 } |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
6212 format = get_bits(&s->gb, 5); |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
6213 if (format != 0 && format != 1) { |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
6214 av_log(s->avctx, AV_LOG_ERROR, "Bad picture format\n"); |
1353
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
6215 return -1; |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
6216 } |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
6217 s->h263_flv = format+1; |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
6218 s->picture_number = get_bits(&s->gb, 8); /* picture timestamp */ |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
6219 format = get_bits(&s->gb, 3); |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
6220 switch (format) { |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
6221 case 0: |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
6222 width = get_bits(&s->gb, 8); |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
6223 height = get_bits(&s->gb, 8); |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
6224 break; |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
6225 case 1: |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
6226 width = get_bits(&s->gb, 16); |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
6227 height = get_bits(&s->gb, 16); |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
6228 break; |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
6229 case 2: |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
6230 width = 352; |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
6231 height = 288; |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
6232 break; |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
6233 case 3: |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
6234 width = 176; |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
6235 height = 144; |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
6236 break; |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
6237 case 4: |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
6238 width = 128; |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
6239 height = 96; |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
6240 break; |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
6241 case 5: |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
6242 width = 320; |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
6243 height = 240; |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
6244 break; |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
6245 case 6: |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
6246 width = 160; |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
6247 height = 120; |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
6248 break; |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
6249 default: |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
6250 width = height = 0; |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
6251 break; |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
6252 } |
2422 | 6253 if(avcodec_check_dimensions(s->avctx, width, height)) |
1353
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
6254 return -1; |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
6255 s->width = width; |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
6256 s->height = height; |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
6257 |
6481 | 6258 s->pict_type = FF_I_TYPE + get_bits(&s->gb, 2); |
6259 s->dropable= s->pict_type > FF_P_TYPE; | |
1944 | 6260 if (s->dropable) |
6481 | 6261 s->pict_type = FF_P_TYPE; |
2967 | 6262 |
2979 | 6263 skip_bits1(&s->gb); /* deblocking flag */ |
1644 | 6264 s->chroma_qscale= s->qscale = get_bits(&s->gb, 5); |
1353
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
6265 |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
6266 s->h263_plus = 0; |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
6267 |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
6268 s->unrestricted_mv = 1; |
1364 | 6269 s->h263_long_vectors = 0; |
1353
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
6270 |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
6271 /* PEI */ |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
6272 while (get_bits1(&s->gb) != 0) { |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
6273 skip_bits(&s->gb, 8); |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
6274 } |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
6275 s->f_code = 1; |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
6276 |
1364 | 6277 if(s->avctx->debug & FF_DEBUG_PICT_INFO){ |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
6278 av_log(s->avctx, AV_LOG_DEBUG, "%c esc_type:%d, qp:%d num:%d\n", |
2414
18d77621fbc7
print "D" instead of "P" for dropable frames in flv with -debug 1
michael
parents:
2406
diff
changeset
|
6279 s->dropable ? 'D' : av_get_pict_type_char(s->pict_type), s->h263_flv-1, s->qscale, s->picture_number); |
1364 | 6280 } |
2967 | 6281 |
1353
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
6282 s->y_dc_scale_table= |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
6283 s->c_dc_scale_table= ff_mpeg1_dc_scale_table; |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
6284 |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
6285 return 0; |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
6286 } |