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