]> git.sesse.net Git - vlc/blob - plugins/dummy/vout_dummy.c
* ./plugins/dummy/dummy.c: added --dummy-chroma option.
[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.23 2002/05/20 19:02:22 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 /*****************************************************************************
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->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_render     = vout_Render;
78     p_function_list->functions.vout.pf_display    = vout_Display;
79 }
80
81 /*****************************************************************************
82  * vout_Create: allocates dummy video thread output method
83  *****************************************************************************
84  * This function allocates and initializes a dummy vout method.
85  *****************************************************************************/
86 static int vout_Create( vout_thread_t *p_vout )
87 {
88     /* Allocate structure */
89     p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
90     if( p_vout->p_sys == NULL )
91     {
92         intf_ErrMsg("error: %s", strerror(ENOMEM) );
93         return( 1 );
94     }
95
96     return( 0 );
97 }
98
99 /*****************************************************************************
100  * vout_Init: initialize dummy video thread output method
101  *****************************************************************************/
102 static int vout_Init( vout_thread_t *p_vout )
103 {
104     int i_index, i_chroma;
105     char *psz_chroma;
106     picture_t *p_pic;
107     boolean_t b_chroma = 0;
108
109     psz_chroma = config_GetPszVariable( "dummy-chroma" );
110     if( psz_chroma )
111     {
112         if( strlen( psz_chroma ) >= 4 )
113         {
114             i_chroma  = (unsigned char)psz_chroma[0] <<  0;
115             i_chroma |= (unsigned char)psz_chroma[1] <<  8;
116             i_chroma |= (unsigned char)psz_chroma[2] << 16;
117             i_chroma |= (unsigned char)psz_chroma[3] << 24;
118
119             b_chroma = 1;
120         }
121
122         free( psz_chroma );
123     }
124
125     I_OUTPUTPICTURES = 0;
126
127     /* Initialize the output structure */
128     if( b_chroma )
129     {
130         intf_WarnMsg( 3, "vout info: forcing chroma 0x%.8x (%4.4s)",
131                          i_chroma, (char*)&i_chroma );
132         p_vout->output.i_chroma = i_chroma;
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     }
137     else
138     {
139         p_vout->output.i_chroma = FOURCC_RV16;
140         p_vout->output.i_rmask  = 0xf800;
141         p_vout->output.i_gmask  = 0x07e0;
142         p_vout->output.i_bmask  = 0x001f;
143         p_vout->output.i_width  = p_vout->render.i_width;
144         p_vout->output.i_height = p_vout->render.i_height;
145         p_vout->output.i_aspect = p_vout->render.i_aspect;
146     }
147
148     /* Try to initialize DUMMY_MAX_DIRECTBUFFERS direct buffers */
149     while( I_OUTPUTPICTURES < DUMMY_MAX_DIRECTBUFFERS )
150     {
151         p_pic = NULL;
152
153         /* Find an empty picture slot */
154         for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
155         {
156             if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
157             {
158                 p_pic = p_vout->p_picture + i_index;
159                 break;
160             }
161         }
162
163         /* Allocate the picture */
164         if( p_pic == NULL )
165         {
166             break;
167         }
168
169         vout_AllocatePicture( p_pic, p_vout->output.i_width,
170                                      p_vout->output.i_height,
171                                      p_vout->output.i_chroma );
172
173         if( p_pic->i_planes == 0 )
174         {
175             break;
176         }
177
178         p_pic->i_status = DESTROYED_PICTURE;
179         p_pic->i_type   = DIRECT_PICTURE;
180
181         PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
182
183         I_OUTPUTPICTURES++;
184     }
185
186     return( 0 );
187 }
188
189 /*****************************************************************************
190  * vout_End: terminate dummy video thread output method
191  *****************************************************************************/
192 static void vout_End( vout_thread_t *p_vout )
193 {
194     int i_index;
195
196     /* Free the fake output buffers we allocated */
197     for( i_index = I_OUTPUTPICTURES ; i_index ; )
198     {
199         i_index--;
200         free( PP_OUTPUTPICTURE[ i_index ]->p_data_orig );
201     }
202 }
203
204 /*****************************************************************************
205  * vout_Destroy: destroy dummy video thread output method
206  *****************************************************************************
207  * Terminate an output method created by DummyCreateOutputMethod
208  *****************************************************************************/
209 static void vout_Destroy( vout_thread_t *p_vout )
210 {
211     free( p_vout->p_sys );
212 }
213
214 /*****************************************************************************
215  * vout_Manage: handle dummy events
216  *****************************************************************************
217  * This function should be called regularly by video output thread. It manages
218  * console events. It returns a non null value on error.
219  *****************************************************************************/
220 static int vout_Manage( vout_thread_t *p_vout )
221 {
222     return( 0 );
223 }
224
225 /*****************************************************************************
226  * vout_Render: render previously calculated output
227  *****************************************************************************/
228 static void vout_Render( vout_thread_t *p_vout, picture_t *p_pic )
229 {
230     /* No need to do anything, the fake direct buffers stay as they are */
231 }
232
233 /*****************************************************************************
234  * vout_Display: displays previously rendered output
235  *****************************************************************************/
236 static void vout_Display( vout_thread_t *p_vout, picture_t *p_pic )
237 {
238     /* No need to do anything, the fake direct buffers stay as they are */
239 }
240