summaryrefslogtreecommitdiff
path: root/src/buffer/video.c
diff options
context:
space:
mode:
authorAndrew Opalach <andrew@akon.city> 2026-07-02 17:58:38 -0400
committerAndrew Opalach <andrew@akon.city> 2026-07-02 18:00:10 -0400
commit38cce5e94a10e5420e4685bbe5ebb1aade6d522f (patch)
treee2e49e69c225a9f9a224d02ae1f7a5c27af91f19 /src/buffer/video.c
parent34933b7e1d682e67702999270cd3ceec0e167316 (diff)
downloadcamu-38cce5e94a10e5420e4685bbe5ebb1aade6d522f.tar.gz
camu-38cce5e94a10e5420e4685bbe5ebb1aade6d522f.tar.bz2
camu-38cce5e94a10e5420e4685bbe5ebb1aade6d522f.zip
Allow count to be more correct in frame_queue API
queue_libplacebo's behavior is currently unchanged, though. Signed-off-by: Andrew Opalach <andrew@akon.city>
Diffstat (limited to 'src/buffer/video.c')
-rw-r--r--src/buffer/video.c29
1 files changed, 16 insertions, 13 deletions
diff --git a/src/buffer/video.c b/src/buffer/video.c
index fac08b9..1c37403 100644
--- a/src/buffer/video.c
+++ b/src/buffer/video.c
@@ -22,9 +22,11 @@
#define BUFFER_MARK_RESET (BUFFER_MARK_HIGH * 2)
#else
#define BUFFER_MARK_LOW 4
-#define BUFFER_MARK_BUFFERED 6 // Must be >1.
-#define BUFFER_MARK_HIGH 8
-#define BUFFER_MARK_RESET (BUFFER_MARK_HIGH * 2)
+#define BUFFER_MARK_BUFFERED 7 // Must be >1.
+#define BUFFER_MARK_HIGH 9
+// Keep MARK_RESET high because currently the decoder can produce an
+// unpredictable amount of frames at any point.
+#define BUFFER_MARK_RESET (BUFFER_MARK_HIGH * 4)
#endif
bool camu_video_buffer_init(struct camu_video_buffer *buf, struct camu_clock *clock)
@@ -125,7 +127,7 @@ void camu_video_buffer_set_latency(struct camu_video_buffer *buf, f64 latency)
}
#ifdef CAMU_HAVE_FFMPEG
-static bool push_av_frame_internal(struct camu_video_buffer *buf, AVFrame *frame)
+static bool push_av_frame_internal(struct camu_video_buffer *buf, AVFrame *frame, u32 *count)
{
AVStream *stream = buf->stream->av.stream;
f64 pts = frame->best_effort_timestamp * av_q2d(stream->time_base);
@@ -143,7 +145,7 @@ static bool push_av_frame_internal(struct camu_video_buffer *buf, AVFrame *frame
av_frame_free(&frame);
frame = av_frame_clone(buf->scaler->get_frame(buf->scaler)->av.frame);
}
- buf->queue->push_av_frame(buf->queue, frame, pts);
+ buf->queue->push_av_frame(buf->queue, frame, pts, count);
return true;
}
#endif
@@ -160,18 +162,19 @@ void camu_video_buffer_push(struct camu_video_buffer *buf, struct camu_codec_fra
return;
}
+ u32 count;
switch (frame->mode) {
case CAMU_NORMAL: {
f64 base_pts = atomic_load(f64)(&buf->pts, AL_ATOMIC_ACQUIRE);
if (base_pts == -1.0) {
atomic_store(f64)(&buf->pts, 0.0, AL_ATOMIC_RELEASE);
}
- buf->queue->push(buf->queue, frame, 0.0);
+ buf->queue->push(buf->queue, frame, 0.0, &count);
break;
}
#ifdef CAMU_HAVE_FFMPEG
case CAMU_FFMPEG_COMPAT: {
- if (!push_av_frame_internal(buf, frame->av.frame)) {
+ if (!push_av_frame_internal(buf, frame->av.frame, &count)) {
camu_codec_frame_discard(frame);
return;
}
@@ -181,12 +184,11 @@ void camu_video_buffer_push(struct camu_video_buffer *buf, struct camu_codec_fra
#endif
}
- s32 count = buf->queue->count(buf->queue);
if (!buf->buffered && (buf->is_static || count >= BUFFER_MARK_BUFFERED)) {
// Preserve order of: set flow -> flush -> callback, for static buffers.
if (buf->is_static) {
atomic_store(u32)(&buf->flow, FLUSHED, AL_ATOMIC_RELEASE);
- buf->queue->flush(buf->queue);
+ buf->queue->flush(buf->queue, &count);
}
buf->buffered = true;
buf->buffered_with_one_frame = count == 1;
@@ -212,9 +214,9 @@ void camu_video_buffer_flush(struct camu_video_buffer *buf, bool error)
log_debug("Flush requested.");
u8 flow = error ? FLUSHED_ERROR : FLUSHED;
atomic_store(u32)(&buf->flow, flow, AL_ATOMIC_RELAXED);
- buf->queue->flush(buf->queue);
+ u32 count;
+ buf->queue->flush(buf->queue, &count);
if (!buf->buffered) {
- s32 count = buf->queue->count(buf->queue);
buf->buffered = true;
buf->buffered_with_one_frame = count == 1;
log_debug("Buffered (mark: %.2fs).", count * buf->avg_frame_duration);
@@ -251,7 +253,9 @@ bool camu_video_buffer_read(struct camu_video_buffer *buf, void *out, bool *weig
u8 flow = atomic_load(u32)(&buf->flow, AL_ATOMIC_ACQUIRE);
if (flow == ERRORED) return false;
- u8 ret = buf->queue->read(buf->queue, base_pts, out);
+
+ u32 count;
+ u8 ret = buf->queue->read(buf->queue, base_pts, out, &count);
if (ret == CAMU_QUEUE_ERR || flow == FLUSHED_ERROR) {
buf->callback(buf->userdata, CAMU_BUFFER_ERRORED);
atomic_store(u32)(&buf->flow, ERRORED, AL_ATOMIC_RELEASE);
@@ -274,7 +278,6 @@ bool camu_video_buffer_read(struct camu_video_buffer *buf, void *out, bool *weig
atomic_store(u32)(&buf->flow, SIGNALED, AL_ATOMIC_RELEASE);
} else if (flow == FLOWING) {
// Never attempt to uncork if flow = FLUSHED.
- s32 count = buf->queue->count(buf->queue);
if (count <= BUFFER_MARK_LOW) {
buf->callback(buf->userdata, CAMU_BUFFER_UNCORK);
} else if (count >= BUFFER_MARK_RESET) {