respect
致敬雷神
start
从 AVFormatContext (解封装结构体) 入口开始吧 …
1 | libavformat/options.c |
1 | libavformat/demux.c |
1 | libavformat/demux.c |
1 | libavformat/options.c |
1 | libavformat/aviobuf.c |
1 | libavformat/avio.c |
1 | libavformat/aviobuf.c |
1 | libavformat/http.c |
1 | libavformat/avio.c |
1 | libavformat/tcp.c |
整体的代码流程如上,关键入口都在对应的地方加了注释
class relation
avformat 初始化 根据 url协议找到 urlprotocol, 创建urlcontext & aviocontext
三者的关系如下
1 | avformatcontext.pb = aviocontext |
urlprotocol privdata 指定为 httpcontext
httpcontext 内部持有的urlcontext 根据 tcp 找到tcpprotocolhttpconext.hd = urlcontext
后续进入到 tcp 发送数据的流程
SSL/TLS
上面为了快速弄清楚调用过程,当做http处理,简化了tls这一块,https早已普及,所以https 跟 tcp 中间有一层 ssl/tls
ffmpeg 内部处理tls协议的有好几个 gnutls openssl schannel securetransport libtls mbedtls
根据不用的平台保留对应的哪一个,我的设备是mac,对应的是 securetransport
1 | libavformat/tls_securetransport.c |
1 | libavformat/tls.c |
tls这块的处理逻辑 作为http 跟 tcp的中间层,都是遵循的URLProtocol协议,所以流程基本跟http、tcp一样。
关键点也同样加了对应的注释辅助理解,关于sslcontext 见下面的苹果文档, 如果熟悉tls的四次握手,基本还是可以理解。
summary
整个代码过程顺下来,基本就是网络协议的调用过程,http/https -> ssl/tls -> tcp(socket)
最后来一张wireshark的抓包,很明显看到从tcp的三次握手开始, 紧接着tls的四次捂手,然后就是真正的请求数据的传输了…