From 9285594e9d4ff4a3a2f7f937789b8b21bbebd7f1 Mon Sep 17 00:00:00 2001 From: Andri Yngvason Date: Sun, 5 Jun 2022 15:50:43 +0000 Subject: [PATCH] Call encoder.on_done in a function --- include/encoder.h | 3 +++ src/encoder.c | 7 +++++++ src/open-h264.c | 3 +-- src/raw-encoding.c | 3 +-- src/tight.c | 3 +-- src/zrle.c | 3 +-- 6 files changed, 14 insertions(+), 8 deletions(-) diff --git a/include/encoder.h b/include/encoder.h index 6aece2a..9e13752 100644 --- a/include/encoder.h +++ b/include/encoder.h @@ -90,3 +90,6 @@ int encoder_push(struct encoder* self, struct nvnc_fb* fb, struct rcbuf* encoder_pull(struct encoder* self, uint64_t* pts); void encoder_request_key_frame(struct encoder* self); + +void encoder_finish_frame(struct encoder* self, struct rcbuf* result, + uint64_t pts); diff --git a/src/encoder.c b/src/encoder.c index cbd2c1d..ed4071f 100644 --- a/src/encoder.c +++ b/src/encoder.c @@ -141,3 +141,10 @@ void encoder_request_key_frame(struct encoder* self) if (self->impl->request_key_frame) return self->impl->request_key_frame(self); } + +void encoder_finish_frame(struct encoder* self, struct rcbuf* result, + uint64_t pts) +{ + if (self->on_done) + self->on_done(self, result, pts); +} diff --git a/src/open-h264.c b/src/open-h264.c index a4f3518..527a672 100644 --- a/src/open-h264.c +++ b/src/open-h264.c @@ -76,8 +76,7 @@ static void open_h264_handle_packet(const void* data, size_t size, uint64_t pts, vec_append(&self->pending, data, size); self->pts = pts; - if (self->parent.on_done) - self->parent.on_done(&self->parent, NULL, NVNC_NO_PTS); + encoder_finish_frame(&self->parent, NULL, NVNC_NO_PTS); } static int open_h264_init_pending(struct open_h264* self) diff --git a/src/raw-encoding.c b/src/raw-encoding.c index d29f8a0..2138b90 100644 --- a/src/raw-encoding.c +++ b/src/raw-encoding.c @@ -173,8 +173,7 @@ static void raw_encoder_on_done(void* obj) aml_unref(self->work); self->work = NULL; - if (self->encoder.on_done) - self->encoder.on_done(&self->encoder, result, pts); + encoder_finish_frame(&self->encoder, result, pts); rcbuf_unref(result); } diff --git a/src/tight.c b/src/tight.c index 303da1c..ea9cc61 100644 --- a/src/tight.c +++ b/src/tight.c @@ -519,8 +519,7 @@ static void on_tight_finished(void* obj) self->encoder.n_rects = self->n_rects; - if (self->encoder.on_done) - self->encoder.on_done(&self->encoder, result, self->pts); + encoder_finish_frame(&self->encoder, result, self->pts); self->pts = NVNC_NO_PTS; rcbuf_unref(result); diff --git a/src/zrle.c b/src/zrle.c index 228d9f8..6c001c2 100644 --- a/src/zrle.c +++ b/src/zrle.c @@ -375,8 +375,7 @@ static void zrle_encoder_on_done(void* obj) aml_unref(self->work); self->work = NULL; - if (self->encoder.on_done) - self->encoder.on_done(&self->encoder, result, pts); + encoder_finish_frame(&self->encoder, result, pts); rcbuf_unref(result); }