1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-11-21 10:55:51 +02:00
Commit Graph

78 Commits

Author SHA1 Message Date
Marvin Scholz
ac60ad1872 avcodec/aacdec_usac: Fix array size
The array in ff_aac_usac_mdst_filt_cur that is passed to that has a size
of 7 elements, not 6 and the code in the function accesses the array at
index 6, which would be out of bounds if the size was actually 6.

Fixes: CID1603196
2024-07-03 02:48:27 +02:00
Leo Izen
539d2e989d
avcodec/aacdec_lpd: remove unused local variables
int idx, and int first_tcx_flag are set but not used, so this commit
removes their declarations and assignments.
2024-06-28 01:43:52 -04:00
Michael Niedermayer
1080116658
avcodec/aac/aacdec_usac: Test ac in usac
ff_aac_usac_config_decode() needs AACDecContext to be set but some callers
pass NULL.

Happens only when the LATM decoder is used, and USAC is not supported in
LATM

Fixes: member access within null pointer of type 'AACDecContext' (aka 'struct AACDecContext')
Fixes: 69435/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_AAC_LATM_fuzzer-5733527483121664

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Reviewed-by: Lynne <dev@lynne.ee>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2024-06-26 20:55:11 +02:00
Lynne
0b67c83b2e
aacdec_usac, aacsbr: implement SBR support for USAC
Currently, no eSBR features are supported.
Thankfully, no encoders exist for it yet.
2024-06-23 09:10:15 +02:00
Lynne
d45e20c37b
aacdec_usac: remove custom rate_idx and use standard variable for it
m4ac.sampling_index is what aacdec.c uses.
2024-06-21 10:50:22 +02:00
Lynne
a381cbc7c7
aacdec_usac: rename noise_scale to noise_bands
This was a typo.
2024-06-21 10:50:21 +02:00
Lynne
89de2f0de1
aacdec_ac: fix an overread
Fixes reading state->last[i + 1] in ff_aac_ac_get_context for the
last array member.
2024-06-21 10:50:21 +02:00
Lynne
50e5b78b79
aac: expose ff_aac_sample_rate_idx() in aac.h
The rate index is a value important to both encoders and decoders.
USAC needs it as well, so put it into the shared main header.
2024-06-21 10:50:20 +02:00
Lynne
1c3545f053
aacdec_usac: apply specification fix M55715 2024-06-21 10:50:13 +02:00
Lynne
bdd3c6ca50
aacdec_usac: always zero out alpha_q values for stereo streams
The issue is that if a frame has no complex stereo prediction,
the alpha values must all be assumed to be zero if the next frame
has complex prediction and uses delta coding.
2024-06-12 03:33:45 +02:00
Lynne
d79fbad366
aacdec_usac: rename spectrum decode function and remove unused arg
The LC part of the decoder combines scalefactor application with
spectrum decoding, and this was the plan here, but that's not possible,
so change the function name.
2024-06-12 03:33:45 +02:00
Lynne
11a8e0a4e5
aacdec_usac: dequantize scalefactors after noise synthesis
The issue here is that the spec implied that the offset is done
on the dequantized scalefactor, but in fact, it is done on the
scalefactor offset. Delay dequantizing the scalefactors until
after noise synthesis is performed, and change to apply the
offset onto the offset.
2024-06-12 03:33:38 +02:00
Lynne
714596bcbf
aacdec_usac: zero out alpha values for the current frame 2024-06-08 00:22:41 +02:00
Lynne
c2d459cb51
aacdec_usac: fix stereo alpha values for transients
Typo.
Also added comments and fixed the branch underneath.
2024-06-08 00:22:40 +02:00
Lynne
7223523335
aacdec_usac: use correct TNS values
The standard slightly modified the maximum TNS bands allowed.
2024-06-08 00:22:40 +02:00
Lynne
9b41cc0430
aacdec_usac: do not round noise amplitude values
Use floating point division instead of integer division.
2024-06-08 00:22:40 +02:00
Lynne
a18d0659f4
aacdec_usac: skip coeff decoding if the number to be decoded is 0
Yet another thing not mentioned in the spec.
2024-06-08 00:22:39 +02:00
Lynne
1ad9a4008b
aacdec_usac: decouple TNS active from TNS data present flag
The issue was that in case of common TNS parameters, TNS was
entirely skipped, as tns.present was set to 0.
2024-06-08 00:22:39 +02:00
Lynne
c0fdb0cdfd
aacdec_usac: do not continue parsing bitstream on core_mode == 1
Although LPD is not functional yet, the bitstream ends at that point.
2024-06-08 00:22:38 +02:00
Lynne
8ecaa64b9b
aacdec_usac: respect tns_on_lr flag
This was left out, and due to av_unused, forgotten about.
2024-06-08 00:22:38 +02:00
Lynne
25b848a0bd
aacdec_usac: correctly set and use the layout map 2024-06-08 00:22:38 +02:00
Lynne
ae495b56ff
aacdec_usac: remove fallback for custom maps with invalid position
Not needed as every possible index is mapped.
2024-06-08 00:22:37 +02:00
Lynne
91ab17e2fe
aacdec_usac: tag LFE channels as such in the channel map
Missed.
2024-06-08 00:22:37 +02:00
Lynne
62cd6d9e59
aacdec_usac: clean up nb_elems on error
Require that there is a valid layout with a valid number of channels
before accepting nb_elems.
The value is required when flushing.

Thanks to kasper93 for figuring it out.
2024-06-08 00:22:37 +02:00
Lynne
1c066867df
aac: define a new profile for USAC
This allows users to determine whether a stream is USAC or not.
2024-06-08 00:22:35 +02:00
Lynne
8a2fe8a5b9
mpeg4audio: rename AOT_USAC_NOSBR to AOT_USAC
The issue is that AOT 45 isn't defined anywhere, and looking at the git
blame, it seems to have sprung up through a reordering of the enum,
and adding a hole.

The spec does not define an explicit AOT for SBR and no SBR, and only
uses AOT 42 (previously AOT_USAC_NOSBR), so just rename AOT_USAC to
it and replace its use everywhere.
2024-06-08 00:22:31 +02:00
Lynne
7413b81e50
aacdec_usac: fix typo in debug message 2024-06-04 03:08:46 +02:00
Lynne
f4371029f8
aacdec_usac: fix off by one error check on channel numbers 2024-06-04 03:08:45 +02:00
Lynne
0d93e04bc6
aacdec_usac: error out on receiving too many channels for the current layout
Verify that we have a correct number of channels.
2024-06-04 03:08:45 +02:00
Lynne
39826eacff
aacdec_usac: error out on too many elements
USAC supports up to 64 audio channels, but puts no limit on the total
number of extensions that may be present. Which may mean that there's
a single audio channel, with 65 thousand extension elements.

We assume that 64 elements is the maximum for now. So check the value.
2024-06-04 03:08:44 +02:00
Lynne
b70fdbde9c
aacdec_usac: prevent get_bits(0) in get_escaped_value
Some calls to get_escaped_value() specify 0 bits as the third value.
This would result in get_bits(0), which is not a correct usage of the
get_bits API.
2024-06-04 03:08:39 +02:00
James Almer
4d59d58ea6 avcodec/aac/aacdec_usac: remove unnecessary cast
Fixes "libavcodec/aac/aacdec_usac.c(543): error C2440: 'type cast': cannot convert from 'GetBitContext' to 'GetBitContext'"
from msvc.

Signed-off-by: James Almer <jamrial@gmail.com>
2024-06-02 20:14:20 -03:00
Lynne
18757b26bd
aacdec_usac: fix typo in fac_length
The spec says:
fac_length = (window_sequence==EIGHT_SHORT_SEQUENCE) ? ccfl/16 : ccfl/8;

The length used was flipped for short vs long.
2024-06-02 21:12:31 +02:00
James Almer
d8ffd65bfd avcodec/aac/aacdec_usac: remove call to realloc
Must be one of the lavu wrappers instead.

Signed-off-by: James Almer <jamrial@gmail.com>
2024-06-02 15:32:04 -03:00
Lynne
eee5fa0808
aacdec: add a decoder for AAC USAC (xHE-AAC)
This commit adds a decoder for the frequency-domain part of USAC.

What works:
 - Mono
 - Stereo (no prediction)
 - Stereo (mid/side coding)
 - Stereo (complex prediction)

What's left:
 - SBR
 - Speech coding

Known issues:
 - Desync with certain sequences
 - Preroll crossover missing (shouldn't matter, bitrate adaptation only)
2024-06-02 18:34:45 +02:00
Lynne
0513c5cd25
aacdec_dsp: implement 768-point transform and windowing
Required for USAC
2024-06-02 18:34:44 +02:00
Lynne
f8543f3763
aacdec: expose decode_tns
USAC has the same syntax, with one minor change we can check for.
2024-06-02 18:34:43 +02:00
Lynne
0f2303f629
aacdec: expose channel layout related functions 2024-06-02 18:34:43 +02:00
Lynne
39b8d84b53
aacdec: move from scalefactor ranged arrays to flat arrays
AAC uses an unconventional system to send scalefactors
(the volume+quantization value for each band).
Each window is split into either 1 or 8 blocks (long vs short),
and transformed separately from one another, with the coefficients
for each being also completely independent. The scalefactors
slightly increase from 64 (long) to 128 (short) to accomodate
better per-block-per-band volume for each window.

To reduce overhead, the codec signals scalefactor sizes in an obtuse way,
where each group's scalefactor types are sent via a variable length decoding,
with a range.
But our decoder was written in a way where those ranges were carried through
the entire decoder, and to actually read them you had to use the range.

Instead of having a dedicated array with a range for each scalefactor,
just let the decoder directly index each scalefactor.

This also switches the form of quantized scalefactors to the format
the spec uses, where for intensity stereo and regular, scalefactors
are stored in a scalefactor - 100 form, rather than as-is.

USAC gets rid of the complex scalefactor handling. This commit permits
for code sharing between both.
2024-06-02 18:34:43 +02:00
Lynne
baf8651d56
aacdec: restore arm32 dequantization optimizations
Unintentionally removed as part of 03cf101645.
Untested, but its assumed that unlike most of the old ARM code,
this one was still working.
2024-05-13 13:02:02 +02:00
Andreas Rheinhardt
2eab5a1f54 avcodec/aac/aacdec: Fix linking errors with only one decoder enabled
This is achieved by using function pointers for AAC SBR functions.
This unfortunately necessitated to use void* in
ff_aac_sbr_apply(_fixed).
Fixes ticket #10999.

Reviewed-by: Lynne <dev@lynne.ee>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-05-07 12:33:50 +02:00
Andreas Rheinhardt
f5d2dc7b4b avcodec/aac/aacdec_(fixed|float): Set AACDecDSP, AACDecProc directly
This is more in line with how we initialize DSP functions
and avoids tables of function pointers as well as relocations
for these.

Reviewed-by: Lynne <dev@lynne.ee>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-05-07 00:02:57 +02:00
Andreas Rheinhardt
8762aa4d62 avcodec/aac/aacdec: Move init functions to aacdec_fixed/float
This allows to merge it with AACDecDSP.init and remove the latter
(it is called only once anyway); it also allows to make
the fixed/float AACDecDSP and AACDecProc implementations internal
to aacdec_fixed/float.c (which also fixes a violation of our
naming conventions). And it some linker errors when either decoder
is disabled.

Reviewed-by: Lynne <dev@lynne.ee>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-05-07 00:01:39 +02:00
Andreas Rheinhardt
0fc3d8e4d6 avcodec/aac/aacdec: Avoid compiling latm decoder if disabled
Reviewed-by: Lynne <dev@lynne.ee>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-05-07 00:00:04 +02:00
Andreas Rheinhardt
d4fb110f5c avcodec/aac/aacdec: Mark flush as cold
Reviewed-by: Lynne <dev@lynne.ee>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-05-06 23:59:43 +02:00
Andreas Rheinhardt
41922bef7a avcodec/aac/aacdec_(fixed|float): Avoid AAC_RENAME, INTFLOAT
Unnecessary now that this has been detemplatized.

Reviewed-by: Lynne <dev@lynne.ee>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-05-06 23:59:27 +02:00
Andreas Rheinhardt
c13b5d96c8 avcodec/aac/aacdec_float: Call ff_aac_float_common_init() only once
That's enough.

Reviewed-by: Lynne <dev@lynne.ee>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-05-06 23:59:10 +02:00
Andreas Rheinhardt
41ea317ced avcodec/aac/aacdec: Avoid branch to set sample_fmt
Reviewed-by: Lynne <dev@lynne.ee>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-05-06 23:58:58 +02:00
Andreas Rheinhardt
ef16882e8f avcodec/aac/aacdec: Move channel number check out of init_dsp()
Also move initializing random_state.

Reviewed-by: Lynne <dev@lynne.ee>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-05-06 23:58:31 +02:00
Andreas Rheinhardt
e4e9144a5c avcodec/aac/aacdec: Remove unnecessary ff_thread_once()
ff_aacdec_common_init_once() already uses its own AVOnce.

Reviewed-by: Lynne <dev@lynne.ee>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2024-05-06 23:58:08 +02:00