ByteIOContext结构封装了媒体数据流细节,将文件媒体流,网络媒体流抽象成一个字节序列的流,对上层提供了一个统一的接口,下面是对这个结构的详细的介绍。
typedef struct {
//数据缓冲区,存放字节序列的流。
unsigned char *buffer;
//数据缓冲区的大小。
int buffer_size;
//buf_ptr缓冲区当前数据指针。
//buf_end缓冲区数据结尾。
unsigned char *buf_ptr, *buf_end;
void *opaque;
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; /**< position in the file of the current buffer */
int must_flush; /**< true if the next seek should flush */
int eof_reached; /**< true if eof reached */
int write_flag; /**< true if open for writing */
int is_streamed;
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
int (*read_pause)(void *opaque, int pause);
int64_t (*read_seek)(void *opaque, int stream_index,
int64_t timestamp, int flags);
} ByteIOContext;