summaryrefslogtreecommitdiff
path: root/libswresample/swresample.c
diff options
context:
space:
mode:
authorGyan Doshi <ffmpeg@gyani.pro>2023-12-15 12:16:39 +0530
committerGyan Doshi <ffmpeg@gyani.pro>2023-12-18 15:47:04 +0530
commitbe8a4f80b97222d99b4262c9230ca8a1db28973a (patch)
treeabebe63960a360fc6ce05016563cf914d16ae084 /libswresample/swresample.c
parent2ad0b8e0ea36115595f16bca203a5fdaabafb4ab (diff)
swr/swresample: avoid reapplication of firstpts
During a resampling operation where 1) user has specified first_pts 2) SWR_FLAG_RESAMPLE is not set initially (directly or otherwise) 3) first_pts has been fulfilled (always using hard compensation) then upon first encountering a delay where a soft compensation is required, swr_set_compensation will lead to another init of swr which will reset outpts to the specified firstpts thus leading to an output frame having its pts = firstpts. When the next input frame is received, swr will see a large delay and inject silence from firstpts to the current frame's pts. This can lead to severe desync and in worst case, loss of audio playback. Parameter firstpts initialized to AV_NOPTS_VALUE in swr_alloc and then checked in swr_init to avoid resetting outpts, thus avoiding reapplication of firstpts. Fixes #4131.
Diffstat (limited to 'libswresample/swresample.c')
-rw-r--r--libswresample/swresample.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/libswresample/swresample.c b/libswresample/swresample.c
index f2a9b40474..1cf83a803f 100644
--- a/libswresample/swresample.c
+++ b/libswresample/swresample.c
@@ -375,8 +375,9 @@ av_cold int swr_init(struct SwrContext *s){
if (s->firstpts_in_samples != AV_NOPTS_VALUE) {
if (!s->async && s->min_compensation >= FLT_MAX/2)
s->async = 1;
- s->firstpts =
- s->outpts = s->firstpts_in_samples * s->out_sample_rate;
+ if (s->firstpts == AV_NOPTS_VALUE)
+ s->firstpts =
+ s->outpts = s->firstpts_in_samples * s->out_sample_rate;
} else
s->firstpts = AV_NOPTS_VALUE;