codec/esout: add support for CEA708
[vlc.git] / src / input / event.c
blob201c5c6fe374bb8f3d4a1afd8cc5c57906bf21a5
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 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 /*****************************************************************************
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 Trigger( p_input, INPUT_EVENT_DEAD );
57 void input_SendEventPosition( input_thread_t *p_input, double f_position, mtime_t i_time )
59 vlc_value_t val;
61 /* */
62 val.f_float = f_position;
63 var_Change( p_input, "position", VLC_VAR_SETVALUE, &val, NULL );
65 /* */
66 val.i_int = i_time;
67 var_Change( p_input, "time", VLC_VAR_SETVALUE, &val, NULL );
69 Trigger( p_input, INPUT_EVENT_POSITION );
71 void input_SendEventLength( input_thread_t *p_input, mtime_t i_length )
73 vlc_value_t val;
75 /* FIXME ugly + what about meta change event ? */
76 if( var_GetInteger( p_input, "length" ) == i_length )
77 return;
79 input_item_SetDuration( input_priv(p_input)->p_item, i_length );
81 val.i_int = i_length;
82 var_Change( p_input, "length", VLC_VAR_SETVALUE, &val, NULL );
84 Trigger( p_input, INPUT_EVENT_LENGTH );
86 void input_SendEventStatistics( input_thread_t *p_input )
88 Trigger( p_input, INPUT_EVENT_STATISTICS );
90 void input_SendEventRate( input_thread_t *p_input, int i_rate )
92 vlc_value_t val;
94 val.f_float = (float)INPUT_RATE_DEFAULT / (float)i_rate;
95 var_Change( p_input, "rate", VLC_VAR_SETVALUE, &val, NULL );
97 Trigger( p_input, INPUT_EVENT_RATE );
99 void input_SendEventAudioDelay( input_thread_t *p_input, mtime_t i_delay )
101 vlc_value_t val;
103 val.i_int = i_delay;
104 var_Change( p_input, "audio-delay", VLC_VAR_SETVALUE, &val, NULL );
106 Trigger( p_input, INPUT_EVENT_AUDIO_DELAY );
109 void input_SendEventSubtitleDelay( input_thread_t *p_input, mtime_t i_delay )
111 vlc_value_t val;
113 val.i_int = i_delay;
114 var_Change( p_input, "spu-delay", VLC_VAR_SETVALUE, &val, NULL );
116 Trigger( p_input, INPUT_EVENT_SUBTITLE_DELAY );
119 /* TODO and file name ? */
120 void input_SendEventRecord( input_thread_t *p_input, bool b_recording )
122 vlc_value_t val;
124 val.b_bool = b_recording;
125 var_Change( p_input, "record", VLC_VAR_SETVALUE, &val, NULL );
127 Trigger( p_input, INPUT_EVENT_RECORD );
130 void input_SendEventTitle( input_thread_t *p_input, int i_title )
132 vlc_value_t val;
134 val.i_int = i_title;
135 var_Change( p_input, "title", VLC_VAR_SETVALUE, &val, NULL );
137 input_ControlVarTitle( p_input, i_title );
139 Trigger( p_input, INPUT_EVENT_TITLE );
142 void input_SendEventSeekpoint( input_thread_t *p_input, int i_title, int i_seekpoint )
144 vlc_value_t val;
146 /* "chapter" */
147 val.i_int = i_seekpoint;
148 var_Change( p_input, "chapter", VLC_VAR_SETVALUE, &val, NULL );
150 /* "title %2u" */
151 char psz_title[sizeof ("title ") + 3 * sizeof (int)];
152 sprintf( psz_title, "title %2u", i_title );
153 var_Change( p_input, psz_title, VLC_VAR_SETVALUE, &val, NULL );
155 /* */
156 Trigger( p_input, INPUT_EVENT_CHAPTER );
159 void input_SendEventSignal( input_thread_t *p_input, double f_quality, double f_strength )
161 vlc_value_t val;
163 val.f_float = f_quality;
164 var_Change( p_input, "signal-quality", VLC_VAR_SETVALUE, &val, NULL );
166 val.f_float = f_strength;
167 var_Change( p_input, "signal-strength", VLC_VAR_SETVALUE, &val, NULL );
169 Trigger( p_input, INPUT_EVENT_SIGNAL );
172 void input_SendEventState( input_thread_t *p_input, int i_state )
174 vlc_value_t val;
176 val.i_int = i_state;
177 var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
179 Trigger( p_input, INPUT_EVENT_STATE );
182 void input_SendEventCache( input_thread_t *p_input, double f_level )
184 vlc_value_t val;
186 val.f_float = f_level;
187 var_Change( p_input, "cache", VLC_VAR_SETVALUE, &val, NULL );
189 Trigger( p_input, INPUT_EVENT_CACHE );
192 void input_SendEventMeta( input_thread_t *p_input )
194 Trigger( p_input, INPUT_EVENT_ITEM_META );
197 void input_SendEventMetaInfo( input_thread_t *p_input )
199 Trigger( p_input, INPUT_EVENT_ITEM_INFO );
202 void input_SendEventMetaEpg( input_thread_t *p_input )
204 Trigger( p_input, INPUT_EVENT_ITEM_EPG );
206 /*****************************************************************************
207 * Event for es_out.c
208 *****************************************************************************/
209 void input_SendEventProgramAdd( input_thread_t *p_input,
210 int i_program, const char *psz_text )
212 VarListAdd( p_input, "program", INPUT_EVENT_PROGRAM, i_program, psz_text );
214 void input_SendEventProgramDel( input_thread_t *p_input, int i_program )
216 VarListDel( p_input, "program", INPUT_EVENT_PROGRAM, i_program );
218 void input_SendEventProgramSelect( input_thread_t *p_input, int i_program )
220 VarListSelect( p_input, "program", INPUT_EVENT_PROGRAM, i_program );
222 void input_SendEventProgramScrambled( input_thread_t *p_input, int i_group, bool b_scrambled )
224 if( var_GetInteger( p_input, "program" ) != i_group )
225 return;
227 var_SetBool( p_input, "program-scrambled", b_scrambled );
228 Trigger( p_input, INPUT_EVENT_PROGRAM );
231 static const char *GetEsVarName( enum es_format_category_e i_cat )
233 switch( i_cat )
235 case VIDEO_ES:
236 return "video-es";
237 case AUDIO_ES:
238 return "audio-es";
239 case SPU_ES:
240 return "spu-es";
241 default:
242 return NULL;
245 void input_SendEventEsAdd( input_thread_t *p_input, enum es_format_category_e i_cat, int i_id, const char *psz_text )
247 const char *psz_varname = GetEsVarName( i_cat );
248 if( psz_varname )
249 VarListAdd( p_input, psz_varname, INPUT_EVENT_ES, i_id, psz_text );
251 void input_SendEventEsDel( input_thread_t *p_input, enum es_format_category_e i_cat, int i_id )
253 const char *psz_varname = GetEsVarName( i_cat );
254 if( psz_varname )
255 VarListDel( p_input, psz_varname, INPUT_EVENT_ES, i_id );
257 /* i_id == -1 will unselect */
258 void input_SendEventEsSelect( input_thread_t *p_input, enum es_format_category_e i_cat, int i_id )
260 const char *psz_varname = GetEsVarName( i_cat );
261 if( psz_varname )
262 VarListSelect( p_input, psz_varname, INPUT_EVENT_ES, i_id );
265 void input_SendEventTeletextAdd( input_thread_t *p_input,
266 int i_teletext, const char *psz_text )
268 VarListAdd( p_input, "teletext-es", INPUT_EVENT_TELETEXT, i_teletext, psz_text );
270 void input_SendEventTeletextDel( input_thread_t *p_input, int i_teletext )
272 VarListDel( p_input, "teletext-es", INPUT_EVENT_TELETEXT, i_teletext );
274 void input_SendEventTeletextSelect( input_thread_t *p_input, int i_teletext )
276 VarListSelect( p_input, "teletext-es", INPUT_EVENT_TELETEXT, i_teletext );
279 void input_SendEventVout( input_thread_t *p_input )
281 Trigger( p_input, INPUT_EVENT_VOUT );
284 void input_SendEventAout( input_thread_t *p_input )
286 Trigger( p_input, INPUT_EVENT_AOUT );
289 /*****************************************************************************
290 * Event for control.c/input.c
291 *****************************************************************************/
292 void input_SendEventBookmark( input_thread_t *p_input )
294 Trigger( p_input, INPUT_EVENT_BOOKMARK );
297 /*****************************************************************************
299 *****************************************************************************/
300 static void Trigger( input_thread_t *p_input, int i_type )
302 var_SetInteger( p_input, "intf-event", i_type );
304 static void VarListAdd( input_thread_t *p_input,
305 const char *psz_variable, int i_event,
306 int i_value, const char *psz_text )
308 vlc_value_t val;
309 vlc_value_t text;
311 val.i_int = i_value;
312 text.psz_string = (char*)psz_text;
314 var_Change( p_input, psz_variable, VLC_VAR_ADDCHOICE,
315 &val, psz_text ? &text : NULL );
317 Trigger( p_input, i_event );
319 static void VarListDel( input_thread_t *p_input,
320 const char *psz_variable, int i_event,
321 int i_value )
323 vlc_value_t val;
325 if( i_value >= 0 )
327 val.i_int = i_value;
328 var_Change( p_input, psz_variable, VLC_VAR_DELCHOICE, &val, NULL );
330 else
332 var_Change( p_input, psz_variable, VLC_VAR_CLEARCHOICES, &val, NULL );
335 Trigger( p_input, i_event );
337 static void VarListSelect( input_thread_t *p_input,
338 const char *psz_variable, int i_event,
339 int i_value )
341 vlc_value_t val;
343 val.i_int = i_value;
344 var_Change( p_input, psz_variable, VLC_VAR_SETVALUE, &val, NULL );
346 Trigger( p_input, i_event );