Commit fe8e0394 authored by Martin Storsjö's avatar Martin Storsjö

applehttp: Expose the stream bitrate via metadata

This helps callers to intelligently switch between bitrate
variants.
Signed-off-by: 's avatarMartin Storsjö <martin@martin.st>
parent cac27579
...@@ -72,5 +72,7 @@ This demuxer presents all AVStreams from all variant streams. ...@@ -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 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 discard flags on AVStreams (by pressing 'a' or 'v' in ffplay),
the caller can decide which variant streams to actually receive. 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 @c man end INPUT DEVICES
...@@ -367,6 +367,7 @@ static int applehttp_read_header(AVFormatContext *s, AVFormatParameters *ap) ...@@ -367,6 +367,7 @@ static int applehttp_read_header(AVFormatContext *s, AVFormatParameters *ap)
for (i = 0; i < c->n_variants; i++) { for (i = 0; i < c->n_variants; i++) {
struct variant *v = c->variants[i]; struct variant *v = c->variants[i];
AVInputFormat *in_fmt = NULL; AVInputFormat *in_fmt = NULL;
char bitrate_str[20];
if (v->n_segments == 0) if (v->n_segments == 0)
continue; continue;
...@@ -393,6 +394,7 @@ static int applehttp_read_header(AVFormatContext *s, AVFormatParameters *ap) ...@@ -393,6 +394,7 @@ static int applehttp_read_header(AVFormatContext *s, AVFormatParameters *ap)
if (ret < 0) if (ret < 0)
goto fail; goto fail;
v->stream_offset = stream_offset; v->stream_offset = stream_offset;
snprintf(bitrate_str, sizeof(bitrate_str), "%d", v->bandwidth);
/* Create new AVStreams for each stream in this variant */ /* Create new AVStreams for each stream in this variant */
for (j = 0; j < v->ctx->nb_streams; j++) { for (j = 0; j < v->ctx->nb_streams; j++) {
AVStream *st = av_new_stream(s, i); AVStream *st = av_new_stream(s, i);
...@@ -401,6 +403,7 @@ static int applehttp_read_header(AVFormatContext *s, AVFormatParameters *ap) ...@@ -401,6 +403,7 @@ static int applehttp_read_header(AVFormatContext *s, AVFormatParameters *ap)
goto fail; goto fail;
} }
avcodec_copy_context(st->codec, v->ctx->streams[j]->codec); 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; stream_offset += v->ctx->nb_streams;
} }
......
...@@ -104,6 +104,7 @@ struct AVFormatContext; ...@@ -104,6 +104,7 @@ struct AVFormatContext;
* service_provider -- name of the service provider in broadcasting. * service_provider -- name of the service provider in broadcasting.
* title -- name of the work. * title -- name of the work.
* track -- number of this work in the set, can be in form current/total. * track -- number of this work in the set, can be in form current/total.
* variant_bitrate -- the total bitrate of the bitrate variant that the current stream is part of
*/ */
#define AV_METADATA_MATCH_CASE 1 #define AV_METADATA_MATCH_CASE 1
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
#define LIBAVFORMAT_VERSION_MAJOR 53 #define LIBAVFORMAT_VERSION_MAJOR 53
#define LIBAVFORMAT_VERSION_MINOR 0 #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, \ #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
LIBAVFORMAT_VERSION_MINOR, \ LIBAVFORMAT_VERSION_MINOR, \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment