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