| 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 | 
 | 
|---|
| 19 | #ifndef PHONON_MMF_ABSTRACTMEDIAPLAYER_H
 | 
|---|
| 20 | #define PHONON_MMF_ABSTRACTMEDIAPLAYER_H
 | 
|---|
| 21 | 
 | 
|---|
| 22 | #include <QTimer>
 | 
|---|
| 23 | #include <QScopedPointer>
 | 
|---|
| 24 | #include <e32std.h>
 | 
|---|
| 25 | #include "abstractplayer.h"
 | 
|---|
| 26 | #ifdef PHONON_MMF_PROGRESSIVE_DOWNLOAD
 | 
|---|
| 27 | #   include "download.h"
 | 
|---|
| 28 | #endif
 | 
|---|
| 29 | 
 | 
|---|
| 30 | class RFile;
 | 
|---|
| 31 | 
 | 
|---|
| 32 | QT_BEGIN_NAMESPACE
 | 
|---|
| 33 | 
 | 
|---|
| 34 | namespace Phonon
 | 
|---|
| 35 | {
 | 
|---|
| 36 | namespace MMF
 | 
|---|
| 37 | {
 | 
|---|
| 38 | class AudioOutput;
 | 
|---|
| 39 | class MediaObject;
 | 
|---|
| 40 | 
 | 
|---|
| 41 | /**
 | 
|---|
| 42 |  * Interface via which MMF client APIs for both audio and video can be
 | 
|---|
| 43 |  * accessed.
 | 
|---|
| 44 |  */
 | 
|---|
| 45 | class AbstractMediaPlayer : public AbstractPlayer
 | 
|---|
| 46 | {
 | 
|---|
| 47 |     Q_OBJECT
 | 
|---|
| 48 | 
 | 
|---|
| 49 | protected:
 | 
|---|
| 50 |     AbstractMediaPlayer(MediaObject *parent, const AbstractPlayer *player);
 | 
|---|
| 51 | 
 | 
|---|
| 52 | public:
 | 
|---|
| 53 |     virtual void open();
 | 
|---|
| 54 |     virtual void close();
 | 
|---|
| 55 | 
 | 
|---|
| 56 |     // MediaObjectInterface
 | 
|---|
| 57 |     virtual void play();
 | 
|---|
| 58 |     virtual void pause();
 | 
|---|
| 59 |     virtual void stop();
 | 
|---|
| 60 |     virtual void seek(qint64 milliseconds);
 | 
|---|
| 61 |     virtual bool isSeekable() const;
 | 
|---|
| 62 |     virtual qint64 currentTime() const;
 | 
|---|
| 63 |     virtual void volumeChanged(qreal volume);
 | 
|---|
| 64 | 
 | 
|---|
| 65 | protected:
 | 
|---|
| 66 |     // AbstractPlayer
 | 
|---|
| 67 |     virtual void doSetTickInterval(qint32 interval);
 | 
|---|
| 68 |     virtual Phonon::State phononState(PrivateState state) const;
 | 
|---|
| 69 |     virtual void changeState(PrivateState newState);
 | 
|---|
| 70 | 
 | 
|---|
| 71 |     virtual void doPlay() = 0;
 | 
|---|
| 72 |     virtual void doPause() = 0;
 | 
|---|
| 73 |     virtual void doStop() = 0;
 | 
|---|
| 74 |     virtual void doSeek(qint64 pos) = 0;
 | 
|---|
| 75 |     virtual int setDeviceVolume(int mmfVolume) = 0;
 | 
|---|
| 76 |     virtual int openFile(const QString &fileName) = 0;
 | 
|---|
| 77 |     virtual int openFile(RFile& file) = 0;
 | 
|---|
| 78 |     virtual int openUrl(const QString& url, int iap) = 0;
 | 
|---|
| 79 |     virtual int openDescriptor(const TDesC8 &des) = 0;
 | 
|---|
| 80 |     virtual int bufferStatus() const = 0;
 | 
|---|
| 81 |     virtual void doClose() = 0;
 | 
|---|
| 82 | 
 | 
|---|
| 83 |     void updateMetaData();
 | 
|---|
| 84 |     virtual qint64 getCurrentTime() const = 0;
 | 
|---|
| 85 |     virtual int numberOfMetaDataEntries() const = 0;
 | 
|---|
| 86 |     virtual QPair<QString, QString> metaDataEntry(int index) const = 0;
 | 
|---|
| 87 | 
 | 
|---|
| 88 | protected:
 | 
|---|
| 89 |     void bufferingStarted();
 | 
|---|
| 90 |     void bufferingComplete();
 | 
|---|
| 91 |     void maxVolumeChanged(int maxVolume);
 | 
|---|
| 92 |     void loadingComplete(int error);
 | 
|---|
| 93 |     void playbackComplete(int error);
 | 
|---|
| 94 | 
 | 
|---|
| 95 |     static qint64 toMilliSeconds(const TTimeIntervalMicroSeconds &);
 | 
|---|
| 96 | 
 | 
|---|
| 97 |     bool isProgressiveDownload() const;
 | 
|---|
| 98 |     bool progressiveDownloadStalled() const;
 | 
|---|
| 99 | 
 | 
|---|
| 100 | private:
 | 
|---|
| 101 |     void startPositionTimer();
 | 
|---|
| 102 |     void stopPositionTimer();
 | 
|---|
| 103 |     void startBufferStatusTimer();
 | 
|---|
| 104 |     void stopBufferStatusTimer();
 | 
|---|
| 105 |     void stopTimers();
 | 
|---|
| 106 |     void doVolumeChanged();
 | 
|---|
| 107 |     void emitMarksIfReached(qint64 position);
 | 
|---|
| 108 |     void resetMarksIfRewound();
 | 
|---|
| 109 |     void startPlayback();
 | 
|---|
| 110 |     void setProgressiveDownloadStalled();
 | 
|---|
| 111 | 
 | 
|---|
| 112 |     enum Pending {
 | 
|---|
| 113 |         NothingPending,
 | 
|---|
| 114 |         PausePending,
 | 
|---|
| 115 |         PlayPending
 | 
|---|
| 116 |     };
 | 
|---|
| 117 | 
 | 
|---|
| 118 |     void setPending(Pending pending);
 | 
|---|
| 119 | 
 | 
|---|
| 120 | private Q_SLOTS:
 | 
|---|
| 121 |     void positionTick();
 | 
|---|
| 122 |     void bufferStatusTick();
 | 
|---|
| 123 | #ifdef PHONON_MMF_PROGRESSIVE_DOWNLOAD
 | 
|---|
| 124 |     void downloadLengthChanged(qint64);
 | 
|---|
| 125 |     void downloadStateChanged(Download::State);
 | 
|---|
| 126 | #endif
 | 
|---|
| 127 | 
 | 
|---|
| 128 | private:
 | 
|---|
| 129 |     MediaObject *const          m_parent;
 | 
|---|
| 130 | 
 | 
|---|
| 131 |     Pending                     m_pending;
 | 
|---|
| 132 | 
 | 
|---|
| 133 |     QScopedPointer<QTimer>      m_positionTimer;
 | 
|---|
| 134 |     qint64                      m_position;
 | 
|---|
| 135 | 
 | 
|---|
| 136 |     QScopedPointer<QTimer>      m_bufferStatusTimer;
 | 
|---|
| 137 |     PrivateState                m_stateBeforeBuffering;
 | 
|---|
| 138 | 
 | 
|---|
| 139 |     int                         m_mmfMaxVolume;
 | 
|---|
| 140 | 
 | 
|---|
| 141 |     bool                        m_prefinishMarkSent;
 | 
|---|
| 142 |     bool                        m_aboutToFinishSent;
 | 
|---|
| 143 | 
 | 
|---|
| 144 |     // Used for playback of resource files
 | 
|---|
| 145 |     TPtrC8                      m_buffer;
 | 
|---|
| 146 | 
 | 
|---|
| 147 | #ifdef PHONON_MMF_PROGRESSIVE_DOWNLOAD
 | 
|---|
| 148 |     Download                    *m_download;
 | 
|---|
| 149 |     bool                        m_downloadStalled;
 | 
|---|
| 150 | #endif
 | 
|---|
| 151 | 
 | 
|---|
| 152 |     QMultiMap<QString, QString> m_metaData;
 | 
|---|
| 153 | 
 | 
|---|
| 154 | };
 | 
|---|
| 155 | }
 | 
|---|
| 156 | }
 | 
|---|
| 157 | 
 | 
|---|
| 158 | QT_END_NAMESPACE
 | 
|---|
| 159 | 
 | 
|---|
| 160 | #endif
 | 
|---|
| 161 | 
 | 
|---|