]> git.sesse.net Git - vlc/blob - bindings/python/vlc_module.c
A bit of vlc/libvlc cleanup:
[vlc] / bindings / python / vlc_module.c
1 /*****************************************************************************
2  * vlc_module.c: vlc python binding module
3  *****************************************************************************
4  * Copyright (C) 2006 the VideoLAN team
5  * $Id: $
6  *
7  * Authors: Olivier Aubert <oaubert at bat710.univ-lyon1.fr>
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 /* We need to access some internal features of VLC (for vlc_object) */
25 /* This is gruik as we are not libvlc at all */
26 #define __LIBVLC__
27
28
29 #include "vlcglue.h"
30
31 /**************************************************************************
32  * VLC Module
33  **************************************************************************/
34
35 #ifndef vlcMODINIT_FUNC /* declarations for DLL import/export */
36 #define vlcMODINIT_FUNC void
37 #endif
38
39 static PyMethodDef vlc_methods[] = {
40     { NULL }  /* Sentinel */
41 };
42
43 /* Module globals */
44 PyObject* MediaControl_InternalException          = NULL;
45 PyObject* MediaControl_PositionKeyNotSupported    = NULL;
46 PyObject *MediaControl_PositionOriginNotSupported = NULL;
47 PyObject* MediaControl_InvalidPosition            = NULL;
48 PyObject *MediaControl_PlaylistException          = NULL;
49
50 vlcMODINIT_FUNC
51 initvlc( void )
52 {
53     PyObject* p_module;
54
55     PyPosition_Type.tp_new = PyType_GenericNew;
56     PyPosition_Type.tp_alloc = PyType_GenericAlloc;
57
58     vlcInput_Type.tp_new = PyType_GenericNew;
59     vlcInput_Type.tp_alloc = PyType_GenericAlloc;
60
61     p_module = Py_InitModule3( "vlc", vlc_methods,
62                                "VLC media player embedding module." );
63
64     if( !p_module )
65       return;
66
67     if( PyType_Ready( &PyPosition_Type ) < 0 )
68         return;
69     if( PyType_Ready( &MediaControl_Type ) < 0 )
70         return;
71     if( PyType_Ready( &vlcObject_Type ) < 0 )
72         return;
73     if( PyType_Ready( &vlcInstance_Type ) < 0 )
74         return;
75     if( PyType_Ready( &vlcInput_Type ) < 0 )
76         return;
77
78     /* Exceptions */
79     MediaControl_InternalException =
80             PyErr_NewException( "vlc.InternalException", NULL, NULL );
81     Py_INCREF( MediaControl_InternalException );
82     PyModule_AddObject( p_module, "InternalException",
83                         MediaControl_InternalException );
84
85     MediaControl_PositionKeyNotSupported =
86             PyErr_NewException( "vlc.PositionKeyNotSupported", NULL, NULL );
87     Py_INCREF( MediaControl_PositionKeyNotSupported );
88     PyModule_AddObject( p_module, "PositionKeyNotSupported",
89                         MediaControl_PositionKeyNotSupported );
90
91     MediaControl_PositionOriginNotSupported=
92             PyErr_NewException( "vlc.InvalidPosition", NULL, NULL );
93     Py_INCREF( MediaControl_PositionOriginNotSupported );
94     PyModule_AddObject( p_module, "PositionOriginNotSupported",
95                         MediaControl_PositionOriginNotSupported );
96
97     MediaControl_InvalidPosition =
98             PyErr_NewException( "vlc.InvalidPosition", NULL, NULL );
99     Py_INCREF( MediaControl_InvalidPosition );
100     PyModule_AddObject( p_module, "InvalidPosition",
101                         MediaControl_InvalidPosition );
102
103     MediaControl_PlaylistException =
104             PyErr_NewException( "vlc.PlaylistException", NULL, NULL );
105     Py_INCREF( MediaControl_PlaylistException );
106     PyModule_AddObject( p_module, "PlaylistException",
107                         MediaControl_PlaylistException );
108
109     /* Exceptions */
110     vlcInstance_Exception =
111         PyErr_NewException( "vlc.InstanceException", NULL, NULL );
112     Py_INCREF( vlcInstance_Exception );
113     PyModule_AddObject( p_module, "InstanceException",
114                         vlcInstance_Exception );
115
116     /* Types */
117     Py_INCREF( &PyPosition_Type );
118     PyModule_AddObject( p_module, "Position",
119                         ( PyObject * )&PyPosition_Type );
120
121     Py_INCREF( &MediaControl_Type );
122     PyModule_AddObject( p_module, "MediaControl",
123                         ( PyObject * )&MediaControl_Type );
124
125     Py_INCREF( &vlcObject_Type );
126     PyModule_AddObject( p_module, "Object",
127                         ( PyObject * )&vlcObject_Type );
128     Py_INCREF( &vlcInstance_Type );
129     PyModule_AddObject( p_module, "Instance",
130                         ( PyObject * )&vlcInstance_Type );
131     Py_INCREF( &vlcInput_Type );
132     PyModule_AddObject( p_module, "Input",
133                         ( PyObject * )&vlcInput_Type );
134
135     /* Constants */
136     PyModule_AddIntConstant( p_module, "AbsolutePosition",
137                              mediacontrol_AbsolutePosition );
138     PyModule_AddIntConstant( p_module, "RelativePosition",
139                              mediacontrol_RelativePosition );
140     PyModule_AddIntConstant( p_module, "ModuloPosition",
141                              mediacontrol_ModuloPosition );
142
143     PyModule_AddIntConstant( p_module, "ByteCount",
144                              mediacontrol_ByteCount );
145     PyModule_AddIntConstant( p_module, "SampleCount",
146                              mediacontrol_SampleCount );
147     PyModule_AddIntConstant( p_module, "MediaTime",
148                              mediacontrol_MediaTime );
149     PyModule_AddIntConstant( p_module, "PlayingStatus",
150                              mediacontrol_PlayingStatus );
151     PyModule_AddIntConstant( p_module, "PauseStatus",
152                              mediacontrol_PauseStatus );
153     PyModule_AddIntConstant( p_module, "ForwardStatus",
154                              mediacontrol_ForwardStatus );
155     PyModule_AddIntConstant( p_module, "BackwardStatus",
156                              mediacontrol_BackwardStatus );
157     PyModule_AddIntConstant( p_module, "InitStatus",
158                              mediacontrol_InitStatus );
159     PyModule_AddIntConstant( p_module, "EndStatus",
160                              mediacontrol_EndStatus );
161     PyModule_AddIntConstant( p_module, "UndefinedStatus",
162                              mediacontrol_UndefinedStatus );
163 }
164
165
166 /* Make libpostproc happy... */
167 void * fast_memcpy( void * to, const void * from, size_t len )
168 {
169   return memcpy( to, from, len );
170 }
171
172 /* Horrible hack... Please do not look.  Temporary workaround for the
173    forward declaration mess of python types (cf vlcglue.h). If we do a
174    separate compilation, we have to declare some types as extern. But
175    the recommended way to forward declare types in python is
176    static... I am sorting the mess but in the meantime, this will
177    produce a working python module.
178 */
179 #include "vlc_mediacontrol.c"
180 #include "vlc_position.c"
181 #include "vlc_instance.c"
182 #include "vlc_input.c"
183 #include "vlc_object.c"