summaryrefslogtreecommitdiff
path: root/src/buffer
diff options
context:
space:
mode:
Diffstat (limited to 'src/buffer')
-rw-r--r--src/buffer/frame_queue.h9
-rw-r--r--src/buffer/video.c29
2 files changed, 20 insertions, 18 deletions
diff --git a/src/buffer/frame_queue.h b/src/buffer/frame_queue.h
index ca47457..6626b95 100644
--- a/src/buffer/frame_queue.h
+++ b/src/buffer/frame_queue.h
@@ -17,14 +17,13 @@ enum {
struct camu_frame_queue {
struct camu_video_buffer *buf;
bool (*configure_subtitles)(struct camu_frame_queue *, u32, u32, struct camu_codec_stream *);
- void (*push)(struct camu_frame_queue *, struct camu_codec_frame *, f64);
+ void (*push)(struct camu_frame_queue *, struct camu_codec_frame *, f64, u32 *);
#ifdef CAMU_HAVE_FFMPEG
- void (*push_av_frame)(struct camu_frame_queue *, AVFrame *, f64);
+ void (*push_av_frame)(struct camu_frame_queue *, AVFrame *, f64, u32 *);
#endif
void (*push_subtitle)(struct camu_frame_queue *, struct camu_codec_packet *);
- void (*flush)(struct camu_frame_queue *);
- s32 (*count)(struct camu_frame_queue *);
- u8 (*read)(struct camu_frame_queue *, f64, void *);
+ void (*flush)(struct camu_frame_queue *, u32 *);
+ u8 (*read)(struct camu_frame_queue *, f64, void *, u32 *);
void (*reset)(struct camu_frame_queue *);
void (*free)(struct camu_frame_queue **);
};
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) {