GStreamer Plugin Writer's Guide (0.10.12) | ||
---|---|---|
<<< Previous | Pre-made base classes | Next >>> |
In the previous part, particularly Providing random access, we have learned that some types
of elements can provide random access. This applies most definitely to
source elements reading from a randomly seekable location, such as file
sources. However, other source elements may be better described as a
live source element, such as a camera source, an audio card source and
such; those are not seekable and do not provide byte-exact access. For
all such use cases, GStreamer provides two base classes:
GstBaseSrc
for the basic source functionality, and
GstPushSrc
, which is a non-byte exact source
base-class. The pushsource base class itself derives from basesource as
well, and thus all statements about the basesource apply to the
pushsource, too.
The basesrc class does several things automatically for derived classes, so they no longer have to worry about it:
Fixes to GstBaseSrc
apply to all derived
classes automatically.
Automatic pad activation handling, and task-wrapping in case we get assigned to start a task ourselves.
The GstBaseSrc
may not be suitable for all cases,
though; it has limitations:
There is one and only one sourcepad. Source elements requiring multiple sourcepads cannot use this base-class.
Since the base-class owns the pad and derived classes can only control it as far as the virtual functions allow, you are limited to the functionality provided by the virtual functions. If you need more, you cannot use this base-class.
It is possible to use special memory, such as X server memory pointers
or mmap ()'ed memory areas, as data pointers in
buffers returned from the create() virtual function.
In almost all cases, you will want to subclass
GstBuffer
so that your own set of functions can
be called when the buffer is destroyed.
An audio source is nothing more but a special case of a pushsource.
Audio sources would be anything that reads audio, such as a source
reading from a soundserver, a kernel interface (such as ALSA) or a
test sound / signal generator. GStreamer provides two base classes,
similar to the two audiosinks described in Writing an audio sink; one is ringbuffer-based, and
requires the derived class to take care of its own scheduling,
synchronization and such. The other is based on this
GstBaseAudioSrc
and is called
GstAudioSrc
, and provides a simple
open (), close () and
read () interface, which is rather simple to
implement and will suffice for most soundserver sources and audio
interfaces (e.g. ALSA or OSS) out there.
The GstAudioSrc
base-class has several benefits
for derived classes, on top of the benefits of the
GstPushSrc
base-class that it is based on:
Does syncronization and provides a clock.
New features can be added to it and will apply to all derived classes automatically.
<<< Previous | Home | Next >>> |
Pre-made base classes | Up | Writing a transformation element |