Commit 3c59acf1 authored by Jean-Michel Trivi's avatar Jean-Michel Trivi

AAC encoder bitrate limitation

AAC encoder: Make the bit rate limiting functionality more stable for multichannel
     configurations where element bit rate for SBR can differ significantly.

Bug 9428126

Change-Id: I35b134c5b3c160a8f5a16b4314782b731fe49cd8
parent fc4d7b0e
...@@ -98,7 +98,7 @@ amm-info@iis.fraunhofer.de ...@@ -98,7 +98,7 @@ amm-info@iis.fraunhofer.de
/* Encoder library info */ /* Encoder library info */
#define AACENCODER_LIB_VL0 3 #define AACENCODER_LIB_VL0 3
#define AACENCODER_LIB_VL1 4 #define AACENCODER_LIB_VL1 4
#define AACENCODER_LIB_VL2 4 #define AACENCODER_LIB_VL2 5
#define AACENCODER_LIB_TITLE "AAC Encoder" #define AACENCODER_LIB_TITLE "AAC Encoder"
#define AACENCODER_LIB_BUILD_DATE __DATE__ #define AACENCODER_LIB_BUILD_DATE __DATE__
#define AACENCODER_LIB_BUILD_TIME __TIME__ #define AACENCODER_LIB_BUILD_TIME __TIME__
...@@ -525,14 +525,20 @@ INT aacEncoder_LimitBitrate( ...@@ -525,14 +525,20 @@ INT aacEncoder_LimitBitrate(
/* Limit bit rate in respect to available SBR modes if active */ /* Limit bit rate in respect to available SBR modes if active */
if (sbrActive) if (sbrActive)
{ {
SBR_ELEMENT_INFO sbrElInfo[6]; int numIterations = 0;
INT sbrBitRate = 0; INT initialBitrate, adjustedBitrate;
int e, tooBig=-1; initialBitrate = adjustedBitrate = bitRate;
/* Find total bitrate which provides valid configuration for each SBR element. */
do {
int e;
SBR_ELEMENT_INFO sbrElInfo[(6)];
FDK_ASSERT(cm.nElements <= (6)); FDK_ASSERT(cm.nElements <= (6));
initialBitrate = adjustedBitrate;
/* Get bit rate for each SBR element */ /* Get bit rate for each SBR element */
aacEncDistributeSbrBits(&cm, sbrElInfo, bitRate); aacEncDistributeSbrBits(&cm, sbrElInfo, initialBitrate);
for (e=0; e<cm.nElements; e++) for (e=0; e<cm.nElements; e++)
{ {
...@@ -546,35 +552,31 @@ INT aacEncoder_LimitBitrate( ...@@ -546,35 +552,31 @@ INT aacEncoder_LimitBitrate(
if (sbrBitRateOut == 0) { if (sbrBitRateOut == 0) {
return 0; return 0;
} }
/* If bitrates don't match, distribution and limiting needs to be determined again.
Abort element loop and restart with adapted bitrate. */
if (sbrElementBitRateIn != sbrBitRateOut) {
if (sbrElementBitRateIn < sbrBitRateOut) { if (sbrElementBitRateIn < sbrBitRateOut) {
FDK_ASSERT(tooBig != 1); adjustedBitrate = fMax(initialBitrate, (INT)fDivNorm((FIXP_DBL)(sbrBitRateOut+8), cm.elInfo[e].relativeBits));
tooBig = 0; break;
if (e == 0) {
sbrBitRate = 0;
}
} }
if (sbrElementBitRateIn > sbrBitRateOut) { if (sbrElementBitRateIn > sbrBitRateOut) {
FDK_ASSERT(tooBig != 0); adjustedBitrate = fMin(initialBitrate, (INT)fDivNorm((FIXP_DBL)(sbrBitRateOut-8), cm.elInfo[e].relativeBits));
tooBig = 1; break;
if (e == 0) {
sbrBitRate = 5000000;
}
}
if (tooBig != -1)
{
INT sbrBitRateLimit = (INT)fDivNorm((FIXP_DBL)sbrBitRateOut, cm.elInfo[e].relativeBits);
if (tooBig) {
sbrBitRate = fMin(sbrBitRate, sbrBitRateLimit-16);
FDK_ASSERT( (INT)fMultNorm(cm.elInfo[e].relativeBits, (FIXP_DBL)sbrBitRate) < sbrBitRateOut);
} else {
sbrBitRate = fMax(sbrBitRate, sbrBitRateLimit+16);
FDK_ASSERT( (INT)fMultNorm(cm.elInfo[e].relativeBits, (FIXP_DBL)sbrBitRate) >= sbrBitRateOut);
}
}
}
if (tooBig != -1) {
bitRate = sbrBitRate;
} }
} /* sbrElementBitRateIn != sbrBitRateOut */
} /* elements */
numIterations++; /* restrict iteration to worst case of num elements */
} while ( (initialBitrate!=adjustedBitrate) && (numIterations<=cm.nElements) );
/* Unequal bitrates mean that no reasonable bitrate configuration found. */
bitRate = (initialBitrate==adjustedBitrate) ? adjustedBitrate : 0;
} }
FDK_ASSERT(bitRate > 0); FDK_ASSERT(bitRate > 0);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment