From 12d8d945cc4dafea3452b61ec97151d994164fd4 Mon Sep 17 00:00:00 2001 From: erankor Date: Thu, 18 May 2017 16:21:56 +0300 Subject: [PATCH] add #EXT-X-INDEPENDENT-SEGMENTS to hls manifests when vod_align_segments_to_key_frames is on --- vod/hls/m3u8_builder.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/vod/hls/m3u8_builder.c b/vod/hls/m3u8_builder.c index 7a80d230..43bde547 100644 --- a/vod/hls/m3u8_builder.c +++ b/vod/hls/m3u8_builder.c @@ -25,6 +25,7 @@ // constants static const u_char m3u8_header[] = "#EXTM3U\n"; static const u_char m3u8_footer[] = "#EXT-X-ENDLIST\n"; +static const u_char m3u8_independent_segments[] = "#EXT-X-INDEPENDENT-SEGMENTS\n"; static const char m3u8_stream_inf_video[] = "#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=%uD,RESOLUTION=%uDx%uD,FRAME-RATE=%uD.%03uD,CODECS=\"%V"; static const char m3u8_stream_inf_audio[] = "#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=%uD,CODECS=\"%V"; static const char m3u8_iframe_stream_inf[] = "#EXT-X-I-FRAME-STREAM-INF:BANDWIDTH=%uD,RESOLUTION=%uDx%uD,CODECS=\"%V\",URI=\""; @@ -423,6 +424,11 @@ m3u8_builder_build_index_playlist( } } + if (media_set->segmenter_conf->align_to_key_frames) + { + result_size += sizeof(m3u8_independent_segments) - 1; + } + // allocate the buffer result->data = vod_alloc(request_context->pool, result_size); if (result->data == NULL) @@ -522,6 +528,11 @@ m3u8_builder_build_index_playlist( conf->m3u8_version, segment_durations.items[0].segment_index + 1); + if (media_set->segmenter_conf->align_to_key_frames) + { + p = vod_copy(p, m3u8_independent_segments, sizeof(m3u8_independent_segments) - 1); + } + // write the segments for (cur_item = segment_durations.items; cur_item < last_item; cur_item++) { @@ -1008,6 +1019,11 @@ m3u8_builder_build_master_playlist( result_size = sizeof(m3u8_header); + if (media_set->segmenter_conf->align_to_key_frames) + { + result_size += sizeof(m3u8_independent_segments) - 1; + } + max_video_stream_inf = sizeof(m3u8_stream_inf_video) - 1 + 5 * VOD_INT32_LEN + MAX_CODEC_NAME_SIZE + MAX_CODEC_NAME_SIZE + 1 + // 1 = , @@ -1095,6 +1111,11 @@ m3u8_builder_build_master_playlist( // write the header p = vod_copy(result->data, m3u8_header, sizeof(m3u8_header) - 1); + if (media_set->segmenter_conf->align_to_key_frames) + { + p = vod_copy(p, m3u8_independent_segments, sizeof(m3u8_independent_segments) - 1); + } + if (adaptation_sets.count[ADAPTATION_TYPE_AUDIO] > 1) { // output alternative audio