Commit 65c95de2 authored by Willy Aubry's avatar Willy Aubry Committed by Michael Niedermayer

avformat/HLS: modified EXT-X-MEDIA-SEQUENCE header in order to follow the HLS standard

When using the wrap option the EXT-X-MEDIA-SEQUENCE header of the playlist file was reset instead of being incremented.
It is now incremented by one for every media URI removed from the playlist file as the standard states.
Signed-off-by: 's avatarWilly Aubry <waubry@viotech.net>
Signed-off-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parent 40feed52
...@@ -65,6 +65,7 @@ typedef struct { ...@@ -65,6 +65,7 @@ typedef struct {
const AVClass *class; /**< Class for private options. */ const AVClass *class; /**< Class for private options. */
int segment_idx; ///< index of the segment file to write, starting from 0 int segment_idx; ///< index of the segment file to write, starting from 0
int segment_idx_wrap; ///< number after which the index wraps int segment_idx_wrap; ///< number after which the index wraps
int segment_idx_wrap_nb; ///< number of time the index has wraped
int segment_count; ///< number of segment files already written int segment_count; ///< number of segment files already written
AVOutputFormat *oformat; AVOutputFormat *oformat;
AVFormatContext *avf; AVFormatContext *avf;
...@@ -199,6 +200,9 @@ static int segment_start(AVFormatContext *s, int write_header) ...@@ -199,6 +200,9 @@ static int segment_start(AVFormatContext *s, int write_header)
} }
seg->segment_idx++; seg->segment_idx++;
if ((seg->segment_idx_wrap) && (seg->segment_idx%seg->segment_idx_wrap == 0))
seg->segment_idx_wrap_nb++;
if ((err = set_segment_filename(s)) < 0) if ((err = set_segment_filename(s)) < 0)
return err; return err;
...@@ -689,7 +693,7 @@ static int seg_write_packet(AVFormatContext *s, AVPacket *pkt) ...@@ -689,7 +693,7 @@ static int seg_write_packet(AVFormatContext *s, AVPacket *pkt)
if ((ret = segment_start(s, seg->individual_header_trailer)) < 0) if ((ret = segment_start(s, seg->individual_header_trailer)) < 0)
goto fail; goto fail;
seg->cur_entry.index = seg->segment_idx; seg->cur_entry.index = seg->segment_idx + seg->segment_idx_wrap*seg->segment_idx_wrap_nb;
seg->cur_entry.start_time = (double)pkt->pts * av_q2d(st->time_base); seg->cur_entry.start_time = (double)pkt->pts * av_q2d(st->time_base);
seg->cur_entry.start_pts = av_rescale_q(pkt->pts, st->time_base, AV_TIME_BASE_Q); seg->cur_entry.start_pts = av_rescale_q(pkt->pts, st->time_base, AV_TIME_BASE_Q);
} else if (pkt->pts != AV_NOPTS_VALUE) { } else if (pkt->pts != AV_NOPTS_VALUE) {
...@@ -795,6 +799,7 @@ static const AVOption options[] = { ...@@ -795,6 +799,7 @@ static const AVOption options[] = {
{ "segment_frames", "set segment split frame numbers", OFFSET(frames_str),AV_OPT_TYPE_STRING,{.str = NULL}, 0, 0, E }, { "segment_frames", "set segment split frame numbers", OFFSET(frames_str),AV_OPT_TYPE_STRING,{.str = NULL}, 0, 0, E },
{ "segment_wrap", "set number after which the index wraps", OFFSET(segment_idx_wrap), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, E }, { "segment_wrap", "set number after which the index wraps", OFFSET(segment_idx_wrap), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, E },
{ "segment_start_number", "set the sequence number of the first segment", OFFSET(segment_idx), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, E }, { "segment_start_number", "set the sequence number of the first segment", OFFSET(segment_idx), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, E },
{ "segment_wrap_number", "set the number of wrap before the first segment", OFFSET(segment_idx_wrap_nb), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, E },
{ "individual_header_trailer", "write header/trailer to each segment", OFFSET(individual_header_trailer), AV_OPT_TYPE_INT, {.i64 = 1}, 0, 1, E }, { "individual_header_trailer", "write header/trailer to each segment", OFFSET(individual_header_trailer), AV_OPT_TYPE_INT, {.i64 = 1}, 0, 1, E },
{ "write_header_trailer", "write a header to the first segment and a trailer to the last one", OFFSET(write_header_trailer), AV_OPT_TYPE_INT, {.i64 = 1}, 0, 1, E }, { "write_header_trailer", "write a header to the first segment and a trailer to the last one", OFFSET(write_header_trailer), AV_OPT_TYPE_INT, {.i64 = 1}, 0, 1, E },
......
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