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: Willy Aubry <waubry@viotech.net>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
pull/60/head
Willy Aubry 11 years ago committed by Michael Niedermayer
parent 40feed5248
commit 65c95de213
  1. 7
      libavformat/segment.c

@ -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)
} }
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)
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[] = {
{ "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 },

Loading…
Cancel
Save