StreamInterface Class Reference
from PyKDE4.phonon import *
Namespace: Phonon
Detailed Description
- Abstract class:
- This class can be used as a base class for new classes, but can not be instantiated directly.
\class StreamInterface streaminterface.h phonon/StreamInterface Backend interface to handle media streams (AbstractMediaStream).
All functions relay their calls to the AbstractMediaStream using invokeMethod on the AbstractMediaStream's QMetaObject. This means that every function call will actually be executed in the thread context of the AbstractMediaStream (which usually is a thread Phonon also lives in, could however also be another one). This protectes the AbstractMediaStream against calls from different threads, such as a callback thread. This is very important as most IO implementations are by default not thread-safe.
This protection is only established in one direction though, meaning that a backend implementation of this interface must be made thread-safe at all costs as it can get called from any thread.
Methods | |
__init__ (self) | |
connectToSource (self, Phonon.MediaSource mediaSource) | |
endOfData (self) | |
enoughData (self) | |
needData (self) | |
reset (self) | |
seekStream (self, long seekTo) | |
setStreamSeekable (self, bool s) | |
setStreamSize (self, long newSize) | |
writeData (self, QByteArray data) |
Method Documentation
__init__ | ( | self ) |
connectToSource | ( | self, | ||
Phonon.MediaSource | mediaSource | |||
) |
Call this function from the constructor of your StreamInterface implementation (or as soon as you get the MediaSource object). This will connect your object to the AbstractMediaStream object. Only after the connection is done will the following functions have an effect.
endOfData | ( | self ) |
- Abstract method:
- This method is abstract and can be overridden but not called directly.
Called when no more media data is available and writeData will not be called anymore.
enoughData | ( | self ) |
Call this function to tell the AbstractMediaStream that you have enough data in your buffer and that it should pause calling writeData if possible.
needData | ( | self ) |
Call this function to tell the AbstractMediaStream that you need more data. The data will arrive through writeData. writeData() will not be called from needData() due to the thread protection of the AbstractMediaStream.
Depending on the buffering you need you either treat needData as a replacement for a read call like QIODevice.read, or you start calling needData whenever your buffer reaches a certain lower threshold.
reset | ( | self ) |
Resets the AbstractMediaStream. E.g. this can be useful for non-seekable streams to start over again.
seekStream | ( | self, | ||
long | seekTo | |||
) |
If the stream is seekable, calling this function will make the next call to writeData pass data that starts at the byte offset seekTo.
setStreamSeekable | ( | self, | ||
bool | s | |||
) |
- Abstract method:
- This method is abstract and can be overridden but not called directly.
Tells whether the stream is seekable.
setStreamSize | ( | self, | ||
long | newSize | |||
) |
- Abstract method:
- This method is abstract and can be overridden but not called directly.
Called at the start of the stream to tell how many bytes will be sent through writeData (if no seeks happen, of course). If this value is negative the stream size cannot be determined (might be a "theoretically infinite" stream - like webradio).
writeData | ( | self, | ||
QByteArray | data | |||
) |
- Abstract method:
- This method is abstract and can be overridden but not called directly.
Called by the application to send a chunk of (encoded) media data.
It is recommended to keep the QByteArray object until the data is consumed so that no memcopy is needed.