Mercurial > mplayer.hg
annotate gui/win32/interface.c @ 23326:d98c777b8b6b
Update regexp to ffmpegs version to avoid incorrect CONFIG_MP3_HEADER_DECOMPRESS_DECODER
author | reimar |
---|---|
date | Sat, 19 May 2007 11:17:49 +0000 |
parents | 71efd1fc20c8 |
children | 5701e23ebcb4 |
rev | line source |
---|---|
23077 | 1 /* |
23079 | 2 * MPlayer GUI for Win32 |
3 * Copyright (C) 2003 Sascha Sommer <saschasommer@freenet.de> | |
4 * Copyright (C) 2006 Erik Augustson <erik_27can@yahoo.com> | |
5 * Copyright (C) 2006 Gianluigi Tiesi <sherpya@netfarm.it> | |
6 * | |
7 * This file is part of MPlayer. | |
8 * | |
9 * MPlayer 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. | |
13 * | |
14 * MPlayer 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. | |
18 * | |
19 * You should have received a copy of the GNU General Public License | |
20 * along with MPlayer; if not, write to the Free Software | |
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
22 */ | |
23077 | 23 |
24 #include <windows.h> | |
23091
52488bb09d90
Consistently use quotes instead of angled brackets in #include
diego
parents:
23079
diff
changeset
|
25 |
52488bb09d90
Consistently use quotes instead of angled brackets in #include
diego
parents:
23079
diff
changeset
|
26 #include "interface.h" |
52488bb09d90
Consistently use quotes instead of angled brackets in #include
diego
parents:
23079
diff
changeset
|
27 #include "m_option.h" |
52488bb09d90
Consistently use quotes instead of angled brackets in #include
diego
parents:
23079
diff
changeset
|
28 #include "mixer.h" |
52488bb09d90
Consistently use quotes instead of angled brackets in #include
diego
parents:
23079
diff
changeset
|
29 #include "mp_msg.h" |
52488bb09d90
Consistently use quotes instead of angled brackets in #include
diego
parents:
23079
diff
changeset
|
30 #include "help_mp.h" |
52488bb09d90
Consistently use quotes instead of angled brackets in #include
diego
parents:
23079
diff
changeset
|
31 #include "codec-cfg.h" |
52488bb09d90
Consistently use quotes instead of angled brackets in #include
diego
parents:
23079
diff
changeset
|
32 #include "stream/stream.h" |
52488bb09d90
Consistently use quotes instead of angled brackets in #include
diego
parents:
23079
diff
changeset
|
33 #include "libmpdemux/demuxer.h" |
52488bb09d90
Consistently use quotes instead of angled brackets in #include
diego
parents:
23079
diff
changeset
|
34 #include "libmpdemux/stheader.h" |
23077 | 35 #ifdef USE_DVDREAD |
23091
52488bb09d90
Consistently use quotes instead of angled brackets in #include
diego
parents:
23079
diff
changeset
|
36 #include "stream/stream_dvd.h" |
23077 | 37 #endif |
23091
52488bb09d90
Consistently use quotes instead of angled brackets in #include
diego
parents:
23079
diff
changeset
|
38 #include "input/input.h" |
52488bb09d90
Consistently use quotes instead of angled brackets in #include
diego
parents:
23079
diff
changeset
|
39 #include "libvo/video_out.h" |
52488bb09d90
Consistently use quotes instead of angled brackets in #include
diego
parents:
23079
diff
changeset
|
40 #include "libao2/audio_out.h" |
52488bb09d90
Consistently use quotes instead of angled brackets in #include
diego
parents:
23079
diff
changeset
|
41 #include "access_mpcontext.h" |
23077 | 42 #include "gui.h" |
43 #include "dialogs.h" | |
44 #include "wincfg.h" | |
45 #ifdef HAVE_LIBCDIO | |
46 #include <cdio/cdio.h> | |
47 #endif | |
48 | |
49 extern int abs_seek_pos; | |
50 extern float rel_seek_secs; | |
51 extern int vcd_track; | |
52 extern af_cfg_t af_cfg; | |
53 int guiWinID = 0; | |
54 | |
55 char *skinName = NULL; | |
56 char *codecname = NULL; | |
57 int mplGotoTheNext = 1; | |
58 static gui_t *mygui = NULL; | |
59 static int update_subwindow(void); | |
60 static RECT old_rect; | |
61 static DWORD style; | |
62 ao_functions_t *audio_out = NULL; | |
63 vo_functions_t *video_out = NULL; | |
64 mixer_t *mixer = NULL; | |
65 | |
66 /* test for playlist files, no need to specify -playlist on the commandline. | |
67 * add any conceivable playlist extensions here. | |
68 * - Erik | |
69 */ | |
70 int parse_filename(char *file, play_tree_t *playtree, m_config_t *mconfig, int clear) | |
71 { | |
72 if(clear) | |
73 mygui->playlist->clear_playlist(mygui->playlist); | |
74 | |
75 if(strstr(file, ".m3u") || strstr(file, ".pls")) | |
76 { | |
77 playtree = parse_playlist_file(file); | |
78 import_playtree_playlist_into_gui(playtree, mconfig); | |
79 return 1; | |
80 } | |
81 return 0; | |
82 } | |
83 | |
84 /** | |
85 * \brief this actually creates a new list containing only one element... | |
86 */ | |
87 void gaddlist( char ***list, const char *entry) | |
88 { | |
89 int i; | |
90 | |
91 if (*list) | |
92 { | |
93 for (i=0; (*list)[i]; i++) free((*list)[i]); | |
94 free(*list); | |
95 } | |
96 | |
97 *list = malloc(2 * sizeof(char **)); | |
98 (*list)[0] = gstrdup(entry); | |
99 (*list)[1] = NULL; | |
100 } | |
101 | |
102 char *gstrdup(const char *str) | |
103 { | |
104 if (!str) return NULL; | |
105 return strdup(str); | |
106 } | |
107 | |
108 /** | |
109 * \brief this replaces a string starting with search by replace. | |
110 * If not found, replace is appended. | |
111 */ | |
112 void greplace(char ***list, char *search, char *replace) | |
113 { | |
114 int i = 0; | |
115 int len = (search) ? strlen(search) : 0; | |
116 | |
117 if (*list) | |
118 { | |
119 for (i = 0; (*list)[i]; i++) | |
120 { | |
121 if (search && (!strncmp((*list)[i], search, len))) | |
122 { | |
123 free((*list)[i]); | |
124 (*list)[i] = gstrdup(replace); | |
125 return; | |
126 } | |
127 } | |
128 *list = realloc(*list, (i + 2) * sizeof(char *)); | |
129 } | |
130 else | |
131 *list = malloc(2 * sizeof(char *)); | |
132 | |
133 (*list)[i] = gstrdup(replace); | |
134 (*list)[i + 1] = NULL; | |
135 } | |
136 | |
137 /* this function gets called by the gui to update mplayer */ | |
138 static void guiSetEvent(int event) | |
139 { | |
140 if(guiIntfStruct.mpcontext) | |
141 mixer = mpctx_get_mixer(guiIntfStruct.mpcontext); | |
142 | |
143 switch(event) | |
144 { | |
145 case evPlay: | |
146 case evPlaySwitchToPause: | |
23148
71efd1fc20c8
add missing case value, fixes functionality when using some skins.
vayne
parents:
23147
diff
changeset
|
147 case evPauseSwitchToPlay: |
23077 | 148 mplPlay(); |
149 break; | |
150 case evPause: | |
151 mplPause(); | |
152 break; | |
153 #ifdef USE_DVDREAD | |
154 case evPlayDVD: | |
155 { | |
156 static char dvdname[MAX_PATH]; | |
157 guiIntfStruct.DVD.current_title = dvd_title; | |
158 guiIntfStruct.DVD.current_chapter = dvd_chapter; | |
159 guiIntfStruct.DVD.current_angle = dvd_angle; | |
160 guiIntfStruct.DiskChanged = 1; | |
161 | |
162 mplSetFileName(NULL, dvd_device, STREAMTYPE_DVD); | |
163 dvdname[0] = 0; | |
164 strcat(dvdname, "DVD Movie"); | |
165 GetVolumeInformation(dvd_device, dvdname, MAX_PATH, NULL, NULL, NULL, NULL, 0); | |
166 capitalize(dvdname); | |
167 mp_msg(MSGT_GPLAYER, MSGL_V, "Opening DVD %s -> %s\n", dvd_device, dvdname); | |
168 guiGetEvent(guiSetParameters, (char *) STREAMTYPE_DVD); | |
169 mygui->playlist->clear_playlist(mygui->playlist); | |
170 mygui->playlist->add_track(mygui->playlist, filename, NULL, dvdname, 0); | |
171 mygui->startplay(mygui); | |
172 break; | |
173 } | |
174 #endif | |
175 #ifdef HAVE_LIBCDIO | |
176 case evPlayCD: | |
177 { | |
178 int i; | |
179 char track[10]; | |
180 char trackname[10]; | |
181 CdIo_t *p_cdio = cdio_open(NULL, DRIVER_UNKNOWN); | |
182 track_t i_tracks; | |
183 | |
184 if(p_cdio == NULL) printf("Couldn't find a driver.\n"); | |
185 i_tracks = cdio_get_num_tracks(p_cdio); | |
186 | |
187 mygui->playlist->clear_playlist(mygui->playlist); | |
188 for(i=0;i<i_tracks;i++) | |
189 { | |
190 sprintf(track, "cdda://%d", i+1); | |
191 sprintf(trackname, "Track %d", i+1); | |
192 mygui->playlist->add_track(mygui->playlist, track, NULL, trackname, 0); | |
193 } | |
194 cdio_destroy(p_cdio); | |
195 mygui->startplay(mygui); | |
196 break; | |
197 } | |
198 #endif | |
199 case evFullScreen: | |
200 mp_input_queue_cmd(mp_input_parse_cmd("vo_fullscreen")); | |
201 break; | |
202 case evExit: | |
203 { | |
204 /* We are asking mplayer to exit, later it will ask us after uninit is made | |
205 this should be the only safe way to quit */ | |
206 mygui->activewidget = NULL; | |
207 mp_input_queue_cmd(mp_input_parse_cmd("quit")); | |
208 break; | |
209 } | |
210 case evStop: | |
211 if(guiIntfStruct.Playing) | |
212 guiGetEvent(guiCEvent, (void *) guiSetStop); | |
213 break; | |
214 case evSetMoviePosition: | |
215 { | |
216 rel_seek_secs = guiIntfStruct.Position / 100.0f; | |
217 abs_seek_pos = 3; | |
218 break; | |
219 } | |
220 case evForward10sec: | |
221 { | |
222 rel_seek_secs = 10.0f; | |
223 abs_seek_pos = 0; | |
224 break; | |
225 } | |
226 case evBackward10sec: | |
227 { | |
228 rel_seek_secs = -10.0f; | |
229 abs_seek_pos = 0; | |
230 break; | |
231 } | |
232 case evSetBalance: | |
233 case evSetVolume: | |
234 { | |
235 float l,r; | |
236 | |
237 if (guiIntfStruct.Playing == 0) | |
238 break; | |
239 | |
240 if (guiIntfStruct.Balance == 50.0f) | |
241 mixer_setvolume(mixer, guiIntfStruct.Volume, guiIntfStruct.Volume); | |
242 | |
243 l = guiIntfStruct.Volume * ((100.0f - guiIntfStruct.Balance) / 50.0f); | |
244 r = guiIntfStruct.Volume * ((guiIntfStruct.Balance) / 50.0f); | |
245 | |
246 if (l > guiIntfStruct.Volume) l=guiIntfStruct.Volume; | |
247 if (r > guiIntfStruct.Volume) r=guiIntfStruct.Volume; | |
248 mixer_setvolume(mixer, l, r); | |
249 /* Check for balance support on mixer - there is a better way ?? */ | |
250 if (r != l) | |
251 { | |
252 mixer_getvolume(mixer, &l, &r); | |
253 if (r == l) | |
254 { | |
255 mp_msg(MSGT_GPLAYER, MSGL_V, "[GUI] Mixer doesn't support balanced audio\n"); | |
256 mixer_setvolume(mixer, guiIntfStruct.Volume, guiIntfStruct.Volume); | |
257 guiIntfStruct.Balance = 50.0f; | |
258 } | |
259 } | |
260 break; | |
261 } | |
262 case evMute: | |
263 { | |
264 mp_cmd_t * cmd = calloc(1, sizeof(*cmd)); | |
265 cmd->id=MP_CMD_MUTE; | |
266 cmd->name=strdup("mute"); | |
267 mp_input_queue_cmd(cmd); | |
268 break; | |
269 } | |
270 case evDropFile: | |
271 case evLoadPlay: | |
272 { | |
273 switch(guiIntfStruct.StreamType) | |
274 { | |
23147
21c35763b178
compilation fix for disabling dvd functionality, patch by <bangbangbear at gmail dot com>, slightly modified by me.
vayne
parents:
23123
diff
changeset
|
275 #ifdef USE_DVDREAD |
23077 | 276 case STREAMTYPE_DVD: |
277 { | |
278 guiIntfStruct.Title = guiIntfStruct.DVD.current_title; | |
279 guiIntfStruct.Chapter = guiIntfStruct.DVD.current_chapter; | |
280 guiIntfStruct.Angle = guiIntfStruct.DVD.current_angle; | |
281 guiIntfStruct.DiskChanged = 1; | |
282 guiGetEvent(guiCEvent, (void *) guiSetPlay); | |
283 break; | |
284 } | |
23147
21c35763b178
compilation fix for disabling dvd functionality, patch by <bangbangbear at gmail dot com>, slightly modified by me.
vayne
parents:
23123
diff
changeset
|
285 #endif |
23077 | 286 default: |
287 { | |
288 guiIntfStruct.FilenameChanged = guiIntfStruct.NewPlay = 1; | |
289 update_playlistwindow(); | |
290 mplGotoTheNext = guiIntfStruct.Playing? 0 : 1; | |
291 guiGetEvent(guiCEvent, (void *) guiSetStop); | |
292 guiGetEvent(guiCEvent, (void *) guiSetPlay); | |
293 break; | |
294 } | |
295 } | |
296 break; | |
297 } | |
298 case evNext: | |
299 mplNext(); | |
300 break; | |
301 case evPrev: | |
302 mplPrev(); | |
303 break; | |
304 } | |
305 } | |
306 | |
307 void mplPlay( void ) | |
308 { | |
309 if((!guiIntfStruct.Filename ) || (guiIntfStruct.Filename[0] == 0)) | |
310 return; | |
311 | |
312 if(guiIntfStruct.Playing > 0) | |
313 { | |
314 mplPause(); | |
315 return; | |
316 } | |
317 guiIntfStruct.NewPlay = 1; | |
318 guiGetEvent(guiCEvent, (void *) guiSetPlay); | |
319 } | |
320 | |
321 void mplPause( void ) | |
322 { | |
323 if(!guiIntfStruct.Playing) return; | |
324 | |
325 if(guiIntfStruct.Playing == 1) | |
326 { | |
327 mp_cmd_t * cmd = calloc(1, sizeof(*cmd)); | |
328 cmd->id=MP_CMD_PAUSE; | |
329 cmd->name=strdup("pause"); | |
330 mp_input_queue_cmd(cmd); | |
331 } else guiIntfStruct.Playing = 1; | |
332 } | |
333 | |
334 void mplNext(void) | |
335 { | |
336 if(guiIntfStruct.Playing == 2) return; | |
337 switch(guiIntfStruct.StreamType) | |
338 { | |
339 #ifdef USE_DVDREAD | |
340 case STREAMTYPE_DVD: | |
341 if(guiIntfStruct.DVD.current_chapter == (guiIntfStruct.DVD.chapters - 1)) | |
342 return; | |
343 guiIntfStruct.DVD.current_chapter++; | |
344 break; | |
345 #endif | |
346 default: | |
347 if(mygui->playlist->current == (mygui->playlist->trackcount - 1)) | |
348 return; | |
349 mplSetFileName(NULL, mygui->playlist->tracks[(mygui->playlist->current)++]->filename, | |
350 STREAMTYPE_STREAM); | |
351 break; | |
352 } | |
353 mygui->startplay(mygui); | |
354 } | |
355 | |
356 void mplPrev(void) | |
357 { | |
358 if(guiIntfStruct.Playing == 2) return; | |
359 switch(guiIntfStruct.StreamType) | |
360 { | |
361 #ifdef USE_DVDREAD | |
362 case STREAMTYPE_DVD: | |
363 if(guiIntfStruct.DVD.current_chapter == 1) | |
364 return; | |
365 guiIntfStruct.DVD.current_chapter--; | |
366 break; | |
367 #endif | |
368 default: | |
369 if(mygui->playlist->current == 0) | |
370 return; | |
371 mplSetFileName(NULL, mygui->playlist->tracks[(mygui->playlist->current)--]->filename, | |
372 STREAMTYPE_STREAM); | |
373 break; | |
374 } | |
375 mygui->startplay(mygui); | |
376 } | |
377 | |
378 void mplEnd( void ) | |
379 { | |
380 if(!mplGotoTheNext && guiIntfStruct.Playing) | |
381 { | |
382 mplGotoTheNext = 1; | |
383 return; | |
384 } | |
385 | |
386 if(mplGotoTheNext && guiIntfStruct.Playing && | |
387 (mygui->playlist->current < (mygui->playlist->trackcount - 1)) && | |
388 guiIntfStruct.StreamType != STREAMTYPE_DVD && | |
389 guiIntfStruct.StreamType != STREAMTYPE_DVDNAV) | |
390 { | |
391 /* we've finished this file, reset the aspect */ | |
392 if(movie_aspect >= 0) | |
393 movie_aspect = -1; | |
394 | |
395 mplGotoTheNext = guiIntfStruct.FilenameChanged = guiIntfStruct.NewPlay = 1; | |
396 mplSetFileName(NULL, mygui->playlist->tracks[(mygui->playlist->current)++]->filename, STREAMTYPE_STREAM); | |
397 //sprintf(guiIntfStruct.Filename, mygui->playlist->tracks[(mygui->playlist->current)++]->filename); | |
398 } | |
399 | |
400 if(guiIntfStruct.FilenameChanged && guiIntfStruct.NewPlay) | |
401 return; | |
402 | |
403 guiIntfStruct.TimeSec = 0; | |
404 guiIntfStruct.Position = 0; | |
405 guiIntfStruct.AudioType = 0; | |
406 | |
407 #ifdef USE_DVDREAD | |
408 guiIntfStruct.DVD.current_title = 1; | |
409 guiIntfStruct.DVD.current_chapter = 1; | |
410 guiIntfStruct.DVD.current_angle = 1; | |
411 #endif | |
412 | |
413 if (mygui->playlist->current == (mygui->playlist->trackcount - 1)) | |
414 mygui->playlist->current = 0; | |
415 | |
416 fullscreen = 0; | |
417 if(style == WS_VISIBLE | WS_POPUP) | |
418 { | |
419 style = WS_OVERLAPPEDWINDOW | WS_SIZEBOX; | |
420 SetWindowLong(mygui->subwindow, GWL_STYLE, style); | |
421 } | |
422 guiGetEvent(guiCEvent, (void *) guiSetStop); | |
423 } | |
424 | |
425 void mplSetFileName(char *dir, char *name, int type) | |
426 { | |
427 if(!name) return; | |
428 if(!dir) | |
429 guiSetFilename(guiIntfStruct.Filename, name) | |
430 else | |
431 guiSetDF(guiIntfStruct.Filename, dir, name); | |
432 | |
433 guiIntfStruct.StreamType = type; | |
434 free((void **) &guiIntfStruct.AudioFile); | |
435 free((void **) &guiIntfStruct.Subtitlename); | |
436 } | |
437 | |
438 void mplFullScreen( void ) | |
439 { | |
440 if(!guiIntfStruct.sh_video) return; | |
441 | |
442 if(sub_window) | |
443 { | |
444 if(!fullscreen && IsWindowVisible(mygui->subwindow) && !IsIconic(mygui->subwindow)) | |
445 GetWindowRect(mygui->subwindow, &old_rect); | |
446 | |
447 if(fullscreen) | |
448 { | |
449 fullscreen = 0; | |
450 style = WS_OVERLAPPEDWINDOW | WS_SIZEBOX; | |
451 } else { | |
452 fullscreen = 1; | |
453 style = WS_VISIBLE | WS_POPUP; | |
454 } | |
455 SetWindowLong(mygui->subwindow, GWL_STYLE, style); | |
456 update_subwindow(); | |
457 } | |
458 video_out->control(VOCTRL_FULLSCREEN, 0); | |
459 if(sub_window) ShowWindow(mygui->subwindow, SW_SHOW); | |
460 } | |
461 | |
462 static DWORD WINAPI GuiThread(void) | |
463 { | |
464 MSG msg; | |
465 | |
466 if(!skinName) skinName = strdup("Blue"); | |
467 if(!mygui) mygui = create_gui(get_path("skins"), skinName, guiSetEvent); | |
23078 | 468 if(!mygui) exit_player("Unable to load GUI."); |
23077 | 469 |
470 if(autosync && autosync != gtkAutoSync) | |
471 { | |
472 gtkAutoSyncOn = 1; | |
473 gtkAutoSync = autosync; | |
474 } | |
475 | |
476 while(mygui) | |
477 { | |
478 GetMessage(&msg, NULL, 0, 0); | |
479 TranslateMessage(&msg); | |
480 DispatchMessage(&msg); | |
481 } | |
23078 | 482 fprintf(stderr, "[GUI] GUI thread terminated.\n"); |
23077 | 483 fflush(stderr); |
484 return 0; | |
485 } | |
486 | |
487 void guiInit(void) | |
488 { | |
489 DWORD threadId; | |
490 memset(&guiIntfStruct, 0, sizeof(guiIntfStruct)); | |
491 /* Create The gui thread */ | |
492 if (!mygui) | |
493 { | |
494 CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) GuiThread, NULL, 0, &threadId); | |
495 mp_msg(MSGT_GPLAYER, MSGL_V, "[GUI] Creating GUI Thread 0x%04x\n", threadId); | |
496 } | |
497 | |
498 /* Wait until the gui is created */ | |
499 while(!mygui) Sleep(100); | |
23078 | 500 mp_msg(MSGT_GPLAYER, MSGL_V, "[GUI] GUI thread started.\n"); |
23077 | 501 } |
502 | |
503 void guiDone(void) | |
504 { | |
505 if(mygui) | |
506 { | |
507 fprintf(stderr, "[GUI] Closed by main mplayer window\n"); | |
508 fflush(stderr); | |
509 mygui->uninit(mygui); | |
510 free(mygui); | |
511 TerminateThread(GuiThread, 0); | |
512 mygui = NULL; | |
513 } | |
514 /* Remove tray icon */ | |
515 Shell_NotifyIcon(NIM_DELETE, &nid); | |
516 cfg_write(); | |
517 } | |
518 | |
519 /* this function gets called by mplayer to update the gui */ | |
520 int guiGetEvent(int type, char *arg) | |
521 { | |
522 stream_t *stream = (stream_t *) arg; | |
523 #ifdef USE_DVDREAD | |
524 dvd_priv_t *dvdp = (dvd_priv_t *) arg; | |
525 #endif | |
526 if(!mygui || !mygui->skin) return 0; | |
527 | |
528 if(guiIntfStruct.mpcontext) | |
529 { | |
530 audio_out = mpctx_get_audio_out(guiIntfStruct.mpcontext); | |
531 video_out = mpctx_get_video_out(guiIntfStruct.mpcontext); | |
532 mixer = mpctx_get_mixer(guiIntfStruct.mpcontext); | |
533 playtree = mpctx_get_playtree_iter(guiIntfStruct.mpcontext); | |
534 } | |
535 | |
536 switch (type) | |
537 { | |
538 case guiSetFileFormat: | |
539 guiIntfStruct.FileFormat = (int) arg; | |
540 break; | |
541 case guiSetParameters: | |
542 { | |
543 guiGetEvent(guiSetDefaults, NULL); | |
544 guiIntfStruct.DiskChanged = 0; | |
545 guiIntfStruct.FilenameChanged = 0; | |
546 guiIntfStruct.NewPlay = 0; | |
547 switch(guiIntfStruct.StreamType) | |
548 { | |
549 case STREAMTYPE_PLAYLIST: | |
550 break; | |
551 #ifdef USE_DVDREAD | |
552 case STREAMTYPE_DVD: | |
553 { | |
554 char tmp[512]; | |
555 dvd_title = guiIntfStruct.DVD.current_title; | |
556 dvd_chapter = guiIntfStruct.DVD.current_chapter; | |
557 dvd_angle = guiIntfStruct.DVD.current_angle; | |
558 sprintf(tmp,"dvd://%d", guiIntfStruct.Title); | |
559 guiSetFilename(guiIntfStruct.Filename, tmp); | |
560 break; | |
561 } | |
562 #endif | |
563 } | |
564 if(guiIntfStruct.Filename) | |
565 filename = strdup(guiIntfStruct.Filename); | |
566 else if(filename) | |
567 strcpy(guiIntfStruct.Filename, filename); | |
568 break; | |
569 } | |
570 case guiSetAudioOnly: | |
571 { | |
572 guiIntfStruct.AudioOnly = (int) arg; | |
573 if(IsWindowVisible(mygui->subwindow)) | |
574 ShowWindow(mygui->subwindow, SW_HIDE); | |
575 break; | |
576 } | |
577 case guiSetContext: | |
578 guiIntfStruct.mpcontext = (void *) arg; | |
579 break; | |
580 case guiSetDemuxer: | |
581 guiIntfStruct.demuxer = (void *) arg; | |
582 break; | |
583 case guiSetValues: | |
584 { | |
585 guiIntfStruct.sh_video = arg; | |
586 if (arg) | |
587 { | |
588 sh_video_t *sh = (sh_video_t *)arg; | |
589 codecname = sh->codec->name; | |
590 guiIntfStruct.FPS = sh->fps; | |
591 | |
592 /* we have video, show the subwindow */ | |
593 if(!IsWindowVisible(mygui->subwindow) || IsIconic(mygui->subwindow)) | |
594 ShowWindow(mygui->subwindow, SW_SHOWNORMAL); | |
595 if(WinID == -1) | |
596 update_subwindow(); | |
597 | |
598 } | |
599 break; | |
600 } | |
601 case guiSetShVideo: | |
602 { | |
603 guiIntfStruct.MovieWidth = vo_dwidth; | |
604 guiIntfStruct.MovieHeight = vo_dheight; | |
605 | |
606 sub_aspect = (float)guiIntfStruct.MovieWidth/guiIntfStruct.MovieHeight; | |
607 if(WinID != -1) | |
608 update_subwindow(); | |
609 break; | |
610 } | |
611 case guiSetStream: | |
612 { | |
613 guiIntfStruct.StreamType = stream->type; | |
614 switch(stream->type) | |
615 { | |
616 #ifdef USE_DVDREAD | |
617 case STREAMTYPE_DVD: | |
618 guiGetEvent(guiSetDVD, (char *) stream->priv); | |
619 break; | |
620 #endif | |
621 } | |
622 break; | |
623 } | |
624 #ifdef USE_DVDREAD | |
625 case guiSetDVD: | |
626 { | |
627 guiIntfStruct.DVD.titles = dvdp->vmg_file->tt_srpt->nr_of_srpts; | |
628 guiIntfStruct.DVD.chapters = dvdp->vmg_file->tt_srpt->title[dvd_title].nr_of_ptts; | |
629 guiIntfStruct.DVD.angles = dvdp->vmg_file->tt_srpt->title[dvd_title].nr_of_angles; | |
630 guiIntfStruct.DVD.nr_of_audio_channels = dvdp->nr_of_channels; | |
631 memcpy(guiIntfStruct.DVD.audio_streams, dvdp->audio_streams, sizeof(dvdp->audio_streams)); | |
632 guiIntfStruct.DVD.nr_of_subtitles = dvdp->nr_of_subtitles; | |
633 memcpy(guiIntfStruct.DVD.subtitles, dvdp->subtitles, sizeof(dvdp->subtitles)); | |
634 guiIntfStruct.DVD.current_title = dvd_title + 1; | |
635 guiIntfStruct.DVD.current_chapter = dvd_chapter + 1; | |
636 guiIntfStruct.DVD.current_angle = dvd_angle + 1; | |
637 guiIntfStruct.Track = dvd_title + 1; | |
638 break; | |
639 } | |
640 #endif | |
641 case guiReDraw: | |
642 mygui->updatedisplay(mygui, mygui->mainwindow); | |
643 break; | |
644 case guiSetAfilter: | |
645 guiIntfStruct.afilter = (void *) arg; | |
646 break; | |
647 case guiCEvent: | |
648 { | |
649 guiIntfStruct.Playing = (int) arg; | |
650 switch (guiIntfStruct.Playing) | |
651 { | |
652 case guiSetPlay: | |
653 { | |
654 guiIntfStruct.Playing = 1; | |
655 break; | |
656 } | |
657 case guiSetStop: | |
658 { | |
659 guiIntfStruct.Playing = 0; | |
660 if(movie_aspect >= 0) | |
661 movie_aspect = -1; | |
662 update_subwindow(); | |
663 break; | |
664 } | |
665 case guiSetPause: | |
666 guiIntfStruct.Playing = 2; | |
667 break; | |
668 } | |
669 break; | |
670 } | |
671 case guiIEvent: | |
672 { | |
673 mp_msg(MSGT_GPLAYER,MSGL_V, "cmd: %d\n", (int) arg); | |
674 /* MPlayer asks us to quit */ | |
675 switch((int) arg) | |
676 { | |
677 case MP_CMD_GUI_FULLSCREEN: | |
678 mplFullScreen(); | |
679 break; | |
680 case MP_CMD_QUIT: | |
681 { | |
682 mygui->uninit(mygui); | |
683 free(mygui); | |
684 mygui = NULL; | |
685 exit_player("Done"); | |
686 return 0; | |
687 } | |
688 case MP_CMD_GUI_STOP: | |
689 guiGetEvent(guiCEvent, (void *) guiSetStop); | |
690 break; | |
691 case MP_CMD_GUI_PLAY: | |
692 guiGetEvent(guiCEvent, (void *) guiSetPlay); | |
693 break; | |
694 case MP_CMD_GUI_SKINBROWSER: | |
695 if(fullscreen) guiSetEvent(evFullScreen); | |
696 PostMessage(mygui->mainwindow, WM_COMMAND, (WPARAM) ID_SKINBROWSER, 0); | |
697 break; | |
698 case MP_CMD_GUI_PLAYLIST: | |
699 if(fullscreen) guiSetEvent(evFullScreen); | |
700 PostMessage(mygui->mainwindow, WM_COMMAND, (WPARAM) ID_PLAYLIST, 0); | |
701 break; | |
702 case MP_CMD_GUI_PREFERENCES: | |
703 if(fullscreen) guiSetEvent(evFullScreen); | |
704 PostMessage(mygui->mainwindow, WM_COMMAND, (WPARAM) ID_PREFS, 0); | |
705 break; | |
706 case MP_CMD_GUI_LOADFILE: | |
707 if(fullscreen) guiSetEvent(evFullScreen); | |
708 PostMessage(mygui->mainwindow, WM_COMMAND, (WPARAM) IDFILE_OPEN, 0); | |
709 break; | |
710 case MP_CMD_GUI_LOADSUBTITLE: | |
711 if(fullscreen) guiSetEvent(evFullScreen); | |
712 PostMessage(mygui->mainwindow, WM_COMMAND, (WPARAM) IDSUBTITLE_OPEN, 0); | |
713 break; | |
714 default: | |
715 break; | |
716 } | |
717 break; | |
718 } | |
719 case guiSetFileName: | |
720 if (arg) guiIntfStruct.Filename = (char *) arg; | |
721 break; | |
722 case guiSetDefaults: | |
723 { | |
724 audio_id = -1; | |
725 video_id = -1; | |
726 dvdsub_id = -1; | |
727 vobsub_id = -1; | |
728 stream_cache_size = -1; | |
729 autosync = 0; | |
730 vcd_track = 0; | |
731 dvd_title = 0; | |
732 force_fps = 0; | |
733 if(!mygui->playlist->tracks) return 0; | |
734 filename = guiIntfStruct.Filename = mygui->playlist->tracks[mygui->playlist->current]->filename; | |
735 guiIntfStruct.Track = mygui->playlist->current + 1; | |
736 if(gtkAONorm) greplace(&af_cfg.list, "volnorm", "volnorm"); | |
737 if(gtkAOExtraStereo) | |
738 { | |
739 char *name = malloc(12 + 20 + 1); | |
740 snprintf(name, 12 + 20, "extrastereo=%f", gtkAOExtraStereoMul); | |
741 name[12 + 20] = 0; | |
742 greplace(&af_cfg.list, "extrastereo", name); | |
743 free(name); | |
744 } | |
745 if(gtkCacheOn) stream_cache_size = gtkCacheSize; | |
746 if(gtkAutoSyncOn) autosync = gtkAutoSync; | |
747 break; | |
748 } | |
749 case guiSetVolume: | |
750 { | |
751 if(audio_out) | |
752 { | |
753 /* Some audio_out drivers do not support balance e.g. dsound */ | |
754 /* FIXME this algo is not correct */ | |
755 float l, r; | |
756 mixer_getvolume(mixer, &l, &r); | |
757 guiIntfStruct.Volume = (r > l ? r : l); /* max(r,l) */ | |
758 if (r != l) | |
759 guiIntfStruct.Balance = ((r-l) + 100.0f) * 0.5f; | |
760 else | |
761 guiIntfStruct.Balance = 50.0f; | |
762 } | |
763 break; | |
764 } | |
765 default: | |
766 mp_msg(MSGT_GPLAYER, MSGL_ERR, "[GUI] GOT UNHANDLED EVENT %i\n", type); | |
767 } | |
768 return 0; | |
769 } | |
770 | |
771 /* This function adds/inserts one file into the gui playlist */ | |
772 int import_file_into_gui(char *pathname, int insert) | |
773 { | |
774 char filename[MAX_PATH]; | |
775 char *filepart = filename; | |
776 | |
777 if (strstr(pathname, "://")) | |
778 { | |
779 mp_msg(MSGT_GPLAYER, MSGL_V, "[GUI] Adding special %s\n", pathname); | |
780 mygui->playlist->add_track(mygui->playlist, pathname, NULL, NULL, 0); | |
781 return 1; | |
782 } | |
783 if (GetFullPathName(pathname, MAX_PATH, filename, &filepart)) | |
784 { | |
785 if (!(GetFileAttributes(filename) & FILE_ATTRIBUTE_DIRECTORY)) | |
786 { | |
787 mp_msg(MSGT_GPLAYER, MSGL_V, "[GUI] Adding filename: %s - fullpath: %s\n", filepart, filename); | |
788 mygui->playlist->add_track(mygui->playlist, filename, NULL, filepart, 0); | |
789 return 1; | |
790 } | |
791 else | |
792 mp_msg(MSGT_GPLAYER, MSGL_V, "[GUI] Cannot add %s\n", filename); | |
793 } | |
794 | |
795 return 0; | |
796 } | |
797 | |
798 /* This function imports the initial playtree (based on cmd-line files) into the gui playlist | |
799 by either: | |
800 - overwriting gui pl (enqueue=0) */ | |
801 | |
802 int import_initial_playtree_into_gui(play_tree_t *my_playtree, m_config_t *config, int enqueue) | |
803 { | |
804 play_tree_iter_t *my_pt_iter = NULL; | |
805 int result = 0; | |
806 | |
807 if(!mygui) guiInit(); | |
808 | |
809 if((my_pt_iter = pt_iter_create(&my_playtree, config))) | |
810 { | |
811 while ((filename = pt_iter_get_next_file(my_pt_iter)) != NULL) | |
812 { | |
813 if (parse_filename(filename, my_playtree, config, 0)) | |
814 result = 1; | |
815 else if (import_file_into_gui(filename, 0)) /* Add it to end of list */ | |
816 result = 1; | |
817 } | |
818 } | |
819 mplGotoTheNext = 1; | |
820 | |
821 if (result) | |
822 { | |
823 mygui->playlist->current = 0; | |
824 filename = mygui->playlist->tracks[0]->filename; | |
825 } | |
826 return result; | |
827 } | |
828 | |
829 /* This function imports and inserts an playtree, that is created "on the fly", for example by | |
830 parsing some MOV-Reference-File; or by loading an playlist with "File Open" | |
831 The file which contained the playlist is thereby replaced with it's contents. */ | |
832 | |
833 int import_playtree_playlist_into_gui(play_tree_t *my_playtree, m_config_t *config) | |
834 { | |
835 play_tree_iter_t *my_pt_iter = NULL; | |
836 int result = 0; | |
837 | |
838 if((my_pt_iter = pt_iter_create(&my_playtree, config))) | |
839 { | |
840 while ((filename = pt_iter_get_next_file(my_pt_iter)) != NULL) | |
841 if (import_file_into_gui(filename, 1)) /* insert it into the list and set plCurrent = new item */ | |
842 result = 1; | |
843 pt_iter_destroy(&my_pt_iter); | |
844 } | |
845 filename = NULL; | |
846 return result; | |
847 } | |
848 | |
849 inline void gtkMessageBox(int type, const char *str) | |
850 { | |
851 if (type & GTK_MB_FATAL) | |
852 MessageBox(NULL, str, "MPlayer GUI for Windows Error", MB_OK | MB_ICONERROR); | |
853 | |
854 fprintf(stderr, "[GUI] MessageBox: %s\n", str); | |
855 fflush(stderr); | |
856 } | |
857 | |
858 void guiMessageBox(int level, char *str) | |
859 { | |
860 switch(level) | |
861 { | |
862 case MSGL_FATAL: | |
863 gtkMessageBox(GTK_MB_FATAL | GTK_MB_SIMPLE, str); | |
864 break; | |
865 case MSGL_ERR: | |
866 gtkMessageBox(GTK_MB_ERROR | GTK_MB_SIMPLE, str); | |
867 break; | |
868 } | |
869 } | |
870 | |
871 static int update_subwindow(void) | |
872 { | |
873 int x,y; | |
874 RECT rd; | |
875 WINDOWPOS wp; | |
876 | |
877 if(!sub_window) | |
878 { | |
879 WinID = -1; // so far only directx supports WinID in windows | |
880 | |
881 if(IsWindowVisible(mygui->subwindow) && guiIntfStruct.sh_video && guiIntfStruct.Playing) | |
882 { | |
883 ShowWindow(mygui->subwindow, SW_HIDE); | |
884 return 0; | |
885 } | |
886 else if(guiIntfStruct.AudioOnly) | |
887 return 0; | |
888 else ShowWindow(mygui->subwindow, SW_SHOW); | |
889 } | |
890 | |
891 /* we've come out of fullscreen at the end of file */ | |
892 if((!IsWindowVisible(mygui->subwindow) || IsIconic(mygui->subwindow)) && !guiIntfStruct.AudioOnly) | |
893 ShowWindow(mygui->subwindow, SW_SHOWNORMAL); | |
894 | |
895 /* get our current window coordinates */ | |
896 GetWindowRect(mygui->subwindow, &rd); | |
897 | |
898 x = rd.left; | |
899 y = rd.top; | |
900 | |
901 /* restore sub window position when coming out of fullscreen */ | |
902 if(x <= 0) x = old_rect.left; | |
903 if(y <= 0) y = old_rect.top; | |
904 | |
905 if(!guiIntfStruct.Playing) | |
906 { | |
907 window *desc = NULL; | |
908 int i; | |
909 | |
910 for (i=0; i<mygui->skin->windowcount; i++) | |
911 if(mygui->skin->windows[i]->type == wiSub) | |
912 desc = mygui->skin->windows[i]; | |
913 | |
914 rd.right = rd.left+desc->base->bitmap[0]->width; | |
915 rd.bottom = rd.top+desc->base->bitmap[0]->height; | |
916 sub_aspect = (float)(rd.right-rd.left)/(rd.bottom-rd.top); | |
917 } | |
918 else | |
919 { | |
920 rd.right = rd.left+guiIntfStruct.MovieWidth; | |
921 rd.bottom = rd.top+guiIntfStruct.MovieHeight; | |
922 | |
923 if (movie_aspect > 0.0) // forced aspect from the cmdline | |
924 sub_aspect = movie_aspect; | |
925 } | |
926 | |
927 | |
928 AdjustWindowRect(&rd, WS_OVERLAPPEDWINDOW | WS_SIZEBOX, 0); | |
929 SetWindowPos(mygui->subwindow, 0, x, y, rd.right-rd.left, rd.bottom-rd.top, SWP_NOOWNERZORDER); | |
930 | |
931 wp.hwnd = mygui->subwindow; | |
932 wp.x = rd.left; | |
933 wp.y = rd.top; | |
934 wp.cx = rd.right-rd.left; | |
935 wp.cy = rd.bottom-rd.top; | |
936 wp.flags = SWP_NOOWNERZORDER | SWP_SHOWWINDOW; | |
937 | |
938 /* erase the bitmap image if there's video */ | |
939 if(guiIntfStruct.Playing != 0 && guiIntfStruct.sh_video) | |
940 SendMessage(mygui->subwindow, WM_ERASEBKGND, (WPARAM)GetDC(mygui->subwindow), 0); | |
941 | |
942 /* reset the window aspect */ | |
943 SendMessage(mygui->subwindow, WM_WINDOWPOSCHANGED, 0, (LPARAM)&wp); | |
944 return 0; | |
945 } | |
946 | |
947 void guiEventHandling(void) {} |