]> git.sesse.net Git - vlc/blob - modules/misc/stats/vout.c
Merge branch 1.0-bugfix
[vlc] / modules / misc / stats / vout.c
1 /*****************************************************************************
2  * vout.c: video output display for stats purpose
3  *****************************************************************************
4  * Copyright (C) 2000-2008 the VideoLAN team
5  *
6  * Authors: Samuel Hocevar <sam@zoy.org>
7  *          Pierre d'Herbemont <pdherbemont@videolan.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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
31
32 #include <vlc_common.h>
33 #include <vlc_vout.h>
34
35 #define DUMMY_WIDTH 16
36 #define DUMMY_HEIGHT 16
37 #define DUMMY_MAX_DIRECTBUFFERS 10
38
39 #include "stats.h"
40
41 /*****************************************************************************
42  * Local prototypes
43  *****************************************************************************/
44 static int  Init       ( vout_thread_t * );
45 static void End        ( vout_thread_t * );
46 static int  Manage     ( vout_thread_t * );
47 static void Render     ( vout_thread_t *, picture_t * );
48 static void Display    ( vout_thread_t *, picture_t * );
49 static void SetPalette ( vout_thread_t *, uint16_t *, uint16_t *, uint16_t * );
50 static int  Control   ( vout_thread_t *, int, va_list );
51
52 /*****************************************************************************
53  * OpenVideo: activates dummy video thread output method
54  *****************************************************************************
55  * This function initializes a dummy vout method.
56  *****************************************************************************/
57 int OpenVideo ( vlc_object_t *p_this )
58 {
59     vout_thread_t * p_vout = (vout_thread_t *)p_this;
60
61     p_vout->pf_init = Init;
62     p_vout->pf_end = End;
63     p_vout->pf_manage = Manage;
64     p_vout->pf_render = Render;
65     p_vout->pf_display = Display;
66     p_vout->pf_control = Control;
67
68     return VLC_SUCCESS;
69 }
70
71 /*****************************************************************************
72  * Control: control facility for the vout
73  *****************************************************************************/
74 static int Control( vout_thread_t *p_vout, int i_query, va_list args )
75 {
76     (void) p_vout; (void) i_query; (void) args;
77     return VLC_EGENERIC;
78 }
79
80
81 /*****************************************************************************
82  * Init: initialize dummy video thread output method
83  *****************************************************************************/
84 static int Init( vout_thread_t *p_vout )
85 {
86     int i_index, i_chroma;
87     char *psz_chroma;
88     picture_t *p_pic;
89     bool b_chroma = 0;
90
91     psz_chroma = config_GetPsz( p_vout, "dummy-chroma" );
92     if( psz_chroma )
93     {
94         if( strlen( psz_chroma ) >= 4 )
95         {
96             i_chroma = VLC_FOURCC( psz_chroma[0], psz_chroma[1],
97                                    psz_chroma[2], psz_chroma[3] );
98             b_chroma = 1;
99         }
100
101         free( psz_chroma );
102     }
103
104     I_OUTPUTPICTURES = 0;
105
106     /* Initialize the output structure */
107     if( b_chroma )
108     {
109         msg_Dbg( p_vout, "forcing chroma 0x%.8x (%4.4s)",
110                          i_chroma, (char*)&i_chroma );
111         p_vout->output.i_chroma = i_chroma;
112         if ( i_chroma == VLC_CODEC_RGB8 )
113         {
114             p_vout->output.pf_setpalette = SetPalette;
115         }
116         p_vout->output.i_width  = p_vout->render.i_width;
117         p_vout->output.i_height = p_vout->render.i_height;
118         p_vout->output.i_aspect = p_vout->render.i_aspect;
119     }
120     else
121     {
122         /* Use same chroma as input */
123         p_vout->output.i_chroma = p_vout->render.i_chroma;
124         p_vout->output.i_rmask  = p_vout->render.i_rmask;
125         p_vout->output.i_gmask  = p_vout->render.i_gmask;
126         p_vout->output.i_bmask  = p_vout->render.i_bmask;
127         p_vout->output.i_width  = p_vout->render.i_width;
128         p_vout->output.i_height = p_vout->render.i_height;
129         p_vout->output.i_aspect = p_vout->render.i_aspect;
130     }
131
132     /* Try to initialize DUMMY_MAX_DIRECTBUFFERS direct buffers */
133     while( I_OUTPUTPICTURES < DUMMY_MAX_DIRECTBUFFERS )
134     {
135         p_pic = NULL;
136
137         /* Find an empty picture slot */
138         for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
139         {
140             if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
141             {
142                 p_pic = p_vout->p_picture + i_index;
143                 break;
144             }
145         }
146
147         /* Allocate the picture */
148         if( p_pic == NULL )
149         {
150             break;
151         }
152
153         vout_AllocatePicture( VLC_OBJECT(p_vout), p_pic, p_vout->output.i_chroma,
154                               p_vout->output.i_width, p_vout->output.i_height,
155                               p_vout->output.i_aspect );
156
157         if( p_pic->i_planes == 0 )
158         {
159             break;
160         }
161
162         p_pic->i_status = DESTROYED_PICTURE;
163         p_pic->i_type   = DIRECT_PICTURE;
164
165         PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
166
167         I_OUTPUTPICTURES++;
168     }
169
170     return( 0 );
171 }
172
173 /*****************************************************************************
174  * End: terminate dummy video thread output method
175  *****************************************************************************/
176 static void End( vout_thread_t *p_vout )
177 {
178     int i_index;
179
180     /* Free the fake output buffers we allocated */
181     for( i_index = I_OUTPUTPICTURES ; i_index ; )
182     {
183         i_index--;
184         free( PP_OUTPUTPICTURE[ i_index ]->p_data_orig );
185     }
186 }
187
188 /*****************************************************************************
189  * Manage: handle dummy events
190  *****************************************************************************
191  * This function should be called regularly by video output thread. It manages
192  * console events. It returns a non null value on error.
193  *****************************************************************************/
194 static int Manage( vout_thread_t *p_vout )
195 {
196     VLC_UNUSED(p_vout);
197     return( 0 );
198 }
199
200 /*****************************************************************************
201  * Render: render previously calculated output
202  *****************************************************************************/
203 static void Render( vout_thread_t *p_vout, picture_t *p_pic )
204 {
205     VLC_UNUSED(p_vout); VLC_UNUSED(p_pic);
206     /* No need to do anything, the fake direct buffers stay as they are */
207 }
208
209 /*****************************************************************************
210  * Display: displays previously rendered output
211  *****************************************************************************/
212 static void Display( vout_thread_t *p_vout, picture_t *p_pic )
213 {
214     msg_Dbg( p_vout, "VOUT got %"PRIu64" ms offset",
215              (mdate() - *(mtime_t *)p_pic->p->p_pixels) / 1000 );
216
217     /* No need to do anything, the fake direct buffers stay as they are */
218 }
219
220 /*****************************************************************************
221  * SetPalette: set the palette for the picture
222  *****************************************************************************/
223 static void SetPalette ( vout_thread_t *p_vout,
224                          uint16_t *red, uint16_t *green, uint16_t *blue )
225 {
226     VLC_UNUSED(p_vout); VLC_UNUSED(red); VLC_UNUSED(green); VLC_UNUSED(blue);
227     /* No need to do anything, the fake direct buffers stay as they are */
228 }