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