From patchwork Fri Nov 24 03:58:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jeyapal, Karthick" X-Patchwork-Id: 6325 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.161.94 with SMTP id m30csp1607144jah; Thu, 23 Nov 2017 19:58:17 -0800 (PST) X-Google-Smtp-Source: AGs4zMYKhz56e0yJPXdba23O+NprHD3B9d7jVAsOLrbAyt87lnsNUQwpJ8F5TuNMqWGkH+xxYghp X-Received: by 10.28.236.71 with SMTP id k68mr8211406wmh.120.1511495897558; Thu, 23 Nov 2017 19:58:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511495897; cv=none; d=google.com; s=arc-20160816; b=SB0T69WMXK9qNlHXpC6ruOojMPBW0O+ZBVIDkNhHj29uOS/cyfDKA9YXd9Avkz3wJn 0crVKXlo/DRi7jMfLJkFBcJ8HmSrCFhJ0j6xv6jl55V0hrxvcR8mmiHEbyVY3/kqR1B1 pgkxjFSWddx+tFl4n51VL09pCUI2Zgjn76ONyURTYf5wTONmslzuUD0gJpkNUbbzUq0n pG+Zact75sB+gAXHuin4cfvw7SUAIt6JKpUjXw4GU23Gog6ebQWxyvTFH4fhtRrjrKVT ouzKAY0dgzeJ5yUo5NpfoIyyhThMRNmR+ZKq3Bc+8fkox38xbClBEqStdbEzjNlp/LtG NXKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:content-id:content-language :accept-language:message-id:date:thread-index:thread-topic:to:from :dkim-signature:delivered-to:arc-authentication-results; bh=dyYn6+QbkGGHZiFbdvzodZjJCvCoYyvwXM6B469KqGw=; b=LpiPIDsRGk3jUQY7gaRP3/e0pgVyK+Q6amL5NhGnq+E3NAp+3tB3t5UMO6d/3aXBgC 98hInsquTQ4Yb2U0nLacCPUxI6OMsmb24HoimlsNcaGZYn6e0voB6nD8rp0qIHip+Ikw Jmx2HgVTqtHeIgUIN34cKYp/QHBuQBhjXZ9KIHODXIxOz4Q1mj1V1N8Z/DYL7kb2js1+ gi7cqvGWHl4qWJFdYlVSGZRdZvpDNNXm9vSNm1qVnBeUvcUeMl6PExqiV1JZb2j57pgc qIPi0KW+I9uSQEOL9UVBu066wi1+PZ7ibnxDt2cbgkQ2bV2kmIo3Q9m3UbHh2VlwZDaS P4Zg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@akamai.com header.s=jan2016.eng header.b=fQnYtYGn; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=QUARANTINE sp=NONE dis=NONE) header.from=akamai.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id j26si6031511wmh.121.2017.11.23.19.58.17; Thu, 23 Nov 2017 19:58:17 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@akamai.com header.s=jan2016.eng header.b=fQnYtYGn; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=QUARANTINE sp=NONE dis=NONE) header.from=akamai.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 31A4C68A1C3; Fri, 24 Nov 2017 05:58:15 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mx0a-00190b01.pphosted.com (mx0a-00190b01.pphosted.com [67.231.149.131]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6A0C468A109 for ; Fri, 24 Nov 2017 05:58:09 +0200 (EET) Received: from pps.filterd (m0122333.ppops.net [127.0.0.1]) by mx0a-00190b01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vAO3w8uQ020092 for ; Fri, 24 Nov 2017 03:58:08 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=akamai.com; h=from : to : subject : date : message-id : content-type : content-id : content-transfer-encoding : mime-version; s=jan2016.eng; bh=5jTEV7sH7/FKG6OmGyeVWq21qubUnjASFXPeD/yuRXo=; b=fQnYtYGnNjhuuRSrZTSphls0PwDgeZSGnajJ5D2HQ8oErT+EsrmE5XRi5KqGXT57Megs BpWrEMvGuX/4rAE4hlFr975u5ARUePQ+qsgg/F3PyOvOXPQXwdM3DxKIuHOCodYtpHCu Ue5S7pZPrD593xafHjy5DuilGF0JCgnvxyAySR84Ti5OvNDAJfnnMKhWqw7bvYEwcfBs 8cNAm0v3s3qjiSuP7VrN9VlKxNaOqFz/7gD7kjvQW8XtwXVcdqfOb5UDvJAJDPq7XtgQ Y0F6Vuh3v8uvzaK+cyedEETi3IxY7RfeInqmFW5KFh3zP2AFPzNXffXU9fXjDPjuOk3f DA== Received: from prod-mail-ppoint3 ([96.6.114.86]) by mx0a-00190b01.pphosted.com with ESMTP id 2ecuy67b7r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 24 Nov 2017 03:58:08 +0000 Received: from pps.filterd (prod-mail-ppoint3.akamai.com [127.0.0.1]) by prod-mail-ppoint3.akamai.com (8.16.0.21/8.16.0.21) with SMTP id vAO3uDJj030826 for ; Thu, 23 Nov 2017 22:58:07 -0500 Received: from email.msg.corp.akamai.com ([172.27.155.31]) by prod-mail-ppoint3.akamai.com with ESMTP id 2eah31e4h1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Thu, 23 Nov 2017 22:58:06 -0500 Received: from ASIN1EX-DAG2MB2.msg.corp.akamai.com (172.27.155.102) by asin1ex-dag2mb1.msg.corp.akamai.com (172.27.155.101) with Microsoft SMTP Server (TLS) id 15.0.1263.5; Fri, 24 Nov 2017 09:28:02 +0530 Received: from ASIN1EX-DAG2MB2.msg.corp.akamai.com ([172.27.155.102]) by asin1ex-dag2mb2.msg.corp.akamai.com ([172.27.155.102]) with mapi id 15.00.1263.000; Fri, 24 Nov 2017 09:28:02 +0530 From: "Jeyapal, Karthick" To: "ffmpeg-devel@ffmpeg.org" Thread-Topic: [PATCH v2 1/2] avformat/hlsenc: Modularized playlist creation to allow reuse Thread-Index: AQHTZNhsxsDnXQGl40ONUAmPXa61aQ== Date: Fri, 24 Nov 2017 03:58:01 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [172.19.222.208] Content-ID: MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-11-24_02:, , signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1711240052 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-11-24_02:, , signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1711240052 Subject: Re: [FFmpeg-devel] [PATCH v2 1/2] avformat/hlsenc: Modularized playlist creation to allow reuse X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" I have rebased the below patch for latest master and have sent a new patch v3. Regards, Karthick On 11/22/17, 2:50 PM, "Karthick J" wrote: --- libavformat/hlsenc.c | 237 +++++++++++++++++++++++++++------------------------ libavformat/hlsenc.h | 67 +++++++++++++++ 2 files changed, 193 insertions(+), 111 deletions(-) create mode 100644 libavformat/hlsenc.h -- 1.9.1 diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index 3c47ced..d5b1b98 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -45,6 +45,7 @@ #include "avformat.h" #include "avio_internal.h" +#include "hlsenc.h" #include "internal.h" #include "os_support.h" @@ -73,35 +74,11 @@ typedef struct HLSSegment { struct HLSSegment *next; } HLSSegment; -typedef enum HLSFlags { - // Generate a single media file and use byte ranges in the playlist. - HLS_SINGLE_FILE = (1 << 0), - HLS_DELETE_SEGMENTS = (1 << 1), - HLS_ROUND_DURATIONS = (1 << 2), - HLS_DISCONT_START = (1 << 3), - HLS_OMIT_ENDLIST = (1 << 4), - HLS_SPLIT_BY_TIME = (1 << 5), - HLS_APPEND_LIST = (1 << 6), - HLS_PROGRAM_DATE_TIME = (1 << 7), - HLS_SECOND_LEVEL_SEGMENT_INDEX = (1 << 8), // include segment index in segment filenames when use_localtime e.g.: %%03d - HLS_SECOND_LEVEL_SEGMENT_DURATION = (1 << 9), // include segment duration (microsec) in segment filenames when use_localtime e.g.: %%09t - HLS_SECOND_LEVEL_SEGMENT_SIZE = (1 << 10), // include segment size (bytes) in segment filenames when use_localtime e.g.: %%014s - HLS_TEMP_FILE = (1 << 11), - HLS_PERIODIC_REKEY = (1 << 12), -} HLSFlags; - typedef enum { SEGMENT_TYPE_MPEGTS, SEGMENT_TYPE_FMP4, } SegmentType; -typedef enum { - PLAYLIST_TYPE_NONE, - PLAYLIST_TYPE_EVENT, - PLAYLIST_TYPE_VOD, - PLAYLIST_TYPE_NB, -} PlaylistType; - typedef struct VariantStream { unsigned number; int64_t sequence; @@ -206,6 +183,113 @@ typedef struct HLSContext { unsigned int master_publish_rate; } HLSContext; +void ff_hls_write_playlist_version(AVIOContext *out, int version) { + if (!out) + return; + avio_printf(out, "#EXTM3U\n"); + avio_printf(out, "#EXT-X-VERSION:%d\n", version); +} + +void ff_hls_write_stream_info(AVStream *st, AVIOContext *out, + int bandwidth, char *filename) { + if (!out || !filename) + return; + + if (!bandwidth) { + av_log(NULL, AV_LOG_WARNING, + "Bandwidth info not available, set audio and video bitrates\n"); + return; + } + + avio_printf(out, "#EXT-X-STREAM-INF:BANDWIDTH=%d", bandwidth); + if (st && st->codecpar->width > 0 && st->codecpar->height > 0) + avio_printf(out, ",RESOLUTION=%dx%d", st->codecpar->width, + st->codecpar->height); + avio_printf(out, "\n%s\n\n", filename); +} + +void ff_hls_write_playlist_header(AVIOContext *out, int version, int allowcache, + int target_duration, int64_t sequence, + uint32_t playlist_type) { + if (!out) + return; + ff_hls_write_playlist_version(out, version); + if (allowcache == 0 || allowcache == 1) { + avio_printf(out, "#EXT-X-ALLOW-CACHE:%s\n", allowcache == 0 ? "NO" : "YES"); + } + avio_printf(out, "#EXT-X-TARGETDURATION:%d\n", target_duration); + avio_printf(out, "#EXT-X-MEDIA-SEQUENCE:%"PRId64"\n", sequence); + av_log(NULL, AV_LOG_VERBOSE, "EXT-X-MEDIA-SEQUENCE:%"PRId64"\n", sequence); + + if (playlist_type == PLAYLIST_TYPE_EVENT) { + avio_printf(out, "#EXT-X-PLAYLIST-TYPE:EVENT\n"); + } else if (playlist_type == PLAYLIST_TYPE_VOD) { + avio_printf(out, "#EXT-X-PLAYLIST-TYPE:VOD\n"); + } +} + +void ff_hls_write_init_file(AVIOContext *out, char *filename, + int byterange_mode, int64_t size, int64_t pos) { + avio_printf(out, "#EXT-X-MAP:URI=\"%s\"", filename); + if (byterange_mode) { + avio_printf(out, ",BYTERANGE=\"%"PRId64"@%"PRId64"\"", size, pos); + } + avio_printf(out, "\n"); +} + +void ff_hls_write_file_entry(AVIOContext *out, int insert_discont, + int byterange_mode, uint32_t flags, double duration, + int64_t size, int64_t pos, //Used only if HLS_SINGLE_FILE flag is set + char *baseurl, //Ignored if NULL + char *filename, double *prog_date_time) { + if (!out || !filename) + return; + + if (insert_discont) { + avio_printf(out, "#EXT-X-DISCONTINUITY\n"); + } + if (flags & HLS_ROUND_DURATIONS) + avio_printf(out, "#EXTINF:%ld,\n", lrint(duration)); + else + avio_printf(out, "#EXTINF:%f,\n", duration); + if (byterange_mode) + avio_printf(out, "#EXT-X-BYTERANGE:%"PRId64"@%"PRId64"\n", size, pos); + + if ((flags & HLS_PROGRAM_DATE_TIME) && prog_date_time) { + time_t tt, wrongsecs; + int milli; + struct tm *tm, tmpbuf; + char buf0[128], buf1[128]; + tt = (int64_t)prog_date_time; + milli = av_clip(lrint(1000*(*prog_date_time - tt)), 0, 999); + tm = localtime_r(&tt, &tmpbuf); + strftime(buf0, sizeof(buf0), "%Y-%m-%dT%H:%M:%S", tm); + if (!strftime(buf1, sizeof(buf1), "%z", tm) || buf1[1]<'0' ||buf1[1]>'2') { + int tz_min, dst = tm->tm_isdst; + tm = gmtime_r(&tt, &tmpbuf); + tm->tm_isdst = dst; + wrongsecs = mktime(tm); + tz_min = (FFABS(wrongsecs - tt) + 30) / 60; + snprintf(buf1, sizeof(buf1), + "%c%02d%02d", + wrongsecs <= tt ? '+' : '-', + tz_min / 60, + tz_min % 60); + } + avio_printf(out, "#EXT-X-PROGRAM-DATE-TIME:%s.%03d%s\n", buf0, milli, buf1); + *prog_date_time += duration; + } + if (baseurl) + avio_printf(out, "%s", baseurl); + avio_printf(out, "%s\n", filename); +} + +void ff_hls_write_end_list (AVIOContext *out) { + if (!out) + return; + avio_printf(out, "#EXT-X-ENDLIST\n"); +} + static int get_int_from_double(double val) { return (int)((val - (int)val) >= 0.001) ? (int)(val + 1) : (int)val; @@ -1022,19 +1106,6 @@ static void hls_free_segments(HLSSegment *p) } } -static void write_m3u8_head_block(HLSContext *hls, AVIOContext *out, int version, - int target_duration, int64_t sequence) -{ - avio_printf(out, "#EXTM3U\n"); - avio_printf(out, "#EXT-X-VERSION:%d\n", version); - if (hls->allowcache == 0 || hls->allowcache == 1) { - avio_printf(out, "#EXT-X-ALLOW-CACHE:%s\n", hls->allowcache == 0 ? "NO" : "YES"); - } - avio_printf(out, "#EXT-X-TARGETDURATION:%d\n", target_duration); - avio_printf(out, "#EXT-X-MEDIA-SEQUENCE:%"PRId64"\n", sequence); - av_log(hls, AV_LOG_VERBOSE, "EXT-X-MEDIA-SEQUENCE:%"PRId64"\n", sequence); -} - static void hls_rename_temp_file(AVFormatContext *s, AVFormatContext *oc) { size_t len = strlen(oc->filename); @@ -1101,8 +1172,7 @@ static int create_master_playlist(AVFormatContext *s, goto fail; } - avio_printf(master_pb, "#EXTM3U\n"); - avio_printf(master_pb, "#EXT-X-VERSION:%d\n", hls->version); + ff_hls_write_playlist_version(master_pb, hls->version); /* For variant streams with video add #EXT-X-STREAM-INF tag with attributes*/ for (i = 0; i < hls->nb_varstreams; i++) { @@ -1143,18 +1213,7 @@ static int create_master_playlist(AVFormatContext *s, bandwidth += aud_st->codecpar->bit_rate; bandwidth += bandwidth / 10; - if (!bandwidth) { - av_log(NULL, AV_LOG_WARNING, - "Bandwidth info not available, set audio and video bitrates\n"); - av_freep(&m3U8_rel_name); - continue; - } - - avio_printf(master_pb, "#EXT-X-STREAM-INF:BANDWIDTH=%d", bandwidth); - if (vid_st && vid_st->codecpar->width > 0 && vid_st->codecpar->height > 0) - avio_printf(master_pb, ",RESOLUTION=%dx%d", vid_st->codecpar->width, - vid_st->codecpar->height); - avio_printf(master_pb, "\n%s\n\n", m3U8_rel_name); + ff_hls_write_stream_info(vid_st, master_pb, bandwidth, m3U8_rel_name); av_freep(&m3U8_rel_name); } @@ -1209,12 +1268,8 @@ static int hls_window(AVFormatContext *s, int last, VariantStream *vs) } vs->discontinuity_set = 0; - write_m3u8_head_block(hls, out, hls->version, target_duration, sequence); - if (hls->pl_type == PLAYLIST_TYPE_EVENT) { - avio_printf(out, "#EXT-X-PLAYLIST-TYPE:EVENT\n"); - } else if (hls->pl_type == PLAYLIST_TYPE_VOD) { - avio_printf(out, "#EXT-X-PLAYLIST-TYPE:VOD\n"); - } + ff_hls_write_playlist_header(out, hls->version, hls->allowcache, + target_duration, sequence, hls->pl_type); if((hls->flags & HLS_DISCONT_START) && sequence==hls->start_sequence && vs->discontinuity_set==0 ){ avio_printf(out, "#EXT-X-DISCONTINUITY\n"); @@ -1231,74 +1286,34 @@ static int hls_window(AVFormatContext *s, int last, VariantStream *vs) iv_string = en->iv_string; } - if (en->discont) { - avio_printf(out, "#EXT-X-DISCONTINUITY\n"); - } - if ((hls->segment_type == SEGMENT_TYPE_FMP4) && (en == vs->segments)) { - avio_printf(out, "#EXT-X-MAP:URI=\"%s\"", vs->fmp4_init_filename); - if (hls->flags & HLS_SINGLE_FILE) { - avio_printf(out, ",BYTERANGE=\"%"PRId64"@%"PRId64"\"", en->size, en->pos); - } - avio_printf(out, "\n"); + ff_hls_write_init_file(out, vs->fmp4_init_filename, + hls->flags & HLS_SINGLE_FILE, en->size, en->pos); } - if (hls->flags & HLS_ROUND_DURATIONS) - avio_printf(out, "#EXTINF:%ld,\n", lrint(en->duration)); - else - avio_printf(out, "#EXTINF:%f,\n", en->duration); - if (byterange_mode) - avio_printf(out, "#EXT-X-BYTERANGE:%"PRId64"@%"PRId64"\n", - en->size, en->pos); - - if (hls->flags & HLS_PROGRAM_DATE_TIME) { - time_t tt, wrongsecs; - int milli; - struct tm *tm, tmpbuf; - char buf0[128], buf1[128]; - tt = (int64_t)prog_date_time; - milli = av_clip(lrint(1000*(prog_date_time - tt)), 0, 999); - tm = localtime_r(&tt, &tmpbuf); - strftime(buf0, sizeof(buf0), "%Y-%m-%dT%H:%M:%S", tm); - if (!strftime(buf1, sizeof(buf1), "%z", tm) || buf1[1]<'0' ||buf1[1]>'2') { - int tz_min, dst = tm->tm_isdst; - tm = gmtime_r(&tt, &tmpbuf); - tm->tm_isdst = dst; - wrongsecs = mktime(tm); - tz_min = (FFABS(wrongsecs - tt) + 30) / 60; - snprintf(buf1, sizeof(buf1), - "%c%02d%02d", - wrongsecs <= tt ? '+' : '-', - tz_min / 60, - tz_min % 60); - } - avio_printf(out, "#EXT-X-PROGRAM-DATE-TIME:%s.%03d%s\n", buf0, milli, buf1); - prog_date_time += en->duration; - } - if (vs->baseurl) - avio_printf(out, "%s", vs->baseurl); - avio_printf(out, "%s\n", en->filename); + + ff_hls_write_file_entry(out, en->discont, byterange_mode, hls->flags, + en->duration, en->size, en->pos, vs->baseurl, + en->filename, &prog_date_time); + } if (last && (hls->flags & HLS_OMIT_ENDLIST)==0) - avio_printf(out, "#EXT-X-ENDLIST\n"); + ff_hls_write_end_list(out); if( vs->vtt_m3u8_name ) { if ((ret = s->io_open(s, &sub_out, vs->vtt_m3u8_name, AVIO_FLAG_WRITE, &options)) < 0) goto fail; - write_m3u8_head_block(hls, sub_out, hls->version, target_duration, sequence); + ff_hls_write_playlist_header(sub_out, hls->version, hls->allowcache, + target_duration, sequence, PLAYLIST_TYPE_NONE); for (en = vs->segments; en; en = en->next) { - avio_printf(sub_out, "#EXTINF:%f,\n", en->duration); - if (byterange_mode) - avio_printf(sub_out, "#EXT-X-BYTERANGE:%"PRIi64"@%"PRIi64"\n", - en->size, en->pos); - if (vs->baseurl) - avio_printf(sub_out, "%s", vs->baseurl); - avio_printf(sub_out, "%s\n", en->sub_filename); + ff_hls_write_file_entry(sub_out, 0, byterange_mode, + hls->flags, en->duration, en->size, en->pos, + vs->baseurl, en->sub_filename, NULL); } if (last) - avio_printf(sub_out, "#EXT-X-ENDLIST\n"); + ff_hls_write_end_list(sub_out); } diff --git a/libavformat/hlsenc.h b/libavformat/hlsenc.h new file mode 100644 index 0000000..d4723f6 --- /dev/null +++ b/libavformat/hlsenc.h @@ -0,0 +1,67 @@ +/* + * Apple HTTP Live Streaming segmenter + * Copyright (c) 2012, Luca Barbato + * Copyright (c) 2017 Akamai Technologies, Inc. + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVFORMAT_HLSENC_H_ +#define AVFORMAT_HLSENC_H_ + +#include "libavutil/common.h" + +typedef enum HLSFlags { + // Generate a single media file and use byte ranges in the playlist. + HLS_SINGLE_FILE = (1 << 0), + HLS_DELETE_SEGMENTS = (1 << 1), + HLS_ROUND_DURATIONS = (1 << 2), + HLS_DISCONT_START = (1 << 3), + HLS_OMIT_ENDLIST = (1 << 4), + HLS_SPLIT_BY_TIME = (1 << 5), + HLS_APPEND_LIST = (1 << 6), + HLS_PROGRAM_DATE_TIME = (1 << 7), + HLS_SECOND_LEVEL_SEGMENT_INDEX = (1 << 8), // include segment index in segment filenames when use_localtime e.g.: %%03d + HLS_SECOND_LEVEL_SEGMENT_DURATION = (1 << 9), // include segment duration (microsec) in segment filenames when use_localtime e.g.: %%09t + HLS_SECOND_LEVEL_SEGMENT_SIZE = (1 << 10), // include segment size (bytes) in segment filenames when use_localtime e.g.: %%014s + HLS_TEMP_FILE = (1 << 11), + HLS_PERIODIC_REKEY = (1 << 12), +} HLSFlags; + +typedef enum { + PLAYLIST_TYPE_NONE, + PLAYLIST_TYPE_EVENT, + PLAYLIST_TYPE_VOD, + PLAYLIST_TYPE_NB, +} PlaylistType; + +void ff_hls_write_playlist_version(AVIOContext *out, int version); +void ff_hls_write_stream_info(AVStream *st, AVIOContext *out, + int bandwidth, char *filename); +void ff_hls_write_playlist_header(AVIOContext *out, int version, int allowcache, + int target_duration, int64_t sequence, + uint32_t playlist_type); +void ff_hls_write_init_file(AVIOContext *out, char *filename, + int byterange_mode, int64_t size, int64_t pos); +void ff_hls_write_file_entry(AVIOContext *out, int insert_discont, + int byterange_mode, uint32_t flags, double duration, + int64_t size, int64_t pos, //Used only if HLS_SINGLE_FILE flag is set + char *baseurl, //Ignored if NULL + char *filename, double *prog_date_time); +void ff_hls_write_end_list (AVIOContext *out); + +#endif /* AVFORMAT_HLSENC_H_ */