]> git.sesse.net Git - vlc/blobdiff - modules/video_output/msw/directx.c
Add a bunch of help strings. Feel free to correct them, and add more
[vlc] / modules / video_output / msw / directx.c
index 910e982bffa56cf21bae30b47f82f789675a1122..be246c9e8c7d913f496b9dbc9d37661738764877 100644 (file)
@@ -34,9 +34,6 @@
  * display video in window mode.
  *
  *****************************************************************************/
-
-#include <errno.h>                                                 /* ENOMEM */
-
 #ifdef HAVE_CONFIG_H
 # include "config.h"
 #endif
@@ -158,17 +155,16 @@ BOOL WINAPI DirectXEnumCallback2( GUID* p_guid, LPTSTR psz_desc,
     "window to open on. For example, \"\\\\.\\DISPLAY1\" or " \
     "\"\\\\.\\DISPLAY2\"." )
 
-#define WALLPAPER_TEXT N_("Enable wallpaper mode ")
-#define WALLPAPER_LONGTEXT N_( \
-    "The wallpaper mode allows you to display the video as the desktop " \
-    "background. Note that this feature only works in overlay mode and " \
-    "the desktop must not already have a wallpaper." )
+#define DX_HELP N_("Recommended video output for Windows XP. " \
+    "Incompatible with Vista's Aero interface" )
 
 static const char *const ppsz_dev[] = { "" };
 static const char *const ppsz_dev_text[] = { N_("Default") };
 
 vlc_module_begin ()
     set_shortname( "DirectX" )
+    set_description( N_("DirectX (DirectDraw) video output") )
+    set_help(DX_HELP)
     set_category( CAT_VIDEO )
     set_subcategory( SUBCAT_VIDEO_VOUT )
     add_bool( "directx-hw-yuv", true, NULL, HW_YUV_TEXT, HW_YUV_LONGTEXT,
@@ -183,10 +179,6 @@ vlc_module_begin ()
         change_string_list( ppsz_dev, ppsz_dev_text, FindDevicesCallback )
         change_action_add( FindDevicesCallback, N_("Refresh list") )
 
-    add_bool( "directx-wallpaper", false, NULL, WALLPAPER_TEXT, WALLPAPER_LONGTEXT,
-              true )
-
-    set_description( N_("DirectX (DirectDraw) video output") )
     set_capability( "video output", 100 )
     add_shortcut( "directx" )
     set_callbacks( OpenVideo, CloseVideo )
@@ -218,6 +210,7 @@ static int OpenVideo( vlc_object_t *p_this )
     p_vout->p_sys = calloc( 1, sizeof( vout_sys_t ) );
     if( p_vout->p_sys == NULL )
         return VLC_ENOMEM;
+    vlc_mutex_init( &p_vout->p_sys->lock );
 
     /* Initialisations */
     p_vout->pf_init = Init;
@@ -272,11 +265,11 @@ static int OpenVideo( vlc_object_t *p_this )
 
     /* Variable to indicate if the window should be on top of others */
     /* Trigger a callback right now */
-    var_Create( p_vout, "directx-wallpaper", VLC_VAR_BOOL|VLC_VAR_DOINHERIT );
+    var_Create( p_vout, "video-wallpaper", VLC_VAR_BOOL|VLC_VAR_DOINHERIT );
     val.psz_string = _("Wallpaper");
-    var_Change( p_vout, "directx-wallpaper", VLC_VAR_SETTEXT, &val, NULL );
-    var_AddCallback( p_vout, "directx-wallpaper", WallpaperCallback, NULL );
-    var_TriggerCallback( p_vout, "directx-wallpaper" );
+    var_Change( p_vout, "video-wallpaper", VLC_VAR_SETTEXT, &val, NULL );
+    var_AddCallback( p_vout, "video-wallpaper", WallpaperCallback, NULL );
+    var_TriggerCallback( p_vout, "video-wallpaper" );
 
     return VLC_SUCCESS;
 
@@ -380,15 +373,24 @@ static int Init( vout_thread_t *p_vout )
     {
         /* If it still didn't work then don't try to use an overlay */
         p_vout->output.i_chroma = i_chroma_backup;
-        p_vout->p_sys->b_using_overlay = 0;
+        p_vout->p_sys->b_using_overlay = false;
         msg_Warn( p_vout, "Could not initialize directx overlay" ) ;
         NewPictureVec( p_vout, p_vout->p_picture );
     }
 
+    p_vout->fmt_out.i_chroma = p_vout->output.i_chroma;
+
     /* Change the window title bar text */
-    PostMessage( p_vout->p_sys->hwnd, WM_VLC_CHANGE_TEXT, 0, 0 );
+    const char *psz_fallback;
+    if( p_vout->p_sys->b_using_overlay )
+        psz_fallback = VOUT_TITLE " (hardware YUV overlay DirectX output)";
+    else if( p_vout->p_sys->b_hw_yuv )
+        psz_fallback = VOUT_TITLE " (hardware YUV DirectX output)";
+    else
+        psz_fallback = VOUT_TITLE " (software RGB DirectX output)";
+    EventThreadUpdateTitle( p_vout->p_sys->p_event, psz_fallback );
+    EventThreadUseOverlay( p_vout->p_sys->p_event, p_vout->p_sys->b_using_overlay );
 
-    p_vout->fmt_out.i_chroma = p_vout->output.i_chroma;
     return VLC_SUCCESS;
 }
 
@@ -418,11 +420,12 @@ static void CloseVideo( vlc_object_t *p_this )
     vout_thread_t * p_vout = (vout_thread_t *)p_this;
 
     /* Make sure the wallpaper is restored */
-    var_DelCallback( p_vout, "directx-wallpaper", WallpaperCallback, NULL );
+    var_DelCallback( p_vout, "video-wallpaper", WallpaperCallback, NULL );
     SwitchWallpaperMode( p_vout, false );
 
     CommonClean( p_vout );
 
+    vlc_mutex_destroy( &p_vout->p_sys->lock );
     free( p_vout->p_sys );
 }
 
@@ -434,40 +437,7 @@ static void CloseVideo( vlc_object_t *p_this )
  *****************************************************************************/
 static int Manage( vout_thread_t *p_vout )
 {
-    /* If we do not control our window, we check for geometry changes
-     * ourselves because the parent might not send us its events. */
-    vlc_mutex_lock( &p_vout->p_sys->lock );
-    if( p_vout->p_sys->hparent && !p_vout->b_fullscreen )
-    {
-        RECT rect_parent;
-        POINT point;
-
-        vlc_mutex_unlock( &p_vout->p_sys->lock );
-
-        GetClientRect( p_vout->p_sys->hparent, &rect_parent );
-        point.x = point.y = 0;
-        ClientToScreen( p_vout->p_sys->hparent, &point );
-        OffsetRect( &rect_parent, point.x, point.y );
-
-        if( !EqualRect( &rect_parent, &p_vout->p_sys->rect_parent ) )
-        {
-            p_vout->p_sys->rect_parent = rect_parent;
-
-            /* This one is to force the update even if only
-             * the position has changed */
-            SetWindowPos( p_vout->p_sys->hwnd, 0, 1, 1,
-                          rect_parent.right - rect_parent.left,
-                          rect_parent.bottom - rect_parent.top, 0 );
-
-            SetWindowPos( p_vout->p_sys->hwnd, 0, 0, 0,
-                          rect_parent.right - rect_parent.left,
-                          rect_parent.bottom - rect_parent.top, 0 );
-        }
-    }
-    else
-    {
-        vlc_mutex_unlock( &p_vout->p_sys->lock );
-    }
+    CommonManage( p_vout );
 
     /*
      * Position Change
@@ -487,51 +457,6 @@ static int Manage( vout_thread_t *p_vout )
         }
     }
 
-    /* autoscale toggle */
-    if( p_vout->i_changes & VOUT_SCALE_CHANGE )
-    {
-        p_vout->i_changes &= ~VOUT_SCALE_CHANGE;
-
-        p_vout->b_autoscale = var_GetBool( p_vout, "autoscale" );
-        p_vout->i_zoom = (int) ZOOM_FP_FACTOR;
-
-        UpdateRects( p_vout, true );
-    }
-
-    /* scaling factor */
-    if( p_vout->i_changes & VOUT_ZOOM_CHANGE )
-    {
-        p_vout->i_changes &= ~VOUT_ZOOM_CHANGE;
-
-        p_vout->b_autoscale = false;
-        p_vout->i_zoom =
-            (int)( ZOOM_FP_FACTOR * var_GetFloat( p_vout, "scale" ) );
-        UpdateRects( p_vout, true );
-    }
-
-    /* Check for cropping / aspect changes */
-    if( p_vout->i_changes & VOUT_CROP_CHANGE ||
-        p_vout->i_changes & VOUT_ASPECT_CHANGE )
-    {
-        p_vout->i_changes &= ~VOUT_CROP_CHANGE;
-        p_vout->i_changes &= ~VOUT_ASPECT_CHANGE;
-
-        p_vout->fmt_out.i_x_offset = p_vout->fmt_in.i_x_offset;
-        p_vout->fmt_out.i_y_offset = p_vout->fmt_in.i_y_offset;
-        p_vout->fmt_out.i_visible_width = p_vout->fmt_in.i_visible_width;
-        p_vout->fmt_out.i_visible_height = p_vout->fmt_in.i_visible_height;
-        p_vout->fmt_out.i_aspect = p_vout->fmt_in.i_aspect;
-        p_vout->fmt_out.i_sar_num = p_vout->fmt_in.i_sar_num;
-        p_vout->fmt_out.i_sar_den = p_vout->fmt_in.i_sar_den;
-        p_vout->output.i_aspect = p_vout->fmt_in.i_aspect;
-        UpdateRects( p_vout, true );
-    }
-
-    /* We used to call the Win32 PeekMessage function here to read the window
-     * messages. But since window can stay blocked into this function for a
-     * long time (for example when you move your window on the screen), I
-     * decided to isolate PeekMessage in another thread. */
-
     if( p_vout->p_sys->i_changes & DX_WALLPAPER_CHANGE )
     {
         SwitchWallpaperMode( p_vout, !p_vout->p_sys->b_wallpaper );
@@ -539,80 +464,6 @@ static int Manage( vout_thread_t *p_vout )
         DirectDrawUpdateOverlay( p_vout );
     }
 
-    /*
-     * Fullscreen change
-     */
-    if( p_vout->i_changes & VOUT_FULLSCREEN_CHANGE
-        || p_vout->p_sys->i_changes & VOUT_FULLSCREEN_CHANGE )
-    {
-        Win32ToggleFullscreen( p_vout );
-
-        p_vout->i_changes &= ~VOUT_FULLSCREEN_CHANGE;
-        p_vout->p_sys->i_changes &= ~VOUT_FULLSCREEN_CHANGE;
-    }
-
-    /*
-     * Pointer change
-     */
-    if( p_vout->b_fullscreen && !p_vout->p_sys->b_cursor_hidden &&
-        (mdate() - p_vout->p_sys->i_lastmoved) >
-            p_vout->p_sys->i_mouse_hide_timeout )
-    {
-        POINT point;
-        HWND hwnd;
-
-        /* Hide the cursor only if it is inside our window */
-        GetCursorPos( &point );
-        hwnd = WindowFromPoint(point);
-        if( hwnd == p_vout->p_sys->hwnd || hwnd == p_vout->p_sys->hvideownd )
-        {
-            PostMessage( p_vout->p_sys->hwnd, WM_VLC_HIDE_MOUSE, 0, 0 );
-        }
-        else
-        {
-            p_vout->p_sys->i_lastmoved = mdate();
-        }
-    }
-
-    /*
-     * "Always on top" status change
-     */
-    if( p_vout->p_sys->b_on_top_change )
-    {
-        vlc_value_t val;
-        HMENU hMenu = GetSystemMenu( p_vout->p_sys->hwnd, FALSE );
-
-        var_Get( p_vout, "video-on-top", &val );
-
-        /* Set the window on top if necessary */
-        if( val.b_bool && !( GetWindowLong( p_vout->p_sys->hwnd, GWL_EXSTYLE )
-                           & WS_EX_TOPMOST ) )
-        {
-            CheckMenuItem( hMenu, IDM_TOGGLE_ON_TOP,
-                           MF_BYCOMMAND | MFS_CHECKED );
-            SetWindowPos( p_vout->p_sys->hwnd, HWND_TOPMOST, 0, 0, 0, 0,
-                          SWP_NOSIZE | SWP_NOMOVE );
-        }
-        else
-        /* The window shouldn't be on top */
-        if( !val.b_bool && ( GetWindowLong( p_vout->p_sys->hwnd, GWL_EXSTYLE )
-                           & WS_EX_TOPMOST ) )
-        {
-            CheckMenuItem( hMenu, IDM_TOGGLE_ON_TOP,
-                           MF_BYCOMMAND | MFS_UNCHECKED );
-            SetWindowPos( p_vout->p_sys->hwnd, HWND_NOTOPMOST, 0, 0, 0, 0,
-                          SWP_NOSIZE | SWP_NOMOVE );
-        }
-
-        p_vout->p_sys->b_on_top_change = false;
-    }
-
-    /* Check if the event thread is still running */
-    if( !vlc_object_alive (p_vout->p_sys->p_event) )
-    {
-        return VLC_EGENERIC; /* exit */
-    }
-
     return VLC_SUCCESS;
 }
 
@@ -741,20 +592,20 @@ BOOL WINAPI DirectXEnumCallback( GUID* p_guid, LPTSTR psz_desc,
                                  HMONITOR hmon )
 {
     vout_thread_t *p_vout = (vout_thread_t *)p_context;
-    vlc_value_t device;
+    char *psz_device;
 
     msg_Dbg( p_vout, "DirectXEnumCallback: %s, %s", psz_desc, psz_drivername );
 
     if( hmon )
     {
-        var_Get( p_vout, "directx-device", &device );
+        psz_device = var_GetString( p_vout, "directx-device" );
 
-        if( ( !device.psz_string || !*device.psz_string ) &&
+        if( ( !psz_device || !*psz_device ) &&
             hmon == p_vout->p_sys->hmonitor )
         {
-            free( device.psz_string );
+            free( psz_device );
         }
-        else if( strcmp( psz_drivername, device.psz_string ) == 0 )
+        else if( strcmp( psz_drivername, psz_device ) == 0 )
         {
             MONITORINFO monitor_info;
             monitor_info.cbSize = sizeof( MONITORINFO );
@@ -778,11 +629,11 @@ BOOL WINAPI DirectXEnumCallback( GUID* p_guid, LPTSTR psz_desc,
             }
 
             p_vout->p_sys->hmonitor = hmon;
-            free( device.psz_string );
+            free( psz_device );
         }
         else
         {
-            free( device.psz_string );
+            free( psz_device );
             return TRUE; /* Keep enumerating */
         }
 
@@ -833,13 +684,13 @@ static int DirectXInitDDraw( vout_thread_t *p_vout )
 
     if( OurDirectDrawEnumerateEx && p_vout->p_sys->MonitorFromWindow )
     {
-        vlc_value_t device;
+        char *psz_device;
 
-        var_Get( p_vout, "directx-device", &device );
-        if( device.psz_string )
+        psz_device = var_GetString( p_vout, "directx-device" );
+        if( psz_device )
         {
-            msg_Dbg( p_vout, "directx-device: %s", device.psz_string );
-            free( device.psz_string );
+            msg_Dbg( p_vout, "directx-device: %s", psz_device );
+            free( psz_device );
         }
 
         p_vout->p_sys->hmonitor =
@@ -1414,6 +1265,7 @@ static int NewPictureVec( vout_thread_t *p_vout, picture_t *p_pic )
                         }
                     }
                 }
+                free( pi_codes );
             }
 
             if( b_result )
@@ -1960,11 +1812,9 @@ BOOL WINAPI DirectXEnumCallback2( GUID* p_guid, LPTSTR psz_desc,
 
     module_config_t *p_item = (module_config_t *)p_context;
 
-    p_item->ppsz_list =
-        (char **)realloc( p_item->ppsz_list,
+    p_item->ppsz_list = xrealloc( p_item->ppsz_list,
                           (p_item->i_list+2) * sizeof(char *) );
-    p_item->ppsz_list_text =
-        (char **)realloc( p_item->ppsz_list_text,
+    p_item->ppsz_list_text = xrealloc( p_item->ppsz_list_text,
                           (p_item->i_list+2) * sizeof(char *) );
 
     p_item->ppsz_list[p_item->i_list] = strdup( psz_drivername );
@@ -2044,8 +1894,8 @@ static int WallpaperCallback( vlc_object_t *p_this, char const *psz_cmd,
         {
             /* Modify playlist as well because the vout might have to be
              * restarted */
-            var_Create( p_playlist, "directx-wallpaper", VLC_VAR_BOOL );
-            var_Set( p_playlist, "directx-wallpaper", newval );
+            var_Create( p_playlist, "video-wallpaper", VLC_VAR_BOOL );
+            var_Set( p_playlist, "video-wallpaper", newval );
             pl_Release( p_vout );
         }