event.c 10.4 KB
Newer Older
1 2 3 4 5 6 7 8
/*****************************************************************************
 * event.c: Events
 *****************************************************************************
 * Copyright (C) 2008 Laurent Aimar
 * $Id$
 *
 * Authors: Laurent Aimar < fenrir _AT_ videolan _DOT_ org>
 *
Jean-Baptiste Kempf's avatar
LGPL  
Jean-Baptiste Kempf committed
9 10 11
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
12 13 14 15
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Jean-Baptiste Kempf's avatar
LGPL  
Jean-Baptiste Kempf committed
16 17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
18
 *
Jean-Baptiste Kempf's avatar
LGPL  
Jean-Baptiste Kempf committed
19 20 21
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 23 24 25 26 27 28 29 30 31 32 33 34
 *****************************************************************************/

/*****************************************************************************
 * Preamble
 *****************************************************************************/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <vlc_common.h>
#include <vlc_input.h>
#include "input_internal.h"
#include "event.h"
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
35
#include <assert.h>
36

37 38 39 40 41 42 43 44 45 46 47
/* */
static void Trigger( input_thread_t *, int i_type );
static void VarListAdd( input_thread_t *,
                        const char *psz_variable, int i_event,
                        int i_value, const char *psz_text );
static void VarListDel( input_thread_t *,
                        const char *psz_variable, int i_event,
                        int i_value );
static void VarListSelect( input_thread_t *,
                           const char *psz_variable, int i_event,
                           int i_value );
Laurent Aimar's avatar
Laurent Aimar committed
48

49 50 51
/*****************************************************************************
 * Event for input.c
 *****************************************************************************/
52 53 54 55 56
void input_SendEventDead( input_thread_t *p_input )
{
    Trigger( p_input, INPUT_EVENT_DEAD );
}

57
void input_SendEventPosition( input_thread_t *p_input, double f_position, mtime_t i_time )
58 59 60 61
{
    vlc_value_t val;

    /* */
62
    val.f_float = f_position;
63 64 65
    var_Change( p_input, "position", VLC_VAR_SETVALUE, &val, NULL );

    /* */
66
    val.i_int = i_time;
67 68
    var_Change( p_input, "time", VLC_VAR_SETVALUE, &val, NULL );

69 70 71 72 73 74
    Trigger( p_input, INPUT_EVENT_POSITION );
}
void input_SendEventLength( input_thread_t *p_input, mtime_t i_length )
{
    vlc_value_t val;

Antoine Cellerier's avatar
Antoine Cellerier committed
75
    /* FIXME ugly + what about meta change event ? */
76
    if( var_GetInteger( p_input, "length" ) == i_length )
77 78
        return;

79
    input_item_SetDuration( input_priv(p_input)->p_item, i_length );
80

81
    val.i_int = i_length;
82 83
    var_Change( p_input, "length", VLC_VAR_SETVALUE, &val, NULL );

84
    Trigger( p_input, INPUT_EVENT_LENGTH );
85 86 87
}
void input_SendEventStatistics( input_thread_t *p_input )
{
Laurent Aimar's avatar
Laurent Aimar committed
88
    Trigger( p_input, INPUT_EVENT_STATISTICS );
89 90 91
}
void input_SendEventRate( input_thread_t *p_input, int i_rate )
{
92
    vlc_value_t val;
93

94 95
    val.f_float = (float)INPUT_RATE_DEFAULT / (float)i_rate;
    var_Change( p_input, "rate", VLC_VAR_SETVALUE, &val, NULL );
96

Laurent Aimar's avatar
Laurent Aimar committed
97
    Trigger( p_input, INPUT_EVENT_RATE );
98 99 100
}
void input_SendEventAudioDelay( input_thread_t *p_input, mtime_t i_delay )
{
Antoine Cellerier's avatar
Antoine Cellerier committed
101
    vlc_value_t val;
102

103
    val.i_int = i_delay;
Antoine Cellerier's avatar
Antoine Cellerier committed
104
    var_Change( p_input, "audio-delay", VLC_VAR_SETVALUE, &val, NULL );
105

Laurent Aimar's avatar
Laurent Aimar committed
106
    Trigger( p_input, INPUT_EVENT_AUDIO_DELAY );
107 108 109 110
}

void input_SendEventSubtitleDelay( input_thread_t *p_input, mtime_t i_delay )
{
Antoine Cellerier's avatar
Antoine Cellerier committed
111
    vlc_value_t val;
112

113
    val.i_int = i_delay;
Antoine Cellerier's avatar
Antoine Cellerier committed
114
    var_Change( p_input, "spu-delay", VLC_VAR_SETVALUE, &val, NULL );
115

Laurent Aimar's avatar
Laurent Aimar committed
116
    Trigger( p_input, INPUT_EVENT_SUBTITLE_DELAY );
117 118 119 120 121
}

/* TODO and file name ? */
void input_SendEventRecord( input_thread_t *p_input, bool b_recording )
{
Antoine Cellerier's avatar
Antoine Cellerier committed
122
    vlc_value_t val;
123

Antoine Cellerier's avatar
Antoine Cellerier committed
124 125
    val.b_bool = b_recording;
    var_Change( p_input, "record", VLC_VAR_SETVALUE, &val, NULL );
126

Laurent Aimar's avatar
Laurent Aimar committed
127
    Trigger( p_input, INPUT_EVENT_RECORD );
128 129 130 131
}

void input_SendEventTitle( input_thread_t *p_input, int i_title )
{
Antoine Cellerier's avatar
Antoine Cellerier committed
132
    vlc_value_t val;
133

Antoine Cellerier's avatar
Antoine Cellerier committed
134 135
    val.i_int = i_title;
    var_Change( p_input, "title", VLC_VAR_SETVALUE, &val, NULL );
136

Antoine Cellerier's avatar
Antoine Cellerier committed
137
    input_ControlVarTitle( p_input, i_title );
138

Laurent Aimar's avatar
Laurent Aimar committed
139
    Trigger( p_input, INPUT_EVENT_TITLE );
140 141 142 143
}

void input_SendEventSeekpoint( input_thread_t *p_input, int i_title, int i_seekpoint )
{
Antoine Cellerier's avatar
Antoine Cellerier committed
144
    vlc_value_t val;
145

146
    /* "chapter" */
Antoine Cellerier's avatar
Antoine Cellerier committed
147 148
    val.i_int = i_seekpoint;
    var_Change( p_input, "chapter", VLC_VAR_SETVALUE, &val, NULL );
149

150 151 152
    /* "title %2u" */
    char psz_title[sizeof ("title ") + 3 * sizeof (int)];
    sprintf( psz_title, "title %2u", i_title );
153 154 155
    var_Change( p_input, psz_title, VLC_VAR_SETVALUE, &val, NULL );

    /* */
Laurent Aimar's avatar
Laurent Aimar committed
156
    Trigger( p_input, INPUT_EVENT_CHAPTER );
157 158 159 160
}

void input_SendEventSignal( input_thread_t *p_input, double f_quality, double f_strength )
{
Laurent Aimar's avatar
Laurent Aimar committed
161 162 163
    vlc_value_t val;

    val.f_float = f_quality;
Antoine Cellerier's avatar
Antoine Cellerier committed
164
    var_Change( p_input, "signal-quality", VLC_VAR_SETVALUE, &val, NULL );
165

Laurent Aimar's avatar
Laurent Aimar committed
166
    val.f_float = f_strength;
Antoine Cellerier's avatar
Antoine Cellerier committed
167
    var_Change( p_input, "signal-strength", VLC_VAR_SETVALUE, &val, NULL );
Laurent Aimar's avatar
Laurent Aimar committed
168 169

    Trigger( p_input, INPUT_EVENT_SIGNAL );
170 171 172 173 174 175 176 177 178
}

void input_SendEventState( input_thread_t *p_input, int i_state )
{
    vlc_value_t val;

    val.i_int = i_state;
    var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );

Laurent Aimar's avatar
Laurent Aimar committed
179
    Trigger( p_input, INPUT_EVENT_STATE );
180 181
}

182 183 184 185 186
void input_SendEventCache( input_thread_t *p_input, double f_level )
{
    vlc_value_t val;

    val.f_float = f_level;
Antoine Cellerier's avatar
Antoine Cellerier committed
187
    var_Change( p_input, "cache", VLC_VAR_SETVALUE, &val, NULL );
188 189 190 191

    Trigger( p_input, INPUT_EVENT_CACHE );
}

192 193
void input_SendEventMeta( input_thread_t *p_input )
{
Laurent Aimar's avatar
Laurent Aimar committed
194
    Trigger( p_input, INPUT_EVENT_ITEM_META );
195 196 197 198
}

void input_SendEventMetaInfo( input_thread_t *p_input )
{
Laurent Aimar's avatar
Laurent Aimar committed
199
    Trigger( p_input, INPUT_EVENT_ITEM_INFO );
200 201
}

202 203 204 205
void input_SendEventMetaEpg( input_thread_t *p_input )
{
    Trigger( p_input, INPUT_EVENT_ITEM_EPG );
}
206 207 208 209 210 211
/*****************************************************************************
 * Event for es_out.c
 *****************************************************************************/
void input_SendEventProgramAdd( input_thread_t *p_input,
                                int i_program, const char *psz_text )
{
212
    VarListAdd( p_input, "program", INPUT_EVENT_PROGRAM, i_program, psz_text );
213 214 215
}
void input_SendEventProgramDel( input_thread_t *p_input, int i_program )
{
216
    VarListDel( p_input, "program", INPUT_EVENT_PROGRAM, i_program );
217 218 219
}
void input_SendEventProgramSelect( input_thread_t *p_input, int i_program )
{
220
    VarListSelect( p_input, "program", INPUT_EVENT_PROGRAM, i_program );
221
}
222 223 224 225 226 227 228 229
void input_SendEventProgramScrambled( input_thread_t *p_input, int i_group, bool b_scrambled )
{
    if( var_GetInteger( p_input, "program" ) != i_group )
        return;

    var_SetBool( p_input, "program-scrambled", b_scrambled );
    Trigger( p_input, INPUT_EVENT_PROGRAM );
}
230

231
static const char *GetEsVarName( enum es_format_category_e i_cat )
232 233 234 235 236 237 238
{
    switch( i_cat )
    {
    case VIDEO_ES:
        return "video-es";
    case AUDIO_ES:
        return "audio-es";
239
    case SPU_ES:
240
        return "spu-es";
241 242
    default:
        return NULL;
243 244
    }
}
245
void input_SendEventEsAdd( input_thread_t *p_input, enum es_format_category_e i_cat, int i_id, const char *psz_text )
246
{
247 248 249
    const char *psz_varname = GetEsVarName( i_cat );
    if( psz_varname )
        VarListAdd( p_input, psz_varname, INPUT_EVENT_ES, i_id, psz_text );
250
}
251
void input_SendEventEsDel( input_thread_t *p_input, enum es_format_category_e i_cat, int i_id )
252
{
253 254 255
    const char *psz_varname = GetEsVarName( i_cat );
    if( psz_varname )
        VarListDel( p_input, psz_varname, INPUT_EVENT_ES, i_id );
256
}
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 )
259
{
260 261 262
    const char *psz_varname = GetEsVarName( i_cat );
    if( psz_varname )
        VarListSelect( p_input, psz_varname, INPUT_EVENT_ES, i_id );
263 264
}

265 266
void input_SendEventTeletextAdd( input_thread_t *p_input,
                                 int i_teletext, const char *psz_text )
Laurent Aimar's avatar
Laurent Aimar committed
267
{
268 269 270 271 272 273 274 275 276
    VarListAdd( p_input, "teletext-es", INPUT_EVENT_TELETEXT, i_teletext, psz_text );
}
void input_SendEventTeletextDel( input_thread_t *p_input, int i_teletext )
{
    VarListDel( p_input, "teletext-es", INPUT_EVENT_TELETEXT, i_teletext );
}
void input_SendEventTeletextSelect( input_thread_t *p_input, int i_teletext )
{
    VarListSelect( p_input, "teletext-es", INPUT_EVENT_TELETEXT, i_teletext );
Laurent Aimar's avatar
Laurent Aimar committed
277 278
}

Laurent Aimar's avatar
Laurent Aimar committed
279 280 281 282 283
void input_SendEventVout( input_thread_t *p_input )
{
    Trigger( p_input, INPUT_EVENT_VOUT );
}

284 285 286 287 288
void input_SendEventAout( input_thread_t *p_input )
{
    Trigger( p_input, INPUT_EVENT_AOUT );
}

289 290 291 292 293 294 295 296
/*****************************************************************************
 * Event for control.c/input.c
 *****************************************************************************/
void input_SendEventBookmark( input_thread_t *p_input )
{
    Trigger( p_input, INPUT_EVENT_BOOKMARK );
}

Laurent Aimar's avatar
Laurent Aimar committed
297 298 299 300 301 302 303
/*****************************************************************************
 *
 *****************************************************************************/
static void Trigger( input_thread_t *p_input, int i_type )
{
    var_SetInteger( p_input, "intf-event", i_type );
}
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349
static void VarListAdd( input_thread_t *p_input,
                        const char *psz_variable, int i_event,
                        int i_value, const char *psz_text )
{
    vlc_value_t val;
    vlc_value_t text;

    val.i_int = i_value;
    text.psz_string = (char*)psz_text;

    var_Change( p_input, psz_variable, VLC_VAR_ADDCHOICE,
                &val, psz_text ? &text : NULL );

    Trigger( p_input, i_event );
}
static void VarListDel( input_thread_t *p_input,
                        const char *psz_variable, int i_event,
                        int i_value )
{
    vlc_value_t val;

    if( i_value >= 0 )
    {
        val.i_int = i_value;
        var_Change( p_input, psz_variable, VLC_VAR_DELCHOICE, &val, NULL );
    }
    else
    {
        var_Change( p_input, psz_variable, VLC_VAR_CLEARCHOICES, &val, NULL );
    }

    Trigger( p_input, i_event );
}
static void VarListSelect( input_thread_t *p_input,
                           const char *psz_variable, int i_event,
                           int i_value )
{
    vlc_value_t val;

    val.i_int = i_value;
    var_Change( p_input, psz_variable, VLC_VAR_SETVALUE, &val, NULL );

    Trigger( p_input, i_event );
}