| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
#include <errno.h> |
|---|
| 29 |
#include <unistd.h> |
|---|
| 30 |
#include <fcntl.h> |
|---|
| 31 |
#include <sys/ioctl.h> |
|---|
| 32 |
#include <sys/mman.h> |
|---|
| 33 |
|
|---|
| 34 |
#ifdef HAVE_CONFIG_H |
|---|
| 35 |
# include "config.h" |
|---|
| 36 |
#endif |
|---|
| 37 |
|
|---|
| 38 |
#include <vlc_common.h> |
|---|
| 39 |
#include <vlc_plugin.h> |
|---|
| 40 |
#include <vlc_vout.h> |
|---|
| 41 |
|
|---|
| 42 |
#ifdef SYS_BSD |
|---|
| 43 |
#include <sys/types.h> |
|---|
| 44 |
#endif |
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
static int Create ( vlc_object_t * ); |
|---|
| 50 |
static void Destroy ( vlc_object_t * ); |
|---|
| 51 |
|
|---|
| 52 |
static int Init ( vout_thread_t * ); |
|---|
| 53 |
static void End ( vout_thread_t * ); |
|---|
| 54 |
static void Display ( vout_thread_t *, picture_t * ); |
|---|
| 55 |
|
|---|
| 56 |
static int NewPicture ( vout_thread_t *, picture_t * ); |
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 |
vlc_module_begin(); |
|---|
| 62 |
set_description( N_("Matrox Graphic Array video output") ); |
|---|
| 63 |
set_capability( "video output", 10 ); |
|---|
| 64 |
set_callbacks( Create, Destroy ); |
|---|
| 65 |
vlc_module_end(); |
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 |
#ifndef __LINUX_MGAVID_H |
|---|
| 74 |
# define __LINUX_MGAVID_H |
|---|
| 75 |
|
|---|
| 76 |
# define MGA_VID_CONFIG _IOR('J', 1, mga_vid_config_t) |
|---|
| 77 |
# define MGA_VID_ON _IO ('J', 2) |
|---|
| 78 |
# define MGA_VID_OFF _IO ('J', 3) |
|---|
| 79 |
# define MGA_VID_FSEL _IOR('J', 4, int) |
|---|
| 80 |
# define MGA_G200 0x1234 |
|---|
| 81 |
# define MGA_G400 0x5678 |
|---|
| 82 |
|
|---|
| 83 |
# define MGA_VID_FORMAT_YV12 0x32315659 |
|---|
| 84 |
# define MGA_VID_FORMAT_IYUV (('I'<<24)|('Y'<<16)|('U'<<8)|'V') |
|---|
| 85 |
# define MGA_VID_FORMAT_I420 (('I'<<24)|('4'<<16)|('2'<<8)|'0') |
|---|
| 86 |
# define MGA_VID_FORMAT_YUY2 (('Y'<<24)|('U'<<16)|('Y'<<8)|'2') |
|---|
| 87 |
# define MGA_VID_FORMAT_UYVY (('U'<<24)|('Y'<<16)|('V'<<8)|'Y') |
|---|
| 88 |
|
|---|
| 89 |
# define MGA_VID_VERSION 0x0201 |
|---|
| 90 |
|
|---|
| 91 |
# define MGA_NUM_FRAMES 1 |
|---|
| 92 |
|
|---|
| 93 |
typedef struct mga_vid_config_t |
|---|
| 94 |
{ |
|---|
| 95 |
uint16_t version; |
|---|
| 96 |
uint16_t card_type; |
|---|
| 97 |
uint32_t ram_size; |
|---|
| 98 |
uint32_t src_width; |
|---|
| 99 |
uint32_t src_height; |
|---|
| 100 |
uint32_t dest_width; |
|---|
| 101 |
uint32_t dest_height; |
|---|
| 102 |
uint32_t x_org; |
|---|
| 103 |
uint32_t y_org; |
|---|
| 104 |
uint8_t colkey_on; |
|---|
| 105 |
uint8_t colkey_red; |
|---|
| 106 |
uint8_t colkey_green; |
|---|
| 107 |
uint8_t colkey_blue; |
|---|
| 108 |
uint32_t format; |
|---|
| 109 |
uint32_t frame_size; |
|---|
| 110 |
uint32_t num_frames; |
|---|
| 111 |
} mga_vid_config_t; |
|---|
| 112 |
#endif |
|---|
| 113 |
|
|---|
| 114 |
struct vout_sys_t |
|---|
| 115 |
{ |
|---|
| 116 |
mga_vid_config_t mga; |
|---|
| 117 |
int i_fd; |
|---|
| 118 |
uint8_t * p_video; |
|---|
| 119 |
}; |
|---|
| 120 |
|
|---|
| 121 |
struct picture_sys_t |
|---|
| 122 |
{ |
|---|
| 123 |
int i_frame; |
|---|
| 124 |
}; |
|---|
| 125 |
|
|---|
| 126 |
#define CEIL32(x) (((x)+31)&~31) |
|---|
| 127 |
|
|---|
| 128 |
|
|---|
| 129 |
|
|---|
| 130 |
|
|---|
| 131 |
|
|---|
| 132 |
|
|---|
| 133 |
static int Create( vlc_object_t *p_this ) |
|---|
| 134 |
{ |
|---|
| 135 |
vout_thread_t *p_vout = (vout_thread_t *)p_this; |
|---|
| 136 |
|
|---|
| 137 |
|
|---|
| 138 |
p_vout->p_sys = malloc( sizeof( vout_sys_t ) ); |
|---|
| 139 |
if( p_vout->p_sys == NULL ) |
|---|
| 140 |
return( 1 ); |
|---|
| 141 |
|
|---|
| 142 |
p_vout->p_sys->i_fd = open( "/dev/mga_vid", O_RDWR ); |
|---|
| 143 |
if( p_vout->p_sys->i_fd == -1 ) |
|---|
| 144 |
{ |
|---|
| 145 |
msg_Err( p_vout, "cannot open MGA driver /dev/mga_vid" ); |
|---|
| 146 |
free( p_vout->p_sys ); |
|---|
| 147 |
return( 1 ); |
|---|
| 148 |
} |
|---|
| 149 |
|
|---|
| 150 |
p_vout->pf_init = Init; |
|---|
| 151 |
p_vout->pf_end = End; |
|---|
| 152 |
p_vout->pf_manage = NULL; |
|---|
| 153 |
p_vout->pf_render = NULL; |
|---|
| 154 |
p_vout->pf_display = Display; |
|---|
| 155 |
|
|---|
| 156 |
return( 0 ); |
|---|
| 157 |
} |
|---|
| 158 |
|
|---|
| 159 |
|
|---|
| 160 |
|
|---|
| 161 |
|
|---|
| 162 |
static int Init( vout_thread_t *p_vout ) |
|---|
| 163 |
{ |
|---|
| 164 |
int i_index; |
|---|
| 165 |
picture_t *p_pic; |
|---|
| 166 |
|
|---|
| 167 |
I_OUTPUTPICTURES = 0; |
|---|
| 168 |
|
|---|
| 169 |
|
|---|
| 170 |
p_vout->output.i_width = p_vout->render.i_width; |
|---|
| 171 |
p_vout->output.i_height = p_vout->render.i_height; |
|---|
| 172 |
p_vout->output.i_aspect = p_vout->render.i_aspect; |
|---|
| 173 |
|
|---|
| 174 |
|
|---|
| 175 |
p_vout->p_sys->mga.src_width = CEIL32(p_vout->output.i_width); |
|---|
| 176 |
p_vout->p_sys->mga.src_height = p_vout->output.i_height; |
|---|
| 177 |
vout_PlacePicture( p_vout, 1024, 768, |
|---|
| 178 |
&p_vout->p_sys->mga.x_org, &p_vout->p_sys->mga.y_org, |
|---|
| 179 |
&p_vout->p_sys->mga.dest_width, |
|---|
| 180 |
&p_vout->p_sys->mga.dest_height ); |
|---|
| 181 |
|
|---|
| 182 |
|
|---|
| 183 |
p_vout->p_sys->mga.colkey_on = 0; |
|---|
| 184 |
p_vout->p_sys->mga.num_frames = MGA_NUM_FRAMES; |
|---|
| 185 |
p_vout->p_sys->mga.frame_size = CEIL32(p_vout->output.i_width) |
|---|
| 186 |
* p_vout->output.i_height * 2; |
|---|
| 187 |
p_vout->p_sys->mga.version = MGA_VID_VERSION; |
|---|
| 188 |
|
|---|
| 189 |
|
|---|
| 190 |
|
|---|
| 191 |
p_vout->output.i_chroma = VLC_FOURCC('Y','M','G','A'); |
|---|
| 192 |
p_vout->p_sys->mga.format = MGA_VID_FORMAT_YV12; |
|---|
| 193 |
|
|---|
| 194 |
if( ioctl(p_vout->p_sys->i_fd, MGA_VID_CONFIG, &p_vout->p_sys->mga) ) |
|---|
| 195 |
{ |
|---|
| 196 |
msg_Err( p_vout, "MGA config ioctl failed" ); |
|---|
| 197 |
return -1; |
|---|
| 198 |
} |
|---|
| 199 |
|
|---|
| 200 |
if( p_vout->p_sys->mga.card_type == MGA_G200 ) |
|---|
| 201 |
{ |
|---|
| 202 |
msg_Dbg( p_vout, "detected MGA G200 (%d MB Ram)", |
|---|
| 203 |
p_vout->p_sys->mga.ram_size ); |
|---|
| 204 |
} |
|---|
| 205 |
else |
|---|
| 206 |
{ |
|---|
| 207 |
msg_Dbg( p_vout, "detected MGA G400/G450 (%d MB Ram)", |
|---|
| 208 |
p_vout->p_sys->mga.ram_size ); |
|---|
| 209 |
} |
|---|
| 210 |
|
|---|
| 211 |
p_vout->p_sys->p_video = mmap( 0, p_vout->p_sys->mga.frame_size |
|---|
| 212 |
* MGA_NUM_FRAMES, |
|---|
| 213 |
PROT_WRITE, MAP_SHARED, |
|---|
| 214 |
p_vout->p_sys->i_fd, 0 ); |
|---|
| 215 |
|
|---|
| 216 |
|
|---|
| 217 |
while( I_OUTPUTPICTURES < MGA_NUM_FRAMES ) |
|---|
| 218 |
{ |
|---|
| 219 |
p_pic = NULL; |
|---|
| 220 |
|
|---|
| 221 |
|
|---|
| 222 |
for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ ) |
|---|
| 223 |
{ |
|---|
| 224 |
if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE ) |
|---|
| 225 |
{ |
|---|
| 226 |
p_pic = p_vout->p_picture + i_index; |
|---|
| 227 |
break; |
|---|
| 228 |
} |
|---|
| 229 |
} |
|---|
| 230 |
|
|---|
| 231 |
|
|---|
| 232 |
if( p_pic == NULL || NewPicture( p_vout, p_pic ) ) |
|---|
| 233 |
{ |
|---|
| 234 |
break; |
|---|
| 235 |
} |
|---|
| 236 |
|
|---|
| 237 |
p_pic->i_status = DESTROYED_PICTURE; |
|---|
| 238 |
p_pic->i_type = DIRECT_PICTURE; |
|---|
| 239 |
|
|---|
| 240 |
PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic; |
|---|
| 241 |
|
|---|
| 242 |
I_OUTPUTPICTURES++; |
|---|
| 243 |
} |
|---|
| 244 |
|
|---|
| 245 |
|
|---|
| 246 |
for( i_index = 0; i_index < I_OUTPUTPICTURES; i_index++ ) |
|---|
| 247 |
{ |
|---|
| 248 |
memset( p_vout->p_sys->p_video |
|---|
| 249 |
+ p_vout->p_sys->mga.frame_size * i_index, |
|---|
| 250 |
0x00, p_vout->p_sys->mga.frame_size / 2 ); |
|---|
| 251 |
memset( p_vout->p_sys->p_video |
|---|
| 252 |
+ p_vout->p_sys->mga.frame_size * ( 2*i_index + 1 ) / 2, |
|---|
| 253 |
0x80, p_vout->p_sys->mga.frame_size / 2 ); |
|---|
| 254 |
} |
|---|
| 255 |
|
|---|
| 256 |
|
|---|
| 257 |
ioctl( p_vout->p_sys->i_fd, MGA_VID_ON, 0 ); |
|---|
| 258 |
|
|---|
| 259 |
return( 0 ); |
|---|
| 260 |
} |
|---|
| 261 |
|
|---|
| 262 |
|
|---|
| 263 |
|
|---|
| 264 |
|
|---|
| 265 |
static void End( vout_thread_t *p_vout ) |
|---|
| 266 |
{ |
|---|
| 267 |
int i_index; |
|---|
| 268 |
|
|---|
| 269 |
ioctl( p_vout->p_sys->i_fd, MGA_VID_OFF, 0 ); |
|---|
| 270 |
|
|---|
| 271 |
|
|---|
| 272 |
for( i_index = I_OUTPUTPICTURES ; i_index ; ) |
|---|
| 273 |
{ |
|---|
| 274 |
i_index--; |
|---|
| 275 |
} |
|---|
| 276 |
} |
|---|
| 277 |
|
|---|
| 278 |
|
|---|
| 279 |
|
|---|
| 280 |
|
|---|
| 281 |
|
|---|
| 282 |
|
|---|
| 283 |
static void Destroy( vlc_object_t *p_this ) |
|---|
| 284 |
{ |
|---|
| 285 |
vout_thread_t *p_vout = (vout_thread_t *)p_this; |
|---|
| 286 |
close( p_vout->p_sys->i_fd ); |
|---|
| 287 |
free( p_vout->p_sys ); |
|---|
| 288 |
} |
|---|
| 289 |
|
|---|
| 290 |
|
|---|
| 291 |
|
|---|
| 292 |
|
|---|
| 293 |
static void Display( vout_thread_t *p_vout, picture_t *p_pic ) |
|---|
| 294 |
{ |
|---|
| 295 |
ioctl( p_vout->p_sys->i_fd, MGA_VID_FSEL, &p_pic->p_sys->i_frame ); |
|---|
| 296 |
} |
|---|
| 297 |
|
|---|
| 298 |
|
|---|
| 299 |
|
|---|
| 300 |
|
|---|
| 301 |
|
|---|
| 302 |
|
|---|
| 303 |
|
|---|
| 304 |
|
|---|
| 305 |
static int NewPicture( vout_thread_t *p_vout, picture_t *p_pic ) |
|---|
| 306 |
{ |
|---|
| 307 |
|
|---|
| 308 |
|
|---|
| 309 |
p_pic->p_data = p_vout->p_sys->p_video + I_OUTPUTPICTURES |
|---|
| 310 |
* p_vout->p_sys->mga.frame_size; |
|---|
| 311 |
|
|---|
| 312 |
p_pic->p_sys = malloc( sizeof( picture_sys_t ) ); |
|---|
| 313 |
|
|---|
| 314 |
if( p_pic->p_sys == NULL ) |
|---|
| 315 |
{ |
|---|
| 316 |
return -1; |
|---|
| 317 |
} |
|---|
| 318 |
|
|---|
| 319 |
p_pic->Y_PIXELS = p_pic->p_data; |
|---|
| 320 |
p_pic->p[Y_PLANE].i_lines = p_vout->output.i_height; |
|---|
| 321 |
p_pic->p[Y_PLANE].i_visible_lines = p_vout->output.i_height; |
|---|
| 322 |
p_pic->p[Y_PLANE].i_pitch = CEIL32( p_vout->output.i_width ); |
|---|
| 323 |
p_pic->p[Y_PLANE].i_pixel_pitch = 1; |
|---|
| 324 |
p_pic->p[Y_PLANE].i_visible_pitch = p_vout->output.i_width; |
|---|
| 325 |
|
|---|
| 326 |
p_pic->U_PIXELS = p_pic->p_data + p_vout->p_sys->mga.frame_size * 2/4; |
|---|
| 327 |
p_pic->p[U_PLANE].i_lines = p_vout->output.i_height / 2; |
|---|
| 328 |
p_pic->p[U_PLANE].i_visible_lines = p_vout->output.i_height / 2; |
|---|
| 329 |
p_pic->p[U_PLANE].i_pitch = CEIL32( p_vout->output.i_width ) / 2; |
|---|
| 330 |
p_pic->p[U_PLANE].i_pixel_pitch = 1; |
|---|
| 331 |
p_pic->p[U_PLANE].i_visible_pitch = p_pic->p[U_PLANE].i_pitch; |
|---|
| 332 |
|
|---|
| 333 |
p_pic->V_PIXELS = p_pic->p_data + p_vout->p_sys->mga.frame_size * 3/4; |
|---|
| 334 |
p_pic->p[V_PLANE].i_lines = p_vout->output.i_height / 2; |
|---|
| 335 |
p_pic->p[V_PLANE].i_visible_lines = p_vout->output.i_height / 2; |
|---|
| 336 |
p_pic->p[V_PLANE].i_pitch = CEIL32( p_vout->output.i_width ) / 2; |
|---|
| 337 |
p_pic->p[V_PLANE].i_pixel_pitch = 1; |
|---|
| 338 |
p_pic->p[V_PLANE].i_visible_pitch = p_pic->p[V_PLANE].i_pitch; |
|---|
| 339 |
|
|---|
| 340 |
p_pic->p_sys->i_frame = I_OUTPUTPICTURES; |
|---|
| 341 |
|
|---|
| 342 |
p_pic->i_planes = 3; |
|---|
| 343 |
|
|---|
| 344 |
return 0; |
|---|
| 345 |
} |
|---|
| 346 |
|
|---|