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