Mercurial > mplayer.hg
annotate gui/win32/interface.c @ 33298:f0733d37f56b
Fix bug with gfree() definition in Win32 GUI.
gfree (taking pointer of pointer) was erroneously defined
free (taking pointer). Get rid of gfree() by using suitable
free() statements.
Patch by Stephen Sheldon, sfsheldo gmail com.
author | ib |
---|---|
date | Fri, 06 May 2011 09:35:46 +0000 |
parents | d116366f3523 |
children | c9a13a381946 |
rev | line source |
---|---|
23077 | 1 /* |
23079 | 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 file is part of MPlayer. | |
8 * | |
9 * MPlayer is free software; you can redistribute it and/or modify | |
10 * it under the terms of the GNU General Public License as published by | |
11 * the Free Software Foundation; either version 2 of the License, or | |
12 * (at your option) any later version. | |
13 * | |
14 * MPlayer is distributed in the hope that it will be useful, | |
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 * GNU General Public License for more details. | |
18 * | |
26457 | 19 * You should have received a copy of the GNU General Public License along |
20 * with MPlayer; if not, write to the Free Software Foundation, Inc., | |
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
23079 | 22 */ |
23077 | 23 |
24 #include <windows.h> | |
30901 | 25 #include "path.h" |
26372
76413880bfad
Update include paths to account for build system changes.
diego
parents:
26193
diff
changeset
|
26 #include "gui/interface.h" |
23091
52488bb09d90
Consistently use quotes instead of angled brackets in #include
diego
parents:
23079
diff
changeset
|
27 #include "m_option.h" |
52488bb09d90
Consistently use quotes instead of angled brackets in #include
diego
parents:
23079
diff
changeset
|
28 #include "mixer.h" |
52488bb09d90
Consistently use quotes instead of angled brackets in #include
diego
parents:
23079
diff
changeset
|
29 #include "mp_msg.h" |
52488bb09d90
Consistently use quotes instead of angled brackets in #include
diego
parents:
23079
diff
changeset
|
30 #include "help_mp.h" |
52488bb09d90
Consistently use quotes instead of angled brackets in #include
diego
parents:
23079
diff
changeset
|
31 #include "codec-cfg.h" |
52488bb09d90
Consistently use quotes instead of angled brackets in #include
diego
parents:
23079
diff
changeset
|
32 #include "stream/stream.h" |
52488bb09d90
Consistently use quotes instead of angled brackets in #include
diego
parents:
23079
diff
changeset
|
33 #include "libmpdemux/demuxer.h" |
52488bb09d90
Consistently use quotes instead of angled brackets in #include
diego
parents:
23079
diff
changeset
|
34 #include "libmpdemux/stheader.h" |
27341
e7c989f7a7c9
Start unifying names of internal preprocessor directives.
diego
parents:
26457
diff
changeset
|
35 #ifdef CONFIG_DVDREAD |
23091
52488bb09d90
Consistently use quotes instead of angled brackets in #include
diego
parents:
23079
diff
changeset
|
36 #include "stream/stream_dvd.h" |
23077 | 37 #endif |
23091
52488bb09d90
Consistently use quotes instead of angled brackets in #include
diego
parents:
23079
diff
changeset
|
38 #include "input/input.h" |
52488bb09d90
Consistently use quotes instead of angled brackets in #include
diego
parents:
23079
diff
changeset
|
39 #include "libvo/video_out.h" |
52488bb09d90
Consistently use quotes instead of angled brackets in #include
diego
parents:
23079
diff
changeset
|
40 #include "libao2/audio_out.h" |
52488bb09d90
Consistently use quotes instead of angled brackets in #include
diego
parents:
23079
diff
changeset
|
41 #include "access_mpcontext.h" |
30558 | 42 #include "libmpcodecs/vd.h" |
31425
2392ad3cec9c
Move af_cfg extern variable declaration to dec_audio.h.
diego
parents:
31312
diff
changeset
|
43 #include "libmpcodecs/dec_audio.h" |
30558 | 44 #include "gui/mplayer/gmplayer.h" |
45 #include "mp_core.h" | |
32093 | 46 #include "mpcommon.h" |
23077 | 47 #include "gui.h" |
48 #include "dialogs.h" | |
27391
1d2faa1020fb
Rename a bunch of miscellaneous preprocessor directives.
diego
parents:
27341
diff
changeset
|
49 #ifdef CONFIG_LIBCDIO |
23077 | 50 #include <cdio/cdio.h> |
51 #endif | |
52 | |
53 int guiWinID = 0; | |
54 | |
55 char *skinName = NULL; | |
56 char *codecname = NULL; | |
57 int mplGotoTheNext = 1; | |
58 static gui_t *mygui = NULL; | |
59 static int update_subwindow(void); | |
60 static RECT old_rect; | |
61 static DWORD style; | |
24992 | 62 static HANDLE hThread; |
63 static unsigned threadId; | |
25765
304fc0bbefe1
audio_out / video_out structs should be treated as const
reimar
parents:
24992
diff
changeset
|
64 const ao_functions_t *audio_out = NULL; |
304fc0bbefe1
audio_out / video_out structs should be treated as const
reimar
parents:
24992
diff
changeset
|
65 const vo_functions_t *video_out = NULL; |
23077 | 66 mixer_t *mixer = NULL; |
67 | |
68 /* test for playlist files, no need to specify -playlist on the commandline. | |
69 * add any conceivable playlist extensions here. | |
70 * - Erik | |
71 */ | |
72 int parse_filename(char *file, play_tree_t *playtree, m_config_t *mconfig, int clear) | |
73 { | |
74 if(clear) | |
75 mygui->playlist->clear_playlist(mygui->playlist); | |
76 | |
77 if(strstr(file, ".m3u") || strstr(file, ".pls")) | |
78 { | |
79 playtree = parse_playlist_file(file); | |
80 import_playtree_playlist_into_gui(playtree, mconfig); | |
81 return 1; | |
82 } | |
83 return 0; | |
84 } | |
85 | |
86 /** | |
87 * \brief this actually creates a new list containing only one element... | |
88 */ | |
89 void gaddlist( char ***list, const char *entry) | |
90 { | |
91 int i; | |
92 | |
93 if (*list) | |
94 { | |
95 for (i=0; (*list)[i]; i++) free((*list)[i]); | |
96 free(*list); | |
97 } | |
98 | |
99 *list = malloc(2 * sizeof(char **)); | |
100 (*list)[0] = gstrdup(entry); | |
101 (*list)[1] = NULL; | |
102 } | |
103 | |
104 char *gstrdup(const char *str) | |
105 { | |
106 if (!str) return NULL; | |
107 return strdup(str); | |
108 } | |
109 | |
110 /** | |
111 * \brief this replaces a string starting with search by replace. | |
112 * If not found, replace is appended. | |
113 */ | |
114 void greplace(char ***list, char *search, char *replace) | |
115 { | |
116 int i = 0; | |
117 int len = (search) ? strlen(search) : 0; | |
118 | |
119 if (*list) | |
120 { | |
121 for (i = 0; (*list)[i]; i++) | |
122 { | |
123 if (search && (!strncmp((*list)[i], search, len))) | |
124 { | |
125 free((*list)[i]); | |
126 (*list)[i] = gstrdup(replace); | |
127 return; | |
128 } | |
129 } | |
130 *list = realloc(*list, (i + 2) * sizeof(char *)); | |
131 } | |
132 else | |
133 *list = malloc(2 * sizeof(char *)); | |
134 | |
135 (*list)[i] = gstrdup(replace); | |
136 (*list)[i + 1] = NULL; | |
137 } | |
138 | |
139 /* this function gets called by the gui to update mplayer */ | |
140 static void guiSetEvent(int event) | |
141 { | |
142 if(guiIntfStruct.mpcontext) | |
143 mixer = mpctx_get_mixer(guiIntfStruct.mpcontext); | |
144 | |
145 switch(event) | |
146 { | |
147 case evPlay: | |
148 case evPlaySwitchToPause: | |
23148
71efd1fc20c8
add missing case value, fixes functionality when using some skins.
vayne
parents:
23147
diff
changeset
|
149 case evPauseSwitchToPlay: |
23077 | 150 mplPlay(); |
151 break; | |
152 case evPause: | |
153 mplPause(); | |
154 break; | |
27341
e7c989f7a7c9
Start unifying names of internal preprocessor directives.
diego
parents:
26457
diff
changeset
|
155 #ifdef CONFIG_DVDREAD |
23077 | 156 case evPlayDVD: |
157 { | |
158 static char dvdname[MAX_PATH]; | |
159 guiIntfStruct.DVD.current_title = dvd_title; | |
160 guiIntfStruct.DVD.current_chapter = dvd_chapter; | |
161 guiIntfStruct.DVD.current_angle = dvd_angle; | |
162 guiIntfStruct.DiskChanged = 1; | |
163 | |
164 mplSetFileName(NULL, dvd_device, STREAMTYPE_DVD); | |
165 dvdname[0] = 0; | |
166 strcat(dvdname, "DVD Movie"); | |
167 GetVolumeInformation(dvd_device, dvdname, MAX_PATH, NULL, NULL, NULL, NULL, 0); | |
168 capitalize(dvdname); | |
169 mp_msg(MSGT_GPLAYER, MSGL_V, "Opening DVD %s -> %s\n", dvd_device, dvdname); | |
170 guiGetEvent(guiSetParameters, (char *) STREAMTYPE_DVD); | |
171 mygui->playlist->clear_playlist(mygui->playlist); | |
172 mygui->playlist->add_track(mygui->playlist, filename, NULL, dvdname, 0); | |
173 mygui->startplay(mygui); | |
174 break; | |
175 } | |
176 #endif | |
27391
1d2faa1020fb
Rename a bunch of miscellaneous preprocessor directives.
diego
parents:
27341
diff
changeset
|
177 #ifdef CONFIG_LIBCDIO |
23077 | 178 case evPlayCD: |
179 { | |
180 int i; | |
181 char track[10]; | |
182 char trackname[10]; | |
183 CdIo_t *p_cdio = cdio_open(NULL, DRIVER_UNKNOWN); | |
184 track_t i_tracks; | |
185 | |
186 if(p_cdio == NULL) printf("Couldn't find a driver.\n"); | |
187 i_tracks = cdio_get_num_tracks(p_cdio); | |
188 | |
189 mygui->playlist->clear_playlist(mygui->playlist); | |
190 for(i=0;i<i_tracks;i++) | |
191 { | |
192 sprintf(track, "cdda://%d", i+1); | |
193 sprintf(trackname, "Track %d", i+1); | |
194 mygui->playlist->add_track(mygui->playlist, track, NULL, trackname, 0); | |
195 } | |
196 cdio_destroy(p_cdio); | |
197 mygui->startplay(mygui); | |
198 break; | |
199 } | |
200 #endif | |
201 case evFullScreen: | |
202 mp_input_queue_cmd(mp_input_parse_cmd("vo_fullscreen")); | |
203 break; | |
204 case evExit: | |
205 { | |
206 /* We are asking mplayer to exit, later it will ask us after uninit is made | |
207 this should be the only safe way to quit */ | |
208 mygui->activewidget = NULL; | |
209 mp_input_queue_cmd(mp_input_parse_cmd("quit")); | |
210 break; | |
211 } | |
212 case evStop: | |
213 if(guiIntfStruct.Playing) | |
214 guiGetEvent(guiCEvent, (void *) guiSetStop); | |
215 break; | |
216 case evSetMoviePosition: | |
217 { | |
218 rel_seek_secs = guiIntfStruct.Position / 100.0f; | |
219 abs_seek_pos = 3; | |
220 break; | |
221 } | |
222 case evForward10sec: | |
223 { | |
224 rel_seek_secs = 10.0f; | |
225 abs_seek_pos = 0; | |
226 break; | |
227 } | |
228 case evBackward10sec: | |
229 { | |
230 rel_seek_secs = -10.0f; | |
231 abs_seek_pos = 0; | |
232 break; | |
233 } | |
234 case evSetBalance: | |
235 case evSetVolume: | |
236 { | |
237 float l,r; | |
238 | |
239 if (guiIntfStruct.Playing == 0) | |
240 break; | |
241 | |
242 if (guiIntfStruct.Balance == 50.0f) | |
243 mixer_setvolume(mixer, guiIntfStruct.Volume, guiIntfStruct.Volume); | |
244 | |
245 l = guiIntfStruct.Volume * ((100.0f - guiIntfStruct.Balance) / 50.0f); | |
246 r = guiIntfStruct.Volume * ((guiIntfStruct.Balance) / 50.0f); | |
247 | |
248 if (l > guiIntfStruct.Volume) l=guiIntfStruct.Volume; | |
249 if (r > guiIntfStruct.Volume) r=guiIntfStruct.Volume; | |
250 mixer_setvolume(mixer, l, r); | |
251 /* Check for balance support on mixer - there is a better way ?? */ | |
252 if (r != l) | |
253 { | |
254 mixer_getvolume(mixer, &l, &r); | |
255 if (r == l) | |
256 { | |
257 mp_msg(MSGT_GPLAYER, MSGL_V, "[GUI] Mixer doesn't support balanced audio\n"); | |
258 mixer_setvolume(mixer, guiIntfStruct.Volume, guiIntfStruct.Volume); | |
259 guiIntfStruct.Balance = 50.0f; | |
260 } | |
261 } | |
262 break; | |
263 } | |
264 case evMute: | |
265 { | |
266 mp_cmd_t * cmd = calloc(1, sizeof(*cmd)); | |
267 cmd->id=MP_CMD_MUTE; | |
268 cmd->name=strdup("mute"); | |
269 mp_input_queue_cmd(cmd); | |
270 break; | |
271 } | |
272 case evDropFile: | |
273 case evLoadPlay: | |
274 { | |
275 switch(guiIntfStruct.StreamType) | |
276 { | |
27341
e7c989f7a7c9
Start unifying names of internal preprocessor directives.
diego
parents:
26457
diff
changeset
|
277 #ifdef CONFIG_DVDREAD |
23077 | 278 case STREAMTYPE_DVD: |
279 { | |
280 guiIntfStruct.Title = guiIntfStruct.DVD.current_title; | |
281 guiIntfStruct.Chapter = guiIntfStruct.DVD.current_chapter; | |
282 guiIntfStruct.Angle = guiIntfStruct.DVD.current_angle; | |
283 guiIntfStruct.DiskChanged = 1; | |
284 guiGetEvent(guiCEvent, (void *) guiSetPlay); | |
285 break; | |
286 } | |
23147
21c35763b178
compilation fix for disabling dvd functionality, patch by <bangbangbear at gmail dot com>, slightly modified by me.
vayne
parents:
23123
diff
changeset
|
287 #endif |
23077 | 288 default: |
289 { | |
290 guiIntfStruct.FilenameChanged = guiIntfStruct.NewPlay = 1; | |
291 update_playlistwindow(); | |
292 mplGotoTheNext = guiIntfStruct.Playing? 0 : 1; | |
293 guiGetEvent(guiCEvent, (void *) guiSetStop); | |
294 guiGetEvent(guiCEvent, (void *) guiSetPlay); | |
295 break; | |
296 } | |
297 } | |
298 break; | |
299 } | |
300 case evNext: | |
301 mplNext(); | |
302 break; | |
303 case evPrev: | |
304 mplPrev(); | |
305 break; | |
306 } | |
307 } | |
308 | |
309 void mplPlay( void ) | |
310 { | |
311 if((!guiIntfStruct.Filename ) || (guiIntfStruct.Filename[0] == 0)) | |
312 return; | |
313 | |
314 if(guiIntfStruct.Playing > 0) | |
315 { | |
316 mplPause(); | |
317 return; | |
318 } | |
319 guiIntfStruct.NewPlay = 1; | |
320 guiGetEvent(guiCEvent, (void *) guiSetPlay); | |
321 } | |
322 | |
323 void mplPause( void ) | |
324 { | |
325 if(!guiIntfStruct.Playing) return; | |
326 | |
327 if(guiIntfStruct.Playing == 1) | |
328 { | |
329 mp_cmd_t * cmd = calloc(1, sizeof(*cmd)); | |
330 cmd->id=MP_CMD_PAUSE; | |
331 cmd->name=strdup("pause"); | |
332 mp_input_queue_cmd(cmd); | |
333 } else guiIntfStruct.Playing = 1; | |
334 } | |
335 | |
336 void mplNext(void) | |
337 { | |
338 if(guiIntfStruct.Playing == 2) return; | |
339 switch(guiIntfStruct.StreamType) | |
340 { | |
27341
e7c989f7a7c9
Start unifying names of internal preprocessor directives.
diego
parents:
26457
diff
changeset
|
341 #ifdef CONFIG_DVDREAD |
23077 | 342 case STREAMTYPE_DVD: |
343 if(guiIntfStruct.DVD.current_chapter == (guiIntfStruct.DVD.chapters - 1)) | |
344 return; | |
345 guiIntfStruct.DVD.current_chapter++; | |
346 break; | |
347 #endif | |
348 default: | |
349 if(mygui->playlist->current == (mygui->playlist->trackcount - 1)) | |
350 return; | |
351 mplSetFileName(NULL, mygui->playlist->tracks[(mygui->playlist->current)++]->filename, | |
352 STREAMTYPE_STREAM); | |
353 break; | |
354 } | |
355 mygui->startplay(mygui); | |
356 } | |
357 | |
358 void mplPrev(void) | |
359 { | |
360 if(guiIntfStruct.Playing == 2) return; | |
361 switch(guiIntfStruct.StreamType) | |
362 { | |
27341
e7c989f7a7c9
Start unifying names of internal preprocessor directives.
diego
parents:
26457
diff
changeset
|
363 #ifdef CONFIG_DVDREAD |
23077 | 364 case STREAMTYPE_DVD: |
365 if(guiIntfStruct.DVD.current_chapter == 1) | |
366 return; | |
367 guiIntfStruct.DVD.current_chapter--; | |
368 break; | |
369 #endif | |
370 default: | |
371 if(mygui->playlist->current == 0) | |
372 return; | |
373 mplSetFileName(NULL, mygui->playlist->tracks[(mygui->playlist->current)--]->filename, | |
374 STREAMTYPE_STREAM); | |
375 break; | |
376 } | |
377 mygui->startplay(mygui); | |
378 } | |
379 | |
380 void mplEnd( void ) | |
381 { | |
382 if(!mplGotoTheNext && guiIntfStruct.Playing) | |
383 { | |
384 mplGotoTheNext = 1; | |
385 return; | |
386 } | |
387 | |
388 if(mplGotoTheNext && guiIntfStruct.Playing && | |
389 (mygui->playlist->current < (mygui->playlist->trackcount - 1)) && | |
390 guiIntfStruct.StreamType != STREAMTYPE_DVD && | |
391 guiIntfStruct.StreamType != STREAMTYPE_DVDNAV) | |
392 { | |
393 /* we've finished this file, reset the aspect */ | |
394 if(movie_aspect >= 0) | |
395 movie_aspect = -1; | |
396 | |
397 mplGotoTheNext = guiIntfStruct.FilenameChanged = guiIntfStruct.NewPlay = 1; | |
398 mplSetFileName(NULL, mygui->playlist->tracks[(mygui->playlist->current)++]->filename, STREAMTYPE_STREAM); | |
399 //sprintf(guiIntfStruct.Filename, mygui->playlist->tracks[(mygui->playlist->current)++]->filename); | |
400 } | |
401 | |
402 if(guiIntfStruct.FilenameChanged && guiIntfStruct.NewPlay) | |
403 return; | |
404 | |
405 guiIntfStruct.TimeSec = 0; | |
406 guiIntfStruct.Position = 0; | |
407 guiIntfStruct.AudioType = 0; | |
408 | |
27341
e7c989f7a7c9
Start unifying names of internal preprocessor directives.
diego
parents:
26457
diff
changeset
|
409 #ifdef CONFIG_DVDREAD |
23077 | 410 guiIntfStruct.DVD.current_title = 1; |
411 guiIntfStruct.DVD.current_chapter = 1; | |
412 guiIntfStruct.DVD.current_angle = 1; | |
413 #endif | |
414 | |
415 if (mygui->playlist->current == (mygui->playlist->trackcount - 1)) | |
416 mygui->playlist->current = 0; | |
417 | |
418 fullscreen = 0; | |
419 if(style == WS_VISIBLE | WS_POPUP) | |
420 { | |
421 style = WS_OVERLAPPEDWINDOW | WS_SIZEBOX; | |
422 SetWindowLong(mygui->subwindow, GWL_STYLE, style); | |
423 } | |
424 guiGetEvent(guiCEvent, (void *) guiSetStop); | |
425 } | |
426 | |
427 void mplSetFileName(char *dir, char *name, int type) | |
428 { | |
429 if(!name) return; | |
430 if(!dir) | |
431 guiSetFilename(guiIntfStruct.Filename, name) | |
432 else | |
433 guiSetDF(guiIntfStruct.Filename, dir, name); | |
434 | |
435 guiIntfStruct.StreamType = type; | |
33298 | 436 free(guiIntfStruct.AudioFile); |
437 guiIntfStruct.AudioFile = NULL; | |
438 free(guiIntfStruct.Subtitlename); | |
439 guiIntfStruct.Subtitlename = NULL; | |
23077 | 440 } |
441 | |
442 void mplFullScreen( void ) | |
443 { | |
444 if(!guiIntfStruct.sh_video) return; | |
445 | |
446 if(sub_window) | |
447 { | |
448 if(!fullscreen && IsWindowVisible(mygui->subwindow) && !IsIconic(mygui->subwindow)) | |
449 GetWindowRect(mygui->subwindow, &old_rect); | |
450 | |
451 if(fullscreen) | |
452 { | |
453 fullscreen = 0; | |
454 style = WS_OVERLAPPEDWINDOW | WS_SIZEBOX; | |
455 } else { | |
456 fullscreen = 1; | |
457 style = WS_VISIBLE | WS_POPUP; | |
458 } | |
459 SetWindowLong(mygui->subwindow, GWL_STYLE, style); | |
460 update_subwindow(); | |
461 } | |
462 video_out->control(VOCTRL_FULLSCREEN, 0); | |
463 if(sub_window) ShowWindow(mygui->subwindow, SW_SHOW); | |
464 } | |
465 | |
24992 | 466 static unsigned __stdcall GuiThread(void* param) |
23077 | 467 { |
468 MSG msg; | |
469 | |
470 if(!skinName) skinName = strdup("Blue"); | |
471 if(!mygui) mygui = create_gui(get_path("skins"), skinName, guiSetEvent); | |
30558 | 472 if(!mygui) exit_player(EXIT_ERROR); |
23077 | 473 |
474 if(autosync && autosync != gtkAutoSync) | |
475 { | |
476 gtkAutoSyncOn = 1; | |
477 gtkAutoSync = autosync; | |
478 } | |
479 | |
24992 | 480 while(GetMessage(&msg, NULL, 0, 0)) |
23077 | 481 { |
482 TranslateMessage(&msg); | |
483 DispatchMessage(&msg); | |
484 } | |
23078 | 485 fprintf(stderr, "[GUI] GUI thread terminated.\n"); |
23077 | 486 fflush(stderr); |
487 return 0; | |
488 } | |
489 | |
490 void guiInit(void) | |
491 { | |
492 memset(&guiIntfStruct, 0, sizeof(guiIntfStruct)); | |
493 /* Create The gui thread */ | |
494 if (!mygui) | |
495 { | |
24992 | 496 hThread = _beginthreadex(NULL, 0, GuiThread, NULL, 0, &threadId); |
23077 | 497 mp_msg(MSGT_GPLAYER, MSGL_V, "[GUI] Creating GUI Thread 0x%04x\n", threadId); |
498 } | |
499 | |
500 /* Wait until the gui is created */ | |
501 while(!mygui) Sleep(100); | |
23078 | 502 mp_msg(MSGT_GPLAYER, MSGL_V, "[GUI] GUI thread started.\n"); |
23077 | 503 } |
504 | |
505 void guiDone(void) | |
506 { | |
507 if(mygui) | |
508 { | |
509 fprintf(stderr, "[GUI] Closed by main mplayer window\n"); | |
510 fflush(stderr); | |
24992 | 511 PostThreadMessage(threadId, WM_QUIT, 0, 0); |
512 WaitForSingleObject(hThread, INFINITE); | |
513 CloseHandle(hThread); | |
23077 | 514 mygui->uninit(mygui); |
515 free(mygui); | |
516 mygui = NULL; | |
517 } | |
518 /* Remove tray icon */ | |
519 Shell_NotifyIcon(NIM_DELETE, &nid); | |
520 cfg_write(); | |
521 } | |
522 | |
523 /* this function gets called by mplayer to update the gui */ | |
30722
b0342ca7ea61
Fix windows Gui compilation and remove some related typecasts.
reimar
parents:
30558
diff
changeset
|
524 int guiGetEvent(int type, void *arg) |
23077 | 525 { |
30722
b0342ca7ea61
Fix windows Gui compilation and remove some related typecasts.
reimar
parents:
30558
diff
changeset
|
526 stream_t *stream = arg; |
27341
e7c989f7a7c9
Start unifying names of internal preprocessor directives.
diego
parents:
26457
diff
changeset
|
527 #ifdef CONFIG_DVDREAD |
30722
b0342ca7ea61
Fix windows Gui compilation and remove some related typecasts.
reimar
parents:
30558
diff
changeset
|
528 dvd_priv_t *dvdp = arg; |
23077 | 529 #endif |
530 if(!mygui || !mygui->skin) return 0; | |
531 | |
532 if(guiIntfStruct.mpcontext) | |
533 { | |
534 audio_out = mpctx_get_audio_out(guiIntfStruct.mpcontext); | |
535 video_out = mpctx_get_video_out(guiIntfStruct.mpcontext); | |
536 mixer = mpctx_get_mixer(guiIntfStruct.mpcontext); | |
537 playtree = mpctx_get_playtree_iter(guiIntfStruct.mpcontext); | |
538 } | |
539 | |
540 switch (type) | |
541 { | |
542 case guiSetFileFormat: | |
543 guiIntfStruct.FileFormat = (int) arg; | |
544 break; | |
545 case guiSetParameters: | |
546 { | |
547 guiGetEvent(guiSetDefaults, NULL); | |
548 guiIntfStruct.DiskChanged = 0; | |
549 guiIntfStruct.FilenameChanged = 0; | |
550 guiIntfStruct.NewPlay = 0; | |
551 switch(guiIntfStruct.StreamType) | |
552 { | |
553 case STREAMTYPE_PLAYLIST: | |
554 break; | |
27341
e7c989f7a7c9
Start unifying names of internal preprocessor directives.
diego
parents:
26457
diff
changeset
|
555 #ifdef CONFIG_DVDREAD |
23077 | 556 case STREAMTYPE_DVD: |
557 { | |
558 char tmp[512]; | |
559 dvd_title = guiIntfStruct.DVD.current_title; | |
560 dvd_chapter = guiIntfStruct.DVD.current_chapter; | |
561 dvd_angle = guiIntfStruct.DVD.current_angle; | |
562 sprintf(tmp,"dvd://%d", guiIntfStruct.Title); | |
563 guiSetFilename(guiIntfStruct.Filename, tmp); | |
564 break; | |
565 } | |
566 #endif | |
567 } | |
568 if(guiIntfStruct.Filename) | |
569 filename = strdup(guiIntfStruct.Filename); | |
570 else if(filename) | |
571 strcpy(guiIntfStruct.Filename, filename); | |
572 break; | |
573 } | |
574 case guiSetAudioOnly: | |
575 { | |
576 guiIntfStruct.AudioOnly = (int) arg; | |
577 if(IsWindowVisible(mygui->subwindow)) | |
578 ShowWindow(mygui->subwindow, SW_HIDE); | |
579 break; | |
580 } | |
581 case guiSetContext: | |
30722
b0342ca7ea61
Fix windows Gui compilation and remove some related typecasts.
reimar
parents:
30558
diff
changeset
|
582 guiIntfStruct.mpcontext = arg; |
23077 | 583 break; |
584 case guiSetDemuxer: | |
30722
b0342ca7ea61
Fix windows Gui compilation and remove some related typecasts.
reimar
parents:
30558
diff
changeset
|
585 guiIntfStruct.demuxer = arg; |
23077 | 586 break; |
587 case guiSetValues: | |
588 { | |
589 guiIntfStruct.sh_video = arg; | |
590 if (arg) | |
591 { | |
30722
b0342ca7ea61
Fix windows Gui compilation and remove some related typecasts.
reimar
parents:
30558
diff
changeset
|
592 sh_video_t *sh = arg; |
23077 | 593 codecname = sh->codec->name; |
594 guiIntfStruct.FPS = sh->fps; | |
595 | |
596 /* we have video, show the subwindow */ | |
597 if(!IsWindowVisible(mygui->subwindow) || IsIconic(mygui->subwindow)) | |
598 ShowWindow(mygui->subwindow, SW_SHOWNORMAL); | |
599 if(WinID == -1) | |
600 update_subwindow(); | |
601 | |
602 } | |
603 break; | |
604 } | |
605 case guiSetShVideo: | |
606 { | |
607 guiIntfStruct.MovieWidth = vo_dwidth; | |
608 guiIntfStruct.MovieHeight = vo_dheight; | |
609 | |
610 sub_aspect = (float)guiIntfStruct.MovieWidth/guiIntfStruct.MovieHeight; | |
611 if(WinID != -1) | |
612 update_subwindow(); | |
613 break; | |
614 } | |
615 case guiSetStream: | |
616 { | |
617 guiIntfStruct.StreamType = stream->type; | |
618 switch(stream->type) | |
619 { | |
27341
e7c989f7a7c9
Start unifying names of internal preprocessor directives.
diego
parents:
26457
diff
changeset
|
620 #ifdef CONFIG_DVDREAD |
23077 | 621 case STREAMTYPE_DVD: |
622 guiGetEvent(guiSetDVD, (char *) stream->priv); | |
623 break; | |
624 #endif | |
625 } | |
626 break; | |
627 } | |
27341
e7c989f7a7c9
Start unifying names of internal preprocessor directives.
diego
parents:
26457
diff
changeset
|
628 #ifdef CONFIG_DVDREAD |
23077 | 629 case guiSetDVD: |
630 { | |
631 guiIntfStruct.DVD.titles = dvdp->vmg_file->tt_srpt->nr_of_srpts; | |
632 guiIntfStruct.DVD.chapters = dvdp->vmg_file->tt_srpt->title[dvd_title].nr_of_ptts; | |
633 guiIntfStruct.DVD.angles = dvdp->vmg_file->tt_srpt->title[dvd_title].nr_of_angles; | |
634 guiIntfStruct.DVD.nr_of_audio_channels = dvdp->nr_of_channels; | |
635 memcpy(guiIntfStruct.DVD.audio_streams, dvdp->audio_streams, sizeof(dvdp->audio_streams)); | |
636 guiIntfStruct.DVD.nr_of_subtitles = dvdp->nr_of_subtitles; | |
637 memcpy(guiIntfStruct.DVD.subtitles, dvdp->subtitles, sizeof(dvdp->subtitles)); | |
638 guiIntfStruct.DVD.current_title = dvd_title + 1; | |
639 guiIntfStruct.DVD.current_chapter = dvd_chapter + 1; | |
640 guiIntfStruct.DVD.current_angle = dvd_angle + 1; | |
641 guiIntfStruct.Track = dvd_title + 1; | |
642 break; | |
643 } | |
644 #endif | |
645 case guiReDraw: | |
646 mygui->updatedisplay(mygui, mygui->mainwindow); | |
647 break; | |
648 case guiSetAfilter: | |
30722
b0342ca7ea61
Fix windows Gui compilation and remove some related typecasts.
reimar
parents:
30558
diff
changeset
|
649 guiIntfStruct.afilter = arg; |
23077 | 650 break; |
651 case guiCEvent: | |
652 { | |
653 guiIntfStruct.Playing = (int) arg; | |
654 switch (guiIntfStruct.Playing) | |
655 { | |
656 case guiSetPlay: | |
657 { | |
658 guiIntfStruct.Playing = 1; | |
659 break; | |
660 } | |
661 case guiSetStop: | |
662 { | |
663 guiIntfStruct.Playing = 0; | |
664 if(movie_aspect >= 0) | |
665 movie_aspect = -1; | |
666 update_subwindow(); | |
667 break; | |
668 } | |
669 case guiSetPause: | |
670 guiIntfStruct.Playing = 2; | |
671 break; | |
672 } | |
673 break; | |
674 } | |
675 case guiIEvent: | |
676 { | |
677 mp_msg(MSGT_GPLAYER,MSGL_V, "cmd: %d\n", (int) arg); | |
678 /* MPlayer asks us to quit */ | |
679 switch((int) arg) | |
680 { | |
31312
0b7792622c88
Remove Gui-specific slave commands and associated key-bindings and other code.
reimar
parents:
30901
diff
changeset
|
681 case MP_CMD_VO_FULLSCREEN: |
23077 | 682 mplFullScreen(); |
683 break; | |
684 case MP_CMD_QUIT: | |
685 { | |
686 mygui->uninit(mygui); | |
687 free(mygui); | |
688 mygui = NULL; | |
30558 | 689 exit_player(EXIT_QUIT); |
23077 | 690 return 0; |
691 } | |
692 default: | |
693 break; | |
694 } | |
695 break; | |
696 } | |
697 case guiSetFileName: | |
30722
b0342ca7ea61
Fix windows Gui compilation and remove some related typecasts.
reimar
parents:
30558
diff
changeset
|
698 if (arg) guiIntfStruct.Filename = arg; |
23077 | 699 break; |
700 case guiSetDefaults: | |
701 { | |
702 audio_id = -1; | |
703 video_id = -1; | |
704 dvdsub_id = -1; | |
705 vobsub_id = -1; | |
706 stream_cache_size = -1; | |
707 autosync = 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 | |
854 if(!sub_window) | |
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 */ | |
873 GetWindowRect(mygui->subwindow, &rd); | |
874 | |
875 x = rd.left; | |
876 y = rd.top; | |
877 | |
878 /* restore sub window position when coming out of fullscreen */ | |
879 if(x <= 0) x = old_rect.left; | |
880 if(y <= 0) y = old_rect.top; | |
881 | |
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 | |
904 | |
905 AdjustWindowRect(&rd, WS_OVERLAPPEDWINDOW | WS_SIZEBOX, 0); | |
906 SetWindowPos(mygui->subwindow, 0, x, y, rd.right-rd.left, rd.bottom-rd.top, SWP_NOOWNERZORDER); | |
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) {} |