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];
181 if (w <= 0 || h <= 0)
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;
377 int header_extension=0, mb_num,
len;
382 for(len=0; len<32; len++){
414 if(header_extension){
420 check_marker(&s->
gb,
"before time_increment in video packed header");
422 check_marker(&s->
gb,
"before vop_coding_type in video packed header");
464 int x,
y, mb_v, sum, dx, dy,
shift;
480 if(n) dy -= 1<<(shift + a + 1);
481 else dx -= 1<<(shift + a + 1);
498 if (sum < -len) sum= -
len;
499 else if (sum >= len) sum= len-1;
518 if (code < 0 || code > 9 ){
530 level =
get_bits(&s->
gb, code-1) + (1<<(code-1));
532 level = -
get_bits(&s->
gb, code-1) - (1<<(code-1));
557 static const int8_t quant_tab[4] = { -1, -2, 1, 2 };
607 if(dc_pred_dir) dir|=1;
611 int mx, my, pred_x, pred_y,
bits;
631 mot_val[0 ]= mot_val[2 ]=
633 mot_val[1 ]= mot_val[3 ]=
656 mot_val[0 ]= mot_val[2 ]=
658 mot_val[1 ]= mot_val[3 ]=
668 if ((cbpc & 16) == 0) {
687 mot_val[0 ]= mot_val[2 ] =
689 mot_val[1 ]= mot_val[3 ]=
722 static const int8_t quant_tab[4] = { -1, -2, 1, 2 };
770 if(dc_pred_dir) dir|=1;
797 if(mb_num >= mb_count)
return 0;
861 int n,
int coded,
int intra,
int rvlc)
902 if (dc_pred_dir == 0)
932 qadd = (s->
qscale - 1) | 1;
970 level= level * qmul + qadd;
983 if (cache&0x80000000) {
984 if (cache&0x40000000) {
1011 if(s->error_recognition >= FF_ER_COMPLIANT){
1012 const int abs_level=
FFABS(level);
1014 const int run1= run - rl->
max_run[last][abs_level] - 1;
1015 if(abs_level <= rl->max_level[last][run]){
1019 if(s->error_recognition > FF_ER_COMPLIANT){
1020 if(abs_level <= rl->max_level[last][run]*2){
1024 if(run1 >= 0 && abs_level <= rl->max_level[last][run1]){
1032 if (level>0) level= level * qmul + qadd;
1033 else level= level * qmul - qadd;
1035 if((
unsigned)(level + 2048) > 4095){
1037 if(level > 2560 || level<-2560){
1042 level= level<0 ? -2048 : 2047;
1051 i+= run + rl->
max_run[run>>7][level/qmul] +1;
1060 level = level + rl->
max_level[run>>7][(run-1)&63] * qmul;
1077 block[scan_table[i]] =
level;
1081 block[scan_table[i]] =
level;
1162 for (i = 0; i < 6; i++) {
1189 int16_t
block[6][64])
1191 int cbpc, cbpy, i, cbp, pred_x, pred_y, mx, my, dquant;
1193 static int8_t quant_tab[4] = { -1, -2, 1, 2 };
1240 cbp = (cbpc & 3) | (cbpy << 2);
1248 if ((cbpc & 16) == 0) {
1255 s->
mv[0][0][0] = mx;
1256 s->
mv[0][0][1] = my;
1276 s->
mv[0][i][0] = mx;
1277 s->
mv[0][i][1] = my;
1293 s->
mv[0][0][0] = mx;
1294 s->
mv[0][0][1] = my;
1308 s->
mv[0][i][0] = mx;
1309 s->
mv[0][i][1] = my;
1424 s->
last_mv[0][i][0]= s->
mv[0][i][0] = mx;
1425 s->
last_mv[0][i][1]= (s->
mv[0][i][1] = my)*2;
1435 s->
last_mv[1][i][0]= s->
mv[1][i][0] = mx;
1436 s->
last_mv[1][i][1]= (s->
mv[1][i][1] = my)*2;
1477 cbp = (cbpc & 3) | (cbpy << 2);
1490 for (i = 0; i < 6; i++) {
1499 for (i = 0; i < 6; i++) {
1532 int hours, minutes, seconds;
1544 s->
time_base= seconds + 60*(minutes + 60*hours);
1586 int chroma_format=
get_bits(gb, 2);
1660 if (vo_ver_id == 1) {
1707 for(i=0; i<64; i++){
1721 for(i=0; i<64; i++){
1743 for(i=0; i<64; i++){
1771 int estimation_method=
get_bits(gb, 2);
1772 if(estimation_method<2){
1787 if(!
check_marker(gb,
"in complexity estimation part 1")){
1805 if(!
check_marker(gb,
"in complexity estimation part 2")){
1809 if(estimation_method==1){
1829 if(vo_ver_id != 1) {
1848 int h_sampling_factor_n;
1849 int h_sampling_factor_m;
1850 int v_sampling_factor_n;
1851 int v_sampling_factor_m;
1856 h_sampling_factor_n=
get_bits(gb, 5);
1857 h_sampling_factor_m=
get_bits(gb, 5);
1858 v_sampling_factor_n=
get_bits(gb, 5);
1859 v_sampling_factor_m=
get_bits(gb, 5);
1862 if( h_sampling_factor_n==0 || h_sampling_factor_m==0
1863 || v_sampling_factor_n==0 || v_sampling_factor_m==0){
1897 int ver = 0, build = 0, ver2 = 0, ver3 = 0;
1907 e=sscanf(buf,
"DivX%dBuild%d%c", &ver, &build, &last);
1909 e=sscanf(buf,
"DivX%db%d%c", &ver, &build, &last);
1916 "wasteful way to store B-frames ('packed B-frames'). "
1917 "Consider using a tool like VirtualDub or avidemux to fix it.\n");
1923 e=sscanf(buf,
"FFmpe%*[^b]b%d", &build)+3;
1925 e=sscanf(buf,
"FFmpeg v%d.%d.%d / libavcodec build: %d", &ver, &ver2, &ver3, &build);
1927 e=sscanf(buf,
"Lavc%d.%d.%d", &ver, &ver2, &ver3)+1;
1929 build= (ver<<16) + (ver2<<8) + ver3;
1932 if(strcmp(buf,
"ffmpeg")==0){
1941 e=sscanf(buf,
"XviD%d", &build);
1950 int time_incr, time_increment;
1971 av_log(s->
avctx,
AV_LOG_ERROR,
"hmm, seems the headers are not complete, trying to guess time_increment_bits\n");
2137 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",
2156 if(load_backward_shape){
2166 av_log(s->
avctx,
AV_LOG_WARNING,
"looks like this file was encoded with (divx4/(old)xvid/opendivx) -> forcing low_delay flag\n");
2190 unsigned startcode,
v;
2213 startcode = ((startcode << 8) | v) & 0xffffffff;
2215 if((startcode&0xFFFFFF00) != 0x100)
2250 if(startcode >= 0x120 && startcode <= 0x12F){
2278 static int done = 0;
2356 "MPEG4 Video Decoder",
2363 "MPEG4 Video VDPAU Decoder",
2390 #if CONFIG_MPEG4_VDPAU_DECODER
2391 AVCodec ff_mpeg4_vdpau_decoder = {
2392 .
name =
"mpeg4_vdpau",
2401 CODEC_CAP_HWACCEL_VDPAU,