1. ffmpeg中的http協(xié)議相關(guān)代碼閱讀筆記 http://blog.csdn.net/toymaker/article/details/6037926 此文解答了我的一個(gè)大疑惑 ,, 關(guān)于 HTTPContxt是什么? 以下是摘自上面鏈接。 http.c函數(shù)的URLProtocol結(jié)構(gòu)體中有個(gè)PrivateData的指針,,這個(gè)指針存儲(chǔ)了http協(xié)議中的一些內(nèi)部使用到的數(shù)據(jù)變量,內(nèi)部處理的數(shù)據(jù)變量結(jié)構(gòu)體如下: typedef struct { const AVClass *class; URLContext *hd; unsigned char buffer[BUFFER_SIZE], *buf_ptr, *buf_end; int line_count; int http_code; int64_t chunksize; /**< Used if "Transfer-Encoding: chunked" otherwise -1. */ int64_t off, filesize; char location[MAX_URL_SIZE]; HTTPAuthState auth_state; unsigned char headers[BUFFER_SIZE]; int willclose; /**< Set if the server correctly handles Connection: close and will close the connection after feeding us the content. */ } HTTPContext; 可以看到一個(gè)比較重要的信息是:該私有的內(nèi)部數(shù)據(jù)中竟然也有一個(gè)URLContext,,那這個(gè)是什么呢?這個(gè)URLContext的協(xié)議又是什么呢,?我通過(guò)閱讀代碼發(fā)現(xiàn)這個(gè)URLContext就是指向的tcp協(xié)議,用來(lái)通過(guò)tcp讀取和返回?cái)?shù)據(jù),。很感慨阿,。這樣很簡(jiǎn)單的就可以同時(shí)支持http,,tcp協(xié)議,而且把tcp,udp協(xié)議封裝起來(lái)以后,,基本上其他的像rtsp, mms等協(xié)議也可以通過(guò)制定他們自己的內(nèi)在協(xié)議來(lái)處理了。 2. 接下來(lái)由點(diǎn)及面,。 對(duì)應(yīng)ffmpeg幾個(gè)關(guān)鍵結(jié)構(gòu)體幫助對(duì)于框架學(xué)習(xí),, 參照如下: 2.1 雷神的: FFMPEG中最關(guān)鍵的結(jié)構(gòu)體之間的關(guān)系 http://blog.csdn.net/leixiaohua1020/article/details/11693997 我的使用場(chǎng)景 http ts流解析部分(解碼部分不提), 對(duì)應(yīng)的結(jié)構(gòu)體主要在: libavformat/http.c libavformat/mpegts.c libavformat/avio.c avio.h, 以下為個(gè)人見(jiàn)解,,可能出錯(cuò)請(qǐng)指出,。 avio.c -> http.c -> mpegts.c 首先看了avio.c: url_open-> ffurl_open->ffurl_alloc&ffurl_connect ffurl_read->retry_transfer_wrapper 此處卡住了,, 分析點(diǎn)1 : int ffurl_connect(URLContext* uc) { int err = uc->prot->url_open(uc, uc->filename, uc->flags); ...... ] 查看URLContext: 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,。 uc->prot->url_open(uc, uc->filename, uc->flags);此處正是調(diào)用到http.c url_open 接著看http.c URLProtocol ff_http_protocol = { .name = "http", .url_open = http_open, .url_read = http_read_compressed,/*http_read*/ .url_write = http_write, .url_seek = http_seek, .url_close = http_close, .url_getinfo = http_get_info, .url_get_file_handle = http_get_file_handle, .priv_data_size = sizeof(HTTPContext), .priv_data_class = &httpcontext_class, }; URLProtocol ff_shttp_protocol = { .name = "shttp", .url_open = shttp_open, .url_read = http_read_compressed,/*http_read*/ .url_write = http_write, .url_seek = http_seek, .url_close = http_close, .url_getinfo = http_get_info, .url_get_file_handle = http_get_file_handle, .priv_data_size = sizeof(HTTPContext), .priv_data_class = &shttpcontext_class, }; 分析點(diǎn)2 retry_transfer_wrapper ret=retry_transfer_wrapper(h, buf+readedlen, toread, toread, h->prot->url_read); ffurl_read()調(diào)用retry_transfer_wrapper()的時(shí)候,最后一個(gè)參數(shù)是URLProtocol的url_read(),,而ffurl_write()調(diào)用retry_transfer_wrapper()的時(shí)候,,最后一個(gè)參數(shù)是URLProtocol的url_write(), 此處邏輯是 retry_transfer_wrapper (avio.c) -> url_read既是http_read (http.c) 至此 : Protocol layer 的應(yīng)該是完成了。 url_open-> ffurl_open->ffurl_alloc&ffurl_connect (avio.c) -> http_open(http.c) ffurl_read->retry_transfer_wrapper-> url_read既是http_read (http.c) 看了url_oepn ,, int url_open(URLContext **puc, const char *filename, int flags) { return ffurl_open(puc, filename, flags); } 此處應(yīng)該只是 URLContext-> URLProtocol 原文鏈接:https://blog.csdn.net/Sam_sunbeyond/article/details/79257582 |
|
來(lái)自: 開(kāi)花結(jié)果 > 《FFMPEG》