diff mbox series

[FFmpeg-devel] avcodec/libopusenc: reload packet loss at encode

Message ID 20210216140425.166567-1-philip-dylan.gleonec@savoirfairelinux.com
State New
Headers show
Series [FFmpeg-devel] avcodec/libopusenc: reload packet loss at encode
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Philip-Dylan Gleonec Feb. 16, 2021, 2:04 p.m. UTC
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. 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 <philip-dylan.gleonec@savoirfairelinux.com>
---
 libavcodec/libopusenc.c | 9 +++++++++
 1 file changed, 9 insertions(+)

Comments

Philip-Dylan Gleonec March 3, 2021, 3:50 p.m. UTC | #1
Le 16/02/2021 à 15:04, Philip-Dylan Gleonec a écrit :
> 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. 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 <philip-dylan.gleonec@savoirfairelinux.com>
> ---
>   libavcodec/libopusenc.c | 9 +++++++++
>   1 file changed, 9 insertions(+)
> 
> diff --git a/libavcodec/libopusenc.c b/libavcodec/libopusenc.c
> index 70d17f802b..c18e8ae7fa 100644
> --- a/libavcodec/libopusenc.c
> +++ b/libavcodec/libopusenc.c
> @@ -460,6 +460,15 @@ static int libopus_encode(AVCodecContext *avctx, AVPacket *avpkt,
>       int ret;
>       int discard_padding;
>   
> +    if (opus->opts.fec) {
> +        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);
>           if (ret < 0)
> 

Hello,

Is someone interested in picking this up, or is there some correction I 
should make to this patch ?

Regards,
Philip-Dylan Gleonec
diff mbox series

Patch

diff --git a/libavcodec/libopusenc.c b/libavcodec/libopusenc.c
index 70d17f802b..c18e8ae7fa 100644
--- a/libavcodec/libopusenc.c
+++ b/libavcodec/libopusenc.c
@@ -460,6 +460,15 @@  static int libopus_encode(AVCodecContext *avctx, AVPacket *avpkt,
     int ret;
     int discard_padding;
 
+    if (opus->opts.fec) {
+        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);
         if (ret < 0)