[09/10] hls: Create an AVProgram for each variant

Message ID 1375038091-92151-9-git-send-email-martin@martin.st
State Committed
Headers show

Commit Message

Martin Storsjö July 28, 2013, 7:01 p.m.
From: LYF <yefei.li@gmail.com>

Without the information, an application may choose audio from one
variant and video from another variant, which leads to fetching two
variants from the network. This enables av_find_best_stream() to find
matching audio and video streams, so that only one variant is fetched.
---
 libavformat/hls.c |    9 +++++++++
 1 file changed, 9 insertions(+)

Comments

Luca Barbato July 28, 2013, 8:19 p.m. | #1
On 28/07/13 21:01, Martin Storsjö wrote:
> From: LYF <yefei.li@gmail.com>
> 
> Without the information, an application may choose audio from one
> variant and video from another variant, which leads to fetching two
> variants from the network. This enables av_find_best_stream() to find
> matching audio and video streams, so that only one variant is fetched.
> ---
>  libavformat/hls.c |    9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/libavformat/hls.c b/libavformat/hls.c
> index 7cde121..7445cb8 100644
> --- a/libavformat/hls.c
> +++ b/libavformat/hls.c
> @@ -489,6 +489,7 @@ static int hls_read_header(AVFormatContext *s)
>          struct variant *v = c->variants[i];
>          AVInputFormat *in_fmt = NULL;
>          char bitrate_str[20];
> +        AVProgram *program;

if you feel like keep the empty line.

>          if (v->n_segments == 0)
>              continue;
>  
> @@ -533,6 +534,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 */

redundant comment is redundant.

> +        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);
> @@ -541,6 +549,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;
>              avpriv_set_pts_info(st, ist->pts_wrap_bits, ist->time_base.num, ist->time_base.den);
>              avcodec_copy_context(st->codec, v->ctx->streams[j]->codec);
> 

Seems fine

lu

Patch

diff --git a/libavformat/hls.c b/libavformat/hls.c
index 7cde121..7445cb8 100644
--- a/libavformat/hls.c
+++ b/libavformat/hls.c
@@ -489,6 +489,7 @@  static int hls_read_header(AVFormatContext *s)
         struct variant *v = c->variants[i];
         AVInputFormat *in_fmt = NULL;
         char bitrate_str[20];
+        AVProgram *program;
         if (v->n_segments == 0)
             continue;
 
@@ -533,6 +534,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);
@@ -541,6 +549,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;
             avpriv_set_pts_info(st, ist->pts_wrap_bits, ist->time_base.num, ist->time_base.den);
             avcodec_copy_context(st->codec, v->ctx->streams[j]->codec);