![]() |
Home · All Classes · Main Classes · Grouped Classes · Modules · Functions | ![]() |
Base class for custom media data streams. Author: Matthias Kretz <kretz@kde.org> More...
#include <Phonon>
Inherits QObject.
Base class for custom media data streams. Author: Matthias Kretz <kretz@kde.org>
provides custom data streams for MediaSources.
The MediaSource knows how to handle the most common media sources, such as files and CD. If you need to fetch multimedia from other sources, you can reimplement this class, which can be used by a MediaSource.
When a backend needs more data from the stream, needData() will be called. You must then use writeData() to write the data to the backend. You can either write one time and wait for a new needData() call, or continue to write data until you receive an enoughData() call. When the stream is at its end, call endOfData() instead of writeData().
Before the custom stream is passed to a MediaSource, setStreamSize() needs to be called, and also setStreamSeekable() (if the stream is seekable). A good place to do this work is in the constructor. A seekable stream must also reimplement seekStream().
We show two examples. The first writes data repeatedly until it receives the enoughData() call, while the second only writes once and waits for a new needData() call.
Push:
PushStream::PushStream(QObject *parent) : AbstractMediaStream(parent), m_timer(new QTimer(this)) { setStreamSize(getMediaStreamSize()); connect(m_timer, SIGNAL(timeout()), SLOT(moreData())); m_timer->setInterval(0); } void PushStream::moreData() { const QByteArray data = getMediaData(); if (data.isEmpty()) { endOfData(); } else { writeData(data); } } void PushStream::needData() { m_timer->start(); moreData(); } void PushStream::enoughData() { m_timer->stop(); }
Pull:
PullStream::PullStream(QObject *parent) : AbstractMediaStream(parent) { setStreamSize(getMediaStreamSize()); } void PullStream::needData() { const QByteArray data = getMediaData(); if (data.isEmpty()) { endOfData(); } else { writeData(data); } }
See also Phonon::MediaSource and Phonon::MediaObject.
Constructs an AbstractMediaStream object with the given parent.
Tells the backend that the media data stream is at its end.
Warning: Don't call this function before the first needData() is emitted.
See also writeData() and needData().
If your stream is a push stream, reimplement this function to be notified when the backend has enough data and your stream object may take a break.
This method is important for pushing data to the backend in order to not fill the backend buffer unnecessarily.
See also needData().
If an I/O error occurs you should call this function to make MediaObject go into ErrorState. errorType classifies the error, while errorString is a textual description of the error suitable for users of Phonon applications.
See also MediaObject::errorType() and MediaObject::errorString().
Reimplement this function to be notified when the backend needs data.
When this function is called you should write data to the backend (See writeData()).
See also writeData(), endOfData(), and enoughData().
Reimplement this function to reset the stream. Subsequent calls to writeData should start from the first position of the data unless a seek is requested.
The function is necessary for the case where a non-seekable MediaStream is played more than once. For a seekable stream the implementation can simply call
seekStream(0);
See also writeData() and needData().
Reimplement this function if your stream is seekable.
When this function is called the next call to writeData has to be at the requested offset.
Warning: Do not call the parent implementation.
See also setStreamSeekable(), streamSeekable(), and needData().
Sets whether your data stream is seekable. s should be true if the stream is seekable; otherwise false.
Defaults to false.
If you set this to true you have to implement the seekStream() function.
See also streamSeekable().
Sets the size of the stream in number of bytes.
A negative value means that the length of the stream cannot be known.
Defaults to 0.
This function has to be called. A backend will not call needData() until the stream size is set.
See also streamSize().
Returns whether your data stream is set as seekable.
Defaults to false.
See also setStreamSeekable().
Returns the stream size that was set with setStreamSize().
A negative value means that the length of the stream cannot be known.
Defaults to 0.
See also setStreamSize().
Sends the media data to the backend for decoding.
Use this function to send data to the backend after needData() has been called.
If your stream is a push stream, data should be written until the enoughData() function is called. For a pull stream, write data once before the call to needData() function returns.
If the data is depleted, call endOfData() instead of writeData().
Warning: Don't call this function before the first needData() is emitted.
See also needData() and endOfData().
Copyright © 2008 Trolltech | Trademarks | Qt 4.4.0-beta1 |