Notify new frames via callbacks

Currently, a frame is available to the consumer as soon as it is pushed
by the producer (which can detect if the previous frame is skipped).

Notify the new frames (and frame skipped) via callbacks instead.

This paves the way to add (optional) buffering, which will introduce a
delay between the time when the frame is produced and the time it is
available to be consumed.
This commit is contained in:
Romain Vimont
2021-07-04 12:42:22 +02:00
parent 4d8bcfc68a
commit 408a301201
4 changed files with 68 additions and 32 deletions

View File

@@ -139,9 +139,27 @@ run_v4l2_sink(void *data) {
return 0;
}
static void
sc_video_buffer_on_new_frame(struct sc_video_buffer *vb, bool previous_skipped,
void *userdata) {
(void) vb;
struct sc_v4l2_sink *vs = userdata;
if (!previous_skipped) {
sc_mutex_lock(&vs->mutex);
vs->has_frame = true;
sc_cond_signal(&vs->cond);
sc_mutex_unlock(&vs->mutex);
}
}
static bool
sc_v4l2_sink_open(struct sc_v4l2_sink *vs) {
bool ok = sc_video_buffer_init(&vs->vb);
static const struct sc_video_buffer_callbacks cbs = {
.on_new_frame = sc_video_buffer_on_new_frame,
};
bool ok = sc_video_buffer_init(&vs->vb, &cbs, vs);
if (!ok) {
LOGE("Could not initialize video buffer");
return false;
@@ -303,20 +321,7 @@ sc_v4l2_sink_close(struct sc_v4l2_sink *vs) {
static bool
sc_v4l2_sink_push(struct sc_v4l2_sink *vs, const AVFrame *frame) {
bool previous_skipped;
bool ok = sc_video_buffer_push(&vs->vb, frame, &previous_skipped);
if (!ok) {
return false;
}
if (!previous_skipped) {
sc_mutex_lock(&vs->mutex);
vs->has_frame = true;
sc_cond_signal(&vs->cond);
sc_mutex_unlock(&vs->mutex);
}
return true;
return sc_video_buffer_push(&vs->vb, frame);
}
static bool