FFmpeg结构体:AVIOContext

1.描述

AVIOContext是FFmpeg管理输入输出数据的结构体,位于avio.h文件中。

2.结构体定义

  1 typedef struct AVIOContext {
  2     /**
  3      * A class for private options.
  4      *
  5      * If this AVIOContext is created by avio_open2(), av_class is set and
  6      * passes the options down to protocols.
  7      *
  8      * If this AVIOContext is manually allocated, then av_class may be set by
  9      * the caller.
 10      *
 11      * warning -- this field can be NULL, be sure to not pass this AVIOContext
 12      * to any av_opt_* functions in that case.
 13      */
 14     const AVClass *av_class;
 15 
 16     /*
 17      * The following shows the relationship between buffer, buf_ptr, buf_end, buf_size,
 18      * and pos, when reading and when writing (since AVIOContext is used for both):
 19      *
 20      **********************************************************************************
 21      *                                   READING
 22      **********************************************************************************
 23      *
 24      *                            |              buffer_size              |
 25      *                            |---------------------------------------|
 26      *                            |                                       |
 27      *
 28      *                         buffer          buf_ptr       buf_end
 29      *                            +---------------+-----------------------+
 30      *                            |/ / / / / / / /|/ / / / / / /|         |
 31      *  read buffer:              |/ / consumed / | to be read /|         |
 32      *                            |/ / / / / / / /|/ / / / / / /|         |
 33      *                            +---------------+-----------------------+
 34      *
 35      *                                                         pos
 36      *              +-------------------------------------------+-----------------+
 37      *  input file: |                                           |                 |
 38      *              +-------------------------------------------+-----------------+
 39      *
 40      *
 41      **********************************************************************************
 42      *                                   WRITING
 43      **********************************************************************************
 44      *
 45      *                                          |          buffer_size          |
 46      *                                          |-------------------------------|
 47      *                                          |                               |
 48      *
 49      *                                       buffer              buf_ptr     buf_end
 50      *                                          +-------------------+-----------+
 51      *                                          |/ / / / / / / / / /|           |
 52      *  write buffer:                           | / to be flushed / |           |
 53      *                                          |/ / / / / / / / / /|           |
 54      *                                          +-------------------+-----------+
 55      *
 56      *                                         pos
 57      *               +--------------------------+-----------------------------------+
 58      *  output file: |                          |                                   |
 59      *               +--------------------------+-----------------------------------+
 60      *
 61      */
 62     unsigned char *buffer;  /**< Start of the buffer. */
 63     int buffer_size;        /**< Maximum buffer size */
 64     unsigned char *buf_ptr; /**< Current position in the buffer */
 65     unsigned char *buf_end; /**< End of the data, may be less than
 66                                  buffer+buffer_size if the read function returned
 67                                  less data than requested, e.g. for streams where
 68                                  no more data has been received yet. */
 69     void *opaque;           /**< A private pointer, passed to the read/write/seek/...
 70                                  functions. */
 71     int (*read_packet)(void *opaque, uint8_t *buf, int buf_size);
 72     int (*write_packet)(void *opaque, uint8_t *buf, int buf_size);
 73     int64_t (*seek)(void *opaque, int64_t offset, int whence);
 74     int64_t pos;            /**< position in the file of the current buffer */
 75     int must_flush;         /**< true if the next seek should flush */
 76     int eof_reached;        /**< true if eof reached */
 77     int write_flag;         /**< true if open for writing */
 78     int max_packet_size;
 79     unsigned long checksum;
 80     unsigned char *checksum_ptr;
 81     unsigned long (*update_checksum)(unsigned long checksum, const uint8_t *buf, unsigned int size);
 82     int error;              /**< contains the error code or 0 if no error happened */
 83     /**
 84      * Pause or resume playback for network streaming protocols - e.g. MMS.
 85      */
 86     int (*read_pause)(void *opaque, int pause);
 87     /**
 88      * Seek to a given timestamp in stream with the specified stream_index.
 89      * Needed for some network streaming protocols which don't support seeking
 90      * to byte position.
 91      */
 92     int64_t (*read_seek)(void *opaque, int stream_index,
 93                          int64_t timestamp, int flags);
 94     /**
 95      * A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
 96      */
 97     int seekable;
 98 
 99     /**
100      * max filesize, used to limit allocations
101      * This field is internal to libavformat and access from outside is not allowed.
102      */
103     int64_t maxsize;
104 
105     /**
106      * avio_read and avio_write should if possible be satisfied directly
107      * instead of going through a buffer, and avio_seek will always
108      * call the underlying seek function directly.
109      */
110     int direct;
111 
112     /**
113      * Bytes read statistic
114      * This field is internal to libavformat and access from outside is not allowed.
115      */
116     int64_t bytes_read;
117 
118     /**
119      * seek statistic
120      * This field is internal to libavformat and access from outside is not allowed.
121      */
122     int seek_count;
123 
124     /**
125      * writeout statistic
126      * This field is internal to libavformat and access from outside is not allowed.
127      */
128     int writeout_count;
129 
130     /**
131      * Original buffer size
132      * used internally after probing and ensure seekback to reset the buffer size
133      * This field is internal to libavformat and access from outside is not allowed.
134      */
135     int orig_buffer_size;
136 
137     /**
138      * Threshold to favor readahead over seek.
139      * This is current internal only, do not use from outside.
140      */
141     int short_seek_threshold;
142 
143     /**
144      * ',' separated list of allowed protocols.
145      */
146     const char *protocol_whitelist;
147 
148     /**
149      * ',' separated list of disallowed protocols.
150      */
151     const char *protocol_blacklist;
152 
153     /**
154      * A callback that is used instead of write_packet.
155      */
156     int (*write_data_type)(void *opaque, uint8_t *buf, int buf_size,
157                            enum AVIODataMarkerType type, int64_t time);
158     /**
159      * If set, don't call write_data_type separately for AVIO_DATA_MARKER_BOUNDARY_POINT,
160      * but ignore them and treat them as AVIO_DATA_MARKER_UNKNOWN (to avoid needlessly
161      * small chunks of data returned from the callback).
162      */
163     int ignore_boundary_point;
164 
165     /**
166      * Internal, not meant to be used from outside of AVIOContext.
167      */
168     enum AVIODataMarkerType current_type;
169     int64_t last_time;
170 } AVIOContext;

3.常见变量及其作用

 1 unsigned char *buffer; //缓存开始位置。
 2 int buffer_size; //缓冲区的大小。
 3 unsigned char *buf_ptr;//当前指针在缓冲区中的位置,即当前指针读取到的位置。
 4 unsigned char *buf_end; //缓存结束的位置
 5 
 6 void *opaque;//一个私有指针,传递给read / write / seek / ...函数。
 7 opaque指向了URLContext。URLContext结构体中还有一个结构体URLProtocol。
 8 ps:每种协议(rtp,rtmp,file等)对应一个URLProtocol。
 9 
10 int64_t pos; //当前缓冲区在文件中的位置。
11 int must_flush;  //如果下一次seek需要刷新则为真。
12 int eof_reached;  //是否读到eof,文件结尾。
13 int (*read_pause)(void *opaque, int pause);//暂停或恢复播放网络流媒体协议 - 例如 MMS。
14 int64_t (*read_seek)(void *opaque, int stream_index, int64_t timestamp, int flags);
15 //使用指定的stream_index查找流中给定的时间戳(对于不支持寻找字节位置的网络流协议)。

 

posted on 2024-06-11 14:34  粒子少爷  阅读(5)  评论(0编辑  收藏  举报