]> git.sesse.net Git - vlc/blob - plugins/dummy/vout_dummy.c
* ALL: the first libvlc commit.
[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.24 2002/06/01 12:31:58 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 <vlc/vlc.h>
32 #include <vlc/vout.h>
33
34 #define DUMMY_WIDTH 16
35 #define DUMMY_HEIGHT 16
36 #define DUMMY_MAX_DIRECTBUFFERS 10
37
38 /*****************************************************************************
39  * vout_sys_t: dummy video output method descriptor
40  *****************************************************************************
41  * This structure is part of the video output thread descriptor.
42  * It describes the dummy specific properties of an output thread.
43  *****************************************************************************/
44 struct vout_sys_s
45 {
46     /* Nothing needed here. Maybe stats ? */
47
48     /* Prevent malloc(0) */
49     int i_dummy;
50 };
51
52 /*****************************************************************************
53  * Local prototypes
54  *****************************************************************************/
55 static int  vout_Create    ( vout_thread_t * );
56 static int  vout_Init      ( vout_thread_t * );
57 static void vout_End       ( vout_thread_t * );
58 static void vout_Destroy   ( vout_thread_t * );
59 static int  vout_Manage    ( vout_thread_t * );
60 static void vout_Render    ( vout_thread_t *, picture_t * );
61 static void vout_Display   ( vout_thread_t *, picture_t * );
62
63 /*****************************************************************************
64  * Functions exported as capabilities. They are declared as static so that
65  * we don't pollute the namespace too much.
66  *****************************************************************************/
67 void _M( vout_getfunctions )( function_list_t * p_function_list )
68 {
69     p_function_list->functions.vout.pf_create     = vout_Create;
70     p_function_list->functions.vout.pf_init       = vout_Init;
71     p_function_list->functions.vout.pf_end        = vout_End;
72     p_function_list->functions.vout.pf_destroy    = vout_Destroy;
73     p_function_list->functions.vout.pf_manage     = vout_Manage;
74     p_function_list->functions.vout.pf_render     = vout_Render;
75     p_function_list->functions.vout.pf_display    = vout_Display;
76 }
77
78 /*****************************************************************************
79  * vout_Create: allocates dummy video thread output method
80  *****************************************************************************
81  * This function allocates and initializes a dummy vout method.
82  *****************************************************************************/
83 static int vout_Create( vout_thread_t *p_vout )
84 {
85     /* Allocate structure */
86     p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
87     if( p_vout->p_sys == NULL )
88     {
89         msg_Err( p_vout, "out of memory" );
90         return( 1 );
91     }
92
93     return( 0 );
94 }
95
96 /*****************************************************************************
97  * vout_Init: initialize dummy video thread output method
98  *****************************************************************************/
99 static int vout_Init( vout_thread_t *p_vout )
100 {
101     int i_index, i_chroma;
102     char *psz_chroma;
103     picture_t *p_pic;
104     vlc_bool_t b_chroma = 0;
105
106     psz_chroma = config_GetPsz( p_vout, "dummy-chroma" );
107     if( psz_chroma )
108     {
109         if( strlen( psz_chroma ) >= 4 )
110         {
111             i_chroma  = (unsigned char)psz_chroma[0] <<  0;
112             i_chroma |= (unsigned char)psz_chroma[1] <<  8;
113             i_chroma |= (unsigned char)psz_chroma[2] << 16;
114             i_chroma |= (unsigned char)psz_chroma[3] << 24;
115
116             b_chroma = 1;
117         }
118
119         free( psz_chroma );
120     }
121
122     I_OUTPUTPICTURES = 0;
123
124     /* Initialize the output structure */
125     if( b_chroma )
126     {
127         msg_Dbg( p_vout, "forcing chroma 0x%.8x (%4.4s)",
128                          i_chroma, (char*)&i_chroma );
129         p_vout->output.i_chroma = i_chroma;
130         p_vout->output.i_width  = p_vout->render.i_width;
131         p_vout->output.i_height = p_vout->render.i_height;
132         p_vout->output.i_aspect = p_vout->render.i_aspect;
133     }
134     else
135     {
136         p_vout->output.i_chroma = FOURCC_RV16;
137         p_vout->output.i_rmask  = 0xf800;
138         p_vout->output.i_gmask  = 0x07e0;
139         p_vout->output.i_bmask  = 0x001f;
140         p_vout->output.i_width  = p_vout->render.i_width;
141         p_vout->output.i_height = p_vout->render.i_height;
142         p_vout->output.i_aspect = p_vout->render.i_aspect;
143     }
144
145     /* Try to initialize DUMMY_MAX_DIRECTBUFFERS direct buffers */
146     while( I_OUTPUTPICTURES < DUMMY_MAX_DIRECTBUFFERS )
147     {
148         p_pic = NULL;
149
150         /* Find an empty picture slot */
151         for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
152         {
153             if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
154             {
155                 p_pic = p_vout->p_picture + i_index;
156                 break;
157             }
158         }
159
160         /* Allocate the picture */
161         if( p_pic == NULL )
162         {
163             break;
164         }
165
166         vout_AllocatePicture( p_vout, p_pic, p_vout->output.i_width,
167                               p_vout->output.i_height,
168                               p_vout->output.i_chroma );
169
170         if( p_pic->i_planes == 0 )
171         {
172             break;
173         }
174
175         p_pic->i_status = DESTROYED_PICTURE;
176         p_pic->i_type   = DIRECT_PICTURE;
177
178         PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
179
180         I_OUTPUTPICTURES++;
181     }
182
183     return( 0 );
184 }
185
186 /*****************************************************************************
187  * vout_End: terminate dummy video thread output method
188  *****************************************************************************/
189 static void vout_End( vout_thread_t *p_vout )
190 {
191     int i_index;
192
193     /* Free the fake output buffers we allocated */
194     for( i_index = I_OUTPUTPICTURES ; i_index ; )
195     {
196         i_index--;
197         free( PP_OUTPUTPICTURE[ i_index ]->p_data_orig );
198     }
199 }
200
201 /*****************************************************************************
202  * vout_Destroy: destroy dummy video thread output method
203  *****************************************************************************
204  * Terminate an output method created by DummyCreateOutputMethod
205  *****************************************************************************/
206 static void vout_Destroy( vout_thread_t *p_vout )
207 {
208     free( p_vout->p_sys );
209 }
210
211 /*****************************************************************************
212  * vout_Manage: handle dummy events
213  *****************************************************************************
214  * This function should be called regularly by video output thread. It manages
215  * console events. It returns a non null value on error.
216  *****************************************************************************/
217 static int vout_Manage( vout_thread_t *p_vout )
218 {
219     return( 0 );
220 }
221
222 /*****************************************************************************
223  * vout_Render: render previously calculated output
224  *****************************************************************************/
225 static void vout_Render( vout_thread_t *p_vout, picture_t *p_pic )
226 {
227     /* No need to do anything, the fake direct buffers stay as they are */
228 }
229
230 /*****************************************************************************
231  * vout_Display: displays previously rendered output
232  *****************************************************************************/
233 static void vout_Display( vout_thread_t *p_vout, picture_t *p_pic )
234 {
235     /* No need to do anything, the fake direct buffers stay as they are */
236 }
237