Commit Graph

1303 Commits

Author SHA1 Message Date
Fraunhofer IIS FDK e499f9485e Adjust VBR mode depending on given peak bitrate and fix crash recovery usage.
Operating the FDK encoder in A2DP with variable bitrate mode
configuration resulted in unexpected encoder return value AACENC_ENCODE_ERROR.

Due to peak bitrate restriction the encoder quite often runs into requantization.
In case the bitrate constraint is not fulfilled, the so-called crash recovery is
used as final emergency step. The crash recovery reduces the overall bit
consumption considering the given number of bits to be saved. The bit difference
is extracted from audio element structures. In VBR mode the element wise bit
consumption state was not updated since there is typically no bitrate limitation
required.

The patch solves the choppy audio problems and increases audio quality for
AAC VBR encoding.

The changes in FDKaacEnc_QCMain() ensure that audio element bit info is always
updated. This is achieved by always calling FDKaacEnc_BitResRedistribution()
and FDKaacEnc_prepareBitDistribution() with maxBitsPerFrame variable as total
bits parameter.
Furthermore, VBR assumes a certain target bitrate which is used for internal
configuration and limitations. In case the peak bitrate parameter is less than
the VBR mode target bitrate the maximum of both bitrate configurations was used.

The function FDKaacEnc_AdjustVBRBitrateMode() is added to adjust the encoder
internal VBR mode to a desired target bitrate less than given peak bitrate.
It is possible that the peak bitrate is very close to the desired target bitrate.
The virtual available bitreservoir is quite low and the encoder would run quite
often into requantization with needless audio quality reduction. In such a
configuration, it is a better choice to use the CBR targeted threshold adaption
to avoid audio quality reduction.

In FDKaacEnc_Initialize(), there was already a bitResMode selection depending
on available bitreservoir for CBR. This selection will now also be used for VBR.
In case the bitResMode is AACENC_BR_MODE_FULL and VBR mode is selected, the VBR
threshold adaption is used. Otherwise, CBR threshold adaption strategy is used
and therefore, no unnecessary fill bits are written.

Bug: 161400526
Test: see bug
Change-Id: I1865f817180150da6add2623a64f1a102622784a
2021-01-08 10:52:53 +08:00
Jean-Michel Trivi 0c275a3341 Merge "Introduce additional sanity checks to validate program config element." 2020-12-28 19:49:14 +00:00
TreeHugger Robot 31608d9a1f Merge changes Ib8b6973e,I19874768
* changes:
  Check number of core channels and SAC decoder input channels to avoid a channel mismatch.
  Revise bypass mode in SpatialDecApplyParameterSets() to prevent an assert in fDivNorm().
2020-12-28 18:41:27 +00:00
TreeHugger Robot e1f4578a40 Merge changes I6aaeef87,I9681942b,I60ac86f0,I025e943e,I75edf24b
* changes:
  Improve decoder robustness by storing flags and elFlags temporarily.
  ELD downscale factor 3 is only allowed for framesize 480.
  Check transportDec_OutOfBandConfig() input buffer size parameter.
  Evaluate and return StoreConfigAsBitstream() error state.
  Introduce aacDecoder_drcDisable() and always disable legacy DRC for USAC.
2020-12-28 18:34:58 +00:00
TreeHugger Robot d4fb5f5374 Merge "Make sure that alphaValue is correctly initialized in sbrDecoder_drcApplySlot()." 2020-12-28 18:33:39 +00:00
TreeHugger Robot 04d0fa42ff Merge changes I5eb0f88a,I1d853414
* changes:
  Fix unsigned integer overflow in Hcr_State_BODY_SIGN_ESC__ESC_WORD().
  Validate DRC compression factor and DRC boost factor value range in aacDecoder_SetParam().
2020-12-28 18:30:10 +00:00
Fraunhofer IIS FDK 36dd057c40 Introduce additional sanity checks to validate program config element.
Bug: 176246647
Test: atest android.media.cts.DecoderTestAacFormat android.media.cts.DecoderTestXheAac android.media.cts.DecoderTestAacDrc
Change-Id: I3e04480ab5a74da1a9d09af5da95afb2000b3117
2020-12-28 09:21:16 -08:00
Fraunhofer IIS FDK 5eb9ed1b1f Check number of core channels and SAC decoder input channels to avoid a channel mismatch.
Bug: 176246647
Test: atest android.media.cts.DecoderTestAacFormat android.media.cts.DecoderTestXheAac android.media.cts.DecoderTestAacDrc
Change-Id: Ib8b6973e9c29e13b8ef33d7736be2b977928face
2020-12-28 09:21:16 -08:00
Fraunhofer IIS FDK bfd912da32 Improve decoder robustness by storing flags and elFlags temporarily.
Bug: 176246647
Test: atest DecoderTestXheAac DecoderTestAacDrc
Change-Id: I6aaeef87e1f2ce5d5031f088b8c57e6f5806929d
2020-12-28 09:21:16 -08:00
Fraunhofer IIS FDK 9256cfbb73 Make sure that alphaValue is correctly initialized in sbrDecoder_drcApplySlot().
Bug: 176246647
Test: atest DecoderTestXheAac DecoderTestAacDrc
Change-Id: I5bded2e3d29278bb5df561eaa2a46d963ee21df8
2020-12-28 09:21:16 -08:00
Fraunhofer IIS FDK 293ccc7fbc Fix unsigned integer overflow in Hcr_State_BODY_SIGN_ESC__ESC_WORD().
Bug: 176246647
Test: atest DecoderTestXheAac DecoderTestAacDrc
Change-Id: I5eb0f88a55e856c427f9e4647332070f66e673c5
2020-12-28 09:21:16 -08:00
Fraunhofer IIS FDK d6a7375bfa Revise bypass mode in SpatialDecApplyParameterSets() to prevent an assert in fDivNorm().
Bug: 176246647
Test: atest android.media.cts.DecoderTestAacFormat android.media.cts.DecoderTestXheAac android.media.cts.DecoderTestAacDrc
Change-Id: I198747688f1677b82f27a17a2fcf40229c92b1da
2020-12-28 09:21:16 -08:00
Fraunhofer IIS FDK 9f2d1a18d4 ELD downscale factor 3 is only allowed for framesize 480.
Bug: 176246647
Test: atest DecoderTestXheAac DecoderTestAacDrc
Change-Id: I9681942ba39761e4f1d66236ad80c2420ca5abe9
2020-12-28 09:21:16 -08:00
Fraunhofer IIS FDK b1136d1c34 Check transportDec_OutOfBandConfig() input buffer size parameter.
Bug: 176246647
Test: atest DecoderTestXheAac DecoderTestAacDrc
Change-Id: I60ac86f09a5652c820d60dfdc12212637f888164
2020-12-28 09:21:16 -08:00
Fraunhofer IIS FDK fcc3c65ec5 Evaluate and return StoreConfigAsBitstream() error state.
Bug: 176246647
Test: atest DecoderTestXheAac DecoderTestAacDrc
Change-Id: I025e943e91f9be1a5259a761a8ff88defd8babea
2020-12-28 09:21:16 -08:00
Fraunhofer IIS FDK 8f2e68d5c4 Introduce aacDecoder_drcDisable() and always disable legacy DRC for USAC.
Bug: 176246647
Test: atest DecoderTestXheAac DecoderTestAacDrc
Change-Id: I75edf24b18e1f5392b6eb179d5574cb93fcbc7c2
2020-12-28 09:21:16 -08:00
Jean-Michel Trivi 3708417303 Merge "Prevent integer overflow in subbandTPApply() energy update." 2020-12-28 16:30:05 +00:00
Jean-Michel Trivi f67a5bb99c Merge "Limit smoothedNoise values to avoid integer overflows in adjustTimeSlotHQ() and adjustTimeSlotHQ_GainAndNoise()." 2020-12-28 16:29:55 +00:00
Jean-Michel Trivi 1e2fb8395c Merge "Avoid integer overflow in dct_II()." 2020-12-28 16:21:42 +00:00
Anuj Joshi ec3d6d9f0e Added aac_enc_fuzzer
Test: ./aac_enc_fuzzer
Bug: 172429950

Change-Id: Ia84f85425f6df10b13a3d045472f7f684f27eb8a
2020-12-28 10:33:12 +05:30
TreeHugger Robot 4080278410 Merge "Prevent integer overflows in dualChannelFiltering() and eightChannelFiltering()." 2020-12-27 01:47:15 +00:00
Fraunhofer IIS FDK c8a38ef647 Adjust VBR mode depending on given peak bitrate and fix crash recovery usage.
Operating the FDK encoder in A2DP with variable bitrate mode
configuration resulted in unexpected encoder return value AACENC_ENCODE_ERROR.

Due to peak bitrate restriction the encoder quite often runs into requantization.
In case the bitrate constraint is not fulfilled, the so-called crash recovery is
used as final emergency step. The crash recovery reduces the overall bit
consumption considering the given number of bits to be saved. The bit difference
is extracted from audio element structures. In VBR mode the element wise bit
consumption state was not updated since there is typically no bitrate limitation
required.

The patch solves the choppy audio problems and increases audio quality for
AAC VBR encoding.

The changes in FDKaacEnc_QCMain() ensure that audio element bit info is always
updated. This is achieved by always calling FDKaacEnc_BitResRedistribution()
and FDKaacEnc_prepareBitDistribution() with maxBitsPerFrame variable as total
bits parameter.
Furthermore, VBR assumes a certain target bitrate which is used for internal
configuration and limitations. In case the peak bitrate parameter is less than
the VBR mode target bitrate the maximum of both bitrate configurations was used.

The function FDKaacEnc_AdjustVBRBitrateMode() is added to adjust the encoder
internal VBR mode to a desired target bitrate less than given peak bitrate.
It is possible that the peak bitrate is very close to the desired target bitrate.
The virtual available bitreservoir is quite low and the encoder would run quite
often into requantization with needless audio quality reduction. In such a
configuration, it is a better choice to use the CBR targeted threshold adaption
to avoid audio quality reduction.

In FDKaacEnc_Initialize(), there was already a bitResMode selection depending
on available bitreservoir for CBR. This selection will now also be used for VBR.
In case the bitResMode is AACENC_BR_MODE_FULL and VBR mode is selected, the VBR
threshold adaption is used. Otherwise, CBR threshold adaption strategy is used
and therefore, no unnecessary fill bits are written.

Bug: 161400526
Test: see bug
Change-Id: I1865f817180150da6add2623a64f1a102622784a
2020-12-23 18:57:54 -08:00
Fraunhofer IIS FDK 883c114399 Validate DRC compression factor and DRC boost factor value range in aacDecoder_SetParam().
Bug: 176246647
Test: atest DecoderTestXheAac DecoderTestAacDrc
Change-Id: I1d8534145bcf400c5da58d64d3b7e73a87cb43be
2020-12-23 15:08:03 -08:00
Fraunhofer IIS FDK aad908c262 Prevent integer overflow in subbandTPApply() energy update.
Bug: 176246647
Test: atest DecoderTestXheAac DecoderTestAacDrc
Change-Id: I9ed8b33414907706808956cffad252052928c799
2020-12-23 15:04:17 -08:00
Fraunhofer IIS FDK 4305167ceb Limit smoothedNoise values to avoid integer overflows in adjustTimeSlotHQ() and adjustTimeSlotHQ_GainAndNoise().
Bug: 176246647
Test: atest DecoderTestXheAac DecoderTestAacDrc
Change-Id: Ib630d56a626ddd59a9155df38cda2011c3165346
2020-12-23 14:50:36 -08:00
Fraunhofer IIS FDK 2b281bb5a3 Avoid integer overflow in dct_II().
Bug: 176246647
Test: atest DecoderTestXheAac DecoderTestAacDrc
Change-Id: I6c30c4dec3f85410c2748eb42d38f5eb72521ec5
2020-12-23 14:46:18 -08:00
Fraunhofer IIS FDK 9f9bffb763 Prevent integer overflows in dualChannelFiltering() and eightChannelFiltering().
Bug: 176246647
Test: atest DecoderTestXheAac DecoderTestAacDrc
Change-Id: Ic9217bbb3980807036ae6ae121e6ddb7cc1bce35
2020-12-23 14:45:11 -08:00
Cindy Zhou c93fff6784 Enable cfi for aac
Bug: 158010610
Bug: 173497308
Test: ran atest DecoderConformanceTest, ImageReaderDecoderTest,
VideoDecoderPerfTest, VideoEncoderTest.  Compare the
before and after enabling CFI results since there was a number of tests
that were initially failing.

Change-Id: I0d0d2a76512dc909a67f34adacff9ffbf536dbe7
2020-12-17 07:45:11 -08:00
Xin Li f4f79ae49c Mark ab/6881855 as merged am: b831187d3a am: a5f0e4af6d
Original change: https://googleplex-android-review.googlesource.com/c/platform/external/aac/+/13112547

Change-Id: I9243e7da297d69b2bcb1f2d87a4b7a36c961e063
2020-11-24 00:35:17 +00:00
Xin Li a5f0e4af6d Mark ab/6881855 as merged am: b831187d3a
Original change: https://googleplex-android-review.googlesource.com/c/platform/external/aac/+/13112547

Change-Id: Id04d2590c249cad13da8dd8975d0a12ce96a9597
2020-11-24 00:10:16 +00:00
Xin Li b831187d3a Mark ab/6881855 as merged
Bug: 172690556
Change-Id: I4edc064b9a87da525672e61919ec8fb59a70202e
2020-11-23 11:29:57 -08:00
Bill Yi 95d83d6c0d [automerger skipped] Merge "Merge rvc-release RP1A.201105.002 to aosp-master - DO NOT MERGE" am: f4adff7fbb am: 0834f1a0b8 -s ours am: dd90d1595f -s ours am: de35b0d3cc -s ours
am skip reason: subject contains skip directive

Original change: https://android-review.googlesource.com/c/platform/external/aac/+/1486978

Change-Id: I01e518ed4a6d04fd21c673bd6fbf7c6739d21320
2020-11-05 04:57:08 +00:00
Bill Yi 54e05b6496 [automerger skipped] Merge rvc-release RP1A.201105.002 to aosp-master - DO NOT MERGE am: 5b4265a02a am: 8b4e287ff6 -s ours am: 51ff3aa199 -s ours am: 700bc783fb -s ours
am skip reason: subject contains skip directive

Original change: https://android-review.googlesource.com/c/platform/external/aac/+/1486978

Change-Id: I77b49175f9c8523aa87b1aa4b99a106bdaef25b6
2020-11-05 04:57:01 +00:00
Bill Yi de35b0d3cc [automerger skipped] Merge "Merge rvc-release RP1A.201105.002 to aosp-master - DO NOT MERGE" am: f4adff7fbb am: 0834f1a0b8 -s ours am: dd90d1595f -s ours
am skip reason: Change-Id I44e842648acbceb02bbc28cf2ad729a0caddf60d with SHA-1 1f2e0ecb62 is in history

Original change: https://android-review.googlesource.com/c/platform/external/aac/+/1486978

Change-Id: I9d8f11842a7d222ff9eaf50be2e44f1507c4bb49
2020-11-05 04:21:11 +00:00
Bill Yi 700bc783fb [automerger skipped] Merge rvc-release RP1A.201105.002 to aosp-master - DO NOT MERGE am: 5b4265a02a am: 8b4e287ff6 -s ours am: 51ff3aa199 -s ours
am skip reason: Change-Id I44e842648acbceb02bbc28cf2ad729a0caddf60d with SHA-1 1f2e0ecb62 is in history

Original change: https://android-review.googlesource.com/c/platform/external/aac/+/1486978

Change-Id: Ifc66ac802e4e6eec723e5e762cf94f107f5f7ba6
2020-11-05 04:21:02 +00:00
Bill Yi dd90d1595f [automerger skipped] Merge "Merge rvc-release RP1A.201105.002 to aosp-master - DO NOT MERGE" am: f4adff7fbb am: 0834f1a0b8 -s ours
am skip reason: Change-Id I44e842648acbceb02bbc28cf2ad729a0caddf60d with SHA-1 1f2e0ecb62 is in history

Original change: https://android-review.googlesource.com/c/platform/external/aac/+/1486978

Change-Id: Ic6a0942fdd1af69a14653a456accfd76e9361bf1
2020-11-05 04:01:22 +00:00
Bill Yi 51ff3aa199 [automerger skipped] Merge rvc-release RP1A.201105.002 to aosp-master - DO NOT MERGE am: 5b4265a02a am: 8b4e287ff6 -s ours
am skip reason: Change-Id I44e842648acbceb02bbc28cf2ad729a0caddf60d with SHA-1 1f2e0ecb62 is in history

Original change: https://android-review.googlesource.com/c/platform/external/aac/+/1486978

Change-Id: Ia3fae7d8939333684ff3ea15081ac69624d58873
2020-11-05 04:01:14 +00:00
Bill Yi 0834f1a0b8 Merge "Merge rvc-release RP1A.201105.002 to aosp-master - DO NOT MERGE" am: f4adff7fbb
Original change: https://android-review.googlesource.com/c/platform/external/aac/+/1486978

Change-Id: Ied811f647e67defe1286b9a8e4a0bdc2c89da3c2
2020-11-05 03:01:21 +00:00
Bill Yi 8b4e287ff6 Merge rvc-release RP1A.201105.002 to aosp-master - DO NOT MERGE am: 5b4265a02a
Original change: https://android-review.googlesource.com/c/platform/external/aac/+/1486978

Change-Id: Ifc71d75171dfbc250f59774aea3ddb950e70d356
2020-11-05 03:01:13 +00:00
Bill Yi f4adff7fbb Merge "Merge rvc-release RP1A.201105.002 to aosp-master - DO NOT MERGE" 2020-11-05 01:06:54 +00:00
Bill Yi 5b4265a02a Merge rvc-release RP1A.201105.002 to aosp-master - DO NOT MERGE
Merged-In: I44e842648acbceb02bbc28cf2ad729a0caddf60d
Change-Id: Iead5cf2ca1c993da0844a11d1e64bf3cc86ed5dd
2020-11-04 13:57:54 -08:00
Bill Yi ac5e8684ad [automerger skipped] Merge rvc-release RP1A.201105.002 to stage-aosp-master - DO NOT MERGE am: 4c3407e563 -s ours am: 1f2e0ecb62 -s ours am: 092c1fb7fb -s ours
am skip reason: subject contains skip directive

Original change: https://googleplex-android-review.googlesource.com/c/platform/external/aac/+/12984835

Change-Id: I8fc1c1761320ee974541e04597bba6d4f795575b
2020-11-04 19:24:27 +00:00
Bill Yi 092c1fb7fb [automerger skipped] Merge rvc-release RP1A.201105.002 to stage-aosp-master - DO NOT MERGE am: 4c3407e563 -s ours am: 1f2e0ecb62 -s ours
am skip reason: Change-Id I31fe9fe1e8dd7e919848be94dd73dfb779e7065d with SHA-1 aacea3ffc5 is in history

Original change: https://googleplex-android-review.googlesource.com/c/platform/external/aac/+/12984835

Change-Id: Ib5460d11c6484d4794e75fcd4c9ba48a4b57a472
2020-11-04 19:06:22 +00:00
Bill Yi 1f2e0ecb62 [automerger skipped] Merge rvc-release RP1A.201105.002 to stage-aosp-master - DO NOT MERGE am: 4c3407e563 -s ours
am skip reason: Change-Id I31fe9fe1e8dd7e919848be94dd73dfb779e7065d with SHA-1 aacea3ffc5 is in history

Original change: https://googleplex-android-review.googlesource.com/c/platform/external/aac/+/12984835

Change-Id: I44e842648acbceb02bbc28cf2ad729a0caddf60d
2020-11-04 18:34:36 +00:00
Bill Yi 4c3407e563 Merge rvc-release RP1A.201105.002 to stage-aosp-master - DO NOT MERGE
Merged-In: I31fe9fe1e8dd7e919848be94dd73dfb779e7065d
Change-Id: I462d697908f9803317f038c916d5942967efa28a
2020-11-03 22:27:17 -08:00
Xin Li 2dda9ea1e0 [automerger skipped] Skip ab/6749736 in stage. am: f473247482 -s ours am: aacea3ffc5 -s ours am: c0e0f2885b -s ours
am skip reason: Change-Id Icfe1613791fb53502d99e3030dd9e9baa3fa5c33 with SHA-1 73da86e336 is in history

Original change: https://googleplex-android-review.googlesource.com/c/platform/external/aac/+/12795744

Change-Id: I70d88a980024111702d47c78401560d02fc5569c
2020-10-09 03:25:21 +00:00
Xin Li c0e0f2885b [automerger skipped] Skip ab/6749736 in stage. am: f473247482 -s ours am: aacea3ffc5 -s ours
am skip reason: Change-Id Icfe1613791fb53502d99e3030dd9e9baa3fa5c33 with SHA-1 73da86e336 is in history

Original change: https://googleplex-android-review.googlesource.com/c/platform/external/aac/+/12795744

Change-Id: Ideafc491bc2347878d68eb5c50389169382cc35c
2020-10-09 02:35:07 +00:00
Xin Li aacea3ffc5 [automerger skipped] Skip ab/6749736 in stage. am: f473247482 -s ours
am skip reason: Change-Id Icfe1613791fb53502d99e3030dd9e9baa3fa5c33 with SHA-1 73da86e336 is in history

Original change: https://googleplex-android-review.googlesource.com/c/platform/external/aac/+/12795744

Change-Id: I31fe9fe1e8dd7e919848be94dd73dfb779e7065d
2020-10-09 02:10:07 +00:00
Xin Li f473247482 Skip ab/6749736 in stage.
Merged-In: Icfe1613791fb53502d99e3030dd9e9baa3fa5c33
Change-Id: I7d1c753bfa3343d5931058143dc016c3a0861700
2020-10-08 16:52:22 -07:00
Jean-Michel Trivi f451278f0e Fix fuzzer's use of aacDecoder_DecodeFrame
The aacDecoder_DecodeFrame function takes a size in numbers of
samples (INT_PCM), not a number of bytes. Using a number of
bytes caused the FDK to believe the array was larger than it
really was. Therefore on invalid frames, it would try to
clear a size larger than was really available, causing an OOB
crash.

Bug: 161014225
Test: check clusterfuzz results for case 6217304556437504
Change-Id: I9278898a17c1c961c568e841c6037d0c14bcc8b4
2020-10-05 16:27:56 -07:00