Commit graph

6884 commits

Author SHA1 Message Date
Wim Taymans
082463efd0 protocol: add v0 compatibility
For flatpaks we need to be able to support older v0 protocol clients.
To handle this we have:

- the connection detects an old client when it receives the first
  message. It can do this by checking the sequence number, on old
  versions it contains the message size and is never 0, on new
  clients the sequence number is 0.

- We add a new signal at the start of the connection with the detected
  version number. This installs the right version of the core proxy.
  We also move the binding of the client until the hello message is
  received. This way we can have a new client connect (portal),
  hand over the connection to an old client, which then removes the
  client binding again in the hello request with a v0 version.
  There are some changes to the passing of fds in v0 vs v3 which need
  to investigated some more.

- bump version of our interfaces to 3. This makes it possible to
  have v0 and v3 protocol marshal functions.

- Add version number in the proxy. This is mostly automatically done
  internally based on the version numbers the library is compiled
  with. Where the version number was in the API before, it is now
  actually used to look up the right protocol marshal functions. For
  Proxies there is usually just 1 version, the current one. It is the
  server that will support different versions.

- Add v0 compat marshal functions to convert from and to v0 format.
  This has some complications. v0 has a type map it keeps in sync
  with the server. For this we have a static type map with mappings
  to our own v3 types. Pods are mostly the same except for objects
  that used to have arbitrary pods in v0 vs spa_pod_prop in v3. Also
  convert between v0 spa_pod_prop and v3 spa_pod_choice.
  Formats and commands are also slightly different so handle those
  mappings as well.
  We only have marshal functions for the server side (resource)
  v0 functions.

- Add v0 compatible client-node again. It's a bit tricky to map, v0
  client-node basically lets the server to the mixing and teeing
  and just does the processing of the internal node.
2019-10-08 23:20:18 +02:00
Wim Taymans
d99350635a protocol-native: add flags for future extensions 2019-10-08 22:46:25 +02:00
Wim Taymans
117db11f7e Remove some unused fields 2019-10-08 22:44:56 +02:00
Wim Taymans
9d842fb5eb improve debug and error reporting 2019-10-08 22:33:31 +02:00
Wim Taymans
0ecbe4844e mixer: Move floatmix to the audio mixer plugin
Move floatmix to the audiomixer plugin and change the name to
AUDIO_MIXER_DSP.
Add runtime selectable sse and sse2 optimizations.
Load the port mixer plugin dynamically based on the factory_name.
Add some more debug
2019-10-03 16:20:12 +02:00
Wim Taymans
1f700e7cdd dict: add SORTED flag and faster lookup in that case 2019-10-03 09:29:51 +02:00
Wim Taymans
fb95e7660a media-session: start the midi bridge from the session 2019-10-02 21:12:42 +02:00
Wim Taymans
6e0c279bc1 improve properties on objects 2019-10-02 20:16:12 +02:00
Wim Taymans
9c4e5f4e27 port: improve buffer handling
Remove the buffers_move method, it's not needed.
2019-10-02 18:34:03 +02:00
Wim Taymans
d4fab985a2 small leak fixes 2019-10-02 18:33:47 +02:00
Wim Taymans
5cfb6634f4 port: select a mixer when we set a format
When the port receives a format, look if we can find a mixer for it
and configure it.

Use the float32 mono mixer when possible.

Use the new pw_buffers in the link.

Let the port allocate buffers between the mixer and node when
requested.

The client-node doesn't need a mixer because mixing is done on the
client.

Remove all mixer and buffer negotiation code from adapter because
it is now done at the port level.
2019-10-02 18:07:10 +02:00
Wim Taymans
4a47bf4706 buffers: refactor buffer allocation code
Refactor the code in pw_link to allocate buffers. Add some more
options and make it generally useful to negotiate buffers between
2 ports.
2019-10-02 18:05:48 +02:00
Wim Taymans
e04d58ee3a Improve some debug 2019-10-02 18:02:07 +02:00
Wim Taymans
6e0ffb0c47 flags: change flag macros
SPA_FLAG_CHECK -> SPA_FLAG_IS_SET
SPA_FLAG_UNSET -> SPA_FLAG_CLEAR
Add SPA_FLAG_UPDATE
2019-10-02 18:00:42 +02:00
Wim Taymans
cc8e992cd1 protocol: improve flushing
Use the IO_OUT flag to schedule flushing instead of a flush_event.

Handle EGAIN and wait for IO_OUT to try again.

Fixes #111
2019-10-01 12:53:56 +02:00
Wim Taymans
3d48ba8394 connection: move remaining data and fds
If we can't send all of the data, move the remaining data to the
start of the buffer so that we can send it again later.

See #111
2019-10-01 10:45:20 +02:00
Wim Taymans
82ee139f65 spa: improve object properties 2019-10-01 10:04:22 +02:00
Wim Taymans
dc83c10c9a media-session: add device reservation for alsa
Implement the device reservation DBus API.

When we acquire the device name, set our device profile to 'On'. This
adds our sources and sinks to the graph.

When we lose the name, switch back to 'Off' and remove our nodes
again.

Move the session mamager stuff in a directory.

Fixes #191
2019-09-30 21:51:46 +02:00
Wim Taymans
96ac81958b properties: setf with NULL format is like remove 2019-09-30 10:41:31 +02:00
Barry Song
df495b5a8e link: fix the race condition of port_set_io
This patch is fixing random crashes when vlc player connects rtsp.
we have two places to do link_activate, one is in node_activate(1),
the other one happens on link_paused(2).

The order of (1) and (2) can vary for each different connection.
Sometimes, (1) comes before (2); Sometimes, (1) comes after (2).
This will cause one crash in about five connections from vlc to
rtsp.

If link_paused(2) is earlier than node_activate, it will do set_io
and make activated=true, then when node_activate(1) comes, nothing
will happen:
int pw_link_activate(struct pw_link *this)
{
        struct impl *impl = SPA_CONTAINER_OF(this, struct impl, this);
        int res;

        pw_log_debug(NAME" %p: activate %d %d", this, impl->activated, this->info.state);

        if (impl->activated)
                return 0;
        ...
}
In this case, everything works well.

If node_activate(1) is earlier than (2), it will do port_set_io, but
"activated" will still be false after port_set_io since the link state
can be not PW_LINK_STATE_PAUSED:
int pw_link_activate(struct pw_link *this)
{
        struct impl *impl = SPA_CONTAINER_OF(this, struct impl, this);
        int res;

        pw_log_debug(NAME" %p: activate %d %d", this, impl->activated, this->info.state);

        if (impl->activated)
                return 0;

        pw_link_prepare(this);

        ... // port_set_io

        if (this->info.state == PW_LINK_STATE_PAUSED) {
                pw_loop_invoke(this->output->node->data_loop,
                       do_activate_link, SPA_ID_INVALID, NULL, 0, false, this);
                impl->activated = true;
        }
        return 0;
}
Then when link_paused(2) happens after (1), port_set_io will be done
again.
This will lead to random crash of pipewire.

Signed-off-by: Barry Song

Fixes #186
2019-09-30 09:32:35 +02:00
Wim Taymans
4421cc473b Revert "link: only set port io once"
This reverts commit 024429ea7b.
2019-09-30 09:27:00 +02:00
Wim Taymans
024429ea7b link: only set port io once
Only set port_io once.

Fixes #186
2019-09-27 10:34:51 +02:00
Wim Taymans
c59af4debc examples: copy properties for pw_remote_export()
pw_remote_export() takes ownership of the properties so make a copy
of the ones we still want to hold on to.
2019-09-27 10:13:21 +02:00
Wim Taymans
68fc530d9c remote: take ownership of properties in _export()
pw_remote_export() takes ownership of the properties so implement
this in the device and spa_node export functions.

Fixes #187
2019-09-27 10:06:25 +02:00
George Kiagiadakis
5183e1d4b4 bluez-monitor: fix usage of pw_properties_setf without a format string
Otherwise compilation will fail with certain -Wformat-security flags
Add the flag to the warnings.
2019-09-26 17:26:23 +02:00
Wim Taymans
efe3aba608 adapter: put port channel in port name if possible 2019-09-25 10:44:40 +02:00
Wim Taymans
db341a6450 improve properties on node and port
Rename some alsa filenames.
2019-09-23 20:51:34 +02:00
Wim Taymans
77e07e1948 improve properties on globals and ports 2019-09-20 13:28:06 +02:00
Wim Taymans
6756a3c8fc monitor: remove monitor API and use device
Remove the monitor API, we can use the device API for it. Make sure
we support creating devices (like alsa) from another device (udev).

Use new object.id to store the object id in the object properties. Use
the port.id/node.id etc to make relations to other objects.
2019-09-20 13:04:14 +02:00
Wim Taymans
818fb9e904 alsa: add midi bridge
Add a node that exposes all midi input and output ports and converts to
and from PipeWire control streams.
2019-09-19 16:57:00 +02:00
Wim Taymans
4381e79632 control: clean up some control includes
Remove control from channelmix, it's not used
Add control metadata
Add OSC control type
Improve some docs
2019-09-16 15:49:46 +02:00
Wim Taymans
8b85cc225e rename HAVE/NEED_BUFFER -> HAVE/NEED_DATA
It is more generic and works with control-only ports as well
2019-09-16 12:55:23 +02:00
Wim Taymans
d648ea4ad3 control: don't fail on async port_set_io 2019-09-10 18:50:28 +02:00
Wim Taymans
7fd6d6d820 node: revert previous commit
Always add work to the work queue, some code relies on the fact that
the state change continuation happens from next iteration of the
mainloop.

Don't warn when destroying the work queue and there are still items in
it, this is ok.
2019-09-10 12:27:29 +02:00
Wim Taymans
80ba0b2dcf node: only put async state changes to work queue 2019-09-10 12:13:26 +02:00
Wim Taymans
c9855763c3 remote: always close the fd in connect_fd
Not closing the fd causes leaks in existing apps. It's probably better
to always close it and let apps deal with that by using dup or similar.

Make gst sink and source dup the fd before connect_fd().

Fixes #181
2019-09-10 11:05:38 +02:00
Wim Taymans
3142d3b979 mem: add private mapping flag 2019-09-10 09:59:31 +02:00
Wim Taymans
b9e517ee67 pipewire: add PIPEWIRE_LOG environment variable
PIPEWIRE_LOG will redirect logging to a file.
2019-09-10 09:44:05 +02:00
Wim Taymans
0fe7f9765d link: use the port as the work-queue object
Use the port as the object/seq identifier of the defered work. This
way we can handle feedback links between the same node and identify
what port completed.
2019-09-10 09:42:23 +02:00
Wim Taymans
9c9bff8fe9 data-loop: add _wait function
Add function to wait for one iteration of the loop. This can be used
by specialized implementations of the data loop, like jack.
2019-09-09 17:17:03 +02:00
Wim Taymans
3340f3cacc core: don't touch unassigned nodes that don't need_driver 2019-09-05 17:06:49 +02:00
Wim Taymans
bd2d0ebc75 node: handle target without node 2019-09-03 13:57:20 +02:00
Wim Taymans
faaf84286b node: improve position and transport
Reorganize some things, let the clients update the segment info
in their own activation, then let the server merge it. This avoids
clients stepping on eachother. When looping through the clients,
copy the segment info when we encounter its owner.

Remove the list of segment owners to the activation. This is better
than in the activation because we can then just keep one list of
owners.

Remove the NONBLOCK flag from the eventfd so that we can do blocking
reads as well.

Just keep a reposition owner in the driver activation. This points
to the node that has the reposition info. This avoid complicated
synchronization to keep multiple nodes from stepping on eachother.
Now they can just prepare the reposition info in their activation and
set themselves as the reposition owner. The last one who succeeds
wins.
2019-09-02 12:05:05 +02:00
Wim Taymans
ca34a75173 protocol-native: attempt to remove socket
After we grab the lockfile we should remove the socket when it
exists so that we can bind again. This should solve startup
problems after a crash, which left the socket around and caused
bind failures.
2019-08-30 18:08:00 +02:00
Wim Taymans
0f9594e119 node: add suport for quantum updates
When the node latency property is changed, trigger a graph recalc
to set the new quantum if needed.

Also update the driver quantum when unassigned nodes are assigned
to a driver.
2019-08-30 17:00:26 +02:00
Wim Taymans
8afa5b0ada node: move segment owner into the io area
This makes it easier to keep track of who is responsible for what.
Also remove the valid fields and move them to flags in the segment
info. That way, the owner can update the flags without having to
worry about concurrency.

Keep separate info for the reposition information. We need to do this
to make it possible to seek in other formats than the frame.

Clear out the owner field when the node is destroyed or removed from
the driver.
2019-08-29 18:24:09 +02:00
Wim Taymans
a910deb0fc pipewire: set default log level to WARNING 2019-08-29 15:34:36 +02:00
Wim Taymans
35c5cf9b52 node: improve sync
Place the requested sync and position update flag in the node
activation. This way we can use our existing loop to update the node
sync states and check if the node is ready.

Implement sync timeout, when the client can't start or seek within the
timeout, we start RUNNING anyway and hope the client catches up.
2019-08-29 14:01:48 +02:00
Wim Taymans
84405dae2a node: add fields to support sync
Sync is enabled when clients need time to move to a new location.
It's a bit like GStreamer preroll after a seek. Clients that need
time, increment the sync_total. Whenever a seek is done, the server
waits in the Starting state until the sync_pending is 0 (or timeout
later).

Improve atomic operations
2019-08-28 13:56:23 +02:00
Wim Taymans
0a15e1f804 io: add offset for clock times
Add an offset to apply to the clock time before we can compare to the
segment values. This way we can keep the segment start independent of the
clock values and we only need to adjust the offset when paused. It's
like the base_time in GStreamer to calculate the running time.
2019-08-28 10:28:06 +02:00