1 /*****************************************************************************
2 * timer.cpp : wxWindows plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000-2001 VideoLAN
5 * $Id: timer.cpp,v 1.5 2002/11/23 16:17:12 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() */
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;
60 Start( 100 /*milliseconds*/, wxTIMER_CONTINUOUS );
67 /*****************************************************************************
69 *****************************************************************************/
70 /*****************************************************************************
71 * wxModeManage: actualise the aspect of the interface whenever the input
73 *****************************************************************************
74 * The lock has to be taken before you call the function.
75 *****************************************************************************/
76 static int wxModeManage( intf_thread_t * p_intf )
81 /*****************************************************************************
82 * wxSetupMenus: function that generates title/chapter/audio/subpic
83 * menus with help from preceding functions
84 *****************************************************************************
85 * Function called with the lock on stream
86 *****************************************************************************/
87 static int wxSetupMenus( intf_thread_t * p_intf )
92 /*****************************************************************************
93 * Manage: manage main thread messages
94 *****************************************************************************
95 * In this function, called approx. 10 times a second, we check what the
96 * main program wanted to tell us.
97 *****************************************************************************/
102 vlc_mutex_lock( &p_intf->change_lock );
104 /* If the "display popup" flag has changed */
105 if( p_intf->b_menu_change )
107 p_intf->b_menu_change = 0;
110 /* Update the log window */
111 vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
112 i_stop = *p_intf->p_sys->p_sub->pi_stop;
113 vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
115 if( p_intf->p_sys->p_sub->i_start != i_stop )
117 /* Append all messages to log window */
120 /* Update the playlist */
121 p_intf->p_sys->p_playlist_window->Manage();
123 /* Update the input */
124 if( p_intf->p_sys->p_input == NULL )
126 p_intf->p_sys->p_input = (input_thread_t *)vlc_object_find( p_intf,
130 if(p_intf->p_sys->p_input)
132 p_main_interface->frame_sizer->Add(
133 p_main_interface->slider_frame, 1, wxGROW, 0 );
134 p_main_interface->slider_frame->Show();
135 p_main_interface->frame_sizer->Layout();
136 p_main_interface->frame_sizer->Fit( p_main_interface );
137 p_main_interface->statusbar->SetStatusText(
138 p_intf->p_sys->p_input->psz_source, 1 );
141 else if( p_intf->p_sys->p_input->b_dead )
144 if(p_intf->p_sys->p_input)
146 p_main_interface->slider_frame->Hide();
147 p_main_interface->frame_sizer->Remove(
148 p_main_interface->slider_frame );
149 p_main_interface->frame_sizer->Layout();
150 p_main_interface->frame_sizer->Fit( p_main_interface );
153 p_main_interface->statusbar->SetStatusText( "", 1 );
155 vlc_object_release( p_intf->p_sys->p_input );
156 p_intf->p_sys->p_input = NULL;
159 if( p_intf->p_sys->p_input )
161 input_thread_t *p_input = p_intf->p_sys->p_input;
163 vlc_mutex_lock( &p_input->stream.stream_lock );
165 if( !p_input->b_die )
167 /* New input or stream map change */
168 if( p_input->stream.b_changed )
170 wxModeManage( p_intf );
171 wxSetupMenus( p_intf );
172 p_intf->p_sys->b_playing = 1;
175 /* Manage the slider */
176 if( p_input->stream.b_seekable && p_intf->p_sys->b_playing )
179 stream_position_t position;
181 /* If the user hasn't touched the slider since the last time,
182 * then the input can safely change it */
183 if( p_intf->p_sys->i_slider_pos ==
184 p_intf->p_sys->i_slider_oldpos )
186 /* Update the value */
187 vlc_mutex_unlock( &p_input->stream.stream_lock );
188 input_Tell( p_input, &position );
189 vlc_mutex_lock( &p_input->stream.stream_lock );
190 p_intf->p_sys->i_slider_oldpos =
191 ( SLIDER_MAX_POS * position.i_tell ) / position.i_size;
193 if( p_intf->p_sys->i_slider_pos !=
194 p_intf->p_sys->i_slider_oldpos )
196 p_intf->p_sys->i_slider_pos =
197 p_intf->p_sys->i_slider_oldpos;
199 p_main_interface->slider->SetValue(
200 p_intf->p_sys->i_slider_pos );
202 DisplayStreamDate( p_main_interface->slider_box,
204 p_intf->p_sys->i_slider_pos );
208 /* Otherwise, send message to the input if the user has
209 * finished dragging the slider */
210 else if( p_intf->p_sys->b_slider_free )
212 /* release the lock to be able to seek */
213 vlc_mutex_unlock( &p_input->stream.stream_lock );
214 input_Seek( p_input, p_intf->p_sys->i_slider_pos *
215 100 / SLIDER_MAX_POS,
216 INPUT_SEEK_PERCENT | INPUT_SEEK_SET );
217 vlc_mutex_lock( &p_input->stream.stream_lock );
219 /* Update the old value */
220 p_intf->p_sys->i_slider_oldpos =
221 p_intf->p_sys->i_slider_pos;
225 if( p_intf->p_sys->i_part !=
226 p_input->stream.p_selected_area->i_part )
228 p_intf->p_sys->b_chapter_update = 1;
229 wxSetupMenus( p_intf );
233 vlc_mutex_unlock( &p_input->stream.stream_lock );
235 else if( p_intf->p_sys->b_playing && !p_intf->b_die )
237 wxModeManage( p_intf );
238 p_intf->p_sys->b_playing = 0;
243 vlc_mutex_unlock( &p_intf->change_lock );
245 /* Prepare to die, young Skywalker */
246 p_main_interface->Close(TRUE);
250 vlc_mutex_unlock( &p_intf->change_lock );
253 /*****************************************************************************
254 * DisplayStreamDate: display stream date
255 *****************************************************************************
256 * This function displays the current date related to the position in
257 * the stream. It is called whenever the slider changes its value.
258 * The lock has to be taken before you call the function.
259 *****************************************************************************/
260 void DisplayStreamDate( wxControl *p_slider_frame, intf_thread_t * p_intf ,
263 if( p_intf->p_sys->p_input )
265 #define p_area p_intf->p_sys->p_input->stream.p_selected_area
266 char psz_time[ OFFSETTOTIME_MAX_SIZE ];
268 p_slider_frame->SetLabel(
269 input_OffsetToTime( p_intf->p_sys->p_input,
271 p_area->i_size * i_pos / SLIDER_MAX_POS ) );