]> git.sesse.net Git - vlc/blobdiff - src/video_output/video_output.c
. rajout de l'option -Winline
[vlc] / src / video_output / video_output.c
index 0421499f7a650e84669d46d544e6fda55f333ecc..86a0a779be5e84c4ae6153f283e1a7d3d9bd940b 100644 (file)
@@ -12,7 +12,7 @@
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version.
- * 
+ *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
@@ -91,9 +91,10 @@ vout_thread_t * vout_CreateThread   ( char *psz_display, int i_root_window,
                           int i_method, void *p_data )
 {
     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 */
-    char *          psz_method;
+    int             i_best_index = 0, i_best_score = 0;
 
     /* Allocate descriptor */
     intf_DbgMsg("\n");
@@ -104,29 +105,37 @@ vout_thread_t * vout_CreateThread   ( char *psz_display, int i_root_window,
         return( NULL );
     }
 
-    /* Request an interface plugin */
-    psz_method = main_GetPszVariable( VOUT_METHOD_VAR, VOUT_DEFAULT_METHOD );
+    p_vout->p_set_palette       = SetPalette;
+
+    /* 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( RequestPlugin( &p_vout->vout_plugin, "vout", psz_method ) < 0 )
+    if( i_best_score == 0 )
     {
-        intf_ErrMsg( "error: could not open video plugin vout_%s.so\n", psz_method );
         free( p_vout );
         return( NULL );
     }
 
-    /* Get plugins */
-    p_vout->p_sys_create = 
-        GetPluginFunction( p_vout->vout_plugin, "vout_SysCreate" );
-    p_vout->p_sys_init =
-        GetPluginFunction( p_vout->vout_plugin, "vout_SysInit" );
-    p_vout->p_sys_end =
-        GetPluginFunction( p_vout->vout_plugin, "vout_SysEnd" );
-    p_vout->p_sys_destroy =
-        GetPluginFunction( p_vout->vout_plugin, "vout_SysDestroy" );
-    p_vout->p_sys_manage =
-        GetPluginFunction( p_vout->vout_plugin, "vout_SysManage" );
-    p_vout->p_sys_display =
-        GetPluginFunction( p_vout->vout_plugin, "vout_SysDisplay" );
+    /* Get the plugin functions */
+    ( (vout_getplugin_t *)
+      p_main->p_bank->p_info[ i_best_index ]->vout_GetPlugin )( p_vout );
 
     /* Initialize thread properties - thread id and locks will be initialized
      * later */
@@ -136,8 +145,9 @@ vout_thread_t * vout_CreateThread   ( char *psz_display, int i_root_window,
     p_vout->pi_status           = (pi_status != NULL) ? pi_status : &i_status;
     *p_vout->pi_status          = THREAD_CREATE;
 
-    /* Initialize some fields used by the system-dependant method - these fields will
-     * probably be modified by the method, and are only preferences */
+    /* Initialize some fields used by the system-dependant method - these
+     * 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;
@@ -152,8 +162,6 @@ vout_thread_t * vout_CreateThread   ( char *psz_display, int i_root_window,
     p_vout->b_interface         = 0;
     p_vout->b_scale             = 0;
 
-    p_vout->p_set_palette       = SetPalette;
-
     intf_DbgMsg( "wished configuration: %dx%d, %d/%d bpp (%d Bpl)\n",
                  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 );
@@ -186,26 +194,30 @@ vout_thread_t * vout_CreateThread   ( char *psz_display, int i_root_window,
     }
     p_vout->i_pictures = 0;
 
-    /* Initialize synchronization informations */
+    /* Initialize synchronization information */
     p_vout->i_synchro_level     = VOUT_SYNCHRO_LEVEL_START;
 
     /* 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 ) )
     {
-        TrashPlugin( p_vout->vout_plugin );
         free( p_vout );
         return( NULL );
     }
-    intf_DbgMsg("actual configuration: %dx%d, %d/%d bpp (%d Bpl), masks: 0x%x/0x%x/0x%x\n",
-                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_DbgMsg( "actual configuration: %dx%d, %d/%d bpp (%d Bpl), "
+                 "masks: 0x%x/0x%x/0x%x\n",
+                 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,   p_vout->i_red_mask );
-    MaskToShift( &p_vout->i_green_lshift, &p_vout->i_green_rshift, p_vout->i_green_mask );
-    MaskToShift( &p_vout->i_blue_lshift,  &p_vout->i_blue_rshift,  p_vout->i_blue_mask );
+    MaskToShift( &p_vout->i_red_lshift, &p_vout->i_red_rshift,
+                 p_vout->i_red_mask );
+    MaskToShift( &p_vout->i_green_lshift, &p_vout->i_green_rshift,
+                 p_vout->i_green_mask );
+    MaskToShift( &p_vout->i_blue_lshift, &p_vout->i_blue_rshift,
+                 p_vout->i_blue_mask );
 
     /* Set some useful colors */
     p_vout->i_white_pixel = RGB2PIXEL( p_vout, 255, 255, 255 );
@@ -215,28 +227,28 @@ 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 );
+    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( "share/" VOUT_DEFAULT_FONT );
     }
     if( p_vout->p_default_font == NULL )
     {
+        intf_ErrMsg( "vout error: could not load default font\n" );
         p_vout->p_sys_destroy( p_vout );
-        TrashPlugin( p_vout->vout_plugin );
         free( p_vout );
         return( NULL );
     }
-    p_vout->p_large_font        = vout_LoadFont( DATA_PATH "/" VOUT_LARGE_FONT );
+    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( "share/" VOUT_LARGE_FONT );
     }
     if( p_vout->p_large_font == NULL )
     {
+        intf_ErrMsg( "vout error: could not load large font\n" );
         vout_UnloadFont( p_vout->p_default_font );
         p_vout->p_sys_destroy( p_vout );
-        TrashPlugin( p_vout->vout_plugin );
         free( p_vout );
         return( NULL );
     }
@@ -246,19 +258,20 @@ vout_thread_t * vout_CreateThread   ( char *psz_display, int i_root_window,
     vlc_mutex_init( &p_vout->subpicture_lock );
     vlc_mutex_init( &p_vout->change_lock );
     vlc_mutex_lock( &p_vout->change_lock );
-    if( vlc_thread_create( &p_vout->thread_id, "video output", (void *) RunThread, (void *) p_vout) )
+    if( vlc_thread_create( &p_vout->thread_id, "video output",
+                           (void *) RunThread, (void *) p_vout) )
     {
         intf_ErrMsg("error: %s\n", strerror(ENOMEM));
         vout_UnloadFont( p_vout->p_default_font );
         vout_UnloadFont( p_vout->p_large_font );
         p_vout->p_sys_destroy( p_vout );
-        TrashPlugin( p_vout->vout_plugin );
         free( p_vout );
         return( NULL );
     }
 
-    intf_Msg("Video display initialized (%dx%d, %d/%d bpp)\n", p_vout->i_width,
-             p_vout->i_height, p_vout->i_screen_depth, p_vout->i_bytes_per_pixel * 8 );
+    intf_Msg( "Video display initialized (%dx%d, %d/%d bpp)\n", 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 */
     if( pi_status == NULL )
@@ -334,7 +347,7 @@ void  vout_DisplaySubPicture( vout_thread_t *p_vout, subpicture_t *p_subpic )
     p_subpic->i_status = READY_SUBPICTURE;
 
 #ifdef DEBUG_VIDEO
-    /* Send subpicture informations */
+    /* Send subpicture information */
     intf_DbgMsg("subpicture %p: type=%d, begin date=%s, end date=%s\n",
                 p_subpic, p_subpic->i_type,
                 mstrtime( psz_begin_date, p_subpic->begin_date ),
@@ -343,7 +356,7 @@ void  vout_DisplaySubPicture( vout_thread_t *p_vout, subpicture_t *p_subpic )
 }
 
 /*****************************************************************************
- * vout_CreateSubPicture: allocate an subpicture in the video output heap.
+ * vout_CreateSubPicture: allocate a subpicture in the video output heap.
  *****************************************************************************
  * This function create a reserved subpicture in the video output heap.
  * A null pointer is returned if the function fails. This method provides an
@@ -398,10 +411,10 @@ subpicture_t *vout_CreateSubPicture( vout_thread_t *p_vout, int i_type,
         }
     }
 
-    /* If no free subpicture is available, use a destroyed subpicture */
+    /* If no free subpictures are available, use a destroyed subpicture */
     if( (p_free_subpic == NULL) && (p_destroyed_subpic != NULL ) )
     {
-        /* No free subpicture or matching destroyed subpicture has been
+        /* No free subpicture or matching destroyed subpictures have been
          * found, but a destroyed subpicture is still avalaible */
         free( p_destroyed_subpic->p_data );
         p_free_subpic = p_destroyed_subpic;
@@ -430,7 +443,8 @@ subpicture_t *vout_CreateSubPicture( vout_thread_t *p_vout, int i_type,
         }
 
         if( p_free_subpic->p_data != NULL )
-        {           /* Copy subpicture informations, set some default values */
+        {
+            /* Copy subpicture information, set some default values */
             p_free_subpic->i_type                      = i_type;
             p_free_subpic->i_status                    = RESERVED_SUBPICTURE;
             p_free_subpic->i_size                      = i_size;
@@ -447,7 +461,7 @@ subpicture_t *vout_CreateSubPicture( vout_thread_t *p_vout, int i_type,
             p_free_subpic->i_type   =  EMPTY_SUBPICTURE;
             p_free_subpic->i_status =  FREE_SUBPICTURE;
             p_free_subpic =            NULL;
-            intf_ErrMsg("warning: %s\n", strerror( ENOMEM ) );
+            intf_ErrMsg("spu warning: %s\n", strerror( ENOMEM ) );
         }
 
 #ifdef DEBUG_VIDEO
@@ -458,7 +472,7 @@ subpicture_t *vout_CreateSubPicture( vout_thread_t *p_vout, int i_type,
     }
 
     /* No free or destroyed subpicture could be found */
-    intf_DbgMsg( "warning: heap is full\n" );
+    intf_DbgMsg( "warning: subpicture heap is full\n" );
     vlc_mutex_unlock( &p_vout->subpicture_lock );
     return( NULL );
 }
@@ -664,7 +678,7 @@ picture_t *vout_CreatePicture( vout_thread_t *p_vout, int i_type,
 
         if( p_free_picture->p_data != NULL )
         {
-            /* Copy picture informations, set some default values */
+            /* Copy picture information, set some default values */
             p_free_picture->i_type                      = i_type;
             p_free_picture->i_status                    = RESERVED_PICTURE;
             p_free_picture->i_matrix_coefficients       = 1;
@@ -685,7 +699,7 @@ picture_t *vout_CreatePicture( vout_thread_t *p_vout, int i_type,
             p_free_picture->i_type   =  EMPTY_PICTURE;
             p_free_picture->i_status =  FREE_PICTURE;
             p_free_picture =            NULL;
-            intf_ErrMsg("warning: %s\n", strerror( ENOMEM ) );
+            intf_ErrMsg("vout warning: %s\n", strerror( ENOMEM ) );
         }
 
 #ifdef DEBUG_VIDEO
@@ -696,7 +710,7 @@ picture_t *vout_CreatePicture( vout_thread_t *p_vout, int i_type,
     }
 
     /* No free or destroyed picture could be found */
-    intf_DbgMsg( "warning: heap is full\n" );
+    intf_DbgMsg( "warning: picture heap is full\n" );
     vlc_mutex_unlock( &p_vout->picture_lock );
     return( NULL );
 }
@@ -859,7 +873,7 @@ static int BinaryLog(u32 i)
     }
     if (i != ((u32)1 << i_log))
     {
-        intf_ErrMsg("internal error: binary log overflow\n");
+        intf_DbgMsg("internal error: binary log overflow\n");
     }
 
     return( i_log );
@@ -1062,13 +1076,17 @@ last_display_date = display_date;
                 /* Set picture dimensions and clear buffer */
                 SetBufferPicture( p_vout, p_pic );
 
-                /* Render picture and informations */
+                /* Render picture and information */
                 RenderPicture( p_vout, p_pic );
                 if( p_vout->b_info )
                 {
                     RenderPictureInfo( p_vout, p_pic );
                     RenderInfo( p_vout );
                 }
+                if( p_subpic )
+                {
+                    RenderSubPicture( p_vout, p_subpic );
+                }
             }
 
             /* Remove picture from heap */
@@ -1089,49 +1107,8 @@ last_display_date = display_date;
             {
                 RenderInterface( p_vout );
             }
-            if( p_subpic )
-            {
-                if( b_display )
-                {
-                    RenderSubPicture( p_vout, p_subpic );
-                }
-
-                /* Remove subpicture from heap */
-                /*vlc_mutex_lock( &p_vout->subpicture_lock );
-                p_subpic->i_status = DESTROYED_SUBPICTURE;
-                vlc_mutex_unlock( &p_vout->subpicture_lock );*/
-            }
-
-        }
-#if 0
-        else if( p_subpic )                              /* subpicture alone */
-        {
-            b_display = p_vout->b_active;
-            p_vout->last_display_date = display_date;
-
-            if( b_display )
-            {
-                /* Clear buffer */
-                SetBufferPicture( p_vout, NULL );
-
-                /* Render informations, interface and subpicture */
-                if( p_vout->b_info )
-                {
-                    RenderInfo( p_vout );
-                }
-                if( p_vout->b_interface )
-                {
-                    RenderInterface( p_vout );
-                }
-                RenderSubPicture( p_vout, p_subpic );
-            }
 
-            /* Remove subpicture from heap */
-            /*vlc_mutex_lock( &p_vout->subpicture_lock );
-            p_subpic->i_status = DESTROYED_SUBPICTURE;
-            vlc_mutex_unlock( &p_vout->subpicture_lock );*/
         }
-#endif
         else if( p_vout->b_active )        /* idle or interface screen alone */
         {
             if( p_vout->b_interface && 0 /* && XXX?? intf_change */ )
@@ -1294,9 +1271,6 @@ static void DestroyThread( vout_thread_t *p_vout, int i_status )
     vout_UnloadFont( p_vout->p_large_font );
     p_vout->p_sys_destroy( p_vout );
 
-    /* Close plugin */
-    TrashPlugin( p_vout->vout_plugin );
-
     /* Free structure */
     free( p_vout );
     *pi_status = i_status;
@@ -1306,7 +1280,7 @@ static void DestroyThread( vout_thread_t *p_vout, int i_status )
  * Print: print simple text on a picture
  *****************************************************************************
  * This function will print a simple text on the picture. It is designed to
- * print debugging or general informations.
+ * print debugging or general information.
  *****************************************************************************/
 void Print( vout_thread_t *p_vout, int i_x, int i_y, int i_h_align, int i_v_align, unsigned char *psz_text )
 {
@@ -1385,7 +1359,7 @@ static void SetBufferArea( vout_thread_t *p_vout, int i_x, int i_y, int i_w, int
     if( i_area == p_buffer->i_areas )
     {
         /* New area is below all existing ones: just add it at the end of the
-         * array, if possible - else, append it to the last one */
+         * array, if possible - otherwise, append it to the last one */
         if( i_area < VOUT_MAX_AREAS )
         {
             p_buffer->pi_area_begin[i_area] = i_y;
@@ -1395,7 +1369,7 @@ static void SetBufferArea( vout_thread_t *p_vout, int i_x, int i_y, int i_w, int
         else
         {
 #ifdef DEBUG_VIDEO
-            intf_DbgMsg("areas overflow\n");
+            intf_DbgMsg("area overflow\n");
 #endif
             p_buffer->pi_area_end[VOUT_MAX_AREAS - 1] = i_h;
         }
@@ -1566,7 +1540,7 @@ static void SetBufferPicture( vout_thread_t *p_vout, picture_t *p_pic )
     }
 
     /*
-     * Set new picture size - if is is smaller than the previous one, clear
+     * Set new picture size - if it is smaller than the previous one, clear
      * around it. Since picture are centered, only their size is tested.
      */
     if( (p_buffer->i_pic_width > i_pic_width) || (p_buffer->i_pic_height > i_pic_height) )
@@ -1632,10 +1606,10 @@ static void SetBufferPicture( vout_thread_t *p_vout, picture_t *p_pic )
 /*****************************************************************************
  * RenderPicture: render a picture
  *****************************************************************************
- * This function convert a picture from a video heap to a pixel-encoded image
- * and copy it to the current rendering buffer. No lock is required, since the
- * rendered picture has been determined as existant, and will only be destroyed
- * by the vout thread later.
+ * This function converts a picture from a video heap to a pixel-encoded image
+ * and copies it to the current rendering buffer. No lock is required, since
+ * the * rendered picture has been determined as existant, and will only be
+ * destroyed by the vout thread later.
  *****************************************************************************/
 static void RenderPicture( vout_thread_t *p_vout, picture_t *p_pic )
 {
@@ -1646,7 +1620,7 @@ static void RenderPicture( vout_thread_t *p_vout, picture_t *p_pic )
     vout_buffer_t *     p_buffer;                        /* rendering buffer */
     byte_t *            p_pic_data;                /* convertion destination */
 
-    /* Get and set rendering informations */
+    /* Get and set rendering information */
     p_buffer =          &p_vout->p_buffer[ p_vout->i_buffer_index ];
     p_pic_data =        p_buffer->p_data +
                         p_buffer->i_pic_x * p_vout->i_bytes_per_pixel +
@@ -1700,10 +1674,10 @@ static void RenderPicture( vout_thread_t *p_vout, picture_t *p_pic )
 }
 
 /*****************************************************************************
- * RenderPictureInfo: print additionnal informations on a picture
+ * RenderPictureInfo: print additionnal information on a picture
  *****************************************************************************
- * This function will print informations such as fps and other picture
- * dependant informations.
+ * This function will print information such as fps and other picture
+ * dependant information.
  *****************************************************************************/
 static void RenderPictureInfo( vout_thread_t *p_vout, picture_t *p_pic )
 {
@@ -1795,10 +1769,10 @@ static int RenderIdle( vout_thread_t *p_vout )
 }
 
 /*****************************************************************************
- * RenderInfo: render additionnal informations
+ * RenderInfo: render additionnal information
  *****************************************************************************
- * This function render informations which do not depend of the current picture
- * rendered.
+ * This function renders information which do not depend on the current
+ * picture rendered.
  *****************************************************************************/
 static void RenderInfo( vout_thread_t *p_vout )
 {
@@ -1836,7 +1810,7 @@ static void RenderInfo( vout_thread_t *p_vout )
 /*****************************************************************************
  * RenderSubPicture: render a subpicture
  *****************************************************************************
- * This function render a sub picture unit.
+ * This function renders a sub picture unit.
  *****************************************************************************/
 static void RenderSubPicture( vout_thread_t *p_vout, subpicture_t *p_subpic )
 {
@@ -1851,6 +1825,7 @@ static void RenderSubPicture( vout_thread_t *p_vout, subpicture_t *p_subpic )
             /* test if the picture really has to be displayed */
             if( mdate() < p_subpic->begin_date )
             {
+                /* not yet, see you later */
                 break;
             }
             if( mdate() > p_subpic->end_date )
@@ -1859,10 +1834,8 @@ static void RenderSubPicture( vout_thread_t *p_vout, subpicture_t *p_subpic )
                 vout_DestroySubPicture( p_vout, p_subpic );
                 break;
             }
-            vout_RenderSPU( p_subpic->p_data, p_subpic->type.spu.i_offset,
-                            p_subpic,
-                            p_vout->p_buffer[ p_vout->i_buffer_index ].p_data,
-                            p_vout->i_bytes_per_pixel,
+            vout_RenderSPU( &p_vout->p_buffer[ p_vout->i_buffer_index ],
+                            p_subpic, p_vout->i_bytes_per_pixel,
                             p_vout->i_bytes_per_line );
             break;
         case TEXT_SUBPICTURE:                            /* single line text */
@@ -1909,7 +1882,7 @@ static void RenderSubPicture( vout_thread_t *p_vout, subpicture_t *p_subpic )
 /*****************************************************************************
  * RenderInterface: render the interface
  *****************************************************************************
- * This function render the interface, if any.
+ * This function renders the interface, if any.
  *****************************************************************************/
 static void RenderInterface( vout_thread_t *p_vout )
 {