Merge "C2AllocatorBlob: allow multiple maps"
diff --git a/OWNERS b/OWNERS
index 8f405e9..9989bf0 100644
--- a/OWNERS
+++ b/OWNERS
@@ -2,3 +2,7 @@
 etalvala@google.com
 lajos@google.com
 marcone@google.com
+
+# LON
+olly@google.com
+andrewlewis@google.com
diff --git a/cmds/stagefright/AudioPlayer.cpp b/cmds/stagefright/AudioPlayer.cpp
index eb76953..55427ca 100644
--- a/cmds/stagefright/AudioPlayer.cpp
+++ b/cmds/stagefright/AudioPlayer.cpp
@@ -134,15 +134,18 @@
     success = format->findInt32(kKeySampleRate, &mSampleRate);
     CHECK(success);
 
-    int32_t numChannels, channelMask;
+    int32_t numChannels;
     success = format->findInt32(kKeyChannelCount, &numChannels);
     CHECK(success);
 
-    if(!format->findInt32(kKeyChannelMask, &channelMask)) {
+    audio_channel_mask_t channelMask;
+    if (int32_t rawChannelMask; !format->findInt32(kKeyChannelMask, &rawChannelMask)) {
         // log only when there's a risk of ambiguity of channel mask selection
         ALOGI_IF(numChannels > 2,
                 "source format didn't specify channel mask, using (%d) channel order", numChannels);
         channelMask = CHANNEL_MASK_USE_CHANNEL_ORDER;
+    } else {
+        channelMask = static_cast<audio_channel_mask_t>(rawChannelMask);
     }
 
     audio_format_t audioFormat = AUDIO_FORMAT_PCM_16_BIT;
diff --git a/include/media/MicrophoneInfo.h b/include/media/MicrophoneInfo.h
index 2287aca..0a24b02 100644
--- a/include/media/MicrophoneInfo.h
+++ b/include/media/MicrophoneInfo.h
@@ -205,11 +205,11 @@
 private:
     status_t readFloatVector(
             const Parcel* parcel, Vector<float> *vectorPtr, size_t defaultLength) {
-        std::unique_ptr<std::vector<float>> v;
+        std::optional<std::vector<float>> v;
         status_t result = parcel->readFloatVector(&v);
         if (result != OK) return result;
         vectorPtr->clear();
-        if (v.get() != nullptr) {
+        if (v) {
             for (const auto& iter : *v) {
                 vectorPtr->push_back(iter);
             }
diff --git a/media/codec2/hidl/1.0/vts/functional/video/VtsHalMediaC2V1_0TargetVideoEncTest.cpp b/media/codec2/hidl/1.0/vts/functional/video/VtsHalMediaC2V1_0TargetVideoEncTest.cpp
index ecaf3a8..5bcea5b 100644
--- a/media/codec2/hidl/1.0/vts/functional/video/VtsHalMediaC2V1_0TargetVideoEncTest.cpp
+++ b/media/codec2/hidl/1.0/vts/functional/video/VtsHalMediaC2V1_0TargetVideoEncTest.cpp
@@ -107,6 +107,13 @@
         mOutputSize = 0u;
         mTimestampDevTest = false;
         if (mCompName == unknown_comp) mDisableTest = true;
+
+        C2SecureModeTuning secureModeTuning{};
+        mComponent->query({&secureModeTuning}, {}, C2_MAY_BLOCK, nullptr);
+        if (secureModeTuning.value == C2Config::SM_READ_PROTECTED) {
+            mDisableTest = true;
+        }
+
         if (mDisableTest) std::cout << "[   WARN   ] Test Disabled \n";
     }
 
diff --git a/media/codec2/hidl/client/client.cpp b/media/codec2/hidl/client/client.cpp
index 7e4352d..4650672 100644
--- a/media/codec2/hidl/client/client.cpp
+++ b/media/codec2/hidl/client/client.cpp
@@ -843,6 +843,11 @@
                             return;
                         }
                     });
+            if (!transStatus.isOk()) {
+                LOG(DEBUG) << "SimpleParamReflector -- transaction failed: "
+                           << transStatus.description();
+                descriptor.reset();
+            }
             return descriptor;
         }
 
diff --git a/media/codec2/sfplugin/C2OMXNode.cpp b/media/codec2/sfplugin/C2OMXNode.cpp
index c7588e9..dd1f485 100644
--- a/media/codec2/sfplugin/C2OMXNode.cpp
+++ b/media/codec2/sfplugin/C2OMXNode.cpp
@@ -25,6 +25,7 @@
 #include <C2AllocatorGralloc.h>
 #include <C2BlockInternal.h>
 #include <C2Component.h>
+#include <C2Config.h>
 #include <C2PlatformSupport.h>
 
 #include <OMX_Component.h>
@@ -44,6 +45,8 @@
 
 namespace {
 
+constexpr OMX_U32 kPortIndexInput = 0;
+
 class Buffer2D : public C2Buffer {
 public:
     explicit Buffer2D(C2ConstGraphicBlock block) : C2Buffer({ block }) {}
@@ -200,11 +203,27 @@
                 return BAD_VALUE;
             }
             OMX_PARAM_PORTDEFINITIONTYPE *pDef = (OMX_PARAM_PORTDEFINITIONTYPE *)params;
-            // TODO: read these from intf()
+            if (pDef->nPortIndex != kPortIndexInput) {
+                break;
+            }
+
             pDef->nBufferCountActual = 16;
+
+            std::shared_ptr<Codec2Client::Component> comp = mComp.lock();
+            C2PortActualDelayTuning::input inputDelay(0);
+            C2ActualPipelineDelayTuning pipelineDelay(0);
+            c2_status_t c2err = comp->query(
+                    {&inputDelay, &pipelineDelay}, {}, C2_DONT_BLOCK, nullptr);
+            if (c2err == C2_OK || c2err == C2_BAD_INDEX) {
+                pDef->nBufferCountActual = 4;
+                pDef->nBufferCountActual += (inputDelay ? inputDelay.value : 0u);
+                pDef->nBufferCountActual += (pipelineDelay ? pipelineDelay.value : 0u);
+            }
+
             pDef->eDomain = OMX_PortDomainVideo;
             pDef->format.video.nFrameWidth = mWidth;
             pDef->format.video.nFrameHeight = mHeight;
+            pDef->format.video.eColorFormat = OMX_COLOR_FormatAndroidOpaque;
             err = OK;
             break;
         }
diff --git a/media/codec2/sfplugin/CCodec.cpp b/media/codec2/sfplugin/CCodec.cpp
index 1405b97..57252b2 100644
--- a/media/codec2/sfplugin/CCodec.cpp
+++ b/media/codec2/sfplugin/CCodec.cpp
@@ -246,8 +246,19 @@
         if (source == nullptr) {
             return NO_INIT;
         }
-        constexpr size_t kNumSlots = 16;
-        for (size_t i = 0; i < kNumSlots; ++i) {
+
+        size_t numSlots = 4;
+        constexpr OMX_U32 kPortIndexInput = 0;
+
+        OMX_PARAM_PORTDEFINITIONTYPE param;
+        param.nPortIndex = kPortIndexInput;
+        status_t err = mNode->getParameter(OMX_IndexParamPortDefinition,
+                                           &param, sizeof(param));
+        if (err == OK) {
+            numSlots = param.nBufferCountActual;
+        }
+
+        for (size_t i = 0; i < numSlots; ++i) {
             source->onInputBufferAdded(i);
         }
 
diff --git a/media/codec2/sfplugin/CCodecBufferChannel.cpp b/media/codec2/sfplugin/CCodecBufferChannel.cpp
index 3919ea2..aa4a004 100644
--- a/media/codec2/sfplugin/CCodecBufferChannel.cpp
+++ b/media/codec2/sfplugin/CCodecBufferChannel.cpp
@@ -1066,9 +1066,6 @@
             Mutexed<OutputSurface>::Locked output(mOutputSurface);
             output->maxDequeueBuffers = numOutputSlots +
                     reorderDepth.value + kRenderingDepth;
-            if (!secure) {
-                output->maxDequeueBuffers += numInputSlots;
-            }
             outputSurface = output->surface ?
                     output->surface->getIGraphicBufferProducer() : nullptr;
             if (outputSurface) {
@@ -1529,6 +1526,7 @@
     }
 
     std::optional<uint32_t> newInputDelay, newPipelineDelay;
+    bool needMaxDequeueBufferCountUpdate = false;
     while (!worklet->output.configUpdate.empty()) {
         std::unique_ptr<C2Param> param;
         worklet->output.configUpdate.back().swap(param);
@@ -1537,24 +1535,10 @@
             case C2PortReorderBufferDepthTuning::CORE_INDEX: {
                 C2PortReorderBufferDepthTuning::output reorderDepth;
                 if (reorderDepth.updateFrom(*param)) {
-                    bool secure = mComponent->getName().find(".secure") !=
-                                  std::string::npos;
-                    mOutput.lock()->buffers->setReorderDepth(
-                            reorderDepth.value);
                     ALOGV("[%s] onWorkDone: updated reorder depth to %u",
                           mName, reorderDepth.value);
-                    size_t numOutputSlots = mOutput.lock()->numSlots;
-                    size_t numInputSlots = mInput.lock()->numSlots;
-                    Mutexed<OutputSurface>::Locked output(mOutputSurface);
-                    output->maxDequeueBuffers = numOutputSlots +
-                            reorderDepth.value + kRenderingDepth;
-                    if (!secure) {
-                        output->maxDequeueBuffers += numInputSlots;
-                    }
-                    if (output->surface) {
-                        output->surface->setMaxDequeuedBufferCount(
-                                output->maxDequeueBuffers);
-                    }
+                    mOutput.lock()->buffers->setReorderDepth(reorderDepth.value);
+                    needMaxDequeueBufferCountUpdate = true;
                 } else {
                     ALOGD("[%s] onWorkDone: failed to read reorder depth",
                           mName);
@@ -1598,14 +1582,11 @@
                     if (outputDelay.updateFrom(*param)) {
                         ALOGV("[%s] onWorkDone: updating output delay %u",
                               mName, outputDelay.value);
-                        bool secure = mComponent->getName().find(".secure") !=
-                                      std::string::npos;
-                        (void)mPipelineWatcher.lock()->outputDelay(
-                                outputDelay.value);
+                        (void)mPipelineWatcher.lock()->outputDelay(outputDelay.value);
+                        needMaxDequeueBufferCountUpdate = true;
 
                         bool outputBuffersChanged = false;
                         size_t numOutputSlots = 0;
-                        size_t numInputSlots = mInput.lock()->numSlots;
                         {
                             Mutexed<Output>::Locked output(mOutput);
                             if (!output->buffers) {
@@ -1631,16 +1612,6 @@
                         if (outputBuffersChanged) {
                             mCCodecCallback->onOutputBuffersChanged();
                         }
-
-                        uint32_t depth = mOutput.lock()->buffers->getReorderDepth();
-                        Mutexed<OutputSurface>::Locked output(mOutputSurface);
-                        output->maxDequeueBuffers = numOutputSlots + depth + kRenderingDepth;
-                        if (!secure) {
-                            output->maxDequeueBuffers += numInputSlots;
-                        }
-                        if (output->surface) {
-                            output->surface->setMaxDequeuedBufferCount(output->maxDequeueBuffers);
-                        }
                     }
                 }
                 break;
@@ -1669,6 +1640,20 @@
             input->numSlots = newNumSlots;
         }
     }
+    if (needMaxDequeueBufferCountUpdate) {
+        size_t numOutputSlots = 0;
+        uint32_t reorderDepth = 0;
+        {
+            Mutexed<Output>::Locked output(mOutput);
+            numOutputSlots = output->numSlots;
+            reorderDepth = output->buffers->getReorderDepth();
+        }
+        Mutexed<OutputSurface>::Locked output(mOutputSurface);
+        output->maxDequeueBuffers = numOutputSlots + reorderDepth + kRenderingDepth;
+        if (output->surface) {
+            output->surface->setMaxDequeuedBufferCount(output->maxDequeueBuffers);
+        }
+    }
 
     int32_t flags = 0;
     if (worklet->output.flags & C2FrameData::FLAG_END_OF_STREAM) {
diff --git a/media/codec2/sfplugin/CCodecConfig.cpp b/media/codec2/sfplugin/CCodecConfig.cpp
index 96f86e8..79c6227 100644
--- a/media/codec2/sfplugin/CCodecConfig.cpp
+++ b/media/codec2/sfplugin/CCodecConfig.cpp
@@ -1151,14 +1151,11 @@
 
     bool changed = false;
     if (domain & mInputDomain) {
-        sp<AMessage> oldFormat = mInputFormat;
-        mInputFormat = mInputFormat->dup(); // trigger format changed
+        sp<AMessage> oldFormat = mInputFormat->dup();
         mInputFormat->extend(getFormatForDomain(reflected, mInputDomain));
         if (mInputFormat->countEntries() != oldFormat->countEntries()
                 || mInputFormat->changesFrom(oldFormat)->countEntries() > 0) {
             changed = true;
-        } else {
-            mInputFormat = oldFormat; // no change
         }
     }
     if (domain & mOutputDomain) {
diff --git a/media/extractors/ogg/OggExtractor.cpp b/media/extractors/ogg/OggExtractor.cpp
index 828bcd6..eb2246d 100644
--- a/media/extractors/ogg/OggExtractor.cpp
+++ b/media/extractors/ogg/OggExtractor.cpp
@@ -1304,8 +1304,8 @@
                 || audioChannelCount <= 0 || audioChannelCount > FCC_8) {
             ALOGE("Invalid haptic channel count found in metadata: %d", mHapticChannelCount);
         } else {
-            const audio_channel_mask_t channelMask = audio_channel_out_mask_from_count(
-                    audioChannelCount) | hapticChannelMask;
+            const audio_channel_mask_t channelMask = static_cast<audio_channel_mask_t>(
+                    audio_channel_out_mask_from_count(audioChannelCount) | hapticChannelMask);
             AMediaFormat_setInt32(mMeta, AMEDIAFORMAT_KEY_CHANNEL_MASK, channelMask);
             AMediaFormat_setInt32(
                     mMeta, AMEDIAFORMAT_KEY_HAPTIC_CHANNEL_COUNT, mHapticChannelCount);
diff --git a/media/libaaudio/src/utility/AAudioUtilities.cpp b/media/libaaudio/src/utility/AAudioUtilities.cpp
index 9007b10..dbb3d2b 100644
--- a/media/libaaudio/src/utility/AAudioUtilities.cpp
+++ b/media/libaaudio/src/utility/AAudioUtilities.cpp
@@ -231,7 +231,8 @@
         case AAUDIO_ALLOW_CAPTURE_BY_SYSTEM:
             return AUDIO_FLAG_NO_MEDIA_PROJECTION;
         case AAUDIO_ALLOW_CAPTURE_BY_NONE:
-            return AUDIO_FLAG_NO_MEDIA_PROJECTION | AUDIO_FLAG_NO_SYSTEM_CAPTURE;
+            return static_cast<audio_flags_mask_t>(
+                    AUDIO_FLAG_NO_MEDIA_PROJECTION | AUDIO_FLAG_NO_SYSTEM_CAPTURE);
         default:
             ALOGE("%s() 0x%08X unrecognized", __func__, policy);
             return AUDIO_FLAG_NONE; //
diff --git a/media/libaudioclient/AudioRecord.cpp b/media/libaudioclient/AudioRecord.cpp
index 509e063..d97f6cf 100644
--- a/media/libaudioclient/AudioRecord.cpp
+++ b/media/libaudioclient/AudioRecord.cpp
@@ -279,7 +279,8 @@
         mAttributes.source = inputSource;
         if (inputSource == AUDIO_SOURCE_VOICE_COMMUNICATION
                 || inputSource == AUDIO_SOURCE_CAMCORDER) {
-            mAttributes.flags |= AUDIO_FLAG_CAPTURE_PRIVATE;
+            mAttributes.flags = static_cast<audio_flags_mask_t>(
+                    mAttributes.flags | AUDIO_FLAG_CAPTURE_PRIVATE);
         }
     } else {
         // stream type shouldn't be looked at, this track has audio attributes
diff --git a/media/libaudioclient/AudioTrack.cpp b/media/libaudioclient/AudioTrack.cpp
index 807aa13..721873a 100644
--- a/media/libaudioclient/AudioTrack.cpp
+++ b/media/libaudioclient/AudioTrack.cpp
@@ -222,7 +222,7 @@
 {
     mAttributes.content_type = AUDIO_CONTENT_TYPE_UNKNOWN;
     mAttributes.usage = AUDIO_USAGE_UNKNOWN;
-    mAttributes.flags = 0x0;
+    mAttributes.flags = AUDIO_FLAG_NONE;
     strcpy(mAttributes.tags, "");
 }
 
@@ -458,7 +458,7 @@
     if (format == AUDIO_FORMAT_DEFAULT) {
         format = AUDIO_FORMAT_PCM_16_BIT;
     } else if (format == AUDIO_FORMAT_IEC61937) { // HDMI pass-through?
-        mAttributes.flags |= AUDIO_OUTPUT_FLAG_IEC958_NONAUDIO;
+        flags = static_cast<audio_output_flags_t>(flags | AUDIO_OUTPUT_FLAG_IEC958_NONAUDIO);
     }
 
     // validate parameters
@@ -635,6 +635,36 @@
     return status;
 }
 
+
+status_t AudioTrack::set(
+        audio_stream_type_t streamType,
+        uint32_t sampleRate,
+        audio_format_t format,
+        uint32_t channelMask,
+        size_t frameCount,
+        audio_output_flags_t flags,
+        callback_t cbf,
+        void* user,
+        int32_t notificationFrames,
+        const sp<IMemory>& sharedBuffer,
+        bool threadCanCallJava,
+        audio_session_t sessionId,
+        transfer_type transferType,
+        const audio_offload_info_t *offloadInfo,
+        uid_t uid,
+        pid_t pid,
+        const audio_attributes_t* pAttributes,
+        bool doNotReconnect,
+        float maxRequiredSpeed,
+        audio_port_handle_t selectedDeviceId)
+{
+    return set(streamType, sampleRate, format,
+            static_cast<audio_channel_mask_t>(channelMask),
+            frameCount, flags, cbf, user, notificationFrames, sharedBuffer,
+            threadCanCallJava, sessionId, transferType, offloadInfo, uid, pid,
+            pAttributes, doNotReconnect, maxRequiredSpeed, selectedDeviceId);
+}
+
 // -------------------------------------------------------------------------
 
 status_t AudioTrack::start()
diff --git a/media/libaudioclient/IAudioFlinger.cpp b/media/libaudioclient/IAudioFlinger.cpp
index 6d79aba..04525d0 100644
--- a/media/libaudioclient/IAudioFlinger.cpp
+++ b/media/libaudioclient/IAudioFlinger.cpp
@@ -1210,7 +1210,7 @@
             CHECK_INTERFACE(IAudioFlinger, data, reply);
             uint32_t sampleRate = data.readInt32();
             audio_format_t format = (audio_format_t) data.readInt32();
-            audio_channel_mask_t channelMask = data.readInt32();
+            audio_channel_mask_t channelMask = (audio_channel_mask_t) data.readInt32();
             reply->writeInt64( getInputBufferSize(sampleRate, format, channelMask) );
             return NO_ERROR;
         } break;
diff --git a/media/libaudioclient/IAudioPolicyService.cpp b/media/libaudioclient/IAudioPolicyService.cpp
index 60af84b..c9bb0aa 100644
--- a/media/libaudioclient/IAudioPolicyService.cpp
+++ b/media/libaudioclient/IAudioPolicyService.cpp
@@ -2628,7 +2628,7 @@
         case SET_ALLOWED_CAPTURE_POLICY: {
             CHECK_INTERFACE(IAudioPolicyService, data, reply);
             uid_t uid = data.readInt32();
-            audio_flags_mask_t flags = data.readInt32();
+            audio_flags_mask_t flags = static_cast<audio_flags_mask_t>(data.readInt32());
             status_t status = setAllowedCapturePolicy(uid, flags);
             reply->writeInt32(status);
             return NO_ERROR;
diff --git a/media/libaudioclient/include/media/AudioTrack.h b/media/libaudioclient/include/media/AudioTrack.h
index 0dbd842..ca51dcd 100644
--- a/media/libaudioclient/include/media/AudioTrack.h
+++ b/media/libaudioclient/include/media/AudioTrack.h
@@ -338,6 +338,27 @@
                             bool doNotReconnect = false,
                             float maxRequiredSpeed = 1.0f,
                             audio_port_handle_t selectedDeviceId = AUDIO_PORT_HANDLE_NONE);
+    // FIXME(b/169889714): Vendor code depends on the old method signature at link time
+            status_t    set(audio_stream_type_t streamType,
+                            uint32_t sampleRate,
+                            audio_format_t format,
+                            uint32_t channelMask,
+                            size_t frameCount   = 0,
+                            audio_output_flags_t flags = AUDIO_OUTPUT_FLAG_NONE,
+                            callback_t cbf      = NULL,
+                            void* user          = NULL,
+                            int32_t notificationFrames = 0,
+                            const sp<IMemory>& sharedBuffer = 0,
+                            bool threadCanCallJava = false,
+                            audio_session_t sessionId  = AUDIO_SESSION_ALLOCATE,
+                            transfer_type transferType = TRANSFER_DEFAULT,
+                            const audio_offload_info_t *offloadInfo = NULL,
+                            uid_t uid = AUDIO_UID_INVALID,
+                            pid_t pid = -1,
+                            const audio_attributes_t* pAttributes = NULL,
+                            bool doNotReconnect = false,
+                            float maxRequiredSpeed = 1.0f,
+                            audio_port_handle_t selectedDeviceId = AUDIO_PORT_HANDLE_NONE);
 
     /* Result of constructing the AudioTrack. This must be checked for successful initialization
      * before using any AudioTrack API (except for set()), because using
diff --git a/media/libaudiofoundation/AudioDeviceTypeAddr.cpp b/media/libaudiofoundation/AudioDeviceTypeAddr.cpp
index b44043a..d65d6ac 100644
--- a/media/libaudiofoundation/AudioDeviceTypeAddr.cpp
+++ b/media/libaudiofoundation/AudioDeviceTypeAddr.cpp
@@ -43,7 +43,9 @@
 
 status_t AudioDeviceTypeAddr::readFromParcel(const Parcel *parcel) {
     status_t status;
-    if ((status = parcel->readUint32(&mType)) != NO_ERROR) return status;
+    uint32_t rawDeviceType;
+    if ((status = parcel->readUint32(&rawDeviceType)) != NO_ERROR) return status;
+    mType = static_cast<audio_devices_t>(rawDeviceType);
     status = parcel->readUtf8FromUtf16(&mAddress);
     return status;
 }
@@ -64,4 +66,4 @@
     return deviceTypes;
 }
 
-}
\ No newline at end of file
+}
diff --git a/media/libaudiofoundation/AudioGain.cpp b/media/libaudiofoundation/AudioGain.cpp
index 0d28335..759140e 100644
--- a/media/libaudiofoundation/AudioGain.cpp
+++ b/media/libaudiofoundation/AudioGain.cpp
@@ -152,8 +152,12 @@
     if ((status = parcel->readInt32(&mIndex)) != NO_ERROR) return status;
     if ((status = parcel->readBool(&mUseInChannelMask)) != NO_ERROR) return status;
     if ((status = parcel->readBool(&mUseForVolume)) != NO_ERROR) return status;
-    if ((status = parcel->readUint32(&mGain.mode)) != NO_ERROR) return status;
-    if ((status = parcel->readUint32(&mGain.channel_mask)) != NO_ERROR) return status;
+    uint32_t rawGainMode;
+    if ((status = parcel->readUint32(&rawGainMode)) != NO_ERROR) return status;
+    mGain.mode = static_cast<audio_gain_mode_t>(rawGainMode);
+    uint32_t rawChannelMask;
+    if ((status = parcel->readUint32(&rawChannelMask)) != NO_ERROR) return status;
+    mGain.channel_mask = static_cast<audio_channel_mask_t>(rawChannelMask);
     if ((status = parcel->readInt32(&mGain.min_value)) != NO_ERROR) return status;
     if ((status = parcel->readInt32(&mGain.max_value)) != NO_ERROR) return status;
     if ((status = parcel->readInt32(&mGain.default_value)) != NO_ERROR) return status;
diff --git a/media/libaudiofoundation/AudioPort.cpp b/media/libaudiofoundation/AudioPort.cpp
index f988690..1846a6b 100644
--- a/media/libaudiofoundation/AudioPort.cpp
+++ b/media/libaudiofoundation/AudioPort.cpp
@@ -268,12 +268,17 @@
     if ((status = parcel->readUint32(reinterpret_cast<uint32_t*>(&mFormat))) != NO_ERROR) {
         return status;
     }
-    if ((status = parcel->readUint32(&mChannelMask)) != NO_ERROR) return status;
+    uint32_t rawChannelMask;
+    if ((status = parcel->readUint32(&rawChannelMask)) != NO_ERROR) return status;
+    mChannelMask = static_cast<audio_channel_mask_t>(rawChannelMask);
     if ((status = parcel->readInt32(&mId)) != NO_ERROR) return status;
     // Read mGain from parcel.
     if ((status = parcel->readInt32(&mGain.index)) != NO_ERROR) return status;
-    if ((status = parcel->readUint32(&mGain.mode)) != NO_ERROR) return status;
-    if ((status = parcel->readUint32(&mGain.channel_mask)) != NO_ERROR) return status;
+    uint32_t rawGainMode;
+    if ((status = parcel->readUint32(&rawGainMode)) != NO_ERROR) return status;
+    mGain.mode = static_cast<audio_gain_mode_t>(rawGainMode);
+    if ((status = parcel->readUint32(&rawChannelMask)) != NO_ERROR) return status;
+    mGain.channel_mask = static_cast<audio_channel_mask_t>(rawChannelMask);
     if ((status = parcel->readUint32(&mGain.ramp_duration_ms)) != NO_ERROR) return status;
     std::vector<int> values;
     if ((status = parcel->readInt32Vector(&values)) != NO_ERROR) return status;
diff --git a/media/libaudiofoundation/AudioProfile.cpp b/media/libaudiofoundation/AudioProfile.cpp
index 91be346..67b600e 100644
--- a/media/libaudiofoundation/AudioProfile.cpp
+++ b/media/libaudiofoundation/AudioProfile.cpp
@@ -157,7 +157,9 @@
     std::vector<int> values;
     if ((status = parcel->readInt32Vector(&values)) != NO_ERROR) return status;
     mChannelMasks.clear();
-    mChannelMasks.insert(values.begin(), values.end());
+    for (auto raw : values) {
+        mChannelMasks.insert(static_cast<audio_channel_mask_t>(raw));
+    }
     values.clear();
     if ((status = parcel->readInt32Vector(&values)) != NO_ERROR) return status;
     mSamplingRates.clear();
diff --git a/media/libaudiofoundation/include/media/AudioContainers.h b/media/libaudiofoundation/include/media/AudioContainers.h
index 72fda49..aa7ca69 100644
--- a/media/libaudiofoundation/include/media/AudioContainers.h
+++ b/media/libaudiofoundation/include/media/AudioContainers.h
@@ -96,7 +96,7 @@
 static inline audio_devices_t deviceTypesToBitMask(const DeviceTypeSet& deviceTypes) {
     audio_devices_t types = AUDIO_DEVICE_NONE;
     for (auto deviceType : deviceTypes) {
-        types |= deviceType;
+        types = static_cast<audio_devices_t>(types | deviceType);
     }
     return types;
 }
@@ -131,4 +131,4 @@
 std::string toString(const DeviceTypeSet& deviceTypes);
 
 
-} // namespace android
\ No newline at end of file
+} // namespace android
diff --git a/media/libaudiohal/Android.bp b/media/libaudiohal/Android.bp
index 1709d1e..fab0fea 100644
--- a/media/libaudiohal/Android.bp
+++ b/media/libaudiohal/Android.bp
@@ -18,6 +18,7 @@
         "libaudiohal@4.0",
         "libaudiohal@5.0",
         "libaudiohal@6.0",
+//        "libaudiohal@7.0",
     ],
 
     shared_libs: [
diff --git a/media/libaudiohal/FactoryHalHidl.cpp b/media/libaudiohal/FactoryHalHidl.cpp
index 5985ef0..7228b22 100644
--- a/media/libaudiohal/FactoryHalHidl.cpp
+++ b/media/libaudiohal/FactoryHalHidl.cpp
@@ -31,6 +31,7 @@
 /** Supported HAL versions, in order of preference.
  */
 const char* sAudioHALVersions[] = {
+    "7.0",
     "6.0",
     "5.0",
     "4.0",
diff --git a/media/libaudiohal/impl/Android.bp b/media/libaudiohal/impl/Android.bp
index 967fba1..df006b5 100644
--- a/media/libaudiohal/impl/Android.bp
+++ b/media/libaudiohal/impl/Android.bp
@@ -116,3 +116,20 @@
     ]
 }
 
+cc_library_shared {
+    enabled: false,
+    name: "libaudiohal@7.0",
+    defaults: ["libaudiohal_default"],
+    shared_libs: [
+        "android.hardware.audio.common@7.0",
+        "android.hardware.audio.common@7.0-util",
+        "android.hardware.audio.effect@7.0",
+        "android.hardware.audio@7.0",
+    ],
+    cflags: [
+        "-DMAJOR_VERSION=7",
+        "-DMINOR_VERSION=0",
+        "-include common/all-versions/VersionMacro.h",
+    ]
+}
+
diff --git a/media/libaudioprocessing/AudioMixer.cpp b/media/libaudioprocessing/AudioMixer.cpp
index 1a31420..00baea2 100644
--- a/media/libaudioprocessing/AudioMixer.cpp
+++ b/media/libaudioprocessing/AudioMixer.cpp
@@ -79,10 +79,14 @@
             && mixerChannelMask == (track->mMixerChannelMask | track->mMixerHapticChannelMask)) {
         return false;  // no need to change
     }
-    const audio_channel_mask_t hapticChannelMask = trackChannelMask & AUDIO_CHANNEL_HAPTIC_ALL;
-    trackChannelMask &= ~AUDIO_CHANNEL_HAPTIC_ALL;
-    const audio_channel_mask_t mixerHapticChannelMask = mixerChannelMask & AUDIO_CHANNEL_HAPTIC_ALL;
-    mixerChannelMask &= ~AUDIO_CHANNEL_HAPTIC_ALL;
+    const audio_channel_mask_t hapticChannelMask =
+            static_cast<audio_channel_mask_t>(trackChannelMask & AUDIO_CHANNEL_HAPTIC_ALL);
+    trackChannelMask = static_cast<audio_channel_mask_t>(
+            trackChannelMask & ~AUDIO_CHANNEL_HAPTIC_ALL);
+    const audio_channel_mask_t mixerHapticChannelMask = static_cast<audio_channel_mask_t>(
+            mixerChannelMask & AUDIO_CHANNEL_HAPTIC_ALL);
+    mixerChannelMask = static_cast<audio_channel_mask_t>(
+            mixerChannelMask & ~AUDIO_CHANNEL_HAPTIC_ALL);
     // always recompute for both channel masks even if only one has changed.
     const uint32_t trackChannelCount = audio_channel_count_from_out_mask(trackChannelMask);
     const uint32_t mixerChannelCount = audio_channel_count_from_out_mask(mixerChannelMask);
@@ -362,7 +366,8 @@
             const audio_channel_mask_t trackChannelMask =
                 static_cast<audio_channel_mask_t>(valueInt);
             if (setChannelMasks(name, trackChannelMask,
-                    (track->mMixerChannelMask | track->mMixerHapticChannelMask))) {
+                    static_cast<audio_channel_mask_t>(
+                            track->mMixerChannelMask | track->mMixerHapticChannelMask))) {
                 ALOGV("setParameter(TRACK, CHANNEL_MASK, %x)", trackChannelMask);
                 invalidate();
             }
@@ -407,7 +412,8 @@
         case MIXER_CHANNEL_MASK: {
             const audio_channel_mask_t mixerChannelMask =
                     static_cast<audio_channel_mask_t>(valueInt);
-            if (setChannelMasks(name, track->channelMask | track->mHapticChannelMask,
+            if (setChannelMasks(name, static_cast<audio_channel_mask_t>(
+                                    track->channelMask | track->mHapticChannelMask),
                     mixerChannelMask)) {
                 ALOGV("setParameter(TRACK, MIXER_CHANNEL_MASK, %#x)", mixerChannelMask);
                 invalidate();
@@ -533,9 +539,10 @@
     Track* t = static_cast<Track*>(track);
 
     audio_channel_mask_t channelMask = t->channelMask;
-    t->mHapticChannelMask = channelMask & AUDIO_CHANNEL_HAPTIC_ALL;
+    t->mHapticChannelMask = static_cast<audio_channel_mask_t>(
+            channelMask & AUDIO_CHANNEL_HAPTIC_ALL);
     t->mHapticChannelCount = audio_channel_count_from_out_mask(t->mHapticChannelMask);
-    channelMask &= ~AUDIO_CHANNEL_HAPTIC_ALL;
+    channelMask = static_cast<audio_channel_mask_t>(channelMask & ~AUDIO_CHANNEL_HAPTIC_ALL);
     t->channelCount = audio_channel_count_from_out_mask(channelMask);
     ALOGV_IF(audio_channel_mask_get_bits(channelMask) != AUDIO_CHANNEL_OUT_STEREO,
             "Non-stereo channel mask: %d\n", channelMask);
diff --git a/media/libaudioprocessing/tests/test-mixer.cpp b/media/libaudioprocessing/tests/test-mixer.cpp
index bc9d2a6..1bbb863 100644
--- a/media/libaudioprocessing/tests/test-mixer.cpp
+++ b/media/libaudioprocessing/tests/test-mixer.cpp
@@ -241,7 +241,8 @@
     // set up the tracks.
     for (size_t i = 0; i < providers.size(); ++i) {
         //printf("track %d out of %d\n", i, providers.size());
-        uint32_t channelMask = audio_channel_out_mask_from_count(providers[i].getNumChannels());
+        audio_channel_mask_t channelMask =
+                audio_channel_out_mask_from_count(providers[i].getNumChannels());
         const int name = i;
         const status_t status = mixer->create(
                 name, channelMask, formats[i], AUDIO_SESSION_OUTPUT_MIX);
diff --git a/media/libeffects/lvm/wrapper/Bundle/EffectBundle.cpp b/media/libeffects/lvm/wrapper/Bundle/EffectBundle.cpp
index 973a164..670b415 100644
--- a/media/libeffects/lvm/wrapper/Bundle/EffectBundle.cpp
+++ b/media/libeffects/lvm/wrapper/Bundle/EffectBundle.cpp
@@ -3394,8 +3394,8 @@
                 return -EINVAL;
             }
 
-            uint32_t device = *(uint32_t*)pCmdData;
-            pContext->pBundledContext->nOutputDevice = (audio_devices_t)device;
+            audio_devices_t device = *(audio_devices_t *)pCmdData;
+            pContext->pBundledContext->nOutputDevice = device;
 
             if (pContext->EffectType == LVM_BASS_BOOST) {
                 if ((device == AUDIO_DEVICE_OUT_SPEAKER) ||
diff --git a/media/libeffects/preprocessing/.clang-format b/media/libeffects/preprocessing/.clang-format
new file mode 120000
index 0000000..f1b4f69
--- /dev/null
+++ b/media/libeffects/preprocessing/.clang-format
@@ -0,0 +1 @@
+../../../../../build/soong/scripts/system-clang-format
\ No newline at end of file
diff --git a/media/libeffects/preprocessing/PreProcessing.cpp b/media/libeffects/preprocessing/PreProcessing.cpp
index f2f74a5..1a5547b 100644
--- a/media/libeffects/preprocessing/PreProcessing.cpp
+++ b/media/libeffects/preprocessing/PreProcessing.cpp
@@ -18,17 +18,17 @@
 #include <string.h>
 #define LOG_TAG "PreProcessing"
 //#define LOG_NDEBUG 0
-#include <utils/Log.h>
-#include <utils/Timers.h>
-#include <hardware/audio_effect.h>
 #include <audio_effects/effect_aec.h>
 #include <audio_effects/effect_agc.h>
+#include <hardware/audio_effect.h>
+#include <utils/Log.h>
+#include <utils/Timers.h>
 #ifndef WEBRTC_LEGACY
 #include <audio_effects/effect_agc2.h>
 #endif
 #include <audio_effects/effect_ns.h>
-#include <module_common_types.h>
 #include <audio_processing.h>
+#include <module_common_types.h>
 #ifdef WEBRTC_LEGACY
 #include "speex/speex_resampler.h"
 #endif
@@ -44,29 +44,28 @@
 #define PREPROC_NUM_SESSIONS 8
 
 // types of pre processing modules
-enum preproc_id
-{
-    PREPROC_AGC,        // Automatic Gain Control
+enum preproc_id {
+    PREPROC_AGC,  // Automatic Gain Control
 #ifndef WEBRTC_LEGACY
-    PREPROC_AGC2,       // Automatic Gain Control 2
+    PREPROC_AGC2,  // Automatic Gain Control 2
 #endif
-    PREPROC_AEC,        // Acoustic Echo Canceler
-    PREPROC_NS,         // Noise Suppressor
+    PREPROC_AEC,  // Acoustic Echo Canceler
+    PREPROC_NS,   // Noise Suppressor
     PREPROC_NUM_EFFECTS
 };
 
 // Session state
 enum preproc_session_state {
-    PREPROC_SESSION_STATE_INIT,        // initialized
-    PREPROC_SESSION_STATE_CONFIG       // configuration received
+    PREPROC_SESSION_STATE_INIT,   // initialized
+    PREPROC_SESSION_STATE_CONFIG  // configuration received
 };
 
 // Effect/Preprocessor state
 enum preproc_effect_state {
-    PREPROC_EFFECT_STATE_INIT,         // initialized
-    PREPROC_EFFECT_STATE_CREATED,      // webRTC engine created
-    PREPROC_EFFECT_STATE_CONFIG,       // configuration received/disabled
-    PREPROC_EFFECT_STATE_ACTIVE        // active/enabled
+    PREPROC_EFFECT_STATE_INIT,     // initialized
+    PREPROC_EFFECT_STATE_CREATED,  // webRTC engine created
+    PREPROC_EFFECT_STATE_CONFIG,   // configuration received/disabled
+    PREPROC_EFFECT_STATE_ACTIVE    // active/enabled
 };
 
 // handle on webRTC engine
@@ -79,95 +78,95 @@
 // Effect operation table. Functions for all pre processors are declared in sPreProcOps[] table.
 // Function pointer can be null if no action required.
 struct preproc_ops_s {
-    int (* create)(preproc_effect_t *fx);
-    int (* init)(preproc_effect_t *fx);
-    int (* reset)(preproc_effect_t *fx);
-    void (* enable)(preproc_effect_t *fx);
-    void (* disable)(preproc_effect_t *fx);
-    int (* set_parameter)(preproc_effect_t *fx, void *param, void *value);
-    int (* get_parameter)(preproc_effect_t *fx, void *param, uint32_t *size, void *value);
-    int (* set_device)(preproc_effect_t *fx, uint32_t device);
+    int (*create)(preproc_effect_t* fx);
+    int (*init)(preproc_effect_t* fx);
+    int (*reset)(preproc_effect_t* fx);
+    void (*enable)(preproc_effect_t* fx);
+    void (*disable)(preproc_effect_t* fx);
+    int (*set_parameter)(preproc_effect_t* fx, void* param, void* value);
+    int (*get_parameter)(preproc_effect_t* fx, void* param, uint32_t* size, void* value);
+    int (*set_device)(preproc_effect_t* fx, uint32_t device);
 };
 
 // Effect context
 struct preproc_effect_s {
-    const struct effect_interface_s *itfe;
-    uint32_t procId;                // type of pre processor (enum preproc_id)
-    uint32_t state;                 // current state (enum preproc_effect_state)
-    preproc_session_t *session;     // session the effect is on
-    const preproc_ops_t *ops;       // effect ops table
-    preproc_fx_handle_t engine;     // handle on webRTC engine
-    uint32_t type;                  // subtype of effect
+    const struct effect_interface_s* itfe;
+    uint32_t procId;             // type of pre processor (enum preproc_id)
+    uint32_t state;              // current state (enum preproc_effect_state)
+    preproc_session_t* session;  // session the effect is on
+    const preproc_ops_t* ops;    // effect ops table
+    preproc_fx_handle_t engine;  // handle on webRTC engine
+    uint32_t type;               // subtype of effect
 #ifdef DUAL_MIC_TEST
-    bool aux_channels_on;           // support auxiliary channels
-    size_t cur_channel_config;      // current auciliary channel configuration
+    bool aux_channels_on;       // support auxiliary channels
+    size_t cur_channel_config;  // current auciliary channel configuration
 #endif
 };
 
 // Session context
 struct preproc_session_s {
-    struct preproc_effect_s effects[PREPROC_NUM_EFFECTS]; // effects in this session
-    uint32_t state;                     // current state (enum preproc_session_state)
-    int id;                             // audio session ID
-    int io;                             // handle of input stream this session is on
-    webrtc::AudioProcessing* apm;       // handle on webRTC audio processing module (APM)
+    struct preproc_effect_s effects[PREPROC_NUM_EFFECTS];  // effects in this session
+    uint32_t state;                // current state (enum preproc_session_state)
+    int id;                        // audio session ID
+    int io;                        // handle of input stream this session is on
+    webrtc::AudioProcessing* apm;  // handle on webRTC audio processing module (APM)
 #ifndef WEBRTC_LEGACY
     // Audio Processing module builder
     webrtc::AudioProcessingBuilder ap_builder;
 #endif
-    size_t apmFrameCount;               // buffer size for webRTC process (10 ms)
-    uint32_t apmSamplingRate;           // webRTC APM sampling rate (8/16 or 32 kHz)
-    size_t frameCount;                  // buffer size before input resampler ( <=> apmFrameCount)
-    uint32_t samplingRate;              // sampling rate at effect process interface
-    uint32_t inChannelCount;            // input channel count
-    uint32_t outChannelCount;           // output channel count
-    uint32_t createdMsk;                // bit field containing IDs of crested pre processors
-    uint32_t enabledMsk;                // bit field containing IDs of enabled pre processors
-    uint32_t processedMsk;              // bit field containing IDs of pre processors already
-                                        // processed in current round
+    size_t apmFrameCount;      // buffer size for webRTC process (10 ms)
+    uint32_t apmSamplingRate;  // webRTC APM sampling rate (8/16 or 32 kHz)
+    size_t frameCount;         // buffer size before input resampler ( <=> apmFrameCount)
+    uint32_t samplingRate;     // sampling rate at effect process interface
+    uint32_t inChannelCount;   // input channel count
+    uint32_t outChannelCount;  // output channel count
+    uint32_t createdMsk;       // bit field containing IDs of crested pre processors
+    uint32_t enabledMsk;       // bit field containing IDs of enabled pre processors
+    uint32_t processedMsk;     // bit field containing IDs of pre processors already
+                               // processed in current round
 #ifdef WEBRTC_LEGACY
-    webrtc::AudioFrame *procFrame;      // audio frame passed to webRTC AMP ProcessStream()
+    webrtc::AudioFrame* procFrame;  // audio frame passed to webRTC AMP ProcessStream()
 #else
     // audio config strucutre
     webrtc::AudioProcessing::Config config;
     webrtc::StreamConfig inputConfig;   // input stream configuration
     webrtc::StreamConfig outputConfig;  // output stream configuration
 #endif
-    int16_t *inBuf;                     // input buffer used when resampling
-    size_t inBufSize;                   // input buffer size in frames
-    size_t framesIn;                    // number of frames in input buffer
+    int16_t* inBuf;    // input buffer used when resampling
+    size_t inBufSize;  // input buffer size in frames
+    size_t framesIn;   // number of frames in input buffer
 #ifdef WEBRTC_LEGACY
-    SpeexResamplerState *inResampler;   // handle on input speex resampler
+    SpeexResamplerState* inResampler;  // handle on input speex resampler
 #endif
-    int16_t *outBuf;                    // output buffer used when resampling
-    size_t outBufSize;                  // output buffer size in frames
-    size_t framesOut;                   // number of frames in output buffer
+    int16_t* outBuf;    // output buffer used when resampling
+    size_t outBufSize;  // output buffer size in frames
+    size_t framesOut;   // number of frames in output buffer
 #ifdef WEBRTC_LEGACY
-    SpeexResamplerState *outResampler;  // handle on output speex resampler
+    SpeexResamplerState* outResampler;  // handle on output speex resampler
 #endif
-    uint32_t revChannelCount;           // number of channels on reverse stream
-    uint32_t revEnabledMsk;             // bit field containing IDs of enabled pre processors
-                                        // with reverse channel
-    uint32_t revProcessedMsk;           // bit field containing IDs of pre processors with reverse
-                                        // channel already processed in current round
+    uint32_t revChannelCount;  // number of channels on reverse stream
+    uint32_t revEnabledMsk;    // bit field containing IDs of enabled pre processors
+                               // with reverse channel
+    uint32_t revProcessedMsk;  // bit field containing IDs of pre processors with reverse
+                               // channel already processed in current round
 #ifdef WEBRTC_LEGACY
-    webrtc::AudioFrame *revFrame;       // audio frame passed to webRTC AMP AnalyzeReverseStream()
+    webrtc::AudioFrame* revFrame;  // audio frame passed to webRTC AMP AnalyzeReverseStream()
 #else
     webrtc::StreamConfig revConfig;     // reverse stream configuration.
 #endif
-    int16_t *revBuf;                    // reverse channel input buffer
-    size_t revBufSize;                  // reverse channel input buffer size
-    size_t framesRev;                   // number of frames in reverse channel input buffer
+    int16_t* revBuf;    // reverse channel input buffer
+    size_t revBufSize;  // reverse channel input buffer size
+    size_t framesRev;   // number of frames in reverse channel input buffer
 #ifdef WEBRTC_LEGACY
-    SpeexResamplerState *revResampler;  // handle on reverse channel input speex resampler
+    SpeexResamplerState* revResampler;  // handle on reverse channel input speex resampler
 #endif
 };
 
 #ifdef DUAL_MIC_TEST
 enum {
-    PREPROC_CMD_DUAL_MIC_ENABLE = EFFECT_CMD_FIRST_PROPRIETARY, // enable dual mic mode
-    PREPROC_CMD_DUAL_MIC_PCM_DUMP_START,                        // start pcm capture
-    PREPROC_CMD_DUAL_MIC_PCM_DUMP_STOP                          // stop pcm capture
+    PREPROC_CMD_DUAL_MIC_ENABLE = EFFECT_CMD_FIRST_PROPRIETARY,  // enable dual mic mode
+    PREPROC_CMD_DUAL_MIC_PCM_DUMP_START,                         // start pcm capture
+    PREPROC_CMD_DUAL_MIC_PCM_DUMP_STOP                           // stop pcm capture
 };
 
 enum {
@@ -180,24 +179,22 @@
 };
 
 const channel_config_t sDualMicConfigs[CHANNEL_CFG_CNT] = {
-        {AUDIO_CHANNEL_IN_MONO , 0},
-        {AUDIO_CHANNEL_IN_STEREO , 0},
-        {AUDIO_CHANNEL_IN_FRONT , AUDIO_CHANNEL_IN_BACK},
-        {AUDIO_CHANNEL_IN_STEREO , AUDIO_CHANNEL_IN_RIGHT}
-};
+        {AUDIO_CHANNEL_IN_MONO, 0},
+        {AUDIO_CHANNEL_IN_STEREO, 0},
+        {AUDIO_CHANNEL_IN_FRONT, AUDIO_CHANNEL_IN_BACK},
+        {AUDIO_CHANNEL_IN_STEREO, AUDIO_CHANNEL_IN_RIGHT}};
 
 bool sHasAuxChannels[PREPROC_NUM_EFFECTS] = {
-        false,   // PREPROC_AGC
+        false,  // PREPROC_AGC
         true,   // PREPROC_AEC
         true,   // PREPROC_NS
 };
 
 bool gDualMicEnabled;
-FILE *gPcmDumpFh;
+FILE* gPcmDumpFh;
 static pthread_mutex_t gPcmDumpLock = PTHREAD_MUTEX_INITIALIZER;
 #endif
 
-
 //------------------------------------------------------------------------------
 // Effect descriptors
 //------------------------------------------------------------------------------
@@ -207,88 +204,75 @@
 
 // Automatic Gain Control
 static const effect_descriptor_t sAgcDescriptor = {
-        { 0x0a8abfe0, 0x654c, 0x11e0, 0xba26, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, // type
-        { 0xaa8130e0, 0x66fc, 0x11e0, 0xbad0, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, // uuid
+        {0x0a8abfe0, 0x654c, 0x11e0, 0xba26, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}},  // type
+        {0xaa8130e0, 0x66fc, 0x11e0, 0xbad0, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}},  // uuid
         EFFECT_CONTROL_API_VERSION,
-        (EFFECT_FLAG_TYPE_PRE_PROC|EFFECT_FLAG_DEVICE_IND),
-        0, //FIXME indicate CPU load
-        0, //FIXME indicate memory usage
+        (EFFECT_FLAG_TYPE_PRE_PROC | EFFECT_FLAG_DEVICE_IND),
+        0,  // FIXME indicate CPU load
+        0,  // FIXME indicate memory usage
         "Automatic Gain Control",
-        "The Android Open Source Project"
-};
+        "The Android Open Source Project"};
 
 #ifndef WEBRTC_LEGACY
 // Automatic Gain Control 2
 static const effect_descriptor_t sAgc2Descriptor = {
-        { 0xae3c653b, 0xbe18, 0x4ab8, 0x8938, { 0x41, 0x8f, 0x0a, 0x7f, 0x06, 0xac } }, // type
-        { 0x89f38e65, 0xd4d2, 0x4d64, 0xad0e, { 0x2b, 0x3e, 0x79, 0x9e, 0xa8, 0x86 } }, // uuid
+        {0xae3c653b, 0xbe18, 0x4ab8, 0x8938, {0x41, 0x8f, 0x0a, 0x7f, 0x06, 0xac}},  // type
+        {0x89f38e65, 0xd4d2, 0x4d64, 0xad0e, {0x2b, 0x3e, 0x79, 0x9e, 0xa8, 0x86}},  // uuid
         EFFECT_CONTROL_API_VERSION,
-        (EFFECT_FLAG_TYPE_PRE_PROC|EFFECT_FLAG_DEVICE_IND),
-        0, //FIXME indicate CPU load
-        0, //FIXME indicate memory usage
+        (EFFECT_FLAG_TYPE_PRE_PROC | EFFECT_FLAG_DEVICE_IND),
+        0,  // FIXME indicate CPU load
+        0,  // FIXME indicate memory usage
         "Automatic Gain Control 2",
-        "The Android Open Source Project"
-};
+        "The Android Open Source Project"};
 #endif
 
 // Acoustic Echo Cancellation
 static const effect_descriptor_t sAecDescriptor = {
-        { 0x7b491460, 0x8d4d, 0x11e0, 0xbd61, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, // type
-        { 0xbb392ec0, 0x8d4d, 0x11e0, 0xa896, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, // uuid
+        {0x7b491460, 0x8d4d, 0x11e0, 0xbd61, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}},  // type
+        {0xbb392ec0, 0x8d4d, 0x11e0, 0xa896, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}},  // uuid
         EFFECT_CONTROL_API_VERSION,
-        (EFFECT_FLAG_TYPE_PRE_PROC|EFFECT_FLAG_DEVICE_IND),
-        0, //FIXME indicate CPU load
-        0, //FIXME indicate memory usage
+        (EFFECT_FLAG_TYPE_PRE_PROC | EFFECT_FLAG_DEVICE_IND),
+        0,  // FIXME indicate CPU load
+        0,  // FIXME indicate memory usage
         "Acoustic Echo Canceler",
-        "The Android Open Source Project"
-};
+        "The Android Open Source Project"};
 
 // Noise suppression
 static const effect_descriptor_t sNsDescriptor = {
-        { 0x58b4b260, 0x8e06, 0x11e0, 0xaa8e, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, // type
-        { 0xc06c8400, 0x8e06, 0x11e0, 0x9cb6, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, // uuid
+        {0x58b4b260, 0x8e06, 0x11e0, 0xaa8e, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}},  // type
+        {0xc06c8400, 0x8e06, 0x11e0, 0x9cb6, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}},  // uuid
         EFFECT_CONTROL_API_VERSION,
-        (EFFECT_FLAG_TYPE_PRE_PROC|EFFECT_FLAG_DEVICE_IND),
-        0, //FIXME indicate CPU load
-        0, //FIXME indicate memory usage
+        (EFFECT_FLAG_TYPE_PRE_PROC | EFFECT_FLAG_DEVICE_IND),
+        0,  // FIXME indicate CPU load
+        0,  // FIXME indicate memory usage
         "Noise Suppression",
-        "The Android Open Source Project"
-};
+        "The Android Open Source Project"};
 
-
-static const effect_descriptor_t *sDescriptors[PREPROC_NUM_EFFECTS] = {
-        &sAgcDescriptor,
+static const effect_descriptor_t* sDescriptors[PREPROC_NUM_EFFECTS] = {&sAgcDescriptor,
 #ifndef WEBRTC_LEGACY
-        &sAgc2Descriptor,
+                                                                       &sAgc2Descriptor,
 #endif
-        &sAecDescriptor,
-        &sNsDescriptor
-};
+                                                                       &sAecDescriptor,
+                                                                       &sNsDescriptor};
 
 //------------------------------------------------------------------------------
 // Helper functions
 //------------------------------------------------------------------------------
 
-const effect_uuid_t * const sUuidToPreProcTable[PREPROC_NUM_EFFECTS] = {
-        FX_IID_AGC,
+const effect_uuid_t* const sUuidToPreProcTable[PREPROC_NUM_EFFECTS] = {FX_IID_AGC,
 #ifndef WEBRTC_LEGACY
-        FX_IID_AGC2,
+                                                                       FX_IID_AGC2,
 #endif
-        FX_IID_AEC,
-        FX_IID_NS
-};
+                                                                       FX_IID_AEC, FX_IID_NS};
 
-
-const effect_uuid_t * ProcIdToUuid(int procId)
-{
+const effect_uuid_t* ProcIdToUuid(int procId) {
     if (procId >= PREPROC_NUM_EFFECTS) {
         return EFFECT_UUID_NULL;
     }
     return sUuidToPreProcTable[procId];
 }
 
-uint32_t UuidToProcId(const effect_uuid_t * uuid)
-{
+uint32_t UuidToProcId(const effect_uuid_t* uuid) {
     size_t i;
     for (i = 0; i < PREPROC_NUM_EFFECTS; i++) {
         if (memcmp(uuid, sUuidToPreProcTable[i], sizeof(*uuid)) == 0) {
@@ -298,15 +282,13 @@
     return i;
 }
 
-bool HasReverseStream(uint32_t procId)
-{
+bool HasReverseStream(uint32_t procId) {
     if (procId == PREPROC_AEC) {
         return true;
     }
     return false;
 }
 
-
 //------------------------------------------------------------------------------
 // Automatic Gain Control (AGC)
 //------------------------------------------------------------------------------
@@ -316,24 +298,22 @@
 static const bool kAgcDefaultLimiter = true;
 
 #ifndef WEBRTC_LEGACY
-int  Agc2Init (preproc_effect_t *effect)
-{
+int Agc2Init(preproc_effect_t* effect) {
     ALOGV("Agc2Init");
     effect->session->config = effect->session->apm->GetConfig();
     effect->session->config.gain_controller2.fixed_digital.gain_db = 0.f;
     effect->session->config.gain_controller2.adaptive_digital.level_estimator =
-        effect->session->config.gain_controller2.kRms;
+            effect->session->config.gain_controller2.kRms;
     effect->session->config.gain_controller2.adaptive_digital.extra_saturation_margin_db = 2.f;
     effect->session->apm->ApplyConfig(effect->session->config);
     return 0;
 }
 #endif
 
-int  AgcInit (preproc_effect_t *effect)
-{
+int AgcInit(preproc_effect_t* effect) {
     ALOGV("AgcInit");
 #ifdef WEBRTC_LEGACY
-    webrtc::GainControl *agc = static_cast<webrtc::GainControl *>(effect->engine);
+    webrtc::GainControl* agc = static_cast<webrtc::GainControl*>(effect->engine);
     agc->set_mode(webrtc::GainControl::kFixedDigital);
     agc->set_target_level_dbfs(kAgcDefaultTargetLevel);
     agc->set_compression_gain_db(kAgcDefaultCompGain);
@@ -349,17 +329,15 @@
 }
 
 #ifndef WEBRTC_LEGACY
-int  Agc2Create(preproc_effect_t *effect)
-{
+int Agc2Create(preproc_effect_t* effect) {
     Agc2Init(effect);
     return 0;
 }
 #endif
 
-int  AgcCreate(preproc_effect_t *effect)
-{
+int AgcCreate(preproc_effect_t* effect) {
 #ifdef WEBRTC_LEGACY
-    webrtc::GainControl *agc = effect->session->apm->gain_control();
+    webrtc::GainControl* agc = effect->session->apm->gain_control();
     ALOGV("AgcCreate got agc %p", agc);
     if (agc == NULL) {
         ALOGW("AgcCreate Error");
@@ -372,230 +350,216 @@
 }
 
 #ifndef WEBRTC_LEGACY
-int Agc2GetParameter(preproc_effect_t *effect,
-                    void *pParam,
-                    uint32_t *pValueSize,
-                    void *pValue)
-{
+int Agc2GetParameter(preproc_effect_t* effect, void* pParam, uint32_t* pValueSize, void* pValue) {
     int status = 0;
-    uint32_t param = *(uint32_t *)pParam;
-    agc2_settings_t *pProperties = (agc2_settings_t *)pValue;
+    uint32_t param = *(uint32_t*)pParam;
+    agc2_settings_t* pProperties = (agc2_settings_t*)pValue;
 
     switch (param) {
-    case AGC2_PARAM_FIXED_DIGITAL_GAIN:
-        if (*pValueSize < sizeof(float)) {
-            *pValueSize = 0.f;
-            return -EINVAL;
-        }
-        break;
-    case AGC2_PARAM_ADAPT_DIGI_LEVEL_ESTIMATOR:
-        if (*pValueSize < sizeof(int32_t)) {
-            *pValueSize = 0;
-            return -EINVAL;
-        }
-        break;
-    case AGC2_PARAM_ADAPT_DIGI_EXTRA_SATURATION_MARGIN:
-        if (*pValueSize < sizeof(float)) {
-            *pValueSize = 0.f;
-            return -EINVAL;
-        }
-        break;
-    case AGC2_PARAM_PROPERTIES:
-        if (*pValueSize < sizeof(agc2_settings_t)) {
-            *pValueSize = 0;
-            return -EINVAL;
-        }
-        break;
+        case AGC2_PARAM_FIXED_DIGITAL_GAIN:
+            if (*pValueSize < sizeof(float)) {
+                *pValueSize = 0.f;
+                return -EINVAL;
+            }
+            break;
+        case AGC2_PARAM_ADAPT_DIGI_LEVEL_ESTIMATOR:
+            if (*pValueSize < sizeof(int32_t)) {
+                *pValueSize = 0;
+                return -EINVAL;
+            }
+            break;
+        case AGC2_PARAM_ADAPT_DIGI_EXTRA_SATURATION_MARGIN:
+            if (*pValueSize < sizeof(float)) {
+                *pValueSize = 0.f;
+                return -EINVAL;
+            }
+            break;
+        case AGC2_PARAM_PROPERTIES:
+            if (*pValueSize < sizeof(agc2_settings_t)) {
+                *pValueSize = 0;
+                return -EINVAL;
+            }
+            break;
 
-    default:
-        ALOGW("Agc2GetParameter() unknown param %08x", param);
-        status = -EINVAL;
-        break;
+        default:
+            ALOGW("Agc2GetParameter() unknown param %08x", param);
+            status = -EINVAL;
+            break;
     }
 
     effect->session->config = effect->session->apm->GetConfig();
     switch (param) {
-    case AGC2_PARAM_FIXED_DIGITAL_GAIN:
-        *(float *) pValue =
-                (float)(effect->session->config.gain_controller2.fixed_digital.gain_db);
-        ALOGV("Agc2GetParameter() target level %f dB", *(float *) pValue);
-        break;
-    case AGC2_PARAM_ADAPT_DIGI_LEVEL_ESTIMATOR:
-        *(uint32_t *) pValue =
-                (uint32_t)(effect->session->config.gain_controller2.adaptive_digital.
-                level_estimator);
-        ALOGV("Agc2GetParameter() level estimator %d",
-                *(webrtc::AudioProcessing::Config::GainController2::LevelEstimator *) pValue);
-        break;
-    case AGC2_PARAM_ADAPT_DIGI_EXTRA_SATURATION_MARGIN:
-        *(float *) pValue =
-                (float)(effect->session->config.gain_controller2.adaptive_digital.
-                extra_saturation_margin_db);
-        ALOGV("Agc2GetParameter() extra saturation margin %f dB", *(float *) pValue);
-        break;
-    case AGC2_PARAM_PROPERTIES:
-        pProperties->fixedDigitalGain =
-                (float)(effect->session->config.gain_controller2.fixed_digital.gain_db);
-        pProperties->level_estimator =
-                (uint32_t)(effect->session->config.gain_controller2.adaptive_digital.
-                level_estimator);
-        pProperties->extraSaturationMargin =
-                (float)(effect->session->config.gain_controller2.adaptive_digital.
-                extra_saturation_margin_db);
-        break;
-    default:
-        ALOGW("Agc2GetParameter() unknown param %d", param);
-        status = -EINVAL;
-        break;
+        case AGC2_PARAM_FIXED_DIGITAL_GAIN:
+            *(float*)pValue =
+                    (float)(effect->session->config.gain_controller2.fixed_digital.gain_db);
+            ALOGV("Agc2GetParameter() target level %f dB", *(float*)pValue);
+            break;
+        case AGC2_PARAM_ADAPT_DIGI_LEVEL_ESTIMATOR:
+            *(uint32_t*)pValue = (uint32_t)(
+                    effect->session->config.gain_controller2.adaptive_digital.level_estimator);
+            ALOGV("Agc2GetParameter() level estimator %d",
+                  *(webrtc::AudioProcessing::Config::GainController2::LevelEstimator*)pValue);
+            break;
+        case AGC2_PARAM_ADAPT_DIGI_EXTRA_SATURATION_MARGIN:
+            *(float*)pValue = (float)(effect->session->config.gain_controller2.adaptive_digital
+                                              .extra_saturation_margin_db);
+            ALOGV("Agc2GetParameter() extra saturation margin %f dB", *(float*)pValue);
+            break;
+        case AGC2_PARAM_PROPERTIES:
+            pProperties->fixedDigitalGain =
+                    (float)(effect->session->config.gain_controller2.fixed_digital.gain_db);
+            pProperties->level_estimator = (uint32_t)(
+                    effect->session->config.gain_controller2.adaptive_digital.level_estimator);
+            pProperties->extraSaturationMargin =
+                    (float)(effect->session->config.gain_controller2.adaptive_digital
+                                    .extra_saturation_margin_db);
+            break;
+        default:
+            ALOGW("Agc2GetParameter() unknown param %d", param);
+            status = -EINVAL;
+            break;
     }
 
     return status;
 }
 #endif
 
-int AgcGetParameter(preproc_effect_t *effect,
-                    void *pParam,
-                    uint32_t *pValueSize,
-                    void *pValue)
-{
+int AgcGetParameter(preproc_effect_t* effect, void* pParam, uint32_t* pValueSize, void* pValue) {
     int status = 0;
-    uint32_t param = *(uint32_t *)pParam;
-    t_agc_settings *pProperties = (t_agc_settings *)pValue;
+    uint32_t param = *(uint32_t*)pParam;
+    t_agc_settings* pProperties = (t_agc_settings*)pValue;
 #ifdef WEBRTC_LEGACY
-    webrtc::GainControl *agc = static_cast<webrtc::GainControl *>(effect->engine);
+    webrtc::GainControl* agc = static_cast<webrtc::GainControl*>(effect->engine);
 #endif
 
     switch (param) {
-    case AGC_PARAM_TARGET_LEVEL:
-    case AGC_PARAM_COMP_GAIN:
-        if (*pValueSize < sizeof(int16_t)) {
-            *pValueSize = 0;
-            return -EINVAL;
-        }
-        break;
-    case AGC_PARAM_LIMITER_ENA:
-        if (*pValueSize < sizeof(bool)) {
-            *pValueSize = 0;
-            return -EINVAL;
-        }
-        break;
-    case AGC_PARAM_PROPERTIES:
-        if (*pValueSize < sizeof(t_agc_settings)) {
-            *pValueSize = 0;
-            return -EINVAL;
-        }
-        break;
+        case AGC_PARAM_TARGET_LEVEL:
+        case AGC_PARAM_COMP_GAIN:
+            if (*pValueSize < sizeof(int16_t)) {
+                *pValueSize = 0;
+                return -EINVAL;
+            }
+            break;
+        case AGC_PARAM_LIMITER_ENA:
+            if (*pValueSize < sizeof(bool)) {
+                *pValueSize = 0;
+                return -EINVAL;
+            }
+            break;
+        case AGC_PARAM_PROPERTIES:
+            if (*pValueSize < sizeof(t_agc_settings)) {
+                *pValueSize = 0;
+                return -EINVAL;
+            }
+            break;
 
-    default:
-        ALOGW("AgcGetParameter() unknown param %08x", param);
-        status = -EINVAL;
-        break;
+        default:
+            ALOGW("AgcGetParameter() unknown param %08x", param);
+            status = -EINVAL;
+            break;
     }
 
 #ifdef WEBRTC_LEGACY
     switch (param) {
-    case AGC_PARAM_TARGET_LEVEL:
-        *(int16_t *) pValue = (int16_t)(agc->target_level_dbfs() * -100);
-        ALOGV("AgcGetParameter() target level %d milliBels", *(int16_t *) pValue);
-        break;
-    case AGC_PARAM_COMP_GAIN:
-        *(int16_t *) pValue = (int16_t)(agc->compression_gain_db() * 100);
-        ALOGV("AgcGetParameter() comp gain %d milliBels", *(int16_t *) pValue);
-        break;
-    case AGC_PARAM_LIMITER_ENA:
-        *(bool *) pValue = (bool)agc->is_limiter_enabled();
-        ALOGV("AgcGetParameter() limiter enabled %s",
-             (*(int16_t *) pValue != 0) ? "true" : "false");
-        break;
-    case AGC_PARAM_PROPERTIES:
-        pProperties->targetLevel = (int16_t)(agc->target_level_dbfs() * -100);
-        pProperties->compGain = (int16_t)(agc->compression_gain_db() * 100);
-        pProperties->limiterEnabled = (bool)agc->is_limiter_enabled();
-        break;
-    default:
-        ALOGW("AgcGetParameter() unknown param %d", param);
-        status = -EINVAL;
-        break;
+        case AGC_PARAM_TARGET_LEVEL:
+            *(int16_t*)pValue = (int16_t)(agc->target_level_dbfs() * -100);
+            ALOGV("AgcGetParameter() target level %d milliBels", *(int16_t*)pValue);
+            break;
+        case AGC_PARAM_COMP_GAIN:
+            *(int16_t*)pValue = (int16_t)(agc->compression_gain_db() * 100);
+            ALOGV("AgcGetParameter() comp gain %d milliBels", *(int16_t*)pValue);
+            break;
+        case AGC_PARAM_LIMITER_ENA:
+            *(bool*)pValue = (bool)agc->is_limiter_enabled();
+            ALOGV("AgcGetParameter() limiter enabled %s",
+                  (*(int16_t*)pValue != 0) ? "true" : "false");
+            break;
+        case AGC_PARAM_PROPERTIES:
+            pProperties->targetLevel = (int16_t)(agc->target_level_dbfs() * -100);
+            pProperties->compGain = (int16_t)(agc->compression_gain_db() * 100);
+            pProperties->limiterEnabled = (bool)agc->is_limiter_enabled();
+            break;
+        default:
+            ALOGW("AgcGetParameter() unknown param %d", param);
+            status = -EINVAL;
+            break;
     }
 #else
     effect->session->config = effect->session->apm->GetConfig();
     switch (param) {
-    case AGC_PARAM_TARGET_LEVEL:
-        *(int16_t *) pValue =
-                (int16_t)(effect->session->config.gain_controller1.target_level_dbfs * -100);
-        ALOGV("AgcGetParameter() target level %d milliBels", *(int16_t *) pValue);
-        break;
-    case AGC_PARAM_COMP_GAIN:
-        *(int16_t *) pValue =
-                (int16_t)(effect->session->config.gain_controller1.compression_gain_db * -100);
-        ALOGV("AgcGetParameter() comp gain %d milliBels", *(int16_t *) pValue);
-        break;
-    case AGC_PARAM_LIMITER_ENA:
-        *(bool *) pValue =
-                (bool)(effect->session->config.gain_controller1.enable_limiter);
-        ALOGV("AgcGetParameter() limiter enabled %s",
-                (*(int16_t *) pValue != 0) ? "true" : "false");
-        break;
-    case AGC_PARAM_PROPERTIES:
-        pProperties->targetLevel =
-                (int16_t)(effect->session->config.gain_controller1.target_level_dbfs * -100);
-        pProperties->compGain =
-                (int16_t)(effect->session->config.gain_controller1.compression_gain_db * -100);
-        pProperties->limiterEnabled =
-                (bool)(effect->session->config.gain_controller1.enable_limiter);
-        break;
-    default:
-        ALOGW("AgcGetParameter() unknown param %d", param);
-        status = -EINVAL;
-        break;
+        case AGC_PARAM_TARGET_LEVEL:
+            *(int16_t*)pValue =
+                    (int16_t)(effect->session->config.gain_controller1.target_level_dbfs * -100);
+            ALOGV("AgcGetParameter() target level %d milliBels", *(int16_t*)pValue);
+            break;
+        case AGC_PARAM_COMP_GAIN:
+            *(int16_t*)pValue =
+                    (int16_t)(effect->session->config.gain_controller1.compression_gain_db * -100);
+            ALOGV("AgcGetParameter() comp gain %d milliBels", *(int16_t*)pValue);
+            break;
+        case AGC_PARAM_LIMITER_ENA:
+            *(bool*)pValue = (bool)(effect->session->config.gain_controller1.enable_limiter);
+            ALOGV("AgcGetParameter() limiter enabled %s",
+                  (*(int16_t*)pValue != 0) ? "true" : "false");
+            break;
+        case AGC_PARAM_PROPERTIES:
+            pProperties->targetLevel =
+                    (int16_t)(effect->session->config.gain_controller1.target_level_dbfs * -100);
+            pProperties->compGain =
+                    (int16_t)(effect->session->config.gain_controller1.compression_gain_db * -100);
+            pProperties->limiterEnabled =
+                    (bool)(effect->session->config.gain_controller1.enable_limiter);
+            break;
+        default:
+            ALOGW("AgcGetParameter() unknown param %d", param);
+            status = -EINVAL;
+            break;
     }
 #endif
     return status;
 }
 
 #ifndef WEBRTC_LEGACY
-int Agc2SetParameter (preproc_effect_t *effect, void *pParam, void *pValue)
-{
+int Agc2SetParameter(preproc_effect_t* effect, void* pParam, void* pValue) {
     int status = 0;
-    uint32_t param = *(uint32_t *)pParam;
+    uint32_t param = *(uint32_t*)pParam;
     float valueFloat = 0.f;
-    agc2_settings_t *pProperties = (agc2_settings_t *)pValue;
+    agc2_settings_t* pProperties = (agc2_settings_t*)pValue;
     effect->session->config = effect->session->apm->GetConfig();
     switch (param) {
-    case AGC2_PARAM_FIXED_DIGITAL_GAIN:
-        valueFloat = (float)(*(int32_t *) pValue);
-        ALOGV("Agc2SetParameter() fixed digital gain %f dB", valueFloat);
-        effect->session->config.gain_controller2.fixed_digital.gain_db = valueFloat;
-        break;
-    case AGC2_PARAM_ADAPT_DIGI_LEVEL_ESTIMATOR:
-        ALOGV("Agc2SetParameter() level estimator %d", *(webrtc::AudioProcessing::Config::
-                GainController2::LevelEstimator *) pValue);
-        effect->session->config.gain_controller2.adaptive_digital.level_estimator =
-                (*(webrtc::AudioProcessing::Config::GainController2::LevelEstimator *) pValue);
-        break;
-    case AGC2_PARAM_ADAPT_DIGI_EXTRA_SATURATION_MARGIN:
-        valueFloat = (float)(*(int32_t *) pValue);
-        ALOGV("Agc2SetParameter() extra saturation margin %f dB", valueFloat);
-        effect->session->config.gain_controller2.adaptive_digital.extra_saturation_margin_db =
-                valueFloat;
-        break;
-    case AGC2_PARAM_PROPERTIES:
-        ALOGV("Agc2SetParameter() properties gain %f, level %d margin %f",
-                pProperties->fixedDigitalGain,
-                pProperties->level_estimator,
-                pProperties->extraSaturationMargin);
-        effect->session->config.gain_controller2.fixed_digital.gain_db =
-                pProperties->fixedDigitalGain;
-        effect->session->config.gain_controller2.adaptive_digital.level_estimator =
-                (webrtc::AudioProcessing::Config::GainController2::LevelEstimator)pProperties->
-                level_estimator;
-        effect->session->config.gain_controller2.adaptive_digital.extra_saturation_margin_db =
-                pProperties->extraSaturationMargin;
-        break;
-    default:
-        ALOGW("Agc2SetParameter() unknown param %08x value %08x", param, *(uint32_t *)pValue);
-        status = -EINVAL;
-        break;
+        case AGC2_PARAM_FIXED_DIGITAL_GAIN:
+            valueFloat = (float)(*(int32_t*)pValue);
+            ALOGV("Agc2SetParameter() fixed digital gain %f dB", valueFloat);
+            effect->session->config.gain_controller2.fixed_digital.gain_db = valueFloat;
+            break;
+        case AGC2_PARAM_ADAPT_DIGI_LEVEL_ESTIMATOR:
+            ALOGV("Agc2SetParameter() level estimator %d",
+                  *(webrtc::AudioProcessing::Config::GainController2::LevelEstimator*)pValue);
+            effect->session->config.gain_controller2.adaptive_digital.level_estimator =
+                    (*(webrtc::AudioProcessing::Config::GainController2::LevelEstimator*)pValue);
+            break;
+        case AGC2_PARAM_ADAPT_DIGI_EXTRA_SATURATION_MARGIN:
+            valueFloat = (float)(*(int32_t*)pValue);
+            ALOGV("Agc2SetParameter() extra saturation margin %f dB", valueFloat);
+            effect->session->config.gain_controller2.adaptive_digital.extra_saturation_margin_db =
+                    valueFloat;
+            break;
+        case AGC2_PARAM_PROPERTIES:
+            ALOGV("Agc2SetParameter() properties gain %f, level %d margin %f",
+                  pProperties->fixedDigitalGain, pProperties->level_estimator,
+                  pProperties->extraSaturationMargin);
+            effect->session->config.gain_controller2.fixed_digital.gain_db =
+                    pProperties->fixedDigitalGain;
+            effect->session->config.gain_controller2.adaptive_digital.level_estimator =
+                    (webrtc::AudioProcessing::Config::GainController2::LevelEstimator)
+                            pProperties->level_estimator;
+            effect->session->config.gain_controller2.adaptive_digital.extra_saturation_margin_db =
+                    pProperties->extraSaturationMargin;
+            break;
+        default:
+            ALOGW("Agc2SetParameter() unknown param %08x value %08x", param, *(uint32_t*)pValue);
+            status = -EINVAL;
+            break;
     }
     effect->session->apm->ApplyConfig(effect->session->config);
 
@@ -605,79 +569,72 @@
 }
 #endif
 
-int AgcSetParameter (preproc_effect_t *effect, void *pParam, void *pValue)
-{
+int AgcSetParameter(preproc_effect_t* effect, void* pParam, void* pValue) {
     int status = 0;
 #ifdef WEBRTC_LEGACY
-    uint32_t param = *(uint32_t *)pParam;
-    t_agc_settings *pProperties = (t_agc_settings *)pValue;
-    webrtc::GainControl *agc = static_cast<webrtc::GainControl *>(effect->engine);
+    uint32_t param = *(uint32_t*)pParam;
+    t_agc_settings* pProperties = (t_agc_settings*)pValue;
+    webrtc::GainControl* agc = static_cast<webrtc::GainControl*>(effect->engine);
 
     switch (param) {
-    case AGC_PARAM_TARGET_LEVEL:
-        ALOGV("AgcSetParameter() target level %d milliBels", *(int16_t *)pValue);
-        status = agc->set_target_level_dbfs(-(*(int16_t *)pValue / 100));
-        break;
-    case AGC_PARAM_COMP_GAIN:
-        ALOGV("AgcSetParameter() comp gain %d milliBels", *(int16_t *)pValue);
-        status = agc->set_compression_gain_db(*(int16_t *)pValue / 100);
-        break;
-    case AGC_PARAM_LIMITER_ENA:
-        ALOGV("AgcSetParameter() limiter enabled %s", *(bool *)pValue ? "true" : "false");
-        status = agc->enable_limiter(*(bool *)pValue);
-        break;
-    case AGC_PARAM_PROPERTIES:
-        ALOGV("AgcSetParameter() properties level %d, gain %d limiter %d",
-             pProperties->targetLevel,
-             pProperties->compGain,
-             pProperties->limiterEnabled);
-        status = agc->set_target_level_dbfs(-(pProperties->targetLevel / 100));
-        if (status != 0) break;
-        status = agc->set_compression_gain_db(pProperties->compGain / 100);
-        if (status != 0) break;
-        status = agc->enable_limiter(pProperties->limiterEnabled);
-        break;
-    default:
-        ALOGW("AgcSetParameter() unknown param %08x value %08x", param, *(uint32_t *)pValue);
-        status = -EINVAL;
-        break;
+        case AGC_PARAM_TARGET_LEVEL:
+            ALOGV("AgcSetParameter() target level %d milliBels", *(int16_t*)pValue);
+            status = agc->set_target_level_dbfs(-(*(int16_t*)pValue / 100));
+            break;
+        case AGC_PARAM_COMP_GAIN:
+            ALOGV("AgcSetParameter() comp gain %d milliBels", *(int16_t*)pValue);
+            status = agc->set_compression_gain_db(*(int16_t*)pValue / 100);
+            break;
+        case AGC_PARAM_LIMITER_ENA:
+            ALOGV("AgcSetParameter() limiter enabled %s", *(bool*)pValue ? "true" : "false");
+            status = agc->enable_limiter(*(bool*)pValue);
+            break;
+        case AGC_PARAM_PROPERTIES:
+            ALOGV("AgcSetParameter() properties level %d, gain %d limiter %d",
+                  pProperties->targetLevel, pProperties->compGain, pProperties->limiterEnabled);
+            status = agc->set_target_level_dbfs(-(pProperties->targetLevel / 100));
+            if (status != 0) break;
+            status = agc->set_compression_gain_db(pProperties->compGain / 100);
+            if (status != 0) break;
+            status = agc->enable_limiter(pProperties->limiterEnabled);
+            break;
+        default:
+            ALOGW("AgcSetParameter() unknown param %08x value %08x", param, *(uint32_t*)pValue);
+            status = -EINVAL;
+            break;
     }
 #else
-    uint32_t param = *(uint32_t *)pParam;
-    t_agc_settings *pProperties = (t_agc_settings *)pValue;
+    uint32_t param = *(uint32_t*)pParam;
+    t_agc_settings* pProperties = (t_agc_settings*)pValue;
     effect->session->config = effect->session->apm->GetConfig();
     switch (param) {
-    case AGC_PARAM_TARGET_LEVEL:
-        ALOGV("AgcSetParameter() target level %d milliBels", *(int16_t *)pValue);
-        effect->session->config.gain_controller1.target_level_dbfs =
-             (-(*(int16_t *)pValue / 100));
-        break;
-    case AGC_PARAM_COMP_GAIN:
-        ALOGV("AgcSetParameter() comp gain %d milliBels", *(int16_t *)pValue);
-        effect->session->config.gain_controller1.compression_gain_db =
-             (*(int16_t *)pValue / 100);
-        break;
-    case AGC_PARAM_LIMITER_ENA:
-        ALOGV("AgcSetParameter() limiter enabled %s", *(bool *)pValue ? "true" : "false");
-        effect->session->config.gain_controller1.enable_limiter =
-             (*(bool *)pValue);
-        break;
-    case AGC_PARAM_PROPERTIES:
-        ALOGV("AgcSetParameter() properties level %d, gain %d limiter %d",
-              pProperties->targetLevel,
-              pProperties->compGain,
-              pProperties->limiterEnabled);
-        effect->session->config.gain_controller1.target_level_dbfs =
-              -(pProperties->targetLevel / 100);
-        effect->session->config.gain_controller1.compression_gain_db =
-              pProperties->compGain / 100;
-        effect->session->config.gain_controller1.enable_limiter =
-              pProperties->limiterEnabled;
-        break;
-    default:
-        ALOGW("AgcSetParameter() unknown param %08x value %08x", param, *(uint32_t *)pValue);
-        status = -EINVAL;
-        break;
+        case AGC_PARAM_TARGET_LEVEL:
+            ALOGV("AgcSetParameter() target level %d milliBels", *(int16_t*)pValue);
+            effect->session->config.gain_controller1.target_level_dbfs =
+                    (-(*(int16_t*)pValue / 100));
+            break;
+        case AGC_PARAM_COMP_GAIN:
+            ALOGV("AgcSetParameter() comp gain %d milliBels", *(int16_t*)pValue);
+            effect->session->config.gain_controller1.compression_gain_db =
+                    (*(int16_t*)pValue / 100);
+            break;
+        case AGC_PARAM_LIMITER_ENA:
+            ALOGV("AgcSetParameter() limiter enabled %s", *(bool*)pValue ? "true" : "false");
+            effect->session->config.gain_controller1.enable_limiter = (*(bool*)pValue);
+            break;
+        case AGC_PARAM_PROPERTIES:
+            ALOGV("AgcSetParameter() properties level %d, gain %d limiter %d",
+                  pProperties->targetLevel, pProperties->compGain, pProperties->limiterEnabled);
+            effect->session->config.gain_controller1.target_level_dbfs =
+                    -(pProperties->targetLevel / 100);
+            effect->session->config.gain_controller1.compression_gain_db =
+                    pProperties->compGain / 100;
+            effect->session->config.gain_controller1.enable_limiter = pProperties->limiterEnabled;
+            break;
+        default:
+            ALOGW("AgcSetParameter() unknown param %08x value %08x", param, *(uint32_t*)pValue);
+            status = -EINVAL;
+            break;
     }
     effect->session->apm->ApplyConfig(effect->session->config);
 #endif
@@ -688,18 +645,16 @@
 }
 
 #ifndef WEBRTC_LEGACY
-void Agc2Enable(preproc_effect_t *effect)
-{
+void Agc2Enable(preproc_effect_t* effect) {
     effect->session->config = effect->session->apm->GetConfig();
     effect->session->config.gain_controller2.enabled = true;
     effect->session->apm->ApplyConfig(effect->session->config);
 }
 #endif
 
-void AgcEnable(preproc_effect_t *effect)
-{
+void AgcEnable(preproc_effect_t* effect) {
 #ifdef WEBRTC_LEGACY
-    webrtc::GainControl *agc = static_cast<webrtc::GainControl *>(effect->engine);
+    webrtc::GainControl* agc = static_cast<webrtc::GainControl*>(effect->engine);
     ALOGV("AgcEnable agc %p", agc);
     agc->Enable(true);
 #else
@@ -710,19 +665,17 @@
 }
 
 #ifndef WEBRTC_LEGACY
-void Agc2Disable(preproc_effect_t *effect)
-{
+void Agc2Disable(preproc_effect_t* effect) {
     effect->session->config = effect->session->apm->GetConfig();
     effect->session->config.gain_controller2.enabled = false;
     effect->session->apm->ApplyConfig(effect->session->config);
 }
 #endif
 
-void AgcDisable(preproc_effect_t *effect)
-{
+void AgcDisable(preproc_effect_t* effect) {
 #ifdef WEBRTC_LEGACY
     ALOGV("AgcDisable");
-    webrtc::GainControl *agc = static_cast<webrtc::GainControl *>(effect->engine);
+    webrtc::GainControl* agc = static_cast<webrtc::GainControl*>(effect->engine);
     agc->Enable(false);
 #else
     effect->session->config = effect->session->apm->GetConfig();
@@ -731,28 +684,13 @@
 #endif
 }
 
-static const preproc_ops_t sAgcOps = {
-        AgcCreate,
-        AgcInit,
-        NULL,
-        AgcEnable,
-        AgcDisable,
-        AgcSetParameter,
-        AgcGetParameter,
-        NULL
-};
+static const preproc_ops_t sAgcOps = {AgcCreate,       AgcInit,         NULL, AgcEnable, AgcDisable,
+                                      AgcSetParameter, AgcGetParameter, NULL};
 
 #ifndef WEBRTC_LEGACY
-static const preproc_ops_t sAgc2Ops = {
-        Agc2Create,
-        Agc2Init,
-        NULL,
-        Agc2Enable,
-        Agc2Disable,
-        Agc2SetParameter,
-        Agc2GetParameter,
-        NULL
-};
+static const preproc_ops_t sAgc2Ops = {Agc2Create,       Agc2Init,    NULL,
+                                       Agc2Enable,       Agc2Disable, Agc2SetParameter,
+                                       Agc2GetParameter, NULL};
 #endif
 
 //------------------------------------------------------------------------------
@@ -765,26 +703,23 @@
 static const bool kAecDefaultComfortNoise = true;
 #endif
 
-int  AecInit (preproc_effect_t *effect)
-{
+int AecInit(preproc_effect_t* effect) {
     ALOGV("AecInit");
 #ifdef WEBRTC_LEGACY
-    webrtc::EchoControlMobile *aec = static_cast<webrtc::EchoControlMobile *>(effect->engine);
+    webrtc::EchoControlMobile* aec = static_cast<webrtc::EchoControlMobile*>(effect->engine);
     aec->set_routing_mode(kAecDefaultMode);
     aec->enable_comfort_noise(kAecDefaultComfortNoise);
 #else
-    effect->session->config =
-        effect->session->apm->GetConfig() ;
-    effect->session->config.echo_canceller.mobile_mode = false;
+    effect->session->config = effect->session->apm->GetConfig();
+    effect->session->config.echo_canceller.mobile_mode = true;
     effect->session->apm->ApplyConfig(effect->session->config);
 #endif
     return 0;
 }
 
-int  AecCreate(preproc_effect_t *effect)
-{
+int AecCreate(preproc_effect_t* effect) {
 #ifdef WEBRTC_LEGACY
-    webrtc::EchoControlMobile *aec = effect->session->apm->echo_control_mobile();
+    webrtc::EchoControlMobile* aec = effect->session->apm->echo_control_mobile();
     ALOGV("AecCreate got aec %p", aec);
     if (aec == NULL) {
         ALOGW("AgcCreate Error");
@@ -792,76 +727,68 @@
     }
     effect->engine = static_cast<preproc_fx_handle_t>(aec);
 #endif
-    AecInit (effect);
+    AecInit(effect);
     return 0;
 }
 
-int AecGetParameter(preproc_effect_t  *effect,
-                    void              *pParam,
-                    uint32_t          *pValueSize,
-                    void              *pValue)
-{
+int AecGetParameter(preproc_effect_t* effect, void* pParam, uint32_t* pValueSize, void* pValue) {
     int status = 0;
-    uint32_t param = *(uint32_t *)pParam;
+    uint32_t param = *(uint32_t*)pParam;
 
     if (*pValueSize < sizeof(uint32_t)) {
         return -EINVAL;
     }
     switch (param) {
-    case AEC_PARAM_ECHO_DELAY:
-    case AEC_PARAM_PROPERTIES:
-        *(uint32_t *)pValue = 1000 * effect->session->apm->stream_delay_ms();
-        ALOGV("AecGetParameter() echo delay %d us", *(uint32_t *)pValue);
-        break;
+        case AEC_PARAM_ECHO_DELAY:
+        case AEC_PARAM_PROPERTIES:
+            *(uint32_t*)pValue = 1000 * effect->session->apm->stream_delay_ms();
+            ALOGV("AecGetParameter() echo delay %d us", *(uint32_t*)pValue);
+            break;
 #ifndef WEBRTC_LEGACY
-    case AEC_PARAM_MOBILE_MODE:
-        effect->session->config =
-            effect->session->apm->GetConfig() ;
-        *(uint32_t *)pValue = effect->session->config.echo_canceller.mobile_mode;
-        ALOGV("AecGetParameter() mobile mode %d us", *(uint32_t *)pValue);
-        break;
+        case AEC_PARAM_MOBILE_MODE:
+            effect->session->config = effect->session->apm->GetConfig();
+            *(uint32_t*)pValue = effect->session->config.echo_canceller.mobile_mode;
+            ALOGV("AecGetParameter() mobile mode %d us", *(uint32_t*)pValue);
+            break;
 #endif
-    default:
-        ALOGW("AecGetParameter() unknown param %08x value %08x", param, *(uint32_t *)pValue);
-        status = -EINVAL;
-        break;
+        default:
+            ALOGW("AecGetParameter() unknown param %08x value %08x", param, *(uint32_t*)pValue);
+            status = -EINVAL;
+            break;
     }
     return status;
 }
 
-int AecSetParameter (preproc_effect_t *effect, void *pParam, void *pValue)
-{
+int AecSetParameter(preproc_effect_t* effect, void* pParam, void* pValue) {
     int status = 0;
-    uint32_t param = *(uint32_t *)pParam;
-    uint32_t value = *(uint32_t *)pValue;
+    uint32_t param = *(uint32_t*)pParam;
+    uint32_t value = *(uint32_t*)pValue;
 
     switch (param) {
-    case AEC_PARAM_ECHO_DELAY:
-    case AEC_PARAM_PROPERTIES:
-        status = effect->session->apm->set_stream_delay_ms(value/1000);
-        ALOGV("AecSetParameter() echo delay %d us, status %d", value, status);
-        break;
+        case AEC_PARAM_ECHO_DELAY:
+        case AEC_PARAM_PROPERTIES:
+            status = effect->session->apm->set_stream_delay_ms(value / 1000);
+            ALOGV("AecSetParameter() echo delay %d us, status %d", value, status);
+            break;
 #ifndef WEBRTC_LEGACY
-    case AEC_PARAM_MOBILE_MODE:
-        effect->session->config =
-            effect->session->apm->GetConfig() ;
-        effect->session->config.echo_canceller.mobile_mode = value;
-        ALOGV("AecSetParameter() mobile mode %d us", value);
-        effect->session->apm->ApplyConfig(effect->session->config);
-        break;
+        case AEC_PARAM_MOBILE_MODE:
+            effect->session->config = effect->session->apm->GetConfig();
+            effect->session->config.echo_canceller.mobile_mode = value;
+            ALOGV("AecSetParameter() mobile mode %d us", value);
+            effect->session->apm->ApplyConfig(effect->session->config);
+            break;
 #endif
-    default:
-        ALOGW("AecSetParameter() unknown param %08x value %08x", param, *(uint32_t *)pValue);
-        status = -EINVAL;
-        break;
+        default:
+            ALOGW("AecSetParameter() unknown param %08x value %08x", param, *(uint32_t*)pValue);
+            status = -EINVAL;
+            break;
     }
     return status;
 }
 
-void AecEnable(preproc_effect_t *effect)
-{
+void AecEnable(preproc_effect_t* effect) {
 #ifdef WEBRTC_LEGACY
-    webrtc::EchoControlMobile *aec = static_cast<webrtc::EchoControlMobile *>(effect->engine);
+    webrtc::EchoControlMobile* aec = static_cast<webrtc::EchoControlMobile*>(effect->engine);
     ALOGV("AecEnable aec %p", aec);
     aec->Enable(true);
 #else
@@ -871,11 +798,10 @@
 #endif
 }
 
-void AecDisable(preproc_effect_t *effect)
-{
+void AecDisable(preproc_effect_t* effect) {
 #ifdef WEBRTC_LEGACY
     ALOGV("AecDisable");
-    webrtc::EchoControlMobile *aec = static_cast<webrtc::EchoControlMobile *>(effect->engine);
+    webrtc::EchoControlMobile* aec = static_cast<webrtc::EchoControlMobile*>(effect->engine);
     aec->Enable(false);
 #else
     effect->session->config = effect->session->apm->GetConfig();
@@ -884,12 +810,12 @@
 #endif
 }
 
-int AecSetDevice(preproc_effect_t *effect, uint32_t device)
-{
+int AecSetDevice(preproc_effect_t* effect, uint32_t device) {
     ALOGV("AecSetDevice %08x", device);
 #ifdef WEBRTC_LEGACY
-    webrtc::EchoControlMobile *aec = static_cast<webrtc::EchoControlMobile *>(effect->engine);
-    webrtc::EchoControlMobile::RoutingMode mode = webrtc::EchoControlMobile::kQuietEarpieceOrHeadset;
+    webrtc::EchoControlMobile* aec = static_cast<webrtc::EchoControlMobile*>(effect->engine);
+    webrtc::EchoControlMobile::RoutingMode mode =
+            webrtc::EchoControlMobile::kQuietEarpieceOrHeadset;
 #endif
 
     if (audio_is_input_device(device)) {
@@ -897,34 +823,27 @@
     }
 
 #ifdef WEBRTC_LEGACY
-    switch(device) {
-    case AUDIO_DEVICE_OUT_EARPIECE:
-        mode = webrtc::EchoControlMobile::kEarpiece;
-        break;
-    case AUDIO_DEVICE_OUT_SPEAKER:
-        mode = webrtc::EchoControlMobile::kSpeakerphone;
-        break;
-    case AUDIO_DEVICE_OUT_WIRED_HEADSET:
-    case AUDIO_DEVICE_OUT_WIRED_HEADPHONE:
-    case AUDIO_DEVICE_OUT_USB_HEADSET:
-    default:
-        break;
+    switch (device) {
+        case AUDIO_DEVICE_OUT_EARPIECE:
+            mode = webrtc::EchoControlMobile::kEarpiece;
+            break;
+        case AUDIO_DEVICE_OUT_SPEAKER:
+            mode = webrtc::EchoControlMobile::kSpeakerphone;
+            break;
+        case AUDIO_DEVICE_OUT_WIRED_HEADSET:
+        case AUDIO_DEVICE_OUT_WIRED_HEADPHONE:
+        case AUDIO_DEVICE_OUT_USB_HEADSET:
+        default:
+            break;
     }
     aec->set_routing_mode(mode);
 #endif
     return 0;
 }
 
-static const preproc_ops_t sAecOps = {
-        AecCreate,
-        AecInit,
-        NULL,
-        AecEnable,
-        AecDisable,
-        AecSetParameter,
-        AecGetParameter,
-        AecSetDevice
-};
+static const preproc_ops_t sAecOps = {AecCreate,       AecInit,     NULL,
+                                      AecEnable,       AecDisable,  AecSetParameter,
+                                      AecGetParameter, AecSetDevice};
 
 //------------------------------------------------------------------------------
 // Noise Suppression (NS)
@@ -934,14 +853,13 @@
 static const webrtc::NoiseSuppression::Level kNsDefaultLevel = webrtc::NoiseSuppression::kModerate;
 #else
 static const webrtc::AudioProcessing::Config::NoiseSuppression::Level kNsDefaultLevel =
-                webrtc::AudioProcessing::Config::NoiseSuppression::kModerate;
+        webrtc::AudioProcessing::Config::NoiseSuppression::kModerate;
 #endif
 
-int  NsInit (preproc_effect_t *effect)
-{
+int NsInit(preproc_effect_t* effect) {
     ALOGV("NsInit");
 #ifdef WEBRTC_LEGACY
-    webrtc::NoiseSuppression *ns = static_cast<webrtc::NoiseSuppression *>(effect->engine);
+    webrtc::NoiseSuppression* ns = static_cast<webrtc::NoiseSuppression*>(effect->engine);
     ns->set_level(kNsDefaultLevel);
     webrtc::Config config;
     std::vector<webrtc::Point> geometry;
@@ -951,27 +869,22 @@
     geometry.push_back(webrtc::Point(0.01f, 0.f, 0.f));
     geometry.push_back(webrtc::Point(0.03f, 0.f, 0.f));
     // The geometry needs to be set with Beamforming enabled.
-    config.Set<webrtc::Beamforming>(
-            new webrtc::Beamforming(true, geometry));
+    config.Set<webrtc::Beamforming>(new webrtc::Beamforming(true, geometry));
     effect->session->apm->SetExtraOptions(config);
-    config.Set<webrtc::Beamforming>(
-            new webrtc::Beamforming(false, geometry));
+    config.Set<webrtc::Beamforming>(new webrtc::Beamforming(false, geometry));
     effect->session->apm->SetExtraOptions(config);
 #else
-    effect->session->config =
-        effect->session->apm->GetConfig() ;
-    effect->session->config.noise_suppression.level =
-        kNsDefaultLevel;
+    effect->session->config = effect->session->apm->GetConfig();
+    effect->session->config.noise_suppression.level = kNsDefaultLevel;
     effect->session->apm->ApplyConfig(effect->session->config);
 #endif
     effect->type = NS_TYPE_SINGLE_CHANNEL;
     return 0;
 }
 
-int  NsCreate(preproc_effect_t *effect)
-{
+int NsCreate(preproc_effect_t* effect) {
 #ifdef WEBRTC_LEGACY
-    webrtc::NoiseSuppression *ns = effect->session->apm->noise_suppression();
+    webrtc::NoiseSuppression* ns = effect->session->apm->noise_suppression();
     ALOGV("NsCreate got ns %p", ns);
     if (ns == NULL) {
         ALOGW("AgcCreate Error");
@@ -979,37 +892,31 @@
     }
     effect->engine = static_cast<preproc_fx_handle_t>(ns);
 #endif
-    NsInit (effect);
+    NsInit(effect);
     return 0;
 }
 
-int NsGetParameter(preproc_effect_t  *effect __unused,
-                   void              *pParam __unused,
-                   uint32_t          *pValueSize __unused,
-                   void              *pValue __unused)
-{
+int NsGetParameter(preproc_effect_t* effect __unused, void* pParam __unused,
+                   uint32_t* pValueSize __unused, void* pValue __unused) {
     int status = 0;
     return status;
 }
 
-int NsSetParameter (preproc_effect_t *effect, void *pParam, void *pValue)
-{
+int NsSetParameter(preproc_effect_t* effect, void* pParam, void* pValue) {
     int status = 0;
 #ifdef WEBRTC_LEGACY
-    webrtc::NoiseSuppression *ns = static_cast<webrtc::NoiseSuppression *>(effect->engine);
-    uint32_t param = *(uint32_t *)pParam;
-    uint32_t value = *(uint32_t *)pValue;
-    switch(param) {
+    webrtc::NoiseSuppression* ns = static_cast<webrtc::NoiseSuppression*>(effect->engine);
+    uint32_t param = *(uint32_t*)pParam;
+    uint32_t value = *(uint32_t*)pValue;
+    switch (param) {
         case NS_PARAM_LEVEL:
             ns->set_level((webrtc::NoiseSuppression::Level)value);
             ALOGV("NsSetParameter() level %d", value);
             break;
-        case NS_PARAM_TYPE:
-        {
+        case NS_PARAM_TYPE: {
             webrtc::Config config;
             std::vector<webrtc::Point> geometry;
-            bool is_beamforming_enabled =
-                    value == NS_TYPE_MULTI_CHANNEL && ns->is_enabled();
+            bool is_beamforming_enabled = value == NS_TYPE_MULTI_CHANNEL && ns->is_enabled();
             config.Set<webrtc::Beamforming>(
                     new webrtc::Beamforming(is_beamforming_enabled, geometry));
             effect->session->apm->SetExtraOptions(config);
@@ -1022,14 +929,13 @@
             status = -EINVAL;
     }
 #else
-    uint32_t param = *(uint32_t *)pParam;
-    uint32_t value = *(uint32_t *)pValue;
-    effect->session->config =
-        effect->session->apm->GetConfig();
+    uint32_t param = *(uint32_t*)pParam;
+    uint32_t value = *(uint32_t*)pValue;
+    effect->session->config = effect->session->apm->GetConfig();
     switch (param) {
         case NS_PARAM_LEVEL:
             effect->session->config.noise_suppression.level =
-               (webrtc::AudioProcessing::Config::NoiseSuppression::Level)value;
+                    (webrtc::AudioProcessing::Config::NoiseSuppression::Level)value;
             ALOGV("NsSetParameter() level %d", value);
             break;
         default:
@@ -1042,10 +948,9 @@
     return status;
 }
 
-void NsEnable(preproc_effect_t *effect)
-{
+void NsEnable(preproc_effect_t* effect) {
 #ifdef WEBRTC_LEGACY
-    webrtc::NoiseSuppression *ns = static_cast<webrtc::NoiseSuppression *>(effect->engine);
+    webrtc::NoiseSuppression* ns = static_cast<webrtc::NoiseSuppression*>(effect->engine);
     ALOGV("NsEnable ns %p", ns);
     ns->Enable(true);
     if (effect->type == NS_TYPE_MULTI_CHANNEL) {
@@ -1055,137 +960,118 @@
         effect->session->apm->SetExtraOptions(config);
     }
 #else
-    effect->session->config =
-        effect->session->apm->GetConfig();
+    effect->session->config = effect->session->apm->GetConfig();
     effect->session->config.noise_suppression.enabled = true;
     effect->session->apm->ApplyConfig(effect->session->config);
 #endif
 }
 
-void NsDisable(preproc_effect_t *effect)
-{
+void NsDisable(preproc_effect_t* effect) {
     ALOGV("NsDisable");
 #ifdef WEBRTC_LEGACY
-    webrtc::NoiseSuppression *ns = static_cast<webrtc::NoiseSuppression *>(effect->engine);
+    webrtc::NoiseSuppression* ns = static_cast<webrtc::NoiseSuppression*>(effect->engine);
     ns->Enable(false);
     webrtc::Config config;
     std::vector<webrtc::Point> geometry;
     config.Set<webrtc::Beamforming>(new webrtc::Beamforming(false, geometry));
     effect->session->apm->SetExtraOptions(config);
 #else
-    effect->session->config =
-        effect->session->apm->GetConfig();
+    effect->session->config = effect->session->apm->GetConfig();
     effect->session->config.noise_suppression.enabled = false;
     effect->session->apm->ApplyConfig(effect->session->config);
 #endif
 }
 
-static const preproc_ops_t sNsOps = {
-        NsCreate,
-        NsInit,
-        NULL,
-        NsEnable,
-        NsDisable,
-        NsSetParameter,
-        NsGetParameter,
-        NULL
-};
+static const preproc_ops_t sNsOps = {NsCreate,  NsInit,         NULL,           NsEnable,
+                                     NsDisable, NsSetParameter, NsGetParameter, NULL};
 
-
-
-static const preproc_ops_t *sPreProcOps[PREPROC_NUM_EFFECTS] = {
-        &sAgcOps,
+static const preproc_ops_t* sPreProcOps[PREPROC_NUM_EFFECTS] = {&sAgcOps,
 #ifndef WEBRTC_LEGACY
-        &sAgc2Ops,
+                                                                &sAgc2Ops,
 #endif
-        &sAecOps,
-        &sNsOps
-};
-
+                                                                &sAecOps, &sNsOps};
 
 //------------------------------------------------------------------------------
 // Effect functions
 //------------------------------------------------------------------------------
 
-void Session_SetProcEnabled(preproc_session_t *session, uint32_t procId, bool enabled);
+void Session_SetProcEnabled(preproc_session_t* session, uint32_t procId, bool enabled);
 
 extern "C" const struct effect_interface_s sEffectInterface;
 extern "C" const struct effect_interface_s sEffectInterfaceReverse;
 
-#define BAD_STATE_ABORT(from, to) \
-        LOG_ALWAYS_FATAL("Bad state transition from %d to %d", from, to);
+#define BAD_STATE_ABORT(from, to) LOG_ALWAYS_FATAL("Bad state transition from %d to %d", from, to);
 
-int Effect_SetState(preproc_effect_t *effect, uint32_t state)
-{
+int Effect_SetState(preproc_effect_t* effect, uint32_t state) {
     int status = 0;
     ALOGV("Effect_SetState proc %d, new %d old %d", effect->procId, state, effect->state);
-    switch(state) {
-    case PREPROC_EFFECT_STATE_INIT:
-        switch(effect->state) {
-        case PREPROC_EFFECT_STATE_ACTIVE:
-            effect->ops->disable(effect);
-            Session_SetProcEnabled(effect->session, effect->procId, false);
+    switch (state) {
+        case PREPROC_EFFECT_STATE_INIT:
+            switch (effect->state) {
+                case PREPROC_EFFECT_STATE_ACTIVE:
+                    effect->ops->disable(effect);
+                    Session_SetProcEnabled(effect->session, effect->procId, false);
+                    break;
+                case PREPROC_EFFECT_STATE_CONFIG:
+                case PREPROC_EFFECT_STATE_CREATED:
+                case PREPROC_EFFECT_STATE_INIT:
+                    break;
+                default:
+                    BAD_STATE_ABORT(effect->state, state);
+            }
+            break;
+        case PREPROC_EFFECT_STATE_CREATED:
+            switch (effect->state) {
+                case PREPROC_EFFECT_STATE_INIT:
+                    status = effect->ops->create(effect);
+                    break;
+                case PREPROC_EFFECT_STATE_CREATED:
+                case PREPROC_EFFECT_STATE_ACTIVE:
+                case PREPROC_EFFECT_STATE_CONFIG:
+                    ALOGE("Effect_SetState invalid transition");
+                    status = -ENOSYS;
+                    break;
+                default:
+                    BAD_STATE_ABORT(effect->state, state);
+            }
             break;
         case PREPROC_EFFECT_STATE_CONFIG:
-        case PREPROC_EFFECT_STATE_CREATED:
-        case PREPROC_EFFECT_STATE_INIT:
+            switch (effect->state) {
+                case PREPROC_EFFECT_STATE_INIT:
+                    ALOGE("Effect_SetState invalid transition");
+                    status = -ENOSYS;
+                    break;
+                case PREPROC_EFFECT_STATE_ACTIVE:
+                    effect->ops->disable(effect);
+                    Session_SetProcEnabled(effect->session, effect->procId, false);
+                    break;
+                case PREPROC_EFFECT_STATE_CREATED:
+                case PREPROC_EFFECT_STATE_CONFIG:
+                    break;
+                default:
+                    BAD_STATE_ABORT(effect->state, state);
+            }
+            break;
+        case PREPROC_EFFECT_STATE_ACTIVE:
+            switch (effect->state) {
+                case PREPROC_EFFECT_STATE_INIT:
+                case PREPROC_EFFECT_STATE_CREATED:
+                    ALOGE("Effect_SetState invalid transition");
+                    status = -ENOSYS;
+                    break;
+                case PREPROC_EFFECT_STATE_ACTIVE:
+                    // enabling an already enabled effect is just ignored
+                    break;
+                case PREPROC_EFFECT_STATE_CONFIG:
+                    effect->ops->enable(effect);
+                    Session_SetProcEnabled(effect->session, effect->procId, true);
+                    break;
+                default:
+                    BAD_STATE_ABORT(effect->state, state);
+            }
             break;
         default:
             BAD_STATE_ABORT(effect->state, state);
-        }
-        break;
-    case PREPROC_EFFECT_STATE_CREATED:
-        switch(effect->state) {
-        case PREPROC_EFFECT_STATE_INIT:
-            status = effect->ops->create(effect);
-            break;
-        case PREPROC_EFFECT_STATE_CREATED:
-        case PREPROC_EFFECT_STATE_ACTIVE:
-        case PREPROC_EFFECT_STATE_CONFIG:
-            ALOGE("Effect_SetState invalid transition");
-            status = -ENOSYS;
-            break;
-        default:
-            BAD_STATE_ABORT(effect->state, state);
-        }
-        break;
-    case PREPROC_EFFECT_STATE_CONFIG:
-        switch(effect->state) {
-        case PREPROC_EFFECT_STATE_INIT:
-            ALOGE("Effect_SetState invalid transition");
-            status = -ENOSYS;
-            break;
-        case PREPROC_EFFECT_STATE_ACTIVE:
-            effect->ops->disable(effect);
-            Session_SetProcEnabled(effect->session, effect->procId, false);
-            break;
-        case PREPROC_EFFECT_STATE_CREATED:
-        case PREPROC_EFFECT_STATE_CONFIG:
-            break;
-        default:
-            BAD_STATE_ABORT(effect->state, state);
-        }
-        break;
-    case PREPROC_EFFECT_STATE_ACTIVE:
-        switch(effect->state) {
-        case PREPROC_EFFECT_STATE_INIT:
-        case PREPROC_EFFECT_STATE_CREATED:
-            ALOGE("Effect_SetState invalid transition");
-            status = -ENOSYS;
-            break;
-        case PREPROC_EFFECT_STATE_ACTIVE:
-            // enabling an already enabled effect is just ignored
-            break;
-        case PREPROC_EFFECT_STATE_CONFIG:
-            effect->ops->enable(effect);
-            Session_SetProcEnabled(effect->session, effect->procId, true);
-            break;
-        default:
-            BAD_STATE_ABORT(effect->state, state);
-        }
-        break;
-    default:
-        BAD_STATE_ABORT(effect->state, state);
     }
     if (status == 0) {
         effect->state = state;
@@ -1193,8 +1079,7 @@
     return status;
 }
 
-int Effect_Init(preproc_effect_t *effect, uint32_t procId)
-{
+int Effect_Init(preproc_effect_t* effect, uint32_t procId) {
     if (HasReverseStream(procId)) {
         effect->itfe = &sEffectInterfaceReverse;
     } else {
@@ -1206,21 +1091,17 @@
     return 0;
 }
 
-int Effect_Create(preproc_effect_t *effect,
-               preproc_session_t *session,
-               effect_handle_t  *interface)
-{
+int Effect_Create(preproc_effect_t* effect, preproc_session_t* session,
+                  effect_handle_t* interface) {
     effect->session = session;
     *interface = (effect_handle_t)&effect->itfe;
     return Effect_SetState(effect, PREPROC_EFFECT_STATE_CREATED);
 }
 
-int Effect_Release(preproc_effect_t *effect)
-{
+int Effect_Release(preproc_effect_t* effect) {
     return Effect_SetState(effect, PREPROC_EFFECT_STATE_INIT);
 }
 
-
 //------------------------------------------------------------------------------
 // Session functions
 //------------------------------------------------------------------------------
@@ -1230,8 +1111,7 @@
 static const int kPreprocDefaultSr = 16000;
 static const int kPreProcDefaultCnl = 1;
 
-int Session_Init(preproc_session_t *session)
-{
+int Session_Init(preproc_session_t* session) {
     size_t i;
     int status = 0;
 
@@ -1248,11 +1128,8 @@
     return status;
 }
 
-
-extern "C" int Session_CreateEffect(preproc_session_t *session,
-                                    int32_t procId,
-                                    effect_handle_t  *interface)
-{
+extern "C" int Session_CreateEffect(preproc_session_t* session, int32_t procId,
+                                    effect_handle_t* interface) {
     int status = -ENOMEM;
 
     ALOGV("Session_CreateEffect procId %d, createdMsk %08x", procId, session->createdMsk);
@@ -1265,10 +1142,10 @@
             goto error;
         }
         const webrtc::ProcessingConfig processing_config = {
-            {{kPreprocDefaultSr, kPreProcDefaultCnl},
-             {kPreprocDefaultSr, kPreProcDefaultCnl},
-             {kPreprocDefaultSr, kPreProcDefaultCnl},
-             {kPreprocDefaultSr, kPreProcDefaultCnl}}};
+                {{kPreprocDefaultSr, kPreProcDefaultCnl},
+                 {kPreprocDefaultSr, kPreProcDefaultCnl},
+                 {kPreprocDefaultSr, kPreProcDefaultCnl},
+                 {kPreprocDefaultSr, kPreProcDefaultCnl}}};
         session->apm->Initialize(processing_config);
         session->procFrame = new webrtc::AudioFrame();
         if (session->procFrame == NULL) {
@@ -1335,7 +1212,7 @@
         goto error;
     }
     ALOGV("Session_CreateEffect OK");
-    session->createdMsk |= (1<<procId);
+    session->createdMsk |= (1 << procId);
     return status;
 
 error:
@@ -1346,7 +1223,7 @@
         delete session->procFrame;
         session->procFrame = NULL;
         delete session->apm;
-        session->apm = NULL; // NOLINT(clang-analyzer-cplusplus.NewDelete)
+        session->apm = NULL;  // NOLINT(clang-analyzer-cplusplus.NewDelete)
 #else
         delete session->apm;
         session->apm = NULL;
@@ -1355,11 +1232,9 @@
     return status;
 }
 
-int Session_ReleaseEffect(preproc_session_t *session,
-                          preproc_effect_t *fx)
-{
+int Session_ReleaseEffect(preproc_session_t* session, preproc_effect_t* fx) {
     ALOGW_IF(Effect_Release(fx) != 0, " Effect_Release() failed for proc ID %d", fx->procId);
-    session->createdMsk &= ~(1<<fx->procId);
+    session->createdMsk &= ~(1 << fx->procId);
     if (session->createdMsk == 0) {
 #ifdef WEBRTC_LEGACY
         delete session->apm;
@@ -1397,9 +1272,7 @@
     return 0;
 }
 
-
-int Session_SetConfig(preproc_session_t *session, effect_config_t *config)
-{
+int Session_SetConfig(preproc_session_t* session, effect_config_t* config) {
     uint32_t inCnl = audio_channel_count_from_in_mask(config->inputCfg.channels);
     uint32_t outCnl = audio_channel_count_from_in_mask(config->outputCfg.channels);
 
@@ -1409,8 +1282,8 @@
         return -EINVAL;
     }
 
-    ALOGV("Session_SetConfig sr %d cnl %08x",
-         config->inputCfg.samplingRate, config->inputCfg.channels);
+    ALOGV("Session_SetConfig sr %d cnl %08x", config->inputCfg.samplingRate,
+          config->inputCfg.channels);
 #ifdef WEBRTC_LEGACY
     int status;
 #endif
@@ -1418,8 +1291,7 @@
     // AEC implementation is limited to 16kHz
     if (config->inputCfg.samplingRate >= 32000 && !(session->createdMsk & (1 << PREPROC_AEC))) {
         session->apmSamplingRate = 32000;
-    } else
-    if (config->inputCfg.samplingRate >= 16000) {
+    } else if (config->inputCfg.samplingRate >= 16000) {
         session->apmSamplingRate = 16000;
     } else if (config->inputCfg.samplingRate >= 8000) {
         session->apmSamplingRate = 8000;
@@ -1427,10 +1299,10 @@
 
 #ifdef WEBRTC_LEGACY
     const webrtc::ProcessingConfig processing_config = {
-      {{static_cast<int>(session->apmSamplingRate), inCnl},
-       {static_cast<int>(session->apmSamplingRate), outCnl},
-       {static_cast<int>(session->apmSamplingRate), inCnl},
-       {static_cast<int>(session->apmSamplingRate), inCnl}}};
+            {{static_cast<int>(session->apmSamplingRate), inCnl},
+             {static_cast<int>(session->apmSamplingRate), outCnl},
+             {static_cast<int>(session->apmSamplingRate), inCnl},
+             {static_cast<int>(session->apmSamplingRate), inCnl}}};
     status = session->apm->Initialize(processing_config);
     if (status < 0) {
         return -EINVAL;
@@ -1443,11 +1315,11 @@
         session->frameCount = session->apmFrameCount;
     } else {
 #ifdef WEBRTC_LEGACY
-        session->frameCount = (session->apmFrameCount * session->samplingRate) /
-                session->apmSamplingRate  + 1;
+        session->frameCount =
+                (session->apmFrameCount * session->samplingRate) / session->apmSamplingRate + 1;
 #else
-        session->frameCount = (session->apmFrameCount * session->samplingRate) /
-                session->apmSamplingRate;
+        session->frameCount =
+                (session->apmFrameCount * session->samplingRate) / session->apmSamplingRate;
 #endif
     }
     session->inChannelCount = inCnl;
@@ -1477,7 +1349,6 @@
     session->framesIn = 0;
     session->framesOut = 0;
 
-
 #ifdef WEBRTC_LEGACY
     if (session->inResampler != NULL) {
         speex_resampler_destroy(session->inResampler);
@@ -1493,36 +1364,30 @@
     }
     if (session->samplingRate != session->apmSamplingRate) {
         int error;
-        session->inResampler = speex_resampler_init(session->inChannelCount,
-                                                    session->samplingRate,
-                                                    session->apmSamplingRate,
-                                                    RESAMPLER_QUALITY,
-                                                    &error);
+        session->inResampler =
+                speex_resampler_init(session->inChannelCount, session->samplingRate,
+                                     session->apmSamplingRate, RESAMPLER_QUALITY, &error);
         if (session->inResampler == NULL) {
             ALOGW("Session_SetConfig Cannot create speex resampler: %s",
-                 speex_resampler_strerror(error));
+                  speex_resampler_strerror(error));
             return -EINVAL;
         }
-        session->outResampler = speex_resampler_init(session->outChannelCount,
-                                                    session->apmSamplingRate,
-                                                    session->samplingRate,
-                                                    RESAMPLER_QUALITY,
-                                                    &error);
+        session->outResampler =
+                speex_resampler_init(session->outChannelCount, session->apmSamplingRate,
+                                     session->samplingRate, RESAMPLER_QUALITY, &error);
         if (session->outResampler == NULL) {
             ALOGW("Session_SetConfig Cannot create speex resampler: %s",
-                 speex_resampler_strerror(error));
+                  speex_resampler_strerror(error));
             speex_resampler_destroy(session->inResampler);
             session->inResampler = NULL;
             return -EINVAL;
         }
-        session->revResampler = speex_resampler_init(session->inChannelCount,
-                                                    session->samplingRate,
-                                                    session->apmSamplingRate,
-                                                    RESAMPLER_QUALITY,
-                                                    &error);
+        session->revResampler =
+                speex_resampler_init(session->inChannelCount, session->samplingRate,
+                                     session->apmSamplingRate, RESAMPLER_QUALITY, &error);
         if (session->revResampler == NULL) {
             ALOGW("Session_SetConfig Cannot create speex resampler: %s",
-                 speex_resampler_strerror(error));
+                  speex_resampler_strerror(error));
             speex_resampler_destroy(session->inResampler);
             session->inResampler = NULL;
             speex_resampler_destroy(session->outResampler);
@@ -1536,8 +1401,7 @@
     return 0;
 }
 
-void Session_GetConfig(preproc_session_t *session, effect_config_t *config)
-{
+void Session_GetConfig(preproc_session_t* session, effect_config_t* config) {
     memset(config, 0, sizeof(effect_config_t));
     config->inputCfg.samplingRate = config->outputCfg.samplingRate = session->samplingRate;
     config->inputCfg.format = config->outputCfg.format = AUDIO_FORMAT_PCM_16_BIT;
@@ -1548,31 +1412,30 @@
             (EFFECT_CONFIG_SMP_RATE | EFFECT_CONFIG_CHANNELS | EFFECT_CONFIG_FORMAT);
 }
 
-int Session_SetReverseConfig(preproc_session_t *session, effect_config_t *config)
-{
+int Session_SetReverseConfig(preproc_session_t* session, effect_config_t* config) {
     if (config->inputCfg.samplingRate != config->outputCfg.samplingRate ||
-            config->inputCfg.format != config->outputCfg.format ||
-            config->inputCfg.format != AUDIO_FORMAT_PCM_16_BIT) {
+        config->inputCfg.format != config->outputCfg.format ||
+        config->inputCfg.format != AUDIO_FORMAT_PCM_16_BIT) {
         return -EINVAL;
     }
 
-    ALOGV("Session_SetReverseConfig sr %d cnl %08x",
-         config->inputCfg.samplingRate, config->inputCfg.channels);
+    ALOGV("Session_SetReverseConfig sr %d cnl %08x", config->inputCfg.samplingRate,
+          config->inputCfg.channels);
 
     if (session->state < PREPROC_SESSION_STATE_CONFIG) {
         return -ENOSYS;
     }
     if (config->inputCfg.samplingRate != session->samplingRate ||
-            config->inputCfg.format != AUDIO_FORMAT_PCM_16_BIT) {
+        config->inputCfg.format != AUDIO_FORMAT_PCM_16_BIT) {
         return -EINVAL;
     }
     uint32_t inCnl = audio_channel_count_from_out_mask(config->inputCfg.channels);
 #ifdef WEBRTC_LEGACY
     const webrtc::ProcessingConfig processing_config = {
-       {{static_cast<int>(session->apmSamplingRate), session->inChannelCount},
-        {static_cast<int>(session->apmSamplingRate), session->outChannelCount},
-        {static_cast<int>(session->apmSamplingRate), inCnl},
-        {static_cast<int>(session->apmSamplingRate), inCnl}}};
+            {{static_cast<int>(session->apmSamplingRate), session->inChannelCount},
+             {static_cast<int>(session->apmSamplingRate), session->outChannelCount},
+             {static_cast<int>(session->apmSamplingRate), inCnl},
+             {static_cast<int>(session->apmSamplingRate), inCnl}}};
     int status = session->apm->Initialize(processing_config);
     if (status < 0) {
         return -EINVAL;
@@ -1590,8 +1453,7 @@
     return 0;
 }
 
-void Session_GetReverseConfig(preproc_session_t *session, effect_config_t *config)
-{
+void Session_GetReverseConfig(preproc_session_t* session, effect_config_t* config) {
     memset(config, 0, sizeof(effect_config_t));
     config->inputCfg.samplingRate = config->outputCfg.samplingRate = session->samplingRate;
     config->inputCfg.format = config->outputCfg.format = AUDIO_FORMAT_PCM_16_BIT;
@@ -1601,10 +1463,9 @@
             (EFFECT_CONFIG_SMP_RATE | EFFECT_CONFIG_CHANNELS | EFFECT_CONFIG_FORMAT);
 }
 
-void Session_SetProcEnabled(preproc_session_t *session, uint32_t procId, bool enabled)
-{
+void Session_SetProcEnabled(preproc_session_t* session, uint32_t procId, bool enabled) {
     if (enabled) {
-        if(session->enabledMsk == 0) {
+        if (session->enabledMsk == 0) {
             session->framesIn = 0;
 #ifdef WEBRTC_LEGACY
             if (session->inResampler != NULL) {
@@ -1632,8 +1493,8 @@
             session->revEnabledMsk &= ~(1 << procId);
         }
     }
-    ALOGV("Session_SetProcEnabled proc %d, enabled %d enabledMsk %08x revEnabledMsk %08x",
-         procId, enabled, session->enabledMsk, session->revEnabledMsk);
+    ALOGV("Session_SetProcEnabled proc %d, enabled %d enabledMsk %08x revEnabledMsk %08x", procId,
+          enabled, session->enabledMsk, session->revEnabledMsk);
     session->processedMsk = 0;
     if (HasReverseStream(procId)) {
         session->revProcessedMsk = 0;
@@ -1647,8 +1508,7 @@
 static int sInitStatus = 1;
 static preproc_session_t sSessions[PREPROC_NUM_SESSIONS];
 
-preproc_session_t *PreProc_GetSession(int32_t procId, int32_t  sessionId, int32_t  ioId)
-{
+preproc_session_t* PreProc_GetSession(int32_t procId, int32_t sessionId, int32_t ioId) {
     size_t i;
     for (i = 0; i < PREPROC_NUM_SESSIONS; i++) {
         if (sSessions[i].id == sessionId) {
@@ -1668,7 +1528,6 @@
     return NULL;
 }
 
-
 int PreProc_Init() {
     size_t i;
     int status = 0;
@@ -1683,8 +1542,7 @@
     return sInitStatus;
 }
 
-const effect_descriptor_t *PreProc_GetDescriptor(const effect_uuid_t *uuid)
-{
+const effect_descriptor_t* PreProc_GetDescriptor(const effect_uuid_t* uuid) {
     size_t i;
     for (i = 0; i < PREPROC_NUM_EFFECTS; i++) {
         if (memcmp(&sDescriptors[i]->uuid, uuid, sizeof(effect_uuid_t)) == 0) {
@@ -1694,35 +1552,31 @@
     return NULL;
 }
 
-
 extern "C" {
 
 //------------------------------------------------------------------------------
 // Effect Control Interface Implementation
 //------------------------------------------------------------------------------
 
-int PreProcessingFx_Process(effect_handle_t     self,
-                            audio_buffer_t    *inBuffer,
-                            audio_buffer_t    *outBuffer)
-{
-    preproc_effect_t * effect = (preproc_effect_t *)self;
+int PreProcessingFx_Process(effect_handle_t self, audio_buffer_t* inBuffer,
+                            audio_buffer_t* outBuffer) {
+    preproc_effect_t* effect = (preproc_effect_t*)self;
 
-    if (effect == NULL){
+    if (effect == NULL) {
         ALOGV("PreProcessingFx_Process() ERROR effect == NULL");
         return -EINVAL;
     }
-    preproc_session_t * session = (preproc_session_t *)effect->session;
+    preproc_session_t* session = (preproc_session_t*)effect->session;
 
-    if (inBuffer == NULL  || inBuffer->raw == NULL  ||
-            outBuffer == NULL || outBuffer->raw == NULL){
+    if (inBuffer == NULL || inBuffer->raw == NULL || outBuffer == NULL || outBuffer->raw == NULL) {
         ALOGW("PreProcessingFx_Process() ERROR bad pointer");
         return -EINVAL;
     }
 
-    session->processedMsk |= (1<<effect->procId);
+    session->processedMsk |= (1 << effect->procId);
 
-//    ALOGV("PreProcessingFx_Process In %d frames enabledMsk %08x processedMsk %08x",
-//         inBuffer->frameCount, session->enabledMsk, session->processedMsk);
+    //    ALOGV("PreProcessingFx_Process In %d frames enabledMsk %08x processedMsk %08x",
+    //         inBuffer->frameCount, session->enabledMsk, session->processedMsk);
 
     if ((session->processedMsk & session->enabledMsk) == session->enabledMsk) {
         effect->session->processedMsk = 0;
@@ -1733,11 +1587,9 @@
             if (outBuffer->frameCount < fr) {
                 fr = outBuffer->frameCount;
             }
-            memcpy(outBuffer->s16,
-                  session->outBuf,
-                  fr * session->outChannelCount * sizeof(int16_t));
-            memmove(session->outBuf,
-                    session->outBuf + fr * session->outChannelCount,
+            memcpy(outBuffer->s16, session->outBuf,
+                   fr * session->outChannelCount * sizeof(int16_t));
+            memmove(session->outBuf, session->outBuf + fr * session->outChannelCount,
                     (session->framesOut - fr) * session->outChannelCount * sizeof(int16_t));
             session->framesOut -= fr;
             framesWr += fr;
@@ -1755,10 +1607,11 @@
                 fr = inBuffer->frameCount;
             }
             if (session->inBufSize < session->framesIn + fr) {
-                int16_t *buf;
+                int16_t* buf;
                 session->inBufSize = session->framesIn + fr;
-                buf = (int16_t *)realloc(session->inBuf,
-                                 session->inBufSize * session->inChannelCount * sizeof(int16_t));
+                buf = (int16_t*)realloc(
+                        session->inBuf,
+                        session->inBufSize * session->inChannelCount * sizeof(int16_t));
                 if (buf == NULL) {
                     session->framesIn = 0;
                     free(session->inBuf);
@@ -1767,14 +1620,13 @@
                 }
                 session->inBuf = buf;
             }
-            memcpy(session->inBuf + session->framesIn * session->inChannelCount,
-                   inBuffer->s16,
+            memcpy(session->inBuf + session->framesIn * session->inChannelCount, inBuffer->s16,
                    fr * session->inChannelCount * sizeof(int16_t));
 #ifdef DUAL_MIC_TEST
             pthread_mutex_lock(&gPcmDumpLock);
             if (gPcmDumpFh != NULL) {
-                fwrite(inBuffer->raw,
-                       fr * session->inChannelCount * sizeof(int16_t), 1, gPcmDumpFh);
+                fwrite(inBuffer->raw, fr * session->inChannelCount * sizeof(int16_t), 1,
+                       gPcmDumpFh);
             }
             pthread_mutex_unlock(&gPcmDumpLock);
 #endif
@@ -1787,21 +1639,13 @@
             spx_uint32_t frIn = session->framesIn;
             spx_uint32_t frOut = session->apmFrameCount;
             if (session->inChannelCount == 1) {
-                speex_resampler_process_int(session->inResampler,
-                                            0,
-                                            session->inBuf,
-                                            &frIn,
-                                            session->procFrame->data_,
-                                            &frOut);
+                speex_resampler_process_int(session->inResampler, 0, session->inBuf, &frIn,
+                                            session->procFrame->data_, &frOut);
             } else {
-                speex_resampler_process_interleaved_int(session->inResampler,
-                                                        session->inBuf,
-                                                        &frIn,
-                                                        session->procFrame->data_,
-                                                        &frOut);
+                speex_resampler_process_interleaved_int(session->inResampler, session->inBuf, &frIn,
+                                                        session->procFrame->data_, &frOut);
             }
-            memmove(session->inBuf,
-                    session->inBuf + frIn * session->inChannelCount,
+            memmove(session->inBuf, session->inBuf + frIn * session->inChannelCount,
                     (session->framesIn - frIn) * session->inChannelCount * sizeof(int16_t));
             session->framesIn -= frIn;
         } else {
@@ -1810,14 +1654,13 @@
                 fr = inBuffer->frameCount;
             }
             memcpy(session->procFrame->data_ + session->framesIn * session->inChannelCount,
-                   inBuffer->s16,
-                   fr * session->inChannelCount * sizeof(int16_t));
+                   inBuffer->s16, fr * session->inChannelCount * sizeof(int16_t));
 
 #ifdef DUAL_MIC_TEST
             pthread_mutex_lock(&gPcmDumpLock);
             if (gPcmDumpFh != NULL) {
-                fwrite(inBuffer->raw,
-                       fr * session->inChannelCount * sizeof(int16_t), 1, gPcmDumpFh);
+                fwrite(inBuffer->raw, fr * session->inChannelCount * sizeof(int16_t), 1,
+                       gPcmDumpFh);
             }
             pthread_mutex_unlock(&gPcmDumpLock);
 #endif
@@ -1844,11 +1687,11 @@
         }
         session->framesIn = 0;
         if (int status = effect->session->apm->ProcessStream(
-                                    (const int16_t* const)inBuffer->s16,
-                                    (const webrtc::StreamConfig)effect->session->inputConfig,
-                                    (const webrtc::StreamConfig)effect->session->outputConfig,
-                                    (int16_t* const)outBuffer->s16);
-             status != 0) {
+                    (const int16_t* const)inBuffer->s16,
+                    (const webrtc::StreamConfig)effect->session->inputConfig,
+                    (const webrtc::StreamConfig)effect->session->outputConfig,
+                    (int16_t* const)outBuffer->s16);
+            status != 0) {
             ALOGE("Process Stream failed with error %d\n", status);
             return status;
         }
@@ -1856,10 +1699,11 @@
 #endif
 
         if (session->outBufSize < session->framesOut + session->frameCount) {
-            int16_t *buf;
+            int16_t* buf;
             session->outBufSize = session->framesOut + session->frameCount;
-            buf = (int16_t *)realloc(session->outBuf,
-                             session->outBufSize * session->outChannelCount * sizeof(int16_t));
+            buf = (int16_t*)realloc(
+                    session->outBuf,
+                    session->outBufSize * session->outChannelCount * sizeof(int16_t));
             if (buf == NULL) {
                 session->framesOut = 0;
                 free(session->outBuf);
@@ -1874,18 +1718,13 @@
             spx_uint32_t frIn = session->apmFrameCount;
             spx_uint32_t frOut = session->frameCount;
             if (session->inChannelCount == 1) {
-                speex_resampler_process_int(session->outResampler,
-                                    0,
-                                    session->procFrame->data_,
-                                    &frIn,
-                                    session->outBuf + session->framesOut * session->outChannelCount,
-                                    &frOut);
+                speex_resampler_process_int(
+                        session->outResampler, 0, session->procFrame->data_, &frIn,
+                        session->outBuf + session->framesOut * session->outChannelCount, &frOut);
             } else {
-                speex_resampler_process_interleaved_int(session->outResampler,
-                                    session->procFrame->data_,
-                                    &frIn,
-                                    session->outBuf + session->framesOut * session->outChannelCount,
-                                    &frOut);
+                speex_resampler_process_interleaved_int(
+                        session->outResampler, session->procFrame->data_, &frIn,
+                        session->outBuf + session->framesOut * session->outChannelCount, &frOut);
             }
             session->framesOut += frOut;
         } else {
@@ -1901,11 +1740,9 @@
         if (framesRq - framesWr < fr) {
             fr = framesRq - framesWr;
         }
-        memcpy(outBuffer->s16 + framesWr * session->outChannelCount,
-              session->outBuf,
-              fr * session->outChannelCount * sizeof(int16_t));
-        memmove(session->outBuf,
-                session->outBuf + fr * session->outChannelCount,
+        memcpy(outBuffer->s16 + framesWr * session->outChannelCount, session->outBuf,
+               fr * session->outChannelCount * sizeof(int16_t));
+        memmove(session->outBuf, session->outBuf + fr * session->outChannelCount,
                 (session->framesOut - fr) * session->outChannelCount * sizeof(int16_t));
         session->framesOut -= fr;
         outBuffer->frameCount += fr;
@@ -1916,39 +1753,32 @@
     }
 }
 
-int PreProcessingFx_Command(effect_handle_t  self,
-                            uint32_t            cmdCode,
-                            uint32_t            cmdSize,
-                            void                *pCmdData,
-                            uint32_t            *replySize,
-                            void                *pReplyData)
-{
-    preproc_effect_t * effect = (preproc_effect_t *) self;
+int PreProcessingFx_Command(effect_handle_t self, uint32_t cmdCode, uint32_t cmdSize,
+                            void* pCmdData, uint32_t* replySize, void* pReplyData) {
+    preproc_effect_t* effect = (preproc_effect_t*)self;
 
-    if (effect == NULL){
+    if (effect == NULL) {
         return -EINVAL;
     }
 
-    //ALOGV("PreProcessingFx_Command: command %d cmdSize %d",cmdCode, cmdSize);
+    // ALOGV("PreProcessingFx_Command: command %d cmdSize %d",cmdCode, cmdSize);
 
-    switch (cmdCode){
+    switch (cmdCode) {
         case EFFECT_CMD_INIT:
-            if (pReplyData == NULL || *replySize != sizeof(int)){
+            if (pReplyData == NULL || *replySize != sizeof(int)) {
                 return -EINVAL;
             }
             if (effect->ops->init) {
                 effect->ops->init(effect);
             }
-            *(int *)pReplyData = 0;
+            *(int*)pReplyData = 0;
             break;
 
         case EFFECT_CMD_SET_CONFIG: {
-            if (pCmdData    == NULL||
-                cmdSize     != sizeof(effect_config_t)||
-                pReplyData  == NULL||
-                *replySize  != sizeof(int)){
+            if (pCmdData == NULL || cmdSize != sizeof(effect_config_t) || pReplyData == NULL ||
+                *replySize != sizeof(int)) {
                 ALOGV("PreProcessingFx_Command cmdCode Case: "
-                        "EFFECT_CMD_SET_CONFIG: ERROR");
+                      "EFFECT_CMD_SET_CONFIG: ERROR");
                 return -EINVAL;
             }
 #ifdef DUAL_MIC_TEST
@@ -1959,55 +1789,51 @@
                 effect->session->enabledMsk = 0;
             }
 #endif
-            *(int *)pReplyData = Session_SetConfig(effect->session, (effect_config_t *)pCmdData);
+            *(int*)pReplyData = Session_SetConfig(effect->session, (effect_config_t*)pCmdData);
 #ifdef DUAL_MIC_TEST
             if (gDualMicEnabled) {
                 effect->session->enabledMsk = enabledMsk;
             }
 #endif
-            if (*(int *)pReplyData != 0) {
+            if (*(int*)pReplyData != 0) {
                 break;
             }
             if (effect->state != PREPROC_EFFECT_STATE_ACTIVE) {
-                *(int *)pReplyData = Effect_SetState(effect, PREPROC_EFFECT_STATE_CONFIG);
+                *(int*)pReplyData = Effect_SetState(effect, PREPROC_EFFECT_STATE_CONFIG);
             }
-            } break;
+        } break;
 
         case EFFECT_CMD_GET_CONFIG:
-            if (pReplyData == NULL ||
-                *replySize != sizeof(effect_config_t)) {
+            if (pReplyData == NULL || *replySize != sizeof(effect_config_t)) {
                 ALOGV("\tLVM_ERROR : PreProcessingFx_Command cmdCode Case: "
-                        "EFFECT_CMD_GET_CONFIG: ERROR");
+                      "EFFECT_CMD_GET_CONFIG: ERROR");
                 return -EINVAL;
             }
 
-            Session_GetConfig(effect->session, (effect_config_t *)pReplyData);
+            Session_GetConfig(effect->session, (effect_config_t*)pReplyData);
             break;
 
         case EFFECT_CMD_SET_CONFIG_REVERSE:
-            if (pCmdData == NULL ||
-                cmdSize != sizeof(effect_config_t) ||
-                pReplyData == NULL ||
+            if (pCmdData == NULL || cmdSize != sizeof(effect_config_t) || pReplyData == NULL ||
                 *replySize != sizeof(int)) {
                 ALOGV("PreProcessingFx_Command cmdCode Case: "
-                        "EFFECT_CMD_SET_CONFIG_REVERSE: ERROR");
+                      "EFFECT_CMD_SET_CONFIG_REVERSE: ERROR");
                 return -EINVAL;
             }
-            *(int *)pReplyData = Session_SetReverseConfig(effect->session,
-                                                          (effect_config_t *)pCmdData);
-            if (*(int *)pReplyData != 0) {
+            *(int*)pReplyData =
+                    Session_SetReverseConfig(effect->session, (effect_config_t*)pCmdData);
+            if (*(int*)pReplyData != 0) {
                 break;
             }
             break;
 
         case EFFECT_CMD_GET_CONFIG_REVERSE:
-            if (pReplyData == NULL ||
-                *replySize != sizeof(effect_config_t)){
+            if (pReplyData == NULL || *replySize != sizeof(effect_config_t)) {
                 ALOGV("PreProcessingFx_Command cmdCode Case: "
-                        "EFFECT_CMD_GET_CONFIG_REVERSE: ERROR");
+                      "EFFECT_CMD_GET_CONFIG_REVERSE: ERROR");
                 return -EINVAL;
             }
-            Session_GetReverseConfig(effect->session, (effect_config_t *)pCmdData);
+            Session_GetReverseConfig(effect->session, (effect_config_t*)pCmdData);
             break;
 
         case EFFECT_CMD_RESET:
@@ -2017,80 +1843,74 @@
             break;
 
         case EFFECT_CMD_GET_PARAM: {
-            effect_param_t *p = (effect_param_t *)pCmdData;
+            effect_param_t* p = (effect_param_t*)pCmdData;
 
             if (pCmdData == NULL || cmdSize < sizeof(effect_param_t) ||
-                    cmdSize < (sizeof(effect_param_t) + p->psize) ||
-                    pReplyData == NULL || replySize == NULL ||
-                    *replySize < (sizeof(effect_param_t) + p->psize)){
+                cmdSize < (sizeof(effect_param_t) + p->psize) || pReplyData == NULL ||
+                replySize == NULL || *replySize < (sizeof(effect_param_t) + p->psize)) {
                 ALOGV("PreProcessingFx_Command cmdCode Case: "
-                        "EFFECT_CMD_GET_PARAM: ERROR");
+                      "EFFECT_CMD_GET_PARAM: ERROR");
                 return -EINVAL;
             }
 
             memcpy(pReplyData, pCmdData, sizeof(effect_param_t) + p->psize);
 
-            p = (effect_param_t *)pReplyData;
+            p = (effect_param_t*)pReplyData;
 
             int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t);
 
             if (effect->ops->get_parameter) {
-                p->status = effect->ops->get_parameter(effect, p->data,
-                                                       &p->vsize,
-                                                       p->data + voffset);
+                p->status =
+                        effect->ops->get_parameter(effect, p->data, &p->vsize, p->data + voffset);
                 *replySize = sizeof(effect_param_t) + voffset + p->vsize;
             }
         } break;
 
-        case EFFECT_CMD_SET_PARAM:{
-            if (pCmdData == NULL||
-                    cmdSize < sizeof(effect_param_t) ||
-                    pReplyData == NULL || replySize == NULL ||
-                    *replySize != sizeof(int32_t)){
+        case EFFECT_CMD_SET_PARAM: {
+            if (pCmdData == NULL || cmdSize < sizeof(effect_param_t) || pReplyData == NULL ||
+                replySize == NULL || *replySize != sizeof(int32_t)) {
                 ALOGV("PreProcessingFx_Command cmdCode Case: "
-                        "EFFECT_CMD_SET_PARAM: ERROR");
+                      "EFFECT_CMD_SET_PARAM: ERROR");
                 return -EINVAL;
             }
-            effect_param_t *p = (effect_param_t *) pCmdData;
+            effect_param_t* p = (effect_param_t*)pCmdData;
 
-            if (p->psize != sizeof(int32_t)){
+            if (p->psize != sizeof(int32_t)) {
                 ALOGV("PreProcessingFx_Command cmdCode Case: "
-                        "EFFECT_CMD_SET_PARAM: ERROR, psize is not sizeof(int32_t)");
+                      "EFFECT_CMD_SET_PARAM: ERROR, psize is not sizeof(int32_t)");
                 return -EINVAL;
             }
             if (effect->ops->set_parameter) {
-                *(int *)pReplyData = effect->ops->set_parameter(effect,
-                                                                (void *)p->data,
-                                                                p->data + p->psize);
+                *(int*)pReplyData =
+                        effect->ops->set_parameter(effect, (void*)p->data, p->data + p->psize);
             }
         } break;
 
         case EFFECT_CMD_ENABLE:
-            if (pReplyData == NULL || replySize == NULL || *replySize != sizeof(int)){
+            if (pReplyData == NULL || replySize == NULL || *replySize != sizeof(int)) {
                 ALOGV("PreProcessingFx_Command cmdCode Case: EFFECT_CMD_ENABLE: ERROR");
                 return -EINVAL;
             }
-            *(int *)pReplyData = Effect_SetState(effect, PREPROC_EFFECT_STATE_ACTIVE);
+            *(int*)pReplyData = Effect_SetState(effect, PREPROC_EFFECT_STATE_ACTIVE);
             break;
 
         case EFFECT_CMD_DISABLE:
-            if (pReplyData == NULL || replySize == NULL || *replySize != sizeof(int)){
+            if (pReplyData == NULL || replySize == NULL || *replySize != sizeof(int)) {
                 ALOGV("PreProcessingFx_Command cmdCode Case: EFFECT_CMD_DISABLE: ERROR");
                 return -EINVAL;
             }
-            *(int *)pReplyData  = Effect_SetState(effect, PREPROC_EFFECT_STATE_CONFIG);
+            *(int*)pReplyData = Effect_SetState(effect, PREPROC_EFFECT_STATE_CONFIG);
             break;
 
         case EFFECT_CMD_SET_DEVICE:
         case EFFECT_CMD_SET_INPUT_DEVICE:
-            if (pCmdData == NULL ||
-                cmdSize != sizeof(uint32_t)) {
+            if (pCmdData == NULL || cmdSize != sizeof(uint32_t)) {
                 ALOGV("PreProcessingFx_Command cmdCode Case: EFFECT_CMD_SET_DEVICE: ERROR");
                 return -EINVAL;
             }
 
             if (effect->ops->set_device) {
-                effect->ops->set_device(effect, *(uint32_t *)pCmdData);
+                effect->ops->set_device(effect, *(uint32_t*)pCmdData);
             }
             break;
 
@@ -2101,30 +1921,30 @@
 #ifdef DUAL_MIC_TEST
         ///// test commands start
         case PREPROC_CMD_DUAL_MIC_ENABLE: {
-            if (pCmdData == NULL|| cmdSize != sizeof(uint32_t) ||
-                    pReplyData == NULL || replySize == NULL) {
+            if (pCmdData == NULL || cmdSize != sizeof(uint32_t) || pReplyData == NULL ||
+                replySize == NULL) {
                 ALOGE("PreProcessingFx_Command cmdCode Case: "
-                        "PREPROC_CMD_DUAL_MIC_ENABLE: ERROR");
+                      "PREPROC_CMD_DUAL_MIC_ENABLE: ERROR");
                 *replySize = 0;
                 return -EINVAL;
             }
-            gDualMicEnabled = *(bool *)pCmdData;
+            gDualMicEnabled = *(bool*)pCmdData;
             if (gDualMicEnabled) {
                 effect->aux_channels_on = sHasAuxChannels[effect->procId];
             } else {
                 effect->aux_channels_on = false;
             }
-            effect->cur_channel_config = (effect->session->inChannelCount == 1) ?
-                    CHANNEL_CFG_MONO : CHANNEL_CFG_STEREO;
+            effect->cur_channel_config =
+                    (effect->session->inChannelCount == 1) ? CHANNEL_CFG_MONO : CHANNEL_CFG_STEREO;
 
             ALOGV("PREPROC_CMD_DUAL_MIC_ENABLE: %s", gDualMicEnabled ? "enabled" : "disabled");
             *replySize = sizeof(int);
-            *(int *)pReplyData = 0;
-            } break;
+            *(int*)pReplyData = 0;
+        } break;
         case PREPROC_CMD_DUAL_MIC_PCM_DUMP_START: {
-            if (pCmdData == NULL|| pReplyData == NULL || replySize == NULL) {
+            if (pCmdData == NULL || pReplyData == NULL || replySize == NULL) {
                 ALOGE("PreProcessingFx_Command cmdCode Case: "
-                        "PREPROC_CMD_DUAL_MIC_PCM_DUMP_START: ERROR");
+                      "PREPROC_CMD_DUAL_MIC_PCM_DUMP_START: ERROR");
                 *replySize = 0;
                 return -EINVAL;
             }
@@ -2133,20 +1953,19 @@
                 fclose(gPcmDumpFh);
                 gPcmDumpFh = NULL;
             }
-            char *path = strndup((char *)pCmdData, cmdSize);
-            gPcmDumpFh = fopen((char *)path, "wb");
+            char* path = strndup((char*)pCmdData, cmdSize);
+            gPcmDumpFh = fopen((char*)path, "wb");
             pthread_mutex_unlock(&gPcmDumpLock);
-            ALOGV("PREPROC_CMD_DUAL_MIC_PCM_DUMP_START: path %s gPcmDumpFh %p",
-                  path, gPcmDumpFh);
+            ALOGV("PREPROC_CMD_DUAL_MIC_PCM_DUMP_START: path %s gPcmDumpFh %p", path, gPcmDumpFh);
             ALOGE_IF(gPcmDumpFh <= 0, "gPcmDumpFh open error %d %s", errno, strerror(errno));
             free(path);
             *replySize = sizeof(int);
-            *(int *)pReplyData = 0;
-            } break;
+            *(int*)pReplyData = 0;
+        } break;
         case PREPROC_CMD_DUAL_MIC_PCM_DUMP_STOP: {
             if (pReplyData == NULL || replySize == NULL) {
                 ALOGE("PreProcessingFx_Command cmdCode Case: "
-                        "PREPROC_CMD_DUAL_MIC_PCM_DUMP_STOP: ERROR");
+                      "PREPROC_CMD_DUAL_MIC_PCM_DUMP_STOP: ERROR");
                 *replySize = 0;
                 return -EINVAL;
             }
@@ -2158,118 +1977,116 @@
             pthread_mutex_unlock(&gPcmDumpLock);
             ALOGV("PREPROC_CMD_DUAL_MIC_PCM_DUMP_STOP");
             *replySize = sizeof(int);
-            *(int *)pReplyData = 0;
-            } break;
-        ///// test commands end
+            *(int*)pReplyData = 0;
+        } break;
+            ///// test commands end
 
         case EFFECT_CMD_GET_FEATURE_SUPPORTED_CONFIGS: {
-            if(!gDualMicEnabled) {
+            if (!gDualMicEnabled) {
                 return -EINVAL;
             }
-            if (pCmdData == NULL|| cmdSize != 2 * sizeof(uint32_t) ||
-                    pReplyData == NULL || replySize == NULL) {
+            if (pCmdData == NULL || cmdSize != 2 * sizeof(uint32_t) || pReplyData == NULL ||
+                replySize == NULL) {
                 ALOGE("PreProcessingFx_Command cmdCode Case: "
-                        "EFFECT_CMD_GET_FEATURE_SUPPORTED_CONFIGS: ERROR");
+                      "EFFECT_CMD_GET_FEATURE_SUPPORTED_CONFIGS: ERROR");
                 *replySize = 0;
                 return -EINVAL;
             }
-            if (*(uint32_t *)pCmdData != EFFECT_FEATURE_AUX_CHANNELS ||
-                  !effect->aux_channels_on) {
+            if (*(uint32_t*)pCmdData != EFFECT_FEATURE_AUX_CHANNELS || !effect->aux_channels_on) {
                 ALOGV("PreProcessingFx_Command feature EFFECT_FEATURE_AUX_CHANNELS not supported by"
-                        " fx %d", effect->procId);
-                *(uint32_t *)pReplyData = -ENOSYS;
+                      " fx %d",
+                      effect->procId);
+                *(uint32_t*)pReplyData = -ENOSYS;
                 *replySize = sizeof(uint32_t);
                 break;
             }
-            size_t num_configs = *((uint32_t *)pCmdData + 1);
-            if (*replySize < (2 * sizeof(uint32_t) +
-                              num_configs * sizeof(channel_config_t))) {
+            size_t num_configs = *((uint32_t*)pCmdData + 1);
+            if (*replySize < (2 * sizeof(uint32_t) + num_configs * sizeof(channel_config_t))) {
                 *replySize = 0;
                 return -EINVAL;
             }
 
-            *((uint32_t *)pReplyData + 1) = CHANNEL_CFG_CNT;
+            *((uint32_t*)pReplyData + 1) = CHANNEL_CFG_CNT;
             if (num_configs < CHANNEL_CFG_CNT ||
-                    *replySize < (2 * sizeof(uint32_t) +
-                                     CHANNEL_CFG_CNT * sizeof(channel_config_t))) {
-                *(uint32_t *)pReplyData = -ENOMEM;
+                *replySize < (2 * sizeof(uint32_t) + CHANNEL_CFG_CNT * sizeof(channel_config_t))) {
+                *(uint32_t*)pReplyData = -ENOMEM;
             } else {
                 num_configs = CHANNEL_CFG_CNT;
-                *(uint32_t *)pReplyData = 0;
+                *(uint32_t*)pReplyData = 0;
             }
             ALOGV("PreProcessingFx_Command EFFECT_CMD_GET_FEATURE_SUPPORTED_CONFIGS num config %d",
                   num_configs);
 
             *replySize = 2 * sizeof(uint32_t) + num_configs * sizeof(channel_config_t);
-            *((uint32_t *)pReplyData + 1) = num_configs;
-            memcpy((uint32_t *)pReplyData + 2, &sDualMicConfigs, num_configs * sizeof(channel_config_t));
-            } break;
+            *((uint32_t*)pReplyData + 1) = num_configs;
+            memcpy((uint32_t*)pReplyData + 2, &sDualMicConfigs,
+                   num_configs * sizeof(channel_config_t));
+        } break;
         case EFFECT_CMD_GET_FEATURE_CONFIG:
-            if(!gDualMicEnabled) {
+            if (!gDualMicEnabled) {
                 return -EINVAL;
             }
-            if (pCmdData == NULL|| cmdSize != sizeof(uint32_t) ||
-                    pReplyData == NULL || replySize == NULL ||
-                    *replySize < sizeof(uint32_t) + sizeof(channel_config_t)) {
+            if (pCmdData == NULL || cmdSize != sizeof(uint32_t) || pReplyData == NULL ||
+                replySize == NULL || *replySize < sizeof(uint32_t) + sizeof(channel_config_t)) {
                 ALOGE("PreProcessingFx_Command cmdCode Case: "
-                        "EFFECT_CMD_GET_FEATURE_CONFIG: ERROR");
+                      "EFFECT_CMD_GET_FEATURE_CONFIG: ERROR");
                 return -EINVAL;
             }
-            if (*(uint32_t *)pCmdData != EFFECT_FEATURE_AUX_CHANNELS || !effect->aux_channels_on) {
-                *(uint32_t *)pReplyData = -ENOSYS;
+            if (*(uint32_t*)pCmdData != EFFECT_FEATURE_AUX_CHANNELS || !effect->aux_channels_on) {
+                *(uint32_t*)pReplyData = -ENOSYS;
                 *replySize = sizeof(uint32_t);
                 break;
             }
             ALOGV("PreProcessingFx_Command EFFECT_CMD_GET_FEATURE_CONFIG");
-            *(uint32_t *)pReplyData = 0;
+            *(uint32_t*)pReplyData = 0;
             *replySize = sizeof(uint32_t) + sizeof(channel_config_t);
-            memcpy((uint32_t *)pReplyData + 1,
-                   &sDualMicConfigs[effect->cur_channel_config],
+            memcpy((uint32_t*)pReplyData + 1, &sDualMicConfigs[effect->cur_channel_config],
                    sizeof(channel_config_t));
             break;
         case EFFECT_CMD_SET_FEATURE_CONFIG: {
             ALOGV("PreProcessingFx_Command EFFECT_CMD_SET_FEATURE_CONFIG: "
-                    "gDualMicEnabled %d effect->aux_channels_on %d",
+                  "gDualMicEnabled %d effect->aux_channels_on %d",
                   gDualMicEnabled, effect->aux_channels_on);
-            if(!gDualMicEnabled) {
+            if (!gDualMicEnabled) {
                 return -EINVAL;
             }
-            if (pCmdData == NULL|| cmdSize != (sizeof(uint32_t) + sizeof(channel_config_t)) ||
-                    pReplyData == NULL || replySize == NULL ||
-                    *replySize < sizeof(uint32_t)) {
+            if (pCmdData == NULL || cmdSize != (sizeof(uint32_t) + sizeof(channel_config_t)) ||
+                pReplyData == NULL || replySize == NULL || *replySize < sizeof(uint32_t)) {
                 ALOGE("PreProcessingFx_Command cmdCode Case: "
-                        "EFFECT_CMD_SET_FEATURE_CONFIG: ERROR\n"
-                        "pCmdData %p cmdSize %d pReplyData %p replySize %p *replySize %d",
-                        pCmdData, cmdSize, pReplyData, replySize, replySize ? *replySize : -1);
+                      "EFFECT_CMD_SET_FEATURE_CONFIG: ERROR\n"
+                      "pCmdData %p cmdSize %d pReplyData %p replySize %p *replySize %d",
+                      pCmdData, cmdSize, pReplyData, replySize, replySize ? *replySize : -1);
                 return -EINVAL;
             }
             *replySize = sizeof(uint32_t);
-            if (*(uint32_t *)pCmdData != EFFECT_FEATURE_AUX_CHANNELS || !effect->aux_channels_on) {
-                *(uint32_t *)pReplyData = -ENOSYS;
+            if (*(uint32_t*)pCmdData != EFFECT_FEATURE_AUX_CHANNELS || !effect->aux_channels_on) {
+                *(uint32_t*)pReplyData = -ENOSYS;
                 ALOGV("PreProcessingFx_Command cmdCode Case: "
-                                        "EFFECT_CMD_SET_FEATURE_CONFIG: ERROR\n"
-                                        "CmdData %d effect->aux_channels_on %d",
-                                        *(uint32_t *)pCmdData, effect->aux_channels_on);
+                      "EFFECT_CMD_SET_FEATURE_CONFIG: ERROR\n"
+                      "CmdData %d effect->aux_channels_on %d",
+                      *(uint32_t*)pCmdData, effect->aux_channels_on);
                 break;
             }
             size_t i;
-            for (i = 0; i < CHANNEL_CFG_CNT;i++) {
-                if (memcmp((uint32_t *)pCmdData + 1,
-                           &sDualMicConfigs[i], sizeof(channel_config_t)) == 0) {
+            for (i = 0; i < CHANNEL_CFG_CNT; i++) {
+                if (memcmp((uint32_t*)pCmdData + 1, &sDualMicConfigs[i],
+                           sizeof(channel_config_t)) == 0) {
                     break;
                 }
             }
             if (i == CHANNEL_CFG_CNT) {
-                *(uint32_t *)pReplyData = -EINVAL;
+                *(uint32_t*)pReplyData = -EINVAL;
                 ALOGW("PreProcessingFx_Command EFFECT_CMD_SET_FEATURE_CONFIG invalid config"
-                        "[%08x].[%08x]", *((uint32_t *)pCmdData + 1), *((uint32_t *)pCmdData + 2));
+                      "[%08x].[%08x]",
+                      *((uint32_t*)pCmdData + 1), *((uint32_t*)pCmdData + 2));
             } else {
                 effect->cur_channel_config = i;
-                *(uint32_t *)pReplyData = 0;
+                *(uint32_t*)pReplyData = 0;
                 ALOGV("PreProcessingFx_Command EFFECT_CMD_SET_FEATURE_CONFIG New config"
-                        "[%08x].[%08x]", sDualMicConfigs[i].main_channels, sDualMicConfigs[i].aux_channels);
+                      "[%08x].[%08x]",
+                      sDualMicConfigs[i].main_channels, sDualMicConfigs[i].aux_channels);
             }
-            } break;
+        } break;
 #endif
         default:
             return -EINVAL;
@@ -2277,11 +2094,8 @@
     return 0;
 }
 
-
-int PreProcessingFx_GetDescriptor(effect_handle_t   self,
-                                  effect_descriptor_t *pDescriptor)
-{
-    preproc_effect_t * effect = (preproc_effect_t *) self;
+int PreProcessingFx_GetDescriptor(effect_handle_t self, effect_descriptor_t* pDescriptor) {
+    preproc_effect_t* effect = (preproc_effect_t*)self;
 
     if (effect == NULL || pDescriptor == NULL) {
         return -EINVAL;
@@ -2292,28 +2106,26 @@
     return 0;
 }
 
-int PreProcessingFx_ProcessReverse(effect_handle_t     self,
-                                   audio_buffer_t    *inBuffer,
-                                   audio_buffer_t    *outBuffer __unused)
-{
-    preproc_effect_t * effect = (preproc_effect_t *)self;
+int PreProcessingFx_ProcessReverse(effect_handle_t self, audio_buffer_t* inBuffer,
+                                   audio_buffer_t* outBuffer __unused) {
+    preproc_effect_t* effect = (preproc_effect_t*)self;
 
-    if (effect == NULL){
+    if (effect == NULL) {
         ALOGW("PreProcessingFx_ProcessReverse() ERROR effect == NULL");
         return -EINVAL;
     }
-    preproc_session_t * session = (preproc_session_t *)effect->session;
+    preproc_session_t* session = (preproc_session_t*)effect->session;
 
-    if (inBuffer == NULL  || inBuffer->raw == NULL){
+    if (inBuffer == NULL || inBuffer->raw == NULL) {
         ALOGW("PreProcessingFx_ProcessReverse() ERROR bad pointer");
         return -EINVAL;
     }
 
-    session->revProcessedMsk |= (1<<effect->procId);
+    session->revProcessedMsk |= (1 << effect->procId);
 
-//    ALOGV("PreProcessingFx_ProcessReverse In %d frames revEnabledMsk %08x revProcessedMsk %08x",
-//         inBuffer->frameCount, session->revEnabledMsk, session->revProcessedMsk);
-
+    //    ALOGV("PreProcessingFx_ProcessReverse In %d frames revEnabledMsk %08x revProcessedMsk
+    //    %08x",
+    //         inBuffer->frameCount, session->revEnabledMsk, session->revProcessedMsk);
 
     if ((session->revProcessedMsk & session->revEnabledMsk) == session->revEnabledMsk) {
         effect->session->revProcessedMsk = 0;
@@ -2324,10 +2136,11 @@
                 fr = inBuffer->frameCount;
             }
             if (session->revBufSize < session->framesRev + fr) {
-                int16_t *buf;
+                int16_t* buf;
                 session->revBufSize = session->framesRev + fr;
-                buf = (int16_t *)realloc(session->revBuf,
-                                 session->revBufSize * session->inChannelCount * sizeof(int16_t));
+                buf = (int16_t*)realloc(
+                        session->revBuf,
+                        session->revBufSize * session->inChannelCount * sizeof(int16_t));
                 if (buf == NULL) {
                     session->framesRev = 0;
                     free(session->revBuf);
@@ -2336,8 +2149,7 @@
                 }
                 session->revBuf = buf;
             }
-            memcpy(session->revBuf + session->framesRev * session->inChannelCount,
-                   inBuffer->s16,
+            memcpy(session->revBuf + session->framesRev * session->inChannelCount, inBuffer->s16,
                    fr * session->inChannelCount * sizeof(int16_t));
 
             session->framesRev += fr;
@@ -2348,21 +2160,13 @@
             spx_uint32_t frIn = session->framesRev;
             spx_uint32_t frOut = session->apmFrameCount;
             if (session->inChannelCount == 1) {
-                speex_resampler_process_int(session->revResampler,
-                                            0,
-                                            session->revBuf,
-                                            &frIn,
-                                            session->revFrame->data_,
-                                            &frOut);
+                speex_resampler_process_int(session->revResampler, 0, session->revBuf, &frIn,
+                                            session->revFrame->data_, &frOut);
             } else {
-                speex_resampler_process_interleaved_int(session->revResampler,
-                                                        session->revBuf,
-                                                        &frIn,
-                                                        session->revFrame->data_,
-                                                        &frOut);
+                speex_resampler_process_interleaved_int(session->revResampler, session->revBuf,
+                                                        &frIn, session->revFrame->data_, &frOut);
             }
-            memmove(session->revBuf,
-                    session->revBuf + frIn * session->inChannelCount,
+            memmove(session->revBuf, session->revBuf + frIn * session->inChannelCount,
                     (session->framesRev - frIn) * session->inChannelCount * sizeof(int16_t));
             session->framesRev -= frIn;
         } else {
@@ -2371,8 +2175,7 @@
                 fr = inBuffer->frameCount;
             }
             memcpy(session->revFrame->data_ + session->framesRev * session->inChannelCount,
-                   inBuffer->s16,
-                   fr * session->inChannelCount * sizeof(int16_t));
+                   inBuffer->s16, fr * session->inChannelCount * sizeof(int16_t));
             session->framesRev += fr;
             inBuffer->frameCount = fr;
             if (session->framesRev < session->frameCount) {
@@ -2394,11 +2197,11 @@
         }
         session->framesRev = 0;
         if (int status = effect->session->apm->ProcessReverseStream(
-                        (const int16_t* const)inBuffer->s16,
-                        (const webrtc::StreamConfig)effect->session->revConfig,
-                        (const webrtc::StreamConfig)effect->session->revConfig,
-                        (int16_t* const)outBuffer->s16);
-             status != 0) {
+                    (const int16_t* const)inBuffer->s16,
+                    (const webrtc::StreamConfig)effect->session->revConfig,
+                    (const webrtc::StreamConfig)effect->session->revConfig,
+                    (int16_t* const)outBuffer->s16);
+            status != 0) {
             ALOGE("Process Reverse Stream failed with error %d\n", status);
             return status;
         }
@@ -2409,42 +2212,31 @@
     }
 }
 
-
 // effect_handle_t interface implementation for effect
 const struct effect_interface_s sEffectInterface = {
-    PreProcessingFx_Process,
-    PreProcessingFx_Command,
-    PreProcessingFx_GetDescriptor,
-    NULL
-};
+        PreProcessingFx_Process, PreProcessingFx_Command, PreProcessingFx_GetDescriptor, NULL};
 
 const struct effect_interface_s sEffectInterfaceReverse = {
-    PreProcessingFx_Process,
-    PreProcessingFx_Command,
-    PreProcessingFx_GetDescriptor,
-    PreProcessingFx_ProcessReverse
-};
+        PreProcessingFx_Process, PreProcessingFx_Command, PreProcessingFx_GetDescriptor,
+        PreProcessingFx_ProcessReverse};
 
 //------------------------------------------------------------------------------
 // Effect Library Interface Implementation
 //------------------------------------------------------------------------------
 
-int PreProcessingLib_Create(const effect_uuid_t *uuid,
-                            int32_t             sessionId,
-                            int32_t             ioId,
-                            effect_handle_t  *pInterface)
-{
+int PreProcessingLib_Create(const effect_uuid_t* uuid, int32_t sessionId, int32_t ioId,
+                            effect_handle_t* pInterface) {
     ALOGV("EffectCreate: uuid: %08x session %d IO: %d", uuid->timeLow, sessionId, ioId);
 
     int status;
-    const effect_descriptor_t *desc;
-    preproc_session_t *session;
+    const effect_descriptor_t* desc;
+    preproc_session_t* session;
     uint32_t procId;
 
     if (PreProc_Init() != 0) {
         return sInitStatus;
     }
-    desc =  PreProc_GetDescriptor(uuid);
+    desc = PreProc_GetDescriptor(uuid);
     if (desc == NULL) {
         ALOGW("EffectCreate: fx not found uuid: %08x", uuid->timeLow);
         return -EINVAL;
@@ -2465,14 +2257,13 @@
     return status;
 }
 
-int PreProcessingLib_Release(effect_handle_t interface)
-{
+int PreProcessingLib_Release(effect_handle_t interface) {
     ALOGV("EffectRelease start %p", interface);
     if (PreProc_Init() != 0) {
         return sInitStatus;
     }
 
-    preproc_effect_t *fx = (preproc_effect_t *)interface;
+    preproc_effect_t* fx = (preproc_effect_t*)interface;
 
     if (fx->session->id == 0) {
         return -EINVAL;
@@ -2480,17 +2271,15 @@
     return Session_ReleaseEffect(fx->session, fx);
 }
 
-int PreProcessingLib_GetDescriptor(const effect_uuid_t *uuid,
-                                   effect_descriptor_t *pDescriptor) {
-
-    if (pDescriptor == NULL || uuid == NULL){
+int PreProcessingLib_GetDescriptor(const effect_uuid_t* uuid, effect_descriptor_t* pDescriptor) {
+    if (pDescriptor == NULL || uuid == NULL) {
         return -EINVAL;
     }
 
-    const effect_descriptor_t *desc = PreProc_GetDescriptor(uuid);
+    const effect_descriptor_t* desc = PreProc_GetDescriptor(uuid);
     if (desc == NULL) {
         ALOGV("PreProcessingLib_GetDescriptor() not found");
-        return  -EINVAL;
+        return -EINVAL;
     }
 
     ALOGV("PreProcessingLib_GetDescriptor() got fx %s", desc->name);
@@ -2500,15 +2289,13 @@
 }
 
 // This is the only symbol that needs to be exported
-__attribute__ ((visibility ("default")))
-audio_effect_library_t AUDIO_EFFECT_LIBRARY_INFO_SYM = {
-    .tag = AUDIO_EFFECT_LIBRARY_TAG,
-    .version = EFFECT_LIBRARY_API_VERSION,
-    .name = "Audio Preprocessing Library",
-    .implementor = "The Android Open Source Project",
-    .create_effect = PreProcessingLib_Create,
-    .release_effect = PreProcessingLib_Release,
-    .get_descriptor = PreProcessingLib_GetDescriptor
-};
+__attribute__((visibility("default"))) audio_effect_library_t AUDIO_EFFECT_LIBRARY_INFO_SYM = {
+        .tag = AUDIO_EFFECT_LIBRARY_TAG,
+        .version = EFFECT_LIBRARY_API_VERSION,
+        .name = "Audio Preprocessing Library",
+        .implementor = "The Android Open Source Project",
+        .create_effect = PreProcessingLib_Create,
+        .release_effect = PreProcessingLib_Release,
+        .get_descriptor = PreProcessingLib_GetDescriptor};
 
-}; // extern "C"
+};  // extern "C"
diff --git a/media/libeffects/preprocessing/benchmarks/Android.bp b/media/libeffects/preprocessing/benchmarks/Android.bp
new file mode 100644
index 0000000..2808293
--- /dev/null
+++ b/media/libeffects/preprocessing/benchmarks/Android.bp
@@ -0,0 +1,51 @@
+cc_benchmark {
+    name: "preprocessing_legacy_benchmark",
+    vendor: true,
+    relative_install_path: "soundfx",
+    srcs: ["preprocessing_benchmark.cpp"],
+    shared_libs: [
+        "libaudiopreprocessing_legacy",
+        "libaudioutils",
+        "liblog",
+        "libutils",
+        "libwebrtc_audio_preprocessing",
+    ],
+    cflags: [
+        "-DWEBRTC_POSIX",
+        "-DWEBRTC_LEGACY",
+        "-fvisibility=default",
+        "-Wall",
+        "-Werror",
+        "-Wextra",
+    ],
+    header_libs: [
+        "libaudioeffects",
+        "libhardware_headers",
+        "libwebrtc_absl_headers",
+    ],
+}
+
+cc_benchmark {
+    name: "preprocessing_benchmark",
+    vendor: true,
+    relative_install_path: "soundfx",
+    srcs: ["preprocessing_benchmark.cpp"],
+    shared_libs: [
+        "libaudiopreprocessing",
+        "libaudioutils",
+        "liblog",
+        "libutils",
+    ],
+    cflags: [
+        "-DWEBRTC_POSIX",
+        "-fvisibility=default",
+        "-Wall",
+        "-Werror",
+        "-Wextra",
+    ],
+    header_libs: [
+        "libaudioeffects",
+        "libhardware_headers",
+        "libwebrtc_absl_headers",
+    ],
+}
diff --git a/media/libeffects/preprocessing/benchmarks/preprocessing_benchmark.cpp b/media/libeffects/preprocessing/benchmarks/preprocessing_benchmark.cpp
new file mode 100644
index 0000000..3a0ad6d
--- /dev/null
+++ b/media/libeffects/preprocessing/benchmarks/preprocessing_benchmark.cpp
@@ -0,0 +1,246 @@
+/*
+ * Copyright 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*******************************************************************
+ * A test result running on Pixel 3 for comparison.
+ * The first parameter indicates the channel mask index.
+ * The second parameter indicates the effect index.
+ * 0: Automatic Gain Control,
+ * 1: Acoustic Echo Canceler,
+ * 2: Noise Suppressor,
+ * 3: Automatic Gain Control 2
+ * ---------------------------------------------------------------
+ * Benchmark                     Time             CPU   Iterations
+ * ---------------------------------------------------------------
+ * BM_PREPROCESSING/1/0      59836 ns        59655 ns        11732
+ * BM_PREPROCESSING/1/1      66848 ns        66642 ns        10554
+ * BM_PREPROCESSING/1/2      20726 ns        20655 ns        33822
+ * BM_PREPROCESSING/1/3       5093 ns         5076 ns       137897
+ * BM_PREPROCESSING/2/0     117040 ns       116670 ns         5996
+ * BM_PREPROCESSING/2/1     120600 ns       120225 ns         5845
+ * BM_PREPROCESSING/2/2      38460 ns        38330 ns        18190
+ * BM_PREPROCESSING/2/3       6294 ns         6274 ns       111488
+ * BM_PREPROCESSING/3/0     232272 ns       231528 ns         3025
+ * BM_PREPROCESSING/3/1     226346 ns       225628 ns         3117
+ * BM_PREPROCESSING/3/2      75442 ns        75227 ns         9104
+ * BM_PREPROCESSING/3/3       9782 ns         9750 ns        71805
+ * BM_PREPROCESSING/4/0     290388 ns       289426 ns         2389
+ * BM_PREPROCESSING/4/1     279394 ns       278498 ns         2522
+ * BM_PREPROCESSING/4/2      94029 ns        93759 ns         7307
+ * BM_PREPROCESSING/4/3      11487 ns        11450 ns        61129
+ * BM_PREPROCESSING/5/0     347736 ns       346580 ns         2020
+ * BM_PREPROCESSING/5/1     331853 ns       330788 ns         2122
+ * BM_PREPROCESSING/5/2     112594 ns       112268 ns         6105
+ * BM_PREPROCESSING/5/3      13254 ns        13212 ns        52972
+ *******************************************************************/
+
+#include <audio_effects/effect_aec.h>
+#include <audio_effects/effect_agc.h>
+#include <array>
+#include <climits>
+#include <cstdlib>
+#include <random>
+#include <vector>
+#ifndef WEBRTC_LEGACY
+#include <audio_effects/effect_agc2.h>
+#endif
+#include <audio_effects/effect_ns.h>
+#include <benchmark/benchmark.h>
+#include <hardware/audio_effect.h>
+#include <log/log.h>
+#include <sys/stat.h>
+#include <system/audio.h>
+
+extern audio_effect_library_t AUDIO_EFFECT_LIBRARY_INFO_SYM;
+
+constexpr int kSampleRate = 16000;
+constexpr float kTenMilliSecVal = 0.01;
+constexpr unsigned int kStreamDelayMs = 0;
+constexpr effect_uuid_t kEffectUuids[] = {
+        // agc uuid
+        {0xaa8130e0, 0x66fc, 0x11e0, 0xbad0, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}},
+        // aec uuid
+        {0xbb392ec0, 0x8d4d, 0x11e0, 0xa896, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}},
+        // ns  uuid
+        {0xc06c8400, 0x8e06, 0x11e0, 0x9cb6, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}},
+#ifndef WEBRTC_LEGACY
+        // agc2 uuid
+        {0x89f38e65, 0xd4d2, 0x4d64, 0xad0e, {0x2b, 0x3e, 0x79, 0x9e, 0xa8, 0x86}},
+#endif
+};
+constexpr size_t kNumEffectUuids = std::size(kEffectUuids);
+constexpr audio_channel_mask_t kChMasks[] = {
+        AUDIO_CHANNEL_IN_MONO,          AUDIO_CHANNEL_IN_STEREO, AUDIO_CHANNEL_IN_2POINT0POINT2,
+        AUDIO_CHANNEL_IN_2POINT1POINT2, AUDIO_CHANNEL_IN_6,
+};
+constexpr size_t kNumChMasks = std::size(kChMasks);
+
+// types of pre processing modules
+enum PreProcId {
+    PREPROC_AGC,  // Automatic Gain Control
+    PREPROC_AEC,  // Acoustic Echo Canceler
+    PREPROC_NS,   // Noise Suppressor
+#ifndef WEBRTC_LEGACY
+    PREPROC_AGC2,  // Automatic Gain Control 2
+#endif
+    PREPROC_NUM_EFFECTS
+};
+
+int preProcCreateEffect(effect_handle_t* pEffectHandle, uint32_t effectType,
+                        effect_config_t* pConfig, int sessionId, int ioId) {
+    if (int status = AUDIO_EFFECT_LIBRARY_INFO_SYM.create_effect(&kEffectUuids[effectType],
+                                                                 sessionId, ioId, pEffectHandle);
+        status != 0) {
+        ALOGE("Audio Preprocessing create returned an error = %d\n", status);
+        return EXIT_FAILURE;
+    }
+    int reply = 0;
+    uint32_t replySize = sizeof(reply);
+    if (effectType == PREPROC_AEC) {
+        if (int status = (**pEffectHandle)
+                                 ->command(*pEffectHandle, EFFECT_CMD_SET_CONFIG_REVERSE,
+                                           sizeof(effect_config_t), pConfig, &replySize, &reply);
+            status != 0) {
+            ALOGE("Set config reverse command returned an error = %d\n", status);
+            return EXIT_FAILURE;
+        }
+    }
+    if (int status = (**pEffectHandle)
+                             ->command(*pEffectHandle, EFFECT_CMD_SET_CONFIG,
+                                       sizeof(effect_config_t), pConfig, &replySize, &reply);
+        status != 0) {
+        ALOGE("Set config command returned an error = %d\n", status);
+        return EXIT_FAILURE;
+    }
+    return reply;
+}
+
+int preProcSetConfigParam(effect_handle_t effectHandle, uint32_t paramType, uint32_t paramValue) {
+    int reply = 0;
+    uint32_t replySize = sizeof(reply);
+    uint32_t paramData[2] = {paramType, paramValue};
+    effect_param_t* effectParam = (effect_param_t*)malloc(sizeof(*effectParam) + sizeof(paramData));
+    memcpy(&effectParam->data[0], &paramData[0], sizeof(paramData));
+    effectParam->psize = sizeof(paramData[0]);
+    (*effectHandle)
+            ->command(effectHandle, EFFECT_CMD_SET_PARAM, sizeof(effect_param_t), effectParam,
+                      &replySize, &reply);
+    free(effectParam);
+    return reply;
+}
+
+short preProcGetShortVal(float paramValue) {
+    return static_cast<short>(paramValue * std::numeric_limits<short>::max());
+}
+
+static void BM_PREPROCESSING(benchmark::State& state) {
+    const size_t chMask = kChMasks[state.range(0) - 1];
+    const size_t channelCount = audio_channel_count_from_in_mask(chMask);
+
+    PreProcId effectType = (PreProcId)state.range(1);
+
+    int32_t sessionId = 1;
+    int32_t ioId = 1;
+    effect_handle_t effectHandle = nullptr;
+    effect_config_t config{};
+    config.inputCfg.samplingRate = config.outputCfg.samplingRate = kSampleRate;
+    config.inputCfg.channels = config.outputCfg.channels = chMask;
+    config.inputCfg.format = config.outputCfg.format = AUDIO_FORMAT_PCM_16_BIT;
+
+    if (int status = preProcCreateEffect(&effectHandle, state.range(1), &config, sessionId, ioId);
+        status != 0) {
+        ALOGE("Create effect call returned error %i", status);
+        return;
+    }
+
+    int reply = 0;
+    uint32_t replySize = sizeof(reply);
+    if (int status =
+                (*effectHandle)
+                        ->command(effectHandle, EFFECT_CMD_ENABLE, 0, nullptr, &replySize, &reply);
+        status != 0) {
+        ALOGE("Command enable call returned error %d\n", reply);
+        return;
+    }
+
+    // Initialize input buffer with deterministic pseudo-random values
+    const int frameLength = (int)(kSampleRate * kTenMilliSecVal);
+    std::minstd_rand gen(chMask);
+    std::uniform_real_distribution<> dis(-1.0f, 1.0f);
+    std::vector<short> in(frameLength * channelCount);
+    for (auto& i : in) {
+        i = preProcGetShortVal(dis(gen));
+    }
+    std::vector<short> farIn(frameLength * channelCount);
+    for (auto& i : farIn) {
+        i = preProcGetShortVal(dis(gen));
+    }
+    std::vector<short> out(frameLength * channelCount);
+
+    // Run the test
+    for (auto _ : state) {
+        benchmark::DoNotOptimize(in.data());
+        benchmark::DoNotOptimize(out.data());
+        benchmark::DoNotOptimize(farIn.data());
+
+        audio_buffer_t inBuffer = {.frameCount = (size_t)frameLength, .s16 = in.data()};
+        audio_buffer_t outBuffer = {.frameCount = (size_t)frameLength, .s16 = out.data()};
+        audio_buffer_t farInBuffer = {.frameCount = (size_t)frameLength, .s16 = farIn.data()};
+
+        if (PREPROC_AEC == effectType) {
+            if (int status =
+                        preProcSetConfigParam(effectHandle, AEC_PARAM_ECHO_DELAY, kStreamDelayMs);
+                status != 0) {
+                ALOGE("preProcSetConfigParam returned Error %d\n", status);
+                return;
+            }
+        }
+        if (int status = (*effectHandle)->process(effectHandle, &inBuffer, &outBuffer);
+            status != 0) {
+            ALOGE("\nError: Process i = %d returned with error %d\n", (int)state.range(1), status);
+            return;
+        }
+        if (PREPROC_AEC == effectType) {
+            if (int status =
+                        (*effectHandle)->process_reverse(effectHandle, &farInBuffer, &outBuffer);
+                status != 0) {
+                ALOGE("\nError: Process reverse i = %d returned with error %d\n",
+                      (int)state.range(1), status);
+                return;
+            }
+        }
+    }
+    benchmark::ClobberMemory();
+
+    state.SetComplexityN(state.range(0));
+
+    if (int status = AUDIO_EFFECT_LIBRARY_INFO_SYM.release_effect(effectHandle); status != 0) {
+        ALOGE("release_effect returned an error = %d\n", status);
+        return;
+    }
+}
+
+static void preprocessingArgs(benchmark::internal::Benchmark* b) {
+    for (int i = 1; i <= (int)kNumChMasks; i++) {
+        for (int j = 0; j < (int)kNumEffectUuids; ++j) {
+            b->Args({i, j});
+        }
+    }
+}
+
+BENCHMARK(BM_PREPROCESSING)->Apply(preprocessingArgs);
+
+BENCHMARK_MAIN();
diff --git a/media/libeffects/preprocessing/tests/PreProcessingTest.cpp b/media/libeffects/preprocessing/tests/PreProcessingTest.cpp
index 3244c1f..65b9469 100644
--- a/media/libeffects/preprocessing/tests/PreProcessingTest.cpp
+++ b/media/libeffects/preprocessing/tests/PreProcessingTest.cpp
@@ -37,485 +37,465 @@
 
 // types of pre processing modules
 enum PreProcId {
-  PREPROC_AGC,  // Automatic Gain Control
+    PREPROC_AGC,  // Automatic Gain Control
 #ifndef WEBRTC_LEGACY
-  PREPROC_AGC2,  // Automatic Gain Control 2
+    PREPROC_AGC2,  // Automatic Gain Control 2
 #endif
-  PREPROC_AEC,  // Acoustic Echo Canceler
-  PREPROC_NS,   // Noise Suppressor
-  PREPROC_NUM_EFFECTS
+    PREPROC_AEC,  // Acoustic Echo Canceler
+    PREPROC_NS,   // Noise Suppressor
+    PREPROC_NUM_EFFECTS
 };
 
 enum PreProcParams {
-  ARG_HELP = 1,
-  ARG_INPUT,
-  ARG_OUTPUT,
-  ARG_FAR,
-  ARG_FS,
-  ARG_CH_MASK,
-  ARG_AGC_TGT_LVL,
-  ARG_AGC_COMP_LVL,
-  ARG_AEC_DELAY,
-  ARG_NS_LVL,
+    ARG_HELP = 1,
+    ARG_INPUT,
+    ARG_OUTPUT,
+    ARG_FAR,
+    ARG_FS,
+    ARG_CH_MASK,
+    ARG_AGC_TGT_LVL,
+    ARG_AGC_COMP_LVL,
+    ARG_AEC_DELAY,
+    ARG_NS_LVL,
 #ifndef WEBRTC_LEGACY
-  ARG_AEC_MOBILE,
-  ARG_AGC2_GAIN,
-  ARG_AGC2_LVL,
-  ARG_AGC2_SAT_MGN
+    ARG_AGC2_GAIN,
+    ARG_AGC2_LVL,
+    ARG_AGC2_SAT_MGN
 #endif
 };
 
 struct preProcConfigParams_t {
-  int samplingFreq = 16000;
-  audio_channel_mask_t chMask = AUDIO_CHANNEL_IN_MONO;
-  int nsLevel = 0;         // a value between 0-3
-  int agcTargetLevel = 3;  // in dB
-  int agcCompLevel = 9;    // in dB
+    int samplingFreq = 16000;
+    audio_channel_mask_t chMask = AUDIO_CHANNEL_IN_MONO;
+    int nsLevel = 0;         // a value between 0-3
+    int agcTargetLevel = 3;  // in dB
+    int agcCompLevel = 9;    // in dB
 #ifndef WEBRTC_LEGACY
-  float agc2Gain = 0.f;             // in dB
-  float agc2SaturationMargin = 2.f; // in dB
-  int agc2Level = 0;                // either kRms(0) or kPeak(1)
+    float agc2Gain = 0.f;              // in dB
+    float agc2SaturationMargin = 2.f;  // in dB
+    int agc2Level = 0;                 // either kRms(0) or kPeak(1)
 #endif
-  int aecDelay = 0;        // in ms
+    int aecDelay = 0;  // in ms
 };
 
 const effect_uuid_t kPreProcUuids[PREPROC_NUM_EFFECTS] = {
-    {0xaa8130e0, 0x66fc, 0x11e0, 0xbad0, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}},  // agc uuid
+        {0xaa8130e0, 0x66fc, 0x11e0, 0xbad0, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}},  // agc uuid
 #ifndef WEBRTC_LEGACY
-    {0x89f38e65, 0xd4d2, 0x4d64, 0xad0e, {0x2b, 0x3e, 0x79, 0x9e, 0xa8, 0x86}},  // agc2 uuid
+        {0x89f38e65, 0xd4d2, 0x4d64, 0xad0e, {0x2b, 0x3e, 0x79, 0x9e, 0xa8, 0x86}},  // agc2 uuid
 #endif
-    {0xbb392ec0, 0x8d4d, 0x11e0, 0xa896, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}},  // aec uuid
-    {0xc06c8400, 0x8e06, 0x11e0, 0x9cb6, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}},  // ns  uuid
+        {0xbb392ec0, 0x8d4d, 0x11e0, 0xa896, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}},  // aec uuid
+        {0xc06c8400, 0x8e06, 0x11e0, 0x9cb6, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}},  // ns  uuid
 };
 
 constexpr audio_channel_mask_t kPreProcConfigChMask[] = {
-    AUDIO_CHANNEL_IN_MONO,
-    AUDIO_CHANNEL_IN_STEREO,
-    AUDIO_CHANNEL_IN_FRONT_BACK,
-    AUDIO_CHANNEL_IN_6,
-    AUDIO_CHANNEL_IN_2POINT0POINT2,
-    AUDIO_CHANNEL_IN_2POINT1POINT2,
-    AUDIO_CHANNEL_IN_3POINT0POINT2,
-    AUDIO_CHANNEL_IN_3POINT1POINT2,
-    AUDIO_CHANNEL_IN_5POINT1,
-    AUDIO_CHANNEL_IN_VOICE_UPLINK_MONO,
-    AUDIO_CHANNEL_IN_VOICE_DNLINK_MONO,
-    AUDIO_CHANNEL_IN_VOICE_CALL_MONO,
+        AUDIO_CHANNEL_IN_MONO,
+        AUDIO_CHANNEL_IN_STEREO,
+        AUDIO_CHANNEL_IN_FRONT_BACK,
+        AUDIO_CHANNEL_IN_6,
+        AUDIO_CHANNEL_IN_2POINT0POINT2,
+        AUDIO_CHANNEL_IN_2POINT1POINT2,
+        AUDIO_CHANNEL_IN_3POINT0POINT2,
+        AUDIO_CHANNEL_IN_3POINT1POINT2,
+        AUDIO_CHANNEL_IN_5POINT1,
+        AUDIO_CHANNEL_IN_VOICE_UPLINK_MONO,
+        AUDIO_CHANNEL_IN_VOICE_DNLINK_MONO,
+        AUDIO_CHANNEL_IN_VOICE_CALL_MONO,
 };
 
 constexpr int kPreProcConfigChMaskCount = std::size(kPreProcConfigChMask);
 
 void printUsage() {
-  printf("\nUsage: ");
-  printf("\n     <executable> [options]\n");
-  printf("\nwhere options are, ");
-  printf("\n     --input <inputfile>");
-  printf("\n           path to the input file");
-  printf("\n     --output <outputfile>");
-  printf("\n           path to the output file");
-  printf("\n     --help");
-  printf("\n           Prints this usage information");
-  printf("\n     --fs <sampling_freq>");
-  printf("\n           Sampling frequency in Hz, default 16000.");
-  printf("\n     -ch_mask <channel_mask>\n");
-  printf("\n         0  - AUDIO_CHANNEL_IN_MONO");
-  printf("\n         1  - AUDIO_CHANNEL_IN_STEREO");
-  printf("\n         2  - AUDIO_CHANNEL_IN_FRONT_BACK");
-  printf("\n         3  - AUDIO_CHANNEL_IN_6");
-  printf("\n         4  - AUDIO_CHANNEL_IN_2POINT0POINT2");
-  printf("\n         5  - AUDIO_CHANNEL_IN_2POINT1POINT2");
-  printf("\n         6  - AUDIO_CHANNEL_IN_3POINT0POINT2");
-  printf("\n         7  - AUDIO_CHANNEL_IN_3POINT1POINT2");
-  printf("\n         8  - AUDIO_CHANNEL_IN_5POINT1");
-  printf("\n         9  - AUDIO_CHANNEL_IN_VOICE_UPLINK_MONO");
-  printf("\n         10 - AUDIO_CHANNEL_IN_VOICE_DNLINK_MONO ");
-  printf("\n         11 - AUDIO_CHANNEL_IN_VOICE_CALL_MONO ");
-  printf("\n         default 0");
-  printf("\n     --far <farend_file>");
-  printf("\n           Path to far-end file needed for echo cancellation");
-  printf("\n     --aec");
-  printf("\n           Enable Echo Cancellation, default disabled");
-  printf("\n     --ns");
-  printf("\n           Enable Noise Suppression, default disabled");
-  printf("\n     --agc");
-  printf("\n           Enable Gain Control, default disabled");
+    printf("\nUsage: ");
+    printf("\n     <executable> [options]\n");
+    printf("\nwhere options are, ");
+    printf("\n     --input <inputfile>");
+    printf("\n           path to the input file");
+    printf("\n     --output <outputfile>");
+    printf("\n           path to the output file");
+    printf("\n     --help");
+    printf("\n           Prints this usage information");
+    printf("\n     --fs <sampling_freq>");
+    printf("\n           Sampling frequency in Hz, default 16000.");
+    printf("\n     -ch_mask <channel_mask>\n");
+    printf("\n         0  - AUDIO_CHANNEL_IN_MONO");
+    printf("\n         1  - AUDIO_CHANNEL_IN_STEREO");
+    printf("\n         2  - AUDIO_CHANNEL_IN_FRONT_BACK");
+    printf("\n         3  - AUDIO_CHANNEL_IN_6");
+    printf("\n         4  - AUDIO_CHANNEL_IN_2POINT0POINT2");
+    printf("\n         5  - AUDIO_CHANNEL_IN_2POINT1POINT2");
+    printf("\n         6  - AUDIO_CHANNEL_IN_3POINT0POINT2");
+    printf("\n         7  - AUDIO_CHANNEL_IN_3POINT1POINT2");
+    printf("\n         8  - AUDIO_CHANNEL_IN_5POINT1");
+    printf("\n         9  - AUDIO_CHANNEL_IN_VOICE_UPLINK_MONO");
+    printf("\n         10 - AUDIO_CHANNEL_IN_VOICE_DNLINK_MONO ");
+    printf("\n         11 - AUDIO_CHANNEL_IN_VOICE_CALL_MONO ");
+    printf("\n         default 0");
+    printf("\n     --far <farend_file>");
+    printf("\n           Path to far-end file needed for echo cancellation");
+    printf("\n     --aec");
+    printf("\n           Enable Echo Cancellation, default disabled");
+    printf("\n     --ns");
+    printf("\n           Enable Noise Suppression, default disabled");
+    printf("\n     --agc");
+    printf("\n           Enable Gain Control, default disabled");
 #ifndef WEBRTC_LEGACY
-  printf("\n     --agc2");
-  printf("\n           Enable Gain Controller 2, default disabled");
+    printf("\n     --agc2");
+    printf("\n           Enable Gain Controller 2, default disabled");
 #endif
-  printf("\n     --ns_lvl <ns_level>");
-  printf("\n           Noise Suppression level in dB, default value 0dB");
-  printf("\n     --agc_tgt_lvl <target_level>");
-  printf("\n           AGC Target Level in dB, default value 3dB");
-  printf("\n     --agc_comp_lvl <comp_level>");
-  printf("\n           AGC Comp Level in dB, default value 9dB");
+    printf("\n     --ns_lvl <ns_level>");
+    printf("\n           Noise Suppression level in dB, default value 0dB");
+    printf("\n     --agc_tgt_lvl <target_level>");
+    printf("\n           AGC Target Level in dB, default value 3dB");
+    printf("\n     --agc_comp_lvl <comp_level>");
+    printf("\n           AGC Comp Level in dB, default value 9dB");
 #ifndef WEBRTC_LEGACY
-  printf("\n     --agc2_gain <fixed_digital_gain>");
-  printf("\n           AGC Fixed Digital Gain in dB, default value 0dB");
-  printf("\n     --agc2_lvl <level_estimator>");
-  printf("\n           AGC Adaptive Digital Level Estimator, default value kRms");
-  printf("\n     --agc2_sat_mgn <saturation_margin>");
-  printf("\n           AGC Adaptive Digital Saturation Margin in dB, default value 2dB");
+    printf("\n     --agc2_gain <fixed_digital_gain>");
+    printf("\n           AGC Fixed Digital Gain in dB, default value 0dB");
+    printf("\n     --agc2_lvl <level_estimator>");
+    printf("\n           AGC Adaptive Digital Level Estimator, default value kRms");
+    printf("\n     --agc2_sat_mgn <saturation_margin>");
+    printf("\n           AGC Adaptive Digital Saturation Margin in dB, default value 2dB");
 #endif
-  printf("\n     --aec_delay <delay>");
-  printf("\n           AEC delay value in ms, default value 0ms");
-#ifndef WEBRTC_LEGACY
-  printf("\n     --aec_mobile");
-  printf("\n           Enable mobile mode of echo canceller, default disabled");
-#endif
-  printf("\n");
+    printf("\n     --aec_delay <delay>");
+    printf("\n           AEC delay value in ms, default value 0ms");
+    printf("\n");
 }
 
 constexpr float kTenMilliSecVal = 0.01;
 
-int preProcCreateEffect(effect_handle_t *pEffectHandle, uint32_t effectType,
-                        effect_config_t *pConfig, int sessionId, int ioId) {
-  if (int status = AUDIO_EFFECT_LIBRARY_INFO_SYM.create_effect(&kPreProcUuids[effectType],
-                                                               sessionId, ioId, pEffectHandle);
-      status != 0) {
-    ALOGE("Audio Preprocessing create returned an error = %d\n", status);
-    return EXIT_FAILURE;
-  }
-  int reply = 0;
-  uint32_t replySize = sizeof(reply);
-  if (effectType == PREPROC_AEC) {
+int preProcCreateEffect(effect_handle_t* pEffectHandle, uint32_t effectType,
+                        effect_config_t* pConfig, int sessionId, int ioId) {
+    if (int status = AUDIO_EFFECT_LIBRARY_INFO_SYM.create_effect(&kPreProcUuids[effectType],
+                                                                 sessionId, ioId, pEffectHandle);
+        status != 0) {
+        ALOGE("Audio Preprocessing create returned an error = %d\n", status);
+        return EXIT_FAILURE;
+    }
+    int reply = 0;
+    uint32_t replySize = sizeof(reply);
+    if (effectType == PREPROC_AEC) {
+        (**pEffectHandle)
+                ->command(*pEffectHandle, EFFECT_CMD_SET_CONFIG_REVERSE, sizeof(effect_config_t),
+                          pConfig, &replySize, &reply);
+    }
     (**pEffectHandle)
-        ->command(*pEffectHandle, EFFECT_CMD_SET_CONFIG_REVERSE, sizeof(effect_config_t), pConfig,
-                  &replySize, &reply);
-  }
-  (**pEffectHandle)
-      ->command(*pEffectHandle, EFFECT_CMD_SET_CONFIG, sizeof(effect_config_t), pConfig,
-                &replySize, &reply);
-  return reply;
+            ->command(*pEffectHandle, EFFECT_CMD_SET_CONFIG, sizeof(effect_config_t), pConfig,
+                      &replySize, &reply);
+    return reply;
 }
 
 int preProcSetConfigParam(uint32_t paramType, uint32_t paramValue, effect_handle_t effectHandle) {
-  int reply = 0;
-  uint32_t replySize = sizeof(reply);
-  uint32_t paramData[2] = {paramType, paramValue};
-  effect_param_t *effectParam =
-      (effect_param_t *)malloc(sizeof(*effectParam) + sizeof(paramData));
-  memcpy(&effectParam->data[0], &paramData[0], sizeof(paramData));
-  effectParam->psize = sizeof(paramData[0]);
-  (*effectHandle)
-      ->command(effectHandle, EFFECT_CMD_SET_PARAM, sizeof(effect_param_t), effectParam,
-                &replySize, &reply);
-  free(effectParam);
-  return reply;
+    int reply = 0;
+    uint32_t replySize = sizeof(reply);
+    uint32_t paramData[2] = {paramType, paramValue};
+    effect_param_t* effectParam = (effect_param_t*)malloc(sizeof(*effectParam) + sizeof(paramData));
+    memcpy(&effectParam->data[0], &paramData[0], sizeof(paramData));
+    effectParam->psize = sizeof(paramData[0]);
+    (*effectHandle)
+            ->command(effectHandle, EFFECT_CMD_SET_PARAM, sizeof(effect_param_t), effectParam,
+                      &replySize, &reply);
+    free(effectParam);
+    return reply;
 }
 
-int main(int argc, const char *argv[]) {
-  if (argc == 1) {
-    printUsage();
-    return EXIT_FAILURE;
-  }
-  const char *inputFile = nullptr;
-  const char *outputFile = nullptr;
-  const char *farFile = nullptr;
-  int effectEn[PREPROC_NUM_EFFECTS] = {0};
-#ifndef WEBRTC_LEGACY
-  int aecMobileMode = 0;
-#endif
-
-  const option long_opts[] = {
-      {"help", no_argument, nullptr, ARG_HELP},
-      {"input", required_argument, nullptr, ARG_INPUT},
-      {"output", required_argument, nullptr, ARG_OUTPUT},
-      {"far", required_argument, nullptr, ARG_FAR},
-      {"fs", required_argument, nullptr, ARG_FS},
-      {"ch_mask", required_argument, nullptr, ARG_CH_MASK},
-      {"agc_tgt_lvl", required_argument, nullptr, ARG_AGC_TGT_LVL},
-      {"agc_comp_lvl", required_argument, nullptr, ARG_AGC_COMP_LVL},
-#ifndef WEBRTC_LEGACY
-      {"agc2_gain", required_argument, nullptr, ARG_AGC2_GAIN},
-      {"agc2_lvl", required_argument, nullptr, ARG_AGC2_LVL},
-      {"agc2_sat_mgn", required_argument, nullptr, ARG_AGC2_SAT_MGN},
-#endif
-      {"aec_delay", required_argument, nullptr, ARG_AEC_DELAY},
-      {"ns_lvl", required_argument, nullptr, ARG_NS_LVL},
-      {"aec", no_argument, &effectEn[PREPROC_AEC], 1},
-      {"agc", no_argument, &effectEn[PREPROC_AGC], 1},
-#ifndef WEBRTC_LEGACY
-      {"agc2", no_argument, &effectEn[PREPROC_AGC2], 1},
-#endif
-      {"ns", no_argument, &effectEn[PREPROC_NS], 1},
-#ifndef WEBRTC_LEGACY
-      {"aec_mobile", no_argument, &aecMobileMode, 1},
-#endif
-      {nullptr, 0, nullptr, 0},
-  };
-  struct preProcConfigParams_t preProcCfgParams {};
-
-  while (true) {
-    const int opt = getopt_long(argc, (char *const *)argv, "i:o:", long_opts, nullptr);
-    if (opt == -1) {
-      break;
-    }
-    switch (opt) {
-      case ARG_HELP:
+int main(int argc, const char* argv[]) {
+    if (argc == 1) {
         printUsage();
-        return 0;
-      case ARG_INPUT: {
-        inputFile = (char *)optarg;
-        break;
-      }
-      case ARG_OUTPUT: {
-        outputFile = (char *)optarg;
-        break;
-      }
-      case ARG_FAR: {
-        farFile = (char *)optarg;
-        break;
-      }
-      case ARG_FS: {
-        preProcCfgParams.samplingFreq = atoi(optarg);
-        break;
-      }
-      case ARG_CH_MASK: {
-        int chMaskIdx = atoi(optarg);
-        if (chMaskIdx < 0 or chMaskIdx > kPreProcConfigChMaskCount) {
-          ALOGE("Channel Mask index not in correct range\n");
-          printUsage();
-          return EXIT_FAILURE;
-        }
-        preProcCfgParams.chMask = kPreProcConfigChMask[chMaskIdx];
-        break;
-      }
-      case ARG_AGC_TGT_LVL: {
-        preProcCfgParams.agcTargetLevel = atoi(optarg);
-        break;
-      }
-      case ARG_AGC_COMP_LVL: {
-        preProcCfgParams.agcCompLevel = atoi(optarg);
-        break;
-      }
-#ifndef WEBRTC_LEGACY
-      case ARG_AGC2_GAIN: {
-        preProcCfgParams.agc2Gain = atof(optarg);
-        break;
-      }
-      case ARG_AGC2_LVL: {
-        preProcCfgParams.agc2Level = atoi(optarg);
-        break;
-      }
-      case ARG_AGC2_SAT_MGN: {
-        preProcCfgParams.agc2SaturationMargin = atof(optarg);
-        break;
-      }
-#endif
-      case ARG_AEC_DELAY: {
-        preProcCfgParams.aecDelay = atoi(optarg);
-        break;
-      }
-      case ARG_NS_LVL: {
-        preProcCfgParams.nsLevel = atoi(optarg);
-        break;
-      }
-      default:
-        break;
-    }
-  }
-
-  if (inputFile == nullptr) {
-    ALOGE("Error: missing input file\n");
-    printUsage();
-    return EXIT_FAILURE;
-  }
-
-  std::unique_ptr<FILE, decltype(&fclose)> inputFp(fopen(inputFile, "rb"), &fclose);
-  if (inputFp == nullptr) {
-    ALOGE("Cannot open input file %s\n", inputFile);
-    return EXIT_FAILURE;
-  }
-
-  std::unique_ptr<FILE, decltype(&fclose)> farFp(fopen(farFile, "rb"), &fclose);
-  std::unique_ptr<FILE, decltype(&fclose)> outputFp(fopen(outputFile, "wb"), &fclose);
-  if (effectEn[PREPROC_AEC]) {
-    if (farFile == nullptr) {
-      ALOGE("Far end signal file required for echo cancellation \n");
-      return EXIT_FAILURE;
-    }
-    if (farFp == nullptr) {
-      ALOGE("Cannot open far end stream file %s\n", farFile);
-      return EXIT_FAILURE;
-    }
-    struct stat statInput, statFar;
-    (void)fstat(fileno(inputFp.get()), &statInput);
-    (void)fstat(fileno(farFp.get()), &statFar);
-    if (statInput.st_size != statFar.st_size) {
-      ALOGE("Near and far end signals are of different sizes");
-      return EXIT_FAILURE;
-    }
-  }
-  if (outputFile != nullptr && outputFp == nullptr) {
-    ALOGE("Cannot open output file %s\n", outputFile);
-    return EXIT_FAILURE;
-  }
-
-  int32_t sessionId = 1;
-  int32_t ioId = 1;
-  effect_handle_t effectHandle[PREPROC_NUM_EFFECTS] = {nullptr};
-  effect_config_t config;
-  config.inputCfg.samplingRate = config.outputCfg.samplingRate = preProcCfgParams.samplingFreq;
-  config.inputCfg.channels = config.outputCfg.channels = preProcCfgParams.chMask;
-  config.inputCfg.format = config.outputCfg.format = AUDIO_FORMAT_PCM_16_BIT;
-
-  // Create all the effect handles
-  for (int i = 0; i < PREPROC_NUM_EFFECTS; i++) {
-    if (int status = preProcCreateEffect(&effectHandle[i], i, &config, sessionId, ioId);
-        status != 0) {
-      ALOGE("Create effect call returned error %i", status);
-      return EXIT_FAILURE;
-    }
-  }
-
-  for (int i = 0; i < PREPROC_NUM_EFFECTS; i++) {
-    if (effectEn[i] == 1) {
-      int reply = 0;
-      uint32_t replySize = sizeof(reply);
-      (*effectHandle[i])
-          ->command(effectHandle[i], EFFECT_CMD_ENABLE, 0, nullptr, &replySize, &reply);
-      if (reply != 0) {
-        ALOGE("Command enable call returned error %d\n", reply);
         return EXIT_FAILURE;
-      }
     }
-  }
+    const char* inputFile = nullptr;
+    const char* outputFile = nullptr;
+    const char* farFile = nullptr;
+    int effectEn[PREPROC_NUM_EFFECTS] = {0};
 
-  // Set Config Params of the effects
-  if (effectEn[PREPROC_AGC]) {
-    if (int status = preProcSetConfigParam(AGC_PARAM_TARGET_LEVEL,
-                                           (uint32_t)preProcCfgParams.agcTargetLevel,
-                                           effectHandle[PREPROC_AGC]);
-        status != 0) {
-      ALOGE("Invalid AGC Target Level. Error %d\n", status);
-      return EXIT_FAILURE;
-    }
-    if (int status =
-            preProcSetConfigParam(AGC_PARAM_COMP_GAIN, (uint32_t)preProcCfgParams.agcCompLevel,
-                                  effectHandle[PREPROC_AGC]);
-        status != 0) {
-      ALOGE("Invalid AGC Comp Gain. Error %d\n", status);
-      return EXIT_FAILURE;
-    }
-  }
+    const option long_opts[] = {
+            {"help", no_argument, nullptr, ARG_HELP},
+            {"input", required_argument, nullptr, ARG_INPUT},
+            {"output", required_argument, nullptr, ARG_OUTPUT},
+            {"far", required_argument, nullptr, ARG_FAR},
+            {"fs", required_argument, nullptr, ARG_FS},
+            {"ch_mask", required_argument, nullptr, ARG_CH_MASK},
+            {"agc_tgt_lvl", required_argument, nullptr, ARG_AGC_TGT_LVL},
+            {"agc_comp_lvl", required_argument, nullptr, ARG_AGC_COMP_LVL},
 #ifndef WEBRTC_LEGACY
-  if (effectEn[PREPROC_AGC2]) {
-    if (int status = preProcSetConfigParam(AGC2_PARAM_FIXED_DIGITAL_GAIN,
-                                           (float)preProcCfgParams.agc2Gain,
-                                           effectHandle[PREPROC_AGC2]);
-        status != 0) {
-      ALOGE("Invalid AGC2 Fixed Digital Gain. Error %d\n", status);
-      return EXIT_FAILURE;
-    }
-    if (int status = preProcSetConfigParam(AGC2_PARAM_ADAPT_DIGI_LEVEL_ESTIMATOR,
-                                           (uint32_t)preProcCfgParams.agc2Level,
-                                           effectHandle[PREPROC_AGC2]);
-        status != 0) {
-      ALOGE("Invalid AGC2 Level Estimator. Error %d\n", status);
-      return EXIT_FAILURE;
-    }
-    if (int status = preProcSetConfigParam(AGC2_PARAM_ADAPT_DIGI_EXTRA_SATURATION_MARGIN,
-                                           (float)preProcCfgParams.agc2SaturationMargin,
-                                           effectHandle[PREPROC_AGC2]);
-        status != 0) {
-      ALOGE("Invalid AGC2 Saturation Margin. Error %d\n", status);
-      return EXIT_FAILURE;
-    }
-  }
+            {"agc2_gain", required_argument, nullptr, ARG_AGC2_GAIN},
+            {"agc2_lvl", required_argument, nullptr, ARG_AGC2_LVL},
+            {"agc2_sat_mgn", required_argument, nullptr, ARG_AGC2_SAT_MGN},
 #endif
-  if (effectEn[PREPROC_NS]) {
-    if (int status = preProcSetConfigParam(NS_PARAM_LEVEL, (uint32_t)preProcCfgParams.nsLevel,
-                                           effectHandle[PREPROC_NS]);
-        status != 0) {
-      ALOGE("Invalid Noise Suppression level Error %d\n", status);
-      return EXIT_FAILURE;
-    }
-  }
+            {"aec_delay", required_argument, nullptr, ARG_AEC_DELAY},
+            {"ns_lvl", required_argument, nullptr, ARG_NS_LVL},
+            {"aec", no_argument, &effectEn[PREPROC_AEC], 1},
+            {"agc", no_argument, &effectEn[PREPROC_AGC], 1},
 #ifndef WEBRTC_LEGACY
-  if (effectEn[PREPROC_AEC]) {
-    if (int status = preProcSetConfigParam(AEC_PARAM_MOBILE_MODE, (uint32_t)aecMobileMode,
-                                           effectHandle[PREPROC_AEC]);
-        status != 0) {
-      ALOGE("Invalid AEC mobile mode value %d\n", status);
-      return EXIT_FAILURE;
-    }
-  }
+            {"agc2", no_argument, &effectEn[PREPROC_AGC2], 1},
 #endif
+            {"ns", no_argument, &effectEn[PREPROC_NS], 1},
+            {nullptr, 0, nullptr, 0},
+    };
+    struct preProcConfigParams_t preProcCfgParams {};
 
-  // Process Call
-  const int frameLength = (int)(preProcCfgParams.samplingFreq * kTenMilliSecVal);
-  const int ioChannelCount = audio_channel_count_from_in_mask(preProcCfgParams.chMask);
-  const int ioFrameSize = ioChannelCount * sizeof(short);
-  int frameCounter = 0;
-  while (true) {
-    std::vector<short> in(frameLength * ioChannelCount);
-    std::vector<short> out(frameLength * ioChannelCount);
-    std::vector<short> farIn(frameLength * ioChannelCount);
-    size_t samplesRead = fread(in.data(), ioFrameSize, frameLength, inputFp.get());
-    if (samplesRead == 0) {
-      break;
+    while (true) {
+        const int opt = getopt_long(argc, (char* const*)argv, "i:o:", long_opts, nullptr);
+        if (opt == -1) {
+            break;
+        }
+        switch (opt) {
+            case ARG_HELP:
+                printUsage();
+                return 0;
+            case ARG_INPUT: {
+                inputFile = (char*)optarg;
+                break;
+            }
+            case ARG_OUTPUT: {
+                outputFile = (char*)optarg;
+                break;
+            }
+            case ARG_FAR: {
+                farFile = (char*)optarg;
+                break;
+            }
+            case ARG_FS: {
+                preProcCfgParams.samplingFreq = atoi(optarg);
+                break;
+            }
+            case ARG_CH_MASK: {
+                int chMaskIdx = atoi(optarg);
+                if (chMaskIdx < 0 or chMaskIdx > kPreProcConfigChMaskCount) {
+                    ALOGE("Channel Mask index not in correct range\n");
+                    printUsage();
+                    return EXIT_FAILURE;
+                }
+                preProcCfgParams.chMask = kPreProcConfigChMask[chMaskIdx];
+                break;
+            }
+            case ARG_AGC_TGT_LVL: {
+                preProcCfgParams.agcTargetLevel = atoi(optarg);
+                break;
+            }
+            case ARG_AGC_COMP_LVL: {
+                preProcCfgParams.agcCompLevel = atoi(optarg);
+                break;
+            }
+#ifndef WEBRTC_LEGACY
+            case ARG_AGC2_GAIN: {
+                preProcCfgParams.agc2Gain = atof(optarg);
+                break;
+            }
+            case ARG_AGC2_LVL: {
+                preProcCfgParams.agc2Level = atoi(optarg);
+                break;
+            }
+            case ARG_AGC2_SAT_MGN: {
+                preProcCfgParams.agc2SaturationMargin = atof(optarg);
+                break;
+            }
+#endif
+            case ARG_AEC_DELAY: {
+                preProcCfgParams.aecDelay = atoi(optarg);
+                break;
+            }
+            case ARG_NS_LVL: {
+                preProcCfgParams.nsLevel = atoi(optarg);
+                break;
+            }
+            default:
+                break;
+        }
     }
-    audio_buffer_t inputBuffer, outputBuffer;
-    audio_buffer_t farInBuffer{};
-    inputBuffer.frameCount = samplesRead;
-    outputBuffer.frameCount = samplesRead;
-    inputBuffer.s16 = in.data();
-    outputBuffer.s16 = out.data();
 
-    if (farFp != nullptr) {
-      samplesRead = fread(farIn.data(), ioFrameSize, frameLength, farFp.get());
-      if (samplesRead == 0) {
-        break;
-      }
-      farInBuffer.frameCount = samplesRead;
-      farInBuffer.s16 = farIn.data();
+    if (inputFile == nullptr) {
+        ALOGE("Error: missing input file\n");
+        printUsage();
+        return EXIT_FAILURE;
+    }
+
+    std::unique_ptr<FILE, decltype(&fclose)> inputFp(fopen(inputFile, "rb"), &fclose);
+    if (inputFp == nullptr) {
+        ALOGE("Cannot open input file %s\n", inputFile);
+        return EXIT_FAILURE;
+    }
+
+    std::unique_ptr<FILE, decltype(&fclose)> farFp(fopen(farFile, "rb"), &fclose);
+    std::unique_ptr<FILE, decltype(&fclose)> outputFp(fopen(outputFile, "wb"), &fclose);
+    if (effectEn[PREPROC_AEC]) {
+        if (farFile == nullptr) {
+            ALOGE("Far end signal file required for echo cancellation \n");
+            return EXIT_FAILURE;
+        }
+        if (farFp == nullptr) {
+            ALOGE("Cannot open far end stream file %s\n", farFile);
+            return EXIT_FAILURE;
+        }
+        struct stat statInput, statFar;
+        (void)fstat(fileno(inputFp.get()), &statInput);
+        (void)fstat(fileno(farFp.get()), &statFar);
+        if (statInput.st_size != statFar.st_size) {
+            ALOGE("Near and far end signals are of different sizes");
+            return EXIT_FAILURE;
+        }
+    }
+    if (outputFile != nullptr && outputFp == nullptr) {
+        ALOGE("Cannot open output file %s\n", outputFile);
+        return EXIT_FAILURE;
+    }
+
+    int32_t sessionId = 1;
+    int32_t ioId = 1;
+    effect_handle_t effectHandle[PREPROC_NUM_EFFECTS] = {nullptr};
+    effect_config_t config;
+    config.inputCfg.samplingRate = config.outputCfg.samplingRate = preProcCfgParams.samplingFreq;
+    config.inputCfg.channels = config.outputCfg.channels = preProcCfgParams.chMask;
+    config.inputCfg.format = config.outputCfg.format = AUDIO_FORMAT_PCM_16_BIT;
+
+    // Create all the effect handles
+    for (int i = 0; i < PREPROC_NUM_EFFECTS; i++) {
+        if (int status = preProcCreateEffect(&effectHandle[i], i, &config, sessionId, ioId);
+            status != 0) {
+            ALOGE("Create effect call returned error %i", status);
+            return EXIT_FAILURE;
+        }
     }
 
     for (int i = 0; i < PREPROC_NUM_EFFECTS; i++) {
-      if (effectEn[i] == 1) {
-        if (i == PREPROC_AEC) {
-          if (int status =
-                  preProcSetConfigParam(AEC_PARAM_ECHO_DELAY, (uint32_t)preProcCfgParams.aecDelay,
-                                        effectHandle[PREPROC_AEC]);
-              status != 0) {
-            ALOGE("preProcSetConfigParam returned Error %d\n", status);
-            return EXIT_FAILURE;
-          }
+        if (effectEn[i] == 1) {
+            int reply = 0;
+            uint32_t replySize = sizeof(reply);
+            (*effectHandle[i])
+                    ->command(effectHandle[i], EFFECT_CMD_ENABLE, 0, nullptr, &replySize, &reply);
+            if (reply != 0) {
+                ALOGE("Command enable call returned error %d\n", reply);
+                return EXIT_FAILURE;
+            }
         }
-        if (int status =
-                (*effectHandle[i])->process(effectHandle[i], &inputBuffer, &outputBuffer);
+    }
+
+    // Set Config Params of the effects
+    if (effectEn[PREPROC_AGC]) {
+        if (int status = preProcSetConfigParam(AGC_PARAM_TARGET_LEVEL,
+                                               (uint32_t)preProcCfgParams.agcTargetLevel,
+                                               effectHandle[PREPROC_AGC]);
             status != 0) {
-          ALOGE("\nError: Process i = %d returned with error %d\n", i, status);
-          return EXIT_FAILURE;
-        }
-        if (i == PREPROC_AEC) {
-          if (int status = (*effectHandle[i])
-                               ->process_reverse(effectHandle[i], &farInBuffer, &outputBuffer);
-              status != 0) {
-            ALOGE("\nError: Process reverse i = %d returned with error %d\n", i, status);
+            ALOGE("Invalid AGC Target Level. Error %d\n", status);
             return EXIT_FAILURE;
-          }
         }
-      }
+        if (int status = preProcSetConfigParam(AGC_PARAM_COMP_GAIN,
+                                               (uint32_t)preProcCfgParams.agcCompLevel,
+                                               effectHandle[PREPROC_AGC]);
+            status != 0) {
+            ALOGE("Invalid AGC Comp Gain. Error %d\n", status);
+            return EXIT_FAILURE;
+        }
     }
-    if (outputFp != nullptr) {
-      size_t samplesWritten =
-          fwrite(out.data(), ioFrameSize, outputBuffer.frameCount, outputFp.get());
-      if (samplesWritten != outputBuffer.frameCount) {
-        ALOGE("\nError: Output file writing failed");
-        break;
-      }
+#ifndef WEBRTC_LEGACY
+    if (effectEn[PREPROC_AGC2]) {
+        if (int status = preProcSetConfigParam(AGC2_PARAM_FIXED_DIGITAL_GAIN,
+                                               (float)preProcCfgParams.agc2Gain,
+                                               effectHandle[PREPROC_AGC2]);
+            status != 0) {
+            ALOGE("Invalid AGC2 Fixed Digital Gain. Error %d\n", status);
+            return EXIT_FAILURE;
+        }
+        if (int status = preProcSetConfigParam(AGC2_PARAM_ADAPT_DIGI_LEVEL_ESTIMATOR,
+                                               (uint32_t)preProcCfgParams.agc2Level,
+                                               effectHandle[PREPROC_AGC2]);
+            status != 0) {
+            ALOGE("Invalid AGC2 Level Estimator. Error %d\n", status);
+            return EXIT_FAILURE;
+        }
+        if (int status = preProcSetConfigParam(AGC2_PARAM_ADAPT_DIGI_EXTRA_SATURATION_MARGIN,
+                                               (float)preProcCfgParams.agc2SaturationMargin,
+                                               effectHandle[PREPROC_AGC2]);
+            status != 0) {
+            ALOGE("Invalid AGC2 Saturation Margin. Error %d\n", status);
+            return EXIT_FAILURE;
+        }
     }
-    frameCounter += frameLength;
-  }
-  // Release all the effect handles created
-  for (int i = 0; i < PREPROC_NUM_EFFECTS; i++) {
-    if (int status = AUDIO_EFFECT_LIBRARY_INFO_SYM.release_effect(effectHandle[i]);
-        status != 0) {
-      ALOGE("Audio Preprocessing release returned an error = %d\n", status);
-      return EXIT_FAILURE;
+#endif
+    if (effectEn[PREPROC_NS]) {
+        if (int status = preProcSetConfigParam(NS_PARAM_LEVEL, (uint32_t)preProcCfgParams.nsLevel,
+                                               effectHandle[PREPROC_NS]);
+            status != 0) {
+            ALOGE("Invalid Noise Suppression level Error %d\n", status);
+            return EXIT_FAILURE;
+        }
     }
-  }
-  return EXIT_SUCCESS;
+
+    // Process Call
+    const int frameLength = (int)(preProcCfgParams.samplingFreq * kTenMilliSecVal);
+    const int ioChannelCount = audio_channel_count_from_in_mask(preProcCfgParams.chMask);
+    const int ioFrameSize = ioChannelCount * sizeof(short);
+    int frameCounter = 0;
+    while (true) {
+        std::vector<short> in(frameLength * ioChannelCount);
+        std::vector<short> out(frameLength * ioChannelCount);
+        std::vector<short> farIn(frameLength * ioChannelCount);
+        size_t samplesRead = fread(in.data(), ioFrameSize, frameLength, inputFp.get());
+        if (samplesRead == 0) {
+            break;
+        }
+        audio_buffer_t inputBuffer, outputBuffer;
+        audio_buffer_t farInBuffer{};
+        inputBuffer.frameCount = samplesRead;
+        outputBuffer.frameCount = samplesRead;
+        inputBuffer.s16 = in.data();
+        outputBuffer.s16 = out.data();
+
+        if (farFp != nullptr) {
+            samplesRead = fread(farIn.data(), ioFrameSize, frameLength, farFp.get());
+            if (samplesRead == 0) {
+                break;
+            }
+            farInBuffer.frameCount = samplesRead;
+            farInBuffer.s16 = farIn.data();
+        }
+
+        for (int i = 0; i < PREPROC_NUM_EFFECTS; i++) {
+            if (effectEn[i] == 1) {
+                if (i == PREPROC_AEC) {
+                    if (int status = preProcSetConfigParam(AEC_PARAM_ECHO_DELAY,
+                                                           (uint32_t)preProcCfgParams.aecDelay,
+                                                           effectHandle[PREPROC_AEC]);
+                        status != 0) {
+                        ALOGE("preProcSetConfigParam returned Error %d\n", status);
+                        return EXIT_FAILURE;
+                    }
+                }
+                if (int status = (*effectHandle[i])
+                                         ->process(effectHandle[i], &inputBuffer, &outputBuffer);
+                    status != 0) {
+                    ALOGE("\nError: Process i = %d returned with error %d\n", i, status);
+                    return EXIT_FAILURE;
+                }
+                if (i == PREPROC_AEC) {
+                    if (int status = (*effectHandle[i])
+                                             ->process_reverse(effectHandle[i], &farInBuffer,
+                                                               &outputBuffer);
+                        status != 0) {
+                        ALOGE("\nError: Process reverse i = %d returned with error %d\n", i,
+                              status);
+                        return EXIT_FAILURE;
+                    }
+                }
+            }
+        }
+        if (outputFp != nullptr) {
+            size_t samplesWritten =
+                    fwrite(out.data(), ioFrameSize, outputBuffer.frameCount, outputFp.get());
+            if (samplesWritten != outputBuffer.frameCount) {
+                ALOGE("\nError: Output file writing failed");
+                break;
+            }
+        }
+        frameCounter += frameLength;
+    }
+    // Release all the effect handles created
+    for (int i = 0; i < PREPROC_NUM_EFFECTS; i++) {
+        if (int status = AUDIO_EFFECT_LIBRARY_INFO_SYM.release_effect(effectHandle[i]);
+            status != 0) {
+            ALOGE("Audio Preprocessing release returned an error = %d\n", status);
+            return EXIT_FAILURE;
+        }
+    }
+    return EXIT_SUCCESS;
 }
diff --git a/media/libmediahelper/TypeConverter.cpp b/media/libmediahelper/TypeConverter.cpp
index 705959a..876dc45 100644
--- a/media/libmediahelper/TypeConverter.cpp
+++ b/media/libmediahelper/TypeConverter.cpp
@@ -32,18 +32,21 @@
     MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_BLUETOOTH_SCO),
     MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET),
     MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT),
-    MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_ALL_SCO),
+    // TODO(mnaganov): Remove from here, use 'audio_is_bluetooth_out_sco_device' function.
+    { "AUDIO_DEVICE_OUT_ALL_SCO", static_cast<audio_devices_t>(AUDIO_DEVICE_OUT_ALL_SCO) },
     MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_BLUETOOTH_A2DP),
     MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES),
     MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER),
-    MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_ALL_A2DP),
+    // TODO(mnaganov): Remove from here, use 'audio_is_a2dp_out_device' function.
+    { "AUDIO_DEVICE_OUT_ALL_A2DP", static_cast<audio_devices_t>(AUDIO_DEVICE_OUT_ALL_A2DP) },
     MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_AUX_DIGITAL),
     MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_HDMI),
     MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET),
     MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET),
     MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_USB_ACCESSORY),
     MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_USB_DEVICE),
-    MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_ALL_USB),
+    // TODO(mnaganov): Remove from here, use 'audio_is_usb_out_device' function.
+    { "AUDIO_DEVICE_OUT_ALL_USB", static_cast<audio_devices_t>(AUDIO_DEVICE_OUT_ALL_USB) },
     MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_REMOTE_SUBMIX),
     MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_TELEPHONY_TX),
     MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_OUT_LINE),
@@ -72,7 +75,8 @@
     MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_AMBIENT),
     MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BUILTIN_MIC),
     MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET),
-    MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_ALL_SCO),
+    // TODO(mnaganov): Remove from here, use 'audio_is_bluetooth_in_sco_device' function.
+    { "AUDIO_DEVICE_IN_ALL_SCO", static_cast<audio_devices_t>(AUDIO_DEVICE_IN_ALL_SCO) },
     MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_WIRED_HEADSET),
     MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_AUX_DIGITAL),
     MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_HDMI),
@@ -85,7 +89,8 @@
     MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET),
     MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_ACCESSORY),
     MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_USB_DEVICE),
-    MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_ALL_USB),
+    // TODO(mnaganov): Remove from here, use 'audio_is_usb_in_device' function.
+    { "AUDIO_DEVICE_IN_ALL_USB", static_cast<audio_devices_t>(AUDIO_DEVICE_IN_ALL_USB) },
     MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_FM_TUNER),
     MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_TV_TUNER),
     MAKE_STRING_FROM_ENUM(AUDIO_DEVICE_IN_LINE),
diff --git a/media/libmediametrics/Android.bp b/media/libmediametrics/Android.bp
index 03068c7..ba84761 100644
--- a/media/libmediametrics/Android.bp
+++ b/media/libmediametrics/Android.bp
@@ -3,7 +3,7 @@
     export_include_dirs: ["include"],
 }
 
-cc_library_shared {
+cc_library {
     name: "libmediametrics",
 
     srcs: [
diff --git a/media/libmediaplayerservice/StagefrightRecorder.cpp b/media/libmediaplayerservice/StagefrightRecorder.cpp
index 7897959..71beceb 100644
--- a/media/libmediaplayerservice/StagefrightRecorder.cpp
+++ b/media/libmediaplayerservice/StagefrightRecorder.cpp
@@ -125,6 +125,7 @@
 
     ALOGV("Constructor");
 
+    mMetricsItem = NULL;
     mAnalyticsDirty = false;
     reset();
 }
@@ -199,10 +200,12 @@
 void StagefrightRecorder::flushAndResetMetrics(bool reinitialize) {
     ALOGV("flushAndResetMetrics");
     // flush anything we have, maybe setup a new record
-    if (mAnalyticsDirty && mMetricsItem != NULL) {
-        updateMetrics();
-        if (mMetricsItem->count() > 0) {
-            mMetricsItem->selfrecord();
+    if (mMetricsItem != NULL) {
+        if (mAnalyticsDirty) {
+            updateMetrics();
+            if (mMetricsItem->count() > 0) {
+                mMetricsItem->selfrecord();
+            }
         }
         delete mMetricsItem;
         mMetricsItem = NULL;
@@ -1113,7 +1116,7 @@
     if (mPrivacySensitive == PRIVACY_SENSITIVE_DEFAULT) {
         if (attr.source == AUDIO_SOURCE_VOICE_COMMUNICATION
                 || attr.source == AUDIO_SOURCE_CAMCORDER) {
-            attr.flags |= AUDIO_FLAG_CAPTURE_PRIVATE;
+            attr.flags = static_cast<audio_flags_mask_t>(attr.flags | AUDIO_FLAG_CAPTURE_PRIVATE);
             mPrivacySensitive = PRIVACY_SENSITIVE_ENABLED;
         } else {
             mPrivacySensitive = PRIVACY_SENSITIVE_DISABLED;
@@ -1129,7 +1132,7 @@
             return NULL;
         }
         if (mPrivacySensitive == PRIVACY_SENSITIVE_ENABLED) {
-            attr.flags |= AUDIO_FLAG_CAPTURE_PRIVATE;
+            attr.flags = static_cast<audio_flags_mask_t>(attr.flags | AUDIO_FLAG_CAPTURE_PRIVATE);
         }
     }
 
diff --git a/media/libmediaplayerservice/include/MediaPlayerInterface.h b/media/libmediaplayerservice/include/MediaPlayerInterface.h
index 436cb31..81da5b9 100644
--- a/media/libmediaplayerservice/include/MediaPlayerInterface.h
+++ b/media/libmediaplayerservice/include/MediaPlayerInterface.h
@@ -60,7 +60,7 @@
 #define DEFAULT_AUDIOSINK_SAMPLERATE 44100
 
 // when the channel mask isn't known, use the channel count to derive a mask in AudioSink::open()
-#define CHANNEL_MASK_USE_CHANNEL_ORDER 0
+#define CHANNEL_MASK_USE_CHANNEL_ORDER AUDIO_CHANNEL_NONE
 
 // duration below which we do not allow deep audio buffering
 #define AUDIO_SINK_MIN_DEEP_BUFFER_DURATION_US 5000000
diff --git a/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.cpp b/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.cpp
index 7e8fe45..6a8c708 100644
--- a/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.cpp
+++ b/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.cpp
@@ -1933,11 +1933,12 @@
     int32_t numChannels;
     CHECK(format->findInt32("channel-count", &numChannels));
 
-    int32_t channelMask;
-    if (!format->findInt32("channel-mask", &channelMask)) {
-        // signal to the AudioSink to derive the mask from count.
-        channelMask = CHANNEL_MASK_USE_CHANNEL_ORDER;
-    }
+    int32_t rawChannelMask;
+    audio_channel_mask_t channelMask =
+            format->findInt32("channel-mask", &rawChannelMask) ?
+                    static_cast<audio_channel_mask_t>(rawChannelMask)
+                    // signal to the AudioSink to derive the mask from count.
+                    : CHANNEL_MASK_USE_CHANNEL_ORDER;
 
     int32_t sampleRate;
     CHECK(format->findInt32("sample-rate", &sampleRate));
diff --git a/media/libstagefright/ACodec.cpp b/media/libstagefright/ACodec.cpp
index ffe3052..bc84d78 100644
--- a/media/libstagefright/ACodec.cpp
+++ b/media/libstagefright/ACodec.cpp
@@ -5320,6 +5320,34 @@
                     if (mChannelMaskPresent) {
                         notify->setInt32("channel-mask", mChannelMask);
                     }
+
+                    if (!mIsEncoder && portIndex == kPortIndexOutput) {
+                        AString mime;
+                        if (mConfigFormat->findString("mime", &mime)
+                                && !strcasecmp(MEDIA_MIMETYPE_AUDIO_AAC, mime.c_str())) {
+
+                            OMX_AUDIO_PARAM_ANDROID_AACDRCPRESENTATIONTYPE presentation;
+                            InitOMXParams(&presentation);
+                            err = mOMXNode->getParameter(
+                                    (OMX_INDEXTYPE)OMX_IndexParamAudioAndroidAacDrcPresentation,
+                                    &presentation, sizeof(presentation));
+                            if (err != OK) {
+                                return err;
+                            }
+                            notify->setInt32("aac-encoded-target-level",
+                                             presentation.nEncodedTargetLevel);
+                            notify->setInt32("aac-drc-cut-level", presentation.nDrcCut);
+                            notify->setInt32("aac-drc-boost-level", presentation.nDrcBoost);
+                            notify->setInt32("aac-drc-heavy-compression",
+                                             presentation.nHeavyCompression);
+                            notify->setInt32("aac-target-ref-level",
+                                             presentation.nTargetReferenceLevel);
+                            notify->setInt32("aac-drc-effect-type", presentation.nDrcEffectType);
+                            notify->setInt32("aac-drc-album-mode", presentation.nDrcAlbumMode);
+                            notify->setInt32("aac-drc-output-loudness",
+                                             presentation.nDrcOutputLoudness);
+                        }
+                    }
                     break;
                 }
 
@@ -7767,6 +7795,58 @@
     // Ignore errors as failure is expected for codecs that aren't video encoders.
     (void)configureTemporalLayers(params, false /* inConfigure */, mOutputFormat);
 
+    AString mime;
+    if (!mIsEncoder
+            && (mConfigFormat->findString("mime", &mime))
+            && !strcasecmp(MEDIA_MIMETYPE_AUDIO_AAC, mime.c_str())) {
+        OMX_AUDIO_PARAM_ANDROID_AACDRCPRESENTATIONTYPE presentation;
+        InitOMXParams(&presentation);
+        mOMXNode->getParameter(
+                    (OMX_INDEXTYPE)OMX_IndexParamAudioAndroidAacDrcPresentation,
+                    &presentation, sizeof(presentation));
+        int32_t value32 = 0;
+        bool updated = false;
+        if (params->findInt32("aac-pcm-limiter-enable", &value32)) {
+            presentation.nPCMLimiterEnable = value32;
+            updated = true;
+        }
+        if (params->findInt32("aac-encoded-target-level", &value32)) {
+            presentation.nEncodedTargetLevel = value32;
+            updated = true;
+        }
+        if (params->findInt32("aac-drc-cut-level", &value32)) {
+            presentation.nDrcCut = value32;
+            updated = true;
+        }
+        if (params->findInt32("aac-drc-boost-level", &value32)) {
+            presentation.nDrcBoost = value32;
+            updated = true;
+        }
+        if (params->findInt32("aac-drc-heavy-compression", &value32)) {
+            presentation.nHeavyCompression = value32;
+            updated = true;
+        }
+        if (params->findInt32("aac-target-ref-level", &value32)) {
+            presentation.nTargetReferenceLevel = value32;
+            updated = true;
+        }
+        if (params->findInt32("aac-drc-effect-type", &value32)) {
+            presentation.nDrcEffectType = value32;
+            updated = true;
+        }
+        if (params->findInt32("aac-drc-album-mode", &value32)) {
+            presentation.nDrcAlbumMode = value32;
+            updated = true;
+        }
+        if (!params->findInt32("aac-drc-output-loudness", &value32)) {
+            presentation.nDrcOutputLoudness = value32;
+            updated = true;
+        }
+        if (updated) {
+            mOMXNode->setParameter((OMX_INDEXTYPE)OMX_IndexParamAudioAndroidAacDrcPresentation,
+                &presentation, sizeof(presentation));
+        }
+    }
     return setVendorParameters(params);
 }
 
diff --git a/media/libstagefright/Utils.cpp b/media/libstagefright/Utils.cpp
index d67874f..c005bf6 100644
--- a/media/libstagefright/Utils.cpp
+++ b/media/libstagefright/Utils.cpp
@@ -2136,8 +2136,10 @@
     }
     info->sample_rate = srate;
 
-    int32_t cmask = 0;
-    if (!meta->findInt32(kKeyChannelMask, &cmask) || cmask == CHANNEL_MASK_USE_CHANNEL_ORDER) {
+    int32_t rawChannelMask;
+    audio_channel_mask_t cmask = meta->findInt32(kKeyChannelMask, &rawChannelMask) ?
+            static_cast<audio_channel_mask_t>(rawChannelMask) : CHANNEL_MASK_USE_CHANNEL_ORDER;
+    if (cmask == CHANNEL_MASK_USE_CHANNEL_ORDER) {
         ALOGV("track of type '%s' does not publish channel mask", mime);
 
         // Try a channel count instead
diff --git a/media/libstagefright/codecs/aacdec/SoftAAC2.cpp b/media/libstagefright/codecs/aacdec/SoftAAC2.cpp
index 2aeddd7..28a7a1e 100644
--- a/media/libstagefright/codecs/aacdec/SoftAAC2.cpp
+++ b/media/libstagefright/codecs/aacdec/SoftAAC2.cpp
@@ -38,6 +38,7 @@
 #define DRC_DEFAULT_MOBILE_DRC_HEAVY 1   /* switch for heavy compression for mobile conf */
 #define DRC_DEFAULT_MOBILE_DRC_EFFECT 3  /* MPEG-D DRC effect type; 3 => Limited playback range */
 #define DRC_DEFAULT_MOBILE_DRC_ALBUM 0  /* MPEG-D DRC album mode; 0 => album mode is disabled, 1 => album mode is enabled */
+#define DRC_DEFAULT_MOBILE_OUTPUT_LOUDNESS -1 /* decoder output loudness; -1 => the value is unknown, otherwise dB step value (e.g. 64 for -16 dB) */
 #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 MAX_CHANNEL_COUNT            8  /* maximum number of audio channels that can be decoded */
 // names of properties that can be used to override the default DRC settings
@@ -230,6 +231,15 @@
     // For seven and eight channel input streams, enable 6.1 and 7.1 channel output
     aacDecoder_SetParam(mAACDecoder, AAC_PCM_MAX_OUTPUT_CHANNELS, -1);
 
+    mDrcCompressMode = DRC_DEFAULT_MOBILE_DRC_HEAVY;
+    mDrcTargetRefLevel = DRC_DEFAULT_MOBILE_REF_LEVEL;
+    mDrcEncTargetLevel = DRC_DEFAULT_MOBILE_ENC_LEVEL;
+    mDrcBoostFactor = DRC_DEFAULT_MOBILE_DRC_BOOST;
+    mDrcAttenuationFactor = DRC_DEFAULT_MOBILE_DRC_CUT;
+    mDrcEffectType = DRC_DEFAULT_MOBILE_DRC_EFFECT;
+    mDrcAlbumMode = DRC_DEFAULT_MOBILE_DRC_ALBUM;
+    mDrcOutputLoudness = DRC_DEFAULT_MOBILE_OUTPUT_LOUDNESS;
+
     return status;
 }
 
@@ -358,6 +368,27 @@
             return OMX_ErrorNone;
         }
 
+        case OMX_IndexParamAudioAndroidAacDrcPresentation:
+        {
+             OMX_AUDIO_PARAM_ANDROID_AACDRCPRESENTATIONTYPE *aacPresParams =
+                    (OMX_AUDIO_PARAM_ANDROID_AACDRCPRESENTATIONTYPE *)params;
+
+            ALOGD("get OMX_IndexParamAudioAndroidAacDrcPresentation");
+
+            if (!isValidOMXParam(aacPresParams)) {
+                return OMX_ErrorBadParameter;
+            }
+            aacPresParams->nDrcEffectType = mDrcEffectType;
+            aacPresParams->nDrcAlbumMode = mDrcAlbumMode;
+            aacPresParams->nDrcBoost =  mDrcBoostFactor;
+            aacPresParams->nDrcCut = mDrcAttenuationFactor;
+            aacPresParams->nHeavyCompression = mDrcCompressMode;
+            aacPresParams->nTargetReferenceLevel = mDrcTargetRefLevel;
+            aacPresParams->nEncodedTargetLevel = mDrcEncTargetLevel;
+            aacPresParams ->nDrcOutputLoudness = mDrcOutputLoudness;
+            return OMX_ErrorNone;
+        }
+
         default:
             return SimpleSoftOMXComponent::internalGetParameter(index, params);
     }
@@ -464,11 +495,13 @@
             if (aacPresParams->nDrcEffectType >= -1) {
                 ALOGV("set nDrcEffectType=%d", aacPresParams->nDrcEffectType);
                 aacDecoder_SetParam(mAACDecoder, AAC_UNIDRC_SET_EFFECT, aacPresParams->nDrcEffectType);
+                mDrcEffectType = aacPresParams->nDrcEffectType;
             }
             if (aacPresParams->nDrcAlbumMode >= -1) {
                 ALOGV("set nDrcAlbumMode=%d", aacPresParams->nDrcAlbumMode);
                 aacDecoder_SetParam(mAACDecoder, AAC_UNIDRC_ALBUM_MODE,
                         aacPresParams->nDrcAlbumMode);
+                mDrcAlbumMode = aacPresParams->nDrcAlbumMode;
             }
             bool updateDrcWrapper = false;
             if (aacPresParams->nDrcBoost >= 0) {
@@ -476,34 +509,42 @@
                 mDrcWrap.setParam(DRC_PRES_MODE_WRAP_DESIRED_BOOST_FACTOR,
                         aacPresParams->nDrcBoost);
                 updateDrcWrapper = true;
+                mDrcBoostFactor = aacPresParams->nDrcBoost;
             }
             if (aacPresParams->nDrcCut >= 0) {
                 ALOGV("set nDrcCut=%d", aacPresParams->nDrcCut);
                 mDrcWrap.setParam(DRC_PRES_MODE_WRAP_DESIRED_ATT_FACTOR, aacPresParams->nDrcCut);
                 updateDrcWrapper = true;
+                mDrcAttenuationFactor = aacPresParams->nDrcCut;
             }
             if (aacPresParams->nHeavyCompression >= 0) {
                 ALOGV("set nHeavyCompression=%d", aacPresParams->nHeavyCompression);
                 mDrcWrap.setParam(DRC_PRES_MODE_WRAP_DESIRED_HEAVY,
                         aacPresParams->nHeavyCompression);
                 updateDrcWrapper = true;
+                mDrcCompressMode = aacPresParams->nHeavyCompression;
             }
             if (aacPresParams->nTargetReferenceLevel >= -1) {
                 ALOGV("set nTargetReferenceLevel=%d", aacPresParams->nTargetReferenceLevel);
                 mDrcWrap.setParam(DRC_PRES_MODE_WRAP_DESIRED_TARGET,
                         aacPresParams->nTargetReferenceLevel);
                 updateDrcWrapper = true;
+                mDrcTargetRefLevel = aacPresParams->nTargetReferenceLevel;
             }
             if (aacPresParams->nEncodedTargetLevel >= 0) {
                 ALOGV("set nEncodedTargetLevel=%d", aacPresParams->nEncodedTargetLevel);
                 mDrcWrap.setParam(DRC_PRES_MODE_WRAP_ENCODER_TARGET,
                         aacPresParams->nEncodedTargetLevel);
                 updateDrcWrapper = true;
+                mDrcEncTargetLevel = aacPresParams->nEncodedTargetLevel;
             }
             if (aacPresParams->nPCMLimiterEnable >= 0) {
                 aacDecoder_SetParam(mAACDecoder, AAC_PCM_LIMITER_ENABLE,
                         (aacPresParams->nPCMLimiterEnable != 0));
             }
+            if (aacPresParams ->nDrcOutputLoudness != DRC_DEFAULT_MOBILE_OUTPUT_LOUDNESS) {
+                mDrcOutputLoudness = aacPresParams ->nDrcOutputLoudness;
+            }
             if (updateDrcWrapper) {
                 mDrcWrap.update();
             }
@@ -854,6 +895,11 @@
                     // fall through
                 }
 
+                if ( mDrcOutputLoudness != mStreamInfo->outputLoudness) {
+                    ALOGD("update Loudness, before = %d, now = %d", mDrcOutputLoudness, mStreamInfo->outputLoudness);
+                    mDrcOutputLoudness = mStreamInfo->outputLoudness;
+                }
+
                 /*
                  * AAC+/eAAC+ streams can be signalled in two ways: either explicitly
                  * or implicitly, according to MPEG4 spec. AAC+/eAAC+ is a dual
diff --git a/media/libstagefright/codecs/aacdec/SoftAAC2.h b/media/libstagefright/codecs/aacdec/SoftAAC2.h
index 5bee710..9f98aa1 100644
--- a/media/libstagefright/codecs/aacdec/SoftAAC2.h
+++ b/media/libstagefright/codecs/aacdec/SoftAAC2.h
@@ -85,6 +85,17 @@
     int32_t mOutputDelayRingBufferWritePos;
     int32_t mOutputDelayRingBufferReadPos;
     int32_t mOutputDelayRingBufferFilled;
+
+    //drc
+    int32_t mDrcCompressMode;
+    int32_t mDrcTargetRefLevel;
+    int32_t mDrcEncTargetLevel;
+    int32_t mDrcBoostFactor;
+    int32_t mDrcAttenuationFactor;
+    int32_t mDrcEffectType;
+    int32_t mDrcAlbumMode;
+    int32_t mDrcOutputLoudness;
+
     bool outputDelayRingBufferPutSamples(INT_PCM *samples, int numSamples);
     int32_t outputDelayRingBufferGetSamples(INT_PCM *samples, int numSamples);
     int32_t outputDelayRingBufferSamplesAvailable();
diff --git a/media/libstagefright/codecs/m4v_h263/fuzzer/mpeg4_h263_enc_fuzzer.cpp b/media/libstagefright/codecs/m4v_h263/fuzzer/mpeg4_h263_enc_fuzzer.cpp
index f154706..423325d 100644
--- a/media/libstagefright/codecs/m4v_h263/fuzzer/mpeg4_h263_enc_fuzzer.cpp
+++ b/media/libstagefright/codecs/m4v_h263/fuzzer/mpeg4_h263_enc_fuzzer.cpp
@@ -137,7 +137,8 @@
 void Codec::encodeFrames(const uint8_t *data, size_t size) {
     size_t inputBufferSize = (mFrameWidth * mFrameHeight * 3) / 2;
     size_t outputBufferSize = inputBufferSize * 2;
-    uint8_t outputBuffer[outputBufferSize];
+    uint8_t *outputBuffer = new uint8_t[outputBufferSize];
+    uint8_t *inputBuffer = new uint8_t[inputBufferSize];
 
     // Get VOL header.
     int32_t sizeOutputBuffer = outputBufferSize;
@@ -146,10 +147,9 @@
     size_t numFrame = 0;
     while (size > 0) {
         size_t bytesConsumed = std::min(size, inputBufferSize);
-        uint8_t inputBuffer[inputBufferSize];
         memcpy(inputBuffer, data, bytesConsumed);
-        if (bytesConsumed < sizeof(inputBuffer)) {
-            memset(inputBuffer + bytesConsumed, data[0], sizeof(inputBuffer) - bytesConsumed);
+        if (bytesConsumed < inputBufferSize) {
+            memset(inputBuffer + bytesConsumed, data[0], inputBufferSize - bytesConsumed);
         }
         VideoEncFrameIO videoIn{}, videoOut{};
         videoIn.height = mFrameHeight;
@@ -170,6 +170,8 @@
         data += bytesConsumed;
         size -= bytesConsumed;
     }
+    delete[] inputBuffer;
+    delete[] outputBuffer;
 }
 
 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
diff --git a/media/libstagefright/omx/SimpleSoftOMXComponent.cpp b/media/libstagefright/omx/SimpleSoftOMXComponent.cpp
index ddb459f..44415aa 100644
--- a/media/libstagefright/omx/SimpleSoftOMXComponent.cpp
+++ b/media/libstagefright/omx/SimpleSoftOMXComponent.cpp
@@ -17,6 +17,10 @@
 //#define LOG_NDEBUG 0
 #define LOG_TAG "SimpleSoftOMXComponent"
 #include <utils/Log.h>
+#include <OMX_Core.h>
+#include <OMX_Audio.h>
+#include <OMX_IndexExt.h>
+#include <OMX_AudioExt.h>
 
 #include <media/stagefright/omx/SimpleSoftOMXComponent.h>
 #include <media/stagefright/foundation/ADebug.h>
@@ -74,7 +78,7 @@
 
     OMX_U32 portIndex;
 
-    switch (index) {
+    switch ((int)index) {
         case OMX_IndexParamPortDefinition:
         {
             const OMX_PARAM_PORTDEFINITIONTYPE *portDefs =
@@ -108,6 +112,19 @@
             break;
         }
 
+         case OMX_IndexParamAudioAndroidAacDrcPresentation:
+        {
+            if (mState == OMX_StateInvalid) {
+                return false;
+            }
+            const OMX_AUDIO_PARAM_ANDROID_AACDRCPRESENTATIONTYPE *aacPresParams =
+                            (const OMX_AUDIO_PARAM_ANDROID_AACDRCPRESENTATIONTYPE *)params;
+            if (!isValidOMXParam(aacPresParams)) {
+                return false;
+            }
+            return true;
+         }
+
         default:
             return false;
     }
diff --git a/services/audioflinger/AudioFlinger.h b/services/audioflinger/AudioFlinger.h
index 20f561e..c47afd5 100644
--- a/services/audioflinger/AudioFlinger.h
+++ b/services/audioflinger/AudioFlinger.h
@@ -405,7 +405,7 @@
         case AUDIO_CHANNEL_REPRESENTATION_POSITION: {
             // Haptic channel mask is only applicable for channel position mask.
             const uint32_t channelCount = audio_channel_count_from_out_mask(
-                    channelMask & ~AUDIO_CHANNEL_HAPTIC_ALL);
+                    static_cast<audio_channel_mask_t>(channelMask & ~AUDIO_CHANNEL_HAPTIC_ALL));
             const uint32_t maxChannelCount = kEnableExtendedChannels
                     ? AudioMixer::MAX_NUM_CHANNELS : FCC_2;
             if (channelCount < FCC_2 // mono is not supported at this time
diff --git a/services/audioflinger/SpdifStreamOut.cpp b/services/audioflinger/SpdifStreamOut.cpp
index c7aba79..0ce5681 100644
--- a/services/audioflinger/SpdifStreamOut.cpp
+++ b/services/audioflinger/SpdifStreamOut.cpp
@@ -39,7 +39,7 @@
         , mSpdifEncoder(this, format)
         , mApplicationFormat(AUDIO_FORMAT_DEFAULT)
         , mApplicationSampleRate(0)
-        , mApplicationChannelMask(0)
+        , mApplicationChannelMask(AUDIO_CHANNEL_NONE)
 {
 }
 
diff --git a/services/audioflinger/Threads.cpp b/services/audioflinger/Threads.cpp
index b143388..00fbbb0 100644
--- a/services/audioflinger/Threads.cpp
+++ b/services/audioflinger/Threads.cpp
@@ -2863,8 +2863,8 @@
         (void)posix_memalign(&mEffectBuffer, 32, mEffectBufferSize);
     }
 
-    mHapticChannelMask = mChannelMask & AUDIO_CHANNEL_HAPTIC_ALL;
-    mChannelMask &= ~mHapticChannelMask;
+    mHapticChannelMask = static_cast<audio_channel_mask_t>(mChannelMask & AUDIO_CHANNEL_HAPTIC_ALL);
+    mChannelMask = static_cast<audio_channel_mask_t>(mChannelMask & ~mHapticChannelMask);
     mHapticChannelCount = audio_channel_count_from_out_mask(mHapticChannelMask);
     mChannelCount -= mHapticChannelCount;
 
@@ -4200,7 +4200,7 @@
                             "Enumerated device type(%#x) must not be used "
                             "as it does not support audio patches",
                             patch->sinks[i].ext.device.type);
-        type |= patch->sinks[i].ext.device.type;
+        type = static_cast<audio_devices_t>(type | patch->sinks[i].ext.device.type);
         deviceTypeAddrs.push_back(AudioDeviceTypeAddr(patch->sinks[i].ext.device.type,
                 patch->sinks[i].ext.device.address));
     }
@@ -4450,8 +4450,9 @@
         // wrap the source side of the MonoPipe to make it an AudioBufferProvider
         fastTrack->mBufferProvider = new SourceAudioBufferProvider(new MonoPipeReader(monoPipe));
         fastTrack->mVolumeProvider = NULL;
-        fastTrack->mChannelMask = mChannelMask | mHapticChannelMask; // mPipeSink channel mask for
-                                                                     // audio to FastMixer
+        fastTrack->mChannelMask = static_cast<audio_channel_mask_t>(
+                mChannelMask | mHapticChannelMask); // mPipeSink channel mask for
+                                                    // audio to FastMixer
         fastTrack->mFormat = mFormat; // mPipeSink format for audio to FastMixer
         fastTrack->mHapticPlaybackEnabled = mHapticChannelMask != AUDIO_CHANNEL_NONE;
         fastTrack->mHapticIntensity = AudioMixer::HAPTIC_SCALE_NONE;
@@ -4465,7 +4466,8 @@
         // specify sink channel mask when haptic channel mask present as it can not
         // be calculated directly from channel count
         state->mSinkChannelMask = mHapticChannelMask == AUDIO_CHANNEL_NONE
-                ? AUDIO_CHANNEL_NONE : mChannelMask | mHapticChannelMask;
+                ? AUDIO_CHANNEL_NONE
+                : static_cast<audio_channel_mask_t>(mChannelMask | mHapticChannelMask);
         state->mCommand = FastMixerState::COLD_IDLE;
         // already done in constructor initialization list
         //mFastMixerFutex = 0;
@@ -9185,7 +9187,7 @@
                                 "Enumerated device type(%#x) must not be used "
                                 "as it does not support audio patches",
                                 patch->sinks[i].ext.device.type);
-            type |= patch->sinks[i].ext.device.type;
+            type = static_cast<audio_devices_t>(type | patch->sinks[i].ext.device.type);
             sinkDeviceTypeAddrs.push_back(AudioDeviceTypeAddr(patch->sinks[i].ext.device.type,
                     patch->sinks[i].ext.device.address));
         }
diff --git a/services/audiopolicy/common/managerdefinitions/src/DeviceDescriptor.cpp b/services/audiopolicy/common/managerdefinitions/src/DeviceDescriptor.cpp
index 5120aeb..3d97440 100644
--- a/services/audiopolicy/common/managerdefinitions/src/DeviceDescriptor.cpp
+++ b/services/audiopolicy/common/managerdefinitions/src/DeviceDescriptor.cpp
@@ -380,7 +380,7 @@
     if (isEmpty()) {
         // Return nullptr if this collection is empty.
         return nullptr;
-    } else if (areAllOfSameDeviceType(types(), audio_is_input_device)) {
+    } else if (areAllOfSameDeviceType(types(), audio_call_is_input_device)) {
         // For input case, return the first one when there is only one device.
         return size() > 1 ? nullptr : *begin();
     } else if (areAllOfSameDeviceType(types(), audio_is_output_device)) {
diff --git a/services/audiopolicy/common/managerdefinitions/src/Serializer.cpp b/services/audiopolicy/common/managerdefinitions/src/Serializer.cpp
index 883e713..889f031 100644
--- a/services/audiopolicy/common/managerdefinitions/src/Serializer.cpp
+++ b/services/audiopolicy/common/managerdefinitions/src/Serializer.cpp
@@ -337,7 +337,7 @@
 
     std::string mode = getXmlAttribute(cur, Attributes::mode);
     if (!mode.empty()) {
-        gain->setMode(GainModeConverter::maskFromString(mode));
+        gain->setMode(static_cast<audio_gain_mode_t>(GainModeConverter::maskFromString(mode)));
     }
 
     std::string channelsLiteral = getXmlAttribute(cur, Attributes::channelMask);
diff --git a/services/audiopolicy/config/a2dp_audio_policy_configuration_7_0.xml b/services/audiopolicy/config/a2dp_audio_policy_configuration_7_0.xml
new file mode 100644
index 0000000..2d323f6
--- /dev/null
+++ b/services/audiopolicy/config/a2dp_audio_policy_configuration_7_0.xml
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- A2dp Audio HAL Audio Policy Configuration file -->
+<module name="a2dp" halVersion="2.0">
+    <mixPorts>
+        <mixPort name="a2dp output" role="source"/>
+        <mixPort name="a2dp input" role="sink">
+            <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
+                     samplingRates="44100 48000"
+                     channelMasks="AUDIO_CHANNEL_IN_MONO AUDIO_CHANNEL_IN_STEREO"/>
+        </mixPort>
+    </mixPorts>
+    <devicePorts>
+        <devicePort tagName="BT A2DP Out" type="AUDIO_DEVICE_OUT_BLUETOOTH_A2DP" role="sink">
+            <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
+                     samplingRates="44100"
+                     channelMasks="AUDIO_CHANNEL_OUT_STEREO"/>
+        </devicePort>
+        <devicePort tagName="BT A2DP Headphones" type="AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES" role="sink">
+            <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
+                     samplingRates="44100"
+                     channelMasks="AUDIO_CHANNEL_OUT_STEREO"/>
+        </devicePort>
+        <devicePort tagName="BT A2DP Speaker" type="AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER" role="sink">
+            <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
+                     samplingRates="44100"
+                     channelMasks="AUDIO_CHANNEL_OUT_STEREO"/>
+        </devicePort>
+        <devicePort tagName="BT A2DP In" type="AUDIO_DEVICE_IN_BLUETOOTH_A2DP" role="source">
+            <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
+                     samplingRates="44100 48000"
+                     channelMasks="AUDIO_CHANNEL_IN_MONO AUDIO_CHANNEL_IN_STEREO"/>
+        </devicePort>
+    </devicePorts>
+    <routes>
+        <route type="mix" sink="BT A2DP Out"
+               sources="a2dp output"/>
+        <route type="mix" sink="BT A2DP Headphones"
+               sources="a2dp output"/>
+        <route type="mix" sink="BT A2DP Speaker"
+               sources="a2dp output"/>
+        <route type="mix" sink="a2dp input"
+               sources="BT A2DP In"/>
+    </routes>
+</module>
diff --git a/services/audiopolicy/config/a2dp_in_audio_policy_configuration_7_0.xml b/services/audiopolicy/config/a2dp_in_audio_policy_configuration_7_0.xml
new file mode 100644
index 0000000..d59ad70
--- /dev/null
+++ b/services/audiopolicy/config/a2dp_in_audio_policy_configuration_7_0.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Bluetooth Input Audio HAL Audio Policy Configuration file -->
+<module name="a2dp" halVersion="2.0">
+    <mixPorts>
+        <mixPort name="a2dp input" role="sink">
+            <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
+                     samplingRates="44100 48000"
+                     channelMasks="AUDIO_CHANNEL_IN_MONO AUDIO_CHANNEL_IN_STEREO"/>
+        </mixPort>
+    </mixPorts>
+    <devicePorts>
+        <devicePort tagName="BT A2DP In" type="AUDIO_DEVICE_IN_BLUETOOTH_A2DP" role="source">
+            <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
+                     samplingRates="44100 48000"
+                     channelMasks="AUDIO_CHANNEL_IN_MONO AUDIO_CHANNEL_IN_STEREO"/>
+        </devicePort>
+    </devicePorts>
+    <routes>
+        <route type="mix" sink="a2dp input"
+               sources="BT A2DP In"/>
+    </routes>
+</module>
diff --git a/services/audiopolicy/config/audio_policy_configuration_7_0.xml b/services/audiopolicy/config/audio_policy_configuration_7_0.xml
new file mode 100644
index 0000000..b30ab30
--- /dev/null
+++ b/services/audiopolicy/config/audio_policy_configuration_7_0.xml
@@ -0,0 +1,211 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<!-- Copyright (C) 2019 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+
+<audioPolicyConfiguration version="1.0" xmlns:xi="http://www.w3.org/2001/XInclude">
+    <!-- version section contains a “version” tag in the form “major.minor” e.g version=”1.0” -->
+
+    <!-- Global configuration Decalaration -->
+    <globalConfiguration speaker_drc_enabled="true"/>
+
+
+    <!-- Modules section:
+        There is one section per audio HW module present on the platform.
+        Each module section will contains two mandatory tags for audio HAL “halVersion” and “name”.
+        The module names are the same as in current .conf file:
+                “primary”, “A2DP”, “remote_submix”, “USB”
+        Each module will contain the following sections:
+        “devicePorts”: a list of device descriptors for all input and output devices accessible via this
+        module.
+        This contains both permanently attached devices and removable devices.
+        “mixPorts”: listing all output and input streams exposed by the audio HAL
+        “routes”: list of possible connections between input and output devices or between stream and
+        devices.
+            "route": is defined by an attribute:
+                -"type": <mux|mix> means all sources are mutual exclusive (mux) or can be mixed (mix)
+                -"sink": the sink involved in this route
+                -"sources": all the sources than can be connected to the sink via vis route
+        “attachedDevices”: permanently attached devices.
+        The attachedDevices section is a list of devices names. The names correspond to device names
+        defined in <devicePorts> section.
+        “defaultOutputDevice”: device to be used by default when no policy rule applies
+    -->
+    <modules>
+        <!-- Primary Audio HAL -->
+        <module name="primary" halVersion="3.0">
+            <attachedDevices>
+                <item>Speaker</item>
+                <item>Built-In Mic</item>
+                <item>Built-In Back Mic</item>
+            </attachedDevices>
+            <defaultOutputDevice>Speaker</defaultOutputDevice>
+            <mixPorts>
+                <mixPort name="primary output" role="source" flags="AUDIO_OUTPUT_FLAG_PRIMARY">
+                    <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
+                             samplingRates="48000" channelMasks="AUDIO_CHANNEL_OUT_STEREO"/>
+                </mixPort>
+                <mixPort name="deep_buffer" role="source"
+                        flags="AUDIO_OUTPUT_FLAG_DEEP_BUFFER">
+                    <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
+                             samplingRates="48000" channelMasks="AUDIO_CHANNEL_OUT_STEREO"/>
+                </mixPort>
+                <mixPort name="compressed_offload" role="source"
+                         flags="AUDIO_OUTPUT_FLAG_DIRECT AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD AUDIO_OUTPUT_FLAG_NON_BLOCKING">
+                    <profile name="" format="AUDIO_FORMAT_MP3"
+                             samplingRates="8000 11025 12000 16000 22050 24000 32000 44100 48000"
+                             channelMasks="AUDIO_CHANNEL_OUT_STEREO AUDIO_CHANNEL_OUT_MONO"/>
+                    <profile name="" format="AUDIO_FORMAT_AAC"
+                             samplingRates="8000 11025 12000 16000 22050 24000 32000 44100 48000"
+                             channelMasks="AUDIO_CHANNEL_OUT_STEREO AUDIO_CHANNEL_OUT_MONO"/>
+                    <profile name="" format="AUDIO_FORMAT_AAC_LC"
+                             samplingRates="8000 11025 12000 16000 22050 24000 32000 44100 48000"
+                             channelMasks="AUDIO_CHANNEL_OUT_STEREO AUDIO_CHANNEL_OUT_MONO"/>
+                </mixPort>
+                <mixPort name="voice_tx" role="source">
+                    <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
+                             samplingRates="8000 16000" channelMasks="AUDIO_CHANNEL_OUT_MONO"/>
+                </mixPort>
+                <mixPort name="primary input" role="sink">
+                    <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
+                             samplingRates="8000 11025 12000 16000 22050 24000 32000 44100 48000"
+                             channelMasks="AUDIO_CHANNEL_IN_MONO AUDIO_CHANNEL_IN_STEREO AUDIO_CHANNEL_IN_FRONT_BACK"/>
+                </mixPort>
+                <mixPort name="voice_rx" role="sink">
+                    <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
+                             samplingRates="8000 16000" channelMasks="AUDIO_CHANNEL_IN_MONO"/>
+                </mixPort>
+            </mixPorts>
+            <devicePorts>
+                <!-- Output devices declaration, i.e. Sink DEVICE PORT -->
+                <devicePort tagName="Earpiece" type="AUDIO_DEVICE_OUT_EARPIECE" role="sink">
+                   <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
+                            samplingRates="48000" channelMasks="AUDIO_CHANNEL_IN_MONO"/>
+                </devicePort>
+                <devicePort tagName="Speaker" role="sink" type="AUDIO_DEVICE_OUT_SPEAKER" address="">
+                    <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
+                             samplingRates="48000" channelMasks="AUDIO_CHANNEL_OUT_STEREO"/>
+                    <gains>
+                        <gain name="gain_1" mode="AUDIO_GAIN_MODE_JOINT"
+                              minValueMB="-8400"
+                              maxValueMB="4000"
+                              defaultValueMB="0"
+                              stepValueMB="100"/>
+                    </gains>
+                </devicePort>
+                <devicePort tagName="Wired Headset" type="AUDIO_DEVICE_OUT_WIRED_HEADSET" role="sink">
+                    <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
+                             samplingRates="48000" channelMasks="AUDIO_CHANNEL_OUT_STEREO"/>
+                </devicePort>
+                <devicePort tagName="Wired Headphones" type="AUDIO_DEVICE_OUT_WIRED_HEADPHONE" role="sink">
+                    <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
+                             samplingRates="48000" channelMasks="AUDIO_CHANNEL_OUT_STEREO"/>
+                </devicePort>
+                <devicePort tagName="BT SCO" type="AUDIO_DEVICE_OUT_BLUETOOTH_SCO" role="sink">
+                    <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
+                             samplingRates="8000 16000" channelMasks="AUDIO_CHANNEL_OUT_MONO"/>
+                </devicePort>
+                <devicePort tagName="BT SCO Headset" type="AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET" role="sink">
+                    <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
+                             samplingRates="8000 16000" channelMasks="AUDIO_CHANNEL_OUT_MONO"/>
+                </devicePort>
+                <devicePort tagName="BT SCO Car Kit" type="AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT" role="sink">
+                    <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
+                             samplingRates="8000 16000" channelMasks="AUDIO_CHANNEL_OUT_MONO"/>
+                </devicePort>
+                <devicePort tagName="Telephony Tx" type="AUDIO_DEVICE_OUT_TELEPHONY_TX" role="sink">
+                    <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
+                             samplingRates="8000 16000" channelMasks="AUDIO_CHANNEL_OUT_MONO"/>
+                </devicePort>
+
+                <devicePort tagName="Built-In Mic" type="AUDIO_DEVICE_IN_BUILTIN_MIC" role="source">
+                    <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
+                             samplingRates="8000 11025 12000 16000 22050 24000 32000 44100 48000"
+                             channelMasks="AUDIO_CHANNEL_IN_MONO AUDIO_CHANNEL_IN_STEREO AUDIO_CHANNEL_IN_FRONT_BACK"/>
+                </devicePort>
+                <devicePort tagName="Built-In Back Mic" type="AUDIO_DEVICE_IN_BACK_MIC" role="source">
+                    <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
+                             samplingRates="8000 11025 12000 16000 22050 24000 32000 44100 48000"
+                             channelMasks="AUDIO_CHANNEL_IN_MONO AUDIO_CHANNEL_IN_STEREO AUDIO_CHANNEL_IN_FRONT_BACK"/>
+                </devicePort>
+                <devicePort tagName="Wired Headset Mic" type="AUDIO_DEVICE_IN_WIRED_HEADSET" role="source">
+                    <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
+                             samplingRates="8000 11025 12000 16000 22050 24000 32000 44100 48000"
+                             channelMasks="AUDIO_CHANNEL_IN_MONO AUDIO_CHANNEL_IN_STEREO AUDIO_CHANNEL_IN_FRONT_BACK"/>
+                </devicePort>
+                <devicePort tagName="BT SCO Headset Mic" type="AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET" role="source">
+                    <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
+                             samplingRates="8000 16000" channelMasks="AUDIO_CHANNEL_IN_MONO"/>
+                </devicePort>
+                <devicePort tagName="Telephony Rx" type="AUDIO_DEVICE_IN_TELEPHONY_RX" role="source">
+                    <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
+                             samplingRates="8000 16000" channelMasks="AUDIO_CHANNEL_IN_MONO"/>
+                </devicePort>
+            </devicePorts>
+            <!-- route declaration, i.e. list all available sources for a given sink -->
+            <routes>
+                <route type="mix" sink="Earpiece"
+                       sources="primary output,deep_buffer,BT SCO Headset Mic"/>
+                <route type="mix" sink="Speaker"
+                       sources="primary output,deep_buffer,compressed_offload,BT SCO Headset Mic,Telephony Rx"/>
+                <route type="mix" sink="Wired Headset"
+                       sources="primary output,deep_buffer,compressed_offload,BT SCO Headset Mic,Telephony Rx"/>
+                <route type="mix" sink="Wired Headphones"
+                       sources="primary output,deep_buffer,compressed_offload,BT SCO Headset Mic,Telephony Rx"/>
+                <route type="mix" sink="primary input"
+                       sources="Built-In Mic,Built-In Back Mic,Wired Headset Mic,BT SCO Headset Mic"/>
+                <route type="mix" sink="Telephony Tx"
+                       sources="Built-In Mic,Built-In Back Mic,Wired Headset Mic,BT SCO Headset Mic, voice_tx"/>
+                <route type="mix" sink="voice_rx"
+                       sources="Telephony Rx"/>
+            </routes>
+
+        </module>
+
+        <!-- A2dp Input Audio HAL -->
+        <xi:include href="a2dp_in_audio_policy_configuration_7_0.xml"/>
+
+        <!-- Usb Audio HAL -->
+        <xi:include href="usb_audio_policy_configuration.xml"/>
+
+        <!-- Remote Submix Audio HAL -->
+        <xi:include href="r_submix_audio_policy_configuration.xml"/>
+
+        <!-- Bluetooth Audio HAL -->
+        <xi:include href="bluetooth_audio_policy_configuration_7_0.xml"/>
+
+        <!-- MSD Audio HAL (optional) -->
+        <xi:include href="msd_audio_policy_configuration_7_0.xml"/>
+
+    </modules>
+    <!-- End of Modules section -->
+
+    <!-- Volume section:
+        IMPORTANT NOTE: Volume tables have been moved to engine configuration.
+                        Keep it here for legacy.
+                        Engine will fallback on these files if none are provided by engine.
+     -->
+
+    <xi:include href="audio_policy_volumes.xml"/>
+    <xi:include href="default_volume_tables.xml"/>
+
+    <!-- End of Volume section -->
+
+    <!-- Surround Sound configuration -->
+
+    <xi:include href="surround_sound_configuration_5_0.xml"/>
+
+    <!-- End of Surround Sound configuration -->
+
+</audioPolicyConfiguration>
diff --git a/services/audiopolicy/config/bluetooth_audio_policy_configuration_7_0.xml b/services/audiopolicy/config/bluetooth_audio_policy_configuration_7_0.xml
new file mode 100644
index 0000000..2dffe02
--- /dev/null
+++ b/services/audiopolicy/config/bluetooth_audio_policy_configuration_7_0.xml
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Bluetooth Audio HAL Audio Policy Configuration file -->
+<module name="bluetooth" halVersion="2.0">
+    <mixPorts>
+        <!-- A2DP Audio Ports -->
+        <mixPort name="a2dp output" role="source"/>
+        <!-- Hearing AIDs Audio Ports -->
+        <mixPort name="hearing aid output" role="source">
+            <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
+                     samplingRates="24000 16000"
+                     channelMasks="AUDIO_CHANNEL_OUT_STEREO"/>
+        </mixPort>
+    </mixPorts>
+    <devicePorts>
+        <!-- A2DP Audio Ports -->
+        <devicePort tagName="BT A2DP Out" type="AUDIO_DEVICE_OUT_BLUETOOTH_A2DP" role="sink">
+            <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
+                     samplingRates="44100 48000 88200 96000"
+                     channelMasks="AUDIO_CHANNEL_OUT_STEREO"/>
+        </devicePort>
+        <devicePort tagName="BT A2DP Headphones" type="AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES" role="sink">
+            <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
+                     samplingRates="44100 48000 88200 96000"
+                     channelMasks="AUDIO_CHANNEL_OUT_STEREO"/>
+        </devicePort>
+        <devicePort tagName="BT A2DP Speaker" type="AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER" role="sink">
+            <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
+                     samplingRates="44100 48000 88200 96000"
+                     channelMasks="AUDIO_CHANNEL_OUT_STEREO"/>
+        </devicePort>
+        <!-- Hearing AIDs Audio Ports -->
+        <devicePort tagName="BT Hearing Aid Out" type="AUDIO_DEVICE_OUT_HEARING_AID" role="sink"/>
+    </devicePorts>
+    <routes>
+        <route type="mix" sink="BT A2DP Out"
+               sources="a2dp output"/>
+        <route type="mix" sink="BT A2DP Headphones"
+               sources="a2dp output"/>
+        <route type="mix" sink="BT A2DP Speaker"
+               sources="a2dp output"/>
+        <route type="mix" sink="BT Hearing Aid Out"
+               sources="hearing aid output"/>
+    </routes>
+</module>
diff --git a/services/audiopolicy/config/hearing_aid_audio_policy_configuration_7_0.xml b/services/audiopolicy/config/hearing_aid_audio_policy_configuration_7_0.xml
new file mode 100644
index 0000000..8c364e4
--- /dev/null
+++ b/services/audiopolicy/config/hearing_aid_audio_policy_configuration_7_0.xml
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Hearing aid Audio HAL Audio Policy Configuration file -->
+<module name="hearing_aid" halVersion="2.0">
+    <mixPorts>
+        <mixPort name="hearing aid output" role="source">
+            <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
+                     samplingRates="24000 16000"
+                     channelMasks="AUDIO_CHANNEL_OUT_STEREO"/>
+        </mixPort>
+    </mixPorts>
+    <devicePorts>
+        <devicePort tagName="BT Hearing Aid Out" type="AUDIO_DEVICE_OUT_HEARING_AID" role="sink"/>
+    </devicePorts>
+    <routes>
+        <route type="mix" sink="BT Hearing Aid Out" sources="hearing aid output"/>
+    </routes>
+</module>
diff --git a/services/audiopolicy/config/msd_audio_policy_configuration_7_0.xml b/services/audiopolicy/config/msd_audio_policy_configuration_7_0.xml
new file mode 100644
index 0000000..f167f0b
--- /dev/null
+++ b/services/audiopolicy/config/msd_audio_policy_configuration_7_0.xml
@@ -0,0 +1,78 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Copyright (C) 2017-2018 The Android Open Source Project
+
+     Licensed under the Apache License, Version 2.0 (the "License");
+     you may not use this file except in compliance with the License.
+     You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+     Unless required by applicable law or agreed to in writing, software
+     distributed under the License is distributed on an "AS IS" BASIS,
+     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+     See the License for the specific language governing permissions and
+     limitations under the License.
+-->
+<!-- Multi Stream Decoder Audio Policy Configuration file -->
+<module name="msd" halVersion="2.0">
+    <attachedDevices>
+        <item>MS12 Input</item>
+        <item>MS12 Output</item>
+    </attachedDevices>
+    <mixPorts>
+        <mixPort name="ms12 input" role="source">
+            <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
+                     samplingRates="48000" channelMasks="AUDIO_CHANNEL_OUT_STEREO"/>
+        </mixPort>
+        <mixPort name="ms12 compressed input" role="source"
+                flags="AUDIO_OUTPUT_FLAG_DIRECT AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD AUDIO_OUTPUT_FLAG_NON_BLOCKING">
+            <profile name="" format="AUDIO_FORMAT_AC3"
+                     samplingRates="32000 44100 48000"
+                     channelMasks="AUDIO_CHANNEL_OUT_MONO AUDIO_CHANNEL_OUT_STEREO AUDIO_CHANNEL_OUT_5POINT1"/>
+            <profile name="" format="AUDIO_FORMAT_E_AC3"
+                     samplingRates="32000 44100 48000"
+                     channelMasks="AUDIO_CHANNEL_OUT_MONO AUDIO_CHANNEL_OUT_STEREO AUDIO_CHANNEL_OUT_5POINT1 AUDIO_CHANNEL_OUT_7POINT1"/>
+            <profile name="" format="AUDIO_FORMAT_E_AC3_JOC"
+                     samplingRates="32000 44100 48000"
+                     channelMasks="AUDIO_CHANNEL_OUT_MONO AUDIO_CHANNEL_OUT_STEREO AUDIO_CHANNEL_OUT_5POINT1 AUDIO_CHANNEL_OUT_7POINT1"/>
+            <profile name="" format="AUDIO_FORMAT_AC4"
+                     samplingRates="32000 44100 48000"
+                     channelMasks="AUDIO_CHANNEL_OUT_MONO AUDIO_CHANNEL_OUT_STEREO AUDIO_CHANNEL_OUT_5POINT1 AUDIO_CHANNEL_OUT_7POINT1"/>
+        </mixPort>
+        <!-- The HW AV Sync flag is not required, but is recommended -->
+        <mixPort name="ms12 output" role="sink" flags="AUDIO_INPUT_FLAG_HW_AV_SYNC AUDIO_INPUT_FLAG_DIRECT">
+            <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
+                     samplingRates="48000" channelMasks="AUDIO_CHANNEL_IN_STEREO"/>
+            <profile name="" format="AUDIO_FORMAT_AC3"
+                     samplingRates="48000" channelMasks="AUDIO_CHANNEL_IN_5POINT1"/>
+            <profile name="" format="AUDIO_FORMAT_E_AC3"
+                     samplingRates="48000" channelMasks="AUDIO_CHANNEL_IN_5POINT1"/>
+        </mixPort>
+   </mixPorts>
+   <devicePorts>
+       <devicePort tagName="MS12 Input" type="AUDIO_DEVICE_OUT_BUS"  role="sink">
+           <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
+                    samplingRates="48000" channelMasks="AUDIO_CHANNEL_OUT_STEREO"/>
+           <profile name="" format="AUDIO_FORMAT_AC3"
+                    samplingRates="32000 44100 48000"
+                    channelMasks="AUDIO_CHANNEL_OUT_MONO AUDIO_CHANNEL_OUT_STEREO AUDIO_CHANNEL_OUT_5POINT1"/>
+           <profile name="" format="AUDIO_FORMAT_E_AC3"
+                    samplingRates="32000 44100 48000"
+                    channelMasks="AUDIO_CHANNEL_OUT_MONO AUDIO_CHANNEL_OUT_STEREO AUDIO_CHANNEL_OUT_5POINT1 AUDIO_CHANNEL_OUT_7POINT1"/>
+            <profile name="" format="AUDIO_FORMAT_E_AC3_JOC"
+                     samplingRates="32000 44100 48000"
+                     channelMasks="AUDIO_CHANNEL_OUT_MONO AUDIO_CHANNEL_OUT_STEREO AUDIO_CHANNEL_OUT_5POINT1 AUDIO_CHANNEL_OUT_7POINT1"/>
+           <profile name="" format="AUDIO_FORMAT_AC4"
+                    samplingRates="32000 44100 48000"
+                    channelMasks="AUDIO_CHANNEL_OUT_MONO AUDIO_CHANNEL_OUT_STEREO AUDIO_CHANNEL_OUT_5POINT1 AUDIO_CHANNEL_OUT_7POINT1"/>
+       </devicePort>
+       <devicePort tagName="MS12 Output" type="AUDIO_DEVICE_IN_BUS"  role="source">
+           <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
+                    samplingRates="48000" channelMasks="AUDIO_CHANNEL_IN_STEREO"/>
+        </devicePort>
+    </devicePorts>
+    <routes>
+        <route type="mix" sink="MS12 Input" sources="ms12 input,ms12 compressed input"/>
+        <route type="mix" sink="ms12 output" sources="MS12 Output"/>
+    </routes>
+</module>
diff --git a/services/audiopolicy/config/primary_audio_policy_configuration_7_0.xml b/services/audiopolicy/config/primary_audio_policy_configuration_7_0.xml
new file mode 100644
index 0000000..68a56b2
--- /dev/null
+++ b/services/audiopolicy/config/primary_audio_policy_configuration_7_0.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Default Primary Audio HAL Module Audio Policy Configuration include file -->
+<module name="primary" halVersion="2.0">
+    <attachedDevices>
+        <item>Speaker</item>
+        <item>Built-In Mic</item>
+    </attachedDevices>
+    <defaultOutputDevice>Speaker</defaultOutputDevice>
+    <mixPorts>
+        <mixPort name="primary output" role="source" flags="AUDIO_OUTPUT_FLAG_PRIMARY">
+            <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
+                     samplingRates="44100" channelMasks="AUDIO_CHANNEL_OUT_STEREO"/>
+        </mixPort>
+        <mixPort name="primary input" role="sink">
+            <profile name="" format="AUDIO_FORMAT_PCM_16_BIT"
+                     samplingRates="8000 16000" channelMasks="AUDIO_CHANNEL_IN_MONO"/>
+        </mixPort>
+   </mixPorts>
+   <devicePorts>
+        <devicePort tagName="Speaker" type="AUDIO_DEVICE_OUT_SPEAKER" role="sink">
+        </devicePort>
+
+        <devicePort tagName="Built-In Mic" type="AUDIO_DEVICE_IN_BUILTIN_MIC" role="source">
+        </devicePort>
+    </devicePorts>
+    <routes>
+        <route type="mix" sink="Speaker"
+               sources="primary output"/>
+        <route type="mix" sink="primary input"
+               sources="Built-In Mic"/>
+    </routes>
+</module>
diff --git a/services/audiopolicy/engine/common/src/EngineDefaultConfig.h b/services/audiopolicy/engine/common/src/EngineDefaultConfig.h
index 1821140..d39eff6 100644
--- a/services/audiopolicy/engine/common/src/EngineDefaultConfig.h
+++ b/services/audiopolicy/engine/common/src/EngineDefaultConfig.h
@@ -26,8 +26,8 @@
     {"STRATEGY_PHONE",
      {
          {"phone", AUDIO_STREAM_VOICE_CALL, "AUDIO_STREAM_VOICE_CALL",
-          {{AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_VOICE_COMMUNICATION, AUDIO_SOURCE_DEFAULT, 0,
-            ""}},
+          {{AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_VOICE_COMMUNICATION, AUDIO_SOURCE_DEFAULT,
+            AUDIO_FLAG_NONE, ""}},
          },
          {"sco", AUDIO_STREAM_BLUETOOTH_SCO, "AUDIO_STREAM_BLUETOOTH_SCO",
           {{AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN, AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_SCO,
@@ -39,10 +39,11 @@
      {
          {"ring", AUDIO_STREAM_RING, "AUDIO_STREAM_RING",
           {{AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_NOTIFICATION_TELEPHONY_RINGTONE,
-            AUDIO_SOURCE_DEFAULT, 0, ""}}
+            AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""}}
          },
          {"alarm", AUDIO_STREAM_ALARM, "AUDIO_STREAM_ALARM",
-          {{AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_ALARM, AUDIO_SOURCE_DEFAULT, 0, ""}},
+          {{AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_ALARM, AUDIO_SOURCE_DEFAULT,
+            AUDIO_FLAG_NONE, ""}},
          }
      },
     },
@@ -58,7 +59,7 @@
      {
          {"", AUDIO_STREAM_ACCESSIBILITY, "AUDIO_STREAM_ACCESSIBILITY",
           {{AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_ASSISTANCE_ACCESSIBILITY,
-            AUDIO_SOURCE_DEFAULT, 0, ""}}
+            AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""}}
          }
      },
     },
@@ -66,15 +67,16 @@
      {
          {"", AUDIO_STREAM_NOTIFICATION, "AUDIO_STREAM_NOTIFICATION",
           {
-              {AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_NOTIFICATION, AUDIO_SOURCE_DEFAULT, 0, ""},
+              {AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_NOTIFICATION, AUDIO_SOURCE_DEFAULT,
+               AUDIO_FLAG_NONE, ""},
               {AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_NOTIFICATION_COMMUNICATION_REQUEST,
-               AUDIO_SOURCE_DEFAULT, 0, ""},
+               AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""},
               {AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_NOTIFICATION_COMMUNICATION_INSTANT,
-               AUDIO_SOURCE_DEFAULT, 0, ""},
+               AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""},
               {AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_NOTIFICATION_COMMUNICATION_DELAYED,
-               AUDIO_SOURCE_DEFAULT, 0, ""},
+               AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""},
               {AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_NOTIFICATION_EVENT,
-               AUDIO_SOURCE_DEFAULT, 0, ""}
+               AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""}
           }
          }
      },
@@ -83,21 +85,25 @@
      {
          {"assistant", AUDIO_STREAM_ASSISTANT, "AUDIO_STREAM_ASSISTANT",
           {{AUDIO_CONTENT_TYPE_SPEECH, AUDIO_USAGE_ASSISTANT,
-            AUDIO_SOURCE_DEFAULT, 0, ""}}
+            AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""}}
          },
          {"music", AUDIO_STREAM_MUSIC, "AUDIO_STREAM_MUSIC",
           {
-              {AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_MEDIA, AUDIO_SOURCE_DEFAULT, 0, ""},
-              {AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_GAME, AUDIO_SOURCE_DEFAULT, 0, ""},
-              {AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_ASSISTANT, AUDIO_SOURCE_DEFAULT, 0, ""},
+              {AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_MEDIA, AUDIO_SOURCE_DEFAULT,
+               AUDIO_FLAG_NONE, ""},
+              {AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_GAME, AUDIO_SOURCE_DEFAULT,
+               AUDIO_FLAG_NONE, ""},
+              {AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_ASSISTANT, AUDIO_SOURCE_DEFAULT,
+               AUDIO_FLAG_NONE, ""},
               {AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE,
-               AUDIO_SOURCE_DEFAULT, 0, ""},
-              {AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN, AUDIO_SOURCE_DEFAULT, 0, ""}
+               AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""},
+              {AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN, AUDIO_SOURCE_DEFAULT,
+               AUDIO_FLAG_NONE, ""}
           },
          },
          {"system", AUDIO_STREAM_SYSTEM, "AUDIO_STREAM_SYSTEM",
           {{AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_ASSISTANCE_SONIFICATION,
-            AUDIO_SOURCE_DEFAULT, 0, ""}}
+            AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""}}
          }
      },
     },
@@ -106,7 +112,7 @@
          {"", AUDIO_STREAM_DTMF, "AUDIO_STREAM_DTMF",
           {
               {AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_VOICE_COMMUNICATION_SIGNALLING,
-               AUDIO_SOURCE_DEFAULT, 0, ""}
+               AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""}
           }
          }
      },
@@ -114,7 +120,8 @@
     {"STRATEGY_CALL_ASSISTANT",
      {
          {"", AUDIO_STREAM_CALL_ASSISTANT, "AUDIO_STREAM_CALL_ASSISTANT",
-          {{AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_CALL_ASSISTANT, AUDIO_SOURCE_DEFAULT, 0, ""}}
+          {{AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_CALL_ASSISTANT, AUDIO_SOURCE_DEFAULT,
+            AUDIO_FLAG_NONE, ""}}
          }
      },
     },
@@ -136,14 +143,16 @@
     {"rerouting",
      {
          {"", AUDIO_STREAM_REROUTING, "AUDIO_STREAM_REROUTING",
-          {{AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_VIRTUAL_SOURCE, AUDIO_SOURCE_DEFAULT, 0, ""}}
+          {{AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_VIRTUAL_SOURCE, AUDIO_SOURCE_DEFAULT,
+            AUDIO_FLAG_NONE, ""}}
          }
      },
     },
     {"patch",
      {
          {"", AUDIO_STREAM_PATCH, "AUDIO_STREAM_PATCH",
-          {{AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN, AUDIO_SOURCE_DEFAULT, 0, ""}}
+          {{AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN, AUDIO_SOURCE_DEFAULT,
+            AUDIO_FLAG_NONE, ""}}
          }
      },
     }
diff --git a/services/audiopolicy/engine/config/src/EngineConfig.cpp b/services/audiopolicy/engine/config/src/EngineConfig.cpp
index 4842cb2..daf6418 100644
--- a/services/audiopolicy/engine/config/src/EngineConfig.cpp
+++ b/services/audiopolicy/engine/config/src/EngineConfig.cpp
@@ -228,7 +228,8 @@
             std::string flags = getXmlAttribute(cur, "value");
 
             ALOGV("%s flags %s",  __FUNCTION__, flags.c_str());
-            attributes.flags = AudioFlagConverter::maskFromString(flags, " ");
+            attributes.flags = static_cast<audio_flags_mask_t>(
+                    AudioFlagConverter::maskFromString(flags, " "));
         }
         if (!xmlStrcmp(cur->name, (const xmlChar *)("Bundle"))) {
             std::string bundleKey = getXmlAttribute(cur, "key");
diff --git a/services/audiopolicy/engineconfigurable/parameter-framework/plugin/InputSource.cpp b/services/audiopolicy/engineconfigurable/parameter-framework/plugin/InputSource.cpp
index f91f8d7..f8a6fc0 100644
--- a/services/audiopolicy/engineconfigurable/parameter-framework/plugin/InputSource.cpp
+++ b/services/audiopolicy/engineconfigurable/parameter-framework/plugin/InputSource.cpp
@@ -45,7 +45,7 @@
 
 bool InputSource::sendToHW(string & /*error*/)
 {
-    uint32_t applicableInputDevice;
+    audio_devices_t applicableInputDevice;
     blackboardRead(&applicableInputDevice, sizeof(applicableInputDevice));
     return mPolicyPluginInterface->setDeviceForInputSource(mId, applicableInputDevice);
 }
diff --git a/services/audiopolicy/engineconfigurable/parameter-framework/plugin/ProductStrategy.h b/services/audiopolicy/engineconfigurable/parameter-framework/plugin/ProductStrategy.h
index 244f082..6c8eb65 100644
--- a/services/audiopolicy/engineconfigurable/parameter-framework/plugin/ProductStrategy.h
+++ b/services/audiopolicy/engineconfigurable/parameter-framework/plugin/ProductStrategy.h
@@ -32,7 +32,7 @@
 
     struct Device
     {
-        uint32_t applicableDevice; /**< applicable device for this strategy. */
+        audio_devices_t applicableDevice; /**< applicable device for this strategy. */
         char deviceAddress[mMaxStringSize]; /**< device address associated with this strategy. */
     } __attribute__((packed));
 
diff --git a/services/audiopolicy/engineconfigurable/src/InputSource.cpp b/services/audiopolicy/engineconfigurable/src/InputSource.cpp
index aa06ae3..f4645e6 100644
--- a/services/audiopolicy/engineconfigurable/src/InputSource.cpp
+++ b/services/audiopolicy/engineconfigurable/src/InputSource.cpp
@@ -51,7 +51,7 @@
         mApplicableDevices = devices;
         return NO_ERROR;
     }
-    devices |= AUDIO_DEVICE_BIT_IN;
+    devices = static_cast<audio_devices_t>(devices | AUDIO_DEVICE_BIT_IN);
     if (!audio_is_input_device(devices)) {
         ALOGE("%s: trying to set an invalid device 0x%X for input source %s",
               __FUNCTION__, devices, getName().c_str());
diff --git a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
index ae71959..047b804 100644
--- a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
+++ b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
@@ -903,7 +903,8 @@
     // Only honor audibility enforced when required. The client will be
     // forced to reconnect if the forced usage changes.
     if (mEngine->getForceUse(AUDIO_POLICY_FORCE_FOR_SYSTEM) != AUDIO_POLICY_FORCE_SYSTEM_ENFORCED) {
-        dstAttr->flags &= ~AUDIO_FLAG_AUDIBILITY_ENFORCED;
+        dstAttr->flags = static_cast<audio_flags_mask_t>(
+                dstAttr->flags & ~AUDIO_FLAG_AUDIBILITY_ENFORCED);
     }
 
     return NO_ERROR;
@@ -935,7 +936,7 @@
         return status;
     }
     if (auto it = mAllowedCapturePolicies.find(uid); it != end(mAllowedCapturePolicies)) {
-        resultAttr->flags |= it->second;
+        resultAttr->flags = static_cast<audio_flags_mask_t>(resultAttr->flags | it->second);
     }
     *stream = mEngine->getStreamTypeForAttributes(*resultAttr);
 
@@ -1253,7 +1254,8 @@
 
     // Discard haptic channel mask when forcing muting haptic channels.
     audio_channel_mask_t channelMask = forceMutingHaptic
-            ? (config->channel_mask & ~AUDIO_CHANNEL_HAPTIC_ALL) : config->channel_mask;
+            ? static_cast<audio_channel_mask_t>(config->channel_mask & ~AUDIO_CHANNEL_HAPTIC_ALL)
+            : config->channel_mask;
 
     // open a direct output if required by specified parameters
     //force direct flag if offload flag is set: offloading implies a direct output stream
diff --git a/services/audiopolicy/service/AudioPolicyInterfaceImpl.cpp b/services/audiopolicy/service/AudioPolicyInterfaceImpl.cpp
index 34d07b6..8f1a7f7 100644
--- a/services/audiopolicy/service/AudioPolicyInterfaceImpl.cpp
+++ b/services/audiopolicy/service/AudioPolicyInterfaceImpl.cpp
@@ -244,11 +244,12 @@
         uid = callingUid;
     }
     if (!mPackageManager.allowPlaybackCapture(uid)) {
-        attr->flags |= AUDIO_FLAG_NO_MEDIA_PROJECTION;
+        attr->flags = static_cast<audio_flags_mask_t>(attr->flags | AUDIO_FLAG_NO_MEDIA_PROJECTION);
     }
     if (((attr->flags & (AUDIO_FLAG_BYPASS_INTERRUPTION_POLICY|AUDIO_FLAG_BYPASS_MUTE)) != 0)
             && !bypassInterruptionPolicyAllowed(pid, uid)) {
-        attr->flags &= ~(AUDIO_FLAG_BYPASS_INTERRUPTION_POLICY|AUDIO_FLAG_BYPASS_MUTE);
+        attr->flags = static_cast<audio_flags_mask_t>(
+                attr->flags & ~(AUDIO_FLAG_BYPASS_INTERRUPTION_POLICY|AUDIO_FLAG_BYPASS_MUTE));
     }
     AutoCallerClear acc;
     AudioPolicyInterface::output_type_t outputType;
diff --git a/services/audiopolicy/tests/audiopolicymanager_tests.cpp b/services/audiopolicy/tests/audiopolicymanager_tests.cpp
index a0074bc..0bd5442 100644
--- a/services/audiopolicy/tests/audiopolicymanager_tests.cpp
+++ b/services/audiopolicy/tests/audiopolicymanager_tests.cpp
@@ -87,7 +87,7 @@
     void getOutputForAttr(
             audio_port_handle_t *selectedDeviceId,
             audio_format_t format,
-            int channelMask,
+            audio_channel_mask_t channelMask,
             int sampleRate,
             audio_output_flags_t flags = AUDIO_OUTPUT_FLAG_NONE,
             audio_io_handle_t *output = nullptr,
@@ -98,7 +98,7 @@
             audio_unique_id_t riid,
             audio_port_handle_t *selectedDeviceId,
             audio_format_t format,
-            int channelMask,
+            audio_channel_mask_t channelMask,
             int sampleRate,
             audio_input_flags_t flags = AUDIO_INPUT_FLAG_NONE,
             audio_port_handle_t *portId = nullptr);
@@ -164,7 +164,7 @@
 void AudioPolicyManagerTest::getOutputForAttr(
         audio_port_handle_t *selectedDeviceId,
         audio_format_t format,
-        int channelMask,
+        audio_channel_mask_t channelMask,
         int sampleRate,
         audio_output_flags_t flags,
         audio_io_handle_t *output,
@@ -194,7 +194,7 @@
         audio_unique_id_t riid,
         audio_port_handle_t *selectedDeviceId,
         audio_format_t format,
-        int channelMask,
+        audio_channel_mask_t channelMask,
         int sampleRate,
         audio_input_flags_t flags,
         audio_port_handle_t *portId) {
@@ -707,7 +707,8 @@
 
     audio_port_handle_t selectedDeviceId = AUDIO_PORT_HANDLE_NONE;
     audio_source_t source = AUDIO_SOURCE_REMOTE_SUBMIX;
-    audio_attributes_t attr = {AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN, source, 0, ""};
+    audio_attributes_t attr = {
+        AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN, source, AUDIO_FLAG_NONE, ""};
     std::string tags = "addr=" + mMixAddress;
     strncpy(attr.tags, tags.c_str(), AUDIO_ATTRIBUTES_TAGS_MAX_SIZE - 1);
     getInputForAttr(attr, mTracker->getRiid(), &selectedDeviceId, AUDIO_FORMAT_PCM_16_BIT,
@@ -757,9 +758,9 @@
         AudioPolicyManagerTestDPPlaybackReRouting,
         testing::Values(
                 (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_MEDIA,
-                                     AUDIO_SOURCE_DEFAULT, 0, ""},
+                                     AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""},
                 (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_ALARM,
-                                     AUDIO_SOURCE_DEFAULT, 0, ""}
+                                     AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""}
                 )
         );
 
@@ -768,47 +769,47 @@
         AudioPolicyManagerTestDPPlaybackReRouting,
         testing::Values(
                 (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_MEDIA,
-                                     AUDIO_SOURCE_DEFAULT, 0, "addr=remote_submix_media"},
+                    AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, "addr=remote_submix_media"},
                 (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_VOICE_COMMUNICATION,
-                                     AUDIO_SOURCE_DEFAULT, 0, "addr=remote_submix_media"},
+                    AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, "addr=remote_submix_media"},
                 (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC,
-                                     AUDIO_USAGE_VOICE_COMMUNICATION_SIGNALLING,
-                                     AUDIO_SOURCE_DEFAULT, 0, "addr=remote_submix_media"},
+                    AUDIO_USAGE_VOICE_COMMUNICATION_SIGNALLING,
+                    AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, "addr=remote_submix_media"},
                 (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_ALARM,
-                                     AUDIO_SOURCE_DEFAULT, 0, "addr=remote_submix_media"},
+                    AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, "addr=remote_submix_media"},
                 (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_NOTIFICATION,
-                                     AUDIO_SOURCE_DEFAULT, 0, "addr=remote_submix_media"},
+                    AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, "addr=remote_submix_media"},
                 (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC,
-                                     AUDIO_USAGE_NOTIFICATION_TELEPHONY_RINGTONE,
-                                     AUDIO_SOURCE_DEFAULT, 0, "addr=remote_submix_media"},
+                    AUDIO_USAGE_NOTIFICATION_TELEPHONY_RINGTONE,
+                    AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, "addr=remote_submix_media"},
                 (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC,
-                                     AUDIO_USAGE_NOTIFICATION_COMMUNICATION_REQUEST,
-                                     AUDIO_SOURCE_DEFAULT, 0, "addr=remote_submix_media"},
+                    AUDIO_USAGE_NOTIFICATION_COMMUNICATION_REQUEST,
+                    AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, "addr=remote_submix_media"},
                 (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC,
-                                     AUDIO_USAGE_NOTIFICATION_COMMUNICATION_INSTANT,
-                                     AUDIO_SOURCE_DEFAULT, 0, "addr=remote_submix_media"},
+                    AUDIO_USAGE_NOTIFICATION_COMMUNICATION_INSTANT,
+                    AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, "addr=remote_submix_media"},
                 (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC,
-                                     AUDIO_USAGE_NOTIFICATION_COMMUNICATION_DELAYED,
-                                     AUDIO_SOURCE_DEFAULT, 0, "addr=remote_submix_media"},
+                    AUDIO_USAGE_NOTIFICATION_COMMUNICATION_DELAYED,
+                    AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, "addr=remote_submix_media"},
                 (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_NOTIFICATION_EVENT,
-                                     AUDIO_SOURCE_DEFAULT, 0, "addr=remote_submix_media"},
+                    AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, "addr=remote_submix_media"},
                 (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC,
-                                     AUDIO_USAGE_ASSISTANCE_ACCESSIBILITY,
-                                     AUDIO_SOURCE_DEFAULT, 0, "addr=remote_submix_media"},
+                    AUDIO_USAGE_ASSISTANCE_ACCESSIBILITY,
+                    AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, "addr=remote_submix_media"},
                 (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC,
-                                     AUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE,
-                                     AUDIO_SOURCE_DEFAULT, 0, "addr=remote_submix_media"},
+                    AUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE,
+                    AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, "addr=remote_submix_media"},
                 (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC,
-                                     AUDIO_USAGE_ASSISTANCE_SONIFICATION,
-                                     AUDIO_SOURCE_DEFAULT, 0, "addr=remote_submix_media"},
+                    AUDIO_USAGE_ASSISTANCE_SONIFICATION,
+                    AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, "addr=remote_submix_media"},
                 (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_GAME,
-                                     AUDIO_SOURCE_DEFAULT, 0, "addr=remote_submix_media"},
+                    AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, "addr=remote_submix_media"},
                 (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_VIRTUAL_SOURCE,
-                                     AUDIO_SOURCE_DEFAULT, 0, "addr=remote_submix_media"},
+                    AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, "addr=remote_submix_media"},
                 (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_ASSISTANT,
-                                     AUDIO_SOURCE_DEFAULT, 0, "addr=remote_submix_media"},
+                    AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, "addr=remote_submix_media"},
                 (audio_attributes_t){AUDIO_CONTENT_TYPE_SPEECH, AUDIO_USAGE_ASSISTANT,
-                                     AUDIO_SOURCE_DEFAULT, 0, "addr=remote_submix_media"}
+                    AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, "addr=remote_submix_media"}
                 )
         );
 
@@ -817,41 +818,41 @@
         AudioPolicyManagerTestDPPlaybackReRouting,
         testing::Values(
                 (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_VOICE_COMMUNICATION,
-                                     AUDIO_SOURCE_DEFAULT, 0, ""},
+                                     AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""},
                 (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC,
                                      AUDIO_USAGE_VOICE_COMMUNICATION_SIGNALLING,
-                                     AUDIO_SOURCE_DEFAULT, 0, ""},
+                                     AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""},
                 (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_NOTIFICATION,
-                                     AUDIO_SOURCE_DEFAULT, 0, ""},
+                                     AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""},
                 (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC,
                                      AUDIO_USAGE_NOTIFICATION_TELEPHONY_RINGTONE,
-                                     AUDIO_SOURCE_DEFAULT, 0, ""},
+                                     AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""},
                 (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC,
                                      AUDIO_USAGE_NOTIFICATION_COMMUNICATION_REQUEST,
-                                     AUDIO_SOURCE_DEFAULT, 0, ""},
+                                     AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""},
                 (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC,
                                      AUDIO_USAGE_NOTIFICATION_COMMUNICATION_INSTANT,
-                                     AUDIO_SOURCE_DEFAULT, 0, ""},
+                                     AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""},
                 (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC,
                                      AUDIO_USAGE_NOTIFICATION_COMMUNICATION_DELAYED,
-                                     AUDIO_SOURCE_DEFAULT, 0, ""},
+                                     AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""},
                 (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_NOTIFICATION_EVENT,
-                                     AUDIO_SOURCE_DEFAULT, 0, ""},
+                                     AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""},
                 (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC,
                                      AUDIO_USAGE_ASSISTANCE_ACCESSIBILITY,
-                                     AUDIO_SOURCE_DEFAULT, 0, ""},
+                                     AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""},
                 (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC,
                                      AUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE,
-                                     AUDIO_SOURCE_DEFAULT, 0, ""},
+                                     AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""},
                 (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC,
                                      AUDIO_USAGE_ASSISTANCE_SONIFICATION,
-                                     AUDIO_SOURCE_DEFAULT, 0, ""},
+                                     AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""},
                 (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_GAME,
-                                     AUDIO_SOURCE_DEFAULT, 0, ""},
+                                     AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""},
                 (audio_attributes_t){AUDIO_CONTENT_TYPE_MUSIC, AUDIO_USAGE_ASSISTANT,
-                                     AUDIO_SOURCE_DEFAULT, 0, ""},
+                                     AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""},
                 (audio_attributes_t){AUDIO_CONTENT_TYPE_SPEECH, AUDIO_USAGE_ASSISTANT,
-                                     AUDIO_SOURCE_DEFAULT, 0, ""}
+                                     AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""}
                 )
         );
 
@@ -892,7 +893,8 @@
 
     audio_port_handle_t selectedDeviceId = AUDIO_PORT_HANDLE_NONE;
     audio_usage_t usage = AUDIO_USAGE_VIRTUAL_SOURCE;
-    audio_attributes_t attr = {AUDIO_CONTENT_TYPE_UNKNOWN, usage, AUDIO_SOURCE_DEFAULT, 0, ""};
+    audio_attributes_t attr =
+            {AUDIO_CONTENT_TYPE_UNKNOWN, usage, AUDIO_SOURCE_DEFAULT, AUDIO_FLAG_NONE, ""};
     std::string tags = std::string("addr=") + mMixAddress;
     strncpy(attr.tags, tags.c_str(), AUDIO_ATTRIBUTES_TAGS_MAX_SIZE - 1);
     getOutputForAttr(&selectedDeviceId, AUDIO_FORMAT_PCM_16_BIT, AUDIO_CHANNEL_OUT_STEREO,
@@ -941,17 +943,19 @@
         AudioPolicyManagerTestDPMixRecordInjection,
         testing::Values(
                 (audio_attributes_t){AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN,
-                                     AUDIO_SOURCE_CAMCORDER, 0, ""},
+                                     AUDIO_SOURCE_CAMCORDER, AUDIO_FLAG_NONE, ""},
                 (audio_attributes_t){AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN,
-                                     AUDIO_SOURCE_CAMCORDER, 0, "addr=remote_submix_media"},
+                                     AUDIO_SOURCE_CAMCORDER, AUDIO_FLAG_NONE,
+                                     "addr=remote_submix_media"},
                 (audio_attributes_t){AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN,
-                                     AUDIO_SOURCE_MIC, 0, "addr=remote_submix_media"},
+                                     AUDIO_SOURCE_MIC, AUDIO_FLAG_NONE,
+                                     "addr=remote_submix_media"},
                 (audio_attributes_t){AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN,
-                                     AUDIO_SOURCE_MIC, 0, ""},
+                                     AUDIO_SOURCE_MIC, AUDIO_FLAG_NONE, ""},
                 (audio_attributes_t){AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN,
-                                     AUDIO_SOURCE_VOICE_COMMUNICATION, 0, ""},
+                                     AUDIO_SOURCE_VOICE_COMMUNICATION, AUDIO_FLAG_NONE, ""},
                 (audio_attributes_t){AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN,
-                                     AUDIO_SOURCE_VOICE_COMMUNICATION, 0,
+                                     AUDIO_SOURCE_VOICE_COMMUNICATION, AUDIO_FLAG_NONE,
                                      "addr=remote_submix_media"}
                 )
         );
@@ -962,14 +966,15 @@
         AudioPolicyManagerTestDPMixRecordInjection,
         testing::Values(
                 (audio_attributes_t){AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN,
-                                     AUDIO_SOURCE_VOICE_RECOGNITION, 0, ""},
+                                     AUDIO_SOURCE_VOICE_RECOGNITION, AUDIO_FLAG_NONE, ""},
                 (audio_attributes_t){AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN,
-                                     AUDIO_SOURCE_HOTWORD, 0, ""},
+                                     AUDIO_SOURCE_HOTWORD, AUDIO_FLAG_NONE, ""},
                 (audio_attributes_t){AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN,
-                                     AUDIO_SOURCE_VOICE_RECOGNITION, 0,
+                                     AUDIO_SOURCE_VOICE_RECOGNITION, AUDIO_FLAG_NONE,
                                      "addr=remote_submix_media"},
                 (audio_attributes_t){AUDIO_CONTENT_TYPE_UNKNOWN, AUDIO_USAGE_UNKNOWN,
-                                     AUDIO_SOURCE_HOTWORD, 0, "addr=remote_submix_media"}
+                                     AUDIO_SOURCE_HOTWORD, AUDIO_FLAG_NONE,
+                                     "addr=remote_submix_media"}
                 )
         );
 
diff --git a/services/mediametrics/Android.bp b/services/mediametrics/Android.bp
index f033d5c..67e6c39 100644
--- a/services/mediametrics/Android.bp
+++ b/services/mediametrics/Android.bp
@@ -111,7 +111,7 @@
     ],
 }
 
-cc_library_shared {
+cc_library {
     name: "libmediametricsservice",
     defaults: [
         "mediametrics_flags_defaults",
diff --git a/services/mediametrics/statsd_audiopolicy.cpp b/services/mediametrics/statsd_audiopolicy.cpp
index 393c6ae..6ef2f2c 100644
--- a/services/mediametrics/statsd_audiopolicy.cpp
+++ b/services/mediametrics/statsd_audiopolicy.cpp
@@ -32,7 +32,7 @@
 #include <statslog.h>
 
 #include "MediaMetricsService.h"
-#include "frameworks/base/core/proto/android/stats/mediametrics/mediametrics.pb.h"
+#include "frameworks/proto_logging/stats/enums/stats/mediametrics/mediametrics.pb.h"
 #include "iface_statsd.h"
 
 namespace android {
diff --git a/services/mediametrics/statsd_audiorecord.cpp b/services/mediametrics/statsd_audiorecord.cpp
index 43feda1..76f4b59 100644
--- a/services/mediametrics/statsd_audiorecord.cpp
+++ b/services/mediametrics/statsd_audiorecord.cpp
@@ -32,7 +32,7 @@
 #include <statslog.h>
 
 #include "MediaMetricsService.h"
-#include "frameworks/base/core/proto/android/stats/mediametrics/mediametrics.pb.h"
+#include "frameworks/proto_logging/stats/enums/stats/mediametrics/mediametrics.pb.h"
 #include "iface_statsd.h"
 
 namespace android {
diff --git a/services/mediametrics/statsd_audiothread.cpp b/services/mediametrics/statsd_audiothread.cpp
index e867f5b..2ad2562 100644
--- a/services/mediametrics/statsd_audiothread.cpp
+++ b/services/mediametrics/statsd_audiothread.cpp
@@ -32,7 +32,7 @@
 #include <statslog.h>
 
 #include "MediaMetricsService.h"
-#include "frameworks/base/core/proto/android/stats/mediametrics/mediametrics.pb.h"
+#include "frameworks/proto_logging/stats/enums/stats/mediametrics/mediametrics.pb.h"
 #include "iface_statsd.h"
 
 namespace android {
diff --git a/services/mediametrics/statsd_audiotrack.cpp b/services/mediametrics/statsd_audiotrack.cpp
index ee5b9b2..6b08a78 100644
--- a/services/mediametrics/statsd_audiotrack.cpp
+++ b/services/mediametrics/statsd_audiotrack.cpp
@@ -32,7 +32,7 @@
 #include <statslog.h>
 
 #include "MediaMetricsService.h"
-#include "frameworks/base/core/proto/android/stats/mediametrics/mediametrics.pb.h"
+#include "frameworks/proto_logging/stats/enums/stats/mediametrics/mediametrics.pb.h"
 #include "iface_statsd.h"
 
 namespace android {
diff --git a/services/mediametrics/statsd_codec.cpp b/services/mediametrics/statsd_codec.cpp
index ec9354f..d502b30 100644
--- a/services/mediametrics/statsd_codec.cpp
+++ b/services/mediametrics/statsd_codec.cpp
@@ -33,7 +33,7 @@
 
 #include "cleaner.h"
 #include "MediaMetricsService.h"
-#include "frameworks/base/core/proto/android/stats/mediametrics/mediametrics.pb.h"
+#include "frameworks/proto_logging/stats/enums/stats/mediametrics/mediametrics.pb.h"
 #include "iface_statsd.h"
 
 namespace android {
diff --git a/services/mediametrics/statsd_extractor.cpp b/services/mediametrics/statsd_extractor.cpp
index 3d5739f..16814d9 100644
--- a/services/mediametrics/statsd_extractor.cpp
+++ b/services/mediametrics/statsd_extractor.cpp
@@ -32,7 +32,7 @@
 #include <statslog.h>
 
 #include "MediaMetricsService.h"
-#include "frameworks/base/core/proto/android/stats/mediametrics/mediametrics.pb.h"
+#include "frameworks/proto_logging/stats/enums/stats/mediametrics/mediametrics.pb.h"
 #include "iface_statsd.h"
 
 namespace android {
diff --git a/services/mediametrics/statsd_nuplayer.cpp b/services/mediametrics/statsd_nuplayer.cpp
index 488bdcb..a8d0f55 100644
--- a/services/mediametrics/statsd_nuplayer.cpp
+++ b/services/mediametrics/statsd_nuplayer.cpp
@@ -32,7 +32,7 @@
 #include <statslog.h>
 
 #include "MediaMetricsService.h"
-#include "frameworks/base/core/proto/android/stats/mediametrics/mediametrics.pb.h"
+#include "frameworks/proto_logging/stats/enums/stats/mediametrics/mediametrics.pb.h"
 #include "iface_statsd.h"
 
 namespace android {
diff --git a/services/mediametrics/statsd_recorder.cpp b/services/mediametrics/statsd_recorder.cpp
index 6d5fca0..2e5ada4 100644
--- a/services/mediametrics/statsd_recorder.cpp
+++ b/services/mediametrics/statsd_recorder.cpp
@@ -32,7 +32,7 @@
 #include <statslog.h>
 
 #include "MediaMetricsService.h"
-#include "frameworks/base/core/proto/android/stats/mediametrics/mediametrics.pb.h"
+#include "frameworks/proto_logging/stats/enums/stats/mediametrics/mediametrics.pb.h"
 #include "iface_statsd.h"
 
 namespace android {
diff --git a/services/oboeservice/AAudioServiceEndpoint.cpp b/services/oboeservice/AAudioServiceEndpoint.cpp
index ceefe93..b139be1 100644
--- a/services/oboeservice/AAudioServiceEndpoint.cpp
+++ b/services/oboeservice/AAudioServiceEndpoint.cpp
@@ -182,11 +182,12 @@
             : AUDIO_SOURCE_DEFAULT;
     audio_flags_mask_t flags;
     if (direction == AAUDIO_DIRECTION_OUTPUT) {
-        flags = AUDIO_FLAG_LOW_LATENCY
-            | AAudioConvert_allowCapturePolicyToAudioFlagsMask(params->getAllowedCapturePolicy());
+        flags = static_cast<audio_flags_mask_t>(AUDIO_FLAG_LOW_LATENCY
+                | AAudioConvert_allowCapturePolicyToAudioFlagsMask(
+                        params->getAllowedCapturePolicy()));
     } else {
-        flags = AUDIO_FLAG_LOW_LATENCY
-            | AAudioConvert_privacySensitiveToAudioFlagsMask(params->isPrivacySensitive());
+        flags = static_cast<audio_flags_mask_t>(AUDIO_FLAG_LOW_LATENCY
+                | AAudioConvert_privacySensitiveToAudioFlagsMask(params->isPrivacySensitive()));
     }
     return {
             .content_type = contentType,