| 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 |
|
|---|
| 29 |
#ifdef HAVE_CONFIG_H |
|---|
| 30 |
# include "config.h" |
|---|
| 31 |
#endif |
|---|
| 32 |
|
|---|
| 33 |
#include <errno.h> |
|---|
| 34 |
#include <signal.h> |
|---|
| 35 |
#include <fcntl.h> |
|---|
| 36 |
#include <unistd.h> |
|---|
| 37 |
|
|---|
| 38 |
#include <termios.h> |
|---|
| 39 |
#include <sys/ioctl.h> |
|---|
| 40 |
#include <sys/mman.h> |
|---|
| 41 |
|
|---|
| 42 |
#include <linux/fb.h> |
|---|
| 43 |
#include <linux/vt.h> |
|---|
| 44 |
#include <linux/kd.h> |
|---|
| 45 |
|
|---|
| 46 |
#include <vlc_common.h> |
|---|
| 47 |
#include <vlc_plugin.h> |
|---|
| 48 |
#include <vlc_vout.h> |
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 |
static int Create ( vlc_object_t * ); |
|---|
| 54 |
static void Destroy ( vlc_object_t * ); |
|---|
| 55 |
|
|---|
| 56 |
static int Init ( vout_thread_t * ); |
|---|
| 57 |
static void End ( vout_thread_t * ); |
|---|
| 58 |
static int Manage ( vout_thread_t * ); |
|---|
| 59 |
static void Display ( vout_thread_t *, picture_t * ); |
|---|
| 60 |
static int Control ( vout_thread_t *, int, va_list ); |
|---|
| 61 |
|
|---|
| 62 |
static int NewPicture ( vout_thread_t *, picture_t * ); |
|---|
| 63 |
static void FreePicture ( vout_thread_t *, picture_t * ); |
|---|
| 64 |
|
|---|
| 65 |
static int OpenDisplay ( vout_thread_t * ); |
|---|
| 66 |
static void CloseDisplay ( vout_thread_t * ); |
|---|
| 67 |
static void SwitchDisplay ( int i_signal ); |
|---|
| 68 |
static void TextMode ( int i_tty ); |
|---|
| 69 |
static void GfxMode ( int i_tty ); |
|---|
| 70 |
|
|---|
| 71 |
#define MAX_DIRECTBUFFERS 1 |
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 |
#define FB_DEV_VAR "fbdev" |
|---|
| 77 |
|
|---|
| 78 |
#define DEVICE_TEXT N_("Framebuffer device") |
|---|
| 79 |
#define DEVICE_LONGTEXT N_( \ |
|---|
| 80 |
"Framebuffer device to use for rendering (usually /dev/fb0).") |
|---|
| 81 |
|
|---|
| 82 |
#define TTY_TEXT N_("Run fb on current tty.") |
|---|
| 83 |
#define TTY_LONGTEXT N_( \ |
|---|
| 84 |
"Run framebuffer on current TTY device (default enabled). " \ |
|---|
| 85 |
"(disable tty handling with caution)" ) |
|---|
| 86 |
|
|---|
| 87 |
#define CHROMA_TEXT N_("Chroma used.") |
|---|
| 88 |
#define CHROMA_LONGTEXT N_( \ |
|---|
| 89 |
"Force use of a specific chroma for output. Default is I420." ) |
|---|
| 90 |
|
|---|
| 91 |
#define ASPECT_RATIO_TEXT N_("Video aspect ratio") |
|---|
| 92 |
#define ASPECT_RATIO_LONGTEXT N_( \ |
|---|
| 93 |
"Aspect ratio of the video image (4:3, 16:9). Default is square pixels." ) |
|---|
| 94 |
|
|---|
| 95 |
#define FB_MODE_TEXT N_("Framebuffer resolution to use.") |
|---|
| 96 |
#define FB_MODE_LONGTEXT N_( \ |
|---|
| 97 |
"Select the resolution for the framebuffer. Currently it supports " \ |
|---|
| 98 |
"the values 0=QCIF 1=CIF 2=NTSC 3=PAL, 4=auto (default 4=auto)" ) |
|---|
| 99 |
|
|---|
| 100 |
#define HW_ACCEL_TEXT N_("Framebuffer uses hw acceleration.") |
|---|
| 101 |
#define HW_ACCEL_LONGTEXT N_( \ |
|---|
| 102 |
"If your framebuffer supports hardware acceleration or does double buffering " \ |
|---|
| 103 |
"in hardware then you must disable this option. It then does double buffering " \ |
|---|
| 104 |
"in software." ) |
|---|
| 105 |
|
|---|
| 106 |
vlc_module_begin(); |
|---|
| 107 |
set_shortname( "Framebuffer" ); |
|---|
| 108 |
set_category( CAT_VIDEO ); |
|---|
| 109 |
set_subcategory( SUBCAT_VIDEO_VOUT ); |
|---|
| 110 |
add_file( FB_DEV_VAR, "/dev/fb0", NULL, DEVICE_TEXT, DEVICE_LONGTEXT, |
|---|
| 111 |
false ); |
|---|
| 112 |
add_bool( "fb-tty", 1, NULL, TTY_TEXT, TTY_LONGTEXT, true ); |
|---|
| 113 |
add_string( "fb-chroma", NULL, NULL, CHROMA_TEXT, CHROMA_LONGTEXT, |
|---|
| 114 |
true ); |
|---|
| 115 |
add_string( "fb-aspect-ratio", NULL, NULL, ASPECT_RATIO_TEXT, |
|---|
| 116 |
ASPECT_RATIO_LONGTEXT, true ); |
|---|
| 117 |
add_integer( "fb-mode", 4, NULL, FB_MODE_TEXT, FB_MODE_LONGTEXT, |
|---|
| 118 |
true ); |
|---|
| 119 |
add_bool( "fb-hw-accel", true, NULL, HW_ACCEL_TEXT, HW_ACCEL_LONGTEXT, |
|---|
| 120 |
true ); |
|---|
| 121 |
set_description( N_("GNU/Linux console framebuffer video output") ); |
|---|
| 122 |
set_capability( "video output", 30 ); |
|---|
| 123 |
set_callbacks( Create, Destroy ); |
|---|
| 124 |
vlc_module_end(); |
|---|
| 125 |
|
|---|
| 126 |
|
|---|
| 127 |
|
|---|
| 128 |
|
|---|
| 129 |
|
|---|
| 130 |
|
|---|
| 131 |
|
|---|
| 132 |
struct vout_sys_t |
|---|
| 133 |
{ |
|---|
| 134 |
|
|---|
| 135 |
int i_tty; |
|---|
| 136 |
bool b_tty; |
|---|
| 137 |
struct termios old_termios; |
|---|
| 138 |
|
|---|
| 139 |
|
|---|
| 140 |
struct sigaction sig_usr1; |
|---|
| 141 |
struct sigaction sig_usr2; |
|---|
| 142 |
struct vt_mode vt_mode; |
|---|
| 143 |
|
|---|
| 144 |
|
|---|
| 145 |
int i_fd; |
|---|
| 146 |
struct fb_var_screeninfo old_info; |
|---|
| 147 |
struct fb_var_screeninfo var_info; |
|---|
| 148 |
bool b_pan; |
|---|
| 149 |
struct fb_cmap fb_cmap; |
|---|
| 150 |
uint16_t *p_palette; |
|---|
| 151 |
bool b_hw_accel; |
|---|
| 152 |
|
|---|
| 153 |
|
|---|
| 154 |
uint32_t i_width; |
|---|
| 155 |
uint32_t i_height; |
|---|
| 156 |
int i_aspect; |
|---|
| 157 |
int i_bytes_per_pixel; |
|---|
| 158 |
bool b_auto; |
|---|
| 159 |
vlc_fourcc_t i_chroma; |
|---|
| 160 |
|
|---|
| 161 |
|
|---|
| 162 |
uint8_t *p_video; |
|---|
| 163 |
size_t i_page_size; |
|---|
| 164 |
}; |
|---|
| 165 |
|
|---|
| 166 |
struct picture_sys_t |
|---|
| 167 |
{ |
|---|
| 168 |
uint8_t * p_data; |
|---|
| 169 |
}; |
|---|
| 170 |
|
|---|
| 171 |
|
|---|
| 172 |
|
|---|
| 173 |
|
|---|
| 174 |
|
|---|
| 175 |
|
|---|
| 176 |
static int Create( vlc_object_t *p_this ) |
|---|
| 177 |
{ |
|---|
| 178 |
vout_thread_t *p_vout = (vout_thread_t *)p_this; |
|---|
| 179 |
vout_sys_t *p_sys; |
|---|
| 180 |
char *psz_chroma; |
|---|
| 181 |
char *psz_aspect; |
|---|
| 182 |
int i_mode; |
|---|
| 183 |
struct sigaction sig_tty; |
|---|
| 184 |
struct vt_mode vt_mode; |
|---|
| 185 |
struct termios new_termios; |
|---|
| 186 |
|
|---|
| 187 |
|
|---|
| 188 |
p_vout->p_sys = p_sys = malloc( sizeof( vout_sys_t ) ); |
|---|
| 189 |
if( p_vout->p_sys == NULL ) |
|---|
| 190 |
return VLC_ENOMEM; |
|---|
| 191 |
memset( p_sys, 0, sizeof(vout_sys_t) ); |
|---|
| 192 |
|
|---|
| 193 |
p_vout->pf_init = Init; |
|---|
| 194 |
p_vout->pf_end = End; |
|---|
| 195 |
p_vout->pf_manage = Manage; |
|---|
| 196 |
p_vout->pf_render = NULL; |
|---|
| 197 |
p_vout->pf_display = Display; |
|---|
| 198 |
p_vout->pf_control = Control; |
|---|
| 199 |
|
|---|
| 200 |
|
|---|
| 201 |
p_sys->b_hw_accel = var_CreateGetBool( p_vout, "fb-hw-accel" ); |
|---|
| 202 |
|
|---|
| 203 |
|
|---|
| 204 |
p_sys->i_tty = 0; |
|---|
| 205 |
p_sys->b_tty = var_CreateGetBool( p_vout, "fb-tty" ); |
|---|
| 206 |
#ifndef WIN32 |
|---|
| 207 |
#if defined(HAVE_ISATTY) |
|---|
| 208 |
|
|---|
| 209 |
if( p_sys->b_tty && !isatty( 0 ) ) |
|---|
| 210 |
{ |
|---|
| 211 |
msg_Warn( p_vout, "fd 0 is not a TTY" ); |
|---|
| 212 |
return VLC_EGENERIC; |
|---|
| 213 |
} |
|---|
| 214 |
else |
|---|
| 215 |
{ |
|---|
| 216 |
msg_Warn( p_vout, "disabling tty handling, use with caution because " |
|---|
| 217 |
"there is no way to return to the tty." ); |
|---|
| 218 |
} |
|---|
| 219 |
#endif |
|---|
| 220 |
#endif |
|---|
| 221 |
|
|---|
| 222 |
psz_chroma = var_CreateGetNonEmptyString( p_vout, "fb-chroma" ); |
|---|
| 223 |
if( psz_chroma ) |
|---|
| 224 |
{ |
|---|
| 225 |
if( strlen( psz_chroma ) == 4 ) |
|---|
| 226 |
{ |
|---|
| 227 |
p_sys->i_chroma = VLC_FOURCC( psz_chroma[0], |
|---|
| 228 |
psz_chroma[1], |
|---|
| 229 |
psz_chroma[2], |
|---|
| 230 |
psz_chroma[3] ); |
|---|
| 231 |
msg_Dbg( p_vout, "forcing chroma '%s'", psz_chroma ); |
|---|
| 232 |
} |
|---|
| 233 |
else |
|---|
| 234 |
{ |
|---|
| 235 |
msg_Warn( p_vout, "invalid chroma (%s), using defaults.", |
|---|
| 236 |
psz_chroma ); |
|---|
| 237 |
} |
|---|
| 238 |
free( psz_chroma ); |
|---|
| 239 |
psz_chroma = NULL; |
|---|
| 240 |
} |
|---|
| 241 |
|
|---|
| 242 |
p_sys->i_aspect = -1; |
|---|
| 243 |
psz_aspect = var_CreateGetNonEmptyString( p_vout, "fb-aspect-ratio" ); |
|---|
| 244 |
if( psz_aspect ) |
|---|
| 245 |
{ |
|---|
| 246 |
char *psz_parser = strchr( psz_aspect, ':' ); |
|---|
| 247 |
|
|---|
| 248 |
if( psz_parser ) |
|---|
| 249 |
{ |
|---|
| 250 |
*psz_parser++ = '\0'; |
|---|
| 251 |
p_sys->i_aspect = ( atoi( psz_aspect ) |
|---|
| 252 |
* VOUT_ASPECT_FACTOR ) / atoi( psz_parser ); |
|---|
| 253 |
} |
|---|
| 254 |
msg_Dbg( p_vout, "using aspect ratio %d:%d", |
|---|
| 255 |
atoi( psz_aspect ), atoi( psz_parser ) ); |
|---|
| 256 |
|
|---|
| 257 |
free( psz_aspect ); |
|---|
| 258 |
psz_aspect = NULL; |
|---|
| 259 |
} |
|---|
| 260 |
|
|---|
| 261 |
p_sys->b_auto = false; |
|---|
| 262 |
i_mode = var_CreateGetInteger( p_vout, "fb-mode" ); |
|---|
| 263 |
switch( i_mode ) |
|---|
| 264 |
{ |
|---|
| 265 |
case 0: |
|---|
| 266 |
p_sys->i_width = 176; |
|---|
| 267 |
p_sys->i_height = 144; |
|---|
| 268 |
break; |
|---|
| 269 |
case 1: |
|---|
| 270 |
p_sys->i_width = 352; |
|---|
| 271 |
p_sys->i_height = 288; |
|---|
| 272 |
break; |
|---|
| 273 |
case 2: |
|---|
| 274 |
p_sys->i_width = 640; |
|---|
| 275 |
p_sys->i_height = 480; |
|---|
| 276 |
break; |
|---|
| 277 |
case 3: |
|---|
| 278 |
p_sys->i_width = 704; |
|---|
| 279 |
p_sys->i_height = 576; |
|---|
| 280 |
break; |
|---|
| 281 |
case 4: |
|---|
| 282 |
default: |
|---|
| 283 |
p_sys->b_auto = true; |
|---|
| 284 |
break; |
|---|
| 285 |
} |
|---|
| 286 |
|
|---|
| 287 |
|
|---|
| 288 |
if( p_sys->b_tty ) |
|---|
| 289 |
{ |
|---|
| 290 |
GfxMode( p_sys->i_tty ); |
|---|
| 291 |
|
|---|
| 292 |
|
|---|
| 293 |
if( tcgetattr(0, &p_vout->p_sys->old_termios) == -1 ) |
|---|
| 294 |
{ |
|---|
| 295 |
msg_Err( p_vout, "tcgetattr failed" ); |
|---|
| 296 |
} |
|---|
| 297 |
|
|---|
| 298 |
if( tcgetattr(0, &new_termios) == -1 ) |
|---|
| 299 |
{ |
|---|
| 300 |
msg_Err( p_vout, "tcgetattr failed" ); |
|---|
| 301 |
} |
|---|
| 302 |
|
|---|
| 303 |
|
|---|
| 304 |
|
|---|
| 305 |
new_termios.c_lflag &= ~ (ICANON); |
|---|
| 306 |
new_termios.c_lflag &= ~(ECHO | ECHOCTL); |
|---|
| 307 |
new_termios.c_iflag = 0; |
|---|
| 308 |
new_termios.c_cc[VMIN] = 1; |
|---|
| 309 |
new_termios.c_cc[VTIME] = 0; |
|---|
| 310 |
|
|---|
| 311 |
if( tcsetattr(0, TCSAFLUSH, &new_termios) == -1 ) |
|---|
| 312 |
{ |
|---|
| 313 |
msg_Err( p_vout, "tcsetattr failed" ); |
|---|
| 314 |
} |
|---|
| 315 |
|
|---|
| 316 |
ioctl( p_sys->i_tty, VT_RELDISP, VT_ACKACQ ); |
|---|
| 317 |
|
|---|
| 318 |
|
|---|
| 319 |
memset( &sig_tty, 0, sizeof( sig_tty ) ); |
|---|
| 320 |
sig_tty.sa_handler = SwitchDisplay; |
|---|
| 321 |
sigemptyset( &sig_tty.sa_mask ); |
|---|
| 322 |
if( sigaction( SIGUSR1, &sig_tty, &p_vout->p_sys->sig_usr1 ) || |
|---|
| 323 |
sigaction( SIGUSR2, &sig_tty, &p_vout->p_sys->sig_usr2 ) ) |
|---|
| 324 |
{ |
|---|
| 325 |
msg_Err( p_vout, "cannot set signal handler (%m)" ); |
|---|
| 326 |
tcsetattr(0, 0, &p_vout->p_sys->old_termios); |
|---|
| 327 |
TextMode( p_sys->i_tty ); |
|---|
| 328 |
free( p_vout->p_sys ); |
|---|
| 329 |
return VLC_EGENERIC; |
|---|
| 330 |
} |
|---|
| 331 |
|
|---|
| 332 |
|
|---|
| 333 |
if( -1 == ioctl( p_sys->i_tty, VT_GETMODE, &p_vout->p_sys->vt_mode ) ) |
|---|
| 334 |
{ |
|---|
| 335 |
msg_Err( p_vout, "cannot get terminal mode (%m)" ); |
|---|
| 336 |
sigaction( SIGUSR1, &p_vout->p_sys->sig_usr1, NULL ); |
|---|
| 337 |
sigaction( SIGUSR2, &p_vout->p_sys->sig_usr2, NULL ); |
|---|
| 338 |
tcsetattr(0, 0, &p_vout->p_sys->old_termios); |
|---|
| 339 |
TextMode( p_sys->i_tty ); |
|---|
| 340 |
free( p_vout->p_sys ); |
|---|
| 341 |
return VLC_EGENERIC; |
|---|
| 342 |
} |
|---|
| 343 |
memcpy( &vt_mode, &p_vout->p_sys->vt_mode, sizeof( vt_mode ) ); |
|---|
| 344 |
vt_mode.mode = VT_PROCESS; |
|---|
| 345 |
vt_mode.waitv = 0; |
|---|
| 346 |
vt_mode.relsig = SIGUSR1; |
|---|
| 347 |
vt_mode.acqsig = SIGUSR2; |
|---|
| 348 |
|
|---|
| 349 |
if( -1 == ioctl( p_sys->i_tty, VT_SETMODE, &vt_mode ) ) |
|---|
| 350 |
{ |
|---|
| 351 |
msg_Err( p_vout, "cannot set terminal mode (%m)" ); |
|---|
| 352 |
sigaction( SIGUSR1, &p_vout->p_sys->sig_usr1, NULL ); |
|---|
| 353 |
sigaction( SIGUSR2, &p_vout->p_sys->sig_usr2, NULL ); |
|---|
| 354 |
tcsetattr(0, 0, &p_vout->p_sys->old_termios); |
|---|
| 355 |
TextMode( p_sys->i_tty ); |
|---|
| 356 |
free( p_vout->p_sys ); |
|---|
| 357 |
return VLC_EGENERIC; |
|---|
| 358 |
} |
|---|
| 359 |
} |
|---|
| 360 |
|
|---|
| 361 |
if( OpenDisplay( p_vout ) ) |
|---|
| 362 |
{ |
|---|
| 363 |
if( p_sys->b_tty ) |
|---|
| 364 |
{ |
|---|
| 365 |
ioctl( p_sys->i_tty, VT_SETMODE, &p_vout->p_sys->vt_mode ); |
|---|
| 366 |
sigaction( SIGUSR1, &p_vout->p_sys->sig_usr1, NULL ); |
|---|
| 367 |
sigaction( SIGUSR2, &p_vout->p_sys->sig_usr2, NULL ); |
|---|
| 368 |
tcsetattr(0, 0, &p_vout->p_sys->old_termios); |
|---|
| 369 |
TextMode( p_sys->i_tty ); |
|---|
| 370 |
} |
|---|
| 371 |
free( p_vout->p_sys ); |
|---|
| 372 |
return VLC_EGENERIC; |
|---|
| 373 |
} |
|---|
| 374 |
|
|---|
| 375 |
return VLC_SUCCESS; |
|---|
| 376 |
} |
|---|
| 377 |
|
|---|
| 378 |
|
|---|
| 379 |
|
|---|
| 380 |
|
|---|
| 381 |
|
|---|
| 382 |
|
|---|
| 383 |
|
|---|
| 384 |
static void Destroy( vlc_object_t *p_this ) |
|---|
| 385 |
{ |
|---|
| 386 |
vout_thread_t *p_vout = (vout_thread_t *)p_this; |
|---|
| 387 |
|
|---|
| 388 |
CloseDisplay( p_vout ); |
|---|
| 389 |
|
|---|
| 390 |
if( p_vout->p_sys->b_tty ) |
|---|
| 391 |
{ |
|---|
| 392 |
|
|---|
| 393 |
ioctl( p_vout->p_sys->i_tty, VT_SETMODE, &p_vout->p_sys->vt_mode ); |
|---|
| 394 |
|
|---|
| 395 |
|
|---|
| 396 |
sigaction( SIGUSR1, &p_vout->p_sys->sig_usr1, NULL ); |
|---|
| 397 |
sigaction( SIGUSR2, &p_vout->p_sys->sig_usr2, NULL ); |
|---|
| 398 |
|
|---|
| 399 |
|
|---|
| 400 |
tcsetattr( 0, 0, &p_vout->p_sys->old_termios ); |
|---|
| 401 |
|
|---|
| 402 |
|
|---|
| 403 |
TextMode( p_vout->p_sys->i_tty ); |
|---|
| 404 |
} |
|---|
| 405 |
|
|---|
| 406 |
|
|---|
| 407 |
free( p_vout->p_sys ); |
|---|
| 408 |
} |
|---|
| 409 |
|
|---|
| 410 |
|
|---|
| 411 |
|
|---|
| 412 |
|
|---|
| 413 |
|
|---|
| 414 |
|
|---|
| 415 |
static int NewPicture( vout_thread_t *p_vout, picture_t *p_pic ) |
|---|
| 416 |
{ |
|---|
| 417 |
|
|---|
| 418 |
|
|---|
| 419 |
p_pic->p_sys = malloc( sizeof( picture_sys_t ) ); |
|---|
| 420 |
if( p_pic->p_sys == NULL ) |
|---|
| 421 |
{ |
|---|
| 422 |
return VLC_ENOMEM; |
|---|
| 423 |
} |
|---|
| 424 |
|
|---|
| 425 |
|
|---|
| 426 |
vout_InitPicture( VLC_OBJECT(p_vout), p_pic, p_vout->output.i_chroma, |
|---|
| 427 |
p_vout->output.i_width, p_vout->output.i_height, |
|---|
| 428 |
p_vout->output.i_aspect ); |
|---|
| 429 |
|
|---|
| 430 |
p_pic->p_sys->p_data = malloc( p_vout->p_sys->i_page_size ); |
|---|
| 431 |
if( !p_pic->p_sys->p_data ) |
|---|
| 432 |
{ |
|---|
| 433 |
free( p_pic->p_sys ); |
|---|
| 434 |
p_pic->p_sys = NULL; |
|---|
| 435 |
return VLC_ENOMEM; |
|---|
| 436 |
} |
|---|
| 437 |
|
|---|
| 438 |
p_pic->p->p_pixels = (uint8_t*) p_pic->p_sys->p_data; |
|---|
| 439 |
|
|---|
| 440 |
p_pic->p->i_pixel_pitch = p_vout->p_sys->i_bytes_per_pixel; |
|---|
| 441 |
p_pic->p->i_lines = p_vout->p_sys->var_info.yres; |
|---|
| 442 |
p_pic->p->i_visible_lines = p_vout->p_sys->var_info.yres; |
|---|
| 443 |
|
|---|
| 444 |
if( p_vout->p_sys->var_info.xres_virtual ) |
|---|
| 445 |
{ |
|---|
| 446 |
p_pic->p->i_pitch = p_vout->p_sys->var_info.xres_virtual |
|---|
| 447 |
* p_vout->p_sys->i_bytes_per_pixel; |
|---|
| 448 |
} |
|---|
| 449 |
else |
|---|
| 450 |
{ |
|---|
| 451 |
p_pic->p->i_pitch = p_vout->p_sys->var_info.xres |
|---|
| 452 |
* p_vout->p_sys->i_bytes_per_pixel; |
|---|
| 453 |
} |
|---|
| 454 |
|
|---|
| 455 |
p_pic->p->i_visible_pitch = p_vout->p_sys->var_info.xres |
|---|
| 456 |
* p_vout->p_sys->i_bytes_per_pixel; |
|---|
| 457 |
p_pic->i_planes = 1; |
|---|
| 458 |
|
|---|
| 459 |
return VLC_SUCCESS; |
|---|
| 460 |
} |
|---|
| 461 |
|
|---|
| 462 |
|
|---|
| 463 |
|
|---|
| 464 |
|
|---|
| 465 |
|
|---|
| 466 |
|
|---|
| 467 |
static void FreePicture( vout_thread_t *p_vout, picture_t *p_pic ) |
|---|
| 468 |
{ |
|---|
| 469 |
VLC_UNUSED(p_vout); |
|---|
| 470 |
free( p_pic->p_sys->p_data ); |
|---|
| 471 |
free( p_pic->p_sys ); |
|---|
| 472 |
p_pic->p_sys = NULL; |
|---|
| 473 |
} |
|---|
| 474 |
|
|---|
| 475 |
|
|---|
| 476 |
|
|---|
| 477 |
|
|---|
| 478 |
static int Init( vout_thread_t *p_vout ) |
|---|
| 479 |
{ |
|---|
| 480 |
vout_sys_t *p_sys = p_vout->p_sys; |
|---|
| 481 |
int i_index; |
|---|
| 482 |
picture_t *p_pic = NULL; |
|---|
| 483 |
|
|---|
| 484 |
I_OUTPUTPICTURES = 0; |
|---|
| 485 |
|
|---|
| 486 |
p_vout->output.i_width = p_vout->render.i_width; |
|---|
| 487 |
p_vout->output.i_height = p_vout->render.i_height; |
|---|
| 488 |
p_vout->output.i_aspect = p_vout->render.i_aspect; |
|---|
| 489 |
|
|---|
| 490 |
p_vout->fmt_out = p_vout->fmt_in; |
|---|
| 491 |
if( p_sys->i_chroma == 0 ) |
|---|
| 492 |
{ |
|---|
| 493 |
|
|---|
| 494 |
|
|---|
| 495 |
switch( p_sys->var_info.bits_per_pixel ) |
|---|
| 496 |
{ |
|---|
| 497 |
case 8: |
|---|
| 498 |
p_vout->output.i_chroma = VLC_FOURCC('R','G','B','2'); break; |
|---|
| 499 |
case 15: |
|---|
| 500 |
p_vout->output.i_chroma = VLC_FOURCC('R','V','1','5'); break; |
|---|
| 501 |
case 16: |
|---|
| 502 |
p_vout->output.i_chroma = VLC_FOURCC('R','V','1','6'); break; |
|---|
| 503 |
case 24: |
|---|
| 504 |
p_vout->output.i_chroma = VLC_FOURCC('R','V','2','4'); break; |
|---|
| 505 |
case 32: |
|---|
| 506 |
p_vout->output.i_chroma = VLC_FOURCC('R','V','3','2'); break; |
|---|
| 507 |
default: |
|---|
| 508 |
msg_Err( p_vout, "unknown screen depth %i", |
|---|
| 509 |
p_vout->p_sys->var_info.bits_per_pixel ); |
|---|
| 510 |
return VLC_EGENERIC; |
|---|
| 511 |
} |
|---|
| 512 |
|
|---|
| 513 |
if( p_sys->var_info.bits_per_pixel != 8 ) |
|---|
| 514 |
{ |
|---|
| 515 |
p_vout->output.i_rmask = ( (1 << p_sys->var_info.red.length) - 1 ) |
|---|
| 516 |
<< p_sys->var_info.red.offset; |
|---|
| 517 |
p_vout->output.i_gmask = ( (1 << p_sys->var_info.green.length) - 1 ) |
|---|
| 518 |
<< p_sys->var_info.green.offset; |
|---|
| 519 |
p_vout->output.i_bmask = ( (1 << p_sys->var_info.blue.length) - 1 ) |
|---|
| 520 |
<< p_sys->var_info.blue.offset; |
|---|
| 521 |
} |
|---|
| 522 |
} |
|---|
| 523 |
else |
|---|
| 524 |
{ |
|---|
| 525 |
p_vout->output.i_chroma = p_sys->i_chroma; |
|---|
| 526 |
} |
|---|
| 527 |
p_vout->fmt_out.i_chroma = p_vout->output.i_chroma; |
|---|
| 528 |
|
|---|
| 529 |
p_vout->output.i_width = |
|---|
| 530 |
p_vout->fmt_out.i_width = |
|---|
| 531 |
p_vout->fmt_out.i_visible_width = p_sys->i_width; |
|---|
| 532 |
p_vout->output.i_height = |
|---|
| 533 |
p_vout->fmt_out.i_height = |
|---|
| 534 |
p_vout->fmt_out.i_visible_height = p_sys->i_height; |
|---|
| 535 |
|
|---|
| 536 |
|
|---|
| 537 |
if( p_sys->i_aspect < 0 ) |
|---|
| 538 |
{ |
|---|
| 539 |
p_vout->output.i_aspect = ( p_sys->i_width |
|---|
| 540 |
* VOUT_ASPECT_FACTOR ) / p_sys->i_height; |
|---|
| 541 |
} |
|---|
| 542 |
else p_vout->output.i_aspect = p_sys->i_aspect; |
|---|
| 543 |
|
|---|
| 544 |
p_vout->fmt_out.i_sar_num = p_vout->fmt_out.i_sar_den = 1; |
|---|
| 545 |
p_vout->fmt_out.i_aspect = p_vout->render.i_aspect = p_vout->output.i_aspect; |
|---|
| 546 |
p_vout->fmt_out.i_x_offset= p_vout->fmt_out.i_y_offset = 0; |
|---|
| 547 |
|
|---|
| 548 |
|
|---|
| 549 |
memset( p_sys->p_video, 0, p_sys->i_page_size ); |
|---|
| 550 |
|
|---|
| 551 |
if( !p_sys->b_hw_accel ) |
|---|
| 552 |
{ |
|---|
| 553 |
|
|---|
| 554 |
while( I_OUTPUTPICTURES < MAX_DIRECTBUFFERS ) |
|---|
| 555 |
{ |
|---|
| 556 |
p_pic = NULL; |
|---|
| 557 |
|
|---|
| 558 |
|
|---|
| 559 |
for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ ) |
|---|
| 560 |
{ |
|---|
| 561 |
if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE ) |
|---|
| 562 |
{ |
|---|
| 563 |
p_pic = p_vout->p_picture + i_index; |
|---|
| 564 |
break; |
|---|
| 565 |
} |
|---|
| 566 |
} |
|---|
| 567 |
|
|---|
| 568 |
|
|---|
| 569 |
if( p_pic == NULL || NewPicture( p_vout, p_pic ) ) |
|---|
| 570 |
{ |
|---|
| 571 |
break; |
|---|
| 572 |
} |
|---|
| 573 |
|
|---|
| 574 |
p_pic->i_status = DESTROYED_PICTURE; |
|---|
| 575 |
p_pic->i_type = DIRECT_PICTURE; |
|---|
| 576 |
|
|---|
| 577 |
PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic; |
|---|
| 578 |
|
|---|
| 579 |
I_OUTPUTPICTURES++; |
|---|
| 580 |
} |
|---|
| 581 |
} |
|---|
| 582 |
else |
|---|
| 583 |
{ |
|---|
| 584 |
|
|---|
| 585 |
p_pic = NULL; |
|---|
| 586 |
|
|---|
| 587 |
|
|---|
| 588 |
for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ ) |
|---|
| 589 |
{ |
|---|
| 590 |
if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE ) |
|---|
| 591 |
{ |
|---|
| 592 |
p_pic = p_vout->p_picture + i_index; |
|---|
| 593 |
break; |
|---|
| 594 |
} |
|---|
| 595 |
} |
|---|
| 596 |
|
|---|
| 597 |
|
|---|
| 598 |
if( p_pic == NULL ) |
|---|
| 599 |
{ |
|---|
| 600 |
return VLC_EGENERIC; |
|---|
| 601 |
} |
|---|
| 602 |
|
|---|
| 603 |
|
|---|
| 604 |
|
|---|
| 605 |
p_pic->p->p_pixels = p_vout->p_sys->p_video; |
|---|
| 606 |
p_pic->p->i_pixel_pitch = p_vout->p_sys->i_bytes_per_pixel; |
|---|
| 607 |
p_pic->p->i_lines = p_vout->p_sys->var_info.yres; |
|---|
| 608 |
p_pic->p->i_visible_lines = p_vout->p_sys->var_info.yres; |
|---|
| 609 |
|
|---|
| 610 |
if( p_vout->p_sys->var_info.xres_virtual ) |
|---|
| 611 |
{ |
|---|
| 612 |
p_pic->p->i_pitch = p_vout->p_sys->var_info.xres_virtual |
|---|
| 613 |
* p_vout->p_sys->i_bytes_per_pixel; |
|---|
| 614 |
} |
|---|
| 615 |
else |
|---|
| 616 |
{ |
|---|
| 617 |
p_pic->p->i_pitch = p_vout->p_sys->var_info.xres |
|---|
| 618 |
* p_vout->p_sys->i_bytes_per_pixel; |
|---|
| 619 |
} |
|---|
| 620 |
|
|---|
| 621 |
p_pic->p->i_visible_pitch = p_vout->p_sys->var_info.xres |
|---|
| 622 |
* p_vout->p_sys->i_bytes_per_pixel; |
|---|
| 623 |
p_pic->i_planes = 1; |
|---|
| 624 |
p_pic->i_status = DESTROYED_PICTURE; |
|---|
| 625 |
p_pic->i_type = DIRECT_PICTURE; |
|---|
| 626 |
|
|---|
| 627 |
PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic; |
|---|
| 628 |
|
|---|
| 629 |
I_OUTPUTPICTURES++; |
|---|
| 630 |
} |
|---|
| 631 |
|
|---|
| 632 |
return VLC_SUCCESS; |
|---|
| 633 |
} |
|---|
| 634 |
|
|---|
| 635 |
|
|---|
| 636 |
|
|---|
| 637 |
|
|---|
| 638 |
static void End( vout_thread_t *p_vout ) |
|---|
| 639 |
{ |
|---|
| 640 |
if( !p_vout->p_sys->b_hw_accel ) |
|---|
| 641 |
{ |
|---|
| 642 |
int i_index; |
|---|
| 643 |
|
|---|
| 644 |
|
|---|
| 645 |
for( i_index = I_OUTPUTPICTURES ; i_index ; ) |
|---|
| 646 |
{ |
|---|
| 647 |
i_index--; |
|---|
| 648 |
FreePicture( p_vout, PP_OUTPUTPICTURE[ i_index ] ); |
|---|
| 649 |
} |
|---|
| 650 |
|
|---|
| 651 |
} |
|---|
| 652 |
|
|---|
| 653 |
memset( p_vout->p_sys->p_video, 0, p_vout->p_sys->i_page_size ); |
|---|
| 654 |
} |
|---|
| 655 |
|
|---|
| 656 |
|
|---|
| 657 |
|
|---|
| 658 |
|
|---|
| 659 |
static int Control( vout_thread_t *p_vout, int i_query, va_list args ) |
|---|
| 660 |
{ |
|---|
| 661 |
switch( i_query ) |
|---|
| 662 |
{ |
|---|
| 663 |
default: |
|---|
| 664 |
return vout_vaControlDefault( p_vout, i_query, args ); |
|---|
| 665 |
} |
|---|
| 666 |
} |
|---|
| 667 |
|
|---|
| 668 |
|
|---|
| 669 |
|
|---|
| 670 |
|
|---|
| 671 |
|
|---|
| 672 |
|
|---|
| 673 |
|
|---|
| 674 |
static int Manage( vout_thread_t *p_vout ) |
|---|
| 675 |
{ |
|---|
| 676 |
#if 0 |
|---|
| 677 |
uint8_t buf; |
|---|
| 678 |
|
|---|
| 679 |
if ( read(0, &buf, 1) == 1) |
|---|
| 680 |
{ |
|---|
| 681 |
switch( buf ) |
|---|
| 682 |
{ |
|---|
| 683 |
case 'q': |
|---|
| 684 |
vlc_object_kill( p_vout->p_libvlc ); |
|---|
| 685 |
break; |
|---|
| 686 |
|
|---|
| 687 |
default: |
|---|
| 688 |
break; |
|---|
| 689 |
} |
|---|
| 690 |
} |
|---|
| 691 |
#endif |
|---|
| 692 |
|
|---|
| 693 |
|
|---|
| 694 |
|
|---|
| 695 |
|
|---|
| 696 |
if( p_vout->i_changes & VOUT_SIZE_CHANGE ) |
|---|
| 697 |
{ |
|---|
| 698 |
msg_Dbg( p_vout, "reinitializing framebuffer screen" ); |
|---|
| 699 |
p_vout->i_changes &= ~VOUT_SIZE_CHANGE; |
|---|
| 700 |
|
|---|
| 701 |
|
|---|
| 702 |
End( p_vout ); |
|---|
| 703 |
|
|---|
| 704 |
|
|---|
| 705 |
if( Init( p_vout ) ) |
|---|
| 706 |
{ |
|---|
| 707 |
msg_Err( p_vout, "cannot reinit framebuffer screen" ); |
|---|
| 708 |
return VLC_EGENERIC; |
|---|
| 709 |
} |
|---|
| 710 |
|
|---|
| 711 |
|
|---|
| 712 |
memset( p_vout->p_sys->p_video, 0, p_vout->p_sys->i_page_size ); |
|---|
| 713 |
|
|---|
| 714 |
#if 0 |
|---|
| 715 |
|
|---|
| 716 |
|
|---|
| 717 |
p_vout->i_changes |= VOUT_YUV_CHANGE; |
|---|
| 718 |
#endif |
|---|
| 719 |
} |
|---|
| 720 |
|
|---|
| 721 |
return VLC_SUCCESS; |
|---|
| 722 |
} |
|---|
| 723 |
|
|---|
| 724 |
|
|---|
| 725 |
|
|---|
| 726 |
|
|---|
| 727 |
|
|---|
| 728 |
|
|---|
| 729 |
|
|---|
| 730 |
static void Display( vout_thread_t *p_vout, picture_t *p_pic ) |
|---|
| 731 |
{ |
|---|
| 732 |
static int panned=0; |
|---|
| 733 |
|
|---|
| 734 |
if( p_vout->p_sys->b_pan ) |
|---|
| 735 |
{ |
|---|
| 736 |
p_vout->p_sys->var_info.yoffset = 0; |
|---|
| 737 |
|
|---|
| 738 |
|
|---|
| 739 |
|
|---|
| 740 |
|
|---|
| 741 |
p_vout->p_sys->var_info.xoffset = 0; |
|---|
| 742 |
|
|---|
| 743 |
if( panned < 0 ) |
|---|
| 744 |
{ |
|---|
| 745 |
ioctl( p_vout->p_sys->i_fd, |
|---|
| 746 |
FBIOPAN_DISPLAY, &p_vout->p_sys->var_info ); |
|---|
| 747 |
panned++; |
|---|
| 748 |
} |
|---|
| 749 |
} |
|---|
| 750 |
|
|---|
| 751 |
if( !p_vout->p_sys->b_hw_accel ) |
|---|
| 752 |
{ |
|---|
| 753 |
vlc_memcpy( p_vout->p_sys->p_video, p_pic->p->p_pixels, |
|---|
| 754 |
p_vout->p_sys->i_page_size ); |
|---|
| 755 |
} |
|---|
| 756 |
} |
|---|
| 757 |
|
|---|
| 758 |
#if 0 |
|---|
| 759 |
static void SetPalette( vout_thread_t *p_vout, uint16_t *red, uint16_t *green, |
|---|
| 760 |
uint16_t *blue, uint16_t *transp ) |
|---|
| 761 |
{ |
|---|
| 762 |
struct fb_cmap cmap = { 0, 256, red, green, blue, transp }; |
|---|
| 763 |
|
|---|
| 764 |
ioctl( p_vout->p_sys->i_fd, FBIOPUTCMAP, &cmap ); |
|---|
| 765 |
} |
|---|
| 766 |
#endif |
|---|
| 767 |
|
|---|
| 768 |
|
|---|
| 769 |
|
|---|
| 770 |
|
|---|
| 771 |
|
|---|
| 772 |
|
|---|
| 773 |
static int OpenDisplay( vout_thread_t *p_vout ) |
|---|
| 774 |
{ |
|---|
| 775 |
vout_sys_t *p_sys = (vout_sys_t *) p_vout->p_sys; |
|---|
| 776 |
char *psz_device; |
|---|
| 777 |
struct fb_fix_screeninfo fix_info; |
|---|
| 778 |
|
|---|
| 779 |
|
|---|
| 780 |
if( !(psz_device = config_GetPsz( p_vout, FB_DEV_VAR )) ) |
|---|
| 781 |
{ |
|---|
| 782 |
msg_Err( p_vout, "don't know which fb device to open" ); |
|---|
| 783 |
return VLC_EGENERIC; |
|---|
| 784 |
} |
|---|
| 785 |
|
|---|
| 786 |
p_sys->i_fd = open( psz_device, O_RDWR); |
|---|
| 787 |
if( p_sys->i_fd == -1 ) |
|---|
| 788 |
{ |
|---|
| 789 |
msg_Err( p_vout, "cannot open %s (%m)", psz_device ); |
|---|
| 790 |
free( psz_device ); |
|---|
| 791 |
return VLC_EGENERIC; |
|---|
| 792 |
} |
|---|
| 793 |
free( psz_device ); |
|---|
| 794 |
psz_device = NULL; |
|---|
| 795 |
|
|---|
| 796 |
|
|---|
| 797 |
if( ioctl( p_sys->i_fd, FBIOGET_VSCREENINFO, &p_sys->var_info ) ) |
|---|
| 798 |
{ |
|---|
| 799 |
msg_Err( p_vout, "cannot get fb info (%m)" ); |
|---|
| 800 |
close( p_sys->i_fd ); |
|---|
| 801 |
return VLC_EGENERIC; |
|---|
| 802 |
} |
|---|
| 803 |
|
|---|
| 804 |
memcpy( &p_sys->old_info, &p_sys->var_info, |
|---|
| 805 |
sizeof( struct fb_var_screeninfo ) ); |
|---|
| 806 |
|
|---|
| 807 |
|
|---|
| 808 |
if( !p_sys->b_auto ) |
|---|
| 809 |
{ |
|---|
| 810 |
p_sys->var_info.xres = p_sys->var_info.xres_virtual = p_sys->i_width; |
|---|
| 811 |
p_sys->var_info.yres = p_sys->var_info.yres_virtual = p_sys->i_height; |
|---|
| 812 |
p_vout->fmt_out.i_width = p_sys->i_width; |
|---|
| 813 |
p_vout->fmt_out.i_height = p_sys->i_height; |
|---|
| 814 |
} |
|---|
| 815 |
|
|---|
| 816 |
|
|---|
| 817 |
p_sys->var_info.activate = p_sys->b_tty |
|---|
| 818 |
? FB_ACTIVATE_NXTOPEN |
|---|
| 819 |
: FB_ACTIVATE_NOW; |
|---|
| 820 |
p_sys->var_info.xoffset = 0; |
|---|
| 821 |
p_sys->var_info.yoffset = 0; |
|---|
| 822 |
|
|---|
| 823 |
if( ioctl( p_sys->i_fd, FBIOPUT_VSCREENINFO, &p_sys->var_info ) ) |
|---|
| 824 |
{ |
|---|
| 825 |
msg_Err( p_vout, "cannot set fb info (%m)" ); |
|---|
| 826 |
close( p_sys->i_fd ); |
|---|
| 827 |
return VLC_EGENERIC; |
|---|
| 828 |
} |
|---|
| 829 |
|
|---|
| 830 |
|
|---|
| 831 |
if( ioctl( p_sys->i_fd, FBIOGET_FSCREENINFO, &fix_info ) |
|---|
| 832 |
|| ioctl( p_sys->i_fd, FBIOGET_VSCREENINFO, &p_sys->var_info ) ) |
|---|
| 833 |
{ |
|---|
| 834 |
msg_Err( p_vout, "cannot get additional fb info (%m)" ); |
|---|
| 835 |
|
|---|
| 836 |
|
|---|
| 837 |
ioctl( p_sys->i_fd, FBIOPUT_VSCREENINFO, &p_sys->old_info ); |
|---|
| 838 |
|
|---|
| 839 |
close( p_sys->i_fd ); |
|---|
| 840 |
return VLC_EGENERIC; |
|---|
| 841 |
} |
|---|
| 842 |
|
|---|
| 843 |
|
|---|
| 844 |
|
|---|
| 845 |
if( (p_sys->i_height != p_sys->var_info.yres) || |
|---|
| 846 |
(p_sys->i_width != p_sys->var_info.xres) ) |
|---|
| 847 |
{ |
|---|
| 848 |
p_sys->b_auto = true; |
|---|
| 849 |
msg_Warn( p_vout, |
|---|
| 850 |
"using framebuffer native resolution instead of requested (%ix%i)", |
|---|
| 851 |
p_sys->i_width, p_sys->i_height ); |
|---|
| 852 |
} |
|---|
| 853 |
p_sys->i_height = p_sys->var_info.yres; |
|---|
| 854 |
p_sys->i_width = p_sys->var_info.xres_virtual |
|---|
| 855 |
? p_sys->var_info.xres_virtual |
|---|
| 856 |
: p_sys->var_info.xres; |
|---|
| 857 |
|
|---|
| 858 |
|
|---|
| 859 |
|
|---|
| 860 |
msg_Dbg( p_vout, "%ix%i (virtual %ix%i) (request %ix%i)", |
|---|
| 861 |
p_sys->var_info.xres, p_sys->var_info.yres, |
|---|
| 862 |
p_sys->var_info.xres_virtual, |
|---|
| 863 |
p_sys->var_info.yres_virtual, |
|---|
| 864 |
p_sys->i_width, p_sys->i_height ); |
|---|
| 865 |
|
|---|
| 866 |
p_sys->p_palette = NULL; |
|---|
| 867 |
p_sys->b_pan = ( fix_info.ypanstep || fix_info.ywrapstep ); |
|---|
| 868 |
|
|---|
| 869 |
switch( p_sys->var_info.bits_per_pixel ) |
|---|
| 870 |
{ |
|---|
| 871 |
case 8: |
|---|
| 872 |
p_sys->p_palette = malloc( 8 * 256 * sizeof( uint16_t ) ); |
|---|
| 873 |
if( !p_sys->p_palette ) |
|---|
| 874 |
{ |
|---|
| 875 |
|
|---|
| 876 |
ioctl( p_sys->i_fd, FBIOPUT_VSCREENINFO, &p_sys->old_info ); |
|---|
| 877 |
|
|---|
| 878 |
close( p_sys->i_fd ); |
|---|
| 879 |
return VLC_ENOMEM; |
|---|
| 880 |
} |
|---|
| 881 |
p_sys->fb_cmap.start = 0; |
|---|
| 882 |
p_sys->fb_cmap.len = 256; |
|---|
| 883 |
p_sys->fb_cmap.red = p_sys->p_palette; |
|---|
| 884 |
p_sys->fb_cmap.green = p_sys->p_palette + 256 * sizeof( uint16_t ); |
|---|
| 885 |
p_sys->fb_cmap.blue = p_sys->p_p |
|---|