[vlc-devel] commit: Modified the way title is updated (msw). (Laurent Aimar )

git version control git at videolan.org
Mon Sep 28 20:56:57 CEST 2009


vlc | branch: master | Laurent Aimar <fenrir at videolan.org> | Mon Sep 28 20:50:46 2009 +0200| [b28b938857b3dec075c094d89198ee756e968bd6] | committer: Laurent Aimar 

Modified the way title is updated (msw).

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=b28b938857b3dec075c094d89198ee756e968bd6
---

 modules/video_output/msw/direct3d.c |    2 +-
 modules/video_output/msw/directx.c  |   12 +++++-
 modules/video_output/msw/events.c   |   73 +++++++++++++++++------------------
 modules/video_output/msw/glwin32.c  |    2 +-
 modules/video_output/msw/vout.h     |    4 ++
 modules/video_output/msw/wingdi.c   |    6 ++-
 6 files changed, 56 insertions(+), 43 deletions(-)

diff --git a/modules/video_output/msw/direct3d.c b/modules/video_output/msw/direct3d.c
index c4384b2..f6ecbfc 100644
--- a/modules/video_output/msw/direct3d.c
+++ b/modules/video_output/msw/direct3d.c
@@ -275,7 +275,7 @@ static int Init( vout_thread_t *p_vout )
     }
 
     /* Change the window title bar text */
-    PostMessage( p_vout->p_sys->hwnd, WM_VLC_CHANGE_TEXT, 0, 0 );
+    EventThreadUpdateTitle( p_vout->p_sys->p_event, VOUT_TITLE " (Direct3D output)" );
 
     p_vout->fmt_out.i_chroma = p_vout->output.i_chroma;
     return VLC_SUCCESS;
diff --git a/modules/video_output/msw/directx.c b/modules/video_output/msw/directx.c
index 5af1c0d..ae27d9e 100644
--- a/modules/video_output/msw/directx.c
+++ b/modules/video_output/msw/directx.c
@@ -385,10 +385,18 @@ static int Init( vout_thread_t *p_vout )
         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 );
 
-    p_vout->fmt_out.i_chroma = p_vout->output.i_chroma;
     return VLC_SUCCESS;
 }
 
diff --git a/modules/video_output/msw/events.c b/modules/video_output/msw/events.c
index 6702835..2104dce 100644
--- a/modules/video_output/msw/events.c
+++ b/modules/video_output/msw/events.c
@@ -330,50 +330,30 @@ static void *EventThread( void *p_this )
             break;
 
         case WM_VLC_CHANGE_TEXT:
-            var_Get( p_vout, "video-title", &val );
-            if( !val.psz_string || !*val.psz_string ) /* Default video title */
-            {
-                free( val.psz_string );
-
-#ifdef MODULE_NAME_IS_wingdi
-                val.psz_string = strdup( VOUT_TITLE " (WinGDI output)" );
-#endif
-#ifdef MODULE_NAME_IS_wingapi
-                val.psz_string = strdup( VOUT_TITLE " (WinGAPI output)" );
-#endif
-#ifdef MODULE_NAME_IS_glwin32
-                val.psz_string = strdup( VOUT_TITLE " (OpenGL output)" );
-#endif
-#ifdef MODULE_NAME_IS_direct3d
-                val.psz_string = strdup( VOUT_TITLE " (Direct3D output)" );
-#endif
-#ifdef MODULE_NAME_IS_directx
-                if( p_event->p_vout->p_sys->b_using_overlay ) val.psz_string =
-                    strdup( VOUT_TITLE " (hardware YUV overlay DirectX output)" );
-                else if( p_event->p_vout->p_sys->b_hw_yuv ) val.psz_string =
-                    strdup( VOUT_TITLE " (hardware YUV DirectX output)" );
-                else val.psz_string =
-                    strdup( VOUT_TITLE " (software RGB DirectX output)" );
-#endif
-            }
-
+        {
+            vlc_mutex_lock( &p_event->lock );
+            wchar_t *pwz_title = NULL;
+            if( p_event->psz_title )
             {
-                wchar_t *psz_title = malloc( strlen(val.psz_string) * 2 + 2 );
-                if( psz_title )
+                const size_t i_length = strlen(p_event->psz_title);
+                pwz_title = malloc( 2 * (i_length + 1) );
+                if( pwz_title )
                 {
-                    mbstowcs( psz_title, val.psz_string, strlen(val.psz_string)*2);
-                    psz_title[strlen(val.psz_string)] = 0;
-                    free( val.psz_string ); val.psz_string = (char *)psz_title;
+                    mbstowcs( pwz_title, p_event->psz_title, 2 * i_length );
+                    pwz_title[i_length] = 0;
                 }
             }
+            vlc_mutex_unlock( &p_event->lock );
 
-            SetWindowText( p_event->p_vout->p_sys->hwnd,
-                           (LPCTSTR)val.psz_string );
-            if( p_event->p_vout->p_sys->hfswnd )
-                SetWindowText( p_event->p_vout->p_sys->hfswnd,
-                               (LPCTSTR)val.psz_string );
-            free( val.psz_string );
+            if( pwz_title )
+            {
+                SetWindowText( p_vout->p_sys->hwnd, (LPCTSTR)pwz_title );
+                if( p_vout->p_sys->hfswnd )
+                    SetWindowText( p_vout->p_sys->hfswnd, (LPCTSTR)pwz_title );
+                free( pwz_title );
+            }
             break;
+        }
 
         default:
             /* Messages we don't handle directly are dispatched to the
@@ -913,6 +893,21 @@ void EventThreadMouseAutoHide( event_thread_t *p_event )
         }
     }
 }
+void EventThreadUpdateTitle( event_thread_t *p_event, const char *psz_fallback )
+{
+    char *psz_title = var_GetNonEmptyString( p_event->p_vout, "video-title" );
+    if( !psz_title )
+        psz_title = strdup( psz_fallback );
+    if( !psz_title )
+        return;
+
+    vlc_mutex_lock( &p_event->lock );
+    free( p_event->psz_title );
+    p_event->psz_title = psz_title;
+    vlc_mutex_unlock( &p_event->lock );
+
+    PostMessage( p_event->p_vout->p_sys->hwnd, WM_VLC_CHANGE_TEXT, 0, 0 );
+}
 
 event_thread_t *EventThreadCreate( vout_thread_t *p_vout )
 {
@@ -936,12 +931,14 @@ event_thread_t *EventThreadCreate( vout_thread_t *p_vout )
     p_event->i_lastmoved          = mdate();
     p_event->i_mouse_hide_timeout =
         var_GetInteger(p_vout, "mouse-hide-timeout") * 1000;
+    p_event->psz_title = NULL;
    
     return p_event;
 }
 
 void EventThreadDestroy( event_thread_t *p_event )
 {
+    free( p_event->psz_title );
     vlc_cond_destroy( &p_event->wait );
     vlc_mutex_destroy( &p_event->lock );
     free( p_event );
diff --git a/modules/video_output/msw/glwin32.c b/modules/video_output/msw/glwin32.c
index 5b92bce..46226fa 100644
--- a/modules/video_output/msw/glwin32.c
+++ b/modules/video_output/msw/glwin32.c
@@ -123,7 +123,7 @@ static int Init( vout_thread_t *p_vout )
     int iFormat;
 
     /* Change the window title bar text */
-    PostMessage( p_vout->p_sys->hwnd, WM_VLC_CHANGE_TEXT, 0, 0 );
+    EventThreadUpdateTitle( p_vout->p_sys->p_event, VOUT_TITLE " (OpenGL output)" );
 
     p_vout->p_sys->hGLDC = GetDC( p_vout->p_sys->hvideownd );
 
diff --git a/modules/video_output/msw/vout.h b/modules/video_output/msw/vout.h
index 3697c03..6a974ed 100644
--- a/modules/video_output/msw/vout.h
+++ b/modules/video_output/msw/vout.h
@@ -42,6 +42,9 @@ typedef struct
     volatile mtime_t i_lastmoved;
     mtime_t          i_mouse_hide_timeout;
 
+    /* Title */
+    char *psz_title;
+
 } event_thread_t;
 
 #ifdef MODULE_NAME_IS_wingapi
@@ -263,6 +266,7 @@ int             EventThreadStart( event_thread_t * );
 void            EventThreadStop( event_thread_t * );
 
 void            EventThreadMouseAutoHide( event_thread_t * );
+void            EventThreadUpdateTitle( event_thread_t *, const char *psz_fallback );
 
 /*****************************************************************************
  * Prototypes from common.c
diff --git a/modules/video_output/msw/wingdi.c b/modules/video_output/msw/wingdi.c
index 0078c4f..86185d9 100644
--- a/modules/video_output/msw/wingdi.c
+++ b/modules/video_output/msw/wingdi.c
@@ -270,7 +270,11 @@ static int Init( vout_thread_t *p_vout )
     PP_OUTPUTPICTURE[ I_OUTPUTPICTURES++ ] = p_pic;
 
     /* Change the window title bar text */
-    PostMessage( p_vout->p_sys->hwnd, WM_VLC_CHANGE_TEXT, 0, 0 );
+#ifdef MODULE_NAME_IS_wingapi
+    EventThreadUpdateTitle( p_vout->p_sys->p_event, VOUT_TITLE " (WinGAPI output)" );
+#else
+    EventThreadUpdateTitle( p_vout->p_sys->p_event, VOUT_TITLE " (WinGDI output)" );
+#endif
     UpdateRects( p_vout, true );
 
     return VLC_SUCCESS;




More information about the vlc-devel mailing list