summaryrefslogtreecommitdiff
path: root/src/libsink/sink.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libsink/sink.c')
-rw-r--r--src/libsink/sink.c60
1 files changed, 29 insertions, 31 deletions
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)) {