From patchwork Tue Jan 11 09:23:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gijs Peskens X-Patchwork-Id: 33203 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp3521816iog; Tue, 11 Jan 2022 01:23:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJzGnxhCu2CY5PZc717/Zrk10ojGitd++ql4lsZxFXa9pV0rulhn40ZYkGaB/3tMRhm9enUY X-Received: by 2002:a17:906:4b06:: with SMTP id y6mr3053293eju.354.1641893038440; Tue, 11 Jan 2022 01:23:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1641893038; cv=none; d=google.com; s=arc-20160816; b=T+jWpnaFm49E/WPdt+pwMRM4GzmGk6hyaWHdjloj979VR5kAv5jx160m6Ak++YwCUj gzRZEE/QJtVOqcCW9RlYqMdWt7h5YWXRja3XnsxxpIlLrtW+f2GzFALHzgbL7GHyDDEX DmLW3JZXW+xSBIXBvvPo12O2umjhHFEcz2LX9FwXsW5/jNV6+C4LMsO+OpWJgXmJEWbP /8nYMoPxcESyyPkmnDZtdyywBpBmD/ifGYb+sgNzs6qkGSpU4y/jjxadVVaxGKdRqnr3 nKQwzKVd68sUOXDfTHOCmZJGJ0ie1gADZdF6lOghkCEr1AoKAWUMpS0kDtl0q897vO6t aHaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:message-id:date:to:from :dkim-signature:delivered-to; bh=wYibndW8IcnBrX3c4M0BWHnuZBHRqBW5qSDG7LxTfO0=; b=d8ZCSBxT3C7uedB/0pE3fCMAzip2x3E8iaKHp0m821dhufNXmdoqyM6mingmF4Tibj 4C+ylP/Kf6mpaiFj9ipu4MR2tHqF7VdTSCCuv65M8VgIWypGLEzQcoHrtJeEjYKtFzDa yQbaxuuhA2m5bvDkGKdfIBxPydQysdKaURogKQfz/t2lJiMn2xz8fdn6pX8yrnuAjREF y39IFNxfrheckAGgb6Wqb4LU32hYqvshZIMyeHtvJvHhCOKTtjPD7afXaZz4GxkVdzLZ hJKQ1+BLxksH1+1zzvDFWSE4rJQhCQd95hhLacTDvKQYxESCWsHI+MGfwtgixpGZDMdp mnUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@heteigenwijsje.nl header.s=dkim header.b=MbeIYH2d; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=peskens.net Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id n11si5035257edx.532.2022.01.11.01.23.56; Tue, 11 Jan 2022 01:23:58 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@heteigenwijsje.nl header.s=dkim header.b=MbeIYH2d; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=peskens.net Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E465668ADF7; Tue, 11 Jan 2022 11:23:52 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from smtp.heteigenwijsje.nl (unknown [185.216.161.180]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C090E68818E for ; Tue, 11 Jan 2022 11:23:46 +0200 (EET) Received: from mail.heteigenwijsje.nl (localhost [127.0.0.1]) by smtp.heteigenwijsje.nl (Postfix) with ESMTP id B13948CCFB for ; Tue, 11 Jan 2022 10:18:36 +0100 (CET) Authentication-Results: mail.heteigenwijsje.nl (amavisd-new); dkim=pass (1024-bit key) reason="pass (just generated, assumed good)" header.d=heteigenwijsje.nl DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= heteigenwijsje.nl; h=content-transfer-encoding:mime-version :x-mailer:message-id:date:date:subject:subject:to:from:from; s= dkim; t=1641892710; x=1644484711; bh=RgpnaYwc6DlaniJhHvrj/x5ps+A Gzvua4na7x339aAY=; b=MbeIYH2dXF+SZkm9g7UqQOAqjvwGglUWt/rahIiIefq jm8fsM/Wg1eEZe6qfWwEFe+oFHn8xhMotKKQ9brPNDF9ZXz1cDY5XK1VQrGgCLR5 0zdOUb2fziL2P6c3FfKIdMLT2bSUsQ7v3tjRkEa+sGydon8RT4yiZ7tYwk38MrNQ = X-Virus-Scanned: amavisd-new at mail.heteigenwijsje.nl Received: from smtp.heteigenwijsje.nl ([127.0.0.1]) by mail.heteigenwijsje.nl (mail.heteigenwijsje.nl [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id Jl3k74t1I-74 for ; Tue, 11 Jan 2022 10:18:30 +0100 (CET) Received: from smtp.heteigenwijsje.nl (localhost [127.0.0.1]) by smtp.heteigenwijsje.nl (Postfix) with ESMTP id 05C1B8C7FC for ; Tue, 11 Jan 2022 10:18:30 +0100 (CET) Received: from unknown ([2001:985:7aa4:1:40c0:375f:e41:372b]) by smtp.heteigenwijsje.nl with ESMTPSA id MFurAGZL3WFfFAEAc3PRCQ (envelope-from ) for ; Tue, 11 Jan 2022 10:18:30 +0100 From: Gijs Peskens To: ffmpeg-devel@ffmpeg.org Date: Tue, 11 Jan 2022 10:23:38 +0100 Message-Id: <20220111092338.194468-1-gijs@peskens.net> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] libRIST: allow setting fifo size and fail on overflow. X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: EjC14UTra2X3 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