]> git.sesse.net Git - vlc/blob - bindings/python/vlcglue.h
d5f604c4ec2223f2018ca16c24c7b6fd13e72165
[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 <olivier.aubert at liris.cnrs.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 /* Python 2.5 64-bit support compatibility define */
37 #if PY_VERSION_HEX < 0x02050000 && !defined(PY_SSIZE_T_MIN)
38 typedef int Py_ssize_t;
39 #define PY_SSIZE_T_MAX INT_MAX
40 #define PY_SSIZE_T_MIN INT_MIN
41 #endif
42
43
44 /**********************************************************************
45  * Exceptions handling
46  **********************************************************************/
47
48 #define MC_TRY exception=mediacontrol_exception_create( )
49
50 #define MC_EXCEPT  \
51   if( exception && exception->code ) { \
52     PyObject *py_exc = MediaControl_InternalException; \
53     switch( exception->code ) { \
54     case mediacontrol_InternalException: \
55       py_exc = MediaControl_InternalException; \
56       break; \
57     case mediacontrol_PlaylistException: \
58       py_exc = MediaControl_PlaylistException; \
59       break; \
60     case mediacontrol_InvalidPosition: \
61       py_exc = MediaControl_InvalidPosition; \
62       break; \
63     case mediacontrol_PositionKeyNotSupported: \
64       py_exc = MediaControl_PositionKeyNotSupported; \
65       break; \
66     case mediacontrol_PositionOriginNotSupported: \
67       py_exc = MediaControl_PositionOriginNotSupported; \
68       break; \
69     } \
70     PyErr_SetString( py_exc, exception->message ); \
71     mediacontrol_exception_free( exception ); \
72     return NULL; \
73   } else if( exception ) { mediacontrol_exception_free( exception ); }
74
75 PyObject *MediaControl_InternalException;
76 PyObject *MediaControl_PositionKeyNotSupported;
77 PyObject *MediaControl_PositionOriginNotSupported;
78 PyObject *MediaControl_InvalidPosition;
79 PyObject *MediaControl_PlaylistException;
80 PyObject *vlc_Exception;
81
82 /**********************************************************************
83  * vlc.Instance Object
84  **********************************************************************/
85 typedef struct
86 {
87     PyObject_HEAD
88     libvlc_instance_t* p_instance;
89 } vlcInstance;
90
91 /**********************************************************************
92  * MediaControl Object
93  **********************************************************************/
94 typedef struct
95 {
96     PyObject_HEAD
97     mediacontrol_Instance* mc;
98     vlcInstance *vlc_instance;
99 } MediaControl;
100
101 /**********************************************************************
102  * Position Object
103  **********************************************************************/
104 typedef struct
105 {
106     PyObject_HEAD
107     int origin;
108     int key;
109     PY_LONG_LONG value;
110 } PyPosition;
111
112 /**********************************************************************
113  * vlc.MediaPlayer Object
114  **********************************************************************/
115 typedef struct
116 {
117     PyObject_HEAD
118     libvlc_media_player_t* p_mp;
119 } vlcMediaPlayer;
120
121 /**********************************************************************
122  * vlc.Media Object
123  **********************************************************************/
124 typedef struct
125 {
126     PyObject_HEAD
127     libvlc_media_t* p_media;
128 } vlcMedia;
129
130 /* Forward declarations */
131 staticforward PyTypeObject MediaControl_Type;
132 staticforward PyTypeObject PyPosition_Type;
133 staticforward PyTypeObject vlcInstance_Type;
134 staticforward PyTypeObject vlcMediaPlayer_Type;
135 staticforward PyTypeObject vlcMedia_Type;
136
137 #define LIBVLC_INSTANCE(self) (((vlcInstance*)self)->p_instance)
138 #define LIBVLC_MEDIAPLAYER(self) (((vlcMediaPlayer*)self)->p_mp)
139 #define LIBVLC_MEDIA(self) (((vlcMedia*)self)->p_media)
140 #define LIBVLC_MC(self) (((MediaControl*)self)->mc)
141
142 #define LIBVLC_TRY libvlc_exception_init( &ex );
143
144 #define LIBVLC_EXCEPT if( libvlc_exception_raised( &ex ) ) { \
145     PyObject *py_exc = vlc_Exception; \
146     PyErr_SetString( py_exc, libvlc_exception_get_message( &ex ) ); \
147     return NULL; \
148   }
149
150 mediacontrol_PositionKey positionKey_py_to_c( PyObject * py_key );
151 mediacontrol_PositionOrigin positionOrigin_py_to_c( PyObject * py_origin );
152 mediacontrol_Position * position_py_to_c( PyObject * py_position );
153 PyPosition * position_c_to_py( mediacontrol_Position * position );
154
155 /* Long long conversion on Mac os X/ppc */
156 #if defined (__ppc__) || defined(__ppc64__)
157 #define ntohll(x) ((long long) x >> 64)
158 #else
159 #define ntohll(x) (x)
160 #endif
161
162 #endif