1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
|
#define HAVE_XINE
#ifdef HAVE_XINE
/* yes, it's xine, not Xine. But eServicexine looks odd. */
#include <lib/base/eerror.h>
#include <lib/base/object.h>
#include <lib/base/ebase.h>
#include <string>
#include <lib/service/servicexine.h>
#include <lib/service/service.h>
#include <lib/base/init_num.h>
#include <lib/base/init.h>
static xine_t *xine; /* TODO: move this into a static class */
// eServiceFactoryXine
eServiceFactoryXine::eServiceFactoryXine()
{
ePtr<eServiceCenter> sc;
eServiceCenter::getPrivInstance(sc);
if (sc)
sc->addServiceFactory(eServiceFactoryXine::id, this);
m_service_info = new eStaticServiceXineInfo();
}
eServiceFactoryXine::~eServiceFactoryXine()
{
ePtr<eServiceCenter> sc;
eServiceCenter::getPrivInstance(sc);
if (sc)
sc->removeServiceFactory(eServiceFactoryXine::id);
}
DEFINE_REF(eServiceFactoryXine)
// iServiceHandler
RESULT eServiceFactoryXine::play(const eServiceReference &ref, ePtr<iPlayableService> &ptr)
{
// check resources...
ptr = new eServiceXine(ref.path.c_str());
return 0;
}
RESULT eServiceFactoryXine::record(const eServiceReference &ref, ePtr<iRecordableService> &ptr)
{
ptr=0;
return -1;
}
RESULT eServiceFactoryXine::list(const eServiceReference &, ePtr<iListableService> &ptr)
{
ptr=0;
return -1;
}
RESULT eServiceFactoryXine::info(const eServiceReference &ref, ePtr<iStaticServiceInformation> &ptr)
{
ptr = m_service_info;
return 0;
}
RESULT eServiceFactoryXine::offlineOperations(const eServiceReference &, ePtr<iServiceOfflineOperations> &ptr)
{
ptr = 0;
return -1;
}
// eStaticServiceXineInfo
DEFINE_REF(eStaticServiceXineInfo)
eStaticServiceXineInfo::eStaticServiceXineInfo()
{
}
RESULT eStaticServiceXineInfo::getName(const eServiceReference &ref, std::string &name)
{
size_t last = ref.path.rfind('/');
if (last != std::string::npos)
name = ref.path.substr(last+1);
else
name = ref.path;
return 0;
}
int eStaticServiceXineInfo::getLength(const eServiceReference &ref)
{
return -1;
}
// eServiceXine
eServiceXine::eServiceXine(const char *filename): m_filename(filename), m_pump(eApp, 1)
{
m_state = stError;
stream = 0;
event_queue = 0;
ao_port = 0;
vo_port = 0;
if ((vo_port = xine_open_video_driver(xine, "fb", XINE_VISUAL_TYPE_FB, NULL)) == NULL)
{
eWarning("cannot open xine video driver");
}
if ((ao_port = xine_open_audio_driver(xine , "alsa", NULL)) == NULL)
{
eWarning("cannot open xine audio driver");
}
stream = xine_stream_new(xine, ao_port, vo_port);
event_queue = xine_event_new_queue(stream);
xine_event_create_listener_thread(event_queue, eventListenerWrap, this);
// CONNECT(m_pump.recv_msg, eServiceXine::gstPoll);
m_state = stIdle;
}
eServiceXine::~eServiceXine()
{
if (m_state == stRunning)
stop();
if (stream)
xine_close(stream);
if (event_queue)
xine_event_dispose_queue(event_queue);
if (stream)
xine_dispose(stream);
if (ao_port)
xine_close_audio_driver(xine, ao_port);
if (vo_port)
xine_close_video_driver(xine, vo_port);
}
DEFINE_REF(eServiceXine);
void eServiceXine::eventListenerWrap(void *user_data, const xine_event_t *event)
{
eServiceXine *e = (eServiceXine*)user_data;
e->eventListener(event);
}
void eServiceXine::eventListener(const xine_event_t *event)
{
eDebug("handle %d", event->type);
switch(event->type) {
case XINE_EVENT_UI_PLAYBACK_FINISHED:
break;
}
}
RESULT eServiceXine::connectEvent(const Slot2<void,iPlayableService*,int> &event, ePtr<eConnection> &connection)
{
connection = new eConnection((iPlayableService*)this, m_event.connect(event));
return 0;
}
RESULT eServiceXine::start()
{
if (m_state == stError)
return -1;
assert(m_state == stIdle);
assert(stream);
if (!xine_open(stream, m_filename.c_str()))
{
eWarning("xine_open failed!");
return -1;
}
if (!xine_play(stream, 0, 0))
{
eWarning("xine_play failed!");
return -1;
}
m_state = stRunning;
m_event(this, evStart);
return 0;
}
RESULT eServiceXine::stop()
{
if (m_state == stError)
return -1;
assert(m_state != stIdle);
assert(stream);
if (m_state == stStopped)
return -1;
printf("Xine: %s stop\n", m_filename.c_str());
xine_stop(stream);
// STOP
m_state = stStopped;
return 0;
}
RESULT eServiceXine::setTarget(int target)
{
return -1;
}
RESULT eServiceXine::pause(ePtr<iPauseableService> &ptr)
{
ptr=this;
return 0;
}
RESULT eServiceXine::setSlowMotion(int ratio)
{
return -1;
}
RESULT eServiceXine::setFastForward(int ratio)
{
return -1;
}
// iPausableService
RESULT eServiceXine::pause()
{
// PAUSE
return 0;
}
RESULT eServiceXine::unpause()
{
// PLAY
return 0;
}
/* iSeekableService */
RESULT eServiceXine::seek(ePtr<iSeekableService> &ptr)
{
ptr = this;
return 0;
}
RESULT eServiceXine::getLength(pts_t &pts)
{
// LENGTH
return 0;
}
RESULT eServiceXine::seekTo(pts_t to)
{
// SEEK
return 0;
}
RESULT eServiceXine::seekRelative(int direction, pts_t to)
{
// SEEK RELATIVE
return 0;
}
RESULT eServiceXine::getPlayPosition(pts_t &pts)
{
// GET POSITION
return 0;
}
RESULT eServiceXine::setTrickmode(int trick)
{
/* trickmode currently doesn't make any sense for us. */
return -1;
}
RESULT eServiceXine::isCurrentlySeekable()
{
return 1;
}
RESULT eServiceXine::info(ePtr<iServiceInformation>&i)
{
i = this;
return 0;
}
RESULT eServiceXine::getName(std::string &name)
{
name = "xine File: " + m_filename;
return 0;
}
int eServiceXine::getInfo(int w)
{
switch (w)
{
case sTitle:
case sArtist:
case sAlbum:
case sComment:
case sTracknumber:
case sGenre:
return resIsString;
default:
return resNA;
}
}
std::string eServiceXine::getInfoString(int w)
{
return "";
}
class eXine
{
public:
eXine()
{
/* this should be done once. */
if(!xine_check_version(1, 1, 0))
{
int major, minor, sub;
xine_get_version (&major, &minor, &sub);
eWarning("Require xine library version 1.1.0, found %d.%d.%d.\n",
major, minor,sub);
return;
} else {
int major, minor, sub;
eDebug("Built with xine library %d.%d.%d (%s)\n",
XINE_MAJOR_VERSION, XINE_MINOR_VERSION, XINE_SUB_VERSION, XINE_VERSION);
xine_get_version (&major, &minor, &sub);
eDebug("Found xine library version: %d.%d.%d (%s).\n",
major, minor, sub, xine_get_version_string());
}
xine = xine_new();
xine_engine_set_param(xine, XINE_ENGINE_PARAM_VERBOSITY, 1);
xine_init(xine);
}
~eXine()
{
if (xine)
xine_exit(xine);
}
};
eAutoInitP0<eXine> init_eXine(eAutoInitNumbers::service, "libxine");
eAutoInitPtr<eServiceFactoryXine> init_eServiceFactoryXine(eAutoInitNumbers::service+1, "eServiceFactoryXine");
#else
#warning xine not available
#endif
|