1 /*****************************************************************************
2 * input_manager.cpp : Manage an input and interact with its GUI elements
3 ****************************************************************************
4 * Copyright (C) 2006-2007 the VideoLAN team
7 * Authors: Clément Stenac <zorglub@videolan.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 *****************************************************************************/
25 #include "input_manager.hpp"
26 #include "dialogs_provider.hpp"
28 static int ChangeVideo( vlc_object_t *p_this, const char *var, vlc_value_t o,
29 vlc_value_t n, void *param );
30 static int ChangeAudio( vlc_object_t *p_this, const char *var, vlc_value_t o,
31 vlc_value_t n, void *param );
33 /**********************************************************************
34 * InputManager implementation
35 **********************************************************************/
37 InputManager::InputManager( QObject *parent, intf_thread_t *_p_intf) :
38 QObject( parent ), p_intf( _p_intf )
40 i_old_playing_status = END_S;
42 ON_TIMEOUT( update() );
45 InputManager::~InputManager()
50 void InputManager::setInput( input_thread_t *_p_input )
54 emit positionUpdated( 0.0,0,0 );
55 b_had_audio = b_had_video = b_has_audio = b_has_video = false;
58 vlc_object_yield( p_input );
60 var_Change( p_input, "video-es", VLC_VAR_CHOICESCOUNT, &val, NULL );
61 b_has_video = val.i_int > 0;
62 var_Change( p_input, "audio-es", VLC_VAR_CHOICESCOUNT, &val, NULL );
63 b_has_audio = val.i_int > 0;
64 var_AddCallback( p_input, "audio-es", ChangeAudio, this );
65 var_AddCallback( p_input, "video-es", ChangeVideo, this );
69 void InputManager::delInput()
73 var_DelCallback( p_input, "audio-es", ChangeAudio, this );
74 var_DelCallback( p_input, "video-es", ChangeVideo, this );
75 vlc_object_release( p_input );
80 void InputManager::update()
82 /// \todo Emit the signals only if it changed
83 if( !p_input ) return;
85 if( p_input->b_dead || p_input->b_die )
87 emit positionUpdated( 0.0, 0, 0 );
88 msg_Dbg( p_intf, "*********** NAV 0");
89 emit navigationChanged( 0 );
90 emit statusChanged( 0 ); // 0 = STOPPED, 1 = PLAY, 2 = PAUSE
95 if( !b_had_audio && b_has_audio )
97 if( !b_had_video && b_has_video )
100 /* Update position */
101 mtime_t i_length, i_time;
103 i_length = var_GetTime( p_input, "length" ) / 1000000;
104 i_time = var_GetTime( p_input, "time") / 1000000;
105 f_pos = var_GetFloat( p_input, "position" );
106 emit positionUpdated( f_pos, i_time, i_length );
108 /* Update disc status */
109 vlc_value_t val; val.i_int = 0;
110 var_Change( p_input, "title", VLC_VAR_CHOICESCOUNT, &val, NULL );
114 var_Change( p_input, "chapter", VLC_VAR_CHOICESCOUNT, &val, NULL );
117 msg_Dbg( p_intf, "******* CHAPTER");
118 emit navigationChanged( 1 ); // 1 = chapter, 2 = title, 0 = NO
122 msg_Dbg( p_intf, "******* TITLE");
123 emit navigationChanged( 2 );
128 emit navigationChanged( 0 );
133 if( input_GetItem(p_input)->p_meta &&
134 input_GetItem(p_input)->p_meta->psz_nowplaying &&
135 *input_GetItem(p_input)->p_meta->psz_nowplaying )
137 text.sprintf( "%s - %s",
138 input_GetItem(p_input)->p_meta->psz_nowplaying,
139 input_GetItem(p_input)->psz_name );
143 text.sprintf( "%s", input_GetItem(p_input)->psz_name );
145 emit nameChanged( text );
147 /* Update playing status */
148 var_Get( p_input, "state", &val );
149 val.i_int = val.i_int == PAUSE_S ? PAUSE_S : PLAYING_S;
150 if( i_old_playing_status != val.i_int )
152 i_old_playing_status = val.i_int;
153 emit statusChanged( val.i_int == PAUSE_S ? PAUSE_S : PLAYING_S );
157 void InputManager::sliderUpdate( float new_pos )
160 var_SetFloat( p_input, "position", new_pos );
163 void InputManager::togglePlayPause()
166 var_Get( p_input, "state", &state );
167 if( state.i_int != PAUSE_S )
169 /* A stream is being played, pause it */
170 state.i_int = PAUSE_S;
174 /* Stream is paused, resume it */
175 state.i_int = PLAYING_S;
177 var_Set( p_input, "state", state );
178 emit statusChanged( state.i_int );
181 void InputManager::sectionPrev()
185 int i_type = var_Type( p_input, "next-chapter" );
186 vlc_value_t val; val.b_bool = VLC_TRUE;
187 var_Set( p_input, (i_type & VLC_VAR_TYPE) != 0 ?
188 "prev-chapter":"prev-title", val );
192 void InputManager::sectionNext()
196 int i_type = var_Type( p_input, "next-chapter" );
197 vlc_value_t val; val.b_bool = VLC_TRUE;
198 var_Set( p_input, (i_type & VLC_VAR_TYPE) != 0 ?
199 "next-chapter":"next-title", val );
203 void InputManager::sectionMenu()
206 var_SetInteger( p_input, "title 0", 2);
209 void InputManager::slower()
212 var_SetVoid( p_input, "rate-slower" );
215 void InputManager::faster()
218 var_SetVoid( p_input, "rate-faster" );
221 void InputManager::normalRate()
224 var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT );
227 /**********************************************************************
228 * MainInputManager implementation. Wrap an input manager and
229 * take care of updating the main playlist input
230 **********************************************************************/
231 MainInputManager * MainInputManager::instance = NULL;
233 MainInputManager::MainInputManager( intf_thread_t *_p_intf ) : QObject(NULL),
237 im = new InputManager( this, p_intf );
238 ON_TIMEOUT( updateInput() );
239 /* Warn our embedded IM about input changes */
240 CONNECT( this, inputChanged( input_thread_t * ),
241 im, setInput( input_thread_t * ) );
244 MainInputManager::~MainInputManager()
246 if( p_input ) vlc_object_release( p_input );
249 void MainInputManager::updateInput()
251 vlc_mutex_lock( &p_intf->change_lock );
252 if( p_input && p_input->b_dead )
254 vlc_object_release( p_input );
257 emit inputChanged( NULL );
263 p_input = THEPL->p_input;
266 vlc_object_yield( p_input );
267 emit inputChanged( p_input );
271 vlc_mutex_unlock( &p_intf->change_lock );
274 void MainInputManager::stop()
276 playlist_Stop( THEPL );
279 void MainInputManager::next()
281 playlist_Next( THEPL );
284 void MainInputManager::prev()
286 playlist_Prev( THEPL );
289 void MainInputManager::togglePlayPause()
291 if( p_input == NULL )
293 playlist_Play( THEPL );
296 getIM()->togglePlayPause();
299 static int ChangeAudio( vlc_object_t *p_this, const char *var, vlc_value_t o,
300 vlc_value_t n, void *param )
302 InputManager *im = (InputManager*)param;
303 im->b_has_audio = true;
307 static int ChangeVideo( vlc_object_t *p_this, const char *var, vlc_value_t o,
308 vlc_value_t n, void *param )
310 InputManager *im = (InputManager*)param;
311 im->b_has_video = true;