]> git.sesse.net Git - vlc/blob - plugins/dummy/vout_dummy.c
6656120f99a8e92c8b1050a53cab2c3eadef7e4f
[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.14 2002/01/02 14:37: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 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_Display   ( struct vout_thread_s *, struct picture_s * );
62
63 static int  DummyNewPicture( struct vout_thread_s *, struct picture_s * );
64
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 )
70 {
71     p_function_list->pf_probe = vout_Probe;
72     p_function_list->functions.vout.pf_create     = vout_Create;
73     p_function_list->functions.vout.pf_init       = vout_Init;
74     p_function_list->functions.vout.pf_end        = vout_End;
75     p_function_list->functions.vout.pf_destroy    = vout_Destroy;
76     p_function_list->functions.vout.pf_manage     = vout_Manage;
77     p_function_list->functions.vout.pf_display    = vout_Display;
78     p_function_list->functions.vout.pf_setpalette = NULL;
79 }
80
81 /*****************************************************************************
82  * intf_Probe: return a score
83  *****************************************************************************/
84 static int vout_Probe( probedata_t *p_data )
85 {
86     return( 1 );
87 }
88
89 /*****************************************************************************
90  * vout_Create: allocates dummy video thread output method
91  *****************************************************************************
92  * This function allocates and initializes a dummy vout method.
93  *****************************************************************************/
94 static int vout_Create( vout_thread_t *p_vout )
95 {
96     /* Allocate structure */
97     p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
98     if( p_vout->p_sys == NULL )
99     {
100         intf_ErrMsg("error: %s", strerror(ENOMEM) );
101         return( 1 );
102     }
103
104     return( 0 );
105 }
106
107 /*****************************************************************************
108  * vout_Init: initialize dummy video thread output method
109  *****************************************************************************/
110 static int vout_Init( vout_thread_t *p_vout )
111 {
112     int i_index;
113     picture_t *p_pic;
114     
115     I_OUTPUTPICTURES = 0;
116
117     /* Initialize the output structure */
118     switch( p_vout->render.i_chroma )
119     {
120         case FOURCC_I420:
121         case FOURCC_IYUV:
122         case FOURCC_YV12:
123             p_vout->output.i_chroma = p_vout->render.i_chroma;
124             p_vout->output.i_width  = p_vout->render.i_width;
125             p_vout->output.i_height = p_vout->render.i_height;
126             p_vout->output.i_aspect = p_vout->render.i_aspect;
127             break;
128
129         default:
130             p_vout->output.i_chroma = FOURCC_BI_BITFIELDS | DEPTH_16BPP;
131             p_vout->output.i_width  = p_vout->render.i_width;
132             p_vout->output.i_height = p_vout->render.i_height;
133             p_vout->output.i_aspect = p_vout->render.i_aspect;
134             break;
135     }
136
137     /* Try to initialize DUMMY_MAX_DIRECTBUFFERS direct buffers */
138     while( I_OUTPUTPICTURES < DUMMY_MAX_DIRECTBUFFERS )
139     {
140         p_pic = NULL;
141
142         /* Find an empty picture slot */
143         for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
144         {
145             if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
146             {
147                 p_pic = p_vout->p_picture + i_index;
148                 break;
149             }
150         }
151
152         /* Allocate the picture */
153         if( p_pic == NULL || DummyNewPicture( p_vout, p_pic ) )
154         {
155             break;
156         }
157
158         p_pic->i_status        = DESTROYED_PICTURE;
159         p_pic->i_type          = DIRECT_PICTURE;
160
161         p_pic->i_left_margin   =
162         p_pic->i_right_margin  =
163         p_pic->i_top_margin    =
164         p_pic->i_bottom_margin = 0;
165
166         PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
167
168         I_OUTPUTPICTURES++;
169     }
170
171     return( 0 );
172 }
173
174 /*****************************************************************************
175  * vout_End: terminate dummy video thread output method
176  *****************************************************************************/
177 static void vout_End( vout_thread_t *p_vout )
178 {
179     int i_index;
180
181     /* Free the fake output buffers we allocated */
182     for( i_index = I_OUTPUTPICTURES ; i_index ; )
183     {
184         i_index--;
185         free( PP_OUTPUTPICTURE[ i_index ]->planes[ 0 ].p_data );
186     }
187 }
188
189 /*****************************************************************************
190  * vout_Destroy: destroy dummy video thread output method
191  *****************************************************************************
192  * Terminate an output method created by DummyCreateOutputMethod
193  *****************************************************************************/
194 static void vout_Destroy( vout_thread_t *p_vout )
195 {
196     free( p_vout->p_sys );
197 }
198
199 /*****************************************************************************
200  * vout_Manage: handle dummy events
201  *****************************************************************************
202  * This function should be called regularly by video output thread. It manages
203  * console events. It returns a non null value on error.
204  *****************************************************************************/
205 static int vout_Manage( vout_thread_t *p_vout )
206 {
207     return( 0 );
208 }
209
210 /*****************************************************************************
211  * vout_Display: displays previously rendered output
212  *****************************************************************************
213  * This function send the currently rendered image to dummy image, waits until
214  * it is displayed and switch the two rendering buffers, preparing next frame.
215  *****************************************************************************/
216 static void vout_Display( vout_thread_t *p_vout, picture_t *p_pic )
217 {
218     /* No need to do anything, the fake direct buffers stay as they are */
219 }
220
221
222 /*****************************************************************************
223  * DummyNewPicture: allocate a picture
224  *****************************************************************************
225  * Returns 0 on success, -1 otherwise
226  *****************************************************************************/
227 static int DummyNewPicture( vout_thread_t *p_vout, picture_t *p_pic )
228 {
229     int i_luma_bytes, i_chroma_bytes;
230
231     int i_width  = p_vout->output.i_width;
232     int i_height = p_vout->output.i_height;
233
234     switch( p_vout->output.i_chroma )
235     {
236     /* We know this chroma, allocate a buffer which will be used
237      * directly by the decoder */
238     case FOURCC_I420:
239     case FOURCC_IYUV:
240     case FOURCC_YV12:
241
242         /* Allocate the memory buffer */
243         i_luma_bytes = i_width * i_height * sizeof(pixel_data_t);
244         i_chroma_bytes = i_width * ( i_height / 2 ) * sizeof(pixel_data_t);
245
246         /* Y buffer */
247         p_pic->P_Y = malloc( i_luma_bytes + 2 * i_chroma_bytes );
248         p_pic->planes[ Y_PLANE ].i_bytes = i_luma_bytes;
249         p_pic->planes[ Y_PLANE ].i_line_bytes = i_width * sizeof(pixel_data_t);
250
251         /* U buffer */
252         p_pic->P_U = p_pic->P_Y + i_height * i_width;
253         p_pic->planes[ U_PLANE ].i_bytes = i_chroma_bytes / 2;
254         p_pic->planes[ U_PLANE ].i_line_bytes = i_width / 2 * sizeof(pixel_data_t);
255
256         /* V buffer */
257         p_pic->P_V = p_pic->P_U + i_height * i_width / 2;
258         p_pic->planes[ V_PLANE ].i_bytes = i_chroma_bytes / 2;
259         p_pic->planes[ V_PLANE ].i_line_bytes = i_width / 2 * sizeof(pixel_data_t);
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_BI_BITFIELDS | DEPTH_16BPP:
270
271         /* Precalculate some values */
272         i_luma_bytes = sizeof(u16) * i_width * i_height;
273
274         /* Allocate the memory buffer */
275         p_pic->P_MAIN = malloc( i_luma_bytes );
276         p_pic->planes[ MAIN_PLANE ].i_bytes = i_luma_bytes;
277
278         /* Fill important structures */
279         p_pic->planes[ MAIN_PLANE ].i_red_mask   = 0xf800;
280         p_pic->planes[ MAIN_PLANE ].i_green_mask = 0x07e0;
281         p_pic->planes[ MAIN_PLANE ].i_blue_mask  = 0x001f;
282
283         /* We allocated 1 plane */
284         p_pic->i_planes = 1;
285
286         return( 0 );
287         break;
288
289     default:
290         p_pic->i_planes = 0;
291         return( 0 );
292         break;
293     }
294 }
295