ffmpeg-hls拉流
协议接口变量
const URLProtocol ff_hls_protocol = { .name = "hls", .url_open = hls_open, .url_read = hls_read, .url_close = hls_close, .flags = URL_PROTOCOL_FLAG_NESTED_SCHEME, .priv_data_size = sizeof(HLSContext),};
从上面可以看出来一共就三个接口,打开,读取,关闭
打开
static int hls_open(URLContext *h, const char *uri, int flags){ HLSContext *s = h->priv_data; int ret, i; const char *nested_url; if (flags & AVIO_FLAG_WRITE) return AVERROR(ENOSYS); h->is_streamed = 1; if (av_strstart(uri, "hls+", &nested_url)) { av_strlcpy(s->playlisturl, nested_url, sizeof(s->playlisturl)); } else if (av_strstart(uri, "hls://", &nested_url)) { av_log(h, AV_LOG_ERROR, "No nested protocol specified. Specify e.g. hls+http://%s\n", nested_url); ret = AVERROR(EINVAL); goto fail; } else { av_log(h, AV_LOG_ERROR, "Unsupported url %s\n", uri); ret = AVERROR(EINVAL); goto fail; } av_log(h, AV_LOG_WARNING, "Using the hls protocol is discouraged, please try using the " "hls demuxer instead. The hls demuxer should be more complete " "and work as well as the protocol implementation. (If not, " "please report it.) To use the demuxer, simply use %s as url.\n", s->playlisturl); if ((ret = parse_playlist(h, s->playlisturl)) < 0) goto fail; if (s->n_segments == 0 && s->n_variants > 0) { int max_bandwidth = 0, maxvar = -1; for (i = 0; i < s->n_variants; i++) { if (s->variants[i]->bandwidth > max_bandwidth || i == 0) { max_bandwidth = s->variants[i]->bandwidth; maxvar = i; } } av_strlcpy(s->playlisturl, s->variants[maxvar]->url, sizeof(s->playlisturl)); if ((ret = parse_playlist(h, s->playlisturl)) < 0) goto fail; } if (s->n_segments == 0) { av_log(h, AV_LOG_WARNING, "Empty playlist\n"); ret = AVERROR(EIO); goto fail; } s->cur_seq_no = s->start_seq_no; if (!s->finished && s->n_segments >= 3) s->cur_seq_no = s->start_seq_no + s->n_segments - 3; return 0;fail: hls_close(h); return ret;}
open主要是读取m3u8的信息,并存储到变量中