Mercurial > mplayer.hg
annotate gui/mplayer/play.c @ 31366:0bf908d29807
SIGPIPE is not really a crash, try to exit cleanly in case we receive one.
Particularly in the network code it would be better to ignore it, but
some window managers use it to indicate a close request.
author | reimar |
---|---|
date | Wed, 16 Jun 2010 17:33:17 +0000 |
parents | 3d23e24c5c60 |
children | 5c708ee9b4ab |
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" |
30653
3d23e24c5c60
Declare externally used variables from vd.c as extern in vd.h.
diego
parents:
29263
diff
changeset
|
29 #include "libmpcodecs/vd.h" |
26382
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
30 #include "libvo/x11_common.h" |
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
31 #include "libvo/video_out.h" |
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
32 #include "input/input.h" |
b2f4abcf20ed
Make include paths consistent; do not use ../ in them.
diego
parents:
26365
diff
changeset
|
33 |
26365
10dfbc523184
Add gui/ prefix to some #include paths so that compilation from the
diego
parents:
26203
diff
changeset
|
34 #include "gui/wm/ws.h" |
10dfbc523184
Add gui/ prefix to some #include paths so that compilation from the
diego
parents:
26203
diff
changeset
|
35 #include "gui/wm/wsxdnd.h" |
23077 | 36 |
26365
10dfbc523184
Add gui/ prefix to some #include paths so that compilation from the
diego
parents:
26203
diff
changeset
|
37 #include "gui/app.h" |
10dfbc523184
Add gui/ prefix to some #include paths so that compilation from the
diego
parents:
26203
diff
changeset
|
38 #include "gui/wm/wskeys.h" |
10dfbc523184
Add gui/ prefix to some #include paths so that compilation from the
diego
parents:
26203
diff
changeset
|
39 #include "gui/interface.h" |
23077 | 40 |
41 #include "widgets.h" | |
42 #include "gmplayer.h" | |
43 #include "play.h" | |
44 | |
26365
10dfbc523184
Add gui/ prefix to some #include paths so that compilation from the
diego
parents:
26203
diff
changeset
|
45 #include "gui/skin/skin.h" |
10dfbc523184
Add gui/ prefix to some #include paths so that compilation from the
diego
parents:
26203
diff
changeset
|
46 #include "gui/skin/font.h" |
23077 | 47 |
48 #include "stream/stream.h" | |
49 | |
50 extern float rel_seek_secs; | |
51 extern int abs_seek_pos; | |
52 | |
53 int mplGotoTheNext = 1; | |
54 | |
55 void mplFullScreen( void ) | |
56 { | |
57 if ( guiIntfStruct.NoWindow && guiIntfStruct.Playing ) return; | |
58 | |
59 if ( ( guiIntfStruct.Playing )&&( appMPlayer.subWindow.isFullScreen ) ) | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27370
diff
changeset
|
60 { |
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27370
diff
changeset
|
61 appMPlayer.subWindow.OldWidth=guiIntfStruct.MovieWidth; appMPlayer.subWindow.OldHeight=guiIntfStruct.MovieHeight; |
23077 | 62 switch ( appMPlayer.sub.x ) |
63 { | |
64 case -1: appMPlayer.subWindow.OldX=( wsMaxX / 2 ) - ( appMPlayer.subWindow.OldWidth / 2 ) + wsOrgX; break; | |
65 case -2: appMPlayer.subWindow.OldX=wsMaxX - appMPlayer.subWindow.OldWidth + wsOrgX; break; | |
66 default: appMPlayer.subWindow.OldX=appMPlayer.sub.x; break; | |
67 } | |
68 switch ( appMPlayer.sub.y ) | |
69 { | |
70 case -1: appMPlayer.subWindow.OldY=( wsMaxY / 2 ) - ( appMPlayer.subWindow.OldHeight / 2 ) + wsOrgY; break; | |
71 case -2: appMPlayer.subWindow.OldY=wsMaxY - appMPlayer.subWindow.OldHeight + wsOrgY; break; | |
72 default: appMPlayer.subWindow.OldY=appMPlayer.sub.y; break; | |
73 } | |
74 } | |
75 if ( guiIntfStruct.Playing || gtkShowVideoWindow ) wsFullScreen( &appMPlayer.subWindow ); | |
76 fullscreen=vo_fs=appMPlayer.subWindow.isFullScreen; | |
77 wsSetLayer( wsDisplay,appMPlayer.mainWindow.WindowID,appMPlayer.subWindow.isFullScreen ); | |
78 if ( appMPlayer.menuIsPresent ) wsSetLayer( wsDisplay,appMPlayer.menuWindow.WindowID,appMPlayer.subWindow.isFullScreen ); | |
79 | |
80 if ( guiIntfStruct.Playing ) wsSetBackgroundRGB( &appMPlayer.subWindow,0,0,0 ); | |
81 else wsSetBackgroundRGB( &appMPlayer.subWindow,appMPlayer.sub.R,appMPlayer.sub.G,appMPlayer.sub.B ); | |
82 } | |
83 | |
84 void mplEnd( void ) | |
85 { | |
86 plItem * next; | |
87 | |
88 if ( !mplGotoTheNext && guiIntfStruct.Playing) { mplGotoTheNext=1; return; } | |
89 | |
90 if ( guiIntfStruct.Playing && (next=gtkSet( gtkGetNextPlItem,0,NULL )) && plLastPlayed != next ) | |
91 { | |
92 plLastPlayed=next; | |
93 guiSetDF( guiIntfStruct.Filename,next->path,next->name ); | |
94 guiIntfStruct.StreamType=STREAMTYPE_FILE; | |
95 guiIntfStruct.FilenameChanged=guiIntfStruct.NewPlay=1; | |
96 gfree( (void **)&guiIntfStruct.AudioFile ); | |
97 gfree( (void **)&guiIntfStruct.Subtitlename ); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27370
diff
changeset
|
98 } |
23077 | 99 else |
100 { | |
101 if ( guiIntfStruct.FilenameChanged || guiIntfStruct.NewPlay ) return; | |
102 | |
103 guiIntfStruct.TimeSec=0; | |
104 guiIntfStruct.Position=0; | |
105 guiIntfStruct.AudioType=0; | |
106 guiIntfStruct.NoWindow=False; | |
107 | |
27341
e7c989f7a7c9
Start unifying names of internal preprocessor directives.
diego
parents:
26458
diff
changeset
|
108 #ifdef CONFIG_DVDREAD |
23077 | 109 guiIntfStruct.DVD.current_title=1; |
110 guiIntfStruct.DVD.current_chapter=1; | |
111 guiIntfStruct.DVD.current_angle=1; | |
112 #endif | |
113 | |
114 if ( !appMPlayer.subWindow.isFullScreen && gtkShowVideoWindow) | |
115 { | |
116 wsResizeWindow( &appMPlayer.subWindow,appMPlayer.sub.width,appMPlayer.sub.height ); | |
117 wsMoveWindow( &appMPlayer.subWindow,True,appMPlayer.sub.x,appMPlayer.sub.y ); | |
118 } | |
119 else wsVisibleWindow( &appMPlayer.subWindow,wsHideWindow ); | |
120 guiGetEvent( guiCEvent,guiSetStop ); | |
121 mplSubRender=1; | |
122 wsSetBackgroundRGB( &appMPlayer.subWindow,appMPlayer.sub.R,appMPlayer.sub.G,appMPlayer.sub.B ); | |
123 wsClearWindow( appMPlayer.subWindow ); | |
124 wsPostRedisplay( &appMPlayer.subWindow ); | |
125 } | |
126 } | |
127 | |
128 void mplPlay( void ) | |
129 { | |
130 if ( ( !guiIntfStruct.Filename )|| | |
131 ( guiIntfStruct.Filename[0] == 0 )|| | |
132 ( guiIntfStruct.Playing == 1 ) ) return; | |
133 if ( guiIntfStruct.Playing == 2 ) { mplPause(); return; } | |
134 guiGetEvent( guiCEvent,(void *)guiSetPlay ); | |
135 mplSubRender=0; | |
136 wsSetBackgroundRGB( &appMPlayer.subWindow,0,0,0 ); | |
137 wsClearWindow( appMPlayer.subWindow ); | |
138 } | |
139 | |
140 void mplPause( void ) | |
141 { | |
142 if ( !guiIntfStruct.Playing ) return; | |
143 if ( guiIntfStruct.Playing == 1 ) | |
144 { | |
145 mp_cmd_t * cmd = calloc( 1,sizeof( *cmd ) ); | |
146 cmd->id=MP_CMD_PAUSE; | |
147 cmd->name=strdup("pause"); | |
148 mp_input_queue_cmd(cmd); | |
149 } else guiIntfStruct.Playing=1; | |
150 } | |
151 | |
152 void mplState( void ) | |
153 { | |
154 if ( ( guiIntfStruct.Playing == 0 )||( guiIntfStruct.Playing == 2 ) ) | |
155 { | |
156 btnModify( evPlaySwitchToPause,btnReleased ); | |
157 btnModify( evPauseSwitchToPlay,btnDisabled ); | |
158 } | |
159 else | |
160 { | |
161 btnModify( evPlaySwitchToPause,btnDisabled ); | |
162 btnModify( evPauseSwitchToPlay,btnReleased ); | |
163 } | |
164 } | |
165 | |
166 float mplGetPosition( void ) | |
167 { // return 0.0 ... 100.0 | |
168 return guiIntfStruct.Position; | |
169 } | |
170 | |
171 void mplRelSeek( float s ) | |
172 { // -+s | |
173 rel_seek_secs=s; abs_seek_pos=0; | |
174 } | |
175 | |
176 void mplAbsSeek( float s ) | |
177 { // 0.0 ... 100.0 | |
178 if ( guiIntfStruct.StreamType == STREAMTYPE_STREAM ) return; | |
179 rel_seek_secs=0.01*s; abs_seek_pos=3; | |
180 } | |
181 | |
182 listItems tmpList; | |
183 | |
184 void ChangeSkin( char * name ) | |
185 { | |
186 int ret; | |
187 int prev = appMPlayer.menuIsPresent; | |
188 int bprev = appMPlayer.barIsPresent; | |
189 | |
190 mainVisible=0; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27370
diff
changeset
|
191 |
23077 | 192 appInitStruct( &tmpList ); |
193 skinAppMPlayer=&tmpList; | |
194 fntFreeFont(); | |
195 ret=skinRead( name ); | |
196 | |
197 appInitStruct( &tmpList ); | |
198 skinAppMPlayer=&appMPlayer; | |
199 appInitStruct( &appMPlayer ); | |
200 if ( ret ) name=skinName; | |
201 if ( skinRead( name ) ) | |
202 { | |
203 mainVisible=1; | |
204 return; | |
205 } | |
206 | |
207 // --- reload menu window | |
208 | |
209 if ( prev && appMPlayer.menuIsPresent ) | |
210 { | |
211 if ( mplMenuDrawBuffer ) free( mplMenuDrawBuffer ); | |
212 if ( ( mplMenuDrawBuffer = calloc( 1,appMPlayer.menuBase.Bitmap.ImageSize ) ) == NULL ) | |
213 { mp_msg( MSGT_GPLAYER,MSGL_STATUS,MSGTR_NEMDB ); return; } | |
214 wsResizeWindow( &appMPlayer.menuWindow,appMPlayer.menuBase.width,appMPlayer.menuBase.height ); | |
215 wsResizeImage( &appMPlayer.menuWindow,appMPlayer.menuBase.width,appMPlayer.menuBase.height ); | |
216 wsSetShape( &appMPlayer.menuWindow,appMPlayer.menuBase.Mask.Image ); | |
217 wsVisibleWindow( &appMPlayer.menuWindow,wsHideWindow ); | |
218 } else { mplMenuInit(); } | |
219 | |
220 // --- reload sub window | |
221 if ( appMPlayer.sub.Bitmap.Image ) wsResizeImage( &appMPlayer.subWindow,appMPlayer.sub.Bitmap.Width,appMPlayer.sub.Bitmap.Height ); | |
222 if ( ( !appMPlayer.subWindow.isFullScreen )&&( !guiIntfStruct.Playing ) ) | |
223 { | |
224 wsResizeWindow( &appMPlayer.subWindow,appMPlayer.sub.width,appMPlayer.sub.height ); | |
225 wsMoveWindow( &appMPlayer.subWindow,True,appMPlayer.sub.x,appMPlayer.sub.y ); | |
226 } | |
227 if ( appMPlayer.sub.Bitmap.Image ) wsConvert( &appMPlayer.subWindow,appMPlayer.sub.Bitmap.Image,appMPlayer.sub.Bitmap.ImageSize ); | |
228 if ( !guiIntfStruct.Playing ) | |
229 { | |
230 mplSubRender=1; | |
231 wsSetBackgroundRGB( &appMPlayer.subWindow,appMPlayer.sub.R,appMPlayer.sub.G,appMPlayer.sub.B ); | |
232 wsClearWindow( appMPlayer.subWindow ); | |
233 wsPostRedisplay( &appMPlayer.subWindow ); | |
234 } | |
235 | |
236 // --- reload play bar | |
237 if ( bprev ) wsDestroyWindow( &appMPlayer.barWindow ); | |
238 mplPBInit(); | |
239 | |
240 // --- reload main window | |
241 if ( mplDrawBuffer ) free( mplDrawBuffer ); | |
242 if ( ( mplDrawBuffer = calloc( 1,appMPlayer.main.Bitmap.ImageSize ) ) == NULL ) | |
243 { mp_msg( MSGT_GPLAYER,MSGL_STATUS,MSGTR_NEMDB ); return; } | |
244 | |
245 wsDestroyWindow( &appMPlayer.mainWindow ); | |
246 | |
247 wsCreateWindow( &appMPlayer.mainWindow, | |
248 appMPlayer.main.x,appMPlayer.main.y,appMPlayer.main.width,appMPlayer.main.height, | |
249 wsNoBorder,wsShowMouseCursor|wsHandleMouseButton|wsHandleMouseMove,wsShowFrame|wsMaxSize|wsHideWindow,"MPlayer" ); | |
250 wsCreateImage( &appMPlayer.mainWindow,appMPlayer.main.Bitmap.Width,appMPlayer.main.Bitmap.Height ); | |
251 wsSetShape( &appMPlayer.mainWindow,appMPlayer.main.Mask.Image ); | |
252 wsSetIcon( wsDisplay,appMPlayer.mainWindow.WindowID,guiIcon,guiIconMask ); | |
253 | |
254 appMPlayer.mainWindow.ReDraw=(void *)mplMainDraw; | |
255 appMPlayer.mainWindow.MouseHandler=mplMainMouseHandle; | |
256 appMPlayer.mainWindow.KeyHandler=mplMainKeyHandle; | |
257 appMPlayer.mainWindow.DandDHandler=mplDandDHandler; | |
258 | |
259 wsXDNDMakeAwareness( &appMPlayer.mainWindow ); | |
260 if ( !appMPlayer.mainDecoration ) wsWindowDecoration( &appMPlayer.mainWindow,0 ); | |
261 wsVisibleWindow( &appMPlayer.mainWindow,wsShowWindow ); | |
262 mainVisible=1; | |
263 // --- | |
264 | |
265 btnModify( evSetVolume,guiIntfStruct.Volume ); | |
266 btnModify( evSetBalance,guiIntfStruct.Balance ); | |
267 btnModify( evSetMoviePosition,guiIntfStruct.Position ); | |
268 btnModify( evFullScreen,!appMPlayer.subWindow.isFullScreen ); | |
269 | |
270 wsSetLayer( wsDisplay,appMPlayer.mainWindow.WindowID,appMPlayer.subWindow.isFullScreen ); | |
271 wsSetLayer( wsDisplay,appMPlayer.menuWindow.WindowID,appMPlayer.subWindow.isFullScreen ); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27370
diff
changeset
|
272 |
23077 | 273 } |
274 | |
275 void mplSetFileName( char * dir,char * name,int type ) | |
276 { | |
277 if ( !name ) return; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27370
diff
changeset
|
278 |
23077 | 279 if ( !dir ) guiSetFilename( guiIntfStruct.Filename,name ) |
280 else guiSetDF( guiIntfStruct.Filename,dir,name ); | |
281 | |
282 // filename=guiIntfStruct.Filename; | |
283 guiIntfStruct.StreamType=type; | |
284 gfree( (void **)&guiIntfStruct.AudioFile ); | |
285 gfree( (void **)&guiIntfStruct.Subtitlename ); | |
286 } | |
287 | |
288 void mplCurr( void ) | |
289 { | |
290 plItem * curr; | |
291 int stop = 0; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27370
diff
changeset
|
292 |
23077 | 293 if ( guiIntfStruct.Playing == 2 ) return; |
294 switch ( guiIntfStruct.StreamType ) | |
295 { | |
27341
e7c989f7a7c9
Start unifying names of internal preprocessor directives.
diego
parents:
26458
diff
changeset
|
296 #ifdef CONFIG_DVDREAD |
23077 | 297 case STREAMTYPE_DVD: |
298 break; | |
299 #endif | |
27370
14c5017f40d2
Change a bunch of video/audio-output-specific preprocessor directives from
diego
parents:
27341
diff
changeset
|
300 #ifdef CONFIG_VCD |
23077 | 301 case STREAMTYPE_VCD: |
302 break; | |
303 #endif | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27370
diff
changeset
|
304 default: |
23077 | 305 if ( (curr=gtkSet( gtkGetCurrPlItem,0,NULL)) ) |
306 { | |
307 mplSetFileName( curr->path,curr->name,STREAMTYPE_FILE ); | |
308 mplGotoTheNext=0; | |
309 break; | |
310 } | |
311 return; | |
312 } | |
313 if ( stop ) mplEventHandling( evStop,0 ); | |
314 if ( guiIntfStruct.Playing == 1 ) mplEventHandling( evPlay,0 ); | |
315 } | |
316 | |
317 | |
318 void mplPrev( void ) | |
319 { | |
320 plItem * prev; | |
321 int stop = 0; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27370
diff
changeset
|
322 |
23077 | 323 if ( guiIntfStruct.Playing == 2 ) return; |
324 switch ( guiIntfStruct.StreamType ) | |
325 { | |
27341
e7c989f7a7c9
Start unifying names of internal preprocessor directives.
diego
parents:
26458
diff
changeset
|
326 #ifdef CONFIG_DVDREAD |
23077 | 327 case STREAMTYPE_DVD: |
328 if ( --guiIntfStruct.DVD.current_chapter == 0 ) | |
329 { | |
330 guiIntfStruct.DVD.current_chapter=1; | |
331 if ( --guiIntfStruct.DVD.current_title <= 0 ) { guiIntfStruct.DVD.current_title=1; stop=1; } | |
332 } | |
333 guiIntfStruct.Track=guiIntfStruct.DVD.current_title; | |
334 break; | |
335 #endif | |
27370
14c5017f40d2
Change a bunch of video/audio-output-specific preprocessor directives from
diego
parents:
27341
diff
changeset
|
336 #ifdef CONFIG_VCD |
23077 | 337 case STREAMTYPE_VCD: |
338 if ( --guiIntfStruct.Track == 0 ) { guiIntfStruct.Track=1; stop=1; } | |
339 break; | |
340 #endif | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27370
diff
changeset
|
341 default: |
23077 | 342 if ( (prev=gtkSet( gtkGetPrevPlItem,0,NULL)) ) |
343 { | |
344 mplSetFileName( prev->path,prev->name,STREAMTYPE_FILE ); | |
345 mplGotoTheNext=0; | |
346 break; | |
347 } | |
348 return; | |
349 } | |
350 if ( stop ) mplEventHandling( evStop,0 ); | |
351 if ( guiIntfStruct.Playing == 1 ) mplEventHandling( evPlay,0 ); | |
352 } | |
353 | |
354 void mplNext( void ) | |
355 { | |
356 int stop = 0; | |
357 plItem * next; | |
358 | |
359 if ( guiIntfStruct.Playing == 2 ) return; | |
360 switch ( guiIntfStruct.StreamType ) | |
361 { | |
27341
e7c989f7a7c9
Start unifying names of internal preprocessor directives.
diego
parents:
26458
diff
changeset
|
362 #ifdef CONFIG_DVDREAD |
23077 | 363 case STREAMTYPE_DVD: |
364 if ( guiIntfStruct.DVD.current_chapter++ == guiIntfStruct.DVD.chapters ) | |
365 { | |
366 guiIntfStruct.DVD.current_chapter=1; | |
367 if ( ++guiIntfStruct.DVD.current_title > guiIntfStruct.DVD.titles ) { guiIntfStruct.DVD.current_title=guiIntfStruct.DVD.titles; stop=1; } | |
368 } | |
369 guiIntfStruct.Track=guiIntfStruct.DVD.current_title; | |
370 break; | |
371 #endif | |
27370
14c5017f40d2
Change a bunch of video/audio-output-specific preprocessor directives from
diego
parents:
27341
diff
changeset
|
372 #ifdef CONFIG_VCD |
23077 | 373 case STREAMTYPE_VCD: |
374 if ( ++guiIntfStruct.Track > guiIntfStruct.VCDTracks ) { guiIntfStruct.Track=guiIntfStruct.VCDTracks; stop=1; } | |
375 break; | |
376 #endif | |
377 default: | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27370
diff
changeset
|
378 if ( (next=gtkSet( gtkGetNextPlItem,0,NULL)) ) |
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27370
diff
changeset
|
379 { |
23077 | 380 mplSetFileName( next->path,next->name,STREAMTYPE_FILE ); |
381 mplGotoTheNext=0; | |
382 break; | |
383 } | |
384 return; | |
385 } | |
386 if ( stop ) mplEventHandling( evStop,0 ); | |
387 if ( guiIntfStruct.Playing == 1 ) mplEventHandling( evPlay,0 ); | |
388 } |