diff options
author | Rodger Combs <rodger.combs@gmail.com> | 2015-03-28 18:27:35 -0600 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2015-03-29 13:34:15 +0200 |
commit | bcf44c91c30940822bd8bcd612c2a5ab0a3440f2 (patch) | |
tree | 687ba4e7aba40fa13355260d4a8507cbe7ba12f7 /libavformat/hls.c | |
parent | 81487781e739a20deeeb5d3d232c5737e794e80f (diff) | |
download | ffmpeg-bcf44c91c30940822bd8bcd612c2a5ab0a3440f2.tar.gz |
libavformat/hls: add an option to start from a given segment in a live stream
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavformat/hls.c')
-rw-r--r-- | libavformat/hls.c | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/libavformat/hls.c b/libavformat/hls.c index af890bd4ad..4a7d003f72 100644 --- a/libavformat/hls.c +++ b/libavformat/hls.c @@ -165,6 +165,7 @@ struct variant { }; typedef struct HLSContext { + AVClass *class; int n_variants; struct variant **variants; int n_playlists; @@ -173,6 +174,7 @@ typedef struct HLSContext { struct rendition **renditions; int cur_seq_no; + int live_start_index; int first_packet; int64_t first_timestamp; int64_t cur_timestamp; @@ -1237,10 +1239,12 @@ static int select_cur_seq_no(HLSContext *c, struct playlist *pls) * require us to download a segment to inspect its timestamps. */ return c->cur_seq_no; - /* If this is a live stream with more than 3 segments, start at the - * third last segment. */ - if (pls->n_segments > 3) - return pls->start_seq_no + pls->n_segments - 3; + /* If this is a live stream, start live_start_index segments from the + * start or end */ + if (c->live_start_index < 0) + return pls->start_seq_no + FFMAX(pls->n_segments + c->live_start_index, 0); + else + return pls->start_seq_no + FFMIN(c->live_start_index, pls->n_segments - 1); } /* Otherwise just start on the first segment. */ @@ -1714,9 +1718,25 @@ static int hls_probe(AVProbeData *p) return 0; } +#define OFFSET(x) offsetof(HLSContext, x) +#define FLAGS AV_OPT_FLAG_DECODING_PARAM +static const AVOption hls_options[] = { + {"live_start_index", "segment index to start live streams at (negative values are from the end)", + OFFSET(live_start_index), FF_OPT_TYPE_INT, {.i64 = -3}, INT_MIN, INT_MAX, FLAGS}, + {NULL} +}; + +static const AVClass hls_class = { + .class_name = "hls,applehttp", + .item_name = av_default_item_name, + .option = hls_options, + .version = LIBAVUTIL_VERSION_INT, +}; + AVInputFormat ff_hls_demuxer = { .name = "hls,applehttp", .long_name = NULL_IF_CONFIG_SMALL("Apple HTTP Live Streaming"), + .priv_class = &hls_class, .priv_data_size = sizeof(HLSContext), .read_probe = hls_probe, .read_header = hls_read_header, |