Commit Graph

34 Commits

Author SHA1 Message Date
Andreas Rheinhardt
5e68727fa7 avfilter/af_headphone: Only attempt once to init coeffs
The headphone filter does most of its initialization after its init
function, because it can perform certain tasks only after all but its
first input streams have reached eof. When this happens, it allocates
certain buffers and errors out if an allocation fails.

Yet the filter didn't check whether some of these buffers already exist
(which may happen if an earlier attempt has been interrupted in the
middle (due to an allocation error)) in which case the old buffers leak.

This commit makes sure that initializing the buffers is only attempted
once; if not successfull at the first attempt, future calls to the
filter will error out. Trying to support resuming initialization doesn't
seem worthwhile.

Notice that some allocations were freed before a new allocation was
performed; yet this effort was incomplete. Said code has been removed.

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-09-09 13:46:24 +02:00
Andreas Rheinhardt
a84c77396b avfilter/af_headphone: Combine several loops when checking for EOF
Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-09-09 13:46:18 +02:00
Andreas Rheinhardt
58b6594b01 avfilter/af_headphone: Fix stack buffer overflow
The number of channels can be up to 64, not only 16.

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-09-09 13:46:13 +02:00
Andreas Rheinhardt
14226be499 avfilter/af_headphone: Don't overrun array
The headphone filter stores the channel position of the ith HRIR stream
in the ith element of an array of 64 elements; but because there is no
check for duplicate channels, it is easy to write beyond the end of the
array by simply repeating channels.

This commit adds a check for duplicate channels to rule this out.

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-09-09 13:46:07 +02:00
Andreas Rheinhardt
7b74e02ef2 avfilter/af_headphone: Fix segfault when using very short streams
When the headphone filter does its processing in the time domain,
the lengths of the buffers involved are determined by three parameters,
only two of which are relevant here: ir_len and air_len. The former is
the length (in samples) of the longest HRIR input stream and the latter
is the smallest power-of-two bigger than ir_len.

Using optimized functions to calculate the convolution places
restrictions on the alignment of the length of the vectors whose scalar
product is calculated. Therefore said length, namely ir_len, is aligned
on 32; but the number of elements of the buffers used is given by air_len
and for ir_len < 16 a buffer overflow happens.

This commit fixes this by ensuring that air_len is always >= 32 if
processing happens in the time domain.

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-09-09 13:45:59 +02:00
Andreas Rheinhardt
dfd46e2d16 avfilter/af_headphone: Check for the existence of samples
Not providing any samples makes no sense at all. And if no samples
were provided for one of the HRIR streams, one would either run into
an av_assert1 in ff_inlink_consume_samples() or into a segfault in
take_samples() in avfilter.c.

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-09-09 13:45:39 +02:00
Andreas Rheinhardt
709fca0a94 avfilter/af_headphone: Remove always true check
Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-09-09 13:45:20 +02:00
Andreas Rheinhardt
e2d4a5807f avfilter/af_headphone: Don't use uninitialized buffer in log message
This buffer was supposed to be initialized by sscanf(input, "%7[A-Z]%n",
buf, &len), yet if the first input character is not in the A-Z range,
buf is not touched (in particular it needn't be zero-terminated if the
failure happened when parsing the first channel and it still contains
the last channel name if the failure happened when one channel name
could be successfully parsed). This is treated as error in which case
buf is used directly in the log message. This commit fixes this by
actually using the string that could not be matched in the log message
instead.

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-09-09 13:36:54 +02:00
Nicolas George
2f76476549 lavfi: regroup formats lists in a single structure.
It will allow to refernce it as a whole without clunky macros.

Most of the changes have been automatically made with sed:

sed -i '
  s/-> *in_formats/->incfg.formats/g;
  s/-> *out_formats/->outcfg.formats/g;
  s/-> *in_channel_layouts/->incfg.channel_layouts/g;
  s/-> *out_channel_layouts/->outcfg.channel_layouts/g;
  s/-> *in_samplerates/->incfg.samplerates/g;
  s/-> *out_samplerates/->outcfg.samplerates/g;
  ' src/libavfilter/*(.)
2020-09-08 14:02:40 +02:00
Andreas Rheinhardt
ca8e5dedc7 avfilter/af_headphone: Fix leak of channel layouts list on error
In case the multichannel HRIR mode was enabled, an error could happen
between allocating a channel layouts list and attaching it to its target
destination. If an error happened, the list would leak. This is fixed by
attaching the list to its target directly after its allocation.

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-08-26 23:52:57 +02:00
Andreas Rheinhardt
0960da42f5 avfilter/af_headphone: Fix segfault upon allocation failure
The headphone filter uses a variable number of inpads and allocates them
in its init function; if all goes well, the number of inpads coincides
with a number stored in the filter's private context. Yet if allocating a
subsequent inpad fails, the uninit function nevertheless uses the number
stored in the private context to determine the number of inpads to free
and not the AVFilterContext's nb_inputs. This will lead to an access
beyond the end of the allocated AVFilterContext.input_pads array and
an invalid free.

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-08-26 23:52:56 +02:00
Paul B Mahol
dc33250765 avfilter/af_headphone: return on error immediately 2019-09-16 10:27:42 +02:00
Paul B Mahol
aece1eb1e9 avfilter/af_headphone: use av_log2() 2018-12-27 12:30:04 +01:00
Paul B Mahol
9ce96a744d avfilter/af_headphone: fix regression after 7c201e420 2018-12-26 10:41:41 +01:00
Paul B Mahol
6c7eb0708e avfilter/af_headphone: speed up fast convolution
Do IFFT only once per output channel.
2018-12-25 19:17:25 +01:00
Paul B Mahol
3bc711a267 avfilter/af_headphone: do not reduce LFE gain too much 2018-12-24 15:24:20 +01:00
Paul B Mahol
7c201e420a avfilter/af_headphone: fix filtering of non-power of 2 length IRs in time domain 2018-12-22 20:47:02 +01:00
Paul B Mahol
47ba085472 avfilter/af_headphone: use fabsf() instead of fabs() 2018-12-21 12:06:03 +01:00
Paul B Mahol
0f2cfa3d80 avfilter/af_headphone: do not leak input frames on error 2018-11-12 09:38:30 +01:00
Martin Vignali
75625c555c avfilter/af_headphone : fix mem leak
report by coverity
CID 1439934
CID 1439935
2018-11-09 21:55:32 +01:00
Paul B Mahol
6725fd8b0f avfilter/af_headphone: use lavfi internal queue instead
Signed-off-by: Paul B Mahol <onemda@gmail.com>
2018-10-04 12:10:20 +02:00
Paul B Mahol
9cf0079638 avfilter/af_headphone: switch to activate
Signed-off-by: Paul B Mahol <onemda@gmail.com>
2018-04-16 18:29:34 +02:00
Paul B Mahol
e1c8bd2389 avfilter/af_headphone: fix type=time with hrir=multich
Signed-off-by: Paul B Mahol <onemda@gmail.com>
2018-04-16 09:31:11 +02:00
Paul B Mahol
3e003a985f avfilter/af_headphone: add single hrir multichannel stream mode
Signed-off-by: Paul B Mahol <onemda@gmail.com>
2018-04-15 16:08:28 +02:00
Paul B Mahol
a56580b117 avfilter/af_headphone: fix memory leak and overread
Signed-off-by: Paul B Mahol <onemda@gmail.com>
2018-04-14 19:42:16 +02:00
Paul B Mahol
8daca7697b avfilter/af_headphone: do not output invalid samples when flushing
Signed-off-by: Paul B Mahol <onemda@gmail.com>
2018-04-14 18:38:54 +02:00
Paul B Mahol
01170e9db0 avfilter/af_headphone: fix flushing
Signed-off-by: Paul B Mahol <onemda@gmail.com>
2018-04-14 17:51:26 +02:00
Paul B Mahol
2b0f821f51 avfilter/af_headphone: improve performance and reduce latency
Remove not needed code.

Signed-off-by: Paul B Mahol <onemda@gmail.com>
2018-04-14 17:28:26 +02:00
Paul B Mahol
4073046089 avfilter/af_headphone: add missing error check
Signed-off-by: Paul B Mahol <onemda@gmail.com>
2017-11-20 13:54:04 +01:00
Paul B Mahol
5d07275529 avfilter/af_headphone: increase max ir length
Signed-off-by: Paul B Mahol <onemda@gmail.com>
2017-09-25 12:12:13 +02:00
Paul B Mahol
13f9639e3e avfilter/af_headphone: check ff_insert_inpad() for failure
Signed-off-by: Paul B Mahol <onemda@gmail.com>
2017-08-25 09:45:20 +02:00
Paul B Mahol
f483949188 avfilter/af_headphone: do not free frame that's gonna be reused later
Signed-off-by: Paul B Mahol <onemda@gmail.com>
2017-06-24 19:15:57 +02:00
Paul B Mahol
9b667f609c avfilter/af_headphone: fix possible memory leaks on failure
Signed-off-by: Paul B Mahol <onemda@gmail.com>
2017-06-15 11:19:12 +02:00
Paul B Mahol
d4d1fc823f avfilter: add native headphone spatialization filter
Signed-off-by: Paul B Mahol <onemda@gmail.com>
2017-06-12 18:08:52 +02:00