demux: ts: only seek on pcr for current program
[vlc.git] / modules / video_output / event_thread.c
blob817de309a8a8cdc47e11f52c0cb66f1061a0077f
1 /*****************************************************************************
2 * event.c: event thread for broken old video output display plugins
3 *****************************************************************************
4 * Copyright (C) 2009 Laurent Aimar
5 * $Id$
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 *****************************************************************************/
24 #ifdef HAVE_CONFIG_H
25 # include <config.h>
26 #endif
28 #include <stdnoreturn.h>
29 #include <stdlib.h>
30 #include <string.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 {
38 vout_display_t *vd;
39 block_fifo_t *fifo;
40 vlc_thread_t 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;
49 for (;;) {
50 block_t *event = block_FifoGet(fifo);
52 int cancel = vlc_savecancel();
53 int key;
55 memcpy(&key, event->p_buffer, sizeof (key));
56 block_Release(event);
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))
65 return;
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))
79 return NULL;
81 vdet->vd = vd;
82 vdet->fifo = block_FifoNew();
83 if (unlikely(vdet->fifo == NULL)) {
84 free(vdet);
85 return NULL;
88 if (vlc_clone(&vdet->thread, VoutDisplayEventKeyDispatch, vdet,
89 VLC_THREAD_PRIORITY_LOW)) {
90 block_FifoRelease(vdet->fifo);
91 free(vdet);
92 return NULL;
94 return vdet;
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);
102 free(vdet);