]> git.sesse.net Git - vlc/blobdiff - src/video_output/video_output.c
* Ported Glide and MGA plugins to the new module API. MGA never worked,
[vlc] / src / video_output / video_output.c
index a441ead96bcc25f7c146875c758fcccb046de11f..6d48fd4b7c1925cc6fa0b6767fb35bdc593b3933 100644 (file)
@@ -41,7 +41,8 @@
 #include "common.h"
 #include "threads.h"
 #include "mtime.h"
-#include "plugins.h"
+#include "modules.h"
+
 #include "video.h"
 #include "video_output.h"
 #include "video_text.h"
@@ -49,6 +50,7 @@
 #include "video_yuv.h"
 
 #include "intf_msg.h"
+
 #include "main.h"
 
 /*****************************************************************************
@@ -90,15 +92,11 @@ static void     SetPalette        ( p_vout_thread_t p_vout, u16 *red,
  * If pi_status is NULL, then the function will block until the thread is ready.
  * If not, it will be updated using one of the THREAD_* constants.
  *****************************************************************************/
-vout_thread_t * vout_CreateThread   ( char *psz_display, int i_root_window,
-                          int i_width, int i_height, int *pi_status,
-                          int i_method, void *p_data )
+vout_thread_t * vout_CreateThread   ( int *pi_status )
 {
     vout_thread_t * p_vout;                             /* thread descriptor */
-    typedef void    ( vout_getplugin_t ) ( vout_thread_t * p_vout );
     int             i_status;                               /* thread status */
     int             i_index;               /* index for array initialization */
-    int             i_best_index = 0, i_best_score = 0;
 
     /* Allocate descriptor */
     p_vout = (vout_thread_t *) malloc( sizeof(vout_thread_t) );
@@ -109,37 +107,31 @@ vout_thread_t * vout_CreateThread   ( char *psz_display, int i_root_window,
         return( NULL );
     }
 
-    p_vout->p_set_palette       = SetPalette;
+    /* Choose the best module */
+    p_vout->p_module = module_Need( p_main->p_bank,
+                                    MODULE_CAPABILITY_VOUT, NULL );
 
-    /* Get a suitable video plugin */
-    for( i_index = 0 ; i_index < p_main->p_bank->i_plugin_count ; i_index++ )
-    {
-        /* If there's a plugin in p_info ... */
-        if( p_main->p_bank->p_info[ i_index ] != NULL )
-        {
-            /* ... and if this plugin provides the functions we want ... */
-            if( p_main->p_bank->p_info[ i_index ]->vout_GetPlugin != NULL )
-            {
-                /* ... and if this plugin has a good score ... */
-                if( p_main->p_bank->p_info[ i_index ]->i_score > i_best_score )
-                {
-                    /* ... then take it */
-                    i_best_score = p_main->p_bank->p_info[ i_index ]->i_score;
-                    i_best_index = i_index;
-                }
-            }
-        }
-    }
-
-    if( i_best_score == 0 )
+    if( p_vout->p_module == NULL )
     {
+        intf_ErrMsg( "vout error: no suitable vout module" );
         free( p_vout );
         return( NULL );
     }
 
-    /* Get the plugin functions */
-    ( (vout_getplugin_t *)
-      p_main->p_bank->p_info[ i_best_index ]->vout_GetPlugin )( p_vout );
+#define f p_vout->p_module->p_functions->vout.functions.vout
+    p_vout->pf_create     = f.pf_create;
+    p_vout->pf_init       = f.pf_init;
+    p_vout->pf_end        = f.pf_end;
+    p_vout->pf_destroy    = f.pf_destroy;
+    p_vout->pf_manage     = f.pf_manage;
+    p_vout->pf_display    = f.pf_display;
+    p_vout->pf_setpalette = f.pf_setpalette;
+#undef f
+
+    if( p_vout->pf_setpalette == NULL )
+    {
+        p_vout->pf_setpalette = SetPalette;
+    }
 
     /* Initialize thread properties - thread id and locks will be initialized
      * later */
@@ -153,23 +145,25 @@ vout_thread_t * vout_CreateThread   ( char *psz_display, int i_root_window,
      * fields will probably be modified by the method, and are only
      * preferences */
     p_vout->i_changes             = 0;
-    p_vout->i_width               = i_width;
-    p_vout->i_height              = i_height;
-    p_vout->i_bytes_per_line      = i_width * 2;
+    p_vout->i_width               = main_GetIntVariable( VOUT_WIDTH_VAR,
+                                                         VOUT_WIDTH_DEFAULT );
+    p_vout->i_height              = main_GetIntVariable( VOUT_HEIGHT_VAR,
+                                                         VOUT_HEIGHT_DEFAULT );
+    p_vout->i_bytes_per_line      = p_vout->i_width * 2;
     p_vout->i_screen_depth        = 15;
     p_vout->i_bytes_per_pixel     = 2;
     p_vout->f_gamma               = VOUT_GAMMA;
     p_vout->b_need_render         = 1;
 
     p_vout->b_grayscale           = main_GetIntVariable( VOUT_GRAYSCALE_VAR,
-                                                       VOUT_GRAYSCALE_DEFAULT );
+                                                     VOUT_GRAYSCALE_DEFAULT );
     p_vout->b_info                = 0;
     p_vout->b_interface           = 0;
     p_vout->b_scale               = 1;
 
-    intf_DbgMsg( "wished configuration: %dx%d, %d/%d bpp (%d Bpl)",
-                 p_vout->i_width, p_vout->i_height, p_vout->i_screen_depth,
-                 p_vout->i_bytes_per_pixel * 8, p_vout->i_bytes_per_line );
+    intf_WarnMsg( 1, "wished configuration: %dx%d, %d/%d bpp (%d Bpl)",
+                  p_vout->i_width, p_vout->i_height, p_vout->i_screen_depth,
+                  p_vout->i_bytes_per_pixel * 8, p_vout->i_bytes_per_line );
 
     /* Initialize idle screen */
     p_vout->last_display_date   = 0;
@@ -199,17 +193,18 @@ vout_thread_t * vout_CreateThread   ( char *psz_display, int i_root_window,
 
     /* Create and initialize system-dependant method - this function issues its
      * own error messages */
-    if( p_vout->p_sys_create( p_vout, psz_display, i_root_window, p_data ) )
+    if( p_vout->pf_create( p_vout ) )
     {
+        module_Unneed( p_main->p_bank, p_vout->p_module );
         free( p_vout );
         return( NULL );
     }
-    intf_DbgMsg( "actual configuration: %dx%d, %d/%d bpp (%d Bpl), "
-                 "masks: 0x%x/0x%x/0x%x",
-                 p_vout->i_width, p_vout->i_height, p_vout->i_screen_depth,
-                 p_vout->i_bytes_per_pixel * 8, p_vout->i_bytes_per_line,
-                 p_vout->i_red_mask, p_vout->i_green_mask,
-                 p_vout->i_blue_mask );
+    intf_WarnMsg( 1, "actual configuration: %dx%d, %d/%d bpp (%d Bpl), "
+                  "masks: 0x%x/0x%x/0x%x",
+                  p_vout->i_width, p_vout->i_height, p_vout->i_screen_depth,
+                  p_vout->i_bytes_per_pixel * 8, p_vout->i_bytes_per_line,
+                  p_vout->i_red_mask, p_vout->i_green_mask,
+                  p_vout->i_blue_mask );
 
     /* Calculate shifts from system-updated masks */
     MaskToShift( &p_vout->i_red_lshift, &p_vout->i_red_rshift,
@@ -227,28 +222,21 @@ vout_thread_t * vout_CreateThread   ( char *psz_display, int i_root_window,
 
     /* Load fonts - fonts must be initialized after the system method since
      * they may be dependant on screen depth and other thread properties */
-    p_vout->p_default_font = vout_LoadFont( DATA_PATH "/" VOUT_DEFAULT_FONT );
-    if( p_vout->p_default_font == NULL )
-    {
-        p_vout->p_default_font = vout_LoadFont( "share/" VOUT_DEFAULT_FONT );
-    }
+    p_vout->p_default_font = vout_LoadFont( VOUT_DEFAULT_FONT );
     if( p_vout->p_default_font == NULL )
     {
         intf_ErrMsg( "vout error: could not load default font" );
-        p_vout->p_sys_destroy( p_vout );
+        p_vout->pf_destroy( p_vout );
         free( p_vout );
         return( NULL );
     }
-    p_vout->p_large_font = vout_LoadFont( DATA_PATH "/" VOUT_LARGE_FONT );
-    if( p_vout->p_large_font == NULL )
-    {
-        p_vout->p_large_font = vout_LoadFont( "share/" VOUT_LARGE_FONT );
-    }
+
+    p_vout->p_large_font = vout_LoadFont( VOUT_LARGE_FONT );
     if( p_vout->p_large_font == NULL )
     {
         intf_ErrMsg( "vout error: could not load large font" );
         vout_UnloadFont( p_vout->p_default_font );
-        p_vout->p_sys_destroy( p_vout );
+        p_vout->pf_destroy( p_vout );
         free( p_vout );
         return( NULL );
     }
@@ -264,13 +252,13 @@ vout_thread_t * vout_CreateThread   ( char *psz_display, int i_root_window,
         intf_ErrMsg("vout error: %s", strerror(ENOMEM));
         vout_UnloadFont( p_vout->p_default_font );
         vout_UnloadFont( p_vout->p_large_font );
-        p_vout->p_sys_destroy( p_vout );
+        p_vout->pf_destroy( p_vout );
         free( p_vout );
         return( NULL );
     }
 
-    intf_Msg( "Video display initialized (%dx%d, %d/%d bpp)", p_vout->i_width,
-              p_vout->i_height, p_vout->i_screen_depth,
+    intf_Msg( "vout: video display initialized (%dx%d, %d/%d bpp)",
+              p_vout->i_width, p_vout->i_height, p_vout->i_screen_depth,
               p_vout->i_bytes_per_pixel * 8 );
 
     /* If status is NULL, wait until the thread is created */
@@ -858,29 +846,29 @@ void vout_Pixel2RGB( vout_thread_t *p_vout, u32 i_pixel, int *pi_red, int *pi_gr
  *****************************************************************************/
 static int BinaryLog(u32 i)
 {
-    int i_log;
+    int i_log = 0;
 
-    i_log = 0;
-    if (i & 0xffff0000)
+    if(i & 0xffff0000)
     {
-        i_log = 16;
+        i_log += 16;
     }
-    if (i & 0xff00ff00)
+    if(i & 0xff00ff00)
     {
         i_log += 8;
     }
-    if (i & 0xf0f0f0f0)
+    if(i & 0xf0f0f0f0)
     {
         i_log += 4;
     }
-    if (i & 0xcccccccc)
+    if(i & 0xcccccccc)
     {
         i_log += 2;
     }
-    if (i & 0xaaaaaaaa)
+    if(i & 0xaaaaaaaa)
     {
-        i_log++;
+        i_log += 1;
     }
+
     if (i != ((u32)1 << i_log))
     {
         intf_DbgMsg("internal error: binary log overflow");
@@ -930,19 +918,16 @@ static int InitThread( vout_thread_t *p_vout )
 #endif
 
    /* Initialize output method - this function issues its own error messages */
-    if( p_vout->p_sys_init( p_vout ) )
+    if( p_vout->pf_init( p_vout ) )
     {
         return( 1 );
     }
 
-    if( p_vout->b_need_render )
+    /* Initialize convertion tables and functions */
+    if( vout_InitYUV( p_vout ) )
     {
-        /* Initialize convertion tables and functions */
-        if( vout_InitYUV( p_vout ) )
-        {
-            intf_ErrMsg("vout error: can't allocate YUV translation tables");
-            return( 1 );
-        }
+        intf_ErrMsg("vout error: can't allocate YUV translation tables");
+        return( 1 );
     }
 
     /* Mark thread as running and return */
@@ -1191,7 +1176,7 @@ static void RunThread( vout_thread_t *p_vout)
 #endif
         if( b_display /* && !(p_vout->i_changes & VOUT_NODISPLAY_CHANGE) */ )
         {
-            p_vout->p_sys_display( p_vout );
+            p_vout->pf_display( p_vout );
 #ifndef SYS_BEOS
             p_vout->i_buffer_index = ++p_vout->i_buffer_index & 1;
 #endif
@@ -1217,7 +1202,7 @@ static void RunThread( vout_thread_t *p_vout)
         /*
          * Check events and manage thread
          */
-        if( p_vout->p_sys_manage( p_vout ) | Manage( p_vout ) )
+        if( p_vout->pf_manage( p_vout ) | Manage( p_vout ) )
         {
             /* A fatal error occured, and the thread must terminate immediately,
              * without displaying anything - setting b_error to 1 cause the
@@ -1275,8 +1260,8 @@ static void EndThread( vout_thread_t *p_vout )
         struct tms cpu_usage;
         times( &cpu_usage );
 
-        intf_Msg("vout stats: cpu usage (user: %d, system: %d)",
-                 cpu_usage.tms_utime, cpu_usage.tms_stime);
+        intf_Msg( "vout stats: cpu usage (user: %d, system: %d)",
+                  cpu_usage.tms_utime, cpu_usage.tms_stime );
     }
 #endif
 
@@ -1288,6 +1273,7 @@ static void EndThread( vout_thread_t *p_vout )
             free( p_vout->p_picture[i_index].p_data );
         }
     }
+
     for( i_index = 0; i_index < VOUT_MAX_SUBPICTURES; i_index++ )
     {
         if( p_vout->p_subpicture[i_index].i_status != FREE_SUBPICTURE )
@@ -1298,7 +1284,10 @@ static void EndThread( vout_thread_t *p_vout )
 
     /* Destroy translation tables */
     vout_EndYUV( p_vout );
-    p_vout->p_sys_end( p_vout );
+    p_vout->pf_end( p_vout );
+
+    /* Release the change lock */
+    vlc_mutex_unlock( &p_vout->change_lock );
 }
 
 /*****************************************************************************
@@ -1317,13 +1306,16 @@ static void DestroyThread( vout_thread_t *p_vout, int i_status )
     /* Destroy thread structures allocated by Create and InitThread */
     vout_UnloadFont( p_vout->p_default_font );
     vout_UnloadFont( p_vout->p_large_font );
-    p_vout->p_sys_destroy( p_vout );
+    p_vout->pf_destroy( p_vout );
 
     /* Destroy the locks */
     vlc_mutex_destroy( &p_vout->picture_lock );
     vlc_mutex_destroy( &p_vout->subpicture_lock );
     vlc_mutex_destroy( &p_vout->change_lock );
                 
+    /* Release the module */
+    module_Unneed( p_main->p_bank, p_vout->p_module );
+
     /* Free structure */
     free( p_vout );
     *pi_status = i_status;
@@ -1831,12 +1823,14 @@ int RenderSplash( vout_thread_t *p_vout )
  *****************************************************************************/
 int RenderIdle( vout_thread_t *p_vout )
 {
+#if 0
     int         i_x = 0, i_y = 0;                           /* text position */
     int         i_width, i_height;                              /* text size */
-    mtime_t     current_date;                                /* current date */
     int         i_amount = 0;                             /*  amount to draw */
     char *psz_text =    "Waiting for stream";            /* text to display */
     char *psz_wtext =   "[................]";
+#endif
+    mtime_t     current_date;                                /* current date */
 
 
     memset( p_vout->p_buffer[ p_vout->i_buffer_index ].p_data,
@@ -1848,6 +1842,8 @@ int RenderIdle( vout_thread_t *p_vout )
 //            && (current_date - p_vout->last_idle_date) > VOUT_IDLE_DELAY 
     )
     {
+        /* FIXME: idle screen disabled */
+#if 0
         SetBufferPicture( p_vout, NULL );
         vout_TextSize( p_vout->p_large_font, WIDE_TEXT | OUTLINED_TEXT, psz_text,
                        &i_width, &i_height );
@@ -1871,6 +1867,7 @@ int RenderIdle( vout_thread_t *p_vout )
 
             SetBufferArea( p_vout, i_x, i_y, i_width, i_height * 2 );
         }
+#endif
         return( 1 );
     }
     return( 0 );
@@ -2064,14 +2061,15 @@ static int Manage( vout_thread_t *p_vout )
 
     /* Clear changes flags which does not need management or have been
      * handled */
-    p_vout->i_changes &= ~(VOUT_GAMMA_CHANGE | VOUT_GRAYSCALE_CHANGE |
-                           VOUT_YUV_CHANGE   | VOUT_INFO_CHANGE |
-                           VOUT_INTF_CHANGE  | VOUT_SCALE_CHANGE );
+    p_vout->i_changes &= ~(VOUT_GAMMA_CHANGE  | VOUT_GRAYSCALE_CHANGE |
+                           VOUT_YUV_CHANGE    | VOUT_INFO_CHANGE |
+                           VOUT_INTF_CHANGE   | VOUT_SCALE_CHANGE |
+                           VOUT_CURSOR_CHANGE | VOUT_FULLSCREEN_CHANGE );
 
     /* Detect unauthorized changes */
     if( p_vout->i_changes )
     {
-        /* Some changes were not acknowledged by p_vout->p_sys_manage or this
+        /* Some changes were not acknowledged by p_vout->pf_manage or this
          * function, it means they should not be authorized */
         intf_ErrMsg( "vout error: unauthorized changes in the vout thread" );
         return( 1 );