Configure needs AS to be set for the Makefiles.
[mplayer/glamo.git] / gui / mplayer / play.c
blobb398f9f90141f3a0e6e14fc1c126eb4fbe480f43
1 /*
2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include <inttypes.h>
20 #include <stdlib.h>
21 #include <stdio.h>
22 #include <string.h>
24 #include <unistd.h>
25 #include <signal.h>
27 #include "config.h"
28 #include "help_mp.h"
29 #include "libvo/x11_common.h"
30 #include "libvo/video_out.h"
31 #include "input/input.h"
33 #include "gui/wm/ws.h"
34 #include "gui/wm/wsxdnd.h"
36 #include "gui/app.h"
37 #include "gui/wm/wskeys.h"
38 #include "gui/interface.h"
40 #include "widgets.h"
41 #include "gmplayer.h"
42 #include "play.h"
44 #include "gui/skin/skin.h"
45 #include "gui/skin/font.h"
47 #include "stream/stream.h"
49 extern float rel_seek_secs;
50 extern int abs_seek_pos;
52 int mplGotoTheNext = 1;
54 void mplFullScreen( void )
56 if ( guiIntfStruct.NoWindow && guiIntfStruct.Playing ) return;
58 if ( ( guiIntfStruct.Playing )&&( appMPlayer.subWindow.isFullScreen ) )
60 appMPlayer.subWindow.OldWidth=guiIntfStruct.MovieWidth; appMPlayer.subWindow.OldHeight=guiIntfStruct.MovieHeight;
61 switch ( appMPlayer.sub.x )
63 case -1: appMPlayer.subWindow.OldX=( wsMaxX / 2 ) - ( appMPlayer.subWindow.OldWidth / 2 ) + wsOrgX; break;
64 case -2: appMPlayer.subWindow.OldX=wsMaxX - appMPlayer.subWindow.OldWidth + wsOrgX; break;
65 default: appMPlayer.subWindow.OldX=appMPlayer.sub.x; break;
67 switch ( appMPlayer.sub.y )
69 case -1: appMPlayer.subWindow.OldY=( wsMaxY / 2 ) - ( appMPlayer.subWindow.OldHeight / 2 ) + wsOrgY; break;
70 case -2: appMPlayer.subWindow.OldY=wsMaxY - appMPlayer.subWindow.OldHeight + wsOrgY; break;
71 default: appMPlayer.subWindow.OldY=appMPlayer.sub.y; break;
74 if ( guiIntfStruct.Playing || gtkShowVideoWindow ) wsFullScreen( &appMPlayer.subWindow );
75 fullscreen=vo_fs=appMPlayer.subWindow.isFullScreen;
76 wsSetLayer( wsDisplay,appMPlayer.mainWindow.WindowID,appMPlayer.subWindow.isFullScreen );
77 if ( appMPlayer.menuIsPresent ) wsSetLayer( wsDisplay,appMPlayer.menuWindow.WindowID,appMPlayer.subWindow.isFullScreen );
79 if ( guiIntfStruct.Playing ) wsSetBackgroundRGB( &appMPlayer.subWindow,0,0,0 );
80 else wsSetBackgroundRGB( &appMPlayer.subWindow,appMPlayer.sub.R,appMPlayer.sub.G,appMPlayer.sub.B );
83 void mplEnd( void )
85 plItem * next;
87 if ( !mplGotoTheNext && guiIntfStruct.Playing) { mplGotoTheNext=1; return; }
89 if ( guiIntfStruct.Playing && (next=gtkSet( gtkGetNextPlItem,0,NULL )) && plLastPlayed != next )
91 plLastPlayed=next;
92 guiSetDF( guiIntfStruct.Filename,next->path,next->name );
93 guiIntfStruct.StreamType=STREAMTYPE_FILE;
94 guiIntfStruct.FilenameChanged=guiIntfStruct.NewPlay=1;
95 gfree( (void **)&guiIntfStruct.AudioFile );
96 gfree( (void **)&guiIntfStruct.Subtitlename );
98 else
100 if ( guiIntfStruct.FilenameChanged || guiIntfStruct.NewPlay ) return;
102 guiIntfStruct.TimeSec=0;
103 guiIntfStruct.Position=0;
104 guiIntfStruct.AudioType=0;
105 guiIntfStruct.NoWindow=False;
107 #ifdef CONFIG_DVDREAD
108 guiIntfStruct.DVD.current_title=1;
109 guiIntfStruct.DVD.current_chapter=1;
110 guiIntfStruct.DVD.current_angle=1;
111 #endif
113 if ( !appMPlayer.subWindow.isFullScreen && gtkShowVideoWindow)
115 wsResizeWindow( &appMPlayer.subWindow,appMPlayer.sub.width,appMPlayer.sub.height );
116 wsMoveWindow( &appMPlayer.subWindow,True,appMPlayer.sub.x,appMPlayer.sub.y );
118 else wsVisibleWindow( &appMPlayer.subWindow,wsHideWindow );
119 guiGetEvent( guiCEvent,guiSetStop );
120 mplSubRender=1;
121 wsSetBackgroundRGB( &appMPlayer.subWindow,appMPlayer.sub.R,appMPlayer.sub.G,appMPlayer.sub.B );
122 wsClearWindow( appMPlayer.subWindow );
123 wsPostRedisplay( &appMPlayer.subWindow );
127 void mplPlay( void )
129 if ( ( !guiIntfStruct.Filename )||
130 ( guiIntfStruct.Filename[0] == 0 )||
131 ( guiIntfStruct.Playing == 1 ) ) return;
132 if ( guiIntfStruct.Playing == 2 ) { mplPause(); return; }
133 guiGetEvent( guiCEvent,(void *)guiSetPlay );
134 mplSubRender=0;
135 wsSetBackgroundRGB( &appMPlayer.subWindow,0,0,0 );
136 wsClearWindow( appMPlayer.subWindow );
139 void mplPause( void )
141 if ( !guiIntfStruct.Playing ) return;
142 if ( guiIntfStruct.Playing == 1 )
144 mp_cmd_t * cmd = calloc( 1,sizeof( *cmd ) );
145 cmd->id=MP_CMD_PAUSE;
146 cmd->name=strdup("pause");
147 mp_input_queue_cmd(cmd);
148 } else guiIntfStruct.Playing=1;
151 void mplState( void )
153 if ( ( guiIntfStruct.Playing == 0 )||( guiIntfStruct.Playing == 2 ) )
155 btnModify( evPlaySwitchToPause,btnReleased );
156 btnModify( evPauseSwitchToPlay,btnDisabled );
158 else
160 btnModify( evPlaySwitchToPause,btnDisabled );
161 btnModify( evPauseSwitchToPlay,btnReleased );
165 float mplGetPosition( void )
166 { // return 0.0 ... 100.0
167 return guiIntfStruct.Position;
170 void mplRelSeek( float s )
171 { // -+s
172 rel_seek_secs=s; abs_seek_pos=0;
175 void mplAbsSeek( float s )
176 { // 0.0 ... 100.0
177 if ( guiIntfStruct.StreamType == STREAMTYPE_STREAM ) return;
178 rel_seek_secs=0.01*s; abs_seek_pos=3;
181 listItems tmpList;
183 void ChangeSkin( char * name )
185 int ret;
186 int prev = appMPlayer.menuIsPresent;
187 int bprev = appMPlayer.barIsPresent;
189 mainVisible=0;
191 appInitStruct( &tmpList );
192 skinAppMPlayer=&tmpList;
193 fntFreeFont();
194 ret=skinRead( name );
196 appInitStruct( &tmpList );
197 skinAppMPlayer=&appMPlayer;
198 appInitStruct( &appMPlayer );
199 if ( ret ) name=skinName;
200 if ( skinRead( name ) )
202 mainVisible=1;
203 return;
206 // --- reload menu window
208 if ( prev && appMPlayer.menuIsPresent )
210 if ( mplMenuDrawBuffer ) free( mplMenuDrawBuffer );
211 if ( ( mplMenuDrawBuffer = calloc( 1,appMPlayer.menuBase.Bitmap.ImageSize ) ) == NULL )
212 { mp_msg( MSGT_GPLAYER,MSGL_STATUS,MSGTR_NEMDB ); return; }
213 wsResizeWindow( &appMPlayer.menuWindow,appMPlayer.menuBase.width,appMPlayer.menuBase.height );
214 wsResizeImage( &appMPlayer.menuWindow,appMPlayer.menuBase.width,appMPlayer.menuBase.height );
215 wsSetShape( &appMPlayer.menuWindow,appMPlayer.menuBase.Mask.Image );
216 wsVisibleWindow( &appMPlayer.menuWindow,wsHideWindow );
217 } else { mplMenuInit(); }
219 // --- reload sub window
220 if ( appMPlayer.sub.Bitmap.Image ) wsResizeImage( &appMPlayer.subWindow,appMPlayer.sub.Bitmap.Width,appMPlayer.sub.Bitmap.Height );
221 if ( ( !appMPlayer.subWindow.isFullScreen )&&( !guiIntfStruct.Playing ) )
223 wsResizeWindow( &appMPlayer.subWindow,appMPlayer.sub.width,appMPlayer.sub.height );
224 wsMoveWindow( &appMPlayer.subWindow,True,appMPlayer.sub.x,appMPlayer.sub.y );
226 if ( appMPlayer.sub.Bitmap.Image ) wsConvert( &appMPlayer.subWindow,appMPlayer.sub.Bitmap.Image,appMPlayer.sub.Bitmap.ImageSize );
227 if ( !guiIntfStruct.Playing )
229 mplSubRender=1;
230 wsSetBackgroundRGB( &appMPlayer.subWindow,appMPlayer.sub.R,appMPlayer.sub.G,appMPlayer.sub.B );
231 wsClearWindow( appMPlayer.subWindow );
232 wsPostRedisplay( &appMPlayer.subWindow );
235 // --- reload play bar
236 if ( bprev ) wsDestroyWindow( &appMPlayer.barWindow );
237 mplPBInit();
239 // --- reload main window
240 if ( mplDrawBuffer ) free( mplDrawBuffer );
241 if ( ( mplDrawBuffer = calloc( 1,appMPlayer.main.Bitmap.ImageSize ) ) == NULL )
242 { mp_msg( MSGT_GPLAYER,MSGL_STATUS,MSGTR_NEMDB ); return; }
244 wsDestroyWindow( &appMPlayer.mainWindow );
246 wsCreateWindow( &appMPlayer.mainWindow,
247 appMPlayer.main.x,appMPlayer.main.y,appMPlayer.main.width,appMPlayer.main.height,
248 wsNoBorder,wsShowMouseCursor|wsHandleMouseButton|wsHandleMouseMove,wsShowFrame|wsMaxSize|wsHideWindow,"MPlayer" );
249 wsCreateImage( &appMPlayer.mainWindow,appMPlayer.main.Bitmap.Width,appMPlayer.main.Bitmap.Height );
250 wsSetShape( &appMPlayer.mainWindow,appMPlayer.main.Mask.Image );
251 wsSetIcon( wsDisplay,appMPlayer.mainWindow.WindowID,guiIcon,guiIconMask );
253 appMPlayer.mainWindow.ReDraw=(void *)mplMainDraw;
254 appMPlayer.mainWindow.MouseHandler=mplMainMouseHandle;
255 appMPlayer.mainWindow.KeyHandler=mplMainKeyHandle;
256 appMPlayer.mainWindow.DandDHandler=mplDandDHandler;
258 wsXDNDMakeAwareness( &appMPlayer.mainWindow );
259 if ( !appMPlayer.mainDecoration ) wsWindowDecoration( &appMPlayer.mainWindow,0 );
260 wsVisibleWindow( &appMPlayer.mainWindow,wsShowWindow );
261 mainVisible=1;
262 // ---
264 btnModify( evSetVolume,guiIntfStruct.Volume );
265 btnModify( evSetBalance,guiIntfStruct.Balance );
266 btnModify( evSetMoviePosition,guiIntfStruct.Position );
267 btnModify( evFullScreen,!appMPlayer.subWindow.isFullScreen );
269 wsSetLayer( wsDisplay,appMPlayer.mainWindow.WindowID,appMPlayer.subWindow.isFullScreen );
270 wsSetLayer( wsDisplay,appMPlayer.menuWindow.WindowID,appMPlayer.subWindow.isFullScreen );
274 void mplSetFileName( char * dir,char * name,int type )
276 if ( !name ) return;
278 if ( !dir ) guiSetFilename( guiIntfStruct.Filename,name )
279 else guiSetDF( guiIntfStruct.Filename,dir,name );
281 // filename=guiIntfStruct.Filename;
282 guiIntfStruct.StreamType=type;
283 gfree( (void **)&guiIntfStruct.AudioFile );
284 gfree( (void **)&guiIntfStruct.Subtitlename );
287 void mplCurr( void )
289 plItem * curr;
290 int stop = 0;
292 if ( guiIntfStruct.Playing == 2 ) return;
293 switch ( guiIntfStruct.StreamType )
295 #ifdef CONFIG_DVDREAD
296 case STREAMTYPE_DVD:
297 break;
298 #endif
299 #ifdef CONFIG_VCD
300 case STREAMTYPE_VCD:
301 break;
302 #endif
303 default:
304 if ( (curr=gtkSet( gtkGetCurrPlItem,0,NULL)) )
306 mplSetFileName( curr->path,curr->name,STREAMTYPE_FILE );
307 mplGotoTheNext=0;
308 break;
310 return;
312 if ( stop ) mplEventHandling( evStop,0 );
313 if ( guiIntfStruct.Playing == 1 ) mplEventHandling( evPlay,0 );
317 void mplPrev( void )
319 plItem * prev;
320 int stop = 0;
322 if ( guiIntfStruct.Playing == 2 ) return;
323 switch ( guiIntfStruct.StreamType )
325 #ifdef CONFIG_DVDREAD
326 case STREAMTYPE_DVD:
327 if ( --guiIntfStruct.DVD.current_chapter == 0 )
329 guiIntfStruct.DVD.current_chapter=1;
330 if ( --guiIntfStruct.DVD.current_title <= 0 ) { guiIntfStruct.DVD.current_title=1; stop=1; }
332 guiIntfStruct.Track=guiIntfStruct.DVD.current_title;
333 break;
334 #endif
335 #ifdef CONFIG_VCD
336 case STREAMTYPE_VCD:
337 if ( --guiIntfStruct.Track == 0 ) { guiIntfStruct.Track=1; stop=1; }
338 break;
339 #endif
340 default:
341 if ( (prev=gtkSet( gtkGetPrevPlItem,0,NULL)) )
343 mplSetFileName( prev->path,prev->name,STREAMTYPE_FILE );
344 mplGotoTheNext=0;
345 break;
347 return;
349 if ( stop ) mplEventHandling( evStop,0 );
350 if ( guiIntfStruct.Playing == 1 ) mplEventHandling( evPlay,0 );
353 void mplNext( void )
355 int stop = 0;
356 plItem * next;
358 if ( guiIntfStruct.Playing == 2 ) return;
359 switch ( guiIntfStruct.StreamType )
361 #ifdef CONFIG_DVDREAD
362 case STREAMTYPE_DVD:
363 if ( guiIntfStruct.DVD.current_chapter++ == guiIntfStruct.DVD.chapters )
365 guiIntfStruct.DVD.current_chapter=1;
366 if ( ++guiIntfStruct.DVD.current_title > guiIntfStruct.DVD.titles ) { guiIntfStruct.DVD.current_title=guiIntfStruct.DVD.titles; stop=1; }
368 guiIntfStruct.Track=guiIntfStruct.DVD.current_title;
369 break;
370 #endif
371 #ifdef CONFIG_VCD
372 case STREAMTYPE_VCD:
373 if ( ++guiIntfStruct.Track > guiIntfStruct.VCDTracks ) { guiIntfStruct.Track=guiIntfStruct.VCDTracks; stop=1; }
374 break;
375 #endif
376 default:
377 if ( (next=gtkSet( gtkGetNextPlItem,0,NULL)) )
379 mplSetFileName( next->path,next->name,STREAMTYPE_FILE );
380 mplGotoTheNext=0;
381 break;
383 return;
385 if ( stop ) mplEventHandling( evStop,0 );
386 if ( guiIntfStruct.Playing == 1 ) mplEventHandling( evPlay,0 );