From patchwork Wed Mar 16 14:00:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philip-Dylan Gleonec X-Patchwork-Id: 34792 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6838:3486:0:0:0:0 with SMTP id ek6csp51155nkb; Wed, 16 Mar 2022 07:02:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzybMjUKHM6gDrvvnEUCVYJ4FCqyjeVem5eNdwA8kVFEgKSG/FI39wS7ng6aYWrHETbPJGH X-Received: by 2002:a17:906:a210:b0:6d5:9fa:11ce with SMTP id r16-20020a170906a21000b006d509fa11cemr153232ejy.172.1647439317869; Wed, 16 Mar 2022 07:01:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647439317; cv=none; d=google.com; s=arc-20160816; b=aYVE5cWJ1x5gcC571JPq2/of7fKjJLwD6pgWd6gn1yU9EHadSYWHh+dhMaLObzErL9 eAywDp5682PyurFU4X22/bkLSyggfEY/RKoA8qugM787Ungf6aaBID/zKx0DeE1/57Ft kc2PJsRm5yrTPt7iXF578gOswweC7PYbE9dsBWXlE6kG+pS8nJkr/3jKOhfzbVb1YZwc U09kklwteRtD0rLUjbm4zxZI6BCGtoq0NTSv88UWCtHT1QG0tTvICiCSzTJu0Xz0umxf UgDM/KPzb7f8AjWFZuGhn83+VrYTyzEvd6+N8Z2A5jWIq4HhRZOOHVsOFXmhTo9GRlMa hSww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc: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:delivered-to; bh=GHZmI7xA6w2AVkIdaWRROqaPRgLGIMKYoC09Cog241A=; b=eL/8oq9F5kYof1XJHsysnlqUTzyCtUW7KTuUSJUKQlP+lGCj81AVt/hQaoIpURlOgj zjAHpOPl435/ukKdwTmSbzRZlaTYf8aoqi+8T+SFKF41SDs2yMEWVzK5JGX/fiXus9ix Vr1JlakWR4P6soXLp/ufCd3rv7ltKQETHyjA+9ZsPKQ8VVp9RNK76NxJCRLG5wQzpU6O zcRDXXVA77FxXIhcleo7QoMNm7/SFNYX6vpv512C5cTdVtZpPmhdGW7Ja8/VRwNi42P6 +2CJWgWjzGWrFQ8pW4iRav08qa6fmnP2GZOO24WswAMkPh7TQltoWYeoikhktY+gr1p2 +TQg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id q23-20020a170906771700b006b775f31a5bsi1147635ejm.673.2022.03.16.07.01.57; Wed, 16 Mar 2022 07:01:57 -0700 (PDT) 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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id CBA5D68B00F; Wed, 16 Mar 2022 16:01:53 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail.savoirfairelinux.com (mail.savoirfairelinux.com [208.88.110.44]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3B27168AEE9 for ; Wed, 16 Mar 2022 16:01:47 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by mail.savoirfairelinux.com (Postfix) with ESMTP id 56FA09C0383 for ; Wed, 16 Mar 2022 10:01:46 -0400 (EDT) Received: from mail.savoirfairelinux.com ([127.0.0.1]) by localhost (mail.savoirfairelinux.com [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id MWt_cDIphzdr; Wed, 16 Mar 2022 10:01:46 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mail.savoirfairelinux.com (Postfix) with ESMTP id F078A9C0382; Wed, 16 Mar 2022 10:01:45 -0400 (EDT) X-Virus-Scanned: amavisd-new at mail.savoirfairelinux.com Received: from mail.savoirfairelinux.com ([127.0.0.1]) by localhost (mail.savoirfairelinux.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id tpgEnSGFaw4S; Wed, 16 Mar 2022 10:01:45 -0400 (EDT) Received: from localhost.localdomain (lfbn-ren-1-221-128.w83-205.abo.wanadoo.fr [83.205.67.128]) by mail.savoirfairelinux.com (Postfix) with ESMTPSA id 6E6BB9C036E; Wed, 16 Mar 2022 10:01:45 -0400 (EDT) From: Philip-Dylan Gleonec To: ffmpeg-devel@ffmpeg.org Date: Wed, 16 Mar 2022 15:00:44 +0100 Message-Id: <20220316140045.369016-2-philip-dylan.gleonec@savoirfairelinux.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220316140045.369016-1-philip-dylan.gleonec@savoirfairelinux.com> References: <20220316140045.369016-1-philip-dylan.gleonec@savoirfairelinux.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/2] avcodec/libopusenc: reload packet loss at encode 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 Cc: Philip-Dylan Gleonec Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: BObgfC5qRkzx An estimation of packet loss is required by libopus to compute its FEC data. Currently, this estimation is constant, and can not be changed after configuration. This means an application using libopus through ffmpeg can not adapt the packet loss estimation when the network quality degrades. This patch makes the encoder reload the packet_loss AVOption before encoding samples, if fec is enabled and the packet loss estimation set is different than the current one. This way an application can modify the packet loss estimation by changing the AVOption. Typical use-case is a RTP stream, where packet loss can be estimated from RTCP packets. Signed-off-by: Philip-Dylan Gleonec --- libavcodec/libopusenc.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/libavcodec/libopusenc.c b/libavcodec/libopusenc.c index 45b23fcbb5..b9e2fc45e3 100644 --- a/libavcodec/libopusenc.c +++ b/libavcodec/libopusenc.c @@ -460,6 +460,23 @@ static int libopus_encode(AVCodecContext *avctx, AVPacket *avpkt, uint8_t *audio; int ret; int discard_padding; + int32_t opus_packet_loss = 0; + + ret = opus_multistream_encoder_ctl(opus->enc, + OPUS_GET_PACKET_LOSS_PERC(&opus_packet_loss)); + if (ret != OPUS_OK) + av_log(avctx, AV_LOG_WARNING, + "Unable to get expected packet loss percentage: %s\n", + opus_strerror(ret)); + + if (opus->opts.fec && (opus_packet_loss != opus->opts.packet_loss)) { + ret = opus_multistream_encoder_ctl(opus->enc, + OPUS_SET_PACKET_LOSS_PERC(opus->opts.packet_loss)); + if (ret != OPUS_OK) + av_log(avctx, AV_LOG_WARNING, + "Unable to set expected packet loss percentage: %s\n", + opus_strerror(ret)); + } if (frame) { ret = ff_af_queue_add(&opus->afq, frame);