# class AbstractMediaStream2

### abstract

Module | phonon
Namespace | Phonon
Class | AbstractMediaStream2
Inherits | Phonon::AbstractMediaStream

\class AbstractMediaStream2 abstractmediastream2.h Phonon/AbstractMediaStream2 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)
    : AbstractMediaStream2(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)
    : AbstractMediaStream2(parent)
    {
    setStreamSize(getMediaStreamSize());
    }

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

Author Matthias Kretz <kretz@kde.org>

### methods

- AbstractMediaStream2 (parent)

  returns ctor

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

  Constructs an AbstractMediaStream2 object with a parent.

- AbstractMediaStream2 (dd, parent)

  returns ctor

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

- event (e)

  returns bool

  Argument | Type | Default
  --- | --- | ---
  e | QEvent |

- needData (size)

  returns Nothing
  pure virtual

  Argument | Type | Default
  --- | --- | ---
  size | quint32 |

  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.

  size - The number of bytes that are needed. If possible, pass size bytes of media data in the next writeData call.

- resetDone ( )

  returns Nothing

- seekStreamDone ( )

  returns Nothing