From patchwork Wed Nov 17 14:19:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gijs Peskens X-Patchwork-Id: 31461 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:d206:0:0:0:0:0 with SMTP id q6csp828885iob; Wed, 17 Nov 2021 06:20:03 -0800 (PST) X-Google-Smtp-Source: ABdhPJzLYZ3ozVtrVMpthqpoIxiFpTSP/jxRhhY5E+UtjbeSB244W7TQWc+eSmT9DLc4TXENln+J X-Received: by 2002:a17:907:94c4:: with SMTP id dn4mr22004427ejc.512.1637158802846; Wed, 17 Nov 2021 06:20:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1637158802; cv=none; d=google.com; s=arc-20160816; b=F8YHQAEEkgppC27/xog2KwEgOvZNX2iwAnM+35ixioX5O6iIC5G8/V9YBEyhMyULKw m5AKj6dYSo4J4u4kAABM4fPLi/Bb1j3kfrbpyF6AFRe9GBsOa+rDPEQx7HAKEv01TSwD MQmGgzvG6TAXBdXOMCibhrtut7tIyZJbpinwpV8RT8eiXoIKDkzUzUV5c5ZqVgyM7+h7 sIud7/PqnWyfPh6/XmzyQexXEUtAMgglXXsVMKeqRGx9jA84eS0PFVB9EDuzAVXJHiKt gy8HO285/CGe+1d85O2W/iTeZ/FM3iJAQzuWlrhoQtuwZgp5Rhqrf9lksZSYH4Kcr3pb gnLA== 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=bmoQkW9Kh7pz088VdutHrYYK7bfBuFdki8k8Hllz+qU=; b=Gt71nt7HiEHdEBJmGVdQHAUF+CzKBv3MNcj6RO8tsNUNsKy6Nf/nV3/UUuCEmHKKWm YGkBWYL+GPF8A2kkfhoAy8pu8UccK1Qpj/Zm1gRM9XEqzZFhGhJLYHJ43Qin8kUGfzLy BMW807MPx0JZ13YdSdORoD7i4UlM86bTTNhk3BWK3BLBEg5JJDPOgEb1Q+i/zKkkyU/n r2hmRZ09Qjpl2JzCa2YTaKo1hTj8KastzF16qSF+eDQb76JFq/3VIc2LjFn+68Pc8KAI wlQlp7rk95eFD6jB1XREnh3tzvdcQCaw8gBFNhSSC/hVJJTNhMcXQK8wgUltH/X9GSXD GJnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@heteigenwijsje.nl header.s=dkim header.b=YbUbXw+u; 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 sb42si63195900ejc.480.2021.11.17.06.20.01; Wed, 17 Nov 2021 06:20:02 -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=YbUbXw+u; 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 E489168AE10; Wed, 17 Nov 2021 16:19:41 +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 4FEB168A636 for ; Wed, 17 Nov 2021 16:19:34 +0200 (EET) Received: from mail.heteigenwijsje.nl (localhost [127.0.0.1]) by smtp.heteigenwijsje.nl (Postfix) with ESMTP id 77ED79BA30 for ; Wed, 17 Nov 2021 15:15:10 +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=1637158508; x=1639750509; bh=P+LK6cT+2Im/lRKd6cZvjtHshGy 1ek7RBFxBUnLPCRc=; b=YbUbXw+ucLd7pBeMQwae5Pd9JlS/X6SYY9UTgTN0MHa nLvAbGrV6Vfrbo9Atm6+eqrqV4rHZUl4jDqGo3tbQMel9Lz1RgM5Th56m0TnX4zW BxlP6EbO/jBW6e7T6pdBu+GZkoNeT0gYvpQ80FJva3fedO4FzKxkohPRZ6agQDLY = 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 LDdSVGzFx9De for ; Wed, 17 Nov 2021 15:15:08 +0100 (CET) Received: from smtp.heteigenwijsje.nl (localhost [127.0.0.1]) by smtp.heteigenwijsje.nl (Postfix) with ESMTP id 2B28A9B265 for ; Wed, 17 Nov 2021 15:15:08 +0100 (CET) Received: from gijs-desktop.in2ip.nl ([94.208.100.217]) by smtp.heteigenwijsje.nl with ESMTPSA id 6BvGCGwOlWH2ygAAc3PRCQ (envelope-from ) for ; Wed, 17 Nov 2021 15:15:08 +0100 From: Gijs Peskens To: ffmpeg-devel@ffmpeg.org Date: Wed, 17 Nov 2021 15:19:28 +0100 Message-Id: <20211117141929.1164334-1-gijs@peskens.net> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/2] libRIST: Correctly initialize logging_settings 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: l2Ggi1t3NkZy 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); From patchwork Wed Nov 17 14:19:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gijs Peskens X-Patchwork-Id: 31462 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:d206:0:0:0:0:0 with SMTP id q6csp828597iob; Wed, 17 Nov 2021 06:19:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJxBlXDVBgZNl2jN7fv65uVpJpBn6vksRspjN0XF9DGdj79A5PU4GCAfiNuBKxfoLKrbkM3K X-Received: by 2002:a17:906:3157:: with SMTP id e23mr22336844eje.359.1637158788448; Wed, 17 Nov 2021 06:19:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1637158788; cv=none; d=google.com; s=arc-20160816; b=ldFEKWjR7sQ9FXXwsl8NNvgwaD08jefokVLRnM/HEZ4dR+gsXtG943CROOy+xIUKuo 52AziqqtkiaVyYnHjRN1Xa+vjbC8o/O6/qGjKREhCYrx4zhWdP1vL0flwVk+y6XMDO6Q l2PTwIyoKUntvGbfr3Rwk4ffwbFEltkff0ts1DYx1Qt1dRnX1qqKijVxHN4egszj6eJR v9IcMdv8/b9m4e+a3qJbbFCNV5wtJy5hD1SjLMnTNXsOLDTZTb/5m/H9yiRLrCmas0h+ 68D8VVAcUXJHZj3JvHegui9mIeOmfTBGv6Y11Oal6/pRzKHlOD7xaKrQNw4WyZVpw6Nw iXzw== 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:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=nYo22Ux5Kyz+6I/q15k/uQ7yxEHQkCzqdy4mvAo6D9k=; b=r4pTvo6Z2ClGYqXCD0V8ShtRI83oAwcqFLjGuaIDuNiZjNGgSFLcCbaTwHz7STtJxy dF1LizRMySswNjfxgbpAIrXDUK+ZfGEWoFJHgvvKA9kwJ9ygPCG/e6IPYvU/Kcf14x/Q eJTrYqcrVxxjt6eIxkhS0S6/iovx+v/yiGEL7WaXWf5COlMs+2ooq+z2LoqB40g2jGW8 x8a+W5VzfRolgO++5nGbFauqqYucbDLr7Z/c056Foo0lX2Obrblh/ooasokgLHyw+55P HwMv6F5+EdFIfvKeF3vDwhpzf7LCOydMUHzEp/aJ4MmBMpMkcaiLaoamECvYk0NEqI52 q/sw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@heteigenwijsje.nl header.s=dkim header.b=QDNtUt+e; 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 qw34si55405461ejc.778.2021.11.17.06.19.46; Wed, 17 Nov 2021 06:19:48 -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=QDNtUt+e; 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 EE1B968AD50; Wed, 17 Nov 2021 16:19:40 +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 4D08D6806E2 for ; Wed, 17 Nov 2021 16:19:34 +0200 (EET) Received: from mail.heteigenwijsje.nl (localhost [127.0.0.1]) by smtp.heteigenwijsje.nl (Postfix) with ESMTP id 75DD69B912 for ; Wed, 17 Nov 2021 15:15:10 +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 :references:in-reply-to:x-mailer:message-id:date:date:subject :subject:to:from:from; s=dkim; t=1637158508; x=1639750509; bh=za U407KLoNUvuMEfgFDbc053Y4ZmGCTmOjNhTRDD/O4=; b=QDNtUt+eIgWM66BzHR OLM1ng5zXvOzFttBK/qIbGEtmRqBl5XZWeGqoD+1pWQDlfIVEu6fED//d75ICK6K Fc6XZaa+VCMaz90lDUo8RH7IMrFRqwycGneIcnjRHYeam3ytkjOKPL0DbeBqSEAW U3A6Nlj970/MFlIUDxKnr13hs= 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 wPya5jfTDz-d for ; Wed, 17 Nov 2021 15:15:08 +0100 (CET) Received: from smtp.heteigenwijsje.nl (localhost [127.0.0.1]) by smtp.heteigenwijsje.nl (Postfix) with ESMTP id 57F249B9F5 for ; Wed, 17 Nov 2021 15:15:08 +0100 (CET) Received: from gijs-desktop.in2ip.nl ([94.208.100.217]) by smtp.heteigenwijsje.nl with ESMTPSA id UPEnFGwOlWH2ygAAc3PRCQ (envelope-from ) for ; Wed, 17 Nov 2021 15:15:08 +0100 From: Gijs Peskens To: ffmpeg-devel@ffmpeg.org Date: Wed, 17 Nov 2021 15:19:29 +0100 Message-Id: <20211117141929.1164334-2-gijs@peskens.net> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211117141929.1164334-1-gijs@peskens.net> References: <20211117141929.1164334-1-gijs@peskens.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/2] 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: J8UG4vzpkS5d 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) *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_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, 30000, .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