]> git.sesse.net Git - vlc/blobdiff - modules/video_output/x11/xvmc.c
No need to add a '\n' at the end of messages passed to msg_*
[vlc] / modules / video_output / x11 / xvmc.c
index cd6bda6b37f937bab14353f1db180295d0137c21..0d35750c920ae3a58d6f659c1979d1fffe08e5d8 100644 (file)
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <stdlib.h>                                      /* malloc(), free() */
-#include <string.h>                                            /* strerror() */
 
-#include <vlc/vlc.h>
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_plugin.h>
 #include <vlc_interface.h>
 #include <vlc_vout.h>
 #include <vlc_keys.h>
@@ -66,7 +69,7 @@
 #include <X11/extensions/Xvlib.h>
 #include <X11/extensions/vldXvMC.h>
 
-#include "../../codec/xxmc/accel_xvmc.h"
+#include "../../codec/xvmc/accel_xvmc.h"
 #include "xcommon.h"
 #include "../../codec/spudec/spudec.h"
 #include <unistd.h>
@@ -85,8 +88,8 @@
 /*****************************************************************************
  * Exported prototypes
  *****************************************************************************/
-extern int  E_(Activate)   ( vlc_object_t * );
-extern void E_(Deactivate) ( vlc_object_t * );
+extern int  Activate   ( vlc_object_t * );
+extern void Deactivate ( vlc_object_t * );
 
 /*****************************************************************************
  * Module descriptor
@@ -130,29 +133,29 @@ extern void E_(Deactivate) ( vlc_object_t * );
 #define CROP_TEXT N_("Crop")
 #define CROP_LONGTEXT N_("You can choose the crop style to apply.")
 
-vlc_module_begin();
-    set_shortname( "XVMC" );
-    add_string( "xvmc-display", NULL, NULL, DISPLAY_TEXT, DISPLAY_LONGTEXT, VLC_TRUE );
-    add_integer( "xvmc-adaptor", -1, NULL, ADAPTOR_TEXT, ADAPTOR_LONGTEXT, VLC_TRUE );
-    add_bool( "xvmc-altfullscreen", 0, NULL, ALT_FS_TEXT, ALT_FS_LONGTEXT, VLC_TRUE );
-    add_string( "xvmc-chroma", NULL, NULL, CHROMA_TEXT, CHROMA_LONGTEXT, VLC_TRUE );
+vlc_module_begin ()
+    set_shortname( "XVMC" )
+    add_string( "xvmc-display", NULL, NULL, DISPLAY_TEXT, DISPLAY_LONGTEXT, true )
+    add_integer( "xvmc-adaptor", -1, NULL, ADAPTOR_TEXT, ADAPTOR_LONGTEXT, true )
+    add_bool( "xvmc-altfullscreen", 0, NULL, ALT_FS_TEXT, ALT_FS_LONGTEXT, true )
+    add_string( "xvmc-chroma", NULL, NULL, CHROMA_TEXT, CHROMA_LONGTEXT, true )
 #ifdef HAVE_SYS_SHM_H
-    add_bool( "xvmc-shm", 1, NULL, SHM_TEXT, SHM_LONGTEXT, VLC_TRUE );
+    add_bool( "xvmc-shm", 1, NULL, SHM_TEXT, SHM_LONGTEXT, true )
 #endif
 #ifdef HAVE_XINERAMA
-    add_integer ( "xvmc-xineramascreen", 0, NULL, SCREEN_TEXT, SCREEN_LONGTEXT, VLC_TRUE );
+    add_integer ( "xvmc-xineramascreen", -1, NULL, SCREEN_TEXT, SCREEN_LONGTEXT, true )
 #endif
-    add_string( "xvmc-deinterlace-mode", "bob", NULL, MODE_TEXT, MODE_LONGTEXT, VLC_FALSE );
-    add_string( "xvmc-crop-style", "eq", NULL, CROP_TEXT, CROP_LONGTEXT, VLC_FALSE );
+    add_string( "xvmc-deinterlace-mode", "bob", NULL, MODE_TEXT, MODE_LONGTEXT, false )
+    add_string( "xvmc-crop-style", "eq", NULL, CROP_TEXT, CROP_LONGTEXT, false )
 
-    set_description( _("XVMC extension video output") );
-    set_capability( "video output", 160 );
-    set_callbacks( E_(Activate), E_(Deactivate) );
-vlc_module_end();
+    set_description( N_("XVMC extension video output") )
+    set_capability( "video output", 10 )
+    set_callbacks( Activate, Deactivate )
+vlc_module_end ()
 
 /* following functions are local */
 
-static unsigned accel_priority[] = {
+static const unsigned accel_priority[] = {
     VLC_XVMC_ACCEL_VLD,
 };
 
@@ -240,7 +243,7 @@ static void colorToPalette( const uint32_t *icolor, unsigned char *palette_p,
                             unsigned num_xvmc_components, char *xvmc_components )
 {
     const clut_t *color = (const clut_t *) icolor;
-    int i;
+    unsigned int i;
 
     for (i=0; i<num_xvmc_components; ++i)
     {
@@ -260,7 +263,7 @@ void xx44_to_xvmc_palette( const xx44_palette_t *p,unsigned char *xvmc_palette,
                            unsigned first_xx44_entry, unsigned num_xx44_entries,
                            unsigned num_xvmc_components, char *xvmc_components )
 {
-    int i;
+    unsigned int i;
     const uint32_t *cluts = p->cluts + first_xx44_entry;
 
     for( i=0; i<num_xx44_entries; ++i )
@@ -276,7 +279,7 @@ void xx44_to_xvmc_palette( const xx44_palette_t *p,unsigned char *xvmc_palette,
 
 static int xx44_paletteIndex( xx44_palette_t *p, int color, uint32_t clut )
 {
-    int i;
+    unsigned int i;
     uint32_t *cluts = p->cluts;
     int tmp;
 
@@ -308,8 +311,9 @@ static void memblend_xx44( uint8_t *mem, uint8_t val,
 {
     uint8_t masked_val = val & mask;
 
-    if (size < 0)
-        return;
+/* size_t is unsigned, therefore always positive
+   if (size < 0)
+        return;*/
 
     while(size--)
     {
@@ -336,8 +340,7 @@ void blend_xx44( uint8_t *dst_img, subpicture_t *sub_img,
     int clip_right;
     int i_len, i_color;
     uint16_t *p_source = NULL;
-    uint16_t i_colprecomp, i_destalpha;
-
+#if 0
     if (!sub_img)
         return;
 
@@ -347,7 +350,6 @@ void blend_xx44( uint8_t *dst_img, subpicture_t *sub_img,
     y_off = sub_img->i_y;
     alphamask = (ia44) ? 0x0F : 0xF0;
     p_source = (uint16_t *)sub_img->p_sys->p_data;
-    i_colprecomp, i_destalpha;
 
     dst_y = dst_img + dst_pitch*y_off + x_off;
 
@@ -467,15 +469,16 @@ void blend_xx44( uint8_t *dst_img, subpicture_t *sub_img,
         }
         dst_y += dst_pitch;
     }
+#endif
 }
 
 int xxmc_xvmc_surface_valid( vout_thread_t *p_vout, XvMCSurface *surf )
 {
     xvmc_surface_handler_t *handler = &p_vout->p_sys->xvmc_surf_handler;
-    unsigned int index = surf - handler->surfaces;
+    unsigned long index = surf - handler->surfaces;
     int ret;
 
-    if (index >= XVMC_MAX_SURFACES)
+    if( index >= XVMC_MAX_SURFACES )
         return 0;
     pthread_mutex_lock(&handler->mutex);
     ret = handler->surfValid[index];
@@ -542,7 +545,7 @@ XvMCSubpicture *xxmc_xvmc_alloc_subpicture( vout_thread_t *p_vout,
                 return NULL;
             }
             XVMCUNLOCKDISPLAY( p_vout->p_sys->p_display );
-            msg_Dbg( p_vout, "video_out_xxmc: created subpicture %d\n", i );
+            msg_Dbg( p_vout, "video_out_xxmc: created subpicture %d", i );
             handler->subInUse[i] = 1;
             handler->subValid[i] = 1;
             pthread_mutex_unlock( &handler->mutex );
@@ -571,7 +574,7 @@ static void xxmc_xvmc_surface_handler_construct( vout_thread_t *p_vout )
 {
     int i;
     xvmc_surface_handler_t *handler = &p_vout->p_sys->xvmc_surf_handler;
-    
     pthread_mutex_init( &handler->mutex, NULL );
     for( i=0; i<XVMC_MAX_SURFACES; ++i )
     {
@@ -743,25 +746,27 @@ int checkXvMCCap( vout_thread_t *p_vout )
     XFree(surfaceInfo);
 
     /*
-    * Try to create a direct rendering context. This will fail if we are not
-    * on the displaying computer or an indirect context is not available.
-    */
+     * Try to create a direct rendering context. This will fail if we are not
+     * on the displaying computer or an indirect context is not available.
+     */
     XVMCUNLOCKDISPLAY( p_vout->p_sys->p_display );
     curCap = p_vout->p_sys->xvmc_cap;
     if( Success == XvMCCreateContext( p_vout->p_sys->p_display, i_xvport,
                                       curCap->type_id,
                                       curCap->max_width,
                                       curCap->max_height,
-                                      XVMC_DIRECT, &c) )
+                                      XVMC_DIRECT, &c ) )
     {
-            p_vout->p_sys->context_flags = XVMC_DIRECT;
+        msg_Dbg( p_vout, "using direct XVMC rendering context" );
+        p_vout->p_sys->context_flags = XVMC_DIRECT;
     }
     else if( Success == XvMCCreateContext( p_vout->p_sys->p_display, i_xvport,
                                            curCap->type_id,
                                            curCap->max_width,
                                            curCap->max_height,
-                                           0, &c) )
+                                           0, &c ) )
     {
+        msg_Dbg( p_vout, "using default XVMC rendering context" );
         p_vout->p_sys->context_flags = 0;
     }
     else
@@ -774,9 +779,9 @@ int checkXvMCCap( vout_thread_t *p_vout )
         xvmc_context_writer_unlock( &p_vout->p_sys->xvmc_lock );
         return VLC_SUCCESS;
     }
-    XVMCLOCKDISPLAY( p_vout->p_sys->p_display );  
+    XVMCLOCKDISPLAY( p_vout->p_sys->p_display );
     XvMCDestroyContext( p_vout->p_sys->p_display, &c );
-    xxmc_xvmc_surface_handler_construct(p_vout );
+    xxmc_xvmc_surface_handler_construct( p_vout );
     /*  p_vout->p_sys->capabilities |= VO_CAP_XXMC; */
     XVMCUNLOCKDISPLAY( p_vout->p_sys->p_display );
     init_xx44_palette( &p_vout->p_sys->palette , 0 );
@@ -808,7 +813,7 @@ static int xxmc_setup_subpictures( vout_thread_t *p_vout,
             XLockDisplay( p_vout->p_sys->p_display );
             msg_Dbg(p_vout, "xxmc_setup_subpictures");
 #ifdef HAVE_SYS_SHM_H
-            if( p_vout->p_sys->b_shm )
+            if( p_vout->p_sys->i_shm_opcode )
             {
                 /* Create image using XShm extension */
                 p_vout->p_sys->subImage = CreateShmImage( p_vout,
@@ -832,16 +837,16 @@ static int xxmc_setup_subpictures( vout_thread_t *p_vout,
         sp = xxmc_xvmc_alloc_subpicture( p_vout, &p_vout->p_sys->context,
                                          width, height,
                                          curCap->subPicType.id );
-        if( !sp == NULL )
-            return VLC_EGENERIC;
-
-        init_xx44_palette( &p_vout->p_sys->palette, sp->num_palette_entries );
-        p_vout->p_sys->xvmc_palette = (char *) malloc( sp->num_palette_entries
-                                                       * sp->entry_bytes );
-        xxmc_xvmc_free_subpicture( p_vout, sp);
-        if( !p_vout->p_sys->xvmc_pallette )
-            return VLC_EGENERIC;
-        p_vout->p_sys->hwSubpictures = 1;
+        if( sp )
+        {
+            init_xx44_palette( &p_vout->p_sys->palette, sp->num_palette_entries );
+            p_vout->p_sys->xvmc_palette = (char *) malloc( sp->num_palette_entries
+                    * sp->entry_bytes );
+            xxmc_xvmc_free_subpicture( p_vout, sp);
+            if( !p_vout->p_sys->xvmc_palette )
+                return VLC_EGENERIC;
+            p_vout->p_sys->hwSubpictures = 1;
+        }
     }
     return VLC_SUCCESS;
 }
@@ -958,6 +963,7 @@ static XvMCSurface *xxmc_xvmc_alloc_surface( vout_thread_t *p_vout,
         if( handler->surfValid[i] && !handler->surfInUse[i] )
         {
             handler->surfInUse[i] = 1;
+            msg_Dbg( p_vout, "reusing surface %d", i );
             xxmc_xvmc_dump_surfaces( p_vout );
             pthread_mutex_unlock( &handler->mutex );
             return (handler->surfaces + i);
@@ -968,7 +974,7 @@ static XvMCSurface *xxmc_xvmc_alloc_surface( vout_thread_t *p_vout,
         if( !handler->surfInUse[i] )
         {
             XVMCLOCKDISPLAY( p_vout->p_sys->p_display );
-            if( Success != XvMCCreateSurface( p_vout->p_sys->p_display
+            if( Success != XvMCCreateSurface( p_vout->p_sys->p_display,
                                               context,
                                               handler->surfaces + i) )
             {
@@ -1034,8 +1040,8 @@ void xxmc_dispose_context( vout_thread_t *p_vout )
 static int xxmc_find_context( vout_thread_t *p_vout, vlc_xxmc_t *xxmc,
         unsigned int width, unsigned int height )
 {
-    int i, k;
-    vlc_bool_t found = VLC_FALSE;
+    unsigned int i, k;
+    bool found = false;
     xvmc_capabilities_t *curCap = NULL;
     unsigned int request_mpeg_flags, request_accel_flags;
 
@@ -1061,7 +1067,7 @@ static int xxmc_find_context( vout_thread_t *p_vout, vlc_xxmc_t *xxmc,
                   (width <= curCap->max_width) &&
                   (height <= curCap->max_height) )
             {
-                found = VLC_TRUE;
+                found = true;
                 break;
             }
             curCap++;
@@ -1115,7 +1121,8 @@ static void xvmc_flushsync(picture_t *picture)
 
     xvmc_context_reader_lock( &p_vout->p_sys->xvmc_lock );
 
-    if( ! xxmc_xvmc_surface_valid( p_vout, picture->p_sys->xvmc_surf)) {
+    if( !xxmc_xvmc_surface_valid( p_vout, picture->p_sys->xvmc_surf ) )
+    {
         msg_Dbg(p_vout, "xvmc_flushsync 1 : %d", picture->p_sys->xxmc_data.result );
         picture->p_sys->xxmc_data.result = 128;
         xvmc_context_reader_unlock( &p_vout->p_sys->xvmc_lock );
@@ -1315,7 +1322,7 @@ static void dispose_ximage( vout_thread_t *p_vout, XShmSegmentInfo *shminfo,
                 XvImage *myimage )
 {
 # ifdef HAVE_SYS_SHM_H
-    if( p_vout->p_sys->b_shm )
+    if( p_vout->p_sys->i_shm_opcode )
     {
         XShmDetach( p_vout->p_sys->p_display, shminfo );
         XFree( myimage );
@@ -1338,11 +1345,11 @@ static void dispose_ximage( vout_thread_t *p_vout, XShmSegmentInfo *shminfo,
 
 void xvmc_vld_frame( picture_t *picture )
 {
-    vout_sys_t *p_sys = picture->p_sys;
+    picture_sys_t *p_sys  = picture->p_sys;
     vout_thread_t *p_vout = p_sys->p_vout;
-    vlc_vld_frame_t *vft = &(p_sys->xxmc_data.vld_frame);
-    picture_t *ff = (picture_t *) vft->forward_reference_picture;
-    picture_t *bf = (picture_t *) vft->backward_reference_picture;
+    vlc_vld_frame_t *vft  = &(p_sys->xxmc_data.vld_frame);
+    picture_t *ff         = (picture_t *) vft->forward_reference_picture;
+    picture_t *bf         = (picture_t *) vft->backward_reference_picture;
     XvMCMpegControl ctl;
     XvMCSurface *fs=0, *bs=0;
     XvMCQMatrix qmx;
@@ -1394,7 +1401,7 @@ void xvmc_vld_frame( picture_t *picture )
     qmx.load_chroma_non_intra_quantiser_matrix = 0;
     xvmc_context_reader_lock( &p_vout->p_sys->xvmc_lock );
 
-    if( ! xxmc_xvmc_surface_valid( p_vout, picture->p_sys->xvmc_surf) )
+    if( !xxmc_xvmc_surface_valid( p_vout, picture->p_sys->xvmc_surf ) )
     {
         picture->p_sys->xxmc_data.result = 128;
         xvmc_context_reader_unlock( &p_vout->p_sys->xvmc_lock );
@@ -1416,7 +1423,7 @@ void xvmc_vld_frame( picture_t *picture )
 
 void xvmc_vld_slice( picture_t *picture )
 {
-    vout_sys_t *p_sys     = picture->p_sys;
+    picture_sys_t *p_sys  = picture->p_sys;
     vout_thread_t *p_vout = p_sys->p_vout;
 
     xvmc_context_reader_lock( &p_vout->p_sys->xvmc_lock );
@@ -1432,7 +1439,7 @@ void xvmc_vld_slice( picture_t *picture )
     picture->p_sys->xxmc_data.result =
             XvMCPutSlice2( p_vout->p_sys->p_display,
                            &p_vout->p_sys->context,
-                            picture->p_sys->xxmc_data.slice_data,
+                            (char *)picture->p_sys->xxmc_data.slice_data,
                             picture->p_sys->xxmc_data.slice_data_size,
                             picture->p_sys->xxmc_data.slice_code );