Commit graph

253 commits

Author SHA1 Message Date
Ahmed S. Darwish
f665b2b10d protocol-native: Don't signal memfd support for 9.0 clients
Although such 9.0 clients support memfd transport, they have an
iochannel bug that would break memfd audio if they're run in 32
bit mode over a 64-bit kernel. Influence them to use the POSIX
shared memory model instead.

Also bump the protocol version to exclusively mark such v9.0
libraries. Check commit 451d1d6762 for further details.

BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=97769
Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
2016-11-19 15:11:59 +02:00
Pierre Ossman
eeec52caa0 memblockq: move minreq handling in to memblockq
Having it handled in the callers proved to be a poor fit as it
became difficult to handle a shrinking minreq sanely. It could end
up in a state where the request was never sent downstream to the
client.
2016-07-22 14:44:35 +05:30
Ahmed S. Darwish
82d0314a05 protocol-native: DRY: Remove pdispatch callbacks declarations
Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
2016-07-04 21:08:36 +03:00
Arun Raghavan
7ac5390042 client, protocol-native: Use macros for protocol version/flag access
This makes it easier to read and cleaner in general.
2016-06-22 12:55:54 +05:30
Ahmed S. Darwish
d2a6afcab3 core: Support memfd transport; bump protocol version
Now that all layers in the stack support memfd blocks, add memfd
support for the daemon's global core mempool. Also introduce
"enable-memfd=" daemon argument and configuration option.

For now, memfd support is an opt-in feature to be activated only
when daemon's enable-memfd= is set to yes.

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
2016-04-27 18:37:08 +05:30
Ahmed S. Darwish
b1d47d60fc client audio: Support memfd transport
Now that all layers in the stack support memfd blocks, add memfd
pools support for client context and audio playback data.

Use such memfd pools by default only if the server signals memfd
support in its connection negotiations.

Also add ability for clients to force-disable memfd transport
through the `enable-memfd=' client configuration option.

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
2016-04-27 18:37:07 +05:30
Tanu Kaskinen
16b4624961 sink-input, source-output: remove set_name()
pa_sink_input_set_property() does everything pa_sink_input_set_name()
does.
2016-04-25 13:50:47 +03:00
Ahmed S. Darwish
26d5b6d199 protocol-native: Disable srbchannel for setups without SCM_CREDENTIALS
srbchannel needs fd passing. Otherwise we get the following error
for systems without SCM_CREDENTIALS support:

    Code should not be reached at pulsecore/pstream-util.c:95,
    function pa_pstream_send_tagstruct_with_fds(). Aborting.

[[ The root cause is that we define HAVE_CREDS only if
SCM_CREDENTIALS is defined, but SCM_CREDENTIALS is a Linux-specific
symbol. Thus HAVE_CREDS is always disabled on Solaris.

And since pulse couples the non-portable creds passing support
with the portable fd passing one, through _35_ places where
HAVE_CREDS is used, a real fix needs a PA redesign -- assuming that
latency on Solaris is something people care about. ]]

BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=94339
Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
2016-04-24 18:16:34 +03:00
Ahmed S. Darwish
27d0a3b388 pstream: Support memfd blocks transport
Now that we have the necessary infrastructure to memexport and
mempimport a memfd memblock, extend that support higher up in the
chain with pstreams.

A PA endpoint can now _transparently_ send a memfd memblock to the
other end by simply calling pa_pstream_send_memblock() – provided
the block's memfd pool was earlier registered with the pstream.

If the pipe does not support memfd transfers, we fall back to
sending the block's full data instead of just its reference.

** Further details:

A single pstream connection usually transfers blocks from multiple
pools including the server's srbchannel mempool, the client's
audio data mempool, and the server's global core mempool.

If these mempools are memfd-backed, we now require registering
them with the pstream before sending any blocks they cover. This
is done to minimize fd passing overhead and avoid fd leaks.

Moreover, to support all these pools without hard-coding their
number or nature in the Pulse communication protocol itself, a new
REGISTER_MEMFD_SHMID command is introduced. That command can be
sent _anytime_ during the pstream's lifetime and is used for
creating on demand SHM ID to memfd mappings.

Suggested-by: David Henningsson <david.henningsson@canonical.com>
Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
2016-04-02 05:55:14 +02:00
Ahmed S. Darwish
ee2db62277 pulsecore: Specially mark global mempools
Color global mempools with a special mark. This special marking
is needed for handling memfd-backed pools.

To avoid fd leaks, memfd pools are registered with the connection
pstream to create an ID<->memfd mapping on both PA endpoints.
Such memory regions are then always referenced by their IDs and
never by their fds, and so their fds can be safely closed later.

Unfortunately this scheme cannot work with global pools since the
registration ID<->memfd mechanism needs to happen for each newly
connected client, and thus the need for a more special handling.
That is, for the pool's fd to be always open :-(

Almost all mempools are now created on a per-client basis. The
only exception is the pa_core's mempool which is still shared
between all clients of the system.

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
2016-04-02 05:53:33 +02:00
Ahmed S. Darwish
b88acd0266 pulsecore: Transform pa_mempool_new() into a factory method
Soon we're going to have three types of memory pools: POSIX shm_open()
pools, memfd memfd_create() ones, and privately malloc()-ed pools.

Thus introduce annotations for the memory types supported and change
pa_mempool_new() into a factory method based on required memory.

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
2016-04-02 05:44:34 +02:00
Ahmed S. Darwish
211a520543 srbchannel: Introduce per-client SHM files
The PA daemon currently uses a single SHM file for all clients
sending and receiving commands over the low-latency srbchannel
mechanism.

To avoid leaks between clients in that case, and to provide the
necessary ground work later for sandboxing and memfds, create the
srbchannel SHM files on a per-client basis.

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
2016-04-02 05:41:28 +02:00
Peter Meerwald
d36baaf81e core: Add missing return on protocol error
CID 1323582

when a protocol error occors, better bail out :)
2015-09-16 08:05:52 +02:00
Arun Raghavan
e490a900e2 protocol-native: Fix source latency calculation in ADJUST_LATENCY mode
This fixes buffer attr calculation so that we set the source latency to
the requested latency. This makes sense because the intermediate
delay_memblockq is just a mechanism to send data to the client. It
should not actually add to the total latency over what the source
already provides.

With this, the meaning of fragsize and maxlength become more
meaningful/accurate with regards to ADJUST_LATENCY mode -- fragsize
becomes the latency the source is configured for (which is then
approximately the total latency until the buffer reaches the client).
Maxlength, as before, continues to be the maximum amount of data we
might hold for the client before overrunning.
2015-05-12 19:49:05 +07:00
David Henningsson
6a71b5f967 protocol-native: Re-enable srbchannel
Signed-off-by: David Henningsson <david.henningsson@canonical.com>
2015-03-11 12:52:42 +01:00
Peter Meerwald
037fdf485f tagstruct: Distinguish pa_tagstruct_new() use cases
pa_tagstruct_new() is called either with no data, i.e. (NULL, 0)
to create a dynamic tagstruct or with a pointer to fixed data

introduce a new function pa_tagstruct_new_fixed() for the latter case

Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
2015-02-26 23:23:17 +01:00
David Henningsson
34862dbd43 protocol-native: Disable srbchannel by default
Recent testing has shown some srbchannel related bugs that
indicates that the srbchannel feature is not ready to be enabled
by default.

Therefore, temporary disable it for the 6.0 release and re-enable
it in git master once 6.0 is released.

Bugs:
https://bugs.freedesktop.org/show_bug.cgi?id=88452
https://bugs.freedesktop.org/show_bug.cgi?id=88167

Signed-off-by: David Henningsson <david.henningsson@canonical.com>
2015-01-21 15:06:53 +01:00
Ondrej Holecek
5effc83479 update FSF addresses to FSF web page
FSF addresses used in PA sources are no longer valid and rpmlint
generates numerous warnings during packaging because of this.
This patch changes all FSF addresses to FSF web page according to
the GPL how-to: https://www.gnu.org/licenses/gpl-howto.en.html

Done automatically by sed-ing through sources.
2015-01-14 22:20:40 +02:00
Arun Raghavan
8718496d14 creds: Rename pa_ancil to pa_cmsg_ancil_data
Makes the purpose of the structure clearear.
2014-10-31 10:46:10 +05:30
David Henningsson
22827a5e1e protocol-native: Fail if trying to push unaligned memblock into queue
We will just ignore the memblock if this happens. We already have
a check for this in the client library, so this one is just for
security reasons.

Signed-off-by: David Henningsson <david.henningsson@canonical.com>
2014-10-24 15:01:13 +02:00
David Henningsson
58cffdcfc8 Replace "authorization" with "authentication"
Since we don't have "limited" clients, a client that authenticates
correctly is automatically authorized. However, it's the authentication
that can go wrong, rather than the authorization.

Buglink: https://bugs.freedesktop.org/show_bug.cgi?id=78566
Signed-off-by: David Henningsson <david.henningsson@canonical.com>
2014-09-02 12:50:48 +02:00
Peter Meerwald
fd19327327 srbchannel: pa_srbchannel_new() may fail
return from setup_srbchannel() when pa_srbchannel_new() fails

pa_srbchannel_new() depends on HAVE_SYS_EVENTFD_H, e.g. Debian/kFreeBSD doesn't
have it

Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
Acked-by: David Henningsson <david.henningsson@canonical.com>
2014-08-18 23:21:59 +02:00
David Henningsson
a476371254 protocol-native: Enable srbchannel
The srbchannel is enabled if protocol version >= 30 and
SHM is available. There is also a module parameter
srbchannel=false that can be used for disabling the srbchannel.

The setup is done in these steps:
1) Server receives authentication (like today)
2) Server sends enable_srbchannel to client
3) Server sends memblock to client
4) Client receives enable_srbchannel
5) Client receives memblock
6) Client sends enable_srbchannel back to server
7) Client switches over
8) Server receives enable_srbchannel and switches over

Signed-off-by: David Henningsson <david.henningsson@canonical.com>
2014-06-27 14:28:21 +02:00
David Henningsson
06bc22b220 iochannel/pstream/pdispatch: Add support for receiving file descriptors
The file descriptors are read from the iochannel just like the creds are.
So instead of passing just creds (and creds_valid), we now pass the
entire pa_ancil struct.

Signed-off-by: David Henningsson <david.henningsson@canonical.com>
2014-06-27 14:16:32 +02:00
Tanu Kaskinen
14845b2c8e esound, native: Pass an absolute path to pa_authkey_load() when using a file in the home directory
If a relative path is passed to pa_authkey_load(), it will interpret
the path as relative to the home directory. This is wrong, because
relative paths should be interpreted to be relative to the config home
directory. Before fixing pa_authkey_load(), this patch prepares for
the change by using absolute paths when the file actually needs to be
in the home directory (i.e. the fallback cookie path for the native
protocol and the default cookie path for the esound protocol).
2014-06-24 13:17:16 +03:00
Pierre Ossman
91224484b1 protocol-native: Early request bandaid for high latency sink/source
As it is implemented, the early request mode can in some cases be counter-productive. The mode is designed to give the client a steady request/report rate of small-ish chunks (A somewhat silly client requirement but at least Flash and Firefox break horribly when you break this.).

Unfortunately PulseAudio does not have any mechanism for telling a sink/source how often it should request/report data. So a more blunt hack was applied where the entire latency is restricted to the fragment size.

So far so good, but where the current code breaks down is when the sink cannot satisfy this tiny latency request. We then "report" to the client what we can guarantee by setting the fragment size to the sink's/source's full buffer size/latency.

This severely changes the resulting buffer attributes from what the client requested, and in practice breaks applications. The most prominent user of this feature is the ALSA plugin, and it doesn't even have a mechanism of adapting to the server giving back something different than what was requested.

So long term, the whole early request mode needs to be implemented in a better way. Either the sink's/source's need to grow the ability to control request/report rate. Or we put some form of timer based emulation in front of them on behalf of these clients.

Short term, we should change the behaviour of what happens when we cannot guarantee a fragment rate. Instead of giving the client really shitty buffering parameters as a result, we should just keep the requested attributes and do things on a best-effort basic. Basically how things would behave if the client didn't have the early request bit at all.

The attached patch does just that, as well as expand on the comment about how the early request thing is implemented.

BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=66962
2014-05-23 14:43:32 +02:00
Tanu Kaskinen
ef4ae785aa sink-input, source-output: Remove redundant get_mute() functions
The functions just return the muted value. Callers can as well read
the struct field directly, it's simpler that way.
2014-05-02 16:00:56 +03:00
Arun Raghavan
3152226502 Revert "protocol-native: Don't enumerate unlinked sinks and sources"
This reverts commit bd0bd9143f.
2014-02-17 16:32:40 +05:30
Arun Raghavan
bd0bd9143f protocol-native: Don't enumerate unlinked sinks and sources
This makes sure that there is no window between pa_sink/source_new()
and _put() where enumerating sinks/sources causes an assert (several
calls in sink/source_get_info need a linked sink or source).
2014-02-14 21:36:21 +05:30
Tanu Kaskinen
7297feb50b protocol-native: Fix a crash
Without this check pa_source_output_set_volume() crashes if
so->volume_writable is false. The same check already exists for sink
inputs.

BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=74529
2014-02-04 21:32:16 +02:00
Peter Meerwald
94deb3725d core: Fix asserting command in protocol-native
https://scan7.coverity.com:8443/reports.htm#v10206/p10016/fileInstanceId=8690&defectInstanceId=3688&mergedDefectId=591259

Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
2013-12-20 12:55:17 +01:00
Peter Meerwald
e11b699d45 core: Fix uninit pointer read in protocol-native
https://scan7.coverity.com:8443/reports.htm#v10205/p10016/fileInstanceId=8690&defectInstanceId=3703&mergedDefectId=591290&eventIds=3703-7&eventId=3703-7

Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
2013-12-20 12:55:17 +01:00
Tanu Kaskinen
a67318f8af Add pa_sample_rate_valid()
I think this makes the code a bit nicer to read and write. This also
reduces the chances of off-by-one errors when checking the bounds of
sample rate values.
2013-12-15 11:21:56 +01:00
Tanu Kaskinen
ce304d6208 Pass the profile object instead of the profile name to pa_card_set_profile()
When setting attribute foo, or in this case the card profile, in my
opinion the thing passed to the set_foo() function should be of the
type of foo, not a string identifier that can be used to search for
the actual foo in set_foo().

This is mostly a question of taste, but there's at least some small
benefit from passing the actual object: often the profile object is
already available when calling pa_card_set_profile(), so passing the
card name would cause unnecessary searching when pa_card_set_profile()
needs to look up the profile from the hashmap.
2013-11-29 07:25:13 +02:00
Scott Reeves
5ddb486a8c protocol-native: Remove written differently but functionally redundant check. 2013-11-29 06:56:10 +02:00
Parin Porecha
382b8294e3 protocol-native: Express XOR asserts more concisely
7 instances of the roundabout asserts were found,
All of them have been replaced with appropriate XOR asserts.

BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=47493
2013-11-20 09:06:47 +02:00
Arun Raghavan
6825df8cec hashmap: Add the ability to free keys
Since the hashmap stores a pointer to the key provided at pa_hashmap_put()
time, it make sense to allow the hashmap to be given ownership of the key and
have it free it at pa_hashmap_remove/free time.

To do this cleanly, we now provide the key and value free functions at hashmap
creation time with a pa_hashmap_new_full. With this, we do away with the free
function that was provided at remove/free time for freeing the value.
2013-09-17 18:01:22 +05:30
Luiz Augusto von Dentz
b98a2e158f introspect: Expose card profile available flag
Available flag can be used by clients to disable the selection of
profiles unavailable.

Update protocol to 29
2013-07-15 19:41:07 +03:00
poljar (Damir Jelić)
d806b19714 Remove pa_bool_t and replace it with bool.
commands used for this (executed from the pulseaudio/src directory):
    find . -regex '\(.*\.[hc]\|.*\.cc\|.*\.m4\)' -not -name 'macro.h' \
        -a -not -name 'reserve.[ch]' -a -not -name 'reserve-monitor.[ch]' \
        -a -not -name 'glib-mainloop.c' -a -not -name 'gkt-test.c' \
        -a -not -name 'glib-mainloop.c' -a -not -name 'gkt-test.c' \
        -a -not -name 'poll-win32.c' -a -not -name 'thread-win32.c' \
        -a -not -name 'dllmain.c' -a -not -name 'gconf-helper.c' \
        -exec sed -i -e 's/\bpa_bool_t\b/bool/g' \
        -e 's/\bTRUE\b/true/g' -e 's/\bFALSE\b/false/g' {} \;

and:
    sed -i -e '181,194!s/\bpa_bool_t\b/bool/' \
        -e '181,194!s/\bTRUE\b/true/' -e \
        '181,194!s/\bFALSE\b/false/' pulsecore/macro.h
2013-07-04 12:25:30 +03:00
poljar (Damir Jelić)
97da92d894 Whitespace cleanup: Remove all multiple newlines
This patch removes all occurrences of double and triple
newlines.

Command used for this:
find .  -type d \( -name ffmpeg \) -prune -o \
        -regex '\(.*\.[hc]\|.*\.cc\)' \
        -a -not -name 'adrian-aec.*' -a -not \
        -name reserve.c -a -not -name 'rtkit.*' \
        -exec sed -i -e '/^$/{N;s/^\n$//}' {} \;

Two passes were needed to remove triple newlines.
The excluded files are mirrored files from external sources.
2013-06-24 16:56:24 +03:00
poljar (Damir Jelić)
e95d054e40 Style fix: Remove new lines from opening brackets
This patch replaces every occurrence of ')\n{' with ') {'.

Command used for this:
    find .  -type d \( -name ffmpeg \) -prune -o \
        -regex '\(.*\.[hc]\|.*\.cc\)' \
        -a -not -name core-util.c -a -not \
        -name adrian-aec.c -a -not -name g711.c \
        -exec sed -i -e '/)$/{N;s/)\n{$/) {/}' {} \;

The excluded files are mirrored files from external sources.
2013-06-24 16:56:24 +03:00
Tanu Kaskinen
1e42a289d4 native: Don't enable prebuffering when draining
BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=64284
2013-06-11 13:46:44 +03:00
Tanu Kaskinen
0bbef56976 device-port: Make it impossible to have dual-direction ports 2013-06-04 00:38:39 +05:30
David Henningsson
5f326b705d protocol-native: Lower default minreq in low-latency scenarios
If minreq is not explicitly specified, it was always initialized to
20 ms (DEFAULT_PROCESS_MSEC). However when the total latency is not
much higher than 20 ms, this is way too high. Instead use
tlength/4 as a measure: this will give a decent sink_usec in all
modes (both traditional, adjust latency and early request modes).

This greatly improves PulseAudio's ability to ask for data in time
in low-latency scenarios.

Signed-off-by: David Henningsson <david.henningsson@canonical.com>
2013-03-25 15:44:34 +02:00
David Henningsson
2026c41be6 protocol-native: Ensure tlength is not set higher than maxlength
Tlength should never be set higher than maxlength. While this is
corrected by memblockq later, we still need a correct tlength for
the subsequent calculations.

Signed-off-by: David Henningsson <david.henningsson@canonical.com>
2013-03-25 15:43:33 +02:00
Arun Raghavan
15009b03f1 protocol-native: Fix some debug output
s->buffer_attr_req is what we want to be printing from since that holds
the actualy requested buffer attributes.
2013-03-25 09:47:04 +00:00
David Henningsson
e87eb85474 core, alsa: Better drain reporting
Previously, a drain request was acknowledged up to two hw buffers
too late, causing unnecessary delays.

This implements a new chain of events called process_underrun
which triggers exactly when the sink input has finished playing,
so the drain can be acknowledged quicker.

It could later be improved to give better underrun reporting to
clients too.

Tested-by: Dmitri Paduchikh <dpaduchikh@gmail.com>
Signed-off-by: David Henningsson <david.henningsson@canonical.com>
2013-03-20 11:55:42 +01:00
Tanu Kaskinen
061878b5a4 idxset: Use pa_free_cb_t instead of pa_free2_cb_t
There were no users for the userdata pointer.
2013-02-16 01:15:27 +02:00
Tanu Kaskinen
8872c238ba hashmap: Use pa_free_cb_t instead of pa_free2_cb_t
The previous patch removed module-gconf's dependency on the userdata
pointer of the free callback, and that was the only place where the
userdata pointer of pa_free2_cb_t was used, so now there's no need for
pa_free2_cb_t in pa_hashmap_free(). Using pa_free_cb_t instead allows
removing a significant amount of repetitive code.
2013-02-16 01:12:21 +02:00
Tanu Kaskinen
0f44b1e820 Log the reason for every suspend/resume.
I was looking at a log that showed that a suspend happened (at
a strange time), but the log didn't tell me why the suspend was done.
This patch tries to make sure that that won't happen again.
2012-12-19 12:31:47 +02:00