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