]> git.sesse.net Git - vlc/blobdiff - plugins/sdl/vout_sdl.c
* Fixed the BeOS compile typo.
[vlc] / plugins / sdl / vout_sdl.c
index a8bac09361a2a536528cf89e8ae89e9a77c7da0c..42c46c12d0da8b388f742cf34dfb9c42e8b5d592 100644 (file)
@@ -2,6 +2,7 @@
  * vout_sdl.c: SDL video output display method
  *****************************************************************************
  * Copyright (C) 1998, 1999, 2000 VideoLAN
+ * $Id: vout_sdl.c,v 1.53 2001/05/30 17:03:12 sam Exp $
  *
  * Authors: Samuel Hocevar <sam@zoy.org>
  *          Pierre Baillet <oct@zoy.org>
@@ -22,6 +23,9 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
  *****************************************************************************/
 
+#define MODULE_NAME sdl
+#include "modules_inner.h"
+
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
 #include <stdlib.h>                                                /* free() */
 #include <string.h>                                            /* strerror() */
 
+#ifndef WIN32
+#include <netinet/in.h>                               /* BSD: struct in_addr */
+#endif
+
 #include <SDL/SDL.h>
 
 #include "config.h"
@@ -38,7 +46,6 @@
 #include "threads.h"
 #include "mtime.h"
 #include "tests.h"
-#include "modules.h"
 
 #include "video.h"
 #include "video_output.h"
 /* FIXME: get rid of this */
 #include "keystrokes.h"
 #include "main.h"
+#include "netutils.h"
+
+#include "modules.h"
+#include "modules_export.h"
 
 /*****************************************************************************
  * FIXME: this file is ...                                                   *
@@ -71,13 +82,19 @@ typedef struct vout_sys_s
 {
     int i_width;
     int i_height;
+
     SDL_Surface *   p_display;                             /* display device */
     SDL_Overlay *   p_overlay;                             /* overlay device */
-    boolean_t   b_fullscreen;
+
     boolean_t   b_overlay;
     boolean_t   b_cursor;
     boolean_t   b_reopen_display;
+
+    boolean_t   b_cursor_autohidden;
+    mtime_t     i_lastmoved;
+
     Uint8   *   p_sdl_buf[2];                          /* Buffer information */
+
 } vout_sys_t;
 
 /*****************************************************************************
@@ -100,7 +117,7 @@ static void SDLCloseDisplay     ( vout_thread_t *p_vout );
  * Functions exported as capabilities. They are declared as static so that
  * we don't pollute the namespace too much.
  *****************************************************************************/
-void vout_getfunctions( function_list_t * p_function_list )
+void _M( vout_getfunctions )( function_list_t * p_function_list )
 {
     p_function_list->pf_probe = vout_Probe;
     p_function_list->functions.vout.pf_create     = vout_Create;
@@ -146,8 +163,12 @@ static int vout_Create( vout_thread_t *p_vout )
     }
 
     /* Initialize library */
-    if( SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTTHREAD | SDL_INIT_NOPARACHUTE)
-            < 0 )
+    if( SDL_Init( SDL_INIT_VIDEO
+#ifndef WIN32
+    /* Win32 SDL implementation doesn't support SDL_INIT_EVENTTHREAD yet*/
+                | SDL_INIT_EVENTTHREAD
+#endif
+                | SDL_INIT_NOPARACHUTE ) < 0 )
     {
         intf_ErrMsg( "vout error: can't initialize SDL (%s)", SDL_GetError() );
         free( p_vout->p_sys );
@@ -155,7 +176,11 @@ static int vout_Create( vout_thread_t *p_vout )
     }
 
     p_vout->p_sys->b_cursor = 1; /* TODO should be done with a main_GetInt.. */
-    p_vout->p_sys->b_fullscreen = main_GetIntVariable( VOUT_FULLSCREEN_VAR,
+
+    p_vout->p_sys->b_cursor_autohidden = 0;
+    p_vout->p_sys->i_lastmoved = mdate();
+
+    p_vout->b_fullscreen = main_GetIntVariable( VOUT_FULLSCREEN_VAR,
                                 VOUT_FULLSCREEN_DEFAULT );
     p_vout->p_sys->b_overlay = main_GetIntVariable( VOUT_OVERLAY_VAR,
                                 VOUT_OVERLAY_DEFAULT );
@@ -198,7 +223,8 @@ static int vout_Create( vout_thread_t *p_vout )
     intf_AssignKey(p_intf, SDLK_c,      INTF_KEY_TOGGLE_GRAYSCALE, 0);
     intf_AssignKey(p_intf, SDLK_SPACE,  INTF_KEY_TOGGLE_INTERFACE, 0);
     intf_AssignKey(p_intf, SDLK_i,      INTF_KEY_TOGGLE_INFO, 0);
-    intf_AssignKey(p_intf, SDLK_s,      INTF_KEY_TOGGLE_SCALING, 0); }
+    intf_AssignKey(p_intf, SDLK_s,      INTF_KEY_TOGGLE_SCALING, 0);
+    intf_AssignKey(p_intf, SDLK_d,      INTF_KEY_DUMP_STREAM, 0); }
 
     return( 0 );
 }
@@ -213,11 +239,13 @@ static int vout_Init( vout_thread_t *p_vout )
     /* This hack is hugly, but hey, you are, too. */
 
     SDL_Overlay *   p_overlay;
-
-    p_overlay = SDL_CreateYUVOverlay( VOUT_WIDTH_DEFAULT, VOUT_HEIGHT_DEFAULT,
+    
+    p_overlay = SDL_CreateYUVOverlay( 
+           main_GetIntVariable( VOUT_WIDTH_VAR,VOUT_WIDTH_DEFAULT ),
+           main_GetIntVariable( VOUT_HEIGHT_VAR,VOUT_HEIGHT_DEFAULT ),
                                       SDL_YV12_OVERLAY, 
                                       p_vout->p_sys->p_display );
-    intf_Msg( "vout: YUV acceleration %s",
+    intf_WarnMsg( 2, "vout: YUV acceleration %s",
               p_overlay->hw_overlay ? "activated" : "unavailable !" ); 
     p_vout->b_need_render = !p_overlay->hw_overlay;
 
@@ -256,7 +284,7 @@ static void vout_Destroy( vout_thread_t *p_vout )
 static int vout_Manage( vout_thread_t *p_vout )
 {
     SDL_Event event;                                            /* SDL event */
-    Uint8   i_key;
+    char *    p_key;
 
     /* Process events */
     while( SDL_PollEvent(&event) )
@@ -269,6 +297,22 @@ static int vout_Manage( vout_thread_t *p_vout )
             p_vout->i_changes |= VOUT_SIZE_CHANGE;
             break;
 
+        case SDL_MOUSEMOTION:
+            if( p_vout->p_sys->b_cursor &&
+                (abs(event.motion.xrel) > 2 || abs(event.motion.yrel) > 2) )
+            {
+                if( p_vout->p_sys->b_cursor_autohidden )
+                {
+                    p_vout->p_sys->b_cursor_autohidden = 0;
+                    SDL_ShowCursor( 1 );
+                }
+                else
+                {
+                    p_vout->p_sys->i_lastmoved = mdate();
+                }
+            }
+            break;
+
         case SDL_MOUSEBUTTONUP:
             switch( event.button.button )
             {
@@ -292,9 +336,8 @@ static int vout_Manage( vout_thread_t *p_vout )
             break;
 
         case SDL_KEYDOWN:                             /* if a key is pressed */
-            i_key = event.key.keysym.sym;
 
-            switch( i_key )
+            switch( event.key.keysym.sym )
             {
             case SDLK_f:                             /* switch to fullscreen */
                 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
@@ -323,11 +366,51 @@ static int vout_Manage( vout_thread_t *p_vout )
                 p_vout->b_interface = ! p_vout->b_interface;
                 p_vout->i_changes |= VOUT_INTF_CHANGE;
                 break;
+            
+            case SDLK_F10:
+                network_ChannelJoin( 0 );
+                break;
+            case SDLK_F1:
+                network_ChannelJoin( 1 );
+                break;
+            case SDLK_F2:
+                network_ChannelJoin( 2 );
+                break;
+            case SDLK_F3:
+                network_ChannelJoin( 3 );
+                break;
+            case SDLK_F4:
+                network_ChannelJoin( 4 );
+                break;
+            case SDLK_F5:
+                network_ChannelJoin( 5 );
+                break;
+            case SDLK_F6:
+                network_ChannelJoin( 6 );
+                break;
+            case SDLK_F7:
+                network_ChannelJoin( 7 );
+                break;
+            case SDLK_F8:
+                network_ChannelJoin( 8 );
+                break;
+            case SDLK_F9:
+                network_ChannelJoin( 9 );
+                break;
 
+            case SDLK_MENU:
+                p_main->p_intf->b_menu_change = 1;
+                break;
+                
             default:
-                if( intf_ProcessKey( p_main->p_intf, (char )i_key ) )
+                p_key = SDL_GetKeyName( event.key.keysym.sym ) ;
+                if( intf_ProcessKey( p_main->p_intf, 
+                                     (char )event.key.keysym.sym ) )
                 {
-                   intf_DbgMsg( "unhandled key '%c' (%i)", (char)i_key, i_key );                }
+                   intf_DbgMsg( "unhandled key '%c' (%i)", 
+                                (char)event.key.keysym.sym, 
+                                event.key.keysym.sym );                
+                }
                 break;
             }
             break;
@@ -377,41 +460,35 @@ static int vout_Manage( vout_thread_t *p_vout )
      */
     if( p_vout->i_changes & VOUT_FULLSCREEN_CHANGE )
     {
-        p_vout->p_sys->b_fullscreen = ! p_vout->p_sys->b_fullscreen;
-
-        if( p_vout->p_sys->b_fullscreen )
-        {
-            p_vout->p_sys->b_fullscreen = 0;
-            p_vout->p_sys->b_cursor = 1;
-            SDL_ShowCursor( 1 );
-        }
-        else
-        {
-            p_vout->p_sys->b_fullscreen = 1;
-            p_vout->p_sys->b_cursor = 0;
-            SDL_ShowCursor( 0 );
-        }
+        p_vout->b_fullscreen = ! p_vout->b_fullscreen;
 
         SDL_WM_ToggleFullScreen(p_vout->p_sys->p_display);
 
+        p_vout->p_sys->b_cursor_autohidden = 0;
+        SDL_ShowCursor( p_vout->p_sys->b_cursor &&
+                        ! p_vout->p_sys->b_cursor_autohidden );
+
         p_vout->i_changes &= ~VOUT_FULLSCREEN_CHANGE;
     }
 
     /*
      * Pointer change
      */
+    if( ! p_vout->p_sys->b_cursor_autohidden &&
+        ( mdate() - p_vout->p_sys->i_lastmoved > 2000000 ) )
+    {
+        /* Hide the mouse automatically */
+        p_vout->p_sys->b_cursor_autohidden = 1;
+        SDL_ShowCursor( 0 );
+    }
+
     if( p_vout->i_changes & VOUT_CURSOR_CHANGE )
     {
-        if( p_vout->p_sys->b_cursor )
-        {
-            SDL_ShowCursor( 0 );
-            p_vout->p_sys->b_cursor = 0;
-        }
-        else
-        {
-            SDL_ShowCursor( 1 );
-            p_vout->p_sys->b_cursor = 1;
-        }
+        p_vout->p_sys->b_cursor = ! p_vout->p_sys->b_cursor;
+
+        SDL_ShowCursor( p_vout->p_sys->b_cursor &&
+                        ! p_vout->p_sys->b_cursor_autohidden );
+
         p_vout->i_changes &= ~VOUT_CURSOR_CHANGE;
     }
     
@@ -466,7 +543,6 @@ static void vout_Display( vout_thread_t *p_vout )
         }
         else
         {
-        
             /*
              * p_vout->p_rendered_pic->p_y/u/v contains the YUV buffers to
              * render 
@@ -481,8 +557,8 @@ static void vout_Display( vout_thread_t *p_vout )
                                              SDL_YV12_OVERLAY, 
                                              p_vout->p_sys->p_display
                                            );
-                intf_Msg("vout: YUV acceleration %s",
-                            p_vout->p_sys->p_overlay->hw_overlay
+                intf_WarnMsg( 2, "vout: YUV acceleration %s",
+                              p_vout->p_sys->p_overlay->hw_overlay
                             ? "activated" : "unavailable !" ); 
             }
 
@@ -535,21 +611,29 @@ static int SDLOpenDisplay( vout_thread_t *p_vout )
     /* init flags and cursor */
     flags = SDL_ANYFORMAT | SDL_HWPALETTE;
 
-    if( p_vout->p_sys->b_fullscreen )
+    if( p_vout->b_fullscreen )
+    {
         flags |= SDL_FULLSCREEN;
+    }
     else
+    {
         flags |= SDL_RESIZABLE;
+    }
 
     if( p_vout->b_need_render )
+    {
         flags |= SDL_HWSURFACE | SDL_DOUBLEBUF;
+    }
     else
+    {
         flags |= SDL_SWSURFACE; /* save video memory */
+    }
 
     bpp = SDL_VideoModeOK( p_vout->p_sys->i_width,
                            p_vout->p_sys->i_height,
                            p_vout->i_screen_depth, flags );
 
-    if(bpp == 0)
+    if( bpp == 0 )
     {
         intf_ErrMsg( "vout error: no video mode available" );
         return( 1 );
@@ -565,12 +649,7 @@ static int SDLOpenDisplay( vout_thread_t *p_vout )
         return( 1 );
     }
 
-    SDL_LockSurface(p_vout->p_sys->p_display);
-
-    if( p_vout->p_sys->b_fullscreen )
-        SDL_ShowCursor( 0 );
-    else
-        SDL_ShowCursor( 1 );
+    SDL_LockSurface( p_vout->p_sys->p_display );
 
     SDL_WM_SetCaption( VOUT_TITLE " (SDL output)",
                        VOUT_TITLE " (SDL output)" );
@@ -606,8 +685,8 @@ static int SDLOpenDisplay( vout_thread_t *p_vout )
 
         /* FIXME: palette in 8bpp ?? */
         /* Set and initialize buffers */
-        vout_SetBuffers( p_vout, p_vout->p_sys->p_sdl_buf[ 0 ],
-                                 p_vout->p_sys->p_sdl_buf[ 1 ] );
+        p_vout->pf_setbuffers( p_vout, p_vout->p_sys->p_sdl_buf[ 0 ],
+                                       p_vout->p_sys->p_sdl_buf[ 1 ] );
     }
     else
     {
@@ -619,8 +698,8 @@ static int SDLOpenDisplay( vout_thread_t *p_vout )
         p_vout->i_height =          p_vout->p_sys->p_display->h;
         p_vout->i_bytes_per_line =  p_vout->p_sys->p_display->pitch;
 
-        vout_SetBuffers( p_vout, p_vout->p_sys->p_sdl_buf[ 0 ],
-                                 p_vout->p_sys->p_sdl_buf[ 1 ] );
+        p_vout->pf_setbuffers( p_vout, p_vout->p_sys->p_sdl_buf[ 0 ],
+                                       p_vout->p_sys->p_sdl_buf[ 1 ] );
     }
 
     p_vout->p_sys->b_reopen_display = 0;