00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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
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
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:
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