FFmpeg总结(七)AV系列结构体之AVIOContext

论坛 期权论坛 脚本     
匿名网站用户   2020-12-21 08:15   95   0

转载:逆流的鱼yuiop博客,原地址:http://blog.csdn.net/hejjunlin/article/details/70225206



AVIOContext结构体位于libavformat/avio.h下:

这里写图片描述

AVIOContext的描述:

是字节流IO上下文, AVIOContext不能直接被函数指针调用,应当在应用程序实现自定义IO时,通常是通过avio_alloc_conext()函数进行设置函数指针。

AVIOContext的成员变量:

typedef struct AVIOContext {
     // 一个私有类选项
     // 如果AVIOContext被创建通过avio_open2()函数,av_class可以通过设置的协议选项设置
     // 如果AVIOContext被创建通过avio_alloc_conext(),av_class被调用者设置
    const AVClass *av_class;
    unsigned char *buffer;  // 起始buffer
    int buffer_size;        // 最大buffer大小
    unsigned char *buf_ptr; // 当前buffer中的position
    // 1、指向buffer数据尾部的指针
    // 2、如果read的data返回小于data实际需要的,
    // 它将小于buffer+buffer_size的大小,如streams没有更多数据接受了
    unsigned char *buf_end; 
    void *opaque;           // 一个私有容器,通过read/write/seek操作
    int (*read_packet)(void *opaque, uint8_t *buf, int buf_size);
    int (*write_packet)(void *opaque, uint8_t *buf, int buf_size);
    int64_t (*seek)(void *opaque, int64_t offset, int whence);
    int64_t pos;            // 文件中当前buffer的position
    int must_flush;         // 如果下一次seek要flush操作,返回true
    int eof_reached;        // 如果出现EOF(资源无更多读取),返回true
    int write_flag;         // 打开文件正在write的标识
    int max_packet_size;
    unsigned long checksum;
    unsigned char *checksum_ptr;
    unsigned long (*update_checksum)(unsigned long checksum, const uint8_t *buf, unsigned int size);
    int error;              /**< contains the error code or 0 if no error happened */
    // 网络流协议pause或resume playback时,如MMS
    int (*read_pause)(void *opaque, int pause);
    // seek到给定的时间戳,一些网络流协议不支持seek到对应位置,如直播流
    int64_t (*read_seek)(void *opaque, int stream_index,
                         int64_t timestamp, int flags);
    // 是否能seek,通过AVIO_SEEKABLE标识,当stream不能seek时
    int seekable;

    // 最大文件大小,被用于限制所分配的空间时
    int64_t maxsize;

    // avio_read 及avio_write应满足直接读写,而不是通过一个缓冲区,avio_seek将被直接调用,当seek操作时。
    int direct;

     // 字节读取数据
    int64_t bytes_read;

    // seek读取数据
    int seek_count;

    //字节写入数据
    int writeout_count;

    //原始buffer大小
    int orig_buffer_size;

    int short_seek_threshold;

     //分离用‘,’的可用协议集
    const char *protocol_whitelist;

    //分离用‘,’的不可用协议集
    const char *protocol_blacklist;

    // 代替write_packet的回调函数
    int (*write_data_type)(void *opaque, uint8_t *buf, int buf_size,
                           enum AVIODataMarkerType type, int64_t time);

    int ignore_boundary_point;

    enum AVIODataMarkerType current_type;
    int64_t last_time;
} AVIOContext;
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68

AVIOContext读写时,buffer,buf_ptr,buf_end,buf_size及pos之间的关系:

/*
 * The following shows the relationship between buffer, buf_ptr, buf_end, buf_size,
 * and pos, when reading and when writing (since AVIOContext is used for both):
 *
 **********************************************************************************
 *                                   READING
 **********************************************************************************
 *
 *                            |              buffer_size              |
 *                            |---------------------------------------|
 *                            |                                       |
 *
 *                         buffer          buf_ptr       buf_end
 *                            +---------------+-----------------------+
 *                            |/ / / / / / / /|/ / / / / / /|         |
 *  read buffer:              |/ / consumed / | to be read /|         |
 *                            |/ / / / / / / /|/ / / / / / /|         |
 *                            +---------------+-----------------------+
 *
 *                                                         pos
 *              +-------------------------------------------+-----------------+
 *  input file: |                                           |                 |
 *              +-------------------------------------------+-----------------+
 *
 *
 **********************************************************************************
 *                                   WRITING
 **********************************************************************************
 *
 *                                          |          buffer_size          |
 *                                          |-------------------------------|
 *                                          |                               |
 *
 *                                       buffer              buf_ptr     buf_end
 *                                          +-------------------+-----------+
 *                                          |/ / / / / / / / / /|           |
 *  write buffer:                           | / to be flushed / |           |
 *                                          |/ / / / / / / / / /|           |
 *                                          +-------------------+-----------+
 *
 *                                         pos
 *               +--------------------------+-----------------------------------+
 *  output file: |                          |                                   |
 *               +--------------------------+-----------------------------------+
 *
 */
分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:1136255
帖子:227251
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP