Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH] libRIST: allow setting fifo size and fail on overflow.
@ 2022-01-11  9:23 Gijs Peskens
  2022-01-11  9:43 ` "zhilizhao(赵志立)"
  2022-01-11 10:34 ` Gijs Peskens
  0 siblings, 2 replies; 10+ messages in thread
From: Gijs Peskens @ 2022-01-11  9:23 UTC (permalink / raw)
  To: ffmpeg-devel

Introduce fifo_size and overrun_nonfatal params to configure fifo buffer
behavior.

Use newly introduced RIST_DATA_FLAGS_OVERFLOW flag to check for overrun
and error out in that case.
---
 doc/protocols.texi    |  9 +++++++++
 libavformat/librist.c | 40 +++++++++++++++++++++++++++++++++++++++-
 2 files changed, 48 insertions(+), 1 deletion(-)

diff --git a/doc/protocols.texi b/doc/protocols.texi
index d207df0b52..f1acf0cc77 100644
--- a/doc/protocols.texi
+++ b/doc/protocols.texi
@@ -745,6 +745,15 @@ Set internal RIST buffer size in milliseconds for retransmission of data.
 Default value is 0 which means the librist default (1 sec). Maximum value is 30
 seconds.
 
+@item fifo_size
+Size of the librist receiver output fifo in number of packets. This must be a 
+power of 2.
+Defaults to 8192 (vs the libRIST default of 1024).
+
+@item overrun_nonfatal=@var{1|0}
+Survive in case of libRIST fifo buffer overrun. Default
+value is 0.
+
 @item pkt_size
 Set maximum packet size for sending data. 1316 by default.
 
diff --git a/libavformat/librist.c b/libavformat/librist.c
index 378b635ea7..83bbf9f07a 100644
--- a/libavformat/librist.c
+++ b/libavformat/librist.c
@@ -43,6 +43,9 @@
     ((patch) + ((minor)* 0x100) + ((major) *0x10000))
 #define FF_LIBRIST_VERSION FF_LIBRIST_MAKE_VERSION(LIBRIST_API_VERSION_MAJOR, LIBRIST_API_VERSION_MINOR, LIBRIST_API_VERSION_PATCH)
 #define FF_LIBRIST_VERSION_41 FF_LIBRIST_MAKE_VERSION(4, 1, 0)
+#define FF_LIBRIST_VERSION_42 FF_LIBRIST_MAKE_VERSION(4, 2, 0)
+
+#define FF_LIBRIST_FIFO_SIZE_DEFAULT (2 << 12)//8192
 
 typedef struct RISTContext {
     const AVClass *class;
@@ -52,6 +55,8 @@ typedef struct RISTContext {
     int packet_size;
     int log_level;
     int encryption;
+    int fifo_size;
+    bool overrun_nonfatal;
     char *secret;
 
     struct rist_logging_settings logging_settings;
@@ -70,6 +75,8 @@ static const AVOption librist_options[] = {
     { "main",        NULL,              0,                   AV_OPT_TYPE_CONST, {.i64=RIST_PROFILE_MAIN},     0, 0, .flags = D|E, "profile" },
     { "advanced",    NULL,              0,                   AV_OPT_TYPE_CONST, {.i64=RIST_PROFILE_ADVANCED}, 0, 0, .flags = D|E, "profile" },
     { "buffer_size", "set buffer_size in ms", OFFSET(buffer_size), AV_OPT_TYPE_INT, {.i64=0},                 0, 30000, .flags = D|E },
+    { "fifo_size", "Set libRIST fifo buffer. Size must be power of 2", OFFSET(fifo_size), AV_OPT_TYPE_INT, {.i64=FF_LIBRIST_FIFO_SIZE_DEFAULT}, 2 << 9, 2 << 15, .flags = D|E },
+    { "overrun_nonfatal", "survive in case of libRIST receiving circular buffer overrun", OFFSET(overrun_nonfatal), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1,    D },
     { "pkt_size",    "set packet size", OFFSET(packet_size), AV_OPT_TYPE_INT,   {.i64=1316},                  1, MAX_PAYLOAD_SIZE,    .flags = D|E },
     { "log_level",   "set loglevel",    OFFSET(log_level),   AV_OPT_TYPE_INT,   {.i64=RIST_LOG_INFO},        -1, INT_MAX, .flags = D|E },
     { "secret", "set encryption secret",OFFSET(secret),      AV_OPT_TYPE_STRING,{.str=NULL},                  0, 0,       .flags = D|E },
@@ -90,7 +97,6 @@ static int risterr2ret(int err)
 static int log_cb(void *arg, enum rist_log_level log_level, const char *msg)
 {
     int level;
-
     switch (log_level) {
     case RIST_LOG_ERROR:    level = AV_LOG_ERROR;   break;
     case RIST_LOG_WARN:     level = AV_LOG_WARNING; break;
@@ -139,6 +145,7 @@ static int librist_open(URLContext *h, const char *uri, int flags)
         h->max_packet_size = s->packet_size;
         ret = rist_sender_create(&s->ctx, s->profile, 0, logging_settings);
     }
+
     if (ret < 0)
         goto err;
 
@@ -146,6 +153,7 @@ static int librist_open(URLContext *h, const char *uri, int flags)
         h->max_packet_size = MAX_PAYLOAD_SIZE;
         ret = rist_receiver_create(&s->ctx, s->profile, logging_settings);
     }
+
     if (ret < 0)
         goto err;
 
@@ -161,6 +169,20 @@ static int librist_open(URLContext *h, const char *uri, int flags)
     if (ret < 0)
         goto err;
 
+    //Prior to 4.2.0 there was a bug in libRIST which made this call always fail.
+#if FF_LIBRIST_VERSION >= FF_LIBRIST_VERSION_42
+    if (flags & AVIO_FLAG_READ) {
+        ret = rist_receiver_set_output_fifo_size(s->ctx, s->fifo_size);
+        if (ret != 0) {
+            goto err;
+        }
+    }
+#else 
+    if (s->fifo_size != FF_LIBRIST_FIFO_SIZE_DEFAULT) {
+        av_log(h, AV_LOG_ERROR, "libRIST prior to 0.2.7 has a bug which fails setting the fifo buffer size");
+    }
+#endif
+
     if (((s->encryption == 128 || s->encryption == 256) && !s->secret) ||
         ((peer_config->key_size == 128 || peer_config->key_size == 256) && !peer_config->secret[0])) {
         av_log(h, AV_LOG_ERROR, "secret is mandatory if encryption is enabled\n");
@@ -223,8 +245,24 @@ static int librist_read(URLContext *h, uint8_t *buf, int size)
         return AVERROR_EXTERNAL;
     }
 
+#if FF_LIBRIST_VERSION >= FF_LIBRIST_VERSION_42
+    if (data_block->flags & RIST_DATA_FLAGS_OVERFLOW == RIST_DATA_FLAGS_OVERFLOW) {
+        if (!s->overrun_nonfatal) {
+            av_log(h, AV_LOG_ERROR, "Fifo buffer overrun. "
+                    "To avoid, increase fifo_size URL option. "
+                    "To survive in such case, use overrun_nonfatal option\n");
+            size = AVERROR(EIO);
+            goto out_free;
+        } else {
+            av_log(h, AV_LOG_WARNING, "Fifo buffer buffer overrun. "
+                    "Surviving due to overrun_nonfatal option\n");
+        }
+    }
+#endif
+
     size = data_block->payload_len;
     memcpy(buf, data_block->payload, size);
+out_free:
 #if FF_LIBRIST_VERSION < FF_LIBRIST_VERSION_41
     rist_receiver_data_block_free((struct rist_data_block**)&data_block);
 #else
-- 
2.32.0

_______________________________________________
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".

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [FFmpeg-devel] [PATCH] libRIST: allow setting fifo size and fail on overflow.
  2022-01-11  9:23 [FFmpeg-devel] [PATCH] libRIST: allow setting fifo size and fail on overflow Gijs Peskens
@ 2022-01-11  9:43 ` "zhilizhao(赵志立)"
  2022-01-11  9:45   ` Gijs Peskens
  2022-01-11 10:34 ` Gijs Peskens
  1 sibling, 1 reply; 10+ messages in thread
From: "zhilizhao(赵志立)" @ 2022-01-11  9:43 UTC (permalink / raw)
  To: FFmpeg development discussions and patches



> On Jan 11, 2022, at 5:23 PM, Gijs Peskens <gijs@peskens.net> wrote:
> 
> Introduce fifo_size and overrun_nonfatal params to configure fifo buffer
> behavior.
> 
> Use newly introduced RIST_DATA_FLAGS_OVERFLOW flag to check for overrun
> and error out in that case.
> ---
> doc/protocols.texi    |  9 +++++++++
> libavformat/librist.c | 40 +++++++++++++++++++++++++++++++++++++++-
> 2 files changed, 48 insertions(+), 1 deletion(-)
> 
> diff --git a/doc/protocols.texi b/doc/protocols.texi
> index d207df0b52..f1acf0cc77 100644
> --- a/doc/protocols.texi
> +++ b/doc/protocols.texi
> @@ -745,6 +745,15 @@ Set internal RIST buffer size in milliseconds for retransmission of data.
> Default value is 0 which means the librist default (1 sec). Maximum value is 30
> seconds.
> 
> +@item fifo_size
> +Size of the librist receiver output fifo in number of packets. This must be a 
> +power of 2.
> +Defaults to 8192 (vs the libRIST default of 1024).
> +
> +@item overrun_nonfatal=@var{1|0}
> +Survive in case of libRIST fifo buffer overrun. Default
> +value is 0.
> +
> @item pkt_size
> Set maximum packet size for sending data. 1316 by default.
> 
> diff --git a/libavformat/librist.c b/libavformat/librist.c
> index 378b635ea7..83bbf9f07a 100644
> --- a/libavformat/librist.c
> +++ b/libavformat/librist.c
> @@ -43,6 +43,9 @@
>     ((patch) + ((minor)* 0x100) + ((major) *0x10000))
> #define FF_LIBRIST_VERSION FF_LIBRIST_MAKE_VERSION(LIBRIST_API_VERSION_MAJOR, LIBRIST_API_VERSION_MINOR, LIBRIST_API_VERSION_PATCH)
> #define FF_LIBRIST_VERSION_41 FF_LIBRIST_MAKE_VERSION(4, 1, 0)
> +#define FF_LIBRIST_VERSION_42 FF_LIBRIST_MAKE_VERSION(4, 2, 0)
> +
> +#define FF_LIBRIST_FIFO_SIZE_DEFAULT (2 << 12)//8192

It’s not easy to read without space before ‘//8192’.
I prefer

#define FF_LIBRIST_FIFO_SIZE_DEFAULT 8192 

> 
> typedef struct RISTContext {
>     const AVClass *class;
> @@ -52,6 +55,8 @@ typedef struct RISTContext {
>     int packet_size;
>     int log_level;
>     int encryption;
> +    int fifo_size;
> +    bool overrun_nonfatal;

Should be ‘int’, please check opt.c.

>     char *secret;
> 
>     struct rist_logging_settings logging_settings;
> @@ -70,6 +75,8 @@ static const AVOption librist_options[] = {
>     { "main",        NULL,              0,                   AV_OPT_TYPE_CONST, {.i64=RIST_PROFILE_MAIN},     0, 0, .flags = D|E, "profile" },
>     { "advanced",    NULL,              0,                   AV_OPT_TYPE_CONST, {.i64=RIST_PROFILE_ADVANCED}, 0, 0, .flags = D|E, "profile" },
>     { "buffer_size", "set buffer_size in ms", OFFSET(buffer_size), AV_OPT_TYPE_INT, {.i64=0},                 0, 30000, .flags = D|E },
> +    { "fifo_size", "Set libRIST fifo buffer. Size must be power of 2", OFFSET(fifo_size), AV_OPT_TYPE_INT, {.i64=FF_LIBRIST_FIFO_SIZE_DEFAULT}, 2 << 9, 2 << 15, .flags = D|E },
> +    { "overrun_nonfatal", "survive in case of libRIST receiving circular buffer overrun", OFFSET(overrun_nonfatal), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1,    D },
>     { "pkt_size",    "set packet size", OFFSET(packet_size), AV_OPT_TYPE_INT,   {.i64=1316},                  1, MAX_PAYLOAD_SIZE,    .flags = D|E },
>     { "log_level",   "set loglevel",    OFFSET(log_level),   AV_OPT_TYPE_INT,   {.i64=RIST_LOG_INFO},        -1, INT_MAX, .flags = D|E },
>     { "secret", "set encryption secret",OFFSET(secret),      AV_OPT_TYPE_STRING,{.str=NULL},                  0, 0,       .flags = D|E },
> @@ -90,7 +97,6 @@ static int risterr2ret(int err)
> static int log_cb(void *arg, enum rist_log_level log_level, const char *msg)
> {
>     int level;
> -

Unrelated changes.

>     switch (log_level) {
>     case RIST_LOG_ERROR:    level = AV_LOG_ERROR;   break;
>     case RIST_LOG_WARN:     level = AV_LOG_WARNING; break;
> @@ -139,6 +145,7 @@ static int librist_open(URLContext *h, const char *uri, int flags)
>         h->max_packet_size = s->packet_size;
>         ret = rist_sender_create(&s->ctx, s->profile, 0, logging_settings);
>     }
> +
>     if (ret < 0)
>         goto err;
> 
> @@ -146,6 +153,7 @@ static int librist_open(URLContext *h, const char *uri, int flags)
>         h->max_packet_size = MAX_PAYLOAD_SIZE;
>         ret = rist_receiver_create(&s->ctx, s->profile, logging_settings);
>     }
> +
>     if (ret < 0)
>         goto err;
> 
> @@ -161,6 +169,20 @@ static int librist_open(URLContext *h, const char *uri, int flags)
>     if (ret < 0)
>         goto err;
> 
> +    //Prior to 4.2.0 there was a bug in libRIST which made this call always fail.
> +#if FF_LIBRIST_VERSION >= FF_LIBRIST_VERSION_42
> +    if (flags & AVIO_FLAG_READ) {
> +        ret = rist_receiver_set_output_fifo_size(s->ctx, s->fifo_size);
> +        if (ret != 0) {
> +            goto err;
> +        }
> +    }
> +#else 
> +    if (s->fifo_size != FF_LIBRIST_FIFO_SIZE_DEFAULT) {
> +        av_log(h, AV_LOG_ERROR, "libRIST prior to 0.2.7 has a bug which fails setting the fifo buffer size");

Missing newline at the end of log message.

> +    }
> +#endif
> +
>     if (((s->encryption == 128 || s->encryption == 256) && !s->secret) ||
>         ((peer_config->key_size == 128 || peer_config->key_size == 256) && !peer_config->secret[0])) {
>         av_log(h, AV_LOG_ERROR, "secret is mandatory if encryption is enabled\n");
> @@ -223,8 +245,24 @@ static int librist_read(URLContext *h, uint8_t *buf, int size)
>         return AVERROR_EXTERNAL;
>     }
> 
> +#if FF_LIBRIST_VERSION >= FF_LIBRIST_VERSION_42
> +    if (data_block->flags & RIST_DATA_FLAGS_OVERFLOW == RIST_DATA_FLAGS_OVERFLOW) {
> +        if (!s->overrun_nonfatal) {
> +            av_log(h, AV_LOG_ERROR, "Fifo buffer overrun. "
> +                    "To avoid, increase fifo_size URL option. "
> +                    "To survive in such case, use overrun_nonfatal option\n");
> +            size = AVERROR(EIO);
> +            goto out_free;
> +        } else {
> +            av_log(h, AV_LOG_WARNING, "Fifo buffer buffer overrun. "
> +                    "Surviving due to overrun_nonfatal option\n");

'buffer buffer' ?

> +        }
> +    }
> +#endif
> +
>     size = data_block->payload_len;
>     memcpy(buf, data_block->payload, size);
> +out_free:
> #if FF_LIBRIST_VERSION < FF_LIBRIST_VERSION_41
>     rist_receiver_data_block_free((struct rist_data_block**)&data_block);
> #else
> -- 
> 2.32.0
> 
> _______________________________________________
> 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".

_______________________________________________
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".

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [FFmpeg-devel] [PATCH] libRIST: allow setting fifo size and fail on overflow.
  2022-01-11  9:43 ` "zhilizhao(赵志立)"
@ 2022-01-11  9:45   ` Gijs Peskens
  0 siblings, 0 replies; 10+ messages in thread
From: Gijs Peskens @ 2022-01-11  9:45 UTC (permalink / raw)
  To: ffmpeg-devel

On 11-01-2022 10:43, "zhilizhao(赵志立)" wrote:
>
>> On Jan 11, 2022, at 5:23 PM, Gijs Peskens <gijs@peskens.net> wrote:
>>
>> Introduce fifo_size and overrun_nonfatal params to configure fifo buffer
>> behavior.
>>
>> Use newly introduced RIST_DATA_FLAGS_OVERFLOW flag to check for overrun
>> and error out in that case.
>> ---
>> doc/protocols.texi    |  9 +++++++++
>> libavformat/librist.c | 40 +++++++++++++++++++++++++++++++++++++++-
>> 2 files changed, 48 insertions(+), 1 deletion(-)
>>
>> diff --git a/doc/protocols.texi b/doc/protocols.texi
>> index d207df0b52..f1acf0cc77 100644
>> --- a/doc/protocols.texi
>> +++ b/doc/protocols.texi
>> @@ -745,6 +745,15 @@ Set internal RIST buffer size in milliseconds for retransmission of data.
>> Default value is 0 which means the librist default (1 sec). Maximum value is 30
>> seconds.
>>
>> +@item fifo_size
>> +Size of the librist receiver output fifo in number of packets. This must be a
>> +power of 2.
>> +Defaults to 8192 (vs the libRIST default of 1024).
>> +
>> +@item overrun_nonfatal=@var{1|0}
>> +Survive in case of libRIST fifo buffer overrun. Default
>> +value is 0.
>> +
>> @item pkt_size
>> Set maximum packet size for sending data. 1316 by default.
>>
>> diff --git a/libavformat/librist.c b/libavformat/librist.c
>> index 378b635ea7..83bbf9f07a 100644
>> --- a/libavformat/librist.c
>> +++ b/libavformat/librist.c
>> @@ -43,6 +43,9 @@
>>      ((patch) + ((minor)* 0x100) + ((major) *0x10000))
>> #define FF_LIBRIST_VERSION FF_LIBRIST_MAKE_VERSION(LIBRIST_API_VERSION_MAJOR, LIBRIST_API_VERSION_MINOR, LIBRIST_API_VERSION_PATCH)
>> #define FF_LIBRIST_VERSION_41 FF_LIBRIST_MAKE_VERSION(4, 1, 0)
>> +#define FF_LIBRIST_VERSION_42 FF_LIBRIST_MAKE_VERSION(4, 2, 0)
>> +
>> +#define FF_LIBRIST_FIFO_SIZE_DEFAULT (2 << 12)//8192
> It’s not easy to read without space before ‘//8192’.
> I prefer
>
> #define FF_LIBRIST_FIFO_SIZE_DEFAULT 8192
>
>> typedef struct RISTContext {
>>      const AVClass *class;
>> @@ -52,6 +55,8 @@ typedef struct RISTContext {
>>      int packet_size;
>>      int log_level;
>>      int encryption;
>> +    int fifo_size;
>> +    bool overrun_nonfatal;
> Should be ‘int’, please check opt.c.
>
>>      char *secret;
>>
>>      struct rist_logging_settings logging_settings;
>> @@ -70,6 +75,8 @@ static const AVOption librist_options[] = {
>>      { "main",        NULL,              0,                   AV_OPT_TYPE_CONST, {.i64=RIST_PROFILE_MAIN},     0, 0, .flags = D|E, "profile" },
>>      { "advanced",    NULL,              0,                   AV_OPT_TYPE_CONST, {.i64=RIST_PROFILE_ADVANCED}, 0, 0, .flags = D|E, "profile" },
>>      { "buffer_size", "set buffer_size in ms", OFFSET(buffer_size), AV_OPT_TYPE_INT, {.i64=0},                 0, 30000, .flags = D|E },
>> +    { "fifo_size", "Set libRIST fifo buffer. Size must be power of 2", OFFSET(fifo_size), AV_OPT_TYPE_INT, {.i64=FF_LIBRIST_FIFO_SIZE_DEFAULT}, 2 << 9, 2 << 15, .flags = D|E },
>> +    { "overrun_nonfatal", "survive in case of libRIST receiving circular buffer overrun", OFFSET(overrun_nonfatal), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1,    D },
>>      { "pkt_size",    "set packet size", OFFSET(packet_size), AV_OPT_TYPE_INT,   {.i64=1316},                  1, MAX_PAYLOAD_SIZE,    .flags = D|E },
>>      { "log_level",   "set loglevel",    OFFSET(log_level),   AV_OPT_TYPE_INT,   {.i64=RIST_LOG_INFO},        -1, INT_MAX, .flags = D|E },
>>      { "secret", "set encryption secret",OFFSET(secret),      AV_OPT_TYPE_STRING,{.str=NULL},                  0, 0,       .flags = D|E },
>> @@ -90,7 +97,6 @@ static int risterr2ret(int err)
>> static int log_cb(void *arg, enum rist_log_level log_level, const char *msg)
>> {
>>      int level;
>> -
> Unrelated changes.
>
>>      switch (log_level) {
>>      case RIST_LOG_ERROR:    level = AV_LOG_ERROR;   break;
>>      case RIST_LOG_WARN:     level = AV_LOG_WARNING; break;
>> @@ -139,6 +145,7 @@ static int librist_open(URLContext *h, const char *uri, int flags)
>>          h->max_packet_size = s->packet_size;
>>          ret = rist_sender_create(&s->ctx, s->profile, 0, logging_settings);
>>      }
>> +
>>      if (ret < 0)
>>          goto err;
>>
>> @@ -146,6 +153,7 @@ static int librist_open(URLContext *h, const char *uri, int flags)
>>          h->max_packet_size = MAX_PAYLOAD_SIZE;
>>          ret = rist_receiver_create(&s->ctx, s->profile, logging_settings);
>>      }
>> +
>>      if (ret < 0)
>>          goto err;
>>
>> @@ -161,6 +169,20 @@ static int librist_open(URLContext *h, const char *uri, int flags)
>>      if (ret < 0)
>>          goto err;
>>
>> +    //Prior to 4.2.0 there was a bug in libRIST which made this call always fail.
>> +#if FF_LIBRIST_VERSION >= FF_LIBRIST_VERSION_42
>> +    if (flags & AVIO_FLAG_READ) {
>> +        ret = rist_receiver_set_output_fifo_size(s->ctx, s->fifo_size);
>> +        if (ret != 0) {
>> +            goto err;
>> +        }
>> +    }
>> +#else
>> +    if (s->fifo_size != FF_LIBRIST_FIFO_SIZE_DEFAULT) {
>> +        av_log(h, AV_LOG_ERROR, "libRIST prior to 0.2.7 has a bug which fails setting the fifo buffer size");
> Missing newline at the end of log message.
>
>> +    }
>> +#endif
>> +
>>      if (((s->encryption == 128 || s->encryption == 256) && !s->secret) ||
>>          ((peer_config->key_size == 128 || peer_config->key_size == 256) && !peer_config->secret[0])) {
>>          av_log(h, AV_LOG_ERROR, "secret is mandatory if encryption is enabled\n");
>> @@ -223,8 +245,24 @@ static int librist_read(URLContext *h, uint8_t *buf, int size)
>>          return AVERROR_EXTERNAL;
>>      }
>>
>> +#if FF_LIBRIST_VERSION >= FF_LIBRIST_VERSION_42
>> +    if (data_block->flags & RIST_DATA_FLAGS_OVERFLOW == RIST_DATA_FLAGS_OVERFLOW) {
>> +        if (!s->overrun_nonfatal) {
>> +            av_log(h, AV_LOG_ERROR, "Fifo buffer overrun. "
>> +                    "To avoid, increase fifo_size URL option. "
>> +                    "To survive in such case, use overrun_nonfatal option\n");
>> +            size = AVERROR(EIO);
>> +            goto out_free;
>> +        } else {
>> +            av_log(h, AV_LOG_WARNING, "Fifo buffer buffer overrun. "
>> +                    "Surviving due to overrun_nonfatal option\n");
> 'buffer buffer' ?
>
>> +        }
>> +    }
>> +#endif
>> +
>>      size = data_block->payload_len;
>>      memcpy(buf, data_block->payload, size);
>> +out_free:
>> #if FF_LIBRIST_VERSION < FF_LIBRIST_VERSION_41
>>      rist_receiver_data_block_free((struct rist_data_block**)&data_block);
>> #else
>> -- 
>> 2.32.0
>>
>> _______________________________________________
>> 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".
> _______________________________________________
> 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".
Thanks will correct!
_______________________________________________
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".

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [FFmpeg-devel] [PATCH] libRIST: allow setting fifo size and fail on overflow.
  2022-01-11  9:23 [FFmpeg-devel] [PATCH] libRIST: allow setting fifo size and fail on overflow Gijs Peskens
  2022-01-11  9:43 ` "zhilizhao(赵志立)"
@ 2022-01-11 10:34 ` Gijs Peskens
  2022-01-11 10:35   ` Gijs Peskens
  2022-01-11 11:20   ` "zhilizhao(赵志立)"
  1 sibling, 2 replies; 10+ messages in thread
From: Gijs Peskens @ 2022-01-11 10:34 UTC (permalink / raw)
  To: ffmpeg-devel

Introduce fifo_size and overrun_nonfatal params to configure fifo buffer
behavior.

Use newly introduced RIST_DATA_FLAGS_OVERFLOW flag to check for overrun
and error out in that case.
---
 doc/protocols.texi    |  9 +++++++++
 libavformat/librist.c | 37 +++++++++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+)

diff --git a/doc/protocols.texi b/doc/protocols.texi
index d207df0b52..f1acf0cc77 100644
--- a/doc/protocols.texi
+++ b/doc/protocols.texi
@@ -745,6 +745,15 @@ Set internal RIST buffer size in milliseconds for retransmission of data.
 Default value is 0 which means the librist default (1 sec). Maximum value is 30
 seconds.
 
+@item fifo_size
+Size of the librist receiver output fifo in number of packets. This must be a 
+power of 2.
+Defaults to 8192 (vs the libRIST default of 1024).
+
+@item overrun_nonfatal=@var{1|0}
+Survive in case of libRIST fifo buffer overrun. Default
+value is 0.
+
 @item pkt_size
 Set maximum packet size for sending data. 1316 by default.
 
diff --git a/libavformat/librist.c b/libavformat/librist.c
index 378b635ea7..53f83d3668 100644
--- a/libavformat/librist.c
+++ b/libavformat/librist.c
@@ -43,6 +43,9 @@
     ((patch) + ((minor)* 0x100) + ((major) *0x10000))
 #define FF_LIBRIST_VERSION FF_LIBRIST_MAKE_VERSION(LIBRIST_API_VERSION_MAJOR, LIBRIST_API_VERSION_MINOR, LIBRIST_API_VERSION_PATCH)
 #define FF_LIBRIST_VERSION_41 FF_LIBRIST_MAKE_VERSION(4, 1, 0)
+#define FF_LIBRIST_VERSION_42 FF_LIBRIST_MAKE_VERSION(4, 2, 0)
+
+#define FF_LIBRIST_FIFO_SIZE_DEFAULT 8192
 
 typedef struct RISTContext {
     const AVClass *class;
@@ -52,6 +55,8 @@ typedef struct RISTContext {
     int packet_size;
     int log_level;
     int encryption;
+    int fifo_size;
+    int overrun_nonfatal;
     char *secret;
 
     struct rist_logging_settings logging_settings;
@@ -70,6 +75,8 @@ static const AVOption librist_options[] = {
     { "main",        NULL,              0,                   AV_OPT_TYPE_CONST, {.i64=RIST_PROFILE_MAIN},     0, 0, .flags = D|E, "profile" },
     { "advanced",    NULL,              0,                   AV_OPT_TYPE_CONST, {.i64=RIST_PROFILE_ADVANCED}, 0, 0, .flags = D|E, "profile" },
     { "buffer_size", "set buffer_size in ms", OFFSET(buffer_size), AV_OPT_TYPE_INT, {.i64=0},                 0, 30000, .flags = D|E },
+    { "fifo_size", "Set libRIST fifo buffer. Size must be power of 2", OFFSET(fifo_size), AV_OPT_TYPE_INT, {.i64=FF_LIBRIST_FIFO_SIZE_DEFAULT}, 2 << 9, 2 << 15, .flags = D|E },
+    { "overrun_nonfatal", "survive in case of libRIST receiving circular buffer overrun", OFFSET(overrun_nonfatal), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1,    D },
     { "pkt_size",    "set packet size", OFFSET(packet_size), AV_OPT_TYPE_INT,   {.i64=1316},                  1, MAX_PAYLOAD_SIZE,    .flags = D|E },
     { "log_level",   "set loglevel",    OFFSET(log_level),   AV_OPT_TYPE_INT,   {.i64=RIST_LOG_INFO},        -1, INT_MAX, .flags = D|E },
     { "secret", "set encryption secret",OFFSET(secret),      AV_OPT_TYPE_STRING,{.str=NULL},                  0, 0,       .flags = D|E },
@@ -161,6 +168,20 @@ static int librist_open(URLContext *h, const char *uri, int flags)
     if (ret < 0)
         goto err;
 
+    //Prior to 4.2.0 there was a bug in libRIST which made this call always fail.
+#if FF_LIBRIST_VERSION >= FF_LIBRIST_VERSION_42
+    if (flags & AVIO_FLAG_READ) {
+        ret = rist_receiver_set_output_fifo_size(s->ctx, s->fifo_size);
+        if (ret != 0) {
+            goto err;
+        }
+    }
+#else
+    if (s->fifo_size != FF_LIBRIST_FIFO_SIZE_DEFAULT) {
+        av_log(h, AV_LOG_ERROR, "libRIST prior to 0.2.7 has a bug which fails setting the fifo buffer size\n");
+    }
+#endif
+
     if (((s->encryption == 128 || s->encryption == 256) && !s->secret) ||
         ((peer_config->key_size == 128 || peer_config->key_size == 256) && !peer_config->secret[0])) {
         av_log(h, AV_LOG_ERROR, "secret is mandatory if encryption is enabled\n");
@@ -223,8 +244,24 @@ static int librist_read(URLContext *h, uint8_t *buf, int size)
         return AVERROR_EXTERNAL;
     }
 
+#if FF_LIBRIST_VERSION >= FF_LIBRIST_VERSION_42
+    if (data_block->flags & RIST_DATA_FLAGS_OVERFLOW == RIST_DATA_FLAGS_OVERFLOW) {
+        if (!s->overrun_nonfatal) {
+            av_log(h, AV_LOG_ERROR, "Fifo buffer overrun. "
+                    "To avoid, increase fifo_size URL option. "
+                    "To survive in such case, use overrun_nonfatal option\n");
+            size = AVERROR(EIO);
+            goto out_free;
+        } else {
+            av_log(h, AV_LOG_WARNING, "Fifo buffer overrun. "
+                    "Surviving due to overrun_nonfatal option\n");
+        }
+    }
+#endif
+
     size = data_block->payload_len;
     memcpy(buf, data_block->payload, size);
+out_free:
 #if FF_LIBRIST_VERSION < FF_LIBRIST_VERSION_41
     rist_receiver_data_block_free((struct rist_data_block**)&data_block);
 #else
-- 
2.32.0

_______________________________________________
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".

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [FFmpeg-devel] [PATCH] libRIST: allow setting fifo size and fail on overflow.
  2022-01-11 10:34 ` Gijs Peskens
@ 2022-01-11 10:35   ` Gijs Peskens
  2022-01-11 11:20   ` "zhilizhao(赵志立)"
  1 sibling, 0 replies; 10+ messages in thread
From: Gijs Peskens @ 2022-01-11 10:35 UTC (permalink / raw)
  To: ffmpeg-devel

V2, I don't know why send-patch didn't pick up the subject override :/

On 11-01-2022 11:34, Gijs Peskens wrote:
> Introduce fifo_size and overrun_nonfatal params to configure fifo buffer
> behavior.
>
> Use newly introduced RIST_DATA_FLAGS_OVERFLOW flag to check for overrun
> and error out in that case.
> ---
>   doc/protocols.texi    |  9 +++++++++
>   libavformat/librist.c | 37 +++++++++++++++++++++++++++++++++++++
>   2 files changed, 46 insertions(+)
>
> diff --git a/doc/protocols.texi b/doc/protocols.texi
> index d207df0b52..f1acf0cc77 100644
> --- a/doc/protocols.texi
> +++ b/doc/protocols.texi
> @@ -745,6 +745,15 @@ Set internal RIST buffer size in milliseconds for retransmission of data.
>   Default value is 0 which means the librist default (1 sec). Maximum value is 30
>   seconds.
>   
> +@item fifo_size
> +Size of the librist receiver output fifo in number of packets. This must be a
> +power of 2.
> +Defaults to 8192 (vs the libRIST default of 1024).
> +
> +@item overrun_nonfatal=@var{1|0}
> +Survive in case of libRIST fifo buffer overrun. Default
> +value is 0.
> +
>   @item pkt_size
>   Set maximum packet size for sending data. 1316 by default.
>   
> diff --git a/libavformat/librist.c b/libavformat/librist.c
> index 378b635ea7..53f83d3668 100644
> --- a/libavformat/librist.c
> +++ b/libavformat/librist.c
> @@ -43,6 +43,9 @@
>       ((patch) + ((minor)* 0x100) + ((major) *0x10000))
>   #define FF_LIBRIST_VERSION FF_LIBRIST_MAKE_VERSION(LIBRIST_API_VERSION_MAJOR, LIBRIST_API_VERSION_MINOR, LIBRIST_API_VERSION_PATCH)
>   #define FF_LIBRIST_VERSION_41 FF_LIBRIST_MAKE_VERSION(4, 1, 0)
> +#define FF_LIBRIST_VERSION_42 FF_LIBRIST_MAKE_VERSION(4, 2, 0)
> +
> +#define FF_LIBRIST_FIFO_SIZE_DEFAULT 8192
>   
>   typedef struct RISTContext {
>       const AVClass *class;
> @@ -52,6 +55,8 @@ typedef struct RISTContext {
>       int packet_size;
>       int log_level;
>       int encryption;
> +    int fifo_size;
> +    int overrun_nonfatal;
>       char *secret;
>   
>       struct rist_logging_settings logging_settings;
> @@ -70,6 +75,8 @@ static const AVOption librist_options[] = {
>       { "main",        NULL,              0,                   AV_OPT_TYPE_CONST, {.i64=RIST_PROFILE_MAIN},     0, 0, .flags = D|E, "profile" },
>       { "advanced",    NULL,              0,                   AV_OPT_TYPE_CONST, {.i64=RIST_PROFILE_ADVANCED}, 0, 0, .flags = D|E, "profile" },
>       { "buffer_size", "set buffer_size in ms", OFFSET(buffer_size), AV_OPT_TYPE_INT, {.i64=0},                 0, 30000, .flags = D|E },
> +    { "fifo_size", "Set libRIST fifo buffer. Size must be power of 2", OFFSET(fifo_size), AV_OPT_TYPE_INT, {.i64=FF_LIBRIST_FIFO_SIZE_DEFAULT}, 2 << 9, 2 << 15, .flags = D|E },
> +    { "overrun_nonfatal", "survive in case of libRIST receiving circular buffer overrun", OFFSET(overrun_nonfatal), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1,    D },
>       { "pkt_size",    "set packet size", OFFSET(packet_size), AV_OPT_TYPE_INT,   {.i64=1316},                  1, MAX_PAYLOAD_SIZE,    .flags = D|E },
>       { "log_level",   "set loglevel",    OFFSET(log_level),   AV_OPT_TYPE_INT,   {.i64=RIST_LOG_INFO},        -1, INT_MAX, .flags = D|E },
>       { "secret", "set encryption secret",OFFSET(secret),      AV_OPT_TYPE_STRING,{.str=NULL},                  0, 0,       .flags = D|E },
> @@ -161,6 +168,20 @@ static int librist_open(URLContext *h, const char *uri, int flags)
>       if (ret < 0)
>           goto err;
>   
> +    //Prior to 4.2.0 there was a bug in libRIST which made this call always fail.
> +#if FF_LIBRIST_VERSION >= FF_LIBRIST_VERSION_42
> +    if (flags & AVIO_FLAG_READ) {
> +        ret = rist_receiver_set_output_fifo_size(s->ctx, s->fifo_size);
> +        if (ret != 0) {
> +            goto err;
> +        }
> +    }
> +#else
> +    if (s->fifo_size != FF_LIBRIST_FIFO_SIZE_DEFAULT) {
> +        av_log(h, AV_LOG_ERROR, "libRIST prior to 0.2.7 has a bug which fails setting the fifo buffer size\n");
> +    }
> +#endif
> +
>       if (((s->encryption == 128 || s->encryption == 256) && !s->secret) ||
>           ((peer_config->key_size == 128 || peer_config->key_size == 256) && !peer_config->secret[0])) {
>           av_log(h, AV_LOG_ERROR, "secret is mandatory if encryption is enabled\n");
> @@ -223,8 +244,24 @@ static int librist_read(URLContext *h, uint8_t *buf, int size)
>           return AVERROR_EXTERNAL;
>       }
>   
> +#if FF_LIBRIST_VERSION >= FF_LIBRIST_VERSION_42
> +    if (data_block->flags & RIST_DATA_FLAGS_OVERFLOW == RIST_DATA_FLAGS_OVERFLOW) {
> +        if (!s->overrun_nonfatal) {
> +            av_log(h, AV_LOG_ERROR, "Fifo buffer overrun. "
> +                    "To avoid, increase fifo_size URL option. "
> +                    "To survive in such case, use overrun_nonfatal option\n");
> +            size = AVERROR(EIO);
> +            goto out_free;
> +        } else {
> +            av_log(h, AV_LOG_WARNING, "Fifo buffer overrun. "
> +                    "Surviving due to overrun_nonfatal option\n");
> +        }
> +    }
> +#endif
> +
>       size = data_block->payload_len;
>       memcpy(buf, data_block->payload, size);
> +out_free:
>   #if FF_LIBRIST_VERSION < FF_LIBRIST_VERSION_41
>       rist_receiver_data_block_free((struct rist_data_block**)&data_block);
>   #else
_______________________________________________
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".

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [FFmpeg-devel] [PATCH] libRIST: allow setting fifo size and fail on overflow.
  2022-01-11 10:34 ` Gijs Peskens
  2022-01-11 10:35   ` Gijs Peskens
@ 2022-01-11 11:20   ` "zhilizhao(赵志立)"
  1 sibling, 0 replies; 10+ messages in thread
From: "zhilizhao(赵志立)" @ 2022-01-11 11:20 UTC (permalink / raw)
  To: FFmpeg development discussions and patches



> On Jan 11, 2022, at 6:34 PM, Gijs Peskens <gijs@peskens.net> wrote:
> 
> Introduce fifo_size and overrun_nonfatal params to configure fifo buffer
> behavior.
> 
> Use newly introduced RIST_DATA_FLAGS_OVERFLOW flag to check for overrun
> and error out in that case.
> ---
> doc/protocols.texi    |  9 +++++++++
> libavformat/librist.c | 37 +++++++++++++++++++++++++++++++++++++
> 2 files changed, 46 insertions(+)
> 
> diff --git a/doc/protocols.texi b/doc/protocols.texi
> index d207df0b52..f1acf0cc77 100644
> --- a/doc/protocols.texi
> +++ b/doc/protocols.texi
> @@ -745,6 +745,15 @@ Set internal RIST buffer size in milliseconds for retransmission of data.
> Default value is 0 which means the librist default (1 sec). Maximum value is 30
> seconds.
> 
> +@item fifo_size
> +Size of the librist receiver output fifo in number of packets. This must be a 
> +power of 2.
> +Defaults to 8192 (vs the libRIST default of 1024).
> +
> +@item overrun_nonfatal=@var{1|0}
> +Survive in case of libRIST fifo buffer overrun. Default
> +value is 0.
> +
> @item pkt_size
> Set maximum packet size for sending data. 1316 by default.
> 
> diff --git a/libavformat/librist.c b/libavformat/librist.c
> index 378b635ea7..53f83d3668 100644
> --- a/libavformat/librist.c
> +++ b/libavformat/librist.c
> @@ -43,6 +43,9 @@
>     ((patch) + ((minor)* 0x100) + ((major) *0x10000))
> #define FF_LIBRIST_VERSION FF_LIBRIST_MAKE_VERSION(LIBRIST_API_VERSION_MAJOR, LIBRIST_API_VERSION_MINOR, LIBRIST_API_VERSION_PATCH)
> #define FF_LIBRIST_VERSION_41 FF_LIBRIST_MAKE_VERSION(4, 1, 0)
> +#define FF_LIBRIST_VERSION_42 FF_LIBRIST_MAKE_VERSION(4, 2, 0)
> +
> +#define FF_LIBRIST_FIFO_SIZE_DEFAULT 8192
> 
> typedef struct RISTContext {
>     const AVClass *class;
> @@ -52,6 +55,8 @@ typedef struct RISTContext {
>     int packet_size;
>     int log_level;
>     int encryption;
> +    int fifo_size;
> +    int overrun_nonfatal;
>     char *secret;
> 
>     struct rist_logging_settings logging_settings;
> @@ -70,6 +75,8 @@ static const AVOption librist_options[] = {
>     { "main",        NULL,              0,                   AV_OPT_TYPE_CONST, {.i64=RIST_PROFILE_MAIN},     0, 0, .flags = D|E, "profile" },
>     { "advanced",    NULL,              0,                   AV_OPT_TYPE_CONST, {.i64=RIST_PROFILE_ADVANCED}, 0, 0, .flags = D|E, "profile" },
>     { "buffer_size", "set buffer_size in ms", OFFSET(buffer_size), AV_OPT_TYPE_INT, {.i64=0},                 0, 30000, .flags = D|E },
> +    { "fifo_size", "Set libRIST fifo buffer. Size must be power of 2", OFFSET(fifo_size), AV_OPT_TYPE_INT, {.i64=FF_LIBRIST_FIFO_SIZE_DEFAULT}, 2 << 9, 2 << 15, .flags = D|E },
> +    { "overrun_nonfatal", "survive in case of libRIST receiving circular buffer overrun", OFFSET(overrun_nonfatal), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1,    D },

This is not what I mean. We use int type to hold the result of
AV_OPT_TYPE_BOOL configuration.

If overrun_nonfatal has bool type, it can trigger such error:

    src/libavutil/opt.c:129:9: runtime error: store to misaligned
    address 0x7fbf454121a3 for type 'int', which requires 4 byte alignment

For AVOption, the type is AV_OPT_TYPE_BOOL.

>     { "pkt_size",    "set packet size", OFFSET(packet_size), AV_OPT_TYPE_INT,   {.i64=1316},                  1, MAX_PAYLOAD_SIZE,    .flags = D|E },
>     { "log_level",   "set loglevel",    OFFSET(log_level),   AV_OPT_TYPE_INT,   {.i64=RIST_LOG_INFO},        -1, INT_MAX, .flags = D|E },
>     { "secret", "set encryption secret",OFFSET(secret),      AV_OPT_TYPE_STRING,{.str=NULL},                  0, 0,       .flags = D|E },
> @@ -161,6 +168,20 @@ static int librist_open(URLContext *h, const char *uri, int flags)
>     if (ret < 0)
>         goto err;
> 
> +    //Prior to 4.2.0 there was a bug in libRIST which made this call always fail.
> +#if FF_LIBRIST_VERSION >= FF_LIBRIST_VERSION_42
> +    if (flags & AVIO_FLAG_READ) {
> +        ret = rist_receiver_set_output_fifo_size(s->ctx, s->fifo_size);
> +        if (ret != 0) {
> +            goto err;
> +        }
> +    }
> +#else
> +    if (s->fifo_size != FF_LIBRIST_FIFO_SIZE_DEFAULT) {
> +        av_log(h, AV_LOG_ERROR, "libRIST prior to 0.2.7 has a bug which fails setting the fifo buffer size\n");
> +    }
> +#endif
> +
>     if (((s->encryption == 128 || s->encryption == 256) && !s->secret) ||
>         ((peer_config->key_size == 128 || peer_config->key_size == 256) && !peer_config->secret[0])) {
>         av_log(h, AV_LOG_ERROR, "secret is mandatory if encryption is enabled\n");
> @@ -223,8 +244,24 @@ static int librist_read(URLContext *h, uint8_t *buf, int size)
>         return AVERROR_EXTERNAL;
>     }
> 
> +#if FF_LIBRIST_VERSION >= FF_LIBRIST_VERSION_42
> +    if (data_block->flags & RIST_DATA_FLAGS_OVERFLOW == RIST_DATA_FLAGS_OVERFLOW) {
> +        if (!s->overrun_nonfatal) {
> +            av_log(h, AV_LOG_ERROR, "Fifo buffer overrun. "
> +                    "To avoid, increase fifo_size URL option. "
> +                    "To survive in such case, use overrun_nonfatal option\n");
> +            size = AVERROR(EIO);
> +            goto out_free;
> +        } else {
> +            av_log(h, AV_LOG_WARNING, "Fifo buffer overrun. "
> +                    "Surviving due to overrun_nonfatal option\n");
> +        }
> +    }
> +#endif
> +
>     size = data_block->payload_len;
>     memcpy(buf, data_block->payload, size);
> +out_free:
> #if FF_LIBRIST_VERSION < FF_LIBRIST_VERSION_41
>     rist_receiver_data_block_free((struct rist_data_block**)&data_block);
> #else
> -- 
> 2.32.0
> 
> _______________________________________________
> 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".

_______________________________________________
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".

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [FFmpeg-devel] [PATCH] libRIST: allow setting fifo size and fail on overflow.
  2022-01-31 23:03 ` Marton Balint
@ 2022-06-09 22:05   ` Marton Balint
  0 siblings, 0 replies; 10+ messages in thread
From: Marton Balint @ 2022-06-09 22:05 UTC (permalink / raw)
  To: FFmpeg development discussions and patches



On Tue, 1 Feb 2022, Marton Balint wrote:

>
>
> On Tue, 11 Jan 2022, Gijs Peskens wrote:
>
>>  Introduce fifo_size and overrun_nonfatal params to configure fifo buffer
>>  behavior.
>>
>>  Use newly introduced RIST_DATA_FLAGS_OVERFLOW flag to check for overrun
>>  and error out in that case.
>>  ---
>>  doc/protocols.texi    |  9 +++++++++
>>  libavformat/librist.c | 37 +++++++++++++++++++++++++++++++++++++
>>  2 files changed, 46 insertions(+)

Applied with some fixes.

Regards,
Marton

>>
>>  diff --git a/doc/protocols.texi b/doc/protocols.texi
>>  index d207df0b52..f1acf0cc77 100644
>>  --- a/doc/protocols.texi
>>  +++ b/doc/protocols.texi
>> @@  -745,6 +745,15 @@ Set internal RIST buffer size in milliseconds for 
>> @@  retransmission of data.
>>  Default value is 0 which means the librist default (1 sec). Maximum value
>>  is 30
>>  seconds.
>>
>>  +@item fifo_size
>>  +Size of the librist receiver output fifo in number of packets. This must
>>  be a
>>  +power of 2.
>>  +Defaults to 8192 (vs the libRIST default of 1024).
>>  +
>>  +@item overrun_nonfatal=@var{1|0}
>>  +Survive in case of libRIST fifo buffer overrun. Default
>>  +value is 0.
>
> Please use "librist" (all lowercase) consistently.
>
>>  +
>> @ item pkt_size
>>  Set maximum packet size for sending data. 1316 by default.
>>
>>  diff --git a/libavformat/librist.c b/libavformat/librist.c
>>  index 378b635ea7..87c14eb265 100644
>>  --- a/libavformat/librist.c
>>  +++ b/libavformat/librist.c
>> @@  -43,6 +43,9 @@
>>      ((patch) + ((minor)* 0x100) + ((major) *0x10000))
>>  #define FF_LIBRIST_VERSION
>>  FF_LIBRIST_MAKE_VERSION(LIBRIST_API_VERSION_MAJOR,
>>  LIBRIST_API_VERSION_MINOR, LIBRIST_API_VERSION_PATCH)
>>  #define FF_LIBRIST_VERSION_41 FF_LIBRIST_MAKE_VERSION(4, 1, 0)
>>  +#define FF_LIBRIST_VERSION_42 FF_LIBRIST_MAKE_VERSION(4, 2, 0)
>>  +
>>  +#define FF_LIBRIST_FIFO_SIZE_DEFAULT 8192
>
> FF_LIBRIST prefix is not really needed, as this is not in a header.
>
>>
>>  typedef struct RISTContext {
>>      const AVClass *class;
>> @@  -52,6 +55,8 @@ typedef struct RISTContext {
>>      int packet_size;
>>      int log_level;
>>      int encryption;
>>  +    int fifo_size;
>>  +    int overrun_nonfatal;
>>      char *secret;
>>
>>      struct rist_logging_settings logging_settings;
>> @@  -70,6 +75,8 @@ static const AVOption librist_options[] = {
>>      { "main",        NULL,              0,
>>      AV_OPT_TYPE_CONST, {.i64=RIST_PROFILE_MAIN},     0, 0, .flags = D|E,
>>      "profile" },
>>      { "advanced",    NULL,              0,
>>      AV_OPT_TYPE_CONST, {.i64=RIST_PROFILE_ADVANCED}, 0, 0, .flags = D|E,
>>      "profile" },
>>      { "buffer_size", "set buffer_size in ms", OFFSET(buffer_size),
>>      AV_OPT_TYPE_INT, {.i64=0},                 0, 30000, .flags = D|E },
>>  +    { "fifo_size", "Set libRIST fifo buffer. Size must be power of 2",
>>  OFFSET(fifo_size), AV_OPT_TYPE_INT, {.i64=FF_LIBRIST_FIFO_SIZE_DEFAULT}, 2
>>  << 9, 2 << 15, .flags = D|E },
>
> Minimum and maximum binary notation is very strange. Use 1<<power, or maybe 
> I'd just write 1024 and 65536. Much more readable. Are these arbitrary 
> limits, or the implementation only supports these? Maybe you can be a bit 
> more lax, e.g. 256 minimum and 262144 max.
>
>>  +    { "overrun_nonfatal", "survive in case of libRIST receiving circular
>>  buffer overrun", OFFSET(overrun_nonfatal), AV_OPT_TYPE_BOOL, {.i64 = 0},
>>  0, 1,    D },
>>      { "pkt_size",    "set packet size", OFFSET(packet_size),
>>      AV_OPT_TYPE_INT,   {.i64=1316},                  1, MAX_PAYLOAD_SIZE,
>>      .flags = D|E },
>>      { "log_level",   "set loglevel",    OFFSET(log_level),
>>      AV_OPT_TYPE_INT,   {.i64=RIST_LOG_INFO},        -1, INT_MAX, .flags =
>>      D|E },
>>      { "secret", "set encryption secret",OFFSET(secret),
>>      AV_OPT_TYPE_STRING,{.str=NULL},                  0, 0,       .flags =
>>      D|E },
>> @@  -161,6 +168,20 @@ static int librist_open(URLContext *h, const char 
>> @@  *uri, int flags)
>>      if (ret < 0)
>>          goto err;
>>
>>  +    //Prior to 4.2.0 there was a bug in libRIST which made this call
>>  always fail.
>>  +#if FF_LIBRIST_VERSION >= FF_LIBRIST_VERSION_42
>>  +    if (flags & AVIO_FLAG_READ) {
>>  +        ret = rist_receiver_set_output_fifo_size(s->ctx, s->fifo_size);
>>  +        if (ret != 0) {
>>  +            goto err;
>>  +        }
>>  +    }
>>  +#else
>>  +    if (s->fifo_size != FF_LIBRIST_FIFO_SIZE_DEFAULT) {
>
> Isn't this supposed to be if (s->fifo_size != 1024)? Considering that we are 
> aiming for a bigger default in ffmpeg compared to what is in the library as 
> default, maybe the user should be aware that we cannot set it?
>
>>  +        av_log(h, AV_LOG_ERROR, "libRIST prior to 0.2.7 has a bug which
>>  fails setting the fifo buffer size\n");
>>  +    }
>>  +#endif
>>  +
>
> Thanks,
> Marton
> _______________________________________________
> 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".
>
_______________________________________________
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".

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [FFmpeg-devel] [PATCH] libRIST: allow setting fifo size and fail on overflow.
  2022-01-11 15:07 Gijs Peskens
  2022-01-31  8:12 ` Gijs Peskens
@ 2022-01-31 23:03 ` Marton Balint
  2022-06-09 22:05   ` Marton Balint
  1 sibling, 1 reply; 10+ messages in thread
From: Marton Balint @ 2022-01-31 23:03 UTC (permalink / raw)
  To: FFmpeg development discussions and patches



On Tue, 11 Jan 2022, Gijs Peskens wrote:

> Introduce fifo_size and overrun_nonfatal params to configure fifo buffer
> behavior.
>
> Use newly introduced RIST_DATA_FLAGS_OVERFLOW flag to check for overrun
> and error out in that case.
> ---
> doc/protocols.texi    |  9 +++++++++
> libavformat/librist.c | 37 +++++++++++++++++++++++++++++++++++++
> 2 files changed, 46 insertions(+)
>
> diff --git a/doc/protocols.texi b/doc/protocols.texi
> index d207df0b52..f1acf0cc77 100644
> --- a/doc/protocols.texi
> +++ b/doc/protocols.texi
> @@ -745,6 +745,15 @@ Set internal RIST buffer size in milliseconds for retransmission of data.
> Default value is 0 which means the librist default (1 sec). Maximum value is 30
> seconds.
>
> +@item fifo_size
> +Size of the librist receiver output fifo in number of packets. This must be a
> +power of 2.
> +Defaults to 8192 (vs the libRIST default of 1024).
> +
> +@item overrun_nonfatal=@var{1|0}
> +Survive in case of libRIST fifo buffer overrun. Default
> +value is 0.

Please use "librist" (all lowercase) consistently.

> +
> @item pkt_size
> Set maximum packet size for sending data. 1316 by default.
>
> diff --git a/libavformat/librist.c b/libavformat/librist.c
> index 378b635ea7..87c14eb265 100644
> --- a/libavformat/librist.c
> +++ b/libavformat/librist.c
> @@ -43,6 +43,9 @@
>     ((patch) + ((minor)* 0x100) + ((major) *0x10000))
> #define FF_LIBRIST_VERSION FF_LIBRIST_MAKE_VERSION(LIBRIST_API_VERSION_MAJOR, LIBRIST_API_VERSION_MINOR, LIBRIST_API_VERSION_PATCH)
> #define FF_LIBRIST_VERSION_41 FF_LIBRIST_MAKE_VERSION(4, 1, 0)
> +#define FF_LIBRIST_VERSION_42 FF_LIBRIST_MAKE_VERSION(4, 2, 0)
> +
> +#define FF_LIBRIST_FIFO_SIZE_DEFAULT 8192

FF_LIBRIST prefix is not really needed, as this is not in a header.

>
> typedef struct RISTContext {
>     const AVClass *class;
> @@ -52,6 +55,8 @@ typedef struct RISTContext {
>     int packet_size;
>     int log_level;
>     int encryption;
> +    int fifo_size;
> +    int overrun_nonfatal;
>     char *secret;
>
>     struct rist_logging_settings logging_settings;
> @@ -70,6 +75,8 @@ static const AVOption librist_options[] = {
>     { "main",        NULL,              0,                   AV_OPT_TYPE_CONST, {.i64=RIST_PROFILE_MAIN},     0, 0, .flags = D|E, "profile" },
>     { "advanced",    NULL,              0,                   AV_OPT_TYPE_CONST, {.i64=RIST_PROFILE_ADVANCED}, 0, 0, .flags = D|E, "profile" },
>     { "buffer_size", "set buffer_size in ms", OFFSET(buffer_size), AV_OPT_TYPE_INT, {.i64=0},                 0, 30000, .flags = D|E },
> +    { "fifo_size", "Set libRIST fifo buffer. Size must be power of 2", OFFSET(fifo_size), AV_OPT_TYPE_INT, {.i64=FF_LIBRIST_FIFO_SIZE_DEFAULT}, 2 << 9, 2 << 15, .flags = D|E },

Minimum and maximum binary notation is very strange. Use 1<<power, or 
maybe I'd just write 1024 and 65536. Much more readable. Are these 
arbitrary limits, or the implementation only supports these? Maybe you 
can be a bit more lax, e.g. 256 minimum and 262144 max.

> +    { "overrun_nonfatal", "survive in case of libRIST receiving circular buffer overrun", OFFSET(overrun_nonfatal), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1,    D },
>     { "pkt_size",    "set packet size", OFFSET(packet_size), AV_OPT_TYPE_INT,   {.i64=1316},                  1, MAX_PAYLOAD_SIZE,    .flags = D|E },
>     { "log_level",   "set loglevel",    OFFSET(log_level),   AV_OPT_TYPE_INT,   {.i64=RIST_LOG_INFO},        -1, INT_MAX, .flags = D|E },
>     { "secret", "set encryption secret",OFFSET(secret),      AV_OPT_TYPE_STRING,{.str=NULL},                  0, 0,       .flags = D|E },
> @@ -161,6 +168,20 @@ static int librist_open(URLContext *h, const char *uri, int flags)
>     if (ret < 0)
>         goto err;
>
> +    //Prior to 4.2.0 there was a bug in libRIST which made this call always fail.
> +#if FF_LIBRIST_VERSION >= FF_LIBRIST_VERSION_42
> +    if (flags & AVIO_FLAG_READ) {
> +        ret = rist_receiver_set_output_fifo_size(s->ctx, s->fifo_size);
> +        if (ret != 0) {
> +            goto err;
> +        }
> +    }
> +#else
> +    if (s->fifo_size != FF_LIBRIST_FIFO_SIZE_DEFAULT) {

Isn't this supposed to be if (s->fifo_size != 1024)? Considering that we 
are aiming for a bigger default in ffmpeg compared to what is in the 
library as default, maybe the user should be aware that we cannot set it?

> +        av_log(h, AV_LOG_ERROR, "libRIST prior to 0.2.7 has a bug which fails setting the fifo buffer size\n");
> +    }
> +#endif
> +

Thanks,
Marton
_______________________________________________
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".

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [FFmpeg-devel] [PATCH] libRIST: allow setting fifo size and fail on overflow.
  2022-01-11 15:07 Gijs Peskens
@ 2022-01-31  8:12 ` Gijs Peskens
  2022-01-31 23:03 ` Marton Balint
  1 sibling, 0 replies; 10+ messages in thread
From: Gijs Peskens @ 2022-01-31  8:12 UTC (permalink / raw)
  To: ffmpeg-devel

Bump, could this get another review?

On 11-01-2022 16:07, Gijs Peskens wrote:
> Introduce fifo_size and overrun_nonfatal params to configure fifo buffer
> behavior.
>
> Use newly introduced RIST_DATA_FLAGS_OVERFLOW flag to check for overrun
> and error out in that case.
> ---
>   doc/protocols.texi    |  9 +++++++++
>   libavformat/librist.c | 37 +++++++++++++++++++++++++++++++++++++
>   2 files changed, 46 insertions(+)
>
> diff --git a/doc/protocols.texi b/doc/protocols.texi
> index d207df0b52..f1acf0cc77 100644
> --- a/doc/protocols.texi
> +++ b/doc/protocols.texi
> @@ -745,6 +745,15 @@ Set internal RIST buffer size in milliseconds for retransmission of data.
>   Default value is 0 which means the librist default (1 sec). Maximum value is 30
>   seconds.
>   
> +@item fifo_size
> +Size of the librist receiver output fifo in number of packets. This must be a
> +power of 2.
> +Defaults to 8192 (vs the libRIST default of 1024).
> +
> +@item overrun_nonfatal=@var{1|0}
> +Survive in case of libRIST fifo buffer overrun. Default
> +value is 0.
> +
>   @item pkt_size
>   Set maximum packet size for sending data. 1316 by default.
>   
> diff --git a/libavformat/librist.c b/libavformat/librist.c
> index 378b635ea7..87c14eb265 100644
> --- a/libavformat/librist.c
> +++ b/libavformat/librist.c
> @@ -43,6 +43,9 @@
>       ((patch) + ((minor)* 0x100) + ((major) *0x10000))
>   #define FF_LIBRIST_VERSION FF_LIBRIST_MAKE_VERSION(LIBRIST_API_VERSION_MAJOR, LIBRIST_API_VERSION_MINOR, LIBRIST_API_VERSION_PATCH)
>   #define FF_LIBRIST_VERSION_41 FF_LIBRIST_MAKE_VERSION(4, 1, 0)
> +#define FF_LIBRIST_VERSION_42 FF_LIBRIST_MAKE_VERSION(4, 2, 0)
> +
> +#define FF_LIBRIST_FIFO_SIZE_DEFAULT 8192
>   
>   typedef struct RISTContext {
>       const AVClass *class;
> @@ -52,6 +55,8 @@ typedef struct RISTContext {
>       int packet_size;
>       int log_level;
>       int encryption;
> +    int fifo_size;
> +    int overrun_nonfatal;
>       char *secret;
>   
>       struct rist_logging_settings logging_settings;
> @@ -70,6 +75,8 @@ static const AVOption librist_options[] = {
>       { "main",        NULL,              0,                   AV_OPT_TYPE_CONST, {.i64=RIST_PROFILE_MAIN},     0, 0, .flags = D|E, "profile" },
>       { "advanced",    NULL,              0,                   AV_OPT_TYPE_CONST, {.i64=RIST_PROFILE_ADVANCED}, 0, 0, .flags = D|E, "profile" },
>       { "buffer_size", "set buffer_size in ms", OFFSET(buffer_size), AV_OPT_TYPE_INT, {.i64=0},                 0, 30000, .flags = D|E },
> +    { "fifo_size", "Set libRIST fifo buffer. Size must be power of 2", OFFSET(fifo_size), AV_OPT_TYPE_INT, {.i64=FF_LIBRIST_FIFO_SIZE_DEFAULT}, 2 << 9, 2 << 15, .flags = D|E },
> +    { "overrun_nonfatal", "survive in case of libRIST receiving circular buffer overrun", OFFSET(overrun_nonfatal), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1,    D },
>       { "pkt_size",    "set packet size", OFFSET(packet_size), AV_OPT_TYPE_INT,   {.i64=1316},                  1, MAX_PAYLOAD_SIZE,    .flags = D|E },
>       { "log_level",   "set loglevel",    OFFSET(log_level),   AV_OPT_TYPE_INT,   {.i64=RIST_LOG_INFO},        -1, INT_MAX, .flags = D|E },
>       { "secret", "set encryption secret",OFFSET(secret),      AV_OPT_TYPE_STRING,{.str=NULL},                  0, 0,       .flags = D|E },
> @@ -161,6 +168,20 @@ static int librist_open(URLContext *h, const char *uri, int flags)
>       if (ret < 0)
>           goto err;
>   
> +    //Prior to 4.2.0 there was a bug in libRIST which made this call always fail.
> +#if FF_LIBRIST_VERSION >= FF_LIBRIST_VERSION_42
> +    if (flags & AVIO_FLAG_READ) {
> +        ret = rist_receiver_set_output_fifo_size(s->ctx, s->fifo_size);
> +        if (ret != 0) {
> +            goto err;
> +        }
> +    }
> +#else
> +    if (s->fifo_size != FF_LIBRIST_FIFO_SIZE_DEFAULT) {
> +        av_log(h, AV_LOG_ERROR, "libRIST prior to 0.2.7 has a bug which fails setting the fifo buffer size\n");
> +    }
> +#endif
> +
>       if (((s->encryption == 128 || s->encryption == 256) && !s->secret) ||
>           ((peer_config->key_size == 128 || peer_config->key_size == 256) && !peer_config->secret[0])) {
>           av_log(h, AV_LOG_ERROR, "secret is mandatory if encryption is enabled\n");
> @@ -223,8 +244,24 @@ static int librist_read(URLContext *h, uint8_t *buf, int size)
>           return AVERROR_EXTERNAL;
>       }
>   
> +#if FF_LIBRIST_VERSION >= FF_LIBRIST_VERSION_42
> +    if (data_block->flags & RIST_DATA_FLAGS_OVERFLOW == RIST_DATA_FLAGS_OVERFLOW) {
> +        if (!s->overrun_nonfatal) {
> +            av_log(h, AV_LOG_ERROR, "Fifo buffer overrun. "
> +                    "To avoid, increase fifo_size URL option. "
> +                    "To survive in such case, use overrun_nonfatal option\n");
> +            size = AVERROR(EIO);
> +            goto out_free;
> +        } else {
> +            av_log(h, AV_LOG_WARNING, "Fifo buffer overrun. "
> +                    "Surviving due to overrun_nonfatal option\n");
> +        }
> +    }
> +#endif
> +
>       size = data_block->payload_len;
>       memcpy(buf, data_block->payload, size);
> +out_free:
>   #if FF_LIBRIST_VERSION < FF_LIBRIST_VERSION_41
>       rist_receiver_data_block_free((struct rist_data_block**)&data_block);
>   #else
_______________________________________________
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".

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [FFmpeg-devel] [PATCH] libRIST: allow setting fifo size and fail on overflow.
@ 2022-01-11 15:07 Gijs Peskens
  2022-01-31  8:12 ` Gijs Peskens
  2022-01-31 23:03 ` Marton Balint
  0 siblings, 2 replies; 10+ messages in thread
From: Gijs Peskens @ 2022-01-11 15:07 UTC (permalink / raw)
  To: ffmpeg-devel

Introduce fifo_size and overrun_nonfatal params to configure fifo buffer
behavior.

Use newly introduced RIST_DATA_FLAGS_OVERFLOW flag to check for overrun
and error out in that case.
---
 doc/protocols.texi    |  9 +++++++++
 libavformat/librist.c | 37 +++++++++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+)

diff --git a/doc/protocols.texi b/doc/protocols.texi
index d207df0b52..f1acf0cc77 100644
--- a/doc/protocols.texi
+++ b/doc/protocols.texi
@@ -745,6 +745,15 @@ Set internal RIST buffer size in milliseconds for retransmission of data.
 Default value is 0 which means the librist default (1 sec). Maximum value is 30
 seconds.
 
+@item fifo_size
+Size of the librist receiver output fifo in number of packets. This must be a 
+power of 2.
+Defaults to 8192 (vs the libRIST default of 1024).
+
+@item overrun_nonfatal=@var{1|0}
+Survive in case of libRIST fifo buffer overrun. Default
+value is 0.
+
 @item pkt_size
 Set maximum packet size for sending data. 1316 by default.
 
diff --git a/libavformat/librist.c b/libavformat/librist.c
index 378b635ea7..87c14eb265 100644
--- a/libavformat/librist.c
+++ b/libavformat/librist.c
@@ -43,6 +43,9 @@
     ((patch) + ((minor)* 0x100) + ((major) *0x10000))
 #define FF_LIBRIST_VERSION FF_LIBRIST_MAKE_VERSION(LIBRIST_API_VERSION_MAJOR, LIBRIST_API_VERSION_MINOR, LIBRIST_API_VERSION_PATCH)
 #define FF_LIBRIST_VERSION_41 FF_LIBRIST_MAKE_VERSION(4, 1, 0)
+#define FF_LIBRIST_VERSION_42 FF_LIBRIST_MAKE_VERSION(4, 2, 0)
+
+#define FF_LIBRIST_FIFO_SIZE_DEFAULT 8192
 
 typedef struct RISTContext {
     const AVClass *class;
@@ -52,6 +55,8 @@ typedef struct RISTContext {
     int packet_size;
     int log_level;
     int encryption;
+    int fifo_size;
+    int overrun_nonfatal;
     char *secret;
 
     struct rist_logging_settings logging_settings;
@@ -70,6 +75,8 @@ static const AVOption librist_options[] = {
     { "main",        NULL,              0,                   AV_OPT_TYPE_CONST, {.i64=RIST_PROFILE_MAIN},     0, 0, .flags = D|E, "profile" },
     { "advanced",    NULL,              0,                   AV_OPT_TYPE_CONST, {.i64=RIST_PROFILE_ADVANCED}, 0, 0, .flags = D|E, "profile" },
     { "buffer_size", "set buffer_size in ms", OFFSET(buffer_size), AV_OPT_TYPE_INT, {.i64=0},                 0, 30000, .flags = D|E },
+    { "fifo_size", "Set libRIST fifo buffer. Size must be power of 2", OFFSET(fifo_size), AV_OPT_TYPE_INT, {.i64=FF_LIBRIST_FIFO_SIZE_DEFAULT}, 2 << 9, 2 << 15, .flags = D|E },
+    { "overrun_nonfatal", "survive in case of libRIST receiving circular buffer overrun", OFFSET(overrun_nonfatal), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1,    D },
     { "pkt_size",    "set packet size", OFFSET(packet_size), AV_OPT_TYPE_INT,   {.i64=1316},                  1, MAX_PAYLOAD_SIZE,    .flags = D|E },
     { "log_level",   "set loglevel",    OFFSET(log_level),   AV_OPT_TYPE_INT,   {.i64=RIST_LOG_INFO},        -1, INT_MAX, .flags = D|E },
     { "secret", "set encryption secret",OFFSET(secret),      AV_OPT_TYPE_STRING,{.str=NULL},                  0, 0,       .flags = D|E },
@@ -161,6 +168,20 @@ static int librist_open(URLContext *h, const char *uri, int flags)
     if (ret < 0)
         goto err;
 
+    //Prior to 4.2.0 there was a bug in libRIST which made this call always fail.
+#if FF_LIBRIST_VERSION >= FF_LIBRIST_VERSION_42
+    if (flags & AVIO_FLAG_READ) {
+        ret = rist_receiver_set_output_fifo_size(s->ctx, s->fifo_size);
+        if (ret != 0) {
+            goto err;
+        }
+    }
+#else
+    if (s->fifo_size != FF_LIBRIST_FIFO_SIZE_DEFAULT) {
+        av_log(h, AV_LOG_ERROR, "libRIST prior to 0.2.7 has a bug which fails setting the fifo buffer size\n");
+    }
+#endif
+
     if (((s->encryption == 128 || s->encryption == 256) && !s->secret) ||
         ((peer_config->key_size == 128 || peer_config->key_size == 256) && !peer_config->secret[0])) {
         av_log(h, AV_LOG_ERROR, "secret is mandatory if encryption is enabled\n");
@@ -223,8 +244,24 @@ static int librist_read(URLContext *h, uint8_t *buf, int size)
         return AVERROR_EXTERNAL;
     }
 
+#if FF_LIBRIST_VERSION >= FF_LIBRIST_VERSION_42
+    if (data_block->flags & RIST_DATA_FLAGS_OVERFLOW == RIST_DATA_FLAGS_OVERFLOW) {
+        if (!s->overrun_nonfatal) {
+            av_log(h, AV_LOG_ERROR, "Fifo buffer overrun. "
+                    "To avoid, increase fifo_size URL option. "
+                    "To survive in such case, use overrun_nonfatal option\n");
+            size = AVERROR(EIO);
+            goto out_free;
+        } else {
+            av_log(h, AV_LOG_WARNING, "Fifo buffer overrun. "
+                    "Surviving due to overrun_nonfatal option\n");
+        }
+    }
+#endif
+
     size = data_block->payload_len;
     memcpy(buf, data_block->payload, size);
+out_free:
 #if FF_LIBRIST_VERSION < FF_LIBRIST_VERSION_41
     rist_receiver_data_block_free((struct rist_data_block**)&data_block);
 #else
-- 
2.32.0

_______________________________________________
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".

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2022-06-09 22:05 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-11  9:23 [FFmpeg-devel] [PATCH] libRIST: allow setting fifo size and fail on overflow Gijs Peskens
2022-01-11  9:43 ` "zhilizhao(赵志立)"
2022-01-11  9:45   ` Gijs Peskens
2022-01-11 10:34 ` Gijs Peskens
2022-01-11 10:35   ` Gijs Peskens
2022-01-11 11:20   ` "zhilizhao(赵志立)"
2022-01-11 15:07 Gijs Peskens
2022-01-31  8:12 ` Gijs Peskens
2022-01-31 23:03 ` Marton Balint
2022-06-09 22:05   ` Marton Balint

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git