From 57efe9089cf51587d24686b98b319812e4c9ce23 Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 13 Jul 2015 13:34:58 +0200 Subject: player: extend --hls-bitrate option Fixes #2116. --- DOCS/man/options.rst | 5 ++++- options/options.c | 6 +++--- player/loadfile.c | 14 ++++++++++---- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/DOCS/man/options.rst b/DOCS/man/options.rst index 0b344b5b9e..494bf4b3ea 100644 --- a/DOCS/man/options.rst +++ b/DOCS/man/options.rst @@ -3192,7 +3192,7 @@ Network network transport when playing ``rtsp://...`` URLs. The value ``lavf`` leaves the decision to libavformat. -``--hls-bitrate=`` +``--hls-bitrate=>`` If HLS streams are played, this option controls what streams are selected by default. The option allows the following parameters: @@ -3201,6 +3201,9 @@ Network :min: Pick the streams with the lowest bitrate. :max: Same, but highest bitrate. (Default.) + Additionally, if the option is a number, the stream with the highest rate + equal or below the option value is selected. + The bitrate as used is sent by the server, and there's no guarantee it's actually meaningful. diff --git a/options/options.c b/options/options.c index 7523be990a..62c9bc2286 100644 --- a/options/options.c +++ b/options/options.c @@ -223,8 +223,8 @@ const m_option_t mp_opts[] = { OPT_CHOICE("audio-display", audio_display, 0, ({"no", 0}, {"attachment", 1})), - OPT_CHOICE("hls-bitrate", hls_bitrate, 0, - ({"no", 0}, {"min", 1}, {"max", 2})), + OPT_CHOICE_OR_INT("hls-bitrate", hls_bitrate, 0, 0, INT_MAX, + ({"no", -1}, {"min", 0}, {"max", INT_MAX})), OPT_STRINGLIST("display-tags*", display_tags, 0), @@ -722,7 +722,7 @@ const struct MPOpts mp_default_opts = { .demuxer_min_secs = 1.0, .network_rtsp_transport = 2, .network_timeout = 0.0, - .hls_bitrate = 2, + .hls_bitrate = INT_MAX, .demuxer_min_secs_cache = 10.0, .cache_pausing = 1, .chapterrange = {-1, -1}, diff --git a/player/loadfile.c b/player/loadfile.c index dfcb4a547e..6f5d29d3c8 100644 --- a/player/loadfile.c +++ b/player/loadfile.c @@ -454,10 +454,16 @@ static bool compare_track(struct track *t1, struct track *t2, char **langs, return t1->default_track; if (t1->attached_picture != t2->attached_picture) return !t1->attached_picture; - if (t1->stream && t2->stream && opts->hls_bitrate) { - int d = t1->stream->hls_bitrate - t2->stream->hls_bitrate; - if (d) - return opts->hls_bitrate == 1 ? d < 0 : d > 0; + if (t1->stream && t2->stream && opts->hls_bitrate >= 0 && + t1->stream->hls_bitrate != t2->stream->hls_bitrate) + { + bool t1_ok = t1->stream->hls_bitrate <= opts->hls_bitrate; + bool t2_ok = t2->stream->hls_bitrate <= opts->hls_bitrate; + if (t1_ok != t2_ok) + return t1_ok; + if (t1_ok && t2_ok) + return t1->stream->hls_bitrate > t2->stream->hls_bitrate; + return t1->stream->hls_bitrate < t2->stream->hls_bitrate; } return t1->user_tid <= t2->user_tid; } -- cgit v1.2.3