23 #define UNCHECKED_BITSTREAM_READER 1
35 #define SPRITE_TRAJ_VLC_BITS 6
37 #define MB_TYPE_B_VLC_BITS 4
60 int16_t *ac_val, *ac_val1;
72 if(s->
mb_x==0 || s->
qscale == qscale_table[xy] || n==1 || n==3){
88 if(s->
mb_y==0 || s->
qscale == qscale_table[xy] || n==2 || n==3){
133 v|= 0x7F >> (7-(bits_count&7));
146 for(len=0; len<32; len++){
170 int d[4][2]={{0,0}, {0,0}, {0,0}, {0,0}};
171 int sprite_ref[4][2];
172 int virtual_ref[2][2];
203 while((1<<alpha)<w) alpha++;
204 while((1<<beta )<h) beta++;
210 sprite_ref[0][0]= a*vop_ref[0][0] + d[0][0];
211 sprite_ref[0][1]= a*vop_ref[0][1] + d[0][1];
212 sprite_ref[1][0]= a*vop_ref[1][0] + d[0][0] + d[1][0];
213 sprite_ref[1][1]= a*vop_ref[1][1] + d[0][1] + d[1][1];
214 sprite_ref[2][0]= a*vop_ref[2][0] + d[0][0] + d[2][0];
215 sprite_ref[2][1]= a*vop_ref[2][1] + d[0][1] + d[2][1];
217 sprite_ref[0][0]= (a>>1)*(2*vop_ref[0][0] + d[0][0]);
218 sprite_ref[0][1]= (a>>1)*(2*vop_ref[0][1] + d[0][1]);
219 sprite_ref[1][0]= (a>>1)*(2*vop_ref[1][0] + d[0][0] + d[1][0]);
220 sprite_ref[1][1]= (a>>1)*(2*vop_ref[1][1] + d[0][1] + d[1][1]);
221 sprite_ref[2][0]= (a>>1)*(2*vop_ref[2][0] + d[0][0] + d[2][0]);
222 sprite_ref[2][1]= (a>>1)*(2*vop_ref[2][1] + d[0][1] + d[2][1]);
231 virtual_ref[0][0]= 16*(vop_ref[0][0] + w2)
232 +
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);
233 virtual_ref[0][1]= 16*vop_ref[0][1]
234 +
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);
235 virtual_ref[1][0]= 16*vop_ref[0][0]
236 +
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);
237 virtual_ref[1][1]= 16*(vop_ref[0][1] + h2)
238 +
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);
257 s->
sprite_offset[1][0]= ((sprite_ref[0][0]>>1)|(sprite_ref[0][0]&1)) - a*(vop_ref[0][0]/2);
258 s->
sprite_offset[1][1]= ((sprite_ref[0][1]>>1)|(sprite_ref[0][1]&1)) - a*(vop_ref[0][1]/2);
268 + (-r*sprite_ref[0][0] + virtual_ref[0][0])*(-vop_ref[0][0])
269 + ( r*sprite_ref[0][1] - virtual_ref[0][1])*(-vop_ref[0][1])
270 + (1<<(alpha+rho-1));
272 + (-r*sprite_ref[0][1] + virtual_ref[0][1])*(-vop_ref[0][0])
273 + (-r*sprite_ref[0][0] + virtual_ref[0][0])*(-vop_ref[0][1])
274 + (1<<(alpha+rho-1));
275 s->
sprite_offset[1][0]= ( (-r*sprite_ref[0][0] + virtual_ref[0][0])*(-2*vop_ref[0][0] + 1)
276 +( r*sprite_ref[0][1] - virtual_ref[0][1])*(-2*vop_ref[0][1] + 1)
277 +2*w2*r*sprite_ref[0][0]
279 + (1<<(alpha+rho+1)));
280 s->
sprite_offset[1][1]= ( (-r*sprite_ref[0][1] + virtual_ref[0][1])*(-2*vop_ref[0][0] + 1)
281 +(-r*sprite_ref[0][0] + virtual_ref[0][0])*(-2*vop_ref[0][1] + 1)
282 +2*w2*r*sprite_ref[0][1]
284 + (1<<(alpha+rho+1)));
285 s->
sprite_delta[0][0]= (-r*sprite_ref[0][0] + virtual_ref[0][0]);
286 s->
sprite_delta[0][1]= (+r*sprite_ref[0][1] - virtual_ref[0][1]);
287 s->
sprite_delta[1][0]= (-r*sprite_ref[0][1] + virtual_ref[0][1]);
288 s->
sprite_delta[1][1]= (-r*sprite_ref[0][0] + virtual_ref[0][0]);
294 min_ab=
FFMIN(alpha, beta);
297 s->
sprite_offset[0][0]= (sprite_ref[0][0]<<(alpha+beta+rho-min_ab))
298 + (-r*sprite_ref[0][0] + virtual_ref[0][0])*h3*(-vop_ref[0][0])
299 + (-r*sprite_ref[0][0] + virtual_ref[1][0])*w3*(-vop_ref[0][1])
300 + (1<<(alpha+beta+rho-min_ab-1));
301 s->
sprite_offset[0][1]= (sprite_ref[0][1]<<(alpha+beta+rho-min_ab))
302 + (-r*sprite_ref[0][1] + virtual_ref[0][1])*h3*(-vop_ref[0][0])
303 + (-r*sprite_ref[0][1] + virtual_ref[1][1])*w3*(-vop_ref[0][1])
304 + (1<<(alpha+beta+rho-min_ab-1));
305 s->
sprite_offset[1][0]= (-r*sprite_ref[0][0] + virtual_ref[0][0])*h3*(-2*vop_ref[0][0] + 1)
306 + (-r*sprite_ref[0][0] + virtual_ref[1][0])*w3*(-2*vop_ref[0][1] + 1)
307 + 2*w2*h3*r*sprite_ref[0][0]
309 + (1<<(alpha+beta+rho-min_ab+1));
310 s->
sprite_offset[1][1]= (-r*sprite_ref[0][1] + virtual_ref[0][1])*h3*(-2*vop_ref[0][0] + 1)
311 + (-r*sprite_ref[0][1] + virtual_ref[1][1])*w3*(-2*vop_ref[0][1] + 1)
312 + 2*w2*h3*r*sprite_ref[0][1]
314 + (1<<(alpha+beta+rho-min_ab+1));
315 s->
sprite_delta[0][0]= (-r*sprite_ref[0][0] + virtual_ref[0][0])*h3;
316 s->
sprite_delta[0][1]= (-r*sprite_ref[0][0] + virtual_ref[1][0])*w3;
317 s->
sprite_delta[1][0]= (-r*sprite_ref[0][1] + virtual_ref[0][1])*h3;
318 s->
sprite_delta[1][1]= (-r*sprite_ref[0][1] + virtual_ref[1][1])*w3;
364 int header_extension=0, mb_num,
len;
369 for(len=0; len<32; len++){
401 if(header_extension){
407 check_marker(&s->
gb,
"before time_increment in video packed header");
409 check_marker(&s->
gb,
"before vop_coding_type in video packed header");
450 int x,
y, mb_v, sum, dx, dy,
shift;
466 if(n) dy -= 1<<(shift + a + 1);
467 else dx -= 1<<(shift + a + 1);
484 if (sum < -len) sum= -
len;
485 else if (sum >= len) sum= len-1;
504 if (code < 0 || code > 9 ){
516 level =
get_bits(&s->
gb, code-1) + (1<<(code-1));
518 level = -
get_bits(&s->
gb, code-1) - (1<<(code-1));
543 static const int8_t quant_tab[4] = { -1, -2, 1, 2 };
593 if(dc_pred_dir) dir|=1;
597 int mx, my, pred_x, pred_y,
bits;
617 mot_val[0 ]= mot_val[2 ]=
619 mot_val[1 ]= mot_val[3 ]=
642 mot_val[0 ]= mot_val[2 ]=
644 mot_val[1 ]= mot_val[3 ]=
654 if ((cbpc & 16) == 0) {
673 mot_val[0 ]= mot_val[2 ] =
675 mot_val[1 ]= mot_val[3 ]=
708 static const int8_t quant_tab[4] = { -1, -2, 1, 2 };
756 if(dc_pred_dir) dir|=1;
783 if(mb_num >= mb_count)
return 0;
847 int n,
int coded,
int intra,
int rvlc)
888 if (dc_pred_dir == 0)
918 qadd = (s->
qscale - 1) | 1;
956 level= level * qmul + qadd;
969 if (cache&0x80000000) {
970 if (cache&0x40000000) {
997 if(s->error_recognition >= FF_ER_COMPLIANT){
998 const int abs_level=
FFABS(level);
1000 const int run1= run - rl->
max_run[last][abs_level] - 1;
1001 if(abs_level <= rl->max_level[last][run]){
1005 if(s->error_recognition > FF_ER_COMPLIANT){
1006 if(abs_level <= rl->max_level[last][run]*2){
1010 if(run1 >= 0 && abs_level <= rl->max_level[last][run1]){
1018 if (level>0) level= level * qmul + qadd;
1019 else level= level * qmul - qadd;
1021 if((
unsigned)(level + 2048) > 4095){
1023 if(level > 2560 || level<-2560){
1028 level= level<0 ? -2048 : 2047;
1037 i+= run + rl->
max_run[run>>7][level/qmul] +1;
1046 level = level + rl->
max_level[run>>7][(run-1)&63] * qmul;
1063 block[scan_table[i]] =
level;
1067 block[scan_table[i]] =
level;
1148 for (i = 0; i < 6; i++) {
1175 int16_t
block[6][64])
1177 int cbpc, cbpy, i, cbp, pred_x, pred_y, mx, my, dquant;
1179 static int8_t quant_tab[4] = { -1, -2, 1, 2 };
1226 cbp = (cbpc & 3) | (cbpy << 2);
1234 if ((cbpc & 16) == 0) {
1241 s->
mv[0][0][0] = mx;
1242 s->
mv[0][0][1] = my;
1262 s->
mv[0][i][0] = mx;
1263 s->
mv[0][i][1] = my;
1279 s->
mv[0][0][0] = mx;
1280 s->
mv[0][0][1] = my;
1294 s->
mv[0][i][0] = mx;
1295 s->
mv[0][i][1] = my;
1410 s->
last_mv[0][i][0]= s->
mv[0][i][0] = mx;
1411 s->
last_mv[0][i][1]= (s->
mv[0][i][1] = my)*2;
1421 s->
last_mv[1][i][0]= s->
mv[1][i][0] = mx;
1422 s->
last_mv[1][i][1]= (s->
mv[1][i][1] = my)*2;
1463 cbp = (cbpc & 3) | (cbpy << 2);
1476 for (i = 0; i < 6; i++) {
1485 for (i = 0; i < 6; i++) {
1518 int hours, minutes, seconds;
1530 s->
time_base= seconds + 60*(minutes + 60*hours);
1572 int chroma_format=
get_bits(gb, 2);
1646 if (vo_ver_id == 1) {
1693 for(i=0; i<64; i++){
1707 for(i=0; i<64; i++){
1729 for(i=0; i<64; i++){
1757 int estimation_method=
get_bits(gb, 2);
1758 if(estimation_method<2){
1773 if(!
check_marker(gb,
"in complexity estimation part 1")){
1791 if(!
check_marker(gb,
"in complexity estimation part 2")){
1795 if(estimation_method==1){
1815 if(vo_ver_id != 1) {
1834 int h_sampling_factor_n;
1835 int h_sampling_factor_m;
1836 int v_sampling_factor_n;
1837 int v_sampling_factor_m;
1842 h_sampling_factor_n=
get_bits(gb, 5);
1843 h_sampling_factor_m=
get_bits(gb, 5);
1844 v_sampling_factor_n=
get_bits(gb, 5);
1845 v_sampling_factor_m=
get_bits(gb, 5);
1848 if( h_sampling_factor_n==0 || h_sampling_factor_m==0
1849 || v_sampling_factor_n==0 || v_sampling_factor_m==0){
1883 int ver = 0, build = 0, ver2 = 0, ver3 = 0;
1893 e=sscanf(buf,
"DivX%dBuild%d%c", &ver, &build, &last);
1895 e=sscanf(buf,
"DivX%db%d%c", &ver, &build, &last);
1907 e=sscanf(buf,
"FFmpe%*[^b]b%d", &build)+3;
1909 e=sscanf(buf,
"FFmpeg v%d.%d.%d / libavcodec build: %d", &ver, &ver2, &ver3, &build);
1911 e=sscanf(buf,
"Lavc%d.%d.%d", &ver, &ver2, &ver3)+1;
1913 build= (ver<<16) + (ver2<<8) + ver3;
1916 if(strcmp(buf,
"ffmpeg")==0){
1925 e=sscanf(buf,
"XviD%d", &build);
1934 int time_incr, time_increment;
1955 av_log(s->
avctx,
AV_LOG_ERROR,
"hmm, seems the headers are not complete, trying to guess time_increment_bits\n");
2118 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 time:%"PRId64
" tincr:%d\n",
2137 if(load_backward_shape){
2147 av_log(s->
avctx,
AV_LOG_WARNING,
"looks like this file was encoded with (divx4/(old)xvid/opendivx) -> forcing low_delay flag\n");
2171 unsigned startcode,
v;
2194 startcode = ((startcode << 8) | v) & 0xffffffff;
2196 if((startcode&0xFFFFFF00) != 0x100)
2231 if(startcode >= 0x120 && startcode <= 0x12F){
2259 static int done = 0;
2335 "MPEG4 Video Decoder",
2342 "MPEG4 Video VDPAU Decoder",
2369 #if CONFIG_MPEG4_VDPAU_DECODER
2370 AVCodec ff_mpeg4_vdpau_decoder = {
2371 .
name =
"mpeg4_vdpau",