00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "mpegvideo.h"
00024 #include "mpeg4video.h"
00025 #include "h263.h"
00026 #include "thread.h"
00027
00028
00029
00030
00031
00032 #define SPRITE_TRAJ_VLC_BITS 6
00033 #define DC_VLC_BITS 9
00034 #define MB_TYPE_B_VLC_BITS 4
00035
00036
00037 static VLC dc_lum, dc_chrom;
00038 static VLC sprite_trajectory;
00039 static VLC mb_type_b_vlc;
00040
00041 static const int mb_type_b_map[4]= {
00042 MB_TYPE_DIRECT2 | MB_TYPE_L0L1,
00043 MB_TYPE_L0L1 | MB_TYPE_16x16,
00044 MB_TYPE_L1 | MB_TYPE_16x16,
00045 MB_TYPE_L0 | MB_TYPE_16x16,
00046 };
00047
00053 void mpeg4_pred_ac(MpegEncContext * s, DCTELEM *block, int n,
00054 int dir)
00055 {
00056 int i;
00057 int16_t *ac_val, *ac_val1;
00058 int8_t * const qscale_table= s->current_picture.qscale_table;
00059
00060
00061 ac_val = s->ac_val[0][0] + s->block_index[n] * 16;
00062 ac_val1 = ac_val;
00063 if (s->ac_pred) {
00064 if (dir == 0) {
00065 const int xy= s->mb_x-1 + s->mb_y*s->mb_stride;
00066
00067 ac_val -= 16;
00068
00069 if(s->mb_x==0 || s->qscale == qscale_table[xy] || n==1 || n==3){
00070
00071 for(i=1;i<8;i++) {
00072 block[s->dsp.idct_permutation[i<<3]] += ac_val[i];
00073 }
00074 }else{
00075
00076 for(i=1;i<8;i++) {
00077 block[s->dsp.idct_permutation[i<<3]] += ROUNDED_DIV(ac_val[i]*qscale_table[xy], s->qscale);
00078 }
00079 }
00080 } else {
00081 const int xy= s->mb_x + s->mb_y*s->mb_stride - s->mb_stride;
00082
00083 ac_val -= 16 * s->block_wrap[n];
00084
00085 if(s->mb_y==0 || s->qscale == qscale_table[xy] || n==2 || n==3){
00086
00087 for(i=1;i<8;i++) {
00088 block[s->dsp.idct_permutation[i]] += ac_val[i + 8];
00089 }
00090 }else{
00091
00092 for(i=1;i<8;i++) {
00093 block[s->dsp.idct_permutation[i]] += ROUNDED_DIV(ac_val[i + 8]*qscale_table[xy], s->qscale);
00094 }
00095 }
00096 }
00097 }
00098
00099 for(i=1;i<8;i++)
00100 ac_val1[i ] = block[s->dsp.idct_permutation[i<<3]];
00101
00102
00103 for(i=1;i<8;i++)
00104 ac_val1[8 + i] = block[s->dsp.idct_permutation[i ]];
00105
00106 }
00107
00112 static inline int mpeg4_is_resync(MpegEncContext *s){
00113 int bits_count= get_bits_count(&s->gb);
00114 int v= show_bits(&s->gb, 16);
00115
00116 if(s->workaround_bugs&FF_BUG_NO_PADDING){
00117 return 0;
00118 }
00119
00120 while(v<=0xFF){
00121 if(s->pict_type==AV_PICTURE_TYPE_B || (v>>(8-s->pict_type)!=1) || s->partitioned_frame)
00122 break;
00123 skip_bits(&s->gb, 8+s->pict_type);
00124 bits_count+= 8+s->pict_type;
00125 v= show_bits(&s->gb, 16);
00126 }
00127
00128 if(bits_count + 8 >= s->gb.size_in_bits){
00129 v>>=8;
00130 v|= 0x7F >> (7-(bits_count&7));
00131
00132 if(v==0x7F)
00133 return 1;
00134 }else{
00135 if(v == ff_mpeg4_resync_prefix[bits_count&7]){
00136 int len;
00137 GetBitContext gb= s->gb;
00138
00139 skip_bits(&s->gb, 1);
00140 align_get_bits(&s->gb);
00141
00142 for(len=0; len<32; len++){
00143 if(get_bits1(&s->gb)) break;
00144 }
00145
00146 s->gb= gb;
00147
00148 if(len>=ff_mpeg4_get_video_packet_prefix_length(s))
00149 return 1;
00150 }
00151 }
00152 return 0;
00153 }
00154
00155 static void mpeg4_decode_sprite_trajectory(MpegEncContext * s, GetBitContext *gb)
00156 {
00157 int i;
00158 int a= 2<<s->sprite_warping_accuracy;
00159 int rho= 3-s->sprite_warping_accuracy;
00160 int r=16/a;
00161 const int vop_ref[4][2]= {{0,0}, {s->width,0}, {0, s->height}, {s->width, s->height}};
00162 int d[4][2]={{0,0}, {0,0}, {0,0}, {0,0}};
00163 int sprite_ref[4][2];
00164 int virtual_ref[2][2];
00165 int w2, h2, w3, h3;
00166 int alpha=0, beta=0;
00167 int w= s->width;
00168 int h= s->height;
00169 int min_ab;
00170
00171 for(i=0; i<s->num_sprite_warping_points; i++){
00172 int length;
00173 int x=0, y=0;
00174
00175 length= get_vlc2(gb, sprite_trajectory.table, SPRITE_TRAJ_VLC_BITS, 3);
00176 if(length){
00177 x= get_xbits(gb, length);
00178 }
00179 if(!(s->divx_version==500 && s->divx_build==413)) skip_bits1(gb);
00180
00181 length= get_vlc2(gb, sprite_trajectory.table, SPRITE_TRAJ_VLC_BITS, 3);
00182 if(length){
00183 y=get_xbits(gb, length);
00184 }
00185 skip_bits1(gb);
00186 s->sprite_traj[i][0]= d[i][0]= x;
00187 s->sprite_traj[i][1]= d[i][1]= y;
00188 }
00189 for(; i<4; i++)
00190 s->sprite_traj[i][0]= s->sprite_traj[i][1]= 0;
00191
00192 while((1<<alpha)<w) alpha++;
00193 while((1<<beta )<h) beta++;
00194 w2= 1<<alpha;
00195 h2= 1<<beta;
00196
00197
00198 if(s->divx_version==500 && s->divx_build==413){
00199 sprite_ref[0][0]= a*vop_ref[0][0] + d[0][0];
00200 sprite_ref[0][1]= a*vop_ref[0][1] + d[0][1];
00201 sprite_ref[1][0]= a*vop_ref[1][0] + d[0][0] + d[1][0];
00202 sprite_ref[1][1]= a*vop_ref[1][1] + d[0][1] + d[1][1];
00203 sprite_ref[2][0]= a*vop_ref[2][0] + d[0][0] + d[2][0];
00204 sprite_ref[2][1]= a*vop_ref[2][1] + d[0][1] + d[2][1];
00205 } else {
00206 sprite_ref[0][0]= (a>>1)*(2*vop_ref[0][0] + d[0][0]);
00207 sprite_ref[0][1]= (a>>1)*(2*vop_ref[0][1] + d[0][1]);
00208 sprite_ref[1][0]= (a>>1)*(2*vop_ref[1][0] + d[0][0] + d[1][0]);
00209 sprite_ref[1][1]= (a>>1)*(2*vop_ref[1][1] + d[0][1] + d[1][1]);
00210 sprite_ref[2][0]= (a>>1)*(2*vop_ref[2][0] + d[0][0] + d[2][0]);
00211 sprite_ref[2][1]= (a>>1)*(2*vop_ref[2][1] + d[0][1] + d[2][1]);
00212 }
00213
00214
00215
00216
00217
00218
00219
00220 virtual_ref[0][0]= 16*(vop_ref[0][0] + w2)
00221 + 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);
00222 virtual_ref[0][1]= 16*vop_ref[0][1]
00223 + 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);
00224 virtual_ref[1][0]= 16*vop_ref[0][0]
00225 + 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);
00226 virtual_ref[1][1]= 16*(vop_ref[0][1] + h2)
00227 + 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);
00228
00229 switch(s->num_sprite_warping_points)
00230 {
00231 case 0:
00232 s->sprite_offset[0][0]= 0;
00233 s->sprite_offset[0][1]= 0;
00234 s->sprite_offset[1][0]= 0;
00235 s->sprite_offset[1][1]= 0;
00236 s->sprite_delta[0][0]= a;
00237 s->sprite_delta[0][1]= 0;
00238 s->sprite_delta[1][0]= 0;
00239 s->sprite_delta[1][1]= a;
00240 s->sprite_shift[0]= 0;
00241 s->sprite_shift[1]= 0;
00242 break;
00243 case 1:
00244 s->sprite_offset[0][0]= sprite_ref[0][0] - a*vop_ref[0][0];
00245 s->sprite_offset[0][1]= sprite_ref[0][1] - a*vop_ref[0][1];
00246 s->sprite_offset[1][0]= ((sprite_ref[0][0]>>1)|(sprite_ref[0][0]&1)) - a*(vop_ref[0][0]/2);
00247 s->sprite_offset[1][1]= ((sprite_ref[0][1]>>1)|(sprite_ref[0][1]&1)) - a*(vop_ref[0][1]/2);
00248 s->sprite_delta[0][0]= a;
00249 s->sprite_delta[0][1]= 0;
00250 s->sprite_delta[1][0]= 0;
00251 s->sprite_delta[1][1]= a;
00252 s->sprite_shift[0]= 0;
00253 s->sprite_shift[1]= 0;
00254 break;
00255 case 2:
00256 s->sprite_offset[0][0]= (sprite_ref[0][0]<<(alpha+rho))
00257 + (-r*sprite_ref[0][0] + virtual_ref[0][0])*(-vop_ref[0][0])
00258 + ( r*sprite_ref[0][1] - virtual_ref[0][1])*(-vop_ref[0][1])
00259 + (1<<(alpha+rho-1));
00260 s->sprite_offset[0][1]= (sprite_ref[0][1]<<(alpha+rho))
00261 + (-r*sprite_ref[0][1] + virtual_ref[0][1])*(-vop_ref[0][0])
00262 + (-r*sprite_ref[0][0] + virtual_ref[0][0])*(-vop_ref[0][1])
00263 + (1<<(alpha+rho-1));
00264 s->sprite_offset[1][0]= ( (-r*sprite_ref[0][0] + virtual_ref[0][0])*(-2*vop_ref[0][0] + 1)
00265 +( r*sprite_ref[0][1] - virtual_ref[0][1])*(-2*vop_ref[0][1] + 1)
00266 +2*w2*r*sprite_ref[0][0]
00267 - 16*w2
00268 + (1<<(alpha+rho+1)));
00269 s->sprite_offset[1][1]= ( (-r*sprite_ref[0][1] + virtual_ref[0][1])*(-2*vop_ref[0][0] + 1)
00270 +(-r*sprite_ref[0][0] + virtual_ref[0][0])*(-2*vop_ref[0][1] + 1)
00271 +2*w2*r*sprite_ref[0][1]
00272 - 16*w2
00273 + (1<<(alpha+rho+1)));
00274 s->sprite_delta[0][0]= (-r*sprite_ref[0][0] + virtual_ref[0][0]);
00275 s->sprite_delta[0][1]= (+r*sprite_ref[0][1] - virtual_ref[0][1]);
00276 s->sprite_delta[1][0]= (-r*sprite_ref[0][1] + virtual_ref[0][1]);
00277 s->sprite_delta[1][1]= (-r*sprite_ref[0][0] + virtual_ref[0][0]);
00278
00279 s->sprite_shift[0]= alpha+rho;
00280 s->sprite_shift[1]= alpha+rho+2;
00281 break;
00282 case 3:
00283 min_ab= FFMIN(alpha, beta);
00284 w3= w2>>min_ab;
00285 h3= h2>>min_ab;
00286 s->sprite_offset[0][0]= (sprite_ref[0][0]<<(alpha+beta+rho-min_ab))
00287 + (-r*sprite_ref[0][0] + virtual_ref[0][0])*h3*(-vop_ref[0][0])
00288 + (-r*sprite_ref[0][0] + virtual_ref[1][0])*w3*(-vop_ref[0][1])
00289 + (1<<(alpha+beta+rho-min_ab-1));
00290 s->sprite_offset[0][1]= (sprite_ref[0][1]<<(alpha+beta+rho-min_ab))
00291 + (-r*sprite_ref[0][1] + virtual_ref[0][1])*h3*(-vop_ref[0][0])
00292 + (-r*sprite_ref[0][1] + virtual_ref[1][1])*w3*(-vop_ref[0][1])
00293 + (1<<(alpha+beta+rho-min_ab-1));
00294 s->sprite_offset[1][0]= (-r*sprite_ref[0][0] + virtual_ref[0][0])*h3*(-2*vop_ref[0][0] + 1)
00295 + (-r*sprite_ref[0][0] + virtual_ref[1][0])*w3*(-2*vop_ref[0][1] + 1)
00296 + 2*w2*h3*r*sprite_ref[0][0]
00297 - 16*w2*h3
00298 + (1<<(alpha+beta+rho-min_ab+1));
00299 s->sprite_offset[1][1]= (-r*sprite_ref[0][1] + virtual_ref[0][1])*h3*(-2*vop_ref[0][0] + 1)
00300 + (-r*sprite_ref[0][1] + virtual_ref[1][1])*w3*(-2*vop_ref[0][1] + 1)
00301 + 2*w2*h3*r*sprite_ref[0][1]
00302 - 16*w2*h3
00303 + (1<<(alpha+beta+rho-min_ab+1));
00304 s->sprite_delta[0][0]= (-r*sprite_ref[0][0] + virtual_ref[0][0])*h3;
00305 s->sprite_delta[0][1]= (-r*sprite_ref[0][0] + virtual_ref[1][0])*w3;
00306 s->sprite_delta[1][0]= (-r*sprite_ref[0][1] + virtual_ref[0][1])*h3;
00307 s->sprite_delta[1][1]= (-r*sprite_ref[0][1] + virtual_ref[1][1])*w3;
00308
00309 s->sprite_shift[0]= alpha + beta + rho - min_ab;
00310 s->sprite_shift[1]= alpha + beta + rho - min_ab + 2;
00311 break;
00312 }
00313
00314 if( s->sprite_delta[0][0] == a<<s->sprite_shift[0]
00315 && s->sprite_delta[0][1] == 0
00316 && s->sprite_delta[1][0] == 0
00317 && s->sprite_delta[1][1] == a<<s->sprite_shift[0])
00318 {
00319 s->sprite_offset[0][0]>>=s->sprite_shift[0];
00320 s->sprite_offset[0][1]>>=s->sprite_shift[0];
00321 s->sprite_offset[1][0]>>=s->sprite_shift[1];
00322 s->sprite_offset[1][1]>>=s->sprite_shift[1];
00323 s->sprite_delta[0][0]= a;
00324 s->sprite_delta[0][1]= 0;
00325 s->sprite_delta[1][0]= 0;
00326 s->sprite_delta[1][1]= a;
00327 s->sprite_shift[0]= 0;
00328 s->sprite_shift[1]= 0;
00329 s->real_sprite_warping_points=1;
00330 }
00331 else{
00332 int shift_y= 16 - s->sprite_shift[0];
00333 int shift_c= 16 - s->sprite_shift[1];
00334 for(i=0; i<2; i++){
00335 s->sprite_offset[0][i]<<= shift_y;
00336 s->sprite_offset[1][i]<<= shift_c;
00337 s->sprite_delta[0][i]<<= shift_y;
00338 s->sprite_delta[1][i]<<= shift_y;
00339 s->sprite_shift[i]= 16;
00340 }
00341 s->real_sprite_warping_points= s->num_sprite_warping_points;
00342 }
00343 }
00344
00349 int mpeg4_decode_video_packet_header(MpegEncContext *s)
00350 {
00351 int mb_num_bits= av_log2(s->mb_num - 1) + 1;
00352 int header_extension=0, mb_num, len;
00353
00354
00355 if( get_bits_count(&s->gb) > s->gb.size_in_bits-20) return -1;
00356
00357 for(len=0; len<32; len++){
00358 if(get_bits1(&s->gb)) break;
00359 }
00360
00361 if(len!=ff_mpeg4_get_video_packet_prefix_length(s)){
00362 av_log(s->avctx, AV_LOG_ERROR, "marker does not match f_code\n");
00363 return -1;
00364 }
00365
00366 if(s->shape != RECT_SHAPE){
00367 header_extension= get_bits1(&s->gb);
00368
00369 }
00370
00371 mb_num= get_bits(&s->gb, mb_num_bits);
00372 if(mb_num>=s->mb_num){
00373 av_log(s->avctx, AV_LOG_ERROR, "illegal mb_num in video packet (%d %d) \n", mb_num, s->mb_num);
00374 return -1;
00375 }
00376 if(s->pict_type == AV_PICTURE_TYPE_B){
00377 int mb_x = 0, mb_y = 0;
00378
00379 while(s->next_picture.mbskip_table[ s->mb_index2xy[ mb_num ] ]) {
00380 if (!mb_x) ff_thread_await_progress((AVFrame*)s->next_picture_ptr, mb_y++, 0);
00381 mb_num++;
00382 if (++mb_x == s->mb_width) mb_x = 0;
00383 }
00384 if(mb_num >= s->mb_num) return -1;
00385 }
00386
00387 s->mb_x= mb_num % s->mb_width;
00388 s->mb_y= mb_num / s->mb_width;
00389
00390 if(s->shape != BIN_ONLY_SHAPE){
00391 int qscale= get_bits(&s->gb, s->quant_precision);
00392 if(qscale)
00393 s->chroma_qscale=s->qscale= qscale;
00394 }
00395
00396 if(s->shape == RECT_SHAPE){
00397 header_extension= get_bits1(&s->gb);
00398 }
00399 if(header_extension){
00400 int time_incr=0;
00401
00402 while (get_bits1(&s->gb) != 0)
00403 time_incr++;
00404
00405 check_marker(&s->gb, "before time_increment in video packed header");
00406 skip_bits(&s->gb, s->time_increment_bits);
00407 check_marker(&s->gb, "before vop_coding_type in video packed header");
00408
00409 skip_bits(&s->gb, 2);
00410
00411
00412 if(s->shape != BIN_ONLY_SHAPE){
00413 skip_bits(&s->gb, 3);
00414
00415 if(s->pict_type == AV_PICTURE_TYPE_S && s->vol_sprite_usage==GMC_SPRITE){
00416 mpeg4_decode_sprite_trajectory(s, &s->gb);
00417 av_log(s->avctx, AV_LOG_ERROR, "untested\n");
00418 }
00419
00420
00421
00422 if (s->pict_type != AV_PICTURE_TYPE_I) {
00423 int f_code = get_bits(&s->gb, 3);
00424 if(f_code==0){
00425 av_log(s->avctx, AV_LOG_ERROR, "Error, video packet header damaged (f_code=0)\n");
00426 }
00427 }
00428 if (s->pict_type == AV_PICTURE_TYPE_B) {
00429 int b_code = get_bits(&s->gb, 3);
00430 if(b_code==0){
00431 av_log(s->avctx, AV_LOG_ERROR, "Error, video packet header damaged (b_code=0)\n");
00432 }
00433 }
00434 }
00435 }
00436
00437
00438 return 0;
00439 }
00440
00446 static inline int get_amv(MpegEncContext *s, int n){
00447 int x, y, mb_v, sum, dx, dy, shift;
00448 int len = 1 << (s->f_code + 4);
00449 const int a= s->sprite_warping_accuracy;
00450
00451 if(s->workaround_bugs & FF_BUG_AMV)
00452 len >>= s->quarter_sample;
00453
00454 if(s->real_sprite_warping_points==1){
00455 if(s->divx_version==500 && s->divx_build==413)
00456 sum= s->sprite_offset[0][n] / (1<<(a - s->quarter_sample));
00457 else
00458 sum= RSHIFT(s->sprite_offset[0][n]<<s->quarter_sample, a);
00459 }else{
00460 dx= s->sprite_delta[n][0];
00461 dy= s->sprite_delta[n][1];
00462 shift= s->sprite_shift[0];
00463 if(n) dy -= 1<<(shift + a + 1);
00464 else dx -= 1<<(shift + a + 1);
00465 mb_v= s->sprite_offset[0][n] + dx*s->mb_x*16 + dy*s->mb_y*16;
00466
00467 sum=0;
00468 for(y=0; y<16; y++){
00469 int v;
00470
00471 v= mb_v + dy*y;
00472
00473 for(x=0; x<16; x++){
00474 sum+= v>>shift;
00475 v+= dx;
00476 }
00477 }
00478 sum= RSHIFT(sum, a+8-s->quarter_sample);
00479 }
00480
00481 if (sum < -len) sum= -len;
00482 else if (sum >= len) sum= len-1;
00483
00484 return sum;
00485 }
00486
00493 static inline int mpeg4_decode_dc(MpegEncContext * s, int n, int *dir_ptr)
00494 {
00495 int level, code;
00496
00497 if (n < 4)
00498 code = get_vlc2(&s->gb, dc_lum.table, DC_VLC_BITS, 1);
00499 else
00500 code = get_vlc2(&s->gb, dc_chrom.table, DC_VLC_BITS, 1);
00501 if (code < 0 || code > 9 ){
00502 av_log(s->avctx, AV_LOG_ERROR, "illegal dc vlc\n");
00503 return -1;
00504 }
00505 if (code == 0) {
00506 level = 0;
00507 } else {
00508 if(IS_3IV1){
00509 if(code==1)
00510 level= 2*get_bits1(&s->gb)-1;
00511 else{
00512 if(get_bits1(&s->gb))
00513 level = get_bits(&s->gb, code-1) + (1<<(code-1));
00514 else
00515 level = -get_bits(&s->gb, code-1) - (1<<(code-1));
00516 }
00517 }else{
00518 level = get_xbits(&s->gb, code);
00519 }
00520
00521 if (code > 8){
00522 if(get_bits1(&s->gb)==0){
00523 if(s->error_recognition>=2){
00524 av_log(s->avctx, AV_LOG_ERROR, "dc marker bit missing\n");
00525 return -1;
00526 }
00527 }
00528 }
00529 }
00530
00531 return ff_mpeg4_pred_dc(s, n, level, dir_ptr, 0);
00532 }
00533
00538 static int mpeg4_decode_partition_a(MpegEncContext *s){
00539 int mb_num;
00540 static const int8_t quant_tab[4] = { -1, -2, 1, 2 };
00541
00542
00543 mb_num=0;
00544 s->first_slice_line=1;
00545 for(; s->mb_y<s->mb_height; s->mb_y++){
00546 ff_init_block_index(s);
00547 for(; s->mb_x<s->mb_width; s->mb_x++){
00548 const int xy= s->mb_x + s->mb_y*s->mb_stride;
00549 int cbpc;
00550 int dir=0;
00551
00552 mb_num++;
00553 ff_update_block_index(s);
00554 if(s->mb_x == s->resync_mb_x && s->mb_y == s->resync_mb_y+1)
00555 s->first_slice_line=0;
00556
00557 if(s->pict_type==AV_PICTURE_TYPE_I){
00558 int i;
00559
00560 do{
00561 if(show_bits_long(&s->gb, 19)==DC_MARKER){
00562 return mb_num-1;
00563 }
00564
00565 cbpc = get_vlc2(&s->gb, ff_h263_intra_MCBPC_vlc.table, INTRA_MCBPC_VLC_BITS, 2);
00566 if (cbpc < 0){
00567 av_log(s->avctx, AV_LOG_ERROR, "cbpc corrupted at %d %d\n", s->mb_x, s->mb_y);
00568 return -1;
00569 }
00570 }while(cbpc == 8);
00571
00572 s->cbp_table[xy]= cbpc & 3;
00573 s->current_picture.mb_type[xy]= MB_TYPE_INTRA;
00574 s->mb_intra = 1;
00575
00576 if(cbpc & 4) {
00577 ff_set_qscale(s, s->qscale + quant_tab[get_bits(&s->gb, 2)]);
00578 }
00579 s->current_picture.qscale_table[xy]= s->qscale;
00580
00581 s->mbintra_table[xy]= 1;
00582 for(i=0; i<6; i++){
00583 int dc_pred_dir;
00584 int dc= mpeg4_decode_dc(s, i, &dc_pred_dir);
00585 if(dc < 0){
00586 av_log(s->avctx, AV_LOG_ERROR, "DC corrupted at %d %d\n", s->mb_x, s->mb_y);
00587 return -1;
00588 }
00589 dir<<=1;
00590 if(dc_pred_dir) dir|=1;
00591 }
00592 s->pred_dir_table[xy]= dir;
00593 }else{
00594 int mx, my, pred_x, pred_y, bits;
00595 int16_t * const mot_val= s->current_picture.motion_val[0][s->block_index[0]];
00596 const int stride= s->b8_stride*2;
00597
00598 try_again:
00599 bits= show_bits(&s->gb, 17);
00600 if(bits==MOTION_MARKER){
00601 return mb_num-1;
00602 }
00603 skip_bits1(&s->gb);
00604 if(bits&0x10000){
00605
00606 if(s->pict_type==AV_PICTURE_TYPE_S && s->vol_sprite_usage==GMC_SPRITE){
00607 s->current_picture.mb_type[xy]= MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_GMC | MB_TYPE_L0;
00608 mx= get_amv(s, 0);
00609 my= get_amv(s, 1);
00610 }else{
00611 s->current_picture.mb_type[xy]= MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0;
00612 mx=my=0;
00613 }
00614 mot_val[0 ]= mot_val[2 ]=
00615 mot_val[0+stride]= mot_val[2+stride]= mx;
00616 mot_val[1 ]= mot_val[3 ]=
00617 mot_val[1+stride]= mot_val[3+stride]= my;
00618
00619 if(s->mbintra_table[xy])
00620 ff_clean_intra_table_entries(s);
00621 continue;
00622 }
00623
00624 cbpc = get_vlc2(&s->gb, ff_h263_inter_MCBPC_vlc.table, INTER_MCBPC_VLC_BITS, 2);
00625 if (cbpc < 0){
00626 av_log(s->avctx, AV_LOG_ERROR, "cbpc corrupted at %d %d\n", s->mb_x, s->mb_y);
00627 return -1;
00628 }
00629 if(cbpc == 20)
00630 goto try_again;
00631
00632 s->cbp_table[xy]= cbpc&(8+3);
00633
00634 s->mb_intra = ((cbpc & 4) != 0);
00635
00636 if(s->mb_intra){
00637 s->current_picture.mb_type[xy]= MB_TYPE_INTRA;
00638 s->mbintra_table[xy]= 1;
00639 mot_val[0 ]= mot_val[2 ]=
00640 mot_val[0+stride]= mot_val[2+stride]= 0;
00641 mot_val[1 ]= mot_val[3 ]=
00642 mot_val[1+stride]= mot_val[3+stride]= 0;
00643 }else{
00644 if(s->mbintra_table[xy])
00645 ff_clean_intra_table_entries(s);
00646
00647 if(s->pict_type==AV_PICTURE_TYPE_S && s->vol_sprite_usage==GMC_SPRITE && (cbpc & 16) == 0)
00648 s->mcsel= get_bits1(&s->gb);
00649 else s->mcsel= 0;
00650
00651 if ((cbpc & 16) == 0) {
00652
00653
00654 h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
00655 if(!s->mcsel){
00656 mx = h263_decode_motion(s, pred_x, s->f_code);
00657 if (mx >= 0xffff)
00658 return -1;
00659
00660 my = h263_decode_motion(s, pred_y, s->f_code);
00661 if (my >= 0xffff)
00662 return -1;
00663 s->current_picture.mb_type[xy]= MB_TYPE_16x16 | MB_TYPE_L0;
00664 } else {
00665 mx = get_amv(s, 0);
00666 my = get_amv(s, 1);
00667 s->current_picture.mb_type[xy]= MB_TYPE_16x16 | MB_TYPE_GMC | MB_TYPE_L0;
00668 }
00669
00670 mot_val[0 ]= mot_val[2 ] =
00671 mot_val[0+stride]= mot_val[2+stride]= mx;
00672 mot_val[1 ]= mot_val[3 ]=
00673 mot_val[1+stride]= mot_val[3+stride]= my;
00674 } else {
00675 int i;
00676 s->current_picture.mb_type[xy]= MB_TYPE_8x8 | MB_TYPE_L0;
00677 for(i=0;i<4;i++) {
00678 int16_t *mot_val= h263_pred_motion(s, i, 0, &pred_x, &pred_y);
00679 mx = h263_decode_motion(s, pred_x, s->f_code);
00680 if (mx >= 0xffff)
00681 return -1;
00682
00683 my = h263_decode_motion(s, pred_y, s->f_code);
00684 if (my >= 0xffff)
00685 return -1;
00686 mot_val[0] = mx;
00687 mot_val[1] = my;
00688 }
00689 }
00690 }
00691 }
00692 }
00693 s->mb_x= 0;
00694 }
00695
00696 return mb_num;
00697 }
00698
00703 static int mpeg4_decode_partition_b(MpegEncContext *s, int mb_count){
00704 int mb_num=0;
00705 static const int8_t quant_tab[4] = { -1, -2, 1, 2 };
00706
00707 s->mb_x= s->resync_mb_x;
00708 s->first_slice_line=1;
00709 for(s->mb_y= s->resync_mb_y; mb_num < mb_count; s->mb_y++){
00710 ff_init_block_index(s);
00711 for(; mb_num < mb_count && s->mb_x<s->mb_width; s->mb_x++){
00712 const int xy= s->mb_x + s->mb_y*s->mb_stride;
00713
00714 mb_num++;
00715 ff_update_block_index(s);
00716 if(s->mb_x == s->resync_mb_x && s->mb_y == s->resync_mb_y+1)
00717 s->first_slice_line=0;
00718
00719 if(s->pict_type==AV_PICTURE_TYPE_I){
00720 int ac_pred= get_bits1(&s->gb);
00721 int cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1);
00722 if(cbpy<0){
00723 av_log(s->avctx, AV_LOG_ERROR, "cbpy corrupted at %d %d\n", s->mb_x, s->mb_y);
00724 return -1;
00725 }
00726
00727 s->cbp_table[xy]|= cbpy<<2;
00728 s->current_picture.mb_type[xy] |= ac_pred*MB_TYPE_ACPRED;
00729 }else{
00730 if(IS_INTRA(s->current_picture.mb_type[xy])){
00731 int dir=0,i;
00732 int ac_pred = get_bits1(&s->gb);
00733 int cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1);
00734
00735 if(cbpy<0){
00736 av_log(s->avctx, AV_LOG_ERROR, "I cbpy corrupted at %d %d\n", s->mb_x, s->mb_y);
00737 return -1;
00738 }
00739
00740 if(s->cbp_table[xy] & 8) {
00741 ff_set_qscale(s, s->qscale + quant_tab[get_bits(&s->gb, 2)]);
00742 }
00743 s->current_picture.qscale_table[xy]= s->qscale;
00744
00745 for(i=0; i<6; i++){
00746 int dc_pred_dir;
00747 int dc= mpeg4_decode_dc(s, i, &dc_pred_dir);
00748 if(dc < 0){
00749 av_log(s->avctx, AV_LOG_ERROR, "DC corrupted at %d %d\n", s->mb_x, s->mb_y);
00750 return -1;
00751 }
00752 dir<<=1;
00753 if(dc_pred_dir) dir|=1;
00754 }
00755 s->cbp_table[xy]&= 3;
00756 s->cbp_table[xy]|= cbpy<<2;
00757 s->current_picture.mb_type[xy] |= ac_pred*MB_TYPE_ACPRED;
00758 s->pred_dir_table[xy]= dir;
00759 }else if(IS_SKIP(s->current_picture.mb_type[xy])){
00760 s->current_picture.qscale_table[xy]= s->qscale;
00761 s->cbp_table[xy]= 0;
00762 }else{
00763 int cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1);
00764
00765 if(cbpy<0){
00766 av_log(s->avctx, AV_LOG_ERROR, "P cbpy corrupted at %d %d\n", s->mb_x, s->mb_y);
00767 return -1;
00768 }
00769
00770 if(s->cbp_table[xy] & 8) {
00771 ff_set_qscale(s, s->qscale + quant_tab[get_bits(&s->gb, 2)]);
00772 }
00773 s->current_picture.qscale_table[xy]= s->qscale;
00774
00775 s->cbp_table[xy]&= 3;
00776 s->cbp_table[xy]|= (cbpy^0xf)<<2;
00777 }
00778 }
00779 }
00780 if(mb_num >= mb_count) return 0;
00781 s->mb_x= 0;
00782 }
00783 return 0;
00784 }
00785
00790 int ff_mpeg4_decode_partitions(MpegEncContext *s)
00791 {
00792 int mb_num;
00793 const int part_a_error= s->pict_type==AV_PICTURE_TYPE_I ? (DC_ERROR|MV_ERROR) : MV_ERROR;
00794 const int part_a_end = s->pict_type==AV_PICTURE_TYPE_I ? (DC_END |MV_END) : MV_END;
00795
00796 mb_num= mpeg4_decode_partition_a(s);
00797 if(mb_num<0){
00798 ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, part_a_error);
00799 return -1;
00800 }
00801
00802 if(s->resync_mb_x + s->resync_mb_y*s->mb_width + mb_num > s->mb_num){
00803 av_log(s->avctx, AV_LOG_ERROR, "slice below monitor ...\n");
00804 ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, part_a_error);
00805 return -1;
00806 }
00807
00808 s->mb_num_left= mb_num;
00809
00810 if(s->pict_type==AV_PICTURE_TYPE_I){
00811 while(show_bits(&s->gb, 9) == 1)
00812 skip_bits(&s->gb, 9);
00813 if(get_bits_long(&s->gb, 19)!=DC_MARKER){
00814 av_log(s->avctx, AV_LOG_ERROR, "marker missing after first I partition at %d %d\n", s->mb_x, s->mb_y);
00815 return -1;
00816 }
00817 }else{
00818 while(show_bits(&s->gb, 10) == 1)
00819 skip_bits(&s->gb, 10);
00820 if(get_bits(&s->gb, 17)!=MOTION_MARKER){
00821 av_log(s->avctx, AV_LOG_ERROR, "marker missing after first P partition at %d %d\n", s->mb_x, s->mb_y);
00822 return -1;
00823 }
00824 }
00825 ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, part_a_end);
00826
00827 if( mpeg4_decode_partition_b(s, mb_num) < 0){
00828 if(s->pict_type==AV_PICTURE_TYPE_P)
00829 ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, DC_ERROR);
00830 return -1;
00831 }else{
00832 if(s->pict_type==AV_PICTURE_TYPE_P)
00833 ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, DC_END);
00834 }
00835
00836 return 0;
00837 }
00838
00843 static inline int mpeg4_decode_block(MpegEncContext * s, DCTELEM * block,
00844 int n, int coded, int intra, int rvlc)
00845 {
00846 int level, i, last, run;
00847 int dc_pred_dir;
00848 RLTable * rl;
00849 RL_VLC_ELEM * rl_vlc;
00850 const uint8_t * scan_table;
00851 int qmul, qadd;
00852
00853
00854
00855 if(intra) {
00856 if(s->use_intra_dc_vlc){
00857
00858 if(s->partitioned_frame){
00859 level = s->dc_val[0][ s->block_index[n] ];
00860 if(n<4) level= FASTDIV((level + (s->y_dc_scale>>1)), s->y_dc_scale);
00861 else level= FASTDIV((level + (s->c_dc_scale>>1)), s->c_dc_scale);
00862 dc_pred_dir= (s->pred_dir_table[s->mb_x + s->mb_y*s->mb_stride]<<n)&32;
00863 }else{
00864 level = mpeg4_decode_dc(s, n, &dc_pred_dir);
00865 if (level < 0)
00866 return -1;
00867 }
00868 block[0] = level;
00869 i = 0;
00870 }else{
00871 i = -1;
00872 ff_mpeg4_pred_dc(s, n, 0, &dc_pred_dir, 0);
00873 }
00874 if (!coded)
00875 goto not_coded;
00876
00877 if(rvlc){
00878 rl = &rvlc_rl_intra;
00879 rl_vlc = rvlc_rl_intra.rl_vlc[0];
00880 }else{
00881 rl = &ff_mpeg4_rl_intra;
00882 rl_vlc = ff_mpeg4_rl_intra.rl_vlc[0];
00883 }
00884 if (s->ac_pred) {
00885 if (dc_pred_dir == 0)
00886 scan_table = s->intra_v_scantable.permutated;
00887 else
00888 scan_table = s->intra_h_scantable.permutated;
00889 } else {
00890 scan_table = s->intra_scantable.permutated;
00891 }
00892 qmul=1;
00893 qadd=0;
00894 } else {
00895 i = -1;
00896 if (!coded) {
00897 s->block_last_index[n] = i;
00898 return 0;
00899 }
00900 if(rvlc) rl = &rvlc_rl_inter;
00901 else rl = &ff_h263_rl_inter;
00902
00903 scan_table = s->intra_scantable.permutated;
00904
00905 if(s->mpeg_quant){
00906 qmul=1;
00907 qadd=0;
00908 if(rvlc){
00909 rl_vlc = rvlc_rl_inter.rl_vlc[0];
00910 }else{
00911 rl_vlc = ff_h263_rl_inter.rl_vlc[0];
00912 }
00913 }else{
00914 qmul = s->qscale << 1;
00915 qadd = (s->qscale - 1) | 1;
00916 if(rvlc){
00917 rl_vlc = rvlc_rl_inter.rl_vlc[s->qscale];
00918 }else{
00919 rl_vlc = ff_h263_rl_inter.rl_vlc[s->qscale];
00920 }
00921 }
00922 }
00923 {
00924 OPEN_READER(re, &s->gb);
00925 for(;;) {
00926 UPDATE_CACHE(re, &s->gb);
00927 GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 0);
00928 if (level==0) {
00929
00930 if(rvlc){
00931 if(SHOW_UBITS(re, &s->gb, 1)==0){
00932 av_log(s->avctx, AV_LOG_ERROR, "1. marker bit missing in rvlc esc\n");
00933 return -1;
00934 }; SKIP_CACHE(re, &s->gb, 1);
00935
00936 last= SHOW_UBITS(re, &s->gb, 1); SKIP_CACHE(re, &s->gb, 1);
00937 run= SHOW_UBITS(re, &s->gb, 6); LAST_SKIP_CACHE(re, &s->gb, 6);
00938 SKIP_COUNTER(re, &s->gb, 1+1+6);
00939 UPDATE_CACHE(re, &s->gb);
00940
00941 if(SHOW_UBITS(re, &s->gb, 1)==0){
00942 av_log(s->avctx, AV_LOG_ERROR, "2. marker bit missing in rvlc esc\n");
00943 return -1;
00944 }; SKIP_CACHE(re, &s->gb, 1);
00945
00946 level= SHOW_UBITS(re, &s->gb, 11); SKIP_CACHE(re, &s->gb, 11);
00947
00948 if(SHOW_UBITS(re, &s->gb, 5)!=0x10){
00949 av_log(s->avctx, AV_LOG_ERROR, "reverse esc missing\n");
00950 return -1;
00951 }; SKIP_CACHE(re, &s->gb, 5);
00952
00953 level= level * qmul + qadd;
00954 level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); LAST_SKIP_CACHE(re, &s->gb, 1);
00955 SKIP_COUNTER(re, &s->gb, 1+11+5+1);
00956
00957 i+= run + 1;
00958 if(last) i+=192;
00959 }else{
00960 int cache;
00961 cache= GET_CACHE(re, &s->gb);
00962
00963 if(IS_3IV1)
00964 cache ^= 0xC0000000;
00965
00966 if (cache&0x80000000) {
00967 if (cache&0x40000000) {
00968
00969 SKIP_CACHE(re, &s->gb, 2);
00970 last= SHOW_UBITS(re, &s->gb, 1); SKIP_CACHE(re, &s->gb, 1);
00971 run= SHOW_UBITS(re, &s->gb, 6); LAST_SKIP_CACHE(re, &s->gb, 6);
00972 SKIP_COUNTER(re, &s->gb, 2+1+6);
00973 UPDATE_CACHE(re, &s->gb);
00974
00975 if(IS_3IV1){
00976 level= SHOW_SBITS(re, &s->gb, 12); LAST_SKIP_BITS(re, &s->gb, 12);
00977 }else{
00978 if(SHOW_UBITS(re, &s->gb, 1)==0){
00979 av_log(s->avctx, AV_LOG_ERROR, "1. marker bit missing in 3. esc\n");
00980 return -1;
00981 }; SKIP_CACHE(re, &s->gb, 1);
00982
00983 level= SHOW_SBITS(re, &s->gb, 12); SKIP_CACHE(re, &s->gb, 12);
00984
00985 if(SHOW_UBITS(re, &s->gb, 1)==0){
00986 av_log(s->avctx, AV_LOG_ERROR, "2. marker bit missing in 3. esc\n");
00987 return -1;
00988 }; LAST_SKIP_CACHE(re, &s->gb, 1);
00989
00990 SKIP_COUNTER(re, &s->gb, 1+12+1);
00991 }
00992
00993 #if 0
00994 if(s->error_recognition >= FF_ER_COMPLIANT){
00995 const int abs_level= FFABS(level);
00996 if(abs_level<=MAX_LEVEL && run<=MAX_RUN){
00997 const int run1= run - rl->max_run[last][abs_level] - 1;
00998 if(abs_level <= rl->max_level[last][run]){
00999 av_log(s->avctx, AV_LOG_ERROR, "illegal 3. esc, vlc encoding possible\n");
01000 return -1;
01001 }
01002 if(s->error_recognition > FF_ER_COMPLIANT){
01003 if(abs_level <= rl->max_level[last][run]*2){
01004 av_log(s->avctx, AV_LOG_ERROR, "illegal 3. esc, esc 1 encoding possible\n");
01005 return -1;
01006 }
01007 if(run1 >= 0 && abs_level <= rl->max_level[last][run1]){
01008 av_log(s->avctx, AV_LOG_ERROR, "illegal 3. esc, esc 2 encoding possible\n");
01009 return -1;
01010 }
01011 }
01012 }
01013 }
01014 #endif
01015 if (level>0) level= level * qmul + qadd;
01016 else level= level * qmul - qadd;
01017
01018 if((unsigned)(level + 2048) > 4095){
01019 if(s->error_recognition > FF_ER_COMPLIANT){
01020 if(level > 2560 || level<-2560){
01021 av_log(s->avctx, AV_LOG_ERROR, "|level| overflow in 3. esc, qp=%d\n", s->qscale);
01022 return -1;
01023 }
01024 }
01025 level= level<0 ? -2048 : 2047;
01026 }
01027
01028 i+= run + 1;
01029 if(last) i+=192;
01030 } else {
01031
01032 SKIP_BITS(re, &s->gb, 2);
01033 GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 1);
01034 i+= run + rl->max_run[run>>7][level/qmul] +1;
01035 level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
01036 LAST_SKIP_BITS(re, &s->gb, 1);
01037 }
01038 } else {
01039
01040 SKIP_BITS(re, &s->gb, 1);
01041 GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 1);
01042 i+= run;
01043 level = level + rl->max_level[run>>7][(run-1)&63] * qmul;
01044 level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
01045 LAST_SKIP_BITS(re, &s->gb, 1);
01046 }
01047 }
01048 } else {
01049 i+= run;
01050 level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
01051 LAST_SKIP_BITS(re, &s->gb, 1);
01052 }
01053 if (i > 62){
01054 i-= 192;
01055 if(i&(~63)){
01056 av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y);
01057 return -1;
01058 }
01059
01060 block[scan_table[i]] = level;
01061 break;
01062 }
01063
01064 block[scan_table[i]] = level;
01065 }
01066 CLOSE_READER(re, &s->gb);
01067 }
01068 not_coded:
01069 if (intra) {
01070 if(!s->use_intra_dc_vlc){
01071 block[0] = ff_mpeg4_pred_dc(s, n, block[0], &dc_pred_dir, 0);
01072
01073 i -= i>>31;
01074 }
01075
01076 mpeg4_pred_ac(s, block, n, dc_pred_dir);
01077 if (s->ac_pred) {
01078 i = 63;
01079 }
01080 }
01081 s->block_last_index[n] = i;
01082 return 0;
01083 }
01084
01089 static int mpeg4_decode_partitioned_mb(MpegEncContext *s, DCTELEM block[6][64])
01090 {
01091 int cbp, mb_type;
01092 const int xy= s->mb_x + s->mb_y*s->mb_stride;
01093
01094 mb_type= s->current_picture.mb_type[xy];
01095 cbp = s->cbp_table[xy];
01096
01097 s->use_intra_dc_vlc= s->qscale < s->intra_dc_threshold;
01098
01099 if(s->current_picture.qscale_table[xy] != s->qscale){
01100 ff_set_qscale(s, s->current_picture.qscale_table[xy] );
01101 }
01102
01103 if (s->pict_type == AV_PICTURE_TYPE_P || s->pict_type==AV_PICTURE_TYPE_S) {
01104 int i;
01105 for(i=0; i<4; i++){
01106 s->mv[0][i][0] = s->current_picture.motion_val[0][ s->block_index[i] ][0];
01107 s->mv[0][i][1] = s->current_picture.motion_val[0][ s->block_index[i] ][1];
01108 }
01109 s->mb_intra = IS_INTRA(mb_type);
01110
01111 if (IS_SKIP(mb_type)) {
01112
01113 for(i=0;i<6;i++)
01114 s->block_last_index[i] = -1;
01115 s->mv_dir = MV_DIR_FORWARD;
01116 s->mv_type = MV_TYPE_16X16;
01117 if(s->pict_type==AV_PICTURE_TYPE_S && s->vol_sprite_usage==GMC_SPRITE){
01118 s->mcsel=1;
01119 s->mb_skipped = 0;
01120 }else{
01121 s->mcsel=0;
01122 s->mb_skipped = 1;
01123 }
01124 }else if(s->mb_intra){
01125 s->ac_pred = IS_ACPRED(s->current_picture.mb_type[xy]);
01126 }else if(!s->mb_intra){
01127
01128
01129 s->mv_dir = MV_DIR_FORWARD;
01130 if (IS_8X8(mb_type)) {
01131 s->mv_type = MV_TYPE_8X8;
01132 } else {
01133 s->mv_type = MV_TYPE_16X16;
01134 }
01135 }
01136 } else {
01137 s->mb_intra = 1;
01138 s->ac_pred = IS_ACPRED(s->current_picture.mb_type[xy]);
01139 }
01140
01141 if (!IS_SKIP(mb_type)) {
01142 int i;
01143 s->dsp.clear_blocks(s->block[0]);
01144
01145 for (i = 0; i < 6; i++) {
01146 if(mpeg4_decode_block(s, block[i], i, cbp&32, s->mb_intra, s->rvlc) < 0){
01147 av_log(s->avctx, AV_LOG_ERROR, "texture corrupted at %d %d %d\n", s->mb_x, s->mb_y, s->mb_intra);
01148 return -1;
01149 }
01150 cbp+=cbp;
01151 }
01152 }
01153
01154
01155
01156 if(--s->mb_num_left <= 0){
01157 if(mpeg4_is_resync(s))
01158 return SLICE_END;
01159 else
01160 return SLICE_NOEND;
01161 }else{
01162 if(mpeg4_is_resync(s)){
01163 const int delta= s->mb_x + 1 == s->mb_width ? 2 : 1;
01164 if(s->cbp_table[xy+delta])
01165 return SLICE_END;
01166 }
01167 return SLICE_OK;
01168 }
01169 }
01170
01171 static int mpeg4_decode_mb(MpegEncContext *s,
01172 DCTELEM block[6][64])
01173 {
01174 int cbpc, cbpy, i, cbp, pred_x, pred_y, mx, my, dquant;
01175 int16_t *mot_val;
01176 static int8_t quant_tab[4] = { -1, -2, 1, 2 };
01177 const int xy= s->mb_x + s->mb_y * s->mb_stride;
01178
01179 assert(s->h263_pred);
01180
01181 if (s->pict_type == AV_PICTURE_TYPE_P || s->pict_type==AV_PICTURE_TYPE_S) {
01182 do{
01183 if (get_bits1(&s->gb)) {
01184
01185 s->mb_intra = 0;
01186 for(i=0;i<6;i++)
01187 s->block_last_index[i] = -1;
01188 s->mv_dir = MV_DIR_FORWARD;
01189 s->mv_type = MV_TYPE_16X16;
01190 if(s->pict_type==AV_PICTURE_TYPE_S && s->vol_sprite_usage==GMC_SPRITE){
01191 s->current_picture.mb_type[xy]= MB_TYPE_SKIP | MB_TYPE_GMC | MB_TYPE_16x16 | MB_TYPE_L0;
01192 s->mcsel=1;
01193 s->mv[0][0][0]= get_amv(s, 0);
01194 s->mv[0][0][1]= get_amv(s, 1);
01195
01196 s->mb_skipped = 0;
01197 }else{
01198 s->current_picture.mb_type[xy]= MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0;
01199 s->mcsel=0;
01200 s->mv[0][0][0] = 0;
01201 s->mv[0][0][1] = 0;
01202 s->mb_skipped = 1;
01203 }
01204 goto end;
01205 }
01206 cbpc = get_vlc2(&s->gb, ff_h263_inter_MCBPC_vlc.table, INTER_MCBPC_VLC_BITS, 2);
01207 if (cbpc < 0){
01208 av_log(s->avctx, AV_LOG_ERROR, "cbpc damaged at %d %d\n", s->mb_x, s->mb_y);
01209 return -1;
01210 }
01211 }while(cbpc == 20);
01212
01213 s->dsp.clear_blocks(s->block[0]);
01214 dquant = cbpc & 8;
01215 s->mb_intra = ((cbpc & 4) != 0);
01216 if (s->mb_intra) goto intra;
01217
01218 if(s->pict_type==AV_PICTURE_TYPE_S && s->vol_sprite_usage==GMC_SPRITE && (cbpc & 16) == 0)
01219 s->mcsel= get_bits1(&s->gb);
01220 else s->mcsel= 0;
01221 cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1) ^ 0x0F;
01222
01223 cbp = (cbpc & 3) | (cbpy << 2);
01224 if (dquant) {
01225 ff_set_qscale(s, s->qscale + quant_tab[get_bits(&s->gb, 2)]);
01226 }
01227 if((!s->progressive_sequence) && (cbp || (s->workaround_bugs&FF_BUG_XVID_ILACE)))
01228 s->interlaced_dct= get_bits1(&s->gb);
01229
01230 s->mv_dir = MV_DIR_FORWARD;
01231 if ((cbpc & 16) == 0) {
01232 if(s->mcsel){
01233 s->current_picture.mb_type[xy]= MB_TYPE_GMC | MB_TYPE_16x16 | MB_TYPE_L0;
01234
01235 s->mv_type = MV_TYPE_16X16;
01236 mx= get_amv(s, 0);
01237 my= get_amv(s, 1);
01238 s->mv[0][0][0] = mx;
01239 s->mv[0][0][1] = my;
01240 }else if((!s->progressive_sequence) && get_bits1(&s->gb)){
01241 s->current_picture.mb_type[xy]= MB_TYPE_16x8 | MB_TYPE_L0 | MB_TYPE_INTERLACED;
01242
01243 s->mv_type= MV_TYPE_FIELD;
01244
01245 s->field_select[0][0]= get_bits1(&s->gb);
01246 s->field_select[0][1]= get_bits1(&s->gb);
01247
01248 h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
01249
01250 for(i=0; i<2; i++){
01251 mx = h263_decode_motion(s, pred_x, s->f_code);
01252 if (mx >= 0xffff)
01253 return -1;
01254
01255 my = h263_decode_motion(s, pred_y/2, s->f_code);
01256 if (my >= 0xffff)
01257 return -1;
01258
01259 s->mv[0][i][0] = mx;
01260 s->mv[0][i][1] = my;
01261 }
01262 }else{
01263 s->current_picture.mb_type[xy]= MB_TYPE_16x16 | MB_TYPE_L0;
01264
01265 s->mv_type = MV_TYPE_16X16;
01266 h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
01267 mx = h263_decode_motion(s, pred_x, s->f_code);
01268
01269 if (mx >= 0xffff)
01270 return -1;
01271
01272 my = h263_decode_motion(s, pred_y, s->f_code);
01273
01274 if (my >= 0xffff)
01275 return -1;
01276 s->mv[0][0][0] = mx;
01277 s->mv[0][0][1] = my;
01278 }
01279 } else {
01280 s->current_picture.mb_type[xy]= MB_TYPE_8x8 | MB_TYPE_L0;
01281 s->mv_type = MV_TYPE_8X8;
01282 for(i=0;i<4;i++) {
01283 mot_val = h263_pred_motion(s, i, 0, &pred_x, &pred_y);
01284 mx = h263_decode_motion(s, pred_x, s->f_code);
01285 if (mx >= 0xffff)
01286 return -1;
01287
01288 my = h263_decode_motion(s, pred_y, s->f_code);
01289 if (my >= 0xffff)
01290 return -1;
01291 s->mv[0][i][0] = mx;
01292 s->mv[0][i][1] = my;
01293 mot_val[0] = mx;
01294 mot_val[1] = my;
01295 }
01296 }
01297 } else if(s->pict_type==AV_PICTURE_TYPE_B) {
01298 int modb1;
01299 int modb2;
01300 int mb_type;
01301
01302 s->mb_intra = 0;
01303 s->mcsel=0;
01304
01305 if(s->mb_x==0){
01306 for(i=0; i<2; i++){
01307 s->last_mv[i][0][0]=
01308 s->last_mv[i][0][1]=
01309 s->last_mv[i][1][0]=
01310 s->last_mv[i][1][1]= 0;
01311 }
01312
01313 ff_thread_await_progress((AVFrame*)s->next_picture_ptr, s->mb_y, 0);
01314 }
01315
01316
01317 s->mb_skipped= s->next_picture.mbskip_table[s->mb_y * s->mb_stride + s->mb_x];
01318
01319 if(s->mb_skipped){
01320
01321 for(i=0;i<6;i++)
01322 s->block_last_index[i] = -1;
01323
01324 s->mv_dir = MV_DIR_FORWARD;
01325 s->mv_type = MV_TYPE_16X16;
01326 s->mv[0][0][0] = 0;
01327 s->mv[0][0][1] = 0;
01328 s->mv[1][0][0] = 0;
01329 s->mv[1][0][1] = 0;
01330 s->current_picture.mb_type[xy]= MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0;
01331 goto end;
01332 }
01333
01334 modb1= get_bits1(&s->gb);
01335 if(modb1){
01336 mb_type= MB_TYPE_DIRECT2 | MB_TYPE_SKIP | MB_TYPE_L0L1;
01337 cbp=0;
01338 }else{
01339 modb2= get_bits1(&s->gb);
01340 mb_type= get_vlc2(&s->gb, mb_type_b_vlc.table, MB_TYPE_B_VLC_BITS, 1);
01341 if(mb_type<0){
01342 av_log(s->avctx, AV_LOG_ERROR, "illegal MB_type\n");
01343 return -1;
01344 }
01345 mb_type= mb_type_b_map[ mb_type ];
01346 if(modb2) cbp= 0;
01347 else{
01348 s->dsp.clear_blocks(s->block[0]);
01349 cbp= get_bits(&s->gb, 6);
01350 }
01351
01352 if ((!IS_DIRECT(mb_type)) && cbp) {
01353 if(get_bits1(&s->gb)){
01354 ff_set_qscale(s, s->qscale + get_bits1(&s->gb)*4 - 2);
01355 }
01356 }
01357
01358 if(!s->progressive_sequence){
01359 if(cbp)
01360 s->interlaced_dct= get_bits1(&s->gb);
01361
01362 if(!IS_DIRECT(mb_type) && get_bits1(&s->gb)){
01363 mb_type |= MB_TYPE_16x8 | MB_TYPE_INTERLACED;
01364 mb_type &= ~MB_TYPE_16x16;
01365
01366 if(USES_LIST(mb_type, 0)){
01367 s->field_select[0][0]= get_bits1(&s->gb);
01368 s->field_select[0][1]= get_bits1(&s->gb);
01369 }
01370 if(USES_LIST(mb_type, 1)){
01371 s->field_select[1][0]= get_bits1(&s->gb);
01372 s->field_select[1][1]= get_bits1(&s->gb);
01373 }
01374 }
01375 }
01376
01377 s->mv_dir = 0;
01378 if((mb_type & (MB_TYPE_DIRECT2|MB_TYPE_INTERLACED)) == 0){
01379 s->mv_type= MV_TYPE_16X16;
01380
01381 if(USES_LIST(mb_type, 0)){
01382 s->mv_dir = MV_DIR_FORWARD;
01383
01384 mx = h263_decode_motion(s, s->last_mv[0][0][0], s->f_code);
01385 my = h263_decode_motion(s, s->last_mv[0][0][1], s->f_code);
01386 s->last_mv[0][1][0]= s->last_mv[0][0][0]= s->mv[0][0][0] = mx;
01387 s->last_mv[0][1][1]= s->last_mv[0][0][1]= s->mv[0][0][1] = my;
01388 }
01389
01390 if(USES_LIST(mb_type, 1)){
01391 s->mv_dir |= MV_DIR_BACKWARD;
01392
01393 mx = h263_decode_motion(s, s->last_mv[1][0][0], s->b_code);
01394 my = h263_decode_motion(s, s->last_mv[1][0][1], s->b_code);
01395 s->last_mv[1][1][0]= s->last_mv[1][0][0]= s->mv[1][0][0] = mx;
01396 s->last_mv[1][1][1]= s->last_mv[1][0][1]= s->mv[1][0][1] = my;
01397 }
01398 }else if(!IS_DIRECT(mb_type)){
01399 s->mv_type= MV_TYPE_FIELD;
01400
01401 if(USES_LIST(mb_type, 0)){
01402 s->mv_dir = MV_DIR_FORWARD;
01403
01404 for(i=0; i<2; i++){
01405 mx = h263_decode_motion(s, s->last_mv[0][i][0] , s->f_code);
01406 my = h263_decode_motion(s, s->last_mv[0][i][1]/2, s->f_code);
01407 s->last_mv[0][i][0]= s->mv[0][i][0] = mx;
01408 s->last_mv[0][i][1]= (s->mv[0][i][1] = my)*2;
01409 }
01410 }
01411
01412 if(USES_LIST(mb_type, 1)){
01413 s->mv_dir |= MV_DIR_BACKWARD;
01414
01415 for(i=0; i<2; i++){
01416 mx = h263_decode_motion(s, s->last_mv[1][i][0] , s->b_code);
01417 my = h263_decode_motion(s, s->last_mv[1][i][1]/2, s->b_code);
01418 s->last_mv[1][i][0]= s->mv[1][i][0] = mx;
01419 s->last_mv[1][i][1]= (s->mv[1][i][1] = my)*2;
01420 }
01421 }
01422 }
01423 }
01424
01425 if(IS_DIRECT(mb_type)){
01426 if(IS_SKIP(mb_type))
01427 mx=my=0;
01428 else{
01429 mx = h263_decode_motion(s, 0, 1);
01430 my = h263_decode_motion(s, 0, 1);
01431 }
01432
01433 s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT;
01434 mb_type |= ff_mpeg4_set_direct_mv(s, mx, my);
01435 }
01436 s->current_picture.mb_type[xy]= mb_type;
01437 } else {
01438 do{
01439 cbpc = get_vlc2(&s->gb, ff_h263_intra_MCBPC_vlc.table, INTRA_MCBPC_VLC_BITS, 2);
01440 if (cbpc < 0){
01441 av_log(s->avctx, AV_LOG_ERROR, "I cbpc damaged at %d %d\n", s->mb_x, s->mb_y);
01442 return -1;
01443 }
01444 }while(cbpc == 8);
01445
01446 dquant = cbpc & 4;
01447 s->mb_intra = 1;
01448 intra:
01449 s->ac_pred = get_bits1(&s->gb);
01450 if(s->ac_pred)
01451 s->current_picture.mb_type[xy]= MB_TYPE_INTRA | MB_TYPE_ACPRED;
01452 else
01453 s->current_picture.mb_type[xy]= MB_TYPE_INTRA;
01454
01455 cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1);
01456 if(cbpy<0){
01457 av_log(s->avctx, AV_LOG_ERROR, "I cbpy damaged at %d %d\n", s->mb_x, s->mb_y);
01458 return -1;
01459 }
01460 cbp = (cbpc & 3) | (cbpy << 2);
01461
01462 s->use_intra_dc_vlc= s->qscale < s->intra_dc_threshold;
01463
01464 if (dquant) {
01465 ff_set_qscale(s, s->qscale + quant_tab[get_bits(&s->gb, 2)]);
01466 }
01467
01468 if(!s->progressive_sequence)
01469 s->interlaced_dct= get_bits1(&s->gb);
01470
01471 s->dsp.clear_blocks(s->block[0]);
01472
01473 for (i = 0; i < 6; i++) {
01474 if (mpeg4_decode_block(s, block[i], i, cbp&32, 1, 0) < 0)
01475 return -1;
01476 cbp+=cbp;
01477 }
01478 goto end;
01479 }
01480
01481
01482 for (i = 0; i < 6; i++) {
01483 if (mpeg4_decode_block(s, block[i], i, cbp&32, 0, 0) < 0)
01484 return -1;
01485 cbp+=cbp;
01486 }
01487 end:
01488
01489
01490 if(s->codec_id==CODEC_ID_MPEG4){
01491 if(mpeg4_is_resync(s)){
01492 const int delta= s->mb_x + 1 == s->mb_width ? 2 : 1;
01493
01494 if(s->pict_type==AV_PICTURE_TYPE_B){
01495 ff_thread_await_progress((AVFrame*)s->next_picture_ptr,
01496 (s->mb_x + delta >= s->mb_width) ? FFMIN(s->mb_y+1, s->mb_height-1) : s->mb_y, 0);
01497 }
01498
01499 if(s->pict_type==AV_PICTURE_TYPE_B && s->next_picture.mbskip_table[xy + delta])
01500 return SLICE_OK;
01501 return SLICE_END;
01502 }
01503 }
01504
01505 return SLICE_OK;
01506 }
01507
01508
01509 static int mpeg4_decode_gop_header(MpegEncContext * s, GetBitContext *gb){
01510 int hours, minutes, seconds;
01511
01512 if(!show_bits(gb, 23)){
01513 av_log(s->avctx, AV_LOG_WARNING, "GOP header invalid\n");
01514 return -1;
01515 }
01516
01517 hours= get_bits(gb, 5);
01518 minutes= get_bits(gb, 6);
01519 skip_bits1(gb);
01520 seconds= get_bits(gb, 6);
01521
01522 s->time_base= seconds + 60*(minutes + 60*hours);
01523
01524 skip_bits1(gb);
01525 skip_bits1(gb);
01526
01527 return 0;
01528 }
01529
01530 static int decode_vol_header(MpegEncContext *s, GetBitContext *gb){
01531 int width, height, vo_ver_id;
01532
01533
01534 skip_bits(gb, 1);
01535 s->vo_type= get_bits(gb, 8);
01536 if (get_bits1(gb) != 0) {
01537 vo_ver_id = get_bits(gb, 4);
01538 skip_bits(gb, 3);
01539 } else {
01540 vo_ver_id = 1;
01541 }
01542 s->aspect_ratio_info= get_bits(gb, 4);
01543 if(s->aspect_ratio_info == FF_ASPECT_EXTENDED){
01544 s->avctx->sample_aspect_ratio.num= get_bits(gb, 8);
01545 s->avctx->sample_aspect_ratio.den= get_bits(gb, 8);
01546 }else{
01547 s->avctx->sample_aspect_ratio= ff_h263_pixel_aspect[s->aspect_ratio_info];
01548 }
01549
01550 if ((s->vol_control_parameters=get_bits1(gb))) {
01551 int chroma_format= get_bits(gb, 2);
01552 if(chroma_format!=CHROMA_420){
01553 av_log(s->avctx, AV_LOG_ERROR, "illegal chroma format\n");
01554 }
01555 s->low_delay= get_bits1(gb);
01556 if(get_bits1(gb)){
01557 get_bits(gb, 15);
01558 skip_bits1(gb);
01559 get_bits(gb, 15);
01560 skip_bits1(gb);
01561 get_bits(gb, 15);
01562 skip_bits1(gb);
01563 get_bits(gb, 3);
01564 get_bits(gb, 11);
01565 skip_bits1(gb);
01566 get_bits(gb, 15);
01567 skip_bits1(gb);
01568 }
01569 }else{
01570
01571 if(s->picture_number==0)
01572 s->low_delay=0;
01573 }
01574
01575 s->shape = get_bits(gb, 2);
01576 if(s->shape != RECT_SHAPE) av_log(s->avctx, AV_LOG_ERROR, "only rectangular vol supported\n");
01577 if(s->shape == GRAY_SHAPE && vo_ver_id != 1){
01578 av_log(s->avctx, AV_LOG_ERROR, "Gray shape not supported\n");
01579 skip_bits(gb, 4);
01580 }
01581
01582 check_marker(gb, "before time_increment_resolution");
01583
01584 s->avctx->time_base.den = get_bits(gb, 16);
01585 if(!s->avctx->time_base.den){
01586 av_log(s->avctx, AV_LOG_ERROR, "time_base.den==0\n");
01587 s->avctx->time_base.num = 0;
01588 return -1;
01589 }
01590
01591 s->time_increment_bits = av_log2(s->avctx->time_base.den - 1) + 1;
01592 if (s->time_increment_bits < 1)
01593 s->time_increment_bits = 1;
01594
01595 check_marker(gb, "before fixed_vop_rate");
01596
01597 if (get_bits1(gb) != 0) {
01598 s->avctx->time_base.num = get_bits(gb, s->time_increment_bits);
01599 }else
01600 s->avctx->time_base.num = 1;
01601
01602 s->t_frame=0;
01603
01604 if (s->shape != BIN_ONLY_SHAPE) {
01605 if (s->shape == RECT_SHAPE) {
01606 skip_bits1(gb);
01607 width = get_bits(gb, 13);
01608 skip_bits1(gb);
01609 height = get_bits(gb, 13);
01610 skip_bits1(gb);
01611 if(width && height && !(s->width && s->codec_tag == AV_RL32("MP4S"))){
01612 s->width = width;
01613 s->height = height;
01614 }
01615 }
01616
01617 s->progressive_sequence=
01618 s->progressive_frame= get_bits1(gb)^1;
01619 s->interlaced_dct=0;
01620 if(!get_bits1(gb) && (s->avctx->debug & FF_DEBUG_PICT_INFO))
01621 av_log(s->avctx, AV_LOG_INFO, "MPEG4 OBMC not supported (very likely buggy encoder)\n");
01622 if (vo_ver_id == 1) {
01623 s->vol_sprite_usage = get_bits1(gb);
01624 } else {
01625 s->vol_sprite_usage = get_bits(gb, 2);
01626 }
01627 if(s->vol_sprite_usage==STATIC_SPRITE) av_log(s->avctx, AV_LOG_ERROR, "Static Sprites not supported\n");
01628 if(s->vol_sprite_usage==STATIC_SPRITE || s->vol_sprite_usage==GMC_SPRITE){
01629 if(s->vol_sprite_usage==STATIC_SPRITE){
01630 s->sprite_width = get_bits(gb, 13);
01631 skip_bits1(gb);
01632 s->sprite_height= get_bits(gb, 13);
01633 skip_bits1(gb);
01634 s->sprite_left = get_bits(gb, 13);
01635 skip_bits1(gb);
01636 s->sprite_top = get_bits(gb, 13);
01637 skip_bits1(gb);
01638 }
01639 s->num_sprite_warping_points= get_bits(gb, 6);
01640 if(s->num_sprite_warping_points > 3){
01641 av_log(s->avctx, AV_LOG_ERROR, "%d sprite_warping_points\n", s->num_sprite_warping_points);
01642 s->num_sprite_warping_points= 0;
01643 return -1;
01644 }
01645 s->sprite_warping_accuracy = get_bits(gb, 2);
01646 s->sprite_brightness_change= get_bits1(gb);
01647 if(s->vol_sprite_usage==STATIC_SPRITE)
01648 s->low_latency_sprite= get_bits1(gb);
01649 }
01650
01651
01652 if (get_bits1(gb) == 1) {
01653 s->quant_precision = get_bits(gb, 4);
01654 if(get_bits(gb, 4)!=8) av_log(s->avctx, AV_LOG_ERROR, "N-bit not supported\n");
01655 if(s->quant_precision!=5) av_log(s->avctx, AV_LOG_ERROR, "quant precision %d\n", s->quant_precision);
01656 } else {
01657 s->quant_precision = 5;
01658 }
01659
01660
01661
01662 if((s->mpeg_quant=get_bits1(gb))){
01663 int i, v;
01664
01665
01666 for(i=0; i<64; i++){
01667 int j= s->dsp.idct_permutation[i];
01668 v= ff_mpeg4_default_intra_matrix[i];
01669 s->intra_matrix[j]= v;
01670 s->chroma_intra_matrix[j]= v;
01671
01672 v= ff_mpeg4_default_non_intra_matrix[i];
01673 s->inter_matrix[j]= v;
01674 s->chroma_inter_matrix[j]= v;
01675 }
01676
01677
01678 if(get_bits1(gb)){
01679 int last=0;
01680 for(i=0; i<64; i++){
01681 int j;
01682 v= get_bits(gb, 8);
01683 if(v==0) break;
01684
01685 last= v;
01686 j= s->dsp.idct_permutation[ ff_zigzag_direct[i] ];
01687 s->intra_matrix[j]= v;
01688 s->chroma_intra_matrix[j]= v;
01689 }
01690
01691
01692 for(; i<64; i++){
01693 int j= s->dsp.idct_permutation[ ff_zigzag_direct[i] ];
01694 s->intra_matrix[j]= last;
01695 s->chroma_intra_matrix[j]= last;
01696 }
01697 }
01698
01699
01700 if(get_bits1(gb)){
01701 int last=0;
01702 for(i=0; i<64; i++){
01703 int j;
01704 v= get_bits(gb, 8);
01705 if(v==0) break;
01706
01707 last= v;
01708 j= s->dsp.idct_permutation[ ff_zigzag_direct[i] ];
01709 s->inter_matrix[j]= v;
01710 s->chroma_inter_matrix[j]= v;
01711 }
01712
01713
01714 for(; i<64; i++){
01715 int j= s->dsp.idct_permutation[ ff_zigzag_direct[i] ];
01716 s->inter_matrix[j]= last;
01717 s->chroma_inter_matrix[j]= last;
01718 }
01719 }
01720
01721
01722 }
01723
01724 if(vo_ver_id != 1)
01725 s->quarter_sample= get_bits1(gb);
01726 else s->quarter_sample=0;
01727
01728 if(!get_bits1(gb)){
01729 int pos= get_bits_count(gb);
01730 int estimation_method= get_bits(gb, 2);
01731 if(estimation_method<2){
01732 if(!get_bits1(gb)){
01733 s->cplx_estimation_trash_i += 8*get_bits1(gb);
01734 s->cplx_estimation_trash_i += 8*get_bits1(gb);
01735 s->cplx_estimation_trash_i += 8*get_bits1(gb);
01736 s->cplx_estimation_trash_i += 8*get_bits1(gb);
01737 s->cplx_estimation_trash_i += 8*get_bits1(gb);
01738 s->cplx_estimation_trash_i += 8*get_bits1(gb);
01739 }
01740 if(!get_bits1(gb)){
01741 s->cplx_estimation_trash_i += 8*get_bits1(gb);
01742 s->cplx_estimation_trash_p += 8*get_bits1(gb);
01743 s->cplx_estimation_trash_p += 8*get_bits1(gb);
01744 s->cplx_estimation_trash_i += 8*get_bits1(gb);
01745 }
01746 if(!check_marker(gb, "in complexity estimation part 1")){
01747 skip_bits_long(gb, pos - get_bits_count(gb));
01748 goto no_cplx_est;
01749 }
01750 if(!get_bits1(gb)){
01751 s->cplx_estimation_trash_i += 8*get_bits1(gb);
01752 s->cplx_estimation_trash_i += 8*get_bits1(gb);
01753 s->cplx_estimation_trash_i += 8*get_bits1(gb);
01754 s->cplx_estimation_trash_i += 4*get_bits1(gb);
01755 }
01756 if(!get_bits1(gb)){
01757 s->cplx_estimation_trash_p += 8*get_bits1(gb);
01758 s->cplx_estimation_trash_p += 8*get_bits1(gb);
01759 s->cplx_estimation_trash_b += 8*get_bits1(gb);
01760 s->cplx_estimation_trash_p += 8*get_bits1(gb);
01761 s->cplx_estimation_trash_p += 8*get_bits1(gb);
01762 s->cplx_estimation_trash_p += 8*get_bits1(gb);
01763 }
01764 if(!check_marker(gb, "in complexity estimation part 2")){
01765 skip_bits_long(gb, pos - get_bits_count(gb));
01766 goto no_cplx_est;
01767 }
01768 if(estimation_method==1){
01769 s->cplx_estimation_trash_i += 8*get_bits1(gb);
01770 s->cplx_estimation_trash_p += 8*get_bits1(gb);
01771 }
01772 }else
01773 av_log(s->avctx, AV_LOG_ERROR, "Invalid Complexity estimation method %d\n", estimation_method);
01774 }else{
01775 no_cplx_est:
01776 s->cplx_estimation_trash_i=
01777 s->cplx_estimation_trash_p=
01778 s->cplx_estimation_trash_b= 0;
01779 }
01780
01781 s->resync_marker= !get_bits1(gb);
01782
01783 s->data_partitioning= get_bits1(gb);
01784 if(s->data_partitioning){
01785 s->rvlc= get_bits1(gb);
01786 }
01787
01788 if(vo_ver_id != 1) {
01789 s->new_pred= get_bits1(gb);
01790 if(s->new_pred){
01791 av_log(s->avctx, AV_LOG_ERROR, "new pred not supported\n");
01792 skip_bits(gb, 2);
01793 skip_bits1(gb);
01794 }
01795 s->reduced_res_vop= get_bits1(gb);
01796 if(s->reduced_res_vop) av_log(s->avctx, AV_LOG_ERROR, "reduced resolution VOP not supported\n");
01797 }
01798 else{
01799 s->new_pred=0;
01800 s->reduced_res_vop= 0;
01801 }
01802
01803 s->scalability= get_bits1(gb);
01804
01805 if (s->scalability) {
01806 GetBitContext bak= *gb;
01807 int h_sampling_factor_n;
01808 int h_sampling_factor_m;
01809 int v_sampling_factor_n;
01810 int v_sampling_factor_m;
01811
01812 s->hierachy_type= get_bits1(gb);
01813 skip_bits(gb, 4);
01814 skip_bits1(gb);
01815 h_sampling_factor_n= get_bits(gb, 5);
01816 h_sampling_factor_m= get_bits(gb, 5);
01817 v_sampling_factor_n= get_bits(gb, 5);
01818 v_sampling_factor_m= get_bits(gb, 5);
01819 s->enhancement_type= get_bits1(gb);
01820
01821 if( h_sampling_factor_n==0 || h_sampling_factor_m==0
01822 || v_sampling_factor_n==0 || v_sampling_factor_m==0){
01823
01824
01825 s->scalability=0;
01826 *gb= bak;
01827 }else
01828 av_log(s->avctx, AV_LOG_ERROR, "scalability not supported\n");
01829
01830
01831 }
01832 }
01833 return 0;
01834 }
01835
01840 static int decode_user_data(MpegEncContext *s, GetBitContext *gb){
01841 char buf[256];
01842 int i;
01843 int e;
01844 int ver = 0, build = 0, ver2 = 0, ver3 = 0;
01845 char last;
01846
01847 for(i=0; i<255 && get_bits_count(gb) < gb->size_in_bits; i++){
01848 if(show_bits(gb, 23) == 0) break;
01849 buf[i]= get_bits(gb, 8);
01850 }
01851 buf[i]=0;
01852
01853
01854 e=sscanf(buf, "DivX%dBuild%d%c", &ver, &build, &last);
01855 if(e<2)
01856 e=sscanf(buf, "DivX%db%d%c", &ver, &build, &last);
01857 if(e>=2){
01858 s->divx_version= ver;
01859 s->divx_build= build;
01860 s->divx_packed= e==3 && last=='p';
01861 if(s->divx_packed && !s->showed_packed_warning) {
01862 av_log(s->avctx, AV_LOG_WARNING, "Invalid and inefficient vfw-avi packed B frames detected\n");
01863 s->showed_packed_warning=1;
01864 }
01865 }
01866
01867
01868 e=sscanf(buf, "FFmpe%*[^b]b%d", &build)+3;
01869 if(e!=4)
01870 e=sscanf(buf, "FFmpeg v%d.%d.%d / libavcodec build: %d", &ver, &ver2, &ver3, &build);
01871 if(e!=4){
01872 e=sscanf(buf, "Lavc%d.%d.%d", &ver, &ver2, &ver3)+1;
01873 if (e>1)
01874 build= (ver<<16) + (ver2<<8) + ver3;
01875 }
01876 if(e!=4){
01877 if(strcmp(buf, "ffmpeg")==0){
01878 s->lavc_build= 4600;
01879 }
01880 }
01881 if(e==4){
01882 s->lavc_build= build;
01883 }
01884
01885
01886 e=sscanf(buf, "XviD%d", &build);
01887 if(e==1){
01888 s->xvid_build= build;
01889 }
01890
01891 return 0;
01892 }
01893
01894 static int decode_vop_header(MpegEncContext *s, GetBitContext *gb){
01895 int time_incr, time_increment;
01896
01897 s->pict_type = get_bits(gb, 2) + AV_PICTURE_TYPE_I;
01898 if(s->pict_type==AV_PICTURE_TYPE_B && s->low_delay && s->vol_control_parameters==0 && !(s->flags & CODEC_FLAG_LOW_DELAY)){
01899 av_log(s->avctx, AV_LOG_ERROR, "low_delay flag incorrectly, clearing it\n");
01900 s->low_delay=0;
01901 }
01902
01903 s->partitioned_frame= s->data_partitioning && s->pict_type!=AV_PICTURE_TYPE_B;
01904 if(s->partitioned_frame)
01905 s->decode_mb= mpeg4_decode_partitioned_mb;
01906 else
01907 s->decode_mb= mpeg4_decode_mb;
01908
01909 time_incr=0;
01910 while (get_bits1(gb) != 0)
01911 time_incr++;
01912
01913 check_marker(gb, "before time_increment");
01914
01915 if(s->time_increment_bits==0 || !(show_bits(gb, s->time_increment_bits+1)&1)){
01916 av_log(s->avctx, AV_LOG_ERROR, "hmm, seems the headers are not complete, trying to guess time_increment_bits\n");
01917
01918 for(s->time_increment_bits=1 ;s->time_increment_bits<16; s->time_increment_bits++){
01919 if ( s->pict_type == AV_PICTURE_TYPE_P
01920 || (s->pict_type == AV_PICTURE_TYPE_S && s->vol_sprite_usage==GMC_SPRITE)) {
01921 if((show_bits(gb, s->time_increment_bits+6)&0x37) == 0x30) break;
01922 }else
01923 if((show_bits(gb, s->time_increment_bits+5)&0x1F) == 0x18) break;
01924 }
01925
01926 av_log(s->avctx, AV_LOG_ERROR, "my guess is %d bits ;)\n",s->time_increment_bits);
01927 }
01928
01929 if(IS_3IV1) time_increment= get_bits1(gb);
01930 else time_increment= get_bits(gb, s->time_increment_bits);
01931
01932 if(s->pict_type!=AV_PICTURE_TYPE_B){
01933 s->last_time_base= s->time_base;
01934 s->time_base+= time_incr;
01935 s->time= s->time_base*s->avctx->time_base.den + time_increment;
01936 if(s->workaround_bugs&FF_BUG_UMP4){
01937 if(s->time < s->last_non_b_time){
01938
01939
01940 s->time_base++;
01941 s->time+= s->avctx->time_base.den;
01942 }
01943 }
01944 s->pp_time= s->time - s->last_non_b_time;
01945 s->last_non_b_time= s->time;
01946 }else{
01947 s->time= (s->last_time_base + time_incr)*s->avctx->time_base.den + time_increment;
01948 s->pb_time= s->pp_time - (s->last_non_b_time - s->time);
01949 if(s->pp_time <=s->pb_time || s->pp_time <= s->pp_time - s->pb_time || s->pp_time<=0){
01950
01951 return FRAME_SKIPPED;
01952 }
01953 ff_mpeg4_init_direct_mv(s);
01954
01955 if(s->t_frame==0) s->t_frame= s->pb_time;
01956 if(s->t_frame==0) s->t_frame=1;
01957 s->pp_field_time= ( ROUNDED_DIV(s->last_non_b_time, s->t_frame)
01958 - ROUNDED_DIV(s->last_non_b_time - s->pp_time, s->t_frame))*2;
01959 s->pb_field_time= ( ROUNDED_DIV(s->time, s->t_frame)
01960 - ROUNDED_DIV(s->last_non_b_time - s->pp_time, s->t_frame))*2;
01961 if(!s->progressive_sequence){
01962 if(s->pp_field_time <= s->pb_field_time || s->pb_field_time <= 1)
01963 return FRAME_SKIPPED;
01964 }
01965 }
01966
01967 if(s->avctx->time_base.num)
01968 s->current_picture_ptr->pts= (s->time + s->avctx->time_base.num/2) / s->avctx->time_base.num;
01969 else
01970 s->current_picture_ptr->pts= AV_NOPTS_VALUE;
01971 if(s->avctx->debug&FF_DEBUG_PTS)
01972 av_log(s->avctx, AV_LOG_DEBUG, "MPEG4 PTS: %"PRId64"\n", s->current_picture_ptr->pts);
01973
01974 check_marker(gb, "before vop_coded");
01975
01976
01977 if (get_bits1(gb) != 1){
01978 if(s->avctx->debug&FF_DEBUG_PICT_INFO)
01979 av_log(s->avctx, AV_LOG_ERROR, "vop not coded\n");
01980 return FRAME_SKIPPED;
01981 }
01982 if (s->shape != BIN_ONLY_SHAPE && ( s->pict_type == AV_PICTURE_TYPE_P
01983 || (s->pict_type == AV_PICTURE_TYPE_S && s->vol_sprite_usage==GMC_SPRITE))) {
01984
01985 s->no_rounding = get_bits1(gb);
01986 } else {
01987 s->no_rounding = 0;
01988 }
01989
01990
01991 if (s->shape != RECT_SHAPE) {
01992 if (s->vol_sprite_usage != 1 || s->pict_type != AV_PICTURE_TYPE_I) {
01993 skip_bits(gb, 13);
01994 skip_bits1(gb);
01995 skip_bits(gb, 13);
01996 skip_bits1(gb);
01997 skip_bits(gb, 13);
01998 skip_bits1(gb);
01999 skip_bits(gb, 13);
02000 }
02001 skip_bits1(gb);
02002
02003 if (get_bits1(gb) != 0) {
02004 skip_bits(gb, 8);
02005 }
02006 }
02007
02008
02009 if (s->shape != BIN_ONLY_SHAPE) {
02010 skip_bits_long(gb, s->cplx_estimation_trash_i);
02011 if(s->pict_type != AV_PICTURE_TYPE_I)
02012 skip_bits_long(gb, s->cplx_estimation_trash_p);
02013 if(s->pict_type == AV_PICTURE_TYPE_B)
02014 skip_bits_long(gb, s->cplx_estimation_trash_b);
02015
02016 s->intra_dc_threshold= mpeg4_dc_threshold[ get_bits(gb, 3) ];
02017 if(!s->progressive_sequence){
02018 s->top_field_first= get_bits1(gb);
02019 s->alternate_scan= get_bits1(gb);
02020 }else
02021 s->alternate_scan= 0;
02022 }
02023
02024 if(s->alternate_scan){
02025 ff_init_scantable(s->dsp.idct_permutation, &s->inter_scantable , ff_alternate_vertical_scan);
02026 ff_init_scantable(s->dsp.idct_permutation, &s->intra_scantable , ff_alternate_vertical_scan);
02027 ff_init_scantable(s->dsp.idct_permutation, &s->intra_h_scantable, ff_alternate_vertical_scan);
02028 ff_init_scantable(s->dsp.idct_permutation, &s->intra_v_scantable, ff_alternate_vertical_scan);
02029 } else{
02030 ff_init_scantable(s->dsp.idct_permutation, &s->inter_scantable , ff_zigzag_direct);
02031 ff_init_scantable(s->dsp.idct_permutation, &s->intra_scantable , ff_zigzag_direct);
02032 ff_init_scantable(s->dsp.idct_permutation, &s->intra_h_scantable, ff_alternate_horizontal_scan);
02033 ff_init_scantable(s->dsp.idct_permutation, &s->intra_v_scantable, ff_alternate_vertical_scan);
02034 }
02035
02036 if(s->pict_type == AV_PICTURE_TYPE_S && (s->vol_sprite_usage==STATIC_SPRITE || s->vol_sprite_usage==GMC_SPRITE)){
02037 mpeg4_decode_sprite_trajectory(s, gb);
02038 if(s->sprite_brightness_change) av_log(s->avctx, AV_LOG_ERROR, "sprite_brightness_change not supported\n");
02039 if(s->vol_sprite_usage==STATIC_SPRITE) av_log(s->avctx, AV_LOG_ERROR, "static sprite not supported\n");
02040 }
02041
02042 if (s->shape != BIN_ONLY_SHAPE) {
02043 s->chroma_qscale= s->qscale = get_bits(gb, s->quant_precision);
02044 if(s->qscale==0){
02045 av_log(s->avctx, AV_LOG_ERROR, "Error, header damaged or not MPEG4 header (qscale=0)\n");
02046 return -1;
02047 }
02048
02049 if (s->pict_type != AV_PICTURE_TYPE_I) {
02050 s->f_code = get_bits(gb, 3);
02051 if(s->f_code==0){
02052 av_log(s->avctx, AV_LOG_ERROR, "Error, header damaged or not MPEG4 header (f_code=0)\n");
02053 return -1;
02054 }
02055 }else
02056 s->f_code=1;
02057
02058 if (s->pict_type == AV_PICTURE_TYPE_B) {
02059 s->b_code = get_bits(gb, 3);
02060 }else
02061 s->b_code=1;
02062
02063 if(s->avctx->debug&FF_DEBUG_PICT_INFO){
02064 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",
02065 s->qscale, s->f_code, s->b_code,
02066 s->pict_type == AV_PICTURE_TYPE_I ? "I" : (s->pict_type == AV_PICTURE_TYPE_P ? "P" : (s->pict_type == AV_PICTURE_TYPE_B ? "B" : "S")),
02067 gb->size_in_bits,s->progressive_sequence, s->alternate_scan, s->top_field_first,
02068 s->quarter_sample ? "q" : "h", s->data_partitioning, s->resync_marker, s->num_sprite_warping_points,
02069 s->sprite_warping_accuracy, 1-s->no_rounding, s->vo_type, s->vol_control_parameters ? " VOLC" : " ", s->intra_dc_threshold, s->cplx_estimation_trash_i, s->cplx_estimation_trash_p, s->cplx_estimation_trash_b);
02070 }
02071
02072 if(!s->scalability){
02073 if (s->shape!=RECT_SHAPE && s->pict_type!=AV_PICTURE_TYPE_I) {
02074 skip_bits1(gb);
02075 }
02076 }else{
02077 if(s->enhancement_type){
02078 int load_backward_shape= get_bits1(gb);
02079 if(load_backward_shape){
02080 av_log(s->avctx, AV_LOG_ERROR, "load backward shape isn't supported\n");
02081 }
02082 }
02083 skip_bits(gb, 2);
02084 }
02085 }
02086
02087
02088 if(s->vo_type==0 && s->vol_control_parameters==0 && s->divx_version==-1 && s->picture_number==0){
02089 av_log(s->avctx, AV_LOG_WARNING, "looks like this file was encoded with (divx4/(old)xvid/opendivx) -> forcing low_delay flag\n");
02090 s->low_delay=1;
02091 }
02092
02093 s->picture_number++;
02094
02095 s->y_dc_scale_table= ff_mpeg4_y_dc_scale_table;
02096 s->c_dc_scale_table= ff_mpeg4_c_dc_scale_table;
02097
02098 if(s->workaround_bugs&FF_BUG_EDGE){
02099 s->h_edge_pos= s->width;
02100 s->v_edge_pos= s->height;
02101 }
02102 return 0;
02103 }
02104
02111 int ff_mpeg4_decode_picture_header(MpegEncContext * s, GetBitContext *gb)
02112 {
02113 int startcode, v;
02114
02115
02116 align_get_bits(gb);
02117
02118 if(s->codec_tag == AV_RL32("WV1F") && show_bits(gb, 24) == 0x575630){
02119 skip_bits(gb, 24);
02120 if(get_bits(gb, 8) == 0xF0)
02121 goto end;
02122 }
02123
02124 startcode = 0xff;
02125 for(;;) {
02126 if(get_bits_count(gb) >= gb->size_in_bits){
02127 if(gb->size_in_bits==8 && (s->divx_version>=0 || s->xvid_build>=0)){
02128 av_log(s->avctx, AV_LOG_WARNING, "frame skip %d\n", gb->size_in_bits);
02129 return FRAME_SKIPPED;
02130 }else
02131 return -1;
02132 }
02133
02134
02135 v = get_bits(gb, 8);
02136 startcode = ((startcode << 8) | v) & 0xffffffff;
02137
02138 if((startcode&0xFFFFFF00) != 0x100)
02139 continue;
02140
02141 if(s->avctx->debug&FF_DEBUG_STARTCODE){
02142 av_log(s->avctx, AV_LOG_DEBUG, "startcode: %3X ", startcode);
02143 if (startcode<=0x11F) av_log(s->avctx, AV_LOG_DEBUG, "Video Object Start");
02144 else if(startcode<=0x12F) av_log(s->avctx, AV_LOG_DEBUG, "Video Object Layer Start");
02145 else if(startcode<=0x13F) av_log(s->avctx, AV_LOG_DEBUG, "Reserved");
02146 else if(startcode<=0x15F) av_log(s->avctx, AV_LOG_DEBUG, "FGS bp start");
02147 else if(startcode<=0x1AF) av_log(s->avctx, AV_LOG_DEBUG, "Reserved");
02148 else if(startcode==0x1B0) av_log(s->avctx, AV_LOG_DEBUG, "Visual Object Seq Start");
02149 else if(startcode==0x1B1) av_log(s->avctx, AV_LOG_DEBUG, "Visual Object Seq End");
02150 else if(startcode==0x1B2) av_log(s->avctx, AV_LOG_DEBUG, "User Data");
02151 else if(startcode==0x1B3) av_log(s->avctx, AV_LOG_DEBUG, "Group of VOP start");
02152 else if(startcode==0x1B4) av_log(s->avctx, AV_LOG_DEBUG, "Video Session Error");
02153 else if(startcode==0x1B5) av_log(s->avctx, AV_LOG_DEBUG, "Visual Object Start");
02154 else if(startcode==0x1B6) av_log(s->avctx, AV_LOG_DEBUG, "Video Object Plane start");
02155 else if(startcode==0x1B7) av_log(s->avctx, AV_LOG_DEBUG, "slice start");
02156 else if(startcode==0x1B8) av_log(s->avctx, AV_LOG_DEBUG, "extension start");
02157 else if(startcode==0x1B9) av_log(s->avctx, AV_LOG_DEBUG, "fgs start");
02158 else if(startcode==0x1BA) av_log(s->avctx, AV_LOG_DEBUG, "FBA Object start");
02159 else if(startcode==0x1BB) av_log(s->avctx, AV_LOG_DEBUG, "FBA Object Plane start");
02160 else if(startcode==0x1BC) av_log(s->avctx, AV_LOG_DEBUG, "Mesh Object start");
02161 else if(startcode==0x1BD) av_log(s->avctx, AV_LOG_DEBUG, "Mesh Object Plane start");
02162 else if(startcode==0x1BE) av_log(s->avctx, AV_LOG_DEBUG, "Still Texture Object start");
02163 else if(startcode==0x1BF) av_log(s->avctx, AV_LOG_DEBUG, "Texture Spatial Layer start");
02164 else if(startcode==0x1C0) av_log(s->avctx, AV_LOG_DEBUG, "Texture SNR Layer start");
02165 else if(startcode==0x1C1) av_log(s->avctx, AV_LOG_DEBUG, "Texture Tile start");
02166 else if(startcode==0x1C2) av_log(s->avctx, AV_LOG_DEBUG, "Texture Shape Layer start");
02167 else if(startcode==0x1C3) av_log(s->avctx, AV_LOG_DEBUG, "stuffing start");
02168 else if(startcode<=0x1C5) av_log(s->avctx, AV_LOG_DEBUG, "reserved");
02169 else if(startcode<=0x1FF) av_log(s->avctx, AV_LOG_DEBUG, "System start");
02170 av_log(s->avctx, AV_LOG_DEBUG, " at %d\n", get_bits_count(gb));
02171 }
02172
02173 if(startcode >= 0x120 && startcode <= 0x12F){
02174 if(decode_vol_header(s, gb) < 0)
02175 return -1;
02176 }
02177 else if(startcode == USER_DATA_STARTCODE){
02178 decode_user_data(s, gb);
02179 }
02180 else if(startcode == GOP_STARTCODE){
02181 mpeg4_decode_gop_header(s, gb);
02182 }
02183 else if(startcode == VOP_STARTCODE){
02184 break;
02185 }
02186
02187 align_get_bits(gb);
02188 startcode = 0xff;
02189 }
02190 end:
02191 if(s->flags& CODEC_FLAG_LOW_DELAY)
02192 s->low_delay=1;
02193 s->avctx->has_b_frames= !s->low_delay;
02194 return decode_vop_header(s, gb);
02195 }
02196
02197 static av_cold int decode_init(AVCodecContext *avctx)
02198 {
02199 MpegEncContext *s = avctx->priv_data;
02200 int ret;
02201 static int done = 0;
02202
02203 s->divx_version=
02204 s->divx_build=
02205 s->xvid_build=
02206 s->lavc_build= -1;
02207
02208 if((ret=ff_h263_decode_init(avctx)) < 0)
02209 return ret;
02210
02211 if (!done) {
02212 done = 1;
02213
02214 init_rl(&ff_mpeg4_rl_intra, ff_mpeg4_static_rl_table_store[0]);
02215 init_rl(&rvlc_rl_inter, ff_mpeg4_static_rl_table_store[1]);
02216 init_rl(&rvlc_rl_intra, ff_mpeg4_static_rl_table_store[2]);
02217 INIT_VLC_RL(ff_mpeg4_rl_intra, 554);
02218 INIT_VLC_RL(rvlc_rl_inter, 1072);
02219 INIT_VLC_RL(rvlc_rl_intra, 1072);
02220 INIT_VLC_STATIC(&dc_lum, DC_VLC_BITS, 10 ,
02221 &ff_mpeg4_DCtab_lum[0][1], 2, 1,
02222 &ff_mpeg4_DCtab_lum[0][0], 2, 1, 512);
02223 INIT_VLC_STATIC(&dc_chrom, DC_VLC_BITS, 10 ,
02224 &ff_mpeg4_DCtab_chrom[0][1], 2, 1,
02225 &ff_mpeg4_DCtab_chrom[0][0], 2, 1, 512);
02226 INIT_VLC_STATIC(&sprite_trajectory, SPRITE_TRAJ_VLC_BITS, 15,
02227 &sprite_trajectory_tab[0][1], 4, 2,
02228 &sprite_trajectory_tab[0][0], 4, 2, 128);
02229 INIT_VLC_STATIC(&mb_type_b_vlc, MB_TYPE_B_VLC_BITS, 4,
02230 &mb_type_b_tab[0][1], 2, 1,
02231 &mb_type_b_tab[0][0], 2, 1, 16);
02232 }
02233
02234 s->h263_pred = 1;
02235 s->low_delay = 0;
02236 s->decode_mb= mpeg4_decode_mb;
02237 s->time_increment_bits = 4;
02238 avctx->chroma_sample_location = AVCHROMA_LOC_LEFT;
02239
02240 return 0;
02241 }
02242
02243 AVCodec ff_mpeg4_decoder = {
02244 "mpeg4",
02245 AVMEDIA_TYPE_VIDEO,
02246 CODEC_ID_MPEG4,
02247 sizeof(MpegEncContext),
02248 decode_init,
02249 NULL,
02250 ff_h263_decode_end,
02251 ff_h263_decode_frame,
02252 CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY | CODEC_CAP_FRAME_THREADS,
02253 .flush= ff_mpeg_flush,
02254 .max_lowres= 3,
02255 .long_name= NULL_IF_CONFIG_SMALL("MPEG-4 part 2"),
02256 .pix_fmts= ff_hwaccel_pixfmt_list_420,
02257 .update_thread_context= ONLY_IF_THREADS_ENABLED(ff_mpeg_update_thread_context)
02258 };
02259
02260
02261 #if CONFIG_MPEG4_VDPAU_DECODER
02262 AVCodec ff_mpeg4_vdpau_decoder = {
02263 "mpeg4_vdpau",
02264 AVMEDIA_TYPE_VIDEO,
02265 CODEC_ID_MPEG4,
02266 sizeof(MpegEncContext),
02267 decode_init,
02268 NULL,
02269 ff_h263_decode_end,
02270 ff_h263_decode_frame,
02271 CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY | CODEC_CAP_HWACCEL_VDPAU,
02272 .long_name= NULL_IF_CONFIG_SMALL("MPEG-4 part 2 (VDPAU)"),
02273 .pix_fmts= (const enum PixelFormat[]){PIX_FMT_VDPAU_MPEG4, PIX_FMT_NONE},
02274 };
02275 #endif