[pulseaudio-discuss] PA details needed

Lennart Poettering lennart at poettering.net
Fri Jan 2 09:31:49 PST 2009


On Mon, 29.12.08 16:39, Nanavati, Sitanshu (sitanshu.nanavati at intel.com) wrote:

Heya!

> 1) basic flow wrt source/sink/sink_input/source_output in the PA code, the modules involved and who does what.
> 
> 2) audio mixing and volume control wrt:
> 
>           - flow
>           - modules involved
>           - who does what in a flow
> 
> I have some details on these but not 100% sure.  If someone could
> point me or write the details would be highly appreciated.
> Unfortunately the wiki documentation helps and gives little info.

Unfortunately the Wiki is the only documentation about the internals
we have right now. I know it is incomplete and sometimes
out-of-date. However I do believe that it is useful as a starting
point. Just take it with a grain of salt, and always check the source
code to compare what the wiki says and what is actually the truth.

http://pulseaudio.org/wiki/WritingModules

Here's my one minute intro how the general flow works:

1) the term "source" refers to devices where PCM data is
   produced. (i.e. the "capturing" part of a sound card). It is
   clocked, i.e. a clock is enforced (usually by hardware)
   automatically and implicitly.

2) the term "sink" refers to device where PCM data is
   consumed. (i.e. the "playback" part of a sound card). It is also
   clocked.

3) The term "source output" is a virtual construct that refers to some
   kind of stream that is connected to a source. (i.e. usually some
   kind of client application that wants to record audio). While it
   may carry meta information about sampling rate and such it is not
   automatically or implicitly clocked by itself but it is slaved to
   the clock of the source it is connected to.

4) The term "sink input" is a virtual construct that refers to some
   kind of stream that is connected to a sink. (i.e. usually some kind of
   client that wants to play back audio.) And here too the clock is
   slaved to the sink it is connected to.

5) A source may be connected to 0, 1 or more source outputs. 

6) A sink may be connected to 0, 1 or more sink inputs.

7) A source output is always connected to exactly one source.

8) A sink input is always connected to exactly one sink.

9) Connections except those described in 5-8 are not
   possible. More specifically you may not connect a sink and a source
   directly. (which is intended since then you'd have two clocks in
   your pipeline which would require handling clock deviations which
   is complex and we hence don't automatically do.

10) If the sampling parameters (i.e. channles, freq, type) of a sink
    and a sink input it is connected to differ than we resample as part
    of the sink input and hand data to the sink that is formatted in
    the sampling params of the sink. The sink will mix all data that
    it reads from its sink inputs.

11) If the sampling paramters of a source and a source output it is
    connected to differ than we resample as part of the source output and
    for that use data that is handed to us from the source that is
    formatted in the sampling params of the source. Ths source will
    multiplex the data it read from the device to all its source outputs
    simultaneously.

12) Each sink and each source run a thread of their own (the so called
    IO thread). Since they
    decide about the clocking they can simply call pa_sink_render (for
    the sink case) or pa_source_push (for the source case) whenever
    they think it is appropriate to resample/mix (for the sink case)
    or resample/multiplex (for the source case) the data they
    want to play next/just recorded.

13) The code of the sink inputs/source outputs run as part of the IO
    threads of the sink/source they are connected to. They do *not*
    run their own threads.

If you have two applications running that play audio, the flow chart
might look like this:

 app#1 -> sink input #1 \
                         > sink -> ALSA device
 app#2 -> sink input #2 /

PA modules may create sinks, sink inputs, sources, source outputs at
anytime. They may remove them at anytime too. 

Generally sinks/sources are an abstraction for audio devices, while
sink inputs/source outputs are an abstraction for application clients.

If you have further questions, please be to the point. i.e. it is
easier for me to respond to explicit questions than to general ones,
if you understand what I mean...

I hope this lights things up a bit.

Lennart

-- 
Lennart Poettering                        Red Hat, Inc.
lennart [at] poettering [dot] net         ICQ# 11060553
http://0pointer.net/lennart/           GnuPG 0x1A015CC4



More information about the pulseaudio-discuss mailing list