4-27 x264_frame_copy_picture

dst->i_type     = src->i_type;

    dst->i_qpplus1  = src->i_qpplus1;

         //printf("src->i_pts is [%d]\n",src->i_pts);

    dst->i_pts      = dst->i_reordered_pts = src->i_pts;

    dst->param      = src->param;

    dst->i_pic_struct = src->i_pic_struct;

    dst->extra_sei  = src->extra_sei;

dst->opaque     = src->opaque;

初步对于当前帧的 i_type ,i_qpplus1,i_pts,param,i_pic_struct,extra_sei,opaque赋值

I_pts貌似和帧的数目是一致的,从1到217  pts dts 的一些解释http://www.cnblogs.com/qingquan/archive/2011/07/27/2118967.html

I_pic_struct中指明的是当前帧类型,是帧或者场,看定义里面还有double frame和triple frame的设置

I_type编码帧的类型,ipb之类的,这里应该只是初始化一下。全部都是0

I_qpplus1 注释是 force quantizer for != X264_QP_AUTO 应该是跟量化器相关的设置

Param 就是最开始那个x264_param

Void *opaque 注释 private user data,copies from input to output frames

 

函数get_plane_ptr()  就是为了 最开始定义的 pix[3] 和 stride[3]赋值

调用参数 get_plane_ptr( h, src, &pix[0], &stride[0], 0, 0, 0 );

uint8_t *pix[3];

int stride[3];

h->param.i_width (1920),h->param->height(1080)就是要编码帧的宽度和高度

 

 

只是为了对于临时数组里面做一些基本赋值

static int get_plane_ptr( x264_t *h, x264_picture_t *src, uint8_t **pix, int *stride, int plane, int xshift, int yshift )

{

    int width = h->param.i_width >> xshift;

    int height = h->param.i_height >> yshift;

*pix = src->img.plane[plane];

//应该是亮度和色度的 1920 960 960 这样交替出现的,1920应该是一行中色度的取值

//横向的 cb和 cr都是亮度一般 所以两个960

    *stride = src->img.i_stride[plane];

    if( src->img.i_csp & X264_CSP_VFLIP )

    {   //这里没有执行

        *pix += (height-1) * *stride;

        *stride = -*stride;

    }

    if( width > abs(*stride) )

    {

        x264_log( h, X264_LOG_ERROR, "Input picture width (%d) is greater than stride (%d)\n", width, *stride );

        return -1;

    }

    return 0;

}

 

 

int x264_frame_copy_picture( x264_t *h, x264_frame_t *dst, x264_picture_t *src )

{

    int i_csp = src->img.i_csp & X264_CSP_MASK;

    if( i_csp <= X264_CSP_NONE || i_csp >= X264_CSP_MAX )

    {

        x264_log( h, X264_LOG_ERROR, "Invalid input colorspace\n" );

        return -1;

    }

 

#if HIGH_BIT_DEPTH

    if( !(src->img.i_csp & X264_CSP_HIGH_DEPTH) )

    {

        x264_log( h, X264_LOG_ERROR, "This build of x264 requires high depth input. Rebuild to support 8-bit input.\n" );

        return -1;

    }

#else

    if( src->img.i_csp & X264_CSP_HIGH_DEPTH )

    {

        x264_log( h, X264_LOG_ERROR, "This build of x264 requires 8-bit input. Rebuild to support high depth input.\n" );

        return -1;

    }

#endif

        

    dst->i_type     = src->i_type;

         //printf("[%d]",dst->i_type);

    dst->i_qpplus1  = src->i_qpplus1;

         //printf("src->i_pts is [%d]\n",src->i_pts);

    dst->i_pts      = dst->i_reordered_pts = src->i_pts;

    dst->param      = src->param;

    dst->i_pic_struct = src->i_pic_struct;

    dst->extra_sei  = src->extra_sei;

    dst->opaque     = src->opaque;

 

    uint8_t *pix[3];

    int stride[3];

        

    if ( i_csp >= X264_CSP_BGR )   //YUV小于RGB的

    {

                   printf("===============================error of my thingking===================");

         stride[0] = src->img.i_stride[0];

         pix[0] = src->img.plane[0];

         if( src->img.i_csp & X264_CSP_VFLIP )

         {

             pix[0] += (h->param.i_height-1) * stride[0];

             stride[0] = -stride[0];

         }

         int b = i_csp==X264_CSP_RGB;

         h->mc.plane_copy_deinterleave_rgb( dst->plane[1+b], dst->i_stride[1+b],

                                            dst->plane[0], dst->i_stride[0],

                                            dst->plane[2-b], dst->i_stride[2-b],

                                            (pixel*)pix[0], stride[0]/sizeof(pixel), i_csp==X264_CSP_BGRA ? 4 : 3, h->param.i_width, h->param.i_height );

    }

    else

    {

        int v_shift = CHROMA_V_SHIFT;

        get_plane_ptr( h, src, &pix[0], &stride[0], 0, 0, 0 );

                   //只是做了内存拷贝  下面有这个函数的实现  mc.c

        h->mc.plane_copy( dst->plane[0], dst->i_stride[0], (pixel*)pix[0],

                          stride[0]/sizeof(pixel), h->param.i_width, h->param.i_height );

        if( i_csp == X264_CSP_NV12 || i_csp == X264_CSP_NV16 )

        {

                 printf("i_csp == X264_CSP_NV12 || i_csp == X264_CSP_NV16  1\n");

            get_plane_ptr( h, src, &pix[1], &stride[1], 1, 0, v_shift );

            h->mc.plane_copy( dst->plane[1], dst->i_stride[1], (pixel*)pix[1],

                              stride[1]/sizeof(pixel), h->param.i_width, h->param.i_height>>v_shift );

        }

                   //ics == x264_csp_i420

        else if( i_csp == X264_CSP_I420 || i_csp == X264_CSP_I422 || i_csp == X264_CSP_YV12 || i_csp == X264_CSP_YV16 )

        {        //printf("====================2==========\n    excute here");

            int uv_swap = i_csp == X264_CSP_YV12 || i_csp == X264_CSP_YV16;

            get_plane_ptr( h, src, &pix[1], &stride[1], uv_swap ? 2 : 1, 1, v_shift );

            get_plane_ptr( h, src, &pix[2], &stride[2], uv_swap ? 1 : 2, 1, v_shift );

            h->mc.plane_copy_interleave( dst->plane[1], dst->i_stride[1],

                                         (pixel*)pix[1], stride[1]/sizeof(pixel),

                                         (pixel*)pix[2], stride[2]/sizeof(pixel),

                                         h->param.i_width>>1, h->param.i_height>>v_shift );

                            /*****************************h  recreate memory to store the picture**************************/

                            //printf("the x264_picture memoryis %d \n");

                            //printf("the x264_t memory is %d\n");

                            /*****************************h  recreate memory to store the picture**************************/

        }

        else //if( i_csp == X264_CSP_I444 || i_csp == X264_CSP_YV24 )

        {       printf("===================3===================\n");

            get_plane_ptr( h, src, &pix[1], &stride[1], i_csp==X264_CSP_I444 ? 1 : 2, 0, 0 );

            get_plane_ptr( h, src, &pix[2], &stride[2], i_csp==X264_CSP_I444 ? 2 : 1, 0, 0 );

            h->mc.plane_copy( dst->plane[1], dst->i_stride[1], (pixel*)pix[1],

                              stride[1]/sizeof(pixel), h->param.i_width, h->param.i_height );

            h->mc.plane_copy( dst->plane[2], dst->i_stride[2], (pixel*)pix[2],

                              stride[2]/sizeof(pixel), h->param.i_width, h->param.i_height );

        }

    }

    return 0;

}

 

 

 

void x264_plane_copy_c( pixel *dst, intptr_t i_dst,

                        pixel *src, intptr_t i_src, int w, int h )

{

    while( h-- )

    {

        memcpy( dst, src, w * sizeof(pixel) );

        dst += i_dst;

        src += i_src;

    }

}

 

 

void x264_plane_copy_interleave_c( pixel *dst,  intptr_t i_dst,

                                   pixel *srcu, intptr_t i_srcu,

                                   pixel *srcv, intptr_t i_srcv, int w, int h )

{

    for( int y=0; y<h; y++, dst+=i_dst, srcu+=i_srcu, srcv+=i_srcv )

        for( int x=0; x<w; x++ )

        {

            dst[2*x]   = srcu[x];

            dst[2*x+1] = srcv[x];

        }

}

posted on 2012-04-27 12:54  hatreds  阅读(2002)  评论(0编辑  收藏  举报