]> git.sesse.net Git - vlc/blobdiff - modules/access/screen/win32.c
Qt: capture panel: Disable advanced options instead of being silent on
[vlc] / modules / access / screen / win32.c
index 6ffa9f792d2f0320a996cfb77334707848537784..0092df96faf673a9456dfa0ddc2467d37048caca 100644 (file)
@@ -1,24 +1,24 @@
 /*****************************************************************************
  * win32.c: Screen capture module.
  *****************************************************************************
- * Copyright (C) 2004-2008 the VideoLAN team
+ * Copyright (C) 2004-2011 VLC authors and VideoLAN
  * $Id$
  *
  * Authors: Gildas Bazin <gbazin@videolan.org>
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 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
- * GNU General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 /*****************************************************************************
 
 #include "screen.h"
 
-#ifndef CAPTUREBLT
-#   define CAPTUREBLT (DWORD)0x40000000 /* Include layered windows */
-#endif
-
 struct screen_data_t
 {
     HDC hdc_src;
@@ -55,16 +51,16 @@ int screen_InitCapture( demux_t *p_demux )
     screen_data_t *p_data;
     int i_chroma, i_bits_per_pixel;
 
-    p_sys->p_data = p_data = malloc( sizeof( screen_data_t ) );
+    p_sys->p_data = p_data = calloc( 1, sizeof( screen_data_t ) );
     if( !p_data )
         return VLC_ENOMEM;
-    memset( p_data, 0, sizeof( screen_data_t ) );
 
     /* Get the device context for the whole screen */
-    p_data->hdc_src = CreateDC( "DISPLAY", NULL, NULL, NULL );
+    p_data->hdc_src = CreateDC( TEXT("DISPLAY"), NULL, NULL, NULL );
     if( !p_data->hdc_src )
     {
         msg_Err( p_demux, "cannot get device context" );
+        free( p_data );
         return VLC_EGENERIC;
     }
 
@@ -72,6 +68,7 @@ int screen_InitCapture( demux_t *p_demux )
     if( !p_data->hdc_dst )
     {
         msg_Err( p_demux, "cannot get compat device context" );
+        free( p_data );
         ReleaseDC( 0, p_data->hdc_src );
         return VLC_EGENERIC;
     }
@@ -80,43 +77,43 @@ int screen_InitCapture( demux_t *p_demux )
     switch( i_bits_per_pixel )
     {
     case 8: /* FIXME: set the palette */
-        i_chroma = VLC_FOURCC('R','G','B','2'); break;
+        i_chroma = VLC_CODEC_RGB8; break;
     case 15:
     case 16:    /* Yes it is really 15 bits (when using BI_RGB) */
-        i_chroma = VLC_FOURCC('R','V','1','5'); break;
+        i_chroma = VLC_CODEC_RGB15; break;
     case 24:
-        i_chroma = VLC_FOURCC('R','V','2','4'); break;
+        i_chroma = VLC_CODEC_RGB24; break;
     case 32:
-        i_chroma = VLC_FOURCC('R','V','3','2'); break;
+        i_chroma = VLC_CODEC_RGB32; break;
     default:
-        msg_Err( p_demux, "unknown screen depth %i",
-                 p_sys->fmt.video.i_bits_per_pixel );
+        msg_Err( p_demux, "unknown screen depth %i", i_bits_per_pixel );
+        DeleteDC( p_data->hdc_dst );
         ReleaseDC( 0, p_data->hdc_src );
-        ReleaseDC( 0, p_data->hdc_dst );
+        free( p_data );
         return VLC_EGENERIC;
     }
 
     es_format_Init( &p_sys->fmt, VIDEO_ES, i_chroma );
-    p_sys->fmt.video.i_visible_width =
-    p_sys->fmt.video.i_width  = GetDeviceCaps( p_data->hdc_src, HORZRES );
+    p_sys->fmt.video.i_visible_width  =
+    p_sys->fmt.video.i_width          = GetDeviceCaps( p_data->hdc_src, HORZRES );
     p_sys->fmt.video.i_visible_height =
-    p_sys->fmt.video.i_height = GetDeviceCaps( p_data->hdc_src, VERTRES );
+    p_sys->fmt.video.i_height         = GetDeviceCaps( p_data->hdc_src, VERTRES );
     p_sys->fmt.video.i_bits_per_pixel = i_bits_per_pixel;
-    p_sys->fmt.video.i_chroma = i_chroma;
+    p_sys->fmt.video.i_chroma         = i_chroma;
 
     switch( i_chroma )
     {
-    case VLC_FOURCC('R','V','1','5'):
+    case VLC_CODEC_RGB15:
         p_sys->fmt.video.i_rmask = 0x7c00;
         p_sys->fmt.video.i_gmask = 0x03e0;
         p_sys->fmt.video.i_bmask = 0x001f;
         break;
-    case VLC_FOURCC('R','V','2','4'):
+    case VLC_CODEC_RGB24:
         p_sys->fmt.video.i_rmask = 0x00ff0000;
         p_sys->fmt.video.i_gmask = 0x0000ff00;
         p_sys->fmt.video.i_bmask = 0x000000ff;
         break;
-    case VLC_FOURCC('R','V','3','2'):
+    case VLC_CODEC_RGB32:
         p_sys->fmt.video.i_rmask = 0x00ff0000;
         p_sys->fmt.video.i_gmask = 0x0000ff00;
         p_sys->fmt.video.i_bmask = 0x000000ff;
@@ -126,7 +123,6 @@ int screen_InitCapture( demux_t *p_demux )
         break;
     }
 
-
     return VLC_SUCCESS;
 }
 
@@ -155,7 +151,7 @@ struct block_sys_t
 
 static void CaptureBlockRelease( block_t *p_block )
 {
-    DeleteObject( ((block_sys_t *)p_block)->hbmp );
+    DeleteObject( ((struct block_sys_t *)p_block)->hbmp );
     free( p_block );
 }
 
@@ -163,35 +159,32 @@ static block_t *CaptureBlockNew( demux_t *p_demux )
 {
     demux_sys_t *p_sys = p_demux->p_sys;
     screen_data_t *p_data = p_sys->p_data;
-    block_sys_t *p_block;
+    struct block_sys_t *p_block;
     void *p_buffer;
     int i_buffer;
     HBITMAP hbmp;
 
     if( p_data->bmi.bmiHeader.biSize == 0 )
     {
-        vlc_value_t val;
+        int i_val;
         /* Create the bitmap info header */
-        p_data->bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
-        p_data->bmi.bmiHeader.biWidth = p_sys->fmt.video.i_width;
-        p_data->bmi.bmiHeader.biHeight = - p_sys->fmt.video.i_height;
-        p_data->bmi.bmiHeader.biPlanes = 1;
-        p_data->bmi.bmiHeader.biBitCount = p_sys->fmt.video.i_bits_per_pixel;
-        p_data->bmi.bmiHeader.biCompression = BI_RGB;
-        p_data->bmi.bmiHeader.biSizeImage = 0;
-        p_data->bmi.bmiHeader.biXPelsPerMeter =
-            p_data->bmi.bmiHeader.biYPelsPerMeter = 0;
-        p_data->bmi.bmiHeader.biClrUsed = 0;
-        p_data->bmi.bmiHeader.biClrImportant = 0;
-
-        var_Create( p_demux, "screen-fragment-size",
-                    VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
-        var_Get( p_demux, "screen-fragment-size", &val );
-        p_data->i_fragment_size =
-            val.i_int > 0 ? val.i_int : p_sys->fmt.video.i_height;
-        p_data->i_fragment_size =
-            val.i_int > p_sys->fmt.video.i_height ? p_sys->fmt.video.i_height :
-            p_data->i_fragment_size;
+        p_data->bmi.bmiHeader.biSize          = sizeof(BITMAPINFOHEADER);
+        p_data->bmi.bmiHeader.biWidth         = p_sys->fmt.video.i_width;
+        p_data->bmi.bmiHeader.biHeight        = - p_sys->fmt.video.i_height;
+        p_data->bmi.bmiHeader.biPlanes        = 1;
+        p_data->bmi.bmiHeader.biBitCount      = p_sys->fmt.video.i_bits_per_pixel;
+        p_data->bmi.bmiHeader.biCompression   = BI_RGB;
+        p_data->bmi.bmiHeader.biSizeImage     = 0;
+        p_data->bmi.bmiHeader.biXPelsPerMeter = 0;
+        p_data->bmi.bmiHeader.biYPelsPerMeter = 0;
+        p_data->bmi.bmiHeader.biClrUsed       = 0;
+        p_data->bmi.bmiHeader.biClrImportant  = 0;
+
+        i_val = var_CreateGetInteger( p_demux, "screen-fragment-size" );
+        p_data->i_fragment_size = i_val > 0 ? i_val : (int)p_sys->fmt.video.i_height;
+        p_data->i_fragment_size = i_val > (int)p_sys->fmt.video.i_height ?
+                                            (int)p_sys->fmt.video.i_height :
+                                            p_data->i_fragment_size;
         p_sys->f_fps *= (p_sys->fmt.video.i_height/p_data->i_fragment_size);
         p_sys->i_incr = 1000000 / p_sys->f_fps;
         p_data->i_fragment = 0;
@@ -205,8 +198,7 @@ static block_t *CaptureBlockNew( demux_t *p_demux )
     if( !hbmp || !p_buffer )
     {
         msg_Err( p_demux, "cannot create bitmap" );
-        if( hbmp ) DeleteObject( hbmp );
-        return NULL;
+        goto error;
     }
 
     /* Select the bitmap into the compatible DC */
@@ -218,16 +210,13 @@ static block_t *CaptureBlockNew( demux_t *p_demux )
     if( !p_data->hgdi_backup )
     {
         msg_Err( p_demux, "cannot select bitmap" );
-        DeleteObject( hbmp );
-        return NULL;
+        goto error;
     }
 
     /* Build block */
-    if( !(p_block = malloc( sizeof( block_t ) + sizeof( block_sys_t ) )) )
-    {
-        DeleteObject( hbmp );
-        return NULL;
-    }
+    if( !(p_block = malloc( sizeof( block_t ) + sizeof( struct block_sys_t ) )) )
+        goto error;
+
     /* Fill all fields */
     i_buffer = (p_sys->fmt.video.i_bits_per_pixel + 7) / 8 *
         p_sys->fmt.video.i_width * p_sys->fmt.video.i_height;
@@ -236,6 +225,10 @@ static block_t *CaptureBlockNew( demux_t *p_demux )
     p_block->hbmp            = hbmp;
 
     return &p_block->self;
+
+error:
+    if( hbmp ) DeleteObject( hbmp );
+    return NULL;
 }
 
 block_t *screen_Capture( demux_t *p_demux )
@@ -248,7 +241,7 @@ block_t *screen_Capture( demux_t *p_demux )
         if( !( p_data->p_block = CaptureBlockNew( p_demux ) ) )
         {
             msg_Warn( p_demux, "cannot get block" );
-            return 0;
+            return NULL;
         }
     }