Re: [FFmpeg-devel] [PATCH] avformat/dashenc: Fix the EXT-X-TARGETDURATION as per the hls specification

2017-12-21 Thread Karthick Jeyapal



On 12/21/17 7:45 PM, Carl Eugen Hoyos wrote:

2017-12-21 11:09 GMT+01:00 Karthick J :


  if (target_duration <= duration)
-target_duration = hls_get_int_from_double(duration);
+target_duration = lrint(duration);

If this patch gets committed, please move the function
into dashenc.c.
I am confused. Which function? Could you please clarify? Did you mean 
lrint() function?


Carl Eugen
___
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] avformat/hlsenc: Fix a memory leak when http_persistent is 1

2017-12-20 Thread Karthick Jeyapal



On 12/21/17 9:11 AM, 刘歧 wrote:



On 19 Dec 2017, at 16:49, 刘歧 <l...@chinaffmpeg.org> wrote:


On 19 Dec 2017, at 14:58, Karthick J <kjeya...@akamai.com> wrote:

From: Karthick Jeyapal <kjeya...@akamai.com>

---
libavformat/hlsenc.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index e3442c3..5ee28ea 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -1918,6 +1918,8 @@ static int hls_write_trailer(struct AVFormatContext *s)
av_freep(>baseurl);
}

+ff_format_io_close(s, >m3u8_out);
+ff_format_io_close(s, >sub_m3u8_out);
av_freep(>key_basename);
av_freep(>var_streams);
av_freep(>master_m3u8_url);
--
1.9.1




LGTM



Pushed

Thanks!


Thanks





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


Re: [FFmpeg-devel] [PATCH 3/4] avformat/hlsenc: use hlsenc_io_* APIs

2017-12-18 Thread Karthick Jeyapal



On 12/19/17 11:32 AM, 刘歧 wrote:



On 19 Dec 2017, at 12:11, Karthick Jeyapal <kjeya...@akamai.com> wrote:



On 12/19/17 9:29 AM, 刘歧 wrote:

On 19 Dec 2017, at 11:55, Karthick Jeyapal <kjeya...@akamai.com> wrote:



On 12/18/17 2:17 PM, Steven Liu wrote:

Signed-off-by: Steven Liu <l...@chinaffmpeg.org>
---
  libavformat/hlsenc.c | 23 ---
  1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index 0eebcb4462..0cb75ff198 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -440,7 +440,7 @@ static int hls_delete_old_segments(AVFormatContext *s, 
HLSContext *hls,
  av_dict_set(, "method", "DELETE", 0);
  if ((ret = vs->avf->io_open(vs->avf, , path, AVIO_FLAG_WRITE, 
)) < 0)
  goto fail;
-ff_format_io_close(vs->avf, );
+hlsenc_io_close(vs->avf, , path);

Will not actually close, when http_persistent is 1. I think it is better to 
leave this as ff_format_io_close

  } else if (unlink(path) < 0) {
  av_log(hls, AV_LOG_ERROR, "failed to delete old segment %s: %s\n",
   path, strerror(errno));
@@ -463,7 +463,7 @@ static int hls_delete_old_segments(AVFormatContext *s, 
HLSContext *hls,
  av_free(sub_path);
  goto fail;
  }
-ff_format_io_close(vs->avf, );
+hlsenc_io_close(vs->avf, , sub_path);

Will not actually close, when http_persistent is 1.

  } else if (unlink(sub_path) < 0) {
  av_log(hls, AV_LOG_ERROR, "failed to delete old segment %s: 
%s\n",
   sub_path, strerror(errno));
@@ -556,8 +556,10 @@ static int do_encrypt(AVFormatContext *s, VariantStream 
*vs)
  }
ff_data_to_hex(hls->key_string, key, sizeof(key), 0);
-if ((ret = s->io_open(s, , hls->key_file, AVIO_FLAG_WRITE, NULL)) < 
0)
-return ret;
+ret = hlsenc_io_open(s, , hls->key_file, NULL);

We needn't call hlsenc_io_open if we are not planning to use a persistent 
connection for it. In this case pb is uninitialized and hlsenc_io_open will most 
probably cause a crash or undefined behavior. You can get around that issue by 
initializing pb to NULL. But I think that is unnecessary and are better placed 
with s->io_open().

+if (ret < 0) {
+return ret;;

Extra semicolon

+}
  avio_seek(pb, 0, SEEK_CUR);
  avio_write(pb, key, KEYSIZE);
  avio_close(pb);
@@ -588,7 +590,7 @@ static int hls_encryption_start(AVFormatContext *s)
  ff_get_line(pb, hls->iv_string, sizeof(hls->iv_string));
  hls->iv_string[strcspn(hls->iv_string, "\r\n")] = '\0';
  -ff_format_io_close(s, );
+hlsenc_io_close(s, , hls->key_info_file);
if (!*hls->key_uri) {
  av_log(hls, AV_LOG_ERROR, "no key URI specified in key info file\n");
@@ -606,7 +608,7 @@ static int hls_encryption_start(AVFormatContext *s)
  }
ret = avio_read(pb, key, sizeof(key));
-ff_format_io_close(s, );
+hlsenc_io_close(s, , hls->key_file);

Will not actually close, when http_persistent is 1.

  if (ret != sizeof(key)) {
  av_log(hls, AV_LOG_ERROR, "error reading key file %s\n", 
hls->key_file);
  if (ret >= 0 || ret == AVERROR_EOF)
@@ -1812,7 +1814,6 @@ static int hls_write_packet(AVFormatContext *s, AVPacket 
*pkt)
  vs->init_range_length = range_length;
  avio_open_dyn_buf(>pb);
  vs->packets_written = 0;
-ff_format_io_close(s, >out);
  hlsenc_io_close(s, >out, vs->base_output_dirname);
  }
  } else {
@@ -1845,7 +1846,7 @@ static int hls_write_packet(AVFormatContext *s, AVPacket 
*pkt)
  if (ret < 0) {
  return ret;
  }
-ff_format_io_close(s, >out);
+hlsenc_io_close(s, >out, vs->avf->filename);
  }
  ret = hls_append_segment(s, hls, vs, vs->duration, vs->start_pos, 
vs->size);
  vs->start_pos = new_start_pos;
@@ -1925,14 +1926,14 @@ static int hls_write_trailer(struct AVFormatContext *s)
  if (ret < 0) {
  return ret;
  }
-ff_format_io_close(s, >out);
+hlsenc_io_close(s, >out, vs->avf->filename);

Will not actually close, when http_persistent is 1. hls_write_trailer should 
always call ff_format_io_close()

  }
av_write_trailer(oc);
  if (oc->pb) {
  vs->size = avio_tell(vs->avf->pb) - vs->start_pos;
  if (hls->segment_type != SEGMENT_TYPE_FMP4)
-   

Re: [FFmpeg-devel] [PATCH 3/4] avformat/hlsenc: use hlsenc_io_* APIs

2017-12-18 Thread Karthick Jeyapal



On 12/19/17 9:29 AM, 刘歧 wrote:



On 19 Dec 2017, at 11:55, Karthick Jeyapal <kjeya...@akamai.com> wrote:



On 12/18/17 2:17 PM, Steven Liu wrote:

Signed-off-by: Steven Liu <l...@chinaffmpeg.org>
---
  libavformat/hlsenc.c | 23 ---
  1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index 0eebcb4462..0cb75ff198 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -440,7 +440,7 @@ static int hls_delete_old_segments(AVFormatContext *s, 
HLSContext *hls,
  av_dict_set(, "method", "DELETE", 0);
  if ((ret = vs->avf->io_open(vs->avf, , path, AVIO_FLAG_WRITE, 
)) < 0)
  goto fail;
-ff_format_io_close(vs->avf, );
+hlsenc_io_close(vs->avf, , path);

Will not actually close, when http_persistent is 1. I think it is better to 
leave this as ff_format_io_close

  } else if (unlink(path) < 0) {
  av_log(hls, AV_LOG_ERROR, "failed to delete old segment %s: %s\n",
   path, strerror(errno));
@@ -463,7 +463,7 @@ static int hls_delete_old_segments(AVFormatContext *s, 
HLSContext *hls,
  av_free(sub_path);
  goto fail;
  }
-ff_format_io_close(vs->avf, );
+hlsenc_io_close(vs->avf, , sub_path);

Will not actually close, when http_persistent is 1.

  } else if (unlink(sub_path) < 0) {
  av_log(hls, AV_LOG_ERROR, "failed to delete old segment %s: 
%s\n",
   sub_path, strerror(errno));
@@ -556,8 +556,10 @@ static int do_encrypt(AVFormatContext *s, VariantStream 
*vs)
  }
ff_data_to_hex(hls->key_string, key, sizeof(key), 0);
-if ((ret = s->io_open(s, , hls->key_file, AVIO_FLAG_WRITE, NULL)) < 
0)
-return ret;
+ret = hlsenc_io_open(s, , hls->key_file, NULL);

We needn't call hlsenc_io_open if we are not planning to use a persistent 
connection for it. In this case pb is uninitialized and hlsenc_io_open will most 
probably cause a crash or undefined behavior. You can get around that issue by 
initializing pb to NULL. But I think that is unnecessary and are better placed 
with s->io_open().

+if (ret < 0) {
+return ret;;

Extra semicolon

+}
  avio_seek(pb, 0, SEEK_CUR);
  avio_write(pb, key, KEYSIZE);
  avio_close(pb);
@@ -588,7 +590,7 @@ static int hls_encryption_start(AVFormatContext *s)
  ff_get_line(pb, hls->iv_string, sizeof(hls->iv_string));
  hls->iv_string[strcspn(hls->iv_string, "\r\n")] = '\0';
  -ff_format_io_close(s, );
+hlsenc_io_close(s, , hls->key_info_file);
if (!*hls->key_uri) {
  av_log(hls, AV_LOG_ERROR, "no key URI specified in key info file\n");
@@ -606,7 +608,7 @@ static int hls_encryption_start(AVFormatContext *s)
  }
ret = avio_read(pb, key, sizeof(key));
-ff_format_io_close(s, );
+hlsenc_io_close(s, , hls->key_file);

Will not actually close, when http_persistent is 1.

  if (ret != sizeof(key)) {
  av_log(hls, AV_LOG_ERROR, "error reading key file %s\n", 
hls->key_file);
  if (ret >= 0 || ret == AVERROR_EOF)
@@ -1812,7 +1814,6 @@ static int hls_write_packet(AVFormatContext *s, AVPacket 
*pkt)
  vs->init_range_length = range_length;
  avio_open_dyn_buf(>pb);
  vs->packets_written = 0;
-ff_format_io_close(s, >out);
  hlsenc_io_close(s, >out, vs->base_output_dirname);
  }
  } else {
@@ -1845,7 +1846,7 @@ static int hls_write_packet(AVFormatContext *s, AVPacket 
*pkt)
  if (ret < 0) {
  return ret;
  }
-ff_format_io_close(s, >out);
+hlsenc_io_close(s, >out, vs->avf->filename);
  }
  ret = hls_append_segment(s, hls, vs, vs->duration, vs->start_pos, 
vs->size);
  vs->start_pos = new_start_pos;
@@ -1925,14 +1926,14 @@ static int hls_write_trailer(struct AVFormatContext *s)
  if (ret < 0) {
  return ret;
  }
-ff_format_io_close(s, >out);
+hlsenc_io_close(s, >out, vs->avf->filename);

Will not actually close, when http_persistent is 1. hls_write_trailer should 
always call ff_format_io_close()

  }
av_write_trailer(oc);
  if (oc->pb) {
  vs->size = avio_tell(vs->avf->pb) - vs->start_pos;
  if (hls->segment_type != SEGMENT_TYPE_FMP4)
-ff_format_io_close(s, >pb);
+hlsenc_io_close(s, >pb, oc->filename);

Will not actually close, 

[FFmpeg-devel] Fwd: Re: [PATCH 4/4] avformat/hlsenc: add http options to m3u8 hlsenc

2017-12-18 Thread Karthick Jeyapal


On 12/18/17 2:17 PM, Steven Liu wrote:

Signed-off-by: Steven Liu 
---
  libavformat/hlsenc.c | 8 ++--
  1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index 0cb75ff198..636b7db183 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -1723,6 +1723,7 @@ static int hls_write_packet(AVFormatContext *s, AVPacket 
*pkt)
  int stream_index = 0;
  int range_length = 0;
  uint8_t *buffer = NULL;
+AVDictionary *options = NULL;
  VariantStream *vs = NULL;
  
  for (i = 0; i < hls->nb_varstreams; i++) {

@@ -1835,7 +1836,8 @@ static int hls_write_packet(AVFormatContext *s, AVPacket 
*pkt)
  }
  
  if (hls->segment_type == SEGMENT_TYPE_FMP4) {

-ret = hlsenc_io_open(s, >out, vs->avf->filename, NULL);
+set_http_options(s, , hls);
+ret = hlsenc_io_open(s, >out, vs->avf->filename, );

av_dict_free() call for options needs to be added here

  if (ret < 0) {
  av_log(NULL, AV_LOG_ERROR, "Failed to open file '%s'\n",
  vs->avf->filename);
@@ -1899,6 +1901,7 @@ static int hls_write_trailer(struct AVFormatContext *s)
  HLSContext *hls = s->priv_data;
  AVFormatContext *oc = NULL;
  AVFormatContext *vtt_oc = NULL;
+AVDictionary *options = NULL;
  char *old_filename = NULL;
  int i;
  int ret = 0;
@@ -1916,7 +1919,8 @@ static int hls_write_trailer(struct AVFormatContext *s)
  }
  if ( hls->segment_type == SEGMENT_TYPE_FMP4) {
  int range_length = 0;
-ret = hlsenc_io_open(s, >out, vs->avf->filename, NULL);
+set_http_options(s, , hls);
+ret = hlsenc_io_open(s, >out, vs->avf->filename, );

av_dict_free() call for options needs to be added here

  if (ret < 0) {
  av_log(NULL, AV_LOG_ERROR, "Failed to open file '%s'\n", 
vs->avf->filename);
  return AVERROR(ENOENT);


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


Re: [FFmpeg-devel] [PATCH 3/4] avformat/hlsenc: use hlsenc_io_* APIs

2017-12-18 Thread Karthick Jeyapal



On 12/18/17 2:17 PM, Steven Liu wrote:

Signed-off-by: Steven Liu 
---
  libavformat/hlsenc.c | 23 ---
  1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index 0eebcb4462..0cb75ff198 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -440,7 +440,7 @@ static int hls_delete_old_segments(AVFormatContext *s, 
HLSContext *hls,
  av_dict_set(, "method", "DELETE", 0);
  if ((ret = vs->avf->io_open(vs->avf, , path, AVIO_FLAG_WRITE, 
)) < 0)
  goto fail;
-ff_format_io_close(vs->avf, );
+hlsenc_io_close(vs->avf, , path);
Will not actually close, when http_persistent is 1. I think it is better 
to leave this as ff_format_io_close

  } else if (unlink(path) < 0) {
  av_log(hls, AV_LOG_ERROR, "failed to delete old segment %s: %s\n",
   path, strerror(errno));
@@ -463,7 +463,7 @@ static int hls_delete_old_segments(AVFormatContext *s, 
HLSContext *hls,
  av_free(sub_path);
  goto fail;
  }
-ff_format_io_close(vs->avf, );
+hlsenc_io_close(vs->avf, , sub_path);

Will not actually close, when http_persistent is 1.

  } else if (unlink(sub_path) < 0) {
  av_log(hls, AV_LOG_ERROR, "failed to delete old segment %s: 
%s\n",
   sub_path, strerror(errno));
@@ -556,8 +556,10 @@ static int do_encrypt(AVFormatContext *s, VariantStream 
*vs)
  }
  
  ff_data_to_hex(hls->key_string, key, sizeof(key), 0);

-if ((ret = s->io_open(s, , hls->key_file, AVIO_FLAG_WRITE, NULL)) < 
0)
-return ret;
+ret = hlsenc_io_open(s, , hls->key_file, NULL);
We needn't call hlsenc_io_open if we are not planning to use a 
persistent connection for it. In this case pb is uninitialized and 
hlsenc_io_open will most probably cause a crash or undefined behavior. 
You can get around that issue by initializing pb to NULL. But I think 
that is unnecessary and are better placed with s->io_open().

+if (ret < 0) {
+return ret;;

Extra semicolon

+}
  avio_seek(pb, 0, SEEK_CUR);
  avio_write(pb, key, KEYSIZE);
  avio_close(pb);
@@ -588,7 +590,7 @@ static int hls_encryption_start(AVFormatContext *s)
  ff_get_line(pb, hls->iv_string, sizeof(hls->iv_string));
  hls->iv_string[strcspn(hls->iv_string, "\r\n")] = '\0';
  
-ff_format_io_close(s, );

+hlsenc_io_close(s, , hls->key_info_file);
  
  if (!*hls->key_uri) {

  av_log(hls, AV_LOG_ERROR, "no key URI specified in key info file\n");
@@ -606,7 +608,7 @@ static int hls_encryption_start(AVFormatContext *s)
  }
  
  ret = avio_read(pb, key, sizeof(key));

-ff_format_io_close(s, );
+hlsenc_io_close(s, , hls->key_file);

Will not actually close, when http_persistent is 1.

  if (ret != sizeof(key)) {
  av_log(hls, AV_LOG_ERROR, "error reading key file %s\n", 
hls->key_file);
  if (ret >= 0 || ret == AVERROR_EOF)
@@ -1812,7 +1814,6 @@ static int hls_write_packet(AVFormatContext *s, AVPacket 
*pkt)
  vs->init_range_length = range_length;
  avio_open_dyn_buf(>pb);
  vs->packets_written = 0;
-ff_format_io_close(s, >out);
  hlsenc_io_close(s, >out, vs->base_output_dirname);
  }
  } else {
@@ -1845,7 +1846,7 @@ static int hls_write_packet(AVFormatContext *s, AVPacket 
*pkt)
  if (ret < 0) {
  return ret;
  }
-ff_format_io_close(s, >out);
+hlsenc_io_close(s, >out, vs->avf->filename);
  }
  ret = hls_append_segment(s, hls, vs, vs->duration, vs->start_pos, 
vs->size);
  vs->start_pos = new_start_pos;
@@ -1925,14 +1926,14 @@ static int hls_write_trailer(struct AVFormatContext *s)
  if (ret < 0) {
  return ret;
  }
-ff_format_io_close(s, >out);
+hlsenc_io_close(s, >out, vs->avf->filename);
Will not actually close, when http_persistent is 1. hls_write_trailer 
should always call ff_format_io_close()

  }
  
  av_write_trailer(oc);

  if (oc->pb) {
  vs->size = avio_tell(vs->avf->pb) - vs->start_pos;
  if (hls->segment_type != SEGMENT_TYPE_FMP4)
-ff_format_io_close(s, >pb);
+hlsenc_io_close(s, >pb, oc->filename);
Will not actually close, when http_persistent is 1. hls_write_trailer 
should always call ff_format_io_close()
  
  if ((hls->flags & HLS_TEMP_FILE) && oc->filename[0]) {

  hls_rename_temp_file(s, oc);
@@ -1948,7 +1949,7 @@ static int hls_write_trailer(struct AVFormatContext *s)
  if (vtt_oc->pb)
  av_write_trailer(vtt_oc);
  

Re: [FFmpeg-devel] [PATCH 2/4] avformat/hlsenc: reindent after previous commits

2017-12-18 Thread Karthick Jeyapal



On 12/18/17 2:17 PM, Steven Liu wrote:

Signed-off-by: Steven Liu 
---
  libavformat/hlsenc.c | 24 
  1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index f51fec1030..0eebcb4462 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -1806,14 +1806,14 @@ static int hls_write_packet(AVFormatContext *s, 
AVPacket *pkt)
  if (!byterange_mode) {
  if (hls->segment_type == SEGMENT_TYPE_FMP4) {
  if (!vs->init_range_length) {
-avio_flush(oc->pb);
-range_length = avio_close_dyn_buf(oc->pb, );
-avio_write(vs->out, buffer, range_length);
-vs->init_range_length = range_length;
-avio_open_dyn_buf(>pb);
-vs->packets_written = 0;
-ff_format_io_close(s, >out);
-hlsenc_io_close(s, >out, vs->base_output_dirname);
+avio_flush(oc->pb);
+range_length = avio_close_dyn_buf(oc->pb, );
+avio_write(vs->out, buffer, range_length);
+vs->init_range_length = range_length;
+avio_open_dyn_buf(>pb);
+vs->packets_written = 0;
+ff_format_io_close(s, >out);
+hlsenc_io_close(s, >out, vs->base_output_dirname);
  }
  } else {
  hlsenc_io_close(s, >pb, oc->filename);
@@ -1847,7 +1847,7 @@ static int hls_write_packet(AVFormatContext *s, AVPacket 
*pkt)
  }
  ff_format_io_close(s, >out);
  }
-ret = hls_append_segment(s, hls, vs, vs->duration, vs->start_pos, 
vs->size);
+ret = hls_append_segment(s, hls, vs, vs->duration, vs->start_pos, 
vs->size);
  vs->start_pos = new_start_pos;
  if (ret < 0) {
  av_free(old_filename);
@@ -1932,7 +1932,7 @@ static int hls_write_trailer(struct AVFormatContext *s)
  if (oc->pb) {
  vs->size = avio_tell(vs->avf->pb) - vs->start_pos;
  if (hls->segment_type != SEGMENT_TYPE_FMP4)
-ff_format_io_close(s, >pb);
+ff_format_io_close(s, >pb);
  
  if ((hls->flags & HLS_TEMP_FILE) && oc->filename[0]) {

  hls_rename_temp_file(s, oc);
@@ -2292,8 +2292,8 @@ static int hls_init(AVFormatContext *s)
  }
  }
  
-if ((ret = hls_start(s, vs)) < 0)

-goto fail;
+if ((ret = hls_start(s, vs)) < 0)
+goto fail;
  }
  
  fail:

LGTM

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


Re: [FFmpeg-devel] [PATCH 1/4] avformat/hlsenc: fix first fragment mp4 do not split bug

2017-12-18 Thread Karthick Jeyapal



On 12/18/17 2:17 PM, Steven Liu wrote:

fix ticket id: 6888

Signed-off-by: Steven Liu 
---
  libavformat/hlsenc.c | 72 
  1 file changed, 62 insertions(+), 10 deletions(-)

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index e3442c368f..f51fec1030 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -352,6 +352,29 @@ static void write_styp(AVIOContext *pb)
  ffio_wfourcc(pb, "msix");
  }
  
+static int flush_dynbuf(VariantStream *vs, int *range_length)

+{
+AVFormatContext *ctx = vs->avf;
+uint8_t *buffer;
+
+if (!ctx->pb) {
+return AVERROR(EINVAL);
+}
+
+// flush
+av_write_frame(ctx, NULL);
+avio_flush(ctx->pb);
+
+// write out to file
+*range_length = avio_close_dyn_buf(ctx->pb, );
+ctx->pb = NULL;
+avio_write(vs->out, buffer, *range_length);
+av_free(buffer);
+
+// re-open buffer
+return avio_open_dyn_buf(>pb);
+}
+
  static int hls_delete_old_segments(AVFormatContext *s, HLSContext *hls,
 VariantStream *vs) {
  
@@ -677,7 +700,9 @@ static int hls_mux_init(AVFormatContext *s, VariantStream *vs)

  if ((ret = avio_open_dyn_buf(>pb)) < 0)
  return ret;
  
-if ((ret = s->io_open(s, >out, vs->base_output_dirname, AVIO_FLAG_WRITE, )) < 0) {

+ret = hlsenc_io_open(s, >out, vs->base_output_dirname, );
+av_dict_free();
+if (ret < 0) {
  av_log(s, AV_LOG_ERROR, "Failed to open segment '%s'\n", 
vs->fmp4_init_filename);
  return ret;
  }
@@ -1404,9 +1429,10 @@ static int hls_start(AVFormatContext *s, VariantStream 
*vs)
  av_dict_free();
  if (err < 0)
  return err;
-} else
+} else if (c->segment_type != SEGMENT_TYPE_FMP4) {
  if ((err = hlsenc_io_open(s, >pb, oc->filename, )) < 0)
  goto fail;
+}
  if (vs->vtt_basename) {
  set_http_options(s, , c);
  if ((err = hlsenc_io_open(s, _oc->pb, vtt_oc->filename, )) 
< 0)
@@ -1414,9 +1440,7 @@ static int hls_start(AVFormatContext *s, VariantStream 
*vs)
  }
  av_dict_free();
  
-if (c->segment_type == SEGMENT_TYPE_FMP4 && !(c->flags & HLS_SINGLE_FILE)) {

-write_styp(oc->pb);
-} else {
+if (c->segment_type != SEGMENT_TYPE_FMP4) {
  /* We only require one PAT/PMT per segment. */
  if (oc->oformat->priv_class && oc->priv_data) {
  char period[21];
@@ -1780,7 +1804,8 @@ static int hls_write_packet(AVFormatContext *s, AVPacket 
*pkt)
  vs->size = new_start_pos - vs->start_pos;
  
  if (!byterange_mode) {

-if (hls->segment_type == SEGMENT_TYPE_FMP4 && 
!vs->init_range_length) {
+if (hls->segment_type == SEGMENT_TYPE_FMP4) {
+if (!vs->init_range_length) {
  avio_flush(oc->pb);
  range_length = avio_close_dyn_buf(oc->pb, );
  avio_write(vs->out, buffer, range_length);
@@ -1789,6 +1814,7 @@ static int hls_write_packet(AVFormatContext *s, AVPacket 
*pkt)
  vs->packets_written = 0;
  ff_format_io_close(s, >out);
  hlsenc_io_close(s, >out, vs->base_output_dirname);
+}
  } else {
  hlsenc_io_close(s, >pb, oc->filename);
  }
@@ -1807,7 +1833,20 @@ static int hls_write_packet(AVFormatContext *s, AVPacket 
*pkt)
  vs->number--;
  }
  
-if (!vs->fmp4_init_mode || byterange_mode)

+if (hls->segment_type == SEGMENT_TYPE_FMP4) {
+ret = hlsenc_io_open(s, >out, vs->avf->filename, NULL);
Will it be better if you call "set_http_options()" here itself, instead 
of a separate patch 4/4? In that way this patch would be self contained.

+if (ret < 0) {
+av_log(NULL, AV_LOG_ERROR, "Failed to open file '%s'\n",
+vs->avf->filename);
+return ret;
+}
+write_styp(vs->out);
+ret = flush_dynbuf(vs, _length);
+if (ret < 0) {
+return ret;
+}
+ff_format_io_close(s, >out);
Again is it better to call hlsenc_io_close() here itself instead of 
patch 3/4. Again just from self-containment perspective.

+}
  ret = hls_append_segment(s, hls, vs, vs->duration, vs->start_pos, 
vs->size);
  vs->start_pos = new_start_pos;
  if (ret < 0) {
@@ -1861,6 +1900,7 @@ static int hls_write_trailer(struct AVFormatContext *s)
  AVFormatContext *vtt_oc = NULL;
  char *old_filename = NULL;
  int i;
+int ret = 0;
  VariantStream *vs = NULL;
  
  for (i = 0; i < hls->nb_varstreams; i++) {

@@ -1873,11 +1913,25 @@ static int hls_write_trailer(struct AVFormatContext *s)
  if (!old_filename) {
  return AVERROR(ENOMEM);
  }
-
+if ( 

Re: [FFmpeg-devel] [PATCH 2/2] avformat/dashenc: Persistent HTTP connections supported as an option

2017-12-16 Thread Karthick Jeyapal



On 12/15/17 9:36 PM, Karthick J wrote:

From: Karthick Jeyapal <kjeya...@akamai.com>

---
  libavformat/dashenc.c | 67 +--
  1 file changed, 54 insertions(+), 13 deletions(-)

diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c
index 5687530..e7d1a0d 100644
--- a/libavformat/dashenc.c
+++ b/libavformat/dashenc.c
@@ -37,6 +37,9 @@
  #include "avformat.h"
  #include "avio_internal.h"
  #include "hlsplaylist.h"
+#if CONFIG_HTTP_PROTOCOL
+#include "http.h"
+#endif
  #include "internal.h"
  #include "isom.h"
  #include "os_support.h"
@@ -103,7 +106,10 @@ typedef struct DASHContext {
  const char *utc_timing_url;
  const char *user_agent;
  int hls_playlist;
+int http_persistent;
  int master_playlist_created;
+AVIOContext *mpd_out;
+AVIOContext *m3u8_out;
  } DASHContext;
  
  static struct codec_string {

@@ -117,6 +123,36 @@ static struct codec_string {
  { 0, NULL }
  };
  
+static int dashenc_io_open(AVFormatContext *s, AVIOContext **pb, char *filename,

+   AVDictionary **options) {
+DASHContext *c = s->priv_data;
+int http_base_proto = filename ? ff_is_http_proto(filename) : 0;
+int err = AVERROR_MUXER_NOT_FOUND;
+if (!*pb || !http_base_proto || !c->http_persistent) {
+err = s->io_open(s, pb, filename, AVIO_FLAG_WRITE, options);
+#if CONFIG_HTTP_PROTOCOL
+} else {
+URLContext *http_url_context = ffio_geturlcontext(*pb);
+av_assert0(http_url_context);
+err = ff_http_do_new_request(http_url_context, filename);
+#endif
+}
+return err;
+}
+
+static void dashenc_io_close(AVFormatContext *s, AVIOContext **pb, char 
*filename) {
+DASHContext *c = s->priv_data;
+int http_base_proto = filename ? ff_is_http_proto(filename) : 0;
+
+if (!http_base_proto || !c->http_persistent) {
+ff_format_io_close(s, pb);
+#if CONFIG_HTTP_PROTOCOL
+} else {
+avio_flush(*pb);
+#endif
+}
+}
+
  static void set_codec_str(AVFormatContext *s, AVCodecParameters *par,
char *str, int size)
  {
@@ -218,6 +254,8 @@ static void set_http_options(AVDictionary **options, 
DASHContext *c)
  {
  if (c->user_agent)
  av_dict_set(options, "user_agent", c->user_agent, 0);
+if (c->http_persistent)
+av_dict_set_int(options, "multiple_requests", 1, 0);
  }
  
  static void get_hls_playlist_name(char *playlist_name, int string_size,

@@ -273,9 +311,10 @@ static void dash_free(AVFormatContext *s)
  av_freep(>streams);
  }
  
-static void output_segment_list(OutputStream *os, AVIOContext *out, DASHContext *c,

+static void output_segment_list(OutputStream *os, AVIOContext *out, 
AVFormatContext *s,
  int representation_id, int final)
  {
+DASHContext *c = s->priv_data;
  int i, start_index = 0, start_number = 1;
  if (c->window_size) {
  start_index  = FFMAX(os->nb_segments   - c->window_size, 0);
@@ -339,7 +378,6 @@ static void output_segment_list(OutputStream *os, 
AVIOContext *out, DASHContext
  int timescale = os->ctx->streams[0]->time_base.den;
  char temp_filename_hls[1024];
  char filename_hls[1024];
-AVIOContext *out_hls = NULL;
  AVDictionary *http_opts = NULL;
  int target_duration = 0;
  int ret = 0;
@@ -352,7 +390,7 @@ static void output_segment_list(OutputStream *os, 
AVIOContext *out, DASHContext
  snprintf(temp_filename_hls, sizeof(temp_filename_hls), use_rename ? "%s.tmp" : 
"%s", filename_hls);
  
  set_http_options(_opts, c);

-avio_open2(_hls, temp_filename_hls, AVIO_FLAG_WRITE, NULL, 
_opts);
+dashenc_io_open(s, >m3u8_out, temp_filename_hls, _opts);
  av_dict_free(_opts);
  for (i = start_index; i < os->nb_segments; i++) {
  Segment *seg = os->segments[i];
@@ -361,15 +399,15 @@ static void output_segment_list(OutputStream *os, 
AVIOContext *out, DASHContext
  target_duration = hls_get_int_from_double(duration);
  }
  
-ff_hls_write_playlist_header(out_hls, 6, -1, target_duration,

+ff_hls_write_playlist_header(c->m3u8_out, 6, -1, target_duration,
   start_number, PLAYLIST_TYPE_NONE);
  
-ff_hls_write_init_file(out_hls, os->initfile, c->single_file,

+ff_hls_write_init_file(c->m3u8_out, os->initfile, c->single_file,
 os->init_range_length, os->init_start_pos);
  
  for (i = start_index; i < os->nb_segments; i++) {

  Segment *seg = os->segments[i];
-ret = ff_hls_write_file_entry(out_hls, 0, c->single_file,
+ret 

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 Karthick Jeyapal


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

On 14 Dec 2017, at 16:07, Karthick Jeyapal <kjeya...@akamai.com> wrote:




On Nov 30, 2017, at 2:36 PM, Karthick J <kjeya...@akamai.com> wrote:


From: Karthick Jeyapal <kjeya...@akamai.com>


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

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 <kjeya...@akamai.com> wrote:
> 
> 
> From: Karthick Jeyapal <kjeya...@akamai.com>
> 
> 
> 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\"&qu