]> git.sesse.net Git - vlc/blob - src/input/event.c
Missing <assert.h>
[vlc] / src / input / event.c
1 /*****************************************************************************
2  * event.c: Events
3  *****************************************************************************
4  * Copyright (C) 2008 Laurent Aimar
5  * $Id$
6  *
7  * Authors: Laurent Aimar < fenrir _AT_ videolan _DOT_ org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
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 General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30
31 #include <vlc_common.h>
32 #include <vlc_input.h>
33 #include "input_internal.h"
34 #include "event.h"
35 #include <assert.h>
36
37 static void Trigger( input_thread_t *p_input, int i_type );
38
39 /*****************************************************************************
40  * Event for input.c
41  *****************************************************************************/
42 void input_SendEventTimes( input_thread_t *p_input,
43                            double f_position, mtime_t i_time, mtime_t i_length )
44 {
45     vlc_value_t val;
46
47     /* */
48     val.f_float = f_position;
49     var_Change( p_input, "position", VLC_VAR_SETVALUE, &val, NULL );
50
51     /* */
52     val.i_time = i_time;
53     var_Change( p_input, "time", VLC_VAR_SETVALUE, &val, NULL );
54
55         /* FIXME ugly + what about meta change event ? */
56     if( var_GetTime( p_input, "length" ) != i_length )
57         input_item_SetDuration( p_input->p->p_item, i_length );
58     val.i_time = i_length;
59     var_Change( p_input, "length", VLC_VAR_SETVALUE, &val, NULL );
60
61     Trigger( p_input, INPUT_EVENT_TIMES );
62 }
63 void input_SendEventStatistics( input_thread_t *p_input )
64 {
65     Trigger( p_input, INPUT_EVENT_STATISTICS );
66 }
67 void input_SendEventRate( input_thread_t *p_input, int i_rate )
68 {
69         vlc_value_t val;
70
71         val.i_int = i_rate;
72         var_Change( p_input, "rate", VLC_VAR_SETVALUE, &val, NULL );
73
74     Trigger( p_input, INPUT_EVENT_RATE );
75 }
76 void input_SendEventAudioDelay( input_thread_t *p_input, mtime_t i_delay )
77 {
78         vlc_value_t val;
79
80         val.i_time = i_delay;
81         var_Change( p_input, "audio-delay", VLC_VAR_SETVALUE, &val, NULL );
82
83     Trigger( p_input, INPUT_EVENT_AUDIO_DELAY );
84 }
85
86 void input_SendEventSubtitleDelay( input_thread_t *p_input, mtime_t i_delay )
87 {
88         vlc_value_t val;
89
90         val.i_time = i_delay;
91         var_Change( p_input, "spu-delay", VLC_VAR_SETVALUE, &val, NULL );
92
93     Trigger( p_input, INPUT_EVENT_SUBTITLE_DELAY );
94 }
95
96 /* TODO and file name ? */
97 void input_SendEventRecord( input_thread_t *p_input, bool b_recording )
98 {
99         vlc_value_t val;
100
101         val.b_bool = b_recording;
102         var_Change( p_input, "record", VLC_VAR_SETVALUE, &val, NULL );
103
104     Trigger( p_input, INPUT_EVENT_RECORD );
105 }
106
107 void input_SendEventTitle( input_thread_t *p_input, int i_title )
108 {
109         vlc_value_t val;
110
111         val.i_int = i_title;
112         var_Change( p_input, "title", VLC_VAR_SETVALUE, &val, NULL );
113
114         input_ControlVarTitle( p_input, i_title );
115
116     Trigger( p_input, INPUT_EVENT_TITLE );
117 }
118
119 void input_SendEventSeekpoint( input_thread_t *p_input, int i_title, int i_seekpoint )
120 {
121         vlc_value_t val;
122
123         VLC_UNUSED( i_title );
124         val.i_int = i_seekpoint;
125         var_Change( p_input, "chapter", VLC_VAR_SETVALUE, &val, NULL );
126
127     Trigger( p_input, INPUT_EVENT_CHAPTER );
128 }
129
130 void input_SendEventSignal( input_thread_t *p_input, double f_quality, double f_strength )
131 {
132     vlc_value_t val;
133
134     val.f_float = f_quality;
135         var_Change( p_input, "signal-quality", VLC_VAR_SETVALUE, &val, NULL );
136
137     val.f_float = f_strength;
138         var_Change( p_input, "signal-strength", VLC_VAR_SETVALUE, &val, NULL );
139
140     Trigger( p_input, INPUT_EVENT_SIGNAL );
141 }
142
143 void input_SendEventState( input_thread_t *p_input, int i_state )
144 {
145     vlc_value_t val;
146
147     val.i_int = i_state;
148     var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
149
150     Trigger( p_input, INPUT_EVENT_STATE );
151 }
152
153 void input_SendEventCache( input_thread_t *p_input, double f_level )
154 {
155     vlc_value_t val;
156
157     val.f_float = f_level;
158         var_Change( p_input, "cache", VLC_VAR_SETVALUE, &val, NULL );
159
160     Trigger( p_input, INPUT_EVENT_CACHE );
161 }
162
163 /* FIXME: review them because vlc_event_send might be
164  * moved inside input_item* functions.
165  */
166 void input_SendEventMeta( input_thread_t *p_input )
167 {
168     Trigger( p_input, INPUT_EVENT_ITEM_META );
169
170         /* FIXME remove this ugliness ? */
171         vlc_event_t event;
172
173         event.type = vlc_InputItemMetaChanged;
174         event.u.input_item_meta_changed.meta_type = vlc_meta_ArtworkURL;
175         vlc_event_send( &p_input->p->p_item->event_manager, &event );
176 }
177
178 void input_SendEventMetaInfo( input_thread_t *p_input )
179 {
180     Trigger( p_input, INPUT_EVENT_ITEM_INFO );
181
182         /* FIXME remove this ugliness */
183     vlc_event_t event;
184
185     event.type = vlc_InputItemInfoChanged;
186     vlc_event_send( &p_input->p->p_item->event_manager, &event );
187 }
188
189 void input_SendEventMetaName( input_thread_t *p_input, const char *psz_name )
190 {
191     Trigger( p_input, INPUT_EVENT_ITEM_NAME );
192
193         /* FIXME remove this ugliness */
194     vlc_event_t event;
195
196     event.type = vlc_InputItemNameChanged;
197     event.u.input_item_name_changed.new_name = psz_name;
198     vlc_event_send( &p_input->p->p_item->event_manager, &event );
199 }
200
201 /*****************************************************************************
202  * Event for es_out.c
203  *****************************************************************************/
204 void input_SendEventProgramAdd( input_thread_t *p_input,
205                                 int i_program, const char *psz_text )
206 {
207     vlc_value_t val;
208     vlc_value_t text;
209
210     val.i_int = i_program;
211     text.psz_string = (char*)psz_text;
212
213     var_Change( p_input, "program", VLC_VAR_ADDCHOICE,
214                 &val, psz_text ? &text : NULL );
215
216     Trigger( p_input, INPUT_EVENT_PROGRAM );
217 }
218 void input_SendEventProgramDel( input_thread_t *p_input, int i_program )
219 {
220     vlc_value_t val;
221
222     val.i_int = i_program;
223     var_Change( p_input, "program", VLC_VAR_DELCHOICE, &val, NULL );
224
225     Trigger( p_input, INPUT_EVENT_PROGRAM );
226 }
227 void input_SendEventProgramSelect( input_thread_t *p_input, int i_program )
228 {
229     vlc_value_t val;
230
231     val.i_int = i_program;
232     var_Change( p_input, "program", VLC_VAR_SETVALUE, &val, NULL );
233
234     Trigger( p_input, INPUT_EVENT_PROGRAM );
235 }
236
237 static const char *GetEsVarName( int i_cat )
238 {
239     switch( i_cat )
240     {
241     case VIDEO_ES:
242         return "video-es";
243     case AUDIO_ES:
244         return "audio-es";
245     default:
246         assert( i_cat == SPU_ES );
247         return "spu-es";
248     }
249 }
250 void input_SendEventEsDel( input_thread_t *p_input, int i_cat, int i_id )
251 {
252     vlc_value_t val;
253
254     if( i_cat == UNKNOWN_ES )
255         return;
256
257     if( i_id >= 0 )
258     {
259         val.i_int = i_id;
260         var_Change( p_input, GetEsVarName( i_cat ), VLC_VAR_DELCHOICE, &val, NULL );
261     }
262     else
263     {
264         var_Change( p_input, GetEsVarName( i_cat ), VLC_VAR_CLEARCHOICES, NULL, NULL );
265     }
266
267     Trigger( p_input, INPUT_EVENT_ES );
268 }
269 void input_SendEventEsAdd( input_thread_t *p_input, int i_cat, int i_id, const char *psz_text )
270 {
271     vlc_value_t val;
272     vlc_value_t text;
273
274     if( i_cat == UNKNOWN_ES )
275         return;
276
277     val.i_int = i_id;
278     text.psz_string = (char*)psz_text;
279
280     var_Change( p_input, GetEsVarName( i_cat ), VLC_VAR_ADDCHOICE,
281                 &val, psz_text ? &text : NULL );
282
283     Trigger( p_input, INPUT_EVENT_ES );
284 }
285
286 /* i_id == -1 will unselect */
287 void input_SendEventEsSelect( input_thread_t *p_input, int i_cat, int i_id )
288 {
289     vlc_value_t val;
290
291     if( i_cat == UNKNOWN_ES )
292         return;
293
294     val.i_int = i_id;
295     var_Change( p_input, GetEsVarName( i_cat ), VLC_VAR_SETVALUE, &val, NULL );
296
297     Trigger( p_input, INPUT_EVENT_ES );
298 }
299
300 void input_SendEventTeletext( input_thread_t *p_input, int i_id )
301 {
302     vlc_value_t val;
303
304     val.i_int = i_id;
305     var_Change( p_input, "teletext-es", VLC_VAR_SETVALUE, &val, NULL );
306
307     Trigger( p_input, INPUT_EVENT_TELETEXT );
308 }
309
310 void input_SendEventVout( input_thread_t *p_input )
311 {
312     Trigger( p_input, INPUT_EVENT_VOUT );
313 }
314
315 /*****************************************************************************
316  * Event for control.c/input.c
317  *****************************************************************************/
318 void input_SendEventBookmark( input_thread_t *p_input )
319 {
320     Trigger( p_input, INPUT_EVENT_BOOKMARK );
321 }
322
323 /*****************************************************************************
324  *
325  *****************************************************************************/
326 static void Trigger( input_thread_t *p_input, int i_type )
327 {
328     var_SetInteger( p_input, "intf-event", i_type );
329 }