Re: [FFmpeg-devel] [PATCH 3/3] avformat/hlsenc: Extend persistent http connections to playlists

2017-12-15 Thread Karthick Jeyapal



On 12/15/17 7:58 PM, Steven Liu wrote:

Patchset LGTM, i will push it after 24 hours if there are no objections.

Thanks for the reply.
But that patchset doesn’t apply with the latest master anymore.
I have rebased this patchset and sent a new version v2.



Patchset pushed,

BTW,  Your patchset need more time to make full review, so i need more
time to read and to check it, and the patchset need more time to wait
not only me review it,
so need more time to push it into master, you need read the developer
documentation. http://ffmpeg.org/developer.html#Patches_002fCommitting

Thanks.
I understand your point. The developer documentation mentioned 1 week of 
wait time for big patches.
I pinged only after waiting for 14 days. But if you are busy with 
something else and need more time to review a particular patch, I am 
perfectly fine with it. I just pinged to know the status, so that I 
could plan further tasks appropriately.


Thanks,

Steven
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 3/3] avformat/hlsenc: Extend persistent http connections to playlists

2017-12-15 Thread Steven Liu
>> Patchset LGTM, i will push it after 24 hours if there are no objections.
>
> Thanks for the reply.
> But that patchset doesn’t apply with the latest master anymore.
> I have rebased this patchset and sent a new version v2.
>


Patchset pushed,

BTW,  Your patchset need more time to make full review, so i need more
time to read and to check it, and the patchset need more time to wait
not only me review it,
so need more time to push it into master, you need read the developer
documentation. http://ffmpeg.org/developer.html#Patches_002fCommitting

Thanks,

Steven
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 3/3] avformat/hlsenc: Extend persistent http connections to playlists

2017-12-15 Thread Karthick Jeyapal


On 12/14/17 1:46 PM, 刘歧 wrote:

On 14 Dec 2017, at 16:07, Karthick Jeyapal  wrote:




On Nov 30, 2017, at 2:36 PM, Karthick J  wrote:


From: Karthick Jeyapal 


Before this patch persistent http connections would work only for media 
segments.
The playlists were still opening a new connection everytime.
This patch extends persistent http connections to playlists as well.
---
libavformat/hlsenc.c | 46 ++
1 file changed, 22 insertions(+), 24 deletions(-)


diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index ff982c5..350836d 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -201,6 +201,8 @@ typedef struct HLSContext {
char *master_pl_name;
unsigned int master_publish_rate;
int http_persistent;
+ AVIOContext *m3u8_out;
+ AVIOContext *sub_m3u8_out;
} HLSContext;


static int mkdir_p(const char *path) {
@@ -1081,7 +1083,6 @@ static int create_master_playlist(AVFormatContext *s,
HLSContext *hls = s->priv_data;
VariantStream *vs;
AVStream *vid_st, *aud_st;
- AVIOContext *master_pb = 0;
AVDictionary *options = NULL;
unsigned int i, j;
int m3u8_name_size, ret, bandwidth;
@@ -1102,8 +1103,7 @@ static int create_master_playlist(AVFormatContext *s,


set_http_options(s, , hls);


- ret = s->io_open(s, _pb, hls->master_m3u8_url, AVIO_FLAG_WRITE,\
- );
+ ret = hlsenc_io_open(s, >m3u8_out, hls->master_m3u8_url, );
av_dict_free();
if (ret < 0) {
av_log(NULL, AV_LOG_ERROR, "Failed to open master play list file '%s'\n",
@@ -,7 +,7 @@ static int create_master_playlist(AVFormatContext *s,
goto fail;
}


- ff_hls_write_playlist_version(master_pb, hls->version);
+ ff_hls_write_playlist_version(hls->m3u8_out, hls->version);


/* For variant streams with video add #EXT-X-STREAM-INF tag with attributes*/
for (i = 0; i < hls->nb_varstreams; i++) {
@@ -1152,7 +1152,7 @@ static int create_master_playlist(AVFormatContext *s,
bandwidth += aud_st->codecpar->bit_rate;
bandwidth += bandwidth / 10;


- ff_hls_write_stream_info(vid_st, master_pb, bandwidth, m3u8_rel_name);
+ ff_hls_write_stream_info(vid_st, hls->m3u8_out, bandwidth, m3u8_rel_name);


av_freep(_rel_name);
}
@@ -1160,7 +1160,7 @@ fail:
if(ret >=0)
hls->master_m3u8_created = 1;
av_freep(_rel_name);
- ff_format_io_close(s, _pb);
+ hlsenc_io_close(s, >m3u8_out, hls->master_m3u8_url);
return ret;
}


@@ -1170,8 +1170,6 @@ static int hls_window(AVFormatContext *s, int last, 
VariantStream *vs)
HLSSegment *en;
int target_duration = 0;
int ret = 0;
- AVIOContext *out = NULL;
- AVIOContext *sub_out = NULL;
char temp_filename[1024];
int64_t sequence = FFMAX(hls->start_sequence, vs->sequence - vs->nb_entries);
const char *proto = avio_find_protocol_name(s->filename);
@@ -1203,7 +1201,7 @@ static int hls_window(AVFormatContext *s, int last, 
VariantStream *vs)


set_http_options(s, , hls);
snprintf(temp_filename, sizeof(temp_filename), use_rename ? "%s.tmp" : "%s", 
vs->m3u8_name);
- if ((ret = s->io_open(s, , temp_filename, AVIO_FLAG_WRITE, )) < 0)
+ if ((ret = hlsenc_io_open(s, >m3u8_out, temp_filename, )) < 0)
goto fail;


for (en = vs->segments; en; en = en->next) {
@@ -1212,33 +1210,33 @@ static int hls_window(AVFormatContext *s, int last, 
VariantStream *vs)
}


vs->discontinuity_set = 0;
- ff_hls_write_playlist_header(out, hls->version, hls->allowcache,
+ ff_hls_write_playlist_header(hls->m3u8_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");
+ avio_printf(hls->m3u8_out, "#EXT-X-DISCONTINUITY\n");
vs->discontinuity_set = 1;
}
if (vs->has_video && (hls->flags & HLS_INDEPENDENT_SEGMENTS)) {
- avio_printf(out, "#EXT-X-INDEPENDENT-SEGMENTS\n");
+ avio_printf(hls->m3u8_out, "#EXT-X-INDEPENDENT-SEGMENTS\n");
}
for (en = vs->segments; en; en = en->next) {
if ((hls->encrypt || hls->key_info_file) && (!key_uri || strcmp(en->key_uri, 
key_uri) ||
av_strcasecmp(en->iv_string, iv_string))) {
- avio_printf(out, "#EXT-X-KEY:METHOD=AES-128,URI=\"%s\"", en->key_uri);
+ avio_printf(hls->m3u8_out, "#EXT-X-KEY:METHOD=AES-128,URI=\"%s\"", 
en->key_uri);
if (*en->iv_string)
- avio_printf(out, ",IV=0x%s", en->iv_string);
- avio_printf(out, "\n");
+ avio_printf(hls->m3u8_out, ",IV=0x%s", en->iv_string);
+ avio_printf(hls->m3u8_out, "\n");
key_uri = en->key_uri;
iv_string = en->iv_string;
}


if ((hls->segment_type == SEGMENT_TYPE_FMP4) && (en == vs->segments)) {
- ff_hls_write_init_file(out, vs->fmp4_init_filename,
+ ff_hls_write_init_file(hls->m3u8_out, vs->fmp4_init_filename,
hls->flags & HLS_SINGLE_FILE, en->size, en->pos);
}


- ff_hls_write_file_entry(out, en->discont, byterange_mode,
+ ff_hls_write_file_entry(hls->m3u8_out, en->discont, byterange_mode,
en->duration, hls->flags & HLS_ROUND_DURATIONS,
en->size, en->pos, vs->baseurl,
en->filename, prog_date_time_p);
@@ -1246,29 

Re: [FFmpeg-devel] [PATCH 3/3] avformat/hlsenc: Extend persistent http connections to playlists

2017-12-14 Thread 刘歧

> On 14 Dec 2017, at 16:07, Karthick Jeyapal  wrote:
> 
> 
> 
>> On Nov 30, 2017, at 2:36 PM, Karthick J  wrote:
>> 
>> 
>> From: Karthick Jeyapal 
>> 
>> 
>> Before this patch persistent http connections would work only for media 
>> segments.
>> The playlists were still opening a new connection everytime.
>> This patch extends persistent http connections to playlists as well.
>> ---
>> libavformat/hlsenc.c | 46 ++
>> 1 file changed, 22 insertions(+), 24 deletions(-)
>> 
>> 
>> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
>> index ff982c5..350836d 100644
>> --- a/libavformat/hlsenc.c
>> +++ b/libavformat/hlsenc.c
>> @@ -201,6 +201,8 @@ typedef struct HLSContext {
>> char *master_pl_name;
>> unsigned int master_publish_rate;
>> int http_persistent;
>> + AVIOContext *m3u8_out;
>> + AVIOContext *sub_m3u8_out;
>> } HLSContext;
>> 
>> 
>> static int mkdir_p(const char *path) {
>> @@ -1081,7 +1083,6 @@ static int create_master_playlist(AVFormatContext *s,
>> HLSContext *hls = s->priv_data;
>> VariantStream *vs;
>> AVStream *vid_st, *aud_st;
>> - AVIOContext *master_pb = 0;
>> AVDictionary *options = NULL;
>> unsigned int i, j;
>> int m3u8_name_size, ret, bandwidth;
>> @@ -1102,8 +1103,7 @@ static int create_master_playlist(AVFormatContext *s,
>> 
>> 
>> set_http_options(s, , hls);
>> 
>> 
>> - ret = s->io_open(s, _pb, hls->master_m3u8_url, AVIO_FLAG_WRITE,\
>> - );
>> + ret = hlsenc_io_open(s, >m3u8_out, hls->master_m3u8_url, );
>> av_dict_free();
>> if (ret < 0) {
>> av_log(NULL, AV_LOG_ERROR, "Failed to open master play list file '%s'\n",
>> @@ -,7 +,7 @@ static int create_master_playlist(AVFormatContext *s,
>> goto fail;
>> }
>> 
>> 
>> - ff_hls_write_playlist_version(master_pb, hls->version);
>> + ff_hls_write_playlist_version(hls->m3u8_out, hls->version);
>> 
>> 
>> /* For variant streams with video add #EXT-X-STREAM-INF tag with attributes*/
>> for (i = 0; i < hls->nb_varstreams; i++) {
>> @@ -1152,7 +1152,7 @@ static int create_master_playlist(AVFormatContext *s,
>> bandwidth += aud_st->codecpar->bit_rate;
>> bandwidth += bandwidth / 10;
>> 
>> 
>> - ff_hls_write_stream_info(vid_st, master_pb, bandwidth, m3u8_rel_name);
>> + ff_hls_write_stream_info(vid_st, hls->m3u8_out, bandwidth, m3u8_rel_name);
>> 
>> 
>> av_freep(_rel_name);
>> }
>> @@ -1160,7 +1160,7 @@ fail:
>> if(ret >=0)
>> hls->master_m3u8_created = 1;
>> av_freep(_rel_name);
>> - ff_format_io_close(s, _pb);
>> + hlsenc_io_close(s, >m3u8_out, hls->master_m3u8_url);
>> return ret;
>> }
>> 
>> 
>> @@ -1170,8 +1170,6 @@ static int hls_window(AVFormatContext *s, int last, 
>> VariantStream *vs)
>> HLSSegment *en;
>> int target_duration = 0;
>> int ret = 0;
>> - AVIOContext *out = NULL;
>> - AVIOContext *sub_out = NULL;
>> char temp_filename[1024];
>> int64_t sequence = FFMAX(hls->start_sequence, vs->sequence - vs->nb_entries);
>> const char *proto = avio_find_protocol_name(s->filename);
>> @@ -1203,7 +1201,7 @@ static int hls_window(AVFormatContext *s, int last, 
>> VariantStream *vs)
>> 
>> 
>> set_http_options(s, , hls);
>> snprintf(temp_filename, sizeof(temp_filename), use_rename ? "%s.tmp" : "%s", 
>> vs->m3u8_name);
>> - if ((ret = s->io_open(s, , temp_filename, AVIO_FLAG_WRITE, )) 
>> < 0)
>> + if ((ret = hlsenc_io_open(s, >m3u8_out, temp_filename, )) < 0)
>> goto fail;
>> 
>> 
>> for (en = vs->segments; en; en = en->next) {
>> @@ -1212,33 +1210,33 @@ static int hls_window(AVFormatContext *s, int last, 
>> VariantStream *vs)
>> }
>> 
>> 
>> vs->discontinuity_set = 0;
>> - ff_hls_write_playlist_header(out, hls->version, hls->allowcache,
>> + ff_hls_write_playlist_header(hls->m3u8_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");
>> + avio_printf(hls->m3u8_out, "#EXT-X-DISCONTINUITY\n");
>> vs->discontinuity_set = 1;
>> }
>> if (vs->has_video && (hls->flags & HLS_INDEPENDENT_SEGMENTS)) {
>> - avio_printf(out, "#EXT-X-INDEPENDENT-SEGMENTS\n");
>> + avio_printf(hls->m3u8_out, "#EXT-X-INDEPENDENT-SEGMENTS\n");
>> }
>> for (en = vs->segments; en; en = en->next) {
>> if ((hls->encrypt || hls->key_info_file) && (!key_uri || strcmp(en->key_uri, 
>> key_uri) ||
>> av_strcasecmp(en->iv_string, iv_string))) {
>> - avio_printf(out, "#EXT-X-KEY:METHOD=AES-128,URI=\"%s\"", en->key_uri);
>> + avio_printf(hls->m3u8_out, "#EXT-X-KEY:METHOD=AES-128,URI=\"%s\"", 
>> en->key_uri);
>> if (*en->iv_string)
>> - avio_printf(out, ",IV=0x%s", en->iv_string);
>> - avio_printf(out, "\n");
>> + avio_printf(hls->m3u8_out, ",IV=0x%s", en->iv_string);
>> + avio_printf(hls->m3u8_out, "\n");
>> key_uri = en->key_uri;
>> iv_string = en->iv_string;
>> }
>> 
>> 
>> if ((hls->segment_type == SEGMENT_TYPE_FMP4) && (en == vs->segments)) {
>> - 

Re: [FFmpeg-devel] [PATCH 3/3] avformat/hlsenc: Extend persistent http connections to playlists

2017-12-14 Thread Karthick Jeyapal


> On Nov 30, 2017, at 2:36 PM, Karthick J  wrote:
> 
> 
> From: Karthick Jeyapal 
> 
> 
> Before this patch persistent http connections would work only for media 
> segments.
> The playlists were still opening a new connection everytime.
> This patch extends persistent http connections to playlists as well.
> ---
> libavformat/hlsenc.c | 46 ++
> 1 file changed, 22 insertions(+), 24 deletions(-)
> 
> 
> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> index ff982c5..350836d 100644
> --- a/libavformat/hlsenc.c
> +++ b/libavformat/hlsenc.c
> @@ -201,6 +201,8 @@ typedef struct HLSContext {
> char *master_pl_name;
> unsigned int master_publish_rate;
> int http_persistent;
> + AVIOContext *m3u8_out;
> + AVIOContext *sub_m3u8_out;
> } HLSContext;
> 
> 
> static int mkdir_p(const char *path) {
> @@ -1081,7 +1083,6 @@ static int create_master_playlist(AVFormatContext *s,
> HLSContext *hls = s->priv_data;
> VariantStream *vs;
> AVStream *vid_st, *aud_st;
> - AVIOContext *master_pb = 0;
> AVDictionary *options = NULL;
> unsigned int i, j;
> int m3u8_name_size, ret, bandwidth;
> @@ -1102,8 +1103,7 @@ static int create_master_playlist(AVFormatContext *s,
> 
> 
> set_http_options(s, , hls);
> 
> 
> - ret = s->io_open(s, _pb, hls->master_m3u8_url, AVIO_FLAG_WRITE,\
> - );
> + ret = hlsenc_io_open(s, >m3u8_out, hls->master_m3u8_url, );
> av_dict_free();
> if (ret < 0) {
> av_log(NULL, AV_LOG_ERROR, "Failed to open master play list file '%s'\n",
> @@ -,7 +,7 @@ static int create_master_playlist(AVFormatContext *s,
> goto fail;
> }
> 
> 
> - ff_hls_write_playlist_version(master_pb, hls->version);
> + ff_hls_write_playlist_version(hls->m3u8_out, hls->version);
> 
> 
> /* For variant streams with video add #EXT-X-STREAM-INF tag with attributes*/
> for (i = 0; i < hls->nb_varstreams; i++) {
> @@ -1152,7 +1152,7 @@ static int create_master_playlist(AVFormatContext *s,
> bandwidth += aud_st->codecpar->bit_rate;
> bandwidth += bandwidth / 10;
> 
> 
> - ff_hls_write_stream_info(vid_st, master_pb, bandwidth, m3u8_rel_name);
> + ff_hls_write_stream_info(vid_st, hls->m3u8_out, bandwidth, m3u8_rel_name);
> 
> 
> av_freep(_rel_name);
> }
> @@ -1160,7 +1160,7 @@ fail:
> if(ret >=0)
> hls->master_m3u8_created = 1;
> av_freep(_rel_name);
> - ff_format_io_close(s, _pb);
> + hlsenc_io_close(s, >m3u8_out, hls->master_m3u8_url);
> return ret;
> }
> 
> 
> @@ -1170,8 +1170,6 @@ static int hls_window(AVFormatContext *s, int last, 
> VariantStream *vs)
> HLSSegment *en;
> int target_duration = 0;
> int ret = 0;
> - AVIOContext *out = NULL;
> - AVIOContext *sub_out = NULL;
> char temp_filename[1024];
> int64_t sequence = FFMAX(hls->start_sequence, vs->sequence - vs->nb_entries);
> const char *proto = avio_find_protocol_name(s->filename);
> @@ -1203,7 +1201,7 @@ static int hls_window(AVFormatContext *s, int last, 
> VariantStream *vs)
> 
> 
> set_http_options(s, , hls);
> snprintf(temp_filename, sizeof(temp_filename), use_rename ? "%s.tmp" : "%s", 
> vs->m3u8_name);
> - if ((ret = s->io_open(s, , temp_filename, AVIO_FLAG_WRITE, )) < 
> 0)
> + if ((ret = hlsenc_io_open(s, >m3u8_out, temp_filename, )) < 0)
> goto fail;
> 
> 
> for (en = vs->segments; en; en = en->next) {
> @@ -1212,33 +1210,33 @@ static int hls_window(AVFormatContext *s, int last, 
> VariantStream *vs)
> }
> 
> 
> vs->discontinuity_set = 0;
> - ff_hls_write_playlist_header(out, hls->version, hls->allowcache,
> + ff_hls_write_playlist_header(hls->m3u8_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");
> + avio_printf(hls->m3u8_out, "#EXT-X-DISCONTINUITY\n");
> vs->discontinuity_set = 1;
> }
> if (vs->has_video && (hls->flags & HLS_INDEPENDENT_SEGMENTS)) {
> - avio_printf(out, "#EXT-X-INDEPENDENT-SEGMENTS\n");
> + avio_printf(hls->m3u8_out, "#EXT-X-INDEPENDENT-SEGMENTS\n");
> }
> for (en = vs->segments; en; en = en->next) {
> if ((hls->encrypt || hls->key_info_file) && (!key_uri || strcmp(en->key_uri, 
> key_uri) ||
> av_strcasecmp(en->iv_string, iv_string))) {
> - avio_printf(out, "#EXT-X-KEY:METHOD=AES-128,URI=\"%s\"", en->key_uri);
> + avio_printf(hls->m3u8_out, "#EXT-X-KEY:METHOD=AES-128,URI=\"%s\"", 
> en->key_uri);
> if (*en->iv_string)
> - avio_printf(out, ",IV=0x%s", en->iv_string);
> - avio_printf(out, "\n");
> + avio_printf(hls->m3u8_out, ",IV=0x%s", en->iv_string);
> + avio_printf(hls->m3u8_out, "\n");
> key_uri = en->key_uri;
> iv_string = en->iv_string;
> }
> 
> 
> if ((hls->segment_type == SEGMENT_TYPE_FMP4) && (en == vs->segments)) {
> - ff_hls_write_init_file(out, vs->fmp4_init_filename,
> + ff_hls_write_init_file(hls->m3u8_out, vs->fmp4_init_filename,
> hls->flags & HLS_SINGLE_FILE, en->size, en->pos);
> }
> 
> 
> - ff_hls_write_file_entry(out, en->discont, byterange_mode,
> + 

[FFmpeg-devel] [PATCH 3/3] avformat/hlsenc: Extend persistent http connections to playlists

2017-11-30 Thread Karthick J
From: Karthick Jeyapal 

Before this patch persistent http connections would work only for media 
segments.
The playlists were still opening a new connection everytime.
This patch extends persistent http connections to playlists as well.
---
 libavformat/hlsenc.c | 46 ++
 1 file changed, 22 insertions(+), 24 deletions(-)

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index ff982c5..350836d 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -201,6 +201,8 @@ typedef struct HLSContext {
 char *master_pl_name;
 unsigned int master_publish_rate;
 int http_persistent;
+AVIOContext *m3u8_out;
+AVIOContext *sub_m3u8_out;
 } HLSContext;
 
 static int mkdir_p(const char *path) {
@@ -1081,7 +1083,6 @@ static int create_master_playlist(AVFormatContext *s,
 HLSContext *hls = s->priv_data;
 VariantStream *vs;
 AVStream *vid_st, *aud_st;
-AVIOContext *master_pb = 0;
 AVDictionary *options = NULL;
 unsigned int i, j;
 int m3u8_name_size, ret, bandwidth;
@@ -1102,8 +1103,7 @@ static int create_master_playlist(AVFormatContext *s,
 
 set_http_options(s, , hls);
 
-ret = s->io_open(s, _pb, hls->master_m3u8_url, AVIO_FLAG_WRITE,\
- );
+ret = hlsenc_io_open(s, >m3u8_out, hls->master_m3u8_url, );
 av_dict_free();
 if (ret < 0) {
 av_log(NULL, AV_LOG_ERROR, "Failed to open master play list file 
'%s'\n",
@@ -,7 +,7 @@ static int create_master_playlist(AVFormatContext *s,
 goto fail;
 }
 
-ff_hls_write_playlist_version(master_pb, hls->version);
+ff_hls_write_playlist_version(hls->m3u8_out, hls->version);
 
 /* For variant streams with video add #EXT-X-STREAM-INF tag with 
attributes*/
 for (i = 0; i < hls->nb_varstreams; i++) {
@@ -1152,7 +1152,7 @@ static int create_master_playlist(AVFormatContext *s,
 bandwidth += aud_st->codecpar->bit_rate;
 bandwidth += bandwidth / 10;
 
-ff_hls_write_stream_info(vid_st, master_pb, bandwidth, m3u8_rel_name);
+ff_hls_write_stream_info(vid_st, hls->m3u8_out, bandwidth, 
m3u8_rel_name);
 
 av_freep(_rel_name);
 }
@@ -1160,7 +1160,7 @@ fail:
 if(ret >=0)
 hls->master_m3u8_created = 1;
 av_freep(_rel_name);
-ff_format_io_close(s, _pb);
+hlsenc_io_close(s, >m3u8_out, hls->master_m3u8_url);
 return ret;
 }
 
@@ -1170,8 +1170,6 @@ static int hls_window(AVFormatContext *s, int last, 
VariantStream *vs)
 HLSSegment *en;
 int target_duration = 0;
 int ret = 0;
-AVIOContext *out = NULL;
-AVIOContext *sub_out = NULL;
 char temp_filename[1024];
 int64_t sequence = FFMAX(hls->start_sequence, vs->sequence - 
vs->nb_entries);
 const char *proto = avio_find_protocol_name(s->filename);
@@ -1203,7 +1201,7 @@ static int hls_window(AVFormatContext *s, int last, 
VariantStream *vs)
 
 set_http_options(s, , hls);
 snprintf(temp_filename, sizeof(temp_filename), use_rename ? "%s.tmp" : 
"%s", vs->m3u8_name);
-if ((ret = s->io_open(s, , temp_filename, AVIO_FLAG_WRITE, )) 
< 0)
+if ((ret = hlsenc_io_open(s, >m3u8_out, temp_filename, )) < 0)
 goto fail;
 
 for (en = vs->segments; en; en = en->next) {
@@ -1212,33 +1210,33 @@ static int hls_window(AVFormatContext *s, int last, 
VariantStream *vs)
 }
 
 vs->discontinuity_set = 0;
-ff_hls_write_playlist_header(out, hls->version, hls->allowcache,
+ff_hls_write_playlist_header(hls->m3u8_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");
+avio_printf(hls->m3u8_out, "#EXT-X-DISCONTINUITY\n");
 vs->discontinuity_set = 1;
 }
 if (vs->has_video && (hls->flags & HLS_INDEPENDENT_SEGMENTS)) {
-avio_printf(out, "#EXT-X-INDEPENDENT-SEGMENTS\n");
+avio_printf(hls->m3u8_out, "#EXT-X-INDEPENDENT-SEGMENTS\n");
 }
 for (en = vs->segments; en; en = en->next) {
 if ((hls->encrypt || hls->key_info_file) && (!key_uri || 
strcmp(en->key_uri, key_uri) ||
 av_strcasecmp(en->iv_string, iv_string))) {
-avio_printf(out, "#EXT-X-KEY:METHOD=AES-128,URI=\"%s\"", 
en->key_uri);
+avio_printf(hls->m3u8_out, "#EXT-X-KEY:METHOD=AES-128,URI=\"%s\"", 
en->key_uri);
 if (*en->iv_string)
-avio_printf(out, ",IV=0x%s", en->iv_string);
-avio_printf(out, "\n");
+avio_printf(hls->m3u8_out, ",IV=0x%s", en->iv_string);
+avio_printf(hls->m3u8_out, "\n");
 key_uri = en->key_uri;
 iv_string = en->iv_string;
 }
 
 if ((hls->segment_type == SEGMENT_TYPE_FMP4) && (en == vs->segments)) {
-