]> git.sesse.net Git - vlc/blob - bindings/python/vlcglue.h
python bindings: svn:keywords set to Id
[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 /* 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 #define SELF ((MediaControl*)self)
44
45 /**********************************************************************
46  * Exceptions handling
47  **********************************************************************/
48
49 #define MC_TRY exception=mediacontrol_exception_create( )
50
51 #define MC_EXCEPT  \
52   if( exception && exception->code ) { \
53     PyObject *py_exc = MediaControl_InternalException; \
54     switch( exception->code ) { \
55     case mediacontrol_InternalException: \
56       py_exc = MediaControl_InternalException; \
57       break; \
58     case mediacontrol_PlaylistException: \
59       py_exc = MediaControl_PlaylistException; \
60       break; \
61     case mediacontrol_InvalidPosition: \
62       py_exc = MediaControl_InvalidPosition; \
63       break; \
64     case mediacontrol_PositionKeyNotSupported: \
65       py_exc = MediaControl_PositionKeyNotSupported; \
66       break; \
67     case mediacontrol_PositionOriginNotSupported: \
68       py_exc = MediaControl_PositionOriginNotSupported; \
69       break; \
70     } \
71     PyErr_SetString( py_exc, exception->message ); \
72     mediacontrol_exception_free( exception ); \
73     return NULL; \
74   } else if( exception ) { mediacontrol_exception_free( exception ); }
75
76 PyObject *MediaControl_InternalException;
77 PyObject *MediaControl_PositionKeyNotSupported;
78 PyObject *MediaControl_PositionOriginNotSupported;
79 PyObject *MediaControl_InvalidPosition;
80 PyObject *MediaControl_PlaylistException;
81 PyObject *vlcInstance_Exception;
82
83 /**********************************************************************
84  * vlc.Instance Object
85  **********************************************************************/
86 typedef struct
87 {
88     PyObject_HEAD
89     libvlc_instance_t* p_instance;
90 } vlcInstance;
91
92 #define LIBVLC_INSTANCE ((vlcInstance*)self)
93
94 /**********************************************************************
95  * MediaControl Object
96  **********************************************************************/
97 typedef struct
98 {
99     PyObject_HEAD
100     mediacontrol_Instance* mc;
101     vlcInstance *vlc_instance;
102 } MediaControl;
103
104 /**********************************************************************
105  * Position Object
106  **********************************************************************/
107 typedef struct
108 {
109     PyObject_HEAD
110     int origin;
111     int key;
112     PY_LONG_LONG value;
113 } PyPosition;
114
115 /**********************************************************************
116  * vlc.Input Object
117  **********************************************************************/
118 typedef struct
119 {
120     PyObject_HEAD
121     libvlc_media_instance_t* p_md;
122 } vlcInput;
123
124 /* Forward declarations */
125 staticforward PyTypeObject MediaControl_Type;
126 staticforward PyTypeObject PyPosition_Type;
127 staticforward PyTypeObject vlcInstance_Type;
128 staticforward PyTypeObject vlcInput_Type;
129
130 #define LIBVLC_INPUT ((vlcInput*)self)
131
132 #define LIBVLC_TRY libvlc_exception_init( &ex );
133
134 #define LIBVLC_EXCEPT if( libvlc_exception_raised( &ex ) ) { \
135     PyObject *py_exc = vlcInstance_Exception; \
136     PyErr_SetString( py_exc, libvlc_exception_get_message( &ex ) ); \
137     return NULL; \
138   }
139
140 mediacontrol_PositionKey positionKey_py_to_c( PyObject * py_key );
141 mediacontrol_PositionOrigin positionOrigin_py_to_c( PyObject * py_origin );
142 mediacontrol_Position * position_py_to_c( PyObject * py_position );
143 PyPosition * position_c_to_py( mediacontrol_Position * position );
144
145 /* Long long conversion on Mac os X/ppc */
146 #if defined (__ppc__) || defined(__ppc64__)
147 #define ntohll(x) ((long long) x >> 64)
148 #else
149 #define ntohll(x) (x)
150 #endif
151
152 #endif