Writing a source

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:

The GstBaseSrc may not be suitable for all cases, though; it has limitations:

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.

Writing an audio source

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 GstAudioBaseSrc 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.