Merge pi-dr1-dev to aosp-master

Change-Id: I5d9258cdbcf160849cc159d017fd97ec5e6211ce
diff --git a/media/extractors/midi/MidiExtractor.cpp b/media/extractors/midi/MidiExtractor.cpp
index 949fbe0..a30b6f8 100644
--- a/media/extractors/midi/MidiExtractor.cpp
+++ b/media/extractors/midi/MidiExtractor.cpp
@@ -247,8 +247,9 @@
         EAS_I32 numRendered;
         EAS_RESULT result = EAS_Render(mEasData, p, mEasConfig->mixBufferSize, &numRendered);
         if (result != EAS_SUCCESS) {
-            ALOGE("EAS_Render returned %ld", result);
-            break;
+            ALOGE("EAS_Render() returned %ld, numBytesOutput = %d", result, numBytesOutput);
+            buffer->release();
+            return NULL; // Stop processing to prevent infinite loops.
         }
         p += numRendered * mEasConfig->numChannels;
         numBytesOutput += numRendered * mEasConfig->numChannels * sizeof(EAS_PCM);
diff --git a/media/libmedia/include/media/MediaProfiles.h b/media/libmedia/include/media/MediaProfiles.h
index 6975581..0feb4f3 100644
--- a/media/libmedia/include/media/MediaProfiles.h
+++ b/media/libmedia/include/media/MediaProfiles.h
@@ -83,6 +83,7 @@
      * successful only when validation is successful.
      */
     static constexpr char const * const xmlFiles[] = {
+            "odm/etc/media_profiles_V1_0.xml",
             "vendor/etc/media_profiles_V1_0.xml",
             "system/etc/media_profiles.xml"
             };
diff --git a/media/libstagefright/FrameDecoder.cpp b/media/libstagefright/FrameDecoder.cpp
index 29a219f..6e94517 100644
--- a/media/libstagefright/FrameDecoder.cpp
+++ b/media/libstagefright/FrameDecoder.cpp
@@ -301,10 +301,13 @@
             err = mSource->read(&mediaBuffer, &mReadOptions);
             mReadOptions.clearSeekTo();
             if (err != OK) {
-                ALOGW("Input Error or EOS");
                 mHaveMoreInputs = false;
                 if (!mFirstSample && err == ERROR_END_OF_STREAM) {
+                    (void)mDecoder->queueInputBuffer(
+                            index, 0, 0, 0, MediaCodec::BUFFER_FLAG_EOS);
                     err = OK;
+                } else {
+                    ALOGW("Input Error: err=%d", err);
                 }
                 break;
             }
diff --git a/media/libstagefright/MediaCodec.cpp b/media/libstagefright/MediaCodec.cpp
index da16fde..56fb9e5 100644
--- a/media/libstagefright/MediaCodec.cpp
+++ b/media/libstagefright/MediaCodec.cpp
@@ -860,7 +860,15 @@
 }
 
 //static
-sp<CodecBase> MediaCodec::GetCodecBase(const AString &name) {
+sp<CodecBase> MediaCodec::GetCodecBase(const AString &name, const char *owner) {
+    if (owner) {
+        if (strncmp(owner, "default", 8) == 0) {
+            return new ACodec;
+        } else if (strncmp(owner, "codec2", 7) == 0) {
+            return CreateCCodec();
+        }
+    }
+
     if (name.startsWithIgnoreCase("c2.")) {
         return CreateCCodec();
     } else if (name.startsWithIgnoreCase("omx.")) {
@@ -884,11 +892,6 @@
     // we need to invest in an extra looper to free the main event
     // queue.
 
-    mCodec = GetCodecBase(name);
-    if (mCodec == NULL) {
-        return NAME_NOT_FOUND;
-    }
-
     mCodecInfo.clear();
 
     bool secureCodec = false;
@@ -922,6 +925,11 @@
         return NAME_NOT_FOUND;
     }
 
+    mCodec = GetCodecBase(name, mCodecInfo->getOwnerName());
+    if (mCodec == NULL) {
+        return NAME_NOT_FOUND;
+    }
+
     if (mIsVideo) {
         // video codec needs dedicated looper
         if (mCodecLooper == NULL) {
diff --git a/media/libstagefright/codecs/xaacdec/SoftXAAC.cpp b/media/libstagefright/codecs/xaacdec/SoftXAAC.cpp
index e0d9662..f173e0f 100644
--- a/media/libstagefright/codecs/xaacdec/SoftXAAC.cpp
+++ b/media/libstagefright/codecs/xaacdec/SoftXAAC.cpp
@@ -23,43 +23,53 @@
 #include <OMX_AudioExt.h>
 #include <OMX_IndexExt.h>
 #include <cutils/properties.h>
+#include <math.h>
+#include <media/stagefright/MediaErrors.h>
 #include <media/stagefright/foundation/ADebug.h>
 #include <media/stagefright/foundation/hexdump.h>
-#include <media/stagefright/MediaErrors.h>
 #include <utils/misc.h>
-#include <math.h>
 
-#define DRC_DEFAULT_MOBILE_REF_LEVEL 64  /* 64*-0.25dB = -16 dB below full scale for mobile conf */
-#define DRC_DEFAULT_MOBILE_DRC_CUT   127 /* maximum compression of dynamic range for mobile conf */
-#define DRC_DEFAULT_MOBILE_DRC_BOOST 127 /* maximum compression of dynamic range for mobile conf */
-#define DRC_DEFAULT_MOBILE_DRC_HEAVY 1   /* switch for heavy compression for mobile conf */
-#define DRC_DEFAULT_MOBILE_ENC_LEVEL (-1) /* encoder target level; -1 => the value is unknown, otherwise dB step value (e.g. 64 for -16 dB) */
-#define DRC_KEY_AAC_DRC_EFFECT_TYPE   (3)  /* Default Effect type is "Limited playback" */
+/* 64*-0.25dB = -16 dB below full scale for mobile conf */
+#define DRC_DEFAULT_MOBILE_REF_LEVEL 64
+/* maximum compression of dynamic range for mobile conf */
+#define DRC_DEFAULT_MOBILE_DRC_CUT 127
+/* maximum compression of dynamic range for mobile conf */
+#define DRC_DEFAULT_MOBILE_DRC_BOOST 127
+/* switch for heavy compression for mobile conf */
+#define DRC_DEFAULT_MOBILE_DRC_HEAVY 1
+/* encoder target level; -1 => the value is unknown,
+ * otherwise dB step value (e.g. 64 for -16 dB) */
+#define DRC_DEFAULT_MOBILE_ENC_LEVEL (-1)
+
+/* Default Effect type is "Limited playback" */
+#define DRC_KEY_AAC_DRC_EFFECT_TYPE (3)
+
 /* REF_LEVEL of 64 pairs well with EFFECT_TYPE of 3. */
-#define DRC_DEFAULT_MOBILE_LOUDNESS_LEVEL (64)  /* Default loudness value for MPEG-D DRC */
+/* Default loudness value for MPEG-D DRC */
+#define DRC_DEFAULT_MOBILE_LOUDNESS_LEVEL (64)
 
-#define PROP_DRC_OVERRIDE_REF_LEVEL  "aac_drc_reference_level"
-#define PROP_DRC_OVERRIDE_CUT        "aac_drc_cut"
-#define PROP_DRC_OVERRIDE_BOOST      "aac_drc_boost"
-#define PROP_DRC_OVERRIDE_HEAVY      "aac_drc_heavy"
+#define PROP_DRC_OVERRIDE_REF_LEVEL "aac_drc_reference_level"
+#define PROP_DRC_OVERRIDE_CUT "aac_drc_cut"
+#define PROP_DRC_OVERRIDE_BOOST "aac_drc_boost"
+#define PROP_DRC_OVERRIDE_HEAVY "aac_drc_heavy"
 #define PROP_DRC_OVERRIDE_ENC_LEVEL "aac_drc_enc_target_level"
 #define PROP_DRC_OVERRIDE_EFFECT_TYPE "ro.aac_drc_effect_type"
 
-#define MAX_CHANNEL_COUNT            8  /* maximum number of audio channels that can be decoded */
+/* maximum number of audio channels that can be decoded */
+#define MAX_CHANNEL_COUNT 8
 
-
-#define RETURN_IF_FATAL(retval, str) \
-        if (retval & IA_FATAL_ERROR) { \
-            ALOGE("Error in %s: Returned: %d", str, retval); \
-            return retval; \
-        } else if (retval != IA_NO_ERROR) { \
-            ALOGW("Warning in %s: Returned: %d", str, retval); \
-        }
+#define RETURN_IF_FATAL(retval, str)                       \
+    if (retval & IA_FATAL_ERROR) {                         \
+        ALOGE("Error in %s: Returned: %d", str, retval);   \
+        return retval;                                     \
+    } else if (retval != IA_NO_ERROR) {                    \
+        ALOGW("Warning in %s: Returned: %d", str, retval); \
+    }
 
 namespace android {
 
-template<class T>
-static void InitOMXParams(T *params) {
+template <class T>
+static void InitOMXParams(T* params) {
     params->nSize = sizeof(T);
     params->nVersion.s.nVersionMajor = 1;
     params->nVersion.s.nVersionMinor = 0;
@@ -68,41 +78,35 @@
 }
 
 static const OMX_U32 kSupportedProfiles[] = {
-    OMX_AUDIO_AACObjectLC,
-    OMX_AUDIO_AACObjectHE,
-    OMX_AUDIO_AACObjectHE_PS,
-    OMX_AUDIO_AACObjectLD,
-    OMX_AUDIO_AACObjectELD,
+    OMX_AUDIO_AACObjectLC, OMX_AUDIO_AACObjectHE,  OMX_AUDIO_AACObjectHE_PS,
+    OMX_AUDIO_AACObjectLD, OMX_AUDIO_AACObjectELD,
 };
 
-SoftXAAC::SoftXAAC(
-        const char *name,
-        const OMX_CALLBACKTYPE *callbacks,
-        OMX_PTR appData,
-        OMX_COMPONENTTYPE **component)
+SoftXAAC::SoftXAAC(const char* name, const OMX_CALLBACKTYPE* callbacks, OMX_PTR appData,
+                   OMX_COMPONENTTYPE** component)
     : SimpleSoftOMXComponent(name, callbacks, appData, component),
-    mIsADTS(false),
-    mInputBufferCount(0),
-    mOutputBufferCount(0),
-    mSignalledError(false),
-    mLastInHeader(NULL),
-    mPrevTimestamp(0),
-    mCurrentTimestamp(0),
-    mOutputPortSettingsChange(NONE),
-    mXheaacCodecHandle(NULL),
-    mMpegDDrcHandle(NULL),
-    mInputBufferSize(0),
-    mOutputFrameLength(1024),
-    mInputBuffer(NULL),
-    mOutputBuffer(NULL),
-    mSampFreq(0),
-    mNumChannels(0),
-    mPcmWdSz(0),
-    mChannelMask(0),
-    mIsCodecInitialized(false),
-    mIsCodecConfigFlushRequired(false),
-    mMpegDDRCPresent(0),
-    mDRCFlag(0)
+      mIsADTS(false),
+      mInputBufferCount(0),
+      mOutputBufferCount(0),
+      mSignalledError(false),
+      mLastInHeader(NULL),
+      mPrevTimestamp(0),
+      mCurrentTimestamp(0),
+      mOutputPortSettingsChange(NONE),
+      mXheaacCodecHandle(NULL),
+      mMpegDDrcHandle(NULL),
+      mInputBufferSize(0),
+      mOutputFrameLength(1024),
+      mInputBuffer(NULL),
+      mOutputBuffer(NULL),
+      mSampFreq(0),
+      mNumChannels(0),
+      mPcmWdSz(0),
+      mChannelMask(0),
+      mIsCodecInitialized(false),
+      mIsCodecConfigFlushRequired(false),
+      mMpegDDRCPresent(0),
+      mDRCFlag(0)
 
 {
     initPorts();
@@ -112,7 +116,7 @@
 SoftXAAC::~SoftXAAC() {
     int errCode = deInitXAACDecoder();
     if (0 != errCode) {
-        ALOGE("deInitXAACDecoder() failed %d",errCode);
+        ALOGE("deInitXAACDecoder() failed %d", errCode);
     }
 
     mIsCodecInitialized = false;
@@ -134,7 +138,7 @@
     def.bBuffersContiguous = OMX_FALSE;
     def.nBufferAlignment = 1;
 
-    def.format.audio.cMIMEType = const_cast<char *>("audio/aac");
+    def.format.audio.cMIMEType = const_cast<char*>("audio/aac");
     def.format.audio.pNativeRender = NULL;
     def.format.audio.bFlagErrorConcealment = OMX_FALSE;
     def.format.audio.eEncoding = OMX_AUDIO_CodingAAC;
@@ -152,7 +156,7 @@
     def.bBuffersContiguous = OMX_FALSE;
     def.nBufferAlignment = 2;
 
-    def.format.audio.cMIMEType = const_cast<char *>("audio/raw");
+    def.format.audio.cMIMEType = const_cast<char*>("audio/raw");
     def.format.audio.pNativeRender = NULL;
     def.format.audio.bFlagErrorConcealment = OMX_FALSE;
     def.format.audio.eEncoding = OMX_AUDIO_CodingPCM;
@@ -168,24 +172,23 @@
     int loop = 0;
 
     err_code = initXAACDecoder();
-    if(err_code != IA_NO_ERROR) {
+    if (err_code != IA_NO_ERROR) {
         if (NULL == mXheaacCodecHandle) {
             ALOGE("AAC decoder handle is null");
         }
         if (NULL == mMpegDDrcHandle) {
             ALOGE("MPEG-D DRC decoder handle is null");
         }
-        for(loop= 1; loop < mMallocCount; loop++) {
+        for (loop = 1; loop < mMallocCount; loop++) {
             if (mMemoryArray[loop] == NULL) {
-                ALOGE(" memory allocation error %d\n",loop);
+                ALOGE(" memory allocation error %d\n", loop);
                 break;
             }
         }
         ALOGE("initXAACDecoder Failed");
 
-        for(loop = 0; loop < mMallocCount; loop++) {
-           if(mMemoryArray[loop])
-           free(mMemoryArray[loop]);
+        for (loop = 0; loop < mMallocCount; loop++) {
+            if (mMemoryArray[loop]) free(mMemoryArray[loop]);
         }
         mMallocCount = 0;
         return status;
@@ -197,105 +200,76 @@
     mEndOfOutput = false;
 
     char value[PROPERTY_VALUE_MAX];
-    if (property_get(PROP_DRC_OVERRIDE_REF_LEVEL, value, NULL))
-    {
+    if (property_get(PROP_DRC_OVERRIDE_REF_LEVEL, value, NULL)) {
         ui_drc_val = atoi(value);
-        ALOGV("AAC decoder using desired DRC target reference level of %d instead of %d",ui_drc_val,
-                DRC_DEFAULT_MOBILE_REF_LEVEL);
-    }
-    else
-    {
-        ui_drc_val= DRC_DEFAULT_MOBILE_REF_LEVEL;
+        ALOGV("AAC decoder using desired DRC target reference level of %d instead of %d",
+              ui_drc_val, DRC_DEFAULT_MOBILE_REF_LEVEL);
+    } else {
+        ui_drc_val = DRC_DEFAULT_MOBILE_REF_LEVEL;
     }
 
-    err_code = ixheaacd_dec_api(mXheaacCodecHandle,
-                                IA_API_CMD_SET_CONFIG_PARAM,
-                                IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_TARGET_LEVEL,
-                                &ui_drc_val);
+    err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_SET_CONFIG_PARAM,
+                                IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_TARGET_LEVEL, &ui_drc_val);
 
     RETURN_IF_FATAL(err_code, "IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_TARGET_LEVEL");
-#ifdef     ENABLE_MPEG_D_DRC
-
+#ifdef ENABLE_MPEG_D_DRC
     /* Use ui_drc_val from PROP_DRC_OVERRIDE_REF_LEVEL or DRC_DEFAULT_MOBILE_REF_LEVEL
      * for IA_ENHAACPLUS_DEC_DRC_TARGET_LOUDNESS too */
-    err_code = ixheaacd_dec_api(mXheaacCodecHandle,
-                                IA_API_CMD_SET_CONFIG_PARAM,
-                                IA_ENHAACPLUS_DEC_DRC_TARGET_LOUDNESS,
-                                &ui_drc_val);
 
+    err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_SET_CONFIG_PARAM,
+                                IA_ENHAACPLUS_DEC_DRC_TARGET_LOUDNESS, &ui_drc_val);
 
     RETURN_IF_FATAL(err_code, "IA_ENHAACPLUS_DEC_DRC_TARGET_LOUDNESS");
 #endif
 
-
-    if (property_get(PROP_DRC_OVERRIDE_CUT, value, NULL))
-    {
+    if (property_get(PROP_DRC_OVERRIDE_CUT, value, NULL)) {
         ui_drc_val = atoi(value);
         ALOGV("AAC decoder using desired DRC attenuation factor of %d instead of %d", ui_drc_val,
-                DRC_DEFAULT_MOBILE_DRC_CUT);
-    }
-    else
-    {
-        ui_drc_val=DRC_DEFAULT_MOBILE_DRC_CUT;
+              DRC_DEFAULT_MOBILE_DRC_CUT);
+    } else {
+        ui_drc_val = DRC_DEFAULT_MOBILE_DRC_CUT;
     }
 
-    err_code = ixheaacd_dec_api(mXheaacCodecHandle,
-                                IA_API_CMD_SET_CONFIG_PARAM,
-                                IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_CUT,
-                                &ui_drc_val);
+    err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_SET_CONFIG_PARAM,
+                                IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_CUT, &ui_drc_val);
 
     RETURN_IF_FATAL(err_code, "IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_CUT");
 
-    if (property_get(PROP_DRC_OVERRIDE_BOOST, value, NULL))
-    {
+    if (property_get(PROP_DRC_OVERRIDE_BOOST, value, NULL)) {
         ui_drc_val = atoi(value);
         ALOGV("AAC decoder using desired DRC boost factor of %d instead of %d", ui_drc_val,
-                DRC_DEFAULT_MOBILE_DRC_BOOST);
-    }
-    else
-    {
+              DRC_DEFAULT_MOBILE_DRC_BOOST);
+    } else {
         ui_drc_val = DRC_DEFAULT_MOBILE_DRC_BOOST;
     }
 
-    err_code = ixheaacd_dec_api(mXheaacCodecHandle,
-                                IA_API_CMD_SET_CONFIG_PARAM,
-                                IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_BOOST,
-                                &ui_drc_val);
+    err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_SET_CONFIG_PARAM,
+                                IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_BOOST, &ui_drc_val);
     RETURN_IF_FATAL(err_code, "IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_BOOST");
 
-    if (property_get(PROP_DRC_OVERRIDE_HEAVY, value, NULL))
-    {
+    if (property_get(PROP_DRC_OVERRIDE_HEAVY, value, NULL)) {
         ui_drc_val = atoi(value);
         ALOGV("AAC decoder using desired Heavy compression factor of %d instead of %d", ui_drc_val,
-                DRC_DEFAULT_MOBILE_DRC_HEAVY);
-    }
-    else
-    {
+              DRC_DEFAULT_MOBILE_DRC_HEAVY);
+    } else {
         ui_drc_val = DRC_DEFAULT_MOBILE_DRC_HEAVY;
     }
 
-    err_code = ixheaacd_dec_api(mXheaacCodecHandle,
-                                IA_API_CMD_SET_CONFIG_PARAM,
-                                IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_HEAVY_COMP,
-                                &ui_drc_val);
-   RETURN_IF_FATAL(err_code, "IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_HEAVY_COMP");
+    err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_SET_CONFIG_PARAM,
+                                IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_HEAVY_COMP, &ui_drc_val);
+    RETURN_IF_FATAL(err_code, "IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_HEAVY_COMP");
 
 #ifdef ENABLE_MPEG_D_DRC
-    if (property_get(PROP_DRC_OVERRIDE_EFFECT_TYPE, value, NULL))
-    {
+    if (property_get(PROP_DRC_OVERRIDE_EFFECT_TYPE, value, NULL)) {
         ui_drc_val = atoi(value);
         ALOGV("AAC decoder using desired DRC effect type of %d instead of %d", ui_drc_val,
-                DRC_KEY_AAC_DRC_EFFECT_TYPE);
-    }
-    else
-    {
+              DRC_KEY_AAC_DRC_EFFECT_TYPE);
+    } else {
         ui_drc_val = DRC_KEY_AAC_DRC_EFFECT_TYPE;
     }
 
-    err_code = ixheaacd_dec_api(mXheaacCodecHandle,
-                              IA_API_CMD_SET_CONFIG_PARAM,
-                              IA_ENHAACPLUS_DEC_DRC_EFFECT_TYPE,
-                              &ui_drc_val);
+    err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_SET_CONFIG_PARAM,
+                                IA_ENHAACPLUS_DEC_DRC_EFFECT_TYPE, &ui_drc_val);
 
     RETURN_IF_FATAL(err_code, "IA_ENHAACPLUS_DEC_DRC_EFFECT_TYPE");
 
@@ -303,15 +277,10 @@
     return status;
 }
 
-OMX_ERRORTYPE SoftXAAC::internalGetParameter(
-        OMX_INDEXTYPE index, OMX_PTR params) {
-
-    switch ((OMX_U32) index) {
-
-        case OMX_IndexParamAudioPortFormat:
-        {
-            OMX_AUDIO_PARAM_PORTFORMATTYPE *formatParams =
-                (OMX_AUDIO_PARAM_PORTFORMATTYPE *)params;
+OMX_ERRORTYPE SoftXAAC::internalGetParameter(OMX_INDEXTYPE index, OMX_PTR params) {
+    switch ((OMX_U32)index) {
+        case OMX_IndexParamAudioPortFormat: {
+            OMX_AUDIO_PARAM_PORTFORMATTYPE* formatParams = (OMX_AUDIO_PARAM_PORTFORMATTYPE*)params;
 
             if (!isValidOMXParam(formatParams)) {
                 return OMX_ErrorBadParameter;
@@ -326,16 +295,13 @@
             }
 
             formatParams->eEncoding =
-                (formatParams->nPortIndex == 0)
-                    ? OMX_AUDIO_CodingAAC : OMX_AUDIO_CodingPCM;
+                (formatParams->nPortIndex == 0) ? OMX_AUDIO_CodingAAC : OMX_AUDIO_CodingPCM;
 
             return OMX_ErrorNone;
         }
 
-        case OMX_IndexParamAudioAac:
-        {
-            OMX_AUDIO_PARAM_AACPROFILETYPE *aacParams =
-                (OMX_AUDIO_PARAM_AACPROFILETYPE *)params;
+        case OMX_IndexParamAudioAac: {
+            OMX_AUDIO_PARAM_AACPROFILETYPE* aacParams = (OMX_AUDIO_PARAM_AACPROFILETYPE*)params;
 
             if (!isValidOMXParam(aacParams)) {
                 return OMX_ErrorBadParameter;
@@ -352,9 +318,7 @@
             aacParams->eAACProfile = OMX_AUDIO_AACObjectMain;
 
             aacParams->eAACStreamFormat =
-                mIsADTS
-                    ? OMX_AUDIO_AACStreamFormatMP4ADTS
-                    : OMX_AUDIO_AACStreamFormatMP4FF;
+                mIsADTS ? OMX_AUDIO_AACStreamFormatMP4ADTS : OMX_AUDIO_AACStreamFormatMP4FF;
 
             aacParams->eChannelMode = OMX_AUDIO_ChannelModeStereo;
 
@@ -371,10 +335,8 @@
             return OMX_ErrorNone;
         }
 
-        case OMX_IndexParamAudioPcm:
-        {
-            OMX_AUDIO_PARAM_PCMMODETYPE *pcmParams =
-                (OMX_AUDIO_PARAM_PCMMODETYPE *)params;
+        case OMX_IndexParamAudioPcm: {
+            OMX_AUDIO_PARAM_PCMMODETYPE* pcmParams = (OMX_AUDIO_PARAM_PCMMODETYPE*)params;
 
             if (!isValidOMXParam(pcmParams)) {
                 return OMX_ErrorBadParameter;
@@ -407,10 +369,9 @@
             return OMX_ErrorNone;
         }
 
-        case OMX_IndexParamAudioProfileQuerySupported:
-        {
-            OMX_AUDIO_PARAM_ANDROID_PROFILETYPE *profileParams =
-                (OMX_AUDIO_PARAM_ANDROID_PROFILETYPE *)params;
+        case OMX_IndexParamAudioProfileQuerySupported: {
+            OMX_AUDIO_PARAM_ANDROID_PROFILETYPE* profileParams =
+                (OMX_AUDIO_PARAM_ANDROID_PROFILETYPE*)params;
 
             if (!isValidOMXParam(profileParams)) {
                 return OMX_ErrorBadParameter;
@@ -424,8 +385,7 @@
                 return OMX_ErrorNoMore;
             }
 
-            profileParams->eProfile =
-                kSupportedProfiles[profileParams->nProfileIndex];
+            profileParams->eProfile = kSupportedProfiles[profileParams->nProfileIndex];
 
             return OMX_ErrorNone;
         }
@@ -435,21 +395,17 @@
     }
 }
 
-OMX_ERRORTYPE SoftXAAC::internalSetParameter(
-        OMX_INDEXTYPE index, const OMX_PTR params) {
-
+OMX_ERRORTYPE SoftXAAC::internalSetParameter(OMX_INDEXTYPE index, const OMX_PTR params) {
     switch ((int)index) {
-        case OMX_IndexParamStandardComponentRole:
-        {
-            const OMX_PARAM_COMPONENTROLETYPE *roleParams =
-                (const OMX_PARAM_COMPONENTROLETYPE *)params;
+        case OMX_IndexParamStandardComponentRole: {
+            const OMX_PARAM_COMPONENTROLETYPE* roleParams =
+                (const OMX_PARAM_COMPONENTROLETYPE*)params;
 
             if (!isValidOMXParam(roleParams)) {
                 return OMX_ErrorBadParameter;
             }
 
-            if (strncmp((const char *)roleParams->cRole,
-                        "audio_decoder.aac",
+            if (strncmp((const char*)roleParams->cRole, "audio_decoder.aac",
                         OMX_MAX_STRINGNAME_SIZE - 1)) {
                 return OMX_ErrorUndefined;
             }
@@ -457,10 +413,9 @@
             return OMX_ErrorNone;
         }
 
-        case OMX_IndexParamAudioPortFormat:
-        {
-            const OMX_AUDIO_PARAM_PORTFORMATTYPE *formatParams =
-                (const OMX_AUDIO_PARAM_PORTFORMATTYPE *)params;
+        case OMX_IndexParamAudioPortFormat: {
+            const OMX_AUDIO_PARAM_PORTFORMATTYPE* formatParams =
+                (const OMX_AUDIO_PARAM_PORTFORMATTYPE*)params;
 
             if (!isValidOMXParam(formatParams)) {
                 return OMX_ErrorBadParameter;
@@ -470,20 +425,17 @@
                 return OMX_ErrorUndefined;
             }
 
-            if ((formatParams->nPortIndex == 0
-                        && formatParams->eEncoding != OMX_AUDIO_CodingAAC)
-                || (formatParams->nPortIndex == 1
-                        && formatParams->eEncoding != OMX_AUDIO_CodingPCM)) {
+            if ((formatParams->nPortIndex == 0 && formatParams->eEncoding != OMX_AUDIO_CodingAAC) ||
+                (formatParams->nPortIndex == 1 && formatParams->eEncoding != OMX_AUDIO_CodingPCM)) {
                 return OMX_ErrorUndefined;
             }
 
             return OMX_ErrorNone;
         }
 
-        case OMX_IndexParamAudioAac:
-        {
-            const OMX_AUDIO_PARAM_AACPROFILETYPE *aacParams =
-                (const OMX_AUDIO_PARAM_AACPROFILETYPE *)params;
+        case OMX_IndexParamAudioAac: {
+            const OMX_AUDIO_PARAM_AACPROFILETYPE* aacParams =
+                (const OMX_AUDIO_PARAM_AACPROFILETYPE*)params;
 
             if (!isValidOMXParam(aacParams)) {
                 return OMX_ErrorBadParameter;
@@ -495,8 +447,7 @@
 
             if (aacParams->eAACStreamFormat == OMX_AUDIO_AACStreamFormatMP4FF) {
                 mIsADTS = false;
-            } else if (aacParams->eAACStreamFormat
-                        == OMX_AUDIO_AACStreamFormatMP4ADTS) {
+            } else if (aacParams->eAACStreamFormat == OMX_AUDIO_AACStreamFormatMP4ADTS) {
                 mIsADTS = true;
             } else {
                 return OMX_ErrorUndefined;
@@ -505,10 +456,9 @@
             return OMX_ErrorNone;
         }
 
-        case OMX_IndexParamAudioAndroidAacDrcPresentation:
-        {
-            const OMX_AUDIO_PARAM_ANDROID_AACDRCPRESENTATIONTYPE *aacPresParams =
-                    (const OMX_AUDIO_PARAM_ANDROID_AACDRCPRESENTATIONTYPE *)params;
+        case OMX_IndexParamAudioAndroidAacDrcPresentation: {
+            const OMX_AUDIO_PARAM_ANDROID_AACDRCPRESENTATIONTYPE* aacPresParams =
+                (const OMX_AUDIO_PARAM_ANDROID_AACDRCPRESENTATIONTYPE*)params;
 
             if (!isValidOMXParam(aacPresParams)) {
                 ALOGE("set OMX_ErrorBadParameter");
@@ -525,23 +475,26 @@
             //   nEncodedTargetLevel      idem
             if (aacPresParams->nMaxOutputChannels >= 0) {
                 int max;
-                if (aacPresParams->nMaxOutputChannels >= 8) { max = 8; }
-                else if (aacPresParams->nMaxOutputChannels >= 6) { max = 6; }
-                else if (aacPresParams->nMaxOutputChannels >= 2) { max = 2; }
-                else {
+                if (aacPresParams->nMaxOutputChannels >= 8) {
+                    max = 8;
+                } else if (aacPresParams->nMaxOutputChannels >= 6) {
+                    max = 6;
+                } else if (aacPresParams->nMaxOutputChannels >= 2) {
+                    max = 2;
+                } else {
                     // -1 or 0: disable downmix,  1: mono
                     max = aacPresParams->nMaxOutputChannels;
                 }
             }
             /* Apply DRC Changes */
-            IA_ERRORCODE err_code = setXAACDRCInfo(aacPresParams->nDrcCut,
-                           aacPresParams->nDrcBoost,
-                           aacPresParams->nTargetReferenceLevel,
-                           aacPresParams->nHeavyCompression
+            IA_ERRORCODE err_code = setXAACDRCInfo(aacPresParams->nDrcCut, aacPresParams->nDrcBoost,
+                                                   aacPresParams->nTargetReferenceLevel,
+                                                   aacPresParams->nHeavyCompression
 #ifdef ENABLE_MPEG_D_DRC
-                           ,aacPresParams->nDrcEffectType
+                                                   ,
+                                                   aacPresParams->nDrcEffectType
 #endif
-                           );    // TOD0 : Revert this change
+            );  // TOD0 : Revert this change
             if (err_code != IA_NO_ERROR) {
                 ALOGE("Error in OMX_IndexParamAudioAndroidAacDrcPresentation");
                 return OMX_ErrorBadParameter;
@@ -550,10 +503,8 @@
             return OMX_ErrorNone;
         }
 
-        case OMX_IndexParamAudioPcm:
-        {
-            const OMX_AUDIO_PARAM_PCMMODETYPE *pcmParams =
-                (OMX_AUDIO_PARAM_PCMMODETYPE *)params;
+        case OMX_IndexParamAudioPcm: {
+            const OMX_AUDIO_PARAM_PCMMODETYPE* pcmParams = (OMX_AUDIO_PARAM_PCMMODETYPE*)params;
 
             if (!isValidOMXParam(pcmParams)) {
                 return OMX_ErrorBadParameter;
@@ -577,15 +528,15 @@
 
 void SoftXAAC::onQueueFilled(OMX_U32 /* portIndex */) {
     if (mSignalledError || mOutputPortSettingsChange != NONE) {
-        ALOGE("onQueueFilled do not process %d %d",mSignalledError,mOutputPortSettingsChange);
+        ALOGE("onQueueFilled do not process %d %d", mSignalledError, mOutputPortSettingsChange);
         return;
     }
 
-    uint8_t*  inBuffer        = NULL;
-    uint32_t  inBufferLength  = 0;
+    uint8_t* inBuffer = NULL;
+    uint32_t inBufferLength = 0;
 
-    List<BufferInfo *> &inQueue = getPortQueue(0);
-    List<BufferInfo *> &outQueue = getPortQueue(1);
+    List<BufferInfo*>& inQueue = getPortQueue(0);
+    List<BufferInfo*>& outQueue = getPortQueue(1);
 
     signed int numOutBytes = 0;
 
@@ -595,16 +546,16 @@
     /* Note: entire buffer logic to save and retrieve assumes 2 bytes per*/
     /* sample currently                                                  */
     if (mIsCodecInitialized) {
-        numOutBytes = mOutputFrameLength * (mPcmWdSz/8) * mNumChannels;
-        if ((mPcmWdSz/8) != 2) {
-            ALOGE("XAAC assumes 2 bytes per sample! mPcmWdSz %d",mPcmWdSz);
+        numOutBytes = mOutputFrameLength * (mPcmWdSz / 8) * mNumChannels;
+        if ((mPcmWdSz / 8) != 2) {
+            ALOGE("XAAC assumes 2 bytes per sample! mPcmWdSz %d", mPcmWdSz);
         }
     }
 
     while ((!inQueue.empty() || mEndOfInput) && !outQueue.empty()) {
         if (!inQueue.empty()) {
-            BufferInfo *inInfo = *inQueue.begin();
-            OMX_BUFFERHEADERTYPE *inHeader = inInfo->mHeader;
+            BufferInfo* inInfo = *inQueue.begin();
+            OMX_BUFFERHEADERTYPE* inHeader = inInfo->mHeader;
 
             /* No need to check inHeader != NULL, as inQueue is not empty */
             mEndOfInput = (inHeader->nFlags & OMX_BUFFERFLAG_EOS) != 0;
@@ -618,7 +569,7 @@
                 inBufferLength = inHeader->nFilledLen;
 
                 /* GA header configuration sent to Decoder! */
-                int err_code = configXAACDecoder(inBuffer,inBufferLength);
+                int err_code = configXAACDecoder(inBuffer, inBufferLength);
                 if (0 != err_code) {
                     ALOGW("configXAACDecoder err_code = %d", err_code);
                     mSignalledError = true;
@@ -626,7 +577,8 @@
                     return;
                 }
                 mInputBufferCount++;
-                mOutputBufferCount++; // fake increase of outputBufferCount to keep the counters aligned
+                mOutputBufferCount++;  // fake increase of outputBufferCount to keep the counters
+                                       // aligned
 
                 inInfo->mOwnedByUs = false;
                 inQueue.erase(inQueue.begin());
@@ -657,34 +609,35 @@
             }
 
             // Restore Offset and Length for Port reconfig case
-            size_t tempOffset =  inHeader->nOffset;
+            size_t tempOffset = inHeader->nOffset;
             size_t tempFilledLen = inHeader->nFilledLen;
             if (mIsADTS) {
-                 size_t adtsHeaderSize = 0;
+                size_t adtsHeaderSize = 0;
                 // skip 30 bits, aac_frame_length follows.
                 // ssssssss ssssiiip ppffffPc ccohCCll llllllll lll?????
 
-                const uint8_t *adtsHeader = inHeader->pBuffer + inHeader->nOffset;
+                const uint8_t* adtsHeader = inHeader->pBuffer + inHeader->nOffset;
 
                 bool signalError = false;
                 if (inHeader->nFilledLen < 7) {
-                    ALOGE("Audio data too short to contain even the ADTS header. "
-                            "Got %d bytes.", inHeader->nFilledLen);
+                    ALOGE(
+                        "Audio data too short to contain even the ADTS header. "
+                        "Got %d bytes.",
+                        inHeader->nFilledLen);
                     hexdump(adtsHeader, inHeader->nFilledLen);
                     signalError = true;
                 } else {
                     bool protectionAbsent = (adtsHeader[1] & 1);
 
                     unsigned aac_frame_length =
-                        ((adtsHeader[3] & 3) << 11)
-                        | (adtsHeader[4] << 3)
-                        | (adtsHeader[5] >> 5);
+                        ((adtsHeader[3] & 3) << 11) | (adtsHeader[4] << 3) | (adtsHeader[5] >> 5);
 
                     if (inHeader->nFilledLen < aac_frame_length) {
-                        ALOGE("Not enough audio data for the complete frame. "
-                                "Got %d bytes, frame size according to the ADTS "
-                                "header is %u bytes.",
-                                inHeader->nFilledLen, aac_frame_length);
+                        ALOGE(
+                            "Not enough audio data for the complete frame. "
+                            "Got %d bytes, frame size according to the ADTS "
+                            "header is %u bytes.",
+                            inHeader->nFilledLen, aac_frame_length);
                         hexdump(adtsHeader, inHeader->nFilledLen);
                         signalError = true;
                     } else {
@@ -692,7 +645,7 @@
                         if (aac_frame_length < adtsHeaderSize) {
                             signalError = true;
                         } else {
-                            inBuffer = (uint8_t *)adtsHeader + adtsHeaderSize;
+                            inBuffer = (uint8_t*)adtsHeader + adtsHeaderSize;
                             inBufferLength = aac_frame_length - adtsHeaderSize;
 
                             inHeader->nOffset += adtsHeaderSize;
@@ -712,8 +665,7 @@
                     mCurrentTimestamp = inHeader->nTimeStamp;
                     mLastInHeader = inHeader;
                 } else {
-                    mCurrentTimestamp = mPrevTimestamp +
-                        mOutputFrameLength  * 1000000ll / mSampFreq;
+                    mCurrentTimestamp = mPrevTimestamp + mOutputFrameLength * 1000000ll / mSampFreq;
                 }
             } else {
                 inBuffer = inHeader->pBuffer + inHeader->nOffset;
@@ -730,7 +682,7 @@
             /* which should initialize the codec. Once this state is reached, call the  */
             /* decodeXAACStream API with same frame to decode!                        */
             if (!mIsCodecInitialized) {
-                int err_code = configXAACDecoder(inBuffer,inBufferLength);
+                int err_code = configXAACDecoder(inBuffer, inBufferLength);
                 if (0 != err_code) {
                     ALOGW("configXAACDecoder Failed 2 err_code = %d", err_code);
                     mSignalledError = true;
@@ -743,15 +695,14 @@
             if (!mSampFreq || !mNumChannels) {
                 if ((mInputBufferCount > 2) && (mOutputBufferCount <= 1)) {
                     ALOGW("Invalid AAC stream");
-                    ALOGW("mSampFreq %d mNumChannels %d ",mSampFreq,mNumChannels);
+                    ALOGW("mSampFreq %d mNumChannels %d ", mSampFreq, mNumChannels);
                     mSignalledError = true;
                     notify(OMX_EventError, OMX_ErrorUndefined, 0, NULL);
                     return;
                 }
-            } else if ((mSampFreq != prevSampleRate) ||
-                       (mNumChannels != prevNumChannels)) {
-                ALOGV("Reconfiguring decoder: %d->%d Hz, %d->%d channels",
-                      prevSampleRate, mSampFreq, prevNumChannels, mNumChannels);
+            } else if ((mSampFreq != prevSampleRate) || (mNumChannels != prevNumChannels)) {
+                ALOGV("Reconfiguring decoder: %d->%d Hz, %d->%d channels", prevSampleRate,
+                      mSampFreq, prevNumChannels, mNumChannels);
                 inHeader->nOffset = tempOffset;
                 inHeader->nFilledLen = tempFilledLen;
                 notify(OMX_EventPortSettingsChanged, 1, 0, NULL);
@@ -762,7 +713,8 @@
             signed int bytesConsumed = 0;
             int errorCode = 0;
             if (mIsCodecInitialized) {
-                errorCode = decodeXAACStream(inBuffer,inBufferLength, &bytesConsumed, &numOutBytes);
+                errorCode =
+                    decodeXAACStream(inBuffer, inBufferLength, &bytesConsumed, &numOutBytes);
             } else {
                 ALOGW("Assumption that first frame after header initializes decoder failed!");
             }
@@ -775,7 +727,7 @@
 
             /* In case of error, decoder would have given out empty buffer */
             if ((0 != errorCode) && (0 == numOutBytes) && mIsCodecInitialized) {
-                numOutBytes = mOutputFrameLength * (mPcmWdSz/8) * mNumChannels;
+                numOutBytes = mOutputFrameLength * (mPcmWdSz / 8) * mNumChannels;
             }
             numLoops++;
 
@@ -786,7 +738,7 @@
             if (errorCode) {
                 /* Clear buffer for output buffer is done inside XAAC codec */
                 /* TODO - Check if below memset is on top of reset inside codec */
-                memset(mOutputBuffer, 0, numOutBytes); // TODO: check for overflow, ASAN
+                memset(mOutputBuffer, 0, numOutBytes);  // TODO: check for overflow, ASAN
                 // Discard input buffer.
                 inHeader->nFilledLen = 0;
                 // fall through
@@ -805,8 +757,8 @@
             }
 
             if (!outQueue.empty() && numOutBytes) {
-                BufferInfo *outInfo = *outQueue.begin();
-                OMX_BUFFERHEADERTYPE *outHeader = outInfo->mHeader;
+                BufferInfo* outInfo = *outQueue.begin();
+                OMX_BUFFERHEADERTYPE* outHeader = outInfo->mHeader;
 
                 if (outHeader->nOffset != 0) {
                     ALOGE("outHeader->nOffset != 0 is not handled");
@@ -815,12 +767,10 @@
                     return;
                 }
 
-                signed short *outBuffer =
-                        reinterpret_cast<signed short *>(outHeader->pBuffer + outHeader->nOffset);
+                signed short* outBuffer =
+                    reinterpret_cast<signed short*>(outHeader->pBuffer + outHeader->nOffset);
                 int samplesize = mNumChannels * sizeof(int16_t);
-                if (outHeader->nOffset
-                        + mOutputFrameLength * samplesize
-                        > outHeader->nAllocLen) {
+                if (outHeader->nOffset + mOutputFrameLength * samplesize > outHeader->nAllocLen) {
                     ALOGE("buffer overflow");
                     mSignalledError = true;
                     notify(OMX_EventError, OMX_ErrorUndefined, 0, NULL);
@@ -853,12 +803,12 @@
                     ALOGV(" empty block signaling EOS");
                     // send partial or empty block signaling EOS
                     mEndOfOutput = true;
-                    BufferInfo *outInfo = *outQueue.begin();
-                    OMX_BUFFERHEADERTYPE *outHeader = outInfo->mHeader;
+                    BufferInfo* outInfo = *outQueue.begin();
+                    OMX_BUFFERHEADERTYPE* outHeader = outInfo->mHeader;
 
                     outHeader->nFilledLen = 0;
                     outHeader->nFlags = OMX_BUFFERFLAG_EOS;
-                    outHeader->nTimeStamp = mPrevTimestamp ;
+                    outHeader->nTimeStamp = mPrevTimestamp;
 
                     mOutputBufferCount++;
                     outInfo->mOwnedByUs = false;
@@ -867,7 +817,7 @@
                     notifyFillBufferDone(outHeader);
                     outHeader = NULL;
                 }
-                break; // if outQueue not empty but no more output
+                break;  // if outQueue not empty but no more output
             }
         }
     }
@@ -895,48 +845,36 @@
 int SoftXAAC::configflushDecode() {
     IA_ERRORCODE err_code;
     UWORD32 ui_init_done;
-    uint32_t inBufferLength=8203;
+    uint32_t inBufferLength = 8203;
 
-    err_code = ixheaacd_dec_api(mXheaacCodecHandle,
-                                IA_API_CMD_INIT,
-                                IA_CMD_TYPE_FLUSH_MEM,
-                                NULL);
+    err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_INIT, IA_CMD_TYPE_FLUSH_MEM, NULL);
     RETURN_IF_FATAL(err_code, "IA_CMD_TYPE_FLUSH_MEM");
 
-    err_code = ixheaacd_dec_api(mXheaacCodecHandle,
-                                IA_API_CMD_SET_INPUT_BYTES,
-                                0,
-                                &inBufferLength);
+    err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_SET_INPUT_BYTES, 0, &inBufferLength);
     RETURN_IF_FATAL(err_code, "IA_API_CMD_SET_INPUT_BYTES");
 
-    err_code = ixheaacd_dec_api(mXheaacCodecHandle,
-                                IA_API_CMD_INIT,
-                                IA_CMD_TYPE_FLUSH_MEM,
-                                NULL);
+    err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_INIT, IA_CMD_TYPE_FLUSH_MEM, NULL);
     RETURN_IF_FATAL(err_code, "IA_CMD_TYPE_FLUSH_MEM");
 
-    err_code = ixheaacd_dec_api(mXheaacCodecHandle,
-                                IA_API_CMD_INIT,
-                                IA_CMD_TYPE_INIT_DONE_QUERY,
+    err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_INIT, IA_CMD_TYPE_INIT_DONE_QUERY,
                                 &ui_init_done);
     RETURN_IF_FATAL(err_code, "IA_CMD_TYPE_INIT_DONE_QUERY");
 
-
     if (ui_init_done) {
         err_code = getXAACStreamInfo();
         RETURN_IF_FATAL(err_code, "getXAACStreamInfo");
 
-        ALOGV("Found Codec with below config---\nsampFreq %d\nnumChannels %d\npcmWdSz %d\nchannelMask %d\noutputFrameLength %d",
-                                    mSampFreq,mNumChannels,mPcmWdSz,mChannelMask,mOutputFrameLength);
-        if(mNumChannels > MAX_CHANNEL_COUNT) {
+        ALOGV(
+            "Found Codec with below config---\nsampFreq %d\nnumChannels %d\npcmWdSz "
+            "%d\nchannelMask %d\noutputFrameLength %d",
+            mSampFreq, mNumChannels, mPcmWdSz, mChannelMask, mOutputFrameLength);
+        if (mNumChannels > MAX_CHANNEL_COUNT) {
             ALOGE(" No of channels are more than max channels\n");
             mIsCodecInitialized = false;
-        }
-        else
+        } else
             mIsCodecInitialized = true;
     }
     return err_code;
-
 }
 int SoftXAAC::drainDecoder() {
     return 0;
@@ -965,15 +903,13 @@
         case NONE:
             break;
 
-        case AWAITING_DISABLED:
-        {
+        case AWAITING_DISABLED: {
             CHECK(!enabled);
             mOutputPortSettingsChange = AWAITING_ENABLED;
             break;
         }
 
-        default:
-        {
+        default: {
             CHECK_EQ((int)mOutputPortSettingsChange, (int)AWAITING_ENABLED);
             CHECK(enabled);
             mOutputPortSettingsChange = NONE;
@@ -1012,10 +948,7 @@
     /* ******************************************************************/
 
     /* Get the API size */
-    err_code = ixheaacd_dec_api(NULL,
-                                IA_API_CMD_GET_API_SIZE,
-                                0,
-                                &pui_api_size);
+    err_code = ixheaacd_dec_api(NULL, IA_API_CMD_GET_API_SIZE, 0, &pui_api_size);
     RETURN_IF_FATAL(err_code, "IA_API_CMD_GET_API_SIZE");
 
     if (mMallocCount == MAX_MEM_ALLOCS) {
@@ -1026,19 +959,16 @@
     /* Allocate memory for API */
     mMemoryArray[mMallocCount] = memalign(4, pui_api_size);
     if (mMemoryArray[mMallocCount] == NULL) {
-        ALOGE("malloc for pui_api_size + 4 >> %d Failed",pui_api_size + 4);
+        ALOGE("malloc for pui_api_size + 4 >> %d Failed", pui_api_size + 4);
         return IA_FATAL_ERROR;
     }
     /* Set API object with the memory allocated */
-    mXheaacCodecHandle =
-        (pVOID)((WORD8*)mMemoryArray[mMallocCount]);
+    mXheaacCodecHandle = (pVOID)((WORD8*)mMemoryArray[mMallocCount]);
     mMallocCount++;
 
     /* Set the config params to default values */
-    err_code = ixheaacd_dec_api(mXheaacCodecHandle,
-                                IA_API_CMD_INIT,
-                                IA_CMD_TYPE_INIT_API_PRE_CONFIG_PARAMS,
-                                NULL);
+    err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_INIT,
+                                IA_CMD_TYPE_INIT_API_PRE_CONFIG_PARAMS, NULL);
     RETURN_IF_FATAL(err_code, "IA_CMD_TYPE_INIT_API_PRE_CONFIG_PARAMS");
 #ifdef ENABLE_MPEG_D_DRC
     /* Get the API size */
@@ -1051,28 +981,22 @@
         return IA_FATAL_ERROR;
     }
 
-   /* Allocate memory for API */
-   mMemoryArray[mMallocCount] = memalign(4, pui_api_size);
+    /* Allocate memory for API */
+    mMemoryArray[mMallocCount] = memalign(4, pui_api_size);
 
-   if(mMemoryArray[mMallocCount] == NULL)
-   {
-       ALOGE("malloc for drc api structure Failed");
-       return IA_FATAL_ERROR;
-   }
-   memset(mMemoryArray[mMallocCount],0,pui_api_size);
+    if (mMemoryArray[mMallocCount] == NULL) {
+        ALOGE("malloc for drc api structure Failed");
+        return IA_FATAL_ERROR;
+    }
+    memset(mMemoryArray[mMallocCount], 0, pui_api_size);
 
-   /* Set API object with the memory allocated */
-   mMpegDDrcHandle =
-       (pVOID)((WORD8*)mMemoryArray[mMallocCount]);
+    /* Set API object with the memory allocated */
+    mMpegDDrcHandle = (pVOID)((WORD8*)mMemoryArray[mMallocCount]);
     mMallocCount++;
 
-
     /* Set the config params to default values */
-    err_code = ia_drc_dec_api(
-       mMpegDDrcHandle,
-       IA_API_CMD_INIT,
-       IA_CMD_TYPE_INIT_API_PRE_CONFIG_PARAMS,
-       NULL);
+    err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_INIT,
+                              IA_CMD_TYPE_INIT_API_PRE_CONFIG_PARAMS, NULL);
 
     RETURN_IF_FATAL(err_code, "IA_CMD_TYPE_INIT_API_PRE_CONFIG_PARAMS");
 #endif
@@ -1081,10 +1005,8 @@
     /* Set config parameters                                            */
     /* ******************************************************************/
     UWORD32 ui_mp4_flag = 1;
-    err_code = ixheaacd_dec_api(mXheaacCodecHandle,
-                                IA_API_CMD_SET_CONFIG_PARAM,
-                                IA_ENHAACPLUS_DEC_CONFIG_PARAM_ISMP4,
-                                &ui_mp4_flag);
+    err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_SET_CONFIG_PARAM,
+                                IA_ENHAACPLUS_DEC_CONFIG_PARAM_ISMP4, &ui_mp4_flag);
     RETURN_IF_FATAL(err_code, "IA_ENHAACPLUS_DEC_CONFIG_PARAM_ISMP4");
 
     /* ******************************************************************/
@@ -1092,9 +1014,7 @@
     /* ******************************************************************/
 
     /* Get memory info tables size */
-    err_code = ixheaacd_dec_api(mXheaacCodecHandle,
-                                IA_API_CMD_GET_MEMTABS_SIZE,
-                                0,
+    err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_MEMTABS_SIZE, 0,
                                 &ui_proc_mem_tabs_size);
     RETURN_IF_FATAL(err_code, "IA_API_CMD_GET_MEMTABS_SIZE");
 
@@ -1105,23 +1025,20 @@
 
     mMemoryArray[mMallocCount] = memalign(4, ui_proc_mem_tabs_size);
     if (mMemoryArray[mMallocCount] == NULL) {
-        ALOGE("Malloc for size (ui_proc_mem_tabs_size + 4) = %d failed!",ui_proc_mem_tabs_size + 4);
+        ALOGE("Malloc for size (ui_proc_mem_tabs_size + 4) = %d failed!",
+              ui_proc_mem_tabs_size + 4);
         return IA_FATAL_ERROR;
     }
     mMallocCount++;
     /* Set pointer for process memory tables    */
-    err_code = ixheaacd_dec_api(mXheaacCodecHandle,
-                                IA_API_CMD_SET_MEMTABS_PTR,
-                                0,
+    err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_SET_MEMTABS_PTR, 0,
                                 (pVOID)((WORD8*)mMemoryArray[mMallocCount - 1]));
     RETURN_IF_FATAL(err_code, "IA_API_CMD_SET_MEMTABS_PTR");
 
 
     /* initialize the API, post config, fill memory tables  */
-    err_code = ixheaacd_dec_api(mXheaacCodecHandle,
-                                IA_API_CMD_INIT,
-                                IA_CMD_TYPE_INIT_API_POST_CONFIG_PARAMS,
-                                NULL);
+    err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_INIT,
+                                IA_CMD_TYPE_INIT_API_POST_CONFIG_PARAMS, NULL);
     RETURN_IF_FATAL(err_code, "IA_CMD_TYPE_INIT_API_POST_CONFIG_PARAMS");
 
     /* ******************************************************************/
@@ -1129,75 +1046,59 @@
     /* ******************************************************************/
     /* There are four different types of memories, that needs to be allocated */
     /* persistent,scratch,input and output */
-    for(i = 0; i < 4; i++) {
+    for (i = 0; i < 4; i++) {
         int ui_size = 0, ui_alignment = 0, ui_type = 0;
         pVOID pv_alloc_ptr;
 
         /* Get memory size */
-        err_code = ixheaacd_dec_api(mXheaacCodecHandle,
-                                    IA_API_CMD_GET_MEM_INFO_SIZE,
-                                    i,
-                                    &ui_size);
+        err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_MEM_INFO_SIZE, i, &ui_size);
         RETURN_IF_FATAL(err_code, "IA_API_CMD_GET_MEM_INFO_SIZE");
 
         /* Get memory alignment */
-        err_code = ixheaacd_dec_api(mXheaacCodecHandle,
-                                    IA_API_CMD_GET_MEM_INFO_ALIGNMENT,
-                                    i,
+        err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_MEM_INFO_ALIGNMENT, i,
                                     &ui_alignment);
         RETURN_IF_FATAL(err_code, "IA_API_CMD_GET_MEM_INFO_ALIGNMENT");
 
         /* Get memory type */
-        err_code = ixheaacd_dec_api(mXheaacCodecHandle,
-                                    IA_API_CMD_GET_MEM_INFO_TYPE,
-                                    i,
-                                    &ui_type);
+        err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_MEM_INFO_TYPE, i, &ui_type);
         RETURN_IF_FATAL(err_code, "IA_API_CMD_GET_MEM_INFO_TYPE");
 
         if (mMallocCount == MAX_MEM_ALLOCS) {
             ALOGE("mMemoryArray is full");
             return IA_FATAL_ERROR;
         }
-
-        mMemoryArray[mMallocCount] =
-            memalign(ui_alignment , ui_size);
+        mMemoryArray[mMallocCount] = memalign(ui_alignment, ui_size);
         if (mMemoryArray[mMallocCount] == NULL) {
-            ALOGE("Malloc for size (ui_size + ui_alignment) = %d failed!",ui_size + ui_alignment);
+            ALOGE("Malloc for size (ui_size + ui_alignment) = %d failed!", ui_size + ui_alignment);
             return IA_FATAL_ERROR;
         }
-        pv_alloc_ptr =
-            (pVOID )((WORD8*)mMemoryArray[mMallocCount]);
+        pv_alloc_ptr = (pVOID)((WORD8*)mMemoryArray[mMallocCount]);
         mMallocCount++;
 
         /* Set the buffer pointer */
-        err_code = ixheaacd_dec_api(mXheaacCodecHandle,
-                                    IA_API_CMD_SET_MEM_PTR,
-                                    i,
-                                    pv_alloc_ptr);
+        err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_SET_MEM_PTR, i, pv_alloc_ptr);
         RETURN_IF_FATAL(err_code, "IA_API_CMD_SET_MEM_PTR");
         if (ui_type == IA_MEMTYPE_INPUT) {
             mInputBuffer = (pWORD8)pv_alloc_ptr;
             mInputBufferSize = ui_size;
-
         }
 
         if (ui_type == IA_MEMTYPE_OUTPUT) {
             mOutputBuffer = (pWORD8)pv_alloc_ptr;
         }
-
     }
     /* End first part */
 
-  return IA_NO_ERROR;
+    return IA_NO_ERROR;
 }
 
 int SoftXAAC::configXAACDecoder(uint8_t* inBuffer, uint32_t inBufferLength) {
-
     UWORD32 ui_init_done;
     int32_t i_bytes_consumed;
 
     if (mInputBufferSize < inBufferLength) {
-        ALOGE("Cannot config AAC, input buffer size %d < inBufferLength %d",mInputBufferSize,inBufferLength);
+        ALOGE("Cannot config AAC, input buffer size %d < inBufferLength %d", mInputBufferSize,
+              inBufferLength);
         return false;
     }
 
@@ -1205,51 +1106,41 @@
     memcpy(mInputBuffer, inBuffer, inBufferLength);
 
     /* Set number of bytes to be processed */
-    IA_ERRORCODE err_code = ixheaacd_dec_api(mXheaacCodecHandle,
-                                             IA_API_CMD_SET_INPUT_BYTES,
-                                             0,
-                                             &inBufferLength);
+    IA_ERRORCODE err_code =
+        ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_SET_INPUT_BYTES, 0, &inBufferLength);
     RETURN_IF_FATAL(err_code, "IA_API_CMD_SET_INPUT_BYTES");
 
     if (mIsCodecConfigFlushRequired) {
         /* If codec is already initialized, then GA header is passed again */
         /* Need to call the Flush API instead of INIT_PROCESS */
         mIsCodecInitialized = false; /* Codec needs to be Reinitialized after flush */
-        err_code = ixheaacd_dec_api(mXheaacCodecHandle,
-                                    IA_API_CMD_INIT,
-                                    IA_CMD_TYPE_GA_HDR,
-                                    NULL);
+        err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_INIT, IA_CMD_TYPE_GA_HDR, NULL);
         RETURN_IF_FATAL(err_code, "IA_CMD_TYPE_GA_HDR");
-    }
-    else {
+    } else {
         /* Initialize the process */
-        err_code = ixheaacd_dec_api(mXheaacCodecHandle,
-                                    IA_API_CMD_INIT,
-                                    IA_CMD_TYPE_INIT_PROCESS,
-                                    NULL);
+        err_code =
+            ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_INIT, IA_CMD_TYPE_INIT_PROCESS, NULL);
         RETURN_IF_FATAL(err_code, "IA_CMD_TYPE_INIT_PROCESS");
     }
 
     /* Checking for end of initialization */
-    err_code = ixheaacd_dec_api(mXheaacCodecHandle,
-                                IA_API_CMD_INIT,
-                                IA_CMD_TYPE_INIT_DONE_QUERY,
+    err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_INIT, IA_CMD_TYPE_INIT_DONE_QUERY,
                                 &ui_init_done);
     RETURN_IF_FATAL(err_code, "IA_CMD_TYPE_INIT_DONE_QUERY");
 
     /* How much buffer is used in input buffers */
-    err_code = ixheaacd_dec_api(mXheaacCodecHandle,
-                                IA_API_CMD_GET_CURIDX_INPUT_BUF,
-                                0,
-                                &i_bytes_consumed);
+    err_code =
+        ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CURIDX_INPUT_BUF, 0, &i_bytes_consumed);
     RETURN_IF_FATAL(err_code, "IA_API_CMD_GET_CURIDX_INPUT_BUF");
 
-    if(ui_init_done){
+    if (ui_init_done) {
         err_code = getXAACStreamInfo();
         RETURN_IF_FATAL(err_code, "getXAACStreamInfo");
 
-        ALOGI("Found Codec with below config---\nsampFreq %d\nnumChannels %d\npcmWdSz %d\nchannelMask %d\noutputFrameLength %d",
-                                    mSampFreq,mNumChannels,mPcmWdSz,mChannelMask,mOutputFrameLength);
+        ALOGI(
+            "Found Codec with below config---\nsampFreq %d\nnumChannels %d\npcmWdSz "
+            "%d\nchannelMask %d\noutputFrameLength %d",
+            mSampFreq, mNumChannels, mPcmWdSz, mChannelMask, mOutputFrameLength);
         mIsCodecInitialized = true;
 
 #ifdef ENABLE_MPEG_D_DRC
@@ -1260,452 +1151,366 @@
 
     return IA_NO_ERROR;
 }
-int SoftXAAC::configMPEGDDrc()
-{
-   IA_ERRORCODE err_code = IA_NO_ERROR;
-   int i_effect_type;
-   int i_loud_norm;
-   int i_target_loudness;
-   unsigned int i_sbr_mode;
-   int n_mems;
-   int i;
+int SoftXAAC::configMPEGDDrc() {
+    IA_ERRORCODE err_code = IA_NO_ERROR;
+    int i_effect_type;
+    int i_loud_norm;
+    int i_target_loudness;
+    unsigned int i_sbr_mode;
+    int n_mems;
+    int i;
 
-#ifdef     ENABLE_MPEG_D_DRC
+#ifdef ENABLE_MPEG_D_DRC
     {
+        /* Sampling Frequency */
+        err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM,
+                                  IA_DRC_DEC_CONFIG_PARAM_SAMP_FREQ, &mSampFreq);
+        RETURN_IF_FATAL(err_code, "IA_DRC_DEC_CONFIG_PARAM_SAMP_FREQ");
+        /* Total Number of Channels */
+        err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM,
+                                  IA_DRC_DEC_CONFIG_PARAM_NUM_CHANNELS, &mNumChannels);
+        RETURN_IF_FATAL(err_code, "IA_DRC_DEC_CONFIG_PARAM_NUM_CHANNELS");
 
-    /* Sampling Frequency */
-    {
-      err_code =
-          ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM,
-                         IA_DRC_DEC_CONFIG_PARAM_SAMP_FREQ, &mSampFreq);
-      RETURN_IF_FATAL(err_code, "IA_DRC_DEC_CONFIG_PARAM_SAMP_FREQ");
-    }
-    /* Total Number of Channels */
-    {
-      err_code =
-          ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM,
-                         IA_DRC_DEC_CONFIG_PARAM_NUM_CHANNELS, &mNumChannels);
-      RETURN_IF_FATAL(err_code, "IA_DRC_DEC_CONFIG_PARAM_NUM_CHANNELS");
-    }
+        /* PCM word size  */
+        err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM,
+                                  IA_DRC_DEC_CONFIG_PARAM_PCM_WDSZ, &mPcmWdSz);
+        RETURN_IF_FATAL(err_code, "IA_DRC_DEC_CONFIG_PARAM_PCM_WDSZ");
 
-    /* PCM word size  */
-    {
-      err_code =
-          ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM,
-                         IA_DRC_DEC_CONFIG_PARAM_PCM_WDSZ, &mPcmWdSz);
-      RETURN_IF_FATAL(err_code, "IA_DRC_DEC_CONFIG_PARAM_PCM_WDSZ");
-    }
+        /*Set Effect Type*/
 
-    /*Set Effect Type*/
-
-    {
         err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM,
-            IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_EFFECT_TYPE, &i_effect_type);
+                                    IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_EFFECT_TYPE, &i_effect_type);
         RETURN_IF_FATAL(err_code, "IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_EFFECT_TYPE");
 
-
-        err_code =
-            ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM,
-                IA_DRC_DEC_CONFIG_DRC_EFFECT_TYPE, &i_effect_type);
+        err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM,
+                                  IA_DRC_DEC_CONFIG_DRC_EFFECT_TYPE, &i_effect_type);
         RETURN_IF_FATAL(err_code, "IA_DRC_DEC_CONFIG_DRC_EFFECT_TYPE");
 
-    }
-
-/*Set target loudness */
-
-    {
-        err_code = ixheaacd_dec_api(
-            mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM,
-            IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_TARGET_LOUDNESS, &i_target_loudness);
+        /*Set target loudness */
+        err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM,
+                                    IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_TARGET_LOUDNESS,
+                                    &i_target_loudness);
         RETURN_IF_FATAL(err_code, "IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_TARGET_LOUDNESS");
 
-
-        err_code =
-            ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM,
-                IA_DRC_DEC_CONFIG_DRC_TARGET_LOUDNESS, &i_target_loudness);
+        err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM,
+                                  IA_DRC_DEC_CONFIG_DRC_TARGET_LOUDNESS, &i_target_loudness);
         RETURN_IF_FATAL(err_code, "IA_DRC_DEC_CONFIG_DRC_TARGET_LOUDNESS");
 
-    }
+        /*Set loud_norm_flag*/
+        err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM,
+                                    IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_LOUD_NORM, &i_loud_norm);
+        RETURN_IF_FATAL(err_code, "IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_LOUD_NORM");
 
-    /*Set loud_norm_flag*/
-    {
-        err_code = ixheaacd_dec_api(
-            mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM,
-            IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_LOUD_NORM, &i_loud_norm);
-        RETURN_IF_FATAL(err_code,"IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_LOUD_NORM");
+        err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM,
+                                  IA_DRC_DEC_CONFIG_DRC_LOUD_NORM, &i_loud_norm);
+        RETURN_IF_FATAL(err_code, "IA_DRC_DEC_CONFIG_DRC_LOUD_NORM");
 
+        err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM,
+                                    IA_ENHAACPLUS_DEC_CONFIG_PARAM_SBR_MODE, &i_sbr_mode);
+        RETURN_IF_FATAL(err_code, "IA_ENHAACPLUS_DEC_CONFIG_PARAM_SBR_MODE");
 
-        err_code =
-            ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM,
-                IA_DRC_DEC_CONFIG_DRC_LOUD_NORM, &i_loud_norm);
-        RETURN_IF_FATAL(err_code,"IA_DRC_DEC_CONFIG_DRC_LOUD_NORM");
+        err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_INIT,
+                                  IA_CMD_TYPE_INIT_API_POST_CONFIG_PARAMS, NULL);
 
-    }
+        RETURN_IF_FATAL(err_code, "IA_CMD_TYPE_INIT_API_POST_CONFIG_PARAMS");
 
+        for (i = 0; i < (WORD32)2; i++) {
+            WORD32 ui_size, ui_alignment, ui_type;
+            pVOID pv_alloc_ptr;
 
+            /* Get memory size */
+            err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_GET_MEM_INFO_SIZE, i, &ui_size);
 
-    err_code = ixheaacd_dec_api(
-        mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM,
-        IA_ENHAACPLUS_DEC_CONFIG_PARAM_SBR_MODE, &i_sbr_mode);
-        RETURN_IF_FATAL(err_code,"IA_ENHAACPLUS_DEC_CONFIG_PARAM_SBR_MODE");
+            RETURN_IF_FATAL(err_code, "IA_API_CMD_GET_MEM_INFO_SIZE");
 
-    err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_INIT,
-                              IA_CMD_TYPE_INIT_API_POST_CONFIG_PARAMS, NULL);
+            /* Get memory alignment */
+            err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_GET_MEM_INFO_ALIGNMENT, i,
+                                      &ui_alignment);
 
-    RETURN_IF_FATAL(err_code, "IA_CMD_TYPE_INIT_API_POST_CONFIG_PARAMS");
+            RETURN_IF_FATAL(err_code, "IA_API_CMD_GET_MEM_INFO_ALIGNMENT");
 
+            /* Get memory type */
+            err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_GET_MEM_INFO_TYPE, i, &ui_type);
+            RETURN_IF_FATAL(err_code, "IA_API_CMD_GET_MEM_INFO_TYPE");
+            if (mMallocCount == MAX_MEM_ALLOCS) {
+                ALOGE("mMemoryArray is full");
+                return IA_FATAL_ERROR;
+            }
 
+            mMemoryArray[mMallocCount] = memalign(4, ui_size);
+            if (mMemoryArray[mMallocCount] == NULL) {
+                ALOGE(" Cannot create requested memory  %d", ui_size);
+                return IA_FATAL_ERROR;
+            }
+            pv_alloc_ptr = (pVOID)((WORD8*)mMemoryArray[mMallocCount]);
+            mMallocCount++;
 
-    for (i = 0; i < (WORD32)2; i++) {
-      WORD32 ui_size, ui_alignment, ui_type;
-      pVOID pv_alloc_ptr;
+            /* Set the buffer pointer */
+            err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_MEM_PTR, i, pv_alloc_ptr);
 
-      /* Get memory size */
-      err_code = ia_drc_dec_api(mMpegDDrcHandle,
-                                IA_API_CMD_GET_MEM_INFO_SIZE, i, &ui_size);
+            RETURN_IF_FATAL(err_code, "IA_API_CMD_SET_MEM_PTR");
+        }
+        {
+            WORD32 ui_size;
+            ui_size = 8192 * 2;
+            if (mMallocCount == MAX_MEM_ALLOCS) {
+                ALOGE("mMemoryArray is full");
+                return IA_FATAL_ERROR;
+            }
 
-     RETURN_IF_FATAL(err_code, "IA_API_CMD_GET_MEM_INFO_SIZE");
+            mMemoryArray[mMallocCount] = memalign(4, ui_size);
+            if (mMemoryArray[mMallocCount] == NULL) {
+                ALOGE(" Cannot create requested memory  %d", ui_size);
+                return IA_FATAL_ERROR;
+            }
 
-      /* Get memory alignment */
-      err_code =
-          ia_drc_dec_api(mMpegDDrcHandle,
-                         IA_API_CMD_GET_MEM_INFO_ALIGNMENT, i, &ui_alignment);
+            mDrcInBuf = (int8_t*)mMemoryArray[mMallocCount];
+            mMallocCount++;
+            err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_MEM_PTR, 2,
+                                      /*mOutputBuffer*/ mDrcInBuf);
+            RETURN_IF_FATAL(err_code, "IA_API_CMD_SET_MEM_PTR");
 
-      RETURN_IF_FATAL(err_code, "IA_API_CMD_GET_MEM_INFO_ALIGNMENT");
+            if (mMallocCount == MAX_MEM_ALLOCS) {
+                ALOGE("mMemoryArray is full");
+                return IA_FATAL_ERROR;
+            }
+            mMemoryArray[mMallocCount] = memalign(4, ui_size);
+            if (mMemoryArray[mMallocCount] == NULL) {
+                ALOGE(" Cannot create requested memory  %d", ui_size);
+                return IA_FATAL_ERROR;
+            }
 
-      /* Get memory type */
-      err_code = ia_drc_dec_api(mMpegDDrcHandle,
-                                IA_API_CMD_GET_MEM_INFO_TYPE, i, &ui_type);
-
-     RETURN_IF_FATAL(err_code, "IA_API_CMD_GET_MEM_INFO_TYPE");
-
-      if (mMallocCount == MAX_MEM_ALLOCS) {
-            ALOGE("mMemoryArray is full");
-            return IA_FATAL_ERROR;
-      }
-      mMemoryArray[mMallocCount] = memalign(4, ui_size);
-      if (mMemoryArray[mMallocCount] == NULL) {
-        ALOGE(" Cannot create requested memory  %d",ui_size);
-        return IA_FATAL_ERROR;
-      }
-        pv_alloc_ptr =
-            (pVOID )((WORD8*)mMemoryArray[mMallocCount]);
-        mMallocCount++;
-
-           /* Set the buffer pointer */
-      err_code = ia_drc_dec_api(mMpegDDrcHandle,
-                                IA_API_CMD_SET_MEM_PTR, i, pv_alloc_ptr);
-
-      RETURN_IF_FATAL(err_code, "IA_API_CMD_SET_MEM_PTR");
-    }
-    {
-    WORD32 ui_size;
-    ui_size=8192*2;
-    if (mMallocCount == MAX_MEM_ALLOCS) {
-        ALOGE("mMemoryArray is full");
-        return IA_FATAL_ERROR;
-    }
-
-    mMemoryArray[mMallocCount]=memalign(4, ui_size);
-      if (mMemoryArray[mMallocCount] == NULL) {
-        ALOGE(" Cannot create requested memory  %d",ui_size);
-        return IA_FATAL_ERROR;
-      }
-
-    mDrcInBuf=(int8_t *)mMemoryArray[mMallocCount];
-    mMallocCount++;
-    err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_MEM_PTR,
-                              2, /*mOutputBuffer*/ mDrcInBuf);
-    RETURN_IF_FATAL(err_code, "IA_API_CMD_SET_MEM_PTR");
-
-    if (mMallocCount == MAX_MEM_ALLOCS) {
-        ALOGE("mMemoryArray is full");
-        return IA_FATAL_ERROR;
-    }
-
-    mMemoryArray[mMallocCount]=memalign(4, ui_size);
-      if (mMemoryArray[mMallocCount] == NULL) {
-        ALOGE(" Cannot create requested memory  %d",ui_size);
-        return IA_FATAL_ERROR;
-      }
-
-    mDrcOutBuf=(int8_t *)mMemoryArray[mMallocCount];
-    mMallocCount++;
-    err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_MEM_PTR,
-                              3, /*mOutputBuffer*/ mDrcOutBuf);
-    RETURN_IF_FATAL(err_code, "IA_API_CMD_SET_MEM_PTR");
-    }
-    /*ITTIAM: DRC buffers
+            mDrcOutBuf = (int8_t*)mMemoryArray[mMallocCount];
+            mMallocCount++;
+            err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_MEM_PTR, 3,
+                                      /*mOutputBuffer*/ mDrcOutBuf);
+            RETURN_IF_FATAL(err_code, "IA_API_CMD_SET_MEM_PTR");
+        }
+        /* DRC buffers
             buf[0] - contains extension element pay load loudness related
             buf[1] - contains extension element pay load*/
-    {
-      VOID *p_array[2][16];
-      WORD32 ii;
-      WORD32 buf_sizes[2][16];
-      WORD32 num_elements;
-      WORD32 num_config_ext;
-      WORD32 bit_str_fmt = 1;
-
-
-
-      WORD32 uo_num_chan;
-
-      memset(buf_sizes, 0, 32 * sizeof(WORD32));
-
-      err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM,
-          IA_ENHAACPLUS_DEC_CONFIG_EXT_ELE_BUF_SIZES, &buf_sizes[0][0]);
-      RETURN_IF_FATAL(err_code, "IA_ENHAACPLUS_DEC_CONFIG_EXT_ELE_BUF_SIZES");
-
-      err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM,
-          IA_ENHAACPLUS_DEC_CONFIG_EXT_ELE_PTR, &p_array);
-      RETURN_IF_FATAL(err_code, "IA_ENHAACPLUS_DEC_CONFIG_EXT_ELE_PTR");
-
-      err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_INIT,
-                                IA_CMD_TYPE_INIT_SET_BUFF_PTR, 0);
-      RETURN_IF_FATAL(err_code, "IA_CMD_TYPE_INIT_SET_BUFF_PTR");
-
-
-      err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM,
-          IA_ENHAACPLUS_DEC_CONFIG_NUM_ELE, &num_elements);
-      RETURN_IF_FATAL(err_code, "IA_ENHAACPLUS_DEC_CONFIG_NUM_ELE");
-
-      err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM,
-          IA_ENHAACPLUS_DEC_CONFIG_NUM_CONFIG_EXT, &num_config_ext);
-      RETURN_IF_FATAL(err_code, "IA_ENHAACPLUS_DEC_CONFIG_NUM_CONFIG_EXT");
-
-      for (ii = 0; ii < num_config_ext; ii++) {
-        /*copy loudness bitstream*/
-        if (buf_sizes[0][ii] > 0) {
-          memcpy(mDrcInBuf, p_array[0][ii], buf_sizes[0][ii]);
-
-          /*Set bitstream_split_format */
-          err_code = ia_drc_dec_api(
-              mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM,
-              IA_DRC_DEC_CONFIG_PARAM_BITS_FORMAT, &bit_str_fmt);
-          RETURN_IF_FATAL(err_code, "IA_DRC_DEC_CONFIG_PARAM_BITS_FORMAT");
-
-          /* Set number of bytes to be processed */
-          err_code = ia_drc_dec_api(mMpegDDrcHandle,
-                                    IA_API_CMD_SET_INPUT_BYTES_IL_BS, 0,
-                                    &buf_sizes[0][ii]);
-          RETURN_IF_FATAL(err_code, "IA_API_CMD_SET_INPUT_BYTES_IL_BS");
-
-
-          /* Execute process */
-          err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_INIT,
-                                    IA_CMD_TYPE_INIT_CPY_IL_BSF_BUFF, NULL);
-          RETURN_IF_FATAL(err_code, "IA_CMD_TYPE_INIT_CPY_IL_BSF_BUFF");
-
-
-          mDRCFlag = 1;
-        }
-      }
-
-      for (ii = 0; ii < num_elements; ii++) {
-        /*copy config bitstream*/
-        if (buf_sizes[1][ii] > 0) {
-          memcpy(mDrcInBuf, p_array[1][ii], buf_sizes[1][ii]);
-          /* Set number of bytes to be processed */
-
-          /*Set bitstream_split_format */
-          err_code = ia_drc_dec_api(
-              mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM,
-              IA_DRC_DEC_CONFIG_PARAM_BITS_FORMAT, &bit_str_fmt);
-          RETURN_IF_FATAL(err_code, "IA_DRC_DEC_CONFIG_PARAM_BITS_FORMAT");
-
-          err_code = ia_drc_dec_api(mMpegDDrcHandle,
-                                    IA_API_CMD_SET_INPUT_BYTES_IC_BS, 0,
-                                    &buf_sizes[1][ii]);
-          RETURN_IF_FATAL(err_code, "IA_API_CMD_SET_INPUT_BYTES_IC_BS");
-
-
-          /* Execute process */
-          err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_INIT,
-                                    IA_CMD_TYPE_INIT_CPY_IC_BSF_BUFF, NULL);
-
-          RETURN_IF_FATAL(err_code, "IA_CMD_TYPE_INIT_CPY_IC_BSF_BUFF");
-
-          mDRCFlag = 1;
-        }
-      }
-
-      if (mDRCFlag == 1) {
-        mMpegDDRCPresent = 1;
-      } else {
-        mMpegDDRCPresent = 0;
-      }
-
-
-      /*Read interface buffer config file bitstream*/
-      if(mMpegDDRCPresent==1){
-
-        WORD32 interface_is_present = 1;
-        WORD32 frame_length;
-
-        if(i_sbr_mode != 0)
         {
-            if (i_sbr_mode == 1)
-            {
-                frame_length = 2048;
+            VOID* p_array[2][16];
+            WORD32 ii;
+            WORD32 buf_sizes[2][16];
+            WORD32 num_elements;
+            WORD32 num_config_ext;
+            WORD32 bit_str_fmt = 1;
+
+            WORD32 uo_num_chan;
+
+            memset(buf_sizes, 0, 32 * sizeof(WORD32));
+
+            err_code =
+                ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM,
+                                 IA_ENHAACPLUS_DEC_CONFIG_EXT_ELE_BUF_SIZES, &buf_sizes[0][0]);
+            RETURN_IF_FATAL(err_code, "IA_ENHAACPLUS_DEC_CONFIG_EXT_ELE_BUF_SIZES");
+
+            err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM,
+                                        IA_ENHAACPLUS_DEC_CONFIG_EXT_ELE_PTR, &p_array);
+            RETURN_IF_FATAL(err_code, "IA_ENHAACPLUS_DEC_CONFIG_EXT_ELE_PTR");
+
+            err_code =
+                ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_INIT, IA_CMD_TYPE_INIT_SET_BUFF_PTR, 0);
+            RETURN_IF_FATAL(err_code, "IA_CMD_TYPE_INIT_SET_BUFF_PTR");
+
+            err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM,
+                                        IA_ENHAACPLUS_DEC_CONFIG_NUM_ELE, &num_elements);
+            RETURN_IF_FATAL(err_code, "IA_ENHAACPLUS_DEC_CONFIG_NUM_ELE");
+
+            err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM,
+                                        IA_ENHAACPLUS_DEC_CONFIG_NUM_CONFIG_EXT, &num_config_ext);
+            RETURN_IF_FATAL(err_code, "IA_ENHAACPLUS_DEC_CONFIG_NUM_CONFIG_EXT");
+
+            for (ii = 0; ii < num_config_ext; ii++) {
+                /*copy loudness bitstream*/
+                if (buf_sizes[0][ii] > 0) {
+                    memcpy(mDrcInBuf, p_array[0][ii], buf_sizes[0][ii]);
+
+                    /*Set bitstream_split_format */
+                    err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM,
+                                              IA_DRC_DEC_CONFIG_PARAM_BITS_FORMAT, &bit_str_fmt);
+                    RETURN_IF_FATAL(err_code, "IA_DRC_DEC_CONFIG_PARAM_BITS_FORMAT");
+
+                    /* Set number of bytes to be processed */
+                    err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_INPUT_BYTES_IL_BS, 0,
+                                              &buf_sizes[0][ii]);
+                    RETURN_IF_FATAL(err_code, "IA_API_CMD_SET_INPUT_BYTES_IL_BS");
+
+                    /* Execute process */
+                    err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_INIT,
+                                              IA_CMD_TYPE_INIT_CPY_IL_BSF_BUFF, NULL);
+                    RETURN_IF_FATAL(err_code, "IA_CMD_TYPE_INIT_CPY_IL_BSF_BUFF");
+
+                    mDRCFlag = 1;
+                }
             }
-            else if(i_sbr_mode == 3)
-            {
-                frame_length = 4096;
+
+            for (ii = 0; ii < num_elements; ii++) {
+                /*copy config bitstream*/
+                if (buf_sizes[1][ii] > 0) {
+                    memcpy(mDrcInBuf, p_array[1][ii], buf_sizes[1][ii]);
+                    /* Set number of bytes to be processed */
+
+                    /*Set bitstream_split_format */
+                    err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM,
+                                              IA_DRC_DEC_CONFIG_PARAM_BITS_FORMAT, &bit_str_fmt);
+                    RETURN_IF_FATAL(err_code, "IA_DRC_DEC_CONFIG_PARAM_BITS_FORMAT");
+
+                    err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_INPUT_BYTES_IC_BS, 0,
+                                              &buf_sizes[1][ii]);
+                    RETURN_IF_FATAL(err_code, "IA_API_CMD_SET_INPUT_BYTES_IC_BS");
+
+                    /* Execute process */
+                    err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_INIT,
+                                              IA_CMD_TYPE_INIT_CPY_IC_BSF_BUFF, NULL);
+
+                    RETURN_IF_FATAL(err_code, "IA_CMD_TYPE_INIT_CPY_IC_BSF_BUFF");
+
+                    mDRCFlag = 1;
+                }
             }
-            else
-            {
-                frame_length = 1024;
+
+            if (mDRCFlag == 1) {
+                mMpegDDRCPresent = 1;
+            } else {
+                mMpegDDRCPresent = 0;
+            }
+
+            /*Read interface buffer config file bitstream*/
+            if (mMpegDDRCPresent == 1) {
+                WORD32 interface_is_present = 1;
+                WORD32 frame_length;
+
+                if (i_sbr_mode != 0) {
+                    if (i_sbr_mode == 1) {
+                        frame_length = 2048;
+                    } else if (i_sbr_mode == 3) {
+                        frame_length = 4096;
+                    } else {
+                        frame_length = 1024;
+                    }
+                } else {
+                    frame_length = 4096;
+                }
+
+                err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM,
+                                          IA_DRC_DEC_CONFIG_PARAM_FRAME_SIZE, &frame_length);
+                RETURN_IF_FATAL(err_code, "IA_DRC_DEC_CONFIG_PARAM_FRAME_SIZE");
+
+                err_code =
+                    ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM,
+                                   IA_DRC_DEC_CONFIG_PARAM_INT_PRESENT, &interface_is_present);
+                RETURN_IF_FATAL(err_code, "IA_DRC_DEC_CONFIG_PARAM_INT_PRESENT");
+
+                /* Execute process */
+                err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_INIT,
+                                          IA_CMD_TYPE_INIT_CPY_IN_BSF_BUFF, NULL);
+                RETURN_IF_FATAL(err_code, "IA_CMD_TYPE_INIT_CPY_IN_BSF_BUFF");
+
+                err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_INIT,
+                                          IA_CMD_TYPE_INIT_PROCESS, NULL);
+                RETURN_IF_FATAL(err_code, "IA_CMD_TYPE_INIT_PROCESS");
+
+                err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_GET_CONFIG_PARAM,
+                                          IA_DRC_DEC_CONFIG_PARAM_NUM_CHANNELS, &uo_num_chan);
+                RETURN_IF_FATAL(err_code, "IA_DRC_DEC_CONFIG_PARAM_NUM_CHANNELS");
             }
         }
-        else
-        {
-            frame_length = 4096;
-        }
-
-        err_code =
-            ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM,
-                IA_DRC_DEC_CONFIG_PARAM_FRAME_SIZE, &frame_length);
-        RETURN_IF_FATAL(err_code, "IA_DRC_DEC_CONFIG_PARAM_FRAME_SIZE");
-
-
-
-        err_code = ia_drc_dec_api(
-            mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM,
-            IA_DRC_DEC_CONFIG_PARAM_INT_PRESENT, &interface_is_present);
-        RETURN_IF_FATAL(err_code, "IA_DRC_DEC_CONFIG_PARAM_INT_PRESENT");
-
-
-        /* Execute process */
-        err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_INIT,
-                                  IA_CMD_TYPE_INIT_CPY_IN_BSF_BUFF, NULL);
-        RETURN_IF_FATAL(err_code, "IA_CMD_TYPE_INIT_CPY_IN_BSF_BUFF");
-
-        err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_INIT,
-                                  IA_CMD_TYPE_INIT_PROCESS, NULL);
-        RETURN_IF_FATAL(err_code, "IA_CMD_TYPE_INIT_PROCESS");
-
-        err_code = ia_drc_dec_api(
-            mMpegDDrcHandle, IA_API_CMD_GET_CONFIG_PARAM,
-            IA_DRC_DEC_CONFIG_PARAM_NUM_CHANNELS, &uo_num_chan);
-        RETURN_IF_FATAL(err_code, "IA_DRC_DEC_CONFIG_PARAM_NUM_CHANNELS");
-      }
     }
-  }
 #endif
 
-return err_code;
-
+    return err_code;
 }
-int SoftXAAC::decodeXAACStream(uint8_t* inBuffer,
-                               uint32_t inBufferLength,
-                               int32_t *bytesConsumed,
-                               int32_t *outBytes) {
+int SoftXAAC::decodeXAACStream(uint8_t* inBuffer, uint32_t inBufferLength, int32_t* bytesConsumed,
+                               int32_t* outBytes) {
     if (mInputBufferSize < inBufferLength) {
-        ALOGE("Cannot config AAC, input buffer size %d < inBufferLength %d",mInputBufferSize,inBufferLength);
+        ALOGE("Cannot config AAC, input buffer size %d < inBufferLength %d", mInputBufferSize,
+              inBufferLength);
         return -1;
     }
 
     /* Copy the buffer passed by Android plugin to codec input buffer */
-    memcpy(mInputBuffer,inBuffer,inBufferLength);
+    memcpy(mInputBuffer, inBuffer, inBufferLength);
 
     /* Set number of bytes to be processed */
-    IA_ERRORCODE err_code = ixheaacd_dec_api(mXheaacCodecHandle,
-                                             IA_API_CMD_SET_INPUT_BYTES,
-                                             0,
-                                             &inBufferLength);
+    IA_ERRORCODE err_code =
+        ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_SET_INPUT_BYTES, 0, &inBufferLength);
     RETURN_IF_FATAL(err_code, "IA_API_CMD_SET_INPUT_BYTES");
 
     /* Execute process */
-    err_code = ixheaacd_dec_api(mXheaacCodecHandle,
-                                IA_API_CMD_EXECUTE,
-                                IA_CMD_TYPE_DO_EXECUTE,
-                                NULL);
+    err_code =
+        ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_EXECUTE, IA_CMD_TYPE_DO_EXECUTE, NULL);
     RETURN_IF_FATAL(err_code, "IA_CMD_TYPE_DO_EXECUTE");
 
     UWORD32 ui_exec_done;
     /* Checking for end of processing */
-    err_code = ixheaacd_dec_api(mXheaacCodecHandle,
-                                IA_API_CMD_EXECUTE,
-                                IA_CMD_TYPE_DONE_QUERY,
+    err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_EXECUTE, IA_CMD_TYPE_DONE_QUERY,
                                 &ui_exec_done);
     RETURN_IF_FATAL(err_code, "IA_CMD_TYPE_DONE_QUERY");
 
 #ifdef ENABLE_MPEG_D_DRC
-     {
-      if (ui_exec_done != 1) {
-        VOID *p_array;        // ITTIAM:buffer to handle gain payload
-        WORD32 buf_size = 0;  // ITTIAM:gain payload length
-        WORD32 bit_str_fmt = 1;
-        WORD32 gain_stream_flag = 1;
+    {
+        if (ui_exec_done != 1) {
+            VOID* p_array;        // ITTIAM:buffer to handle gain payload
+            WORD32 buf_size = 0;  // ITTIAM:gain payload length
+            WORD32 bit_str_fmt = 1;
+            WORD32 gain_stream_flag = 1;
 
-        err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM,
-            IA_ENHAACPLUS_DEC_CONFIG_GAIN_PAYLOAD_LEN, &buf_size);
-        RETURN_IF_FATAL(err_code, "IA_ENHAACPLUS_DEC_CONFIG_GAIN_PAYLOAD_LEN");
+            err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM,
+                                        IA_ENHAACPLUS_DEC_CONFIG_GAIN_PAYLOAD_LEN, &buf_size);
+            RETURN_IF_FATAL(err_code, "IA_ENHAACPLUS_DEC_CONFIG_GAIN_PAYLOAD_LEN");
 
+            err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM,
+                                        IA_ENHAACPLUS_DEC_CONFIG_GAIN_PAYLOAD_BUF, &p_array);
+            RETURN_IF_FATAL(err_code, "IA_ENHAACPLUS_DEC_CONFIG_GAIN_PAYLOAD_BUF");
 
-        err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM,
-            IA_ENHAACPLUS_DEC_CONFIG_GAIN_PAYLOAD_BUF, &p_array);
-        RETURN_IF_FATAL(err_code, "IA_ENHAACPLUS_DEC_CONFIG_GAIN_PAYLOAD_BUF");
+            if (buf_size > 0) {
+                /*Set bitstream_split_format */
+                err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM,
+                                          IA_DRC_DEC_CONFIG_PARAM_BITS_FORMAT, &bit_str_fmt);
+                RETURN_IF_FATAL(err_code, "IA_DRC_DEC_CONFIG_PARAM_BITS_FORMAT");
 
+                memcpy(mDrcInBuf, p_array, buf_size);
+                /* Set number of bytes to be processed */
+                err_code =
+                    ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_INPUT_BYTES_BS, 0, &buf_size);
+                RETURN_IF_FATAL(err_code, "IA_DRC_DEC_CONFIG_PARAM_BITS_FORMAT");
 
-        if (buf_size > 0) {
-          /*Set bitstream_split_format */
-          err_code = ia_drc_dec_api(
-              mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM,
-              IA_DRC_DEC_CONFIG_PARAM_BITS_FORMAT, &bit_str_fmt);
-          RETURN_IF_FATAL(err_code, "IA_DRC_DEC_CONFIG_PARAM_BITS_FORMAT");
+                err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM,
+                                          IA_DRC_DEC_CONFIG_GAIN_STREAM_FLAG, &gain_stream_flag);
+                RETURN_IF_FATAL(err_code, "IA_DRC_DEC_CONFIG_PARAM_BITS_FORMAT");
 
-          memcpy(mDrcInBuf, p_array, buf_size);
-          /* Set number of bytes to be processed */
-          err_code =
-              ia_drc_dec_api(mMpegDDrcHandle,
-                             IA_API_CMD_SET_INPUT_BYTES_BS, 0, &buf_size);
-          RETURN_IF_FATAL(err_code, "IA_DRC_DEC_CONFIG_PARAM_BITS_FORMAT");
+                /* Execute process */
+                err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_INIT,
+                                          IA_CMD_TYPE_INIT_CPY_BSF_BUFF, NULL);
+                RETURN_IF_FATAL(err_code, "IA_DRC_DEC_CONFIG_PARAM_BITS_FORMAT");
 
-          err_code = ia_drc_dec_api(
-              mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM,
-              IA_DRC_DEC_CONFIG_GAIN_STREAM_FLAG, &gain_stream_flag);
-          RETURN_IF_FATAL(err_code, "IA_DRC_DEC_CONFIG_PARAM_BITS_FORMAT");
-
-
-          /* Execute process */
-          err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_INIT,
-                                    IA_CMD_TYPE_INIT_CPY_BSF_BUFF, NULL);
-          RETURN_IF_FATAL(err_code, "IA_DRC_DEC_CONFIG_PARAM_BITS_FORMAT");
-
-
-          mMpegDDRCPresent = 1;
+                mMpegDDRCPresent = 1;
+            }
         }
-      }
     }
 #endif
     /* How much buffer is used in input buffers */
-    err_code = ixheaacd_dec_api(mXheaacCodecHandle,
-                                IA_API_CMD_GET_CURIDX_INPUT_BUF,
-                                0,
-                                bytesConsumed);
+    err_code =
+        ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CURIDX_INPUT_BUF, 0, bytesConsumed);
     RETURN_IF_FATAL(err_code, "IA_API_CMD_GET_CURIDX_INPUT_BUF");
 
     /* Get the output bytes */
-    err_code = ixheaacd_dec_api(mXheaacCodecHandle,
-                                IA_API_CMD_GET_OUTPUT_BYTES,
-                                0,
-                                outBytes);
+    err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_OUTPUT_BYTES, 0, outBytes);
     RETURN_IF_FATAL(err_code, "IA_API_CMD_GET_OUTPUT_BYTES");
 #ifdef ENABLE_MPEG_D_DRC
 
     if (mMpegDDRCPresent == 1) {
-      memcpy(mDrcInBuf, mOutputBuffer, *outBytes);
-      err_code = ia_drc_dec_api(mMpegDDrcHandle,
-                                IA_API_CMD_SET_INPUT_BYTES, 0, outBytes);
-      RETURN_IF_FATAL(err_code, "IA_API_CMD_SET_INPUT_BYTES");
+        memcpy(mDrcInBuf, mOutputBuffer, *outBytes);
+        err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_INPUT_BYTES, 0, outBytes);
+        RETURN_IF_FATAL(err_code, "IA_API_CMD_SET_INPUT_BYTES");
 
+        err_code =
+            ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_EXECUTE, IA_CMD_TYPE_DO_EXECUTE, NULL);
+        RETURN_IF_FATAL(err_code, "IA_CMD_TYPE_DO_EXECUTE");
 
-      err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_EXECUTE,
-                                IA_CMD_TYPE_DO_EXECUTE, NULL);
-      RETURN_IF_FATAL(err_code, "IA_CMD_TYPE_DO_EXECUTE");
-
-      memcpy(mOutputBuffer, mDrcOutBuf, *outBytes);
+        memcpy(mOutputBuffer, mDrcOutBuf, *outBytes);
     }
 #endif
     return err_code;
@@ -1715,16 +1520,11 @@
     ALOGI("deInitXAACDecoder");
 
     /* Tell that the input is over in this buffer */
-    IA_ERRORCODE err_code = ixheaacd_dec_api(mXheaacCodecHandle,
-                                             IA_API_CMD_INPUT_OVER,
-                                             0,
-                                             NULL);
+    IA_ERRORCODE err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_INPUT_OVER, 0, NULL);
     RETURN_IF_FATAL(err_code, "IA_API_CMD_INPUT_OVER");
 
-    for(int i = 0; i < mMallocCount; i++)
-    {
-        if(mMemoryArray[i])
-            free(mMemoryArray[i]);
+    for (int i = 0; i < mMallocCount; i++) {
+        if (mMemoryArray[i]) free(mMemoryArray[i]);
     }
     mMallocCount = 0;
 
@@ -1735,59 +1535,47 @@
     IA_ERRORCODE err_code = IA_NO_ERROR;
 
     /* Sampling frequency */
-    err_code = ixheaacd_dec_api(mXheaacCodecHandle,
-                                IA_API_CMD_GET_CONFIG_PARAM,
-                                IA_ENHAACPLUS_DEC_CONFIG_PARAM_SAMP_FREQ,
-                                &mSampFreq);
+    err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM,
+                                IA_ENHAACPLUS_DEC_CONFIG_PARAM_SAMP_FREQ, &mSampFreq);
     RETURN_IF_FATAL(err_code, "IA_ENHAACPLUS_DEC_CONFIG_PARAM_SAMP_FREQ");
 
     /* Total Number of Channels */
-    err_code = ixheaacd_dec_api(mXheaacCodecHandle,
-                                IA_API_CMD_GET_CONFIG_PARAM,
-                                IA_ENHAACPLUS_DEC_CONFIG_PARAM_NUM_CHANNELS,
-                                &mNumChannels);
+    err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM,
+                                IA_ENHAACPLUS_DEC_CONFIG_PARAM_NUM_CHANNELS, &mNumChannels);
     RETURN_IF_FATAL(err_code, "IA_ENHAACPLUS_DEC_CONFIG_PARAM_NUM_CHANNELS");
 
     /* PCM word size */
-    err_code = ixheaacd_dec_api(mXheaacCodecHandle,
-                                IA_API_CMD_GET_CONFIG_PARAM,
-                                IA_ENHAACPLUS_DEC_CONFIG_PARAM_PCM_WDSZ,
-                                &mPcmWdSz);
+    err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM,
+                                IA_ENHAACPLUS_DEC_CONFIG_PARAM_PCM_WDSZ, &mPcmWdSz);
     RETURN_IF_FATAL(err_code, "IA_ENHAACPLUS_DEC_CONFIG_PARAM_PCM_WDSZ");
 
     /* channel mask to tell the arrangement of channels in bit stream */
-    err_code = ixheaacd_dec_api(mXheaacCodecHandle,
-                                IA_API_CMD_GET_CONFIG_PARAM,
-                                IA_ENHAACPLUS_DEC_CONFIG_PARAM_CHANNEL_MASK,
-                                &mChannelMask);
+    err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM,
+                                IA_ENHAACPLUS_DEC_CONFIG_PARAM_CHANNEL_MASK, &mChannelMask);
     RETURN_IF_FATAL(err_code, "IA_ENHAACPLUS_DEC_CONFIG_PARAM_CHANNEL_MASK");
 
     /* Channel mode to tell MONO/STEREO/DUAL-MONO/NONE_OF_THESE */
     UWORD32 ui_channel_mode;
-    err_code = ixheaacd_dec_api(mXheaacCodecHandle,
-                                IA_API_CMD_GET_CONFIG_PARAM,
-                                IA_ENHAACPLUS_DEC_CONFIG_PARAM_CHANNEL_MODE,
-                                &ui_channel_mode);
+    err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM,
+                                IA_ENHAACPLUS_DEC_CONFIG_PARAM_CHANNEL_MODE, &ui_channel_mode);
     RETURN_IF_FATAL(err_code, "IA_ENHAACPLUS_DEC_CONFIG_PARAM_CHANNEL_MODE");
-    if(ui_channel_mode == 0)
+    if (ui_channel_mode == 0)
         ALOGV("Channel Mode: MONO_OR_PS\n");
-    else if(ui_channel_mode == 1)
+    else if (ui_channel_mode == 1)
         ALOGV("Channel Mode: STEREO\n");
-    else if(ui_channel_mode == 2)
+    else if (ui_channel_mode == 2)
         ALOGV("Channel Mode: DUAL-MONO\n");
     else
         ALOGV("Channel Mode: NONE_OF_THESE or MULTICHANNEL\n");
 
     /* Channel mode to tell SBR PRESENT/NOT_PRESENT */
     UWORD32 ui_sbr_mode;
-    err_code = ixheaacd_dec_api(mXheaacCodecHandle,
-                                IA_API_CMD_GET_CONFIG_PARAM,
-                                IA_ENHAACPLUS_DEC_CONFIG_PARAM_SBR_MODE,
-                                &ui_sbr_mode);
+    err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM,
+                                IA_ENHAACPLUS_DEC_CONFIG_PARAM_SBR_MODE, &ui_sbr_mode);
     RETURN_IF_FATAL(err_code, "IA_ENHAACPLUS_DEC_CONFIG_PARAM_SBR_MODE");
-    if(ui_sbr_mode == 0)
+    if (ui_sbr_mode == 0)
         ALOGV("SBR Mode: NOT_PRESENT\n");
-    else if(ui_sbr_mode == 1)
+    else if (ui_sbr_mode == 1)
         ALOGV("SBR Mode: PRESENT\n");
     else
         ALOGV("SBR Mode: ILLEGAL\n");
@@ -1797,132 +1585,103 @@
     /* not yet added in codec                            */
     mOutputFrameLength = 1024 * (1 + ui_sbr_mode);
 
-    ALOGI("mOutputFrameLength %d ui_sbr_mode %d",mOutputFrameLength,ui_sbr_mode);
+    ALOGI("mOutputFrameLength %d ui_sbr_mode %d", mOutputFrameLength, ui_sbr_mode);
 
     return IA_NO_ERROR;
 }
 
-IA_ERRORCODE SoftXAAC::setXAACDRCInfo(int32_t drcCut,
-                                      int32_t drcBoost,
-                                      int32_t drcRefLevel,
+IA_ERRORCODE SoftXAAC::setXAACDRCInfo(int32_t drcCut, int32_t drcBoost, int32_t drcRefLevel,
                                       int32_t drcHeavyCompression
-                                #ifdef ENABLE_MPEG_D_DRC
-                                      ,int32_t drEffectType
-                                #endif
-                                      ) {
+#ifdef ENABLE_MPEG_D_DRC
+                                      ,
+                                      int32_t drEffectType
+#endif
+) {
     IA_ERRORCODE err_code = IA_NO_ERROR;
 
     int32_t ui_drc_enable = 1;
     int32_t i_effect_type, i_target_loudness, i_loud_norm;
-    err_code = ixheaacd_dec_api(mXheaacCodecHandle,
-                                IA_API_CMD_SET_CONFIG_PARAM,
-                                IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_ENABLE,
-                                &ui_drc_enable);
-     RETURN_IF_FATAL(err_code, "IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_ENABLE");
-    if (drcCut !=-1) {
-        err_code = ixheaacd_dec_api(mXheaacCodecHandle,
-                                    IA_API_CMD_SET_CONFIG_PARAM,
-                                    IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_CUT,
-                                    &drcCut);
+    err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_SET_CONFIG_PARAM,
+                                IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_ENABLE, &ui_drc_enable);
+    RETURN_IF_FATAL(err_code, "IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_ENABLE");
+    if (drcCut != -1) {
+        err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_SET_CONFIG_PARAM,
+                                    IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_CUT, &drcCut);
         RETURN_IF_FATAL(err_code, "IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_CUT");
     }
 
-    if (drcBoost !=-1) {
-        err_code = ixheaacd_dec_api(mXheaacCodecHandle,
-                                    IA_API_CMD_SET_CONFIG_PARAM,
-                                    IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_BOOST,
-                                    &drcBoost);
+    if (drcBoost != -1) {
+        err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_SET_CONFIG_PARAM,
+                                    IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_BOOST, &drcBoost);
         RETURN_IF_FATAL(err_code, "IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_BOOST");
     }
 
     if (drcRefLevel != -1) {
-        err_code = ixheaacd_dec_api(mXheaacCodecHandle,
-                                    IA_API_CMD_SET_CONFIG_PARAM,
-                                    IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_TARGET_LEVEL,
-                                    &drcRefLevel);
+        err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_SET_CONFIG_PARAM,
+                                    IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_TARGET_LEVEL, &drcRefLevel);
         RETURN_IF_FATAL(err_code, "IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_TARGET_LEVEL");
     }
 #ifdef ENABLE_MPEG_D_DRC
     if (drcRefLevel != -1) {
-        err_code = ixheaacd_dec_api(mXheaacCodecHandle,
-                                    IA_API_CMD_SET_CONFIG_PARAM,
-                                    IA_ENHAACPLUS_DEC_DRC_TARGET_LOUDNESS,
-                                    &drcRefLevel);
+        err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_SET_CONFIG_PARAM,
+                                    IA_ENHAACPLUS_DEC_DRC_TARGET_LOUDNESS, &drcRefLevel);
         RETURN_IF_FATAL(err_code, "IA_ENHAACPLUS_DEC_DRC_TARGET_LOUDNESS");
     }
 #endif
     if (drcHeavyCompression != -1) {
-        err_code = ixheaacd_dec_api(mXheaacCodecHandle,
-                                    IA_API_CMD_SET_CONFIG_PARAM,
-                                    IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_HEAVY_COMP,
-                                    &drcHeavyCompression);
+        err_code =
+            ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_SET_CONFIG_PARAM,
+                             IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_HEAVY_COMP, &drcHeavyCompression);
         RETURN_IF_FATAL(err_code, "IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_HEAVY_COMP");
     }
 
 #ifdef ENABLE_MPEG_D_DRC
-        err_code = ixheaacd_dec_api(mXheaacCodecHandle,
-                                    IA_API_CMD_SET_CONFIG_PARAM,
-                                    IA_ENHAACPLUS_DEC_DRC_EFFECT_TYPE,
-                                    &drEffectType);
-        RETURN_IF_FATAL(err_code, "IA_ENHAACPLUS_DEC_DRC_EFFECT_TYPE");
+    err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_SET_CONFIG_PARAM,
+                                IA_ENHAACPLUS_DEC_DRC_EFFECT_TYPE, &drEffectType);
+    RETURN_IF_FATAL(err_code, "IA_ENHAACPLUS_DEC_DRC_EFFECT_TYPE");
 #endif
 
 #ifdef ENABLE_MPEG_D_DRC
     /*Set Effect Type*/
+    err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM,
+                                IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_EFFECT_TYPE, &i_effect_type);
+    RETURN_IF_FATAL(err_code, "IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_EFFECT_TYPE");
 
-    {
-        err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM,
-            IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_EFFECT_TYPE, &i_effect_type);
-        RETURN_IF_FATAL(err_code, "IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_EFFECT_TYPE");
+    err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM,
+                              IA_DRC_DEC_CONFIG_DRC_EFFECT_TYPE, &i_effect_type);
 
-        err_code =
-            ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM,
-                IA_DRC_DEC_CONFIG_DRC_EFFECT_TYPE, &i_effect_type);
+    RETURN_IF_FATAL(err_code, "IA_DRC_DEC_CONFIG_DRC_EFFECT_TYPE");
 
-        RETURN_IF_FATAL(err_code, "IA_DRC_DEC_CONFIG_DRC_EFFECT_TYPE");
+    /*Set target loudness */
+    err_code =
+        ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM,
+                         IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_TARGET_LOUDNESS, &i_target_loudness);
+    RETURN_IF_FATAL(err_code, "IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_TARGET_LOUDNESS");
 
-    }
+    err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM,
+                              IA_DRC_DEC_CONFIG_DRC_TARGET_LOUDNESS, &i_target_loudness);
+    RETURN_IF_FATAL(err_code, "IA_DRC_DEC_CONFIG_DRC_TARGET_LOUDNESS");
 
-/*Set target loudness */
-
-    {
-        err_code = ixheaacd_dec_api(
-            mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM,
-            IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_TARGET_LOUDNESS, &i_target_loudness);
-        RETURN_IF_FATAL(err_code, "IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_TARGET_LOUDNESS");
-
-        err_code =
-            ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM,
-                IA_DRC_DEC_CONFIG_DRC_TARGET_LOUDNESS, &i_target_loudness);
-        RETURN_IF_FATAL(err_code, "IA_DRC_DEC_CONFIG_DRC_TARGET_LOUDNESS");
-
-    }
     /*Set loud_norm_flag*/
-    {
-        err_code = ixheaacd_dec_api(
-            mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM,
-            IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_LOUD_NORM, &i_loud_norm);
-        RETURN_IF_FATAL(err_code,"IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_LOUD_NORM");
+    err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM,
+                                IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_LOUD_NORM, &i_loud_norm);
+    RETURN_IF_FATAL(err_code, "IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_LOUD_NORM");
 
-        err_code =
-            ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM,
-                IA_DRC_DEC_CONFIG_DRC_LOUD_NORM, &i_loud_norm);
+    err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM,
+                              IA_DRC_DEC_CONFIG_DRC_LOUD_NORM, &i_loud_norm);
 
-        RETURN_IF_FATAL(err_code,"IA_DRC_DEC_CONFIG_DRC_LOUD_NORM");
-
-    }
+    RETURN_IF_FATAL(err_code, "IA_DRC_DEC_CONFIG_DRC_LOUD_NORM");
 
 #endif
 
-
     return IA_NO_ERROR;
 }
 
 }  // namespace android
 
-android::SoftOMXComponent *createSoftOMXComponent(
-        const char *name, const OMX_CALLBACKTYPE *callbacks,
-        OMX_PTR appData, OMX_COMPONENTTYPE **component) {
+android::SoftOMXComponent* createSoftOMXComponent(const char* name,
+                                                  const OMX_CALLBACKTYPE* callbacks,
+                                                  OMX_PTR appData, OMX_COMPONENTTYPE** component) {
     ALOGI("createSoftOMXComponent for SoftXAACDEC");
     return new android::SoftXAAC(name, callbacks, appData, component);
 }
diff --git a/media/libstagefright/codecs/xaacdec/SoftXAAC.h b/media/libstagefright/codecs/xaacdec/SoftXAAC.h
index 0b3a612..6176082 100644
--- a/media/libstagefright/codecs/xaacdec/SoftXAAC.h
+++ b/media/libstagefright/codecs/xaacdec/SoftXAAC.h
@@ -35,59 +35,49 @@
 
 #define MAX_MEM_ALLOCS 100
 
-extern "C" IA_ERRORCODE ixheaacd_dec_api(pVOID p_ia_module_obj,
-                        WORD32 i_cmd, WORD32 i_idx, pVOID pv_value);
-extern "C" IA_ERRORCODE ia_drc_dec_api(pVOID p_ia_module_obj,
-                        WORD32 i_cmd, WORD32 i_idx, pVOID pv_value);
-extern "C"  IA_ERRORCODE ixheaacd_get_config_param(pVOID p_ia_process_api_obj,
-                                       pWORD32 pi_samp_freq,
-                                       pWORD32 pi_num_chan,
-                                       pWORD32 pi_pcm_wd_sz,
-                                       pWORD32 pi_channel_mask);
+extern "C" IA_ERRORCODE ixheaacd_dec_api(pVOID p_ia_module_obj, WORD32 i_cmd, WORD32 i_idx,
+                                         pVOID pv_value);
+extern "C" IA_ERRORCODE ia_drc_dec_api(pVOID p_ia_module_obj, WORD32 i_cmd, WORD32 i_idx,
+                                       pVOID pv_value);
+extern "C" IA_ERRORCODE ixheaacd_get_config_param(pVOID p_ia_process_api_obj, pWORD32 pi_samp_freq,
+                                                  pWORD32 pi_num_chan, pWORD32 pi_pcm_wd_sz,
+                                                  pWORD32 pi_channel_mask);
 
 namespace android {
 
 struct SoftXAAC : public SimpleSoftOMXComponent {
-    SoftXAAC(const char *name,
-            const OMX_CALLBACKTYPE *callbacks,
-            OMX_PTR appData,
-            OMX_COMPONENTTYPE **component);
+    SoftXAAC(const char* name, const OMX_CALLBACKTYPE* callbacks, OMX_PTR appData,
+             OMX_COMPONENTTYPE** component);
 
-protected:
+   protected:
     virtual ~SoftXAAC();
 
-    virtual OMX_ERRORTYPE internalGetParameter(
-            OMX_INDEXTYPE index, OMX_PTR params);
+    virtual OMX_ERRORTYPE internalGetParameter(OMX_INDEXTYPE index, OMX_PTR params);
 
-    virtual OMX_ERRORTYPE internalSetParameter(
-            OMX_INDEXTYPE index, const OMX_PTR params);
+    virtual OMX_ERRORTYPE internalSetParameter(OMX_INDEXTYPE index, const OMX_PTR params);
 
     virtual void onQueueFilled(OMX_U32 portIndex);
     virtual void onPortFlushCompleted(OMX_U32 portIndex);
     virtual void onPortEnableCompleted(OMX_U32 portIndex, bool enabled);
     virtual void onReset();
 
-private:
+   private:
     enum {
-        kNumInputBuffers        = 4,
-        kNumOutputBuffers       = 4,
-        kNumDelayBlocksMax      = 8,
+        kNumInputBuffers = 4,
+        kNumOutputBuffers = 4,
+        kNumDelayBlocksMax = 8,
     };
 
     bool mIsADTS;
     size_t mInputBufferCount;
     size_t mOutputBufferCount;
     bool mSignalledError;
-    OMX_BUFFERHEADERTYPE *mLastInHeader;
+    OMX_BUFFERHEADERTYPE* mLastInHeader;
     int64_t mPrevTimestamp;
     int64_t mCurrentTimestamp;
     uint32_t mBufSize;
 
-    enum {
-        NONE,
-        AWAITING_DISABLED,
-        AWAITING_ENABLED
-    } mOutputPortSettingsChange;
+    enum { NONE, AWAITING_DISABLED, AWAITING_ENABLED } mOutputPortSettingsChange;
 
     void initPorts();
     status_t initDecoder();
@@ -98,48 +88,43 @@
 
     int configXAACDecoder(uint8_t* inBuffer, uint32_t inBufferLength);
     int configMPEGDDrc();
-    int decodeXAACStream(uint8_t* inBuffer,
-                         uint32_t inBufferLength,
-                         int32_t *bytesConsumed,
-                         int32_t *outBytes);
+    int decodeXAACStream(uint8_t* inBuffer, uint32_t inBufferLength, int32_t* bytesConsumed,
+                         int32_t* outBytes);
 
     int configflushDecode();
     IA_ERRORCODE getXAACStreamInfo();
-    IA_ERRORCODE setXAACDRCInfo(int32_t drcCut,
-                                int32_t drcBoost,
-                                int32_t drcRefLevel,
+    IA_ERRORCODE setXAACDRCInfo(int32_t drcCut, int32_t drcBoost, int32_t drcRefLevel,
                                 int32_t drcHeavyCompression
 #ifdef ENABLE_MPEG_D_DRC
-                                ,int32_t drEffectType
+                                ,
+                                int32_t drEffectType
 #endif
-                               );
+    );
 
     bool mEndOfInput;
     bool mEndOfOutput;
 
-    void*       mXheaacCodecHandle;
-    void*       mMpegDDrcHandle;
-    uint32_t    mInputBufferSize;
-    uint32_t    mOutputFrameLength;
-    int8_t*     mInputBuffer;
-    int8_t*     mOutputBuffer;
-    int32_t     mSampFreq;
-    int32_t     mNumChannels;
-    int32_t     mPcmWdSz;
-    int32_t     mChannelMask;
-    bool        mIsCodecInitialized;
-    bool        mIsCodecConfigFlushRequired;
-    int8_t *mDrcInBuf;
-    int8_t *mDrcOutBuf;
+    void* mXheaacCodecHandle;
+    void* mMpegDDrcHandle;
+    uint32_t mInputBufferSize;
+    uint32_t mOutputFrameLength;
+    int8_t* mInputBuffer;
+    int8_t* mOutputBuffer;
+    int32_t mSampFreq;
+    int32_t mNumChannels;
+    int32_t mPcmWdSz;
+    int32_t mChannelMask;
+    bool mIsCodecInitialized;
+    bool mIsCodecConfigFlushRequired;
+    int8_t* mDrcInBuf;
+    int8_t* mDrcOutBuf;
     int32_t mMpegDDRCPresent;
     int32_t mDRCFlag;
 
-
-    void*       mMemoryArray[MAX_MEM_ALLOCS];
-    int32_t     mMallocCount;
+    void* mMemoryArray[MAX_MEM_ALLOCS];
+    int32_t mMallocCount;
 
     DISALLOW_EVIL_CONSTRUCTORS(SoftXAAC);
-
 };
 
 }  // namespace android
diff --git a/media/libstagefright/httplive/M3UParser.cpp b/media/libstagefright/httplive/M3UParser.cpp
index 52791b9..8ab33f7 100644
--- a/media/libstagefright/httplive/M3UParser.cpp
+++ b/media/libstagefright/httplive/M3UParser.cpp
@@ -234,7 +234,11 @@
         if (mSelectedIndex >= 0 && i == (size_t)mSelectedIndex) {
             const Media &item = mMediaItems.itemAt(i);
 
-            *uri = item.makeURL(baseURL);
+            if (item.mURI.empty()) {
+                *uri = "";
+            } else {
+                *uri = item.makeURL(baseURL);
+            }
             return true;
         }
     }
@@ -465,7 +469,7 @@
         }
 
         if ((*uri).empty()) {
-            *uri = mItems.itemAt(index).mURI;
+            *uri = mItems.itemAt(index).makeURL(mBaseURI.c_str());
         }
     }
 
diff --git a/media/libstagefright/include/media/stagefright/MediaCodec.h b/media/libstagefright/include/media/stagefright/MediaCodec.h
index ad02004..7f6aae6 100644
--- a/media/libstagefright/include/media/stagefright/MediaCodec.h
+++ b/media/libstagefright/include/media/stagefright/MediaCodec.h
@@ -377,7 +377,7 @@
 
     MediaCodec(const sp<ALooper> &looper, pid_t pid, uid_t uid);
 
-    static sp<CodecBase> GetCodecBase(const AString &name);
+    static sp<CodecBase> GetCodecBase(const AString &name, const char *owner = nullptr);
 
     static status_t PostAndAwaitResponse(
             const sp<AMessage> &msg, sp<AMessage> *response);
diff --git a/media/libstagefright/omx/OMXNodeInstance.cpp b/media/libstagefright/omx/OMXNodeInstance.cpp
index 535e084..68b375a 100644
--- a/media/libstagefright/omx/OMXNodeInstance.cpp
+++ b/media/libstagefright/omx/OMXNodeInstance.cpp
@@ -1121,7 +1121,8 @@
         }
 
         case OMXBuffer::kBufferTypeANWBuffer: {
-            if (mPortMode[portIndex] != IOMX::kPortModePresetANWBuffer) {
+            if (mPortMode[portIndex] != IOMX::kPortModePresetANWBuffer
+                    && mPortMode[portIndex] != IOMX::kPortModeDynamicANWBuffer) {
                 break;
             }
             return useGraphicBuffer_l(portIndex, omxBuffer.mGraphicBuffer, buffer);
@@ -1655,12 +1656,15 @@
     }
     BufferMeta *buffer_meta = static_cast<BufferMeta *>(header->pAppPrivate);
 
+    // Invalidate buffers in the client side first before calling OMX_FreeBuffer.
+    // If not, pending events in the client side might access the buffers after free.
+    invalidateBufferID(buffer);
+
     OMX_ERRORTYPE err = OMX_FreeBuffer(mHandle, portIndex, header);
     CLOG_IF_ERROR(freeBuffer, err, "%s:%u %#x", portString(portIndex), portIndex, buffer);
 
     delete buffer_meta;
     buffer_meta = NULL;
-    invalidateBufferID(buffer);
 
     return StatusFromOMXError(err);
 }
diff --git a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
index 91f30c6..8e1c237 100644
--- a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
+++ b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
@@ -4877,11 +4877,15 @@
     //      use device for strategy DTMF
     // 9: the strategy for beacon, a.k.a. "transmitted through speaker" is active on the output:
     //      use device for strategy t-t-s
+
+    // FIXME: extend use of isStrategyActiveOnSameModule() to all strategies
+    // with a refined rule considering mutually exclusive devices (using same backend)
+    // as opposed to all streams on the same audio HAL module.
     if (isStrategyActive(outputDesc, STRATEGY_ENFORCED_AUDIBLE) &&
         mEngine->getForceUse(AUDIO_POLICY_FORCE_FOR_SYSTEM) == AUDIO_POLICY_FORCE_SYSTEM_ENFORCED) {
         device = getDeviceForStrategy(STRATEGY_ENFORCED_AUDIBLE, fromCache);
     } else if (isInCall() ||
-                    isStrategyActive(outputDesc, STRATEGY_PHONE)) {
+               isStrategyActiveOnSameModule(outputDesc, STRATEGY_PHONE)) {
         device = getDeviceForStrategy(STRATEGY_PHONE, fromCache);
     } else if (isStrategyActive(outputDesc, STRATEGY_SONIFICATION)) {
         device = getDeviceForStrategy(STRATEGY_SONIFICATION, fromCache);
@@ -5889,6 +5893,20 @@
     return false;
 }
 
+bool AudioPolicyManager::isStrategyActiveOnSameModule(const sp<AudioOutputDescriptor>& outputDesc,
+                                          routing_strategy strategy, uint32_t inPastMs,
+                                          nsecs_t sysTime) const
+{
+    for (size_t i = 0; i < mOutputs.size(); i++) {
+        sp<SwAudioOutputDescriptor> desc = mOutputs.valueAt(i);
+        if (outputDesc->sharesHwModuleWith(desc)
+            && isStrategyActive(desc, strategy, inPastMs, sysTime)) {
+            return true;
+        }
+    }
+    return false;
+}
+
 audio_policy_forced_cfg_t AudioPolicyManager::getForceUse(audio_policy_force_use_t usage)
 {
     return mEngine->getForceUse(usage);
diff --git a/services/audiopolicy/managerdefault/AudioPolicyManager.h b/services/audiopolicy/managerdefault/AudioPolicyManager.h
index b954714..48e0472 100644
--- a/services/audiopolicy/managerdefault/AudioPolicyManager.h
+++ b/services/audiopolicy/managerdefault/AudioPolicyManager.h
@@ -321,6 +321,10 @@
         bool isStrategyActive(const sp<AudioOutputDescriptor>& outputDesc, routing_strategy strategy,
                               uint32_t inPastMs = 0, nsecs_t sysTime = 0) const;
 
+        bool isStrategyActiveOnSameModule(const sp<AudioOutputDescriptor>& outputDesc,
+                                                  routing_strategy strategy, uint32_t inPastMs = 0,
+                                                  nsecs_t sysTime = 0) const;
+
         // change the route of the specified output. Returns the number of ms we have slept to
         // allow new routing to take effect in certain cases.
         virtual uint32_t setOutputDevice(const sp<AudioOutputDescriptor>& outputDesc,
diff --git a/services/camera/libcameraservice/api1/Camera2Client.cpp b/services/camera/libcameraservice/api1/Camera2Client.cpp
index 30c0bab..8bb24d4 100644
--- a/services/camera/libcameraservice/api1/Camera2Client.cpp
+++ b/services/camera/libcameraservice/api1/Camera2Client.cpp
@@ -106,7 +106,7 @@
     {
         SharedParameters::Lock l(mParameters);
 
-        res = l.mParameters.initialize(&(mDevice->info()), mDeviceVersion);
+        res = l.mParameters.initialize(mDevice.get(), mDeviceVersion);
         if (res != OK) {
             ALOGE("%s: Camera %d: unable to build defaults: %s (%d)",
                     __FUNCTION__, mCameraId, strerror(-res), res);
@@ -254,6 +254,7 @@
     switch (p.sceneMode) {
         case ANDROID_CONTROL_SCENE_MODE_DISABLED:
             result.append("AUTO\n"); break;
+        CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_FACE_PRIORITY)
         CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_ACTION)
         CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_PORTRAIT)
         CASE_APPEND_ENUM(ANDROID_CONTROL_SCENE_MODE_LANDSCAPE)
diff --git a/services/camera/libcameraservice/api1/client2/Parameters.cpp b/services/camera/libcameraservice/api1/client2/Parameters.cpp
index d66dec4..28d186a 100644
--- a/services/camera/libcameraservice/api1/client2/Parameters.cpp
+++ b/services/camera/libcameraservice/api1/client2/Parameters.cpp
@@ -41,23 +41,29 @@
         int cameraFacing) :
         cameraId(cameraId),
         cameraFacing(cameraFacing),
-        info(NULL) {
+        info(NULL),
+        mDefaultSceneMode(ANDROID_CONTROL_SCENE_MODE_DISABLED) {
 }
 
 Parameters::~Parameters() {
 }
 
-status_t Parameters::initialize(const CameraMetadata *info, int deviceVersion) {
+status_t Parameters::initialize(CameraDeviceBase *device, int deviceVersion) {
     status_t res;
+    if (device == nullptr) {
+        ALOGE("%s: device is null!", __FUNCTION__);
+        return BAD_VALUE;
+    }
 
-    if (info->entryCount() == 0) {
+    const CameraMetadata& info = device->info();
+    if (info.entryCount() == 0) {
         ALOGE("%s: No static information provided!", __FUNCTION__);
         return BAD_VALUE;
     }
-    Parameters::info = info;
+    Parameters::info = &info;
     mDeviceVersion = deviceVersion;
 
-    res = buildFastInfo();
+    res = buildFastInfo(device);
     if (res != OK) return res;
 
     res = buildQuirks();
@@ -557,6 +563,10 @@
                     noSceneModes = true;
                     break;
                 case ANDROID_CONTROL_SCENE_MODE_FACE_PRIORITY:
+                    // Face priority can be used as alternate default if supported.
+                    // Per API contract it shouldn't override the user set flash,
+                    // white balance and focus modes.
+                    mDefaultSceneMode = availableSceneModes.data.u8[i];
                     // Not in old API
                     addComma = false;
                     break;
@@ -761,17 +771,7 @@
     focusingAreas.clear();
     focusingAreas.add(Parameters::Area(0,0,0,0,0));
 
-    if (fastInfo.isExternalCamera) {
-        params.setFloat(CameraParameters::KEY_FOCAL_LENGTH, -1.0);
-    } else {
-        camera_metadata_ro_entry_t availableFocalLengths =
-            staticInfo(ANDROID_LENS_INFO_AVAILABLE_FOCAL_LENGTHS, 0, 0, false);
-        if (!availableFocalLengths.count) return NO_INIT;
-
-        float minFocalLength = availableFocalLengths.data.f[0];
-        params.setFloat(CameraParameters::KEY_FOCAL_LENGTH, minFocalLength);
-    }
-
+    params.setFloat(CameraParameters::KEY_FOCAL_LENGTH, fastInfo.defaultFocalLength);
 
     float horizFov, vertFov;
     res = calculatePictureFovs(&horizFov, &vertFov);
@@ -993,7 +993,7 @@
     return paramsFlattened;
 }
 
-status_t Parameters::buildFastInfo() {
+status_t Parameters::buildFastInfo(CameraDeviceBase *device) {
 
     camera_metadata_ro_entry_t activeArraySize =
         staticInfo(ANDROID_SENSOR_INFO_ACTIVE_ARRAY_SIZE, 2, 4);
@@ -1109,20 +1109,12 @@
             focusDistanceCalibration.data.u8[0] !=
             ANDROID_LENS_INFO_FOCUS_DISTANCE_CALIBRATION_UNCALIBRATED);
 
-
-    camera_metadata_ro_entry_t hwLevel = staticInfo(ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL);
-    if (!hwLevel.count) return NO_INIT;
-    fastInfo.isExternalCamera =
-            hwLevel.data.u8[0] == ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL_EXTERNAL;
-
-    camera_metadata_ro_entry_t availableFocalLengths =
-        staticInfo(ANDROID_LENS_INFO_AVAILABLE_FOCAL_LENGTHS, 0, 0, /*required*/false);
-    if (!availableFocalLengths.count && !fastInfo.isExternalCamera) return NO_INIT;
+    res = getDefaultFocalLength(device);
+    if (res != OK) return res;
 
     SortedVector<int32_t> availableFormats = getAvailableOutputFormats();
     if (!availableFormats.size()) return NO_INIT;
 
-
     if (sceneModeOverrides.count > 0) {
         // sceneModeOverrides is defined to have 3 entries for each scene mode,
         // which are AE, AWB, and AF override modes the HAL wants for that scene
@@ -1200,19 +1192,6 @@
     fastInfo.bestFaceDetectMode = bestFaceDetectMode;
     fastInfo.maxFaces = maxFaces;
 
-    // Find smallest (widest-angle) focal length to use as basis of still
-    // picture FOV reporting.
-    if (fastInfo.isExternalCamera) {
-        fastInfo.minFocalLength = -1.0;
-    } else {
-        fastInfo.minFocalLength = availableFocalLengths.data.f[0];
-        for (size_t i = 1; i < availableFocalLengths.count; i++) {
-            if (fastInfo.minFocalLength > availableFocalLengths.data.f[i]) {
-                fastInfo.minFocalLength = availableFocalLengths.data.f[i];
-            }
-        }
-    }
-
     // Check if the HAL supports HAL_PIXEL_FORMAT_YCbCr_420_888
     fastInfo.useFlexibleYuv = false;
     for (size_t i = 0; i < availableFormats.size(); i++) {
@@ -1760,7 +1739,7 @@
 
     // SCENE_MODE
     validatedParams.sceneMode = sceneModeStringToEnum(
-        newParams.get(CameraParameters::KEY_SCENE_MODE) );
+        newParams.get(CameraParameters::KEY_SCENE_MODE), mDefaultSceneMode);
     if (validatedParams.sceneMode != sceneMode &&
             validatedParams.sceneMode !=
             ANDROID_CONTROL_SCENE_MODE_DISABLED) {
@@ -1778,7 +1757,7 @@
         }
     }
     bool sceneModeSet =
-            validatedParams.sceneMode != ANDROID_CONTROL_SCENE_MODE_DISABLED;
+            validatedParams.sceneMode != mDefaultSceneMode;
 
     // FLASH_MODE
     if (sceneModeSet) {
@@ -2157,7 +2136,7 @@
     uint8_t reqSceneMode =
             sceneModeActive ? sceneMode :
             enableFaceDetect ? (uint8_t)ANDROID_CONTROL_SCENE_MODE_FACE_PRIORITY :
-            (uint8_t)ANDROID_CONTROL_SCENE_MODE_DISABLED;
+            mDefaultSceneMode;
     res = request->update(ANDROID_CONTROL_SCENE_MODE,
             &reqSceneMode, 1);
     if (res != OK) return res;
@@ -2446,6 +2425,50 @@
     return true;
 }
 
+status_t Parameters::getDefaultFocalLength(CameraDeviceBase *device) {
+    if (device == nullptr) {
+        ALOGE("%s: Camera device is nullptr", __FUNCTION__);
+        return BAD_VALUE;
+    }
+
+    camera_metadata_ro_entry_t hwLevel = staticInfo(ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL);
+    if (!hwLevel.count) return NO_INIT;
+    fastInfo.isExternalCamera =
+            hwLevel.data.u8[0] == ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL_EXTERNAL;
+
+    camera_metadata_ro_entry_t availableFocalLengths =
+        staticInfo(ANDROID_LENS_INFO_AVAILABLE_FOCAL_LENGTHS, 0, 0, /*required*/false);
+    if (!availableFocalLengths.count && !fastInfo.isExternalCamera) return NO_INIT;
+
+    // Find focal length in PREVIEW template to use as default focal length.
+    if (fastInfo.isExternalCamera) {
+        fastInfo.defaultFocalLength = -1.0;
+    } else {
+        // Find smallest (widest-angle) focal length to use as basis of still
+        // picture FOV reporting.
+        fastInfo.defaultFocalLength = availableFocalLengths.data.f[0];
+        for (size_t i = 1; i < availableFocalLengths.count; i++) {
+            if (fastInfo.defaultFocalLength > availableFocalLengths.data.f[i]) {
+                fastInfo.defaultFocalLength = availableFocalLengths.data.f[i];
+            }
+        }
+
+        // Use focal length in preview template if it exists
+        CameraMetadata previewTemplate;
+        status_t res = device->createDefaultRequest(CAMERA3_TEMPLATE_PREVIEW, &previewTemplate);
+        if (res != OK) {
+            ALOGE("%s: Failed to create default PREVIEW request: %s (%d)",
+                    __FUNCTION__, strerror(-res), res);
+            return res;
+        }
+        camera_metadata_entry entry = previewTemplate.find(ANDROID_LENS_FOCAL_LENGTH);
+        if (entry.count != 0) {
+            fastInfo.defaultFocalLength = entry.data.f[0];
+        }
+    }
+    return OK;
+}
+
 const char* Parameters::getStateName(State state) {
 #define CASE_ENUM_TO_CHAR(x) case x: return(#x); break;
     switch(state) {
@@ -2589,12 +2612,12 @@
         -1;
 }
 
-int Parameters::sceneModeStringToEnum(const char *sceneMode) {
+int Parameters::sceneModeStringToEnum(const char *sceneMode, uint8_t defaultSceneMode) {
     return
         !sceneMode ?
-            ANDROID_CONTROL_SCENE_MODE_DISABLED :
+            defaultSceneMode :
         !strcmp(sceneMode, CameraParameters::SCENE_MODE_AUTO) ?
-            ANDROID_CONTROL_SCENE_MODE_DISABLED :
+            defaultSceneMode :
         !strcmp(sceneMode, CameraParameters::SCENE_MODE_ACTION) ?
             ANDROID_CONTROL_SCENE_MODE_ACTION :
         !strcmp(sceneMode, CameraParameters::SCENE_MODE_PORTRAIT) ?
@@ -3241,12 +3264,12 @@
     if (horizFov != NULL) {
         *horizFov = 180 / M_PI * 2 *
                 atanf(horizCropFactor * sensorSize.data.f[0] /
-                        (2 * fastInfo.minFocalLength));
+                        (2 * fastInfo.defaultFocalLength));
     }
     if (vertFov != NULL) {
         *vertFov = 180 / M_PI * 2 *
                 atanf(vertCropFactor * sensorSize.data.f[1] /
-                        (2 * fastInfo.minFocalLength));
+                        (2 * fastInfo.defaultFocalLength));
     }
     return OK;
 }
diff --git a/services/camera/libcameraservice/api1/client2/Parameters.h b/services/camera/libcameraservice/api1/client2/Parameters.h
index 97f8ea7..42e7a47 100644
--- a/services/camera/libcameraservice/api1/client2/Parameters.h
+++ b/services/camera/libcameraservice/api1/client2/Parameters.h
@@ -30,6 +30,8 @@
 #include <camera/CameraParameters2.h>
 #include <camera/CameraMetadata.h>
 
+#include "common/CameraDeviceBase.h"
+
 namespace android {
 namespace camera2 {
 
@@ -241,7 +243,7 @@
         };
         DefaultKeyedVector<uint8_t, OverrideModes> sceneModeOverrides;
         bool isExternalCamera;
-        float minFocalLength;
+        float defaultFocalLength;
         bool useFlexibleYuv;
         Size maxJpegSize;
         Size maxZslSize;
@@ -264,10 +266,10 @@
     ~Parameters();
 
     // Sets up default parameters
-    status_t initialize(const CameraMetadata *info, int deviceVersion);
+    status_t initialize(CameraDeviceBase *device, int deviceVersion);
 
     // Build fast-access device static info from static info
-    status_t buildFastInfo();
+    status_t buildFastInfo(CameraDeviceBase *device);
     // Query for quirks from static info
     status_t buildQuirks();
 
@@ -300,6 +302,9 @@
     // whether zero shutter lag should be used for non-recording operation
     bool useZeroShutterLag() const;
 
+    // Get default focal length
+    status_t getDefaultFocalLength(CameraDeviceBase *camera);
+
     // Calculate the crop region rectangle, either tightly about the preview
     // resolution, or a region just based on the active array; both take
     // into account the current zoom level.
@@ -326,7 +331,7 @@
     static const char* wbModeEnumToString(uint8_t wbMode);
     static int effectModeStringToEnum(const char *effectMode);
     static int abModeStringToEnum(const char *abMode);
-    static int sceneModeStringToEnum(const char *sceneMode);
+    static int sceneModeStringToEnum(const char *sceneMode, uint8_t defaultScene);
     static flashMode_t flashModeStringToEnum(const char *flashMode);
     static const char* flashModeEnumToString(flashMode_t flashMode);
     static focusMode_t focusModeStringToEnum(const char *focusMode);
@@ -434,6 +439,7 @@
     Size getMaxSize(const Vector<Size>& sizes);
 
     int mDeviceVersion;
+    uint8_t mDefaultSceneMode;
 };
 
 // This class encapsulates the Parameters class so that it can only be accessed
diff --git a/services/camera/libcameraservice/device3/Camera3StreamSplitter.cpp b/services/camera/libcameraservice/device3/Camera3StreamSplitter.cpp
index a0be608..8bc208d 100644
--- a/services/camera/libcameraservice/device3/Camera3StreamSplitter.cpp
+++ b/services/camera/libcameraservice/device3/Camera3StreamSplitter.cpp
@@ -500,6 +500,10 @@
     SP_LOGV("acquired buffer %" PRId64 " from input at slot %d",
             bufferItem.mGraphicBuffer->getId(), bufferItem.mSlot);
 
+    if (bufferItem.mTransformToDisplayInverse) {
+        bufferItem.mTransform |= NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY;
+    }
+
     // Attach and queue the buffer to each of the outputs
     BufferTracker& tracker = *(mBuffers[bufferId]);