[2/2] applehttp: Expose the stream bitrate via metadata

Message ID 1303330120-58614-2-git-send-email-martin@martin.st
State Committed
Headers show

Commit Message

Martin Storsjö April 20, 2011, 8:08 p.m.
This helps callers to intelligently switch between bitrate
variants.
---
 doc/demuxers.texi       |    2 ++
 libavformat/applehttp.c |    3 +++
 libavformat/version.h   |    2 +-
 3 files changed, 6 insertions(+), 1 deletions(-)

Comments

Anton Khirnov April 21, 2011, 4:52 a.m. | #1
On Wed, 20 Apr 2011 23:08:40 +0300, Martin Storsjö <martin@martin.st> wrote:
> This helps callers to intelligently switch between bitrate
> variants.
> ---
>  doc/demuxers.texi       |    2 ++
>  libavformat/applehttp.c |    3 +++
>  libavformat/version.h   |    2 +-
>  3 files changed, 6 insertions(+), 1 deletions(-)
> 
> diff --git a/doc/demuxers.texi b/doc/demuxers.texi
> index 4168fc1..98f9fde 100644
> --- a/doc/demuxers.texi
> +++ b/doc/demuxers.texi
> @@ -72,5 +72,7 @@ This demuxer presents all AVStreams from all variant streams.
>  The id field is set to the bitrate variant index number. By setting
>  the discard flags on AVStreams (by pressing 'a' or 'v' in ffplay),
>  the caller can decide which variant streams to actually receive.
> +The total bitrate of the variant that the stream belongs to is
> +available in a metadata key named "variant_bitrate".
>  
>  @c man end INPUT DEVICES
> diff --git a/libavformat/applehttp.c b/libavformat/applehttp.c
> index df4494a..90b86a8 100644
> --- a/libavformat/applehttp.c
> +++ b/libavformat/applehttp.c
> @@ -367,6 +367,7 @@ static int applehttp_read_header(AVFormatContext *s, AVFormatParameters *ap)
>      for (i = 0; i < c->n_variants; i++) {
>          struct variant *v = c->variants[i];
>          AVInputFormat *in_fmt = NULL;
> +        char bitrate_str[20];
>          if (v->n_segments == 0)
>              continue;
>  
> @@ -393,6 +394,7 @@ static int applehttp_read_header(AVFormatContext *s, AVFormatParameters *ap)
>          if (ret < 0)
>              goto fail;
>          v->stream_offset = stream_offset;
> +        snprintf(bitrate_str, sizeof(bitrate_str), "%d", v->bandwidth);
>          /* Create new AVStreams for each stream in this variant */
>          for (j = 0; j < v->ctx->nb_streams; j++) {
>              AVStream *st = av_new_stream(s, i);
> @@ -401,6 +403,7 @@ static int applehttp_read_header(AVFormatContext *s, AVFormatParameters *ap)
>                  goto fail;
>              }
>              avcodec_copy_context(st->codec, v->ctx->streams[j]->codec);
> +            av_metadata_set2(&st->metadata, "variant_bitrate", bitrate_str, 0);
>          }
>          stream_offset += v->ctx->nb_streams;
>      }
> diff --git a/libavformat/version.h b/libavformat/version.h
> index 0173018..04c5d73 100644
> --- a/libavformat/version.h
> +++ b/libavformat/version.h
> @@ -25,7 +25,7 @@
>  
>  #define LIBAVFORMAT_VERSION_MAJOR 53
>  #define LIBAVFORMAT_VERSION_MINOR  0
> -#define LIBAVFORMAT_VERSION_MICRO  0
> +#define LIBAVFORMAT_VERSION_MICRO  1
>  
>  #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
>                                                 LIBAVFORMAT_VERSION_MINOR, \
> -- 
> 1.7.3.1

Please add an entry to the list of standard metadata tags in avformat.h.

Otherwise ok.
Martin Storsjö April 21, 2011, 6:43 a.m. | #2
On Thu, 21 Apr 2011, Anton Khirnov wrote:

> On Wed, 20 Apr 2011 23:08:40 +0300, Martin Storsjö <martin@martin.st> wrote:
> > This helps callers to intelligently switch between bitrate
> > variants.
> > ---
> >  doc/demuxers.texi       |    2 ++
> >  libavformat/applehttp.c |    3 +++
> >  libavformat/version.h   |    2 +-
> >  3 files changed, 6 insertions(+), 1 deletions(-)
> > 
> > diff --git a/doc/demuxers.texi b/doc/demuxers.texi
> > index 4168fc1..98f9fde 100644
> > --- a/doc/demuxers.texi
> > +++ b/doc/demuxers.texi
> > @@ -72,5 +72,7 @@ This demuxer presents all AVStreams from all variant streams.
> >  The id field is set to the bitrate variant index number. By setting
> >  the discard flags on AVStreams (by pressing 'a' or 'v' in ffplay),
> >  the caller can decide which variant streams to actually receive.
> > +The total bitrate of the variant that the stream belongs to is
> > +available in a metadata key named "variant_bitrate".
> >  
> >  @c man end INPUT DEVICES
> > diff --git a/libavformat/applehttp.c b/libavformat/applehttp.c
> > index df4494a..90b86a8 100644
> > --- a/libavformat/applehttp.c
> > +++ b/libavformat/applehttp.c
> > @@ -367,6 +367,7 @@ static int applehttp_read_header(AVFormatContext *s, AVFormatParameters *ap)
> >      for (i = 0; i < c->n_variants; i++) {
> >          struct variant *v = c->variants[i];
> >          AVInputFormat *in_fmt = NULL;
> > +        char bitrate_str[20];
> >          if (v->n_segments == 0)
> >              continue;
> >  
> > @@ -393,6 +394,7 @@ static int applehttp_read_header(AVFormatContext *s, AVFormatParameters *ap)
> >          if (ret < 0)
> >              goto fail;
> >          v->stream_offset = stream_offset;
> > +        snprintf(bitrate_str, sizeof(bitrate_str), "%d", v->bandwidth);
> >          /* Create new AVStreams for each stream in this variant */
> >          for (j = 0; j < v->ctx->nb_streams; j++) {
> >              AVStream *st = av_new_stream(s, i);
> > @@ -401,6 +403,7 @@ static int applehttp_read_header(AVFormatContext *s, AVFormatParameters *ap)
> >                  goto fail;
> >              }
> >              avcodec_copy_context(st->codec, v->ctx->streams[j]->codec);
> > +            av_metadata_set2(&st->metadata, "variant_bitrate", bitrate_str, 0);
> >          }
> >          stream_offset += v->ctx->nb_streams;
> >      }
> > diff --git a/libavformat/version.h b/libavformat/version.h
> > index 0173018..04c5d73 100644
> > --- a/libavformat/version.h
> > +++ b/libavformat/version.h
> > @@ -25,7 +25,7 @@
> >  
> >  #define LIBAVFORMAT_VERSION_MAJOR 53
> >  #define LIBAVFORMAT_VERSION_MINOR  0
> > -#define LIBAVFORMAT_VERSION_MICRO  0
> > +#define LIBAVFORMAT_VERSION_MICRO  1
> >  
> >  #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
> >                                                 LIBAVFORMAT_VERSION_MINOR, \
> > -- 
> > 1.7.3.1
> 
> Please add an entry to the list of standard metadata tags in avformat.h.
> 
> Otherwise ok.

Updated locally with an entry in avformat.h. Anyone care to ok the 
preceding doc addition? Or just commit this without adding it to the 
demuxer docs, keeping it only in the metadata key list in avformat.h?

// Martin
Diego Biurrun April 21, 2011, 10:45 a.m. | #3
On Thu, Apr 21, 2011 at 09:43:06AM +0300, Martin Storsjö wrote:
> 
> Updated locally with an entry in avformat.h. Anyone care to ok the 
> preceding doc addition? Or just commit this without adding it to the 
> demuxer docs, keeping it only in the metadata key list in avformat.h?

Don't worry about this one sentence, but it's OK anyway.

Diego

Patch

diff --git a/doc/demuxers.texi b/doc/demuxers.texi
index 4168fc1..98f9fde 100644
--- a/doc/demuxers.texi
+++ b/doc/demuxers.texi
@@ -72,5 +72,7 @@  This demuxer presents all AVStreams from all variant streams.
 The id field is set to the bitrate variant index number. By setting
 the discard flags on AVStreams (by pressing 'a' or 'v' in ffplay),
 the caller can decide which variant streams to actually receive.
+The total bitrate of the variant that the stream belongs to is
+available in a metadata key named "variant_bitrate".
 
 @c man end INPUT DEVICES
diff --git a/libavformat/applehttp.c b/libavformat/applehttp.c
index df4494a..90b86a8 100644
--- a/libavformat/applehttp.c
+++ b/libavformat/applehttp.c
@@ -367,6 +367,7 @@  static int applehttp_read_header(AVFormatContext *s, AVFormatParameters *ap)
     for (i = 0; i < c->n_variants; i++) {
         struct variant *v = c->variants[i];
         AVInputFormat *in_fmt = NULL;
+        char bitrate_str[20];
         if (v->n_segments == 0)
             continue;
 
@@ -393,6 +394,7 @@  static int applehttp_read_header(AVFormatContext *s, AVFormatParameters *ap)
         if (ret < 0)
             goto fail;
         v->stream_offset = stream_offset;
+        snprintf(bitrate_str, sizeof(bitrate_str), "%d", v->bandwidth);
         /* Create new AVStreams for each stream in this variant */
         for (j = 0; j < v->ctx->nb_streams; j++) {
             AVStream *st = av_new_stream(s, i);
@@ -401,6 +403,7 @@  static int applehttp_read_header(AVFormatContext *s, AVFormatParameters *ap)
                 goto fail;
             }
             avcodec_copy_context(st->codec, v->ctx->streams[j]->codec);
+            av_metadata_set2(&st->metadata, "variant_bitrate", bitrate_str, 0);
         }
         stream_offset += v->ctx->nb_streams;
     }
diff --git a/libavformat/version.h b/libavformat/version.h
index 0173018..04c5d73 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -25,7 +25,7 @@ 
 
 #define LIBAVFORMAT_VERSION_MAJOR 53
 #define LIBAVFORMAT_VERSION_MINOR  0
-#define LIBAVFORMAT_VERSION_MICRO  0
+#define LIBAVFORMAT_VERSION_MICRO  1
 
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
                                                LIBAVFORMAT_VERSION_MINOR, \