首页 > 其他分享 >结构体指定初始化

结构体指定初始化

时间:2022-09-29 11:23:42浏览次数:49  
标签:初始化 AVFMT struct AVFormatContext int 指定 read stream 结构

结构体指定初始化应该是C和C++都有的一个语法。这个语法在ffmpeg中被大量使用。

 

1. 应用场景

比如ffmpeg中

AVInputFormat ff_mov_demuxer = {
    .name           = "mov,mp4,m4a,3gp,3g2,mj2",
    .long_name      = NULL_IF_CONFIG_SMALL("QuickTime / MOV"),
    .priv_class     = &mov_class,
    .priv_data_size = sizeof(MOVContext),
    .extensions     = "mov,mp4,m4a,3gp,3g2,mj2",
    .read_probe     = mov_probe,
    .read_header    = mov_read_header,
    .read_packet    = mov_read_packet,
    .read_close     = mov_read_close,
    .read_seek      = mov_read_seek,
    .flags          = AVFMT_NO_BYTE_SEEK | AVFMT_SEEK_TO_PTS,
};

AVInputFormat 的定义是:

typedef struct AVInputFormat {
    /**
     * A comma separated list of short names for the format. New names
     * may be appended with a minor bump.
     */
    const char *name;

    /**
     * Descriptive name for the format, meant to be more human-readable
     * than name. You should use the NULL_IF_CONFIG_SMALL() macro
     * to define it.
     */
    const char *long_name;

    /**
     * Can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_SHOW_IDS,
     * AVFMT_NOTIMESTAMPS, AVFMT_GENERIC_INDEX, AVFMT_TS_DISCONT, AVFMT_NOBINSEARCH,
     * AVFMT_NOGENSEARCH, AVFMT_NO_BYTE_SEEK, AVFMT_SEEK_TO_PTS.
     */
    int flags;

    /**
     * If extensions are defined, then no probe is done. You should
     * usually not use extension format guessing because it is not
     * reliable enough
     */
    const char *extensions;

    const struct AVCodecTag * const *codec_tag;

    const AVClass *priv_class; ///< AVClass for the private context

    /**
     * Comma-separated list of mime types.
     * It is used check for matching mime types while probing.
     * @see av_probe_input_format2
     */
    const char *mime_type;

    /*****************************************************************
     * No fields below this line are part of the public API. They
     * may not be used outside of libavformat and can be changed and
     * removed at will.
     * New public fields should be added right above.
     *****************************************************************
     */
    ff_const59 struct AVInputFormat *next;

    /**
     * Raw demuxers store their codec ID here.
     */
    int raw_codec_id;

    /**
     * Size of private data so that it can be allocated in the wrapper.
     */
    int priv_data_size;

    /**
     * Tell if a given file has a chance of being parsed as this format.
     * The buffer provided is guaranteed to be AVPROBE_PADDING_SIZE bytes
     * big so you do not have to check for that unless you need more.
     */
    int (*read_probe)(const AVProbeData *);

    /**
     * Read the format header and initialize the AVFormatContext
     * structure. Return 0 if OK. 'avformat_new_stream' should be
     * called to create new streams.
     */
    int (*read_header)(struct AVFormatContext *);

    /**
     * Read one packet and put it in 'pkt'. pts and flags are also
     * set. 'avformat_new_stream' can be called only if the flag
     * AVFMTCTX_NOHEADER is used and only in the calling thread (not in a
     * background thread).
     * @return 0 on success, < 0 on error.
     *         When returning an error, pkt must not have been allocated
     *         or must be freed before returning
     */
    int (*read_packet)(struct AVFormatContext *, AVPacket *pkt);

    /**
     * Close the stream. The AVFormatContext and AVStreams are not
     * freed by this function
     */
    int (*read_close)(struct AVFormatContext *);

    /**
     * Seek to a given timestamp relative to the frames in
     * stream component stream_index.
     * @param stream_index Must not be -1.
     * @param flags Selects which direction should be preferred if no exact
     *              match is available.
     * @return >= 0 on success (but not necessarily the new offset)
     */
    int (*read_seek)(struct AVFormatContext *,
                     int stream_index, int64_t timestamp, int flags);

    /**
     * Get the next timestamp in stream[stream_index].time_base units.
     * @return the timestamp or AV_NOPTS_VALUE if an error occurred
     */
    int64_t (*read_timestamp)(struct AVFormatContext *s, int stream_index,
                              int64_t *pos, int64_t pos_limit);

    /**
     * Start/resume playing - only meaningful if using a network-based format
     * (RTSP).
     */
    int (*read_play)(struct AVFormatContext *);

    /**
     * Pause playing - only meaningful if using a network-based format
     * (RTSP).
     */
    int (*read_pause)(struct AVFormatContext *);

    /**
     * Seek to timestamp ts.
     * Seeking will be done so that the point from which all active streams
     * can be presented successfully will be closest to ts and within min/max_ts.
     * Active streams are all streams that have AVStream.discard < AVDISCARD_ALL.
     */
    int (*read_seek2)(struct AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);

    /**
     * Returns device list with it properties.
     * @see avdevice_list_devices() for more details.
     */
    int (*get_device_list)(struct AVFormatContext *s, struct AVDeviceInfoList *device_list);

    /**
     * Initialize device capabilities submodule.
     * @see avdevice_capabilities_create() for more details.
     */
    int (*create_device_capabilities)(struct AVFormatContext *s, struct AVDeviceCapabilitiesQuery *caps);

    /**
     * Free device capabilities submodule.
     * @see avdevice_capabilities_free() for more details.
     */
    int (*free_device_capabilities)(struct AVFormatContext *s, struct AVDeviceCapabilitiesQuery *caps);
} AVInputFormat;

 

 

2.测试案例

代码:

#include<string>
#include<iostream>

using namespace std;



struct Student
{
    string name;
    int age;
    int (*print)();
};

int show(){
    cout << "show show show" << endl;
    return 0;
}

Student stu = {
    .name = "cmhu",
    .age = 20,
    .print = show
};

int main(){
    stu.print();
    return 0;
}

运行结果:

image

 

 

 

 

 

 

 

 

 

 

 

 

 

 


 

标签:初始化,AVFMT,struct,AVFormatContext,int,指定,read,stream,结构
From: https://www.cnblogs.com/betterwgo/p/16740793.html

相关文章

  • 数据结构与算法(数组&二维数组)
    数组集合、列表和数组集合:一个或多个元素构成的整体,里面的元素类型不一定相同,且是无序的列表:又称线性列表,有顺序且长度是可变的,没有索引有顺序,可以增删改数组:列表的实......
  • MySQL目录结构和SQL的基本概念
    MySQL目录结构Data目录和my.ini文件有时并不放在MySQL的安装目录下,而是在配置文件中自己指定的目录下。一般情况下,C盘下的ProgramData目录是隐藏的,需要取消隐藏(1......
  • powershell 检查电脑指定软件安装情况
    `#1获取当前日期$collect_date=Get-Date-Format"yyyy-MM-ddHH_mm"2获取计算机主机名$ComputerName=hostname3定义需要查询的软件名称$AppDisplayName="Anyshar......
  • python pip install指定国内源镜像
    有时候安装一些依赖包,网不好,直接超时,或者这个包就是死都下不下来的时候,可以指定国内源镜像。pipinstall-i国内镜像地址包名e.g.pipinstall-i  http://mirr......
  • php-fpm指定配置文件及php相关配置命令
    [root@hostnamecentos7sbin]#./php-fpm-c/usr/local/php/etc/php.ini-y/usr/local/php/etc/php-fpm.conf ......
  • Linux开发环境搭建与使用——Linux 目录结构及文件
    在windows平台下,打开“计算机”,我们看到的是一个个的盘符:在Linux下,我们是看不到这些盘符,我们看到的是文件夹(目录):在早期的UNIX系统中,各个厂家各自定义了自己的UNIX系......
  • 数据结构学习——BST删除特定节点
    BST删除特定节点前言一个平常的星期三晚上,一节通选课中,在老师放的视频和极寒空调的折磨之下,想着做点别的什么的我,打开了博客园。想起来做题下午数据结构课中老师最后在......
  • 虚拟机挂载到开发板的脚本文件,可以指定挂载目录,能自动设置开发板的ip
    虚拟机挂载到开发板的脚本文件,可以指定挂载目录,能自动设置开发板的ip:echo-e"未占用IP\n">ip#把ip重定向到ip文件里,作为记录src=10.221.0.71:/home/wencong#虚拟机需......
  • 流程控制之while与for结构
    while与for循环while循环结构的补充死循环真正的死循环是一旦执行,CPU功能消耗就会急速上升,直到系统采取紧急措施,尽量不要让CPU长时间不间断运算死循环案例eg1:......
  • for循环结构/while注意事项/range方法及实战
    目录今日内容概要1.while循环补充说明2.流程控制之for循环(重点)3.range方法及实战4.今日练习题及答案今日内容概要while循环补充说明控制流程之for循环(重点)range方法......