changeset 723:c3e0bdb64027

add gui support
author pontscho
date Tue, 08 May 2001 12:17:03 +0000
parents b570318ac2f4
children e04e6f585b94
files Makefile cfg-mplayer.h configure libvo/vo_xmga.c libvo/vo_xv.c libvo/x11_common.c libvo/x11_common.h mplayer.c
diffstat 8 files changed, 427 insertions(+), 128 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Tue May 08 01:58:59 2001 +0000
+++ b/Makefile	Tue May 08 12:17:03 2001 +0000
@@ -62,7 +62,10 @@
 encore/libencore.a:
 	$(MAKE) -C encore
 
-$(PRG):	.depend mplayer.o $(OBJS) loader/libloader.a $(DS_DEP) libmpeg2/libmpeg2.a opendivx/libdecore.a $(COMMONLIBS) encore/libencore.a
+mplayerwithoutlink:	.depend mplayer.o $(OBJS) loader/libloader.a $(DS_DEP) libmpeg2/libmpeg2.a opendivx/libdecore.a $(COMMONLIBS) encore/libencore.a
+	@for a in mp3lib libac3 libmpeg2 libvo opendivx encore loader/DirectShow ; do $(MAKE) -C $$a all ; done
+
+$(PRG):	mplayerwithoutlink
 	$(CC) $(CFLAGS) -o $(PRG) mplayer.o $(OBJS) $(XMM_LIBS) $(LIRC_LIBS) $(A_LIBS) -lm $(TERMCAP_LIB) -Lloader -lloader $(DS_LIB) -ldl -Llibmpeg2 -lmpeg2 -Lopendivx -ldecore $(VO_LIBS) $(CSS_LIB) -Lencore -lencore -lpthread
 
 # $(PRG_HQ):	.depend mplayerHQ.o $(OBJS) loader/libloader.a libmpeg2/libmpeg2.a opendivx/libdecore.a $(COMMONLIBS) encore/libencore.a
--- a/cfg-mplayer.h	Tue May 08 01:58:59 2001 +0000
+++ b/cfg-mplayer.h	Tue May 08 12:17:03 2001 +0000
@@ -116,9 +116,9 @@
         
 	{"verbose", &verbose, CONF_TYPE_INT, CONF_RANGE, 0, 100},
 	{"v", cfg_inc_verbose, CONF_TYPE_FUNC, 0, 0, 0},
-	{"-help", help_text, CONF_TYPE_PRINT, CONF_NOCFG, 0, 0},
-	{"help", help_text, CONF_TYPE_PRINT, CONF_NOCFG, 0, 0},
-	{"h", help_text, CONF_TYPE_PRINT, CONF_NOCFG, 0, 0},
+//	{"-help", help_text, CONF_TYPE_PRINT, CONF_NOCFG, 0, 0},
+//	{"help", help_text, CONF_TYPE_PRINT, CONF_NOCFG, 0, 0},
+//	{"h", help_text, CONF_TYPE_PRINT, CONF_NOCFG, 0, 0},
 	{NULL, NULL, 0, 0, 0, 0}
 };
 
--- a/configure	Tue May 08 01:58:59 2001 +0000
+++ b/configure	Tue May 08 12:17:03 2001 +0000
@@ -229,6 +229,8 @@
 
 _select='#define HAVE_AUDIO_SELECT'
 
+_gui=no;
+
 for i in `echo $pparam`; do
 
  case "$i" in
@@ -589,6 +591,9 @@
   --enable-select)
         _select='#define HAVE_AUDIO_SELECT'
 	;;
+  --enable-gui)
+  	_gui=yes
+	;;
   --disable-css)
 	_css=no
 	;;
@@ -656,6 +661,9 @@
   --disable-fastmemcpy)
         _fastmemcpy=no
 	;;
+  --disable-gui)
+  	_gui=no
+	;;
   --with-win32libdir=*)
         _win32libdir=`echo $ac_option | cut -d '=' -f 2`
 	_win32libdirnotify=no
@@ -983,6 +991,12 @@
  _mpg123='#undef DEFAULT_MPG123'
 fi
 
+if [ $_gui = yes ]; then
+ _gui='#define HAVE_GUI'
+else
+ _gui='#undef HAVE_GUI'
+fi
+
 cat > $CCONF << EOF
 
 /* -------- Generated by ./configure ----------- */
@@ -1037,6 +1051,9 @@
 /* Use 3dnow/mmxext/sse/mmx optimized fast memcpy() [maybe buggy... signal 4]*/
 $_fastmemcpy
 
+/* gui support, please do not edit this option */
+$_gui
+
 /* Define if your processor stores words with the most significant
    byte first (like Motorola and SPARC, unlike Intel and VAX).  */
 /* #define WORDS_BIGENDIAN */
--- a/libvo/vo_xmga.c	Tue May 08 01:58:59 2001 +0000
+++ b/libvo/vo_xmga.c	Tue May 08 12:17:03 2001 +0000
@@ -87,6 +87,10 @@
 static uint32_t               drwX,drwY,drwWidth,drwHeight,drwBorderWidth,drwDepth;
 static uint32_t               drwcX,drwcY,dwidth,dheight,mFullscreen;
 
+#ifdef HAVE_GUI
+ static uint32_t               mdwidth,mdheight;
+#endif
+
 static XSetWindowAttributes   xWAttribs;
 
 #include "mga_common.c"
@@ -106,6 +110,20 @@
          XTranslateCoordinates( mDisplay,mWindow,mRoot,0,0,&drwcX,&drwcY,&mRoot );
          //fprintf( stderr,"[xmga] dcx: %d dcy: %d dx: %d dy: %d dw: %d dh: %d\n",drwcX,drwcY,drwX,drwY,drwWidth,drwHeight );
 
+         #ifdef HAVE_GUI
+          if ( vo_window != None )
+           {
+            mFullscreen=0;
+            dwidth=mdwidth; dheight=mdheight;
+            if ( ( drwWidth == vo_screenwidth )&&( drwHeight == vo_screenheight ) )
+             {
+              mFullscreen=1;
+              dwidth=vo_screenwidth;
+              dheight=vo_screenwidth * mdheight / mdwidth;
+             }
+           }
+         #endif
+
          if ( mFullscreen )
           {
            drwX=( vo_screenwidth - (dwidth > vo_screenwidth?vo_screenwidth:dwidth) ) / 2;
@@ -224,19 +242,11 @@
  wndX=0; wndY=0;
  wndWidth=d_width; wndHeight=d_height;
  dwidth=d_width; dheight=d_height;
+ #ifdef HAVE_GUI
+  mdwidth=d_width; mdheight=d_height;
+ #endif
  mFullscreen=fullscreen;
 
- if ( fullscreen )
-  {
-   wndWidth=vo_screenwidth;
-   wndHeight=vo_screenheight;
-  }
-
- XGetWindowAttributes( mDisplay,DefaultRootWindow( mDisplay ),&attribs );
- mDepth=attribs.depth;
- if ( mDepth != 15 && mDepth != 16 && mDepth != 24 && mDepth != 32 ) mDepth=24;
- XMatchVisualInfo( mDisplay,mScreen,mDepth,TrueColor,&vinfo );
- xWAttribs.colormap=XCreateColormap( mDisplay,RootWindow( mDisplay,mScreen ),vinfo.visual,AllocNone );
  switch ( vo_depthonscreen )
   {
    case 32:
@@ -245,34 +255,62 @@
    case 15: fgColor=0x7c1fL; break;
    default: printf( "Sorry, this (%d) color depth not supported.\n",vo_depthonscreen ); return -1;
   }
- xWAttribs.background_pixel=0;
- xWAttribs.border_pixel=0;
- xWAttribs.event_mask=StructureNotifyMask | ExposureMask | KeyPressMask;
- xswamask=CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
 
- mWindow=XCreateWindow( mDisplay,RootWindow( mDisplay,mScreen ),
-   wndX,wndY,
-   wndWidth,wndHeight,
-   xWAttribs.border_pixel,
-   mDepth,
-   InputOutput,
-   vinfo.visual,xswamask,&xWAttribs );
- vo_hidecursor(mDisplay,mWindow);
+#ifdef HAVE_GUI
+ if ( vo_window == None )
+  {
+#endif
+   if ( fullscreen )
+    {
+     wndWidth=vo_screenwidth;
+     wndHeight=vo_screenheight;
+    }
+
+   XGetWindowAttributes( mDisplay,DefaultRootWindow( mDisplay ),&attribs );
+   mDepth=attribs.depth;
+   if ( mDepth != 15 && mDepth != 16 && mDepth != 24 && mDepth != 32 ) mDepth=24;
+   XMatchVisualInfo( mDisplay,mScreen,mDepth,TrueColor,&vinfo );
+   xWAttribs.colormap=XCreateColormap( mDisplay,RootWindow( mDisplay,mScreen ),vinfo.visual,AllocNone );
+   xWAttribs.background_pixel=0;
+   xWAttribs.border_pixel=0;
+   xWAttribs.event_mask=StructureNotifyMask | ExposureMask | KeyPressMask;
+   xswamask=CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
 
- if ( fullscreen ) vo_x11_decoration( mDisplay,mWindow,0 );
+   mWindow=XCreateWindow( mDisplay,RootWindow( mDisplay,mScreen ),
+     wndX,wndY,
+     wndWidth,wndHeight,
+     xWAttribs.border_pixel,
+     mDepth,
+     InputOutput,
+     vinfo.visual,xswamask,&xWAttribs );
+   vo_hidecursor(mDisplay,mWindow);
+
+   if ( fullscreen ) vo_x11_decoration( mDisplay,mWindow,0 );
 
- XGetNormalHints( mDisplay,mWindow,&hint );
- hint.x=wndX; hint.y=wndY;
- hint.width=wndWidth; hint.height=wndHeight;
- hint.base_width=wndWidth; hint.base_height=wndHeight;
- hint.flags=USPosition | USSize;
- XSetNormalHints( mDisplay,mWindow,&hint );
- XStoreName( mDisplay,mWindow,mTitle );
-
+   XGetNormalHints( mDisplay,mWindow,&hint );
+   hint.x=wndX; hint.y=wndY;
+   hint.width=wndWidth; hint.height=wndHeight;
+   hint.base_width=wndWidth; hint.base_height=wndHeight;
+   hint.flags=USPosition | USSize;
+   XSetNormalHints( mDisplay,mWindow,&hint );
+   XStoreName( mDisplay,mWindow,mTitle );
+   XMapWindow( mDisplay,mWindow );
+#ifdef HAVE_GUI
+  }
+  else
+    {
+     mWindow=vo_window;
+     fprintf( stderr,"[xmga] width: %d height: %d d_width: %d d_height: %d\n",width,height,d_width,d_height );
+     if ( vo_screenwidth != d_width )
+      {
+       XMoveWindow( mDisplay,mWindow,( vo_screenwidth - d_width ) / 2,( vo_screenheight - d_height ) / 2 );
+       XResizeWindow( mDisplay,mWindow,d_width,d_height );
+      }
+      else mFullscreen=1;
+    }
+#endif
  mGC=XCreateGC( mDisplay,mWindow,GCForeground,&wGCV );
 
- XMapWindow( mDisplay,mWindow );
-
  set_window();
 
  mga_vid_config.src_width=width;
@@ -285,8 +323,15 @@
 
  if(mga_init()) return -1;
 
- XFlush( mDisplay );
- XSync( mDisplay,False );
+#ifdef HAVE_GUI
+ if ( vo_window == None )
+  {
+#endif
+   XFlush( mDisplay );
+   XSync( mDisplay,False );
+#ifdef HAVE_GUI
+  }
+#endif
 
  saver_off(mDisplay);
 
--- a/libvo/vo_xv.c	Tue May 08 01:58:59 2001 +0000
+++ b/libvo/vo_xv.c	Tue May 08 12:17:03 2001 +0000
@@ -85,6 +85,10 @@
 static uint32_t               drwX,drwY,drwWidth,drwHeight,drwBorderWidth,drwDepth;
 static uint32_t               drwcX,drwcY,dwidth,dheight,mFullscreen;
 
+#ifdef HAVE_GUI
+ static uint32_t               mdwidth,mdheight;
+#endif
+
 /*
  * connect to server, create and map window,
  * allocate colors and (shared) memory
@@ -121,36 +125,54 @@
 
  screen = DefaultScreen(mydisplay);
 
- hint.x = 0;
- hint.y = 0;
- hint.width = d_width;
- hint.height = d_height;
- if ( fullscreen )
+#ifdef HAVE_GUI
+ if ( vo_window == None )
   {
-   hint.width=vo_screenwidth;
-   hint.height=vo_screenheight;
-  }
- hint.flags = PPosition | PSize;
- XGetWindowAttributes(mydisplay, DefaultRootWindow(mydisplay), &attribs);
- depth=attribs.depth;
- if (depth != 15 && depth != 16 && depth != 24 && depth != 32) depth = 24;
- XMatchVisualInfo(mydisplay, screen, depth, TrueColor, &vinfo);
+#endif
+   hint.x = 0;
+   hint.y = 0;
+   hint.width = d_width;
+   hint.height = d_height;
+   if ( fullscreen )
+    {
+     hint.width=vo_screenwidth;
+     hint.height=vo_screenheight;
+    }
+   hint.flags = PPosition | PSize;
+   XGetWindowAttributes(mydisplay, DefaultRootWindow(mydisplay), &attribs);
+   depth=attribs.depth;
+   if (depth != 15 && depth != 16 && depth != 24 && depth != 32) depth = 24;
+   XMatchVisualInfo(mydisplay, screen, depth, TrueColor, &vinfo);
+
+   xswa.background_pixel = 0;
+   xswa.border_pixel     = 0;
+   xswamask = CWBackPixel | CWBorderPixel;
 
- xswa.background_pixel = 0;
- xswa.border_pixel     = 0;
- xswamask = CWBackPixel | CWBorderPixel;
+   mywindow = XCreateWindow(mydisplay, RootWindow(mydisplay,screen),
+   hint.x, hint.y, hint.width, hint.height,
+   0, depth,CopyFromParent,vinfo.visual,xswamask,&xswa);
+   vo_hidecursor(mydisplay,mywindow);
 
- mywindow = XCreateWindow(mydisplay, RootWindow(mydisplay,screen),
- hint.x, hint.y, hint.width, hint.height,
- 0, depth,CopyFromParent,vinfo.visual,xswamask,&xswa);
- vo_hidecursor(mydisplay,mywindow);
-
- XSelectInput(mydisplay, mywindow, StructureNotifyMask | KeyPressMask );
- XSetStandardProperties(mydisplay, mywindow, hello, hello, None, NULL, 0, &hint);
- if ( fullscreen ) vo_x11_decoration( mydisplay,mywindow,0 );
- XMapWindow(mydisplay, mywindow);
- XFlush(mydisplay);
- XSync(mydisplay, False);
+   XSelectInput(mydisplay, mywindow, StructureNotifyMask | KeyPressMask );
+   XSetStandardProperties(mydisplay, mywindow, hello, hello, None, NULL, 0, &hint);
+   if ( fullscreen ) vo_x11_decoration( mydisplay,mywindow,0 );
+   XMapWindow(mydisplay, mywindow);
+   XFlush(mydisplay);
+   XSync(mydisplay, False);
+#ifdef HAVE_GUI
+  }
+  else
+    {
+     mywindow=vo_window;
+     mygc=vo_gc;
+     if ( vo_screenwidth != d_width )
+      {
+       XMoveWindow( mydisplay,mywindow,( vo_screenwidth - d_width ) / 2,( vo_screenheight - d_height ) / 2 );
+       XResizeWindow( mydisplay,mywindow,d_width,d_height );
+      }
+      else mFullscreen=1;
+    }
+#endif
 
  mygc = XCreateGC(mydisplay, mywindow, 0L, &xgcv);
 
@@ -253,6 +275,20 @@
    XTranslateCoordinates( mydisplay,mywindow,mRoot,0,0,&drwcX,&drwcY,&mRoot );
    printf( "[xv] dcx: %d dcy: %d dx: %d dy: %d dw: %d dh: %d\n",drwcX,drwcY,drwX,drwY,drwWidth,drwHeight );
 
+   #ifdef HAVE_GUI
+    if ( vo_window != None )
+     {
+      mFullscreen=0;
+      dwidth=mdwidth; dheight=mdheight;
+      if ( ( drwWidth == vo_screenwidth )&&( drwHeight == vo_screenheight ) )
+       {
+        mFullscreen=1;
+        dwidth=vo_screenwidth;
+        dheight=vo_screenwidth * mdheight / mdwidth;
+       }
+     }
+   #endif
+
    if ( mFullscreen )
     {
      drwX=( vo_screenwidth - (dwidth > vo_screenwidth?vo_screenwidth:dwidth) ) / 2;
--- a/libvo/x11_common.c	Tue May 08 01:58:59 2001 +0000
+++ b/libvo/x11_common.c	Tue May 08 12:17:03 2001 +0000
@@ -149,6 +149,17 @@
   }
 }
 
+#ifdef HAVE_GUI
+ Window    vo_window = None;
+ GC        vo_gc;
+ int       vo_xeventhandling = 1;
+ int       vo_resize = 0;
+ int       vo_expose = 0;
+
+ void vo_setwindow( Window w,GC g )
+ { vo_window=w; vo_gc=g; }
+#endif
+
 int vo_x11_check_events(Display *mydisplay){
  int ret=0;
  XEvent         Event;
@@ -157,26 +168,46 @@
  XComposeStatus stat;
 // unsigned long  vo_KeyTable[512];
 
- while ( XPending( mydisplay ) )
-  {
-   XNextEvent( mydisplay,&Event );
-   switch( Event.type )
-    {
-       case Expose:
-	     ret|=VO_EVENT_EXPOSE;
-             break;
-       case ConfigureNotify:
-             vo_dwidth=Event.xconfigure.width;
-	     vo_dheight=Event.xconfigure.height;
-	     ret|=VO_EVENT_RESIZE;
-             break;
-       case KeyPress:
-             XLookupString( &Event.xkey,buf,sizeof(buf),&keySym,&stat );
-             vo_x11_putkey( ( (keySym&0xff00) != 0?( (keySym&0x00ff) + 256 ):( keySym ) ) );
-	     ret|=VO_EVENT_KEYPRESS;
-             break;
+#ifdef HAVE_GUI
+ if ( vo_xeventhandling )
+   {
+#endif
+    while ( XPending( mydisplay ) )
+      {
+       XNextEvent( mydisplay,&Event );
+       switch( Event.type )
+         {
+          case Expose:
+               ret|=VO_EVENT_EXPOSE;
+               break;
+          case ConfigureNotify:
+               vo_dwidth=Event.xconfigure.width;
+               vo_dheight=Event.xconfigure.height;
+	       ret|=VO_EVENT_RESIZE;
+               break;
+          case KeyPress:
+               XLookupString( &Event.xkey,buf,sizeof(buf),&keySym,&stat );
+               vo_x11_putkey( ( (keySym&0xff00) != 0?( (keySym&0x00ff) + 256 ):( keySym ) ) );
+	       ret|=VO_EVENT_KEYPRESS;
+               break;
+         }
+      }
+#ifdef HAVE_GUI
     }
-  }
+    else
+     {
+      if ( vo_resize )
+       {
+        vo_resize=0;
+        ret|=VO_EVENT_RESIZE;
+       }
+      if ( vo_expose )
+       {
+        vo_expose=0;
+        ret|=VO_EVENT_EXPOSE;
+       }
+     }
+#endif
 
   return ret;
 }
--- a/libvo/x11_common.h	Tue May 08 01:58:59 2001 +0000
+++ b/libvo/x11_common.h	Tue May 08 12:17:03 2001 +0000
@@ -13,5 +13,16 @@
 int vo_x11_check_events(Display *mydisplay);
 #endif
 
+#ifdef HAVE_GUI
+ extern Window    vo_window;
+ extern Display * vo_display;
+ extern GC        vo_gc;
+ extern int       vo_xeventhandling;
+ extern int       vo_expose;
+ extern int       vo_resize;
+
+ extern void vo_setwindow( Window w,GC g );
+#endif
+
 void saver_off( Display * );
 void saver_on( Display * );
--- a/mplayer.c	Tue May 08 01:58:59 2001 +0000
+++ b/mplayer.c	Tue May 08 12:17:03 2001 +0000
@@ -88,6 +88,9 @@
 #include "help_mp.h"
 
 #define DEBUG if(0)
+#ifdef HAVE_GUI
+ int nogui=1; // new
+#endif
 int verbose=0;
 
 #define ABS(x) (((x)>=0)?(x):(-(x)))
@@ -325,7 +328,25 @@
 
 extern void avi_fixate();
 
+#ifdef HAVE_GUI
+ #include "../Gui/mplayer/psignal.h"
+#endif
+
 void exit_player(char* how){
+
+#ifdef HAVE_GUI
+ if ( !nogui )
+  {
+   if ( how != NULL )
+    {
+     if ( !strcmp( how,"Quit" ) ) mplSendMessage( mplEndOfFile );
+     if ( !strcmp( how,"End of file" ) ) mplSendMessage( mplEndOfFile );
+     if ( !strcmp( how,"audio_init" ) ) mplSendMessage( mplAudioError );
+    }
+    else mplSendMessage( mplUnknowError );
+  }
+#endif
+
   if(how) printf("\nExiting... (%s)\n",how);
   if(verbose) printf("max framesize was %d bytes\n",max_framesize);
   // restore terminal:
@@ -340,6 +361,9 @@
 #endif
   if(encode_name) avi_fixate();
 #ifdef HAVE_LIRC
+  #ifdef HAVE_GUI
+   if ( nogui )
+  #endif
   lirc_mp_cleanup();
 #endif
   //if(play_in_bg) system("xsetroot -solid \\#000000");
@@ -359,6 +383,13 @@
   printf("\nMPlayer interrupted by signal %d in module: %s \n",x,
       current_module?current_module:"unknown"
   );
+  #ifdef HAVE_GUI
+   if ( !nogui )
+    {
+     mplShMem->items.error.signal=x;
+     strcpy( mplShMem->items.error.module,current_module?current_module:"unknown" );
+    }
+  #endif
   exit_player(NULL);
 }
 
@@ -372,7 +403,6 @@
 extern int vo_init(void);
 extern int decode_audio(sh_audio_t *sh_audio,unsigned char *buf,int maxlen);
 
-int main(int argc,char* argv[], char *envp[]){
 char* filename=NULL; //"MI2-Trailer.avi";
 int i;
 int seek_to_sec=0;
@@ -437,11 +467,17 @@
 int stream_dump_type=0;
 //int user_bpp=0;
 
+int osd_visible=100;
+int osd_function=OSD_PLAY;
+int osd_last_pts=-303;
+
+int rel_seek_secs=0;
+
 #include "mixer.h"
 #include "cfg-mplayer.h"
 
-  printf("%s",banner_text);
-
+void parse_cfgfiles( void )
+{
 if (parse_config_file(conf, "/etc/mplayer.conf") < 0)
   exit(1);
 if ((conffile = get_path("")) == NULL) {
@@ -462,26 +498,42 @@
     free(conffile);
   }
 }
-if (parse_command_line(conf, argc, argv, envp, &filename) < 0)
-  exit(1);
-
-// Many users forget to include command line in bugreports...
-if(verbose){
-  printf("CommandLine:");
-  for(i=1;i<argc;i++)printf(" '%s'",argv[i]);
-  printf("\n");
 }
 
-if(video_driver && strcmp(video_driver,"help")==0){
-  printf("Available video output drivers:\n");
-  i=0;
-  while (video_out_drivers[i]) {
-    const vo_info_t *info = video_out_drivers[i++]->get_info ();
-  	printf("\t%s\t%s\n", info->short_name, info->name);
-  }
-  printf("\n");
-  exit(0);
-}
+#ifndef HAVE_GUI
+ int main(int argc,char* argv[], char *envp[]){
+#else
+ int mplayer(int argc,char* argv[], char *envp[]){
+#endif
+
+  printf("%s",banner_text);
+
+#ifdef HAVE_GUI
+  if ( nogui )
+   {
+#endif
+    if (parse_command_line(conf, argc, argv, envp, &filename) < 0) exit(1);
+
+    // Many users forget to include command line in bugreports...
+    if(verbose){
+      printf("CommandLine:");
+      for(i=1;i<argc;i++)printf(" '%s'",argv[i]);
+      printf("\n");
+    }
+
+    if(video_driver && strcmp(video_driver,"help")==0){
+      printf("Available video output drivers:\n");
+      i=0;
+      while (video_out_drivers[i]) {
+        const vo_info_t *info = video_out_drivers[i++]->get_info ();
+      	printf("\t%s\t%s\n", info->short_name, info->name);
+      }
+      printf("\n");
+      exit(0);
+     }
+#ifdef HAVE_GUI
+   }
+#endif
 
 if(!filename){
   if(vcd_track) filename="/dev/cdrom"; 
@@ -508,6 +560,9 @@
 // check codec.conf
 if(!parse_codec_cfg(get_path("codecs.conf"))){
     printf("(copy/link DOCS/codecs.conf to ~/.mplayer/codecs.conf)\n");
+    #ifdef HAVE_GUI
+     if ( !nogui ) { mplSendMessage( mplCodecConfNotFound ); usleep( 10000 ); }
+    #endif
     exit(1);
 }
 
@@ -573,12 +628,20 @@
   if (dvdimportkey) {
     if (dvd_import_key(dvdimportkey)) {
 	fprintf(stderr,"Error processing DVD KEY.\n");
+        #ifdef HAVE_GUI
+         if ( !nogui ) { mplSendMessage( mplErrorDVDKeyProcess ); usleep( 10000 ); }
+        #endif
 	exit(1);
     }
     printf("DVD command line requested key is stored for descrambling.\n");
   }
   if (dvd_device) {
-    if (dvd_auth(dvd_device,f)) exit(0);
+    if (dvd_auth(dvd_device,f)) {
+        #ifdef HAVE_GUI
+         if ( !nogui ) { mplSendMessage( mplErrorDVDAuth ); usleep( 10000 ); }
+        #endif
+        exit(0);
+      } 
     printf("DVD auth sequence seems to be OK.\n");
   }
 #endif
@@ -653,6 +716,9 @@
 if(file_format==DEMUXER_TYPE_UNKNOWN){
   printf("============= Sorry, this file format not recognized/supported ===============\n");
   printf("=== If this file is an AVI, ASF or MPEG stream, please contact the author! ===\n");
+  #ifdef HAVE_GUI
+   if ( !nogui ) { mplSendMessage( mplUnknowFileType ); usleep( 10000 ); }
+  #endif
   exit(1);
 }
 //====== File format recognized, set up these for compatibility: =========
@@ -703,6 +769,9 @@
       }
       if(v_pos==-1){
         printf("AVI_NI: missing video stream!? contact the author, it may be a bug :(\n");
+        #ifdef HAVE_GUI
+         if ( !nogui ) { mplSendMessage( mplErrorAVINI ); usleep( 10000 ); }
+        #endif
         exit(1);
       }
       if(a_pos==-1){
@@ -727,6 +796,9 @@
   }
   if(!ds_fill_buffer(d_video)){
     printf("AVI: missing video stream!? contact the author, it may be a bug :(\n");
+    #ifdef HAVE_GUI
+     if ( !nogui ) { mplSendMessage( mplAVIErrorMissingVideoStream ); usleep( 10000 ); }
+    #endif
     exit(1);
   }
   sh_video=d_video->sh;sh_video->ds=d_video;
@@ -768,6 +840,9 @@
 //  demuxer->endpos=avi_header.movi_end;
   if(!ds_fill_buffer(d_video)){
     printf("ASF: missing video stream!? contact the author, it may be a bug :(\n");
+    #ifdef HAVE_GUI
+     if ( !nogui ) { mplSendMessage( mplASFErrorMissingVideoStream ); usleep( 10000 ); }
+    #endif
     exit(1);
   }
   sh_video=d_video->sh;sh_video->ds=d_video;
@@ -836,6 +911,9 @@
       if(!i || !skip_video_packet(d_video)){
         if(verbose)  printf("NONE :(\n");
         printf("MPEG: FATAL: EOF while searching for sequence header\n");
+        #ifdef HAVE_GUI
+         if ( !nogui ) { mplSendMessage( mplMPEGErrorSeqHeaderSearch ); usleep( 10000 ); }
+        #endif
         exit(1);
       }
    }
@@ -845,17 +923,43 @@
    mpeg2_init();
    // ========= Read & process sequence header & extension ============
    videobuffer=shmem_alloc(VIDEOBUFFER_SIZE);
-   if(!videobuffer){ printf("Cannot allocate shared memory\n");exit(0);}
+   if(!videobuffer){ 
+     printf("Cannot allocate shared memory\n");
+     #ifdef HAVE_GUI
+      if ( !nogui ) { mplSendMessage( mplErrorShMemAlloc ); usleep( 10000 ); }
+     #endif
+     exit(0);
+   }
    videobuf_len=0;
-   if(!read_video_packet(d_video)){ printf("FATAL: Cannot read sequence header!\n");exit(1);}
+   if(!read_video_packet(d_video)){ 
+     printf("FATAL: Cannot read sequence header!\n");
+     #ifdef HAVE_GUI
+      if ( !nogui ) { mplSendMessage( mplMPEGErrorCannotReadSeqHeader ); usleep( 10000 ); }
+     #endif
+     exit(1);
+   }
    if(header_process_sequence_header (picture, &videobuffer[4])) {
-     printf ("bad sequence header!\n"); exit(1);
+     printf ("bad sequence header!\n"); 
+     #ifdef HAVE_GUI
+      if ( !nogui ) { mplSendMessage( mplMPEGErrorBadSeqHeader ); usleep( 10000 ); }
+     #endif
+     exit(1);
    }
    if(sync_video_packet(d_video)==0x1B5){ // next packet is seq. ext.
     videobuf_len=0;
-    if(!read_video_packet(d_video)){ printf("FATAL: Cannot read sequence header extension!\n");exit(1);}
+    if(!read_video_packet(d_video)){ 
+      printf("FATAL: Cannot read sequence header extension!\n");
+      #ifdef HAVE_GUI
+       if ( !nogui ) { mplSendMessage( mplMPEGErrorCannotReadSeqHeaderExt ); usleep( 10000 ); }
+      #endif
+      exit(1);
+    }
     if(header_process_extension (picture, &videobuffer[4])) {
-      printf ("bad sequence header extension!\n");  exit(1);
+      printf ("bad sequence header extension!\n");  
+      #ifdef HAVE_GUI
+       if ( !nogui ) { mplSendMessage( mplMPEGErrorBadSeqHeaderExt ); usleep( 10000 ); }
+      #endif
+      exit(1);
     }
    }
    // display info:
@@ -940,6 +1044,14 @@
     sh_video->bih?((unsigned int*) &sh_video->bih->biCompression):NULL,sh_video->codec,0);
   if(!sh_video->codec){
     printf("Can't find codec for video format 0x%X !\n",sh_video->format);
+    #ifdef HAVE_GUI
+     if ( !nogui )
+      {
+       mplShMem->items.videodata.format=sh_video->format;
+       mplSendMessage( mplCantFindCodecForVideoFormat );
+       usleep( 10000 );
+      }
+    #endif
     exit(1);
   }
   if(!allow_dshow && sh_video->codec->driver==4) continue; // skip DShow
@@ -959,6 +1071,9 @@
 }
 if(i>=CODECS_MAX_OUTFMT){
     printf("Sorry, selected video_out device is incompatible with this codec.\n");
+    #ifdef HAVE_GUI
+     if ( !nogui ) { mplSendMessage( mplIncompatibleVideoOutDevice ); usleep( 10000 ); }
+    #endif
     exit(1);
 }
 sh_video->outfmtidx=i;
@@ -967,13 +1082,21 @@
 
 switch(sh_video->codec->driver){
  case 2: {
-   if(!init_video_codec(sh_video)) exit(1);
+   if(!init_video_codec(sh_video)) {
+     #ifdef HAVE_GUI
+      if ( !nogui ) { mplSendMessage( mplUnknowError ); usleep( 10000 ); }
+     #endif
+     exit(1);
+   }  
    if(verbose) printf("INFO: Win32 video codec init OK!\n");
    break;
  }
  case 4: { // Win32/DirectShow
 #ifndef USE_DIRECTSHOW
    printf("MPlayer was compiled WITHOUT directshow support!\n");
+   #ifdef HAVE_GUI
+    if ( !nogui ) { mplSendMessage( mplCompileWithoutDSSupport ); usleep( 10000 ); }
+   #endif
    exit(1);
 #else
    sh_video->our_out_buffer=NULL;
@@ -983,6 +1106,14 @@
         printf("Maybe you forget to upgrade your win32 codecs?? It's time to download the new\n");
         printf("package from:  ftp://thot.banki.hu/esp-team/linux/MPlayer/w32codec.zip  !\n");
         printf("Or you should disable DShow support: make distclean;make -f Makefile.No-DS\n");
+        #ifdef HAVE_GUI
+         if ( !nogui )
+          {
+           strcpy(  mplShMem->items.videodata.codecdll,sh_video->codec->dll );
+           mplSendMessage( mplDSCodecNotFound );
+           usleep( 10000 );
+          }
+        #endif
         exit(1);
    }
    
@@ -1125,11 +1256,24 @@
 
 if(verbose) printf("vo_debug3: out_fmt=0x%08X\n",out_fmt);
 
+   #ifdef HAVE_GUI
+    if ( !nogui )
+     {
+      mplShMem->items.videodata.width=sh_video->disp_w;
+      mplShMem->items.videodata.height=sh_video->disp_h;
+      mplSendMessage( mplSetVideoData );
+     }
+   #endif
+
    if(video_out->init(sh_video->disp_w,sh_video->disp_h,
                       screen_size_x,screen_size_y,
                       fullscreen|(vidmode<<1)|(softzoom<<2),
                       title,out_fmt)){
-     printf("FATAL: Cannot initialize video driver!\n");exit(1);
+     printf("FATAL: Cannot initialize video driver!\n");
+     #ifdef HAVE_GUI
+      if ( !nogui ) { mplSendMessage( mplCantInitVideoDriver ); usleep( 10000 ); }
+     #endif
+     exit(1);
    }
    if(verbose) printf("INFO: Video OUT driver init OK!\n");
 
@@ -1156,13 +1300,13 @@
 double audio_time_usage=0;
 int grab_frames=0;
 char osd_text_buffer[64];
-int osd_visible=100;
-int osd_function=OSD_PLAY;
-int osd_last_pts=-303;
 int drop_frame=0;
 int drop_frame_cnt=0;
 
 #ifdef HAVE_LIRC
+ #ifdef HAVE_GUI
+  if ( nogui )
+ #endif
   lirc_mp_setup();
 #endif
 
@@ -1175,7 +1319,12 @@
   // terminate requests:
   signal(SIGTERM,exit_sighandler); // kill
   signal(SIGHUP,exit_sighandler);  // kill -HUP  /  xterm closed
-  signal(SIGINT,exit_sighandler);  // Interrupt from keyboard
+
+  #ifdef HAVE_GUI
+   if ( nogui )
+  #endif
+     signal(SIGINT,exit_sighandler);  // Interrupt from keyboard
+
   signal(SIGQUIT,exit_sighandler); // Quit from keyboard
   // fatal errors:
   signal(SIGBUS,exit_sighandler);  // bus error
@@ -1658,15 +1807,22 @@
 
   if(osd_function==OSD_PAUSE){
       printf("\n------ PAUSED -------\r");fflush(stdout);
-      while(
+#ifdef HAVE_GUI
+      if ( nogui )
+        {
+#endif
+         while(
 #ifdef HAVE_LIRC
-          lirc_mp_getinput()<=0 &&
+             lirc_mp_getinput()<=0 &&
 #endif
-          (!f || getch2(20)<=0) && mplayer_get_key()<=0){
-	  video_out->check_events();
-          if(!f) usleep(1000); // do not eat the CPU
-      }
-      osd_function=OSD_PLAY;
+             (!f || getch2(20)<=0) && mplayer_get_key()<=0){
+	     video_out->check_events();
+             if(!f) usleep(1000); // do not eat the CPU
+         }
+         osd_function=OSD_PLAY;
+#ifdef HAVE_GUI
+        } else while( osd_function != OSD_PLAY ) usleep( 1000 );
+#endif
   }
 
   } //  while(v_frame<a_frame || force_redraw)
@@ -1674,8 +1830,7 @@
 
 //================= Keyboard events, SEEKing ====================
 
-{ int rel_seek_secs=0;
-  int c;
+{ int c;
   while(
 #ifdef HAVE_LIRC
       (c=lirc_mp_getinput())>0 ||
@@ -2041,6 +2196,7 @@
 //      num_frames=real_num_frames=0;
 
   }
+ rel_seek_secs=0;
 } // keyboard event handler
 
 //================= Update OSD ====================