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