1 /*****************************************************************************
2 * timer.cpp : wxWindows plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2001 VideoLAN
5 * $Id: timer.cpp,v 1.2 2002/11/20 14:24:00 gbazin 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() */
35 /* Let wxWindows take care of the i18n stuff */
38 #ifdef WIN32 /* mingw32 hack */
43 #include <wx/wxprec.h>
47 #include "wxwindows.h"
49 /*****************************************************************************
51 *****************************************************************************/
52 Timer::Timer( intf_thread_t *_p_intf, Interface *_p_main_interface )
55 p_main_interface = _p_main_interface;
57 Start( 100 /*milliseconds*/, wxTIMER_CONTINUOUS );
64 /*****************************************************************************
66 *****************************************************************************/
67 /*****************************************************************************
68 * wxModeManage: actualise the aspect of the interface whenever the input
70 *****************************************************************************
71 * The lock has to be taken before you call the function.
72 *****************************************************************************/
73 static int wxModeManage( intf_thread_t * p_intf )
78 /*****************************************************************************
79 * wxSetupMenus: function that generates title/chapter/audio/subpic
80 * menus with help from preceding functions
81 *****************************************************************************
82 * Function called with the lock on stream
83 *****************************************************************************/
84 static int wxSetupMenus( intf_thread_t * p_intf )
89 /*****************************************************************************
90 * Manage: manage main thread messages
91 *****************************************************************************
92 * In this function, called approx. 10 times a second, we check what the
93 * main program wanted to tell us.
94 *****************************************************************************/
99 vlc_mutex_lock( &p_intf->change_lock );
101 /* If the "display popup" flag has changed */
102 if( p_intf->b_menu_change )
104 p_intf->b_menu_change = 0;
107 /* Update the log window */
108 vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
109 i_stop = *p_intf->p_sys->p_sub->pi_stop;
110 vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
112 if( p_intf->p_sys->p_sub->i_start != i_stop )
116 /* Update the input */
117 if( p_intf->p_sys->p_input == NULL )
119 p_intf->p_sys->p_input = (input_thread_t *)vlc_object_find( p_intf,
123 if(p_intf->p_sys->p_input)
125 p_main_interface->slider->Show();
126 p_main_interface->statusbar->SetStatusText(
127 p_intf->p_sys->p_input->psz_source, 1 );
130 else if( p_intf->p_sys->p_input->b_dead )
133 if(p_intf->p_sys->p_input)
134 p_main_interface->slider->Hide();
136 p_main_interface->statusbar->SetStatusText( "", 1 );
138 vlc_object_release( p_intf->p_sys->p_input );
139 p_intf->p_sys->p_input = NULL;
142 if( p_intf->p_sys->p_input )
144 input_thread_t *p_input = p_intf->p_sys->p_input;
146 vlc_mutex_lock( &p_input->stream.stream_lock );
148 if( !p_input->b_die )
150 /* New input or stream map change */
151 if( p_input->stream.b_changed )
153 wxModeManage( p_intf );
154 wxSetupMenus( p_intf );
155 p_intf->p_sys->b_playing = 1;
158 /* Manage the slider */
159 if( p_input->stream.b_seekable && p_intf->p_sys->b_playing )
162 stream_position_t position;
164 /* If the user hasn't touched the slider since the last time,
165 * then the input can safely change it */
166 if( p_intf->p_sys->i_slider_pos ==
167 p_intf->p_sys->i_slider_oldpos )
169 /* Update the value */
170 vlc_mutex_unlock( &p_input->stream.stream_lock );
171 input_Tell( p_input, &position );
172 vlc_mutex_lock( &p_input->stream.stream_lock );
173 p_intf->p_sys->i_slider_oldpos =
174 ( 100 * position.i_tell ) / position.i_size;
176 if( p_intf->p_sys->i_slider_pos !=
177 p_intf->p_sys->i_slider_oldpos )
179 p_intf->p_sys->i_slider_pos =
180 p_intf->p_sys->i_slider_oldpos;
182 p_main_interface->slider->SetValue(
183 p_intf->p_sys->i_slider_pos );
187 /* Otherwise, send message to the input if the user has
188 * finished dragging the slider */
189 else if( p_intf->p_sys->b_slider_free )
191 /* release the lock to be able to seek */
192 vlc_mutex_unlock( &p_input->stream.stream_lock );
193 input_Seek( p_input, p_intf->p_sys->i_slider_pos,
194 INPUT_SEEK_PERCENT | INPUT_SEEK_SET );
195 vlc_mutex_lock( &p_input->stream.stream_lock );
197 /* Update the old value */
198 p_intf->p_sys->i_slider_oldpos =
199 p_intf->p_sys->i_slider_pos;
203 if( p_intf->p_sys->i_part !=
204 p_input->stream.p_selected_area->i_part )
206 p_intf->p_sys->b_chapter_update = 1;
207 wxSetupMenus( p_intf );
211 vlc_mutex_unlock( &p_input->stream.stream_lock );
213 else if( p_intf->p_sys->b_playing && !p_intf->b_die )
215 wxModeManage( p_intf );
216 p_intf->p_sys->b_playing = 0;
221 vlc_mutex_unlock( &p_intf->change_lock );
223 /* Prepare to die, young Skywalker */
224 p_main_interface->Close(TRUE);
228 vlc_mutex_unlock( &p_intf->change_lock );