32 #define SPRITE_TRAJ_VLC_BITS 6
34 #define MB_TYPE_B_VLC_BITS 4
57 int16_t *ac_val, *ac_val1;
69 if(s->
mb_x==0 || s->
qscale == qscale_table[xy] || n==1 || n==3){
85 if(s->
mb_y==0 || s->
qscale == qscale_table[xy] || n==2 || n==3){
130 v|= 0x7F >> (7-(bits_count&7));
142 for(len=0; len<32; len++){
162 int d[4][2]={{0,0}, {0,0}, {0,0}, {0,0}};
163 int sprite_ref[4][2];
164 int virtual_ref[2][2];
171 if (w <= 0 || h <= 0)
195 while((1<<alpha)<w) alpha++;
196 while((1<<beta )<h) beta++;
202 sprite_ref[0][0]= a*vop_ref[0][0] + d[0][0];
203 sprite_ref[0][1]= a*vop_ref[0][1] + d[0][1];
204 sprite_ref[1][0]= a*vop_ref[1][0] + d[0][0] + d[1][0];
205 sprite_ref[1][1]= a*vop_ref[1][1] + d[0][1] + d[1][1];
206 sprite_ref[2][0]= a*vop_ref[2][0] + d[0][0] + d[2][0];
207 sprite_ref[2][1]= a*vop_ref[2][1] + d[0][1] + d[2][1];
209 sprite_ref[0][0]= (a>>1)*(2*vop_ref[0][0] + d[0][0]);
210 sprite_ref[0][1]= (a>>1)*(2*vop_ref[0][1] + d[0][1]);
211 sprite_ref[1][0]= (a>>1)*(2*vop_ref[1][0] + d[0][0] + d[1][0]);
212 sprite_ref[1][1]= (a>>1)*(2*vop_ref[1][1] + d[0][1] + d[1][1]);
213 sprite_ref[2][0]= (a>>1)*(2*vop_ref[2][0] + d[0][0] + d[2][0]);
214 sprite_ref[2][1]= (a>>1)*(2*vop_ref[2][1] + d[0][1] + d[2][1]);
223 virtual_ref[0][0]= 16*(vop_ref[0][0] + w2)
224 +
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);
225 virtual_ref[0][1]= 16*vop_ref[0][1]
226 +
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);
227 virtual_ref[1][0]= 16*vop_ref[0][0]
228 + 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);
229 virtual_ref[1][1]= 16*(vop_ref[0][1] + h2)
230 + 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);
249 s->
sprite_offset[1][0]= ((sprite_ref[0][0]>>1)|(sprite_ref[0][0]&1)) - a*(vop_ref[0][0]/2);
250 s->
sprite_offset[1][1]= ((sprite_ref[0][1]>>1)|(sprite_ref[0][1]&1)) - a*(vop_ref[0][1]/2);
260 + (-r*sprite_ref[0][0] + virtual_ref[0][0])*(-vop_ref[0][0])
261 + ( r*sprite_ref[0][1] - virtual_ref[0][1])*(-vop_ref[0][1])
262 + (1<<(alpha+rho-1));
264 + (-r*sprite_ref[0][1] + virtual_ref[0][1])*(-vop_ref[0][0])
265 + (-r*sprite_ref[0][0] + virtual_ref[0][0])*(-vop_ref[0][1])
266 + (1<<(alpha+rho-1));
267 s->
sprite_offset[1][0]= ( (-r*sprite_ref[0][0] + virtual_ref[0][0])*(-2*vop_ref[0][0] + 1)
268 +( r*sprite_ref[0][1] - virtual_ref[0][1])*(-2*vop_ref[0][1] + 1)
269 +2*w2*r*sprite_ref[0][0]
271 + (1<<(alpha+rho+1)));
272 s->
sprite_offset[1][1]= ( (-r*sprite_ref[0][1] + virtual_ref[0][1])*(-2*vop_ref[0][0] + 1)
273 +(-r*sprite_ref[0][0] + virtual_ref[0][0])*(-2*vop_ref[0][1] + 1)
274 +2*w2*r*sprite_ref[0][1]
276 + (1<<(alpha+rho+1)));
277 s->
sprite_delta[0][0]= (-r*sprite_ref[0][0] + virtual_ref[0][0]);
278 s->
sprite_delta[0][1]= (+r*sprite_ref[0][1] - virtual_ref[0][1]);
279 s->
sprite_delta[1][0]= (-r*sprite_ref[0][1] + virtual_ref[0][1]);
280 s->
sprite_delta[1][1]= (-r*sprite_ref[0][0] + virtual_ref[0][0]);
286 min_ab=
FFMIN(alpha, beta);
289 s->
sprite_offset[0][0]= (sprite_ref[0][0]<<(alpha+beta+rho-min_ab))
290 + (-r*sprite_ref[0][0] + virtual_ref[0][0])*h3*(-vop_ref[0][0])
291 + (-r*sprite_ref[0][0] + virtual_ref[1][0])*w3*(-vop_ref[0][1])
292 + (1<<(alpha+beta+rho-min_ab-1));
293 s->
sprite_offset[0][1]= (sprite_ref[0][1]<<(alpha+beta+rho-min_ab))
294 + (-r*sprite_ref[0][1] + virtual_ref[0][1])*h3*(-vop_ref[0][0])
295 + (-r*sprite_ref[0][1] + virtual_ref[1][1])*w3*(-vop_ref[0][1])
296 + (1<<(alpha+beta+rho-min_ab-1));
297 s->
sprite_offset[1][0]= (-r*sprite_ref[0][0] + virtual_ref[0][0])*h3*(-2*vop_ref[0][0] + 1)
298 + (-r*sprite_ref[0][0] + virtual_ref[1][0])*w3*(-2*vop_ref[0][1] + 1)
299 + 2*w2*h3*r*sprite_ref[0][0]
301 + (1<<(alpha+beta+rho-min_ab+1));
302 s->
sprite_offset[1][1]= (-r*sprite_ref[0][1] + virtual_ref[0][1])*h3*(-2*vop_ref[0][0] + 1)
303 + (-r*sprite_ref[0][1] + virtual_ref[1][1])*w3*(-2*vop_ref[0][1] + 1)
304 + 2*w2*h3*r*sprite_ref[0][1]
306 + (1<<(alpha+beta+rho-min_ab+1));
307 s->
sprite_delta[0][0]= (-r*sprite_ref[0][0] + virtual_ref[0][0])*h3;
308 s->
sprite_delta[0][1]= (-r*sprite_ref[0][0] + virtual_ref[1][0])*w3;
309 s->
sprite_delta[1][0]= (-r*sprite_ref[0][1] + virtual_ref[0][1])*h3;
310 s->
sprite_delta[1][1]= (-r*sprite_ref[0][1] + virtual_ref[1][1])*w3;
356 int header_extension=0, mb_num,
len;
361 for(len=0; len<32; len++){
381 int mb_x = 0, mb_y = 0;
387 if (++mb_x == s->
mb_width) mb_x = 0;
389 if(mb_num >= s->
mb_num)
return -1;
404 if(header_extension){
410 check_marker(&s->
gb,
"before time_increment in video packed header");
412 check_marker(&s->
gb,
"before vop_coding_type in video packed header");
453 int x, y, mb_v, sum, dx, dy, shift;
469 if(n) dy -= 1<<(shift + a + 1);
470 else dx -= 1<<(shift + a + 1);
487 if (sum < -len) sum= -
len;
488 else if (sum >= len) sum= len-1;
507 if (code < 0 || code > 9 ){
519 level =
get_bits(&s->
gb, code-1) + (1<<(code-1));
521 level = -
get_bits(&s->
gb, code-1) - (1<<(code-1));
546 static const int8_t quant_tab[4] = { -1, -2, 1, 2 };
596 if(dc_pred_dir) dir|=1;
600 int mx, my, pred_x, pred_y,
bits;
620 mot_val[0 ]= mot_val[2 ]=
622 mot_val[1 ]= mot_val[3 ]=
645 mot_val[0 ]= mot_val[2 ]=
647 mot_val[1 ]= mot_val[3 ]=
657 if ((cbpc & 16) == 0) {
676 mot_val[0 ]= mot_val[2 ] =
678 mot_val[1 ]= mot_val[3 ]=
711 static const int8_t quant_tab[4] = { -1, -2, 1, 2 };
759 if(dc_pred_dir) dir|=1;
786 if(mb_num >= mb_count)
return 0;
850 int n,
int coded,
int intra,
int rvlc)
891 if (dc_pred_dir == 0)
921 qadd = (s->
qscale - 1) | 1;
959 level= level * qmul + qadd;
972 if (cache&0x80000000) {
973 if (cache&0x40000000) {
999 if (level>0) level= level * qmul + qadd;
1000 else level= level * qmul - qadd;
1002 if((
unsigned)(level + 2048) > 4095){
1004 if(level > 2560 || level<-2560){
1009 level= level<0 ? -2048 : 2047;
1018 i+= run + rl->
max_run[run>>7][level/qmul] +1;
1027 level = level + rl->
max_level[run>>7][(run-1)&63] * qmul;
1044 block[scan_table[i]] =
level;
1048 block[scan_table[i]] =
level;
1129 for (i = 0; i < 6; i++) {
1158 int cbpc, cbpy, i, cbp, pred_x, pred_y, mx, my, dquant;
1160 static int8_t quant_tab[4] = { -1, -2, 1, 2 };
1207 cbp = (cbpc & 3) | (cbpy << 2);
1215 if ((cbpc & 16) == 0) {
1222 s->
mv[0][0][0] = mx;
1223 s->
mv[0][0][1] = my;
1243 s->
mv[0][i][0] = mx;
1244 s->
mv[0][i][1] = my;
1260 s->
mv[0][0][0] = mx;
1261 s->
mv[0][0][1] = my;
1275 s->
mv[0][i][0] = mx;
1276 s->
mv[0][i][1] = my;
1391 s->
last_mv[0][i][0]= s->
mv[0][i][0] = mx;
1392 s->
last_mv[0][i][1]= (s->
mv[0][i][1] = my)*2;
1402 s->
last_mv[1][i][0]= s->
mv[1][i][0] = mx;
1403 s->
last_mv[1][i][1]= (s->
mv[1][i][1] = my)*2;
1444 cbp = (cbpc & 3) | (cbpy << 2);
1457 for (i = 0; i < 6; i++) {
1466 for (i = 0; i < 6; i++) {
1494 int hours, minutes, seconds;
1497 if (time_code & 0x40) {
1498 hours = time_code >> 13;
1499 minutes = time_code >> 7 & 0x3f;
1500 seconds = time_code & 0x3f;
1501 s->
time_base = seconds + 60*(minutes + 60*hours);
1511 int profile_and_level_indication;
1513 profile_and_level_indication =
get_bits(gb, 8);
1515 s->
avctx->
profile = (profile_and_level_indication & 0xf0) >> 4;
1516 s->
avctx->
level = (profile_and_level_indication & 0x0f);
1547 int chroma_format=
get_bits(gb, 2);
1621 if (vo_ver_id == 1) {
1665 for(i=0; i<64; i++){
1679 for(i=0; i<64; i++){
1701 for(i=0; i<64; i++){
1729 int estimation_method=
get_bits(gb, 2);
1730 if(estimation_method<2){
1745 if(!
check_marker(gb,
"in complexity estimation part 1")){
1763 if(!
check_marker(gb,
"in complexity estimation part 2")){
1767 if(estimation_method==1){
1787 if(vo_ver_id != 1) {
1806 int h_sampling_factor_n;
1807 int h_sampling_factor_m;
1808 int v_sampling_factor_n;
1809 int v_sampling_factor_m;
1814 h_sampling_factor_n=
get_bits(gb, 5);
1815 h_sampling_factor_m=
get_bits(gb, 5);
1816 v_sampling_factor_n=
get_bits(gb, 5);
1817 v_sampling_factor_m=
get_bits(gb, 5);
1820 if( h_sampling_factor_n==0 || h_sampling_factor_m==0
1821 || v_sampling_factor_n==0 || v_sampling_factor_m==0){
1843 int ver = 0, build = 0, ver2 = 0, ver3 = 0;
1853 e=sscanf(buf,
"DivX%dBuild%d%c", &ver, &build, &last);
1855 e=sscanf(buf,
"DivX%db%d%c", &ver, &build, &last);
1867 e=sscanf(buf,
"FFmpe%*[^b]b%d", &build)+3;
1869 e=sscanf(buf,
"FFmpeg v%d.%d.%d / libavcodec build: %d", &ver, &ver2, &ver3, &build);
1871 e=sscanf(buf,
"Lavc%d.%d.%d", &ver, &ver2, &ver3)+1;
1873 build= (ver<<16) + (ver2<<8) + ver3;
1876 if(strcmp(buf,
"ffmpeg")==0){
1885 e=sscanf(buf,
"XviD%d", &build);
1894 int time_incr, time_increment;
1915 av_log(s->
avctx,
AV_LOG_ERROR,
"hmm, seems the headers are not complete, trying to guess time_increment_bits\n");
2065 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",
2080 if(load_backward_shape){
2090 av_log(s->
avctx,
AV_LOG_WARNING,
"looks like this file was encoded with (divx4/(old)xvid/opendivx) -> forcing low_delay flag\n");
2114 unsigned startcode, v;
2137 startcode = ((startcode << 8) | v) & 0xffffffff;
2139 if((startcode&0xFFFFFF00) != 0x100)
2174 if(startcode >= 0x120 && startcode <= 0x12F){
2205 static int done = 0;
2285 #if CONFIG_MPEG4_VDPAU_DECODER
2286 AVCodec ff_mpeg4_vdpau_decoder = {
2287 .
name =
"mpeg4_vdpau",
2294 .capabilities = CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY |
2295 CODEC_CAP_HWACCEL_VDPAU,