summaryrefslogtreecommitdiff
path: root/libavformat/hls.c
diff options
context:
space:
mode:
authorAnssi Hannula <anssi.hannula@iki.fi>2013-12-30 11:40:20 +0200
committerAnssi Hannula <anssi.hannula@iki.fi>2014-04-06 17:55:03 +0300
commitd549b0910c3471beb9ef268ce0d70d3ab9ed7bb3 (patch)
treed84552fc5203548c95d280de9c3379baba32963e /libavformat/hls.c
parent4e85202bcc26b09f45d358da8f4d43aca0d27c0e (diff)
downloadffmpeg-d549b0910c3471beb9ef268ce0d70d3ab9ed7bb3.tar.gz
avformat/hls: avoid unnecessary segment retrievals
Check if the playlist is still needed just before requesting the next segment instead of after exhausting the previous segment. Signed-off-by: Anssi Hannula <anssi.hannula@iki.fi>
Diffstat (limited to 'libavformat/hls.c')
-rw-r--r--libavformat/hls.c37
1 files changed, 21 insertions, 16 deletions
diff --git a/libavformat/hls.c b/libavformat/hls.c
index dfeb520a30..b3019f3e68 100644
--- a/libavformat/hls.c
+++ b/libavformat/hls.c
@@ -963,14 +963,33 @@ static int read_data(void *opaque, uint8_t *buf, int buf_size)
int ret, i;
int just_opened = 0;
+restart:
if (!v->needed)
return AVERROR_EOF;
-restart:
if (!v->input) {
+ int64_t reload_interval;
+
+ /* Check that the playlist is still needed before opening a new
+ * segment. */
+ if (v->ctx && v->ctx->nb_streams &&
+ v->parent->nb_streams >= v->stream_offset + v->ctx->nb_streams) {
+ v->needed = 0;
+ for (i = v->stream_offset; i < v->stream_offset + v->ctx->nb_streams;
+ i++) {
+ if (v->parent->streams[i]->discard < AVDISCARD_ALL)
+ v->needed = 1;
+ }
+ }
+ if (!v->needed) {
+ av_log(v->parent, AV_LOG_INFO, "No longer receiving playlist %d\n",
+ v->index);
+ return AVERROR_EOF;
+ }
+
/* If this is a live stream and the reload interval has elapsed since
* the last playlist reload, reload the playlists now. */
- int64_t reload_interval = default_reload_interval(v);
+ reload_interval = default_reload_interval(v);
reload:
if (!v->finished &&
@@ -1029,20 +1048,6 @@ reload:
c->end_of_segment = 1;
c->cur_seq_no = v->cur_seq_no;
- if (v->ctx && v->ctx->nb_streams &&
- v->parent->nb_streams >= v->stream_offset + v->ctx->nb_streams) {
- v->needed = 0;
- for (i = v->stream_offset; i < v->stream_offset + v->ctx->nb_streams;
- i++) {
- if (v->parent->streams[i]->discard < AVDISCARD_ALL)
- v->needed = 1;
- }
- }
- if (!v->needed) {
- av_log(v->parent, AV_LOG_INFO, "No longer receiving playlist %d\n",
- v->index);
- return AVERROR_EOF;
- }
goto restart;
}