summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/buffer/video.c22
-rw-r--r--src/buffer/video.h2
-rw-r--r--src/buffer/video_null.h4
-rw-r--r--src/libsink/sink.c60
-rw-r--r--src/render/renderer_libplacebo.c2
5 files changed, 44 insertions, 46 deletions
diff --git a/src/buffer/video.c b/src/buffer/video.c
index 5a469a4..fac08b9 100644
--- a/src/buffer/video.c
+++ b/src/buffer/video.c
@@ -33,7 +33,7 @@ bool camu_video_buffer_init(struct camu_video_buffer *buf, struct camu_clock *cl
buf->latency = 0.0;
atomic_store(f64)(&buf->pts, -1.0, AL_ATOMIC_RELAXED);
buf->seek_pts = -1.0;
- buf->single_frame = true;
+ buf->is_static = true;
buf->queue = NULL;
buf->buffered = false;
buf->weighted_first_read = false;
@@ -55,7 +55,7 @@ bool camu_video_buffer_configure(struct camu_video_buffer *buf, struct camu_code
const char *format_name = camu_pixel_format_name(fmt->format);
switch (stream->mode) {
case CAMU_NORMAL: {
- buf->single_frame = true;
+ buf->is_static = true;
buf->avg_frame_duration = 0.0;
log_info("Stream: %s (%ux%u) IMAGE.", format_name, fmt->width, fmt->height);
break;
@@ -63,8 +63,8 @@ bool camu_video_buffer_configure(struct camu_video_buffer *buf, struct camu_code
#ifdef CAMU_HAVE_FFMPEG
case CAMU_FFMPEG_COMPAT: {
AVRational frame_rate = stream->av.stream->avg_frame_rate;
- buf->single_frame = stream->duration == 0 || frame_rate.den == 0;
- if (buf->single_frame) {
+ buf->is_static = stream->duration == 0 || frame_rate.den == 0;
+ if (buf->is_static) {
buf->avg_frame_duration = 0.0;
log_info("Stream: %s (%ux%u) IMAGE.", format_name, fmt->width, fmt->height);
} else {
@@ -131,7 +131,7 @@ static bool push_av_frame_internal(struct camu_video_buffer *buf, AVFrame *frame
f64 pts = frame->best_effort_timestamp * av_q2d(stream->time_base);
f64 base_pts = atomic_load(f64)(&buf->pts, AL_ATOMIC_ACQUIRE);
f64 duration = camu_ff_frame_duration(frame) * av_q2d(stream->time_base);
- if (!buf->single_frame && frame_is_late(buf->clock, base_pts, pts, duration)) {
+ if (!buf->is_static && frame_is_late(buf->clock, base_pts, pts, duration)) {
log_trace("Discarding late frame with PTS %f.", pts);
return false;
}
@@ -152,8 +152,8 @@ void camu_video_buffer_push(struct camu_video_buffer *buf, struct camu_codec_fra
{
u8 flow = atomic_load(u32)(&buf->flow, AL_ATOMIC_ACQUIRE);
if (flow != FLOWING) {
- // A single frame will be FLUSHED after any push().
- if (buf->single_frame) {
+ // A static buffer will be FLUSHED after any push().
+ if (buf->is_static) {
log_warn("Unexpected duplicate frame received.");
}
camu_codec_frame_discard(frame);
@@ -182,9 +182,9 @@ void camu_video_buffer_push(struct camu_video_buffer *buf, struct camu_codec_fra
}
s32 count = buf->queue->count(buf->queue);
- if (!buf->buffered && (buf->single_frame || count >= BUFFER_MARK_BUFFERED)) {
- // Preserve order of: set flow -> flush -> callback, for single frames.
- if (buf->single_frame) {
+ 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);
}
@@ -240,7 +240,7 @@ bool camu_video_buffer_read(struct camu_video_buffer *buf, void *out, bool *weig
al_assert(buf->buffered);
f64 base_pts = atomic_load(f64)(&buf->pts, AL_ATOMIC_ACQUIRE);
- if (!buf->single_frame) {
+ if (!buf->is_static) {
bool allow_set = !buf->weighted_first_read;
bool armed_for_pause = false;
f64 pts = camu_clock_get_pts(buf->clock, buf->latency, allow_set, &armed_for_pause);
diff --git a/src/buffer/video.h b/src/buffer/video.h
index 112688a..19dfd6e 100644
--- a/src/buffer/video.h
+++ b/src/buffer/video.h
@@ -19,7 +19,7 @@ struct camu_video_buffer {
atomic(f64) pts;
f64 seek_pts;
- bool single_frame;
+ bool is_static;
f64 avg_frame_duration;
struct camu_scaler_format fmt;
diff --git a/src/buffer/video_null.h b/src/buffer/video_null.h
index da9d969..90eb2c2 100644
--- a/src/buffer/video_null.h
+++ b/src/buffer/video_null.h
@@ -9,7 +9,7 @@
struct camu_video_buffer {
struct camu_codec_stream *stream;
f64 seek_pts;
- bool single_frame;
+ bool is_static;
f64 avg_frame_duration;
#ifdef CAMU_SCREEN_THREADED
atomic(bool) ref;
@@ -28,7 +28,7 @@ AL_IGNORE_WARNING("-Wunused-function")
static bool camu_video_buffer_init(struct camu_video_buffer *buf, struct camu_clock *clock)
{
(void)clock;
- buf->single_frame = true;
+ buf->is_static = true;
buf->avg_frame_duration = 0.0;
#ifdef CAMU_SCREEN_THREADED
al_atomic_store(bool)(&buf->ref, false, AL_ATOMIC_RELAXED);
diff --git a/src/libsink/sink.c b/src/libsink/sink.c
index 80f40cd..6c061a5 100644
--- a/src/libsink/sink.c
+++ b/src/libsink/sink.c
@@ -95,10 +95,10 @@ AL_STATIC_ASSERT(max_age_lt_lru, ENTRY_MAX_AGE, <, SINK_LRU_MAX);
#define AUDIO_STREAM(entry) ((al_assert(!AUDIO_EMPTY(entry)), (entry)->audio.buf.stream))
#define VIDEO_STREAM(entry) ((al_assert(!VIDEO_EMPTY(entry)), (entry)->video.buf.stream))
-#define VIDEO_IS_SINGLE_FRAME(entry) ((al_assert(!VIDEO_EMPTY(entry)), (entry)->video.buf.single_frame))
+#define VIDEO_IS_STATIC(entry) ((al_assert(!VIDEO_EMPTY(entry)), (entry)->video.buf.is_static))
#define ENTRY_EVAL_ENDED(entry) \
- ((AUDIO_ENDED(entry) && (VIDEO_ENDED(entry) || VIDEO_EMPTY(entry) || VIDEO_IS_SINGLE_FRAME(entry))) || \
+ ((AUDIO_ENDED(entry) && (VIDEO_ENDED(entry) || VIDEO_EMPTY(entry) || VIDEO_IS_STATIC(entry))) || \
(AUDIO_EMPTY(entry) && VIDEO_ENDED(entry)))
#define ENTRY_ENDED(entry) (al_assert(entry->ended == ENTRY_EVAL_ENDED(entry)), entry->ended)
@@ -223,7 +223,7 @@ static void remove_entry_audio_buffer(struct camu_sink_entry *entry)
static void remove_entry_video_buffer(struct camu_sink_entry *entry)
{
- // Don't assert !entry->ended here because of single frame handling.
+ // Don't assert !entry->ended here because of static video handling.
al_assert(!VIDEO_ENDED(entry));
al_assert(VIDEO_STATE(entry) != BUFFER_INIT);
log_trace("remove_entry_video_buffer("ENTRY_FMT"), do_remove: %s.", ENTRY_ARG(entry),
@@ -590,8 +590,8 @@ static void after_add_entry(struct camu_sink_entry *entry, bool skip_audio, bool
static void do_add_entry(struct camu_sink_entry *entry)
{
bool skip_audio = AUDIO_ENDED_OR_EMPTY(entry);
- // Single frames are unconditionally added in add_video_if_set_and_buffered().
- bool skip_video = VIDEO_ENDED_OR_EMPTY(entry) || VIDEO_IS_SINGLE_FRAME(entry);
+ // Static videos are unconditionally added in add_video_if_set_and_buffered().
+ bool skip_video = VIDEO_ENDED_OR_EMPTY(entry) || VIDEO_IS_STATIC(entry);
if (!skip_audio && !skip_video) {
al_assert(VIDEO_STATE(entry) == AUDIO_STATE(entry));
}
@@ -614,7 +614,7 @@ static void add_audio_if_set_and_buffered(struct camu_sink_entry *entry)
break;
case BUFFER_SET_OR_BUFFERED:
AUDIO_STATE(entry) = BUFFER_ADDED;
- if (VIDEO_ADDED_OR_IGNORED(entry) || VIDEO_IS_SINGLE_FRAME(entry)) {
+ if (VIDEO_ADDED_OR_IGNORED(entry) || VIDEO_IS_STATIC(entry)) {
do_add_entry(entry);
}
break;
@@ -623,8 +623,8 @@ static void add_audio_if_set_and_buffered(struct camu_sink_entry *entry)
static void add_video_if_set_and_buffered(struct camu_sink_entry *entry)
{
- // Single frame entries will be added/removed with ended set.
- if (ENTRY_ENDED(entry)) al_assert(VIDEO_IS_SINGLE_FRAME(entry));
+ // Static video buffers will be added/removed with ended set.
+ if (ENTRY_ENDED(entry)) al_assert(VIDEO_IS_STATIC(entry));
al_assert(VIDEO_STATE(entry) != BUFFER_INIT);
al_assert(VIDEO_STATE(entry) != BUFFER_QUEUED);
al_assert(VIDEO_STATE(entry) != BUFFER_ADDED);
@@ -635,7 +635,7 @@ static void add_video_if_set_and_buffered(struct camu_sink_entry *entry)
break;
case BUFFER_SET_OR_BUFFERED:
VIDEO_STATE(entry) = BUFFER_ADDED;
- if (VIDEO_IS_SINGLE_FRAME(entry)) {
+ if (VIDEO_IS_STATIC(entry)) {
add_entry_video_buffer(entry);
bool skip_audio = AUDIO_ENDED_OR_EMPTY(entry);
if (skip_audio) {
@@ -667,9 +667,9 @@ static void add_or_queue_entry(struct camu_sink_entry *entry)
}
}
-static void ensure_single_frame_removed(struct camu_sink_entry *entry)
+static void ensure_static_video_removed(struct camu_sink_entry *entry)
{
- if (!VIDEO_EMPTY(entry) && VIDEO_IS_SINGLE_FRAME(entry)) {
+ if (!VIDEO_EMPTY(entry) && VIDEO_IS_STATIC(entry)) {
remove_entry_video_buffer(entry);
struct camu_sink *sink = entry->sink;
while (entry_video_buffer_held(entry)) { BLOCKING_SLEEP(sink, NNWT_TS_FROM_USEC(2000)); }
@@ -689,11 +689,10 @@ static void switch_to(struct camu_sink *sink, struct camu_sink_entry *target)
if (suspended) {
al_assert(suspended == current);
// It should be impossible for a buffer to be QUEUED while it's entry is suspended.
- // Even for a single frame video buffer because we wouldn't even know if it only
- // has a single frame yet.
+ // Even for a static video buffer because we wouldn't know if it was static yet.
al_assert(AUDIO_STATE(suspended) != BUFFER_QUEUED);
al_assert(VIDEO_STATE(suspended) != BUFFER_QUEUED);
- ensure_single_frame_removed(suspended);
+ ensure_static_video_removed(suspended);
al_assert(AUDIO_STATE(suspended) != BUFFER_ADDED);
al_assert(VIDEO_STATE(suspended) != BUFFER_ADDED);
sink->suspended = NULL;
@@ -719,7 +718,7 @@ static void switch_to(struct camu_sink *sink, struct camu_sink_entry *target)
// If target was just created, it's AUDIO/VIDEO_STATE() will be QUEUED.
// Meaning, at this point, it's video buffer would be considered empty
// as well as being too early to tell if it's static or not.
- stop_video = VIDEO_ENDED_OR_EMPTY(target) || VIDEO_IS_SINGLE_FRAME(target);
+ stop_video = VIDEO_ENDED_OR_EMPTY(target) || VIDEO_IS_STATIC(target);
}
if (stop_video) {
@@ -825,7 +824,7 @@ static void audio_buffer_callback(void *userdata, u8 op)
remove_entry_audio_buffer(entry);
}
AUDIO_STATE(entry) = error ? BUFFER_ERRORED : BUFFER_ENDED;
- if (VIDEO_ENDED_OR_EMPTY(entry) || VIDEO_IS_SINGLE_FRAME(entry)) {
+ if (VIDEO_ENDED_OR_EMPTY(entry) || VIDEO_IS_STATIC(entry)) {
end_entry_and_advance_queue(sink, entry);
}
nn_mutex_unlock(&sink->lock);
@@ -863,7 +862,7 @@ static void video_buffer_callback(void *userdata, u8 op)
if (!AUDIO_EMPTY(entry)) {
camu_audio_buffer_set_no_video(&entry->audio.buf, true);
}
- if (VIDEO_IS_SINGLE_FRAME(entry) && !error) {
+ if (VIDEO_IS_STATIC(entry) && !error) {
nn_mutex_unlock(&sink->lock);
return;
}
@@ -907,7 +906,7 @@ static void clock_callback(void *userdata, u8 op)
static void evaluate_and_set_buffer_params(struct camu_sink *sink, struct camu_sink_entry *entry)
{
- bool ignore_video = VIDEO_EMPTY(entry) || VIDEO_IS_SINGLE_FRAME(entry);
+ bool ignore_video = VIDEO_EMPTY(entry) || VIDEO_IS_STATIC(entry);
f64 audio = camu_mixer_get_latency(sink->audio.mixer);
u32 frames = 0;
f64 video = 0.0;
@@ -1054,10 +1053,10 @@ static void client_callback(void *userdata, u8 op, struct camu_codec_stream *str
case LIANA_CLIENT_REMOVE_BUFFERS: {
struct lia_reconnect_info *rec = (struct lia_reconnect_info *)opaque;
nn_mutex_lock(&sink->lock);
- log_trace("remove_buffers("ENTRY_FMT", %s, %s), entry == current: %s, single_frame: %s.",
+ log_trace("remove_buffers("ENTRY_FMT", %s, %s), entry == current: %s, static: %s.",
ENTRY_ARG(entry), BOOLSTR(rec->reconnect),
BOOLSTR(rec->unconfigured), BOOLSTR(entry == sink->current),
- BOOLSTR(!VIDEO_EMPTY(entry) ? VIDEO_IS_SINGLE_FRAME(entry) : false));
+ BOOLSTR(!VIDEO_EMPTY(entry) ? VIDEO_IS_STATIC(entry) : false));
if (entry == sink->current) {
if (rec->reconnect) {
@@ -1105,8 +1104,8 @@ static void client_callback(void *userdata, u8 op, struct camu_codec_stream *str
remove_entry_audio_buffer(entry);
}
bool skip_video = VIDEO_EMPTY(entry);
- // Don't remove a single_frame if we are reconnecting, unless it's errored.
- skip_video = skip_video || (rec->reconnect && VIDEO_IS_SINGLE_FRAME(entry) && VIDEO_STATE(entry) != BUFFER_ERRORED);
+ // Don't remove a static video buffer if we are reconnecting, unless it's errored.
+ skip_video = skip_video || (rec->reconnect && VIDEO_IS_STATIC(entry) && VIDEO_STATE(entry) != BUFFER_ERRORED);
if (!skip_video && !VIDEO_ENDED(entry)) {
remove_entry_video_buffer(entry);
remove_entry_video_buffer(entry);
@@ -1134,7 +1133,7 @@ static void client_callback(void *userdata, u8 op, struct camu_codec_stream *str
}
if (VIDEO_STATE(entry) == BUFFER_ERRORED) {
al_array_push(rec->detached, VIDEO_STREAM(entry));
- } else if (VIDEO_STATE(entry) == BUFFER_ADDED && VIDEO_IS_SINGLE_FRAME(entry)) {
+ } else if (VIDEO_STATE(entry) == BUFFER_ADDED && VIDEO_IS_STATIC(entry)) {
// Try to not request a duplicate frame. We can only be sure the frame wasn't
// dropped by the VCR if it's ADDED.
rec->mask &= ~(1 << VIDEO_STREAM(entry)->index);
@@ -1175,7 +1174,7 @@ static void client_callback(void *userdata, u8 op, struct camu_codec_stream *str
f64 pos = time->pos / 1000000.0;
log_trace("resume_at("ENTRY_FMT"), pos: %f, paused_at: %f.", ENTRY_ARG(entry), pos, entry->clock.paused_at);
nn_mutex_lock(&sink->lock);
- bool ignore_video = VIDEO_EMPTY(entry) || VIDEO_IS_SINGLE_FRAME(entry);
+ bool ignore_video = VIDEO_EMPTY(entry) || VIDEO_IS_STATIC(entry);
if (!AUDIO_EMPTY(entry)) {
camu_audio_buffer_reset(&entry->audio.buf);
// no_video is set to true in video BUFFER_EOF as a fail-safe. Reset it here.
@@ -1211,7 +1210,7 @@ static void client_callback(void *userdata, u8 op, struct camu_codec_stream *str
}
if (VIDEO_STATE(entry) == BUFFER_INIT) {
VIDEO_STATE(entry) = BUFFER_QUEUED;
- } else if (!VIDEO_EMPTY(entry) && !VIDEO_IS_SINGLE_FRAME(entry)) {
+ } else if (!VIDEO_EMPTY(entry) && !VIDEO_IS_STATIC(entry)) {
add_video_if_set_and_buffered(entry);
}
sink->suspended = NULL;
@@ -1230,8 +1229,8 @@ static void client_callback(void *userdata, u8 op, struct camu_codec_stream *str
}
case CAMU_STREAM_VIDEO: {
nn_locked_assert(!VIDEO_EMPTY(entry), &sink->lock);
- // Single frames are immediately flushed inside the buffer.
- if (!VIDEO_IS_SINGLE_FRAME(entry) || error) {
+ // Static video buffers are immediately flushed inside the buffer.
+ if (!VIDEO_IS_STATIC(entry) || error) {
camu_video_buffer_flush(&entry->video.buf, error);
}
break;
@@ -1244,9 +1243,8 @@ static void client_callback(void *userdata, u8 op, struct camu_codec_stream *str
nn_mutex_lock(&sink->lock);
// We can be assured that CLIENT_REMOVE_BUFFERS has been called on this entry.
- // If a client is closed after a failed reconnect, a single frame
- // video buffer could still be added
- if (rec->reconnect) ensure_single_frame_removed(entry);
+ // If a client is closed after a failed reconnect, a static video buffer could still be added.
+ if (rec->reconnect) ensure_static_video_removed(entry);
al_assert(AUDIO_STATE(entry) != BUFFER_ADDED);
al_assert(VIDEO_STATE(entry) != BUFFER_ADDED);
@@ -1507,7 +1505,7 @@ static bool pause_command_callback(void *userdata, struct nn_rpc_connection *con
entry->paused = false;
camu_clock_resume(&entry->clock, at);
log_info("Clock resumed.");
- if (!VIDEO_ENDED_OR_EMPTY(entry) && !VIDEO_IS_SINGLE_FRAME(entry)) {
+ if (!VIDEO_ENDED_OR_EMPTY(entry) && !VIDEO_IS_STATIC(entry)) {
queue_cmd(sink, CMD(START, .v.u = CAMU_SINK_VIDEO));
}
if (!AUDIO_ENDED_OR_EMPTY(entry)) {
diff --git a/src/render/renderer_libplacebo.c b/src/render/renderer_libplacebo.c
index 48b7ea6..80a71a6 100644
--- a/src/render/renderer_libplacebo.c
+++ b/src/render/renderer_libplacebo.c
@@ -449,7 +449,7 @@ static bool renderer_lp_render(struct camu_renderer *renderer, struct camu_scree
if (mix.frames) {
// weighted is only set when read() returns QUEUE_OK.
result |= (1 | 1 << weighted);
- // Terrible hack. Lets us distinguish single frames with the same dimensions.
+ // Terrible hack. Lets us distinguish static video buffers with the same dimensions.
// Tied to a libplacebo patch to consider info_priv in the hash.
intptr_t hash = (intptr_t)video->buf;
// Also add in seek_pts to account for frame queue resets (seek() while paused).