1 /*****************************************************************************
2 * vmem.c: memory video driver for vlc
3 *****************************************************************************
4 * Copyright (C) 2008 the VideoLAN team
7 * Authors: Sam Hocevar <sam@zoy.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
35 /*****************************************************************************
37 *****************************************************************************/
38 static int Create ( vlc_object_t * );
39 static void Destroy ( vlc_object_t * );
41 static int Init ( vout_thread_t * );
42 static void End ( vout_thread_t * );
43 static int LockPicture ( vout_thread_t *, picture_t * );
44 static int UnlockPicture ( vout_thread_t *, picture_t * );
46 /*****************************************************************************
48 *****************************************************************************/
49 #define T_WIDTH N_( "Width" )
50 #define LT_WIDTH N_( "Video memory buffer width." )
52 #define T_HEIGHT N_( "Height" )
53 #define LT_HEIGHT N_( "Video memory buffer height." )
55 #define T_PITCH N_( "Pitch" )
56 #define LT_PITCH N_( "Video memory buffer pitch in bytes." )
58 #define T_CHROMA N_( "Chroma" )
59 #define LT_CHROMA N_( "Output chroma for the memory image as a 4-character " \
60 "string, eg. \"RV32\"." )
62 #define T_LOCK N_( "Lock function" )
63 #define LT_LOCK N_( "Address of the locking callback function. This " \
64 "function must return a valid memory address for use " \
65 "by the video renderer." )
67 #define T_UNLOCK N_( "Unlock function" )
68 #define LT_UNLOCK N_( "Address of the unlocking callback function" )
70 #define T_DATA N_( "Callback data" )
71 #define LT_DATA N_( "Data for the locking and unlocking functions" )
74 set_description( _( "Video memory module" ) );
75 set_shortname( _("Video memory") );
77 set_category( CAT_VIDEO );
78 set_subcategory( SUBCAT_VIDEO_VOUT );
79 set_capability( "video output", 0 );
81 add_integer( "vmem-width", 320, NULL, T_WIDTH, LT_WIDTH, false );
82 add_integer( "vmem-height", 200, NULL, T_HEIGHT, LT_HEIGHT, false );
83 add_integer( "vmem-pitch", 640, NULL, T_PITCH, LT_PITCH, false );
84 add_string( "vmem-chroma", "RV16", NULL, T_CHROMA, LT_CHROMA, true );
85 add_string( "vmem-lock", "0", NULL, T_LOCK, LT_LOCK, true );
86 add_string( "vmem-unlock", "0", NULL, T_UNLOCK, LT_UNLOCK, true );
87 add_string( "vmem-data", "0", NULL, T_DATA, LT_DATA, true );
89 set_callbacks( Create, Destroy );
92 /*****************************************************************************
93 * vout_sys_t: video output descriptor
94 *****************************************************************************/
97 int i_width, i_height, i_pitch;
99 void * (*pf_lock) (void *);
100 void (*pf_unlock) (void *);
104 /*****************************************************************************
105 * Create: allocates video thread
106 *****************************************************************************
107 * This function allocates and initializes a vout method.
108 *****************************************************************************/
109 static int Create( vlc_object_t *p_this )
111 vout_thread_t *p_vout = ( vout_thread_t * )p_this;
113 /* Allocate instance and initialize some members */
114 p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
115 if( ! p_vout->p_sys )
118 p_vout->pf_init = Init;
119 p_vout->pf_end = End;
120 p_vout->pf_manage = NULL;
121 p_vout->pf_render = NULL;
122 p_vout->pf_display = NULL;
127 /*****************************************************************************
128 * Init: initialize video thread
129 *****************************************************************************/
130 static int Init( vout_thread_t *p_vout )
134 char *psz_chroma, *psz_tmp;
135 int i_width, i_height, i_pitch, i_chroma;
137 i_width = config_GetInt( p_vout, "vmem-width" );
138 i_height = config_GetInt( p_vout, "vmem-height" );
139 i_pitch = config_GetInt( p_vout, "vmem-pitch" );
141 psz_chroma = config_GetPsz( p_vout, "vmem-chroma" );
144 if( strlen( psz_chroma ) < 4 )
146 msg_Err( p_vout, "vmem-chroma should be 4 characters long" );
149 i_chroma = VLC_FOURCC( psz_chroma[0], psz_chroma[1],
150 psz_chroma[2], psz_chroma[3] );
155 msg_Err( p_vout, "Cannot find chroma information." );
159 psz_tmp = config_GetPsz( p_vout, "vmem-lock" );
160 p_vout->p_sys->pf_lock = (void * (*) (void *))(intptr_t)atoll( psz_tmp );
163 psz_tmp = config_GetPsz( p_vout, "vmem-unlock" );
164 p_vout->p_sys->pf_unlock = (void (*) (void *))(intptr_t)atoll( psz_tmp );
167 psz_tmp = config_GetPsz( p_vout, "vmem-data" );
168 p_vout->p_sys->p_data = (void *)(intptr_t)atoll( psz_tmp );
171 if( !p_vout->p_sys->pf_lock || !p_vout->p_sys->pf_unlock )
173 msg_Err( p_vout, "Invalid lock or unlock callbacks" );
177 I_OUTPUTPICTURES = 0;
179 /* Initialize the output structure */
180 p_vout->output.i_chroma = i_chroma;
181 p_vout->output.pf_setpalette = NULL;
182 p_vout->output.i_width = i_width;
183 p_vout->output.i_height = i_height;
184 p_vout->output.i_aspect = p_vout->output.i_width
185 * VOUT_ASPECT_FACTOR / p_vout->output.i_height;
187 /* Define the bitmasks */
190 case VLC_FOURCC( 'R','V','1','5' ):
191 p_vout->output.i_rmask = 0x001f;
192 p_vout->output.i_gmask = 0x03e0;
193 p_vout->output.i_bmask = 0x7c00;
196 case VLC_FOURCC( 'R','V','1','6' ):
197 p_vout->output.i_rmask = 0x001f;
198 p_vout->output.i_gmask = 0x07e0;
199 p_vout->output.i_bmask = 0xf800;
202 case VLC_FOURCC( 'R','V','2','4' ):
203 p_vout->output.i_rmask = 0xff0000;
204 p_vout->output.i_gmask = 0x00ff00;
205 p_vout->output.i_bmask = 0x0000ff;
208 case VLC_FOURCC( 'R','V','3','2' ):
209 p_vout->output.i_rmask = 0xff0000;
210 p_vout->output.i_gmask = 0x00ff00;
211 p_vout->output.i_bmask = 0x0000ff;
215 /* Try to initialize 1 direct buffer */
218 /* Find an empty picture slot */
219 for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
221 if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
223 p_pic = p_vout->p_picture + i_index;
228 /* Allocate the picture */
234 vout_InitPicture( VLC_OBJECT(p_vout), p_pic, p_vout->output.i_chroma,
235 p_vout->output.i_width, p_vout->output.i_height,
236 p_vout->output.i_aspect );
238 p_pic->p->i_pitch = i_pitch;
240 p_pic->pf_lock = LockPicture;
241 p_pic->pf_unlock = UnlockPicture;
243 p_pic->i_status = DESTROYED_PICTURE;
244 p_pic->i_type = DIRECT_PICTURE;
246 PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
253 /*****************************************************************************
254 * End: terminate video thread output method
255 *****************************************************************************/
256 static void End( vout_thread_t *p_vout )
261 /*****************************************************************************
262 * Destroy: destroy video thread
263 *****************************************************************************
264 * Terminate an output method created by Create
265 *****************************************************************************/
266 static void Destroy( vlc_object_t *p_this )
268 vout_thread_t *p_vout = ( vout_thread_t * )p_this;
270 /* Destroy structure */
271 free( p_vout->p_sys );
274 /*****************************************************************************
275 * LockPicture: lock a picture
276 *****************************************************************************
277 * This function locks the picture and prepares it for direct pixel access.
278 *****************************************************************************/
279 static int LockPicture( vout_thread_t *p_vout, picture_t *p_pic )
281 p_pic->p->p_pixels = p_vout->p_sys->pf_lock( p_vout->p_sys->p_data );
286 /*****************************************************************************
287 * UnlockPicture: unlock a picture
288 *****************************************************************************
289 * This function unlocks a previously locked picture.
290 *****************************************************************************/
291 static int UnlockPicture( vout_thread_t *p_vout, picture_t *p_pic )
293 p_vout->p_sys->pf_unlock( p_vout->p_sys->p_data );