Commit graph

11083 commits

Author SHA1 Message Date
Barnabás Pőcze
d7c54b3d82 gitignore: do not ignore the ".gitlab" directory 2023-07-11 14:23:53 +02:00
Barnabás Pőcze
fe45786a5d treewide: add some examples for the spa_auto* macros 2023-07-11 14:23:53 +02:00
Barnabás Pőcze
65d949558b spa: utils: add scope based resource cleanup
systemd, dbus-broker, and many glib applications heavily
utilize the GNU C attribute "cleanup" to achieve C++ RAII-like
semantics for local resource management. This commit introduces
essentialy same mechanism into pipewire.

At the moment, this is inteded to be a strictly private API.

free() and close() as cleanup targets are sufficiently common
to warrant their own special macros:

  spa_autofree char *s = strdup(p);
  // will call `free(s)` at the end of the lifetime of `s`

  spa_autoclose int fd = openat(...);
  // will call `close(fd)` if `fd >= 0` at the end of the lifetime of `fd`

However, with `spa_auto()` or `spa_autoptr()` it is possible to define
other variables that will be cleaned up properly. Currently four are supported:

  spa_autoptr(FILE) f = fopen(...);
  // `f` has type `FILE *`
  // will call `fclose(f)` if `f != NULL`

  spa_autoptr(DIR) d = opendir(...);
  // `d` has type `DIR *`
  // will call `closedir(d)` if `d != NULL`

  spa_autoptr(pw_properties) p = pw_properties_new(NULL, NULL);
  // `p` has type `struct pw_properties *`
  // will call `pw_properties_free(p)`

  spa_auto(pw_strv) v = pw_split_strv(...);
  // `v` has type `char **`
  // will call `pw_strv_free(v)`

It is possible to add support for other types, e.g.

  SPA_DEFINE_AUTOPTR_CLEANUP(pw_main_loop, struct pw_main_loop, {
    // the pointer can be accessed using `*thing`
    // `thing` has type `struct pw_main_loop **`
    spa_clear_ptr(*thing, pw_main_loop_destroy);
  })

  spa_autoptr(pw_main_loop) l = ...;
  // `l` has type `struct pw_main_loop *`
  // will call `pw_main_loop_destroy(l)`

or

  SPA_DEFINE_AUTO_CLEANUP(spa_pod_dynamic_builder, struct spa_pod_dynamic_builder, {
    // `thing` has type `struct spa_pod_dynamic_builder *`
    spa_pod_dynamic_builder_clean(thing);
  })

  spa_auto(spa_pod_dynamic_builder) builder = ...
  // `builder` has type `struct spa_pod_dynamic_builder`
  // will call `spa_pod_dynamic_builder_clean(&builder)`

The first argument is always an arbitrary name. This name must be passed to
`spa_auto()` and `spa_autoptr()` as it is what determines the actual type
and destructor used. The second parameter is the concrete type. For
`SPA_DEFINE_AUTO_CLEANUP()` this is the concrete type to be used, while for
`SPA_DEFINE_AUTOPTR_CLEANUP()` it is the concrete type without the
outermost pointer. That is,

  SPA_DEFINE_AUTOPTR_CLEANUP(A, foo, ...)
  SPA_DEFINE_AUTO_CLEANUP(B, foo, ...)

  spa_autoptr(A) x; // `x` has type `foo *`
  spa_auto(B) y; // `y` has type `foo`

A couple other macros are also added:

  spa_clear_ptr(ptr, destructor)
  // calls `destructor(ptr)` if `ptr != NULL` and sets `ptr` to `NULL`

  spa_clear_fd(fd)
  // calls `close(fd)` if `fd >= 0` and sets `fd` to -1

  spa_steal_ptr(ptr)
  // sets `ptr` to `NULL` and returns the old value,
  // useful for preventing the auto cleanup mechanism from kicking in
  // when returning the pointer from a function

  spa_steal_fd(fd)
  // sets `fd` to -1 and returns the old value
2023-07-11 14:23:53 +02:00
Wim Taymans
4456f2efd1 impl-node: remove the node from the target peers
When we destroy a node, we need to remove the node as a current
driver peer.

Not doing this has 2 problems:
- remote drivers still trigger our node
- the client-node does not clean up the memid for the activation and
  we might reuse it later for a new node with the same fd.

See #3316
2023-07-10 16:59:17 +02:00
Wim Taymans
098ac51272 remote-node: don't init/release our special mix
We have SPA_ID_INVALID mix id for all ports to handle the formats and
buffers, we don't need to init/release the mix for this or else our
n_mix accounting is wrong and we might not clear the format right.
2023-07-10 16:56:58 +02:00
Wim Taymans
3e0050d1cd client-node: clear resource after freeing mem
Some of the mem unref might send a message to the client.

This is not actually the case right now but just to be safe for the
future.
2023-07-10 16:55:05 +02:00
Wim Taymans
a966d4806b improve debug 2023-07-10 16:52:39 +02:00
Wim Taymans
f459320968 impl-node: first remove, then add ourselves
First remove ourself from the old driver, then add ourself to the
new driver.

This got changed as a possible error in b8fe832188
2023-07-10 11:15:53 +02:00
Wim Taymans
baa5497617 spa: warn out of buffers
Running out of buffers is pretty bad and warrants a warning because it
can cause loss of audio.

See #3316
2023-07-07 12:11:02 +02:00
Wim Taymans
21d16b1ad5 module-raop: zero uppet timestamp bits
The Audiopro link1 seems to want to upper bits of the timestamp in
sync messages as 0. It still seems to work with Sonos.

See #3247
2023-07-06 17:01:09 +02:00
Wim Taymans
fdc860c71b protocol-native: give an error when loading twice
Instead of silently ignoring the problem. It's possible that it is
loaded with different settings, which would then silently be ignored.
2023-07-06 13:51:37 +02:00
Wim Taymans
48a892aeec module-rtp: support sess.ignore-ssrc globally 2023-07-06 13:08:21 +02:00
Wim Taymans
126e03ec73 rtp: add option to ignore SSRC
This is useful when there is a fixed receiver and the sender can be
restarted.
2023-07-06 12:55:28 +02:00
Wim Taymans
b95ed6dcc1 jack: create mix explicitly
When we create a port, we should make the SPA_ID_INVALID mix_id for the
shared info on the mixer ports.
Only mix_info should create and destroy mix structures.
2023-07-06 12:53:28 +02:00
Wim Taymans
a9a9c72a0a client-node: create mix explicitly 2023-07-06 12:18:27 +02:00
Wim Taymans
44deacbc67 0.3.73 2023-07-06 11:42:24 +02:00
Wim Taymans
fd1fd7a00f module-rtp-source: improve docs a little 2023-07-05 15:29:56 +02:00
Wim Taymans
b5b01f4dd2 resample-peaks: improve peaks some more
Update the i_count in the loop because we use it to check when we have
completed a chunk.
2023-07-05 14:07:30 +02:00
Wim Taymans
48bf039e25 resample-peaks: fix peaks resampler
Avoid some segfaults in some cases.

fixes #3320
2023-07-05 13:46:08 +02:00
Wim Taymans
178f452127 context: upsample small rates up to the default rate
When the samplerate is smaller than half of the default, try to find a
rate less than the default to upsample to.

pavucontrol now asks for a 1/144 rate, which resulted in a graph rate of
88200 before this change.

See #3320
2023-07-05 12:44:05 +02:00
Wim Taymans
bec73f26a7 impl-node: don't log driver twice
When dumping the driver targets, only log the driver once.
2023-07-05 12:02:35 +02:00
Wim Taymans
159fa7177a alsa: fix threshold sign
Be careful when converting the uint32_t to int64_t, first convert and
then flip the sign.
2023-07-05 12:01:08 +02:00
Wim Taymans
937a13d93f alsa: relax htimestamp threshold a little
Only assume an error when larger than 3 times the expected size. Clamp
to the threshold to not cause excessive delay compensation.
2023-07-05 11:46:19 +02:00
Wim Taymans
895e516a75 pulse-server: support latency_msec in module-raop-discover
See #3247
2023-07-04 14:09:15 +02:00
Wim Taymans
b0a7e4a267 gst: lock/unlock around proxy destroy
See #3324
2023-07-04 12:04:29 +02:00
Wim Taymans
42a099381b v4l2: handle ENOTTY
Instead of erroring out, go to the next format when enumerating frame
size or frame interval.

See #3325
2023-07-04 11:36:37 +02:00
Wim Taymans
4137ff656a module-rt: add option to disable rlimits/portal/rtkit 2023-07-04 11:11:48 +02:00
Wim Taymans
a373d7fde4 module-rt: add comment 2023-07-04 10:36:15 +02:00
Barnabás Pőcze
3c6d1686ca meson.build: add "-Werror=return-type" 2023-07-03 19:40:31 +02:00
Barnabás Pőcze
edbf2dcb4d meson.build: require strict prototypes 2023-07-03 19:40:31 +02:00
Barnabás Pőcze
12a8a916dd meson.build: make old stype defs/decls errors 2023-07-03 19:40:31 +02:00
Barnabás Pőcze
8c17a6626d treewide: mark some functions static
These were found by enabling the "missing-declarations" warning.
2023-07-03 19:40:31 +02:00
Barnabás Pőcze
ab6ff1bcde spa: libcamera: use init list when calling generateConfiguration()
Pass an initializer list to `Camera::generateConfiguration()` instead
of constructing a vector and adding the single element "manually".
2023-07-03 19:40:31 +02:00
Barnabás Pőcze
6275269f09 spa: bluez: remove some unused variables 2023-07-03 19:40:31 +02:00
Barnabás Pőcze
f6ea5421e6 spa: bluez: do not open-code asprintf() 2023-07-03 19:40:31 +02:00
Barnabás Pőcze
605404c781 spa: bluez: device_stop_timer(): remove redundant decl
Also move the declaration of `media_codec_switch_free()`
up to the beginning of the file, near the other decls.
2023-07-03 19:40:31 +02:00
Barnabás Pőcze
0ed8880489 spa: bluez: modemmanager: do not use old style declaration 2023-07-03 19:40:31 +02:00
Barnabás Pőcze
abbdcf1854 spa: bluez: mark modemmanager stub functions static inline 2023-07-03 19:40:31 +02:00
Barnabás Pőcze
ac5dfbe197 pipewire-jack: include "jack/intclient.h"
So that definitions are checked against declarations.
2023-07-03 19:40:31 +02:00
Barnabás Pőcze
0eb463ab98 pipewire: module-client-device: include "client-device.h" in "resource-device.c"
So that definitions are checked against declarations.
2023-07-03 19:40:31 +02:00
Barnabás Pőcze
eaad2b5a87 pipewire: module-avb: include "avb.h" in "descriptors.h"
So that the "avb.h" header file is self-sufficient.
2023-07-03 19:40:31 +02:00
Barnabás Pőcze
c57afbccc1 pipewire: module-avb: add some missing declarations 2023-07-03 19:40:31 +02:00
Barnabás Pőcze
5b05c1c430 pipewire: module-avb: include "avb.h" in "avb.c"
So that definitions are checked against declarations.
2023-07-03 19:40:31 +02:00
Barnabás Pőcze
db510e769a pipewire: module-avb: add missing "stddef.h" include in "avb.h"
Including "stddef.h" is needed for `size_t`.
2023-07-03 19:40:31 +02:00
Barnabás Pőcze
12be42ed6b pipewire: module-netjack2-manager: remove unused module_schedule_destroy() 2023-07-03 19:40:31 +02:00
Barnabás Pőcze
34809d3081 pipewire: module-netjack2-driver: remove unused module_schedule_destroy() 2023-07-03 19:40:31 +02:00
Barnabás Pőcze
0a00d9c4d7 pipewire: module-ffado-driver: remove unused module_schedule_destroy() 2023-07-03 19:40:31 +02:00
Barnabás Pőcze
0f70256230 pulse-server: include "reply.h" in "reply.h"
So that definitions are checked against declarations.
2023-07-03 19:40:31 +02:00
Barnabás Pőcze
3b4a255dec pulse-server: format_info_from_spec(): remove redundant decl 2023-07-03 19:40:31 +02:00
Barnabás Pőcze
1bb714b95e pipewire: utils: make_random(): do not use errno
The function already returns `ssize_t`, so do not use `errno`
to communicate the reason for failure, instead, return the
negative errno.

`pw_getrandom()` was inconsistent in this regard because
sometimes it simply returned a negative errno without
setting `errno`. This change fixes that as well.
2023-07-03 19:40:31 +02:00