qt4: improve code readability.
[vlc/asuraparaju-public.git] / src / input / event.c
blobf0a420518d310a87ce24f9d8fd6d3075e4c25d12
1 /*****************************************************************************
2 * event.c: Events
3 *****************************************************************************
4 * Copyright (C) 2008 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
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.
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.
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 *****************************************************************************/
24 /*****************************************************************************
25 * Preamble
26 *****************************************************************************/
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
31 #include <vlc_common.h>
32 #include <vlc_input.h>
33 #include "input_internal.h"
34 #include "event.h"
35 #include <assert.h>
37 /* */
38 static void Trigger( input_thread_t *, int i_type );
39 static void VarListAdd( input_thread_t *,
40 const char *psz_variable, int i_event,
41 int i_value, const char *psz_text );
42 static void VarListDel( input_thread_t *,
43 const char *psz_variable, int i_event,
44 int i_value );
45 static void VarListSelect( input_thread_t *,
46 const char *psz_variable, int i_event,
47 int i_value );
49 /*****************************************************************************
50 * Event for input.c
51 *****************************************************************************/
52 void input_SendEventDead( input_thread_t *p_input )
54 p_input->b_dead = true;
56 Trigger( p_input, INPUT_EVENT_DEAD );
58 void input_SendEventAbort( input_thread_t *p_input )
60 Trigger( p_input, INPUT_EVENT_ABORT );
63 void input_SendEventPosition( input_thread_t *p_input, double f_position, mtime_t i_time )
65 vlc_value_t val;
67 /* */
68 val.f_float = f_position;
69 var_Change( p_input, "position", VLC_VAR_SETVALUE, &val, NULL );
71 /* */
72 val.i_time = i_time;
73 var_Change( p_input, "time", VLC_VAR_SETVALUE, &val, NULL );
75 Trigger( p_input, INPUT_EVENT_POSITION );
77 void input_SendEventLength( input_thread_t *p_input, mtime_t i_length )
79 vlc_value_t val;
81 /* FIXME ugly + what about meta change event ? */
82 if( var_GetTime( p_input, "length" ) == i_length )
83 return;
85 input_item_SetDuration( p_input->p->p_item, i_length );
87 val.i_time = i_length;
88 var_Change( p_input, "length", VLC_VAR_SETVALUE, &val, NULL );
90 Trigger( p_input, INPUT_EVENT_LENGTH );
92 void input_SendEventStatistics( input_thread_t *p_input )
94 Trigger( p_input, INPUT_EVENT_STATISTICS );
96 void input_SendEventRate( input_thread_t *p_input, int i_rate )
98 vlc_value_t val;
100 val.f_float = (float)INPUT_RATE_DEFAULT / (float)i_rate;
101 var_Change( p_input, "rate", VLC_VAR_SETVALUE, &val, NULL );
103 Trigger( p_input, INPUT_EVENT_RATE );
105 void input_SendEventAudioDelay( input_thread_t *p_input, mtime_t i_delay )
107 vlc_value_t val;
109 val.i_time = i_delay;
110 var_Change( p_input, "audio-delay", VLC_VAR_SETVALUE, &val, NULL );
112 Trigger( p_input, INPUT_EVENT_AUDIO_DELAY );
115 void input_SendEventSubtitleDelay( input_thread_t *p_input, mtime_t i_delay )
117 vlc_value_t val;
119 val.i_time = i_delay;
120 var_Change( p_input, "spu-delay", VLC_VAR_SETVALUE, &val, NULL );
122 Trigger( p_input, INPUT_EVENT_SUBTITLE_DELAY );
125 /* TODO and file name ? */
126 void input_SendEventRecord( input_thread_t *p_input, bool b_recording )
128 vlc_value_t val;
130 val.b_bool = b_recording;
131 var_Change( p_input, "record", VLC_VAR_SETVALUE, &val, NULL );
133 Trigger( p_input, INPUT_EVENT_RECORD );
136 void input_SendEventTitle( input_thread_t *p_input, int i_title )
138 vlc_value_t val;
140 val.i_int = i_title;
141 var_Change( p_input, "title", VLC_VAR_SETVALUE, &val, NULL );
143 input_ControlVarTitle( p_input, i_title );
145 Trigger( p_input, INPUT_EVENT_TITLE );
148 void input_SendEventSeekpoint( input_thread_t *p_input, int i_title, int i_seekpoint )
150 vlc_value_t val;
152 /* "chapter" */
153 val.i_int = i_seekpoint;
154 var_Change( p_input, "chapter", VLC_VAR_SETVALUE, &val, NULL );
156 /* "title %2i" */
157 char psz_title[10];
158 snprintf( psz_title, sizeof(psz_title), "title %2i", i_title );
159 var_Change( p_input, psz_title, VLC_VAR_SETVALUE, &val, NULL );
161 /* */
162 Trigger( p_input, INPUT_EVENT_CHAPTER );
165 void input_SendEventSignal( input_thread_t *p_input, double f_quality, double f_strength )
167 vlc_value_t val;
169 val.f_float = f_quality;
170 var_Change( p_input, "signal-quality", VLC_VAR_SETVALUE, &val, NULL );
172 val.f_float = f_strength;
173 var_Change( p_input, "signal-strength", VLC_VAR_SETVALUE, &val, NULL );
175 Trigger( p_input, INPUT_EVENT_SIGNAL );
178 void input_SendEventState( input_thread_t *p_input, int i_state )
180 vlc_value_t val;
182 val.i_int = i_state;
183 var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
185 Trigger( p_input, INPUT_EVENT_STATE );
188 void input_SendEventCache( input_thread_t *p_input, double f_level )
190 vlc_value_t val;
192 val.f_float = f_level;
193 var_Change( p_input, "cache", VLC_VAR_SETVALUE, &val, NULL );
195 Trigger( p_input, INPUT_EVENT_CACHE );
198 /* FIXME: review them because vlc_event_send might be
199 * moved inside input_item* functions.
201 void input_SendEventMeta( input_thread_t *p_input )
203 Trigger( p_input, INPUT_EVENT_ITEM_META );
205 /* FIXME remove this ugliness ? */
206 vlc_event_t event;
208 event.type = vlc_InputItemMetaChanged;
209 event.u.input_item_meta_changed.meta_type = vlc_meta_ArtworkURL;
210 vlc_event_send( &p_input->p->p_item->event_manager, &event );
213 void input_SendEventMetaInfo( input_thread_t *p_input )
215 Trigger( p_input, INPUT_EVENT_ITEM_INFO );
217 /* FIXME remove this ugliness */
218 vlc_event_t event;
220 event.type = vlc_InputItemInfoChanged;
221 vlc_event_send( &p_input->p->p_item->event_manager, &event );
224 void input_SendEventMetaName( input_thread_t *p_input, const char *psz_name )
226 Trigger( p_input, INPUT_EVENT_ITEM_NAME );
228 /* FIXME remove this ugliness */
229 vlc_event_t event;
231 event.type = vlc_InputItemNameChanged;
232 event.u.input_item_name_changed.new_name = psz_name;
233 vlc_event_send( &p_input->p->p_item->event_manager, &event );
236 void input_SendEventMetaEpg( input_thread_t *p_input )
238 Trigger( p_input, INPUT_EVENT_ITEM_EPG );
240 /*****************************************************************************
241 * Event for es_out.c
242 *****************************************************************************/
243 void input_SendEventProgramAdd( input_thread_t *p_input,
244 int i_program, const char *psz_text )
246 VarListAdd( p_input, "program", INPUT_EVENT_PROGRAM, i_program, psz_text );
248 void input_SendEventProgramDel( input_thread_t *p_input, int i_program )
250 VarListDel( p_input, "program", INPUT_EVENT_PROGRAM, i_program );
252 void input_SendEventProgramSelect( input_thread_t *p_input, int i_program )
254 VarListSelect( p_input, "program", INPUT_EVENT_PROGRAM, i_program );
256 void input_SendEventProgramScrambled( input_thread_t *p_input, int i_group, bool b_scrambled )
258 if( var_GetInteger( p_input, "program" ) != i_group )
259 return;
261 var_SetBool( p_input, "program-scrambled", b_scrambled );
262 Trigger( p_input, INPUT_EVENT_PROGRAM );
265 static const char *GetEsVarName( int i_cat )
267 switch( i_cat )
269 case VIDEO_ES:
270 return "video-es";
271 case AUDIO_ES:
272 return "audio-es";
273 default:
274 assert( i_cat == SPU_ES );
275 return "spu-es";
278 void input_SendEventEsAdd( input_thread_t *p_input, int i_cat, int i_id, const char *psz_text )
280 if( i_cat != UNKNOWN_ES )
281 VarListAdd( p_input, GetEsVarName( i_cat ), INPUT_EVENT_ES,
282 i_id, psz_text );
284 void input_SendEventEsDel( input_thread_t *p_input, int i_cat, int i_id )
286 if( i_cat != UNKNOWN_ES )
287 VarListDel( p_input, GetEsVarName( i_cat ), INPUT_EVENT_ES, i_id );
289 /* i_id == -1 will unselect */
290 void input_SendEventEsSelect( input_thread_t *p_input, int i_cat, int i_id )
292 if( i_cat != UNKNOWN_ES )
293 VarListSelect( p_input, GetEsVarName( i_cat ), INPUT_EVENT_ES, i_id );
296 void input_SendEventTeletextAdd( input_thread_t *p_input,
297 int i_teletext, const char *psz_text )
299 VarListAdd( p_input, "teletext-es", INPUT_EVENT_TELETEXT, i_teletext, psz_text );
301 void input_SendEventTeletextDel( input_thread_t *p_input, int i_teletext )
303 VarListDel( p_input, "teletext-es", INPUT_EVENT_TELETEXT, i_teletext );
305 void input_SendEventTeletextSelect( input_thread_t *p_input, int i_teletext )
307 VarListSelect( p_input, "teletext-es", INPUT_EVENT_TELETEXT, i_teletext );
310 void input_SendEventVout( input_thread_t *p_input )
312 Trigger( p_input, INPUT_EVENT_VOUT );
315 void input_SendEventAout( input_thread_t *p_input )
317 Trigger( p_input, INPUT_EVENT_AOUT );
320 /*****************************************************************************
321 * Event for control.c/input.c
322 *****************************************************************************/
323 void input_SendEventBookmark( input_thread_t *p_input )
325 Trigger( p_input, INPUT_EVENT_BOOKMARK );
328 /*****************************************************************************
330 *****************************************************************************/
331 static void Trigger( input_thread_t *p_input, int i_type )
333 var_SetInteger( p_input, "intf-event", i_type );
335 static void VarListAdd( input_thread_t *p_input,
336 const char *psz_variable, int i_event,
337 int i_value, const char *psz_text )
339 vlc_value_t val;
340 vlc_value_t text;
342 val.i_int = i_value;
343 text.psz_string = (char*)psz_text;
345 var_Change( p_input, psz_variable, VLC_VAR_ADDCHOICE,
346 &val, psz_text ? &text : NULL );
348 Trigger( p_input, i_event );
350 static void VarListDel( input_thread_t *p_input,
351 const char *psz_variable, int i_event,
352 int i_value )
354 vlc_value_t val;
356 if( i_value >= 0 )
358 val.i_int = i_value;
359 var_Change( p_input, psz_variable, VLC_VAR_DELCHOICE, &val, NULL );
361 else
363 var_Change( p_input, psz_variable, VLC_VAR_CLEARCHOICES, &val, NULL );
366 Trigger( p_input, i_event );
368 static void VarListSelect( input_thread_t *p_input,
369 const char *psz_variable, int i_event,
370 int i_value )
372 vlc_value_t val;
374 val.i_int = i_value;
375 var_Change( p_input, psz_variable, VLC_VAR_SETVALUE, &val, NULL );
377 Trigger( p_input, i_event );