Commit graph

109 commits

Author SHA1 Message Date
Wim Taymans
46ef88e520 spa: save the old change_mask and restore when emitting full
When we add a new listener to an object, it will emit the full state
of the object. For this it temporarily sets the change_mask to all
changes. Restore the previous state after this or else we might not
emit the right change_mask for the next listener.

Consider the case where one there are two listeners on an object.
The object emits a change and the first listener wants to enumerate the
changed params. For this is adds a new listener and then triggers the
enumeration. If we set the change_mask to 0 after adding the listener,
the second listener would get a 0 change_mask and fail to update
its state.
2021-05-27 15:21:44 +02:00
Peter Hutterer
cdfd50e166 spa: add spa_atob() to convert a string to a boolean
This replaces the manual check for "true" and some (inconsistent) return value
of atoi. All those instances now require either "true" or "1" to parse as
true, any other value (including NULL) is boolean false.
2021-05-18 22:18:56 +10:00
Peter Hutterer
7697ed0757 treewide: replace strcmp() == 0 with spa_streq()
This change is only done in source files for now, header files will be done
separately.
2021-05-18 22:10:27 +10:00
Peter Hutterer
2405f0942b spa/buffer: rename SPA_MEMBER to SPA_PTROFF
SPA_MEMBER is misleading, all we're doing here is pointer+offset and a
type-casting the result. Rename to SPA_PTROFF which is more expressive (and
has the same number of characters so we don't need to re-indent).
2021-05-06 09:39:39 +00:00
Wim Taymans
f372de8608 resample: refactor rate match code
Use the same code to start rate matching so that we get the same
results for passthrough.
2021-03-14 20:06:45 +01:00
Wim Taymans
a9bf93030e resample: limit input size to max size of empty space
When flushing use the max size of the empty space, not the
max size of the input buffers, which might be larger.
2021-03-13 13:53:41 +01:00
Wim Taymans
801bd98233 audioconvert: use preallocated empty buffer to drain
Avoid calling memset on a large piece of memory when draining
the resampler because it might use up all the allocated time in
our realtime thread. Instead use a prealloced empty buffer.
2021-03-13 12:54:41 +01:00
Wim Taymans
fc044a37af resample: don't copy too much
When we are in passthrough mode, copy only the min of input and
output size or else we might overread/overwrite.

See #875
2021-03-09 12:47:38 +01:00
Wim Taymans
e095105e57 resample: fix passthrough check
Only in passthrough we need to just copy input to output. Otherwise
we need to ask the resampler for the conversion size.
2021-03-09 08:52:43 +01:00
Wim Taymans
99b2973c31 resample: disable when not used. 2021-03-08 16:55:56 +01:00
Wim Taymans
3af768f124 resample: take into account the number of queued input samples
Take the queued input samples into account when calculating the
required input size. This can be 0 when there is still enough
data queued in the input for another period.

Handle 0 read_size in alsa-source and make it push out a 0 buffer,
this will then drain the resampler and make it ask for a new buffer
size. This makes the transition from one period to another more
seamless for the resampler.

Fixes #805
2021-03-04 10:27:44 +01:00
Wim Taymans
00e52ec167 resample: in drain, feed silence in all channels 2021-03-01 18:09:24 +01:00
Wim Taymans
88727afbd2 resample: take already queued sample into account
When asking for samples, take into account the amount of samples
we already have converted.
2021-01-18 15:09:54 +01:00
Wim Taymans
7f007b6bca resample: tweak the resampler to keep delay number of samples
Instead of requiring the upstream node to resubmit the delayed
samples, keep the samples ourselves. The benefit is probably too
small to measure but it simplifies things a lot.
2021-01-08 16:35:26 +01:00
Wim Taymans
7e9ab8b457 resample: first resample the data, then apply the new rate
Else we might not have enough input samples for the new rate.
2021-01-08 13:17:06 +01:00
Wim Taymans
7d73f0b8d0 audioconvert: use some defines for the max ports 2020-12-09 20:32:44 +01:00
Wim Taymans
79fb95bf90 stream: implement Flush
Flush out pending samples in the resampler
Set the io area status to _OK so that buffers are recycled and
new buffers produced.
2020-11-17 17:15:26 +01:00
Jan Grulich
743cf58fb7 Define SPA_FALLTHROUGH to make fall-through annotations work for all compilers
This is needed for example for Clang compiler which uses different
annotations than GCC. It will make WebRTC to happily use PipeWire
since the spa library is header-only and WebRTC defaults to use
Clang with -Wimplicit-fallthrough.
2020-10-22 13:31:19 +02:00
Wim Taymans
f29bf9cb40 resample: reset resample state when starting
Update the initial delay and size in the rate_match io area when
starting.
2020-09-15 13:22:41 +02:00
Wim Taymans
e59c4675a7 audioconvert: send the command to the children
Send the command on the converter to all children as well.
Reset the resampler when we are paused so that we don't end up
with old data.

Fixes #288
2020-09-14 16:39:42 +02:00
Wim Taymans
c446dfb1d6 resample: improve debug 2020-04-12 20:46:59 +02:00
Wim Taymans
b18dacde9a spa: improve draining
Make a new DRAINED status.
Place the DRAINED status on an input IO when a stream is out of
buffers and draining.
All nodes that don't have HAVE_DATA on the input io need to copy
it to the output io and return the status. This makes sure the
DRAINED is forwarded and nodes return DRAINED from _process()
DRAINED on the resampler flushes out the last queued samples and then
forwards the DRAINED in the next iteration.
Emit a new drained signal from the context when a node returns
DRAINED. Use this to trigger the drained signal in the stream.
2020-04-07 17:58:43 +02:00
Wim Taymans
fdb5911e86 resample: use a 0 sized buffer to drain 2020-04-06 18:01:38 +02:00
Wim Taymans
0d1cef6b3a audioconvert: move some things around
To make it easier to add other implementations later.
Improve selection of resampler function
2020-04-03 18:03:42 +02:00
Wim Taymans
07f935a5ed add some more debug 2020-03-19 13:00:35 +01:00
Wim Taymans
8a2af908a7 small optimizations
Add some SPA_LIKELY
Enable FASTPATH by default
2020-03-18 15:43:29 +01:00
Wim Taymans
c4b2be2aad use true and false for boolean properties
So that it's easier to convert them to booleans in introspection
code later.
2020-03-03 18:17:46 +01:00
Wim Taymans
621f6ca10b resample: reset props first, then override 2020-02-14 20:22:55 +01:00
Wim Taymans
dbd483cb46 resample: add resample.quality property 2020-02-14 20:19:47 +01:00
Wim Taymans
3fab544d3d resample: add quality property 2020-02-14 20:16:50 +01:00
Wim Taymans
454e743d1a resample: make quality configurable 2020-02-12 13:31:03 +01:00
Wim Taymans
f026e95585 audioconvert: use position rate as default rate 2020-01-09 16:50:02 +01:00
Wim Taymans
f391353c7f Make interface types a string
This is more in line with wayland and it allows us to create new
interfaces in modules without having to add anything to the type
enum. It also removes some lookups to map type_id to readable
name in debug.
2019-12-19 13:36:04 +01:00
Wim Taymans
9ffec214b8 fix includes 2019-10-25 15:01:02 +02:00
Wim Taymans
af73585948 Increase max buffer size 2019-10-24 15:26:59 +02:00
Wim Taymans
2fa97daa24 add some constants for max samples 2019-10-24 12:35:00 +02:00
Wim Taymans
3aa19dd38a node: send Suspend to the node
Send suspend to the node when suspending. This is usually the same
as puse for all nodes.
Implement negotiation when we Start audioadapter. This makes it
easier that to track the ports that are negotiated for now.
Use Suspend to clear the audioadapter negotiation.
2019-10-21 17:24:51 +02:00
Wim Taymans
116676e149 node: add active flag for rate match
Add flags to the rate match io area
Add flag to activate/deactivate rate match
Set active flag in rate match when slaved
Update rate before starting resample
2019-10-21 10:13:56 +02:00
Wim Taymans
2e3608a34f Improve some debug 2019-10-18 21:54:44 +02:00
Wim Taymans
c8ffcaaefe plugins: just check the data pointer
We don't need to look at the data type, we just just be happy when
the data pointer is filled in.
2019-10-16 12:23:42 +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
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
b356c83d32 node: add support for transport
Move some things around. Move the duration of the current cycle
to the clock. Also add the estimated next timeout to the clock.
Add a generic media specific counter to the clock.

Clean up the position_bar info. We can do with only a double beat
value and make the signature in floats.

Flesh out the io_position info. This has now the information needed
to convert a raw clock time into a stream time. It basically has
the same kind of features as GStreamer segments such as looping,
variable rate playback etc.. It also contains the state of the
timeline (paused/playing) and it can be used to update the position
and state from clients.

There is also extended information in the position field that
clients can update when they can.

Plugins basically only update the clock info they get (and use
the position info to check if they are slaved or not).

Before each cycle, check if there is a pending position update and
apply it.
2019-08-27 14:41:47 +02:00
Wim Taymans
6f8268df40 audioconvert: remove speex resampler
It's slower and less accurate then the native one.
2019-08-07 13:06:14 +02:00
Wim Taymans
f41720e7db Add PortConfig parameter
Add a new PortConfig parameter to configure ports of elements that
are marked with the SPA_NODE_FLAG_*_PORT_CONFIG. This is used to
configure the operation of the audioconver/audioadapter nodes and
how it should convert the internal format. We want to use the
Profile parameter only for cases where there is an enumeration of
values, like with device configuration.

Add unit tests for audioconvert and adapter to check if they handle
PortConfig correctly.

Make the media session use the PortConfig to dynamically configure
the device nodes.

Remove audio-dsp, it is not used anymore and can/should be implemented
with a simple audioconvert spa node now and some PortConfig.
2019-08-06 12:45:20 +02:00
Wim Taymans
deb6c52f76 node: remove port_alloc_buffers
Remove the now obsolete port_alloc_buffer, rework to use the
port_use_buffers with the ALLOC flag.
2019-07-25 14:08:43 +02:00
Wim Taymans
8590ac158b node: add flags to port_use_buffer
Remove the CAN_USE_BUFFERS flag, it is redundant. We can know this
because of the IO params and buffer params.

Add flags to the port_use_buffer call. We also want this call to
replace port_alloc_buffer. Together with a new result event we can
ask the node to (a)synchronously fill up the buffer data for us. This
is part of a plan to let remote nodes provide buffer data.
2019-07-25 13:19:39 +02:00
Wim Taymans
453e75a23e improve some debug 2019-07-15 17:09:44 +02:00
Wim Taymans
c7d7058896 Improve rate matching and clock slaving
Use a new rate_match io area to exhange rate matching info between
sink/source and resampler.
Compensate for the rate match delay when scheduling timeouts.
Let the resampler notify the source of how many samples it needs to
produce the desired quantum. Make sure we keep an extra buffer in
the device to be able to make this possible.
Let the adapter directly call the slave node process function.
2019-07-09 17:44:07 +02:00
Wim Taymans
6720ded529 names: add standard factory name definitions
Define a set of standard factory names and document what they
contain. This makes it possible to change the implementation by
mapping the factory-name to a different shared library.
2019-06-21 13:31:34 +02:00