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