Skip to content
Snippets Groups Projects
Commit c943ba89 authored by Philip-Dylan Gleonec's avatar Philip-Dylan Gleonec Committed by Pierre Lespagnol
Browse files

ffmpeg: reload packet loss for each libopus encode

The libopus codec only reads and impelemnts options from the
AVCodecContext at initialization. This means that packet loss
estimation can not be dynamically set.
This patch corrects this by reloading the packet loss estimation before
each encode. This ensures that each opus packet is encoded with FEC
data corresponding to the last packet loss estimation.
This patch does not check the previous packet loss estimation, as it
would increase software complexity, with one call of
opus_multistream_encoder_ctl() at best when packet loss is unchanged,
and two calls at most (one to get value, one to set value).

Issue: #5157
Change-Id: I3fce82d8b310a5751dc7fbc9a1b766d43c41c304
parent 7c960d55
No related branches found
No related tags found
No related merge requests found
......@@ -24,7 +24,23 @@ index 2a97811d18..40ee7b8fec 100644
OPUS_SET_PACKET_LOSS_PERC(opts->packet_loss));
if (ret != OPUS_OK)
av_log(avctx, AV_LOG_WARNING,
@@ -543,6 +551,7 @@
@@ -452,6 +460,15 @@
int ret;
int discard_padding;
+ // Reload packet loss setting
+ 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)
@@ -543,6 +560,7 @@
{ "audio", "Favor faithfulness to the input", 0, AV_OPT_TYPE_CONST, { .i64 = OPUS_APPLICATION_AUDIO }, 0, 0, FLAGS, "application" },
{ "lowdelay", "Restrict to only the lowest delay modes", 0, AV_OPT_TYPE_CONST, { .i64 = OPUS_APPLICATION_RESTRICTED_LOWDELAY }, 0, 0, FLAGS, "application" },
{ "frame_duration", "Duration of a frame in milliseconds", OFFSET(frame_duration), AV_OPT_TYPE_FLOAT, { .dbl = 20.0 }, 2.5, 120.0, FLAGS },
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment