diff mbox

[FFmpeg-devel] avformat/hlsenc: fix bug of hlsenc http delete old segments

Message ID 20170117062825.8757-1-lq@chinaffmpeg.org
State Accepted
Commit b05d0274ce7dca3d9b3efd9258b46c7a898f04a9
Headers show

Commit Message

Liu Steven Jan. 17, 2017, 6:28 a.m. UTC
when push hls to http server, the old segemnts can not delete by hls formats.
so add the http option into hls_delete_old_segments

Reported-by: Yin Jiaoyuan <yinjiaoyuan@163.com>
Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
---
 libavformat/hlsenc.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

Comments

Steven Liu Jan. 18, 2017, 11:08 p.m. UTC | #1
2017-01-17 14:28 GMT+08:00 Steven Liu <lq@chinaffmpeg.org>:

> when push hls to http server, the old segemnts can not delete by hls
> formats.
> so add the http option into hls_delete_old_segments
>
> Reported-by: Yin Jiaoyuan <yinjiaoyuan@163.com>
> Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
> ---
>  libavformat/hlsenc.c | 17 +++++++++++++++--
>  1 file changed, 15 insertions(+), 2 deletions(-)
>
> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> index f02b887..87f7717 100644
> --- a/libavformat/hlsenc.c
> +++ b/libavformat/hlsenc.c
> @@ -245,6 +245,8 @@ static int hls_delete_old_segments(HLSContext *hls) {
>      int ret = 0, path_size, sub_path_size;
>      char *dirname = NULL, *p, *sub_path;
>      char *path = NULL;
> +    AVDictionary *options = NULL;
> +    AVIOContext *out = NULL;
>
>      segment = hls->segments;
>      while (segment) {
> @@ -294,7 +296,11 @@ static int hls_delete_old_segments(HLSContext *hls) {
>              av_strlcat(path, segment->filename, path_size);
>          }
>
> -        if (unlink(path) < 0) {
> +        if (hls->method) {
> +            av_dict_set(&options, "method", "DELETE", 0);
> +            if ((ret = hls->avf->io_open(hls->avf, &out, path,
> AVIO_FLAG_WRITE, &options)) < 0)
> +                goto fail;
> +        } else if (unlink(path) < 0) {
>              av_log(hls, AV_LOG_ERROR, "failed to delete old segment %s:
> %s\n",
>                                       path, strerror(errno));
>          }
> @@ -309,7 +315,14 @@ static int hls_delete_old_segments(HLSContext *hls) {
>
>              av_strlcpy(sub_path, dirname, sub_path_size);
>              av_strlcat(sub_path, segment->sub_filename, sub_path_size);
> -            if (unlink(sub_path) < 0) {
> +
> +            if (hls->method) {
> +                av_dict_set(&options, "method", "DELETE", 0);
> +                if ((ret = hls->avf->io_open(hls->avf, &out, sub_path,
> AVIO_FLAG_WRITE, &options)) < 0) {
> +                    av_free(sub_path);
> +                    goto fail;
> +                }
> +            } else if (unlink(sub_path) < 0) {
>                  av_log(hls, AV_LOG_ERROR, "failed to delete old segment
> %s: %s\n",
>                                           sub_path, strerror(errno));
>              }
> --
> 2.10.1.382.ga23ca1b.dirty
>
>
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


applied!


Thanks
殷焦元 Jan. 19, 2017, 1:35 a.m. UTC | #2
I test this patch, I found it show below log info and ffmpeg term auto.

av_interleaved_write_frame(): Too many open files
No more output streams to write to, finishing.

I think it is not OK.
Yin Jiaoyuan




At 2017-01-19 07:08:08, "Steven Liu" <lingjiujianke@gmail.com> wrote:
>2017-01-17 14:28 GMT+08:00 Steven Liu <lq@chinaffmpeg.org>:
>
>> when push hls to http server, the old segemnts can not delete by hls
>> formats.
>> so add the http option into hls_delete_old_segments
>>
>> Reported-by: Yin Jiaoyuan <yinjiaoyuan@163.com>
>> Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
>> ---
>>  libavformat/hlsenc.c | 17 +++++++++++++++--
>>  1 file changed, 15 insertions(+), 2 deletions(-)
>>
>> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
>> index f02b887..87f7717 100644
>> --- a/libavformat/hlsenc.c
>> +++ b/libavformat/hlsenc.c
>> @@ -245,6 +245,8 @@ static int hls_delete_old_segments(HLSContext *hls) {
>>      int ret = 0, path_size, sub_path_size;
>>      char *dirname = NULL, *p, *sub_path;
>>      char *path = NULL;
>> +    AVDictionary *options = NULL;
>> +    AVIOContext *out = NULL;
>>
>>      segment = hls->segments;
>>      while (segment) {
>> @@ -294,7 +296,11 @@ static int hls_delete_old_segments(HLSContext *hls) {
>>              av_strlcat(path, segment->filename, path_size);
>>          }
>>
>> -        if (unlink(path) < 0) {
>> +        if (hls->method) {
>> +            av_dict_set(&options, "method", "DELETE", 0);
>> +            if ((ret = hls->avf->io_open(hls->avf, &out, path,
>> AVIO_FLAG_WRITE, &options)) < 0)
>> +                goto fail;
>> +        } else if (unlink(path) < 0) {
>>              av_log(hls, AV_LOG_ERROR, "failed to delete old segment %s:
>> %s\n",
>>                                       path, strerror(errno));
>>          }
>> @@ -309,7 +315,14 @@ static int hls_delete_old_segments(HLSContext *hls) {
>>
>>              av_strlcpy(sub_path, dirname, sub_path_size);
>>              av_strlcat(sub_path, segment->sub_filename, sub_path_size);
>> -            if (unlink(sub_path) < 0) {
>> +
>> +            if (hls->method) {
>> +                av_dict_set(&options, "method", "DELETE", 0);
>> +                if ((ret = hls->avf->io_open(hls->avf, &out, sub_path,
>> AVIO_FLAG_WRITE, &options)) < 0) {
>> +                    av_free(sub_path);
>> +                    goto fail;
>> +                }
>> +            } else if (unlink(sub_path) < 0) {
>>                  av_log(hls, AV_LOG_ERROR, "failed to delete old segment
>> %s: %s\n",
>>                                           sub_path, strerror(errno));
>>              }
>> --
>> 2.10.1.382.ga23ca1b.dirty
>>
>>
>>
>> _______________________________________________
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
>
>applied!
>
>
>Thanks
>_______________________________________________
>ffmpeg-devel mailing list
>ffmpeg-devel@ffmpeg.org
>http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Steven Liu Jan. 19, 2017, 1:56 a.m. UTC | #3
2017-01-19 9:35 GMT+08:00 殷焦元 <yinjiaoyuan@163.com>:

> I test this patch, I found it show below log info and ffmpeg term auto.
>
> av_interleaved_write_frame(): Too many open files
> No more output streams to write to, finishing.
>
> I think it is not OK.
> Yin Jiaoyuan
>

ok , i wll make a new patch to file the too many open files

>
>
>
>
> At 2017-01-19 07:08:08, "Steven Liu" <lingjiujianke@gmail.com> wrote:
> >2017-01-17 14:28 GMT+08:00 Steven Liu <lq@chinaffmpeg.org>:
> >
> >> when push hls to http server, the old segemnts can not delete by hls
> >> formats.
> >> so add the http option into hls_delete_old_segments
> >>
> >> Reported-by: Yin Jiaoyuan <yinjiaoyuan@163.com>
> >> Signed-off-by: Steven Liu <lq@chinaffmpeg.org>
> >> ---
> >>  libavformat/hlsenc.c | 17 +++++++++++++++--
> >>  1 file changed, 15 insertions(+), 2 deletions(-)
> >>
> >> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
> >> index f02b887..87f7717 100644
> >> --- a/libavformat/hlsenc.c
> >> +++ b/libavformat/hlsenc.c
> >> @@ -245,6 +245,8 @@ static int hls_delete_old_segments(HLSContext
> *hls) {
> >>      int ret = 0, path_size, sub_path_size;
> >>      char *dirname = NULL, *p, *sub_path;
> >>      char *path = NULL;
> >> +    AVDictionary *options = NULL;
> >> +    AVIOContext *out = NULL;
> >>
> >>      segment = hls->segments;
> >>      while (segment) {
> >> @@ -294,7 +296,11 @@ static int hls_delete_old_segments(HLSContext
> *hls) {
> >>              av_strlcat(path, segment->filename, path_size);
> >>          }
> >>
> >> -        if (unlink(path) < 0) {
> >> +        if (hls->method) {
> >> +            av_dict_set(&options, "method", "DELETE", 0);
> >> +            if ((ret = hls->avf->io_open(hls->avf, &out, path,
> >> AVIO_FLAG_WRITE, &options)) < 0)
> >> +                goto fail;
> >> +        } else if (unlink(path) < 0) {
> >>              av_log(hls, AV_LOG_ERROR, "failed to delete old segment %s:
> >> %s\n",
> >>                                       path, strerror(errno));
> >>          }
> >> @@ -309,7 +315,14 @@ static int hls_delete_old_segments(HLSContext
> *hls) {
> >>
> >>              av_strlcpy(sub_path, dirname, sub_path_size);
> >>              av_strlcat(sub_path, segment->sub_filename, sub_path_size);
> >> -            if (unlink(sub_path) < 0) {
> >> +
> >> +            if (hls->method) {
> >> +                av_dict_set(&options, "method", "DELETE", 0);
> >> +                if ((ret = hls->avf->io_open(hls->avf, &out, sub_path,
> >> AVIO_FLAG_WRITE, &options)) < 0) {
> >> +                    av_free(sub_path);
> >> +                    goto fail;
> >> +                }
> >> +            } else if (unlink(sub_path) < 0) {
> >>                  av_log(hls, AV_LOG_ERROR, "failed to delete old segment
> >> %s: %s\n",
> >>                                           sub_path, strerror(errno));
> >>              }
> >> --
> >> 2.10.1.382.ga23ca1b.dirty
> >>
> >>
> >>
> >> _______________________________________________
> >> ffmpeg-devel mailing list
> >> ffmpeg-devel@ffmpeg.org
> >> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >
> >
> >applied!
> >
> >
> >Thanks
> >_______________________________________________
> >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
>
diff mbox

Patch

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index f02b887..87f7717 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -245,6 +245,8 @@  static int hls_delete_old_segments(HLSContext *hls) {
     int ret = 0, path_size, sub_path_size;
     char *dirname = NULL, *p, *sub_path;
     char *path = NULL;
+    AVDictionary *options = NULL;
+    AVIOContext *out = NULL;
 
     segment = hls->segments;
     while (segment) {
@@ -294,7 +296,11 @@  static int hls_delete_old_segments(HLSContext *hls) {
             av_strlcat(path, segment->filename, path_size);
         }
 
-        if (unlink(path) < 0) {
+        if (hls->method) {
+            av_dict_set(&options, "method", "DELETE", 0);
+            if ((ret = hls->avf->io_open(hls->avf, &out, path, AVIO_FLAG_WRITE, &options)) < 0)
+                goto fail;
+        } else if (unlink(path) < 0) {
             av_log(hls, AV_LOG_ERROR, "failed to delete old segment %s: %s\n",
                                      path, strerror(errno));
         }
@@ -309,7 +315,14 @@  static int hls_delete_old_segments(HLSContext *hls) {
 
             av_strlcpy(sub_path, dirname, sub_path_size);
             av_strlcat(sub_path, segment->sub_filename, sub_path_size);
-            if (unlink(sub_path) < 0) {
+
+            if (hls->method) {
+                av_dict_set(&options, "method", "DELETE", 0);
+                if ((ret = hls->avf->io_open(hls->avf, &out, sub_path, AVIO_FLAG_WRITE, &options)) < 0) {
+                    av_free(sub_path);
+                    goto fail;
+                }
+            } else if (unlink(sub_path) < 0) {
                 av_log(hls, AV_LOG_ERROR, "failed to delete old segment %s: %s\n",
                                          sub_path, strerror(errno));
             }