]> git.sesse.net Git - vlc/blobdiff - plugins/sdl/vout_sdl.c
* Ported Glide and MGA plugins to the new module API. MGA never worked,
[vlc] / plugins / sdl / vout_sdl.c
index 48b2692a100e50a633d22bc05c73522cc83c97fa..73a8a24137383c4201a7810f59a8f287ca9177c9 100644 (file)
@@ -3,7 +3,9 @@
  *****************************************************************************
  * Copyright (C) 1998, 1999, 2000 VideoLAN
  *
- * Authors:
+ * Authors: Samuel Hocevar <sam@zoy.org>
+ *          Pierre Baillet <oct@zoy.org>
+ *          Arnaud de Bossoreille de Ribou <bozo@via.ecp.fr>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -20,6 +22,9 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
  *****************************************************************************/
 
+#define MODULE_NAME sdl
+#include "modules_inner.h"
+
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
 #include "tests.h"
 #include "modules.h"
 
-/* FIXME: it's up to the _interface_ to do this, not the video output */
-#include "stream_control.h"
-#include "input_ext-intf.h"
-
 #include "video.h"
 #include "video_output.h"
 
 /*****************************************************************************
  * FIXME: this file is ...                                                   *
  *                                                                           *
- *    XXX     XXX         XXX XXX     XXX             XXX     XXX     XXX    *
- *    XXX     XXX     XXX             XXX             XXX     XXX     XXX    *
- *    XXX     XXX     XXX             XXX                 XXX         XXX    *
- *    XXX     XXX     XXX     XXX     XXX                 XXX         XXX    *
- *    XXX     XXX     XXX     XXX     XXX                 XXX                *
- *        XXX             XXX XXX         XXX XXX         XXX         XXX    *
+ *              XXX   XXX     FIXME     XXX     XXX   XXX   XXX              *
+ *              XXX   XXX   XXX   XXX   XXX     XXX   XXX   XXX              *
+ *              XXX   XXX   XXX         XXX       FIXME     XXX              *
+ *              XXX   XXX   XXX  TODO   XXX        XXX      XXX              *
+ *              XXX   XXX   XXX   XXX   XXX        XXX                       *
+ *                FIXME       FIXME       FIXME    XXX      XXX              *
  *                                                                           *
  *****************************************************************************/
 
@@ -79,9 +80,8 @@ typedef struct vout_sys_s
     boolean_t   b_overlay;
     boolean_t   b_cursor;
     boolean_t   b_reopen_display;
-    Uint8   *   p_buffer[2];
-                                                     /* Buffers informations */
-}   vout_sys_t;
+    Uint8   *   p_sdl_buf[2];                          /* Buffer information */
+} vout_sys_t;
 
 /*****************************************************************************
  * Local prototypes.
@@ -93,6 +93,8 @@ static void vout_End       ( struct vout_thread_s * );
 static void vout_Destroy   ( struct vout_thread_s * );
 static int  vout_Manage    ( struct vout_thread_s * );
 static void vout_Display   ( struct vout_thread_s * );
+static void vout_SetPalette( p_vout_thread_t p_vout, u16 *red, u16 *green,
+                             u16 *blue, u16 *transp );
 
 static int  SDLOpenDisplay      ( vout_thread_t *p_vout );
 static void SDLCloseDisplay     ( vout_thread_t *p_vout );
@@ -101,7 +103,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;
@@ -110,11 +112,11 @@ void vout_getfunctions( function_list_t * p_function_list )
     p_function_list->functions.vout.pf_destroy    = vout_Destroy;
     p_function_list->functions.vout.pf_manage     = vout_Manage;
     p_function_list->functions.vout.pf_display    = vout_Display;
-    p_function_list->functions.vout.pf_setpalette = NULL;
+    p_function_list->functions.vout.pf_setpalette = vout_SetPalette;
 }
 
 /*****************************************************************************
- * intf_Probe: probe the video driver and return a score
+ * vout_Probe: probe the video driver and return a score
  *****************************************************************************
  * This function tries to initialize SDL and returns a score to the
  * plugin manager so that it can select the best plugin.
@@ -126,7 +128,7 @@ static int vout_Probe( probedata_t *p_data )
         return( 999 );
     }
 
-    return( 40 );
+    return( 100 );
 }
 
 /*****************************************************************************
@@ -136,7 +138,7 @@ static int vout_Probe( probedata_t *p_data )
  * vout properties to choose the correct mode, and change them according to the
  * mode actually used.
  *****************************************************************************/
-int vout_Create( vout_thread_t *p_vout )
+static int vout_Create( vout_thread_t *p_vout )
 {
     /* Allocate structure */
     p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
@@ -155,12 +157,6 @@ int vout_Create( vout_thread_t *p_vout )
         return( 1 );
     }
 
-    /* Force the software yuv even if it is not used */
-    /* If we don't do this, p_vout is not correctly initialized
-       and it's impossible to switch between soft/hard yuv */
-    /* FIXME: this is a broken way to do !! fix this !! */
-    p_vout->b_need_render = 1;
-
     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,
                                 VOUT_FULLSCREEN_DEFAULT );
@@ -176,14 +172,13 @@ int vout_Create( vout_thread_t *p_vout )
 
     if( SDLOpenDisplay(p_vout) )
     {
-        intf_ErrMsg( "vout error: can't initialize SDL (%s)", SDL_GetError() );
+        intf_ErrMsg( "vout error: can't set up SDL (%s)", SDL_GetError() );
         free( p_vout->p_sys );
         return( 1 );
     }
 
     /* FIXME: get rid of this ASAP, it's FUCKING UGLY */
     { intf_thread_t * p_intf = p_main->p_intf;
-    /* p_intf->p_intf_getKey = intf_getKey; */
     intf_AssignKey(p_intf, SDLK_q,      INTF_KEY_QUIT, 0);
     intf_AssignKey(p_intf, SDLK_ESCAPE, INTF_KEY_QUIT, 0);
     /* intf_AssignKey(p_intf,3,'Q'); */
@@ -216,8 +211,21 @@ int vout_Create( vout_thread_t *p_vout )
  *****************************************************************************
  * This function initialize the SDL display device.
  *****************************************************************************/
-int vout_Init( vout_thread_t *p_vout )
+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,
+                                      SDL_YV12_OVERLAY, 
+                                      p_vout->p_sys->p_display );
+    intf_Msg( "vout: YUV acceleration %s",
+              p_overlay->hw_overlay ? "activated" : "unavailable !" ); 
+    p_vout->b_need_render = !p_overlay->hw_overlay;
+
+    SDL_FreeYUVOverlay( p_overlay );
+
     return( 0 );
 }
 
@@ -226,7 +234,7 @@ int vout_Init( vout_thread_t *p_vout )
  *****************************************************************************
  * Terminate an output method created by vout_SDLCreate
  *****************************************************************************/
-void vout_End( vout_thread_t *p_vout )
+static void vout_End( vout_thread_t *p_vout )
 {
     SDLCloseDisplay( p_vout );
     SDL_Quit();
@@ -237,7 +245,7 @@ void vout_End( vout_thread_t *p_vout )
  *****************************************************************************
  * Terminate an output method created by vout_SDLCreate
  *****************************************************************************/
-void vout_Destroy( vout_thread_t *p_vout )
+static void vout_Destroy( vout_thread_t *p_vout )
 {
     free( p_vout->p_sys );
 }
@@ -248,14 +256,10 @@ void vout_Destroy( vout_thread_t *p_vout )
  * This function should be called regularly by video output thread. It returns
  * a non null value if an error occured.
  *****************************************************************************/
-int vout_Manage( vout_thread_t *p_vout )
+static int vout_Manage( vout_thread_t *p_vout )
 {
     SDL_Event event;                                            /* SDL event */
     Uint8   i_key;
-    int     i_rate;
-
-    /* FIXME: do this nicely */
-    input_thread_t * p_input = p_main->p_intf->p_input;
 
     /* Process events */
     while( SDL_PollEvent(&event) )
@@ -268,16 +272,21 @@ int vout_Manage( vout_thread_t *p_vout )
             p_vout->i_changes |= VOUT_SIZE_CHANGE;
             break;
 
+        case SDL_MOUSEBUTTONUP:
+            switch( event.button.button )
+            {
+            case SDL_BUTTON_RIGHT:
+                p_main->p_intf->b_menu_change = 1;
+                break;
+            }
+            break;
+
         case SDL_MOUSEBUTTONDOWN:
             switch( event.button.button )
             {
             case SDL_BUTTON_MIDDLE:
                 p_vout->i_changes |= VOUT_CURSOR_CHANGE;
                 break;
-
-            case SDL_BUTTON_RIGHT:
-                p_main->p_intf->b_menu_change = 1;
-                break;
             }
             break;
 
@@ -300,81 +309,22 @@ int vout_Manage( vout_thread_t *p_vout )
 
             case SDLK_c:                                 /* toggle grayscale */
                 p_vout->b_grayscale = ! p_vout->b_grayscale;
-                       p_vout->i_changes |= VOUT_GRAYSCALE_CHANGE;
+                p_vout->i_changes |= VOUT_GRAYSCALE_CHANGE;
                 break;
 
             case SDLK_i:                                      /* toggle info */
                 p_vout->b_info = ! p_vout->b_info;
-                       p_vout->i_changes |= VOUT_INFO_CHANGE;
+                p_vout->i_changes |= VOUT_INFO_CHANGE;
                 break;
 
-           case SDLK_s:                                   /* toggle scaling */
+            case SDLK_s:                                   /* toggle scaling */
                 p_vout->b_scale = ! p_vout->b_scale;
-                       p_vout->i_changes |= VOUT_SCALE_CHANGE;
+                p_vout->i_changes |= VOUT_SCALE_CHANGE;
                 break;
 
-           case SDLK_SPACE:                             /* toggle interface */
+            case SDLK_SPACE:                             /* toggle interface */
                 p_vout->b_interface = ! p_vout->b_interface;
-                       p_vout->i_changes |= VOUT_INTF_CHANGE;
-                break;
-
-            /* FIXME : this is temporary */
-            case SDLK_p:
-                if( p_input != NULL )
-                {
-                    if( p_input->stream.control.i_status == PLAYING_S )
-                    {
-                        input_Pause( p_input );
-                    }
-                    else
-                    {
-                        input_Play( p_input );
-                    }
-                }
-                break;
-
-            case SDLK_a:
-                if( p_input != NULL )
-                {
-                    i_rate = p_input->stream.control.i_rate/2;
-                    if ( i_rate >= MINIMAL_RATE )
-                    {
-                        input_Forward( p_input, i_rate );
-                    }
-                }
-                break;
-
-            case SDLK_z:
-                if( p_input != NULL )
-                {
-                    i_rate = p_input->stream.control.i_rate*2;
-                    if ( i_rate <= MAXIMAL_RATE )
-                    {
-                        /* Compensation of int truncature */
-                        if ( i_rate > 500 && i_rate < 1000 )
-                            i_rate = 1000;
-                        input_Forward( p_input, i_rate );
-                    }
-                }
-                break;
-
-            case SDLK_j:
-                if( p_input != NULL )
-                {
-                    /* Jump forwards */
-                    input_Seek( p_input, p_input->stream.i_tell
-                                 + p_input->stream.i_size / 20 );
-                                                               /* gabuzomeu */
-                }
-                break;
-
-            case SDLK_b:
-                if( p_input != NULL )
-                {
-                    /* Jump backwards */
-                    input_Seek( p_input, p_input->stream.i_tell
-                                 - p_input->stream.i_size / 20 );
-                }
+                p_vout->i_changes |= VOUT_INTF_CHANGE;
                 break;
 
             default:
@@ -402,7 +352,7 @@ int vout_Manage( vout_thread_t *p_vout )
         SDLCloseDisplay( p_vout );
         if( SDLOpenDisplay( p_vout ) )
         {
-          intf_ErrMsg( "error: can't open DISPLAY default display" );
+          intf_ErrMsg( "vout error: can't reopen display after resize" );
           return( 1 );
         }
         p_vout->i_changes &= ~VOUT_SIZE_CHANGE;
@@ -419,7 +369,7 @@ int vout_Manage( vout_thread_t *p_vout )
         SDLCloseDisplay( p_vout );
         if( SDLOpenDisplay( p_vout ) )
         {
-          intf_ErrMsg( "error: can't open DISPLAY default display" );
+          intf_ErrMsg( "error: can't reopen display after YUV change" );
           return( 1 );
         }
         p_vout->i_changes &= ~VOUT_YUV_CHANGE;
@@ -478,7 +428,7 @@ int vout_Manage( vout_thread_t *p_vout )
  * anything, but could later send information on which colors it was unable
  * to set.
  *****************************************************************************/
-void vout_SetPalette( p_vout_thread_t p_vout, u16 *red, u16 *green,
+static void vout_SetPalette( p_vout_thread_t p_vout, u16 *red, u16 *green,
                          u16 *blue, u16 *transp)
 {
      /* Create a display surface with a grayscale palette */
@@ -507,7 +457,7 @@ void vout_SetPalette( p_vout_thread_t p_vout, u16 *red, u16 *green,
  * This function send the currently rendered image to the display, wait until
  * it is displayed and switch the two rendering buffer, preparing next frame.
  *****************************************************************************/
-void vout_Display( vout_thread_t *p_vout )
+static void vout_Display( vout_thread_t *p_vout )
 {
     SDL_Rect    disp;
     if((p_vout->p_sys->p_display != NULL) && !p_vout->p_sys->b_reopen_display)
@@ -598,13 +548,13 @@ static int SDLOpenDisplay( vout_thread_t *p_vout )
     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);
+    bpp = SDL_VideoModeOK( p_vout->p_sys->i_width,
+                           p_vout->p_sys->i_height,
+                           p_vout->i_screen_depth, flags );
 
     if(bpp == 0)
     {
-        intf_ErrMsg( "error: can't open DISPLAY default display" );
+        intf_ErrMsg( "vout error: no video mode available" );
         return( 1 );
     }
 
@@ -614,7 +564,7 @@ static int SDLOpenDisplay( vout_thread_t *p_vout )
 
     if( p_vout->p_sys->p_display == NULL )
     {
-        intf_ErrMsg( "error: can't open DISPLAY default display" );
+        intf_ErrMsg( "vout error: cannot set video mode" );
         return( 1 );
     }
 
@@ -625,15 +575,15 @@ static int SDLOpenDisplay( vout_thread_t *p_vout )
     else
         SDL_ShowCursor( 1 );
 
-    SDL_WM_SetCaption( VOUT_TITLE , VOUT_TITLE );
+    SDL_WM_SetCaption( VOUT_TITLE " (SDL output)",
+                       VOUT_TITLE " (SDL output)" );
     SDL_EventState(SDL_KEYUP , SDL_IGNORE);                /* ignore keys up */
-    SDL_EventState(SDL_MOUSEBUTTONUP, SDL_IGNORE);          
 
     if( p_vout->b_need_render )
     {
-        p_vout->p_sys->p_buffer[ 0 ] = p_vout->p_sys->p_display->pixels;
+        p_vout->p_sys->p_sdl_buf[ 0 ] = p_vout->p_sys->p_display->pixels;
         SDL_Flip(p_vout->p_sys->p_display);
-        p_vout->p_sys->p_buffer[ 1 ] = p_vout->p_sys->p_display->pixels;
+        p_vout->p_sys->p_sdl_buf[ 1 ] = p_vout->p_sys->p_display->pixels;
         SDL_Flip(p_vout->p_sys->p_display);
 
         /* Set clipping for text */
@@ -659,21 +609,21 @@ 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_buffer[ 0 ],
-                                 p_vout->p_sys->p_buffer[ 1 ] );
+        vout_SetBuffers( p_vout, p_vout->p_sys->p_sdl_buf[ 0 ],
+                                 p_vout->p_sys->p_sdl_buf[ 1 ] );
     }
     else
     {
-        p_vout->p_sys->p_buffer[ 0 ] = p_vout->p_sys->p_display->pixels;
-        p_vout->p_sys->p_buffer[ 1 ] = p_vout->p_sys->p_display->pixels;
+        p_vout->p_sys->p_sdl_buf[ 0 ] = p_vout->p_sys->p_display->pixels;
+        p_vout->p_sys->p_sdl_buf[ 1 ] = p_vout->p_sys->p_display->pixels;
 
         /* Set thread information */
         p_vout->i_width =           p_vout->p_sys->p_display->w;
         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_buffer[ 0 ],
-                                 p_vout->p_sys->p_buffer[ 1 ] );
+        vout_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;