~medibuntu-maintainers/mplayer/medibuntu.precise

« back to all changes in this revision

Viewing changes to gui/interface.c

  • Committer: Package Import Robot
  • Author(s): Reinhard Tartler
  • Date: 2012-01-12 22:23:28 UTC
  • mfrom: (0.4.7 sid)
  • mto: This revision was merged to the branch mainline in revision 76.
  • Revision ID: package-import@ubuntu.com-20120112222328-8jqdyodym3p84ygu
Tags: 2:1.0~rc4.dfsg1+svn34540-1
* New upstream snapshot
* upload to unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
17
 */
18
18
 
 
19
#include <stdarg.h>
 
20
#include <stdio.h>
19
21
#include <stdlib.h>
20
22
#include <string.h>
21
23
 
24
26
#include "skin/skin.h"
25
27
#include "ui/gmplayer.h"
26
28
#include "ui/widgets.h"
 
29
#include "util/list.h"
 
30
#include "util/mem.h"
 
31
#include "util/string.h"
27
32
#include "wm/ws.h"
28
33
#include "wm/wsxdnd.h"
29
34
 
32
37
#include "help_mp.h"
33
38
#include "input/input.h"
34
39
#include "libaf/equalizer.h"
 
40
#include "libavutil/common.h"
35
41
#include "libmpcodecs/dec_audio.h"
36
42
#include "libmpcodecs/dec_video.h"
37
43
#include "libmpcodecs/vd.h"
50
56
#include "stream/stream_dvd.h"
51
57
#endif
52
58
 
53
 
guiInterface_t guiInfo;
54
 
 
55
 
int guiWinID = -1;
56
 
 
57
 
char *skinName;
58
 
char *skinDirInHome;
59
 
char *skinMPlayerDir;
60
 
 
61
 
plItem *plCurrent    = NULL;
62
 
plItem *plList       = NULL;
63
 
plItem *plLastPlayed = NULL;
64
 
 
65
 
urlItem *URLList = NULL;
66
 
 
67
 
char *fsHistory[fsPersistant_MaxPos] = { NULL, NULL, NULL, NULL, NULL };
68
 
 
69
 
float gtkEquChannels[6][10];
 
59
guiInterface_t guiInfo = {
 
60
    .StreamType = STREAMTYPE_DUMMY,
 
61
    .Balance    = 50.0f
 
62
};
70
63
 
71
64
static int initialized;
72
65
 
73
 
int gstrcmp(const char *a, const char *b)
74
 
{
75
 
    if (!a && !b)
76
 
        return 0;
77
 
    if (!a || !b)
78
 
        return -1;
79
 
 
80
 
    return strcmp(a, b);
81
 
}
82
 
 
83
 
static int gstrncmp(const char *a, const char *b, int size)
84
 
{
85
 
    if (!a && !b)
86
 
        return 0;
87
 
    if (!a || !b)
88
 
        return -1;
89
 
 
90
 
    return strncmp(a, b, size);
91
 
}
92
 
 
93
 
char *gstrdup(const char *str)
94
 
{
95
 
    if (!str)
96
 
        return NULL;
97
 
 
98
 
    return strdup(str);
99
 
}
100
 
 
101
 
char *gstrchr(char *str, int c)
102
 
{
103
 
    if (!str)
104
 
        return NULL;
105
 
 
106
 
    return strchr(str, c);
107
 
}
108
 
 
109
 
void gfree(void **p)
110
 
{
111
 
    free(*p);
112
 
    *p = NULL;
113
 
}
114
 
 
115
 
/**
116
 
 * \brief This actually creates a new list containing only one element...
117
 
 */
118
 
void gaddlist(char ***list, const char *entry)
119
 
{
120
 
    int i;
121
 
 
122
 
    if (*list) {
123
 
        for (i = 0; (*list)[i]; i++)
124
 
            free((*list)[i]);
125
 
 
126
 
        free(*list);
127
 
    }
128
 
 
129
 
    *list      = malloc(2 * sizeof(char **));
130
 
    (*list)[0] = gstrdup(entry);
131
 
    (*list)[1] = NULL;
132
 
}
133
 
 
134
 
/**
135
 
 * \brief This replaces a string starting with search by replace.
136
 
 * If not found, replace is appended.
137
 
 */
138
 
static void greplace(char ***list, const char *search, const char *replace)
139
 
{
140
 
    int i   = 0;
141
 
    int len = (search ? strlen(search) : 0);
142
 
 
143
 
    if (*list) {
144
 
        for (i = 0; (*list)[i]; i++) {
145
 
            if (search && (strncmp((*list)[i], search, len) == 0)) {
146
 
                free((*list)[i]);
147
 
                (*list)[i] = gstrdup(replace);
148
 
                return;
149
 
            }
150
 
        }
151
 
 
152
 
        *list = realloc(*list, (i + 2) * sizeof(char *));
153
 
    } else
154
 
        *list = malloc(2 * sizeof(char *));
155
 
 
156
 
    (*list)[i]     = gstrdup(replace);
157
 
    (*list)[i + 1] = NULL;
158
 
}
 
66
/* MPlayer -> GUI */
159
67
 
160
68
void guiInit(void)
161
69
{
163
71
 
164
72
    mp_msg(MSGT_GPLAYER, MSGL_V, "GUI init.\n");
165
73
 
166
 
    memset(&guiInfo, 0, sizeof(guiInfo));
167
 
    guiInfo.Balance    = 50.0f;
168
 
    guiInfo.StreamType = -1;
169
 
 
170
 
    memset(&gtkEquChannels, 0, sizeof(gtkEquChannels));
 
74
    if (!cdrom_device)
 
75
        cdrom_device = strdup(DEFAULT_CDROM_DEVICE);
 
76
    if (!dvd_device)
 
77
        dvd_device = strdup(DEFAULT_DVD_DEVICE);
171
78
 
172
79
#ifdef CONFIG_DXR3
173
80
    if (!gtkDXR3Device)
202
109
    skinDirInHome  = get_path("skins");
203
110
    skinMPlayerDir = MPLAYER_DATADIR "/skins";
204
111
 
205
 
    mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[interface] skin directory #1: %s\n", skinDirInHome);
206
 
    mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[interface] skin directory #2: %s\n", skinMPlayerDir);
 
112
    mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[interface] skin directory #1: %s\n", skinDirInHome);
 
113
    mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[interface] skin directory #2: %s\n", skinMPlayerDir);
207
114
 
208
115
    if (!skinName)
209
116
        skinName = strdup("default");
220
127
    switch (i) {
221
128
    case -1:
222
129
        gmp_msg(MSGT_GPLAYER, MSGL_FATAL, MSGTR_SKIN_SKINCFG_SkinNotFound, skinName);
223
 
        guiExit(EXIT_ERROR);
 
130
        mplayer(MPLAYER_EXIT_GUI, EXIT_ERROR, 0);
224
131
 
225
132
    case -2:
226
133
        gmp_msg(MSGT_GPLAYER, MSGL_FATAL, MSGTR_SKIN_SKINCFG_SkinCfgError, skinName);
227
 
        guiExit(EXIT_ERROR);
 
134
        mplayer(MPLAYER_EXIT_GUI, EXIT_ERROR, 0);
228
135
    }
229
136
 
230
137
    // initialize windows
233
140
 
234
141
    if (!mainDrawBuffer) {
235
142
        gmp_msg(MSGT_GPLAYER, MSGL_FATAL, MSGTR_NEMDB);
236
 
        guiExit(EXIT_ERROR);
 
143
        mplayer(MPLAYER_EXIT_GUI, EXIT_ERROR, 0);
237
144
    }
238
145
 
239
146
    if (gui_save_pos) {
261
168
    wsCreateImage(&guiApp.subWindow, guiApp.sub.Bitmap.Width, guiApp.sub.Bitmap.Height);
262
169
    wsXDNDMakeAwareness(&guiApp.subWindow);
263
170
 
 
171
    WinID = guiApp.subWindow.WindowID;
 
172
 
264
173
    uiMenuInit();
265
174
    uiPlaybarInit();
266
175
 
271
180
    wsSetShape(&guiApp.mainWindow, guiApp.main.Mask.Image);
272
181
    wsXDNDMakeAwareness(&guiApp.mainWindow);
273
182
 
274
 
    mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[interface] screen depth: %d\n", wsDepthOnScreen);
275
 
    mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[interface] mainWindow ID: 0x%x\n", (int)guiApp.mainWindow.WindowID);
276
 
    mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[interface] subWindow ID: 0x%x\n", (int)guiApp.subWindow.WindowID);
 
183
    mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[interface] screen depth: %d\n", wsDepthOnScreen);
 
184
    mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[interface] mainWindow ID: 0x%x\n", (int)guiApp.mainWindow.WindowID);
 
185
    mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[interface] subWindow ID: 0x%x\n", (int)guiApp.subWindow.WindowID);
277
186
 
278
187
    guiApp.mainWindow.ReDraw       = (void *)uiMainDraw;
279
188
    guiApp.mainWindow.MouseHandler = uiMainMouseHandle;
303
212
 
304
213
    wsVisibleWindow(&guiApp.mainWindow, wsShowWindow);
305
214
 
306
 
#if 0
307
 
    wsVisibleWindow(&guiApp.subWindow, wsShowWindow);
308
 
    {
309
 
        XEvent xev;
310
 
 
311
 
        do
312
 
            XNextEvent(wsDisplay, &xev);
313
 
        while (xev.type != MapNotify || xev.xmap.event != guiApp.subWindow.WindowID);
314
 
 
315
 
        guiApp.subWindow.Mapped = wsMapped;
316
 
    }
317
 
 
318
 
    if (!fullscreen)
319
 
        fullscreen = gtkLoadFullscreen;
320
 
 
321
 
    if (fullscreen) {
322
 
        uiFullScreen();
323
 
        btnModify(evFullScreen, btnPressed);
324
 
    }
325
 
#else
326
 
    if (!fullscreen)
327
 
        fullscreen = gtkLoadFullscreen;
328
 
 
329
215
    if (gtkShowVideoWindow) {
330
216
        wsVisibleWindow(&guiApp.subWindow, wsShowWindow);
 
217
 
331
218
        {
332
219
            XEvent xev;
333
220
 
336
223
            while (xev.type != MapNotify || xev.xmap.event != guiApp.subWindow.WindowID);
337
224
 
338
225
            guiApp.subWindow.Mapped = wsMapped;
 
226
            guiInfo.VideoWindow     = True;
339
227
        }
340
228
 
341
 
        if (fullscreen) {
 
229
        if (gtkLoadFullscreen)
342
230
            uiFullScreen();
343
 
            btnModify(evFullScreen, btnPressed);
344
 
        }
345
 
    } else {
346
 
        if (fullscreen) {
347
 
            wsVisibleWindow(&guiApp.subWindow, wsShowWindow);
348
 
            {
349
 
                XEvent xev;
350
 
 
351
 
                do
352
 
                    XNextEvent(wsDisplay, &xev);
353
 
                while (xev.type != MapNotify || xev.xmap.event != guiApp.subWindow.WindowID);
354
 
 
355
 
                guiApp.subWindow.Mapped = wsMapped;
356
 
            }
357
 
            guiInfo.Playing = GUI_PAUSE; // because of !gtkShowVideoWindow...
358
 
            uiFullScreen();        // ...guiInfo.Playing is required
359
 
            wsVisibleWindow(&guiApp.subWindow, wsHideWindow);
360
 
            btnModify(evFullScreen, btnPressed);
361
 
        }
362
 
    }
363
 
#endif
 
231
    } else
 
232
        wsSetBackgroundRGB(&guiApp.subWindow, 0, 0, 0);
 
233
 
 
234
    if (gtkLoadFullscreen)
 
235
        btnSet(evFullScreen, btnPressed);
364
236
 
365
237
    guiInfo.Playing = GUI_STOP;
366
238
 
367
239
    uiSubRender = 1;
368
240
 
369
 
    if (filename)
370
 
        uiSetFileName(NULL, filename, STREAMTYPE_FILE);
371
 
 
372
 
    if (plCurrent && !filename)
 
241
    if (plCurrent && !filename) {
373
242
        uiSetFileName(plCurrent->path, plCurrent->name, STREAMTYPE_FILE);
 
243
        filename = NULL; // don't start playing
 
244
    }
374
245
 
375
246
    if (subdata)
376
 
        guiSetFilename(guiInfo.Subtitlename, subdata->filename);
 
247
        setdup(&guiInfo.SubtitleFilename, subdata->filename);
377
248
 
378
 
    guiLoadFont();
 
249
    mplayerLoadFont();
379
250
 
380
251
    initialized = 1;
381
252
}
388
259
        if (gui_save_pos) {
389
260
            gui_main_pos_x = guiApp.mainWindow.X;
390
261
            gui_main_pos_y = guiApp.mainWindow.Y;
391
 
            gui_sub_pos_x  = guiApp.subWindow.X;
392
 
            gui_sub_pos_y  = guiApp.subWindow.Y;
 
262
            gui_sub_pos_x  = guiApp.sub.x;
 
263
            gui_sub_pos_y  = guiApp.sub.y;
393
264
        }
394
265
 
395
266
#ifdef CONFIG_ASS
414
285
    mp_msg(MSGT_GPLAYER, MSGL_V, "GUI done.\n");
415
286
}
416
287
 
417
 
void guiExit(enum exit_reason how)
418
 
{
419
 
    exit_player_with_rc(how, how >= EXIT_ERROR);
420
 
}
421
 
 
422
 
void guiLoadFont(void)
423
 
{
424
 
#ifdef CONFIG_FREETYPE
425
 
    load_font_ft(vo_image_width, vo_image_height, &vo_font, font_name, osd_font_scale_factor);
426
 
#else
427
 
    if (vo_font) {
428
 
        int i;
429
 
 
430
 
        free(vo_font->name);
431
 
        free(vo_font->fpath);
432
 
 
433
 
        for (i = 0; i < 16; i++) {
434
 
            if (vo_font->pic_a[i]) {
435
 
                free(vo_font->pic_a[i]->bmp);
436
 
                free(vo_font->pic_a[i]->pal);
437
 
            }
438
 
        }
439
 
 
440
 
        for (i = 0; i < 16; i++) {
441
 
            if (vo_font->pic_b[i]) {
442
 
                free(vo_font->pic_b[i]->bmp);
443
 
                free(vo_font->pic_b[i]->pal);
444
 
            }
445
 
        }
446
 
 
447
 
        free(vo_font);
448
 
        vo_font = NULL;
449
 
    }
450
 
 
451
 
    if (font_name) {
452
 
        vo_font = read_font_desc(font_name, font_factor, 0);
453
 
 
454
 
        if (!vo_font)
455
 
            gmp_msg(MSGT_GPLAYER, MSGL_ERR, MSGTR_CantLoadFont, font_name);
456
 
    } else {
457
 
        font_name = gstrdup(get_path("font/font.desc"));
458
 
        vo_font   = read_font_desc(font_name, font_factor, 0);
459
 
 
460
 
        if (!vo_font) {
461
 
            gfree((void **)&font_name);
462
 
            font_name = gstrdup(MPLAYER_DATADIR "/font/font.desc");
463
 
            vo_font   = read_font_desc(font_name, font_factor, 0);
464
 
        }
465
 
    }
466
 
#endif
467
 
}
468
 
 
469
 
void guiLoadSubtitle(char *name)
470
 
{
471
 
    if (guiInfo.Playing == 0) {
472
 
        guiInfo.SubtitleChanged = 1; // what is this for? (mw)
473
 
        return;
474
 
    }
475
 
 
476
 
    if (subdata) {
477
 
        mp_msg(MSGT_GPLAYER, MSGL_INFO, MSGTR_DeletingSubtitles);
478
 
 
479
 
        sub_free(subdata);
480
 
        subdata = NULL;
481
 
        vo_sub  = NULL;
482
 
 
483
 
        if (vo_osd_list) {
484
 
            int len;
485
 
            mp_osd_obj_t *osd;
486
 
 
487
 
            osd = vo_osd_list;
488
 
 
489
 
            while (osd) {
490
 
                if (osd->type == OSDTYPE_SUBTITLE)
491
 
                    break;
492
 
 
493
 
                osd = osd->next;
494
 
            }
495
 
 
496
 
            if (osd && (osd->flags & OSDFLAG_VISIBLE)) {
497
 
                len = osd->stride * (osd->bbox.y2 - osd->bbox.y1);
498
 
                memset(osd->bitmap_buffer, 0, len);
499
 
                memset(osd->alpha_buffer, 0, len);
500
 
            }
501
 
        }
502
 
    }
503
 
 
504
 
    if (name) {
505
 
        mp_msg(MSGT_GPLAYER, MSGL_INFO, MSGTR_LoadingSubtitles, name);
506
 
 
507
 
        subdata = sub_read_file(name, guiInfo.FPS);
508
 
 
509
 
        if (!subdata)
510
 
            gmp_msg(MSGT_GPLAYER, MSGL_ERR, MSGTR_CantLoadSub, name);
511
 
 
512
 
        sub_name    = (malloc(2 * sizeof(char *))); // when mplayer will be restarted
513
 
        sub_name[0] = strdup(name);                 // sub_name[0] will be read
514
 
        sub_name[1] = NULL;
515
 
    }
516
 
 
517
 
    update_set_of_subtitles();
518
 
}
519
 
 
520
288
static void add_vf(char *str)
521
289
{
522
290
    void *p;
552
320
    mp_msg(MSGT_GPLAYER, MSGL_INFO, MSGTR_AddingVideoFilter, str);
553
321
}
554
322
 
555
 
int guiGetEvent(int type, void *arg)
 
323
int gui(int what, void *data)
556
324
{
557
325
    mixer_t *mixer = NULL;
558
 
 
559
 
    stream_t *stream = arg;
560
 
 
 
326
    stream_t *stream;
561
327
#ifdef CONFIG_DVDREAD
562
 
    dvd_priv_t *dvdp = arg;
 
328
    dvd_priv_t *dvd;
563
329
#endif
 
330
    plItem *next;
 
331
    int msg, state;
564
332
 
565
333
    if (guiInfo.mpcontext)
566
334
        mixer = mpctx_get_mixer(guiInfo.mpcontext);
567
335
 
568
 
    switch (type) {
569
 
    case guiXEvent:
570
 
        guiInfo.event_struct = arg;
571
 
        wsEvents(wsDisplay, arg);
572
 
        gtkEventHandling();
 
336
    switch (what) {
 
337
    case GUI_SET_CONTEXT:
 
338
        guiInfo.mpcontext = data;
573
339
        break;
574
340
 
575
 
    case guiSetState:
 
341
    case GUI_SET_STATE:
576
342
 
577
 
        switch ((int)arg) {
 
343
        switch ((int)data) {
 
344
        case GUI_STOP:
578
345
        case GUI_PLAY:
579
346
// if ( !gtkShowVideoWindow ) wsVisibleWindow( &guiApp.subWindow,wsHideWindow );
580
 
            guiInfo.Playing = GUI_PLAY;
581
 
            break;
582
 
 
583
 
        case GUI_STOP:
584
 
// if ( !gtkShowVideoWindow ) wsVisibleWindow( &guiApp.subWindow,wsHideWindow );
585
 
            guiInfo.Playing = GUI_STOP;
586
 
            break;
587
 
 
588
347
        case GUI_PAUSE:
589
 
            guiInfo.Playing = GUI_PAUSE;
 
348
            guiInfo.Playing = (int)data;
590
349
            break;
591
350
        }
592
351
 
593
352
        uiState();
594
353
        break;
595
354
 
596
 
    case guiSetFileName:
597
 
        if (arg)
598
 
            guiSetFilename(guiInfo.Filename, arg);
599
 
        break;
600
 
 
601
 
    case guiSetAudioOnly:
602
 
 
603
 
        guiInfo.AudioOnly = (int)arg;
604
 
 
605
 
        if ((int)arg) {
606
 
            guiInfo.NoWindow = True;
607
 
            wsVisibleWindow(&guiApp.subWindow, wsHideWindow);
608
 
        } else
609
 
            wsVisibleWindow(&guiApp.subWindow, wsShowWindow);
610
 
 
611
 
        break;
612
 
 
613
 
    case guiSetContext:
614
 
        guiInfo.mpcontext = arg;
615
 
    // NOTE TO MYSELF: is break missing?
616
 
 
617
 
    case guiSetDemuxer:
618
 
        guiInfo.demuxer = arg;
619
 
        break;
620
 
 
621
 
    case guiSetAfilter:
622
 
        guiInfo.afilter = arg;
623
 
        break;
624
 
 
625
 
    case guiSetShVideo:
626
 
 
627
 
        if (!guiApp.subWindow.isFullScreen) {
628
 
            wsResizeWindow(&guiApp.subWindow, vo_dwidth, vo_dheight);
629
 
            wsMoveWindow(&guiApp.subWindow, True, guiApp.sub.x, guiApp.sub.y);
630
 
        }
631
 
 
632
 
        guiInfo.MovieWidth  = vo_dwidth;
633
 
        guiInfo.MovieHeight = vo_dheight;
634
 
 
635
 
        if (guiWinID >= 0)
636
 
            wsMoveWindow(&guiApp.mainWindow, 0, 0, vo_dheight);
637
 
 
638
 
        WinID = guiApp.subWindow.WindowID;
639
 
        break;
640
 
 
641
 
#ifdef CONFIG_DVDREAD
642
 
    case guiSetDVD:
643
 
        guiInfo.DVD.titles   = dvdp->vmg_file->tt_srpt->nr_of_srpts;
644
 
        guiInfo.DVD.chapters = dvdp->vmg_file->tt_srpt->title[dvd_title].nr_of_ptts;
645
 
        guiInfo.DVD.angles   = dvdp->vmg_file->tt_srpt->title[dvd_title].nr_of_angles;
646
 
        guiInfo.DVD.nr_of_audio_channels = dvdp->nr_of_channels;
647
 
        memcpy(guiInfo.DVD.audio_streams, dvdp->audio_streams, sizeof(dvdp->audio_streams));
648
 
        guiInfo.DVD.nr_of_subtitles = dvdp->nr_of_subtitles;
649
 
        memcpy(guiInfo.DVD.subtitles, dvdp->subtitles, sizeof(dvdp->subtitles));
650
 
        guiInfo.DVD.current_title   = dvd_title + 1;
651
 
        guiInfo.DVD.current_chapter = dvd_chapter + 1;
652
 
        guiInfo.DVD.current_angle   = dvd_angle + 1;
653
 
        guiInfo.Track = dvd_title + 1;
654
 
        break;
655
 
#endif
656
 
 
657
 
    case guiSetStream:
658
 
 
659
 
        guiInfo.StreamType = stream->type;
660
 
 
661
 
        switch (stream->type) {
662
 
#ifdef CONFIG_DVDREAD
663
 
        case STREAMTYPE_DVD:
664
 
            guiGetEvent(guiSetDVD, stream->priv);
665
 
            break;
666
 
#endif
667
 
 
668
 
#ifdef CONFIG_VCD
669
 
        case STREAMTYPE_VCD:
670
 
            guiInfo.VCDTracks = 0;
671
 
            stream_control(stream, STREAM_CTRL_GET_NUM_CHAPTERS, &guiInfo.VCDTracks);
672
 
            break;
673
 
#endif
674
 
 
675
 
        default:
676
 
            break;
677
 
        }
678
 
 
679
 
        break;
680
 
 
681
 
    case guiIEvent:
682
 
 
683
 
        mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[interface] guiIEvent: %d\n", (int)arg);
684
 
 
685
 
        switch ((int)arg) {
 
355
    case GUI_HANDLE_EVENTS:
 
356
        if (!guiInfo.Playing || !guiInfo.VideoWindow)
 
357
            wsHandleEvents();
 
358
        wsAutohideCursor();
 
359
        gtkEventHandling();
 
360
        break;
 
361
 
 
362
    case GUI_RUN_COMMAND:
 
363
 
 
364
        mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[interface] GUI_RUN_COMMAND: %d\n", (int)data);
 
365
 
 
366
        switch ((int)data) {
 
367
        case MP_CMD_VO_FULLSCREEN:
 
368
            uiEventHandling(evFullScreen, 0);
 
369
            break;
 
370
 
 
371
        case MP_CMD_PLAY_TREE_STEP:
 
372
            uiEventHandling(evNext, 0);
 
373
            break;
 
374
 
 
375
        case -MP_CMD_PLAY_TREE_STEP:
 
376
            uiEventHandling(evPrev, 0);
 
377
            break;
 
378
 
 
379
        case MP_CMD_STOP:
 
380
            uiEventHandling(evStop, 0);
 
381
            break;
 
382
 
686
383
        case MP_CMD_QUIT:
687
384
            uiEventHandling(evExit, 0);
688
385
            break;
689
 
 
690
 
        case MP_CMD_VO_FULLSCREEN:
691
 
            uiEventHandling(evFullScreen, 0);
692
 
            break;
693
 
        }
694
 
 
695
 
        break;
696
 
 
697
 
    case guiReDraw:
698
 
        uiEventHandling(evRedraw, 0);
699
 
        break;
700
 
 
701
 
    case guiSetVolume:
702
 
        if (mixer) {
703
 
            float l, r;
704
 
 
705
 
            mixer_getvolume(mixer, &l, &r);
706
 
            guiInfo.Volume = (r > l ? r : l);
707
 
 
708
 
            if (r != l)
709
 
                guiInfo.Balance = ((r - l) + 100) * 0.5f;
710
 
            else
711
 
                guiInfo.Balance = 50.0f;
712
 
 
713
 
            btnModify(evSetVolume, guiInfo.Volume);
714
 
            btnModify(evSetBalance, guiInfo.Balance);
715
 
        }
716
 
        break;
717
 
 
718
 
    case guiSetFileFormat:
719
 
        guiInfo.FileFormat = (int)arg;
720
 
        break;
721
 
 
722
 
    case guiSetValues:
723
 
 
724
 
        // video
725
 
 
726
 
        guiInfo.sh_video = arg;
727
 
 
728
 
        if (arg) {
729
 
            sh_video_t *sh = arg;
730
 
            guiInfo.FPS = sh->fps;
731
 
        }
732
 
 
733
 
        if (guiInfo.NoWindow)
734
 
            wsVisibleWindow(&guiApp.subWindow, wsHideWindow);
735
 
 
736
 
        if (guiInfo.StreamType == STREAMTYPE_STREAM)
737
 
            btnSet(evSetMoviePosition, btnDisabled);
738
 
        else
739
 
            btnSet(evSetMoviePosition, btnReleased);
740
 
 
741
 
        // audio
742
 
 
743
 
        if (mixer) {
744
 
            float l, r;
745
 
 
746
 
            mixer_getvolume(mixer, &l, &r);
747
 
            guiInfo.Volume = (r > l ? r : l);
748
 
 
749
 
            if (r != l)
750
 
                guiInfo.Balance = ((r - l) + 100) * 0.5f;
751
 
            else
752
 
                guiInfo.Balance = 50.0f;
753
 
 
754
 
            btnModify(evSetVolume, guiInfo.Volume);
755
 
            btnModify(evSetBalance, guiInfo.Balance);
756
 
        }
757
 
 
758
 
        if (gtkEnableAudioEqualizer) {
759
 
            equalizer_t eq;
760
 
            int i, j;
761
 
 
762
 
            for (i = 0; i < 6; i++) {
763
 
                for (j = 0; j < 10; j++) {
764
 
                    eq.channel = i;
765
 
                    eq.band    = j;
766
 
                    eq.gain    = gtkEquChannels[i][j];
767
 
                    gtkSet(gtkSetEqualizer, 0, &eq);
768
 
                }
769
 
            }
770
 
        }
771
 
 
772
 
        // subtitle
773
 
 
774
 
#ifdef CONFIG_DXR3
775
 
        if (video_driver_list && !gstrcmp(video_driver_list[0], "dxr3") && (guiInfo.FileFormat != DEMUXER_TYPE_MPEG_PS) && !gtkVfLAVC) {
776
 
            gtkMessageBox(GTK_MB_FATAL, MSGTR_NEEDLAVC);
777
 
            guiInfo.Playing = 0;
778
 
            return True;
779
 
        }
780
 
#endif
781
 
 
782
 
        break;
783
 
 
784
 
    case guiSetDefaults:
785
 
 
786
 
// if ( guiInfo.Playing == 1 && guiInfo.FilenameChanged )
787
 
        if (guiInfo.FilenameChanged) {
 
386
        }
 
387
 
 
388
        break;
 
389
 
 
390
    case GUI_RUN_MESSAGE:
 
391
        mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[interface] GUI_RUN_MESSAGE: %s\n", (const char *)data);
 
392
        msg = appFindMessage((const char *)data);
 
393
        if (appFindItem(msg))
 
394
            uiEventHandling(msg, 0);
 
395
        break;
 
396
 
 
397
    case GUI_PREPARE:
 
398
 
 
399
        wsVisibleMouse(&guiApp.subWindow, wsHideMouseCursor);
 
400
 
 
401
        if (guiInfo.NewPlay == GUI_FILE_NEW) {
 
402
            dvd_title = 0;
788
403
            audio_id  = -1;
789
404
            video_id  = -1;
790
405
            dvdsub_id = -1;
791
406
            vobsub_id = -1;
 
407
 
792
408
            stream_cache_size = -1;
793
409
            autosync  = 0;
794
 
            dvd_title = 0;
795
410
            force_fps = 0;
796
411
        }
797
412
 
798
 
        guiInfo.demuxer  = NULL;
799
 
        guiInfo.sh_video = NULL;
800
 
        wsPostRedisplay(&guiApp.subWindow);
801
 
 
802
 
        break;
803
 
 
804
 
    case guiSetParameters:
805
 
 
806
 
        guiGetEvent(guiSetDefaults, NULL);
807
 
 
808
413
        switch (guiInfo.StreamType) {
809
 
        case STREAMTYPE_PLAYLIST:
 
414
        case STREAMTYPE_FILE:
 
415
        case STREAMTYPE_STREAM:
810
416
            break;
811
417
 
 
418
#ifdef CONFIG_CDDA
 
419
        case STREAMTYPE_CDDA:
 
420
        {
 
421
            char tmp[512];
 
422
 
 
423
            sprintf(tmp, "cdda://%d", guiInfo.Track);
 
424
            uiSetFileName(NULL, tmp, SAME_STREAMTYPE);
 
425
        }
 
426
        break;
 
427
#endif
 
428
 
812
429
#ifdef CONFIG_VCD
813
430
        case STREAMTYPE_VCD:
814
431
        {
815
432
            char tmp[512];
816
433
 
817
 
            sprintf(tmp, "vcd://%d", guiInfo.Track + 1);
818
 
            guiSetFilename(guiInfo.Filename, tmp);
 
434
            sprintf(tmp, "vcd://%d", guiInfo.Track);
 
435
            uiSetFileName(NULL, tmp, SAME_STREAMTYPE);
819
436
        }
820
437
        break;
821
438
#endif
825
442
        {
826
443
            char tmp[512];
827
444
 
828
 
            sprintf(tmp, "dvd://%d", guiInfo.Title);
829
 
            guiSetFilename(guiInfo.Filename, tmp);
 
445
            sprintf(tmp, "dvd://%d", guiInfo.Track);
 
446
            uiSetFileName(NULL, tmp, SAME_STREAMTYPE);
830
447
        }
831
448
 
832
449
            dvd_chapter = guiInfo.Chapter;
836
453
#endif
837
454
        }
838
455
 
839
 
// if ( guiInfo.StreamType != STREAMTYPE_PLAYLIST ) // Does not make problems anymore!
840
 
        {
841
 
            if (guiInfo.Filename)
842
 
                filename = gstrdup(guiInfo.Filename);
843
 
            else if (filename)
844
 
                guiSetFilename(guiInfo.Filename, filename);
845
 
        }
846
 
 
847
456
        // video opts
848
457
 
849
458
        if (!video_driver_list) {
859
468
 
860
469
        if (!video_driver_list && !video_driver_list[0]) {
861
470
            gmp_msg(MSGT_GPLAYER, MSGL_FATAL, MSGTR_IDFGCVD);
862
 
            guiExit(EXIT_ERROR);
 
471
            mplayer(MPLAYER_EXIT_GUI, EXIT_ERROR, 0);
863
472
        }
864
473
 
865
474
        {
866
475
            int i = 0;
867
476
 
868
 
            guiInfo.NoWindow = False;
 
477
            guiInfo.VideoWindow = True;
869
478
 
870
479
            while (video_out_drivers[i++]) {
871
480
                if (video_out_drivers[i - 1]->control(VOCTRL_GUISUPPORT, NULL) == VO_TRUE) {
872
481
                    if ((video_driver_list && !gstrcmp(video_driver_list[0], (char *)video_out_drivers[i - 1]->info->short_name)) && (video_out_drivers[i - 1]->control(VOCTRL_GUI_NOWINDOW, NULL) == VO_TRUE)) {
873
 
                        guiInfo.NoWindow = True;
 
482
                        guiInfo.VideoWindow = False;
874
483
                        break;
875
484
                    }
876
485
                }
974
583
 
975
584
        // subtitle
976
585
 
977
 
// subdata->filename=gstrdup( guiInfo.Subtitlename );
 
586
// subdata->filename=gstrdup( guiInfo.SubtitleFilename );
978
587
        stream_dump_type = 0;
979
588
 
980
589
        if (gtkSubDumpMPSub)
984
593
            stream_dump_type = 6;
985
594
 
986
595
        gtkSubDumpMPSub = gtkSubDumpSrt = 0;
987
 
        guiLoadFont();
 
596
        mplayerLoadFont();
988
597
 
989
598
        // misc
990
599
 
994
603
        if (gtkAutoSyncOn)
995
604
            autosync = gtkAutoSync;
996
605
 
997
 
        if (guiInfo.AudioFile)
998
 
            audio_stream = gstrdup(guiInfo.AudioFile);
999
 
        else if (guiInfo.FilenameChanged)
1000
 
            gfree((void **)&audio_stream);
 
606
        if (guiInfo.AudioFilename)
 
607
            audio_stream = gstrdup(guiInfo.AudioFilename);
 
608
        else if (guiInfo.NewPlay == GUI_FILE_NEW)
 
609
            nfree(audio_stream);
1001
610
 
1002
611
// audio_stream = NULL;
1003
612
 
1004
 
        guiInfo.DiskChanged     = 0;
1005
 
        guiInfo.FilenameChanged = 0;
1006
613
        guiInfo.NewPlay = 0;
1007
614
 
1008
615
#ifdef CONFIG_ASS
1013
620
#endif
1014
621
 
1015
622
        break;
1016
 
    }
1017
 
 
1018
 
    return False;
1019
 
}
1020
 
 
1021
 
void guiEventHandling(void)
1022
 
{
1023
 
    if (!guiInfo.Playing || guiInfo.NoWindow)
1024
 
        wsHandleEvents();
1025
 
 
1026
 
    gtkEventHandling();
1027
 
}
1028
 
 
1029
 
// ---
1030
 
#if defined(MP_DEBUG) && 0
1031
 
void list(void)
1032
 
{
1033
 
    plItem *next = plList;
1034
 
 
1035
 
    printf("--- list ---\n");
1036
 
 
1037
 
    while (next || next->next) {
1038
 
        printf("item: %s/%s\n", next->path, next->name);
1039
 
 
1040
 
        if (next->next)
1041
 
            next = next->next;
1042
 
        else
1043
 
            break;
1044
 
    }
1045
 
 
1046
 
    printf("--- end of list ---\n");
1047
 
}
1048
 
#else
1049
 
#define list();
1050
 
#endif
1051
 
 
1052
 
void *gtkSet(int cmd, float fparam, void *vparam)
1053
 
{
1054
 
    equalizer_t *eq   = (equalizer_t *)vparam;
1055
 
    plItem *item      = (plItem *)vparam;
1056
 
    urlItem *url_item = (urlItem *)vparam;
1057
 
    int is_added      = True;
1058
 
 
1059
 
    switch (cmd) {
1060
 
    // handle playlist
1061
 
 
1062
 
    // add item to playlist
1063
 
    case gtkAddPlItem:
1064
 
 
1065
 
        if (plList) {
1066
 
            plItem *next = plList;
1067
 
 
1068
 
            while (next->next)
1069
 
// {
1070
 
// printf( "%s\n",next->name );
1071
 
                next = next->next;
1072
 
// }
1073
 
 
1074
 
            next->next = item;
1075
 
            item->prev = next;
1076
 
            item->next = NULL;
1077
 
        } else {
1078
 
            item->prev = item->next = NULL;
1079
 
            plCurrent  = plList = item;
1080
 
        }
1081
 
 
1082
 
        list();
1083
 
 
1084
 
        return NULL;
1085
 
 
1086
 
    // add item into playlist after current
1087
 
    case gtkInsertPlItem:
1088
 
        if (plCurrent) {
1089
 
            plItem *curr = plCurrent;
1090
 
            item->next = curr->next;
1091
 
 
1092
 
            if (item->next)
1093
 
                item->next->prev = item;
1094
 
 
1095
 
            item->prev = curr;
1096
 
            curr->next = item;
1097
 
            plCurrent  = plCurrent->next;
1098
 
 
1099
 
            return plCurrent;
1100
 
        } else
1101
 
            return gtkSet(gtkAddPlItem, 0, (void *)item);
1102
 
        return NULL;   // NOTE TO MYSELF: remove this
1103
 
 
1104
 
    // get next item from playlist
1105
 
    case gtkGetNextPlItem:
1106
 
        if (plCurrent && plCurrent->next) {
1107
 
            plCurrent = plCurrent->next;
1108
 
// if (!plCurrent && plList)
1109
 
// {
1110
 
// plItem *next = plList;
1111
 
//
1112
 
// while (next->next)
1113
 
// {
1114
 
// if (!next->next) break;
1115
 
// next = next->next;
1116
 
// }
1117
 
//
1118
 
// plCurrent = next;
1119
 
// }
1120
 
            return plCurrent;
1121
 
        }
1122
 
 
1123
 
        return NULL;
1124
 
 
1125
 
    // get previous item from playlist
1126
 
    case gtkGetPrevPlItem:
1127
 
        if (plCurrent && plCurrent->prev) {
1128
 
            plCurrent = plCurrent->prev;
1129
 
// if ( !plCurrent && plList ) plCurrent=plList;
1130
 
            return plCurrent;
1131
 
        }
1132
 
 
1133
 
        return NULL;
1134
 
 
1135
 
    // set current item
1136
 
    case gtkSetCurrPlItem:
1137
 
        plCurrent = item;
1138
 
        return plCurrent;
1139
 
 
1140
 
    // get current item
1141
 
    case gtkGetCurrPlItem:
1142
 
        return plCurrent;
1143
 
 
1144
 
    // delete current item
1145
 
    case gtkDelCurrPlItem:
1146
 
    {
1147
 
        plItem *curr = plCurrent;
1148
 
 
1149
 
        if (!curr)
1150
 
            return NULL;
1151
 
 
1152
 
        if (curr->prev)
1153
 
            curr->prev->next = curr->next;
1154
 
        if (curr->next)
1155
 
            curr->next->prev = curr->prev;
1156
 
        if (curr == plList)
1157
 
            plList = curr->next;
1158
 
 
1159
 
        plCurrent = curr->next;
1160
 
 
1161
 
        // free it
1162
 
        free(curr->path);
1163
 
        free(curr->name);
1164
 
        free(curr);
1165
 
    }
1166
 
 
1167
 
        uiCurr();   // instead of using uiNext && uiPrev
1168
 
 
1169
 
        return plCurrent;
1170
 
 
1171
 
    // delete list
1172
 
    case gtkDelPl:
1173
 
    {
1174
 
        plItem *curr = plList;
1175
 
        plItem *next;
1176
 
 
1177
 
        if (!plList)
1178
 
            return NULL;
1179
 
 
1180
 
        if (!curr->next) {
1181
 
            free(curr->path);
1182
 
            free(curr->name);
1183
 
            free(curr);
1184
 
        } else {
1185
 
            while (curr->next) {
1186
 
                next = curr->next;
1187
 
                free(curr->path);
1188
 
                free(curr->name);
1189
 
                free(curr);
1190
 
                curr = next;
1191
 
            }
1192
 
        }
1193
 
 
1194
 
        plList    = NULL;
1195
 
        plCurrent = NULL;
1196
 
    }
1197
 
 
1198
 
        return NULL;
1199
 
 
1200
 
    // handle url
1201
 
    case gtkAddURLItem:
1202
 
        if (URLList) {
1203
 
            urlItem *next_url = URLList;
1204
 
            is_added = False;
1205
 
 
1206
 
            while (next_url->next) {
1207
 
                if (!gstrcmp(next_url->url, url_item->url)) {
1208
 
                    is_added = True;
1209
 
                    break;
1210
 
                }
1211
 
 
1212
 
                next_url = next_url->next;
1213
 
            }
1214
 
 
1215
 
            if (!is_added && gstrcmp(next_url->url, url_item->url))
1216
 
                next_url->next = url_item;
1217
 
        } else {
1218
 
            url_item->next = NULL;
1219
 
            URLList = url_item;
1220
 
        }
1221
 
 
1222
 
        return NULL;
1223
 
 
1224
 
        // subtitle
1225
 
 
1226
 
#ifndef CONFIG_FREETYPE
1227
 
    case gtkSetFontFactor:
1228
 
        font_factor = fparam;
1229
 
        guiLoadFont();
1230
 
        return NULL;
1231
 
#else
1232
 
    case gtkSetFontOutLine:
1233
 
        subtitle_font_thickness = (8.0f / 100.0f) * fparam;
1234
 
        guiLoadFont();
1235
 
        return NULL;
1236
 
 
1237
 
    case gtkSetFontBlur:
1238
 
        subtitle_font_radius = (8.0f / 100.0f) * fparam;
1239
 
        guiLoadFont();
1240
 
        return NULL;
1241
 
 
1242
 
    case gtkSetFontTextScale:
1243
 
        text_font_scale_factor = fparam;
1244
 
        guiLoadFont();
1245
 
        return NULL;
1246
 
 
1247
 
    case gtkSetFontOSDScale:
1248
 
        osd_font_scale_factor = fparam;
1249
 
        guiLoadFont();
1250
 
        return NULL;
1251
 
 
1252
 
    case gtkSetFontEncoding:
1253
 
        gfree((void **)&subtitle_font_encoding);
1254
 
        subtitle_font_encoding = gstrdup((char *)vparam);
1255
 
        guiLoadFont();
1256
 
        return NULL;
1257
 
 
1258
 
    case gtkSetFontAutoScale:
1259
 
        subtitle_autoscale = (int)fparam;
1260
 
        guiLoadFont();
1261
 
        return NULL;
1262
 
#endif
1263
 
 
1264
 
#ifdef CONFIG_ICONV
1265
 
    case gtkSetSubEncoding:
1266
 
        gfree((void **)&sub_cp);
1267
 
        sub_cp = gstrdup((char *)vparam);
1268
 
        break;
1269
 
#endif
1270
 
 
1271
 
    // misc
1272
 
 
1273
 
    case gtkClearStruct:
1274
 
 
1275
 
        if ((unsigned int)vparam & guiFilenames) {
1276
 
            gfree((void **)&guiInfo.Filename);
1277
 
            gfree((void **)&guiInfo.Subtitlename);
1278
 
            gfree((void **)&guiInfo.AudioFile);
1279
 
            gtkSet(gtkDelPl, 0, NULL);
1280
 
        }
1281
 
 
1282
 
#ifdef CONFIG_DVDREAD
1283
 
        if ((unsigned int)vparam & guiDVD)
1284
 
            memset(&guiInfo.DVD, 0, sizeof(guiDVDStruct));
 
623
 
 
624
    case GUI_SET_STREAM:
 
625
 
 
626
        stream = data;
 
627
        guiInfo.StreamType = stream->type;
 
628
 
 
629
        switch (guiInfo.StreamType) {
 
630
        case STREAMTYPE_FILE:
 
631
        case STREAMTYPE_STREAM:
 
632
            break;
 
633
 
 
634
#ifdef CONFIG_CDDA
 
635
        case STREAMTYPE_CDDA:
 
636
            guiInfo.Tracks = 0;
 
637
            stream_control(stream, STREAM_CTRL_GET_NUM_TITLES, &guiInfo.Tracks);
 
638
            break;
1285
639
#endif
1286
640
 
1287
641
#ifdef CONFIG_VCD
1288
 
        if ((unsigned int)vparam & guiVCD)
1289
 
            guiInfo.VCDTracks = 0;
1290
 
#endif
1291
 
 
1292
 
        return NULL;
1293
 
 
1294
 
    case gtkSetExtraStereo:
1295
 
        gtkAOExtraStereoMul = fparam;
1296
 
        if (guiInfo.afilter)
1297
 
            af_control_any_rev(guiInfo.afilter, AF_CONTROL_ES_MUL | AF_CONTROL_SET, &gtkAOExtraStereoMul);
1298
 
        return NULL;
1299
 
 
1300
 
    case gtkSetPanscan:
1301
 
    {
1302
 
        mp_cmd_t *mp_cmd;
1303
 
 
1304
 
        mp_cmd       = calloc(1, sizeof(*mp_cmd));
1305
 
        mp_cmd->id   = MP_CMD_PANSCAN;
1306
 
        mp_cmd->name = strdup("panscan");
1307
 
        mp_cmd->args[0].v.f = fparam;
1308
 
        mp_cmd->args[1].v.i = 1;
1309
 
        mp_input_queue_cmd(mp_cmd);
1310
 
    }
1311
 
 
1312
 
        return NULL;
1313
 
 
1314
 
    case gtkSetAutoq:
1315
 
        auto_quality = (int)fparam;
1316
 
        return NULL;
1317
 
 
1318
 
    // set equalizers
1319
 
 
1320
 
    case gtkSetContrast:
1321
 
        if (guiInfo.sh_video)
1322
 
            set_video_colors(guiInfo.sh_video, "contrast", (int)fparam);
1323
 
        return NULL;
1324
 
 
1325
 
    case gtkSetBrightness:
1326
 
        if (guiInfo.sh_video)
1327
 
            set_video_colors(guiInfo.sh_video, "brightness", (int)fparam);
1328
 
        return NULL;
1329
 
 
1330
 
    case gtkSetHue:
1331
 
        if (guiInfo.sh_video)
1332
 
            set_video_colors(guiInfo.sh_video, "hue", (int)fparam);
1333
 
        return NULL;
1334
 
 
1335
 
    case gtkSetSaturation:
1336
 
        if (guiInfo.sh_video)
1337
 
            set_video_colors(guiInfo.sh_video, "saturation", (int)fparam);
1338
 
        return NULL;
1339
 
 
1340
 
    case gtkSetEqualizer:
1341
 
    {
1342
 
        af_control_ext_t tmp;
1343
 
 
1344
 
        if (eq) {
1345
 
            gtkEquChannels[eq->channel][eq->band] = eq->gain;
1346
 
            tmp.ch  = eq->channel;
1347
 
            tmp.arg = gtkEquChannels[eq->channel];
1348
 
 
1349
 
            if (guiInfo.afilter)
1350
 
                af_control_any_rev(guiInfo.afilter, AF_CONTROL_EQUALIZER_GAIN | AF_CONTROL_SET, &tmp);
 
642
        case STREAMTYPE_VCD:
 
643
            guiInfo.Tracks = 0;
 
644
            stream_control(stream, STREAM_CTRL_GET_NUM_TITLES, &guiInfo.Tracks);
 
645
            break;
 
646
#endif
 
647
 
 
648
#ifdef CONFIG_DVDREAD
 
649
        case STREAMTYPE_DVD:
 
650
            guiInfo.Tracks = 0;
 
651
            stream_control(stream, STREAM_CTRL_GET_NUM_TITLES, &guiInfo.Tracks);
 
652
            guiInfo.Chapters = 0;
 
653
            stream_control(stream, STREAM_CTRL_GET_NUM_CHAPTERS, &guiInfo.Chapters);
 
654
            guiInfo.Angles = 0;
 
655
            stream_control(stream, STREAM_CTRL_GET_NUM_ANGLES, &guiInfo.Angles);
 
656
            dvd = stream->priv;
 
657
            guiInfo.AudioStreams = dvd->nr_of_channels;
 
658
            memcpy(guiInfo.AudioStream, dvd->audio_streams, sizeof(dvd->audio_streams));
 
659
            guiInfo.Subtitles = dvd->nr_of_subtitles;
 
660
            memcpy(guiInfo.Subtitle, dvd->subtitles, sizeof(dvd->subtitles));
 
661
            guiInfo.Track   = dvd_title + 1;
 
662
            guiInfo.Chapter = dvd_chapter + 1;
 
663
            guiInfo.Angle   = dvd_angle + 1;
 
664
            break;
 
665
#endif
 
666
        }
 
667
 
 
668
        break;
 
669
 
 
670
    case GUI_SET_AFILTER:
 
671
        guiInfo.afilter = data;
 
672
        break;
 
673
 
 
674
    case GUI_SET_VIDEO:
 
675
 
 
676
        // video
 
677
 
 
678
        guiInfo.sh_video = data;
 
679
 
 
680
        state = (guiInfo.StreamType == STREAMTYPE_STREAM ? btnDisabled : btnReleased);
 
681
        btnSet(evForward10sec, state);
 
682
        btnSet(evBackward10sec, state);
 
683
        btnSet(evForward1min, state);
 
684
        btnSet(evBackward1min, state);
 
685
        btnSet(evForward10min, state);
 
686
        btnSet(evBackward10min, state);
 
687
        btnSet(evSetMoviePosition, state);
 
688
 
 
689
#ifdef CONFIG_DXR3
 
690
        if (video_driver_list && !gstrcmp(video_driver_list[0], "dxr3") && (((demuxer_t *)mpctx_get_demuxer(guiInfo.mpcontext))->file_format != DEMUXER_TYPE_MPEG_PS) && !gtkVfLAVC) {
 
691
            gtkMessageBox(GTK_MB_FATAL, MSGTR_NEEDLAVC);
 
692
            return False;
 
693
        }
 
694
#endif
 
695
 
 
696
        break;
 
697
 
 
698
    case GUI_SET_AUDIO:
 
699
 
 
700
        guiInfo.AudioChannels = data ? ((sh_audio_t *)data)->channels : 0;
 
701
 
 
702
        if (data && !guiInfo.sh_video)
 
703
            guiInfo.VideoWindow = False;
 
704
 
 
705
        gui(GUI_SET_MIXER, 0);
 
706
 
 
707
        if (gtkEnableAudioEqualizer) {
 
708
            equalizer_t eq;
 
709
            unsigned int i, j;
 
710
 
 
711
            for (i = 0; i < FF_ARRAY_ELEMS(gtkEquChannels); i++) {
 
712
                for (j = 0; j < FF_ARRAY_ELEMS(*gtkEquChannels); j++) {
 
713
                    eq.channel = i;
 
714
                    eq.band    = j;
 
715
                    eq.gain    = gtkEquChannels[i][j];
 
716
                    mplayer(MPLAYER_SET_EQUALIZER, 0, &eq);
 
717
                }
 
718
            }
 
719
        }
 
720
 
 
721
        // These must be done here (in the last call from MPlayer before
 
722
        // playback starts) and not in GUI_SETUP_VIDEO_WINDOW, because...
 
723
 
 
724
        // ...without video there will be no call to GUI_SETUP_VIDEO_WINDOW
 
725
        if (!guiInfo.VideoWindow) {
 
726
            wsVisibleWindow(&guiApp.subWindow, wsHideWindow);
 
727
            btnSet(evFullScreen, (gtkLoadFullscreen ? btnPressed : btnReleased));
 
728
        }
 
729
 
 
730
        // ...option variable fullscreen determines whether MPlayer will handle
 
731
        //    the window given by WinID as fullscreen window (and will do aspect
 
732
        //    scaling then) or not - quite rubbish
 
733
        fullscreen = gtkLoadFullscreen;
 
734
 
 
735
        break;
 
736
 
 
737
    case GUI_SET_MIXER:
 
738
        if (mixer) {
 
739
            float l, r;
 
740
            static float last_balance = -1;
 
741
 
 
742
            mixer_getvolume(mixer, &l, &r);
 
743
 
 
744
            guiInfo.Volume = FFMAX(l, r);
 
745
            btnModify(evSetVolume, guiInfo.Volume);
 
746
 
 
747
            if (guiInfo.Balance != last_balance) {
 
748
                if (guiInfo.Volume)
 
749
                    guiInfo.Balance = ((r - l) / guiInfo.Volume + 1.0) * 50.0;
 
750
                else
 
751
                    guiInfo.Balance = 50.0f;
 
752
 
 
753
                last_balance = guiInfo.Balance;
 
754
                btnModify(evSetBalance, guiInfo.Balance);
 
755
            }
 
756
        }
 
757
        break;
 
758
 
 
759
    case GUI_REDRAW:
 
760
        uiEventHandling(ivRedraw, 0);
 
761
        break;
 
762
 
 
763
    case GUI_SETUP_VIDEO_WINDOW:
 
764
 
 
765
        guiInfo.VideoWidth  = vo_dwidth;
 
766
        guiInfo.VideoHeight = vo_dheight;
 
767
 
 
768
        if (!guiApp.subWindow.isFullScreen || !guiApp.subWindow.Mapped) {
 
769
            if (!guiApp.subWindow.isFullScreen)
 
770
                wsResizeWindow(&guiApp.subWindow, guiInfo.VideoWidth, guiInfo.VideoHeight);
 
771
 
 
772
            wsMoveWindow(&guiApp.subWindow, False, guiApp.sub.x, guiApp.sub.y);
 
773
 
 
774
            if (!guiApp.subWindow.Mapped)
 
775
                wsVisibleWindow(&guiApp.subWindow, wsShowWindow);
 
776
        }
 
777
 
 
778
        if (gtkLoadFullscreen ^ guiApp.subWindow.isFullScreen)
 
779
            uiEventHandling(evFullScreen, 0);
 
780
 
 
781
        if (guiWinID >= 0)
 
782
            wsMoveWindow(&guiApp.mainWindow, True, 0, guiInfo.VideoHeight);
 
783
 
 
784
        break;
 
785
 
 
786
    case GUI_HANDLE_X_EVENT:
 
787
        wsEvents(wsDisplay, data);
 
788
        gtkEventHandling();
 
789
        break;
 
790
 
 
791
    case GUI_END_FILE:
 
792
 
 
793
        uiEventHandling(ivRedraw, 1);
 
794
 
 
795
        guiInfo.sh_video = NULL;
 
796
 
 
797
        if (!uiGotoTheNext && guiInfo.Playing) {
 
798
            uiGotoTheNext = 1;
 
799
            break;
 
800
        }
 
801
 
 
802
#ifdef CONFIG_CDDA
 
803
        if (guiInfo.StreamType == STREAMTYPE_CDDA) {
 
804
            uiNext();
 
805
 
 
806
            if (guiInfo.Playing)
 
807
                break;
 
808
        }
 
809
#endif
 
810
 
 
811
        if (guiInfo.Playing && (next = listSet(gtkGetNextPlItem, NULL)) && (plLastPlayed != next)) {
 
812
            plLastPlayed = next;
 
813
            uiSetFileName(next->path, next->name, STREAMTYPE_FILE);
 
814
            guiInfo.NewPlay = GUI_FILE_NEW;
 
815
            guiInfo.Track++;
1351
816
        } else {
1352
 
            int i;
1353
 
 
1354
 
            memset(gtkEquChannels, 0, sizeof(gtkEquChannels));
1355
 
 
1356
 
            if (guiInfo.afilter) {
1357
 
                for (i = 0; i < 6; i++) {
1358
 
                    tmp.ch  = i;
1359
 
                    tmp.arg = gtkEquChannels[i];
1360
 
                    af_control_any_rev(guiInfo.afilter, AF_CONTROL_EQUALIZER_GAIN | AF_CONTROL_SET, &tmp);
 
817
            if (guiInfo.NewPlay == GUI_FILE_NEW)
 
818
                break;
 
819
 
 
820
            filename = NULL;
 
821
 
 
822
            guiInfo.ElapsedTime   = 0;
 
823
            guiInfo.Position      = 0;
 
824
            guiInfo.AudioChannels = 0;
 
825
 
 
826
#ifdef CONFIG_DVDREAD
 
827
            guiInfo.Track   = 1;
 
828
            guiInfo.Chapter = 1;
 
829
            guiInfo.Angle   = 1;
 
830
#endif
 
831
 
 
832
            if (gtkShowVideoWindow) {
 
833
                guiInfo.VideoWindow = True;
 
834
                guiInfo.VideoWidth  = guiApp.sub.width;
 
835
                guiInfo.VideoHeight = guiApp.sub.height;
 
836
 
 
837
                if (!guiApp.subWindow.isFullScreen) {
 
838
                    wsResizeWindow(&guiApp.subWindow, guiInfo.VideoWidth, guiInfo.VideoHeight);
 
839
                    wsMoveWindow(&guiApp.subWindow, False, guiApp.sub.x, guiApp.sub.y);
1361
840
                }
 
841
 
 
842
                if (!guiApp.subWindow.Mapped)
 
843
                    wsVisibleWindow(&guiApp.subWindow, wsShowWindow);
 
844
 
 
845
                if (gtkLoadFullscreen ^ guiApp.subWindow.isFullScreen)
 
846
                    uiEventHandling(evFullScreen, 0);
 
847
            } else {
 
848
                wsVisibleWindow(&guiApp.subWindow, wsHideWindow);
 
849
                guiInfo.VideoWindow = False;
 
850
                btnSet(evFullScreen, (gtkLoadFullscreen ? btnPressed : btnReleased));
1362
851
            }
 
852
 
 
853
            gui(GUI_SET_STATE, (void *)GUI_STOP);
 
854
 
 
855
            wsHandleEvents();
 
856
            uiSubRender = 1;
 
857
            wsSetBackgroundRGB(&guiApp.subWindow, guiApp.sub.R, guiApp.sub.G, guiApp.sub.B);
 
858
            wsClearWindow(guiApp.subWindow);
 
859
            wsPostRedisplay(&guiApp.subWindow);
 
860
            wsVisibleMouse(&guiApp.subWindow, wsShowMouseCursor);
1363
861
        }
1364
862
 
1365
 
        return NULL;
1366
 
    }
 
863
        break;
1367
864
    }
1368
865
 
1369
 
    return NULL;
 
866
    return True;
1370
867
}
1371
868
 
1372
869
// This function adds/inserts one file into the gui playlist.
1383
880
    else
1384
881
        pathname[strlen(pathname) - strlen(filename)] = 0;
1385
882
 
1386
 
    mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[interface] playtree, add: %s/%s\n", pathname, filename);
 
883
    mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[interface] playtree, add: %s/%s\n", pathname, filename);
1387
884
 
1388
885
    item = calloc(1, sizeof(plItem));
1389
886
 
1394
891
    item->path = pathname;
1395
892
 
1396
893
    if (insert)
1397
 
        gtkSet(gtkInsertPlItem, 0, (void *)item);            // inserts the item after current, and makes current=item
 
894
        listSet(gtkInsertPlItem, item);           // inserts the item after current, and makes current=item
1398
895
    else
1399
 
        gtkSet(gtkAddPlItem, 0, (void *)item);
 
896
        listSet(gtkAddPlItem, item);
1400
897
 
1401
898
    return 1;
1402
899
}
1405
902
// into the gui playlist by either:
1406
903
// - overwriting gui pl (enqueue=0)
1407
904
// - appending it to gui pl (enqueue=1)
1408
 
int import_initial_playtree_into_gui(play_tree_t *my_playtree, m_config_t *config, int enqueue)
 
905
int guiPlaylistInitialize(play_tree_t *my_playtree, m_config_t *config, int enqueue)
1409
906
{
1410
907
    play_tree_iter_t *my_pt_iter = NULL;
1411
908
    int result = 0;
1412
909
 
1413
910
    if (!enqueue)
1414
 
        gtkSet(gtkDelPl, 0, 0);             // delete playlist before "appending"
 
911
        listSet(gtkDelPl, NULL);             // delete playlist before "appending"
1415
912
 
1416
913
    if ((my_pt_iter = pt_iter_create(&my_playtree, config))) {
1417
914
        while ((filename = pt_iter_get_next_file(my_pt_iter)) != NULL)
1423
920
    uiCurr();   // update filename
1424
921
    uiGotoTheNext = 1;
1425
922
 
1426
 
    if (!enqueue)
1427
 
        filename = guiInfo.Filename;             // Backward compatibility; if file is specified on commandline,
1428
 
                                                 // gmplayer does directly start in Play-Mode.
1429
 
    else
1430
 
        filename = NULL;
 
923
    if (enqueue)
 
924
        filename = NULL;            // don't start playing
1431
925
 
1432
926
    return result;
1433
927
}
1434
928
 
1435
929
// This function imports and inserts an playtree, that is created "on the fly",
1436
930
// for example by parsing some MOV-Reference-File; or by loading an playlist
1437
 
// with "File Open".
 
931
// with "File Open". (The latter, actually, isn't allowed in MPlayer and thus
 
932
// not working which is why this function won't get called for that reason.)
1438
933
// The file which contained the playlist is thereby replaced with it's contents.
1439
 
int import_playtree_playlist_into_gui(play_tree_t *my_playtree, m_config_t *config)
 
934
int guiPlaylistAdd(play_tree_t *my_playtree, m_config_t *config)
1440
935
{
1441
936
    play_tree_iter_t *my_pt_iter = NULL;
1442
937
    int result = 0;
1443
938
    plItem *save;
1444
939
 
1445
 
    save = (plItem *)gtkSet(gtkGetCurrPlItem, 0, 0);    // save current item
 
940
    save = (plItem *)listSet(gtkGetCurrPlItem, NULL);    // save current item
1446
941
 
1447
942
    if ((my_pt_iter = pt_iter_create(&my_playtree, config))) {
1448
943
        while ((filename = pt_iter_get_next_file(my_pt_iter)) != NULL)
1454
949
    }
1455
950
 
1456
951
    if (save)
1457
 
        gtkSet(gtkSetCurrPlItem, 0, (void *)save);
 
952
        listSet(gtkSetCurrPlItem, save);
1458
953
    else
1459
 
        gtkSet(gtkSetCurrPlItem, 0, (void *)plList);     // go to head, if plList was empty before
 
954
        listSet(gtkSetCurrPlItem, plList);    // go to head, if plList was empty before
1460
955
 
1461
956
    if (save && result)
1462
 
        gtkSet(gtkDelCurrPlItem, 0, 0);
 
957
        listSet(gtkDelCurrPlItem, NULL);
1463
958
 
1464
959
    uiCurr();   // update filename
1465
 
    filename = NULL;
1466
960
 
1467
961
    return result;
1468
962
}
1469
963
 
 
964
/* GUI -> MPlayer */
 
965
 
 
966
void mplayer(int what, float value, void *data)
 
967
{
 
968
    equalizer_t *eq = (equalizer_t *)data;
 
969
 
 
970
    switch (what) {
 
971
        // subtitle
 
972
 
 
973
#ifndef CONFIG_FREETYPE
 
974
    case MPLAYER_SET_FONT_FACTOR:
 
975
        font_factor = value;
 
976
        mplayerLoadFont();
 
977
        break;
 
978
#else
 
979
    case MPLAYER_SET_FONT_OUTLINE:
 
980
        subtitle_font_thickness = (8.0f / 100.0f) * value;
 
981
        mplayerLoadFont();
 
982
        break;
 
983
 
 
984
    case MPLAYER_SET_FONT_BLUR:
 
985
        subtitle_font_radius = (8.0f / 100.0f) * value;
 
986
        mplayerLoadFont();
 
987
        break;
 
988
 
 
989
    case MPLAYER_SET_FONT_TEXTSCALE:
 
990
        text_font_scale_factor = value;
 
991
        mplayerLoadFont();
 
992
        break;
 
993
 
 
994
    case MPLAYER_SET_FONT_OSDSCALE:
 
995
        osd_font_scale_factor = value;
 
996
        mplayerLoadFont();
 
997
        break;
 
998
 
 
999
    case MPLAYER_SET_FONT_ENCODING:
 
1000
        nfree(subtitle_font_encoding);
 
1001
        subtitle_font_encoding = gstrdup((char *)data);
 
1002
        mplayerLoadFont();
 
1003
        break;
 
1004
 
 
1005
    case MPLAYER_SET_FONT_AUTOSCALE:
 
1006
        subtitle_autoscale = (int)value;
 
1007
        mplayerLoadFont();
 
1008
        break;
 
1009
#endif
 
1010
 
 
1011
#ifdef CONFIG_ICONV
 
1012
    case MPLAYER_SET_SUB_ENCODING:
 
1013
        nfree(sub_cp);
 
1014
        sub_cp = gstrdup((char *)data);
 
1015
        break;
 
1016
#endif
 
1017
 
 
1018
    case MPLAYER_SET_EXTRA_STEREO:
 
1019
        gtkAOExtraStereoMul = value;
 
1020
        if (guiInfo.afilter)
 
1021
            af_control_any_rev(guiInfo.afilter, AF_CONTROL_ES_MUL | AF_CONTROL_SET, &gtkAOExtraStereoMul);
 
1022
        break;
 
1023
 
 
1024
    case MPLAYER_SET_PANSCAN:
 
1025
    {
 
1026
        mp_cmd_t *mp_cmd;
 
1027
 
 
1028
        mp_cmd       = calloc(1, sizeof(*mp_cmd));
 
1029
        mp_cmd->id   = MP_CMD_PANSCAN;
 
1030
        mp_cmd->name = strdup("panscan");
 
1031
        mp_cmd->args[0].v.f = value;
 
1032
        mp_cmd->args[1].v.i = 1;
 
1033
        mp_input_queue_cmd(mp_cmd);
 
1034
    }
 
1035
    break;
 
1036
 
 
1037
    case MPLAYER_SET_AUTO_QUALITY:
 
1038
        auto_quality = (int)value;
 
1039
        break;
 
1040
 
 
1041
    // set equalizers
 
1042
 
 
1043
    case MPLAYER_SET_CONTRAST:
 
1044
        if (guiInfo.sh_video)
 
1045
            set_video_colors(guiInfo.sh_video, "contrast", (int)value);
 
1046
        break;
 
1047
 
 
1048
    case MPLAYER_SET_BRIGHTNESS:
 
1049
        if (guiInfo.sh_video)
 
1050
            set_video_colors(guiInfo.sh_video, "brightness", (int)value);
 
1051
        break;
 
1052
 
 
1053
    case MPLAYER_SET_HUE:
 
1054
        if (guiInfo.sh_video)
 
1055
            set_video_colors(guiInfo.sh_video, "hue", (int)value);
 
1056
        break;
 
1057
 
 
1058
    case MPLAYER_SET_SATURATION:
 
1059
        if (guiInfo.sh_video)
 
1060
            set_video_colors(guiInfo.sh_video, "saturation", (int)value);
 
1061
        break;
 
1062
 
 
1063
    case MPLAYER_SET_EQUALIZER:
 
1064
    {
 
1065
        af_control_ext_t tmp;
 
1066
 
 
1067
        if (eq) {
 
1068
            gtkEquChannels[eq->channel][eq->band] = eq->gain;
 
1069
            tmp.ch  = eq->channel;
 
1070
            tmp.arg = gtkEquChannels[eq->channel];
 
1071
 
 
1072
            if (guiInfo.afilter)
 
1073
                af_control_any_rev(guiInfo.afilter, AF_CONTROL_EQUALIZER_GAIN | AF_CONTROL_SET, &tmp);
 
1074
        } else {
 
1075
            unsigned int i;
 
1076
 
 
1077
            memset(gtkEquChannels, 0, sizeof(gtkEquChannels));
 
1078
 
 
1079
            if (guiInfo.afilter) {
 
1080
                for (i = 0; i < FF_ARRAY_ELEMS(gtkEquChannels); i++) {
 
1081
                    tmp.ch  = i;
 
1082
                    tmp.arg = gtkEquChannels[i];
 
1083
                    af_control_any_rev(guiInfo.afilter, AF_CONTROL_EQUALIZER_GAIN | AF_CONTROL_SET, &tmp);
 
1084
                }
 
1085
            }
 
1086
        }
 
1087
 
 
1088
        break;
 
1089
    }
 
1090
 
 
1091
    case MPLAYER_EXIT_GUI:
 
1092
        exit_player_with_rc((enum exit_reason)value, (enum exit_reason)value >= EXIT_ERROR);
 
1093
        break;
 
1094
    }
 
1095
}
 
1096
 
 
1097
void mplayerLoadFont(void)
 
1098
{
 
1099
#ifdef CONFIG_FREETYPE
 
1100
    load_font_ft(vo_image_width, vo_image_height, &vo_font, font_name, osd_font_scale_factor);
 
1101
#else
 
1102
    if (vo_font) {
 
1103
        int i;
 
1104
 
 
1105
        free(vo_font->name);
 
1106
        free(vo_font->fpath);
 
1107
 
 
1108
        for (i = 0; i < 16; i++) {
 
1109
            if (vo_font->pic_a[i]) {
 
1110
                free(vo_font->pic_a[i]->bmp);
 
1111
                free(vo_font->pic_a[i]->pal);
 
1112
            }
 
1113
        }
 
1114
 
 
1115
        for (i = 0; i < 16; i++) {
 
1116
            if (vo_font->pic_b[i]) {
 
1117
                free(vo_font->pic_b[i]->bmp);
 
1118
                free(vo_font->pic_b[i]->pal);
 
1119
            }
 
1120
        }
 
1121
 
 
1122
        free(vo_font);
 
1123
        vo_font = NULL;
 
1124
    }
 
1125
 
 
1126
    if (font_name) {
 
1127
        vo_font = read_font_desc(font_name, font_factor, 0);
 
1128
 
 
1129
        if (!vo_font)
 
1130
            gmp_msg(MSGT_GPLAYER, MSGL_ERR, MSGTR_CantLoadFont, font_name);
 
1131
    } else {
 
1132
        font_name = gstrdup(get_path("font/font.desc"));
 
1133
        vo_font   = read_font_desc(font_name, font_factor, 0);
 
1134
 
 
1135
        if (!vo_font) {
 
1136
            nfree(font_name);
 
1137
            font_name = gstrdup(MPLAYER_DATADIR "/font/font.desc");
 
1138
            vo_font   = read_font_desc(font_name, font_factor, 0);
 
1139
        }
 
1140
    }
 
1141
#endif
 
1142
}
 
1143
 
 
1144
void mplayerLoadSubtitle(const char *name)
 
1145
{
 
1146
    if (guiInfo.Playing == 0)
 
1147
        return;
 
1148
 
 
1149
    if (subdata) {
 
1150
        mp_msg(MSGT_GPLAYER, MSGL_INFO, MSGTR_DeletingSubtitles);
 
1151
 
 
1152
        sub_free(subdata);
 
1153
        subdata = NULL;
 
1154
        vo_sub  = NULL;
 
1155
 
 
1156
        if (vo_osd_list) {
 
1157
            int len;
 
1158
            mp_osd_obj_t *osd;
 
1159
 
 
1160
            osd = vo_osd_list;
 
1161
 
 
1162
            while (osd) {
 
1163
                if (osd->type == OSDTYPE_SUBTITLE)
 
1164
                    break;
 
1165
 
 
1166
                osd = osd->next;
 
1167
            }
 
1168
 
 
1169
            if (osd && (osd->flags & OSDFLAG_VISIBLE)) {
 
1170
                len = osd->stride * (osd->bbox.y2 - osd->bbox.y1);
 
1171
                memset(osd->bitmap_buffer, 0, len);
 
1172
                memset(osd->alpha_buffer, 0, len);
 
1173
            }
 
1174
        }
 
1175
    }
 
1176
 
 
1177
    if (name) {
 
1178
        mp_msg(MSGT_GPLAYER, MSGL_INFO, MSGTR_LoadingSubtitles, name);
 
1179
 
 
1180
        subdata = sub_read_file(name, (guiInfo.sh_video ? guiInfo.sh_video->fps : 0));
 
1181
 
 
1182
        if (!subdata)
 
1183
            gmp_msg(MSGT_GPLAYER, MSGL_ERR, MSGTR_CantLoadSub, name);
 
1184
 
 
1185
        sub_name    = (malloc(2 * sizeof(char *))); // when mplayer will be restarted
 
1186
        sub_name[0] = strdup(name);                 // sub_name[0] will be read
 
1187
        sub_name[1] = NULL;
 
1188
    }
 
1189
 
 
1190
    update_set_of_subtitles();
 
1191
}
 
1192
 
1470
1193
// NOTE TO MYSELF: This function is nonsense.
1471
1194
//                 MPlayer should pass messages to the GUI
1472
1195
//                 which must decide then which message has