在vs2008下使用ffmpeg(4):结构体成员初始化

来源:互联网 发布:iapp锁机源码大全 编辑:程序博客网 时间:2024/06/06 09:37

 

快乐虾

http://blog.csdn.net/lights_joy/

lights@hb165.com

  

本文适用于

ffmpeg-checkout-20081210

vs2008

Windows XP

 

欢迎转载,但请保留作者信息

 

ffmpeg中,大量使用了c99中的结构体成员初始化方式,如libavcodec/imgconvert.c中的一个定义:

 

/* this table gives more information about formats */

static const PixFmtInfo pix_fmt_info[PIX_FMT_NB] = {

    /* YUV formats */

    [PIX_FMT_YUV420P] = {

        .name = "yuv420p",

        .nb_channels = 3,

        .color_type = FF_COLOR_YUV,

        .pixel_type = FF_PIXEL_PLANAR,

        .depth = 8,

        .x_chroma_shift = 1, .y_chroma_shift = 1,

    },

    [PIX_FMT_YUV422P] = {

        .name = "yuv422p",

        .nb_channels = 3,

        .color_type = FF_COLOR_YUV,

        .pixel_type = FF_PIXEL_PLANAR,

        .depth = 8,

        .x_chroma_shift = 1, .y_chroma_shift = 0,

    },

………..

};

这一段代码在vs2008下编译将产生很多语法错误,首先在这个结构体数组中,它使用了[PIX_FMT_*]这样的方式指定序号,这样数组的成员可以不必要按照顺序排列,但是在vs2008下,必须调整数组成员的顺序,使之按递增的顺序排列。此外,vs2008也不支持.name = “”这样的定义,因此可以做出如下修改:

 

/* this table gives more information about formats */

static const PixFmtInfo pix_fmt_info[PIX_FMT_NB] = {

    /* YUV formats */

    /*[PIX_FMT_YUV420P] =*/ { // PIX_FMT_YUV420P = 0

        /*.name = */"yuv420p",

        /*.nb_channels = */3,

        /*.color_type = */FF_COLOR_YUV,

        /*.pixel_type = */FF_PIXEL_PLANAR,

         /*.is_alpha = */0,

        /*.x_chroma_shift = */1,

         /*.y_chroma_shift = */1,

        /*.depth = */8,

    },

    /*[PIX_FMT_YUYV422] =*/ {    // PIX_FMT_YUYV422 = 1

        /*.name = */"yuyv422",

        /*.nb_channels = */1,

        /*.color_type = */FF_COLOR_YUV,

        /*.pixel_type = */FF_PIXEL_PACKED,

         /*.is_alpha = */0,

        /*.x_chroma_shift = */1,

         /*.y_chroma_shift = */0,

        /*.depth = */8,

    },

    /*[PIX_FMT_RGB24] =*/ {      // PIX_FMT_RGB24 = 2

        /*.name = */"rgb24",

        /*.nb_channels = */3,

        /*.color_type = */FF_COLOR_RGB,

        /*.pixel_type = */FF_PIXEL_PACKED,

         /*.is_alpha = */0,

        /*.x_chroma_shift = */0,

         /*.y_chroma_shift = */0,

        /*.depth = */8,

    },

………….

};

 

参考资料

vs2008下使用ffmpeg1):inttypes.h的问题(2008-12-11)

vs2008下使用ffmpeg2):readtime的问题(2008-12-11)

vs2008下使用ffmpeg3):结构体构建(2008-12-11)

 

 

 

原创粉丝点击