comparison mpegvideo.c @ 2074:2faafe7a3db6 libavcodec

mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
author iive
date Fri, 11 Jun 2004 07:59:12 +0000
parents 4bfb146e701b
children 3c1dba53954e
comparison
equal deleted inserted replaced
2073:95d303a305d2 2074:2faafe7a3db6
443 // edge emu needs blocksize + filter length - 1 (=17x17 for halfpel / 21x21 for h264) 443 // edge emu needs blocksize + filter length - 1 (=17x17 for halfpel / 21x21 for h264)
444 CHECKED_ALLOCZ(s->allocated_edge_emu_buffer, (s->width+64)*2*17*2); //(width + edge + align)*interlaced*MBsize*tolerance 444 CHECKED_ALLOCZ(s->allocated_edge_emu_buffer, (s->width+64)*2*17*2); //(width + edge + align)*interlaced*MBsize*tolerance
445 s->edge_emu_buffer= s->allocated_edge_emu_buffer + (s->width+64)*2*17; 445 s->edge_emu_buffer= s->allocated_edge_emu_buffer + (s->width+64)*2*17;
446 446
447 //FIXME should be linesize instead of s->width*2 but that isnt known before get_buffer() 447 //FIXME should be linesize instead of s->width*2 but that isnt known before get_buffer()
448 CHECKED_ALLOCZ(s->me.scratchpad, (s->width+64)*2*16*2*sizeof(uint8_t)) 448 CHECKED_ALLOCZ(s->me.scratchpad, (s->width+64)*4*16*2*sizeof(uint8_t))
449 s->rd_scratchpad= s->me.scratchpad; 449 s->rd_scratchpad= s->me.scratchpad;
450 s->b_scratchpad= s->me.scratchpad; 450 s->b_scratchpad= s->me.scratchpad;
451 s->obmc_scratchpad= s->me.scratchpad + 16; 451 s->obmc_scratchpad= s->me.scratchpad + 16;
452 if (s->encoding) { 452 if (s->encoding) {
453 CHECKED_ALLOCZ(s->me.map , ME_MAP_SIZE*sizeof(uint32_t)) 453 CHECKED_ALLOCZ(s->me.map , ME_MAP_SIZE*sizeof(uint32_t))
618 s->mb_stride = s->mb_width + 1; 618 s->mb_stride = s->mb_width + 1;
619 s->b8_stride = s->mb_width*2 + 1; 619 s->b8_stride = s->mb_width*2 + 1;
620 s->b4_stride = s->mb_width*4 + 1; 620 s->b4_stride = s->mb_width*4 + 1;
621 mb_array_size= s->mb_height * s->mb_stride; 621 mb_array_size= s->mb_height * s->mb_stride;
622 mv_table_size= (s->mb_height+2) * s->mb_stride + 1; 622 mv_table_size= (s->mb_height+2) * s->mb_stride + 1;
623
624 /* set chroma shifts */
625 avcodec_get_chroma_sub_sample(s->avctx->pix_fmt,&(s->chroma_x_shift),
626 &(s->chroma_y_shift) );
623 627
624 /* set default edge pos, will be overriden in decode_header if needed */ 628 /* set default edge pos, will be overriden in decode_header if needed */
625 s->h_edge_pos= s->mb_width*16; 629 s->h_edge_pos= s->mb_width*16;
626 s->v_edge_pos= s->mb_height*16; 630 s->v_edge_pos= s->mb_height*16;
627 631
2474 pix_op[dxy](dest, src, stride, h); 2478 pix_op[dxy](dest, src, stride, h);
2475 return emu; 2479 return emu;
2476 } 2480 }
2477 2481
2478 /* apply one mpeg motion vector to the three components */ 2482 /* apply one mpeg motion vector to the three components */
2479 static inline void mpeg_motion(MpegEncContext *s, 2483 static always_inline void mpeg_motion(MpegEncContext *s,
2480 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, 2484 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
2481 int field_based, int bottom_field, int field_select, 2485 int field_based, int bottom_field, int field_select,
2482 uint8_t **ref_picture, op_pixels_func (*pix_op)[4], 2486 uint8_t **ref_picture, op_pixels_func (*pix_op)[4],
2483 int motion_x, int motion_y, int h) 2487 int motion_x, int motion_y, int h)
2484 { 2488 {
2497 linesize = s->current_picture.linesize[0] << field_based; 2501 linesize = s->current_picture.linesize[0] << field_based;
2498 uvlinesize = s->current_picture.linesize[1] << field_based; 2502 uvlinesize = s->current_picture.linesize[1] << field_based;
2499 2503
2500 dxy = ((motion_y & 1) << 1) | (motion_x & 1); 2504 dxy = ((motion_y & 1) << 1) | (motion_x & 1);
2501 src_x = s->mb_x* 16 + (motion_x >> 1); 2505 src_x = s->mb_x* 16 + (motion_x >> 1);
2502 src_y = s->mb_y*(16>>field_based) + (motion_y >> 1); 2506 src_y =(s->mb_y<<(4-field_based)) + (motion_y >> 1);
2503 2507
2504 if (s->out_format == FMT_H263) { 2508 if (s->out_format == FMT_H263) {
2505 if((s->workaround_bugs & FF_BUG_HPEL_CHROMA) && field_based){ 2509 if((s->workaround_bugs & FF_BUG_HPEL_CHROMA) && field_based){
2506 mx = (motion_x>>1)|(motion_x&1); 2510 mx = (motion_x>>1)|(motion_x&1);
2507 my = motion_y >>1; 2511 my = motion_y >>1;
2508 uvdxy = ((my & 1) << 1) | (mx & 1); 2512 uvdxy = ((my & 1) << 1) | (mx & 1);
2509 uvsrc_x = s->mb_x* 8 + (mx >> 1); 2513 uvsrc_x = s->mb_x* 8 + (mx >> 1);
2510 uvsrc_y = s->mb_y*(8>>field_based) + (my >> 1); 2514 uvsrc_y = (s->mb_y<<(3-field_based)) + (my >> 1);
2511 }else{ 2515 }else{
2512 uvdxy = dxy | (motion_y & 2) | ((motion_x & 2) >> 1); 2516 uvdxy = dxy | (motion_y & 2) | ((motion_x & 2) >> 1);
2513 uvsrc_x = src_x>>1; 2517 uvsrc_x = src_x>>1;
2514 uvsrc_y = src_y>>1; 2518 uvsrc_y = src_y>>1;
2515 } 2519 }
2518 my = motion_y / 4; 2522 my = motion_y / 4;
2519 uvdxy = 0; 2523 uvdxy = 0;
2520 uvsrc_x = s->mb_x*8 + mx; 2524 uvsrc_x = s->mb_x*8 + mx;
2521 uvsrc_y = s->mb_y*8 + my; 2525 uvsrc_y = s->mb_y*8 + my;
2522 } else { 2526 } else {
2523 mx = motion_x / 2; 2527 if(s->chroma_y_shift){
2524 my = motion_y / 2; 2528 mx = motion_x / 2;
2525 uvdxy = ((my & 1) << 1) | (mx & 1); 2529 my = motion_y / 2;
2526 uvsrc_x = s->mb_x* 8 + (mx >> 1); 2530 uvdxy = ((my & 1) << 1) | (mx & 1);
2527 uvsrc_y = s->mb_y*(8>>field_based) + (my >> 1); 2531 uvsrc_x = s->mb_x* 8 + (mx >> 1);
2532 uvsrc_y = (s->mb_y<<(3-field_based)) + (my >> 1);
2533 } else {
2534 if(s->chroma_x_shift){
2535 //Chroma422
2536 mx = motion_x / 2;
2537 uvdxy = ((motion_y & 1) << 1) | (mx & 1);
2538 uvsrc_x = s->mb_x* 8 + (mx >> 1);
2539 uvsrc_y = src_y;
2540 } else {
2541 //Chroma444
2542 uvdxy = dxy;
2543 uvsrc_x = src_x;
2544 uvsrc_y = src_y;
2545 }
2546 }
2528 } 2547 }
2529 2548
2530 ptr_y = ref_picture[0] + src_y * linesize + src_x; 2549 ptr_y = ref_picture[0] + src_y * linesize + src_x;
2531 ptr_cb = ref_picture[1] + uvsrc_y * uvlinesize + uvsrc_x; 2550 ptr_cb = ref_picture[1] + uvsrc_y * uvlinesize + uvsrc_x;
2532 ptr_cr = ref_picture[2] + uvsrc_y * uvlinesize + uvsrc_x; 2551 ptr_cr = ref_picture[2] + uvsrc_y * uvlinesize + uvsrc_x;
2533 2552
2534 if( (unsigned)src_x > s->h_edge_pos - (motion_x&1) - 16 2553 if( (unsigned)src_x > s->h_edge_pos - (motion_x&1) - 16
2535 || (unsigned)src_y > v_edge_pos - (motion_y&1) - h){ 2554 || (unsigned)src_y > v_edge_pos - (motion_y&1) - h){
2555 if(s->codec_id == CODEC_ID_MPEG2VIDEO ||
2556 s->codec_id == CODEC_ID_MPEG1VIDEO){
2557 av_log(s->avctx,AV_LOG_DEBUG,"MPEG motion vector out of boundary\n");
2558 return ;
2559 }
2536 ff_emulated_edge_mc(s->edge_emu_buffer, ptr_y, s->linesize, 17, 17+field_based, 2560 ff_emulated_edge_mc(s->edge_emu_buffer, ptr_y, s->linesize, 17, 17+field_based,
2537 src_x, src_y<<field_based, s->h_edge_pos, s->v_edge_pos); 2561 src_x, src_y<<field_based, s->h_edge_pos, s->v_edge_pos);
2538 ptr_y = s->edge_emu_buffer; 2562 ptr_y = s->edge_emu_buffer;
2539 if(!(s->flags&CODEC_FLAG_GRAY)){ 2563 if(!(s->flags&CODEC_FLAG_GRAY)){
2540 uint8_t *uvbuf= s->edge_emu_buffer+18*s->linesize; 2564 uint8_t *uvbuf= s->edge_emu_buffer+18*s->linesize;
2560 } 2584 }
2561 2585
2562 pix_op[0][dxy](dest_y, ptr_y, linesize, h); 2586 pix_op[0][dxy](dest_y, ptr_y, linesize, h);
2563 2587
2564 if(!(s->flags&CODEC_FLAG_GRAY)){ 2588 if(!(s->flags&CODEC_FLAG_GRAY)){
2565 pix_op[1][uvdxy](dest_cb, ptr_cb, uvlinesize, h >> 1); 2589 pix_op[s->chroma_x_shift][uvdxy](dest_cb, ptr_cb, uvlinesize, h >> s->chroma_y_shift);
2566 pix_op[1][uvdxy](dest_cr, ptr_cr, uvlinesize, h >> 1); 2590 pix_op[s->chroma_x_shift][uvdxy](dest_cr, ptr_cr, uvlinesize, h >> s->chroma_y_shift);
2567 } 2591 }
2568 } 2592 }
2569 //FIXME move to dsputil, avg variant, 16x16 version 2593 //FIXME move to dsputil, avg variant, 16x16 version
2570 static inline void put_obmc(uint8_t *dst, uint8_t *src[5], int stride){ 2594 static inline void put_obmc(uint8_t *dst, uint8_t *src[5], int stride){
2571 int x; 2595 int x;
3005 0, 0, s->field_select[dir][i], 3029 0, 0, s->field_select[dir][i],
3006 ref2picture, pix_op, 3030 ref2picture, pix_op,
3007 s->mv[dir][i][0], s->mv[dir][i][1] + 16*i, 8); 3031 s->mv[dir][i][0], s->mv[dir][i][1] + 16*i, 8);
3008 3032
3009 dest_y += 16*s->linesize; 3033 dest_y += 16*s->linesize;
3010 dest_cb+= 8*s->uvlinesize; 3034 dest_cb+= (16>>s->chroma_y_shift)*s->uvlinesize;
3011 dest_cr+= 8*s->uvlinesize; 3035 dest_cr+= (16>>s->chroma_y_shift)*s->uvlinesize;
3012 } 3036 }
3013 break; 3037 break;
3014 case MV_TYPE_DMV: 3038 case MV_TYPE_DMV:
3015 if(s->picture_structure == PICT_FRAME){ 3039 if(s->picture_structure == PICT_FRAME){
3016 for(i=0; i<2; i++){ 3040 for(i=0; i<2; i++){
3113 s->mv_dir : motion vector direction 3137 s->mv_dir : motion vector direction
3114 s->mv_type : motion vector type 3138 s->mv_type : motion vector type
3115 s->mv : motion vector 3139 s->mv : motion vector
3116 s->interlaced_dct : true if interlaced dct used (mpeg2) 3140 s->interlaced_dct : true if interlaced dct used (mpeg2)
3117 */ 3141 */
3118 void MPV_decode_mb(MpegEncContext *s, DCTELEM block[6][64]) 3142 void MPV_decode_mb(MpegEncContext *s, DCTELEM block[12][64])
3119 { 3143 {
3120 int mb_x, mb_y; 3144 int mb_x, mb_y;
3121 const int mb_xy = s->mb_y * s->mb_stride + s->mb_x; 3145 const int mb_xy = s->mb_y * s->mb_stride + s->mb_x;
3122 #ifdef HAVE_XVMC 3146 #ifdef HAVE_XVMC
3123 if(s->avctx->xvmc_acceleration){ 3147 if(s->avctx->xvmc_acceleration){
3188 } else{ 3212 } else{
3189 *mbskip_ptr = 0; /* not skipped */ 3213 *mbskip_ptr = 0; /* not skipped */
3190 } 3214 }
3191 } 3215 }
3192 3216
3193 if (s->interlaced_dct) { 3217 dct_linesize = linesize << s->interlaced_dct;
3194 dct_linesize = linesize * 2; 3218 dct_offset =(s->interlaced_dct)? linesize : linesize*8;
3195 dct_offset = linesize; 3219
3196 } else {
3197 dct_linesize = linesize;
3198 dct_offset = linesize * 8;
3199 }
3200 if(readable){ 3220 if(readable){
3201 dest_y= s->dest[0]; 3221 dest_y= s->dest[0];
3202 dest_cb= s->dest[1]; 3222 dest_cb= s->dest[1];
3203 dest_cr= s->dest[2]; 3223 dest_cr= s->dest[2];
3204 }else{ 3224 }else{
3205 dest_y = s->b_scratchpad; 3225 dest_y = s->b_scratchpad;
3206 dest_cb= s->b_scratchpad+16*linesize; 3226 dest_cb= s->b_scratchpad+16*linesize;
3207 dest_cr= s->b_scratchpad+16*linesize+8; 3227 dest_cr= s->b_scratchpad+32*linesize;
3208 } 3228 }
3209 if (!s->mb_intra) { 3229 if (!s->mb_intra) {
3210 /* motion handling */ 3230 /* motion handling */
3211 /* decoding or more than one mb_type (MC was allready done otherwise) */ 3231 /* decoding or more than one mb_type (MC was allready done otherwise) */
3212 if(!s->encoding){ 3232 if(!s->encoding){
3248 add_dct(s, block[1], 1, dest_y + 8, dct_linesize); 3268 add_dct(s, block[1], 1, dest_y + 8, dct_linesize);
3249 add_dct(s, block[2], 2, dest_y + dct_offset, dct_linesize); 3269 add_dct(s, block[2], 2, dest_y + dct_offset, dct_linesize);
3250 add_dct(s, block[3], 3, dest_y + dct_offset + 8, dct_linesize); 3270 add_dct(s, block[3], 3, dest_y + dct_offset + 8, dct_linesize);
3251 3271
3252 if(!(s->flags&CODEC_FLAG_GRAY)){ 3272 if(!(s->flags&CODEC_FLAG_GRAY)){
3253 add_dct(s, block[4], 4, dest_cb, uvlinesize); 3273 if(s->chroma_y_shift){//Chroma420
3254 add_dct(s, block[5], 5, dest_cr, uvlinesize); 3274 add_dct(s, block[4], 4, dest_cb, uvlinesize);
3255 } 3275 add_dct(s, block[5], 5, dest_cr, uvlinesize);
3256 } 3276 }else{
3277 //chroma422
3278 dct_linesize = uvlinesize << s->interlaced_dct;
3279 dct_offset =(s->interlaced_dct)? uvlinesize : uvlinesize*8;
3280
3281 add_dct(s, block[4], 4, dest_cb, dct_linesize);
3282 add_dct(s, block[5], 5, dest_cr, dct_linesize);
3283 add_dct(s, block[6], 6, dest_cb+dct_offset, dct_linesize);
3284 add_dct(s, block[7], 7, dest_cr+dct_offset, dct_linesize);
3285 if(!s->chroma_x_shift){//Chroma444
3286 add_dct(s, block[8], 8, dest_cb+8, dct_linesize);
3287 add_dct(s, block[9], 9, dest_cr+8, dct_linesize);
3288 add_dct(s, block[10], 10, dest_cb+8+dct_offset, dct_linesize);
3289 add_dct(s, block[11], 11, dest_cr+8+dct_offset, dct_linesize);
3290 }
3291 }
3292 }//fi gray
3293 }
3257 #ifdef CONFIG_RISKY 3294 #ifdef CONFIG_RISKY
3258 else{ 3295 else{
3259 ff_wmv2_add_mb(s, block, dest_y, dest_cb, dest_cr); 3296 ff_wmv2_add_mb(s, block, dest_y, dest_cb, dest_cr);
3260 } 3297 }
3261 #endif 3298 #endif
3276 s->dsp.idct_put(dest_y + 8, dct_linesize, block[1]); 3313 s->dsp.idct_put(dest_y + 8, dct_linesize, block[1]);
3277 s->dsp.idct_put(dest_y + dct_offset , dct_linesize, block[2]); 3314 s->dsp.idct_put(dest_y + dct_offset , dct_linesize, block[2]);
3278 s->dsp.idct_put(dest_y + dct_offset + 8, dct_linesize, block[3]); 3315 s->dsp.idct_put(dest_y + dct_offset + 8, dct_linesize, block[3]);
3279 3316
3280 if(!(s->flags&CODEC_FLAG_GRAY)){ 3317 if(!(s->flags&CODEC_FLAG_GRAY)){
3281 s->dsp.idct_put(dest_cb, uvlinesize, block[4]); 3318 if(s->chroma_y_shift){
3282 s->dsp.idct_put(dest_cr, uvlinesize, block[5]); 3319 s->dsp.idct_put(dest_cb, uvlinesize, block[4]);
3283 } 3320 s->dsp.idct_put(dest_cr, uvlinesize, block[5]);
3321 }else{
3322
3323 dct_linesize = uvlinesize << s->interlaced_dct;
3324 dct_offset =(s->interlaced_dct)? uvlinesize : uvlinesize*8;
3325
3326 s->dsp.idct_put(dest_cb, dct_linesize, block[4]);
3327 s->dsp.idct_put(dest_cr, dct_linesize, block[5]);
3328 s->dsp.idct_put(dest_cb + dct_offset, dct_linesize, block[6]);
3329 s->dsp.idct_put(dest_cr + dct_offset, dct_linesize, block[7]);
3330 if(!s->chroma_x_shift){//Chroma444
3331 s->dsp.idct_put(dest_cb + 8, dct_linesize, block[8]);
3332 s->dsp.idct_put(dest_cr + 8, dct_linesize, block[9]);
3333 s->dsp.idct_put(dest_cb + 8 + dct_offset, dct_linesize, block[10]);
3334 s->dsp.idct_put(dest_cr + 8 + dct_offset, dct_linesize, block[11]);
3335 }
3336 }
3337 }//gray
3284 } 3338 }
3285 } 3339 }
3286 if(!readable){ 3340 if(!readable){
3287 s->dsp.put_pixels_tab[0][0](s->dest[0], dest_y , linesize,16); 3341 s->dsp.put_pixels_tab[0][0](s->dest[0], dest_y , linesize,16);
3288 s->dsp.put_pixels_tab[1][0](s->dest[1], dest_cb, uvlinesize, 8); 3342 s->dsp.put_pixels_tab[s->chroma_x_shift][0](s->dest[1], dest_cb, uvlinesize,16 >> s->chroma_y_shift);
3289 s->dsp.put_pixels_tab[1][0](s->dest[2], dest_cr, uvlinesize, 8); 3343 s->dsp.put_pixels_tab[s->chroma_x_shift][0](s->dest[2], dest_cr, uvlinesize,16 >> s->chroma_y_shift);
3290 } 3344 }
3291 } 3345 }
3292 } 3346 }
3293 3347
3294 #ifdef CONFIG_ENCODERS 3348 #ifdef CONFIG_ENCODERS
3405 offset[2]= 3459 offset[2]=
3406 offset[3]= 0; 3460 offset[3]= 0;
3407 }else{ 3461 }else{
3408 offset[0]= y * s->linesize;; 3462 offset[0]= y * s->linesize;;
3409 offset[1]= 3463 offset[1]=
3410 offset[2]= (y>>1) * s->uvlinesize;; 3464 offset[2]= (y >> s->chroma_y_shift) * s->uvlinesize;
3411 offset[3]= 0; 3465 offset[3]= 0;
3412 } 3466 }
3413 3467
3414 emms_c(); 3468 emms_c();
3415 3469
3426 s->block_index[1]= s->b8_stride*(s->mb_y*2 ) - 1 + s->mb_x*2; 3480 s->block_index[1]= s->b8_stride*(s->mb_y*2 ) - 1 + s->mb_x*2;
3427 s->block_index[2]= s->b8_stride*(s->mb_y*2 + 1) - 2 + s->mb_x*2; 3481 s->block_index[2]= s->b8_stride*(s->mb_y*2 + 1) - 2 + s->mb_x*2;
3428 s->block_index[3]= s->b8_stride*(s->mb_y*2 + 1) - 1 + s->mb_x*2; 3482 s->block_index[3]= s->b8_stride*(s->mb_y*2 + 1) - 1 + s->mb_x*2;
3429 s->block_index[4]= s->mb_stride*(s->mb_y + 1) + s->b8_stride*s->mb_height*2 + s->mb_x - 1; 3483 s->block_index[4]= s->mb_stride*(s->mb_y + 1) + s->b8_stride*s->mb_height*2 + s->mb_x - 1;
3430 s->block_index[5]= s->mb_stride*(s->mb_y + s->mb_height + 2) + s->b8_stride*s->mb_height*2 + s->mb_x - 1; 3484 s->block_index[5]= s->mb_stride*(s->mb_y + s->mb_height + 2) + s->b8_stride*s->mb_height*2 + s->mb_x - 1;
3431 3485 //block_index is not used by mpeg2, so it is not affected by chroma_format
3432 if(s->pict_type==B_TYPE && s->avctx->draw_horiz_band && s->picture_structure==PICT_FRAME){ 3486
3433 s->dest[0] = s->current_picture.data[0] + s->mb_x * 16 - 16; 3487 s->dest[0] = s->current_picture.data[0] + (s->mb_x - 1)*16;
3434 s->dest[1] = s->current_picture.data[1] + s->mb_x * 8 - 8; 3488 s->dest[1] = s->current_picture.data[1] + (s->mb_x - 1)*(16 >> s->chroma_x_shift);
3435 s->dest[2] = s->current_picture.data[2] + s->mb_x * 8 - 8; 3489 s->dest[2] = s->current_picture.data[2] + (s->mb_x - 1)*(16 >> s->chroma_x_shift);
3436 }else{ 3490
3437 s->dest[0] = s->current_picture.data[0] + (s->mb_y * 16* linesize ) + s->mb_x * 16 - 16; 3491 if(!(s->pict_type==B_TYPE && s->avctx->draw_horiz_band && s->picture_structure==PICT_FRAME))
3438 s->dest[1] = s->current_picture.data[1] + (s->mb_y * 8 * uvlinesize) + s->mb_x * 8 - 8; 3492 {
3439 s->dest[2] = s->current_picture.data[2] + (s->mb_y * 8 * uvlinesize) + s->mb_x * 8 - 8; 3493 s->dest[0] += s->mb_y * linesize * 16;
3440 } 3494 s->dest[1] += s->mb_y * uvlinesize * (16 >> s->chroma_y_shift);
3495 s->dest[2] += s->mb_y * uvlinesize * (16 >> s->chroma_y_shift);
3496 }
3441 } 3497 }
3442 3498
3443 #ifdef CONFIG_ENCODERS 3499 #ifdef CONFIG_ENCODERS
3444 3500
3445 static void get_vissual_weight(int16_t *weight, uint8_t *ptr, int stride){ 3501 static void get_vissual_weight(int16_t *weight, uint8_t *ptr, int stride){