函數調用邏輯
avformat_open_input
init_input
av_probe_input_buffer2
函數原型
static int init_input(AVFormatContext *s, const char *filename, AVDictionary **options)
函數說明
該函數主要是初始化AVInputFormat結構體,主要是調用av_probe_input_buffer2函數探測碼流格式。AVFormatContext結構體flags變量,在經過avformat_alloc_context創建AVFormatContext結構體對象指針之後,flags值是0x200000(AVFMT_FLAG_AUTO_BSF),含義是等待包數據然後確定碼流的文件格式,或者是添加一個字節流的過濾器(Wait for packet data before writing a header, and add bitstream filters as requested by the muxer)
AVFMT_FLAG_DISCARD_CORRUPT 0x0100 ///< Discard frames marked corrupted
AVInputFormat結構體flags變量,在經過av_find_input_format("h264"),返回之後flags的值是0x0100(AVFMT_FLAG_DISCARD_CORRUPT)(Discard frames marked corrupted)
函數代碼
static int init_input(AVFormatContext *s, const char *filename,
AVDictionary **options)
{
int ret;
AVProbeData pd = { filename, NULL, 0 };
int score = AVPROBE_SCORE_RETRY;
if (s->pb) {
//當前的flags是0x200000
s->flags |= AVFMT_FLAG_CUSTOM_IO;
//iformat指定h264碼流格式之後,不爲NULL
if (!s->iformat)
return av_probe_input_buffer2(s->pb, &s->iformat, filename,
s, 0, s->format_probesize);
//s->iformat->flags & AVFMT_NOFILE值爲真,但是並沒有在日誌文件中打印出來Custom AVIOContext makes no sense
else if (s->iformat->flags & AVFMT_NOFILE)
av_log(s, AV_LOG_WARNING, "Custom AVIOContext makes no sense and "
"will be ignored with AVFMT_NOFILE format.\n");
return 0;
}
if ((s->iformat && s->iformat->flags & AVFMT_NOFILE) ||
(!s->iformat && (s->iformat = av_probe_input_format2(&pd, 0, &score))))
return score;
if ((ret = s->io_open(s, &s->pb, filename, AVIO_FLAG_READ | s->avio_flags, options)) < 0)
return ret;
if (s->iformat)
return 0;
return av_probe_input_buffer2(s->pb, &s->iformat, filename,
s, 0, s->format_probesize);
}