1
mirror of https://git.videolan.org/git/ffmpeg.git synced 2024-07-23 04:31:30 +02:00
Commit Graph

261 Commits

Author SHA1 Message Date
Michael Niedermayer
057549a9cc avcodec/aacenc: Check both channels for finiteness
Fixes null pointer dereference
Fixes: 10412fc52ecc6eab40ed67f82ca7b372/signal_sigsegv_2618c99_2129_f808373959e46afb165593332799ffbc.aif

Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-01-16 18:33:12 +01:00
Ganesh Ajjanagadde
2e4fd16f5b lavc/aacenc: use isfinite to simplify isnan/isinf logic
Reviewed-by: Claudio Freire <klaussfreire@gmail.com>
Signed-off-by: Ganesh Ajjanagadde <gajjanagadde@gmail.com>
2016-01-14 18:28:38 -05:00
Michael Niedermayer
92465a2347 avcodec/aacenc: Check for +-Inf too
Fixes out of array read
Fixes: 04442da73d935b776d2236282588d4f9/signal_sigsegv_2625a69_8790_ae85ffc889070663319b3417ede777b0.mov

Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-01-13 23:49:27 +01:00
Michael Niedermayer
9006567bae avcodec/aacenc: mark output as const as its not written to
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-01-13 17:09:15 +01:00
Michael Niedermayer
0634c54253 avcodec/aacenc: Fix NAN check
All MDCT outputs must be checked in case of 128point MDCTs
Fixes: out of array read
Fixes: 04442da73d935b776d2236282588d4f9/signal_sigsegv_2625a69_351_52ca6226eb83547a2d26e322ce84ed84.mov

Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-01-13 17:09:15 +01:00
Claudio Freire
509f168017 AAC encoder: don't apply MS on special bands
Change the condition for application of the M/S transform to match
that of the decoder. Namely, that no special coding books must be
in use in either channel. While the condition ought to be
equivalent to the current one when the invariant of is_mask is
kept, matching the decoder's condition is safer and easier to
maintain.
2016-01-13 05:28:34 -03:00
Rostislav Pehlivanov
4386f17bbd acenc: remove deprecated avctx->frame_bits use
The type of last_frame_pb_count was chosen to be an int since overflow
is impossible (the spec says the maximum bits per frame is 6144 per
channel and the encoder checks for that).

Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
Reviewed-by: Paul B Mahol <onemda@gmail.com>
2015-12-18 14:28:40 +00:00
Hendrik Leppkes
362028cac9 Merge commit '16216b713f9a21865cc07993961cf5d0ece24916'
* commit '16216b713f9a21865cc07993961cf5d0ece24916':
  lavc: Drop exporting 2-pass encoding stats

Merged-by: Hendrik Leppkes <h.leppkes@gmail.com>
2015-12-18 14:39:15 +01:00
Rostislav Pehlivanov
ade31b9424 aacenc: switch to using the RNG from libavutil
PSNR doesn't change as expected. The AAC spec doesn't really say
anything about how exactly to generate noise.

Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
2015-12-14 18:53:09 +00:00
Andreas Cadhalpun
5b0da6999f aacenc: update max_sfb when num_swb changes
This fixes out-of-bounds reads in avoid_clipping.

Reviewed-by: Rostislav Pehlivanov <atomnuker@gmail.com>
Signed-off-by: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>
2015-12-08 22:53:09 +01:00
Hendrik Leppkes
92186f2d10 Merge commit 'b805482b1fba1d82fbe47023a24c9261f18979b6'
* commit 'b805482b1fba1d82fbe47023a24c9261f18979b6':
  aac: Provide more information on the failure message

Merged-by: Hendrik Leppkes <h.leppkes@gmail.com>
2015-12-08 09:59:45 +01:00
Vittorio Giovara
16216b713f lavc: Drop exporting 2-pass encoding stats
These variables are coming from mpegvideoenc where are supposedly used
as bit counters on various frame properties. However their use is
unclear as they lack documentation, are available only from a very small
subset of encoders, and they are hardly used in the wild. Also frame_bits
in aacenc is employed in a similar way.

Remove this functionality from AVCodecContex, these variable are mostly
frame properties, and too few encoders support setting them with anything
useful.

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
2015-12-07 11:27:42 -05:00
Rostislav Pehlivanov
b32e989e6c aacenc: move the TNS search and filtering before PNS
The original plan was to have TNS use data from the PNS search to better
tune itself to noise but this was never used nor necessary. This should
slightly boost the PNS accuracy if TNS was used.

Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
2015-12-06 20:16:48 +00:00
Rostislav Pehlivanov
3112501daf aacenc: fix aac_pred option triggering an error
Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
2015-12-05 18:43:17 +00:00
Rostislav Pehlivanov
d9791a8656 aacenc: remove the experimental flag
Thiss commit removes the experimental flag from the native AAC Encoder
and thus makes it the default.

After a lot of work, done by myself and Claudio Freire, the quality of
this encoder rivals and surpasses libfdk_aac in some situations. The
encoder had instability issues earlier which prevented it from having
its experimental flag removed, however the last commits done by Claudio
removed the last known source of instability and solved a lot of
problems which were previously observed. The issues were caused by the
various coding tools interfering with the scalefactor indices. Thus,
with these problems solved, it should now be possible to declare this
encoder as the default and recommend that the users should use it
instead of others provided by external libraries, as it is both faster
and has a subjectively higher quality with selected tracks.
The encoder has still yet to be fine tuned for every possible audio file
type like music or voice, so it is hoped that with the experimental flag
removed the users should be able to provide feedback and make the
encoder better than the alternatives for every type of audio and at
every bitrate.

Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
2015-12-05 15:41:25 +00:00
Rostislav Pehlivanov
b270ec9a10 aacenc: mark coders other than twoloop as experimental
ANMR has some interesting things coming up but is currently not in a
shape fit for non-experimental usage. Same with "FAST".

Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
2015-12-05 15:41:25 +00:00
Rostislav Pehlivanov
3a6e020861 aacenc: mark the "faac"-like coder for removal
This coder produces a much lower quality audio than the rest, is much
slower and is unstable. Hasn't been updated for a very long time as
well, hence it is more appropriate to remove it since it also depends on
a big burden of a code (the encode_window_bands_info function which is
just as old, just as unstable and bad and in no way modifiable or
fixable).

Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
2015-12-05 15:41:25 +00:00
Luca Barbato
b805482b1f aac: Provide more information on the failure message
Bug-Id: 761
2015-12-05 13:11:36 +01:00
Vicente Olivert Riera
a27401a05b mips: rename mipsdspr1 to mipsdsp
Signed-off-by: Vicente Olivert Riera <Vincent.Riera@imgtec.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2015-12-04 02:35:42 +01:00
Claudio Freire
ca203e9985 AAC encoder: improve SF range utilization
This patch does 4 things, all of which interact and thus it
woudln't be possible to commit them separately without causing
either quality regressions or assertion failures.

Fate comparison targets don't all reflect improvements in
quality, yet listening tests show substantially improved quality
and stability.

1. Increase SF range utilization.

The spec requires SF delta values to be constrained within the
range -60..60. The previous code was applying that range to
the whole SF array and not only the deltas of consecutive values,
because doing so requires smarter code: zeroing or otherwise
skipping a band may invalidate lots of SF choices.

This patch implements that logic to allow the coders to utilize
the full dynamic range of scalefactors, increasing quality quite
considerably, and fixing delta-SF-related assertion failures,
since now the limitation is enforced rather than asserted.

2. PNS tweaks

The previous modification makes big improvements in twoloop's
efficiency, and every time that happens PNS logic needs to be
tweaked accordingly to avoid it from stepping all over twoloop's
decisions. This patch includes modifications of the sort.

3. Account for lowpass cutoff during PSY analysis

The closer PSY's allocation is to final allocation the better
the quality is, and given these modifications, twoloop is now
very efficient at avoiding holes. Thus, to compute accurate
thresholds, PSY needs to account for the lowpass applied
implicitly during twoloop (by zeroing high bands).

This patch makes twoloop set the cutoff in psymodel's context
the first time it runs, and makes PSY account for it during
threshold computation, making PE and threshold computations
closer to the final allocation and thus achieving better
subjective quality.

4. Tweaks to RC lambda tracking loop in relation to PNS

Without this tweak some corner cases cause quality regressions.
Basically, lambda needs to react faster to overall bitrate
efficiency changes since now PNS can be quite successful in
enforcing maximum bitrates, when PSY allocates too many bits
to the lower bands, suppressing the signals RC logic uses to
lower lambda in those cases and causing aggressive PNS.

This tweak makes PNS much less aggressive, though it can still
use some further tweaks.

Also update MIPS specializations and adjust fuzz

Also in lavc/mips/aacpsy_mips.h: remove trailing whitespace
2015-12-02 07:47:37 -03:00
Rostislav Pehlivanov
6b40755158 aacenc: fix broken build with hardcoded tables
ff_aac_tableinit is a macro in the case of hardcoded tables, so wrap
that up in a function (similar to how the decoder template does it) and
use that as the argument for ff_thread_once().

Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
2015-11-27 21:24:42 +00:00
Rostislav Pehlivanov
ec0719264c aac: temporarily un-share aac_table_init AVOnce variable
AAC-Fixed decoder segfaulted. This commit makes the aac encoder
and decoder init the table twice in case of transcoding again.

Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
2015-11-27 17:51:42 +00:00
Rostislav Pehlivanov
3d62e7a30f aacenc: make threadsafe
Since the ff_aac_tableinit() can be called by both the encoder and
the decoder (in case of transcoding) this commit shares the AVOnce
variable to prevent this.

Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
2015-11-27 14:52:35 +00:00
Claudio Freire
fc36d852ee AAC encoder: Fix application of M/S with PNS
When both M/S coding and PNS are enabled, scalefactors
and coding books would be mistakenly clobbered when setting
the M/S flag on PNS'd bands. The flag needs to be set to
signal the generation of correlated noise, but the scalefactors,
coefficients and the coding books need to be kept intact.
2015-11-26 03:27:06 -03:00
Michael Niedermayer
c38a6077ee avcodec/aacenc: Fix "libavcodec/aacenc.c:540:13: warning: ISO C90 forbids mixed declarations and code"
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2015-10-17 18:58:11 +02:00
Rostislav Pehlivanov
dfba1be963 aacenc_tns: enable Temporal Noise Shaping by default
In light of the recent changes to the TNS system, it has been
deemed worthy and robust enough to be turned on by default.
2015-10-17 11:10:26 +01:00
Rostislav Pehlivanov
e9299df7a6 aacenc: partially revert previous commits to set options via a profile
It didn't work out because of the exceptions that needed to be made
for the "-1" cases and was overall more confusing that just manually
checking and setting options for each profile.
2015-10-17 03:17:27 +01:00
Rostislav Pehlivanov
27d23ae074 aacenc: add support for encoding files using Long Term Prediction
Long Term Prediction allows for prediction of spectral coefficients
via the previously decoded time-dependent samples. This feature
works well with harmonic content 2 or more frames long, like speech,
human or non-human, piano music or any constant tones at very low
bitrates.

It should be noted that the current coder is highly efficient and
the rate control system is unable to encode files at extremely
low bitrates (less than 14kbps seems to be impossible) so this
extension isn't capable of optimum operation. Dramatic difference
is observable with some types of audio and speech but for the most
part the audiable differences are subtle. The spectrum looks better
however so the encoder is able to harvest the additional bits that
this feature provies, should the user choose to enable it. So
it's best to enable this feature only if encoding at the absolutely
lowest bitrate that the encoder is capable of.
2015-10-17 02:31:20 +01:00
Rostislav Pehlivanov
83900c0ed3 aacenc: (re)enable Mid/Side coding by default
Apparently it was set to be enabled by default but after the
profile commits it was reverted to be off by default because
I didn't notice.
Works well so (re)enable it.
2015-10-17 02:31:20 +01:00
Rostislav Pehlivanov
3f3be1c07a aacenc: correctly zero prediction_used array
An oversight, probably because of copy-pasting the TNS line.
2015-10-17 02:31:20 +01:00
Rostislav Pehlivanov
2d9b5ae071 aacenc: slightly simplify and remove a redundant variable
Functionally identical, doesn't change anything.
2015-10-17 02:31:20 +01:00
Rostislav Pehlivanov
8dd2d5e70a aacenc: indicate that TNS is off by default
Doesn't change anything, just a slight clarification that
under all profiles TNS is currently off. That'll be soon to change
hopefully.
2015-10-17 02:31:20 +01:00
Rostislav Pehlivanov
93e6b23c9f aacenc: shorten name of ff_aac_adjust_common_prediction
To keep it similar to the other functions which are all named *_pred.
2015-10-12 23:33:07 +01:00
Rostislav Pehlivanov
0f4334df45 aacenc: add support for changing options based on a profile
This commit adds the ability for a profile to set the default
options, as well as for the user to override such options
by simply stating them in the command line while still keeping
the same profile, as long as those options are still permitted by
the profile.

Example: setting the profile to aac_low (the default) will turn
PNS and IS on. They can be disabled by -aac_pns 0 and -aac_is 0,
respectively. Turning on -aac_pred 1 will cause the profile to be
elevated to aac_main, as long as no options forbidding aac_main
have been entered (like AAC-LTP, which will be pushed soon).

A useful feature is that by setting the profile to mpeg2_aac_low,
all MPEG4 features will be disabled and if the user tries to enable
them then the program will exit with an error. This profile is
signalled with the same bitstream as aac_low (MPEG4) but some devices
and decoders will fail if any MPEG4 features have been enabled.
2015-10-12 16:57:56 +01:00
Rostislav Pehlivanov
b3deaece87 aacenc: add support for encoding 7.1 channel audio
This commit implements support for 7.1 channel audio. There's no
more predefined bitstream channel mappings so going beyond 8 channels
(and 7 channels exactly) will require programmable channel elements,
which is already underway.
2015-10-12 15:53:17 +01:00
Claudio Freire
b629c67ddf AAC encoder: memoize quantize_band_cost
The bulk of calls to quantize_band_cost are replaced
by a call to a version that memoizes, greatly improving
performance, since during coefficient search there is
a great deal of repeat work.

Memoization cannot always be applied, so do this in a
different function, and leave the original as-is.
2015-10-12 03:56:22 -03:00
Claudio Freire
01ecb7172b AAC encoder: Extensive improvements
This finalizes merging of the work in the patches in ticket #2686.

Improvements to twoloop and RC logic are extensive.

The non-exhaustive list of twoloop improvments includes:
 - Tweaks to distortion limits on the RD optimization phase of twoloop
 - Deeper search in twoloop
 - PNS information marking to let twoloop decide when to use it
   (turned out having the decision made separately wasn't working)
 - Tonal band detection and priorization
 - Better band energy conservation rules
 - Strict hole avoidance

For rate control:
 - Use psymodel's bit allocation to allow proper use of the bit
   reservoir. Don't work against the bit reservoir by moving lambda
   in the opposite direction when psymodel decides to allocate more/less
   bits to a frame.
 - Retry the encode if the effective rate lies outside a reasonable
   margin of psymodel's allocation or the selected ABR.
 - Log average lambda at the end. Useful info for everyone, but especially
   for tuning of the various encoder constants that relate to lambda
   feedback.

Psy:
 - Do not apply lowpass with a FIR filter, instead just let the coder
   zero bands above the cutoff. The FIR filter induces group delay,
   and while zeroing bands causes ripple, it's lost in the quantization
   noise.
 - Experimental VBR bit allocation code
 - Tweak automatic lowpass filter threshold to maximize audio bandwidth
   at all bitrates while still providing acceptable, stable quality.

I/S:
 - Phase decision fixes. Unrelated to #2686, but the bugs only surfaced
   when the merge was finalized. Measure I/S band energy accounting for
   phase, and prevent I/S and M/S from being applied both.

PNS:
 - Avoid marking short bands with PNS when they're part of a window
   group in which there's a large variation of energy from one window
   to the next. PNS can't preserve those and the effect is extremely
   noticeable.

M/S:
 - Implement BMLD protection similar to the specified in
   ISO-IEC/13818:7-2003, Appendix C Section 6.1. Since M/S decision
   doesn't conform to section 6.1, a different method had to be
   implemented, but should provide equivalent protection.
 - Move the decision logic closer to the method specified in
   ISO-IEC/13818:7-2003, Appendix C Section 6.1. Specifically,
   make sure M/S needs less bits than dual stereo.
 - Don't apply M/S in bands that are using I/S

Now, this of course needed adjustments in the compare targets and
fuzz factors of the AAC encoder's fate tests, but if wondering why
the targets go up (more distortion), consider the previous coder
was using too many bits on LF content (far more than required by
psy), and thus those signals will now be more distorted, not less.

The extra distortion isn't audible though, I carried extensive
ABX testing to make sure.

A very similar patch was also extensively tested by Kamendo2 in
the context of #2686.
2015-10-11 17:29:50 -03:00
Claudio Freire
7ec74ae4aa AAC encoder: tweak rate-distortion logic
This patch modifies the encode frame function to
retry encoding the frame when the resulting bit count
is too far off target, but only adjusting lambda
in small, incremental step. It also makes the logic
more conservative - otherwise it will contend with
bit reservoir-related variations in bit allocation,
and result in artifacts when frame have to be truncated
(usually at high bit rates transitioning from low
complexity to high complexity).
2015-09-23 02:33:44 -03:00
Clément Bœsch
a6da2fec7c avcodec/aacenc: use AV_OPT_TYPE_BOOL 2015-09-08 22:39:20 +02:00
Rostislav Pehlivanov
92aa3e7fb2 aacenc: copy PRNG from the decoder
Needed for the following PNS commits.

Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
2015-09-06 15:30:25 +01:00
Rostislav Pehlivanov
20dc527139 aacenc: reorder coding tools
This commit reorders the coding tools such that they're doing what
the decoder does in reverse order. The very first thing the decoder
does is to decode M/S stereo if that's signalled, then prediction,
IS, and finally TNS and PNS in another function.
adjust_frame_information()'s application of IS and M/S was taken
out into two separate functions since prediction doesn't expect
to get the raw coefficients but rathe the coefficients at that
part of the encoding process.

The results show a much better PSNR when any combination of
Intensity Stereo, Mid/Side stereo and Prediction is used, which
is a sign of an increased encoder efficiency as well as the fact
that the decoder gets what it expects.

Otherwise, with only IS, PNS or prediction there are neither
regressions nor improvements except in the case of IS, which
now by itself (or with PNS) is less prone to artifacts. Enabling
M/S (using stereo_mode) as well will also reduce stereo artifacts
induced by IS, so in the very near future M/S may be enabled
by default.

Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
2015-09-02 06:26:45 +01:00
Rostislav Pehlivanov
8ffe1cb4d7 aacenc: disable bandtype modifying extensions when coder != twoloop
If the selected coder isn't twoloop, this commit temporarily
disables IS and PNS.
The problem is in the encode_window_bands_info() being confused
and setting invalid band_types for non-marked (normal) bands.

Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
2015-09-01 12:07:00 +01:00
Rostislav Pehlivanov
bc9927b854 aacenc: Enable Intensity Stereo by default
Since the changes made a few week ago (which were done more than a
month ago) the quality and stability of intensity stereo has been
notably good. There were some requests and wishes to have in on by
default and therefore it has been enabled. Should any regressions
arise changes will be made to preferably keep it operating rather
than just disabling it by default again.

Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
2015-09-01 07:15:23 +01:00
Rostislav Pehlivanov
b7eb7cb3a1 aacenc: Enable Perceptual Noise Substitution by default
It has been in the current encoder in its current implementation
for quite some time now, so enable it by default. Will increase
quality at all bitrates, especially at low ones.

Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
2015-09-01 07:13:33 +01:00
Rostislav Pehlivanov
a0079aae00 aacenc: reorder resetting of cpe->common_window
Purely a cosmetic change, most of the zeroing of encoder resources
should happen at the top of the main loop.

Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
2015-09-01 07:00:10 +01:00
Rostislav Pehlivanov
f3f6c6b928 aacenc_tns: rework coefficient quantization and filter application
This commit reworks the TNS implementation to a hybrid between what
the specifications say, what the decoder does and what's the best
thing to do.

The filter application function was copied from the decoder and
modified such that it applies the inverse AR filter to the
coefficients. The LPC coefficients themselves are fed into the
same quantization expression that the specifications say should
be used however further processing is not done, instead they're
converted to the form that the decoder expects them to be in
and are sent off to the compute_lpc_coeffs function exactly the
way the decoder does. This function does all conversions and will
return the exact coefficients that the decoder will generate, which
are then applied to the coefficients.
Having the exact same coefficients on both the encoder and decoder
is a must since otherwise the entire sfb's over which the filter
is applied will be attenuated.

Despite this major rework, TNS might not work fine on some audio
types at very low bitrates (e.g. sub 90kbps) as it can attenuate
some coefficients too much. Users are advised to experiment with
TNS at higher bitrates if they wish to use this tool or simply
wait for the implementation to be improved.

Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
2015-09-01 06:44:07 +01:00
Rostislav Pehlivanov
d09f9c45c7 aacenc: allocate a larger buffer for the TNS LPC context
Turns out autocorrelating more than 750 coefficients at once
will cause a segfault, despite there being enough space to
hold an entire frame of samples into the buffer.

Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
2015-09-01 06:40:12 +01:00
Rostislav Pehlivanov
5ed5ca706f aacenc: populate tns_max_bands
Needed for the following commits.

Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
2015-09-01 06:20:24 +01:00
Rostislav Pehlivanov
49854c56c2 aacenc: initialize LPC context with MAX_LPC_ORDER
The order should never go above TNS_MAX_ORDER (and thus cause
the context to be reinitialized) but this is just in case.

Also fix a comparison, since the coefficients are zero-indexed.

Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
2015-08-29 19:15:52 +01:00
Rostislav Pehlivanov
f04d86c16a aacenc: remove TNS from the todo list
Pulses are already on the way so expect to see the list
gone in the close future.

TNS is already of sufficiently high quality to be enabled
by default (but isn't yet, so you too can help by testing!).

Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
2015-08-29 06:57:08 +01:00