FFmpeg總結(七)AV系列結構體之AVIOContext

轉載:逆流的魚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: |                          |                                   |
 *               +--------------------------+-----------------------------------+
 *
 */
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章