AVIOContext是FFMPEG管理輸入輸出數(shù)據(jù)的結(jié)構(gòu)體。
參考結(jié)構(gòu)體理解:http://www.itdecent.cn/p/d109e7ef9749
unsigned char *buffer
:緩存開始位置
在解碼的情況下,buffer用于存儲(chǔ)ffmpeg讀入的數(shù)據(jù)。例如打開一個(gè)視頻文件的時(shí)候,先把數(shù)據(jù)從硬盤讀入buffer,然后在送給解碼器用于解碼。
int buffer_size
:緩存大?。J(rèn)32768)
unsigned char *buf_ptr
:當(dāng)前指針讀取到的位置
unsigned char *buf_end
:緩存結(jié)束的位置
void *opaque :URLContext結(jié)構(gòu)體
typedef struct URLContext {
const AVClass *av_class; ///< information for av_log(). Set by url_open().
struct URLProtocol *prot;
int flags;
int is_streamed; /**< true if streamed (no seek possible), default = false */
int max_packet_size; /**< if non zero, the stream is packetized with this max packet size */
void *priv_data;
char *filename; /**< specified URL */
int is_connected;
AVIOInterruptCB interrupt_callback;
} URLContext;
URLContext結(jié)構(gòu)體中還有一個(gè)結(jié)構(gòu)體URLProtocol。注:每種協(xié)議(rtp,rtmp,file等)對(duì)應(yīng)一個(gè)URLProtocol。這個(gè)結(jié)構(gòu)體也不在FFMPEG提供的頭文件中。從FFMPEG源代碼中翻出其的定義:
typedef struct URLProtocol {
const char *name;
int (*url_open)(URLContext *h, const char *url, int flags);
int (*url_read)(URLContext *h, unsigned char *buf, int size);
int (*url_write)(URLContext *h, const unsigned char *buf, int size);
int64_t (*url_seek)(URLContext *h, int64_t pos, int whence);
int (*url_close)(URLContext *h);
struct URLProtocol *next;
int (*url_read_pause)(URLContext *h, int pause);
int64_t (*url_read_seek)(URLContext *h, int stream_index,
int64_t timestamp, int flags);
int (*url_get_file_handle)(URLContext *h);
int priv_data_size;
const AVClass *priv_data_class;
int flags;
int (*url_check)(URLContext *h, int mask);
} URLProtocol;
在這個(gè)結(jié)構(gòu)體中,除了一些回調(diào)函數(shù)接口之外,有一個(gè)變量const char *name,該變量存儲(chǔ)了協(xié)議的名稱。每一種輸入?yún)f(xié)議都對(duì)應(yīng)這樣一個(gè)結(jié)構(gòu)體。
URLProtocol ff_rtmp_protocol = {
.name = "rtmp",
.url_open = rtmp_open,
.url_read = rtmp_read,
.url_write = rtmp_write,
.url_close = rtmp_close,
.url_read_pause = rtmp_read_pause,
.url_read_seek = rtmp_read_seek,
.url_get_file_handle = rtmp_get_file_handle,
.priv_data_size = sizeof(RTMP),
.flags = URL_PROTOCOL_FLAG_NETWORK,
};