Revision 137c8468 libavcodec/mpegvideo.c

View differences:

libavcodec/mpegvideo.c
275 275
    dst->type= FF_BUFFER_TYPE_COPY;
276 276
}
277 277

  
278
static void copy_picture_attributes(AVFrame *dst, AVFrame *src){
278
static void copy_picture_attributes(MpegEncContext *s, AVFrame *dst, AVFrame *src){
279
    int i;
280

  
279 281
    dst->pict_type              = src->pict_type;
280 282
    dst->quality                = src->quality;
281 283
    dst->coded_picture_number   = src->coded_picture_number;
......
284 286
    dst->pts                    = src->pts;
285 287
    dst->interlaced_frame       = src->interlaced_frame;
286 288
    dst->top_field_first        = src->top_field_first;
289

  
290
    if(src->motion_val[0] && src->motion_val[0] != dst->motion_val[0]){
291
        if(src->motion_subsample_log2 != dst->motion_subsample_log2)
292
            av_log(s->avctx, AV_LOG_ERROR, "AVFrame.motion_subsample_log2 doesnt match!\n");
293
        else{
294
            int stride= ((16*s->mb_width )>>src->motion_subsample_log2) + 1;
295
            int height= ((16*s->mb_height)>>src->motion_subsample_log2);
296

  
297
            for(i=0; i<2; i++)
298
                memcpy(dst->motion_val[i], src->motion_val[i], stride*height*sizeof(int16_t));
299
        }
300
    }
287 301
}
288 302

  
289 303
/**
......
347 361
            pic->motion_subsample_log2= 2;
348 362
        }else if(s->out_format == FMT_H263 || s->encoding || (s->avctx->debug&FF_DEBUG_MV) || (s->avctx->debug_mv)){
349 363
            for(i=0; i<2; i++){
350
                CHECKED_ALLOCZ(pic->motion_val_base[i], 2 * (b8_array_size+2) * sizeof(int16_t)*2) //FIXME
364
                CHECKED_ALLOCZ(pic->motion_val_base[i], 2 * (b8_array_size+2) * sizeof(int16_t))
351 365
                pic->motion_val[i]= pic->motion_val_base[i]+2;
352 366
            }
353 367
            pic->motion_subsample_log2= 3;
......
591 605
    s->block_wrap[0]=
592 606
    s->block_wrap[1]=
593 607
    s->block_wrap[2]=
594
    s->block_wrap[3]= s->mb_width*2 + 2;
608
    s->block_wrap[3]= s->b8_stride;
595 609
    s->block_wrap[4]=
596
    s->block_wrap[5]= s->mb_width + 2;
610
    s->block_wrap[5]= s->mb_stride;
597 611
 
598
    y_size = (2 * s->mb_width + 2) * (2 * s->mb_height + 2);
599
    c_size = (s->mb_width + 2) * (s->mb_height + 2);
612
    y_size = s->b8_stride * (2 * s->mb_height + 1);
613
    c_size = s->mb_stride * (s->mb_height + 1);
600 614
    yc_size = y_size + 2 * c_size;
601 615
    
602 616
    /* convert fourcc to upper case */
......
678 692
    }
679 693
    if (s->out_format == FMT_H263) {
680 694
        /* ac values */
681
        CHECKED_ALLOCZ(s->ac_val[0], yc_size * sizeof(int16_t) * 16);
682
        s->ac_val[1] = s->ac_val[0] + y_size;
695
        CHECKED_ALLOCZ(s->ac_val_base, yc_size * sizeof(int16_t) * 16);
696
        s->ac_val[0] = s->ac_val_base + s->b8_stride + 1;
697
        s->ac_val[1] = s->ac_val_base + y_size + s->mb_stride + 1;
683 698
        s->ac_val[2] = s->ac_val[1] + c_size;
684 699
        
685 700
        /* cbp values */
686
        CHECKED_ALLOCZ(s->coded_block, y_size);
701
        CHECKED_ALLOCZ(s->coded_block_base, y_size);
702
        s->coded_block= s->coded_block_base + s->b8_stride + 1;
687 703
        
688 704
        /* divx501 bitstream reorder buffer */
689 705
        CHECKED_ALLOCZ(s->bitstream_buffer, BITSTREAM_BUFFER_SIZE);
......
696 712
    if (s->h263_pred || s->h263_plus || !s->encoding) {
697 713
        /* dc values */
698 714
        //MN: we need these for error resilience of intra-frames
699
        CHECKED_ALLOCZ(s->dc_val[0], yc_size * sizeof(int16_t));
700
        s->dc_val[1] = s->dc_val[0] + y_size;
715
        CHECKED_ALLOCZ(s->dc_val_base, yc_size * sizeof(int16_t));
716
        s->dc_val[0] = s->dc_val_base + s->b8_stride + 1;
717
        s->dc_val[1] = s->dc_val_base + y_size + s->mb_stride + 1;
701 718
        s->dc_val[2] = s->dc_val[1] + c_size;
702 719
        for(i=0;i<yc_size;i++)
703
            s->dc_val[0][i] = 1024;
720
            s->dc_val_base[i] = 1024;
704 721
    }
705 722

  
706 723
    /* which mb is a intra block */
......
781 798
        av_freep(&s->p_field_select_table[i]);
782 799
    }
783 800
    
784
    av_freep(&s->dc_val[0]);
785
    av_freep(&s->ac_val[0]);
786
    av_freep(&s->coded_block);
801
    av_freep(&s->dc_val_base);
802
    av_freep(&s->ac_val_base);
803
    av_freep(&s->coded_block_base);
787 804
    av_freep(&s->mbintra_table);
788 805
    av_freep(&s->cbp_table);
789 806
    av_freep(&s->pred_dir_table);
......
1684 1701
                    if(!USES_LIST(pict->mb_type[mb_index], direction))
1685 1702
                        continue;
1686 1703

  
1704
                    //FIXME for h264
1687 1705
                    if(IS_8X8(pict->mb_type[mb_index])){
1688 1706
                      int i;
1689 1707
                      for(i=0; i<4; i++){
1690 1708
                        int sx= mb_x*16 + 4 + 8*(i&1);
1691 1709
                        int sy= mb_y*16 + 4 + 8*(i>>1);
1692
                        int xy= 1 + mb_x*2 + (i&1) + (mb_y*2 + 1 + (i>>1))*(s->mb_width*2 + 2);
1710
                        int xy= mb_x*2 + (i&1) + (mb_y*2 + (i>>1))*s->b8_stride;
1693 1711
                        int mx= (pict->motion_val[direction][xy][0]>>shift) + sx;
1694 1712
                        int my= (pict->motion_val[direction][xy][1]>>shift) + sy;
1695 1713
                        draw_arrow(ptr, sx, sy, mx, my, s->width, s->height, s->linesize, 100);
......
1699 1717
                      for(i=0; i<2; i++){
1700 1718
                        int sx=mb_x*16 + 8;
1701 1719
                        int sy=mb_y*16 + 4 + 8*i;
1702
                        int xy=1 + mb_x*2 + (mb_y*2 + 1 + i)*(s->mb_width*2 + 2);
1720
                        int xy= mb_x*2 + (mb_y*2 + i)*s->b8_stride;
1703 1721
                        int mx=(pict->motion_val[direction][xy][0]>>shift) + sx;
1704 1722
                        int my=(pict->motion_val[direction][xy][1]>>shift) + sy;
1705 1723
                        draw_arrow(ptr, sx, sy, mx, my, s->width, s->height, s->linesize, 100);
......
1707 1725
                    }else{
1708 1726
                      int sx= mb_x*16 + 8;
1709 1727
                      int sy= mb_y*16 + 8;
1710
                      int xy= 1 + mb_x*2 + (mb_y*2 + 1)*(s->mb_width*2 + 2);
1728
                      int xy= mb_x*2 + mb_y*2*s->b8_stride;
1711 1729
                      int mx= (pict->motion_val[direction][xy][0]>>shift) + sx;
1712 1730
                      int my= (pict->motion_val[direction][xy][1]>>shift) + sy;
1713 1731
                      draw_arrow(ptr, sx, sy, mx, my, s->width, s->height, s->linesize, 100);
......
1884 1902
            }
1885 1903
        }
1886 1904
    }
1887
    copy_picture_attributes(pic, pic_arg);
1905
    copy_picture_attributes(s, pic, pic_arg);
1888 1906
    
1889 1907
    pic->display_picture_number= s->input_picture_number++;
1890 1908
    if(pic->pts != AV_NOPTS_VALUE){ 
......
2013 2031
                s->reordered_input_picture[0]->data[i]= NULL;
2014 2032
            s->reordered_input_picture[0]->type= 0;
2015 2033
            
2016
            copy_picture_attributes((AVFrame*)pic, (AVFrame*)s->reordered_input_picture[0]);
2034
            copy_picture_attributes(s, (AVFrame*)pic, (AVFrame*)s->reordered_input_picture[0]);
2017 2035
            pic->reference              = s->reordered_input_picture[0]->reference;
2018 2036
            
2019 2037
            alloc_picture(s, pic, 0);
......
2746 2764
    if(s->obmc && s->pict_type != B_TYPE){
2747 2765
        int16_t mv_cache[4][4][2];
2748 2766
        const int xy= s->mb_x + s->mb_y*s->mb_stride;
2749
        const int mot_stride= s->mb_width*2 + 2;
2750
        const int mot_xy= 1 + mb_x*2 + (mb_y*2 + 1)*mot_stride;
2767
        const int mot_stride= s->b8_stride;
2768
        const int mot_xy= mb_x*2 + mb_y*2*mot_stride;
2751 2769

  
2752 2770
        assert(!s->mb_skiped);
2753 2771
                
......
3003 3021
 */
3004 3022
void ff_clean_intra_table_entries(MpegEncContext *s)
3005 3023
{
3006
    int wrap = s->block_wrap[0];
3024
    int wrap = s->b8_stride;
3007 3025
    int xy = s->block_index[0];
3008 3026
    
3009 3027
    s->dc_val[0][xy           ] = 
......
3020 3038
        s->coded_block[xy + 1 + wrap] = 0;
3021 3039
    }
3022 3040
    /* chroma */
3023
    wrap = s->block_wrap[4];
3024
    xy = s->mb_x + 1 + (s->mb_y + 1) * wrap;
3041
    wrap = s->mb_stride;
3042
    xy = s->mb_x + s->mb_y * wrap;
3025 3043
    s->dc_val[1][xy] =
3026 3044
    s->dc_val[2][xy] = 1024;
3027 3045
    /* ac pred */
3028 3046
    memset(s->ac_val[1][xy], 0, 16 * sizeof(int16_t));
3029 3047
    memset(s->ac_val[2][xy], 0, 16 * sizeof(int16_t));
3030 3048
    
3031
    s->mbintra_table[s->mb_x + s->mb_y*s->mb_stride]= 0;
3049
    s->mbintra_table[xy]= 0;
3032 3050
}
3033 3051

  
3034 3052
/* generic function called after a macroblock has been parsed by the
......
3348 3366
    const int linesize= s->current_picture.linesize[0]; //not s->linesize as this woulnd be wrong for field pics
3349 3367
    const int uvlinesize= s->current_picture.linesize[1];
3350 3368
        
3351
    s->block_index[0]= s->block_wrap[0]*(s->mb_y*2 + 1) - 1 + s->mb_x*2;
3352
    s->block_index[1]= s->block_wrap[0]*(s->mb_y*2 + 1)     + s->mb_x*2;
3353
    s->block_index[2]= s->block_wrap[0]*(s->mb_y*2 + 2) - 1 + s->mb_x*2;
3354
    s->block_index[3]= s->block_wrap[0]*(s->mb_y*2 + 2)     + s->mb_x*2;
3355
    s->block_index[4]= s->block_wrap[4]*(s->mb_y + 1)                    + s->block_wrap[0]*(s->mb_height*2 + 2) + s->mb_x;
3356
    s->block_index[5]= s->block_wrap[4]*(s->mb_y + 1 + s->mb_height + 2) + s->block_wrap[0]*(s->mb_height*2 + 2) + s->mb_x;
3369
    s->block_index[0]= s->b8_stride*(s->mb_y*2    ) - 2 + s->mb_x*2;
3370
    s->block_index[1]= s->b8_stride*(s->mb_y*2    ) - 1 + s->mb_x*2;
3371
    s->block_index[2]= s->b8_stride*(s->mb_y*2 + 1) - 2 + s->mb_x*2;
3372
    s->block_index[3]= s->b8_stride*(s->mb_y*2 + 1) - 1 + s->mb_x*2;
3373
    s->block_index[4]= s->mb_stride*(s->mb_y + 1)                + s->b8_stride*s->mb_height*2 + s->mb_x - 1;
3374
    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;
3357 3375
    
3358 3376
    if(s->pict_type==B_TYPE && s->avctx->draw_horiz_band && s->picture_structure==PICT_FRAME){
3359 3377
        s->dest[0] = s->current_picture.data[0] + s->mb_x * 16 - 16;

Also available in: Unified diff