Mercurial > mplayer.hg
annotate Gui/win32/interface.c @ 22103:0427f8190a12
Do not read beyond end of data chunk if chunk_size is set.
Sample: http://samples.mplayerhq.hu/A-codecs/wavpcm/ahh.wav
author | reimar |
---|---|
date | Sun, 04 Feb 2007 09:33:57 +0000 |
parents | c885b979fda3 |
children | 9f5657a1dbf7 |
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 | |
21429 | 45 extern m_obj_settings_t *vf_settings; |
18914 | 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(); | |
21897
c885b979fda3
proper fix for avoiding file skipping when mplayer is already playing a file.
vayne
parents:
21765
diff
changeset
|
283 mplGotoTheNext = guiIntfStruct.Playing? 0 : 1; |
18914 | 284 guiGetEvent(guiCEvent, (void *) guiSetStop); |
285 guiGetEvent(guiCEvent, (void *) guiSetPlay); | |
286 break; | |
287 } | |
288 case evNext: | |
289 mplNext(); | |
290 break; | |
291 case evPrev: | |
292 mplPrev(); | |
293 break; | |
294 } | |
295 } | |
296 | |
297 void mplPlay( void ) | |
298 { | |
299 if((!guiIntfStruct.Filename ) || (guiIntfStruct.Filename[0] == 0)) | |
300 return; | |
301 | |
302 if(guiIntfStruct.Playing > 0) | |
303 { | |
304 mplPause(); | |
305 return; | |
306 } | |
307 guiIntfStruct.NewPlay = 1; | |
308 guiGetEvent(guiCEvent, (void *) guiSetPlay); | |
309 } | |
310 | |
311 void mplPause( void ) | |
312 { | |
313 if(!guiIntfStruct.Playing) return; | |
314 | |
315 if(guiIntfStruct.Playing == 1) | |
316 { | |
19061
86350b4b8203
drops casts from void * on malloc/calloc from the gui code
reynaldo
parents:
18953
diff
changeset
|
317 mp_cmd_t * cmd = calloc(1, sizeof(*cmd)); |
18914 | 318 cmd->id=MP_CMD_PAUSE; |
319 cmd->name=strdup("pause"); | |
320 mp_input_queue_cmd(cmd); | |
321 } else guiIntfStruct.Playing = 1; | |
322 } | |
323 | |
324 void mplNext(void) | |
325 { | |
326 if(guiIntfStruct.Playing == 2) return; | |
327 switch(guiIntfStruct.StreamType) | |
328 { | |
329 #ifdef USE_DVDREAD | |
330 case STREAMTYPE_DVD: | |
331 if(guiIntfStruct.DVD.current_chapter == (guiIntfStruct.DVD.chapters - 1)) | |
332 return; | |
333 guiIntfStruct.DVD.current_chapter++; | |
334 break; | |
335 #endif | |
336 default: | |
337 if(mygui->playlist->current == (mygui->playlist->trackcount - 1)) | |
338 return; | |
339 mplSetFileName(NULL, mygui->playlist->tracks[(mygui->playlist->current)++]->filename, | |
340 STREAMTYPE_STREAM); | |
341 break; | |
342 } | |
343 mplGotoTheNext = 0; | |
344 mygui->startplay(mygui); | |
345 } | |
346 | |
347 void mplPrev(void) | |
348 { | |
349 if(guiIntfStruct.Playing == 2) return; | |
350 switch(guiIntfStruct.StreamType) | |
351 { | |
352 #ifdef USE_DVDREAD | |
353 case STREAMTYPE_DVD: | |
354 if(guiIntfStruct.DVD.current_chapter == 1) | |
355 return; | |
356 guiIntfStruct.DVD.current_chapter--; | |
357 break; | |
358 #endif | |
359 default: | |
360 if(mygui->playlist->current == 0) | |
361 return; | |
362 mplSetFileName(NULL, mygui->playlist->tracks[(mygui->playlist->current)--]->filename, | |
363 STREAMTYPE_STREAM); | |
364 break; | |
365 } | |
366 mplGotoTheNext = 0; | |
367 mygui->startplay(mygui); | |
368 } | |
369 | |
370 void mplEnd( void ) | |
371 { | |
372 if(!mplGotoTheNext && guiIntfStruct.Playing) | |
373 { | |
374 mplGotoTheNext = 1; | |
375 return; | |
376 } | |
377 | |
378 if(mplGotoTheNext && guiIntfStruct.Playing && | |
379 (mygui->playlist->current < (mygui->playlist->trackcount - 1)) && | |
380 guiIntfStruct.StreamType != STREAMTYPE_DVD && | |
381 guiIntfStruct.StreamType != STREAMTYPE_DVDNAV) | |
382 { | |
383 /* we've finished this file, reset the aspect */ | |
384 if(movie_aspect >= 0) | |
385 movie_aspect = -1; | |
386 | |
387 mplGotoTheNext = guiIntfStruct.FilenameChanged = guiIntfStruct.NewPlay = 1; | |
388 mplSetFileName(NULL, mygui->playlist->tracks[(mygui->playlist->current)++]->filename, STREAMTYPE_STREAM); | |
389 //sprintf(guiIntfStruct.Filename, mygui->playlist->tracks[(mygui->playlist->current)++]->filename); | |
390 } | |
391 | |
392 if(guiIntfStruct.FilenameChanged && guiIntfStruct.NewPlay) | |
393 return; | |
394 | |
395 guiIntfStruct.TimeSec = 0; | |
396 guiIntfStruct.Position = 0; | |
397 guiIntfStruct.AudioType = 0; | |
398 | |
399 #ifdef USE_DVDREAD | |
400 guiIntfStruct.DVD.current_title = 1; | |
401 guiIntfStruct.DVD.current_chapter = 1; | |
402 guiIntfStruct.DVD.current_angle = 1; | |
403 #endif | |
404 | |
405 if (mygui->playlist->current == (mygui->playlist->trackcount - 1)) | |
406 mygui->playlist->current = 0; | |
407 | |
19408 | 408 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
|
409 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
|
410 { |
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 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
|
412 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
|
413 } |
18914 | 414 guiGetEvent(guiCEvent, (void *) guiSetStop); |
415 } | |
416 | |
417 void mplSetFileName(char *dir, char *name, int type) | |
418 { | |
419 if(!name) return; | |
420 if(!dir) | |
421 guiSetFilename(guiIntfStruct.Filename, name) | |
422 else | |
423 guiSetDF(guiIntfStruct.Filename, dir, name); | |
424 | |
425 guiIntfStruct.StreamType = type; | |
426 free((void **) &guiIntfStruct.AudioFile); | |
427 free((void **) &guiIntfStruct.Subtitlename); | |
428 } | |
429 | |
430 static DWORD WINAPI GuiThread(void) | |
431 { | |
432 MSG msg; | |
433 | |
434 if(!skinName) skinName = strdup("Blue"); | |
435 if(!mygui) mygui = create_gui(get_path("skins"), skinName, guiSetEvent); | |
436 if(!mygui) exit_player("Unable to load gui"); | |
437 | |
438 if(autosync && autosync != gtkAutoSync) | |
439 { | |
440 gtkAutoSyncOn = 1; | |
441 gtkAutoSync = autosync; | |
442 } | |
443 | |
444 while(mygui) | |
445 { | |
446 GetMessage(&msg, NULL, 0, 0); | |
447 TranslateMessage(&msg); | |
448 DispatchMessage(&msg); | |
449 } | |
450 fprintf(stderr, "[GUI] Gui Thread Terminated\n"); | |
451 fflush(stderr); | |
452 return 0; | |
453 } | |
454 | |
455 void guiInit(void) | |
456 { | |
457 memset(&guiIntfStruct, 0, sizeof(guiIntfStruct)); | |
458 /* Create The gui thread */ | |
459 if (!mygui) | |
460 mp_msg(MSGT_GPLAYER, MSGL_V, "[GUI] Creating GUI Thread 0x%04x\n", | |
461 (int) CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) GuiThread, NULL, 0, NULL)); | |
462 | |
463 /* Wait until the gui is created */ | |
464 while(!mygui) Sleep(100); | |
465 mp_msg(MSGT_GPLAYER, MSGL_V, "[GUI] Gui Thread started\n"); | |
466 } | |
467 | |
468 void guiDone(void) | |
469 { | |
470 if(mygui) | |
471 { | |
472 fprintf(stderr, "[GUI] Closed by main mplayer window\n"); | |
473 fflush(stderr); | |
474 mygui->uninit(mygui); | |
475 free(mygui); | |
476 TerminateThread(GuiThread, 0); | |
477 mygui = NULL; | |
478 } | |
479 /* Remove tray icon */ | |
480 Shell_NotifyIcon(NIM_DELETE, &nid); | |
481 cfg_write(); | |
482 } | |
483 | |
484 /* this function gets called by mplayer to update the gui */ | |
485 int guiGetEvent(int type, char *arg) | |
486 { | |
487 stream_t *stream = (stream_t *) arg; | |
488 #ifdef USE_DVDREAD | |
489 dvd_priv_t *dvdp = (dvd_priv_t *) arg; | |
490 #endif | |
19718 | 491 if(!mygui || !mygui->skin) return 0; |
18914 | 492 |
493 switch (type) | |
494 { | |
495 case guiSetFileFormat: | |
496 guiIntfStruct.FileFormat = (int) arg; | |
497 break; | |
498 case guiSetParameters: | |
499 { | |
500 guiGetEvent(guiSetDefaults, NULL); | |
501 guiIntfStruct.DiskChanged = 0; | |
502 guiIntfStruct.FilenameChanged = 0; | |
503 guiIntfStruct.NewPlay = 0; | |
504 switch(guiIntfStruct.StreamType) | |
505 { | |
506 case STREAMTYPE_PLAYLIST: | |
507 break; | |
508 #ifdef USE_DVDREAD | |
509 case STREAMTYPE_DVD: | |
510 { | |
511 char tmp[512]; | |
512 dvd_title = guiIntfStruct.DVD.current_title; | |
513 dvd_chapter = guiIntfStruct.DVD.current_chapter; | |
514 dvd_angle = guiIntfStruct.DVD.current_angle; | |
515 sprintf(tmp,"dvd://%d", guiIntfStruct.Title); | |
516 guiSetFilename(guiIntfStruct.Filename, tmp); | |
517 break; | |
518 } | |
519 #endif | |
520 } | |
521 if(guiIntfStruct.Filename) | |
522 filename = strdup(guiIntfStruct.Filename); | |
523 else if(filename) | |
524 strcpy(guiIntfStruct.Filename, filename); | |
525 break; | |
526 } | |
527 case guiSetAudioOnly: | |
528 { | |
529 guiIntfStruct.AudioOnly = (int) arg; | |
530 if(IsWindowVisible(mygui->subwindow)) | |
531 ShowWindow(mygui->subwindow, SW_HIDE); | |
532 break; | |
533 } | |
534 case guiSetDemuxer: | |
535 guiIntfStruct.demuxer = (void *) arg; | |
536 break; | |
537 case guiSetValues: | |
538 { | |
539 guiIntfStruct.sh_video = arg; | |
540 if (arg) | |
541 { | |
542 sh_video_t *sh = (sh_video_t *)arg; | |
543 codecname = sh->codec->name; | |
544 guiIntfStruct.FPS = sh->fps; | |
545 | |
546 /* we have video, show the subwindow */ | |
547 if(!IsWindowVisible(mygui->subwindow) || IsIconic(mygui->subwindow)) | |
548 ShowWindow(mygui->subwindow, SW_SHOWNORMAL); | |
549 if(WinID == -1) | |
550 update_subwindow(); | |
551 | |
552 } | |
553 break; | |
554 } | |
555 case guiSetShVideo: | |
556 { | |
557 guiIntfStruct.MovieWidth = vo_dwidth; | |
558 guiIntfStruct.MovieHeight = vo_dheight; | |
559 | |
560 sub_aspect = (float)guiIntfStruct.MovieWidth/guiIntfStruct.MovieHeight; | |
561 if(WinID != -1) | |
562 update_subwindow(); | |
563 break; | |
564 } | |
565 case guiSetStream: | |
566 { | |
567 guiIntfStruct.StreamType = stream->type; | |
568 switch(stream->type) | |
569 { | |
570 #ifdef USE_DVDREAD | |
571 case STREAMTYPE_DVD: | |
572 guiGetEvent(guiSetDVD, (char *) stream->priv); | |
573 break; | |
574 #endif | |
575 } | |
576 break; | |
577 } | |
578 #ifdef USE_DVDREAD | |
579 case guiSetDVD: | |
580 { | |
581 guiIntfStruct.DVD.titles = dvdp->vmg_file->tt_srpt->nr_of_srpts; | |
582 guiIntfStruct.DVD.chapters = dvdp->vmg_file->tt_srpt->title[dvd_title].nr_of_ptts; | |
583 guiIntfStruct.DVD.angles = dvdp->vmg_file->tt_srpt->title[dvd_title].nr_of_angles; | |
584 guiIntfStruct.DVD.nr_of_audio_channels = dvdp->nr_of_channels; | |
585 memcpy(guiIntfStruct.DVD.audio_streams, dvdp->audio_streams, sizeof(dvdp->audio_streams)); | |
586 guiIntfStruct.DVD.nr_of_subtitles = dvdp->nr_of_subtitles; | |
587 memcpy(guiIntfStruct.DVD.subtitles, dvdp->subtitles, sizeof(dvdp->subtitles)); | |
588 guiIntfStruct.DVD.current_title = dvd_title + 1; | |
589 guiIntfStruct.DVD.current_chapter = dvd_chapter + 1; | |
590 guiIntfStruct.DVD.current_angle = dvd_angle + 1; | |
591 guiIntfStruct.Track = dvd_title + 1; | |
592 break; | |
593 } | |
594 #endif | |
595 case guiReDraw: | |
596 mygui->updatedisplay(mygui, mygui->mainwindow); | |
597 break; | |
598 case guiSetAfilter: | |
599 guiIntfStruct.afilter = (void *) arg; | |
600 break; | |
601 case guiCEvent: | |
602 { | |
603 guiIntfStruct.Playing = (int) arg; | |
604 switch (guiIntfStruct.Playing) | |
605 { | |
606 case guiSetPlay: | |
607 { | |
608 guiIntfStruct.Playing = 1; | |
609 break; | |
610 } | |
611 case guiSetStop: | |
612 { | |
613 guiIntfStruct.Playing = 0; | |
614 if(movie_aspect >= 0) | |
615 movie_aspect = -1; | |
616 update_subwindow(); | |
617 break; | |
618 } | |
619 case guiSetPause: | |
620 guiIntfStruct.Playing = 2; | |
621 break; | |
622 } | |
623 break; | |
624 } | |
625 case guiIEvent: | |
626 { | |
627 mp_msg(MSGT_GPLAYER,MSGL_V, "cmd: %d\n", (int) arg); | |
628 /* MPlayer asks us to quit */ | |
629 switch((int) arg) | |
630 { | |
631 case MP_CMD_GUI_FULLSCREEN: | |
632 { | |
633 if(!guiIntfStruct.sh_video) break; | |
634 | |
19408 | 635 if(!sub_window) |
19245 | 636 { |
637 video_out->control(VOCTRL_FULLSCREEN, 0); | |
18914 | 638 break; |
19245 | 639 } |
18914 | 640 |
19408 | 641 if(!fullscreen && IsWindowVisible(mygui->subwindow) && !IsIconic(mygui->subwindow)) |
19245 | 642 GetWindowRect(mygui->subwindow, &old_rect); |
643 | |
644 if(fullscreen) | |
18914 | 645 { |
19408 | 646 fullscreen = 0; |
647 style = WS_OVERLAPPEDWINDOW | WS_SIZEBOX; | |
18914 | 648 } else { |
19408 | 649 fullscreen = 1; |
650 style = WS_VISIBLE | WS_POPUP; | |
18914 | 651 } |
19408 | 652 SetWindowLong(mygui->subwindow, GWL_STYLE, style); |
19245 | 653 mpcodecs_config_vo(guiIntfStruct.sh_video, guiIntfStruct.MovieWidth, |
654 guiIntfStruct.MovieHeight, 0); | |
18914 | 655 break; |
656 } | |
657 case MP_CMD_QUIT: | |
658 { | |
659 mygui->uninit(mygui); | |
660 free(mygui); | |
661 mygui = NULL; | |
662 exit_player("Done"); | |
663 return 0; | |
664 } | |
665 case MP_CMD_GUI_STOP: | |
666 guiGetEvent(guiCEvent, (void *) guiSetStop); | |
667 break; | |
668 case MP_CMD_GUI_PLAY: | |
669 guiGetEvent(guiCEvent, (void *) guiSetPlay); | |
670 break; | |
671 case MP_CMD_GUI_SKINBROWSER: | |
19245 | 672 if(fullscreen) guiSetEvent(evFullScreen); |
18914 | 673 PostMessage(mygui->mainwindow, WM_COMMAND, (WPARAM) ID_SKINBROWSER, 0); |
674 break; | |
675 case MP_CMD_GUI_PLAYLIST: | |
19245 | 676 if(fullscreen) guiSetEvent(evFullScreen); |
18914 | 677 PostMessage(mygui->mainwindow, WM_COMMAND, (WPARAM) ID_PLAYLIST, 0); |
678 break; | |
679 case MP_CMD_GUI_PREFERENCES: | |
19245 | 680 if(fullscreen) guiSetEvent(evFullScreen); |
18914 | 681 PostMessage(mygui->mainwindow, WM_COMMAND, (WPARAM) ID_PREFS, 0); |
682 break; | |
683 case MP_CMD_GUI_LOADFILE: | |
19245 | 684 if(fullscreen) guiSetEvent(evFullScreen); |
18914 | 685 PostMessage(mygui->mainwindow, WM_COMMAND, (WPARAM) IDFILE_OPEN, 0); |
686 break; | |
687 case MP_CMD_GUI_LOADSUBTITLE: | |
19245 | 688 if(fullscreen) guiSetEvent(evFullScreen); |
18914 | 689 PostMessage(mygui->mainwindow, WM_COMMAND, (WPARAM) IDSUBTITLE_OPEN, 0); |
690 break; | |
691 default: | |
692 break; | |
693 } | |
694 break; | |
695 } | |
696 case guiSetFileName: | |
697 if (arg) guiIntfStruct.Filename = (char *) arg; | |
698 break; | |
699 case guiSetDefaults: | |
700 { | |
701 audio_id = -1; | |
702 video_id = -1; | |
703 dvdsub_id = -1; | |
704 vobsub_id = -1; | |
705 stream_cache_size = -1; | |
706 autosync = 0; | |
707 vcd_track = 0; | |
708 dvd_title = 0; | |
709 force_fps = 0; | |
710 if(!mygui->playlist->tracks) return 0; | |
711 filename = guiIntfStruct.Filename = mygui->playlist->tracks[mygui->playlist->current]->filename; | |
712 guiIntfStruct.Track = mygui->playlist->current + 1; | |
713 if(gtkAONorm) greplace(&af_cfg.list, "volnorm", "volnorm"); | |
714 if(gtkAOExtraStereo) | |
715 { | |
716 char *name = malloc(12 + 20 + 1); | |
717 snprintf(name, 12 + 20, "extrastereo=%f", gtkAOExtraStereoMul); | |
718 name[12 + 20] = 0; | |
719 greplace(&af_cfg.list, "extrastereo", name); | |
720 free(name); | |
721 } | |
722 if(gtkCacheOn) stream_cache_size = gtkCacheSize; | |
723 if(gtkAutoSyncOn) autosync = gtkAutoSync; | |
724 break; | |
725 } | |
726 case guiSetVolume: | |
727 { | |
728 if(audio_out) | |
729 { | |
730 /* Some audio_out drivers do not support balance e.g. dsound */ | |
731 /* FIXME this algo is not correct */ | |
732 float l, r; | |
733 mixer_getvolume(&mixer, &l, &r); | |
734 guiIntfStruct.Volume = (r > l ? r : l); /* max(r,l) */ | |
735 if (r != l) | |
736 guiIntfStruct.Balance = ((r-l) + 100.0f) * 0.5f; | |
737 else | |
738 guiIntfStruct.Balance = 50.0f; | |
739 } | |
740 break; | |
741 } | |
742 default: | |
743 mp_msg(MSGT_GPLAYER, MSGL_ERR, "[GUI] GOT UNHANDLED EVENT %i\n", type); | |
744 } | |
745 return 0; | |
746 } | |
747 | |
748 /* This function adds/inserts one file into the gui playlist */ | |
749 int import_file_into_gui(char *pathname, int insert) | |
750 { | |
751 char filename[MAX_PATH]; | |
752 char *filepart = filename; | |
753 | |
754 if (strstr(pathname, "://")) | |
755 { | |
756 mp_msg(MSGT_GPLAYER, MSGL_V, "[GUI] Adding special %s\n", pathname); | |
757 mygui->playlist->add_track(mygui->playlist, pathname, NULL, NULL, 0); | |
758 return 1; | |
759 } | |
760 if (GetFullPathName(pathname, MAX_PATH, filename, &filepart)) | |
761 { | |
762 if (!(GetFileAttributes(filename) & FILE_ATTRIBUTE_DIRECTORY)) | |
763 { | |
764 mp_msg(MSGT_GPLAYER, MSGL_V, "[GUI] Adding filename: %s - fullpath: %s\n", filepart, filename); | |
765 mygui->playlist->add_track(mygui->playlist, filename, NULL, filepart, 0); | |
766 return 1; | |
767 } | |
768 else | |
769 mp_msg(MSGT_GPLAYER, MSGL_V, "[GUI] Cannot add %s\n", filename); | |
770 } | |
771 | |
772 return 0; | |
773 } | |
774 | |
775 /* This function imports the initial playtree (based on cmd-line files) into the gui playlist | |
776 by either: | |
777 - overwriting gui pl (enqueue=0) */ | |
778 | |
779 int import_initial_playtree_into_gui(play_tree_t *my_playtree, m_config_t *config, int enqueue) | |
780 { | |
781 play_tree_iter_t *my_pt_iter = NULL; | |
782 int result = 0; | |
783 | |
784 if(!mygui) guiInit(); | |
785 | |
786 if((my_pt_iter = pt_iter_create(&my_playtree, config))) | |
787 { | |
788 while ((filename = pt_iter_get_next_file(my_pt_iter)) != NULL) | |
789 { | |
790 if (parse_filename(filename, my_playtree, config, 0)) | |
791 result = 1; | |
792 else if (import_file_into_gui(filename, 0)) /* Add it to end of list */ | |
793 result = 1; | |
794 } | |
795 } | |
796 mplGotoTheNext = 1; | |
797 | |
798 if (result) | |
799 { | |
800 mygui->playlist->current = 0; | |
801 filename = mygui->playlist->tracks[0]->filename; | |
802 } | |
803 return result; | |
804 } | |
805 | |
806 /* This function imports and inserts an playtree, that is created "on the fly", for example by | |
807 parsing some MOV-Reference-File; or by loading an playlist with "File Open" | |
808 The file which contained the playlist is thereby replaced with it's contents. */ | |
809 | |
810 int import_playtree_playlist_into_gui(play_tree_t *my_playtree, m_config_t *config) | |
811 { | |
812 play_tree_iter_t *my_pt_iter = NULL; | |
813 int result = 0; | |
814 | |
815 if((my_pt_iter = pt_iter_create(&my_playtree, config))) | |
816 { | |
817 while ((filename = pt_iter_get_next_file(my_pt_iter)) != NULL) | |
818 if (import_file_into_gui(filename, 1)) /* insert it into the list and set plCurrent = new item */ | |
819 result = 1; | |
820 pt_iter_destroy(&my_pt_iter); | |
821 } | |
822 filename = NULL; | |
823 return result; | |
824 } | |
825 | |
826 inline void gtkMessageBox(int type, const char *str) | |
827 { | |
828 if (type & GTK_MB_FATAL) | |
829 MessageBox(NULL, str, "MPlayer GUI for Windows Error", MB_OK | MB_ICONERROR); | |
830 | |
831 fprintf(stderr, "[GUI] MessageBox: %s\n", str); | |
832 fflush(stderr); | |
833 } | |
834 | |
835 void guiMessageBox(int level, char *str) | |
836 { | |
837 switch(level) | |
838 { | |
839 case MSGL_FATAL: | |
840 gtkMessageBox(GTK_MB_FATAL | GTK_MB_SIMPLE, str); | |
841 break; | |
842 case MSGL_ERR: | |
843 gtkMessageBox(GTK_MB_ERROR | GTK_MB_SIMPLE, str); | |
844 break; | |
845 } | |
846 } | |
847 | |
848 static int update_subwindow(void) | |
849 { | |
850 int x,y; | |
851 RECT rd; | |
852 WINDOWPOS wp; | |
853 | |
18947
06ab2099c10e
OpenGL outputs actually support WinID, not to mention that showing the option
reimar
parents:
18914
diff
changeset
|
854 if(!sub_window) |
18914 | 855 { |
856 WinID = -1; // so far only directx supports WinID in windows | |
857 | |
858 if(IsWindowVisible(mygui->subwindow) && guiIntfStruct.sh_video && guiIntfStruct.Playing) | |
859 { | |
860 ShowWindow(mygui->subwindow, SW_HIDE); | |
861 return 0; | |
862 } | |
863 else if(guiIntfStruct.AudioOnly) | |
864 return 0; | |
865 else ShowWindow(mygui->subwindow, SW_SHOW); | |
866 } | |
867 | |
868 /* we've come out of fullscreen at the end of file */ | |
869 if((!IsWindowVisible(mygui->subwindow) || IsIconic(mygui->subwindow)) && !guiIntfStruct.AudioOnly) | |
870 ShowWindow(mygui->subwindow, SW_SHOWNORMAL); | |
871 | |
872 /* 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
|
873 GetWindowRect(mygui->subwindow, &rd); |
19245 | 874 |
18914 | 875 x = rd.left; |
876 y = rd.top; | |
877 | |
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
|
878 /* 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
|
879 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
|
880 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
|
881 |
18914 | 882 if(!guiIntfStruct.Playing) |
883 { | |
884 window *desc = NULL; | |
885 int i; | |
886 | |
887 for (i=0; i<mygui->skin->windowcount; i++) | |
888 if(mygui->skin->windows[i]->type == wiSub) | |
889 desc = mygui->skin->windows[i]; | |
890 | |
891 rd.right = rd.left+desc->base->bitmap[0]->width; | |
892 rd.bottom = rd.top+desc->base->bitmap[0]->height; | |
893 sub_aspect = (float)(rd.right-rd.left)/(rd.bottom-rd.top); | |
894 } | |
895 else | |
896 { | |
897 rd.right = rd.left+guiIntfStruct.MovieWidth; | |
898 rd.bottom = rd.top+guiIntfStruct.MovieHeight; | |
899 | |
900 if (movie_aspect > 0.0) // forced aspect from the cmdline | |
901 sub_aspect = movie_aspect; | |
902 } | |
903 | |
19245 | 904 |
18914 | 905 AdjustWindowRect(&rd, WS_OVERLAPPEDWINDOW | WS_SIZEBOX, 0); |
19245 | 906 SetWindowPos(mygui->subwindow, 0, x, y, rd.right-rd.left, rd.bottom-rd.top, SWP_NOOWNERZORDER); |
18914 | 907 |
908 wp.hwnd = mygui->subwindow; | |
909 wp.x = rd.left; | |
910 wp.y = rd.top; | |
911 wp.cx = rd.right-rd.left; | |
912 wp.cy = rd.bottom-rd.top; | |
913 wp.flags = SWP_NOOWNERZORDER | SWP_SHOWWINDOW; | |
914 | |
915 /* erase the bitmap image if there's video */ | |
916 if(guiIntfStruct.Playing != 0 && guiIntfStruct.sh_video) | |
917 SendMessage(mygui->subwindow, WM_ERASEBKGND, (WPARAM)GetDC(mygui->subwindow), 0); | |
918 | |
919 /* reset the window aspect */ | |
920 SendMessage(mygui->subwindow, WM_WINDOWPOSCHANGED, 0, (LPARAM)&wp); | |
921 return 0; | |
922 } | |
923 | |
924 void guiEventHandling(void) {} |