1 /*****************************************************************************
2 * event.c: event thread for broken old video output display plugins
3 *****************************************************************************
4 * Copyright (C) 2009 Laurent Aimar
7 * Authors: Laurent Aimar <fenrir _AT_ videolan _DOT_ org>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation; either version 2.1 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
28 #include <stdnoreturn.h>
31 #include <vlc_common.h>
32 #include <vlc_block.h>
33 #include <vlc_vout_display.h>
35 #include "event_thread.h"
37 struct vout_display_event_thread
{
43 noreturn
static void *VoutDisplayEventKeyDispatch(void *data
)
45 vout_display_event_thread_t
*vdet
= data
;
46 vout_display_t
*vd
= vdet
->vd
;
47 block_fifo_t
*fifo
= vdet
->fifo
;
50 block_t
*event
= block_FifoGet(fifo
);
52 int cancel
= vlc_savecancel();
55 memcpy(&key
, event
->p_buffer
, sizeof (key
));
57 vout_display_SendEventKey(vd
, key
);
58 vlc_restorecancel(cancel
);
62 void VoutDisplayEventKey(vout_display_event_thread_t
*vdet
, int key
)
64 if (unlikely(vdet
== NULL
))
67 block_t
*event
= block_Alloc(sizeof (key
));
68 if (likely(event
!= NULL
)) {
69 memcpy(event
->p_buffer
, &key
, sizeof (key
));
70 block_FifoPut(vdet
->fifo
, event
);
74 struct vout_display_event_thread
*
75 VoutDisplayEventCreateThread(vout_display_t
*vd
)
77 vout_display_event_thread_t
*vdet
= malloc(sizeof (*vdet
));
78 if (unlikely(vdet
== NULL
))
82 vdet
->fifo
= block_FifoNew();
83 if (unlikely(vdet
->fifo
== NULL
)) {
88 if (vlc_clone(&vdet
->thread
, VoutDisplayEventKeyDispatch
, vdet
,
89 VLC_THREAD_PRIORITY_LOW
)) {
90 block_FifoRelease(vdet
->fifo
);
97 void VoutDisplayEventKillThread(vout_display_event_thread_t
*vdet
)
99 vlc_cancel(vdet
->thread
);
100 vlc_join(vdet
->thread
, NULL
);
101 block_FifoRelease(vdet
->fifo
);