summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2023-03-22 15:09:49 +0100
committerAnton Khirnov <anton@khirnov.net>2023-04-09 15:47:45 +0200
commit81cca3dae34b78b367a183fd1726d83f67dbf326 (patch)
tree0ca85dce8f74305c095c79de0872d842841c8040
parent9a85245adfdb259da27a50e7822a7c842e5a3247 (diff)
downloadffmpeg-81cca3dae34b78b367a183fd1726d83f67dbf326.tar.gz
fftools/sync_queue: make sure audio duration matches sample count
For audio AVFrames, nb_samples is typically more trustworthy than duration. Since sync queues look at durations, make sure they match the sample count. The last audio frame in the fate-shortest test is now gone. This is more correct, since it outlasts the last video frame.
-rw-r--r--fftools/sync_queue.c15
-rw-r--r--tests/ref/fate/shortest1
2 files changed, 14 insertions, 2 deletions
diff --git a/fftools/sync_queue.c b/fftools/sync_queue.c
index 4204a821c1..5b98253a4a 100644
--- a/fftools/sync_queue.c
+++ b/fftools/sync_queue.c
@@ -116,6 +116,11 @@ static int64_t frame_ts(const SyncQueue *sq, SyncQueueFrame frame)
frame.f->pts + frame.f->duration;
}
+static int frame_samples(const SyncQueue *sq, SyncQueueFrame frame)
+{
+ return (sq->type == SYNC_QUEUE_PACKETS) ? 0 : frame.f->nb_samples;
+}
+
static int frame_null(const SyncQueue *sq, SyncQueueFrame frame)
{
return (sq->type == SYNC_QUEUE_PACKETS) ? (frame.p == NULL) : (frame.f == NULL);
@@ -293,7 +298,7 @@ int sq_send(SyncQueue *sq, unsigned int stream_idx, SyncQueueFrame frame)
SyncQueueStream *st;
SyncQueueFrame dst;
int64_t ts;
- int ret;
+ int ret, nb_samples;
av_assert0(stream_idx < sq->nb_streams);
st = &sq->streams[stream_idx];
@@ -313,6 +318,14 @@ int sq_send(SyncQueue *sq, unsigned int stream_idx, SyncQueueFrame frame)
frame_move(sq, dst, frame);
+ nb_samples = frame_samples(sq, dst);
+ // make sure frame duration is consistent with sample count
+ if (nb_samples) {
+ av_assert0(dst.f->sample_rate > 0);
+ dst.f->duration = av_rescale_q(nb_samples, (AVRational){ 1, dst.f->sample_rate },
+ dst.f->time_base);
+ }
+
ts = frame_ts(sq, dst);
ret = av_fifo_write(st->fifo, &dst, 1);
diff --git a/tests/ref/fate/shortest b/tests/ref/fate/shortest
index be93ff0da1..b5845508cf 100644
--- a/tests/ref/fate/shortest
+++ b/tests/ref/fate/shortest
@@ -115,4 +115,3 @@
0, 48, 48, 1, 11212, 0xc61a3f0a, S=1, 8
1, 85760, 85760, 1536, 418, 0xae06ca91
0, 49, 49, 1, 1423, 0x45fba9e4, F=0x0, S=1, 8
-1, 87296, 87296, 1536, 418, 0x7bdcc3c7