Phonon  4.7.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Pages
Protected Member Functions | Protected Attributes | Friends | List of all members
Phonon::AbstractMediaStream Class Referenceabstract

Base class for custom media data streams. More...

#include <phonon/AbstractMediaStream>

Inheritance diagram for Phonon::AbstractMediaStream:

Protected Member Functions

 AbstractMediaStream (QObject *parent=0)
 
qint64 streamSize () const
 
void setStreamSize (qint64)
 
bool streamSeekable () const
 
void setStreamSeekable (bool)
 
void writeData (const QByteArray &data)
 
void endOfData ()
 
void error (Phonon::ErrorType errorType, const QString &errorString)
 
virtual Q_INVOKABLE void reset ()=0
 
virtual Q_INVOKABLE void needData ()=0
 
virtual Q_INVOKABLE void enoughData ()
 
virtual Q_INVOKABLE void seekStream (qint64 offset)
 
 AbstractMediaStream (AbstractMediaStreamPrivate &dd, QObject *parent)
 

Protected Attributes

QScopedPointer
< AbstractMediaStreamPrivate > 
d_ptr
 

Friends

class MediaObject
 
class MediaObjectPrivate
 
class StreamInterface
 

Detailed Description

Base class for custom media data streams.

Implement this class to provide a custom data stream to the backend. The class supports both, the push and the pull model.

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)
{
setStreamSize(getMediaStreamSize());
}
void PullStream::needData()
{
const QByteArray data = getMediaData();
if (data.isEmpty()) {
endOfData();
} else {
writeData(data);
}
}
Author
Matthias Kretz kretz.nosp@m.@kde.nosp@m..org

Constructor & Destructor Documentation

Phonon::AbstractMediaStream::AbstractMediaStream ( QObject *  parent = 0)
explicitprotected

Constructs an AbstractMediaStream object with a parent.

Member Function Documentation

void Phonon::AbstractMediaStream::endOfData ( )
protected

Tells the backend that the media data stream is at its end.

Warning
Don't call this function before the first needData() is emitted.
void Phonon::AbstractMediaStream::enoughData ( )
protectedvirtual

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.

void Phonon::AbstractMediaStream::error ( Phonon::ErrorType  errorType,
const QString &  errorString 
)
protected

If an I/O error occurs you should call this function to make MediaObject go into ErrorState.

See Also
MediaObject::errorType()
MediaObject::errorString()
virtual Q_INVOKABLE void Phonon::AbstractMediaStream::needData ( )
protectedpure virtual

Reimplement this function to be notified when the backend needs data.

When this function is called you should try to call writeData or endOfData before returning.

virtual Q_INVOKABLE void Phonon::AbstractMediaStream::reset ( )
protectedpure virtual

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

.

void Phonon::AbstractMediaStream::seekStream ( qint64  offset)
protectedvirtual

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.
void Phonon::AbstractMediaStream::setStreamSeekable ( bool  s)
protected

Sets whether your data stream is seekable.

Defaults to false.

If you set this to true you have to implement the seekStream function.

void Phonon::AbstractMediaStream::setStreamSize ( qint64  newSize)
protected

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.

bool Phonon::AbstractMediaStream::streamSeekable ( ) const
protected

Returns whether your data stream is set as seekable.

Defaults to false.

qint64 Phonon::AbstractMediaStream::streamSize ( ) const
protected

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.

void Phonon::AbstractMediaStream::writeData ( const QByteArray &  data)
protected

Sends the media data to the backend for decoding.

Warning
Don't call this function before the first needData() is emitted.

The documentation for this class was generated from the following files: