Avformat_open_input函数的分析之--HTTP篇

本文详细分析了Avformat_open_input函数在处理HTTP协议时的关键步骤,包括接口参数解析、函数调用流程,如init_input、ffio_open_whitelist、ffurl_open_whitelist等,深入探讨了HTTP连接的建立、请求发送和响应接收的过程,揭示了ffmpeg在处理HTTP链接时的内部工作机制。
摘要由CSDN通过智能技术生成

接口参数的解析
函数的关键函数实现
init_input函数
ffio_open_whitelist函数
ffurl_open_whitelist函数
ffurl_connect函数
http_open函数
http_open_cnx_internal函数

1.接口参数的解析

首先看函数的声明

int avformat_open_input(AVFormatContext **ps, const char *filename,
                        AVInputFormat *fmt, AVDictionary **options)

AVDictionary **options

struct AVDictionary {
  int count;
  AVDictionaryEntry *elems;
};
typedef struct AVDictionaryEntry {
  char *key;
  char *value;
} AVDictionaryEntry;

字典类型的可选参数,可以向ffmpeg中传入指定的参数的值。
比如我们这里传入了av_dict_set_int(&ffp->format_opts, "fpsprobesize", 0, 0); 表示fpsprobesize对应的参数值为0,当然还可以传入更多值,具体可以参考options_table.h这个头文件。

2.函数的关键函数实现

avformat_open_input的具体实现在libavformat/utils.c文件。

init_input函数

第一次调用avformat_open_input函数时,传入的ps是属于初始化状态,很多部分可以忽略,直接跳到以下部分

if ((ret = init_input(s, filename, &tmp)) < 0)
        goto fail;

init_input函数的声明如下

/* Open input file and probe the format if necessary. */
static int init_input(AVFormatContext *s, const char *filename,
                      AVDictionary **options)

函数的主要功能如注释一样,打开一个文件链接,并尽可能解析出该文件的格式。它里面关键的调用是

if ((ret = s->io_open(s, &s->pb, filename, AVIO_FLAG_READ | 
                      s->avio_flags, options)) < 0)
        return ret;

io_open函数是一个回调函数。一般情况下是采用的默认函数io_open_default,具体的赋值是在libavformat/option.c文件中,调用过程如下:

avformat_alloc_context->avformat_get_context_defaults->(s->io_open  = io_open_default;)

其中io_open_default的函数实现

static int io_open_default(AVFormatContext *s, AVIOContext **pb,
                           const char *url, int flags, AVDictionary **options)
{
    printf("io_open_default called\n");
#if FF_API_OLD_OPEN_CALLBACKS
FF_DISABLE_DEPRECATION_WARNINGS
    if (s->open_cb)
        return s->open_cb(s, pb, url, flags, &s->interrupt_callback, options);
FF_ENABLE_DEPRECATION_WARNINGS
#endif

    return ffio_open_whitelist(pb, url, flags, &s->interrupt_callback, options, s->protocol_whitelist, s->protocol_blacklist);
}

这里一般都是没有定义FF_API_OLD_OPEN_CALLBACKS宏的,所以实际是调用ffio_open_whitelist函数。

ffio_open_whitelist函数

继续跟进函数的定义和调用发现ffio_open_whitelist的实现是在libavformat/aviobuf.c

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值