4 /* yes, it's xine, not Xine. But eServicexine looks odd. */
6 #include <lib/base/eerror.h>
7 #include <lib/base/object.h>
8 #include <lib/base/ebase.h>
10 #include <lib/service/servicexine.h>
11 #include <lib/service/service.h>
12 #include <lib/base/init_num.h>
13 #include <lib/base/init.h>
15 static xine_t *xine; /* TODO: move this into a static class */
17 // eServiceFactoryXine
19 eServiceFactoryXine::eServiceFactoryXine()
21 ePtr<eServiceCenter> sc;
23 eServiceCenter::getPrivInstance(sc);
25 sc->addServiceFactory(eServiceFactoryXine::id, this);
27 m_service_info = new eStaticServiceXineInfo();
30 eServiceFactoryXine::~eServiceFactoryXine()
32 ePtr<eServiceCenter> sc;
34 eServiceCenter::getPrivInstance(sc);
36 sc->removeServiceFactory(eServiceFactoryXine::id);
39 DEFINE_REF(eServiceFactoryXine)
42 RESULT eServiceFactoryXine::play(const eServiceReference &ref, ePtr<iPlayableService> &ptr)
45 ptr = new eServiceXine(ref.path.c_str());
49 RESULT eServiceFactoryXine::record(const eServiceReference &ref, ePtr<iRecordableService> &ptr)
55 RESULT eServiceFactoryXine::list(const eServiceReference &, ePtr<iListableService> &ptr)
61 RESULT eServiceFactoryXine::info(const eServiceReference &ref, ePtr<iStaticServiceInformation> &ptr)
67 RESULT eServiceFactoryXine::offlineOperations(const eServiceReference &, ePtr<iServiceOfflineOperations> &ptr)
74 // eStaticServiceXineInfo
77 DEFINE_REF(eStaticServiceXineInfo)
79 eStaticServiceXineInfo::eStaticServiceXineInfo()
83 RESULT eStaticServiceXineInfo::getName(const eServiceReference &ref, std::string &name)
85 size_t last = ref.path.rfind('/');
86 if (last != std::string::npos)
87 name = ref.path.substr(last+1);
93 int eStaticServiceXineInfo::getLength(const eServiceReference &ref)
100 eServiceXine::eServiceXine(const char *filename): m_filename(filename), m_pump(eApp, 1)
109 if ((vo_port = xine_open_video_driver(xine, "fb", XINE_VISUAL_TYPE_FB, NULL)) == NULL)
111 eWarning("cannot open xine video driver");
114 if ((ao_port = xine_open_audio_driver(xine , "alsa", NULL)) == NULL)
116 eWarning("cannot open xine audio driver");
118 stream = xine_stream_new(xine, ao_port, vo_port);
119 event_queue = xine_event_new_queue(stream);
120 xine_event_create_listener_thread(event_queue, eventListenerWrap, this);
122 // CONNECT(m_pump.recv_msg, eServiceXine::gstPoll);
126 eServiceXine::~eServiceXine()
128 if (m_state == stRunning)
134 xine_event_dispose_queue(event_queue);
136 xine_dispose(stream);
138 xine_close_audio_driver(xine, ao_port);
140 xine_close_video_driver(xine, vo_port);
143 DEFINE_REF(eServiceXine);
145 void eServiceXine::eventListenerWrap(void *user_data, const xine_event_t *event)
147 eServiceXine *e = (eServiceXine*)user_data;
148 e->eventListener(event);
151 void eServiceXine::eventListener(const xine_event_t *event)
153 eDebug("handle %d", event->type);
154 switch(event->type) {
155 case XINE_EVENT_UI_PLAYBACK_FINISHED:
160 RESULT eServiceXine::connectEvent(const Slot2<void,iPlayableService*,int> &event, ePtr<eConnection> &connection)
162 connection = new eConnection((iPlayableService*)this, m_event.connect(event));
166 RESULT eServiceXine::start()
168 if (m_state == stError)
171 assert(m_state == stIdle);
174 if (!xine_open(stream, m_filename.c_str()))
176 eWarning("xine_open failed!");
180 if (!xine_play(stream, 0, 0))
182 eWarning("xine_play failed!");
188 m_event(this, evStart);
192 RESULT eServiceXine::stop()
194 if (m_state == stError)
197 assert(m_state != stIdle);
199 if (m_state == stStopped)
201 printf("Xine: %s stop\n", m_filename.c_str());
208 RESULT eServiceXine::setTarget(int target)
213 RESULT eServiceXine::pause(ePtr<iPauseableService> &ptr)
219 RESULT eServiceXine::setSlowMotion(int ratio)
224 RESULT eServiceXine::setFastForward(int ratio)
230 RESULT eServiceXine::pause()
236 RESULT eServiceXine::unpause()
242 /* iSeekableService */
243 RESULT eServiceXine::seek(ePtr<iSeekableService> &ptr)
249 RESULT eServiceXine::getLength(pts_t &pts)
255 RESULT eServiceXine::seekTo(pts_t to)
261 RESULT eServiceXine::seekRelative(int direction, pts_t to)
267 RESULT eServiceXine::getPlayPosition(pts_t &pts)
273 RESULT eServiceXine::setTrickmode(int trick)
275 /* trickmode currently doesn't make any sense for us. */
279 RESULT eServiceXine::isCurrentlySeekable()
284 RESULT eServiceXine::info(ePtr<iServiceInformation>&i)
290 RESULT eServiceXine::getName(std::string &name)
292 name = "xine File: " + m_filename;
296 int eServiceXine::getInfo(int w)
313 std::string eServiceXine::getInfoString(int w)
323 /* this should be done once. */
325 if(!xine_check_version(1, 1, 0))
327 int major, minor, sub;
328 xine_get_version (&major, &minor, &sub);
329 eWarning("Require xine library version 1.1.0, found %d.%d.%d.\n",
333 int major, minor, sub;
334 eDebug("Built with xine library %d.%d.%d (%s)\n",
335 XINE_MAJOR_VERSION, XINE_MINOR_VERSION, XINE_SUB_VERSION, XINE_VERSION);
337 xine_get_version (&major, &minor, &sub);
339 eDebug("Found xine library version: %d.%d.%d (%s).\n",
340 major, minor, sub, xine_get_version_string());
344 xine_engine_set_param(xine, XINE_ENGINE_PARAM_VERBOSITY, 1);
354 eAutoInitP0<eXine> init_eXine(eAutoInitNumbers::service, "libxine");
355 eAutoInitPtr<eServiceFactoryXine> init_eServiceFactoryXine(eAutoInitNumbers::service+1, "eServiceFactoryXine");
357 #warning xine not available