diff options
author | Mikhail Burakov <mburakov@mailbox.org> | 2024-11-18 06:34:31 +0100 |
---|---|---|
committer | Mikhail Burakov <mburakov@mailbox.org> | 2024-11-18 06:34:31 +0100 |
commit | 5be09d7edff924e7486d743e9d15edf07f555341 (patch) | |
tree | 064680d394732b0d1c00bfbbbb1ce3d5ed3d6e5e /encode_context.c | |
parent | 8a93cfdc03683eedc270bae957288af853f22a61 (diff) |
WIPnext
Diffstat (limited to 'encode_context.c')
-rw-r--r-- | encode_context.c | 45 |
1 files changed, 38 insertions, 7 deletions
diff --git a/encode_context.c b/encode_context.c index 7fc1142..bef2f17 100644 --- a/encode_context.c +++ b/encode_context.c @@ -29,6 +29,7 @@ #include <va/va_wayland.h> #include "io_context.h" +#include "queue.h" #include "util.h" struct EncodeContext { @@ -44,6 +45,11 @@ struct EncodeContext { VAConfigAttribValEncHEVCBlockSizes hevc_block_sizes; VAContextID context_id; + struct EncodeContextFrame** frames; + size_t frames_count; + + struct Queue input; + struct Queue reuse; mtx_t mutex; cnd_t cond; @@ -318,19 +324,44 @@ rollback_encode_context: struct EncodeContextFrame* EncodeContextDequeue( struct EncodeContext* encode_context) { - (void)encode_context; - // TODO(mburakov): Implement this! - return NULL; + if (!atomic_load_explicit(&encode_context->running, memory_order_relaxed)) { + LOG("Encode context is not running"); + return false; + } + + if (mtx_lock(&encode_context->mutex) != thrd_success) { + LOG("Failed to lock mutex"); + return false; + } + + void* item; + if (&QueuePop(encode_context->reuse, )) + +rollback_lock: + assert(mtx_unlock(&encode_context->mutex)); + return false; } bool EncodeContextQueue(struct EncodeContext* encode_context, struct EncodeContextFrame* encode_context_frame, bool encode) { - (void)encode_context; - (void)encode_context_frame; - (void)encode; - // TODO(mburakov): Implement this! + if (mtx_lock(&encode_context->mutex) != thrd_success) { + LOG("Failed to lock mutex"); + return false; + } + + struct Queue* queue = + encode ? &encode_context->input : &encode_context->reuse; + if (!QueuePush(queue, encode_context_frame)) { + LOG("Failed to queue frame (%s)", strerror(errno)); + goto rollback_lock; + } + return true; + +rollback_lock: + assert(mtx_unlock(&encode_context->mutex)); + return false; } void EncodeContextDestroy(struct EncodeContext* encode_context) { |