# class AbstractMediaStream

### abstract

Module | phonon
Namespace | Phonon
Class | AbstractMediaStream
Inherits | QObject

\class AbstractMediaStream abstractmediastream.h Phonon/AbstractMediaStream 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>

### methods

- AbstractMediaStream (parent)

  returns ctor

  Argument | Type | Default
  --- | --- | ---
  parent | QObject | 0

  Constructs an AbstractMediaStream object with a parent.

- AbstractMediaStream (dd, parent)

  returns ctor

  Argument | Type | Default
  --- | --- | ---
  dd | AbstractMediaStreamPrivate |
  parent | QObject |

- endOfData ( )

  returns Nothing

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

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

- enoughData ( )

  returns Nothing

  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.

- error (errorType, errorString)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  errorType | Phonon.ErrorType |
  errorString | QString |

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

  See also MediaObject.errorType()

  See also MediaObject.errorString()

- needData ( )

  returns Nothing
  pure 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.

- reset ( )

  returns Nothing
  pure 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

      seekStream(0);
      \endcode.

- seekStream (offset)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  offset | qint64 |

  Reimplement this function if your stream is seekable.

  When this function is called the next call to writeData has to be at the requested \p offset.

  Do not call the parent implementation.

- setStreamSeekable (a0)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  a0 | bool |

  Sets whether your data stream is seekable.

  Defaults to false.

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

- setStreamSize (a0)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  a0 | qint64 |

  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.

- streamSeekable ( )

  returns bool

  Returns whether your data stream is set as seekable.

  Defaults to false.

- streamSize ( )

  returns qint64

  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.

- writeData (data)

  returns Nothing

  Argument | Type | Default
  --- | --- | ---
  data | QByteArray |

  Sends the media data to the backend for decoding.

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