Been working with Marlin over past few days. Mostly in my head.
The upgrade to GStreamer 0.10 has allowed me to rethink how everything fits together.
The old way
The old pipeline was two threads: The decoding thread, and the sink thread. The src passed it to the decoder which decoded it, passed it to audioconvert because we’re pretending we’re proaudio and so we want audio/x-raw-float.
After this we split the audio into mono streams. The Deinterleaver splits the data and creates a new src pad for each stream. As these pads are created we create the queue element and get a new sink pad on the sink. This increments the number of channels in the sink (duh) and also sets the number of channels on the sample that is associated with the sink.
This is quite annoyingly complicated and a lot of weird stuff went on in the sink to co-ordinate the incoming pads and link the pads.
The new way
First thing to notice is one thread. wooo. Hopefully I won’t need any other threads but because I’ve not coded this yet I dunno.
The src and decoder do the same. However, the decoder isn’t linked to anything until it knows the number of channels/sample rate etc and creates the srcpad for it. Because we now know this when we create the rest of the pipeline, we can set the format on the sample associated with the load pipeline in one go, not first create one pad, set it to mono, create the second, stereo, third….etc like we used to. This means we can remove the logic for controlling the sample format away from the sink.
Audioconvert and deinterlacer do their same thing (although deinterlacer should be deinterleaver, but its 2am, so sue me.)
Now however, instead of having on sink that deals with the sample as a whole, we have a sink for each channel. Instead of having lots of sinkpads, this sink only has one, and doesn’t care about the other channels.
We can now associate a channel sink with a certain channel, which we couldn’t before. So even if we disconnect the pipeline, the left channel will still be connected to the left channel when we reconnect. Moving the sample logic simplifies whats going on a lot, and making each sink be mono allowed us (me) to use GstBaseSink which seems to deal with all the hard stuff for me. The sink code has shrunk from 800 lines to about 300. Wooo