Commit graph

972 commits

Author SHA1 Message Date
Dorinda Bassey f4a56ad45d Fix some warnings
added cleanup of unused variables and fix warning about missing initializers
to resolve build warnings in pipewire-rs

Signed-off-by: Dorinda Bassey <dbassey@redhat.com>
2023-11-21 16:32:51 +00:00
Arun Raghavan 2871a65b1f alsa: Add a mechanism to bind ALSA controls as prop params
This adds an api.alsa.bind-ctls property to alsa-pcm sink and source
nodes, to bind a property to an ALSA PCM ctl. The property is an array
of ctl names that should be bound.

This can be handy, for example, to bind the Playback/Capture Rate
controls on a USB gadget, in order to track the PCM's state via a node
param.

This is currently wired to be read-only, but it should be easy enough to
make it writable.
2023-11-07 23:22:53 -05:00
Barnabás Pőcze e4d1ab0c19 spa: debug: log: use SPA_CONTAINER_OF()
Use `SPA_CONTAINER_OF()` instead of direct casting as it is
more resilient against future changes that might reorder the
members in `struct spa_debug_log_ctx`.
2023-11-06 19:01:20 +01:00
Wim Taymans dae0ccacfc spa: explicitly mention that volumes are linear
See #3623
2023-11-04 09:51:14 +01:00
Pauli Virtanen ca0e886159 spa: support: allow spa_log_xxx(NULL, ...) again with UBSan
Calling the spa_log_xxx macros with NULL log used to be allowed,
and it's used in some tests.

Write the NULL check in a way the compiler can understand and make UBSan
a happy UBSan.
2023-10-15 16:20:17 +00:00
Barnabás Pőcze 15e14946fb spa: expose utils/cleanup.h for external users
Up until now, `spa/utils/cleanup.h` was not installed,
but 779f06865c ("pod: add spa_auto support for dynamic builder")
included it in a public header. So now `cleanup.h` also needs to
be installed like any other public header so as to not break
3rd party users.

For example, `xdg-desktop-portal-wlr` would break:
https://codesearch.debian.net/search?q=spa_pod_dynamic_builder_init&literal=1
2023-10-11 19:56:11 +02:00
Wim Taymans 779f06865c pod: add spa_auto support for dynamic builder 2023-10-11 17:27:43 +02:00
Wim Taymans 5102e4cb8d pod: handle realloc failure
When realloc fails, the original pointer is untouched so store the
result of realloc somewhere else so that we don't cause a leak.
2023-10-11 17:26:40 +02:00
Barnabás Pőcze 03901dec2c spa: support: log: remove spa_log_level_enabled()
This is not used anymore in the tree, nor in any 3rd party
code I could find on debian codesearch and github.
2023-10-06 11:11:15 +00:00
Barnabás Pőcze ebf93f1417 spa: support: log: convert spa_log_level_topic_enabled() to a function
There is no reason for it to be a macro.
2023-10-06 11:11:15 +00:00
Barnabás Pőcze 0366a52f3a spa: support: log: convert spa_log_topic_init() to a function
There is no reason for this to be a macro.
2023-10-06 11:11:15 +00:00
Barnabás Pőcze 2e9633b6f6 spa: debug: log: add missing includes
Include `spa/debug/{pod,format,mem,dict}.h` for the declarations
of `spa_debugc_{pod,format,mem,dict}()`.
2023-09-30 17:22:12 +02:00
Barnabás Pőcze 74419e27b4 spa: utils: cleanup: only have one version of spa_clear_ptr()
Depend on `spa_steal_ptr()` for checking if `ptr` is actually a pointer or not.
2023-09-16 17:21:54 +02:00
Barnabás Pőcze ea159e7af0 spa: utils: cleanup: remove unnecessary cast
`spa_exchange()` already returns a value with the type of the first
input, so there is no need to cast again.
2023-09-16 17:21:08 +02:00
Barnabás Pőcze 7191ccb0b8 spa: utils: cleanup: fix GCC version check
GCC 10 seems to support dereferencing incomplete types in `__typeof__`.
2023-09-16 17:10:07 +02:00
Barnabás Pőcze 3fec887a5f spa: utils: spa_exchange(): try to evaluate argument only once 2023-09-16 17:06:01 +02:00
Wim Taymans 69d431acd4 node: clarify port_set_io and SPA_IO_Buffers
port_set_io with SPA_IO_Buffer can be used to enable/disable a port
when the node is running and so the node should make sure the io update
is synchronized with the processing loop.

Use spa_loop_invoke to make sure the mixers handle the port_io updates
correctly.

Setting buffers or a format also needs the port to be disabled so add
some checks for this in the mixers.
2023-09-11 11:23:25 +02:00
Wim Taymans 016d15e598 ratelimit: missed -> suppressed
To avoid confusing with missed samples.
2023-09-08 12:18:23 +02:00
Wim Taymans 7c7dea890b alsa: redirect dict debug to log 2023-09-07 11:57:43 +02:00
Carlos Rafael Giani 8e6d070148 alsa-compress-offload: Add device object and udev based autodetection
As part of this, in alsa-udev.c, certain structures and variables referred
to as "device" are renamed to "card". Otherwise, there is ambiguity, since
"device" can mean a udev device, an SPA device, a compress-offload device,
a PCM device etc.

Also, replace "card id" with "card number" to emphasize that these integers
are not actually SPA object IDs.
2023-09-02 08:28:22 +00:00
Carlos Rafael Giani 1e3a39a76e spa: Add node.description key 2023-09-02 08:28:22 +00:00
Wim Taymans 41dcac0ecd Port: Add tag param
The tag param has a list of arbitrary key/value pairs. Like the Latency
param, it travels up and downstream. Mixers will append the info
dictionaries or do some more fancy merging.

The purpose is to transport arbirary metadata, out-of-band, through the
graph and it's used for stream metadata and other stream properties.
2023-08-29 14:22:13 +02:00
Wim Taymans e90cab1cde node: add xrun counter in clock io
Add an xrun counter in the clock that accumulated the duration of
xruns. Fill this in in alsa-pcm.

A client could use this to dectect xruns (when it changes) and to align
the position and nsec after an xrun.
2023-08-29 09:22:45 +02:00
Tom A. Wagner 7b40ca4f27 pod: Fix spa_pod_builder_control() return type
Fixes the return type of spa_pod_builder_control() from uint32_t to int.

Since the function returns the int returned by spa_pod_builder_raw,
the return type of the function should also be an int.
2023-08-09 12:59:09 +00:00
Arun Raghavan 86bd0eb708 logger: Add a mechanism to force colourised logging
This is handy if we want to redirect to a file but have colours to make
manual parsing easier (for example with `less -R`).
2023-08-08 17:13:31 +00:00
columbarius 6d59ad21c2 spa: set MANDATORY flag when building video format with modifier
Proper negotiation requires that formats with modifiers are not matched
with those without. This is ensured by using SPA_POD_PROP_FLAG_MANDATORY.
2023-08-08 07:00:11 +00:00
Sourav Das c6c3259a08 spa: fixes for dereferencing pointer to incomplete type in __typeof__
before gcc 10 its not supporting pointer dereferencing in __typeof__.
    so made changes according to that. Fixes #3375

    clang also defines __GNUC__ and resolves '4' along with __clang__ which
    resolves '1'. On any version of clang, __GNUC__ and resolves '4'.
    anyway clang has this feature since version 3.
2023-07-30 10:31:19 +05:30
Ashok Sidipotu 79518d13ae spa: libcamera: consume the device numbers libcamera property
Pass on the device numbers property of libcamera to session managers, with they
are better equipped to filter the camera/video devices across v4l2 and libcamera.
2023-07-19 09:21:03 +00:00
Wim Taymans 983d34f344 spa: add some more docs
See #3351
2023-07-17 17:46:04 +02:00
columbarius 0a13d37e5c spa: Add SPA_VIDEO_FLAG_MODIFIER_FIXATION_REQUIRED
This flags allows clients to use the parse_format functions and
determine from their result directly if the modifer was fixated yet.
2023-07-14 08:20:54 +00:00
Wim Taymans 0501ef165a spa: add atomic.h and port macros to it 2023-07-13 12:25:22 +02:00
Wim Taymans 0cefb71c97 spa: fix compilation 2023-07-11 19:56:44 +02:00
Wim Taymans dc07c2321b spa: add spa_ratelimit 2023-07-11 19:25:35 +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
Dorinda Bassey 98ac13a03e cleanup unused variables
added cleanup of unused variables to resolve build warnings in pipewire-rs

Signed-off-by: Dorinda Bassey <dbassey@redhat.com>
2023-06-26 10:51:09 +00:00
Wim Taymans 5d5576f4a8 spa: make latency struct to compare const 2023-05-11 18:28:03 +02:00
Wim Taymans 727775201f spa: make node callbacks fast 2023-05-06 00:47:39 +02:00
Wim Taymans efea7ad060 hooks: add and use _fast callback function
Add a _fast callback function that skips the version and method check.
We can use this in places where performance is critical when we do the
check out of the critical loops.

Make all system methods _fast calls. We expect them to exist and have
the right version. If we add new versions we can make them slow.
2023-05-06 00:27:12 +02:00
Pauli Virtanen 6e17962ad0 impl-port/audioconvert: add PORT_IGNORE_LATENCY
Add port.ignore-latency prop, which if true causes peer ports to ignore
the latency of the given port.

This is useful for ports that are not intended to affect latency
calculations of other ports, such as ports in monitor streams.
2023-05-03 18:01:00 +00:00
Wim Taymans 83d2e85f49 parser: add extra check to make coverity happy
Fixes !1473
2023-04-20 12:32:07 +02:00
Wim Taymans 45b2983439 aec: add new init2 method to initialize with different formats
The WebRTC echo canceler can support different rates and channels for
the record, out and playback streams.

Add a new method to pass this config to the echo-canceler.
2023-04-11 16:54:11 +02:00
Wim Taymans 74831aa967 support: add support for checking loop context
Add check for running the the loop context and thread.

Add checks in filter and stream to avoid doing things when not run from
the context main-loop because this can crash things when doing IPC from
concurrent threads.
2023-04-04 16:19:41 +02:00
Wim Taymans e5809cf4f4 spa: move audio props to audio section 2023-04-03 21:30:11 +02:00
Ashok Sidipotu dcec2e785e audioconvert: add a invalid value for scale
The invalid value here is zero, this will help avoid inadvertant parameter
updates and brings this on par with rest of the volume ramp parameters
2023-04-03 19:04:55 +00:00
Ashok Sidipotu 8bfafaeca2 audioconvert: add support of volume ramp scale parameter
- Add support for Linear and Cubic volume scales
- Also start treating a "zero" value of volume ramp parameters as invalid
2023-04-03 19:04:55 +00:00
Ashok Sidipotu b0f6c4a8c0 audioconvert: add support for volume ramp time params 2023-04-03 19:04:55 +00:00
Ashok Sidipotu 40cf237eb3 audioconvert: add volume ramp parameters
Add volume ramp parameters and the add ramp up and down funtions which get
triggered on volume change.
2023-04-03 19:04:55 +00:00
Wim Taymans 2adf8d38d5 node: add target_rate and target_duration in io_clock
Place the target rate and duration in the io clock area.

The driver is meant to read these new values at the start of the cycle
and update the position rate and duration.

This used to be done by the pipewire server when it received the ready
callback from the driver but this is in fact too late. Most driver would
start processing and set the next timeout based on the old rate/duration
instead of the new pending ones.

There is still a fallback for the old behaviour (with a warning) when
the driver doesn't yet update the position.
2023-03-23 17:57:16 +01:00
Wim Taymans 345582dd15 module-rtp: add opus encoding 2023-03-12 18:40:36 +01:00
Barnabás Pőcze 39ce32985b spa: support single argument static assertions in older standards
Single argument static_assert() is only available since
C++17 and C23. Some compilers accept it even in earlier language
versions, but some do not.

Single argument static assertions can be supported by using
a GCC extensions, namely that `, ## __VA_ARGS__` removes the
comma if the variadic argument list is empty. This enables a
construction which passes a pre-determined string as the second
argument of the underlying static_assert() when only a single
argument is used in the `SPA_STATIC_ASSERT()` macro.

Fixes #3050
2023-03-04 11:57:51 +00:00