1 /*****************************************************************************
2 * timer.cpp : wxWindows plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2001 VideoLAN
5 * $Id: timer.cpp,v 1.13 2003/04/17 14:00:44 anil Exp $
7 * Authors: Gildas Bazin <gbazin@netcourrier.com>
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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
27 #include <stdlib.h> /* malloc(), free() */
28 #include <errno.h> /* ENOMEM */
29 #include <string.h> /* strerror() */
34 #ifdef WIN32 /* mingw32 hack */
39 /* Let vlc take care of the i18n stuff */
40 #define WXINTL_NO_GETTEXT_MACRO
42 #include <wx/wxprec.h>
48 #include "wxwindows.h"
50 void DisplayStreamDate( wxControl *, intf_thread_t *, int );
52 /*****************************************************************************
54 *****************************************************************************/
55 Timer::Timer( intf_thread_t *_p_intf, Interface *_p_main_interface )
58 p_main_interface = _p_main_interface;
59 i_old_playing_status = PAUSE_S;
61 Start( 100 /*milliseconds*/, wxTIMER_CONTINUOUS );
68 /*****************************************************************************
70 *****************************************************************************/
71 /*****************************************************************************
72 * wxModeManage: actualise the aspect of the interface whenever the input
74 *****************************************************************************
75 * The lock has to be taken before you call the function.
76 *****************************************************************************/
77 static int wxModeManage( intf_thread_t * p_intf )
82 /*****************************************************************************
83 * wxSetupMenus: function that generates title/chapter/audio/subpic
84 * menus with help from preceding functions
85 *****************************************************************************
86 * Function called with the lock on stream
87 *****************************************************************************/
88 static int wxSetupMenus( intf_thread_t * p_intf )
93 /*****************************************************************************
94 * Manage: manage main thread messages
95 *****************************************************************************
96 * In this function, called approx. 10 times a second, we check what the
97 * main program wanted to tell us.
98 *****************************************************************************/
101 vlc_bool_t b_pace_control;
103 vlc_mutex_lock( &p_intf->change_lock );
105 /* If the "display popup" flag has changed */
106 if( p_intf->b_menu_change )
108 p_main_interface->p_popup_menu =
109 new PopupMenu( p_intf, p_main_interface );
110 p_intf->b_menu_change = 0;
113 /* Update the log window */
114 p_intf->p_sys->p_messages_window->UpdateLog();
116 /* Update the playlist */
117 p_intf->p_sys->p_playlist_window->Manage();
119 /* Update the fileinfo windows */
120 p_intf->p_sys->p_fileinfo_window->UpdateFileInfo();
122 /* Update the input */
123 if( p_intf->p_sys->p_input == NULL )
125 p_intf->p_sys->p_input = (input_thread_t *)vlc_object_find( p_intf,
130 if( p_intf->p_sys->p_input )
132 //if( p_intf->p_sys->p_input->stream.b_seekable )
134 p_main_interface->slider_frame->Show();
135 p_main_interface->frame_sizer->Show(
136 p_main_interface->slider_frame );
137 p_main_interface->frame_sizer->Layout();
138 p_main_interface->frame_sizer->Fit( p_main_interface );
141 p_main_interface->statusbar->SetStatusText(
142 p_intf->p_sys->p_input->psz_source, 1 );
144 p_main_interface->TogglePlayButton( PLAYING_S );
145 i_old_playing_status = PLAYING_S;
148 /* control buttons for free pace streams */
149 b_pace_control = p_intf->p_sys->p_input->stream.b_pace_control;
152 else if( p_intf->p_sys->p_input->b_dead )
155 //if( p_intf->p_sys->p_input->stream.b_seekable )
157 p_main_interface->slider_frame->Hide();
158 p_main_interface->frame_sizer->Hide(
159 p_main_interface->slider_frame );
160 p_main_interface->frame_sizer->Layout();
161 p_main_interface->frame_sizer->Fit( p_main_interface );
163 p_main_interface->TogglePlayButton( PAUSE_S );
164 i_old_playing_status = PAUSE_S;
167 p_main_interface->statusbar->SetStatusText( "", 1 );
169 vlc_object_release( p_intf->p_sys->p_input );
170 p_intf->p_sys->p_input = NULL;
175 if( p_intf->p_sys->p_input )
177 input_thread_t *p_input = p_intf->p_sys->p_input;
179 vlc_mutex_lock( &p_input->stream.stream_lock );
181 if( !p_input->b_die )
183 /* New input or stream map change */
184 p_intf->p_sys->b_playing = 1;
186 if( p_input->stream.b_changed )
188 wxModeManage( p_intf );
189 wxSetupMenus( p_intf );
190 p_intf->p_sys->b_playing = 1;
192 p_main_interface->TogglePlayButton( PLAYING_S );
193 i_old_playing_status = PLAYING_S;
197 /* Manage the slider */
198 if( p_input->stream.b_seekable && p_intf->p_sys->b_playing )
200 stream_position_t position;
202 /* Update the slider if the user isn't dragging it. */
203 if( p_intf->p_sys->b_slider_free )
205 /* Update the value */
206 vlc_mutex_unlock( &p_input->stream.stream_lock );
207 input_Tell( p_input, &position );
208 vlc_mutex_lock( &p_input->stream.stream_lock );
209 if( position.i_size )
211 p_intf->p_sys->i_slider_pos =
212 ( SLIDER_MAX_POS * position.i_tell ) / position.i_size;
214 p_main_interface->slider->SetValue(
215 p_intf->p_sys->i_slider_pos );
217 DisplayStreamDate( p_main_interface->slider_box,p_intf,
218 p_intf->p_sys->i_slider_pos );
223 if( p_intf->p_sys->i_part !=
224 p_input->stream.p_selected_area->i_part )
226 p_intf->p_sys->b_chapter_update = 1;
227 wxSetupMenus( p_intf );
230 /* Manage Playing status */
231 if( i_old_playing_status != p_input->stream.control.i_status )
233 if( p_input->stream.control.i_status == PAUSE_S )
235 p_main_interface->TogglePlayButton( PAUSE_S );
239 p_main_interface->TogglePlayButton( PLAYING_S );
241 i_old_playing_status = p_input->stream.control.i_status;
245 vlc_mutex_unlock( &p_input->stream.stream_lock );
247 else if( p_intf->p_sys->b_playing && !p_intf->b_die )
249 wxModeManage( p_intf );
250 p_intf->p_sys->b_playing = 0;
251 p_main_interface->TogglePlayButton( PAUSE_S );
252 i_old_playing_status = PAUSE_S;
257 vlc_mutex_unlock( &p_intf->change_lock );
259 /* Prepare to die, young Skywalker */
260 p_main_interface->Close(TRUE);
264 vlc_mutex_unlock( &p_intf->change_lock );
267 /*****************************************************************************
268 * DisplayStreamDate: display stream date
269 *****************************************************************************
270 * This function displays the current date related to the position in
271 * the stream. It is called whenever the slider changes its value.
272 * The lock has to be taken before you call the function.
273 *****************************************************************************/
274 void DisplayStreamDate( wxControl *p_slider_frame, intf_thread_t * p_intf ,
277 if( p_intf->p_sys->p_input )
279 #define p_area p_intf->p_sys->p_input->stream.p_selected_area
280 char psz_time[ OFFSETTOTIME_MAX_SIZE ];
282 p_slider_frame->SetLabel(
283 input_OffsetToTime( p_intf->p_sys->p_input,
285 p_area->i_size * i_pos / SLIDER_MAX_POS ) );