~ubuntu-branches/ubuntu/karmic/quodlibet/karmic

« back to all changes in this revision

Viewing changes to quodlibet/player/_xine.py

  • Committer: Bazaar Package Importer
  • Author(s): Luca Falavigna
  • Date: 2009-01-30 23:55:34 UTC
  • mfrom: (1.1.12 upstream)
  • Revision ID: james.westby@ubuntu.com-20090130235534-l4e72ulw0vqfo17w
Tags: 2.0-1ubuntu1
* Merge from Debian experimental (LP: #276856), remaining Ubuntu changes:
  + debian/patches/40-use-music-profile.patch:
    - Use the "Music and Movies" pipeline per default.
* Refresh the above patch for new upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2006 Lukas Lalinsky
 
2
#
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License version 2 as
 
5
# published by the Free Software Foundation
 
6
#
 
7
# $Id: _xine.py 4330 2008-09-14 03:19:26Z piman $
 
8
 
 
9
import sys
 
10
import ctypes
 
11
 
 
12
try:
 
13
    _libxine = ctypes.cdll.LoadLibrary('libxine.so.1')
 
14
except (ImportError, OSError), e:
 
15
    raise ImportError, e
 
16
 
 
17
class xine_event_t(ctypes.Structure):
 
18
    _fields_ = [
 
19
        ('type', ctypes.c_int),
 
20
        ('stream', ctypes.c_void_p),
 
21
        ('data', ctypes.c_void_p),
 
22
        ('data_length', ctypes.c_int),
 
23
    ]
 
24
 
 
25
class xine_ui_message_data_t(ctypes.Structure):
 
26
    _fields_ = [
 
27
        ('compatibility_num_buttons', ctypes.c_int),
 
28
        ('compatibility_str_len', ctypes.c_int),
 
29
        ('compatibility_str', 256 * ctypes.c_char),
 
30
        ('type', ctypes.c_int),
 
31
        ('explanation', ctypes.c_int),
 
32
        ('num_parameters', ctypes.c_int),
 
33
        ('parameters', ctypes.c_void_p),
 
34
        ('messages', ctypes.c_char),
 
35
    ]
 
36
 
 
37
# event listener callback type
 
38
xine_event_listener_cb_t = ctypes.CFUNCTYPE(
 
39
    ctypes.c_void_p, ctypes.c_void_p,
 
40
    ctypes.POINTER(xine_event_t))
 
41
 
 
42
# event types
 
43
XINE_EVENT_UI_PLAYBACK_FINISHED  = 1
 
44
XINE_EVENT_UI_CHANNELS_CHANGED   = 2
 
45
XINE_EVENT_UI_SET_TITLE          = 3
 
46
XINE_EVENT_UI_MESSAGE            = 4
 
47
XINE_EVENT_FRAME_FORMAT_CHANGE   = 5
 
48
XINE_EVENT_AUDIO_LEVEL           = 6
 
49
XINE_EVENT_QUIT                  = 7
 
50
XINE_EVENT_PROGRESS              = 8
 
51
 
 
52
# stream parameters
 
53
XINE_PARAM_SPEED                 = 1 # see below
 
54
XINE_PARAM_AV_OFFSET             = 2 # unit: 1/90000 ses
 
55
XINE_PARAM_AUDIO_CHANNEL_LOGICAL = 3 # -1 => auto, -2 => off
 
56
XINE_PARAM_SPU_CHANNEL           = 4
 
57
XINE_PARAM_VIDEO_CHANNEL         = 5
 
58
XINE_PARAM_AUDIO_VOLUME          = 6 # 0..100
 
59
XINE_PARAM_AUDIO_MUTE            = 7 # 1=>mute, 0=>unmute
 
60
XINE_PARAM_AUDIO_COMPR_LEVEL     = 8 # <100=>off, % compress otherw
 
61
XINE_PARAM_AUDIO_AMP_LEVEL       = 9 # 0..200, 100=>100% (default)
 
62
XINE_PARAM_AUDIO_REPORT_LEVEL    = 10 # 1=>send events, 0=> don't
 
63
XINE_PARAM_VERBOSITY             = 11 # control console output
 
64
XINE_PARAM_SPU_OFFSET            = 12 # unit: 1/90000 sec
 
65
XINE_PARAM_IGNORE_VIDEO          = 13 # disable video decoding
 
66
XINE_PARAM_IGNORE_AUDIO          = 14 # disable audio decoding
 
67
XINE_PARAM_IGNORE_SPU            = 15 # disable spu decoding
 
68
XINE_PARAM_BROADCASTER_PORT      = 16 # 0: disable, x: server port
 
69
XINE_PARAM_METRONOM_PREBUFFER    = 17 # unit: 1/90000 sec
 
70
XINE_PARAM_EQ_30HZ               = 18 # equalizer gains -100..100
 
71
XINE_PARAM_EQ_60HZ               = 19 # equalizer gains -100..100
 
72
XINE_PARAM_EQ_125HZ              = 20 # equalizer gains -100..100
 
73
XINE_PARAM_EQ_250HZ              = 21 # equalizer gains -100..100
 
74
XINE_PARAM_EQ_500HZ              = 22 # equalizer gains -100..100
 
75
XINE_PARAM_EQ_1000HZ             = 23 # equalizer gains -100..100
 
76
XINE_PARAM_EQ_2000HZ             = 24 # equalizer gains -100..100
 
77
XINE_PARAM_EQ_4000HZ             = 25 # equalizer gains -100..100
 
78
XINE_PARAM_EQ_8000HZ             = 26 # equalizer gains -100..100
 
79
XINE_PARAM_EQ_16000HZ            = 27 # equalizer gains -100..100
 
80
XINE_PARAM_AUDIO_CLOSE_DEVICE    = 28 # force closing audio device
 
81
XINE_PARAM_AUDIO_AMP_MUTE        = 29 # 1=>mute, 0=>unmute
 
82
XINE_PARAM_FINE_SPEED            = 30 # 1.000.000 => normal speed
 
83
XINE_PARAM_EARLY_FINISHED_EVENT  = 31 # send event when demux finish
 
84
XINE_PARAM_GAPLESS_SWITCH        = 32 # next stream only gapless swi
 
85
XINE_PARAM_DELAY_FINISHED_EVENT  = 33 # 1/10sec,0=>disable,-1=>forev
 
86
 
 
87
# speeds
 
88
XINE_SPEED_PAUSE                 = 0
 
89
XINE_SPEED_SLOW_4                = 1
 
90
XINE_SPEED_SLOW_2                = 2
 
91
XINE_SPEED_NORMAL                = 4
 
92
XINE_SPEED_FAST_2                = 8
 
93
XINE_SPEED_FAST_4                = 16
 
94
 
 
95
# metadata
 
96
XINE_META_INFO_TITLE             = 0
 
97
XINE_META_INFO_COMMENT           = 1
 
98
XINE_META_INFO_ARTIST            = 2
 
99
XINE_META_INFO_GENRE             = 3
 
100
XINE_META_INFO_ALBUM             = 4
 
101
XINE_META_INFO_YEAR              = 5
 
102
XINE_META_INFO_VIDEOCODEC        = 6
 
103
XINE_META_INFO_AUDIOCODEC        = 7
 
104
XINE_META_INFO_SYSTEMLAYER       = 8
 
105
XINE_META_INFO_INPUT_PLUGIN      = 9
 
106
 
 
107
# statuses
 
108
XINE_STATUS_IDLE = 0
 
109
XINE_STATUS_STOP = 1
 
110
XINE_STATUS_PLAY = 2
 
111
XINE_STATUS_QUIT = 3
 
112
 
 
113
XINE_MSG_NO_ERROR              = 0 # (messages to UI)
 
114
XINE_MSG_GENERAL_WARNING       = 1 # (warning message)
 
115
XINE_MSG_UNKNOWN_HOST          = 2 # (host name)
 
116
XINE_MSG_UNKNOWN_DEVICE        = 3 # (device name)
 
117
XINE_MSG_NETWORK_UNREACHABLE   = 4 # none
 
118
XINE_MSG_CONNECTION_REFUSED    = 5 # (host name)
 
119
XINE_MSG_FILE_NOT_FOUND        = 6 # (file name or mrl)
 
120
XINE_MSG_READ_ERROR            = 7 # (device/file/mrl)
 
121
XINE_MSG_LIBRARY_LOAD_ERROR    = 8 # (library/decoder)
 
122
XINE_MSG_ENCRYPTED_SOURCE      = 9 # none
 
123
XINE_MSG_SECURITY              = 10 # (security message)
 
124
XINE_MSG_AUDIO_OUT_UNAVAILABLE = 11 # none
 
125
XINE_MSG_PERMISSION_ERROR      = 12 # (file name or mrl)
 
126
XINE_MSG_FILE_EMPTY            = 13 # file is empty
 
127
 
 
128
# xine_t *xine_new(void)
 
129
_libxine.xine_new.restype = ctypes.c_void_p
 
130
 
 
131
# void xine_init(xine_t *self)
 
132
_libxine.xine_init.argtypes = [ctypes.c_void_p]
 
133
 
 
134
# void xine_exit(xine_t *self)
 
135
_libxine.xine_exit.argtypes = [ctypes.c_void_p]
 
136
 
 
137
# void xine_config_load(xine_t *self, const char *cfg_filename)
 
138
_libxine.xine_config_load.argtypes = [ctypes.c_void_p, ctypes.c_char_p]
 
139
 
 
140
# const char *xine_get_homedir(void)
 
141
_libxine.xine_get_homedir.restype = ctypes.c_char_p
 
142
 
 
143
# xine_audio_port_t *xine_open_audio_driver(xine_t *self, const char *id,
 
144
#    void *data)
 
145
_libxine.xine_open_audio_driver.argtypes = [ctypes.c_void_p,
 
146
    ctypes.c_char_p, ctypes.c_void_p]
 
147
_libxine.xine_open_audio_driver.restype = ctypes.c_void_p
 
148
 
 
149
# void xine_close_audio_driver(xine_t *self, xine_audio_port_t *driver)
 
150
_libxine.xine_close_audio_driver.argtypes = [ctypes.c_void_p,
 
151
    ctypes.c_void_p]
 
152
 
 
153
# xine_stream_t *xine_stream_new(xine_t *self,
 
154
#    xine_audio_port_t *ao, xine_video_port_t *vo)
 
155
_libxine.xine_stream_new.argtypes = [ctypes.c_void_p, ctypes.c_void_p,
 
156
    ctypes.c_void_p]
 
157
_libxine.xine_stream_new.restype = ctypes.c_void_p
 
158
 
 
159
# void xine_close(xine_sxine_event_create_listener_threadtream_t *stream)
 
160
_libxine.xine_close.argtypes = [ctypes.c_void_p]
 
161
 
 
162
# int xine_open (xine_stream_t *stream, const char *mrl)
 
163
_libxine.xine_open.argtypes = [ctypes.c_void_p, ctypes.c_char_p]
 
164
_libxine.xine_open.restype = ctypes.c_int
 
165
 
 
166
# int xine_play(xine_stream_t *stream, int start_pos, int start_time)
 
167
_libxine.xine_play.argtypes = [ctypes.c_void_p, ctypes.c_int, ctypes.c_int]
 
168
_libxine.xine_play.restype = ctypes.c_int
 
169
 
 
170
# void xine_stop(xine_stream_t *stream)
 
171
_libxine.xine_stop.argtypes = [ctypes.c_void_p]
 
172
 
 
173
# void xine_dispose(xine_stream_t *stream)
 
174
_libxine.xine_dispose.argtypes = [ctypes.c_void_p]
 
175
 
 
176
# xine_event_queue_t *xine_event_new_queue(xine_stream_t *stream)
 
177
_libxine.xine_event_new_queue.argtypes = [ctypes.c_void_p]
 
178
_libxine.xine_event_new_queue.restype = ctypes.c_void_p
 
179
 
 
180
# void xine_event_dispose_queue(xine_event_queue_t *queue)
 
181
_libxine.xine_event_dispose_queue.argtypes = [ctypes.c_void_p]
 
182
 
 
183
# void xine_event_create_listener_thread(xine_event_queue_t *queue,
 
184
#    xine_event_listener_cb_t callback,
 
185
#    void *user_data)
 
186
_libxine.xine_event_create_listener_thread.argtypes = [ctypes.c_void_p,
 
187
    ctypes.c_void_p, ctypes.c_void_p]
 
188
 
 
189
_libxine.xine_usec_sleep.argtypes = [ctypes.c_int]
 
190
 
 
191
_libxine.xine_set_param.argtypes = [ctypes.c_void_p, ctypes.c_int,
 
192
    ctypes.c_int]
 
193
 
 
194
_libxine.xine_get_param.argtypes = [ctypes.c_void_p, ctypes.c_int]
 
195
_libxine.xine_get_param.restype = ctypes.c_int
 
196
 
 
197
_libxine.xine_get_meta_info.argtypes = [ctypes.c_void_p, ctypes.c_int]
 
198
_libxine.xine_get_meta_info.restype = ctypes.c_char_p
 
199
 
 
200
_libxine.xine_get_status.argtypes = [ctypes.c_void_p]
 
201
_libxine.xine_get_status.restype = ctypes.c_int
 
202
 
 
203
_libxine.xine_get_pos_length.argtypes = [ctypes.c_void_p,
 
204
    ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.c_int),
 
205
    ctypes.POINTER(ctypes.c_int)]
 
206
 
 
207
_libxine.xine_get_version_string.restype = ctypes.c_char_p
 
208
 
 
209
_libxine.xine_get_file_extensions.argtypes = [ctypes.c_void_p]
 
210
_libxine.xine_get_file_extensions.restype = ctypes.c_char_p
 
211
 
 
212
_libxine.xine_get_mime_types.argtypes = [ctypes.c_void_p]
 
213
_libxine.xine_get_mime_types.restype = ctypes.c_char_p
 
214
 
 
215
_libxine.xine_list_input_plugins.argtypes = [ctypes.c_void_p]
 
216
_libxine.xine_list_input_plugins.restype = ctypes.POINTER(ctypes.c_char_p)
 
217
 
 
218
_libxine.xine_check_version.argtypes = [ctypes.c_int, ctypes.c_int, ctypes.c_int]
 
219
_libxine.xine_check_version.restype = ctypes.c_int;
 
220
 
 
221
# copy functions from the library
 
222
module = sys.modules[__name__]
 
223
for name in dir(_libxine):
 
224
    if name.startswith('xine_'):
 
225
        setattr(module, name, getattr(_libxine, name))
 
226
 
 
227
_callbacks = []
 
228
def xine_event_create_listener_thread(queue, callback, user_data):
 
229
    cb = xine_event_listener_cb_t(callback)
 
230
    _callbacks.append(cb)
 
231
    _libxine.xine_event_create_listener_thread(queue, cb, user_data)
 
232
 
 
233
def xine_get_pos_length(stream):
 
234
    _pos_stream = ctypes.c_int()
 
235
    _pos_time = ctypes.c_int()
 
236
    _length_time = ctypes.c_int()
 
237
    result = _libxine.xine_get_pos_length(stream, ctypes.byref(_pos_stream),
 
238
        ctypes.byref(_pos_time), ctypes.byref(_length_time))
 
239
    if result:
 
240
        return _pos_stream.value, _pos_time.value, _length_time.value
 
241
    else:
 
242
        return 0, 0, 0