summaryrefslogtreecommitdiffstats
path: root/libAACenc/src/qc_main.cpp
diff options
context:
space:
mode:
authorDave Burke <daveburke@google.com>2012-05-12 13:17:25 -0700
committerDave Burke <daveburke@google.com>2012-05-12 13:47:46 -0700
commit698b536f3b34a7cfc41a80e1034cc359456bdd66 (patch)
treefa3dfa75d535b188725f1b84316cb4b06db79771 /libAACenc/src/qc_main.cpp
parent9bf37cc9712506b2483650c82d3c41152337ef7e (diff)
downloadODR-AudioEnc-698b536f3b34a7cfc41a80e1034cc359456bdd66.tar.gz
ODR-AudioEnc-698b536f3b34a7cfc41a80e1034cc359456bdd66.tar.bz2
ODR-AudioEnc-698b536f3b34a7cfc41a80e1034cc359456bdd66.zip
Update to 2012_05_11 version.
Fixes: - Don't throw error for invalid bitrate but limit to functional value - More robust ASC parsing - More robust handling of corrupt bitstreams - Handle multiple raw access units Change-Id: Ib49fe2545ff4185fe924126da702fe84ac5c2d87
Diffstat (limited to 'libAACenc/src/qc_main.cpp')
-rw-r--r--libAACenc/src/qc_main.cpp35
1 files changed, 21 insertions, 14 deletions
diff --git a/libAACenc/src/qc_main.cpp b/libAACenc/src/qc_main.cpp
index df9c4c4..3414310 100644
--- a/libAACenc/src/qc_main.cpp
+++ b/libAACenc/src/qc_main.cpp
@@ -1314,23 +1314,30 @@ AAC_ENCODER_ERROR FDKaacEnc_FinalizeBitConsumption(CHANNEL_MAPPING *cm,
/* Now we can get the exact transport bit amount, and hopefully it is equal to the estimated value */
exactTpBits = transportEnc_GetStaticBits(hTpEnc, qcOut->totalBits);
- while (exactTpBits != qcKernel->globHdrBits && (max_iter-- > 0))
- {
- INT diffBits = qcKernel->globHdrBits-exactTpBits;
- if (diffBits >= 0) {
- /* move bits from header to payload */
- qcOut->totFillBits += diffBits;
- qcOut->totalBits += diffBits;
- qcOut->grantedDynBits += diffBits;
+ if (exactTpBits != qcKernel->globHdrBits) {
+ INT diffFillBits = 0;
+
+ /* Number of bits which can be moved to bitreservoir. */
+ INT bitsToBitres = qcKernel->globHdrBits - exactTpBits;
+
+ if (bitsToBitres>0) {
+ /* if bitreservoir can not take all bits, move ramaining bits to fillbits */
+ diffFillBits = FDKmax(0, bitsToBitres - (qcKernel->bitResTotMax-qcKernel->bitResTot));
}
- else {
- /* get missing bits from bitreservoir */
- qcKernel->bitResTot += diffBits;
+ else if (bitsToBitres<0) {
+ /* if bits mus be taken from bitreservoir, reduce fillbits first. */
+ diffFillBits = (FDKmax(FDKmax(bitsToBitres, -qcKernel->bitResTot), -qcOut->totFillBits));
}
- qcKernel->globHdrBits = exactTpBits;
- exactTpBits = transportEnc_GetStaticBits(hTpEnc, qcOut->totalBits);
+
+ diffFillBits = (diffFillBits+7)&~7; /* assure previous alignment */
+
+ qcOut->totFillBits += diffFillBits;
+ qcOut->totalBits += diffFillBits;
+ qcOut->grantedDynBits += diffFillBits;
+
+ /* new header bits */
+ qcKernel->globHdrBits = transportEnc_GetStaticBits(hTpEnc, qcOut->totalBits);
}
- FDK_ASSERT(exactTpBits == qcKernel->globHdrBits);
}
/* Save total fill bits and distribut to alignment and fill bits */