~ubuntu-dev/mplayer/ubuntu-feisty

« back to all changes in this revision

Viewing changes to Gui/mplayer/play.c

  • Committer: Reinhard Tartler
  • Date: 2006-07-08 08:45:33 UTC
  • Revision ID: siretart@tauware.de-20060708084533-dbc155bde7122e78
imported mplayer_0.99+1.0pre7try2+cvs20060117

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
#include <inttypes.h>
 
3
#include <stdlib.h>
 
4
#include <stdio.h>
 
5
#include <string.h>
 
6
 
 
7
#include <unistd.h>
 
8
#include <signal.h>
 
9
 
 
10
#include "wm/ws.h"
 
11
#include "wm/wsxdnd.h"
 
12
#include "../config.h"
 
13
#include "../help_mp.h"
 
14
#include "../mplayer.h"
 
15
#include "../libvo/x11_common.h"
 
16
#include "../libvo/video_out.h"
 
17
#include "../input/input.h"
 
18
 
 
19
#include "app.h"
 
20
 
 
21
#include "wm/wskeys.h"
 
22
#include "interface.h"
 
23
 
 
24
#include "widgets.h"
 
25
#include "./mplayer.h"
 
26
#include "play.h"
 
27
 
 
28
#include "skin/skin.h"
 
29
#include "skin/font.h"
 
30
 
 
31
#include "libmpdemux/stream.h"
 
32
 
 
33
extern float rel_seek_secs;
 
34
extern int abs_seek_pos;
 
35
 
 
36
int mplGotoTheNext = 1;
 
37
 
 
38
void mplFullScreen( void )
 
39
{
 
40
 if ( guiIntfStruct.NoWindow && guiIntfStruct.Playing ) return;
 
41
 
 
42
  if ( ( guiIntfStruct.Playing )&&( appMPlayer.subWindow.isFullScreen ) )
 
43
   { 
 
44
    appMPlayer.subWindow.OldWidth=guiIntfStruct.MovieWidth; appMPlayer.subWindow.OldHeight=guiIntfStruct.MovieHeight; 
 
45
    switch ( appMPlayer.sub.x )
 
46
     {
 
47
      case -1: appMPlayer.subWindow.OldX=( wsMaxX / 2 ) - ( appMPlayer.subWindow.OldWidth / 2 ) + wsOrgX; break;
 
48
      case -2: appMPlayer.subWindow.OldX=wsMaxX - appMPlayer.subWindow.OldWidth + wsOrgX; break;
 
49
      default: appMPlayer.subWindow.OldX=appMPlayer.sub.x; break;
 
50
     }
 
51
    switch ( appMPlayer.sub.y )
 
52
     {
 
53
      case -1: appMPlayer.subWindow.OldY=( wsMaxY / 2 ) - ( appMPlayer.subWindow.OldHeight / 2 ) + wsOrgY; break;
 
54
      case -2: appMPlayer.subWindow.OldY=wsMaxY - appMPlayer.subWindow.OldHeight + wsOrgY; break;
 
55
      default: appMPlayer.subWindow.OldY=appMPlayer.sub.y; break;
 
56
     }
 
57
   }
 
58
  if ( guiIntfStruct.Playing || gtkShowVideoWindow ) wsFullScreen( &appMPlayer.subWindow );
 
59
  fullscreen=vo_fs=appMPlayer.subWindow.isFullScreen;
 
60
  wsSetLayer( wsDisplay,appMPlayer.mainWindow.WindowID,appMPlayer.subWindow.isFullScreen );
 
61
  if ( appMPlayer.menuIsPresent ) wsSetLayer( wsDisplay,appMPlayer.menuWindow.WindowID,appMPlayer.subWindow.isFullScreen );
 
62
 
 
63
 if ( guiIntfStruct.Playing ) wsSetBackgroundRGB( &appMPlayer.subWindow,0,0,0 );
 
64
  else wsSetBackgroundRGB( &appMPlayer.subWindow,appMPlayer.sub.R,appMPlayer.sub.G,appMPlayer.sub.B );
 
65
}
 
66
 
 
67
extern int mplSubRender;
 
68
 
 
69
void mplEnd( void )
 
70
{
 
71
 plItem * next;
 
72
 
 
73
 if ( !mplGotoTheNext && guiIntfStruct.Playing) { mplGotoTheNext=1; return; }
 
74
 
 
75
 if ( guiIntfStruct.Playing && (next=gtkSet( gtkGetNextPlItem,0,NULL )) && plLastPlayed != next )
 
76
  {
 
77
   plLastPlayed=next;
 
78
   guiSetDF( guiIntfStruct.Filename,next->path,next->name );
 
79
   guiIntfStruct.StreamType=STREAMTYPE_FILE;
 
80
   guiIntfStruct.FilenameChanged=guiIntfStruct.NewPlay=1;
 
81
   gfree( (void **)&guiIntfStruct.AudioFile );
 
82
   gfree( (void **)&guiIntfStruct.Subtitlename );
 
83
  } 
 
84
  else
 
85
    {
 
86
     if ( guiIntfStruct.FilenameChanged || guiIntfStruct.NewPlay ) return;
 
87
 
 
88
     guiIntfStruct.TimeSec=0;
 
89
     guiIntfStruct.Position=0;
 
90
     guiIntfStruct.AudioType=0;
 
91
     guiIntfStruct.NoWindow=False;
 
92
 
 
93
#ifdef USE_DVDREAD
 
94
     guiIntfStruct.DVD.current_title=1;
 
95
     guiIntfStruct.DVD.current_chapter=1;
 
96
     guiIntfStruct.DVD.current_angle=1;
 
97
#endif
 
98
 
 
99
     if ( !appMPlayer.subWindow.isFullScreen && gtkShowVideoWindow)
 
100
      {
 
101
       wsResizeWindow( &appMPlayer.subWindow,appMPlayer.sub.width,appMPlayer.sub.height );
 
102
       wsMoveWindow( &appMPlayer.subWindow,True,appMPlayer.sub.x,appMPlayer.sub.y );
 
103
      }
 
104
      else wsVisibleWindow( &appMPlayer.subWindow,wsHideWindow );
 
105
     guiGetEvent( guiCEvent,guiSetStop );
 
106
     mplSubRender=1;
 
107
     wsSetBackgroundRGB( &appMPlayer.subWindow,appMPlayer.sub.R,appMPlayer.sub.G,appMPlayer.sub.B );
 
108
     wsClearWindow( appMPlayer.subWindow );
 
109
     wsPostRedisplay( &appMPlayer.subWindow );
 
110
    }
 
111
}
 
112
 
 
113
void mplPlay( void )
 
114
{
 
115
 if ( ( !guiIntfStruct.Filename )||
 
116
      ( guiIntfStruct.Filename[0] == 0 )||
 
117
      ( guiIntfStruct.Playing == 1 ) ) return;
 
118
 if ( guiIntfStruct.Playing == 2 ) { mplPause(); return; }
 
119
 guiGetEvent( guiCEvent,(void *)guiSetPlay );
 
120
 mplSubRender=0;
 
121
 wsSetBackgroundRGB( &appMPlayer.subWindow,0,0,0 );
 
122
 wsClearWindow( appMPlayer.subWindow );
 
123
}
 
124
 
 
125
void mplPause( void )
 
126
{
 
127
 if ( !guiIntfStruct.Playing ) return;
 
128
 if ( guiIntfStruct.Playing == 1 )
 
129
  {
 
130
   mp_cmd_t * cmd = (mp_cmd_t *)calloc( 1,sizeof( *cmd ) );
 
131
   cmd->id=MP_CMD_PAUSE;
 
132
   cmd->name=strdup("pause");
 
133
   mp_input_queue_cmd(cmd);
 
134
  } else guiIntfStruct.Playing=1;
 
135
}
 
136
 
 
137
void mplState( void )
 
138
{
 
139
 if ( ( guiIntfStruct.Playing == 0 )||( guiIntfStruct.Playing == 2 ) )
 
140
  {
 
141
   btnModify( evPlaySwitchToPause,btnReleased );
 
142
   btnModify( evPauseSwitchToPlay,btnDisabled );
 
143
  }
 
144
  else
 
145
   {
 
146
    btnModify( evPlaySwitchToPause,btnDisabled );
 
147
    btnModify( evPauseSwitchToPlay,btnReleased );
 
148
   }
 
149
}
 
150
 
 
151
float mplGetPosition( void )
 
152
{ // return 0.0 ... 100.0
 
153
 return guiIntfStruct.Position;
 
154
}
 
155
 
 
156
void mplRelSeek( float s )
 
157
{ // -+s
 
158
 rel_seek_secs=s; abs_seek_pos=0;
 
159
}
 
160
 
 
161
void mplAbsSeek( float s )
 
162
{ // 0.0 ... 100.0
 
163
 if ( guiIntfStruct.StreamType == STREAMTYPE_STREAM ) return;
 
164
 rel_seek_secs=0.01*s; abs_seek_pos=3;
 
165
}
 
166
 
 
167
listItems tmpList;
 
168
 
 
169
void ChangeSkin( char * name )
 
170
{
 
171
 int ret;
 
172
 int prev = appMPlayer.menuIsPresent;
 
173
 int bprev = appMPlayer.barIsPresent;
 
174
 
 
175
 mainVisible=0;
 
176
 
 
177
 appInitStruct( &tmpList );
 
178
 skinAppMPlayer=&tmpList;
 
179
 fntFreeFont();
 
180
 ret=skinRead( name );
 
181
 
 
182
 appInitStruct( &tmpList );
 
183
 skinAppMPlayer=&appMPlayer;
 
184
 appInitStruct( &appMPlayer );
 
185
 if ( ret ) name=skinName;
 
186
 if ( skinRead( name ) )
 
187
  {
 
188
   mainVisible=1;
 
189
   return;
 
190
  }
 
191
 
 
192
// --- reload menu window
 
193
 
 
194
 if ( prev && appMPlayer.menuIsPresent )
 
195
  {
 
196
   if ( mplMenuDrawBuffer ) free( mplMenuDrawBuffer );
 
197
   if ( ( mplMenuDrawBuffer = (unsigned char *)calloc( 1,appMPlayer.menuBase.Bitmap.ImageSize ) ) == NULL )
 
198
    { mp_msg( MSGT_GPLAYER,MSGL_STATUS,MSGTR_NEMDB ); return; }
 
199
   wsResizeWindow( &appMPlayer.menuWindow,appMPlayer.menuBase.width,appMPlayer.menuBase.height );
 
200
   wsResizeImage( &appMPlayer.menuWindow,appMPlayer.menuBase.width,appMPlayer.menuBase.height );
 
201
   wsSetShape( &appMPlayer.menuWindow,appMPlayer.menuBase.Mask.Image );
 
202
   wsVisibleWindow( &appMPlayer.menuWindow,wsHideWindow );
 
203
  } else { mplMenuInit(); }
 
204
 
 
205
// --- reload sub window
 
206
 if ( appMPlayer.sub.Bitmap.Image ) wsResizeImage( &appMPlayer.subWindow,appMPlayer.sub.Bitmap.Width,appMPlayer.sub.Bitmap.Height );
 
207
 if ( ( !appMPlayer.subWindow.isFullScreen )&&( !guiIntfStruct.Playing ) )
 
208
  {
 
209
   wsResizeWindow( &appMPlayer.subWindow,appMPlayer.sub.width,appMPlayer.sub.height );
 
210
   wsMoveWindow( &appMPlayer.subWindow,True,appMPlayer.sub.x,appMPlayer.sub.y );
 
211
  }
 
212
 if ( appMPlayer.sub.Bitmap.Image ) wsConvert( &appMPlayer.subWindow,appMPlayer.sub.Bitmap.Image,appMPlayer.sub.Bitmap.ImageSize );
 
213
 if ( !guiIntfStruct.Playing )
 
214
  {
 
215
   mplSubRender=1;
 
216
   wsSetBackgroundRGB( &appMPlayer.subWindow,appMPlayer.sub.R,appMPlayer.sub.G,appMPlayer.sub.B );
 
217
   wsClearWindow( appMPlayer.subWindow );
 
218
   wsPostRedisplay( &appMPlayer.subWindow );
 
219
  }
 
220
 
 
221
// --- reload play bar
 
222
 if ( bprev ) wsDestroyWindow( &appMPlayer.barWindow );
 
223
 mplPBInit();
 
224
 
 
225
// --- reload main window
 
226
 if ( mplDrawBuffer ) free( mplDrawBuffer );
 
227
 if ( ( mplDrawBuffer = (unsigned char *)calloc( 1,appMPlayer.main.Bitmap.ImageSize ) ) == NULL )
 
228
  { mp_msg( MSGT_GPLAYER,MSGL_STATUS,MSGTR_NEMDB ); return; }
 
229
 
 
230
 wsDestroyWindow( &appMPlayer.mainWindow );
 
231
 
 
232
 wsCreateWindow( &appMPlayer.mainWindow,
 
233
   appMPlayer.main.x,appMPlayer.main.y,appMPlayer.main.width,appMPlayer.main.height,
 
234
   wsNoBorder,wsShowMouseCursor|wsHandleMouseButton|wsHandleMouseMove,wsShowFrame|wsMaxSize|wsHideWindow,"MPlayer" );
 
235
 wsCreateImage( &appMPlayer.mainWindow,appMPlayer.main.Bitmap.Width,appMPlayer.main.Bitmap.Height );
 
236
 wsSetShape( &appMPlayer.mainWindow,appMPlayer.main.Mask.Image );
 
237
 wsSetIcon( wsDisplay,appMPlayer.mainWindow.WindowID,guiIcon,guiIconMask );
 
238
 
 
239
 appMPlayer.mainWindow.ReDraw=(void *)mplMainDraw;
 
240
 appMPlayer.mainWindow.MouseHandler=mplMainMouseHandle;
 
241
 appMPlayer.mainWindow.KeyHandler=mplMainKeyHandle;
 
242
 appMPlayer.mainWindow.DandDHandler=mplDandDHandler;
 
243
 
 
244
 wsXDNDMakeAwareness( &appMPlayer.mainWindow );
 
245
 if ( !appMPlayer.mainDecoration ) wsWindowDecoration( &appMPlayer.mainWindow,0 );
 
246
 wsVisibleWindow( &appMPlayer.mainWindow,wsShowWindow );
 
247
 mainVisible=1;
 
248
// ---
 
249
 
 
250
 btnModify( evSetVolume,guiIntfStruct.Volume );
 
251
 btnModify( evSetBalance,guiIntfStruct.Balance );
 
252
 btnModify( evSetMoviePosition,guiIntfStruct.Position );
 
253
 btnModify( evFullScreen,!appMPlayer.subWindow.isFullScreen );
 
254
 
 
255
 wsSetLayer( wsDisplay,appMPlayer.mainWindow.WindowID,appMPlayer.subWindow.isFullScreen );
 
256
 wsSetLayer( wsDisplay,appMPlayer.menuWindow.WindowID,appMPlayer.subWindow.isFullScreen );
 
257
 
 
258
}
 
259
 
 
260
void mplSetFileName( char * dir,char * name,int type )
 
261
{
 
262
 if ( !name ) return;
 
263
 
 
264
 if ( !dir ) guiSetFilename( guiIntfStruct.Filename,name )
 
265
  else guiSetDF( guiIntfStruct.Filename,dir,name );
 
266
 
 
267
// filename=guiIntfStruct.Filename;
 
268
 guiIntfStruct.StreamType=type;
 
269
 gfree( (void **)&guiIntfStruct.AudioFile );
 
270
 gfree( (void **)&guiIntfStruct.Subtitlename );
 
271
}
 
272
 
 
273
void mplCurr( void )
 
274
{
 
275
 plItem * curr;
 
276
 int      stop = 0;
 
277
 
 
278
 if ( guiIntfStruct.Playing == 2 ) return;
 
279
 switch ( guiIntfStruct.StreamType )
 
280
  {
 
281
#ifdef USE_DVDREAD
 
282
   case STREAMTYPE_DVD:
 
283
        break;
 
284
#endif
 
285
#ifdef HAVE_VCD
 
286
   case STREAMTYPE_VCD:
 
287
        break;
 
288
#endif
 
289
   default: 
 
290
        if ( (curr=gtkSet( gtkGetCurrPlItem,0,NULL)) )
 
291
         {
 
292
          mplSetFileName( curr->path,curr->name,STREAMTYPE_FILE );
 
293
          mplGotoTheNext=0;
 
294
          break;
 
295
         }
 
296
        return;
 
297
  }
 
298
 if ( stop ) mplEventHandling( evStop,0 );
 
299
 if ( guiIntfStruct.Playing == 1 ) mplEventHandling( evPlay,0 );
 
300
}
 
301
 
 
302
 
 
303
void mplPrev( void )
 
304
{
 
305
 plItem * prev;
 
306
 int      stop = 0;
 
307
 
 
308
 if ( guiIntfStruct.Playing == 2 ) return;
 
309
 switch ( guiIntfStruct.StreamType )
 
310
  {
 
311
#ifdef USE_DVDREAD
 
312
   case STREAMTYPE_DVD:
 
313
        if ( --guiIntfStruct.DVD.current_chapter == 0 )
 
314
         {
 
315
          guiIntfStruct.DVD.current_chapter=1;
 
316
          if ( --guiIntfStruct.DVD.current_title <= 0 ) { guiIntfStruct.DVD.current_title=1; stop=1; }
 
317
         }
 
318
        guiIntfStruct.Track=guiIntfStruct.DVD.current_title;
 
319
        break;
 
320
#endif
 
321
#ifdef HAVE_VCD
 
322
   case STREAMTYPE_VCD:
 
323
        if ( --guiIntfStruct.Track == 0 ) { guiIntfStruct.Track=1; stop=1; }
 
324
        break;
 
325
#endif
 
326
   default: 
 
327
        if ( (prev=gtkSet( gtkGetPrevPlItem,0,NULL)) )
 
328
         {
 
329
          mplSetFileName( prev->path,prev->name,STREAMTYPE_FILE );
 
330
          mplGotoTheNext=0;
 
331
          break;
 
332
         }
 
333
        return;
 
334
  }
 
335
 if ( stop ) mplEventHandling( evStop,0 );
 
336
 if ( guiIntfStruct.Playing == 1 ) mplEventHandling( evPlay,0 );
 
337
}
 
338
 
 
339
void mplNext( void )
 
340
{
 
341
 int      stop = 0;
 
342
 plItem * next;
 
343
 
 
344
 if ( guiIntfStruct.Playing == 2 ) return;
 
345
 switch ( guiIntfStruct.StreamType )
 
346
  {
 
347
#ifdef USE_DVDREAD
 
348
   case STREAMTYPE_DVD:
 
349
        if ( guiIntfStruct.DVD.current_chapter++ == guiIntfStruct.DVD.chapters )
 
350
         {
 
351
          guiIntfStruct.DVD.current_chapter=1;
 
352
          if ( ++guiIntfStruct.DVD.current_title > guiIntfStruct.DVD.titles ) { guiIntfStruct.DVD.current_title=guiIntfStruct.DVD.titles; stop=1; }
 
353
         }
 
354
        guiIntfStruct.Track=guiIntfStruct.DVD.current_title;
 
355
        break;
 
356
#endif
 
357
#ifdef HAVE_VCD
 
358
   case STREAMTYPE_VCD:
 
359
        if ( ++guiIntfStruct.Track > guiIntfStruct.VCDTracks ) { guiIntfStruct.Track=guiIntfStruct.VCDTracks; stop=1; }
 
360
        break;
 
361
#endif
 
362
   default:
 
363
        if ( (next=gtkSet( gtkGetNextPlItem,0,NULL)) ) 
 
364
         { 
 
365
          mplSetFileName( next->path,next->name,STREAMTYPE_FILE );
 
366
          mplGotoTheNext=0;
 
367
          break;
 
368
         }
 
369
        return;
 
370
  }
 
371
 if ( stop ) mplEventHandling( evStop,0 );
 
372
 if ( guiIntfStruct.Playing == 1 ) mplEventHandling( evPlay,0 );
 
373
}