1 /* This file is part of the KDE project
2 Copyright (C) 2007 Matthias Kretz <kretz@kde.org>
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
21 #include "xinethread.h"
22 #include <QtCore/QMutexLocker>
23 #include <QtCore/QTimer>
24 #include <QtCore/QCoreApplication>
25 #include "xineengine.h"
26 #include "xinestream.h"
34 XineThread::XineThread()
36 m_eventLoopReady(false)
40 XineThread::~XineThread()
44 // called from main thread
45 // should never be called from ByteStream
46 void XineThread::waitForEventLoop()
49 if (!m_eventLoopReady
) {
50 m_waitingForEventLoop
.wait(&m_mutex
);
55 XineStream
*XineThread::newStream()
57 XineThread
*that
= XineEngine::thread();
59 QMutexLocker
locker(&that
->m_mutex
);
60 Q_ASSERT(that
->m_newStream
== 0);
61 QCoreApplication::postEvent(that
, new QEVENT(NewStream
));
62 that
->m_waitingForNewStream
.wait(&that
->m_mutex
);
63 Q_ASSERT(that
->m_newStream
);
64 XineStream
*ret
= that
->m_newStream
;
65 that
->m_newStream
= 0;
69 void XineThread::quit()
71 foreach (QObject
*child
, children()) {
77 bool XineThread::event(QEvent
*e
)
80 case Event::NewStream
:
83 Q_ASSERT(m_newStream
== 0);
84 m_newStream
= new XineStream
;
85 m_newStream
->moveToThread(this);
87 m_waitingForNewStream
.wakeAll();
91 kDebug(610) << "XineThread Rewire event:";
93 RewireEvent
*ev
= static_cast<RewireEvent
*>(e
);
94 foreach (WireCall wire
, ev
->wireCalls
) {
95 kDebug(610) << " " << wire
.source
<< " -> " << wire
.sink
;
97 wire
.source
->assert();
98 wire
.sink
->rewireTo(wire
.source
.data());
103 return QThread::event(e
);
107 void XineThread::run()
109 Q_ASSERT(QThread::currentThread() == this);
110 QTimer::singleShot(0, this, SLOT(eventLoopReady()));
112 m_eventLoopReady
= false;
113 // there should be no remaining XineStreams
114 const QList
<QObject
*> c
= children();
115 foreach (QObject
*obj
, c
) {
116 XineStream
*xs
= qobject_cast
<XineStream
*>(obj
);
124 void XineThread::eventLoopReady()
127 m_eventLoopReady
= true;
129 m_waitingForEventLoop
.wakeAll();
133 } // namespace Phonon
135 #include "xinethread.moc"
136 // vim: sw=4 sts=4 et tw=100