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