1 /*****************************************************************************
2 * vlc_module.c: vlc python binding module
3 *****************************************************************************
4 * Copyright (C) 2006 the VideoLAN team
7 * Authors: Olivier Aubert <oaubert at bat710.univ-lyon1.fr>
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.
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.
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 *****************************************************************************/
27 /**************************************************************************
29 **************************************************************************/
31 #ifndef vlcMODINIT_FUNC /* declarations for DLL import/export */
32 #define vlcMODINIT_FUNC void
35 static PyMethodDef vlc_methods[] = {
36 { NULL } /* Sentinel */
40 PyObject* MediaControl_InternalException = NULL;
41 PyObject* MediaControl_PositionKeyNotSupported = NULL;
42 PyObject *MediaControl_PositionOriginNotSupported = NULL;
43 PyObject* MediaControl_InvalidPosition = NULL;
44 PyObject *MediaControl_PlaylistException = NULL;
53 FIXME: Win32 support is trickier than that (does not support dlopen).
54 Get code from src/modules/os.c to work on different OSes.
56 #define LIBVLCCORE "libvlccore.dll"
58 #define LIBVLCCORE "libvlccore.so"
60 /* Workaround for the 2257/2266 VLC bug. */
61 if ( !dlopen( LIBVLCCORE, RTLD_NOW | RTLD_GLOBAL ) )
63 fprintf( stderr, "Error when loading libvlccore:\n%s\nTrying to continue anyway.\n", dlerror() );
66 /* vlcMediaPlayer_Type.tp_new = PyType_GenericNew; */
67 vlcMediaPlayer_Type.tp_alloc = PyType_GenericAlloc;
68 /* vlcMedia_Type.tp_new = PyType_GenericNew; */
69 vlcMedia_Type.tp_alloc = PyType_GenericAlloc;
71 vlcInstance_Type.tp_alloc = PyType_GenericAlloc;
72 MediaControl_Type.tp_alloc = PyType_GenericAlloc;
74 p_module = Py_InitModule3( "vlc", vlc_methods,
75 "VLC media player embedding module." );
80 if( PyType_Ready( &PyPosition_Type ) < 0 )
82 if( PyType_Ready( &MediaControl_Type ) < 0 )
84 if( PyType_Ready( &vlcInstance_Type ) < 0 )
86 if( PyType_Ready( &vlcMediaPlayer_Type ) < 0 )
88 if( PyType_Ready( &vlcMedia_Type ) < 0 )
92 MediaControl_InternalException =
93 PyErr_NewException( "vlc.InternalException", NULL, NULL );
94 Py_INCREF( MediaControl_InternalException );
95 PyModule_AddObject( p_module, "InternalException",
96 MediaControl_InternalException );
98 MediaControl_PositionKeyNotSupported =
99 PyErr_NewException( "vlc.PositionKeyNotSupported", NULL, NULL );
100 Py_INCREF( MediaControl_PositionKeyNotSupported );
101 PyModule_AddObject( p_module, "PositionKeyNotSupported",
102 MediaControl_PositionKeyNotSupported );
104 MediaControl_PositionOriginNotSupported=
105 PyErr_NewException( "vlc.InvalidPosition", NULL, NULL );
106 Py_INCREF( MediaControl_PositionOriginNotSupported );
107 PyModule_AddObject( p_module, "PositionOriginNotSupported",
108 MediaControl_PositionOriginNotSupported );
110 MediaControl_InvalidPosition =
111 PyErr_NewException( "vlc.InvalidPosition", NULL, NULL );
112 Py_INCREF( MediaControl_InvalidPosition );
113 PyModule_AddObject( p_module, "InvalidPosition",
114 MediaControl_InvalidPosition );
116 MediaControl_PlaylistException =
117 PyErr_NewException( "vlc.PlaylistException", NULL, NULL );
118 Py_INCREF( MediaControl_PlaylistException );
119 PyModule_AddObject( p_module, "PlaylistException",
120 MediaControl_PlaylistException );
124 PyErr_NewException( "vlc.InstanceException", NULL, NULL );
125 Py_INCREF( vlc_Exception );
126 PyModule_AddObject( p_module, "InstanceException",
130 Py_INCREF( &PyPosition_Type );
131 PyModule_AddObject( p_module, "Position",
132 ( PyObject * )&PyPosition_Type );
134 Py_INCREF( &MediaControl_Type );
135 PyModule_AddObject( p_module, "MediaControl",
136 ( PyObject * )&MediaControl_Type );
138 Py_INCREF( &vlcInstance_Type );
139 PyModule_AddObject( p_module, "Instance",
140 ( PyObject * )&vlcInstance_Type );
142 Py_INCREF( &vlcMediaPlayer_Type );
143 PyModule_AddObject( p_module, "MediaPlayer",
144 ( PyObject * )&vlcMediaPlayer_Type );
146 Py_INCREF( &vlcMedia_Type );
147 PyModule_AddObject( p_module, "Media",
148 ( PyObject * )&vlcMedia_Type );
151 PyModule_AddIntConstant( p_module, "AbsolutePosition",
152 mediacontrol_AbsolutePosition );
153 PyModule_AddIntConstant( p_module, "RelativePosition",
154 mediacontrol_RelativePosition );
155 PyModule_AddIntConstant( p_module, "ModuloPosition",
156 mediacontrol_ModuloPosition );
158 PyModule_AddIntConstant( p_module, "ByteCount",
159 mediacontrol_ByteCount );
160 PyModule_AddIntConstant( p_module, "SampleCount",
161 mediacontrol_SampleCount );
162 PyModule_AddIntConstant( p_module, "MediaTime",
163 mediacontrol_MediaTime );
165 PyModule_AddIntConstant( p_module, "PlayingStatus",
166 mediacontrol_PlayingStatus );
167 PyModule_AddIntConstant( p_module, "PauseStatus",
168 mediacontrol_PauseStatus );
169 PyModule_AddIntConstant( p_module, "InitStatus",
170 mediacontrol_InitStatus );
171 PyModule_AddIntConstant( p_module, "EndStatus",
172 mediacontrol_EndStatus );
173 PyModule_AddIntConstant( p_module, "UndefinedStatus",
174 mediacontrol_UndefinedStatus );
178 /* Horrible hack... Please do not look. Temporary workaround for the
179 forward declaration mess of python types (cf vlcglue.h). If we do a
180 separate compilation, we have to declare some types as extern. But
181 the recommended way to forward declared types in python is
182 static... I am sorting the mess but in the meantime, this will
183 produce a working python module.
185 #include "vlc_mediacontrol.c"
186 #include "vlc_position.c"
187 #include "vlc_instance.c"
188 #include "vlc_mediaplayer.c"
189 #include "vlc_media.c"