00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <stdlib.h>
00025
00026 #include <vlc/vlc.h>
00027 #include <vlc/input.h>
00028
00029 #include <Screen.h>
00030 #include <Bitmap.h>
00031
00032 extern "C"
00033 {
00034
00035 #include "screen.h"
00036
00037 struct screen_data_t
00038 {
00039 BScreen * p_screen;
00040 BBitmap * p_bitmap;
00041 };
00042
00043 int screen_InitCapture( demux_t *p_demux )
00044 {
00045 demux_sys_t *p_sys = p_demux->p_sys;
00046 screen_data_t *p_data;
00047 BRect rect;
00048 int i_chroma;
00049 int i_bits_per_pixel;
00050
00051 p_sys->p_data = p_data =
00052 (screen_data_t *)malloc( sizeof( screen_data_t ) );
00053
00054 p_data->p_screen = new BScreen();
00055 rect = p_data->p_screen->Frame();
00056
00057 p_data->p_bitmap = new BBitmap( rect, p_data->p_screen->ColorSpace() );
00058
00059 switch( p_data->p_screen->ColorSpace() )
00060 {
00061 case B_RGB32:
00062 i_chroma = VLC_FOURCC('R','V','3','2');
00063 i_bits_per_pixel = 32;
00064 break;
00065 case B_RGB16:
00066 i_chroma = VLC_FOURCC('R','V','1','6');
00067 i_bits_per_pixel = 16;
00068 break;
00069 default:
00070 msg_Err( p_demux, "screen depth %i unsupported",
00071 p_data->p_screen->ColorSpace() );
00072 delete p_data->p_bitmap;
00073 delete p_data->p_screen;
00074 free( p_data );
00075 return VLC_EGENERIC;
00076 }
00077 es_format_Init( &p_sys->fmt, VIDEO_ES, i_chroma );
00078 p_sys->fmt.video.i_width = (int)rect.Width();
00079 p_sys->fmt.video.i_height = (int)rect.Height();
00080 p_sys->fmt.video.i_bits_per_pixel = i_bits_per_pixel;
00081
00082 return VLC_SUCCESS;
00083 }
00084
00085 int screen_CloseCapture( demux_t *p_demux )
00086 {
00087 demux_sys_t *p_sys = p_demux->p_sys;
00088 screen_data_t *p_data = p_sys->p_data;
00089
00090 delete p_data->p_bitmap;
00091 delete p_data->p_screen;
00092 free( p_data );
00093
00094 return VLC_SUCCESS;
00095 }
00096
00097 block_t *screen_Capture( demux_t *p_demux )
00098 {
00099 demux_sys_t *p_sys = p_demux->p_sys;
00100 screen_data_t *p_data = p_sys->p_data;
00101 block_t *p_block;
00102
00103 p_block = block_New( p_demux, p_sys->fmt.video.i_width *
00104 p_sys->fmt.video.i_height *
00105 p_sys->fmt.video.i_bits_per_pixel / 8 );
00106
00107 p_data->p_screen->ReadBitmap( p_data->p_bitmap );
00108
00109 for( unsigned i = 0; i < p_sys->fmt.video.i_height; i++ )
00110 {
00111 memcpy( p_block->p_buffer + i * p_sys->fmt.video.i_width *
00112 p_sys->fmt.video.i_bits_per_pixel / 8,
00113 (uint8_t *) p_data->p_bitmap->Bits() +
00114 i * p_data->p_bitmap->BytesPerRow(),
00115 p_sys->fmt.video.i_width *
00116 p_sys->fmt.video.i_bits_per_pixel / 8 );
00117 }
00118 return p_block;
00119 }
00120
00121 }