File indexing completed on 2024-05-05 04:44:40
0001 /* This file is part of the KDE project 0002 Copyright (C) 2007-2008 Matthias Kretz <kretz@kde.org> 0003 0004 This library is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Lesser General Public 0006 License as published by the Free Software Foundation; either 0007 version 2.1 of the License, or (at your option) version 3, or any 0008 later version accepted by the membership of KDE e.V. (or its 0009 successor approved by the membership of KDE e.V.), Nokia Corporation 0010 (or its successors, if any) and the KDE Free Qt Foundation, which shall 0011 act as a proxy defined in Section 6 of version 3 of the license. 0012 0013 This library is distributed in the hope that it will be useful, 0014 but WITHOUT ANY WARRANTY; without even the implied warranty of 0015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0016 Lesser General Public License for more details. 0017 0018 You should have received a copy of the GNU Lesser General Public 0019 License along with this library. If not, see <http://www.gnu.org/licenses/>. 0020 0021 */ 0022 0023 #ifndef PHONON_ABSTRACTMEDIASTREAM2_H 0024 #define PHONON_ABSTRACTMEDIASTREAM2_H 0025 0026 #include "abstractmediastream.h" 0027 0028 0029 class QByteArray; 0030 0031 namespace Phonon 0032 { 0033 class MediaObject; 0034 class AbstractMediaStream2Private; 0035 0036 /** \class AbstractMediaStream2 abstractmediastream2.h phonon/AbstractMediaStream2 0037 * \brief Base class for custom media data streams. 0038 * 0039 * Implement this class to provide a custom data stream to the backend. The class supports both, the 0040 * push and the pull model. 0041 * 0042 * Push: 0043 * \code 0044 * PushStream::PushStream(QObject *parent) 0045 * : AbstractMediaStream2(parent), m_timer(new QTimer(this)) 0046 * { 0047 * setStreamSize(getMediaStreamSize()); 0048 * 0049 * connect(m_timer, SIGNAL(timeout()), SLOT(moreData())); 0050 * m_timer->setInterval(0); 0051 * } 0052 * 0053 * void PushStream::moreData() 0054 * { 0055 * const QByteArray data = getMediaData(); 0056 * if (data.isEmpty()) { 0057 * endOfData(); 0058 * } else { 0059 * writeData(data); 0060 * } 0061 * } 0062 * 0063 * void PushStream::needData() 0064 * { 0065 * m_timer->start(); 0066 * moreData(); 0067 * } 0068 * 0069 * void PushStream::enoughData() 0070 * { 0071 * m_timer->stop(); 0072 * } 0073 * \endcode 0074 * 0075 * Pull: 0076 * \code 0077 * PullStream::PullStream(QObject *parent) 0078 * : AbstractMediaStream2(parent) 0079 * { 0080 * setStreamSize(getMediaStreamSize()); 0081 * } 0082 * 0083 * void PullStream::needData() 0084 * { 0085 * const QByteArray data = getMediaData(); 0086 * if (data.isEmpty()) { 0087 * endOfData(); 0088 * } else { 0089 * writeData(data); 0090 * } 0091 * } 0092 * \endcode 0093 * 0094 * \ingroup Playback 0095 * \author Matthias Kretz <kretz@kde.org> 0096 */ 0097 class PHONON_EXPORT AbstractMediaStream2 : public AbstractMediaStream 0098 { 0099 Q_OBJECT 0100 Q_DECLARE_PRIVATE(AbstractMediaStream2) 0101 friend class MediaObject; 0102 friend class MediaObjectPrivate; 0103 friend class MediaSourcePrivate; 0104 protected: 0105 ///////////////////////////////////////////////////////////// 0106 // functions an implementation will call: 0107 ///////////////////////////////////////////////////////////// 0108 0109 /** 0110 * Constructs an AbstractMediaStream2 object with a \p parent. 0111 */ 0112 explicit AbstractMediaStream2(QObject *parent = 0); 0113 0114 void resetDone(); 0115 void seekStreamDone(); 0116 0117 ///////////////////////////////////////////////////////////// 0118 // functions to implement: 0119 ///////////////////////////////////////////////////////////// 0120 0121 /** 0122 * Reimplement this function to be notified when the backend needs data. 0123 * 0124 * When this function is called you should try to call writeData or endOfData before 0125 * returning. 0126 * 0127 * \param size The number of bytes that are needed. If possible, pass \p size bytes of media 0128 * data in the next writeData call. 0129 */ 0130 virtual void needData(quint32 size) = 0; 0131 0132 ///////////////////////////////////////////////////////////// 0133 // internal 0134 ///////////////////////////////////////////////////////////// 0135 0136 bool event(QEvent *e); 0137 AbstractMediaStream2(AbstractMediaStream2Private &dd, QObject *parent); 0138 0139 private: 0140 // hide needData() explicitly 0141 virtual void needData() {} 0142 0143 Q_PRIVATE_SLOT(d_func(), void _k_handleStreamEvent()) 0144 }; 0145 0146 } // namespace Phonon 0147 0148 0149 #endif // PHONON_ABSTRACTMEDIASTREAM2_H