1 /*****************************************************************************
2 * vout_dummy.c: Dummy video output display method for testing purposes
3 *****************************************************************************
4 * Copyright (C) 2000, 2001 VideoLAN
5 * $Id: vout_dummy.c,v 1.18 2002/02/15 13:32:53 sam Exp $
7 * Authors: Samuel 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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
27 #include <errno.h> /* ENOMEM */
28 #include <stdlib.h> /* free() */
29 #include <string.h> /* strerror() */
31 #include <videolan/vlc.h>
34 #include "video_output.h"
36 #define DUMMY_WIDTH 16
37 #define DUMMY_HEIGHT 16
38 #define DUMMY_MAX_DIRECTBUFFERS 10
40 /*****************************************************************************
41 * vout_sys_t: dummy video output method descriptor
42 *****************************************************************************
43 * This structure is part of the video output thread descriptor.
44 * It describes the dummy specific properties of an output thread.
45 *****************************************************************************/
46 typedef struct vout_sys_s
48 /* Nothing needed here. Maybe stats ? */
52 /*****************************************************************************
54 *****************************************************************************/
55 static int vout_Create ( struct vout_thread_s * );
56 static int vout_Init ( struct vout_thread_s * );
57 static void vout_End ( struct vout_thread_s * );
58 static void vout_Destroy ( struct vout_thread_s * );
59 static int vout_Manage ( struct vout_thread_s * );
60 static void vout_Render ( struct vout_thread_s *, struct picture_s * );
61 static void vout_Display ( struct vout_thread_s *, struct picture_s * );
63 static int DummyNewPicture( struct vout_thread_s *, struct picture_s * );
65 /*****************************************************************************
66 * Functions exported as capabilities. They are declared as static so that
67 * we don't pollute the namespace too much.
68 *****************************************************************************/
69 void _M( vout_getfunctions )( function_list_t * p_function_list )
71 p_function_list->functions.vout.pf_create = vout_Create;
72 p_function_list->functions.vout.pf_init = vout_Init;
73 p_function_list->functions.vout.pf_end = vout_End;
74 p_function_list->functions.vout.pf_destroy = vout_Destroy;
75 p_function_list->functions.vout.pf_manage = vout_Manage;
76 p_function_list->functions.vout.pf_render = vout_Render;
77 p_function_list->functions.vout.pf_display = vout_Display;
80 /*****************************************************************************
81 * vout_Create: allocates dummy video thread output method
82 *****************************************************************************
83 * This function allocates and initializes a dummy vout method.
84 *****************************************************************************/
85 static int vout_Create( vout_thread_t *p_vout )
87 /* Allocate structure */
88 p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
89 if( p_vout->p_sys == NULL )
91 intf_ErrMsg("error: %s", strerror(ENOMEM) );
98 /*****************************************************************************
99 * vout_Init: initialize dummy video thread output method
100 *****************************************************************************/
101 static int vout_Init( vout_thread_t *p_vout )
106 I_OUTPUTPICTURES = 0;
108 /* Initialize the output structure */
109 switch( p_vout->render.i_chroma )
114 p_vout->output.i_chroma = p_vout->render.i_chroma;
115 p_vout->output.i_width = p_vout->render.i_width;
116 p_vout->output.i_height = p_vout->render.i_height;
117 p_vout->output.i_aspect = p_vout->render.i_aspect;
121 p_vout->output.i_chroma = FOURCC_RV16;
122 p_vout->output.i_width = p_vout->render.i_width;
123 p_vout->output.i_height = p_vout->render.i_height;
124 p_vout->output.i_aspect = p_vout->render.i_aspect;
128 /* Try to initialize DUMMY_MAX_DIRECTBUFFERS direct buffers */
129 while( I_OUTPUTPICTURES < DUMMY_MAX_DIRECTBUFFERS )
133 /* Find an empty picture slot */
134 for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
136 if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
138 p_pic = p_vout->p_picture + i_index;
143 /* Allocate the picture */
144 if( p_pic == NULL || DummyNewPicture( p_vout, p_pic ) )
149 p_pic->i_status = DESTROYED_PICTURE;
150 p_pic->i_type = DIRECT_PICTURE;
152 PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
160 /*****************************************************************************
161 * vout_End: terminate dummy video thread output method
162 *****************************************************************************/
163 static void vout_End( vout_thread_t *p_vout )
167 /* Free the fake output buffers we allocated */
168 for( i_index = I_OUTPUTPICTURES ; i_index ; )
171 free( PP_OUTPUTPICTURE[ i_index ]->p_data );
175 /*****************************************************************************
176 * vout_Destroy: destroy dummy video thread output method
177 *****************************************************************************
178 * Terminate an output method created by DummyCreateOutputMethod
179 *****************************************************************************/
180 static void vout_Destroy( vout_thread_t *p_vout )
182 free( p_vout->p_sys );
185 /*****************************************************************************
186 * vout_Manage: handle dummy events
187 *****************************************************************************
188 * This function should be called regularly by video output thread. It manages
189 * console events. It returns a non null value on error.
190 *****************************************************************************/
191 static int vout_Manage( vout_thread_t *p_vout )
196 /*****************************************************************************
197 * vout_Render: render previously calculated output
198 *****************************************************************************/
199 static void vout_Render( vout_thread_t *p_vout, picture_t *p_pic )
201 /* No need to do anything, the fake direct buffers stay as they are */
204 /*****************************************************************************
205 * vout_Display: displays previously rendered output
206 *****************************************************************************/
207 static void vout_Display( vout_thread_t *p_vout, picture_t *p_pic )
209 /* No need to do anything, the fake direct buffers stay as they are */
212 /*****************************************************************************
213 * DummyNewPicture: allocate a picture
214 *****************************************************************************
215 * Returns 0 on success, -1 otherwise
216 *****************************************************************************/
217 static int DummyNewPicture( vout_thread_t *p_vout, picture_t *p_pic )
219 int i_width = p_vout->output.i_width;
220 int i_height = p_vout->output.i_height;
222 switch( p_vout->output.i_chroma )
224 /* We know this chroma, allocate a buffer which will be used
225 * directly by the decoder */
230 /* Allocate the memory buffer */
231 p_pic->p_data = memalign( 16, i_width * i_height * 3 / 2 );
234 p_pic->Y_PIXELS = p_pic->p_data;
235 p_pic->p[Y_PLANE].i_lines = i_height;
236 p_pic->p[Y_PLANE].i_pitch = i_width;
237 p_pic->p[Y_PLANE].i_pixel_bytes = 1;
238 p_pic->p[Y_PLANE].b_margin = 0;
241 p_pic->U_PIXELS = p_pic->Y_PIXELS + i_height * i_width;
242 p_pic->p[U_PLANE].i_lines = i_height / 2;
243 p_pic->p[U_PLANE].i_pitch = i_width / 2;
244 p_pic->p[U_PLANE].i_pixel_bytes = 1;
245 p_pic->p[U_PLANE].b_margin = 0;
248 p_pic->V_PIXELS = p_pic->U_PIXELS + i_height * i_width / 4;
249 p_pic->p[V_PLANE].i_lines = i_height / 2;
250 p_pic->p[V_PLANE].i_pitch = i_width / 2;
251 p_pic->p[V_PLANE].i_pixel_bytes = 1;
252 p_pic->p[V_PLANE].b_margin = 0;
254 /* We allocated 3 planes */
260 /* Unknown chroma, allocate an RGB buffer, the video output's job
261 * will be to do the chroma->RGB conversion */
264 /* Allocate the memory buffer */
265 p_pic->p_data = memalign( 16, i_width * i_height * 2 );
267 /* Fill important structures */
268 p_pic->p->p_pixels = p_pic->p_data;
269 p_pic->p->i_lines = i_height;
270 p_pic->p->i_pitch = i_width;
271 p_pic->p->i_pixel_bytes = 2;
272 p_pic->p->b_margin = 0;
273 p_pic->p->i_red_mask = 0xf800;
274 p_pic->p->i_green_mask = 0x07e0;
275 p_pic->p->i_blue_mask = 0x001f;
277 /* We allocated 1 plane */