- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files
- Directories
- Examples

- Class List
- Class Hierarchy
- Class Members

Public Member Functions | Protected Member Functions | Protected Attributes | Friends

# AbstractMediaStream Class Reference

Search for all occurrences

## 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)
       : AbstractMediaStream(parent)
     {
       setStreamSize(getMediaStreamSize());
     }

     void PullStream::needData()
     {
       const QByteArray data = getMediaData();
       if (data.isEmpty()) {
         endOfData();
       } else {
         writeData(data);
       }
     }

Author:
  Matthias Kretz <kretz@kde.org>

Definition at line 103 of file abstractmediastream.h.

`#include <Phonon/AbstractMediaStream>`

Inheritance diagram for AbstractMediaStream:
[legend]

List of all members.

## Public Member Functions
virtual | ~AbstractMediaStream ()
## Protected Member Functions
| AbstractMediaStream (QObject *parent=0)
| Constructs an AbstractMediaStream object with a `parent`.
qint64 | streamSize () const
| Returns the stream size that was set with setStreamSize.
void | setStreamSize (qint64)
| Sets the size of the stream in number of bytes.
bool | streamSeekable () const
| Returns whether your data stream is set as seekable.
void | setStreamSeekable (bool)
| Sets whether your data stream is seekable.
void | writeData (const QByteArray &data)
| Sends the media `data` to the backend for decoding.
void | endOfData ()
| Tells the backend that the media data stream is at its end.
void | error (Phonon::ErrorType errorType, const QString &errorString)
| If an I/O error occurs you should call this function to make MediaObject go into ErrorState.
virtual void | reset ()=0
| Reimplement this function to reset the stream.
virtual void | needData ()=0
| Reimplement this function to be notified when the backend needs data.
virtual void | enoughData ()
| Reimplement this function to be notified when the backend has enough data and your stream object may take a break.
virtual void | seekStream (qint64 offset)
| Reimplement this function if your stream is seekable.
| AbstractMediaStream (AbstractMediaStreamPrivate &dd, QObject *parent)
## Protected Attributes
QScopedPointer < AbstractMediaStreamPrivate > | d_ptr
## Friends
class | MediaObject
class | MediaObjectPrivate
class | StreamInterface

## Constructor & Destructor Documentation

virtual ~AbstractMediaStream | ( |  | ) | `[virtual]`

AbstractMediaStream | ( | QObject * | parent = `0` | ) | `[explicit, protected]`

Constructs an AbstractMediaStream object with a `parent`.

AbstractMediaStream | ( | AbstractMediaStreamPrivate & | dd,
|  | QObject * | parent
| ) |  | `[protected]`

## Member Function Documentation

qint64 streamSize | ( |  | ) | const `[protected]`

Search for all occurrences

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 setStreamSize | ( | qint64 |  | ) | `[protected]`

Search for all occurrences

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 streamSeekable | ( |  | ) | const `[protected]`

Search for all occurrences

Returns whether your data stream is set as seekable.

Defaults to `false`.

void setStreamSeekable | ( | bool |  | ) | `[protected]`

Search for all occurrences

Sets whether your data stream is seekable.

Defaults to `false`.

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

void writeData | ( | const QByteArray & | data | ) | `[protected]`

Search for all occurrences

Sends the media `data` to the backend for decoding.

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

void endOfData | ( |  | ) | `[protected]`

Search for all occurrences

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 error | ( | Phonon::ErrorType | errorType,
|  | const QString & | errorString
| ) |  | `[protected]`

Search for all occurrences

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

See also:
  MediaObject::errorType()
  MediaObject::errorString()

virtual void reset | ( |  | ) | `[protected, pure virtual]`

Search for all occurrences

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);

.

virtual void needData | ( |  | ) | `[protected, pure virtual]`

Search for all occurrences

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 void enoughData | ( |  | ) | `[protected, virtual]`

Search for all occurrences

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.

virtual void seekStream | ( | qint64 | offset | ) | `[protected, virtual]`

Search for all occurrences

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.

## Friends And Related Function Documentation

friend class MediaObject `[friend]`

Search for all occurrences

Definition at line 107 of file abstractmediastream.h.

friend class MediaObjectPrivate `[friend]`

Search for all occurrences

Definition at line 108 of file abstractmediastream.h.

friend class StreamInterface `[friend]`

Search for all occurrences

Definition at line 109 of file abstractmediastream.h.

## Member Data Documentation

QScopedPointer<AbstractMediaStreamPrivate> d_ptr `[protected]`

Search for all occurrences

Reimplemented from QObject.

Definition at line 217 of file abstractmediastream.h.

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

- phonon/abstractmediastream.h

AbstractMediaStream AbstractMediaStream AbstractMediaStream AbstractMediaStream AbstractMediaStream AbstractMediaStream AbstractMediaStream AbstractMediaStream AbstractMediaStream AbstractMediaStream
AbstractMediaStream AbstractMediaStream AbstractMediaStream AbstractMediaStream AbstractMediaStream AbstractMediaStream AbstractMediaStream AbstractMediaStream AbstractMediaStream AbstractMediaStream