| 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 |
|
|---|
| 30 |
#ifdef HAVE_CONFIG_H |
|---|
| 31 |
# include "config.h" |
|---|
| 32 |
#endif |
|---|
| 33 |
|
|---|
| 34 |
#include <vlc_common.h> |
|---|
| 35 |
#include <vlc_plugin.h> |
|---|
| 36 |
#include <vlc_vout.h> |
|---|
| 37 |
#include <directfb.h> |
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
static int Create ( vlc_object_t * ); |
|---|
| 43 |
static void Destroy ( vlc_object_t * ); |
|---|
| 44 |
|
|---|
| 45 |
static int Init ( vout_thread_t * ); |
|---|
| 46 |
static void End ( vout_thread_t * ); |
|---|
| 47 |
static int Manage ( vout_thread_t * ); |
|---|
| 48 |
static void Display ( vout_thread_t *, picture_t * ); |
|---|
| 49 |
|
|---|
| 50 |
static int OpenDisplay ( vout_thread_t * ); |
|---|
| 51 |
static void CloseDisplay ( vout_thread_t * ); |
|---|
| 52 |
|
|---|
| 53 |
struct vout_sys_t |
|---|
| 54 |
{ |
|---|
| 55 |
IDirectFB *p_directfb; |
|---|
| 56 |
IDirectFBSurface *p_primary; |
|---|
| 57 |
DFBSurfacePixelFormat p_pixel_format; |
|---|
| 58 |
|
|---|
| 59 |
int i_width; |
|---|
| 60 |
int i_height; |
|---|
| 61 |
|
|---|
| 62 |
uint8_t* p_pixels; |
|---|
| 63 |
}; |
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 |
vlc_module_begin(); |
|---|
| 69 |
set_shortname( "DirectFB" ); |
|---|
| 70 |
set_category( CAT_VIDEO ); |
|---|
| 71 |
set_subcategory( SUBCAT_VIDEO_VOUT ); |
|---|
| 72 |
set_description( N_("DirectFB video output http://www.directfb.org/") ); |
|---|
| 73 |
set_capability( "video output", 60 ); |
|---|
| 74 |
add_shortcut( "directfb" ); |
|---|
| 75 |
set_callbacks( Create, Destroy ); |
|---|
| 76 |
vlc_module_end(); |
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 |
static int Create( vlc_object_t *p_this ) |
|---|
| 80 |
{ |
|---|
| 81 |
vout_thread_t *p_vout = (vout_thread_t *)p_this; |
|---|
| 82 |
vout_sys_t *p_sys = NULL; |
|---|
| 83 |
p_vout->pf_init = Init; |
|---|
| 84 |
p_vout->pf_end = End; |
|---|
| 85 |
p_vout->pf_manage = Manage; |
|---|
| 86 |
p_vout->pf_render = NULL; |
|---|
| 87 |
p_vout->pf_display = Display; |
|---|
| 88 |
|
|---|
| 89 |
|
|---|
| 90 |
p_vout->p_sys = p_sys = malloc( sizeof( vout_sys_t ) ); |
|---|
| 91 |
if( !p_sys ) |
|---|
| 92 |
return VLC_ENOMEM; |
|---|
| 93 |
|
|---|
| 94 |
p_sys->p_directfb = NULL; |
|---|
| 95 |
p_sys->p_primary = NULL; |
|---|
| 96 |
p_sys->p_pixels = NULL; |
|---|
| 97 |
p_sys->i_width = 0; |
|---|
| 98 |
p_sys->i_height = 0; |
|---|
| 99 |
|
|---|
| 100 |
|
|---|
| 101 |
if( DirectFBInit(NULL,NULL) != DFB_OK ) |
|---|
| 102 |
{ |
|---|
| 103 |
msg_Err(p_vout, "Cannot init DirectFB"); |
|---|
| 104 |
return VLC_EGENERIC; |
|---|
| 105 |
} |
|---|
| 106 |
|
|---|
| 107 |
if( OpenDisplay( p_vout ) ) |
|---|
| 108 |
{ |
|---|
| 109 |
msg_Err(p_vout, "Cannot create primary surface"); |
|---|
| 110 |
free( p_sys ); |
|---|
| 111 |
return VLC_EGENERIC; |
|---|
| 112 |
} |
|---|
| 113 |
return VLC_SUCCESS; |
|---|
| 114 |
} |
|---|
| 115 |
|
|---|
| 116 |
|
|---|
| 117 |
static int Init( vout_thread_t *p_vout ) |
|---|
| 118 |
{ |
|---|
| 119 |
vout_sys_t *p_sys = p_vout->p_sys; |
|---|
| 120 |
IDirectFBSurface *p_primary = (IDirectFBSurface *) p_vout->p_sys->p_primary; |
|---|
| 121 |
uint8_t* p_pixels = NULL; |
|---|
| 122 |
picture_t *p_pic = NULL; |
|---|
| 123 |
int i_rlength, i_glength, i_blength; |
|---|
| 124 |
int i_roffset, i_goffset, i_boffset; |
|---|
| 125 |
int i_line_pitch; |
|---|
| 126 |
int i_size; |
|---|
| 127 |
int i_index; |
|---|
| 128 |
|
|---|
| 129 |
I_OUTPUTPICTURES = 0; |
|---|
| 130 |
|
|---|
| 131 |
switch( p_sys->p_pixel_format ) |
|---|
| 132 |
{ |
|---|
| 133 |
case DSPF_RGB332: |
|---|
| 134 |
|
|---|
| 135 |
|
|---|
| 136 |
i_rlength = 3; |
|---|
| 137 |
i_roffset = 5; |
|---|
| 138 |
i_glength = 3; |
|---|
| 139 |
i_goffset = 2; |
|---|
| 140 |
i_blength = 2; |
|---|
| 141 |
i_boffset = 0; |
|---|
| 142 |
p_vout->output.i_chroma = VLC_FOURCC('R','G','B','2'); |
|---|
| 143 |
break; |
|---|
| 144 |
|
|---|
| 145 |
case DSPF_RGB16: |
|---|
| 146 |
|
|---|
| 147 |
|
|---|
| 148 |
i_rlength = 5; |
|---|
| 149 |
i_roffset = 11; |
|---|
| 150 |
i_glength = 6; |
|---|
| 151 |
i_goffset = 5; |
|---|
| 152 |
i_blength = 5; |
|---|
| 153 |
i_boffset = 0; |
|---|
| 154 |
p_vout->output.i_chroma = VLC_FOURCC('R','V','1','6'); |
|---|
| 155 |
break; |
|---|
| 156 |
|
|---|
| 157 |
case DSPF_RGB24: |
|---|
| 158 |
|
|---|
| 159 |
|
|---|
| 160 |
i_rlength = 8; |
|---|
| 161 |
i_roffset = 16; |
|---|
| 162 |
i_glength = 8; |
|---|
| 163 |
i_goffset = 8; |
|---|
| 164 |
i_blength = 8; |
|---|
| 165 |
i_boffset = 0; |
|---|
| 166 |
p_vout->output.i_chroma = VLC_FOURCC('R','V','2','4'); |
|---|
| 167 |
break; |
|---|
| 168 |
|
|---|
| 169 |
case DSPF_RGB32: |
|---|
| 170 |
|
|---|
| 171 |
|
|---|
| 172 |
i_rlength = 8; |
|---|
| 173 |
i_roffset = 16; |
|---|
| 174 |
i_glength = 8; |
|---|
| 175 |
i_goffset = 8; |
|---|
| 176 |
i_blength = 8; |
|---|
| 177 |
i_boffset = 0; |
|---|
| 178 |
p_vout->output.i_chroma = VLC_FOURCC('R','V','3','2'); |
|---|
| 179 |
break; |
|---|
| 180 |
|
|---|
| 181 |
default: |
|---|
| 182 |
msg_Err( p_vout, "unknown screen depth %i", |
|---|
| 183 |
p_sys->p_pixel_format ); |
|---|
| 184 |
return VLC_EGENERIC; |
|---|
| 185 |
} |
|---|
| 186 |
|
|---|
| 187 |
p_vout->output.i_rmask = ( (1 << i_rlength) - 1 ) << i_roffset; |
|---|
| 188 |
p_vout->output.i_gmask = ( (1 << i_glength) - 1 ) << i_goffset; |
|---|
| 189 |
p_vout->output.i_bmask = ( (1 << i_blength) - 1 ) << i_boffset; |
|---|
| 190 |
|
|---|
| 191 |
|
|---|
| 192 |
p_vout->output.i_width = p_sys->i_width; |
|---|
| 193 |
p_vout->output.i_height = p_sys->i_height; |
|---|
| 194 |
|
|---|
| 195 |
|
|---|
| 196 |
p_vout->output.i_aspect = (p_sys->i_width * VOUT_ASPECT_FACTOR) / |
|---|
| 197 |
p_sys->i_height; |
|---|
| 198 |
|
|---|
| 199 |
|
|---|
| 200 |
|
|---|
| 201 |
for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ ) |
|---|
| 202 |
{ |
|---|
| 203 |
if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE ) |
|---|
| 204 |
{ |
|---|
| 205 |
p_pic = p_vout->p_picture + i_index; |
|---|
| 206 |
break; |
|---|
| 207 |
} |
|---|
| 208 |
} |
|---|
| 209 |
|
|---|
| 210 |
|
|---|
| 211 |
if( !p_pic ) |
|---|
| 212 |
return VLC_EGENERIC; |
|---|
| 213 |
|
|---|
| 214 |
|
|---|
| 215 |
if( p_primary->Lock( p_primary, DSLF_READ, (void **) &p_pixels, |
|---|
| 216 |
&i_line_pitch) != DFB_OK ) |
|---|
| 217 |
return VLC_EGENERIC; |
|---|
| 218 |
|
|---|
| 219 |
|
|---|
| 220 |
i_size = i_line_pitch * p_sys->i_height; |
|---|
| 221 |
p_sys->p_pixels = malloc( i_size ); |
|---|
| 222 |
if( p_sys->p_pixels == NULL ) |
|---|
| 223 |
{ |
|---|
| 224 |
p_primary->Unlock(p_primary); |
|---|
| 225 |
return VLC_ENOMEM; |
|---|
| 226 |
} |
|---|
| 227 |
|
|---|
| 228 |
|
|---|
| 229 |
memcpy( p_sys->p_pixels, p_pixels, i_size ); |
|---|
| 230 |
if( p_primary->Unlock(p_primary) != DFB_OK ) |
|---|
| 231 |
{ |
|---|
| 232 |
return VLC_EGENERIC; |
|---|
| 233 |
} |
|---|
| 234 |
|
|---|
| 235 |
p_pic->p->p_pixels = p_sys->p_pixels; |
|---|
| 236 |
p_pic->p->i_pixel_pitch = i_line_pitch / p_sys->i_width; |
|---|
| 237 |
p_pic->p->i_lines = p_sys->i_height; |
|---|
| 238 |
p_pic->p->i_visible_lines = p_sys->i_height; |
|---|
| 239 |
p_pic->p->i_pitch = i_line_pitch; |
|---|
| 240 |
p_pic->p->i_visible_pitch = i_line_pitch; |
|---|
| 241 |
p_pic->i_planes = 1; |
|---|
| 242 |
p_pic->i_status = DESTROYED_PICTURE; |
|---|
| 243 |
p_pic->i_type = DIRECT_PICTURE; |
|---|
| 244 |
|
|---|
| 245 |
PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic; |
|---|
| 246 |
|
|---|
| 247 |
I_OUTPUTPICTURES++; |
|---|
| 248 |
|
|---|
| 249 |
return VLC_SUCCESS; |
|---|
| 250 |
} |
|---|
| 251 |
|
|---|
| 252 |
static void End( vout_thread_t *p_vout ) |
|---|
| 253 |
{ |
|---|
| 254 |
vout_sys_t *p_sys = p_vout->p_sys; |
|---|
| 255 |
|
|---|
| 256 |
free( p_sys->p_pixels ); |
|---|
| 257 |
} |
|---|
| 258 |
|
|---|
| 259 |
static void Destroy( vlc_object_t *p_this ) |
|---|
| 260 |
{ |
|---|
| 261 |
vout_thread_t *p_vout = (vout_thread_t *)p_this; |
|---|
| 262 |
vout_sys_t *p_sys = p_vout->p_sys; |
|---|
| 263 |
|
|---|
| 264 |
CloseDisplay( p_vout ); |
|---|
| 265 |
free( p_sys ); |
|---|
| 266 |
p_sys = NULL; |
|---|
| 267 |
} |
|---|
| 268 |
|
|---|
| 269 |
static int Manage( vout_thread_t *p_vout ) |
|---|
| 270 |
{ |
|---|
| 271 |
return VLC_SUCCESS; |
|---|
| 272 |
} |
|---|
| 273 |
|
|---|
| 274 |
static void Display( vout_thread_t *p_vout, picture_t *p_pic ) |
|---|
| 275 |
{ |
|---|
| 276 |
vout_sys_t *p_sys = p_vout->p_sys; |
|---|
| 277 |
IDirectFBSurface *p_primary = (IDirectFBSurface *) p_sys->p_primary; |
|---|
| 278 |
uint8_t* p_pixels = NULL; |
|---|
| 279 |
int i_size; |
|---|
| 280 |
int i_line_pitch; |
|---|
| 281 |
|
|---|
| 282 |
|
|---|
| 283 |
if( p_primary->Lock( p_primary, DSLF_WRITE, |
|---|
| 284 |
(void **) &p_pixels, |
|---|
| 285 |
&i_line_pitch) == DFB_OK ) |
|---|
| 286 |
{ |
|---|
| 287 |
i_size = i_line_pitch * p_vout->p_sys->i_height; |
|---|
| 288 |
|
|---|
| 289 |
|
|---|
| 290 |
memcpy( p_pixels, p_pic->p->p_pixels, i_size); |
|---|
| 291 |
if( p_primary->Unlock(p_primary) == DFB_OK ) |
|---|
| 292 |
{ |
|---|
| 293 |
p_primary->Flip(p_primary, NULL, 0); |
|---|
| 294 |
} |
|---|
| 295 |
} |
|---|
| 296 |
} |
|---|
| 297 |
|
|---|
| 298 |
static int OpenDisplay( vout_thread_t *p_vout ) |
|---|
| 299 |
{ |
|---|
| 300 |
vout_sys_t *p_sys = p_vout->p_sys; |
|---|
| 301 |
IDirectFB *p_directfb = NULL; |
|---|
| 302 |
IDirectFBSurface *p_primary = NULL; |
|---|
| 303 |
DFBSurfaceDescription dsc; |
|---|
| 304 |
|
|---|
| 305 |
|
|---|
| 306 |
dsc.flags = DSDESC_CAPS; |
|---|
| 307 |
dsc.caps = DSCAPS_PRIMARY | DSCAPS_FLIPPING; |
|---|
| 308 |
|
|---|
| 309 |
|
|---|
| 310 |
|
|---|
| 311 |
if( DirectFBCreate( &p_directfb ) != DFB_OK ) |
|---|
| 312 |
return VLC_EGENERIC; |
|---|
| 313 |
|
|---|
| 314 |
p_sys->p_directfb = p_directfb; |
|---|
| 315 |
if( !p_directfb ) |
|---|
| 316 |
return VLC_EGENERIC; |
|---|
| 317 |
|
|---|
| 318 |
if( p_directfb->CreateSurface( p_directfb, &dsc, &p_primary ) ) |
|---|
| 319 |
return VLC_EGENERIC; |
|---|
| 320 |
|
|---|
| 321 |
p_sys->p_primary = p_primary; |
|---|
| 322 |
if( !p_primary ) |
|---|
| 323 |
return VLC_EGENERIC; |
|---|
| 324 |
|
|---|
| 325 |
p_primary->GetSize( p_primary, &p_sys->i_width, |
|---|
| 326 |
&p_sys->i_height ); |
|---|
| 327 |
p_primary->GetPixelFormat( p_primary, &p_sys->p_pixel_format ); |
|---|
| 328 |
p_primary->FillRectangle( p_primary, 0, 0, p_sys->i_width, |
|---|
| 329 |
p_sys->i_height ); |
|---|
| 330 |
p_primary->Flip( p_primary, NULL, 0 ); |
|---|
| 331 |
|
|---|
| 332 |
return VLC_SUCCESS; |
|---|
| 333 |
} |
|---|
| 334 |
|
|---|
| 335 |
static void CloseDisplay( vout_thread_t *p_vout ) |
|---|
| 336 |
{ |
|---|
| 337 |
vout_sys_t *p_sys = p_vout->p_sys; |
|---|
| 338 |
IDirectFB *p_directfb = p_sys->p_directfb; |
|---|
| 339 |
IDirectFBSurface *p_primary = p_sys->p_primary; |
|---|
| 340 |
|
|---|
| 341 |
if( p_primary ) |
|---|
| 342 |
p_primary->Release( p_primary ); |
|---|
| 343 |
|
|---|
| 344 |
if( p_directfb ) |
|---|
| 345 |
p_directfb->Release( p_directfb ); |
|---|
| 346 |
} |
|---|