Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

x11.c

00001 /*****************************************************************************
00002  * x11.c: Screen capture module.
00003  *****************************************************************************
00004  * Copyright (C) 2004 the VideoLAN team
00005  * $Id: x11.c 11664 2005-07-09 06:17:09Z courmisch $
00006  *
00007  * Authors: Gildas Bazin <[email protected]>
00008  *
00009  * This program is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00022  *****************************************************************************/
00023 
00024 /*****************************************************************************
00025  * Preamble
00026  *****************************************************************************/
00027 #include <stdlib.h>
00028 
00029 #include <vlc/vlc.h>
00030 #include <vlc/input.h>
00031 
00032 #include <X11/Xlib.h>
00033 #include <X11/Xutil.h>
00034 
00035 #include "screen.h"
00036 
00037 int screen_InitCapture( demux_t *p_demux )
00038 {
00039     demux_sys_t *p_sys = p_demux->p_sys;
00040     Display *p_display;
00041     XWindowAttributes win_info;
00042     int i_chroma;
00043 
00044     /* Open the display */
00045     p_display = XOpenDisplay( NULL );
00046     if( !p_display )
00047     {
00048         msg_Err( p_demux, "cannot open display" );
00049         return VLC_EGENERIC;
00050     }
00051     p_sys->p_data = (void *)p_display;
00052 
00053     /* Get the parameters of the root window */
00054     if( !XGetWindowAttributes( p_display,
00055                                DefaultRootWindow( p_display ),
00056                                &win_info ) )
00057     {
00058         msg_Err( p_demux, "can't get root window attributes" );
00059         XCloseDisplay( p_display );
00060         return VLC_EGENERIC;
00061     }
00062 
00063     switch( win_info.depth )
00064     {
00065     case 8: /* FIXME: set the palette */
00066         i_chroma = VLC_FOURCC('R','G','B','2'); break;
00067     case 15:
00068         i_chroma = VLC_FOURCC('R','V','1','5'); break;
00069     case 16:
00070         i_chroma = VLC_FOURCC('R','V','1','6'); break;
00071     case 24:
00072     case 32:
00073         i_chroma = VLC_FOURCC('R','V','3','2');
00074         win_info.depth = 32;
00075         break;
00076     default:
00077         msg_Err( p_demux, "unknown screen depth %i", win_info.depth );
00078         XCloseDisplay( p_display );
00079         return VLC_EGENERIC;
00080     }
00081 
00082     es_format_Init( &p_sys->fmt, VIDEO_ES, i_chroma );
00083     p_sys->fmt.video.i_width  = win_info.width;
00084     p_sys->fmt.video.i_height = win_info.height;
00085     p_sys->fmt.video.i_bits_per_pixel = win_info.depth;
00086 
00087 #if 0
00088     win_info.visual->red_mask;
00089     win_info.visual->green_mask;
00090     win_info.visual->blue_mask;
00091     win_info.visual->bits_per_rgb;
00092 #endif
00093 
00094     return VLC_SUCCESS;
00095 }
00096 
00097 int screen_CloseCapture( demux_t *p_demux )
00098 {
00099     demux_sys_t *p_sys = p_demux->p_sys;
00100     Display *p_display = (Display *)p_sys->p_data;
00101 
00102     XCloseDisplay( p_display );
00103     return VLC_SUCCESS;
00104 }
00105 
00106 block_t *screen_Capture( demux_t *p_demux )
00107 {
00108     demux_sys_t *p_sys = p_demux->p_sys;
00109     Display *p_display = (Display *)p_sys->p_data;
00110     block_t *p_block;
00111     XImage *image;
00112     int i_size;
00113 
00114     image = XGetImage( p_display, DefaultRootWindow( p_display ),
00115                        0, 0, p_sys->fmt.video.i_width,
00116                        p_sys->fmt.video.i_height, AllPlanes, ZPixmap );
00117 
00118     if( !image )
00119     {
00120         msg_Warn( p_demux, "cannot get image" );
00121         return 0;
00122     }
00123 
00124     i_size = image->bytes_per_line * image->height;
00125 
00126     if( !( p_block = block_New( p_demux, i_size ) ) )
00127     {
00128         msg_Warn( p_demux, "cannot get block" );
00129         XDestroyImage( image );
00130         return 0;
00131     }
00132 
00133     memcpy( p_block->p_buffer, image->data, i_size );
00134 
00135     XDestroyImage( image );
00136 
00137     return p_block;
00138 }
00139 

Generated on Tue Dec 20 10:14:26 2005 for vlc-0.8.4a by  doxygen 1.4.2