[vlc-devel] [PATCH 3/3] caca: use the queue API, avoid block_t
RĂ©mi Denis-Courmont
remi at remlab.net
Sat Apr 11 21:12:41 CEST 2020
---
modules/video_output/caca.c | 63 +++++++++++++++----------------------
1 file changed, 26 insertions(+), 37 deletions(-)
diff --git a/modules/video_output/caca.c b/modules/video_output/caca.c
index de5d130803..296103cd5c 100644
--- a/modules/video_output/caca.c
+++ b/modules/video_output/caca.c
@@ -30,10 +30,11 @@
#endif
#include <stdbool.h>
+#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <vlc_common.h>
-#include <vlc_block.h>
+#include <vlc_queue.h>
#include <vlc_plugin.h>
#include <vlc_vout_display.h>
#if !defined(_WIN32) && !defined(__APPLE__)
@@ -52,7 +53,7 @@ struct vout_display_sys_t {
cucul_dither_t *dither;
bool dead;
- block_fifo_t *fifo;
+ vlc_queue_t q;
vlc_thread_t thread;
vout_window_t *window;
vout_display_place_t place;
@@ -61,26 +62,23 @@ struct vout_display_sys_t {
vlc_tick_t cursor_deadline;
};
+typedef struct vlc_caca_event {
+ struct vlc_caca_event *next;
+ int key;
+} vlc_caca_event_t;
+
+static const ptrdiff_t q_offset = offsetof (vlc_caca_event_t, next);
+
static void *VoutDisplayEventKeyDispatch(void *data)
{
vout_display_t *vd = data;
vout_display_sys_t *sys = vd->sys;
- block_fifo_t *fifo = sys->fifo;
- block_t *event;
+ vlc_caca_event_t *event;
do {
- vlc_fifo_Lock(fifo);
- while (vlc_fifo_IsEmpty(fifo) && !sys->dead)
- vlc_fifo_Wait(fifo);
-
- event = vlc_fifo_DequeueUnlocked(fifo);
- vlc_fifo_Unlock(fifo);
-
- int key;
-
- memcpy(&key, event->p_buffer, sizeof (key));
- block_Release(event);
- vout_window_ReportKeyPress(sys->window, key);
+ event = vlc_queue_DequeueKillable(&sys->q, q_offset, &sys->dead);
+ vout_window_ReportKeyPress(sys->window, event->key);
+ free(event);
} while (event != NULL);
return NULL;
@@ -88,10 +86,11 @@ static void *VoutDisplayEventKeyDispatch(void *data)
static void VoutDisplayEventKey(vout_display_sys_t *sys, int key)
{
- block_t *event = block_Alloc(sizeof (key));
+ vlc_caca_event_t *event = malloc(sizeof (*event));
+
if (likely(event != NULL)) {
- memcpy(event->p_buffer, &key, sizeof (key));
- block_FifoPut(sys->fifo, event);
+ event->key = key;
+ vlc_queue_Enqueue(&sys->q, event, q_offset);
}
}
@@ -363,14 +362,9 @@ static void Close(vout_display_t *vd)
{
vout_display_sys_t *sys = vd->sys;
- if (sys->fifo != NULL) {
- vlc_fifo_Lock(sys->fifo);
- sys->dead = true;
- vlc_fifo_Signal(sys->fifo);
- vlc_fifo_Unlock(sys->fifo);
- vlc_join(sys->thread, NULL);
- block_FifoRelease(sys->fifo);
- }
+ vlc_queue_Kill(&sys->q, &sys->dead);
+ vlc_join(sys->thread, NULL);
+
if (sys->dither)
cucul_free_dither(sys->dither);
caca_free_display(sys->dp);
@@ -480,17 +474,12 @@ static int Open(vout_display_t *vd, const vout_display_cfg_t *cfg,
(title != NULL) ? title : VOUT_TITLE "(Colour AsCii Art)");
free(title);
- block_fifo_t *fifo = block_FifoNew();
- if (likely(fifo != NULL)) {
- sys->dead = false;
- sys->fifo = fifo;
+ sys->dead = false;
+ vlc_queue_Init(&sys->q);
- if (vlc_clone(&sys->thread, VoutDisplayEventKeyDispatch, vd,
- VLC_THREAD_PRIORITY_LOW)) {
- block_FifoRelease(fifo);
- sys->fifo = NULL;
- }
- }
+ if (vlc_clone(&sys->thread, VoutDisplayEventKeyDispatch, vd,
+ VLC_THREAD_PRIORITY_LOW))
+ goto error;
sys->cursor_timeout = VLC_TICK_FROM_MS( var_InheritInteger(vd, "mouse-hide-timeout") );
sys->cursor_deadline = INVALID_DEADLINE;
--
2.26.0
More information about the vlc-devel
mailing list