]> git.sesse.net Git - vlc/blob - modules/misc/dummy/vout.c
* ./modules/*: moved plugins to the new tree. Yet untested builds include
[vlc] / modules / misc / dummy / vout.c
1 /*****************************************************************************
2  * vout_dummy.c: Dummy video output display method for testing purposes
3  *****************************************************************************
4  * Copyright (C) 2000, 2001 VideoLAN
5  * $Id: vout.c,v 1.1 2002/08/04 17:23:43 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  * Local prototypes
40  *****************************************************************************/
41 static int  Init      ( vout_thread_t * );
42 static void End       ( vout_thread_t * );
43 static int  Manage    ( vout_thread_t * );
44 static void Render    ( vout_thread_t *, picture_t * );
45 static void Display   ( vout_thread_t *, picture_t * );
46
47 /*****************************************************************************
48  * OpenVideo: activates dummy video thread output method
49  *****************************************************************************
50  * This function initializes a dummy vout method.
51  *****************************************************************************/
52 int E_(OpenVideo) ( vlc_object_t *p_this )
53 {
54     vout_thread_t * p_vout = (vout_thread_t *)p_this;
55
56     p_vout->pf_init = Init;
57     p_vout->pf_end = End;
58     p_vout->pf_manage = Manage;
59     p_vout->pf_render = Render;
60     p_vout->pf_display = Display;
61
62     return VLC_SUCCESS;
63 }
64
65 /*****************************************************************************
66  * Init: initialize dummy video thread output method
67  *****************************************************************************/
68 static int Init( vout_thread_t *p_vout )
69 {
70     int i_index, i_chroma;
71     char *psz_chroma;
72     picture_t *p_pic;
73     vlc_bool_t b_chroma = 0;
74
75     psz_chroma = config_GetPsz( p_vout, "dummy-chroma" );
76     if( psz_chroma )
77     {
78         if( strlen( psz_chroma ) >= 4 )
79         {
80             i_chroma  = (unsigned char)psz_chroma[0] <<  0;
81             i_chroma |= (unsigned char)psz_chroma[1] <<  8;
82             i_chroma |= (unsigned char)psz_chroma[2] << 16;
83             i_chroma |= (unsigned char)psz_chroma[3] << 24;
84
85             b_chroma = 1;
86         }
87
88         free( psz_chroma );
89     }
90
91     I_OUTPUTPICTURES = 0;
92
93     /* Initialize the output structure */
94     if( b_chroma )
95     {
96         msg_Dbg( p_vout, "forcing chroma 0x%.8x (%4.4s)",
97                          i_chroma, (char*)&i_chroma );
98         p_vout->output.i_chroma = i_chroma;
99         p_vout->output.i_width  = p_vout->render.i_width;
100         p_vout->output.i_height = p_vout->render.i_height;
101         p_vout->output.i_aspect = p_vout->render.i_aspect;
102     }
103     else
104     {
105         p_vout->output.i_chroma = VLC_FOURCC('R','V','1','6');
106         p_vout->output.i_rmask  = 0xf800;
107         p_vout->output.i_gmask  = 0x07e0;
108         p_vout->output.i_bmask  = 0x001f;
109         p_vout->output.i_width  = p_vout->render.i_width;
110         p_vout->output.i_height = p_vout->render.i_height;
111         p_vout->output.i_aspect = p_vout->render.i_aspect;
112     }
113
114     /* Try to initialize DUMMY_MAX_DIRECTBUFFERS direct buffers */
115     while( I_OUTPUTPICTURES < DUMMY_MAX_DIRECTBUFFERS )
116     {
117         p_pic = NULL;
118
119         /* Find an empty picture slot */
120         for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
121         {
122             if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
123             {
124                 p_pic = p_vout->p_picture + i_index;
125                 break;
126             }
127         }
128
129         /* Allocate the picture */
130         if( p_pic == NULL )
131         {
132             break;
133         }
134
135         vout_AllocatePicture( p_vout, p_pic, p_vout->output.i_width,
136                               p_vout->output.i_height,
137                               p_vout->output.i_chroma );
138
139         if( p_pic->i_planes == 0 )
140         {
141             break;
142         }
143
144         p_pic->i_status = DESTROYED_PICTURE;
145         p_pic->i_type   = DIRECT_PICTURE;
146
147         PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
148
149         I_OUTPUTPICTURES++;
150     }
151
152     return( 0 );
153 }
154
155 /*****************************************************************************
156  * End: terminate dummy video thread output method
157  *****************************************************************************/
158 static void End( vout_thread_t *p_vout )
159 {
160     int i_index;
161
162     /* Free the fake output buffers we allocated */
163     for( i_index = I_OUTPUTPICTURES ; i_index ; )
164     {
165         i_index--;
166         free( PP_OUTPUTPICTURE[ i_index ]->p_data_orig );
167     }
168 }
169
170 /*****************************************************************************
171  * Manage: handle dummy events
172  *****************************************************************************
173  * This function should be called regularly by video output thread. It manages
174  * console events. It returns a non null value on error.
175  *****************************************************************************/
176 static int Manage( vout_thread_t *p_vout )
177 {
178     return( 0 );
179 }
180
181 /*****************************************************************************
182  * Render: render previously calculated output
183  *****************************************************************************/
184 static void Render( vout_thread_t *p_vout, picture_t *p_pic )
185 {
186     /* No need to do anything, the fake direct buffers stay as they are */
187 }
188
189 /*****************************************************************************
190  * Display: displays previously rendered output
191  *****************************************************************************/
192 static void Display( vout_thread_t *p_vout, picture_t *p_pic )
193 {
194     /* No need to do anything, the fake direct buffers stay as they are */
195 }
196