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