Mercurial > mplayer.hg
annotate gui/mplayer/play.c @ 27839:9a46fffef0fc
vobsub: add sanity check
author | aurel |
---|---|
date | Sat, 01 Nov 2008 13:51:39 +0000 |
parents | 14c5017f40d2 |
children | 0f1b5b68af32 |
rev | line source |
---|---|
26458 | 1 /* |
2 * This file is part of MPlayer. | |
3 * | |
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. | |
8 * | |
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. | |
13 * | |
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. | |
17 */ | |
23077 | 18 |
19 #include <inttypes.h> | |
20 #include <stdlib.h> | |
21 #include <stdio.h> | |
22 #include <string.h> | |
23 | |
24 #include <unistd.h> | |
25 #include <signal.h> | |
26 | |
26382
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
27 #include "config.h" |
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
28 #include "help_mp.h" |
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
29 #include "libvo/x11_common.h" |
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
30 #include "libvo/video_out.h" |
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
31 #include "input/input.h" |
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
32 |
26365
10dfbc523184
Add gui/ prefix to some #include paths so that compilation from the
diego
parents:
26203
diff
changeset
|
33 #include "gui/wm/ws.h" |
10dfbc523184
Add gui/ prefix to some #include paths so that compilation from the
diego
parents:
26203
diff
changeset
|
34 #include "gui/wm/wsxdnd.h" |
23077 | 35 |
26365
10dfbc523184
Add gui/ prefix to some #include paths so that compilation from the
diego
parents:
26203
diff
changeset
|
36 #include "gui/app.h" |
10dfbc523184
Add gui/ prefix to some #include paths so that compilation from the
diego
parents:
26203
diff
changeset
|
37 #include "gui/wm/wskeys.h" |
10dfbc523184
Add gui/ prefix to some #include paths so that compilation from the
diego
parents:
26203
diff
changeset
|
38 #include "gui/interface.h" |
23077 | 39 |
40 #include "widgets.h" | |
41 #include "gmplayer.h" | |
42 #include "play.h" | |
43 | |
26365
10dfbc523184
Add gui/ prefix to some #include paths so that compilation from the
diego
parents:
26203
diff
changeset
|
44 #include "gui/skin/skin.h" |
10dfbc523184
Add gui/ prefix to some #include paths so that compilation from the
diego
parents:
26203
diff
changeset
|
45 #include "gui/skin/font.h" |
23077 | 46 |
47 #include "stream/stream.h" | |
48 | |
49 extern float rel_seek_secs; | |
50 extern int abs_seek_pos; | |
51 | |
52 int mplGotoTheNext = 1; | |
53 | |
54 void mplFullScreen( void ) | |
55 { | |
56 if ( guiIntfStruct.NoWindow && guiIntfStruct.Playing ) return; | |
57 | |
58 if ( ( guiIntfStruct.Playing )&&( appMPlayer.subWindow.isFullScreen ) ) | |
59 { | |
60 appMPlayer.subWindow.OldWidth=guiIntfStruct.MovieWidth; appMPlayer.subWindow.OldHeight=guiIntfStruct.MovieHeight; | |
61 switch ( appMPlayer.sub.x ) | |
62 { | |
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; | |
66 } | |
67 switch ( appMPlayer.sub.y ) | |
68 { | |
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; | |
72 } | |
73 } | |
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 ); | |
78 | |
79 if ( guiIntfStruct.Playing ) wsSetBackgroundRGB( &appMPlayer.subWindow,0,0,0 ); | |
80 else wsSetBackgroundRGB( &appMPlayer.subWindow,appMPlayer.sub.R,appMPlayer.sub.G,appMPlayer.sub.B ); | |
81 } | |
82 | |
83 void mplEnd( void ) | |
84 { | |
85 plItem * next; | |
86 | |
87 if ( !mplGotoTheNext && guiIntfStruct.Playing) { mplGotoTheNext=1; return; } | |
88 | |
89 if ( guiIntfStruct.Playing && (next=gtkSet( gtkGetNextPlItem,0,NULL )) && plLastPlayed != next ) | |
90 { | |
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 ); | |
97 } | |
98 else | |
99 { | |
100 if ( guiIntfStruct.FilenameChanged || guiIntfStruct.NewPlay ) return; | |
101 | |
102 guiIntfStruct.TimeSec=0; | |
103 guiIntfStruct.Position=0; | |
104 guiIntfStruct.AudioType=0; | |
105 guiIntfStruct.NoWindow=False; | |
106 | |
27341
e7c989f7a7c9
Start unifying names of internal preprocessor directives.
diego
parents:
26458
diff
changeset
|
107 #ifdef CONFIG_DVDREAD |
23077 | 108 guiIntfStruct.DVD.current_title=1; |
109 guiIntfStruct.DVD.current_chapter=1; | |
110 guiIntfStruct.DVD.current_angle=1; | |
111 #endif | |
112 | |
113 if ( !appMPlayer.subWindow.isFullScreen && gtkShowVideoWindow) | |
114 { | |
115 wsResizeWindow( &appMPlayer.subWindow,appMPlayer.sub.width,appMPlayer.sub.height ); | |
116 wsMoveWindow( &appMPlayer.subWindow,True,appMPlayer.sub.x,appMPlayer.sub.y ); | |
117 } | |
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 ); | |
124 } | |
125 } | |
126 | |
127 void mplPlay( void ) | |
128 { | |
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 ); | |
137 } | |
138 | |
139 void mplPause( void ) | |
140 { | |
141 if ( !guiIntfStruct.Playing ) return; | |
142 if ( guiIntfStruct.Playing == 1 ) | |
143 { | |
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; | |
149 } | |
150 | |
151 void mplState( void ) | |
152 { | |
153 if ( ( guiIntfStruct.Playing == 0 )||( guiIntfStruct.Playing == 2 ) ) | |
154 { | |
155 btnModify( evPlaySwitchToPause,btnReleased ); | |
156 btnModify( evPauseSwitchToPlay,btnDisabled ); | |
157 } | |
158 else | |
159 { | |
160 btnModify( evPlaySwitchToPause,btnDisabled ); | |
161 btnModify( evPauseSwitchToPlay,btnReleased ); | |
162 } | |
163 } | |
164 | |
165 float mplGetPosition( void ) | |
166 { // return 0.0 ... 100.0 | |
167 return guiIntfStruct.Position; | |
168 } | |
169 | |
170 void mplRelSeek( float s ) | |
171 { // -+s | |
172 rel_seek_secs=s; abs_seek_pos=0; | |
173 } | |
174 | |
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; | |
179 } | |
180 | |
181 listItems tmpList; | |
182 | |
183 void ChangeSkin( char * name ) | |
184 { | |
185 int ret; | |
186 int prev = appMPlayer.menuIsPresent; | |
187 int bprev = appMPlayer.barIsPresent; | |
188 | |
189 mainVisible=0; | |
190 | |
191 appInitStruct( &tmpList ); | |
192 skinAppMPlayer=&tmpList; | |
193 fntFreeFont(); | |
194 ret=skinRead( name ); | |
195 | |
196 appInitStruct( &tmpList ); | |
197 skinAppMPlayer=&appMPlayer; | |
198 appInitStruct( &appMPlayer ); | |
199 if ( ret ) name=skinName; | |
200 if ( skinRead( name ) ) | |
201 { | |
202 mainVisible=1; | |
203 return; | |
204 } | |
205 | |
206 // --- reload menu window | |
207 | |
208 if ( prev && appMPlayer.menuIsPresent ) | |
209 { | |
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(); } | |
218 | |
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 ) ) | |
222 { | |
223 wsResizeWindow( &appMPlayer.subWindow,appMPlayer.sub.width,appMPlayer.sub.height ); | |
224 wsMoveWindow( &appMPlayer.subWindow,True,appMPlayer.sub.x,appMPlayer.sub.y ); | |
225 } | |
226 if ( appMPlayer.sub.Bitmap.Image ) wsConvert( &appMPlayer.subWindow,appMPlayer.sub.Bitmap.Image,appMPlayer.sub.Bitmap.ImageSize ); | |
227 if ( !guiIntfStruct.Playing ) | |
228 { | |
229 mplSubRender=1; | |
230 wsSetBackgroundRGB( &appMPlayer.subWindow,appMPlayer.sub.R,appMPlayer.sub.G,appMPlayer.sub.B ); | |
231 wsClearWindow( appMPlayer.subWindow ); | |
232 wsPostRedisplay( &appMPlayer.subWindow ); | |
233 } | |
234 | |
235 // --- reload play bar | |
236 if ( bprev ) wsDestroyWindow( &appMPlayer.barWindow ); | |
237 mplPBInit(); | |
238 | |
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; } | |
243 | |
244 wsDestroyWindow( &appMPlayer.mainWindow ); | |
245 | |
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 ); | |
252 | |
253 appMPlayer.mainWindow.ReDraw=(void *)mplMainDraw; | |
254 appMPlayer.mainWindow.MouseHandler=mplMainMouseHandle; | |
255 appMPlayer.mainWindow.KeyHandler=mplMainKeyHandle; | |
256 appMPlayer.mainWindow.DandDHandler=mplDandDHandler; | |
257 | |
258 wsXDNDMakeAwareness( &appMPlayer.mainWindow ); | |
259 if ( !appMPlayer.mainDecoration ) wsWindowDecoration( &appMPlayer.mainWindow,0 ); | |
260 wsVisibleWindow( &appMPlayer.mainWindow,wsShowWindow ); | |
261 mainVisible=1; | |
262 // --- | |
263 | |
264 btnModify( evSetVolume,guiIntfStruct.Volume ); | |
265 btnModify( evSetBalance,guiIntfStruct.Balance ); | |
266 btnModify( evSetMoviePosition,guiIntfStruct.Position ); | |
267 btnModify( evFullScreen,!appMPlayer.subWindow.isFullScreen ); | |
268 | |
269 wsSetLayer( wsDisplay,appMPlayer.mainWindow.WindowID,appMPlayer.subWindow.isFullScreen ); | |
270 wsSetLayer( wsDisplay,appMPlayer.menuWindow.WindowID,appMPlayer.subWindow.isFullScreen ); | |
271 | |
272 } | |
273 | |
274 void mplSetFileName( char * dir,char * name,int type ) | |
275 { | |
276 if ( !name ) return; | |
277 | |
278 if ( !dir ) guiSetFilename( guiIntfStruct.Filename,name ) | |
279 else guiSetDF( guiIntfStruct.Filename,dir,name ); | |
280 | |
281 // filename=guiIntfStruct.Filename; | |
282 guiIntfStruct.StreamType=type; | |
283 gfree( (void **)&guiIntfStruct.AudioFile ); | |
284 gfree( (void **)&guiIntfStruct.Subtitlename ); | |
285 } | |
286 | |
287 void mplCurr( void ) | |
288 { | |
289 plItem * curr; | |
290 int stop = 0; | |
291 | |
292 if ( guiIntfStruct.Playing == 2 ) return; | |
293 switch ( guiIntfStruct.StreamType ) | |
294 { | |
27341
e7c989f7a7c9
Start unifying names of internal preprocessor directives.
diego
parents:
26458
diff
changeset
|
295 #ifdef CONFIG_DVDREAD |
23077 | 296 case STREAMTYPE_DVD: |
297 break; | |
298 #endif | |
27370
14c5017f40d2
Change a bunch of video/audio-output-specific preprocessor directives from
diego
parents:
27341
diff
changeset
|
299 #ifdef CONFIG_VCD |
23077 | 300 case STREAMTYPE_VCD: |
301 break; | |
302 #endif | |
303 default: | |
304 if ( (curr=gtkSet( gtkGetCurrPlItem,0,NULL)) ) | |
305 { | |
306 mplSetFileName( curr->path,curr->name,STREAMTYPE_FILE ); | |
307 mplGotoTheNext=0; | |
308 break; | |
309 } | |
310 return; | |
311 } | |
312 if ( stop ) mplEventHandling( evStop,0 ); | |
313 if ( guiIntfStruct.Playing == 1 ) mplEventHandling( evPlay,0 ); | |
314 } | |
315 | |
316 | |
317 void mplPrev( void ) | |
318 { | |
319 plItem * prev; | |
320 int stop = 0; | |
321 | |
322 if ( guiIntfStruct.Playing == 2 ) return; | |
323 switch ( guiIntfStruct.StreamType ) | |
324 { | |
27341
e7c989f7a7c9
Start unifying names of internal preprocessor directives.
diego
parents:
26458
diff
changeset
|
325 #ifdef CONFIG_DVDREAD |
23077 | 326 case STREAMTYPE_DVD: |
327 if ( --guiIntfStruct.DVD.current_chapter == 0 ) | |
328 { | |
329 guiIntfStruct.DVD.current_chapter=1; | |
330 if ( --guiIntfStruct.DVD.current_title <= 0 ) { guiIntfStruct.DVD.current_title=1; stop=1; } | |
331 } | |
332 guiIntfStruct.Track=guiIntfStruct.DVD.current_title; | |
333 break; | |
334 #endif | |
27370
14c5017f40d2
Change a bunch of video/audio-output-specific preprocessor directives from
diego
parents:
27341
diff
changeset
|
335 #ifdef CONFIG_VCD |
23077 | 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)) ) | |
342 { | |
343 mplSetFileName( prev->path,prev->name,STREAMTYPE_FILE ); | |
344 mplGotoTheNext=0; | |
345 break; | |
346 } | |
347 return; | |
348 } | |
349 if ( stop ) mplEventHandling( evStop,0 ); | |
350 if ( guiIntfStruct.Playing == 1 ) mplEventHandling( evPlay,0 ); | |
351 } | |
352 | |
353 void mplNext( void ) | |
354 { | |
355 int stop = 0; | |
356 plItem * next; | |
357 | |
358 if ( guiIntfStruct.Playing == 2 ) return; | |
359 switch ( guiIntfStruct.StreamType ) | |
360 { | |
27341
e7c989f7a7c9
Start unifying names of internal preprocessor directives.
diego
parents:
26458
diff
changeset
|
361 #ifdef CONFIG_DVDREAD |
23077 | 362 case STREAMTYPE_DVD: |
363 if ( guiIntfStruct.DVD.current_chapter++ == guiIntfStruct.DVD.chapters ) | |
364 { | |
365 guiIntfStruct.DVD.current_chapter=1; | |
366 if ( ++guiIntfStruct.DVD.current_title > guiIntfStruct.DVD.titles ) { guiIntfStruct.DVD.current_title=guiIntfStruct.DVD.titles; stop=1; } | |
367 } | |
368 guiIntfStruct.Track=guiIntfStruct.DVD.current_title; | |
369 break; | |
370 #endif | |
27370
14c5017f40d2
Change a bunch of video/audio-output-specific preprocessor directives from
diego
parents:
27341
diff
changeset
|
371 #ifdef CONFIG_VCD |
23077 | 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)) ) | |
378 { | |
379 mplSetFileName( next->path,next->name,STREAMTYPE_FILE ); | |
380 mplGotoTheNext=0; | |
381 break; | |
382 } | |
383 return; | |
384 } | |
385 if ( stop ) mplEventHandling( evStop,0 ); | |
386 if ( guiIntfStruct.Playing == 1 ) mplEventHandling( evPlay,0 ); | |
387 } |