]> git.sesse.net Git - vlc/blob - plugins/sdl/sdl.c
4290febb09bda0bca61e030be9ea6456a1880e42
[vlc] / plugins / sdl / sdl.c
1 /*****************************************************************************
2  * sdl.c : SDL plugin for vlc
3  *****************************************************************************
4  * Copyright (C) 2000 VideoLAN
5  *
6  * Authors:
7  *      . Initial plugin code by Samuel Hocevar <sam@via.ecp.fr>
8  *      . Modified to use the SDL by Pierre Baillet <octplane@via.ecp.fr>
9  *      
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  * 
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
23  *****************************************************************************/
24
25 #define MODULE_NAME sdl
26
27 /*****************************************************************************
28  * Preamble
29  *****************************************************************************/
30 #include "defs.h"
31
32 #include <stdlib.h>                                      /* malloc(), free() */
33
34 #include "config.h"
35 #include "common.h"                                     /* boolean_t, byte_t */
36 #include "threads.h"
37 #include "mtime.h"
38 #include "tests.h"
39 #include "plugins.h"
40
41 #include "interface.h"
42 #include "audio_output.h"
43 #include "video.h"
44 #include "video_output.h"
45
46 /* audio includes */
47 #include "modules.h"
48 #include "modules_inner.h"
49
50 /*****************************************************************************
51  * Building configuration tree
52  *****************************************************************************/
53
54 MODULE_CONFIG_START
55 ADD_WINDOW( "Configuration for sdl module" )
56  ADD_COMMENT( "For now, the sdl module cannot be configured" )
57 MODULE_CONFIG_END
58
59
60
61 /*****************************************************************************
62  * Exported prototypes
63  *****************************************************************************/
64 static void vout_GetPlugin( p_vout_thread_t p_vout );
65 static void intf_GetPlugin( p_intf_thread_t p_intf );
66
67
68 /* Video output */
69 int     vout_SDLCreate       ( vout_thread_t *p_vout, char *psz_display,
70                                int i_root_window, void *p_data );
71 int     vout_SDLInit         ( p_vout_thread_t p_vout );
72 void    vout_SDLEnd          ( p_vout_thread_t p_vout );
73 void    vout_SDLDestroy      ( p_vout_thread_t p_vout );
74 int     vout_SDLManage       ( p_vout_thread_t p_vout );
75 void    vout_SDLDisplay      ( p_vout_thread_t p_vout );
76 void    vout_SDLSetPalette   ( p_vout_thread_t p_vout,
77                                u16 *red, u16 *green, u16 *blue, u16 *transp );
78 /* Interface */
79 int     intf_SDLCreate       ( p_intf_thread_t p_intf );
80 void    intf_SDLDestroy      ( p_intf_thread_t p_intf );
81 void    intf_SDLManage       ( p_intf_thread_t p_intf );
82
83
84 /*****************************************************************************
85  *  * Capabilities defined in the other files.
86  ******************************************************************************/
87 extern void aout_getfunctions( function_list_t * p_function_list );
88
89 /*****************************************************************************
90  * GetConfig: get the plugin structure and configuration
91  *****************************************************************************/
92 plugin_info_t * GetConfig( void )
93 {
94     plugin_info_t * p_info = (plugin_info_t *) malloc( sizeof(plugin_info_t) );
95
96     p_info->psz_name    = "SDL (video)";
97     p_info->psz_version = VERSION;
98     p_info->psz_author  = "the VideoLAN team <vlc@videolan.org>";
99
100     p_info->aout_GetPlugin = NULL;
101     p_info->vout_GetPlugin = vout_GetPlugin;
102     p_info->intf_GetPlugin = intf_GetPlugin;
103     p_info->yuv_GetPlugin = NULL;
104   
105     
106     /* if the SDL libraries are there, assume we can enter the
107      * initialization part at least, even if we fail afterwards */
108     
109     p_info->i_score = 0x100;
110     
111     /* If this plugin was requested, score it higher */
112     if( TestMethod( VOUT_METHOD_VAR, "sdl" ) )
113     {
114         p_info->i_score += 0x200;
115     }
116
117     return( p_info );
118 }
119
120 /*****************************************************************************
121  * Following functions are only called through the p_info structure
122  *****************************************************************************/
123
124 static void vout_GetPlugin( p_vout_thread_t p_vout )
125 {
126     p_vout->p_sys_create  = vout_SDLCreate;
127     p_vout->p_sys_init    = vout_SDLInit;
128     p_vout->p_sys_end     = vout_SDLEnd;
129     p_vout->p_sys_destroy = vout_SDLDestroy;
130     p_vout->p_sys_manage  = vout_SDLManage;
131     p_vout->p_sys_display = vout_SDLDisplay;
132     p_vout->p_set_palette = vout_SDLSetPalette;
133
134 }
135
136 static void intf_GetPlugin( p_intf_thread_t p_intf )
137 {
138     p_intf->p_sys_create  = intf_SDLCreate;
139     p_intf->p_sys_destroy = intf_SDLDestroy;
140     p_intf->p_sys_manage  = intf_SDLManage;
141 }
142
143 /*****************************************************************************
144  * Audio stuff:  All the new modules things
145  *****************************************************************************/
146
147 /*****************************************************************************
148  * InitModule: get the module structure and configuration.
149  *****************************************************************************
150  * We have to fill psz_name, psz_longname and psz_version. These variables
151  * will be strdup()ed later by the main application because the module can
152  * be unloaded later to save memory, and we want to be able to access this
153  * data even after the module has been unloaded.
154  *****************************************************************************/
155 int InitModule( module_t * p_module )
156 {
157     p_module->psz_name = MODULE_STRING;
158     p_module->psz_longname = "Linux SDL audio module";
159     p_module->psz_version = VERSION;
160
161     p_module->i_capabilities = MODULE_CAPABILITY_NULL
162                                 | MODULE_CAPABILITY_AOUT;
163
164     return( 0 );
165 }
166
167 /*****************************************************************************
168  * ActivateModule: set the module to an usable state.
169  *****************************************************************************
170  * This function fills the capability functions and the configuration
171  * structure. Once ActivateModule() has been called, the i_usage can
172  * be set to 0 and calls to NeedModule() be made to increment it. To unload
173  * the module, one has to wait until i_usage == 0 and call DeactivateModule().
174  *****************************************************************************/
175 int ActivateModule( module_t * p_module )
176 {
177     p_module->p_functions = malloc( sizeof( module_functions_t ) );
178     if( p_module->p_functions == NULL )
179     {
180         return( -1 );
181     }
182
183     aout_getfunctions( &p_module->p_functions->aout );
184
185     p_module->p_config = p_config;
186
187     return( 0 );
188 }
189
190 /*****************************************************************************
191  * DeactivateModule: make sure the module can be unloaded.
192  *****************************************************************************
193  * This function must only be called when i_usage == 0. If it successfully
194  * returns, i_usage can be set to -1 and the module unloaded. Be careful to
195  * lock usage_lock during the whole process.
196  *****************************************************************************/
197 int DeactivateModule( module_t * p_module )
198 {
199     free( p_module->p_functions );
200
201     return( 0 );
202 }
203