| 1 |
/* This file is part of the KDE project |
| 2 |
Copyright (C) 2007 Matthias Kretz <kretz@kde.org> |
| 3 |
|
| 4 |
This library is free software; you can redistribute it and/or |
| 5 |
modify it under the terms of the GNU Lesser General Public |
| 6 |
License as published by the Free Software Foundation; either |
| 7 |
version 2.1 of the License, or (at your option) version 3, or any |
| 8 |
later version accepted by the membership of KDE e.V. (or its |
| 9 |
successor approved by the membership of KDE e.V.), Nokia Corporation |
| 10 |
(or its successors, if any) and the KDE Free Qt Foundation, which shall |
| 11 |
act as a proxy defined in Section 6 of version 3 of the license. |
| 12 |
|
| 13 |
This library is distributed in the hope that it will be useful, |
| 14 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 |
Lesser General Public License for more details. |
| 17 |
|
| 18 |
You should have received a copy of the GNU Lesser General Public |
| 19 |
License along with this library. If not, see <http://www.gnu.org/licenses/>. |
| 20 |
|
| 21 |
*/ |
| 22 |
|
| 23 |
#ifndef PHONON_MEDIASOURCE_H |
| 24 |
#define PHONON_MEDIASOURCE_H |
| 25 |
|
| 26 |
#include "phonon_export.h" |
| 27 |
#include "phononnamespace.h" |
| 28 |
#include "objectdescription.h" |
| 29 |
#include <QtCore/QSharedData> |
| 30 |
#include <QtCore/QString> |
| 31 |
|
| 32 |
QT_BEGIN_HEADER |
| 33 |
QT_BEGIN_NAMESPACE |
| 34 |
|
| 35 |
class QUrl; |
| 36 |
class QIODevice; |
| 37 |
|
| 38 |
namespace Phonon |
| 39 |
{ |
| 40 |
|
| 41 |
class MediaSourcePrivate; |
| 42 |
class AbstractMediaStream; |
| 43 |
|
| 44 |
/** \class MediaSource mediasource.h Phonon/MediaSource |
| 45 |
* Note that all constructors of this class are implicit, so that you can simply write |
| 46 |
* \code |
| 47 |
* MediaObject m; |
| 48 |
* QString fileName("/home/foo/bar.ogg"); |
| 49 |
* QUrl url("http://www.example.com/stream.mp3"); |
| 50 |
* QBuffer *someBuffer; |
| 51 |
* m.setCurrentSource(fileName); |
| 52 |
* m.setCurrentSource(url); |
| 53 |
* m.setCurrentSource(someBuffer); |
| 54 |
* m.setCurrentSource(Phonon::Cd); |
| 55 |
* \endcode |
| 56 |
* |
| 57 |
* \ingroup Playback |
| 58 |
* \ingroup Recording |
| 59 |
* \author Matthias Kretz <kretz@kde.org> |
| 60 |
*/ |
| 61 |
class PHONON_EXPORT MediaSource |
| 62 |
{ |
| 63 |
friend class StreamInterface; |
| 64 |
public: |
| 65 |
/** |
| 66 |
* Identifies the type of media described by the MediaSource object. |
| 67 |
* |
| 68 |
* \see MediaSource::type() |
| 69 |
*/ |
| 70 |
enum Type { |
| 71 |
/** |
| 72 |
* The MediaSource object does not describe any valid source. |
| 73 |
*/ |
| 74 |
Invalid = -1, |
| 75 |
/** |
| 76 |
* The MediaSource object describes a local file. |
| 77 |
*/ |
| 78 |
LocalFile, |
| 79 |
/** |
| 80 |
* The MediaSource object describes a URL, which can be both a local file and a file on |
| 81 |
* the network. |
| 82 |
*/ |
| 83 |
Url, |
| 84 |
/** |
| 85 |
* The MediaSource object describes a disc. |
| 86 |
*/ |
| 87 |
Disc, |
| 88 |
/** |
| 89 |
* The MediaSource object describes a data stream. |
| 90 |
* |
| 91 |
* This is also the type used for QIODevices. |
| 92 |
* |
| 93 |
* \see AbstractMediaStream |
| 94 |
*/ |
| 95 |
Stream, |
| 96 |
/** |
| 97 |
* An empty MediaSource. |
| 98 |
* |
| 99 |
* It can be used to unload the current media from a MediaObject. |
| 100 |
* |
| 101 |
* \see MediaSource() |
| 102 |
*/ |
| 103 |
Empty |
| 104 |
/* post 4.0: |
| 105 |
/ ** |
| 106 |
* Links multiple MediaSource objects together. |
| 107 |
* / |
| 108 |
Link |
| 109 |
*/ |
| 110 |
}; |
| 111 |
|
| 112 |
/** |
| 113 |
* Creates an empty MediaSource. |
| 114 |
* |
| 115 |
* An empty MediaSource is considered valid and can be set on a MediaObject to unload its |
| 116 |
* current media. |
| 117 |
* |
| 118 |
* \see Empty |
| 119 |
*/ |
| 120 |
MediaSource(); |
| 121 |
|
| 122 |
/** |
| 123 |
* Creates a MediaSource object for a local file or a Qt resource. |
| 124 |
* |
| 125 |
* \param fileName file name of a local media file or a Qt resource that was compiled in. |
| 126 |
*/ |
| 127 |
MediaSource(const QString &fileName); //krazy:exclude=explicit |
| 128 |
|
| 129 |
/** |
| 130 |
* Creates a MediaSource object for a URL. |
| 131 |
* |
| 132 |
* \param url URL to a media file or stream. |
| 133 |
*/ |
| 134 |
MediaSource(const QUrl &url); //krazy:exclude=explicit |
| 135 |
|
| 136 |
/** |
| 137 |
* Creates a MediaSource object for discs. |
| 138 |
* |
| 139 |
* \param discType See \ref DiscType |
| 140 |
* \param deviceName A platform dependent device name. This can be useful if the computer |
| 141 |
* has more than one CD drive. It is recommended to use Solid to retrieve the device name in |
| 142 |
* a portable way. |
| 143 |
*/ |
| 144 |
MediaSource(Phonon::DiscType discType, const QString &deviceName = QString()); //krazy:exclude=explicit |
| 145 |
|
| 146 |
#ifndef QT_NO_PHONON_ABSTRACTMEDIASTREAM |
| 147 |
/** |
| 148 |
* Creates a MediaSource object for a data stream. |
| 149 |
* |
| 150 |
* Your application can provide the media data by subclassing AbstractMediaStream and |
| 151 |
* passing a pointer to that object. %Phonon will never delete the \p stream. |
| 152 |
* |
| 153 |
* \param stream The AbstractMediaStream subclass to provide the media data. |
| 154 |
* |
| 155 |
* \see setAutoDelete |
| 156 |
*/ |
| 157 |
MediaSource(AbstractMediaStream *stream); //krazy:exclude=explicit |
| 158 |
|
| 159 |
/** |
| 160 |
* Creates a MediaSource object for a QIODevice. |
| 161 |
* |
| 162 |
* This constructor can be very handy in the combination of QByteArray and QBuffer. |
| 163 |
* |
| 164 |
* \param ioDevice An arbitrary readable QIODevice subclass. If the device is not opened |
| 165 |
* MediaSource will open it as QIODevice::ReadOnly. Sequential I/O devices are possible, |
| 166 |
* too. For those MediaObject::isSeekable() will have to return false obviously. |
| 167 |
* |
| 168 |
* \see setAutoDelete |
| 169 |
*/ |
| 170 |
MediaSource(QIODevice *ioDevice); //krazy:exclude=explicit |
| 171 |
#endif |
| 172 |
|
| 173 |
/** |
| 174 |
* Creates a MediaSource object for capture devices. |
| 175 |
*/ |
| 176 |
//MediaSource(const AudioCaptureDevice &, const VideoCaptureDevice &); |
| 177 |
|
| 178 |
/** |
| 179 |
* Destroys the MediaSource object. |
| 180 |
*/ |
| 181 |
~MediaSource(); |
| 182 |
|
| 183 |
/** |
| 184 |
* Constructs a copy of \p rhs. |
| 185 |
* |
| 186 |
* This constructor is fast thanks to explicit sharing. |
| 187 |
*/ |
| 188 |
MediaSource(const MediaSource &rhs); |
| 189 |
|
| 190 |
/** |
| 191 |
* Assigns \p rhs to this MediaSource and returns a reference to this MediaSource. |
| 192 |
* |
| 193 |
* This operation is fast thanks to explicit sharing. |
| 194 |
*/ |
| 195 |
MediaSource &operator=(const MediaSource &rhs); |
| 196 |
|
| 197 |
/** |
| 198 |
* Returns \p true if this MediaSource is equal to \p rhs; otherwise returns \p false. |
| 199 |
*/ |
| 200 |
bool operator==(const MediaSource &rhs) const; |
| 201 |
|
| 202 |
/** |
| 203 |
* Tell the MediaSource to take ownership of the AbstractMediaStream or QIODevice that was |
| 204 |
* passed in the constructor. |
| 205 |
* |
| 206 |
* The default setting is \p false, for safety. If you turn it on, you should only access |
| 207 |
* the AbstractMediaStream/QIODevice object as long as you yourself keep a MediaSource |
| 208 |
* object around. As long as you keep the MediaSource object wrapping the stream/device |
| 209 |
* the object will not get deleted. |
| 210 |
* |
| 211 |
* \see autoDelete |
| 212 |
*/ |
| 213 |
void setAutoDelete(bool enable); |
| 214 |
|
| 215 |
/** |
| 216 |
* Returns the setting of the auto-delete option. The default is \p false. |
| 217 |
* |
| 218 |
* \see setAutoDelete |
| 219 |
*/ |
| 220 |
bool autoDelete() const; |
| 221 |
|
| 222 |
/** |
| 223 |
* Returns the type of the MediaSource (depends on the constructor that was used). |
| 224 |
* |
| 225 |
* \see Type |
| 226 |
*/ |
| 227 |
Type type() const; |
| 228 |
|
| 229 |
/** |
| 230 |
* Returns the file name of the MediaSource if type() == LocalFile; otherwise returns |
| 231 |
* QString(). |
| 232 |
*/ |
| 233 |
QString fileName() const; |
| 234 |
|
| 235 |
/** |
| 236 |
* Returns the url of the MediaSource if type() == URL or type() == LocalFile; otherwise |
| 237 |
* returns QUrl(). |
| 238 |
*/ |
| 239 |
QUrl url() const; |
| 240 |
|
| 241 |
/** |
| 242 |
* Returns the disc type of the MediaSource if type() == Disc; otherwise returns \ref |
| 243 |
* NoDisc. |
| 244 |
*/ |
| 245 |
Phonon::DiscType discType() const; |
| 246 |
|
| 247 |
/** |
| 248 |
* Returns the device name of the MediaSource if type() == Disc; otherwise returns |
| 249 |
* QString(). |
| 250 |
*/ |
| 251 |
QString deviceName() const; |
| 252 |
|
| 253 |
#ifndef QT_NO_PHONON_ABSTRACTMEDIASTREAM |
| 254 |
/** |
| 255 |
* Returns the media stream of the MediaSource if type() == Stream; otherwise returns 0. |
| 256 |
* QIODevices are handled as streams, too. |
| 257 |
*/ |
| 258 |
AbstractMediaStream *stream() const; |
| 259 |
#endif |
| 260 |
|
| 261 |
//AudioCaptureDevice audioCaptureDevice() const; |
| 262 |
//VideoCaptureDevice videoCaptureDevice() const; |
| 263 |
|
| 264 |
/* post 4.0: |
| 265 |
MediaSource(const QList<MediaSource> &mediaList); |
| 266 |
QList<MediaSource> substreams() const; |
| 267 |
*/ |
| 268 |
|
| 269 |
protected: |
| 270 |
QExplicitlySharedDataPointer<MediaSourcePrivate> d; |
| 271 |
MediaSource(MediaSourcePrivate &); |
| 272 |
}; |
| 273 |
|
| 274 |
} // namespace Phonon |
| 275 |
|
| 276 |
QT_END_NAMESPACE |
| 277 |
QT_END_HEADER |
| 278 |
|
| 279 |
#endif // PHONON_MEDIASOURCE_H |