23 #define UNCHECKED_BITSTREAM_READER 1
37 #define SPRITE_TRAJ_VLC_BITS 6
39 #define MB_TYPE_B_VLC_BITS 4
62 int16_t *ac_val, *ac_val1;
74 if(s->
mb_x==0 || s->
qscale == qscale_table[xy] || n==1 || n==3){
90 if(s->
mb_y==0 || s->
qscale == qscale_table[xy] || n==2 || n==3){
135 v|= 0x7F >> (7-(bits_count&7));
148 for(len=0; len<32; len++){
172 int d[4][2]={{0,0}, {0,0}, {0,0}, {0,0}};
173 int sprite_ref[4][2];
174 int virtual_ref[2][2];
205 while((1<<alpha)<w) alpha++;
206 while((1<<beta )<h) beta++;
212 sprite_ref[0][0]= a*vop_ref[0][0] + d[0][0];
213 sprite_ref[0][1]= a*vop_ref[0][1] + d[0][1];
214 sprite_ref[1][0]= a*vop_ref[1][0] + d[0][0] + d[1][0];
215 sprite_ref[1][1]= a*vop_ref[1][1] + d[0][1] + d[1][1];
216 sprite_ref[2][0]= a*vop_ref[2][0] + d[0][0] + d[2][0];
217 sprite_ref[2][1]= a*vop_ref[2][1] + d[0][1] + d[2][1];
219 sprite_ref[0][0]= (a>>1)*(2*vop_ref[0][0] + d[0][0]);
220 sprite_ref[0][1]= (a>>1)*(2*vop_ref[0][1] + d[0][1]);
221 sprite_ref[1][0]= (a>>1)*(2*vop_ref[1][0] + d[0][0] + d[1][0]);
222 sprite_ref[1][1]= (a>>1)*(2*vop_ref[1][1] + d[0][1] + d[1][1]);
223 sprite_ref[2][0]= (a>>1)*(2*vop_ref[2][0] + d[0][0] + d[2][0]);
224 sprite_ref[2][1]= (a>>1)*(2*vop_ref[2][1] + d[0][1] + d[2][1]);
233 virtual_ref[0][0]= 16*(vop_ref[0][0] + w2)
234 +
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);
235 virtual_ref[0][1]= 16*vop_ref[0][1]
236 +
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);
237 virtual_ref[1][0]= 16*vop_ref[0][0]
238 +
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);
239 virtual_ref[1][1]= 16*(vop_ref[0][1] + h2)
240 +
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);
259 s->
sprite_offset[1][0]= ((sprite_ref[0][0]>>1)|(sprite_ref[0][0]&1)) - a*(vop_ref[0][0]/2);
260 s->
sprite_offset[1][1]= ((sprite_ref[0][1]>>1)|(sprite_ref[0][1]&1)) - a*(vop_ref[0][1]/2);
270 + (-r*sprite_ref[0][0] + virtual_ref[0][0])*(-vop_ref[0][0])
271 + ( r*sprite_ref[0][1] - virtual_ref[0][1])*(-vop_ref[0][1])
272 + (1<<(alpha+rho-1));
274 + (-r*sprite_ref[0][1] + virtual_ref[0][1])*(-vop_ref[0][0])
275 + (-r*sprite_ref[0][0] + virtual_ref[0][0])*(-vop_ref[0][1])
276 + (1<<(alpha+rho-1));
277 s->
sprite_offset[1][0]= ( (-r*sprite_ref[0][0] + virtual_ref[0][0])*(-2*vop_ref[0][0] + 1)
278 +( r*sprite_ref[0][1] - virtual_ref[0][1])*(-2*vop_ref[0][1] + 1)
279 +2*w2*r*sprite_ref[0][0]
281 + (1<<(alpha+rho+1)));
282 s->
sprite_offset[1][1]= ( (-r*sprite_ref[0][1] + virtual_ref[0][1])*(-2*vop_ref[0][0] + 1)
283 +(-r*sprite_ref[0][0] + virtual_ref[0][0])*(-2*vop_ref[0][1] + 1)
284 +2*w2*r*sprite_ref[0][1]
286 + (1<<(alpha+rho+1)));
287 s->
sprite_delta[0][0]= (-r*sprite_ref[0][0] + virtual_ref[0][0]);
288 s->
sprite_delta[0][1]= (+r*sprite_ref[0][1] - virtual_ref[0][1]);
289 s->
sprite_delta[1][0]= (-r*sprite_ref[0][1] + virtual_ref[0][1]);
290 s->
sprite_delta[1][1]= (-r*sprite_ref[0][0] + virtual_ref[0][0]);
296 min_ab=
FFMIN(alpha, beta);
299 s->
sprite_offset[0][0]= (sprite_ref[0][0]<<(alpha+beta+rho-min_ab))
300 + (-r*sprite_ref[0][0] + virtual_ref[0][0])*h3*(-vop_ref[0][0])
301 + (-r*sprite_ref[0][0] + virtual_ref[1][0])*w3*(-vop_ref[0][1])
302 + (1<<(alpha+beta+rho-min_ab-1));
303 s->
sprite_offset[0][1]= (sprite_ref[0][1]<<(alpha+beta+rho-min_ab))
304 + (-r*sprite_ref[0][1] + virtual_ref[0][1])*h3*(-vop_ref[0][0])
305 + (-r*sprite_ref[0][1] + virtual_ref[1][1])*w3*(-vop_ref[0][1])
306 + (1<<(alpha+beta+rho-min_ab-1));
307 s->
sprite_offset[1][0]= (-r*sprite_ref[0][0] + virtual_ref[0][0])*h3*(-2*vop_ref[0][0] + 1)
308 + (-r*sprite_ref[0][0] + virtual_ref[1][0])*w3*(-2*vop_ref[0][1] + 1)
309 + 2*w2*h3*r*sprite_ref[0][0]
311 + (1<<(alpha+beta+rho-min_ab+1));
312 s->
sprite_offset[1][1]= (-r*sprite_ref[0][1] + virtual_ref[0][1])*h3*(-2*vop_ref[0][0] + 1)
313 + (-r*sprite_ref[0][1] + virtual_ref[1][1])*w3*(-2*vop_ref[0][1] + 1)
314 + 2*w2*h3*r*sprite_ref[0][1]
316 + (1<<(alpha+beta+rho-min_ab+1));
317 s->
sprite_delta[0][0]= (-r*sprite_ref[0][0] + virtual_ref[0][0])*h3;
318 s->
sprite_delta[0][1]= (-r*sprite_ref[0][0] + virtual_ref[1][0])*w3;
319 s->
sprite_delta[1][0]= (-r*sprite_ref[0][1] + virtual_ref[0][1])*h3;
320 s->
sprite_delta[1][1]= (-r*sprite_ref[0][1] + virtual_ref[1][1])*w3;
366 int header_extension=0, mb_num,
len;
371 for(len=0; len<32; len++){
403 if(header_extension){
409 check_marker(&s->
gb,
"before time_increment in video packed header");
411 check_marker(&s->
gb,
"before vop_coding_type in video packed header");
452 int x,
y, mb_v, sum, dx, dy,
shift;
468 if(n) dy -= 1<<(shift + a + 1);
469 else dx -= 1<<(shift + a + 1);
486 if (sum < -len) sum= -
len;
487 else if (sum >= len) sum= len-1;
506 if (code < 0 || code > 9 ){
518 level =
get_bits(&s->
gb, code-1) + (1<<(code-1));
520 level = -
get_bits(&s->
gb, code-1) - (1<<(code-1));
545 static const int8_t quant_tab[4] = { -1, -2, 1, 2 };
595 if(dc_pred_dir) dir|=1;
599 int mx, my, pred_x, pred_y,
bits;
619 mot_val[0 ]= mot_val[2 ]=
621 mot_val[1 ]= mot_val[3 ]=
644 mot_val[0 ]= mot_val[2 ]=
646 mot_val[1 ]= mot_val[3 ]=
656 if ((cbpc & 16) == 0) {
675 mot_val[0 ]= mot_val[2 ] =
677 mot_val[1 ]= mot_val[3 ]=
710 static const int8_t quant_tab[4] = { -1, -2, 1, 2 };
758 if(dc_pred_dir) dir|=1;
785 if(mb_num >= mb_count)
return 0;
849 int n,
int coded,
int intra,
int rvlc)
890 if (dc_pred_dir == 0)
920 qadd = (s->
qscale - 1) | 1;
958 level= level * qmul + qadd;
971 if (cache&0x80000000) {
972 if (cache&0x40000000) {
999 if(s->error_recognition >= FF_ER_COMPLIANT){
1000 const int abs_level=
FFABS(level);
1002 const int run1= run - rl->
max_run[last][abs_level] - 1;
1003 if(abs_level <= rl->max_level[last][run]){
1007 if(s->error_recognition > FF_ER_COMPLIANT){
1008 if(abs_level <= rl->max_level[last][run]*2){
1012 if(run1 >= 0 && abs_level <= rl->max_level[last][run1]){
1020 if (level>0) level= level * qmul + qadd;
1021 else level= level * qmul - qadd;
1023 if((
unsigned)(level + 2048) > 4095){
1025 if(level > 2560 || level<-2560){
1030 level= level<0 ? -2048 : 2047;
1039 i+= run + rl->
max_run[run>>7][level/qmul] +1;
1048 level = level + rl->
max_level[run>>7][(run-1)&63] * qmul;
1065 block[scan_table[i]] =
level;
1069 block[scan_table[i]] =
level;
1150 for (i = 0; i < 6; i++) {
1177 int16_t
block[6][64])
1179 int cbpc, cbpy, i, cbp, pred_x, pred_y, mx, my, dquant;
1181 static int8_t quant_tab[4] = { -1, -2, 1, 2 };
1228 cbp = (cbpc & 3) | (cbpy << 2);
1236 if ((cbpc & 16) == 0) {
1243 s->
mv[0][0][0] = mx;
1244 s->
mv[0][0][1] = my;
1264 s->
mv[0][i][0] = mx;
1265 s->
mv[0][i][1] = my;
1281 s->
mv[0][0][0] = mx;
1282 s->
mv[0][0][1] = my;
1296 s->
mv[0][i][0] = mx;
1297 s->
mv[0][i][1] = my;
1412 s->
last_mv[0][i][0]= s->
mv[0][i][0] = mx;
1413 s->
last_mv[0][i][1]= (s->
mv[0][i][1] = my)*2;
1423 s->
last_mv[1][i][0]= s->
mv[1][i][0] = mx;
1424 s->
last_mv[1][i][1]= (s->
mv[1][i][1] = my)*2;
1465 cbp = (cbpc & 3) | (cbpy << 2);
1478 for (i = 0; i < 6; i++) {
1487 for (i = 0; i < 6; i++) {
1520 int hours, minutes, seconds;
1532 s->
time_base= seconds + 60*(minutes + 60*hours);
1574 int chroma_format=
get_bits(gb, 2);
1648 if (vo_ver_id == 1) {
1695 for(i=0; i<64; i++){
1709 for(i=0; i<64; i++){
1731 for(i=0; i<64; i++){
1759 int estimation_method=
get_bits(gb, 2);
1760 if(estimation_method<2){
1775 if(!
check_marker(gb,
"in complexity estimation part 1")){
1793 if(!
check_marker(gb,
"in complexity estimation part 2")){
1797 if(estimation_method==1){
1817 if(vo_ver_id != 1) {
1836 int h_sampling_factor_n;
1837 int h_sampling_factor_m;
1838 int v_sampling_factor_n;
1839 int v_sampling_factor_m;
1844 h_sampling_factor_n=
get_bits(gb, 5);
1845 h_sampling_factor_m=
get_bits(gb, 5);
1846 v_sampling_factor_n=
get_bits(gb, 5);
1847 v_sampling_factor_m=
get_bits(gb, 5);
1850 if( h_sampling_factor_n==0 || h_sampling_factor_m==0
1851 || v_sampling_factor_n==0 || v_sampling_factor_m==0){
1885 int ver = 0, build = 0, ver2 = 0, ver3 = 0;
1895 e=sscanf(buf,
"DivX%dBuild%d%c", &ver, &build, &last);
1897 e=sscanf(buf,
"DivX%db%d%c", &ver, &build, &last);
1909 e=sscanf(buf,
"FFmpe%*[^b]b%d", &build)+3;
1911 e=sscanf(buf,
"FFmpeg v%d.%d.%d / libavcodec build: %d", &ver, &ver2, &ver3, &build);
1913 e=sscanf(buf,
"Lavc%d.%d.%d", &ver, &ver2, &ver3)+1;
1915 build= (ver<<16) + (ver2<<8) + ver3;
1918 if(strcmp(buf,
"ffmpeg")==0){
1927 e=sscanf(buf,
"XviD%d", &build);
1936 int time_incr, time_increment;
1957 av_log(s->
avctx,
AV_LOG_ERROR,
"hmm, seems the headers are not complete, trying to guess time_increment_bits\n");
2120 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",
2139 if(load_backward_shape){
2149 av_log(s->
avctx,
AV_LOG_WARNING,
"looks like this file was encoded with (divx4/(old)xvid/opendivx) -> forcing low_delay flag\n");
2173 unsigned startcode,
v;
2196 startcode = ((startcode << 8) | v) & 0xffffffff;
2198 if((startcode&0xFFFFFF00) != 0x100)
2233 if(startcode >= 0x120 && startcode <= 0x12F){
2261 static int done = 0;
2339 "MPEG4 Video Decoder",
2346 "MPEG4 Video VDPAU Decoder",
2373 #if CONFIG_MPEG4_VDPAU_DECODER
2374 AVCodec ff_mpeg4_vdpau_decoder = {
2375 .
name =
"mpeg4_vdpau",