32 #define SPRITE_TRAJ_VLC_BITS 6
34 #define MB_TYPE_B_VLC_BITS 4
84 int16_t *ac_val, *ac_val1;
96 if(s->
mb_x==0 || s->
qscale == qscale_table[xy] || n==1 || n==3){
112 if(s->
mb_y==0 || s->
qscale == qscale_table[xy] || n==2 || n==3){
157 v|= 0x7F >> (7-(bits_count&7));
169 for(len=0; len<32; len++){
189 int d[4][2]={{0,0}, {0,0}, {0,0}, {0,0}};
190 int sprite_ref[4][2];
191 int virtual_ref[2][2];
198 if (w <= 0 || h <= 0)
222 while((1<<alpha)<w) alpha++;
223 while((1<<beta )<h) beta++;
229 sprite_ref[0][0]= a*vop_ref[0][0] + d[0][0];
230 sprite_ref[0][1]= a*vop_ref[0][1] + d[0][1];
231 sprite_ref[1][0]= a*vop_ref[1][0] + d[0][0] + d[1][0];
232 sprite_ref[1][1]= a*vop_ref[1][1] + d[0][1] + d[1][1];
233 sprite_ref[2][0]= a*vop_ref[2][0] + d[0][0] + d[2][0];
234 sprite_ref[2][1]= a*vop_ref[2][1] + d[0][1] + d[2][1];
236 sprite_ref[0][0]= (a>>1)*(2*vop_ref[0][0] + d[0][0]);
237 sprite_ref[0][1]= (a>>1)*(2*vop_ref[0][1] + d[0][1]);
238 sprite_ref[1][0]= (a>>1)*(2*vop_ref[1][0] + d[0][0] + d[1][0]);
239 sprite_ref[1][1]= (a>>1)*(2*vop_ref[1][1] + d[0][1] + d[1][1]);
240 sprite_ref[2][0]= (a>>1)*(2*vop_ref[2][0] + d[0][0] + d[2][0]);
241 sprite_ref[2][1]= (a>>1)*(2*vop_ref[2][1] + d[0][1] + d[2][1]);
250 virtual_ref[0][0]= 16*(vop_ref[0][0] + w2)
251 +
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);
252 virtual_ref[0][1]= 16*vop_ref[0][1]
253 +
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);
254 virtual_ref[1][0]= 16*vop_ref[0][0]
255 + 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);
256 virtual_ref[1][1]= 16*(vop_ref[0][1] + h2)
257 + 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);
276 s->
sprite_offset[1][0]= ((sprite_ref[0][0]>>1)|(sprite_ref[0][0]&1)) - a*(vop_ref[0][0]/2);
277 s->
sprite_offset[1][1]= ((sprite_ref[0][1]>>1)|(sprite_ref[0][1]&1)) - a*(vop_ref[0][1]/2);
287 + (-r*sprite_ref[0][0] + virtual_ref[0][0])*(-vop_ref[0][0])
288 + ( r*sprite_ref[0][1] - virtual_ref[0][1])*(-vop_ref[0][1])
289 + (1<<(alpha+rho-1));
291 + (-r*sprite_ref[0][1] + virtual_ref[0][1])*(-vop_ref[0][0])
292 + (-r*sprite_ref[0][0] + virtual_ref[0][0])*(-vop_ref[0][1])
293 + (1<<(alpha+rho-1));
294 s->
sprite_offset[1][0]= ( (-r*sprite_ref[0][0] + virtual_ref[0][0])*(-2*vop_ref[0][0] + 1)
295 +( r*sprite_ref[0][1] - virtual_ref[0][1])*(-2*vop_ref[0][1] + 1)
296 +2*w2*r*sprite_ref[0][0]
298 + (1<<(alpha+rho+1)));
299 s->
sprite_offset[1][1]= ( (-r*sprite_ref[0][1] + virtual_ref[0][1])*(-2*vop_ref[0][0] + 1)
300 +(-r*sprite_ref[0][0] + virtual_ref[0][0])*(-2*vop_ref[0][1] + 1)
301 +2*w2*r*sprite_ref[0][1]
303 + (1<<(alpha+rho+1)));
304 s->
sprite_delta[0][0]= (-r*sprite_ref[0][0] + virtual_ref[0][0]);
305 s->
sprite_delta[0][1]= (+r*sprite_ref[0][1] - virtual_ref[0][1]);
306 s->
sprite_delta[1][0]= (-r*sprite_ref[0][1] + virtual_ref[0][1]);
307 s->
sprite_delta[1][1]= (-r*sprite_ref[0][0] + virtual_ref[0][0]);
313 min_ab=
FFMIN(alpha, beta);
316 s->
sprite_offset[0][0]= (sprite_ref[0][0]<<(alpha+beta+rho-min_ab))
317 + (-r*sprite_ref[0][0] + virtual_ref[0][0])*h3*(-vop_ref[0][0])
318 + (-r*sprite_ref[0][0] + virtual_ref[1][0])*w3*(-vop_ref[0][1])
319 + (1<<(alpha+beta+rho-min_ab-1));
320 s->
sprite_offset[0][1]= (sprite_ref[0][1]<<(alpha+beta+rho-min_ab))
321 + (-r*sprite_ref[0][1] + virtual_ref[0][1])*h3*(-vop_ref[0][0])
322 + (-r*sprite_ref[0][1] + virtual_ref[1][1])*w3*(-vop_ref[0][1])
323 + (1<<(alpha+beta+rho-min_ab-1));
324 s->
sprite_offset[1][0]= (-r*sprite_ref[0][0] + virtual_ref[0][0])*h3*(-2*vop_ref[0][0] + 1)
325 + (-r*sprite_ref[0][0] + virtual_ref[1][0])*w3*(-2*vop_ref[0][1] + 1)
326 + 2*w2*h3*r*sprite_ref[0][0]
328 + (1<<(alpha+beta+rho-min_ab+1));
329 s->
sprite_offset[1][1]= (-r*sprite_ref[0][1] + virtual_ref[0][1])*h3*(-2*vop_ref[0][0] + 1)
330 + (-r*sprite_ref[0][1] + virtual_ref[1][1])*w3*(-2*vop_ref[0][1] + 1)
331 + 2*w2*h3*r*sprite_ref[0][1]
333 + (1<<(alpha+beta+rho-min_ab+1));
334 s->
sprite_delta[0][0]= (-r*sprite_ref[0][0] + virtual_ref[0][0])*h3;
335 s->
sprite_delta[0][1]= (-r*sprite_ref[0][0] + virtual_ref[1][0])*w3;
336 s->
sprite_delta[1][0]= (-r*sprite_ref[0][1] + virtual_ref[0][1])*h3;
337 s->
sprite_delta[1][1]= (-r*sprite_ref[0][1] + virtual_ref[1][1])*w3;
383 int header_extension=0, mb_num,
len;
388 for(len=0; len<32; len++){
408 int mb_x = 0, mb_y = 0;
414 if (++mb_x == s->
mb_width) mb_x = 0;
416 if(mb_num >= s->
mb_num)
return -1;
431 if(header_extension){
437 check_marker(&s->
gb,
"before time_increment in video packed header");
439 check_marker(&s->
gb,
"before vop_coding_type in video packed header");
480 int x, y, mb_v, sum, dx, dy, shift;
496 if(n) dy -= 1<<(shift + a + 1);
497 else dx -= 1<<(shift + a + 1);
514 if (sum < -len) sum= -
len;
515 else if (sum >= len) sum= len-1;
534 if (code < 0 || code > 9 ){
546 level =
get_bits(&s->
gb, code-1) + (1<<(code-1));
548 level = -
get_bits(&s->
gb, code-1) - (1<<(code-1));
573 static const int8_t quant_tab[4] = { -1, -2, 1, 2 };
623 if(dc_pred_dir) dir|=1;
627 int mx, my, pred_x, pred_y,
bits;
647 mot_val[0 ]= mot_val[2 ]=
649 mot_val[1 ]= mot_val[3 ]=
672 mot_val[0 ]= mot_val[2 ]=
674 mot_val[1 ]= mot_val[3 ]=
684 if ((cbpc & 16) == 0) {
703 mot_val[0 ]= mot_val[2 ] =
705 mot_val[1 ]= mot_val[3 ]=
738 static const int8_t quant_tab[4] = { -1, -2, 1, 2 };
786 if(dc_pred_dir) dir|=1;
813 if(mb_num >= mb_count)
return 0;
877 int n,
int coded,
int intra,
int rvlc)
918 if (dc_pred_dir == 0)
948 qadd = (s->
qscale - 1) | 1;
986 level= level * qmul + qadd;
999 if (cache&0x80000000) {
1000 if (cache&0x40000000) {
1026 if (level>0) level= level * qmul + qadd;
1027 else level= level * qmul - qadd;
1029 if((
unsigned)(level + 2048) > 4095){
1031 if(level > 2560 || level<-2560){
1036 level= level<0 ? -2048 : 2047;
1045 i+= run + rl->
max_run[run>>7][level/qmul] +1;
1054 level = level + rl->
max_level[run>>7][(run-1)&63] * qmul;
1071 block[scan_table[i]] =
level;
1075 block[scan_table[i]] =
level;
1156 for (i = 0; i < 6; i++) {
1185 int cbpc, cbpy, i, cbp, pred_x, pred_y, mx, my, dquant;
1187 static int8_t quant_tab[4] = { -1, -2, 1, 2 };
1234 cbp = (cbpc & 3) | (cbpy << 2);
1242 if ((cbpc & 16) == 0) {
1249 s->
mv[0][0][0] = mx;
1250 s->
mv[0][0][1] = my;
1270 s->
mv[0][i][0] = mx;
1271 s->
mv[0][i][1] = my;
1287 s->
mv[0][0][0] = mx;
1288 s->
mv[0][0][1] = my;
1302 s->
mv[0][i][0] = mx;
1303 s->
mv[0][i][1] = my;
1418 s->
last_mv[0][i][0]= s->
mv[0][i][0] = mx;
1419 s->
last_mv[0][i][1]= (s->
mv[0][i][1] = my)*2;
1429 s->
last_mv[1][i][0]= s->
mv[1][i][0] = mx;
1430 s->
last_mv[1][i][1]= (s->
mv[1][i][1] = my)*2;
1471 cbp = (cbpc & 3) | (cbpy << 2);
1484 for (i = 0; i < 6; i++) {
1493 for (i = 0; i < 6; i++) {
1521 int hours, minutes, seconds;
1524 if (time_code & 0x40) {
1525 hours = time_code >> 13;
1526 minutes = time_code >> 7 & 0x3f;
1527 seconds = time_code & 0x3f;
1528 s->
time_base = seconds + 60*(minutes + 60*hours);
1538 int profile_and_level_indication;
1540 profile_and_level_indication =
get_bits(gb, 8);
1542 s->
avctx->
profile = (profile_and_level_indication & 0xf0) >> 4;
1543 s->
avctx->
level = (profile_and_level_indication & 0x0f);
1574 int chroma_format=
get_bits(gb, 2);
1648 if (vo_ver_id == 1) {
1692 for(i=0; i<64; i++){
1706 for(i=0; i<64; i++){
1728 for(i=0; i<64; i++){
1756 int estimation_method=
get_bits(gb, 2);
1757 if(estimation_method<2){
1772 if(!
check_marker(gb,
"in complexity estimation part 1")){
1790 if(!
check_marker(gb,
"in complexity estimation part 2")){
1794 if(estimation_method==1){
1814 if(vo_ver_id != 1) {
1833 int h_sampling_factor_n;
1834 int h_sampling_factor_m;
1835 int v_sampling_factor_n;
1836 int v_sampling_factor_m;
1841 h_sampling_factor_n=
get_bits(gb, 5);
1842 h_sampling_factor_m=
get_bits(gb, 5);
1843 v_sampling_factor_n=
get_bits(gb, 5);
1844 v_sampling_factor_m=
get_bits(gb, 5);
1847 if( h_sampling_factor_n==0 || h_sampling_factor_m==0
1848 || v_sampling_factor_n==0 || v_sampling_factor_m==0){
1870 int ver = 0, build = 0, ver2 = 0, ver3 = 0;
1880 e=sscanf(buf,
"DivX%dBuild%d%c", &ver, &build, &last);
1882 e=sscanf(buf,
"DivX%db%d%c", &ver, &build, &last);
1894 e=sscanf(buf,
"FFmpe%*[^b]b%d", &build)+3;
1896 e=sscanf(buf,
"FFmpeg v%d.%d.%d / libavcodec build: %d", &ver, &ver2, &ver3, &build);
1898 e=sscanf(buf,
"Lavc%d.%d.%d", &ver, &ver2, &ver3)+1;
1900 build= (ver<<16) + (ver2<<8) + ver3;
1903 if(strcmp(buf,
"ffmpeg")==0){
1912 e=sscanf(buf,
"XviD%d", &build);
1921 int time_incr, time_increment;
1942 av_log(s->
avctx,
AV_LOG_ERROR,
"hmm, seems the headers are not complete, trying to guess time_increment_bits\n");
2092 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",
2107 if(load_backward_shape){
2117 av_log(s->
avctx,
AV_LOG_WARNING,
"looks like this file was encoded with (divx4/(old)xvid/opendivx) -> forcing low_delay flag\n");
2141 unsigned startcode, v;
2164 startcode = ((startcode << 8) | v) & 0xffffffff;
2166 if((startcode&0xFFFFFF00) != 0x100)
2201 if(startcode >= 0x120 && startcode <= 0x12F){
2290 #if CONFIG_MPEG4_VDPAU_DECODER
2291 AVCodec ff_mpeg4_vdpau_decoder = {
2292 .
name =
"mpeg4_vdpau",
2299 .capabilities = CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY |
2300 CODEC_CAP_HWACCEL_VDPAU,