diff mbox series

[FFmpeg-devel,1/3] avformat/fifo: add option to delay output

Message ID 1588166700-76420-1-git-send-email-leozhang@qiyi.com
State New
Headers show
Series Patch set to delay output live stream | expand

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

leozhang April 29, 2020, 1:25 p.m. UTC
Signed-off-by: leozhang <leozhang@qiyi.com>
---
 doc/muxers.texi    | 3 +++
 libavformat/fifo.c | 7 +++++++
 2 files changed, 10 insertions(+)

Comments

Nicolas George April 29, 2020, 1:31 p.m. UTC | #1
leozhang (12020-04-29):
> Signed-off-by: leozhang <leozhang@qiyi.com>
> ---
>  doc/muxers.texi    | 3 +++
>  libavformat/fifo.c | 7 +++++++
>  2 files changed, 10 insertions(+)
> 
> diff --git a/doc/muxers.texi b/doc/muxers.texi
> index cb2bb42..a74cbc4 100644
> --- a/doc/muxers.texi
> +++ b/doc/muxers.texi
> @@ -2271,6 +2271,9 @@ certain (usually permanent) errors the recovery is not attempted even when
>  Specify whether to wait for the keyframe after recovering from
>  queue overflow or failure. This option is set to 0 (false) by default.
>  

> +@item output_delay
> +Time to delay output, in microseconds. Default value is 0.

This is not accurate enough. This will block every output packet for the
extra specified duration.

Not sure if it is very useful, compared with the other patch.

> +
>  @end table
>  
>  @subsection Examples
> diff --git a/libavformat/fifo.c b/libavformat/fifo.c
> index d11dc66..bdecf2d 100644
> --- a/libavformat/fifo.c
> +++ b/libavformat/fifo.c
> @@ -77,6 +77,8 @@ typedef struct FifoContext {
>      /* Value > 0 signals queue overflow */
>      volatile uint8_t overflow_flag;
>  
> +    /* Time to delay output, in microseconds */
> +    uint64_t output_delay;
>  } FifoContext;
>  
>  typedef struct FifoThreadContext {
> @@ -397,6 +399,8 @@ static void *fifo_consumer_thread(void *data)
>      memset(&fifo_thread_ctx, 0, sizeof(FifoThreadContext));
>      fifo_thread_ctx.avf = avf;
>  
> +    av_usleep(fifo->output_delay);
> +
>      while (1) {
>          uint8_t just_flushed = 0;
>  
> @@ -630,6 +634,9 @@ static const AVOption options[] = {
>          {"recover_any_error", "Attempt recovery regardless of type of the error", OFFSET(recover_any_error),
>           AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, AV_OPT_FLAG_ENCODING_PARAM},
>  

> +        {"output_delay", "Time to delay output, in microseconds", OFFSET(output_delay),
> +         AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM},

AV_OPT_TYPE_DURATION and adapt the description and documentation.

> +
>          {NULL},
>  };
>  

Regards,
leozhang April 30, 2020, 3:48 a.m. UTC | #2
Nicolas George <george@nsup.org> 于2020年4月29日周三 下午9:31写道:
>
> leozhang (12020-04-29):
> > Signed-off-by: leozhang <leozhang@qiyi.com>
> > ---
> >  doc/muxers.texi    | 3 +++
> >  libavformat/fifo.c | 7 +++++++
> >  2 files changed, 10 insertions(+)
> >
> > diff --git a/doc/muxers.texi b/doc/muxers.texi
> > index cb2bb42..a74cbc4 100644
> > --- a/doc/muxers.texi
> > +++ b/doc/muxers.texi
> > @@ -2271,6 +2271,9 @@ certain (usually permanent) errors the recovery is not attempted even when
> >  Specify whether to wait for the keyframe after recovering from
> >  queue overflow or failure. This option is set to 0 (false) by default.
> >
>
> > +@item output_delay
> > +Time to delay output, in microseconds. Default value is 0.
>
> This is not accurate enough. This will block every output packet for the
> extra specified duration.
>
> Not sure if it is very useful, compared with the other patch.
In live streaming applications, if user wouldn't want broadcast what's
coming next immediately, can set wanted output delay.
>
> > +
> >  @end table
> >
> >  @subsection Examples
> > diff --git a/libavformat/fifo.c b/libavformat/fifo.c
> > index d11dc66..bdecf2d 100644
> > --- a/libavformat/fifo.c
> > +++ b/libavformat/fifo.c
> > @@ -77,6 +77,8 @@ typedef struct FifoContext {
> >      /* Value > 0 signals queue overflow */
> >      volatile uint8_t overflow_flag;
> >
> > +    /* Time to delay output, in microseconds */
> > +    uint64_t output_delay;
> >  } FifoContext;
> >
> >  typedef struct FifoThreadContext {
> > @@ -397,6 +399,8 @@ static void *fifo_consumer_thread(void *data)
> >      memset(&fifo_thread_ctx, 0, sizeof(FifoThreadContext));
> >      fifo_thread_ctx.avf = avf;
> >
> > +    av_usleep(fifo->output_delay);
> > +
> >      while (1) {
> >          uint8_t just_flushed = 0;
> >
> > @@ -630,6 +634,9 @@ static const AVOption options[] = {
> >          {"recover_any_error", "Attempt recovery regardless of type of the error", OFFSET(recover_any_error),
> >           AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, AV_OPT_FLAG_ENCODING_PARAM},
> >
>
> > +        {"output_delay", "Time to delay output, in microseconds", OFFSET(output_delay),
> > +         AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM},
>
> AV_OPT_TYPE_DURATION and adapt the description and documentation.
Will fix it in v2 version. Thanks.
>
> > +
> >          {NULL},
> >  };
> >
>
> Regards,
>
> --
>   Nicolas George
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
diff mbox series

Patch

diff --git a/doc/muxers.texi b/doc/muxers.texi
index cb2bb42..a74cbc4 100644
--- a/doc/muxers.texi
+++ b/doc/muxers.texi
@@ -2271,6 +2271,9 @@  certain (usually permanent) errors the recovery is not attempted even when
 Specify whether to wait for the keyframe after recovering from
 queue overflow or failure. This option is set to 0 (false) by default.
 
+@item output_delay
+Time to delay output, in microseconds. Default value is 0.
+
 @end table
 
 @subsection Examples
diff --git a/libavformat/fifo.c b/libavformat/fifo.c
index d11dc66..bdecf2d 100644
--- a/libavformat/fifo.c
+++ b/libavformat/fifo.c
@@ -77,6 +77,8 @@  typedef struct FifoContext {
     /* Value > 0 signals queue overflow */
     volatile uint8_t overflow_flag;
 
+    /* Time to delay output, in microseconds */
+    uint64_t output_delay;
 } FifoContext;
 
 typedef struct FifoThreadContext {
@@ -397,6 +399,8 @@  static void *fifo_consumer_thread(void *data)
     memset(&fifo_thread_ctx, 0, sizeof(FifoThreadContext));
     fifo_thread_ctx.avf = avf;
 
+    av_usleep(fifo->output_delay);
+
     while (1) {
         uint8_t just_flushed = 0;
 
@@ -630,6 +634,9 @@  static const AVOption options[] = {
         {"recover_any_error", "Attempt recovery regardless of type of the error", OFFSET(recover_any_error),
          AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, AV_OPT_FLAG_ENCODING_PARAM},
 
+        {"output_delay", "Time to delay output, in microseconds", OFFSET(output_delay),
+         AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM},
+
         {NULL},
 };