extern const PixFmtInfo pix_fmt_info[] 的链接问题

在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,

    },

………….

};

转载请标明出处: http://blog.csdn.net/lights_joy/archive/2008/12/11/3500595.aspx

你可能感兴趣的:(C++,ffmpeg,Const,extern)