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