Arun Raghavan [Fri, 7 Oct 2011 10:58:11 +0000 (16:28 +0530)]
echo-cancel: Plug in WebRTC drift compensation
This adds the ability for echo cancellers to provide their own drift
compensation, and hooks in the appropriate bits to implement this in the
WebRTC canceller.
We do this by introducing an alternative model for the canceller. So
far, the core engine just provided a run() method which was given
blocksize-sized chunks of playback and record samples. The new model has
the engine provide play() and record() methods that can (in theory) be
called by the playback and capture threads. The latter would actually do
the processing required.
In addition to this a set_drift() method may be provided by the
implementation. PA will provide periodic samples of the drift to the
engine. These values need to be aggregated and processed over some time,
since the point values vary quite a bit (but generally fit a linear
regression reasonably accurately). At some point of time, we might move
the actual drift calculation into PA and change the semantics of this
function.
NOTE: This needs further testing before being deemed ready for wider use.
Siarhei Siamashka [Thu, 20 Oct 2011 12:47:48 +0000 (15:47 +0300)]
bluetooth: sbc: overflow bugfix and audio decoding quality improvement
The "(((audio_sample << 1) | 1) << frame->scale_factor[ch][sb])"
part of expression
"frame->sb_sample[blk][ch][sb] =
(((audio_sample << 1) | 1) << frame->scale_factor[ch][sb]) /
levels[ch][sb] - (1 << frame->scale_factor[ch][sb])"
in "sbc_unpack_frame" function can sometimes overflow 32-bit signed int.
This problem can be reproduced by first using bitpool 128 and encoding
some random noise data, and then feeding it to sbc decoder. The obvious
thing to do would be to change "audio_sample" variable type to uint32_t.
However the problem is a little bit more complicated. According
to the section "12.6.2 Scale Factors" of A2DP spec:
scalefactor[ch][sb] = pow(2.0, (scale_factor[ch][sb] + 1))
And according to "12.6.4 Reconstruction of the Subband Samples":
sb_sample[blk][ch][sb] = scalefactor[ch][sb] *
((audio_sample[blk][ch][sb]*2.0+1.0) / levels[ch][sb]-1.0);
Hence the current code for calculating "sb_sample[blk][ch][sb]" is
not quite correct, because it loses one least significant bit of
sample data and passes twice smaller sample values to the synthesis
filter (the filter also deviates from the spec to compensate this).
This all has quite a noticeable impact on audio quality. Moreover,
it makes sense to keep a few extra bits of precision here in order
to minimize rounding errors. So the proposed patch introduces a new
SBCDEC_FIXED_EXTRA_BITS constant and uses uint64_t data type
for intermediate calculations in order to safeguard against
overflows. This patch intentionally addresses only the quality
issue, but performance can be also improved later (like replacing
division with multiplication by reciprocal).
Test for the difference of sbc encoding/decoding roundtrip vs.
the original audio file for joint stereo, bitpool 128, 8 subbands
and http://media.xiph.org/sintel/sintel-master-st.flac sample
demonstrates some quality improvement:
=== before ===
--- comparing original / sbc_encoder.exe + sbcdec ---
stddev: 4.64 PSNR: 82.97 bytes:170495708/170496000
=== after ===
--- comparing original / sbc_encoder.exe + sbcdec ---
stddev: 1.95 PSNR: 90.50 bytes:170495708/170496000
Marcel Holtmann [Fri, 26 Aug 2011 18:18:54 +0000 (11:18 -0700)]
bluetooth: audio: Update license for shared header files
The header files with constants and structures for audio specific
interaction with Pulseaudio are suppose to be under LGPL license.
For some odd reason a2dp-codecs.h ended up being under GPL license
which is against the intention of this being shared and re-used by
non-GPL programs. Fix this now to avoid any future confusion.
Arun Raghavan [Thu, 27 Oct 2011 10:49:18 +0000 (12:49 +0200)]
core: Add a string list membership check function
This adds a pa_str_in_list() to check for a given string in a
space-separated list of strings. For now, this is merely present to
avoid duplication of role matching code (intended roles can be a
space-separate list) across modules.
The documentation says we expect a comma-separate list of intended
roles, but the code splits the string on whitespaces, so this corrects
the documentation to match the implementation.
Colin Guthrie [Mon, 24 Oct 2011 21:35:38 +0000 (23:35 +0200)]
role-cork: Make module-role-cork more generic.
Operate on a list of 'trigger roles' and 'cork roles'. i.e.
react to any stream with a role in the trigger list and apply a
cork to any stream with the a role in the cork list.
The trigger roles default to 'phone' and the cork roles default
to both 'music' and 'video' thus achieving the same functionality
as currently when called without any arguments.
Colin Guthrie [Thu, 20 Oct 2011 13:11:53 +0000 (14:11 +0100)]
conf: Use .nofail when loading module-jackdbus-detect
When starting via a console login, PA will likely not have a session DBus
to play with. As there is no X11 environment, libdbus will be unable
to launch a session DBus for us and thus the module will fail to load
which in turn prevents PA from loading.
If the user subsequently logs into X11 this it will still not be possible
to load the module as the server will be ignorant of the X11 and DBus
environment variables so a longer term solution for handling this should
be found.
Colin Guthrie [Thu, 20 Oct 2011 09:04:49 +0000 (10:04 +0100)]
Update LICENSE.
Some of the license wording was less than clear. Try to clarify the
different GPL 'downgrade' scenarios but also be generic to ensure that
those packagers where GPL is a problem check thoroughly before they ship.
Inspired by comments from Brian Cameron @ Oracle via fdo#41822
Colin Guthrie [Tue, 11 Oct 2011 19:42:42 +0000 (20:42 +0100)]
build-sys: Provide a simple CMake Config setup (similar to pkgconfig)
I'd rather not have to do this, as I don't really see the point in
duplicating what is done in pkgconfig, but this is likely the
easiest way to avoid nasty hacks.
Arun Raghavan [Tue, 18 Oct 2011 04:23:20 +0000 (09:53 +0530)]
sink,source: Account for corked streams in update_rate()
pa_sink/source_used_by() ignores corked/monitor streams, but we need to
make sure there aren't any of these while updating rate (at least for
now -- this is a restriction that would be nice to get rid of).
Arun Raghavan [Mon, 10 Oct 2011 19:17:56 +0000 (00:47 +0530)]
source: Bring rate update code in sync with sink code
Basically adds code to handle passthrough sources. This isn't a tested
path at the moment, but in the future, when we do wish to support these,
it'll save us the trouble of having to sync all the code again.
Pierre-Louis Bossart [Tue, 2 Aug 2011 23:37:29 +0000 (18:37 -0500)]
alsa: support for alternate sampling rate
This is where the actual changes happen.
Some additional checks would be required to make sure the
rate is actually supported
Tested with both PCM and passthrough streams
This adds the WebRTC echo canceller as another module-echo-cancel
backend. We're exposing both the full echo canceller as well as the
mobile echo control version as modargs.
Pending items:
1. The mobile canceller doesn't seem to work at the moment.
2. We still need to add bits to hook in drift compensation (to support
sink and source from different devices).
The most controversial part of this patch would probably be the
mandatory build-time dependency on a C++ compiler. If the optional
--enable-webrtc-aec is set, then there's also a dependency on libstdc++.
Tanu Kaskinen [Thu, 6 Oct 2011 20:09:15 +0000 (23:09 +0300)]
alsa: New modarg "paths_dir" for module-alsa-card
The new module argument can be used to provide a custom
directory for loading alsa path configuration files. This is
useful for testing: no need to be root to create test
configuration files.
Arun Raghavan [Wed, 12 Oct 2011 12:14:30 +0000 (17:44 +0530)]
filter-apply: Move sink/source unlink callbacks before m-s-r
module-stream-restore and modile-filter-apply can get into an infinite
loop if m-s-r is called before m-f-a (m-s-r rescues a stream and
attaches it to a sink/source, which then triggers m-f-a to move it back
to the filter sink/source, and so on). The purpose of the m-f-a hooks is
to beat m-s-r, so moving them to be run first.
Arun Raghavan [Wed, 5 Oct 2011 06:59:10 +0000 (12:29 +0530)]
echo-cancel: Skip processing till there's enough data
This makes sure that we only perform any processing (resync or actual
cancellation) after the source provides enough data to actuall run the
canceller.
echo-cancel: Skip canceller when no source outputs are connected
When a source-output isn't connected to our virtual source, we skip echo
cancellation altogether. This makes sense in general, and makes sure
that we don't end up adjusting for delay/drift when nothing is
connected. This should make convergence faster when the canceller
actually starts being used.
Arun Raghavan [Wed, 5 Oct 2011 08:11:43 +0000 (13:41 +0530)]
echo-cancel: Increase threshold for resyncing, make it configurable
This increase the threshold for difference between the playback and
capture stream before samples are dropped from 1ms to 5ms (the
cancellers are generally robust to this much and higher). Also, we make
this a module parameter to allow easier experimentation with different
values.
Pierre-Louis Bossart [Fri, 7 Oct 2011 23:12:32 +0000 (18:12 -0500)]
alsa: reset watermark to initial values on resume
Watermark level and latency values are not restored when
resuming, the values used prior to suspending are reused.
This leads to side effects when underruns happen and buffer
sizes are updated, PulseAudio can never meet lower latency
requirements.
Solution: keep track of watermark and latency values on sink or
source creation, and reapply them on resume to start with
a clean slate.
David Henningsson [Wed, 5 Oct 2011 09:15:53 +0000 (11:15 +0200)]
source-output: Do not use unset channel map in pa_source_output_new
This problem was found when tracing down a crash coming from the
esound protocol, which does not set a channel map.
BugLink: http://bugs.launchpad.net/bugs/864071 Signed-off-by: David Henningsson <david.henningsson@canonical.com>
N.B.: As Colin notes, this is because commit 117c7145 was incomplete
("format: Fix channel map handling")
Arun Raghavan [Tue, 4 Oct 2011 19:28:52 +0000 (00:58 +0530)]
alsa: Make mixer error handling more robust still
Instead of relying on the snd_mixer_* functions failing, we check for
POLLERR and POLLNVAL first. After this, any errors in handling the mixer
events are deemed fatal (that is we cause the ALSA source/sink thread to
terminate).
The case where POLLERR is set but POLLNVAL is not does not actually
occur, but we're making this a soft failure (stop polling the mixer, but
don't kill the I/O thread). If other conditions where POLLERR occurs
turn up, we need to handle them explicitly.
Thanks to Linus Torvalds for helping get this right.
Arun Raghavan [Tue, 4 Oct 2011 08:36:26 +0000 (14:06 +0530)]
echo-cancel: Fail if loaded between a sink and its monitor
Loading between a sink and its monitor causes a deadlock (while sending
messages for latency snapshots). It isn't a case that has any real
conceivable use, so let's just disallow it.
Arun Raghavan [Tue, 4 Oct 2011 04:59:03 +0000 (10:29 +0530)]
alsa: Better error handling in mixer rtpoll callback
This improves the error handling in the mixer rtpoll callback. It avoids
a crash if an error occurs (the rtpoll_item is freed but still
referenced), and specifically makes sure we don't continue trying to
poll the device if the card is disconnected.
Arun Raghavan [Tue, 4 Oct 2011 05:35:59 +0000 (11:05 +0530)]
alsa: Give compressed formats preference over PCM
This makes set_formats() put PCM formats lower down the list than
compressed formats since we negotiate by picking the first format in
this list that is also in the client-provided list of possible formats
during sink input creation.
This will be incorrect if we ever decide to do encoding in PA (for
things like AC3/DTS encoding for multichannel output over S/PDIF).
Marc-André Lureau [Sat, 1 Oct 2011 11:16:35 +0000 (12:16 +0100)]
stream-restore: Support a simple fallback volume table
The purpose of this patch is to make it possible to configure stream volumes
before pulseaudio is run for the first time. This is useful, for example, in
embedded products where the default volumes have to be sensible already in
the first boot.
memblockq: Improve debuggability by storing a name and a sample spec.
These are not used for anything at this point, but this
makes it easy to add ad-hoc debug prints that show the
memblockq name and to convert between bytes and usecs.
Colin Guthrie [Sat, 1 Oct 2011 11:03:44 +0000 (12:03 +0100)]
libpulse: Always return a three part version number in API calls.
For both the headers and the library we should provide clean, three part
strings as this has been what we've previously done in the past
and some external systems apparently rely on this format. While it's not
something we've officially commented on before, there is no real advantage
to us to change it so let's not try to tidy things up too much
considering some third party apps (e.g. Skype) seem to dislike a two
part version string.
sink,source: Avoid unnecessary call to pa_rtclock_now()
pa_{sink,source}_volume_change_apply were being called by the ALSA I/O
thread on every iteration, causing a pa_rtclock_now() call, which can
sometimes be heavy. We avoid this call by making sure there actually are
changes to apply before proceeding into the function.
While we're at it, also dropping a redundant check on s->write_volume.
sink,source: Handle missing in the shared volume case
This makes sure that when we're traversing the device chain for sources
and sinks with shared volume, we handle the case that a sink-input or
source-output of one of these might be unlinked (while unloading a
module, for example).
David Henningsson [Wed, 14 Sep 2011 12:55:07 +0000 (14:55 +0200)]
conf: Make sure module-dbus-protocol is loaded after module-default-device-restore
module-dbus-protocol gets the default sink, which sets the default sink
if not already set. This is turn makes module-default-device-restore do
nothing.
To solve the problem, make sure module-default-device-restore is loaded
before module-dbus-protocol and not the other way around.
Uses the shared volume infrastructure by default with an option to
fallback on the old pretend-volume-sharing-that-kind-of-works if someone
wants it that way.
Users who keep left != right (or any sort of unbalanced channel volumes)
will likely want to disable shared volumes since it will cause their
master sink/source volume to be balanced.
This really isn't a very pleasant scenario since users would need to
manually set up echo cancellation in their config for this (until we
have a way to store module configuration). That said, the majority case
benefits from the volume sharing, so let's not wait for the
configuration infrastructure to be ready to use this.
Uses the shared volume infrastructure by default with an option to
fallback on the old pretend-volume-sharing-that-kind-of-works if someone
wants it that way.
volume: Handle varying channel count for shared volumes
This handles the case where a virtual sink/source and it's master have
different channel counts. The solution is not ideal because if the
former has fewer channels and the master has channel volumes that are
not all at the same level, it will lose this information and have all
channels at the same level.
This is not just a theoretical problem, since module-echo-cancel
prefers a mono virtual source/sink and will usually be sitting on top of
a stereo ALSA source/sink.
That said, I don't really see a good solution to this problem, so the
idea is to make volume sharing optional (on by default) in
module-echo-cancel, so that the few people who care can then disable it
if they so desire.
Colin Guthrie [Tue, 13 Sep 2011 20:15:49 +0000 (21:15 +0100)]
volume: Rename 'sync volume' to 'deferred volume'.
This just covers Lennart's concern over the terminology used.
The majority of this change is simply the following command:
grep -rli sync[-_]volume . | xargs sed -i 's/sync_volume/deferred_volume/g;s/PA_SINK_SYNC_VOLUME/PA_SINK_DEFERRED_VOLUME/g;s/PA_SOURCE_SYNC_VOLUME/PA_SOURCE_DEFERRED_VOLUME/g;s/sync-volume/deferred-volume/g'
Some minor tweaks were added on top to tidy up formatting and
a couple of phrases were clarified too.
Colin Guthrie [Tue, 6 Sep 2011 10:35:33 +0000 (11:35 +0100)]
modargs: Ensure modargs can be accessed in their raw form.
When dealing with proplists passed as modargs, we need the unescaped form
in order to properly deal with quotes (ticks + double quotes). As the previous
code always called pa_unescape() before adding it into the modarg hashmap, this
was impossible.
This modification simply stores two proplists. If the unescaped value
is different from the raw value, we also keep the raw form.
When parsing proplist arguments, we use this raw form and do the unescaping
ourselves when processing it.
This changes the current behaviour which required you to double escape
proplists arguments. This double escape mechanism did allow you to mix
and match what types of quotes you used to delimit the individial
proplist values, but it made the actual data much harder to pass in.
This approach has the drawback that you cannot mix and match the quotes
you use, but this is a very minor issue and IMO pales in comparison to
the general clarity gained.
See the discussion on the mailing list for more background:
http://lists.freedesktop.org/archives/pulseaudio-discuss/2011-September/011220.html
Antonio Ospite [Fri, 9 Sep 2011 10:05:29 +0000 (12:05 +0200)]
alsa-mixer: Add support for the Microsoft Kinect Sensor device
The Kinect shows up as a UAC device after the firmware has been loaded,
but in order to be detected by pulseaudio a 4-channels input only
mapping is needed. Provide a new profile for that and set it with a udev
rule.
pa_core_maybe_vacuum now vacuums if there are either no streams or all devices are suspended.
The mempool_vacuum argument to module-suspend-on-idle is gone and defaults to true now.
Colin Guthrie [Wed, 7 Sep 2011 19:19:44 +0000 (20:19 +0100)]
bluetooth: Bump DBus version to 1.3.0 and drop conditional code.
We used to support older DBus versions but 1.3.0 is two years old
now and by requiring it we cut down of deviated code paths at
runtime and thus have less support issues.
Colin Guthrie [Mon, 5 Sep 2011 21:19:41 +0000 (22:19 +0100)]
raop: Use the port supplied by avahi when connecting to RAOP devices.
The Apple TV for example uses a non-default port, but we previously ignored
this. We now correctly parse the server string but in so doing, we end up
parsing the address twice. As we need a pure IP/hostname of the device itself
to use in our requests, this is somewhat unavoidable.
Sadly there are still other problems with Apple TVs, but this is still
one step closer.
Colin Guthrie [Sun, 4 Sep 2011 19:05:14 +0000 (21:05 +0200)]
formats: Export more functions needed for a clean build.
All of these functions are not actually defined in format.h
(they are defined in internal.h) and thus should really be
included only in libpulsecommon and implemented in a separate
source file.
However if that approach was taken, and these functions were
included in libpulsecommon, then they would have a link time
dependancy on libpulse (as these four functions use other
pa_format_info_* functions). As the opposite is already true
(libpulse depends on libpulsecommon), this is not possible as
it creates a circular dependancy.
Thus the only option is to just to include these four functions
in the map-file, but not actually export any public headers for
them. Of course users could use this implementation by defining
them in their own headers, but the only practical problem
with this approach is naming conflicts which is unlikely to happen.
Colin Guthrie [Sun, 4 Sep 2011 18:40:21 +0000 (20:40 +0200)]
formats: The format code should be in libpulse, not libpulsecommon
Without this change any applications calling e.g. pa_format_info_new()
and friends will be explicitly linked against libpulsecommon-$MAJORMINOR.so
which is something we specifically avoid as it may contain ABI/API unstable
functions.
Also ensure we export pa_format_info_from_string() for external use.