]> git.sesse.net Git - vlc/blob - src/misc/modules_plugin.h
* include/common.h and input_ext-plugins.h, src/misc/modules_plugin.h : export...
[vlc] / src / misc / modules_plugin.h
1 /*****************************************************************************
2  * modules_plugin.h : Plugin management functions used by the core application.
3  *****************************************************************************
4  * Copyright (C) 2001 VideoLAN
5  * $Id: modules_plugin.h,v 1.25 2002/05/10 02:04:17 fenrir 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  * Inline functions for handling dynamic modules
26  *****************************************************************************/
27
28 /*****************************************************************************
29  * module_load: load a dynamic library
30  *****************************************************************************
31  * This function loads a dynamically linked library using a system dependant
32  * method, and returns a non-zero value on error, zero otherwise.
33  *****************************************************************************/
34 static __inline__ int
35 module_load( char * psz_filename, module_handle_t * handle )
36 {
37 #ifdef SYS_BEOS
38     *handle = load_add_on( psz_filename );
39     return( *handle < 0 );
40
41 #elif defined(WIN32)
42     *handle = LoadLibrary( psz_filename );
43     return( *handle == NULL ); 
44
45 #elif defined(RTLD_NOW)
46 #   if defined(SYS_LINUX)
47     /* We should NOT open modules with RTLD_GLOBAL, or we are going to get
48      * namespace collisions when two modules have common public symbols,
49      * but ALSA is being a pest here. */
50     if( strstr( psz_filename, "alsa.so" ) )
51     {
52         *handle = dlopen( psz_filename, RTLD_NOW | RTLD_GLOBAL );
53         return( *handle == NULL );
54     }
55 #   endif
56     *handle = dlopen( psz_filename, RTLD_NOW );
57     return( *handle == NULL );
58
59 #else
60     *handle = dlopen( psz_filename, DL_LAZY );
61     return( *handle == NULL );
62
63 #endif
64 }
65
66 /*****************************************************************************
67  * module_unload: unload a dynamic library
68  *****************************************************************************
69  * This function unloads a previously opened dynamically linked library
70  * using a system dependant method. No return value is taken in consideration,
71  * since some libraries sometimes refuse to close properly.
72  *****************************************************************************/
73 static __inline__ void
74 module_unload( module_handle_t handle )
75 {
76 #ifdef SYS_BEOS
77     unload_add_on( handle );
78
79 #elif defined(WIN32)
80     FreeLibrary( handle );
81
82 #else
83     dlclose( handle );
84
85 #endif
86     return;
87 }
88
89 /*****************************************************************************
90  * module_getsymbol: get a symbol from a dynamic library
91  *****************************************************************************
92  * This function queries a loaded library for a symbol specified in a
93  * string, and returns a pointer to it. We don't check for dlerror() or
94  * similar functions, since we want a non-NULL symbol anyway.
95  *****************************************************************************/
96 static __inline__ void *
97 module_getsymbol_inner( module_handle_t handle, char * psz_function )
98 {
99 #ifdef SYS_BEOS
100     void * p_symbol;
101     if( B_OK == get_image_symbol( handle, psz_function,
102                                   B_SYMBOL_TYPE_TEXT, &p_symbol ) )
103     {
104         return( p_symbol );
105     }
106     else
107     {
108         return( NULL );
109     }
110
111 #elif defined(WIN32)
112     return( (void *)GetProcAddress( handle, psz_function ) );
113
114 #else
115     return( dlsym( handle, psz_function ) );
116
117 #endif
118 }
119
120 static __inline__ void *
121 module_getsymbol( module_handle_t handle, char * psz_function )
122 {
123     void * p_symbol = module_getsymbol_inner( handle, psz_function );
124
125     /* MacOS X dl library expects symbols to begin with "_". So do
126      * some other operating systems. That's really lame, but hey, what
127      * can we do ? */
128     if( p_symbol == NULL )
129     {
130         char *psz_call = malloc( strlen( psz_function ) + 2 );
131
132         strcpy( psz_call + 1, psz_function );
133         psz_call[ 0 ] = '_';
134         p_symbol = module_getsymbol_inner( handle, psz_call );
135         free( psz_call );
136     }
137
138     return p_symbol;
139 }
140
141 /*****************************************************************************
142  * module_error: wrapper for dlerror()
143  *****************************************************************************
144  * This function returns the error message of the last module operation. It
145  * returns the string "failed" on systems which do not have a dlerror() like
146  * function. psz_buffer can be used to store temporary data, it is guaranteed
147  * to be kept intact until the return value of module_error has been used.
148  *****************************************************************************/
149 static __inline__ const char *
150 module_error( char *psz_buffer )
151 {
152 #if defined(SYS_BEOS)
153     return( "failed" );
154
155 #elif defined(WIN32)
156     int i, i_error = GetLastError();
157
158     FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
159                    NULL, i_error, MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
160                    (LPTSTR) psz_buffer, 256, NULL);
161
162     /* Go to the end of the string */
163     for( i = 0;
164          psz_buffer[i] && psz_buffer[i] != '\r' && psz_buffer[i] != '\n';
165          i++ ) {};
166
167     if( psz_buffer[i] )
168     {
169         snprintf( psz_buffer + i, 256 - i, " (error %i)", i_error );
170         psz_buffer[ 255 ] = '\0';
171     }
172     
173     return psz_buffer;
174
175 #else
176     return( dlerror() );
177
178 #endif
179 }
180
181 /*****************************************************************************
182  * STORE_SYMBOLS: store known symbols into p_symbols for plugin access.
183  *****************************************************************************/
184 #define STORE_SYMBOLS( p_symbols ) \
185     (p_symbols)->p_main = p_main; \
186     (p_symbols)->p_module_bank = p_module_bank; \
187     (p_symbols)->p_input_bank = p_input_bank; \
188     (p_symbols)->p_aout_bank = p_aout_bank; \
189     (p_symbols)->p_vout_bank = p_vout_bank; \
190     (p_symbols)->config_GetIntVariable = config_GetIntVariable; \
191     (p_symbols)->config_GetPszVariable = config_GetPszVariable; \
192     (p_symbols)->config_GetFloatVariable = config_GetFloatVariable; \
193     (p_symbols)->config_PutIntVariable = config_PutIntVariable; \
194     (p_symbols)->config_PutPszVariable = config_PutPszVariable; \
195     (p_symbols)->config_PutFloatVariable = config_PutFloatVariable; \
196     (p_symbols)->config_LoadConfigFile = config_LoadConfigFile; \
197     (p_symbols)->config_SaveConfigFile = config_SaveConfigFile; \
198     (p_symbols)->config_Duplicate = config_Duplicate; \
199     (p_symbols)->config_FindConfig = config_FindConfig; \
200     (p_symbols)->config_SetCallbacks = config_SetCallbacks; \
201     (p_symbols)->config_UnsetCallbacks = config_UnsetCallbacks; \
202     (p_symbols)->intf_MsgSub = intf_MsgSub; \
203     (p_symbols)->intf_MsgUnsub = intf_MsgUnsub; \
204     (p_symbols)->intf_Msg = intf_Msg; \
205     (p_symbols)->intf_ErrMsg = intf_ErrMsg; \
206     (p_symbols)->intf_StatMsg = intf_StatMsg;\
207     (p_symbols)->intf_WarnMsg = intf_WarnMsg; \
208     (p_symbols)->intf_PlaylistAdd = intf_PlaylistAdd; \
209     (p_symbols)->intf_PlaylistDelete = intf_PlaylistDelete; \
210     (p_symbols)->intf_PlaylistNext = intf_PlaylistNext; \
211     (p_symbols)->intf_PlaylistPrev = intf_PlaylistPrev; \
212     (p_symbols)->intf_PlaylistDestroy = intf_PlaylistDestroy; \
213     (p_symbols)->intf_PlaylistJumpto = intf_PlaylistJumpto; \
214     (p_symbols)->intf_UrlDecode = intf_UrlDecode; \
215     (p_symbols)->intf_Eject = intf_Eject; \
216     (p_symbols)->msleep = msleep; \
217     (p_symbols)->mdate = mdate; \
218     (p_symbols)->mstrtime = mstrtime; \
219     (p_symbols)->network_ChannelCreate = network_ChannelCreate; \
220     (p_symbols)->network_ChannelJoin = network_ChannelJoin; \
221     (p_symbols)->input_SetProgram = input_SetProgram; \
222     (p_symbols)->input_SetStatus = input_SetStatus; \
223     (p_symbols)->input_Seek = input_Seek; \
224     (p_symbols)->input_DumpStream = input_DumpStream; \
225     (p_symbols)->input_OffsetToTime = input_OffsetToTime; \
226     (p_symbols)->input_ChangeES = input_ChangeES; \
227     (p_symbols)->input_ToggleES = input_ToggleES; \
228     (p_symbols)->input_ChangeProgram = input_ChangeProgram; \
229     (p_symbols)->input_ChangeArea = input_ChangeArea; \
230     (p_symbols)->input_FindProgram = input_FindProgram; \
231     (p_symbols)->input_FindES = input_FindES; \
232     (p_symbols)->input_AddES = input_AddES; \
233     (p_symbols)->input_DelES = input_DelES; \
234     (p_symbols)->input_SelectES = input_SelectES; \
235     (p_symbols)->input_UnselectES = input_UnselectES; \
236     (p_symbols)->input_AddProgram = input_AddProgram; \
237     (p_symbols)->input_DelProgram = input_DelProgram; \
238     (p_symbols)->input_AddArea = input_AddArea; \
239     (p_symbols)->input_DelArea = input_DelArea; \
240     (p_symbols)->InitBitstream = InitBitstream; \
241     (p_symbols)->NextDataPacket = NextDataPacket; \
242     (p_symbols)->BitstreamNextDataPacket = BitstreamNextDataPacket; \
243     (p_symbols)->DecoderError = DecoderError; \
244     (p_symbols)->input_InitStream = input_InitStream; \
245     (p_symbols)->input_EndStream = input_EndStream; \
246     (p_symbols)->input_ParsePES = input_ParsePES; \
247     (p_symbols)->input_GatherPES = input_GatherPES; \
248     (p_symbols)->input_DecodePES = input_DecodePES; \
249     (p_symbols)->input_ReadPS = input_ReadPS; \
250     (p_symbols)->input_ParsePS = input_ParsePS; \
251     (p_symbols)->input_DemuxPS = input_DemuxPS; \
252     (p_symbols)->input_ReadTS = input_ReadTS; \
253     (p_symbols)->input_DemuxTS = input_DemuxTS; \
254     (p_symbols)->input_ClockManageRef = input_ClockManageRef; \
255     (p_symbols)->input_ClockManageControl = input_ClockManageControl; \
256     (p_symbols)->input_ClockGetTS = input_ClockGetTS; \
257     (p_symbols)->input_FDSeek = input_FDSeek; \
258     (p_symbols)->input_FDClose = input_FDClose; \
259     (p_symbols)->input_FDRead = input_FDRead; \
260     (p_symbols)->input_FDNetworkRead = input_FDNetworkRead; \
261     (p_symbols)->input_BuffersInit = input_BuffersInit; \
262     (p_symbols)->input_BuffersEnd = input_BuffersEnd; \
263     (p_symbols)->input_NewBuffer = input_NewBuffer; \
264     (p_symbols)->input_ReleaseBuffer = input_ReleaseBuffer; \
265     (p_symbols)->input_ShareBuffer = input_ShareBuffer; \
266     (p_symbols)->input_NewPacket = input_NewPacket; \
267     (p_symbols)->input_DeletePacket = input_DeletePacket; \
268     (p_symbols)->input_NewPES = input_NewPES; \
269     (p_symbols)->input_DeletePES = input_DeletePES; \
270     (p_symbols)->input_FillBuffer = input_FillBuffer; \
271     (p_symbols)->input_Peek = input_Peek; \
272     (p_symbols)->input_SplitBuffer = input_SplitBuffer; \
273     (p_symbols)->input_AccessInit = input_AccessInit; \
274     (p_symbols)->input_AccessReinit = input_AccessReinit; \
275     (p_symbols)->input_AccessEnd = input_AccessEnd; \
276     (p_symbols)->aout_CreateFifo = aout_CreateFifo; \
277     (p_symbols)->aout_DestroyFifo = aout_DestroyFifo; \
278     (p_symbols)->vout_CreateThread = vout_CreateThread; \
279     (p_symbols)->vout_DestroyThread = vout_DestroyThread; \
280     (p_symbols)->vout_CreateSubPicture = vout_CreateSubPicture; \
281     (p_symbols)->vout_DestroySubPicture = vout_DestroySubPicture; \
282     (p_symbols)->vout_DisplaySubPicture = vout_DisplaySubPicture; \
283     (p_symbols)->vout_CreatePicture = vout_CreatePicture; \
284     (p_symbols)->vout_AllocatePicture = vout_AllocatePicture; \
285     (p_symbols)->vout_DisplayPicture = vout_DisplayPicture; \
286     (p_symbols)->vout_DestroyPicture = vout_DestroyPicture; \
287     (p_symbols)->vout_DatePicture = vout_DatePicture; \
288     (p_symbols)->vout_LinkPicture = vout_LinkPicture; \
289     (p_symbols)->vout_UnlinkPicture = vout_UnlinkPicture; \
290     (p_symbols)->vout_PlacePicture = vout_PlacePicture; \
291     (p_symbols)->vout_ChromaCmp = vout_ChromaCmp; \
292     (p_symbols)->UnalignedGetBits = UnalignedGetBits; \
293     (p_symbols)->UnalignedRemoveBits = UnalignedRemoveBits; \
294     (p_symbols)->UnalignedShowBits = UnalignedShowBits; \
295     (p_symbols)->CurrentPTS = CurrentPTS; \
296     (p_symbols)->DecodeLanguage = DecodeLanguage; \
297     (p_symbols)->module_Need = module_Need; \
298     (p_symbols)->module_Unneed = module_Unneed;