1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
|
// main window
#include <stdlib.h>
#include <stdio.h>
#include <inttypes.h>
#include <sys/stat.h>
#include <unistd.h>
#include "app.h"
#include "skin/font.h"
#include "skin/skin.h"
#include "wm/ws.h"
#include "../config.h"
#include "../help_mp.h"
#include "../libvo/x11_common.h"
#include "../libvo/fastmemcpy.h"
#include "../stream/stream.h"
#include "../mixer.h"
#include "../libvo/sub.h"
#include "../mplayer.h"
#include "../libmpdemux/demuxer.h"
#include "../libmpdemux/stheader.h"
#include "../codec-cfg.h"
#include "../m_option.h"
#include "../m_property.h"
#define GUI_REDRAW_WAIT 375
#include "play.h"
#include "widgets.h"
extern mixer_t mixer; // mixer from mplayer.c
extern unsigned int GetTimerMS( void );
unsigned char * mplDrawBuffer = NULL;
int mplMainRender = 1;
int mplMainAutoPlay = 0;
int mplMiddleMenu = 0;
int mainVisible = 1;
int boxMoved = 0;
int sx = 0,sy = 0;
int i,pot = 0;
#include "common.h"
void mplMainDraw( void )
{
if ( appMPlayer.mainWindow.State == wsWindowClosed ) exit_player( MSGTR_Exit_quit );
if ( appMPlayer.mainWindow.Visible == wsWindowNotVisible ||
!mainVisible ) return;
// !appMPlayer.mainWindow.Mapped ) return;
if ( mplMainRender && appMPlayer.mainWindow.State == wsWindowExpose )
{
btnModify( evSetMoviePosition,guiIntfStruct.Position );
btnModify( evSetVolume,guiIntfStruct.Volume );
memcpy( mplDrawBuffer,appMPlayer.main.Bitmap.Image,appMPlayer.main.Bitmap.ImageSize );
Render( &appMPlayer.mainWindow,appMPlayer.Items,appMPlayer.NumberOfItems,mplDrawBuffer,appMPlayer.main.Bitmap.ImageSize );
mplMainRender=0;
}
wsPutImage( &appMPlayer.mainWindow );
// XFlush( wsDisplay );
}
extern void exit_player(const char* how);
extern int vcd_track;
static unsigned last_redraw_time = 0;
void mplEventHandling( int msg,float param )
{
int iparam = (int)param;
switch( msg )
{
// --- user events
case evExit:
exit_player( "Exit" );
break;
case evPlayNetwork:
gfree( (void **)&guiIntfStruct.Subtitlename );
gfree( (void **)&guiIntfStruct.AudioFile );
guiIntfStruct.StreamType=STREAMTYPE_STREAM;
goto play;
case evSetURL:
gtkShow( evPlayNetwork,NULL );
break;
case evSetAudio:
if ( !guiIntfStruct.demuxer || audio_id == iparam ) break;
audio_id=iparam;
goto play;
case evSetVideo:
if ( !guiIntfStruct.demuxer || video_id == iparam ) break;
video_id=iparam;
goto play;
case evSetSubtitle:
mp_property_do("sub",M_PROPERTY_SET,&iparam);
break;
#ifdef HAVE_VCD
case evSetVCDTrack:
guiIntfStruct.Track=iparam;
case evPlayVCD:
gtkSet( gtkClearStruct,0,(void *)guiALL );
guiIntfStruct.StreamType=STREAMTYPE_VCD;
goto play;
#endif
#ifdef USE_DVDREAD
case evPlayDVD:
guiIntfStruct.DVD.current_title=1;
guiIntfStruct.DVD.current_chapter=1;
guiIntfStruct.DVD.current_angle=1;
play_dvd_2:
gtkSet( gtkClearStruct,0,(void *)(guiALL - guiDVD) );
guiIntfStruct.StreamType=STREAMTYPE_DVD;
goto play;
#endif
case evPlay:
case evPlaySwitchToPause:
play:
if ( ( msg == evPlaySwitchToPause )&&( guiIntfStruct.Playing == 2 ) ) goto NoPause;
if ( gtkSet( gtkGetCurrPlItem,0,NULL ) &&( guiIntfStruct.StreamType == STREAMTYPE_FILE ) )
{
plItem * next = gtkSet( gtkGetCurrPlItem,0,NULL );
plLastPlayed=next;
mplSetFileName( next->path,next->name,STREAMTYPE_FILE );
}
switch ( guiIntfStruct.StreamType )
{
case STREAMTYPE_STREAM:
case STREAMTYPE_FILE:
gtkSet( gtkClearStruct,0,(void *)(guiALL - guiFilenames) );
break;
#ifdef HAVE_VCD
case STREAMTYPE_VCD:
gtkSet( gtkClearStruct,0,(void *)(guiALL - guiVCD - guiFilenames) );
if ( !cdrom_device ) cdrom_device=gstrdup( DEFAULT_CDROM_DEVICE );
mplSetFileName( NULL,cdrom_device,STREAMTYPE_VCD );
if ( guiIntfStruct.Playing != 2 )
{
if ( !guiIntfStruct.Track )
{
if ( guiIntfStruct.VCDTracks > 1 ) guiIntfStruct.Track=2;
else guiIntfStruct.Track=1;
}
guiIntfStruct.DiskChanged=1;
}
break;
#endif
#ifdef USE_DVDREAD
case STREAMTYPE_DVD:
gtkSet( gtkClearStruct,0,(void *)(guiALL - guiDVD - guiFilenames) );
if ( !dvd_device ) dvd_device=gstrdup( DEFAULT_DVD_DEVICE );
mplSetFileName( NULL,dvd_device,STREAMTYPE_DVD );
if ( guiIntfStruct.Playing != 2 )
{
guiIntfStruct.Title=guiIntfStruct.DVD.current_title;
guiIntfStruct.Chapter=guiIntfStruct.DVD.current_chapter;
guiIntfStruct.Angle=guiIntfStruct.DVD.current_angle;
guiIntfStruct.DiskChanged=1;
}
break;
#endif
}
guiIntfStruct.NewPlay=1;
mplPlay();
break;
#ifdef USE_DVDREAD
case evSetDVDSubtitle:
dvdsub_id=iparam;
goto play_dvd_2;
break;
case evSetDVDAudio:
audio_id=iparam;
goto play_dvd_2;
break;
case evSetDVDChapter:
guiIntfStruct.DVD.current_chapter=iparam;
goto play_dvd_2;
break;
case evSetDVDTitle:
guiIntfStruct.DVD.current_title=iparam;
guiIntfStruct.DVD.current_chapter=1;
guiIntfStruct.DVD.current_angle=1;
goto play_dvd_2;
break;
#endif
case evPause:
case evPauseSwitchToPlay:
NoPause:
mplPause();
break;
case evStop:
guiIntfStruct.Playing=guiSetStop;
mplState();
guiIntfStruct.NoWindow=False;
break;
case evLoadPlay:
mplMainAutoPlay=1;
// guiIntfStruct.StreamType=STREAMTYPE_FILE;
case evLoad:
gtkSet( gtkDelPl,0,NULL );
gtkShow( evLoad,NULL );
break;
case evLoadSubtitle: gtkShow( evLoadSubtitle,NULL ); break;
case evDropSubtitle:
gfree( (void **)&guiIntfStruct.Subtitlename );
guiLoadSubtitle( NULL );
break;
case evLoadAudioFile: gtkShow( evLoadAudioFile,NULL ); break;
case evPrev: mplPrev(); break;
case evNext: mplNext(); break;
case evPlayList: gtkShow( evPlayList,NULL ); break;
case evSkinBrowser: gtkShow( evSkinBrowser,skinName ); break;
case evAbout: gtkShow( evAbout,NULL ); break;
case evPreferences: gtkShow( evPreferences,NULL ); break;
case evEqualizer: gtkShow( evEqualizer,NULL ); break;
case evForward10min: mplRelSeek( 600 ); break;
case evBackward10min: mplRelSeek( -600 );break;
case evForward1min: mplRelSeek( 60 ); break;
case evBackward1min: mplRelSeek( -60 ); break;
case evForward10sec: mplRelSeek( 10 ); break;
case evBackward10sec: mplRelSeek( -10 ); break;
case evSetMoviePosition: mplAbsSeek( param ); break;
case evIncVolume: vo_x11_putkey( wsGrayMul ); break;
case evDecVolume: vo_x11_putkey( wsGrayDiv ); break;
case evMute: mixer_mute( &mixer ); break;
case evSetVolume:
guiIntfStruct.Volume=param;
goto set_volume;
case evSetBalance:
guiIntfStruct.Balance=param;
set_volume:
{
float l = guiIntfStruct.Volume * ( ( 100.0 - guiIntfStruct.Balance ) / 50.0 );
float r = guiIntfStruct.Volume * ( ( guiIntfStruct.Balance ) / 50.0 );
if ( l > guiIntfStruct.Volume ) l=guiIntfStruct.Volume;
if ( r > guiIntfStruct.Volume ) r=guiIntfStruct.Volume;
// printf( "!!! v: %.2f b: %.2f -> %.2f x %.2f\n",guiIntfStruct.Volume,guiIntfStruct.Balance,l,r );
mixer_setvolume( &mixer,l,r );
}
#ifdef USE_OSD
if ( osd_level )
{
osd_visible=(GetTimerMS() + 1000) | 1;
vo_osd_progbar_type=OSD_VOLUME;
vo_osd_progbar_value=( ( guiIntfStruct.Volume ) * 256.0 ) / 100.0;
vo_osd_changed( OSDTYPE_PROGBAR );
}
#endif
break;
case evIconify:
switch ( iparam )
{
case 0: wsIconify( appMPlayer.mainWindow ); break;
case 1: wsIconify( appMPlayer.subWindow ); break;
}
break;
case evHalfSize:
btnSet( evFullScreen,btnReleased );
if ( guiIntfStruct.Playing )
{
if ( appMPlayer.subWindow.isFullScreen )
{
mplFullScreen();
}
wsResizeWindow( &appMPlayer.subWindow, guiIntfStruct.MovieWidth / 2, guiIntfStruct.MovieHeight / 2 );
wsMoveWindow( &appMPlayer.subWindow, 0,
( wsMaxX - guiIntfStruct.MovieWidth/2 )/2 + wsOrgX,
( wsMaxY - guiIntfStruct.MovieHeight/2 )/2 + wsOrgY );
}
break;
case evDoubleSize:
btnSet( evFullScreen,btnReleased );
if ( guiIntfStruct.Playing )
{
if ( appMPlayer.subWindow.isFullScreen )
{
mplFullScreen();
}
wsResizeWindow( &appMPlayer.subWindow, guiIntfStruct.MovieWidth * 2, guiIntfStruct.MovieHeight * 2 );
wsMoveWindow( &appMPlayer.subWindow, 0,
( wsMaxX - guiIntfStruct.MovieWidth*2 )/2 + wsOrgX,
( wsMaxY - guiIntfStruct.MovieHeight*2 )/2 + wsOrgY );
}
break;
case evNormalSize:
btnSet( evFullScreen,btnReleased );
if ( guiIntfStruct.Playing )
{
if ( appMPlayer.subWindow.isFullScreen )
{
mplFullScreen();
}
wsResizeWindow( &appMPlayer.subWindow, guiIntfStruct.MovieWidth, guiIntfStruct.MovieHeight );
wsMoveWindow( &appMPlayer.subWindow, 0,
( wsMaxX - guiIntfStruct.MovieWidth )/2 + wsOrgX,
( wsMaxY - guiIntfStruct.MovieHeight )/2 + wsOrgY );
break;
} else if ( !appMPlayer.subWindow.isFullScreen ) break;
case evFullScreen:
if ( !guiIntfStruct.Playing && !gtkShowVideoWindow ) break;
mplFullScreen();
if ( appMPlayer.subWindow.isFullScreen ) btnSet( evFullScreen,btnPressed );
else btnSet( evFullScreen,btnReleased );
break;
case evSetAspect:
switch ( iparam )
{
case 2: movie_aspect=16.0f / 9.0f; break;
case 3: movie_aspect=4.0f / 3.0f; break;
case 4: movie_aspect=2.35; break;
case 1:
default: movie_aspect=-1;
}
wsClearWindow( appMPlayer.subWindow );
#ifdef USE_DVDREAD
if ( guiIntfStruct.StreamType == STREAMTYPE_DVD || guiIntfStruct.StreamType == STREAMTYPE_VCD ) goto play_dvd_2;
else
#endif
guiIntfStruct.NewPlay=1;
break;
// --- timer events
case evRedraw:
{
unsigned now = GetTimerMS();
extern int mplPBFade;
if ((now > last_redraw_time) &&
(now < last_redraw_time + GUI_REDRAW_WAIT) &&
!mplPBFade)
break;
last_redraw_time = now;
}
mplMainRender=1;
wsPostRedisplay( &appMPlayer.mainWindow );
wsPostRedisplay( &appMPlayer.barWindow );
break;
// --- system events
#ifdef MP_DEBUG
case evNone:
mp_msg( MSGT_GPLAYER,MSGL_STATUS,"[mw] event none received.\n" );
break;
default:
mp_msg( MSGT_GPLAYER,MSGL_STATUS,"[mw] unknown event received ( %d,%.2f ).\n",msg,param );
break;
#endif
}
}
#define itPLMButton (itNULL - 1)
#define itPRMButton (itNULL - 2)
void mplMainMouseHandle( int Button,int X,int Y,int RX,int RY )
{
static int itemtype = 0;
int i;
wItem * item = NULL;
float value = 0.0f;
static int SelectedItem = -1;
int currentselected = -1;
for ( i=0;i < appMPlayer.NumberOfItems + 1;i++ )
if ( ( appMPlayer.Items[i].pressed != btnDisabled )&&
( wgIsRect( X,Y,appMPlayer.Items[i].x,appMPlayer.Items[i].y,appMPlayer.Items[i].x+appMPlayer.Items[i].width,appMPlayer.Items[i].y+appMPlayer.Items[i].height ) ) )
{ currentselected=i; break; }
switch ( Button )
{
case wsPMMouseButton:
gtkShow( evHidePopUpMenu,NULL );
mplShowMenu( RX,RY );
itemtype=itPRMButton;
break;
case wsRMMouseButton:
mplHideMenu( RX,RY,0 );
break;
case wsPLMouseButton:
gtkShow( evHidePopUpMenu,NULL );
sx=X; sy=Y; boxMoved=1; itemtype=itPLMButton;
SelectedItem=currentselected;
if ( SelectedItem == -1 ) break;
boxMoved=0;
item=&appMPlayer.Items[SelectedItem];
itemtype=item->type;
item->pressed=btnPressed;
switch( item->type )
{
case itButton:
if ( ( SelectedItem > -1 ) &&
( ( ( item->msg == evPlaySwitchToPause && item->msg == evPauseSwitchToPlay ) ) ||
( ( item->msg == evPauseSwitchToPlay && item->msg == evPlaySwitchToPause ) ) ) )
{ item->pressed=btnDisabled; }
break;
}
break;
case wsRLMouseButton:
boxMoved=0;
item=&appMPlayer.Items[SelectedItem];
item->pressed=btnReleased;
SelectedItem=-1;
if ( currentselected == - 1 ) { itemtype=0; break; }
value=0;
switch( itemtype )
{
case itPotmeter:
case itHPotmeter:
btnModify( item->msg,(float)( X - item->x ) / item->width * 100.0f );
mplEventHandling( item->msg,item->value );
value=item->value;
break;
case itVPotmeter:
btnModify( item->msg, ( 1. - (float)( Y - item->y ) / item->height) * 100.0f );
mplEventHandling( item->msg,item->value );
value=item->value;
break;
}
mplEventHandling( item->msg,value );
itemtype=0;
break;
case wsRRMouseButton:
gtkShow( evShowPopUpMenu,NULL );
break;
// --- rolled mouse ... de szar :)))
case wsP5MouseButton: value=-2.5f; goto rollerhandled;
case wsP4MouseButton: value= 2.5f;
rollerhandled:
item=&appMPlayer.Items[currentselected];
if ( ( item->type == itHPotmeter )||( item->type == itVPotmeter )||( item->type == itPotmeter ) )
{
item->value+=value;
btnModify( item->msg,item->value );
mplEventHandling( item->msg,item->value );
}
break;
// --- moving
case wsMoveMouse:
item=&appMPlayer.Items[SelectedItem];
switch ( itemtype )
{
case itPLMButton:
wsMoveWindow( &appMPlayer.mainWindow,False,RX - abs( sx ),RY - abs( sy ) );
mplMainRender=0;
break;
case itPRMButton:
mplMenuMouseHandle( X,Y,RX,RY );
break;
case itPotmeter:
item->value=(float)( X - item->x ) / item->width * 100.0f;
goto potihandled;
case itVPotmeter:
item->value=(1. - (float)( Y - item->y ) / item->height) * 100.0f;
goto potihandled;
case itHPotmeter:
item->value=(float)( X - item->x ) / item->width * 100.0f;
potihandled:
if ( item->value > 100.0f ) item->value=100.0f;
if ( item->value < 0.0f ) item->value=0.0f;
mplEventHandling( item->msg,item->value );
break;
}
break;
}
}
int keyPressed = 0;
void mplMainKeyHandle( int KeyCode,int Type,int Key )
{
int msg = evNone;
if ( Type != wsKeyPressed ) return;
if ( !Key )
{
switch ( KeyCode )
{
case wsXFMMPrev: msg=evPrev; break;
case wsXFMMStop: msg=evStop; break;
case wsXFMMPlay: msg=evPlaySwitchToPause; break;
case wsXFMMNext: msg=evNext; break;
case wsXFMMVolUp: msg=evIncVolume; break;
case wsXFMMVolDown: msg=evDecVolume; break;
case wsXFMMMute: msg=evMute; break;
}
}
else
{
switch ( Key )
{
case wsEnter: msg=evPlay; break;
case wsXF86LowerVolume: msg=evDecVolume; break;
case wsXF86RaiseVolume: msg=evIncVolume; break;
case wsXF86Mute: msg=evMute; break;
case wsXF86Play: msg=evPlaySwitchToPause; break;
case wsXF86Stop: msg=evStop; break;
case wsXF86Prev: msg=evPrev; break;
case wsXF86Next: msg=evNext; break;
case wsXF86Media: msg=evLoad; break;
case wsEscape:
if ( appMPlayer.subWindow.isFullScreen )
{
if ( guiIntfStruct.event_struct ) ((XEvent *)guiIntfStruct.event_struct)->type=None;
mplEventHandling( evNormalSize,0 );
return;
}
default: vo_x11_putkey( Key ); return;
}
}
if ( msg != evNone ) mplEventHandling( msg,0 );
}
/* this will be used to handle Drag&Drop files */
void mplDandDHandler(int num,char** files)
{
struct stat buf;
int f = 0;
char* subtitles = NULL;
char* filename = NULL;
if (num <= 0)
return;
/* now fill it with new items */
for(f=0; f < num; f++){
char* str = strdup( files[f] );
plItem* item;
#ifdef USE_ICONV
if ( strchr( str,'%' ) )
{
char * tmp=gconvert_uri_to_filename( str );
free( str ); str=tmp;
}
#endif
if(stat(str,&buf) == 0 && S_ISDIR(buf.st_mode) == 0) {
/* this is not a directory so try to play it */
mp_msg( MSGT_GPLAYER,MSGL_V,"Received D&D %s\n",str );
/* check if it is a subtitle file */
{
char* ext = strrchr(str,'.');
if (ext) {
static char supported[] = "utf/sub/srt/smi/rt//txt/ssa/aqt/";
char* type;
int len;
if((len=strlen(++ext)) && (type=strstr(supported,ext)) &&\
(type-supported)%4 == 0 && *(type+len) == '/'){
/* handle subtitle file */
gfree((void**)&subtitles);
subtitles = str;
continue;
}
}
}
/* clear playlist */
if (filename == NULL) {
filename = files[f];
gtkSet(gtkDelPl,0,NULL);
}
item = calloc(1,sizeof(plItem));
/* FIXME: decompose file name ? */
/* yes -- Pontscho */
if ( strrchr( str,'/' ) ) {
char * s = strrchr( str,'/' ); *s=0; s++;
item->name = gstrdup( s );
item->path = gstrdup( str );
} else {
item->name = strdup(str);
item->path = strdup("");
}
gtkSet(gtkAddPlItem,0,(void*)item);
} else {
mp_msg( MSGT_GPLAYER,MSGL_WARN,MSGTR_NotAFile,str );
}
free( str );
}
if (filename) {
mplSetFileName( NULL,filename,STREAMTYPE_FILE );
if ( guiIntfStruct.Playing == 1 ) mplEventHandling( evStop,0 );
mplEventHandling( evPlay,0 );
}
if (subtitles) {
gfree((void**)&guiIntfStruct.Subtitlename);
guiIntfStruct.Subtitlename = subtitles;
guiLoadSubtitle(guiIntfStruct.Subtitlename);
}
}
|