| 1 |
/* This file is part of the KDE project. |
| 2 |
|
| 3 |
Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
| 4 |
|
| 5 |
This library is free software: you can redistribute it and/or modify |
| 6 |
it under the terms of the GNU Lesser General Public License as published by |
| 7 |
the Free Software Foundation, either version 2.1 or 3 of the License. |
| 8 |
|
| 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 |
| 12 |
GNU Lesser General Public License for more details. |
| 13 |
|
| 14 |
You should have received a copy of the GNU Lesser General Public License |
| 15 |
along with this library. If not, see <http://www.gnu.org/licenses/>. |
| 16 |
*/ |
| 17 |
|
| 18 |
#ifndef PHONON_MEDIAOBJECT_H |
| 19 |
#define PHONON_MEDIAOBJECT_H |
| 20 |
|
| 21 |
#include <phonon/mediaobjectinterface.h> |
| 22 |
|
| 23 |
#include <QtCore/QHash> |
| 24 |
#include <QtCore/QObject> |
| 25 |
#include <QtCore/QQueue> |
| 26 |
#include <QtCore/QBasicTimer> |
| 27 |
#include <QtCore/QWaitCondition> |
| 28 |
#include <QtCore/QMutex> |
| 29 |
#include <QtCore/QThread> |
| 30 |
#include <QFile> |
| 31 |
#include <QIODevice> |
| 32 |
|
| 33 |
#include <windows.h> |
| 34 |
|
| 35 |
|
| 36 |
QT_BEGIN_NAMESPACE |
| 37 |
|
| 38 |
namespace Phonon |
| 39 |
{ |
| 40 |
class MediaSource; |
| 41 |
|
| 42 |
namespace WaveOut |
| 43 |
{ |
| 44 |
class WorkerThread; |
| 45 |
class AudioOutput; |
| 46 |
|
| 47 |
class MediaObject : public QObject, public Phonon::MediaObjectInterface |
| 48 |
{ |
| 49 |
Q_OBJECT |
| 50 |
Q_INTERFACES(Phonon::MediaObjectInterface) |
| 51 |
|
| 52 |
public: |
| 53 |
MediaObject(QObject *parent); |
| 54 |
~MediaObject(); |
| 55 |
Phonon::State state() const; |
| 56 |
bool hasVideo() const; |
| 57 |
bool isSeekable() const; |
| 58 |
qint64 currentTime() const; |
| 59 |
qint32 tickInterval() const; |
| 60 |
|
| 61 |
void setTickInterval(qint32 newTickInterval); |
| 62 |
void play(); |
| 63 |
void pause(); |
| 64 |
void stop(); |
| 65 |
void seek(qint64 time); |
| 66 |
|
| 67 |
QString errorString() const; |
| 68 |
Phonon::ErrorType errorType() const; |
| 69 |
qint64 totalTime() const; |
| 70 |
qint32 prefinishMark() const; |
| 71 |
void setPrefinishMark(qint32 newPrefinishMark); |
| 72 |
qint32 transitionTime() const; |
| 73 |
void setTransitionTime(qint32); |
| 74 |
qint64 remainingTime() const; |
| 75 |
MediaSource source() const; |
| 76 |
void setSource(const MediaSource &source); |
| 77 |
void setNextSource(const MediaSource &source); |
| 78 |
|
| 79 |
|
| 80 |
Q_SIGNALS: |
| 81 |
void stateChanged(Phonon::State newstate, Phonon::State oldstate); |
| 82 |
void tick(qint64 time); |
| 83 |
void metaDataChanged(QMultiMap<QString, QString>); |
| 84 |
void seekableChanged(bool); |
| 85 |
void hasVideoChanged(bool); |
| 86 |
void bufferStatus(int); |
| 87 |
void finished(); |
| 88 |
void prefinishMarkReached(qint32); |
| 89 |
void aboutToFinish(); |
| 90 |
void totalTimeChanged(qint64 length) const; |
| 91 |
void currentSourceChanged(const MediaSource &); |
| 92 |
void outOfData(QIODevice *ioStream, QByteArray *buffer, bool *m_bufferingFinshed); |
| 93 |
|
| 94 |
protected: |
| 95 |
void setAudioOutput(QObject *audioOutput); |
| 96 |
|
| 97 |
private Q_SLOTS: |
| 98 |
void setVolume(qreal newVolume); |
| 99 |
|
| 100 |
private: |
| 101 |
bool m_nextBufferIndex; |
| 102 |
bool prepareBuffers(); |
| 103 |
void unPrepareBuffers(); |
| 104 |
bool getWaveOutDevice(); |
| 105 |
bool openWaveFile(QString fileName); |
| 106 |
bool readHeader(); |
| 107 |
bool boolUpdateBuffer(); |
| 108 |
bool fillBuffers(); |
| 109 |
void swapBuffers(); |
| 110 |
void setState(Phonon::State newState); |
| 111 |
void setError(ErrorType errorType, QString errorMessage); |
| 112 |
void deleteValidWaveOutDevice(); |
| 113 |
void playBuffer(WAVEHDR *waveHeader); |
| 114 |
|
| 115 |
static void QT_WIN_CALLBACK WaveOutCallBack(HWAVEOUT hWaveOut, UINT uMsg, DWORD dwInstance, DWORD dwParam1, DWORD dwParam2); |
| 116 |
|
| 117 |
struct { |
| 118 |
WAVEHDR *waveHeader; |
| 119 |
QByteArray data; |
| 120 |
} m_soundBuffer1, m_soundBuffer2; |
| 121 |
|
| 122 |
WAVEFORMATEX m_waveFormatEx; |
| 123 |
HWAVEOUT m_hWaveOut; |
| 124 |
|
| 125 |
QFile *m_file; |
| 126 |
QIODevice *m_stream; |
| 127 |
QString m_errorString; |
| 128 |
|
| 129 |
WorkerThread *m_thread; |
| 130 |
|
| 131 |
MediaSource m_source; |
| 132 |
MediaSource m_nextSource; |
| 133 |
AudioOutput *m_audioOutput; |
| 134 |
ErrorType m_errorType; |
| 135 |
|
| 136 |
qreal m_volume; |
| 137 |
qint64 m_mediaSize; |
| 138 |
qint64 m_totalTime; |
| 139 |
qint64 m_currentTime; |
| 140 |
qint64 m_transitionTime; |
| 141 |
qint64 m_prefinishMark; |
| 142 |
qint64 m_tickIntervalResolution; |
| 143 |
qint32 m_tickInterval; |
| 144 |
qint32 m_tick; |
| 145 |
Phonon::State m_state; |
| 146 |
|
| 147 |
bool m_bufferingFinished; |
| 148 |
bool m_paused; |
| 149 |
bool m_stopped; |
| 150 |
bool m_hasNextSource; |
| 151 |
bool m_hasSource; |
| 152 |
bool m_sourceIsValid; |
| 153 |
bool m_bufferPrepared; |
| 154 |
|
| 155 |
friend class Backend; |
| 156 |
}; |
| 157 |
} |
| 158 |
} |
| 159 |
|
| 160 |
QT_END_NAMESPACE |
| 161 |
|
| 162 |
#endif // PHONON_MEDIAOBJECT_H |