summaryrefslogtreecommitdiff
path: root/libavformat/hls.c
diff options
context:
space:
mode:
authorLYF <yefei.li@gmail.com>2012-11-16 14:12:27 +0800
committerMichael Niedermayer <michaelni@gmx.at>2012-11-21 01:24:01 +0100
commit23db5418ed2ebaddbbc57a45b81caa6e94724587 (patch)
tree3e8a63d8e79708bd2af4faa191ecd885f28d0365 /libavformat/hls.c
parent8b6aeb1fcdd975422e251ebfc3da8565d7f6c604 (diff)
hls: create an AVProgram for each variant
Without the information, application may choose audio from one variant and video from another variant, which leads to fetch two variants from network. This enables av_find_best_stream() to find matching audio and video streams, so that only one variant is fetched from network. Signed-off-by: LYF <yefei.li@gmail.com> Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavformat/hls.c')
-rw-r--r--libavformat/hls.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/libavformat/hls.c b/libavformat/hls.c
index ef5803ba4b..e29ab02173 100644
--- a/libavformat/hls.c
+++ b/libavformat/hls.c
@@ -504,6 +504,7 @@ static int hls_read_header(AVFormatContext *s)
struct variant *v = c->variants[i];
AVInputFormat *in_fmt = NULL;
char bitrate_str[20];
+ AVProgram * program = NULL;
if (v->n_segments == 0)
continue;
@@ -549,6 +550,13 @@ static int hls_read_header(AVFormatContext *s)
if (ret < 0)
goto fail;
snprintf(bitrate_str, sizeof(bitrate_str), "%d", v->bandwidth);
+
+ /* Create new AVprogram for variant i */
+ program = av_new_program(s, i);
+ if ( !program )
+ goto fail;
+ av_dict_set(&program->metadata, "variant_bitrate", bitrate_str, 0);
+
/* Create new AVStreams for each stream in this variant */
for (j = 0; j < v->ctx->nb_streams; j++) {
AVStream *st = avformat_new_stream(s, NULL);
@@ -556,6 +564,7 @@ static int hls_read_header(AVFormatContext *s)
ret = AVERROR(ENOMEM);
goto fail;
}
+ ff_program_add_stream_index(s, i, stream_offset + j);
st->id = i;
avcodec_copy_context(st->codec, v->ctx->streams[j]->codec);
if (v->bandwidth)