diff mbox

[FFmpeg-devel,1/1] Prevent writing manifest files multiple times

Message ID 20190326203818.15055-2-joep@exmachina.nl
State New
Headers show

Commit Message

joepadmiraal March 26, 2019, 8:38 p.m. UTC
---
 libavformat/dashenc.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

Comments

Diego Felix de Souza via ffmpeg-devel April 2, 2019, 6:01 a.m. UTC | #1
On 3/27/19 2:08 AM, joepadmiraal wrote:
> ---

>  libavformat/dashenc.c | 17 ++++++++++++++++-

>  1 file changed, 16 insertions(+), 1 deletion(-)

Sorry for the delayed reply. Thanks for submitting a patch for a very useful optimization. Here are my review comments.

Please add a prefix "libavformat/dashenc : " to the subject line(First line of commit message). 
>

> diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c

> index 1b74bce060..e4f7843e03 100644

> --- a/libavformat/dashenc.c

> +++ b/libavformat/dashenc.c

> @@ -144,6 +144,8 @@ typedef struct DASHContext {

>      int ignore_io_errors;

>      int lhls;

>      int master_publish_rate;

> +    int nr_of_streams_to_flush;

> +    int nr_of_streams_flushed;

>  } DASHContext;

>  

>  static struct codec_string {

> @@ -1079,6 +1081,7 @@ static int dash_init(AVFormatContext *s)

>      char *ptr;

>      char basename[1024];

>  

> +    c->nr_of_streams_to_flush = 0;

>      if (c->single_file_name)

>          c->single_file = 1;

>      if (c->single_file)

> @@ -1274,12 +1277,18 @@ static int dash_init(AVFormatContext *s)

>          os->max_pts = AV_NOPTS_VALUE;

>          os->last_dts = AV_NOPTS_VALUE;

>          os->segment_index = 1;

> +

> +        if (s->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)

> +            c->nr_of_streams_to_flush++;

>      }

>  

>      if (!c->has_video && c->seg_duration <= 0) {

>          av_log(s, AV_LOG_WARNING, "no video stream and no seg duration set\n");

>          return AVERROR(EINVAL);

>      }

> +

> +    c->nr_of_streams_flushed = 0;

> +

>      return 0;

>  }

>  

> @@ -1565,8 +1574,14 @@ static int dash_flush(AVFormatContext *s, int final, int stream)

>          }

>      }

>  

> -    if (ret >= 0)

> +    if (ret >= 0) {

> +        c->nr_of_streams_flushed++;

> +        if (c->nr_of_streams_flushed != c->nr_of_streams_to_flush)

> +            return ret;

This seems to break support for the case c->has_video is false(audio-only). For that case c->nr_of_streams_to_flush will be 0 and will always satisfy the "if" condition here. Hence manifest will never get written for audio-only use-case.
> +

> +        c->nr_of_streams_flushed = 0;

>          ret = write_manifest(s, final);

> +    }

>      return ret;

>  }

>
diff mbox

Patch

diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c
index 1b74bce060..e4f7843e03 100644
--- a/libavformat/dashenc.c
+++ b/libavformat/dashenc.c
@@ -144,6 +144,8 @@  typedef struct DASHContext {
     int ignore_io_errors;
     int lhls;
     int master_publish_rate;
+    int nr_of_streams_to_flush;
+    int nr_of_streams_flushed;
 } DASHContext;
 
 static struct codec_string {
@@ -1079,6 +1081,7 @@  static int dash_init(AVFormatContext *s)
     char *ptr;
     char basename[1024];
 
+    c->nr_of_streams_to_flush = 0;
     if (c->single_file_name)
         c->single_file = 1;
     if (c->single_file)
@@ -1274,12 +1277,18 @@  static int dash_init(AVFormatContext *s)
         os->max_pts = AV_NOPTS_VALUE;
         os->last_dts = AV_NOPTS_VALUE;
         os->segment_index = 1;
+
+        if (s->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)
+            c->nr_of_streams_to_flush++;
     }
 
     if (!c->has_video && c->seg_duration <= 0) {
         av_log(s, AV_LOG_WARNING, "no video stream and no seg duration set\n");
         return AVERROR(EINVAL);
     }
+
+    c->nr_of_streams_flushed = 0;
+
     return 0;
 }
 
@@ -1565,8 +1574,14 @@  static int dash_flush(AVFormatContext *s, int final, int stream)
         }
     }
 
-    if (ret >= 0)
+    if (ret >= 0) {
+        c->nr_of_streams_flushed++;
+        if (c->nr_of_streams_flushed != c->nr_of_streams_to_flush)
+            return ret;
+
+        c->nr_of_streams_flushed = 0;
         ret = write_manifest(s, final);
+    }
     return ret;
 }