Andre Guedes [Fri, 28 Sep 2018 21:27:27 +0000 (14:27 -0700)]
usb_stream: Fix leaks when us_set_hw_constraint() fails
If us_set_hw_constraint() returns error, we leak the 'us' object and all
the resources referenced by it. This patch fixes the issue by calling
us_free() before returning.
Andre Guedes [Fri, 28 Sep 2018 21:27:26 +0000 (14:27 -0700)]
oss: Fix leaks when oss_hw_constraint() fails
If oss_hw_constraint() returns error, we leak 'oss' object and all the
resources referenced by it. This patch fixes the issue by jumping to
'error' label where the proper clean up is already done.
Andre Guedes [Fri, 28 Sep 2018 21:27:25 +0000 (14:27 -0700)]
jack: Fix leaks when jack_set_hw_constraint() fails
If jack_set_hw_constraint() returns error, we leak the 'jack' object and
all the resources referenced by it. This patch fixes the issue by
calling snd_pcm_jack_free() before returning.
Andre Guedes [Fri, 28 Sep 2018 21:27:24 +0000 (14:27 -0700)]
a52: Fix leaks when a52_set_hw_constraint() fails
If a52_set_hw_constraint() returns error, we leak 'rec' and
'rec->slave'. This patch fixes the issue by jumping to 'error' label
where the proper clean up is already done.
jack: Only allow ALSA periods multiple of JACKd period
There is a higher Xrun probability whenever the ALSA period is not a
multiple of the JACKd period and the ALSA buffer is only twice the period.
Allowing ALSA buffers of min. 3x period is not a good solution because this
would increase the latency.
As an example in case of ALSA is using a period of 11 frames and JACK a
period of 12 frames and a buffer of 22 frames (2x ALSA period) is used:
- The buffer is filled and contains 22 frames
- JACK is reading 12 frames. Buffer is only containing 10 frames
- Now, ALSA has to be scheduled exactly after the last JACK read and
before the next read. Otherwise we will get an Xrun
In case of ALSA is using a multiple period of JACK, JACK can always read
2 periods before an Xrun if the buffer was full.
In case of ALSA is using a period of 12 frames and JACK a period of 11
frames and a buffer of 24 frames (2x ALSA period) is used:
- The buffer is filled and contains 24 frames
- JACK is reading 11 frames. Buffer is now containing 13 frames. But ALSA
can still not write to the buffer
- JACK reads 11 additional frames. Buffer contains 2 frames
- Now, ALSA has to be scheduled exactly after the last JACK read and
before the next read. Otherwise we will get an Xrun
In case of ALSA is using a multiple period of JACK, ALSA can always write
to the buffer as long as the buffer is filled with less or equal of half
of buffer.
Therefore this patch enforces an ALSA period which is always a multiple
of the JACKd period.
Timo Wischer [Tue, 3 Jul 2018 13:59:23 +0000 (15:59 +0200)]
jack: Update poll_fd also in draining state
... to support snd_pcm_drain for the JACK IO plugin.
With this changes there will be an poll_fd event in DRAINING state even if
the min_avail was not yet reached. Otherwise the application would never
recognize that all samples were processed by JACK.
In addition the JACK real-time thread is also processing when in DRAINING
state and not only when in RUNNING or PREPARE state.
Signed-off-by: Timo Wischer <twischer@de.adit-jv.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
Timo Wischer [Tue, 3 Jul 2018 13:59:22 +0000 (15:59 +0200)]
jack: Avoid call to snd_pcm_avail_update() from JACK thread
snd_pcm_avail_update() can call snd_pcm_jack_stop() but
snd_pcm_jack_stop() should not be called by the JACK thread.
It should only be called by the thread how has called
snd_pcm_jack_start().
In addition the execution of snd_pcm_avail_update() can take a while.
Therefore it should not be called by the JACK thread to not block this
thread.
Signed-off-by: Timo Wischer <twischer@de.adit-jv.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
Jaroslav Kysela [Mon, 16 Apr 2018 14:24:29 +0000 (16:24 +0200)]
Move rate-lavc to rate-lav subdirectory and update to use libavresample
- --disable-avcodec renamed to --disable-libav
- --avcodec-includedir renamed to --libav-includedir
- --avcodec-libdir renamed to --libav-libdir
- --disable-lavcrate renamed to --disable-lavrate
The .c changes are from Anton Khirnov. The rest is from Jaroslav Kysela.
From: Anton Khirnov Signed-off-by: Jaroslav Kysela <perex@perex.cz>
Timo Wischer [Fri, 16 Mar 2018 14:23:32 +0000 (15:23 +0100)]
jack: Report Xruns to user application
Only increasing the hw_ptr is not sufficient
because it will not be evaluated by the ALSA library
to detect an Xrun.
In addition there is a raise where an Xrun detected by the JACK thread
could not be detected in the ALSA thread.
- In playback use case
- The hw_ptr will be increased by the JACK thread
(hw_ptr > appl_ptr => Xrun)
- But the ALSA thread increases the appl_ptr before evaluating the
hw_ptr
- Therefore the hw_ptr < appl_ptr again
- ALSA will not detect the Xrun which was already detected by the
JACK thread
Therefore an additional variable is required to report an Xrun from the
JACK thread to ALSA.
Signed-off-by: Timo Wischer <twischer@de.adit-jv.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
Timo Wischer [Tue, 13 Mar 2018 08:34:44 +0000 (09:34 +0100)]
jack: Do not Xrun the ALSA buffer
when the JACK thread is requesting too many audio frames
Playback:
Without this commit the ALSA audio buffer will be played with endless
repeats as long as the user application has not provided new audio data.
Therefore this garbage will be played as long as the user application has
not called snd_pcm_stop() after an Xrun. With this fix the rest of the
JACK buffer will be filled with silence.
Capture:
Without this commit the audio data in the ALSA buffer would be
overwritten. With this commit the new data from the JACK buffer will not
be copied. Therefore the existing data in the ALSA buffer will not be
overwritten.
Signed-off-by: Timo Wischer <twischer@de.adit-jv.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
Timo Wischer [Fri, 23 Feb 2018 14:18:08 +0000 (15:18 +0100)]
jack: Use boundary as hw_ptr wrap around
instead of using buffer_size as wrap around.
This is required to detect Xruns.
It is also required to allow the JACK thread
to processes the whole ALSA audio buffer at once
without calling snd_pcm_avail_update() in between.
For example when the hw_ptr will be updated with
hw_ptr += buffer_size
and it is using the buffer_size as wrap around
hw_ptr %= buffer_size
would result in the same value as before the add operation.
Due to that the user application would not recognize
that the complete audio buffer was copied.
Signed-off-by: Timo Wischer <twischer@de.adit-jv.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
Kui Wang [Thu, 13 Jul 2017 19:33:05 +0000 (19:33 +0000)]
pulse: prevent double-free when pulse_hw_constraint returns error
When pulse_hw_constraint returns error, snd_pcm_ioplug_delete() is called.
It will then call pulse_close() where "snd_pcm_pulse_t *pcm" will be free.
Then if goto the "error" label, the "snd_pcm_pulse_t *pcm" will be double-free.
To prevent this, just jump over the code which might cause double-free.
Signed-off-by: Kui Wang <wangkuisuper@hotmail.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
Daniel Kirchner [Wed, 9 Mar 2016 08:17:09 +0000 (09:17 +0100)]
a52: Fix usage of obsoleted avcodec_*_frame() functions
pcm_a52.c uses avcodec_alloc_frame and avcodec_free_frame that have
been replaced by av_frame_alloc and av_frame_free in recent versions
of libavcodec. The following patch should fix this while remaining
backwards compatible.
Tanu Kaskinen [Wed, 27 Jan 2016 11:45:51 +0000 (13:45 +0200)]
pph: include config.h from rate_speexrate.c
Fixes compilation against libspeexdsp 1.2rc3.
rate_speexrate.c includes speex_resampler.h, which depends on config.h
by referencing the HAVE_SPEEX_SPEEXDSP_TYPES_H macro. AFAIK it's not
a good idea to include config.h from headers (I don't know/remember
why, though), which is why I include config.h from rate_speexrate.c
instead of speex_resampler.h.
Tom Yan [Tue, 12 Jan 2016 07:57:39 +0000 (15:57 +0800)]
a52: fix reported input channel order
a52 plugin expects the input to be in ALSA order and remaps it to general order when encoding. However it reports that the input it takes should be in general order.
This fix should make programs (e.g. mpv) that is aware of channel layout reported by ALSA remap sources appropriately before sending when necessary.
It should not cause any regression to programs (e.g. mplayer) that does not check the reported channel layout (hence not affected by the issue) and remaps sources anyway.
Signed-off-by: Tom Yan <tom.ty89@gmail.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
Valentin Corfu [Tue, 11 Aug 2015 06:37:14 +0000 (09:37 +0300)]
jack: Fixing a small memory leak
A small memory leak can be observed when using alsa-plugins (jack).
Check the following valgrind log:
...
==1034== 8 bytes in 1 blocks are definitely lost in loss record 7 of 108
==1034== at 0x4027E5A: calloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==1034== by 0x4035102: snd_pcm_jack_prepare (in /usr/lib/alsa-lib/libasound_module_pcm_jack.so)
==1034== by 0x40D07AB: snd_pcm_ioplug_prepare (pcm_ioplug.c:145)
==1034== by 0x4084961: snd_pcm_prepare (pcm.c:1052)
==1034== by 0x409DDB4: snd_pcm_plugin_prepare (pcm_plugin.c:162)
==1034== by 0x4084961: snd_pcm_prepare (pcm.c:1052)
==1034== by 0x409DDB4: snd_pcm_plugin_prepare (pcm_plugin.c:162)
==1034== by 0x4084961: snd_pcm_prepare (pcm.c:1052)
==1034== by 0x4084A1D: snd_pcm_hw_params (pcm.c:838)
==1034== by 0x4090013: snd_pcm_set_params (pcm.c:8053)
==1034== by 0x80486EB: main (in /root/pcm_min_ok)
...
==1034== LEAK SUMMARY:
==1034== definitely lost: 8 bytes in 1 blocks
==1034== indirectly lost: 0 bytes in 0 blocks
==1034== possibly lost: 31,311 bytes in 1,630 blocks
==1034== still reachable: 5,619 bytes in 24 blocks
==1034== suppressed: 0 bytes in 0 blocks
...
The previous commit fixed the build of the recent speexdsp, but it
also broke the build with the old library. Actually the only needed
change is the inclusion of speex/speex_types.h instead of
speex/speexdsp_types.h, so it can be easily worked around via the
check in configure script.
Along with this change, make the version check back to 1.2 from
1.2rc2, as 1.2rc1 works fine now again, too.
Speexdsp was separated from speex in 1.2rc2. speex_types.h is not
shipped by speexdsp, so alsa-plugins shouldn't use that file. speexdsp
has speexdsp_types.h, which has the same contents as speex_types.h.
speexdsp_types.h is a new file introduced in 1.2rc2, so this change
bumps the minimum supported speexdsp version. The version check in
configure.ac will actually break if speexdsp 1.2 ever gets released,
because pkg-config thinks that "1.2" < "1.2rc2", but I think it's
useful to fail if the installed speexdsp version is 1.2rc1 (which I
believe is very common on current distributions). If a non-rc version
of speexdsp will ever get released, I hope version number 1.2 will be
skipped for this reason. (A non-rc version seems unlikely, since
1.2rc1 was released years ago, so it's pretty likely that the project
is stuck on so called "release candidates" forever...)
Takashi Iwai [Thu, 12 Mar 2015 08:13:44 +0000 (09:13 +0100)]
rate: Allow LGPL for libsamplerate commercial licensee
alsa-plugins-rate is tagged with GPL just for following the license of
libsamplerate. However, libsamplerate provides a commercial license
to allow it used with less restrictions. In that case, we also don't
have to stick with GPL. Instead, the code follows LGPL like other
plugin codes in this package.
a52: Ignore start request if we're already running
When trying to start a PCM that's already running, the result is EBADFD.
We might have implicitly started the buffer by filling it up,
so just ignore this request if we're already running.
Reported-by: Chow Loong Jin <hyperair@ubuntu.com> Signed-off-by: David Henningsson <david.henningsson@canonical.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
jack: Restore PID to jack client name when not specified explicitly
Commit 14190cd8 added a facility to explicitly name Jack clients with
a 'name' option, but did so in a way that was not fully
backwards-compatible with older versions of the alsa-plugins. There
were two issues:
1. Re-using the magical "name" variable, which comes preloaded with
the name of the PCM
2. The code assumed snd_config_get_string sets a variable to NULL if
the config entry does not exist. Instead, this function leaves the
variable unchanged.
The result of these two errors meant that the PCM name would be
treated as if it were a user-defined name, and the old code which
embedded the PID would never be run
This code uses a completely new variable to store the explicitly-set
client name, so that the two code paths no longer collide.
Sergey [Mon, 26 May 2014 03:54:05 +0000 (07:54 +0400)]
jack: fix polling and recovering
This patch fixes polling in alsa-to-jack plugin.
It makes poll()+_poll_revents() return correct values
when there's something to read/write.
It also makes jack pcm survive snd_pcm_recover(-EPIPE).
Valentin Corfu [Tue, 11 Feb 2014 09:06:36 +0000 (04:06 -0500)]
jack: Allow to specify a client name as parameters
The current jack client name contains the process id of the application
providing the audio samples. This leads to unpredictable jack client
names which makes handling of the connections by a controlling
application very hard.
This modification now, allows to specify a client name as parameters
in the configuration file. The implementation is backward
compatible and simply adds a new configuration option to the plugin.
Takashi Iwai [Fri, 30 Nov 2012 16:15:44 +0000 (17:15 +0100)]
a52: Add the support of recent libavcodec / libavutil
The recent avcodec requires the planar support, which is essentially
non-interleaved formats. We need to limit the accepted access types
depending on it.
pcm_pulse: set prebuf parameter according to software parameters
The current default value for prebuf is very high, almost the full
virtual ALSA buffer. This breaks some application especially where
low latency is involved.
This patch makes pcm_pulse implement the sw_params callback and get
the prebuf value from the ALSA software parameters. Thus the
trigger latency is much more like what an ALSA application should
expect from an ALSA PCM device.
Acked-by: David Henningsson <david.henningsson@canonical.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
Andrew Eikum [Mon, 20 Aug 2012 09:28:14 +0000 (11:28 +0200)]
pulse: Support 24-bit formats
These formats were introduced in PulseAudio 0.9.15. There aren't any
new formats supported since then, so this also brings the PulseAudio
plugin in sync with current PulseAudio.
Signed-off-by: Andrew Eikum <aeikum@codeweavers.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
Fons Adriaensen [Mon, 9 Jan 2012 17:18:10 +0000 (18:18 +0100)]
jack: Fix revents for playback
The following patch will make snd_pcm_poll_descriptors_revents()
return the correct value when used on a jack plugin device.
The current version returns POLLIN regardless of capture or
playback.
Takashi Iwai [Tue, 23 Aug 2011 15:02:17 +0000 (17:02 +0200)]
pulse - only underrun if no more data has been written
Original patch from David Henningsson <david.henningsson@canonical.com>
If more data has already been written after the underrun, the underrun
will automatically end and therefore we should not report it or
restart the stream.
[ This patch adds a more check of underrun with a new PA function so
that the underrun handles works more reliably. As the feature is
supported only in a recent version of PA, the underrun handling is
enabled as default now for the new PA, while it's still disabled for
older PA. -- tiwai ]
Signed-off-by: David Henningsson <david.henningsson@canonical.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
applications hang after some seconds when using the jack plugin.
Kevin Ross <kevin@familyross.net> writes:
The cause: The plugin creates a pipe, so that the fd's could be
polled to indicate completion of a transfer. However, the call to
write() blocks when playing audio, as nothing actually reads from the
pipe, and it fills up until it blocks.
Making the socket non-blocking fixes the problem, and testing with
playback and capture both work properly for me now.
[Adrian: I've also tested Kevin's patch and confirm it works.]
Signed-off-by: Adrian Knoth <adi@drcomp.erfurt.thur.de> Signed-off-by: Takashi Iwai <tiwai@suse.de>
a52 - Fix a52 codec with recent libavcodec updates
The recent libavcodec is changed to accept only float input, but
the old ac3 encoder is still somehow working with a different name.
This patch makes it working again.
Added a config option "handle_underrun" to specify whether pulse plugin
handles the underrun reported from PA. The default value is now set to
false, i.e. it will ignore underruns in PA (for good reasons below).
You can take back to the old behavior by setting handle_underrun true.
The original idea was brought by David Henningsson <diwic@ubuntu.com>,
while this patch is simplified and makes the behavior configurable.
The reasons for avoiding underruns (cited from David's original patch):
Reporting underruns to ALSA seems to do more bad than good, for these reasons:
* If pulseaudio gets an underrun, the normal way to end that underrun is to
feed it with more buffers. This is different from the ALSA way of dealing
with underruns, which requires hardware buffer pointers to be reset.
* In addition, underrun signals are delivered asynchronously from pulseaudio.
This means that there might be more buffers on the way to pulseaudio when
the underrun is reported, making the underrun obsolete. Unfortunately,
there is currently no known way to determine whether this is the case or
not.
This patch improves recovering from underruns, and prevents hangs inside
snd_pcm_write* and snd_pcm_read* due to snd_pcm_avail* returning too
low values. It especially helps low latency situations.
Signed-off-by: David Henningsson <diwic@ubuntu.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>