]> git.sesse.net Git - vlc/blob - bindings/python/vlcglue.h
Rename bindings/mediacontrol-python to bindings/python
[vlc] / bindings / python / vlcglue.h
1 /*****************************************************************************
2  * vlcglue.h: Main header for the Python binding
3  *****************************************************************************
4  * Copyright (C) 1998-2004 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Olivier Aubert <oaubert at bat710.univ-lyon1.fr>
8  *          ClĂ©ment Stenac <zorglub@videolan.org>
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24 #ifndef _VLCGLUE_H
25 #define _VLCGLUE_H 1
26
27 #include <Python.h>
28 #include "structmember.h"
29
30 #include <stdio.h>
31 #include <vlc/vlc.h>
32 #include <vlc/libvlc.h>
33 #include <vlc/mediacontrol_structures.h>
34 #include <vlc/mediacontrol.h>
35
36 #define SELF ((MediaControl*)self)
37
38 /**********************************************************************
39  * Exceptions handling
40  **********************************************************************/
41
42 #define MC_TRY exception=mediacontrol_exception_init(exception)
43
44 #define MC_EXCEPT  \
45   if( exception->code ) { \
46     PyObject *py_exc = MediaControl_InternalException; \
47     switch( exception->code ) { \
48     case mediacontrol_InternalException: \
49       py_exc = MediaControl_InternalException; \
50       break; \
51     case mediacontrol_PlaylistException: \
52       py_exc = MediaControl_PlaylistException; \
53       break; \
54     case mediacontrol_InvalidPosition: \
55       py_exc = MediaControl_InvalidPosition; \
56       break; \
57     case mediacontrol_PositionKeyNotSupported: \
58       py_exc = MediaControl_PositionKeyNotSupported; \
59       break; \
60     case mediacontrol_PositionOriginNotSupported: \
61       py_exc = MediaControl_PositionOriginNotSupported; \
62       break; \
63     } \
64     PyErr_SetString( py_exc, exception->message ); \
65     mediacontrol_exception_free( exception ); \
66     return NULL; \
67   } else { mediacontrol_exception_free( exception ); }
68
69 PyObject *MediaControl_InternalException;
70 PyObject *MediaControl_PositionKeyNotSupported;
71 PyObject *MediaControl_PositionOriginNotSupported;
72 PyObject *MediaControl_InvalidPosition;
73 PyObject *MediaControl_PlaylistException;
74 PyObject *vlcInstance_Exception;
75
76 /**********************************************************************
77  * VLC Object
78  **********************************************************************/
79 #define VLCSELF ( ( vlcObject* )self )
80
81 /**********************************************************************
82  * VLCObject Object
83  **********************************************************************/
84 typedef struct
85 {
86     PyObject_HEAD
87     vlc_object_t* p_object;
88     int b_released;
89 } vlcObject;
90
91 /**********************************************************************
92  * MediaControl Object
93  **********************************************************************/
94 typedef struct
95 {
96     PyObject_HEAD
97     mediacontrol_Instance* mc;
98 } MediaControl;
99
100 /**********************************************************************
101  * Position Object
102  **********************************************************************/
103 typedef struct
104 {
105     PyObject_HEAD
106     int origin;
107     int key;
108     PY_LONG_LONG value;
109 } PyPosition;
110
111 /**********************************************************************
112  * vlc.Instance Object
113  **********************************************************************/
114 typedef struct
115 {
116     PyObject_HEAD
117     libvlc_instance_t* p_instance;
118 } vlcInstance;
119
120 #define LIBVLC_INSTANCE ((vlcInstance*)self)
121
122 /**********************************************************************
123  * vlc.Input Object
124  **********************************************************************/
125 typedef struct
126 {
127     PyObject_HEAD
128     libvlc_input_t* p_input;
129 } vlcInput;
130
131 /* Forward declarations */
132 staticforward PyTypeObject vlcObject_Type;
133 staticforward PyTypeObject MediaControl_Type;
134 staticforward PyTypeObject PyPosition_Type;
135 staticforward PyTypeObject vlcInstance_Type;
136 staticforward PyTypeObject vlcInput_Type;
137
138 #define LIBVLC_INPUT ((vlcInput*)self)
139
140 #define LIBVLC_TRY libvlc_exception_init( &ex );
141
142 #define LIBVLC_EXCEPT if( libvlc_exception_raised( &ex ) ) { \
143     PyObject *py_exc = vlcInstance_Exception; \
144     PyErr_SetString( py_exc, libvlc_exception_get_message( &ex ) ); \
145     return NULL; \
146   }
147
148 mediacontrol_PositionKey positionKey_py_to_c( PyObject * py_key );
149 mediacontrol_PositionOrigin positionOrigin_py_to_c( PyObject * py_origin );
150 mediacontrol_Position * position_py_to_c( PyObject * py_position );
151 PyPosition * position_c_to_py( mediacontrol_Position * position );
152
153 /* Long long conversion on Mac os X/ppc */
154 #if defined (__ppc__) || defined(__ppc64__)
155 #define ntohll(x) ((long long) x >> 64)
156 #else
157 #define ntohll(x) (x)
158 #endif
159
160 #endif