]> git.sesse.net Git - vlc/blob - plugins/dummy/vout_dummy.c
* ./BUGS: added a list of known bugs. Please add your findings!
[vlc] / plugins / dummy / vout_dummy.c
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.15 2002/01/04 14:01:34 sam Exp $
6  *
7  * Authors: Samuel Hocevar <sam@zoy.org>
8  *
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.
13  * 
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.
18  *
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  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <errno.h>                                                 /* ENOMEM */
28 #include <stdlib.h>                                                /* free() */
29 #include <string.h>                                            /* strerror() */
30
31 #include <videolan/vlc.h>
32
33 #include "video.h"
34 #include "video_output.h"
35
36 #define DUMMY_WIDTH 16
37 #define DUMMY_HEIGHT 16
38 #define DUMMY_MAX_DIRECTBUFFERS 5
39
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
47 {
48     /* Nothing needed here. Maybe stats ? */
49
50 } vout_sys_t;
51
52 /*****************************************************************************
53  * Local prototypes
54  *****************************************************************************/
55 static int  vout_Probe     ( probedata_t *p_data );
56 static int  vout_Create    ( struct vout_thread_s * );
57 static int  vout_Init      ( struct vout_thread_s * );
58 static void vout_End       ( struct vout_thread_s * );
59 static void vout_Destroy   ( struct vout_thread_s * );
60 static int  vout_Manage    ( struct vout_thread_s * );
61 static void vout_Render    ( struct vout_thread_s *, struct picture_s * );
62 static void vout_Display   ( struct vout_thread_s *, struct picture_s * );
63
64 static int  DummyNewPicture( struct vout_thread_s *, struct picture_s * );
65
66 /*****************************************************************************
67  * Functions exported as capabilities. They are declared as static so that
68  * we don't pollute the namespace too much.
69  *****************************************************************************/
70 void _M( vout_getfunctions )( function_list_t * p_function_list )
71 {
72     p_function_list->pf_probe = vout_Probe;
73     p_function_list->functions.vout.pf_create     = vout_Create;
74     p_function_list->functions.vout.pf_init       = vout_Init;
75     p_function_list->functions.vout.pf_end        = vout_End;
76     p_function_list->functions.vout.pf_destroy    = vout_Destroy;
77     p_function_list->functions.vout.pf_manage     = vout_Manage;
78     p_function_list->functions.vout.pf_render     = vout_Render;
79     p_function_list->functions.vout.pf_display    = vout_Display;
80     p_function_list->functions.vout.pf_setpalette = NULL;
81 }
82
83 /*****************************************************************************
84  * intf_Probe: return a score
85  *****************************************************************************/
86 static int vout_Probe( probedata_t *p_data )
87 {
88     return( 1 );
89 }
90
91 /*****************************************************************************
92  * vout_Create: allocates dummy video thread output method
93  *****************************************************************************
94  * This function allocates and initializes a dummy vout method.
95  *****************************************************************************/
96 static int vout_Create( vout_thread_t *p_vout )
97 {
98     /* Allocate structure */
99     p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
100     if( p_vout->p_sys == NULL )
101     {
102         intf_ErrMsg("error: %s", strerror(ENOMEM) );
103         return( 1 );
104     }
105
106     return( 0 );
107 }
108
109 /*****************************************************************************
110  * vout_Init: initialize dummy video thread output method
111  *****************************************************************************/
112 static int vout_Init( vout_thread_t *p_vout )
113 {
114     int i_index;
115     picture_t *p_pic;
116     
117     I_OUTPUTPICTURES = 0;
118
119     /* Initialize the output structure */
120     switch( p_vout->render.i_chroma )
121     {
122         case FOURCC_I420:
123         case FOURCC_IYUV:
124         case FOURCC_YV12:
125             p_vout->output.i_chroma = p_vout->render.i_chroma;
126             p_vout->output.i_width  = p_vout->render.i_width;
127             p_vout->output.i_height = p_vout->render.i_height;
128             p_vout->output.i_aspect = p_vout->render.i_aspect;
129             break;
130
131         default:
132             p_vout->output.i_chroma = FOURCC_RV16;
133             p_vout->output.i_width  = p_vout->render.i_width;
134             p_vout->output.i_height = p_vout->render.i_height;
135             p_vout->output.i_aspect = p_vout->render.i_aspect;
136             break;
137     }
138
139     /* Try to initialize DUMMY_MAX_DIRECTBUFFERS direct buffers */
140     while( I_OUTPUTPICTURES < DUMMY_MAX_DIRECTBUFFERS )
141     {
142         p_pic = NULL;
143
144         /* Find an empty picture slot */
145         for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
146         {
147             if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
148             {
149                 p_pic = p_vout->p_picture + i_index;
150                 break;
151             }
152         }
153
154         /* Allocate the picture */
155         if( p_pic == NULL || DummyNewPicture( p_vout, p_pic ) )
156         {
157             break;
158         }
159
160         p_pic->i_status = DESTROYED_PICTURE;
161         p_pic->i_type   = DIRECT_PICTURE;
162
163         PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
164
165         I_OUTPUTPICTURES++;
166     }
167
168     return( 0 );
169 }
170
171 /*****************************************************************************
172  * vout_End: terminate dummy video thread output method
173  *****************************************************************************/
174 static void vout_End( vout_thread_t *p_vout )
175 {
176     int i_index;
177
178     /* Free the fake output buffers we allocated */
179     for( i_index = I_OUTPUTPICTURES ; i_index ; )
180     {
181         i_index--;
182         free( PP_OUTPUTPICTURE[ i_index ]->p_data );
183     }
184 }
185
186 /*****************************************************************************
187  * vout_Destroy: destroy dummy video thread output method
188  *****************************************************************************
189  * Terminate an output method created by DummyCreateOutputMethod
190  *****************************************************************************/
191 static void vout_Destroy( vout_thread_t *p_vout )
192 {
193     free( p_vout->p_sys );
194 }
195
196 /*****************************************************************************
197  * vout_Manage: handle dummy events
198  *****************************************************************************
199  * This function should be called regularly by video output thread. It manages
200  * console events. It returns a non null value on error.
201  *****************************************************************************/
202 static int vout_Manage( vout_thread_t *p_vout )
203 {
204     return( 0 );
205 }
206
207 /*****************************************************************************
208  * vout_Render: render previously calculated output
209  *****************************************************************************/
210 static void vout_Render( vout_thread_t *p_vout, picture_t *p_pic )
211 {
212     /* No need to do anything, the fake direct buffers stay as they are */
213 }
214
215 /*****************************************************************************
216  * vout_Display: displays previously rendered output
217  *****************************************************************************/
218 static void vout_Display( vout_thread_t *p_vout, picture_t *p_pic )
219 {
220     /* No need to do anything, the fake direct buffers stay as they are */
221 }
222
223 /*****************************************************************************
224  * DummyNewPicture: allocate a picture
225  *****************************************************************************
226  * Returns 0 on success, -1 otherwise
227  *****************************************************************************/
228 static int DummyNewPicture( vout_thread_t *p_vout, picture_t *p_pic )
229 {
230     int i_width  = p_vout->output.i_width;
231     int i_height = p_vout->output.i_height;
232
233     switch( p_vout->output.i_chroma )
234     {
235     /* We know this chroma, allocate a buffer which will be used
236      * directly by the decoder */
237     case FOURCC_I420:
238     case FOURCC_IYUV:
239     case FOURCC_YV12:
240
241         /* Allocate the memory buffer */
242         p_pic->p_data = memalign( 16, i_width * i_height * 3 / 2 );
243
244         /* Y buffer */
245         p_pic->Y_PIXELS = p_pic->p_data;
246         p_pic->p[Y_PLANE].i_lines = i_height;
247         p_pic->p[Y_PLANE].i_pitch = i_width;
248         p_pic->p[Y_PLANE].i_pixel_bytes = 1;
249         p_pic->p[Y_PLANE].b_margin = 0;
250
251         /* U buffer */
252         p_pic->U_PIXELS = p_pic->Y_PIXELS + i_height * i_width;
253         p_pic->p[U_PLANE].i_lines = i_height / 2;
254         p_pic->p[U_PLANE].i_pitch = i_width / 2;
255         p_pic->p[U_PLANE].i_pixel_bytes = 1;
256         p_pic->p[U_PLANE].b_margin = 0;
257
258         /* V buffer */
259         p_pic->V_PIXELS = p_pic->U_PIXELS + i_height * i_width / 4;
260         p_pic->p[V_PLANE].i_lines = i_height / 2;
261         p_pic->p[V_PLANE].i_pitch = i_width / 2;
262         p_pic->p[V_PLANE].i_pixel_bytes = 1;
263         p_pic->p[V_PLANE].b_margin = 0;
264
265         /* We allocated 3 planes */
266         p_pic->i_planes = 3;
267
268         return( 0 );
269         break;
270
271     /* Unknown chroma, allocate an RGB buffer, the video output's job
272      * will be to do the chroma->RGB conversion */
273     case FOURCC_RV16:
274
275         /* Allocate the memory buffer */
276         p_pic->p_data = memalign( 16, i_width * i_height * 2 );
277
278         /* Fill important structures */
279         p_pic->p->p_pixels = p_pic->p_data;
280         p_pic->p->i_lines = i_height;
281         p_pic->p->i_pitch = i_width;
282         p_pic->p->i_pixel_bytes = 2;
283         p_pic->p->b_margin = 0;
284         p_pic->p->i_red_mask   = 0xf800;
285         p_pic->p->i_green_mask = 0x07e0;
286         p_pic->p->i_blue_mask  = 0x001f;
287
288         /* We allocated 1 plane */
289         p_pic->i_planes = 1;
290
291         return( 0 );
292         break;
293
294     default:
295         p_pic->i_planes = 0;
296         return( 0 );
297         break;
298     }
299 }
300