[FFmpeg-devel] [PATCH 1/3] librist: replace deprecated functions.
This gets rid of of rist_receiver_data_read, rist_receiver_data_block_free and rist_parse_address these functions have been deprecated since librist release v0.2.1 and are replaced with functions suffixed with 2. I added a version macro check at the top of the file to ensure ffmpeg can still be compiled against older versions. Signed-off-by: Gijs Peskens --- libavformat/librist.c | 37 ++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/libavformat/librist.c b/libavformat/librist.c index 8f51050c3e..b120346f48 100644 --- a/libavformat/librist.c +++ b/libavformat/librist.c @@ -34,10 +34,24 @@ #include "url.h" #include - +#include // RIST_MAX_PACKET_SIZE - 28 minimum protocol overhead #define MAX_PAYLOAD_SIZE (1-28) +#define FF_LIBRIST_MAKE_VERSION(major, minor, patch) \ +((patch) + ((minor)* 0x100) + ((major) *0x1)) +#define FF_LIBRIST_VERSION FF_LIBRIST_MAKE_VERSION(LIBRIST_API_VERSION_MAJOR, LIBRIST_API_VERSION_MINOR, LIBRIST_API_VERSION_PATCH) +//API version 4.1 deprecated: +// rist_receiver_data_read +// rist_receiver_data_callback_set +// rist_receiver_data_block_free +// rist_parse_address +// rist_parse_udp_address +// rist_peer_config_free +// rist_logging_settings_free +// rist_udp_config_free +//And replaced them with functions suffixed with 2 +#define FF_LIBRIST_VERSION_41 FF_LIBRIST_MAKE_VERSION(4, 1, 0) typedef struct RISTContext { const AVClass *class; @@ -146,7 +160,11 @@ static int librist_open(URLContext *h, const char *uri, int flags) if (ret < 0) goto err; +#if FF_LIBRIST_VERSION < FF_LIBRIST_VERSION_41 ret = rist_parse_address(uri, (const struct rist_peer_config **)&peer_config); +#else +ret = rist_parse_address2(uri, &peer_config); +#endif if (ret < 0) goto err; @@ -187,10 +205,16 @@ err: static int librist_read(URLContext *h, uint8_t *buf, int size) { RISTContext *s = h->priv_data; -const struct rist_data_block *data_block; int ret; +#if FF_LIBRIST_VERSION < FF_LIBRIST_VERSION_41 +const struct rist_data_block *data_block; ret = rist_receiver_data_read(s->ctx, &data_block, POLLING_TIME); +#else +struct rist_data_block *data_block; +ret = rist_receiver_data_read2(s->ctx, &data_block, POLLING_TIME); +#endif + if (ret < 0) return risterr2ret(ret); @@ -198,14 +222,21 @@ static int librist_read(URLContext *h, uint8_t *buf, int size) return AVERROR(EAGAIN); if (data_block->payload_len > MAX_PAYLOAD_SIZE) { +#if FF_LIBRIST_VERSION < FF_LIBRIST_VERSION_41 rist_receiver_data_block_free((struct rist_data_block**)&data_block); +#else +rist_receiver_data_block_free2(&data_block); +#endif return AVERROR_EXTERNAL; } size = data_block->payload_len; memcpy(buf, data_block->payload, size); +#if FF_LIBRIST_VERSION < FF_LIBRIST_VERSION_41 rist_receiver_data_block_free((struct rist_data_block**)&data_block); - +#else +rist_receiver_data_block_free2(&data_block); +#endif return size; } -- 2.30.2 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 2/3] librist: allow use of circular buffer for receiving.
libRIST internally stores packets in a fifo of 1024 packets, overwriting old packets when not read in a sufficient pace. Unfortunately this results in many fifo overflow errors when ffmpeg consumes a libRIST stream. This patch creates a receiver thread based on the UDP circular buffer code. Signed-off-by: Gijs Peskens --- libavformat/librist.c | 201 -- 1 file changed, 196 insertions(+), 5 deletions(-) diff --git a/libavformat/librist.c b/libavformat/librist.c index b120346f48..47c01a8432 100644 --- a/libavformat/librist.c +++ b/libavformat/librist.c @@ -26,6 +26,8 @@ #include "libavutil/opt.h" #include "libavutil/parseutils.h" #include "libavutil/time.h" +#include "libavutil/fifo.h" +#include "libavutil/intreadwrite.h" #include "avformat.h" #include "internal.h" @@ -33,6 +35,15 @@ #include "os_support.h" #include "url.h" +#if HAVE_W32THREADS +#undef HAVE_PTHREAD_CANCEL +#define HAVE_PTHREAD_CANCEL 1 +#endif + +#if HAVE_PTHREAD_CANCEL +#include "libavutil/thread.h" +#endif + #include #include // RIST_MAX_PACKET_SIZE - 28 minimum protocol overhead @@ -67,6 +78,19 @@ typedef struct RISTContext { struct rist_peer *peer; struct rist_ctx *ctx; + +int circular_buffer_size; +AVFifoBuffer *fifo; +int circular_buffer_error; +int overrun_nonfatal; + +#if HAVE_PTHREAD_CANCEL +pthread_t receiver_thread; +pthread_mutex_t mutex; +pthread_cond_t cond; +int thread_started; +int thread_stop; +#endif } RISTContext; #define D AV_OPT_FLAG_DECODING_PARAM @@ -82,6 +106,8 @@ static const AVOption librist_options[] = { { "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 }, { "encryption","set encryption type",OFFSET(encryption), AV_OPT_TYPE_INT ,{.i64=0}, 0, INT_MAX, .flags = D|E }, +{ "fifo_size", "set the receiving circular buffer size, expressed as a number of packets with size of 188 bytes, 0 to disable", OFFSET(circular_buffer_size), AV_OPT_TYPE_INT, {.i64 = 7*4096}, 0, INT_MAX, D }, +{ "overrun_nonfatal", "survive in case of receiving circular buffer overrun", OFFSET(overrun_nonfatal), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1,D }, { NULL } }; @@ -119,6 +145,15 @@ static int librist_close(URLContext *h) RISTContext *s = h->priv_data; int ret = 0; +#if HAVE_PTHREAD_CANCEL +if (s->thread_started) { +pthread_mutex_lock(&s->mutex); +s->thread_stop = 1; +pthread_mutex_unlock(&s->mutex); +pthread_join(s->receiver_thread, NULL); +} +#endif +av_fifo_freep(&s->fifo); s->peer = NULL; if (s->ctx) @@ -128,6 +163,78 @@ static int librist_close(URLContext *h) return risterr2ret(ret); } +static void *receiver_thread(void *_url_context) +{ +URLContext *h = _url_context; +RISTContext *s = h->priv_data; +int ret; +uint8_t tmp[4]; +#if FF_LIBRIST_VERSION < FF_LIBRIST_VERSION_41 +const struct rist_data_block *data_block; +#else +struct rist_data_block *data_block; +#endif + +while (1) +{ +pthread_mutex_lock(&s->mutex); +if (s->thread_stop) +break; +pthread_mutex_unlock(&s->mutex); +#if FF_LIBRIST_VERSION < FF_LIBRIST_VERSION_41 +ret = rist_receiver_data_read(s->ctx, &data_block, POLLING_TIME); +#else +ret = rist_receiver_data_read2(s->ctx, &data_block, POLLING_TIME); +#endif +if (ret == 0) +continue; + +pthread_mutex_lock(&s->mutex); +if (ret < 0) { +s->circular_buffer_error = ret; +break; +} + +if (data_block->payload_len > MAX_PAYLOAD_SIZE) { +#if FF_LIBRIST_VERSION < FF_LIBRIST_VERSION_41 +rist_receiver_data_block_free((struct rist_data_block**)&data_block); +#else +rist_receiver_data_block_free2(&data_block); +#endif +s->circular_buffer_error = AVERROR_EXTERNAL; +break; +} +AV_WL32(tmp, data_block->payload_len); +if (av_fifo_space(s->fifo) < (data_block->payload_len +4)) +{ +/* No Space left */ +if (s->overrun_nonfatal) { +av_log(h, AV_LOG_WARNING, "Circular buffer overrun. " +"Surviving due to overrun_nonfatal option\n"); +continue; +} else { +av_log(h, AV_LOG_ERROR, "Circular buffer overrun.
[FFmpeg-devel] [PATCH 3/3] librist: set logsocket config to -1
Signed-off-by: Gijs Peskens --- libavformat/librist.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libavformat/librist.c b/libavformat/librist.c index 47c01a8432..987056ccd1 100644 --- a/libavformat/librist.c +++ b/libavformat/librist.c @@ -245,6 +245,7 @@ static int librist_open(URLContext *h, const char *uri, int flags) if ((flags & AVIO_FLAG_READ_WRITE) == AVIO_FLAG_READ_WRITE) return AVERROR(EINVAL); +s->logging_settings.log_socket = -1; ret = rist_logging_set(&logging_settings, s->log_level, log_cb, h, NULL, NULL); if (ret < 0) return risterr2ret(ret); -- 2.30.2 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 2/2] libRIST: allow setting fifo size and fail on overflow.
Introduce fifo_size and overrun_nonfatal params to configure fifo buffer behavior. Fifo size is used to left shift 2, since libRIST only accepts powers of 2. Use newly introduced RIST_DATA_FLAGS_OVERFLOW flag to check for overrun and error out in that case. --- libavformat/librist.c | 36 1 file changed, 36 insertions(+) diff --git a/libavformat/librist.c b/libavformat/librist.c index 378b635ea7..6f68868f3c 100644 --- a/libavformat/librist.c +++ b/libavformat/librist.c @@ -43,6 +43,9 @@ ((patch) + ((minor)* 0x100) + ((major) *0x1)) #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_DEFAULT_SHIFT 13 typedef struct RISTContext { const AVClass *class; @@ -52,6 +55,8 @@ typedef struct RISTContext { int packet_size; int log_level; int encryption; +int fifo_shift; +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, 3, .flags = D|E }, +{ "fifo_size", "Set libRIST fifo buffer size, applied as: buffer_size=2^fifo_size", OFFSET(fifo_shift), AV_OPT_TYPE_INT, {.i64=FF_LIBRIST_FIFO_DEFAULT_SHIFT}, 10, 63, .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,19 @@ 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, 2 << s->fifo_shift); +if (ret != 0) +goto err; +} +#else +if (s->fifo_buffer_size != FF_LIBRIST_FIFO_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 +243,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-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-devel] [PATCH 1/2] libRIST: Correctly initialize logging_settings
Correct solution as suggested by Martin Balint on ffmpeg-devel --- libavformat/librist.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libavformat/librist.c b/libavformat/librist.c index 6eae90cc2f..378b635ea7 100644 --- a/libavformat/librist.c +++ b/libavformat/librist.c @@ -130,6 +130,7 @@ static int librist_open(URLContext *h, const char *uri, int flags) if ((flags & AVIO_FLAG_READ_WRITE) == AVIO_FLAG_READ_WRITE) return AVERROR(EINVAL); +s->logging_settings = (struct rist_logging_settings)LOGGING_SETTINGS_INITIALIZER; ret = rist_logging_set(&logging_settings, s->log_level, log_cb, h, NULL, NULL); if (ret < 0) return risterr2ret(ret); -- 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-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH 2/2] libRIST: allow setting fifo size and fail on overflow.
Thanks for reviewing again! On 18-11-2021 20:35, Marton Balint wrote: On Wed, 17 Nov 2021, Gijs Peskens wrote: Introduce fifo_size and overrun_nonfatal params to configure fifo buffer behavior. Fifo size is used to left shift 2, since libRIST only accepts powers of 2. Can you please make fifo_size simply mean the number of packets? User facing options should be easily understandable by the user. Even if librist (at the moment) only supports power of two values. Yes, will do. libRIST will error out with a log message when it's not accepted, so I'd forego checking if the chosen number is a power of 2 on the ffmpeg side. Use newly introduced RIST_DATA_FLAGS_OVERFLOW flag to check for overrun and error out in that case. --- libavformat/librist.c | 36 1 file changed, 36 insertions(+) diff --git a/libavformat/librist.c b/libavformat/librist.c index 378b635ea7..6f68868f3c 100644 --- a/libavformat/librist.c +++ b/libavformat/librist.c @@ -43,6 +43,9 @@ ((patch) + ((minor)* 0x100) + ((major) *0x1)) #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_DEFAULT_SHIFT 13 typedef struct RISTContext { const AVClass *class; @@ -52,6 +55,8 @@ typedef struct RISTContext { int packet_size; int log_level; int encryption; + int fifo_shift; + 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, 3, .flags = D|E }, + { "fifo_size", "Set libRIST fifo buffer size, applied as: buffer_size=2^fifo_size", OFFSET(fifo_shift), AV_OPT_TYPE_INT, {.i64=FF_LIBRIST_FIFO_DEFAULT_SHIFT}, 10, 63, .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 }, This changes existing default behaviour slightly by exiting in case of an overflow. I guess that it makes it consistent with udp.c, so fine with me if you think it is better that way. If desired I can reverse the defaults so existing workflows are not impacted (though I doubt many exist due to the young age of the librist module). Though the consistency with udp feels more logical to me. { "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,19 @@ 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, 2 << s->fifo_shift); + if (ret != 0) + goto err; + } +#else + if (s->fifo_buffer_size != FF_LIBRIST_FIFO_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 +243,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); + g
[FFmpeg-devel] [PATCH] libRIST: allow setting fifo size and fail on overflow.
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) *0x1)) #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, 3, .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_VERS
Re: [FFmpeg-devel] [PATCH] libRIST: allow setting fifo size and fail on overflow.
On 11-01-2022 10:43, "zhilizhao(赵志立)" wrote: On Jan 11, 2022, at 5:23 PM, 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 | 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) *0x1)) #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, 3, .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
[FFmpeg-devel] [PATCH] libRIST: allow setting fifo size and fail on overflow.
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) *0x1)) #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, 3, .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 __
Re: [FFmpeg-devel] [PATCH] libRIST: allow setting fifo size and fail on overflow.
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) *0x1)) #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, 3, .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); +
[FFmpeg-devel] [PATCH] libRIST: allow setting fifo size and fail on overflow.
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) *0x1)) #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, 3, .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 _
Re: [FFmpeg-devel] [PATCH] libRIST: allow setting fifo size and fail on overflow.
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) *0x1)) #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, 3, .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 { +a
Re: [FFmpeg-devel] FFmpeg 6.0
On 21-02-2023 12:38, Michael Niedermayer wrote: On Fri, Feb 10, 2023 at 06:47:03PM +0100, Michael Niedermayer wrote: Hi all i plan to branch off release/6.0 from master in the next days If theres something blocking and i should wait, please reply here 6.0 release will be maybe 1 week after the branch point once it has branched all important fixes should be backported of course What name shall 6.0 bear ? ill pick what has the highest number of votes Here are some previously suggested names: Darwin, De broglie, Desitter, Galois, Gauss, Heaviside, Jacobi, Maxwell, Mellin, Perelman, Poincaré, Ramanujan, Sagan, Viterbi, Voltaire, Von Neumann thx [...] Assuming with Desitter the Dutch mathematician (https://en.wikipedia.org/wiki/Willem_de_Sitter) is intended the correct name would be "de Sitter" ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@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-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] How to implement pcap ffmpeg format?
Wouldn't the simplest solution just be a tiny tool that unwraps the pcap stuff and just passes the packet data out on stdout? That's assuming ffmpeg allows receiving RTP packets on stdin. On 21-02-2023 23:55, sonntex wrote: New pcap ffmpeg format can have all options rtpdec requires. Anyway, I don't suggest you implement this feature. I just want to find a good entry point to start coding personally. I need to create a development tool for rtp tracing, and pcap files seem a good idea because I can grab rtp using tcpdump, or create pcap files directly in my application, or whatever. It's better then wrap vp8/vp9 to ivf or h264 to byte stream and pass it to ffmpeg via pipe because it doesn't require coding of new solutions for every video and audio formats transferring over rtp. On Tue, Feb 21, 2023 at 10:38 PM Kieran Kunhya wrote: On Tue, 21 Feb 2023, 22:33 sonntex, wrote: I want to implement something which helps me to play rtp stored in pcap files. tcpdump -i lo udp port 5 -s0 -w - | ffplay -i - The specification of pcap files is really simple and I could create a new ffmpeg format, but don't know how to process rtp packets extracted from pcap, because it seems that all functions for rtp parsing are private. Need a good example of inner ffmpeg formats processing. How is ffmpeg meant to know the meaning of the contents of a pcap and the format inside? This is a very bad idea. What's next, ffmpeg implementing userspace TCP? Are we going to add support for parsing filesystems as well? Regards, Kieran Kunhya ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@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-requ...@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-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] FFmpeg release 6.1 (SDR Plans)
On 21-09-2023 18:21, Michael Niedermayer wrote: Hi all As the 6.1 release is upcoming and as it was previously stated by me that sdr will be part of 6.1. Heres some update of what i intend to do about that. People previously agreed to including a SDR input device in libavdevice with SDR in a seperate library. If the community and the SDR code are happy with each other before the release then SDR will simply be merged and be part of 6.1 like any other feature. OTOH If a majority of people are against the SDR code at the time of branching 6.1. Then i will make a separate release identical to 6.1 with the SDR code and of course also provide security support What does this mean? Does this mean an FFmpeg release containing code that interfaces with your SDR library? Or does it mean the library fully integrated into FFmpeg? Of course iam happy to change my plans if someone has a better suggestion! What i intend to do with SDR next is AVExecutor support to improve processing capacity with multiple threads and also to look into factoring the code so SDR is more seperated, where this will lead to i do not know thx [...] ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@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-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH] avformat/movenc: Remove experimental status of TrueHD-in-MP4 muxing (mlpa)
On 11-11-2022 16:05, Nomis101 wrote: Am 11.11.22 um 14:48 schrieb Nomis101: Am 11.11.22 um 14:05 schrieb Jan Ekström: On Wed, Nov 9, 2022 at 9:15 PM Nomis101 wrote: Am 06.11.22 um 21:57 schrieb Carl Eugen Hoyos: Am Sa., 5. Nov. 2022 um 22:31 Uhr schrieb Nomis101 : Support for mlpa muxing was added back in 2019: http://git.videolan.org/?p=ffmpeg.git;a=commitdiff;h=808a6717e0c584738c60a109afd6d47f4973d619 But it was hidden back then behind FF_COMPLIANCE_EXPERIMENTAL, because it was new and there was no support from other applications. In the meantime there is support in MediaInfo: MediaArea/MediaInfoLib#1258 For VLC: videolan/vlc@9c49f40 Since version 7.3.4 for Infuse: https://community.firecore.com/t/dolby-mlp-mlpa-codec-support/26100/31 And mpv does support this as well. If there was ever a good reason to make this feature experimental, I don't think these applications change the situation. The reason to make this experimental was, because there was no implementation from others at this time. http://ffmpeg.org/pipermail/ffmpeg-devel/2019-August/248435.html Now, there is implementation from others. How many implementation from others will be needed to change the situation? I think the main thing was to have the feature verified by non-FFmpeg things. Basically, if you wrote out a TrueHD file and actual 3rd party implementations that didn't just utilize FFmpeg for reading would happily read it, then the flag should be removed. If the VLC commit did not specifically say "we did it like this to enable support for files that FFmpeg generated" but rather that they followed the spec, then that's one alternative implementation indeed. And if MediaInfo or that Infuse thing also added support for the exact same mapping and that neither specifically utilized FFmpeg internally, then those also apply. Finally, I think the D company has a git repo for "dlb_mp4base", you could check if that supports this mapping. Best regards, Jan OK, thanks Jan for the detailed explanation. I will check D company. Infuse has implemented it independently of FFmpeg. VLC and Mediainfo I do not know. The specs were mentioned in the bug, but also FFmpeg. But both would not implement anything if there was no specification for it. There is also support in "dlb_mp4base": https://github.com/DolbyLaboratories/dlb_mp4base/blob/8da6d4a8fc095a88349fbdac33e7e68fb3b93649/src/mp4_muxer.c#L149 But does it correctly demux a variety of files generated by FFMPEG? ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@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-requ...@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-requ...@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-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [RFC][PATCH] libavformat: add librist protocol
Hi, some feedback from one of the libRIST developers: Testing this patch (via diff found on:https://patchwork.ffmpeg.org/project/ffmpeg/patch/20210126205145.20448-1-one...@gmail.com/ ) I've noticed FFmpeg is not reading fast enough from the libRIST FIFO buffer (which is limited to 1024 packets) causing it to overrun. Unfortunately libRIST had a bug where it kept incrementing the buffer counter indefinitely, this has now been fixed and it will log an error whenever this happens (which is very often with FFmpeg). FFmpeg will need to read the FIFO faster, by calling the librist_read function more often. If that's not possible within the design of FFmpeg the module can either: -use the callback (runs within a libRIST thread context) and store the data_block ptrs in a FIFO -dedicate a thread and store the data_block ptrs in a FIFO The librist_read function can then pop from the fifo, copy out the data, and free the block. Also I suggest to set the default loglevel at least to RIST_LOG_ERROR preferably at least to RIST_LOG_WARN. I'd also suggest changing the default buffer size and the min/max values, the unit is ms. I'd suggest a min of 1 (0 would select the default of libRIST -> 1000) a max somewhere far out enough but limited enough to prevent shooting in the foot (i.e.: 30 seconds worth) and a default of 1000. You can consider disabling advanced profile, libRIST limits profile to MAIN atm, and advanced will likely not be out (VSF spec) before summer (and quite likely much later). How does FFmpeg handle multiplexed streams from libRIST currently? This is not clear to me. I'd think at the very least FFmpeg would need to allow the user to filter to 1 stream based on the tunneled destination port number, as the RIST protocol allows multiple streams to be tunneled into 1 MAIN profile session. Personally I'd also like to be able to get the stats out of ffmpeg, an option for that would be very welcome (simply writing out to a file would be very helpful). Sincerely, Gijs Peskens On 22-12-2020 19:09, onemda at gmail.com (Paul B Mahol) wrote: Signed-off-by: Paul B Mahol --- TODO: What about logging messages? Return codes? File handles? Add support for password? Advanced stuff? --- configure | 5 ++ libavformat/Makefile| 1 + libavformat/librist.c | 164 libavformat/protocols.c | 1 + 4 files changed, 171 insertions(+) create mode 100644 libavformat/librist.c diff --git a/configure b/configure index 90914752f1..462f2dcf64 100755 --- a/configure +++ b/configure @@ -259,6 +259,7 @@ External library support: --enable-libpulseenable Pulseaudio input via libpulse [no] --enable-librabbitmq enable RabbitMQ library [no] --enable-librav1eenable AV1 encoding via rav1e [no] + --enable-librist enable RIST via librist [no] --enable-librsvg enable SVG rasterization via librsvg [no] --enable-librubberband enable rubberband needed for rubberband filter [no] --enable-librtmp enable RTMP[E] support via librtmp [no] @@ -1797,6 +1798,7 @@ EXTERNAL_LIBRARY_LIST=" libpulse librabbitmq librav1e +librist librsvg librtmp libshine @@ -3488,6 +3490,8 @@ unix_protocol_select="network" # external library protocols libamqp_protocol_deps="librabbitmq" libamqp_protocol_select="network" +librist_protocol_deps="librist" +librist_protocol_select="network" librtmp_protocol_deps="librtmp" librtmpe_protocol_deps="librtmp" librtmps_protocol_deps="librtmp" @@ -6404,6 +6408,7 @@ enabled libopus && { enabled libpulse && require_pkg_config libpulse libpulse pulse/pulseaudio.h pa_context_new enabled librabbitmq && require_pkg_config librabbitmq "librabbitmq >= 0.7.1" amqp.h amqp_new_connection enabled librav1e && require_pkg_config librav1e "rav1e >= 0.1.0" rav1e.h rav1e_context_new +enabled librist && require_pkg_config librist "librist >= 0.2" librist/librist.h rist_receiver_create enabled librsvg && require_pkg_config librsvg librsvg-2.0 librsvg-2.0/librsvg/rsvg.h rsvg_handle_render_cairo enabled librtmp && require_pkg_config librtmp librtmp librtmp/rtmp.h RTMP_Socket enabled librubberband && require_pkg_config librubberband "rubberband >= 1.8.1" rubberband/rubberband-c.h rubberband_new -lstdc++ && append librubberband_extralibs "-lstdc++" diff --git a/libavformat/Makefile b/libavformat/Makefile index 97d868081b..799e16c59e 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -652,6 +652,7 @@ OBJS-$(CONFIG_UNIX_PROTOCOL) += unix.o # exter
Re: [FFmpeg-devel] [RFC][PATCH] libavformat: add librist protocol
Thanks for your swift reply! (and for your work on the patch, which I believe I forgot to thank you for) On 22-02-2021 09:17, Paul B Mahol wrote: On Mon, Feb 22, 2021 at 9:10 AM Gijs Peskens wrote: Hi, some feedback from one of the libRIST developers: Testing this patch (via diff found on: https://patchwork.ffmpeg.org/project/ffmpeg/patch/20210126205145.20448-1-one...@gmail.com/ ) I've noticed FFmpeg is not reading fast enough from the libRIST FIFO buffer (which is limited to 1024 packets) causing it to overrun. Unfortunately libRIST had a bug where it kept incrementing the buffer counter indefinitely, this has now been fixed and it will log an error whenever this happens (which is very often with FFmpeg). FFmpeg will need to read the FIFO faster, by calling the librist_read function more often. If that's not possible within the design of FFmpeg the module can either: Unfortunately some other devs disagree with initial patch and thus this issue. I don't think this is as much a matter of opinion as it is a matter of fact ;) Right now we (libRIST) have the output FIFO limited to 1024 packets, I don't see that changing in the near future. Right now FFmpeg RIST input is simply broken, since the FIFO is overflowing repeatedly by as much as 5-600 packets. When the FIFO is full libRIST will (by design) free the oldest packet in it when adding a new packet to the FIFO, so reading it at a lower rate than packet insertion will inevitably lead to discontinuities, which RIST is supposed to prevent. So if the FIFO is to be used it /must/ be read at a rate high enough to prevent overflow. -use the callback (runs within a libRIST thread context) and store the data_block ptrs in a FIFO That can not be used by FFmpeg API unfortunately. -dedicate a thread and store the data_block ptrs in a FIFO The librist_read function can then pop from the fifo, copy out the data, and free the block. Also I suggest to set the default loglevel at least to RIST_LOG_ERROR preferably at least to RIST_LOG_WARN. I'd also suggest changing the default buffer size and the min/max values, the unit is ms. I'd suggest a min of 1 (0 would select the default of libRIST -> 1000) a max somewhere far out enough but limited enough to prevent shooting in the foot (i.e.: 30 seconds worth) and a default of 1000. You can consider disabling advanced profile, libRIST limits profile to MAIN atm, and advanced will likely not be out (VSF spec) before summer (and quite likely much later). How does FFmpeg handle multiplexed streams from libRIST currently? This is not clear to me. I'd think at the very least FFmpeg would need to allow the user to filter to 1 stream based on the tunneled destination port number, as the RIST protocol allows multiple streams to be tunneled into 1 MAIN profile session. Personally I'd also like to be able to get the stats out of ffmpeg, an option for that would be very welcome (simply writing out to a file would be very helpful). Sincerely, Gijs Peskens On 22-12-2020 19:09, onemda at gmail.com (Paul B Mahol) wrote: Signed-off-by: Paul B Mahol --- TODO: What about logging messages? Return codes? File handles? Add support for password? Advanced stuff? --- configure | 5 ++ libavformat/Makefile| 1 + libavformat/librist.c | 164 libavformat/protocols.c | 1 + 4 files changed, 171 insertions(+) create mode 100644 libavformat/librist.c diff --git a/configure b/configure index 90914752f1..462f2dcf64 100755 --- a/configure +++ b/configure @@ -259,6 +259,7 @@ External library support: --enable-libpulseenable Pulseaudio input via libpulse [no] --enable-librabbitmq enable RabbitMQ library [no] --enable-librav1eenable AV1 encoding via rav1e [no] + --enable-librist enable RIST via librist [no] --enable-librsvg enable SVG rasterization via librsvg [no] --enable-librubberband enable rubberband needed for rubberband filter [no] --enable-librtmp enable RTMP[E] support via librtmp [no] @@ -1797,6 +1798,7 @@ EXTERNAL_LIBRARY_LIST=" libpulse librabbitmq librav1e +librist librsvg librtmp libshine @@ -3488,6 +3490,8 @@ unix_protocol_select="network" # external library protocols libamqp_protocol_deps="librabbitmq" libamqp_protocol_select="network" +librist_protocol_deps="librist" +librist_protocol_select="network" librtmp_protocol_deps="librtmp" librtmpe_protocol_deps="librtmp" librtmps_protocol_deps="librtmp" @@ -6404,6 +6408,7 @@ enabled libopus && { enabled libpulse && require_pkg_config libpulse libpulse pulse/pulseaudio.h pa_context_new enabled librabbitmq && require_pkg_config librabbitmq "librabbitmq &g
Re: [FFmpeg-devel] [RFC] financial sustainability Plan A (SPI)
On 26-10-2023 17:45, Michael Niedermayer wrote: To help 2. we should favor flashy, cool development that can bring in more donations Wouldn't it make more sense to fund grunt work that's needed, but no-one wants to do? I'd imagine there's more developers that like to have their name attached to flashy cool new advertisable features and less to "boring" "reworked X for stability" ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".