AudioFlinger: Improve effect compatibility with RAW and FAST am: d3bb0adfe4
am: 4a7ef5c1d7

Change-Id: Ia7d516d957b0582ec6776d4306019e6f2dfc10c0
diff --git a/Android.bp b/Android.bp
new file mode 100644
index 0000000..edd3d04
--- /dev/null
+++ b/Android.bp
@@ -0,0 +1,18 @@
+ndk_headers {
+    name: "libcamera2ndk_headers",
+    from: "include/camera/ndk/",
+    to: "camera",
+    srcs: ["include/camera/ndk/**/*.h"],
+}
+
+ndk_headers {
+    name: "libmediandk_headers",
+    from: "include/ndk/",
+    to: "media",
+    srcs: ["include/ndk/**/*.h"],
+}
+
+subdirs = [
+    "camera/ndk",
+    "media/*",
+]
diff --git a/camera/CameraUtils.cpp b/camera/CameraUtils.cpp
index 1676be1..67fc116 100644
--- a/camera/CameraUtils.cpp
+++ b/camera/CameraUtils.cpp
@@ -45,7 +45,7 @@
     }
 
     camera_metadata_ro_entry_t entryFacing = staticInfo.find(ANDROID_LENS_FACING);
-    if (entry.count == 0) {
+    if (entryFacing.count == 0) {
         ALOGE("%s: Can't find android.lens.facing in static metadata!", __FUNCTION__);
         return INVALID_OPERATION;
     }
diff --git a/camera/ICamera.cpp b/camera/ICamera.cpp
index 0680d7c..2bf956d 100644
--- a/camera/ICamera.cpp
+++ b/camera/ICamera.cpp
@@ -60,7 +60,7 @@
 class BpCamera: public BpInterface<ICamera>
 {
 public:
-    BpCamera(const sp<IBinder>& impl)
+    explicit BpCamera(const sp<IBinder>& impl)
         : BpInterface<ICamera>(impl)
     {
     }
diff --git a/camera/ICameraClient.cpp b/camera/ICameraClient.cpp
index 68cbfb8..1b6fac4 100644
--- a/camera/ICameraClient.cpp
+++ b/camera/ICameraClient.cpp
@@ -37,7 +37,7 @@
 class BpCameraClient: public BpInterface<ICameraClient>
 {
 public:
-    BpCameraClient(const sp<IBinder>& impl)
+    explicit BpCameraClient(const sp<IBinder>& impl)
         : BpInterface<ICameraClient>(impl)
     {
     }
diff --git a/camera/ICameraRecordingProxy.cpp b/camera/ICameraRecordingProxy.cpp
index 63c4b1d..c9f8b5c 100644
--- a/camera/ICameraRecordingProxy.cpp
+++ b/camera/ICameraRecordingProxy.cpp
@@ -38,7 +38,7 @@
 class BpCameraRecordingProxy: public BpInterface<ICameraRecordingProxy>
 {
 public:
-    BpCameraRecordingProxy(const sp<IBinder>& impl)
+    explicit BpCameraRecordingProxy(const sp<IBinder>& impl)
         : BpInterface<ICameraRecordingProxy>(impl)
     {
     }
diff --git a/camera/ICameraRecordingProxyListener.cpp b/camera/ICameraRecordingProxyListener.cpp
index fa4dfd8..8529d3e 100644
--- a/camera/ICameraRecordingProxyListener.cpp
+++ b/camera/ICameraRecordingProxyListener.cpp
@@ -33,7 +33,7 @@
 class BpCameraRecordingProxyListener: public BpInterface<ICameraRecordingProxyListener>
 {
 public:
-    BpCameraRecordingProxyListener(const sp<IBinder>& impl)
+    explicit BpCameraRecordingProxyListener(const sp<IBinder>& impl)
         : BpInterface<ICameraRecordingProxyListener>(impl)
     {
     }
diff --git a/camera/ICameraServiceProxy.cpp b/camera/ICameraServiceProxy.cpp
index 694e9c3..a9d0836 100644
--- a/camera/ICameraServiceProxy.cpp
+++ b/camera/ICameraServiceProxy.cpp
@@ -26,7 +26,8 @@
 
 class BpCameraServiceProxy: public BpInterface<ICameraServiceProxy> {
 public:
-    BpCameraServiceProxy(const sp<IBinder>& impl) : BpInterface<ICameraServiceProxy>(impl) {}
+    explicit BpCameraServiceProxy(const sp<IBinder>& impl)
+        : BpInterface<ICameraServiceProxy>(impl) {}
 
     virtual void pingForUserUpdate() {
         Parcel data;
diff --git a/camera/VendorTagDescriptor.cpp b/camera/VendorTagDescriptor.cpp
index 02ece14..f3b3dbb 100644
--- a/camera/VendorTagDescriptor.cpp
+++ b/camera/VendorTagDescriptor.cpp
@@ -192,7 +192,7 @@
     // Set up reverse mapping
     for (size_t i = 0; i < static_cast<size_t>(tagCount); ++i) {
         uint32_t tag = allTags[i];
-        String8 sectionString = mSections[mTagToSectionMap.valueFor(tag)];
+        const String8& sectionString = mSections[mTagToSectionMap.valueFor(tag)];
 
         ssize_t reverseIndex = -1;
         if ((reverseIndex = mReverseMapping.indexOfKey(sectionString)) < 0) {
@@ -284,7 +284,7 @@
     return &mSections;
 }
 
-status_t VendorTagDescriptor::lookupTag(String8 name, String8 section, /*out*/uint32_t* tag) const {
+status_t VendorTagDescriptor::lookupTag(const String8& name, const String8& section, /*out*/uint32_t* tag) const {
     ssize_t index = mReverseMapping.indexOfKey(section);
     if (index < 0) {
         ALOGE("%s: Section '%s' does not exist.", __FUNCTION__, section.string());
diff --git a/camera/cameraserver/Android.mk b/camera/cameraserver/Android.mk
index 7e36c5e..c0d75f3 100644
--- a/camera/cameraserver/Android.mk
+++ b/camera/cameraserver/Android.mk
@@ -21,6 +21,7 @@
 
 LOCAL_SHARED_LIBRARIES := \
 	libcameraservice \
+	liblog \
 	libcutils \
 	libutils \
 	libbinder \
diff --git a/camera/ndk/Android.bp b/camera/ndk/Android.bp
new file mode 100644
index 0000000..6f2351f
--- /dev/null
+++ b/camera/ndk/Android.bp
@@ -0,0 +1,23 @@
+// Copyright (C) 2016 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.
+
+// Headers module is in frameworks/av/Android.bp because modules are not allowed
+// to refer to headers in parent directories and the headers live in
+// frameworks/av/include.
+
+ndk_library {
+    name: "libcamera2ndk.ndk",
+    symbol_file: "libcamera2ndk.map.txt",
+    first_version: "24",
+}
diff --git a/camera/ndk/impl/ACameraCaptureSession.h b/camera/ndk/impl/ACameraCaptureSession.h
index 58428e6..f56219c 100644
--- a/camera/ndk/impl/ACameraCaptureSession.h
+++ b/camera/ndk/impl/ACameraCaptureSession.h
@@ -24,7 +24,7 @@
 using namespace android;
 
 struct ACaptureSessionOutput {
-    ACaptureSessionOutput(ANativeWindow* window) : mWindow(window) {};
+    explicit ACaptureSessionOutput(ANativeWindow* window) : mWindow(window) {};
 
     bool operator == (const ACaptureSessionOutput& other) const {
         return mWindow == other.mWindow;
diff --git a/camera/ndk/impl/ACameraDevice.h b/camera/ndk/impl/ACameraDevice.h
index 71e364d..051462b 100644
--- a/camera/ndk/impl/ACameraDevice.h
+++ b/camera/ndk/impl/ACameraDevice.h
@@ -65,7 +65,7 @@
     // Callbacks from camera service
     class ServiceCallback : public hardware::camera2::BnCameraDeviceCallbacks {
       public:
-        ServiceCallback(CameraDevice* device) : mDevice(device) {}
+        explicit ServiceCallback(CameraDevice* device) : mDevice(device) {}
         binder::Status onDeviceError(int32_t errorCode,
                            const CaptureResultExtras& resultExtras) override;
         binder::Status onDeviceIdle() override;
diff --git a/camera/ndk/impl/ACameraManager.h b/camera/ndk/impl/ACameraManager.h
index 3f2262f..5b88904 100644
--- a/camera/ndk/impl/ACameraManager.h
+++ b/camera/ndk/impl/ACameraManager.h
@@ -60,7 +60,7 @@
 
     class DeathNotifier : public IBinder::DeathRecipient {
       public:
-        DeathNotifier(CameraManagerGlobal* cm) : mCameraManager(cm) {}
+        explicit DeathNotifier(CameraManagerGlobal* cm) : mCameraManager(cm) {}
       protected:
         // IBinder::DeathRecipient implementation
         virtual void binderDied(const wp<IBinder>& who);
@@ -71,7 +71,7 @@
 
     class CameraServiceListener final : public hardware::BnCameraServiceListener {
       public:
-        CameraServiceListener(CameraManagerGlobal* cm) : mCameraManager(cm) {}
+        explicit CameraServiceListener(CameraManagerGlobal* cm) : mCameraManager(cm) {}
         virtual binder::Status onStatusChanged(int32_t status, int32_t cameraId);
 
         // Torch API not implemented yet
@@ -86,7 +86,7 @@
 
     // Wrapper of ACameraManager_AvailabilityCallbacks so we can store it in std::set
     struct Callback {
-        Callback(const ACameraManager_AvailabilityCallbacks *callback) :
+        explicit Callback(const ACameraManager_AvailabilityCallbacks *callback) :
             mAvailable(callback->onCameraAvailable),
             mUnavailable(callback->onCameraUnavailable),
             mContext(callback->context) {}
diff --git a/camera/ndk/impl/ACaptureRequest.h b/camera/ndk/impl/ACaptureRequest.h
index 6bd8406..3ef6a84 100644
--- a/camera/ndk/impl/ACaptureRequest.h
+++ b/camera/ndk/impl/ACaptureRequest.h
@@ -22,7 +22,7 @@
 using namespace android;
 
 struct ACameraOutputTarget {
-    ACameraOutputTarget(ANativeWindow* window) : mWindow(window) {};
+    explicit ACameraOutputTarget(ANativeWindow* window) : mWindow(window) {};
 
     bool operator == (const ACameraOutputTarget& other) const {
         return mWindow == other.mWindow;
diff --git a/camera/ndk/libcamera2ndk.map.txt b/camera/ndk/libcamera2ndk.map.txt
new file mode 100644
index 0000000..41bb22b
--- /dev/null
+++ b/camera/ndk/libcamera2ndk.map.txt
@@ -0,0 +1,46 @@
+LIBCAMERA2NDK {
+  global:
+    ACameraCaptureSession_abortCaptures;
+    ACameraCaptureSession_capture;
+    ACameraCaptureSession_close;
+    ACameraCaptureSession_getDevice;
+    ACameraCaptureSession_setRepeatingRequest;
+    ACameraCaptureSession_stopRepeating;
+    ACameraDevice_close;
+    ACameraDevice_createCaptureRequest;
+    ACameraDevice_createCaptureSession;
+    ACameraDevice_getId;
+    ACameraManager_create;
+    ACameraManager_delete;
+    ACameraManager_deleteCameraIdList;
+    ACameraManager_getCameraCharacteristics;
+    ACameraManager_getCameraIdList;
+    ACameraManager_openCamera;
+    ACameraManager_registerAvailabilityCallback;
+    ACameraManager_unregisterAvailabilityCallback;
+    ACameraMetadata_copy;
+    ACameraMetadata_free;
+    ACameraMetadata_getAllTags;
+    ACameraMetadata_getConstEntry;
+    ACameraOutputTarget_create;
+    ACameraOutputTarget_free;
+    ACaptureRequest_addTarget;
+    ACaptureRequest_free;
+    ACaptureRequest_getAllTags;
+    ACaptureRequest_getConstEntry;
+    ACaptureRequest_removeTarget;
+    ACaptureRequest_setEntry_double;
+    ACaptureRequest_setEntry_float;
+    ACaptureRequest_setEntry_i32;
+    ACaptureRequest_setEntry_i64;
+    ACaptureRequest_setEntry_rational;
+    ACaptureRequest_setEntry_u8;
+    ACaptureSessionOutputContainer_add;
+    ACaptureSessionOutputContainer_create;
+    ACaptureSessionOutputContainer_free;
+    ACaptureSessionOutputContainer_remove;
+    ACaptureSessionOutput_create;
+    ACaptureSessionOutput_free;
+  local:
+    *;
+};
diff --git a/camera/tests/Android.mk b/camera/tests/Android.mk
index 8019999..0978a81 100644
--- a/camera/tests/Android.mk
+++ b/camera/tests/Android.mk
@@ -21,6 +21,7 @@
 	CameraBinderTests.cpp
 
 LOCAL_SHARED_LIBRARIES := \
+	liblog \
 	libutils \
 	libcutils \
 	libcamera_metadata \
diff --git a/cmds/stagefright/mediafilter.cpp b/cmds/stagefright/mediafilter.cpp
index 1183112..d829df0 100644
--- a/cmds/stagefright/mediafilter.cpp
+++ b/cmds/stagefright/mediafilter.cpp
@@ -69,7 +69,7 @@
 namespace android {
 
 struct SaturationRSFilter : RenderScriptWrapper::RSFilterCallback {
-    void init(RSC::sp<RSC::RS> context) {
+    void init(const RSC::sp<RSC::RS> &context) {
         mScript = new ScriptC_saturation(context);
         mScript->set_gSaturation(3.f);
     }
@@ -90,7 +90,7 @@
 };
 
 struct NightVisionRSFilter : RenderScriptWrapper::RSFilterCallback {
-    void init(RSC::sp<RSC::RS> context) {
+    void init(const RSC::sp<RSC::RS> &context) {
         mScript = new ScriptC_nightvision(context);
     }
 
@@ -110,7 +110,7 @@
 };
 
 struct ARGBToRGBARSFilter : RenderScriptWrapper::RSFilterCallback {
-    void init(RSC::sp<RSC::RS> context) {
+    void init(const RSC::sp<RSC::RS> &context) {
         mScript = new ScriptC_argbtorgba(context);
     }
 
diff --git a/cmds/stagefright/stagefright.cpp b/cmds/stagefright/stagefright.cpp
index ca68722..2bb35cb 100644
--- a/cmds/stagefright/stagefright.cpp
+++ b/cmds/stagefright/stagefright.cpp
@@ -401,7 +401,7 @@
 ////////////////////////////////////////////////////////////////////////////////
 
 struct DetectSyncSource : public MediaSource {
-    DetectSyncSource(const sp<IMediaSource> &source);
+    explicit DetectSyncSource(const sp<IMediaSource> &source);
 
     virtual status_t start(MetaData *params = NULL);
     virtual status_t stop();
diff --git a/cmds/stagefright/stream.cpp b/cmds/stagefright/stream.cpp
index bca3832..16ff39d 100644
--- a/cmds/stagefright/stream.cpp
+++ b/cmds/stagefright/stream.cpp
@@ -45,7 +45,7 @@
 
 struct MyStreamSource : public BnStreamSource {
     // Object assumes ownership of fd.
-    MyStreamSource(int fd);
+    explicit MyStreamSource(int fd);
 
     virtual void setListener(const sp<IStreamListener> &listener);
     virtual void setBuffers(const Vector<sp<IMemory> > &buffers);
@@ -125,7 +125,7 @@
 ////////////////////////////////////////////////////////////////////////////////
 
 struct MyConvertingStreamSource : public BnStreamSource {
-    MyConvertingStreamSource(const char *filename);
+    explicit MyConvertingStreamSource(const char *filename);
 
     virtual void setListener(const sp<IStreamListener> &listener);
     virtual void setBuffers(const Vector<sp<IMemory> > &buffers);
diff --git a/drm/common/Android.mk b/drm/common/Android.mk
index db67534..ca3d2cd 100644
--- a/drm/common/Android.mk
+++ b/drm/common/Android.mk
@@ -31,6 +31,8 @@
     DrmInfoEvent.cpp \
     ReadWriteUtils.cpp
 
+LOCAL_STATIC_LIBRARIES := libbinder
+
 LOCAL_C_INCLUDES := \
     $(TOP)/frameworks/av/include \
     $(TOP)/frameworks/av/drm/libdrmframework/include \
diff --git a/drm/common/DrmInfoEvent.cpp b/drm/common/DrmInfoEvent.cpp
index 27a5a2d..703e363 100644
--- a/drm/common/DrmInfoEvent.cpp
+++ b/drm/common/DrmInfoEvent.cpp
@@ -19,7 +19,7 @@
 
 using namespace android;
 
-DrmInfoEvent::DrmInfoEvent(int uniqueId, int infoType, const String8 message)
+DrmInfoEvent::DrmInfoEvent(int uniqueId, int infoType, const String8 &message)
     : mUniqueId(uniqueId),
       mInfoType(infoType),
       mMessage(message) {
diff --git a/drm/common/IDrmManagerService.cpp b/drm/common/IDrmManagerService.cpp
index caae75f..44f98dd 100644
--- a/drm/common/IDrmManagerService.cpp
+++ b/drm/common/IDrmManagerService.cpp
@@ -33,7 +33,7 @@
 
 #include "IDrmManagerService.h"
 
-#define INVALID_BUFFER_LENGTH -1
+#define INVALID_BUFFER_LENGTH (-1)
 #define MAX_BINDER_TRANSACTION_SIZE ((1*1024*1024)-(4096*2))
 
 using namespace android;
diff --git a/drm/common/ReadWriteUtils.cpp b/drm/common/ReadWriteUtils.cpp
index d696f16..16b5b34 100644
--- a/drm/common/ReadWriteUtils.cpp
+++ b/drm/common/ReadWriteUtils.cpp
@@ -30,7 +30,7 @@
 
 using namespace android;
 
-#define FAILURE -1
+#define FAILURE (-1)
 
 String8 ReadWriteUtils::readBytes(const String8& filePath) {
     FILE* file = NULL;
diff --git a/drm/drmserver/DrmManager.cpp b/drm/drmserver/DrmManager.cpp
index e168ba2..1d835f9 100644
--- a/drm/drmserver/DrmManager.cpp
+++ b/drm/drmserver/DrmManager.cpp
@@ -33,7 +33,7 @@
 #include "DrmManager.h"
 #include "ReadWriteUtils.h"
 
-#define DECRYPT_FILE_ERROR -1
+#define DECRYPT_FILE_ERROR (-1)
 
 using namespace android;
 
@@ -413,7 +413,7 @@
         handle->decryptId = mDecryptSessionId + 1;
 
         for (size_t index = 0; index < plugInIdList.size(); index++) {
-            String8 plugInId = plugInIdList.itemAt(index);
+            const String8& plugInId = plugInIdList.itemAt(index);
             IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId);
             result = rDrmEngine.openDecryptSession(uniqueId, handle, fd, offset, length, mime);
 
@@ -441,7 +441,7 @@
         handle->decryptId = mDecryptSessionId + 1;
 
         for (size_t index = 0; index < plugInIdList.size(); index++) {
-            String8 plugInId = plugInIdList.itemAt(index);
+            const String8& plugInId = plugInIdList.itemAt(index);
             IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId);
             result = rDrmEngine.openDecryptSession(uniqueId, handle, uri, mime);
 
@@ -470,7 +470,7 @@
         handle->decryptId = mDecryptSessionId + 1;
 
         for (size_t index = 0; index < plugInIdList.size(); index++) {
-            String8 plugInId = plugInIdList.itemAt(index);
+            const String8& plugInId = plugInIdList.itemAt(index);
             IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId);
             result = rDrmEngine.openDecryptSession(uniqueId, handle, buf, mimeType);
 
diff --git a/drm/libdrmframework/DrmManagerClientImpl.cpp b/drm/libdrmframework/DrmManagerClientImpl.cpp
index cbd013e..c047eb1 100644
--- a/drm/libdrmframework/DrmManagerClientImpl.cpp
+++ b/drm/libdrmframework/DrmManagerClientImpl.cpp
@@ -28,7 +28,7 @@
 
 using namespace android;
 
-#define INVALID_VALUE -1
+#define INVALID_VALUE (-1)
 
 Mutex DrmManagerClientImpl::sMutex;
 sp<IDrmManagerService> DrmManagerClientImpl::sDrmManagerService;
diff --git a/drm/libdrmframework/include/IDrmManagerService.h b/drm/libdrmframework/include/IDrmManagerService.h
index fe55650..0376b49 100644
--- a/drm/libdrmframework/include/IDrmManagerService.h
+++ b/drm/libdrmframework/include/IDrmManagerService.h
@@ -169,7 +169,7 @@
 class BpDrmManagerService: public BpInterface<IDrmManagerService>
 {
 public:
-    BpDrmManagerService(const sp<IBinder>& impl)
+    explicit BpDrmManagerService(const sp<IBinder>& impl)
             : BpInterface<IDrmManagerService>(impl) {}
 
     virtual int addUniqueId(bool isNative);
diff --git a/drm/libdrmframework/include/IDrmServiceListener.h b/drm/libdrmframework/include/IDrmServiceListener.h
index 7f7109f..78c5d1a 100644
--- a/drm/libdrmframework/include/IDrmServiceListener.h
+++ b/drm/libdrmframework/include/IDrmServiceListener.h
@@ -49,7 +49,7 @@
 class BpDrmServiceListener: public BpInterface<IDrmServiceListener>
 {
 public:
-    BpDrmServiceListener(const sp<IBinder>& impl)
+    explicit BpDrmServiceListener(const sp<IBinder>& impl)
             : BpInterface<IDrmServiceListener>(impl) {}
 
     virtual status_t notify(const DrmInfoEvent& event);
diff --git a/drm/libdrmframework/plugins/common/util/src/MimeTypeUtil.cpp b/drm/libdrmframework/plugins/common/util/src/MimeTypeUtil.cpp
index 4bd1adb..3b1566f 100644
--- a/drm/libdrmframework/plugins/common/util/src/MimeTypeUtil.cpp
+++ b/drm/libdrmframework/plugins/common/util/src/MimeTypeUtil.cpp
@@ -115,7 +115,7 @@
  * replacement mimetype otherwise the original mimetype
  * is returned.
  *
- * If the mimetype is of unsupported group i.e. application / *
+ * If the mimetype is of unsupported group i.e. application/...
  * then "unsupported/drm.mimetype" will be returned.
  *
  * @param mimeType - mimetype in lower case to convert.
diff --git a/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/include/FwdLockEngine.h b/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/include/FwdLockEngine.h
index a31b951..d222703 100644
--- a/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/include/FwdLockEngine.h
+++ b/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/include/FwdLockEngine.h
@@ -539,7 +539,7 @@
             offset = 0;
         }
 
-        DecodeSession(int fd) {
+        explicit DecodeSession(int fd) {
             fileDesc = fd;
             offset = 0;
         }
diff --git a/drm/libdrmframework/plugins/passthru/src/DrmPassthruPlugIn.cpp b/drm/libdrmframework/plugins/passthru/src/DrmPassthruPlugIn.cpp
index 084e323..7f5b0ec 100644
--- a/drm/libdrmframework/plugins/passthru/src/DrmPassthruPlugIn.cpp
+++ b/drm/libdrmframework/plugins/passthru/src/DrmPassthruPlugIn.cpp
@@ -52,12 +52,12 @@
 
 }
 
-DrmMetadata* DrmPassthruPlugIn::onGetMetadata(int uniqueId, const String8* path) {
+DrmMetadata* DrmPassthruPlugIn::onGetMetadata(int /*uniqueId*/, const String8* /*path*/) {
     return NULL;
 }
 
 DrmConstraints* DrmPassthruPlugIn::onGetConstraints(
-        int uniqueId, const String8* path, int action) {
+        int uniqueId, const String8* /*path*/, int /*action*/) {
     ALOGV("DrmPassthruPlugIn::onGetConstraints From Path: %d", uniqueId);
     DrmConstraints* drmConstraints = new DrmConstraints();
 
@@ -108,7 +108,7 @@
 }
 
 status_t DrmPassthruPlugIn::onSetOnInfoListener(
-            int uniqueId, const IDrmEngine::OnInfoListener* infoListener) {
+            int uniqueId, const IDrmEngine::OnInfoListener* /*infoListener*/) {
     ALOGV("DrmPassthruPlugIn::onSetOnInfoListener : %d", uniqueId);
     return DRM_NO_ERROR;
 }
@@ -135,8 +135,8 @@
     return drmSupportInfo;
 }
 
-status_t DrmPassthruPlugIn::onSaveRights(int uniqueId, const DrmRights& drmRights,
-            const String8& rightsPath, const String8& contentPath) {
+status_t DrmPassthruPlugIn::onSaveRights(int uniqueId, const DrmRights& /*drmRights*/,
+            const String8& /*rightsPath*/, const String8& /*contentPath*/) {
     ALOGV("DrmPassthruPlugIn::onSaveRights : %d", uniqueId);
     return DRM_NO_ERROR;
 }
@@ -157,49 +157,50 @@
     return drmInfo;
 }
 
-bool DrmPassthruPlugIn::onCanHandle(int uniqueId, const String8& path) {
+bool DrmPassthruPlugIn::onCanHandle(int /*uniqueId*/, const String8& path) {
     ALOGV("DrmPassthruPlugIn::canHandle: %s ", path.string());
     String8 extension = path.getPathExtension();
     extension.toLower();
     return (String8(".passthru") == extension);
 }
 
-String8 DrmPassthruPlugIn::onGetOriginalMimeType(int uniqueId, const String8& path, int fd) {
+String8 DrmPassthruPlugIn::onGetOriginalMimeType(int uniqueId,
+            const String8& /*path*/, int /*fd*/) {
     ALOGV("DrmPassthruPlugIn::onGetOriginalMimeType() : %d", uniqueId);
     return String8("video/passthru");
 }
 
 int DrmPassthruPlugIn::onGetDrmObjectType(
-            int uniqueId, const String8& path, const String8& mimeType) {
+            int uniqueId, const String8& /*path*/, const String8& /*mimeType*/) {
     ALOGV("DrmPassthruPlugIn::onGetDrmObjectType() : %d", uniqueId);
     return DrmObjectType::UNKNOWN;
 }
 
-int DrmPassthruPlugIn::onCheckRightsStatus(int uniqueId, const String8& path, int action) {
+int DrmPassthruPlugIn::onCheckRightsStatus(int uniqueId, const String8& /*path*/, int /*action*/) {
     ALOGV("DrmPassthruPlugIn::onCheckRightsStatus() : %d", uniqueId);
     int rightsStatus = RightsStatus::RIGHTS_VALID;
     return rightsStatus;
 }
 
-status_t DrmPassthruPlugIn::onConsumeRights(int uniqueId, DecryptHandle* decryptHandle,
-            int action, bool reserve) {
+status_t DrmPassthruPlugIn::onConsumeRights(int uniqueId,
+            DecryptHandle* /*decryptHandle*/, int /*action*/, bool /*reserve*/) {
     ALOGV("DrmPassthruPlugIn::onConsumeRights() : %d", uniqueId);
     return DRM_NO_ERROR;
 }
 
-status_t DrmPassthruPlugIn::onSetPlaybackStatus(int uniqueId, DecryptHandle* decryptHandle,
-            int playbackStatus, int64_t position) {
+status_t DrmPassthruPlugIn::onSetPlaybackStatus(int uniqueId,
+            DecryptHandle* /*decryptHandle*/, int /*playbackStatus*/, int64_t /*position*/) {
     ALOGV("DrmPassthruPlugIn::onSetPlaybackStatus() : %d", uniqueId);
     return DRM_NO_ERROR;
 }
 
-bool DrmPassthruPlugIn::onValidateAction(int uniqueId, const String8& path,
-            int action, const ActionDescription& description) {
+bool DrmPassthruPlugIn::onValidateAction(int uniqueId,
+            const String8& /*path*/, int /*action*/, const ActionDescription& /*description*/) {
     ALOGV("DrmPassthruPlugIn::onValidateAction() : %d", uniqueId);
     return true;
 }
 
-status_t DrmPassthruPlugIn::onRemoveRights(int uniqueId, const String8& path) {
+status_t DrmPassthruPlugIn::onRemoveRights(int uniqueId, const String8& /*path*/) {
     ALOGV("DrmPassthruPlugIn::onRemoveRights() : %d", uniqueId);
     return DRM_NO_ERROR;
 }
@@ -209,13 +210,13 @@
     return DRM_NO_ERROR;
 }
 
-status_t DrmPassthruPlugIn::onOpenConvertSession(int uniqueId, int convertId) {
+status_t DrmPassthruPlugIn::onOpenConvertSession(int uniqueId, int /*convertId*/) {
     ALOGV("DrmPassthruPlugIn::onOpenConvertSession() : %d", uniqueId);
     return DRM_NO_ERROR;
 }
 
 DrmConvertedStatus* DrmPassthruPlugIn::onConvertData(
-            int uniqueId, int convertId, const DrmBuffer* inputData) {
+            int uniqueId, int /*convertId*/, const DrmBuffer* inputData) {
     ALOGV("DrmPassthruPlugIn::onConvertData() : %d", uniqueId);
     DrmBuffer* convertedData = NULL;
 
@@ -229,13 +230,13 @@
     return new DrmConvertedStatus(DrmConvertedStatus::STATUS_OK, convertedData, 0 /*offset*/);
 }
 
-DrmConvertedStatus* DrmPassthruPlugIn::onCloseConvertSession(int uniqueId, int convertId) {
+DrmConvertedStatus* DrmPassthruPlugIn::onCloseConvertSession(int uniqueId, int /*convertId*/) {
     ALOGV("DrmPassthruPlugIn::onCloseConvertSession() : %d", uniqueId);
     return new DrmConvertedStatus(DrmConvertedStatus::STATUS_OK, NULL, 0 /*offset*/);
 }
 
 status_t DrmPassthruPlugIn::onOpenDecryptSession(
-            int uniqueId, DecryptHandle* decryptHandle, int fd, off64_t offset, off64_t length) {
+            int uniqueId, DecryptHandle* decryptHandle, int /*fd*/, off64_t /*offset*/, off64_t /*length*/) {
     ALOGV("DrmPassthruPlugIn::onOpenDecryptSession() : %d", uniqueId);
 
 #ifdef ENABLE_PASSTHRU_DECRYPTION
@@ -250,7 +251,7 @@
 }
 
 status_t DrmPassthruPlugIn::onOpenDecryptSession(
-            int uniqueId, DecryptHandle* decryptHandle, const char* uri) {
+            int /*uniqueId*/, DecryptHandle* /*decryptHandle*/, const char* /*uri*/) {
     return DRM_ERROR_CANNOT_HANDLE;
 }
 
@@ -265,14 +266,14 @@
     return DRM_NO_ERROR;
 }
 
-status_t DrmPassthruPlugIn::onInitializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle,
-            int decryptUnitId, const DrmBuffer* headerInfo) {
+status_t DrmPassthruPlugIn::onInitializeDecryptUnit(int uniqueId, DecryptHandle* /*decryptHandle*/,
+            int /*decryptUnitId*/, const DrmBuffer* /*headerInfo*/) {
     ALOGV("DrmPassthruPlugIn::onInitializeDecryptUnit() : %d", uniqueId);
     return DRM_NO_ERROR;
 }
 
-status_t DrmPassthruPlugIn::onDecrypt(int uniqueId, DecryptHandle* decryptHandle,
-            int decryptUnitId, const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) {
+status_t DrmPassthruPlugIn::onDecrypt(int uniqueId, DecryptHandle* /*decryptHandle*/,
+            int /*decryptUnitId*/, const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* /*IV*/) {
     ALOGV("DrmPassthruPlugIn::onDecrypt() : %d", uniqueId);
     /**
      * As a workaround implementation passthru would copy the given
@@ -293,13 +294,13 @@
 }
 
 status_t DrmPassthruPlugIn::onFinalizeDecryptUnit(
-            int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId) {
+            int uniqueId, DecryptHandle* /*decryptHandle*/, int /*decryptUnitId*/) {
     ALOGV("DrmPassthruPlugIn::onFinalizeDecryptUnit() : %d", uniqueId);
     return DRM_NO_ERROR;
 }
 
-ssize_t DrmPassthruPlugIn::onPread(int uniqueId, DecryptHandle* decryptHandle,
-            void* buffer, ssize_t numBytes, off64_t offset) {
+ssize_t DrmPassthruPlugIn::onPread(int uniqueId, DecryptHandle* /*decryptHandle*/,
+            void* /*buffer*/, ssize_t /*numBytes*/, off64_t /*offset*/) {
     ALOGV("DrmPassthruPlugIn::onPread() : %d", uniqueId);
     return 0;
 }
diff --git a/drm/libmediadrm/Android.mk b/drm/libmediadrm/Android.mk
index 6a2ed31..f1c6b00 100644
--- a/drm/libmediadrm/Android.mk
+++ b/drm/libmediadrm/Android.mk
@@ -23,9 +23,6 @@
 	libstagefright_foundation \
 	libutils
 
-LOCAL_C_INCLUDES := \
-    libcore/include
-
 LOCAL_CFLAGS += -Werror -Wno-error=deprecated-declarations -Wall
 LOCAL_CLANG := true
 
diff --git a/drm/libmediadrm/Drm.cpp b/drm/libmediadrm/Drm.cpp
index 7c1f5c8..9ab08db 100644
--- a/drm/libmediadrm/Drm.cpp
+++ b/drm/libmediadrm/Drm.cpp
@@ -61,7 +61,7 @@
 }
 
 struct DrmSessionClient : public DrmSessionClientInterface {
-    DrmSessionClient(Drm* drm) : mDrm(drm) {}
+    explicit DrmSessionClient(Drm* drm) : mDrm(drm) {}
 
     virtual bool reclaimSession(const Vector<uint8_t>& sessionId) {
         sp<Drm> drm = mDrm.promote();
diff --git a/drm/libmediadrm/DrmSessionManager.cpp b/drm/libmediadrm/DrmSessionManager.cpp
index a87fb9d..02270d0 100644
--- a/drm/libmediadrm/DrmSessionManager.cpp
+++ b/drm/libmediadrm/DrmSessionManager.cpp
@@ -65,7 +65,7 @@
 DrmSessionManager::~DrmSessionManager() {}
 
 void DrmSessionManager::addSession(
-        int pid, sp<DrmSessionClientInterface> drm, const Vector<uint8_t> &sessionId) {
+        int pid, const sp<DrmSessionClientInterface>& drm, const Vector<uint8_t> &sessionId) {
     ALOGV("addSession(pid %d, drm %p, sessionId %s)", pid, drm.get(),
             GetSessionIdString(sessionId).string());
 
@@ -116,7 +116,7 @@
     }
 }
 
-void DrmSessionManager::removeDrm(sp<DrmSessionClientInterface> drm) {
+void DrmSessionManager::removeDrm(const sp<DrmSessionClientInterface>& drm) {
     ALOGV("removeDrm(%p)", drm.get());
 
     Mutex::Autolock lock(mLock);
diff --git a/drm/mediadrm/plugins/clearkey/CryptoPlugin.h b/drm/mediadrm/plugins/clearkey/CryptoPlugin.h
index de84c36..a6d2f7b 100644
--- a/drm/mediadrm/plugins/clearkey/CryptoPlugin.h
+++ b/drm/mediadrm/plugins/clearkey/CryptoPlugin.h
@@ -31,7 +31,7 @@
 
 class CryptoPlugin : public android::CryptoPlugin {
 public:
-    CryptoPlugin(const android::Vector<uint8_t>& sessionId) {
+    explicit CryptoPlugin(const android::Vector<uint8_t>& sessionId) {
         mInitStatus = setMediaDrmSession(sessionId);
     }
 
diff --git a/drm/mediadrm/plugins/clearkey/DrmPlugin.h b/drm/mediadrm/plugins/clearkey/DrmPlugin.h
index efb9f8b..c4d934e 100644
--- a/drm/mediadrm/plugins/clearkey/DrmPlugin.h
+++ b/drm/mediadrm/plugins/clearkey/DrmPlugin.h
@@ -39,7 +39,7 @@
 
 class DrmPlugin : public android::DrmPlugin {
 public:
-    DrmPlugin(SessionLibrary* sessionLibrary)
+    explicit DrmPlugin(SessionLibrary* sessionLibrary)
             : mSessionLibrary(sessionLibrary) {}
     virtual ~DrmPlugin() {}
 
diff --git a/drm/mediadrm/plugins/mock/MockDrmCryptoPlugin.cpp b/drm/mediadrm/plugins/mock/MockDrmCryptoPlugin.cpp
index 1e80f8e..a38cca9 100644
--- a/drm/mediadrm/plugins/mock/MockDrmCryptoPlugin.cpp
+++ b/drm/mediadrm/plugins/mock/MockDrmCryptoPlugin.cpp
@@ -766,7 +766,7 @@
         return result;
     }
 
-    String8 MockDrmPlugin::stringMapToString(KeyedVector<String8, String8> map) const
+    String8 MockDrmPlugin::stringMapToString(const KeyedVector<String8, String8>& map) const
     {
         String8 result("{ ");
         for (size_t i = 0; i < map.size(); i++) {
diff --git a/drm/mediadrm/plugins/mock/MockDrmCryptoPlugin.h b/drm/mediadrm/plugins/mock/MockDrmCryptoPlugin.h
index 40d4e84..98bdd69 100644
--- a/drm/mediadrm/plugins/mock/MockDrmCryptoPlugin.h
+++ b/drm/mediadrm/plugins/mock/MockDrmCryptoPlugin.h
@@ -138,7 +138,7 @@
     private:
         String8 vectorToString(Vector<uint8_t> const &vector) const;
         String8 arrayToString(uint8_t const *array, size_t len) const;
-        String8 stringMapToString(KeyedVector<String8, String8> map) const;
+        String8 stringMapToString(const KeyedVector<String8, String8>& map) const;
 
         SortedVector<Vector<uint8_t> > mSessions;
         SortedVector<Vector<uint8_t> > mKeySets;
diff --git a/include/camera/Camera.h b/include/camera/Camera.h
index be793a2..57dc228 100644
--- a/include/camera/Camera.h
+++ b/include/camera/Camera.h
@@ -170,7 +170,7 @@
     class RecordingProxy : public BnCameraRecordingProxy
     {
     public:
-        RecordingProxy(const sp<Camera>& camera);
+        explicit RecordingProxy(const sp<Camera>& camera);
 
         // ICameraRecordingProxy interface
         virtual status_t startRecording(const sp<ICameraRecordingProxyListener>& listener);
@@ -183,7 +183,7 @@
     };
 
 protected:
-                        Camera(int cameraId);
+    explicit            Camera(int cameraId);
                         Camera(const Camera&);
                         Camera& operator=(const Camera);
 
diff --git a/include/camera/VendorTagDescriptor.h b/include/camera/VendorTagDescriptor.h
index 60e2d2d..bfc8c96 100644
--- a/include/camera/VendorTagDescriptor.h
+++ b/include/camera/VendorTagDescriptor.h
@@ -91,7 +91,7 @@
          *
          * Returns OK on success, or a negative error code.
          */
-        status_t lookupTag(String8 name, String8 section, /*out*/uint32_t* tag) const;
+        status_t lookupTag(const String8& name, const String8& section, /*out*/uint32_t* tag) const;
 
         /**
          * Dump the currently configured vendor tags to a file descriptor.
diff --git a/include/camera/ndk/NdkCameraCaptureSession.h b/include/camera/ndk/NdkCameraCaptureSession.h
index 7b314e9..d96f538 100644
--- a/include/camera/ndk/NdkCameraCaptureSession.h
+++ b/include/camera/ndk/NdkCameraCaptureSession.h
@@ -32,6 +32,8 @@
  * Do not reference types that are not part of the NDK.
  * Do not #include files that aren't part of the NDK.
  */
+#include <sys/cdefs.h>
+
 #include <android/native_window.h>
 #include "NdkCameraError.h"
 #include "NdkCameraMetadata.h"
@@ -39,9 +41,9 @@
 #ifndef _NDK_CAMERA_CAPTURE_SESSION_H
 #define _NDK_CAMERA_CAPTURE_SESSION_H
 
-#ifdef __cplusplus
-extern "C" {
-#endif
+__BEGIN_DECLS
+
+#if __ANDROID_API__ >= 24
 
 /**
  * ACameraCaptureSession is an opaque type that manages frame captures of a camera device.
@@ -587,11 +589,10 @@
  */
 camera_status_t ACameraCaptureSession_abortCaptures(ACameraCaptureSession* session);
 
+#endif /* __ANDROID_API__ >= 24 */
 
-#ifdef __cplusplus
-} // extern "C"
-#endif
+__END_DECLS
 
-#endif // _NDK_CAMERA_CAPTURE_SESSION_H
+#endif /* _NDK_CAMERA_CAPTURE_SESSION_H */
 
 /** @} */
diff --git a/include/camera/ndk/NdkCameraDevice.h b/include/camera/ndk/NdkCameraDevice.h
index 9011cb6..9b7f6f4 100644
--- a/include/camera/ndk/NdkCameraDevice.h
+++ b/include/camera/ndk/NdkCameraDevice.h
@@ -32,6 +32,7 @@
  * Do not reference types that are not part of the NDK.
  * Do not #include files that aren't part of the NDK.
  */
+#include <sys/cdefs.h>
 
 #include <android/native_window.h>
 #include "NdkCameraError.h"
@@ -41,9 +42,9 @@
 #ifndef _NDK_CAMERA_DEVICE_H
 #define _NDK_CAMERA_DEVICE_H
 
-#ifdef __cplusplus
-extern "C" {
-#endif
+__BEGIN_DECLS
+
+#if __ANDROID_API__ >= 24
 
 /**
  * ACameraDevice is opaque type that provides access to a camera device.
@@ -658,11 +659,11 @@
         const ACameraCaptureSession_stateCallbacks* callbacks,
         /*out*/ACameraCaptureSession** session);
 
-#ifdef __cplusplus
-} // extern "C"
-#endif
+#endif /* __ANDROID_API__ >= 24 */
 
-#endif // _NDK_CAMERA_DEVICE_H
+__END_DECLS
+
+#endif /* _NDK_CAMERA_DEVICE_H */
 
 /** @} */
 
diff --git a/include/camera/ndk/NdkCameraError.h b/include/camera/ndk/NdkCameraError.h
index 36251fc..6b58155 100644
--- a/include/camera/ndk/NdkCameraError.h
+++ b/include/camera/ndk/NdkCameraError.h
@@ -36,9 +36,11 @@
 #ifndef _NDK_CAMERA_ERROR_H
 #define _NDK_CAMERA_ERROR_H
 
-#ifdef __cplusplus
-extern "C" {
-#endif
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS
+
+#if __ANDROID_API__ >= 24
 
 typedef enum {
     ACAMERA_OK = 0,
@@ -130,11 +132,10 @@
     ACAMERA_ERROR_PERMISSION_DENIED     = ACAMERA_ERROR_BASE - 13,
 } camera_status_t;
 
+#endif /* __ANDROID_API__ >= 24 */
 
-#ifdef __cplusplus
-} // extern "C"
-#endif
+__END_DECLS
 
-#endif // _NDK_CAMERA_ERROR_H
+#endif /* _NDK_CAMERA_ERROR_H */
 
 /** @} */
diff --git a/include/camera/ndk/NdkCameraManager.h b/include/camera/ndk/NdkCameraManager.h
index 9188e94..5b5c98b 100644
--- a/include/camera/ndk/NdkCameraManager.h
+++ b/include/camera/ndk/NdkCameraManager.h
@@ -36,13 +36,15 @@
 #ifndef _NDK_CAMERA_MANAGER_H
 #define _NDK_CAMERA_MANAGER_H
 
+#include <sys/cdefs.h>
+
 #include "NdkCameraError.h"
 #include "NdkCameraMetadata.h"
 #include "NdkCameraDevice.h"
 
-#ifdef __cplusplus
-extern "C" {
-#endif
+__BEGIN_DECLS
+
+#if __ANDROID_API__ >= 24
 
 /**
  * ACameraManager is opaque type that provides access to camera service.
@@ -271,10 +273,10 @@
         ACameraDevice_StateCallbacks* callback,
         /*out*/ACameraDevice** device);
 
-#ifdef __cplusplus
-} // extern "C"
-#endif
+#endif /* __ANDROID_API__ >= 24 */
 
-#endif //_NDK_CAMERA_MANAGER_H
+__END_DECLS
+
+#endif /* _NDK_CAMERA_MANAGER_H */
 
 /** @} */
diff --git a/include/camera/ndk/NdkCameraMetadata.h b/include/camera/ndk/NdkCameraMetadata.h
index d929854..f2aec98 100644
--- a/include/camera/ndk/NdkCameraMetadata.h
+++ b/include/camera/ndk/NdkCameraMetadata.h
@@ -36,12 +36,14 @@
 #ifndef _NDK_CAMERA_METADATA_H
 #define _NDK_CAMERA_METADATA_H
 
+#include <sys/cdefs.h>
+
 #include "NdkCameraError.h"
 #include "NdkCameraMetadataTags.h"
 
-#ifdef __cplusplus
-extern "C" {
-#endif
+__BEGIN_DECLS
+
+#if __ANDROID_API__ >= 24
 
 /**
  * ACameraMetadata is opaque type that provides access to read-only camera metadata like camera
@@ -226,10 +228,10 @@
  */
 void ACameraMetadata_free(ACameraMetadata* metadata);
 
-#ifdef __cplusplus
-} // extern "C"
-#endif
+#endif /* __ANDROID_API__ >= 24 */
 
-#endif //_NDK_CAMERA_METADATA_H
+__END_DECLS
+
+#endif /* _NDK_CAMERA_METADATA_H */
 
 /** @} */
diff --git a/include/camera/ndk/NdkCameraMetadataTags.h b/include/camera/ndk/NdkCameraMetadataTags.h
index e7f6989..0fec983 100644
--- a/include/camera/ndk/NdkCameraMetadataTags.h
+++ b/include/camera/ndk/NdkCameraMetadataTags.h
@@ -36,6 +36,12 @@
 #ifndef _NDK_CAMERA_METADATA_TAGS_H
 #define _NDK_CAMERA_METADATA_TAGS_H
 
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS
+
+#if __ANDROID_API__ >= 24
+
 typedef enum acamera_metadata_section {
     ACAMERA_COLOR_CORRECTION,
     ACAMERA_CONTROL,
@@ -6901,8 +6907,10 @@
 
 } acamera_metadata_enum_android_depth_depth_is_exclusive_t;
 
+#endif /* __ANDROID_API__ >= 24 */
 
+__END_DECLS
 
-#endif //_NDK_CAMERA_METADATA_TAGS_H
+#endif /* _NDK_CAMERA_METADATA_TAGS_H */
 
 /** @} */
diff --git a/include/camera/ndk/NdkCaptureRequest.h b/include/camera/ndk/NdkCaptureRequest.h
index cd97f4d..c62ba2c 100644
--- a/include/camera/ndk/NdkCaptureRequest.h
+++ b/include/camera/ndk/NdkCaptureRequest.h
@@ -32,6 +32,9 @@
  * Do not reference types that are not part of the NDK.
  * Do not #include files that aren't part of the NDK.
  */
+
+#include <sys/cdefs.h>
+
 #include <android/native_window.h>
 #include "NdkCameraError.h"
 #include "NdkCameraMetadata.h"
@@ -39,9 +42,9 @@
 #ifndef _NDK_CAPTURE_REQUEST_H
 #define _NDK_CAPTURE_REQUEST_H
 
-#ifdef __cplusplus
-extern "C" {
-#endif
+__BEGIN_DECLS
+
+#if __ANDROID_API__ >= 24
 
 // Container for output targets
 typedef struct ACameraOutputTargets ACameraOutputTargets;
@@ -300,10 +303,10 @@
  */
 void ACaptureRequest_free(ACaptureRequest* request);
 
-#ifdef __cplusplus
-} // extern "C"
-#endif
+#endif /* __ANDROID_API__ >= 24 */
 
-#endif // _NDK_CAPTURE_REQUEST_H
+__END_DECLS
+
+#endif /* _NDK_CAPTURE_REQUEST_H */
 
 /** @} */
diff --git a/include/drm/DrmConstraints.h b/include/drm/DrmConstraints.h
index a9ec942..b8bb24f 100644
--- a/include/drm/DrmConstraints.h
+++ b/include/drm/DrmConstraints.h
@@ -70,7 +70,7 @@
     class KeyIterator {
         friend class DrmConstraints;
     private:
-        KeyIterator(DrmConstraints* drmConstraints)
+        explicit KeyIterator(DrmConstraints* drmConstraints)
             : mDrmConstraints(drmConstraints), mIndex(0) {}
 
     public:
@@ -93,7 +93,7 @@
     class Iterator {
         friend class DrmConstraints;
     private:
-        Iterator(DrmConstraints* drmConstraints)
+        explicit Iterator(DrmConstraints* drmConstraints)
             : mDrmConstraints(drmConstraints), mIndex(0) {}
 
     public:
diff --git a/include/drm/DrmInfo.h b/include/drm/DrmInfo.h
index 7b48541..53dfd61 100644
--- a/include/drm/DrmInfo.h
+++ b/include/drm/DrmInfo.h
@@ -55,7 +55,7 @@
         friend class DrmInfo;
 
     private:
-        KeyIterator(const DrmInfo* drmInfo)
+        explicit KeyIterator(const DrmInfo* drmInfo)
             : mDrmInfo(const_cast <DrmInfo*> (drmInfo)), mIndex(0) {}
 
     public:
@@ -79,7 +79,7 @@
         friend class DrmInfo;
 
     private:
-        Iterator(const DrmInfo* drmInfo)
+        explicit Iterator(const DrmInfo* drmInfo)
             : mDrmInfo(const_cast <DrmInfo*> (drmInfo)), mIndex(0) {}
 
     public:
diff --git a/include/drm/DrmInfoEvent.h b/include/drm/DrmInfoEvent.h
index dfca228..3165f02 100644
--- a/include/drm/DrmInfoEvent.h
+++ b/include/drm/DrmInfoEvent.h
@@ -77,7 +77,7 @@
      * @param[in] infoType Type of information
      * @param[in] message Message description
      */
-    DrmInfoEvent(int uniqueId, int infoType, const String8 message);
+    DrmInfoEvent(int uniqueId, int infoType, const String8& message);
 
     /**
      * Destructor for DrmInfoEvent
diff --git a/include/drm/DrmInfoRequest.h b/include/drm/DrmInfoRequest.h
index 3e48ecc..e2da4fe 100644
--- a/include/drm/DrmInfoRequest.h
+++ b/include/drm/DrmInfoRequest.h
@@ -69,7 +69,7 @@
         friend class DrmInfoRequest;
 
     private:
-        KeyIterator(const DrmInfoRequest* drmInfoRequest)
+        explicit KeyIterator(const DrmInfoRequest* drmInfoRequest)
             : mDrmInfoRequest(const_cast <DrmInfoRequest*> (drmInfoRequest)), mIndex(0) {}
 
     public:
@@ -93,7 +93,7 @@
         friend class DrmInfoRequest;
 
     private:
-        Iterator(const DrmInfoRequest* drmInfoRequest)
+        explicit Iterator(const DrmInfoRequest* drmInfoRequest)
             : mDrmInfoRequest(const_cast <DrmInfoRequest*> (drmInfoRequest)), mIndex(0) {}
 
     public:
diff --git a/include/drm/DrmMetadata.h b/include/drm/DrmMetadata.h
index 2c7538a..6624450 100644
--- a/include/drm/DrmMetadata.h
+++ b/include/drm/DrmMetadata.h
@@ -35,7 +35,7 @@
     class KeyIterator {
         friend class DrmMetadata;
     private:
-        KeyIterator(DrmMetadata* drmMetadata) : mDrmMetadata(drmMetadata), mIndex(0) {}
+        explicit KeyIterator(DrmMetadata* drmMetadata) : mDrmMetadata(drmMetadata), mIndex(0) {}
 
     public:
         KeyIterator(const KeyIterator& keyIterator);
@@ -57,7 +57,7 @@
     class Iterator {
         friend class DrmMetadata;
     private:
-        Iterator(DrmMetadata* drmMetadata) : mDrmMetadata(drmMetadata), mIndex(0) {}
+        explicit Iterator(DrmMetadata* drmMetadata) : mDrmMetadata(drmMetadata), mIndex(0) {}
 
     public:
         Iterator(const Iterator& iterator);
diff --git a/include/drm/DrmSupportInfo.h b/include/drm/DrmSupportInfo.h
index bf12b0b..bf85dbb 100644
--- a/include/drm/DrmSupportInfo.h
+++ b/include/drm/DrmSupportInfo.h
@@ -37,7 +37,7 @@
     class MimeTypeIterator {
         friend class DrmSupportInfo;
     private:
-        MimeTypeIterator(DrmSupportInfo* drmSupportInfo)
+        explicit MimeTypeIterator(DrmSupportInfo* drmSupportInfo)
            : mDrmSupportInfo(drmSupportInfo), mIndex(0) {}
     public:
         MimeTypeIterator(const MimeTypeIterator& iterator);
@@ -60,7 +60,7 @@
        friend class DrmSupportInfo;
 
     private:
-        FileSuffixIterator(DrmSupportInfo* drmSupportInfo)
+        explicit FileSuffixIterator(DrmSupportInfo* drmSupportInfo)
             : mDrmSupportInfo(drmSupportInfo), mIndex(0) {}
     public:
         FileSuffixIterator(const FileSuffixIterator& iterator);
diff --git a/include/drm/drm_framework_common.h b/include/drm/drm_framework_common.h
index 637409c..0750406 100644
--- a/include/drm/drm_framework_common.h
+++ b/include/drm/drm_framework_common.h
@@ -23,7 +23,7 @@
 #include <utils/String8.h>
 #include <utils/Errors.h>
 
-#define INVALID_VALUE -1
+#define INVALID_VALUE (-1)
 
 namespace android {
 
diff --git a/include/media/AudioPolicy.h b/include/media/AudioPolicy.h
index 8528c7a..8da0069 100644
--- a/include/media/AudioPolicy.h
+++ b/include/media/AudioPolicy.h
@@ -36,7 +36,7 @@
                                       (RULE_EXCLUSION_MASK|RULE_MATCH_ATTRIBUTE_CAPTURE_PRESET)
 #define RULE_EXCLUDE_UID              (RULE_EXCLUSION_MASK|RULE_MATCH_UID)
 
-#define MIX_TYPE_INVALID -1
+#define MIX_TYPE_INVALID (-1)
 #define MIX_TYPE_PLAYERS 0
 #define MIX_TYPE_RECORDERS 1
 
@@ -45,7 +45,7 @@
 // keep in sync with AudioSystem.java
 #define DYNAMIC_POLICY_EVENT_MIX_STATE_UPDATE 0
 
-#define MIX_STATE_DISABLED -1
+#define MIX_STATE_DISABLED (-1)
 #define MIX_STATE_IDLE 0
 #define MIX_STATE_MIXING 1
 
diff --git a/include/media/AudioSystem.h b/include/media/AudioSystem.h
index 2e6646a..2174b2f 100644
--- a/include/media/AudioSystem.h
+++ b/include/media/AudioSystem.h
@@ -326,7 +326,7 @@
 
     static audio_mode_t getPhoneState();
 
-    static status_t registerPolicyMixes(Vector<AudioMix> mixes, bool registration);
+    static status_t registerPolicyMixes(const Vector<AudioMix>& mixes, bool registration);
 
     static status_t startAudioSource(const struct audio_port_config *source,
                                       const audio_attributes_t *attributes,
diff --git a/include/media/DrmSessionManager.h b/include/media/DrmSessionManager.h
index ba5c268..ba27199 100644
--- a/include/media/DrmSessionManager.h
+++ b/include/media/DrmSessionManager.h
@@ -45,12 +45,12 @@
     static sp<DrmSessionManager> Instance();
 
     DrmSessionManager();
-    DrmSessionManager(sp<ProcessInfoInterface> processInfo);
+    explicit DrmSessionManager(sp<ProcessInfoInterface> processInfo);
 
-    void addSession(int pid, sp<DrmSessionClientInterface> drm, const Vector<uint8_t>& sessionId);
+    void addSession(int pid, const sp<DrmSessionClientInterface>& drm, const Vector<uint8_t>& sessionId);
     void useSession(const Vector<uint8_t>& sessionId);
     void removeSession(const Vector<uint8_t>& sessionId);
-    void removeDrm(sp<DrmSessionClientInterface> drm);
+    void removeDrm(const sp<DrmSessionClientInterface>& drm);
     bool reclaimSession(int callingPid);
 
 protected:
diff --git a/include/media/IAudioPolicyService.h b/include/media/IAudioPolicyService.h
index 0e9e3bc..ef15a0c 100644
--- a/include/media/IAudioPolicyService.h
+++ b/include/media/IAudioPolicyService.h
@@ -160,7 +160,7 @@
 
     virtual audio_mode_t getPhoneState() = 0;
 
-    virtual status_t registerPolicyMixes(Vector<AudioMix> mixes, bool registration) = 0;
+    virtual status_t registerPolicyMixes(const Vector<AudioMix>& mixes, bool registration) = 0;
 
     virtual status_t startAudioSource(const struct audio_port_config *source,
                                       const audio_attributes_t *attributes,
diff --git a/include/media/IMediaSource.h b/include/media/IMediaSource.h
index 2ff42ec..2bde782 100644
--- a/include/media/IMediaSource.h
+++ b/include/media/IMediaSource.h
@@ -98,7 +98,7 @@
         SeekMode mSeekMode;
         int64_t mLatenessUs;
         bool mNonBlocking;
-    };
+    } __attribute__((packed)); // sent through Binder
 
     // Returns a new buffer of data. Call blocks until a
     // buffer is available, an error is encountered or the end of the stream
diff --git a/include/media/RingBuffer.h b/include/media/RingBuffer.h
index df7c00e..4d92d87 100644
--- a/include/media/RingBuffer.h
+++ b/include/media/RingBuffer.h
@@ -39,7 +39,7 @@
     /**
      * Construct a RingBuffer that can grow up to the given length.
      */
-    RingBuffer(size_t length);
+    explicit RingBuffer(size_t length);
 
     /**
      * Forward iterator to this class.  Implements an std:forward_iterator.
diff --git a/include/media/SharedLibrary.h b/include/media/SharedLibrary.h
index 88451a0..fd02203 100644
--- a/include/media/SharedLibrary.h
+++ b/include/media/SharedLibrary.h
@@ -24,7 +24,7 @@
 namespace android {
     class SharedLibrary : public RefBase {
     public:
-        SharedLibrary(const String8 &path);
+        explicit SharedLibrary(const String8 &path);
         ~SharedLibrary();
 
         bool operator!() const;
diff --git a/include/media/mediaplayer.h b/include/media/mediaplayer.h
index cec9d99..389ec01 100644
--- a/include/media/mediaplayer.h
+++ b/include/media/mediaplayer.h
@@ -30,7 +30,7 @@
 #include <utils/KeyedVector.h>
 #include <utils/String8.h>
 
-class ANativeWindow;
+struct ANativeWindow;
 
 namespace android {
 
diff --git a/include/media/stagefright/ACodec.h b/include/media/stagefright/ACodec.h
index 25f7173..7b3e71c 100644
--- a/include/media/stagefright/ACodec.h
+++ b/include/media/stagefright/ACodec.h
@@ -238,6 +238,7 @@
     sp<IdleToLoadedState> mIdleToLoadedState;
     sp<FlushingState> mFlushingState;
     sp<SkipCutBuffer> mSkipCutBuffer;
+    int32_t mSampleRate;
 
     AString mComponentName;
     uint32_t mFlags;
diff --git a/include/media/stagefright/FrameRenderTracker.h b/include/media/stagefright/FrameRenderTracker.h
index 9333e8f..8396657 100644
--- a/include/media/stagefright/FrameRenderTracker.h
+++ b/include/media/stagefright/FrameRenderTracker.h
@@ -32,7 +32,7 @@
 class Fence;
 class GraphicBuffer;
 
-struct FrameRenderTracker : public RefBase {
+struct FrameRenderTracker {
     // Tracks the render information about a frame. Frames go through several states while
     // the render information is tracked:
     //
diff --git a/include/media/stagefright/MediaBuffer.h b/include/media/stagefright/MediaBuffer.h
index a61ddaa..2c0ebe7 100644
--- a/include/media/stagefright/MediaBuffer.h
+++ b/include/media/stagefright/MediaBuffer.h
@@ -56,11 +56,11 @@
     // The underlying data remains the responsibility of the caller!
     MediaBuffer(void *data, size_t size);
 
-    MediaBuffer(size_t size);
+    explicit MediaBuffer(size_t size);
 
-    MediaBuffer(const sp<GraphicBuffer>& graphicBuffer);
+    explicit MediaBuffer(const sp<GraphicBuffer>& graphicBuffer);
 
-    MediaBuffer(const sp<ABuffer> &buffer);
+    explicit MediaBuffer(const sp<ABuffer> &buffer);
 
     MediaBuffer(const sp<IMemory> &mem) :
         MediaBuffer((uint8_t *)mem->pointer() + sizeof(SharedControl), mem->size()) {
diff --git a/include/media/stagefright/MediaCodec.h b/include/media/stagefright/MediaCodec.h
index fe579b7..497974d 100644
--- a/include/media/stagefright/MediaCodec.h
+++ b/include/media/stagefright/MediaCodec.h
@@ -33,7 +33,7 @@
 struct AReplyToken;
 struct AString;
 struct CodecBase;
-struct IBatteryStats;
+class IBatteryStats;
 struct ICrypto;
 class IMemory;
 struct MemoryDealer;
@@ -41,7 +41,7 @@
 class IResourceManagerService;
 struct PersistentSurface;
 struct SoftwareRenderer;
-struct Surface;
+class Surface;
 
 struct MediaCodec : public AHandler {
     enum ConfigureFlags {
@@ -175,7 +175,7 @@
     // by adding rendered frame information to a base notification message. Returns the number
     // of frames that were rendered.
     static size_t CreateFramesRenderedMessage(
-            std::list<FrameRenderTracker::Info> done, sp<AMessage> &msg);
+            const std::list<FrameRenderTracker::Info> &done, sp<AMessage> &msg);
 
 protected:
     virtual ~MediaCodec();
@@ -274,7 +274,7 @@
 
         void addResource(
                 int64_t clientId,
-                const sp<IResourceManagerClient> client,
+                const sp<IResourceManagerClient> &client,
                 const Vector<MediaResource> &resources);
 
         void removeResource(int64_t clientId);
diff --git a/include/media/stagefright/Utils.h b/include/media/stagefright/Utils.h
index 01b3e3f..8eff914 100644
--- a/include/media/stagefright/Utils.h
+++ b/include/media/stagefright/Utils.h
@@ -28,7 +28,7 @@
 namespace android {
 
 #define FOURCC(c1, c2, c3, c4) \
-    (c1 << 24 | c2 << 16 | c3 << 8 | c4)
+    ((c1) << 24 | (c2) << 16 | (c3) << 8 | (c4))
 
 uint16_t U16_AT(const uint8_t *ptr);
 uint32_t U32_AT(const uint8_t *ptr);
@@ -75,7 +75,7 @@
     int64_t mTimeUs;
     sp<AMessage> mMeta;
 
-    HLSTime(const sp<AMessage> &meta = NULL);
+    explicit HLSTime(const sp<AMessage> &meta = NULL);
     int64_t getSegmentTimeUs() const;
 };
 
@@ -83,10 +83,10 @@
 
 // read and write various object to/from AMessage
 
-void writeToAMessage(sp<AMessage> msg, const AudioPlaybackRate &rate);
+void writeToAMessage(const sp<AMessage> &msg, const AudioPlaybackRate &rate);
 void readFromAMessage(const sp<AMessage> &msg, AudioPlaybackRate *rate /* nonnull */);
 
-void writeToAMessage(sp<AMessage> msg, const AVSyncSettings &sync, float videoFpsHint);
+void writeToAMessage(const sp<AMessage> &msg, const AVSyncSettings &sync, float videoFpsHint);
 void readFromAMessage(
         const sp<AMessage> &msg, AVSyncSettings *sync /* nonnull */, float *videoFps /* nonnull */);
 
diff --git a/include/media/stagefright/foundation/ABase.h b/include/media/stagefright/foundation/ABase.h
index ef1e010..76a787e 100644
--- a/include/media/stagefright/foundation/ABase.h
+++ b/include/media/stagefright/foundation/ABase.h
@@ -24,7 +24,7 @@
 
 #define DISALLOW_EVIL_CONSTRUCTORS(name) \
     name(const name &); \
-    name &operator=(const name &)
+    name &operator=(const name &) /* NOLINT */
 
 /* Returns true if the size parameter is safe for new array allocation (32-bit)
  *
diff --git a/include/media/stagefright/foundation/ABuffer.h b/include/media/stagefright/foundation/ABuffer.h
index dc9c778..ef11434 100644
--- a/include/media/stagefright/foundation/ABuffer.h
+++ b/include/media/stagefright/foundation/ABuffer.h
@@ -30,7 +30,7 @@
 class MediaBufferBase;
 
 struct ABuffer : public RefBase {
-    ABuffer(size_t capacity);
+    explicit ABuffer(size_t capacity);
     ABuffer(void *data, size_t capacity);
 
     uint8_t *base() { return (uint8_t *)mData; }
diff --git a/include/media/stagefright/foundation/AHandler.h b/include/media/stagefright/foundation/AHandler.h
index fe02a86..53d8a9b 100644
--- a/include/media/stagefright/foundation/AHandler.h
+++ b/include/media/stagefright/foundation/AHandler.h
@@ -60,7 +60,7 @@
     ALooper::handler_id mID;
     wp<ALooper> mLooper;
 
-    inline void setID(ALooper::handler_id id, wp<ALooper> looper) {
+    inline void setID(ALooper::handler_id id, const wp<ALooper> &looper) {
         mID = id;
         mLooper = looper;
     }
diff --git a/include/media/stagefright/foundation/ALooperRoster.h b/include/media/stagefright/foundation/ALooperRoster.h
index 9912455..5873e68 100644
--- a/include/media/stagefright/foundation/ALooperRoster.h
+++ b/include/media/stagefright/foundation/ALooperRoster.h
@@ -28,7 +28,7 @@
     ALooperRoster();
 
     ALooper::handler_id registerHandler(
-            const sp<ALooper> looper, const sp<AHandler> &handler);
+            const sp<ALooper> &looper, const sp<AHandler> &handler);
 
     void unregisterHandler(ALooper::handler_id handlerID);
     void unregisterStaleHandlers();
diff --git a/include/media/stagefright/foundation/AMessage.h b/include/media/stagefright/foundation/AMessage.h
index 4b2b868..782f8e6 100644
--- a/include/media/stagefright/foundation/AMessage.h
+++ b/include/media/stagefright/foundation/AMessage.h
@@ -31,7 +31,7 @@
 class Parcel;
 
 struct AReplyToken : public RefBase {
-    AReplyToken(const sp<ALooper> &looper)
+    explicit AReplyToken(const sp<ALooper> &looper)
         : mLooper(looper),
           mReplied(false) {
     }
diff --git a/include/media/stagefright/foundation/AString.h b/include/media/stagefright/foundation/AString.h
index 2f6d532..ff086b3 100644
--- a/include/media/stagefright/foundation/AString.h
+++ b/include/media/stagefright/foundation/AString.h
@@ -28,9 +28,9 @@
 
 struct AString {
     AString();
-    AString(const char *s);
+    AString(const char *s);  // NOLINT, implicit conversion
     AString(const char *s, size_t size);
-    AString(const String8 &from);
+    AString(const String8 &from);  // NOLINT, implicit conversion
     AString(const AString &from);
     AString(const AString &from, size_t offset, size_t n);
     ~AString();
diff --git a/include/media/stagefright/foundation/AWakeLock.h b/include/media/stagefright/foundation/AWakeLock.h
index 57716c1..323e7d7 100644
--- a/include/media/stagefright/foundation/AWakeLock.h
+++ b/include/media/stagefright/foundation/AWakeLock.h
@@ -43,7 +43,7 @@
 
     class PMDeathRecipient : public IBinder::DeathRecipient {
     public:
-        PMDeathRecipient(AWakeLock *wakeLock) : mWakeLock(wakeLock) {}
+        explicit PMDeathRecipient(AWakeLock *wakeLock) : mWakeLock(wakeLock) {}
         virtual ~PMDeathRecipient() {}
 
         // IBinder::DeathRecipient
diff --git a/include/ndk/NdkImage.h b/include/ndk/NdkImage.h
index cd0b11e..9a99287 100644
--- a/include/ndk/NdkImage.h
+++ b/include/ndk/NdkImage.h
@@ -36,12 +36,16 @@
 #ifndef _NDK_IMAGE_H
 #define _NDK_IMAGE_H
 
+#include <sys/cdefs.h>
+
 #include "NdkMediaError.h"
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
+#if __ANDROID_API__ >= 24
+
 /**
  * AImage is an opaque type that provides access to image generated by {@link AImageReader}.
  */
@@ -604,6 +608,8 @@
         const AImage* image, int planeIdx,
         /*out*/uint8_t** data, /*out*/int* dataLength);
 
+#endif /* __ANDROID_API__ >= 24 */
+
 #ifdef __cplusplus
 } // extern "C"
 #endif
diff --git a/include/ndk/NdkImageReader.h b/include/ndk/NdkImageReader.h
index 7c7ec6a..8d72c28 100644
--- a/include/ndk/NdkImageReader.h
+++ b/include/ndk/NdkImageReader.h
@@ -36,6 +36,8 @@
 #ifndef _NDK_IMAGE_READER_H
 #define _NDK_IMAGE_READER_H
 
+#include <sys/cdefs.h>
+
 #include <android/native_window.h>
 #include "NdkMediaError.h"
 #include "NdkImage.h"
@@ -44,6 +46,8 @@
 extern "C" {
 #endif
 
+#if __ANDROID_API__ >= 24
+
 /**
  * AImage is an opaque type that allows direct application access to image data rendered into a
  * {@link ANativeWindow}.
@@ -294,6 +298,8 @@
 media_status_t AImageReader_setImageListener(
         AImageReader* reader, AImageReader_ImageListener* listener);
 
+#endif /* __ANDROID_API__ >= 24 */
+
 #ifdef __cplusplus
 } // extern "C"
 #endif
diff --git a/include/ndk/NdkMediaCodec.h b/include/ndk/NdkMediaCodec.h
index fcb3a99..ad17321 100644
--- a/include/ndk/NdkMediaCodec.h
+++ b/include/ndk/NdkMediaCodec.h
@@ -27,6 +27,8 @@
 #ifndef _NDK_MEDIA_CODEC_H
 #define _NDK_MEDIA_CODEC_H
 
+#include <sys/cdefs.h>
+
 #include <android/native_window.h>
 
 #include "NdkMediaCrypto.h"
@@ -37,6 +39,7 @@
 extern "C" {
 #endif
 
+#if __ANDROID_API__ >= 21
 
 struct AMediaCodec;
 typedef struct AMediaCodec AMediaCodec;
@@ -254,6 +257,8 @@
  */
 media_status_t AMediaCodecCryptoInfo_getEncryptedBytes(AMediaCodecCryptoInfo*, size_t *dst);
 
+#endif /* __ANDROID_API__ >= 21 */
+
 #ifdef __cplusplus
 } // extern "C"
 #endif
diff --git a/include/ndk/NdkMediaCrypto.h b/include/ndk/NdkMediaCrypto.h
index 90374c5..9236765 100644
--- a/include/ndk/NdkMediaCrypto.h
+++ b/include/ndk/NdkMediaCrypto.h
@@ -28,6 +28,7 @@
 #ifndef _NDK_MEDIA_CRYPTO_H
 #define _NDK_MEDIA_CRYPTO_H
 
+#include <sys/cdefs.h>
 #include <sys/types.h>
 #include <stdbool.h>
 
@@ -35,6 +36,8 @@
 extern "C" {
 #endif
 
+#if __ANDROID_API__ >= 21
+
 struct AMediaCrypto;
 typedef struct AMediaCrypto AMediaCrypto;
 
@@ -48,6 +51,7 @@
 
 void AMediaCrypto_delete(AMediaCrypto* crypto);
 
+#endif /* __ANDROID_API__ >= 21 */
 
 #ifdef __cplusplus
 } // extern "C"
diff --git a/include/ndk/NdkMediaDrm.h b/include/ndk/NdkMediaDrm.h
index 3c312a9..9dd6283 100644
--- a/include/ndk/NdkMediaDrm.h
+++ b/include/ndk/NdkMediaDrm.h
@@ -27,14 +27,17 @@
 #ifndef _NDK_MEDIA_DRM_H
 #define _NDK_MEDIA_DRM_H
 
+#include <stdbool.h>
+#include <stdint.h>
+#include <sys/cdefs.h>
+
 #include "NdkMediaError.h"
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-#include <stdint.h>
-#include <stdbool.h>
+#if __ANDROID_API__ >= 21
 
 struct AMediaDrm;
 typedef struct AMediaDrm AMediaDrm;
@@ -448,6 +451,8 @@
         const char *macAlgorithm, uint8_t *keyId, const uint8_t *message, size_t messageSize,
         const uint8_t *signature, size_t signatureSize);
 
+#endif /* __ANDROID_API__ >= 21 */
+
 #ifdef __cplusplus
 } // extern "C"
 #endif
diff --git a/include/ndk/NdkMediaError.h b/include/ndk/NdkMediaError.h
index 60d401b..fb00b1d 100644
--- a/include/ndk/NdkMediaError.h
+++ b/include/ndk/NdkMediaError.h
@@ -28,10 +28,14 @@
 #ifndef _NDK_MEDIA_ERROR_H
 #define _NDK_MEDIA_ERROR_H
 
+#include <sys/cdefs.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif
 
+#if __ANDROID_API__ >= 21
+
 typedef enum {
     AMEDIA_OK = 0,
 
@@ -59,6 +63,7 @@
 
 } media_status_t;
 
+#endif /* __ANDROID_API__ >= 21 */
 
 #ifdef __cplusplus
 } // extern "C"
diff --git a/include/ndk/NdkMediaExtractor.h b/include/ndk/NdkMediaExtractor.h
index 7324d31..c3180dc 100644
--- a/include/ndk/NdkMediaExtractor.h
+++ b/include/ndk/NdkMediaExtractor.h
@@ -28,6 +28,7 @@
 #ifndef _NDK_MEDIA_EXTRACTOR_H
 #define _NDK_MEDIA_EXTRACTOR_H
 
+#include <sys/cdefs.h>
 #include <sys/types.h>
 
 #include "NdkMediaCodec.h"
@@ -38,6 +39,8 @@
 extern "C" {
 #endif
 
+#if __ANDROID_API__ >= 21
+
 struct AMediaExtractor;
 typedef struct AMediaExtractor AMediaExtractor;
 
@@ -158,6 +161,8 @@
     AMEDIAEXTRACTOR_SAMPLE_FLAG_ENCRYPTED = 2,
 };
 
+#endif /* __ANDROID_API__ >= 21 */
+
 #ifdef __cplusplus
 } // extern "C"
 #endif
diff --git a/include/ndk/NdkMediaFormat.h b/include/ndk/NdkMediaFormat.h
index ab29791..a2a21d2 100644
--- a/include/ndk/NdkMediaFormat.h
+++ b/include/ndk/NdkMediaFormat.h
@@ -27,6 +27,7 @@
 #ifndef _NDK_MEDIA_FORMAT_H
 #define _NDK_MEDIA_FORMAT_H
 
+#include <sys/cdefs.h>
 #include <sys/types.h>
 
 #include "NdkMediaError.h"
@@ -35,6 +36,8 @@
 extern "C" {
 #endif
 
+#if __ANDROID_API__ >= 21
+
 struct AMediaFormat;
 typedef struct AMediaFormat AMediaFormat;
 
@@ -104,6 +107,8 @@
 extern const char* AMEDIAFORMAT_KEY_WIDTH;
 extern const char* AMEDIAFORMAT_KEY_STRIDE;
 
+#endif /* __ANDROID_API__ >= 21 */
+
 #ifdef __cplusplus
 } // extern "C"
 #endif
diff --git a/include/ndk/NdkMediaMuxer.h b/include/ndk/NdkMediaMuxer.h
index 90d946c..25987a2 100644
--- a/include/ndk/NdkMediaMuxer.h
+++ b/include/ndk/NdkMediaMuxer.h
@@ -28,6 +28,7 @@
 #ifndef _NDK_MEDIA_MUXER_H
 #define _NDK_MEDIA_MUXER_H
 
+#include <sys/cdefs.h>
 #include <sys/types.h>
 
 #include "NdkMediaCodec.h"
@@ -38,6 +39,8 @@
 extern "C" {
 #endif
 
+#if __ANDROID_API__ >= 21
+
 struct AMediaMuxer;
 typedef struct AMediaMuxer AMediaMuxer;
 
@@ -112,6 +115,8 @@
 media_status_t AMediaMuxer_writeSampleData(AMediaMuxer *muxer,
         size_t trackIdx, const uint8_t *data, const AMediaCodecBufferInfo *info);
 
+#endif /* __ANDROID_API__ >= 21 */
+
 #ifdef __cplusplus
 } // extern "C"
 #endif
diff --git a/media/common_time/ICommonClock.cpp b/media/common_time/ICommonClock.cpp
index 19b7d6e..f1f1fca 100644
--- a/media/common_time/ICommonClock.cpp
+++ b/media/common_time/ICommonClock.cpp
@@ -48,7 +48,7 @@
 class BpCommonClock : public BpInterface<ICommonClock>
 {
   public:
-    BpCommonClock(const sp<IBinder>& impl)
+    explicit BpCommonClock(const sp<IBinder>& impl)
         : BpInterface<ICommonClock>(impl) {}
 
     virtual status_t isCommonTimeValid(bool* valid, uint32_t* timelineID) {
@@ -401,7 +401,7 @@
 class BpCommonClockListener : public BpInterface<ICommonClockListener>
 {
   public:
-    BpCommonClockListener(const sp<IBinder>& impl)
+    explicit BpCommonClockListener(const sp<IBinder>& impl)
         : BpInterface<ICommonClockListener>(impl) {}
 
     virtual void onTimelineChanged(uint64_t timelineID) {
diff --git a/media/common_time/ICommonTimeConfig.cpp b/media/common_time/ICommonTimeConfig.cpp
index 67167b0..e587b39 100644
--- a/media/common_time/ICommonTimeConfig.cpp
+++ b/media/common_time/ICommonTimeConfig.cpp
@@ -50,7 +50,7 @@
 class BpCommonTimeConfig : public BpInterface<ICommonTimeConfig>
 {
   public:
-    BpCommonTimeConfig(const sp<IBinder>& impl)
+    explicit BpCommonTimeConfig(const sp<IBinder>& impl)
         : BpInterface<ICommonTimeConfig>(impl) {}
 
     virtual status_t getMasterElectionPriority(uint8_t *priority) {
diff --git a/media/common_time/cc_helper.cpp b/media/common_time/cc_helper.cpp
index 222b7ce..6a7de74 100644
--- a/media/common_time/cc_helper.cpp
+++ b/media/common_time/cc_helper.cpp
@@ -80,7 +80,7 @@
     }
 }
 
-void CCHelper::CommonClockListener::onTimelineChanged(uint64_t timelineID __unused) {
+void CCHelper::CommonClockListener::onTimelineChanged(uint64_t /*timelineID*/) {
     // do nothing; listener is only really used as a token so the server can
     // find out when clients die.
 }
diff --git a/media/img_utils/include/img_utils/EndianUtils.h b/media/img_utils/include/img_utils/EndianUtils.h
index e99be1a..bfa42e9 100644
--- a/media/img_utils/include/img_utils/EndianUtils.h
+++ b/media/img_utils/include/img_utils/EndianUtils.h
@@ -58,7 +58,7 @@
          * Wrap the given Output.  Calling write methods will result in
          * writes to this output.
          */
-        EndianOutput(Output* out, Endianness end=LITTLE);
+        explicit EndianOutput(Output* out, Endianness end=LITTLE);
 
         virtual ~EndianOutput();
 
diff --git a/media/img_utils/include/img_utils/FileInput.h b/media/img_utils/include/img_utils/FileInput.h
index 4d4f22b..66afaff 100644
--- a/media/img_utils/include/img_utils/FileInput.h
+++ b/media/img_utils/include/img_utils/FileInput.h
@@ -36,7 +36,7 @@
         /**
          * Create a file input for the given path.
          */
-        FileInput(String8 path);
+        explicit FileInput(String8 path);
 
         virtual ~FileInput();
 
diff --git a/media/img_utils/include/img_utils/FileOutput.h b/media/img_utils/include/img_utils/FileOutput.h
index fd5be27..3d4cf76 100644
--- a/media/img_utils/include/img_utils/FileOutput.h
+++ b/media/img_utils/include/img_utils/FileOutput.h
@@ -29,7 +29,7 @@
 
 class ANDROID_API FileOutput : public Output {
     public:
-        FileOutput(String8 path);
+        explicit FileOutput(String8 path);
         virtual ~FileOutput();
         virtual status_t open();
         virtual status_t write(const uint8_t* buf, size_t offset, size_t count);
diff --git a/media/img_utils/include/img_utils/TiffHelpers.h b/media/img_utils/include/img_utils/TiffHelpers.h
index 0969e4d..3e5f863 100644
--- a/media/img_utils/include/img_utils/TiffHelpers.h
+++ b/media/img_utils/include/img_utils/TiffHelpers.h
@@ -25,7 +25,7 @@
 const uint8_t ZERO_WORD[] = {0, 0, 0, 0};
 
 #define BAIL_ON_FAIL(x, flag) \
-    if ((flag = (x)) != OK) return flag;
+    if (((flag) = (x)) != OK) return flag;
 
 #define BYTES_TILL_WORD(index) \
     ((TIFF_WORD_SIZE - ((index) % TIFF_WORD_SIZE)) % TIFF_WORD_SIZE)
diff --git a/media/img_utils/include/img_utils/TiffIfd.h b/media/img_utils/include/img_utils/TiffIfd.h
index 51b5c9a..2d8e91f 100644
--- a/media/img_utils/include/img_utils/TiffIfd.h
+++ b/media/img_utils/include/img_utils/TiffIfd.h
@@ -42,7 +42,7 @@
  */
 class ANDROID_API TiffIfd : public TiffWritable {
     public:
-        TiffIfd(uint32_t ifdId);
+        explicit TiffIfd(uint32_t ifdId);
         virtual ~TiffIfd();
 
         /**
diff --git a/media/img_utils/src/Android.mk b/media/img_utils/src/Android.mk
index 4074849..c1f64ca 100644
--- a/media/img_utils/src/Android.mk
+++ b/media/img_utils/src/Android.mk
@@ -34,6 +34,7 @@
   StripSource.cpp \
 
 LOCAL_SHARED_LIBRARIES := \
+  liblog \
   libexpat \
   libutils \
   libcutils \
diff --git a/media/img_utils/src/TiffWriter.cpp b/media/img_utils/src/TiffWriter.cpp
index a6f9218..564474f 100644
--- a/media/img_utils/src/TiffWriter.cpp
+++ b/media/img_utils/src/TiffWriter.cpp
@@ -40,7 +40,7 @@
 }
 
 #define ARRAY_SIZE(array) \
-    (sizeof(array) / sizeof(array[0]))
+    (sizeof(array) / sizeof((array)[0]))
 
 KeyedVector<uint16_t, const TagDefinition_t*> TiffWriter::sTagMaps[] = {
     buildTagMap(TIFF_EP_TAG_DEFINITIONS, ARRAY_SIZE(TIFF_EP_TAG_DEFINITIONS)),
diff --git a/media/libcpustats/Android.mk b/media/libcpustats/Android.mk
index 57fe527..b2d73ee 100644
--- a/media/libcpustats/Android.mk
+++ b/media/libcpustats/Android.mk
@@ -8,6 +8,6 @@
 
 LOCAL_MODULE := libcpustats
 
-LOCAL_CFLAGS := -std=gnu++11 -Werror -Wall
+LOCAL_CFLAGS := -Werror -Wall
 
 include $(BUILD_STATIC_LIBRARY)
diff --git a/media/libeffects/Android.bp b/media/libeffects/Android.bp
new file mode 100644
index 0000000..ccaa2b4
--- /dev/null
+++ b/media/libeffects/Android.bp
@@ -0,0 +1 @@
+subdirs = ["factory"]
diff --git a/media/libeffects/factory/Android.bp b/media/libeffects/factory/Android.bp
new file mode 100644
index 0000000..0d8b6eb
--- /dev/null
+++ b/media/libeffects/factory/Android.bp
@@ -0,0 +1,13 @@
+// Effect factory library
+cc_library_shared {
+    name: "libeffects",
+    srcs: ["EffectsFactory.c"],
+
+    shared_libs: [
+        "libcutils",
+        "liblog",
+        "libdl",
+    ],
+
+    include_dirs: ["system/media/audio_effects/include"],
+}
diff --git a/media/libeffects/factory/Android.mk b/media/libeffects/factory/Android.mk
deleted file mode 100644
index a932af7..0000000
--- a/media/libeffects/factory/Android.mk
+++ /dev/null
@@ -1,19 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-
-# Effect factory library
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES:= \
-	EffectsFactory.c
-
-LOCAL_SHARED_LIBRARIES := \
-	libcutils liblog
-
-LOCAL_MODULE:= libeffects
-
-LOCAL_SHARED_LIBRARIES += libdl
-
-LOCAL_C_INCLUDES := \
-    $(call include-path-for, audio-effects)
-
-include $(BUILD_SHARED_LIBRARY)
diff --git a/media/libeffects/lvm/lib/Bass/src/LVDBE_Coeffs.h b/media/libeffects/lvm/lib/Bass/src/LVDBE_Coeffs.h
index 94a7869..b1ebadf 100644
--- a/media/libeffects/lvm/lib/Bass/src/LVDBE_Coeffs.h
+++ b/media/libeffects/lvm/lib/Bass/src/LVDBE_Coeffs.h
@@ -36,190 +36,190 @@
 
  /* Coefficients for centre frequency 55Hz */
 #define HPF_Fs8000_Fc55_A0                         1029556328         /* Floating point value 0.958849 */
-#define HPF_Fs8000_Fc55_A1                        -2059112655         /* Floating point value -1.917698 */
+#define HPF_Fs8000_Fc55_A1                       (-2059112655)        /* Floating point value -1.917698 */
 #define HPF_Fs8000_Fc55_A2                         1029556328         /* Floating point value 0.958849 */
-#define HPF_Fs8000_Fc55_B1                        -2081986375         /* Floating point value -1.939001 */
+#define HPF_Fs8000_Fc55_B1                       (-2081986375)        /* Floating point value -1.939001 */
 #define HPF_Fs8000_Fc55_B2                         1010183914         /* Floating point value 0.940807 */
 #define HPF_Fs11025_Fc55_A0                        1038210831         /* Floating point value 0.966909 */
-#define HPF_Fs11025_Fc55_A1                       -2076421662         /* Floating point value -1.933818 */
+#define HPF_Fs11025_Fc55_A1                      (-2076421662)        /* Floating point value -1.933818 */
 #define HPF_Fs11025_Fc55_A2                        1038210831         /* Floating point value 0.966909 */
-#define HPF_Fs11025_Fc55_B1                       -2099950710         /* Floating point value -1.955732 */
+#define HPF_Fs11025_Fc55_B1                      (-2099950710)        /* Floating point value -1.955732 */
 #define HPF_Fs11025_Fc55_B2                        1027238450         /* Floating point value 0.956690 */
 #define HPF_Fs12000_Fc55_A0                        1040079943         /* Floating point value 0.968650 */
-#define HPF_Fs12000_Fc55_A1                       -2080159885         /* Floating point value -1.937300 */
+#define HPF_Fs12000_Fc55_A1                      (-2080159885)        /* Floating point value -1.937300 */
 #define HPF_Fs12000_Fc55_A2                        1040079943         /* Floating point value 0.968650 */
-#define HPF_Fs12000_Fc55_B1                       -2103811702         /* Floating point value -1.959327 */
+#define HPF_Fs12000_Fc55_B1                      (-2103811702)        /* Floating point value -1.959327 */
 #define HPF_Fs12000_Fc55_B2                        1030940477         /* Floating point value 0.960138 */
 #define HPF_Fs16000_Fc55_A0                        1045381988         /* Floating point value 0.973588 */
-#define HPF_Fs16000_Fc55_A1                       -2090763976         /* Floating point value -1.947176 */
+#define HPF_Fs16000_Fc55_A1                      (-2090763976)        /* Floating point value -1.947176 */
 #define HPF_Fs16000_Fc55_A2                        1045381988         /* Floating point value 0.973588 */
-#define HPF_Fs16000_Fc55_B1                       -2114727793         /* Floating point value -1.969494 */
+#define HPF_Fs16000_Fc55_B1                      (-2114727793)        /* Floating point value -1.969494 */
 #define HPF_Fs16000_Fc55_B2                        1041478147         /* Floating point value 0.969952 */
 #define HPF_Fs22050_Fc55_A0                        1049766523         /* Floating point value 0.977671 */
-#define HPF_Fs22050_Fc55_A1                       -2099533046         /* Floating point value -1.955343 */
+#define HPF_Fs22050_Fc55_A1                      (-2099533046)        /* Floating point value -1.955343 */
 #define HPF_Fs22050_Fc55_A2                        1049766523         /* Floating point value 0.977671 */
-#define HPF_Fs22050_Fc55_B1                       -2123714381         /* Floating point value -1.977863 */
+#define HPF_Fs22050_Fc55_B1                      (-2123714381)        /* Floating point value -1.977863 */
 #define HPF_Fs22050_Fc55_B2                        1050232780         /* Floating point value 0.978105 */
 #define HPF_Fs24000_Fc55_A0                        1050711051         /* Floating point value 0.978551 */
-#define HPF_Fs24000_Fc55_A1                       -2101422103         /* Floating point value -1.957102 */
+#define HPF_Fs24000_Fc55_A1                      (-2101422103)        /* Floating point value -1.957102 */
 #define HPF_Fs24000_Fc55_A2                        1050711051         /* Floating point value 0.978551 */
-#define HPF_Fs24000_Fc55_B1                       -2125645498         /* Floating point value -1.979662 */
+#define HPF_Fs24000_Fc55_B1                      (-2125645498)        /* Floating point value -1.979662 */
 #define HPF_Fs24000_Fc55_B2                        1052123526         /* Floating point value 0.979866 */
 #define HPF_Fs32000_Fc55_A0                        1053385759         /* Floating point value 0.981042 */
-#define HPF_Fs32000_Fc55_A1                       -2106771519         /* Floating point value -1.962084 */
+#define HPF_Fs32000_Fc55_A1                      (-2106771519)        /* Floating point value -1.962084 */
 #define HPF_Fs32000_Fc55_A2                        1053385759         /* Floating point value 0.981042 */
-#define HPF_Fs32000_Fc55_B1                       -2131104794         /* Floating point value -1.984746 */
+#define HPF_Fs32000_Fc55_B1                      (-2131104794)        /* Floating point value -1.984746 */
 #define HPF_Fs32000_Fc55_B2                        1057486949         /* Floating point value 0.984861 */
 #define HPF_Fs44100_Fc55_A0                        1055592498         /* Floating point value 0.983097 */
-#define HPF_Fs44100_Fc55_A1                       -2111184995         /* Floating point value -1.966194 */
+#define HPF_Fs44100_Fc55_A1                      (-2111184995)        /* Floating point value -1.966194 */
 #define HPF_Fs44100_Fc55_A2                        1055592498         /* Floating point value 0.983097 */
-#define HPF_Fs44100_Fc55_B1                       -2135598658         /* Floating point value -1.988931 */
+#define HPF_Fs44100_Fc55_B1                      (-2135598658)        /* Floating point value -1.988931 */
 #define HPF_Fs44100_Fc55_B2                        1061922249         /* Floating point value 0.988992 */
 #define HPF_Fs48000_Fc55_A0                        1056067276         /* Floating point value 0.983539 */
-#define HPF_Fs48000_Fc55_A1                       -2112134551         /* Floating point value -1.967079 */
+#define HPF_Fs48000_Fc55_A1                      (-2112134551)        /* Floating point value -1.967079 */
 #define HPF_Fs48000_Fc55_A2                        1056067276         /* Floating point value 0.983539 */
-#define HPF_Fs48000_Fc55_B1                       -2136564296         /* Floating point value -1.989831 */
+#define HPF_Fs48000_Fc55_B1                      (-2136564296)        /* Floating point value -1.989831 */
 #define HPF_Fs48000_Fc55_B2                        1062877714         /* Floating point value 0.989882 */
 
  /* Coefficients for centre frequency 66Hz */
 #define HPF_Fs8000_Fc66_A0                         1023293271         /* Floating point value 0.953016 */
-#define HPF_Fs8000_Fc66_A1                        -2046586542         /* Floating point value -1.906032 */
+#define HPF_Fs8000_Fc66_A1                       (-2046586542)        /* Floating point value -1.906032 */
 #define HPF_Fs8000_Fc66_A2                         1023293271         /* Floating point value 0.953016 */
-#define HPF_Fs8000_Fc66_B1                        -2068896860         /* Floating point value -1.926810 */
+#define HPF_Fs8000_Fc66_B1                       (-2068896860)        /* Floating point value -1.926810 */
 #define HPF_Fs8000_Fc66_B2                          997931110         /* Floating point value 0.929396 */
 #define HPF_Fs11025_Fc66_A0                        1033624228         /* Floating point value 0.962638 */
-#define HPF_Fs11025_Fc66_A1                       -2067248455         /* Floating point value -1.925275 */
+#define HPF_Fs11025_Fc66_A1                      (-2067248455)        /* Floating point value -1.925275 */
 #define HPF_Fs11025_Fc66_A2                        1033624228         /* Floating point value 0.962638 */
-#define HPF_Fs11025_Fc66_B1                       -2090448000         /* Floating point value -1.946881 */
+#define HPF_Fs11025_Fc66_B1                      (-2090448000)        /* Floating point value -1.946881 */
 #define HPF_Fs11025_Fc66_B2                        1018182305         /* Floating point value 0.948256 */
 #define HPF_Fs12000_Fc66_A0                        1035857662         /* Floating point value 0.964718 */
-#define HPF_Fs12000_Fc66_A1                       -2071715325         /* Floating point value -1.929435 */
+#define HPF_Fs12000_Fc66_A1                      (-2071715325)        /* Floating point value -1.929435 */
 #define HPF_Fs12000_Fc66_A2                        1035857662         /* Floating point value 0.964718 */
-#define HPF_Fs12000_Fc66_B1                       -2095080333         /* Floating point value -1.951196 */
+#define HPF_Fs12000_Fc66_B1                      (-2095080333)        /* Floating point value -1.951196 */
 #define HPF_Fs12000_Fc66_B2                        1022587158         /* Floating point value 0.952359 */
 #define HPF_Fs16000_Fc66_A0                        1042197528         /* Floating point value 0.970622 */
-#define HPF_Fs16000_Fc66_A1                       -2084395056         /* Floating point value -1.941244 */
+#define HPF_Fs16000_Fc66_A1                      (-2084395056)        /* Floating point value -1.941244 */
 #define HPF_Fs16000_Fc66_A2                        1042197528         /* Floating point value 0.970622 */
-#define HPF_Fs16000_Fc66_B1                       -2108177912         /* Floating point value -1.963394 */
+#define HPF_Fs16000_Fc66_B1                      (-2108177912)        /* Floating point value -1.963394 */
 #define HPF_Fs16000_Fc66_B2                        1035142690         /* Floating point value 0.964052 */
 #define HPF_Fs22050_Fc66_A0                        1047445145         /* Floating point value 0.975509 */
-#define HPF_Fs22050_Fc66_A1                       -2094890289         /* Floating point value -1.951019 */
+#define HPF_Fs22050_Fc66_A1                      (-2094890289)        /* Floating point value -1.951019 */
 #define HPF_Fs22050_Fc66_A2                        1047445145         /* Floating point value 0.975509 */
-#define HPF_Fs22050_Fc66_B1                       -2118961025         /* Floating point value -1.973436 */
+#define HPF_Fs22050_Fc66_B1                      (-2118961025)        /* Floating point value -1.973436 */
 #define HPF_Fs22050_Fc66_B2                        1045593102         /* Floating point value 0.973784 */
 #define HPF_Fs24000_Fc66_A0                        1048576175         /* Floating point value 0.976563 */
-#define HPF_Fs24000_Fc66_A1                       -2097152349         /* Floating point value -1.953125 */
+#define HPF_Fs24000_Fc66_A1                      (-2097152349)        /* Floating point value -1.953125 */
 #define HPF_Fs24000_Fc66_A2                        1048576175         /* Floating point value 0.976563 */
-#define HPF_Fs24000_Fc66_B1                       -2121278255         /* Floating point value -1.975594 */
+#define HPF_Fs24000_Fc66_B1                      (-2121278255)        /* Floating point value -1.975594 */
 #define HPF_Fs24000_Fc66_B2                        1047852379         /* Floating point value 0.975889 */
 #define HPF_Fs32000_Fc66_A0                        1051780119         /* Floating point value 0.979547 */
-#define HPF_Fs32000_Fc66_A1                       -2103560237         /* Floating point value -1.959093 */
+#define HPF_Fs32000_Fc66_A1                      (-2103560237)        /* Floating point value -1.959093 */
 #define HPF_Fs32000_Fc66_A2                        1051780119         /* Floating point value 0.979547 */
-#define HPF_Fs32000_Fc66_B1                       -2127829187         /* Floating point value -1.981695 */
+#define HPF_Fs32000_Fc66_B1                      (-2127829187)        /* Floating point value -1.981695 */
 #define HPF_Fs32000_Fc66_B2                        1054265623         /* Floating point value 0.981861 */
 #define HPF_Fs44100_Fc66_A0                        1054424722         /* Floating point value 0.982010 */
-#define HPF_Fs44100_Fc66_A1                       -2108849444         /* Floating point value -1.964019 */
+#define HPF_Fs44100_Fc66_A1                      (-2108849444)        /* Floating point value -1.964019 */
 #define HPF_Fs44100_Fc66_A2                        1054424722         /* Floating point value 0.982010 */
-#define HPF_Fs44100_Fc66_B1                       -2133221723         /* Floating point value -1.986718 */
+#define HPF_Fs44100_Fc66_B1                      (-2133221723)        /* Floating point value -1.986718 */
 #define HPF_Fs44100_Fc66_B2                        1059573993         /* Floating point value 0.986805 */
 #define HPF_Fs48000_Fc66_A0                        1054993851         /* Floating point value 0.982540 */
-#define HPF_Fs48000_Fc66_A1                       -2109987702         /* Floating point value -1.965079 */
+#define HPF_Fs48000_Fc66_A1                      (-2109987702)        /* Floating point value -1.965079 */
 #define HPF_Fs48000_Fc66_A2                        1054993851         /* Floating point value 0.982540 */
-#define HPF_Fs48000_Fc66_B1                       -2134380475         /* Floating point value -1.987797 */
+#define HPF_Fs48000_Fc66_B1                      (-2134380475)        /* Floating point value -1.987797 */
 #define HPF_Fs48000_Fc66_B2                        1060718118         /* Floating point value 0.987871 */
 
  /* Coefficients for centre frequency 78Hz */
 #define HPF_Fs8000_Fc78_A0                         1016504203         /* Floating point value 0.946693 */
-#define HPF_Fs8000_Fc78_A1                        -2033008405         /* Floating point value -1.893387 */
+#define HPF_Fs8000_Fc78_A1                       (-2033008405)        /* Floating point value -1.893387 */
 #define HPF_Fs8000_Fc78_A2                         1016504203         /* Floating point value 0.946693 */
-#define HPF_Fs8000_Fc78_B1                        -2054623390         /* Floating point value -1.913517 */
+#define HPF_Fs8000_Fc78_B1                       (-2054623390)        /* Floating point value -1.913517 */
 #define HPF_Fs8000_Fc78_B2                          984733853         /* Floating point value 0.917105 */
 #define HPF_Fs11025_Fc78_A0                        1028643741         /* Floating point value 0.957999 */
-#define HPF_Fs11025_Fc78_A1                       -2057287482         /* Floating point value -1.915998 */
+#define HPF_Fs11025_Fc78_A1                      (-2057287482)        /* Floating point value -1.915998 */
 #define HPF_Fs11025_Fc78_A2                        1028643741         /* Floating point value 0.957999 */
-#define HPF_Fs11025_Fc78_B1                       -2080083769         /* Floating point value -1.937229 */
+#define HPF_Fs11025_Fc78_B1                      (-2080083769)        /* Floating point value -1.937229 */
 #define HPF_Fs11025_Fc78_B2                        1008393904         /* Floating point value 0.939140 */
 #define HPF_Fs12000_Fc78_A0                        1031271067         /* Floating point value 0.960446 */
-#define HPF_Fs12000_Fc78_A1                       -2062542133         /* Floating point value -1.920892 */
+#define HPF_Fs12000_Fc78_A1                      (-2062542133)        /* Floating point value -1.920892 */
 #define HPF_Fs12000_Fc78_A2                        1031271067         /* Floating point value 0.960446 */
-#define HPF_Fs12000_Fc78_B1                       -2085557048         /* Floating point value -1.942326 */
+#define HPF_Fs12000_Fc78_B1                      (-2085557048)        /* Floating point value -1.942326 */
 #define HPF_Fs12000_Fc78_B2                        1013551620         /* Floating point value 0.943944 */
 #define HPF_Fs16000_Fc78_A0                        1038734628         /* Floating point value 0.967397 */
-#define HPF_Fs16000_Fc78_A1                       -2077469256         /* Floating point value -1.934794 */
+#define HPF_Fs16000_Fc78_A1                      (-2077469256)        /* Floating point value -1.934794 */
 #define HPF_Fs16000_Fc78_A2                        1038734628         /* Floating point value 0.967397 */
-#define HPF_Fs16000_Fc78_B1                       -2101033380         /* Floating point value -1.956740 */
+#define HPF_Fs16000_Fc78_B1                      (-2101033380)        /* Floating point value -1.956740 */
 #define HPF_Fs16000_Fc78_B2                        1028275228         /* Floating point value 0.957656 */
 #define HPF_Fs22050_Fc78_A0                        1044918584         /* Floating point value 0.973156 */
-#define HPF_Fs22050_Fc78_A1                       -2089837169         /* Floating point value -1.946313 */
+#define HPF_Fs22050_Fc78_A1                      (-2089837169)        /* Floating point value -1.946313 */
 #define HPF_Fs22050_Fc78_A2                        1044918584         /* Floating point value 0.973156 */
-#define HPF_Fs22050_Fc78_B1                       -2113775854         /* Floating point value -1.968607 */
+#define HPF_Fs22050_Fc78_B1                      (-2113775854)        /* Floating point value -1.968607 */
 #define HPF_Fs22050_Fc78_B2                        1040555007         /* Floating point value 0.969092 */
 #define HPF_Fs24000_Fc78_A0                        1046252164         /* Floating point value 0.974398 */
-#define HPF_Fs24000_Fc78_A1                       -2092504328         /* Floating point value -1.948797 */
+#define HPF_Fs24000_Fc78_A1                      (-2092504328)        /* Floating point value -1.948797 */
 #define HPF_Fs24000_Fc78_A2                        1046252164         /* Floating point value 0.974398 */
-#define HPF_Fs24000_Fc78_B1                       -2116514229         /* Floating point value -1.971157 */
+#define HPF_Fs24000_Fc78_B1                      (-2116514229)        /* Floating point value -1.971157 */
 #define HPF_Fs24000_Fc78_B2                        1043212719         /* Floating point value 0.971568 */
 #define HPF_Fs32000_Fc78_A0                        1050031301         /* Floating point value 0.977918 */
-#define HPF_Fs32000_Fc78_A1                       -2100062603         /* Floating point value -1.955836 */
+#define HPF_Fs32000_Fc78_A1                      (-2100062603)        /* Floating point value -1.955836 */
 #define HPF_Fs32000_Fc78_A2                        1050031301         /* Floating point value 0.977918 */
-#define HPF_Fs32000_Fc78_B1                       -2124255900         /* Floating point value -1.978367 */
+#define HPF_Fs32000_Fc78_B1                      (-2124255900)        /* Floating point value -1.978367 */
 #define HPF_Fs32000_Fc78_B2                        1050762639         /* Floating point value 0.978599 */
 #define HPF_Fs44100_Fc78_A0                        1053152258         /* Floating point value 0.980824 */
-#define HPF_Fs44100_Fc78_A1                       -2106304516         /* Floating point value -1.961649 */
+#define HPF_Fs44100_Fc78_A1                      (-2106304516)        /* Floating point value -1.961649 */
 #define HPF_Fs44100_Fc78_A2                        1053152258         /* Floating point value 0.980824 */
-#define HPF_Fs44100_Fc78_B1                       -2130628742         /* Floating point value -1.984303 */
+#define HPF_Fs44100_Fc78_B1                      (-2130628742)        /* Floating point value -1.984303 */
 #define HPF_Fs44100_Fc78_B2                        1057018180         /* Floating point value 0.984425 */
 #define HPF_Fs48000_Fc78_A0                        1053824087         /* Floating point value 0.981450 */
-#define HPF_Fs48000_Fc78_A1                       -2107648173         /* Floating point value -1.962900 */
+#define HPF_Fs48000_Fc78_A1                      (-2107648173)        /* Floating point value -1.962900 */
 #define HPF_Fs48000_Fc78_A2                        1053824087         /* Floating point value 0.981450 */
-#define HPF_Fs48000_Fc78_B1                       -2131998154         /* Floating point value -1.985578 */
+#define HPF_Fs48000_Fc78_B1                      (-2131998154)        /* Floating point value -1.985578 */
 #define HPF_Fs48000_Fc78_B2                        1058367200         /* Floating point value 0.985681 */
 
  /* Coefficients for centre frequency 90Hz */
 #define HPF_Fs8000_Fc90_A0                         1009760053         /* Floating point value 0.940412 */
-#define HPF_Fs8000_Fc90_A1                        -2019520105         /* Floating point value -1.880825 */
+#define HPF_Fs8000_Fc90_A1                       (-2019520105)        /* Floating point value -1.880825 */
 #define HPF_Fs8000_Fc90_A2                         1009760053         /* Floating point value 0.940412 */
-#define HPF_Fs8000_Fc90_B1                        -2040357139         /* Floating point value -1.900231 */
+#define HPF_Fs8000_Fc90_B1                       (-2040357139)        /* Floating point value -1.900231 */
 #define HPF_Fs8000_Fc90_B2                          971711129         /* Floating point value 0.904977 */
 #define HPF_Fs11025_Fc90_A0                        1023687217         /* Floating point value 0.953383 */
-#define HPF_Fs11025_Fc90_A1                       -2047374434         /* Floating point value -1.906766 */
+#define HPF_Fs11025_Fc90_A1                      (-2047374434)        /* Floating point value -1.906766 */
 #define HPF_Fs11025_Fc90_A2                        1023687217         /* Floating point value 0.953383 */
-#define HPF_Fs11025_Fc90_B1                       -2069722397         /* Floating point value -1.927579 */
+#define HPF_Fs11025_Fc90_B1                      (-2069722397)        /* Floating point value -1.927579 */
 #define HPF_Fs11025_Fc90_B2                         998699604         /* Floating point value 0.930111 */
 #define HPF_Fs12000_Fc90_A0                        1026704754         /* Floating point value 0.956193 */
-#define HPF_Fs12000_Fc90_A1                       -2053409508         /* Floating point value -1.912387 */
+#define HPF_Fs12000_Fc90_A1                      (-2053409508)        /* Floating point value -1.912387 */
 #define HPF_Fs12000_Fc90_A2                        1026704754         /* Floating point value 0.956193 */
-#define HPF_Fs12000_Fc90_B1                       -2076035996         /* Floating point value -1.933459 */
+#define HPF_Fs12000_Fc90_B1                      (-2076035996)        /* Floating point value -1.933459 */
 #define HPF_Fs12000_Fc90_B2                        1004595918         /* Floating point value 0.935603 */
 #define HPF_Fs16000_Fc90_A0                        1035283225         /* Floating point value 0.964183 */
-#define HPF_Fs16000_Fc90_A1                       -2070566451         /* Floating point value -1.928365 */
+#define HPF_Fs16000_Fc90_A1                      (-2070566451)        /* Floating point value -1.928365 */
 #define HPF_Fs16000_Fc90_A2                        1035283225         /* Floating point value 0.964183 */
-#define HPF_Fs16000_Fc90_B1                       -2093889811         /* Floating point value -1.950087 */
+#define HPF_Fs16000_Fc90_B1                      (-2093889811)        /* Floating point value -1.950087 */
 #define HPF_Fs16000_Fc90_B2                        1021453326         /* Floating point value 0.951303 */
 #define HPF_Fs22050_Fc90_A0                        1042398116         /* Floating point value 0.970809 */
-#define HPF_Fs22050_Fc90_A1                       -2084796232         /* Floating point value -1.941618 */
+#define HPF_Fs22050_Fc90_A1                      (-2084796232)        /* Floating point value -1.941618 */
 #define HPF_Fs22050_Fc90_A2                        1042398116         /* Floating point value 0.970809 */
-#define HPF_Fs22050_Fc90_B1                       -2108591057         /* Floating point value -1.963778 */
+#define HPF_Fs22050_Fc90_B1                      (-2108591057)        /* Floating point value -1.963778 */
 #define HPF_Fs22050_Fc90_B2                        1035541188         /* Floating point value 0.964423 */
 #define HPF_Fs24000_Fc90_A0                        1043933302         /* Floating point value 0.972239 */
-#define HPF_Fs24000_Fc90_A1                       -2087866604         /* Floating point value -1.944477 */
+#define HPF_Fs24000_Fc90_A1                      (-2087866604)        /* Floating point value -1.944477 */
 #define HPF_Fs24000_Fc90_A2                        1043933302         /* Floating point value 0.972239 */
-#define HPF_Fs24000_Fc90_B1                       -2111750495         /* Floating point value -1.966721 */
+#define HPF_Fs24000_Fc90_B1                      (-2111750495)        /* Floating point value -1.966721 */
 #define HPF_Fs24000_Fc90_B2                        1038593601         /* Floating point value 0.967266 */
 #define HPF_Fs32000_Fc90_A0                        1048285391         /* Floating point value 0.976292 */
-#define HPF_Fs32000_Fc90_A1                       -2096570783         /* Floating point value -1.952584 */
+#define HPF_Fs32000_Fc90_A1                      (-2096570783)        /* Floating point value -1.952584 */
 #define HPF_Fs32000_Fc90_A2                        1048285391         /* Floating point value 0.976292 */
-#define HPF_Fs32000_Fc90_B1                       -2120682737         /* Floating point value -1.975040 */
+#define HPF_Fs32000_Fc90_B1                      (-2120682737)        /* Floating point value -1.975040 */
 #define HPF_Fs32000_Fc90_B2                        1047271295         /* Floating point value 0.975347 */
 #define HPF_Fs44100_Fc90_A0                        1051881330         /* Floating point value 0.979641 */
-#define HPF_Fs44100_Fc90_A1                       -2103762660         /* Floating point value -1.959282 */
+#define HPF_Fs44100_Fc90_A1                      (-2103762660)        /* Floating point value -1.959282 */
 #define HPF_Fs44100_Fc90_A2                        1051881330         /* Floating point value 0.979641 */
-#define HPF_Fs44100_Fc90_B1                       -2128035809         /* Floating point value -1.981888 */
+#define HPF_Fs44100_Fc90_B1                      (-2128035809)        /* Floating point value -1.981888 */
 #define HPF_Fs44100_Fc90_B2                        1054468533         /* Floating point value 0.982050 */
 #define HPF_Fs48000_Fc90_A0                        1052655619         /* Floating point value 0.980362 */
-#define HPF_Fs48000_Fc90_A1                       -2105311238         /* Floating point value -1.960724 */
+#define HPF_Fs48000_Fc90_A1                      (-2105311238)        /* Floating point value -1.960724 */
 #define HPF_Fs48000_Fc90_A2                        1052655619         /* Floating point value 0.980362 */
-#define HPF_Fs48000_Fc90_B1                       -2129615871         /* Floating point value -1.983359 */
+#define HPF_Fs48000_Fc90_B1                      (-2129615871)        /* Floating point value -1.983359 */
 #define HPF_Fs48000_Fc90_B2                        1056021492         /* Floating point value 0.983497 */
 
 
@@ -232,189 +232,189 @@
  /* Coefficients for centre frequency 55Hz */
 #define BPF_Fs8000_Fc55_A0                            9875247         /* Floating point value 0.009197 */
 #define BPF_Fs8000_Fc55_A1                                  0         /* Floating point value 0.000000 */
-#define BPF_Fs8000_Fc55_A2                           -9875247         /* Floating point value -0.009197 */
-#define BPF_Fs8000_Fc55_B1                        -2125519830         /* Floating point value -1.979545 */
+#define BPF_Fs8000_Fc55_A2                          (-9875247)        /* Floating point value -0.009197 */
+#define BPF_Fs8000_Fc55_B1                       (-2125519830)        /* Floating point value -1.979545 */
 #define BPF_Fs8000_Fc55_B2                         1053762629         /* Floating point value 0.981393 */
 #define BPF_Fs11025_Fc55_A0                           7183952         /* Floating point value 0.006691 */
 #define BPF_Fs11025_Fc55_A1                                 0         /* Floating point value 0.000000 */
-#define BPF_Fs11025_Fc55_A2                          -7183952         /* Floating point value -0.006691 */
-#define BPF_Fs11025_Fc55_B1                       -2131901658         /* Floating point value -1.985488 */
+#define BPF_Fs11025_Fc55_A2                         (-7183952)        /* Floating point value -0.006691 */
+#define BPF_Fs11025_Fc55_B1                      (-2131901658)        /* Floating point value -1.985488 */
 #define BPF_Fs11025_Fc55_B2                        1059207548         /* Floating point value 0.986464 */
 #define BPF_Fs12000_Fc55_A0                           6603871         /* Floating point value 0.006150 */
 #define BPF_Fs12000_Fc55_A1                                 0         /* Floating point value 0.000000 */
-#define BPF_Fs12000_Fc55_A2                          -6603871         /* Floating point value -0.006150 */
-#define BPF_Fs12000_Fc55_B1                       -2133238092         /* Floating point value -1.986733 */
+#define BPF_Fs12000_Fc55_A2                         (-6603871)        /* Floating point value -0.006150 */
+#define BPF_Fs12000_Fc55_B1                      (-2133238092)        /* Floating point value -1.986733 */
 #define BPF_Fs12000_Fc55_B2                        1060381143         /* Floating point value 0.987557 */
 #define BPF_Fs16000_Fc55_A0                           4960591         /* Floating point value 0.004620 */
 #define BPF_Fs16000_Fc55_A1                                 0         /* Floating point value 0.000000 */
-#define BPF_Fs16000_Fc55_A2                          -4960591         /* Floating point value -0.004620 */
-#define BPF_Fs16000_Fc55_B1                       -2136949052         /* Floating point value -1.990189 */
+#define BPF_Fs16000_Fc55_A2                         (-4960591)        /* Floating point value -0.004620 */
+#define BPF_Fs16000_Fc55_B1                      (-2136949052)        /* Floating point value -1.990189 */
 #define BPF_Fs16000_Fc55_B2                        1063705760         /* Floating point value 0.990653 */
 #define BPF_Fs22050_Fc55_A0                           3604131         /* Floating point value 0.003357 */
 #define BPF_Fs22050_Fc55_A1                                 0         /* Floating point value 0.000000 */
-#define BPF_Fs22050_Fc55_A2                          -3604131         /* Floating point value -0.003357 */
-#define BPF_Fs22050_Fc55_B1                       -2139929085         /* Floating point value -1.992964 */
+#define BPF_Fs22050_Fc55_A2                         (-3604131)        /* Floating point value -0.003357 */
+#define BPF_Fs22050_Fc55_B1                      (-2139929085)        /* Floating point value -1.992964 */
 #define BPF_Fs22050_Fc55_B2                        1066450095         /* Floating point value 0.993209 */
 #define BPF_Fs24000_Fc55_A0                           3312207         /* Floating point value 0.003085 */
 #define BPF_Fs24000_Fc55_A1                                 0         /* Floating point value 0.000000 */
-#define BPF_Fs24000_Fc55_A2                          -3312207         /* Floating point value -0.003085 */
-#define BPF_Fs24000_Fc55_B1                       -2140560606         /* Floating point value -1.993552 */
+#define BPF_Fs24000_Fc55_A2                         (-3312207)        /* Floating point value -0.003085 */
+#define BPF_Fs24000_Fc55_B1                      (-2140560606)        /* Floating point value -1.993552 */
 #define BPF_Fs24000_Fc55_B2                        1067040703         /* Floating point value 0.993759 */
 #define BPF_Fs32000_Fc55_A0                           2486091         /* Floating point value 0.002315 */
 #define BPF_Fs32000_Fc55_A1                                 0         /* Floating point value 0.000000 */
-#define BPF_Fs32000_Fc55_A2                          -2486091         /* Floating point value -0.002315 */
-#define BPF_Fs32000_Fc55_B1                       -2142328962         /* Floating point value -1.995199 */
+#define BPF_Fs32000_Fc55_A2                         (-2486091)        /* Floating point value -0.002315 */
+#define BPF_Fs32000_Fc55_B1                      (-2142328962)        /* Floating point value -1.995199 */
 #define BPF_Fs32000_Fc55_B2                        1068712067         /* Floating point value 0.995316 */
 #define BPF_Fs44100_Fc55_A0                           1805125         /* Floating point value 0.001681 */
 #define BPF_Fs44100_Fc55_A1                                 0         /* Floating point value 0.000000 */
-#define BPF_Fs44100_Fc55_A2                          -1805125         /* Floating point value -0.001681 */
-#define BPF_Fs44100_Fc55_B1                       -2143765772         /* Floating point value -1.996537 */
+#define BPF_Fs44100_Fc55_A2                         (-1805125)        /* Floating point value -0.001681 */
+#define BPF_Fs44100_Fc55_B1                      (-2143765772)        /* Floating point value -1.996537 */
 #define BPF_Fs44100_Fc55_B2                        1070089770         /* Floating point value 0.996599 */
 #define BPF_Fs48000_Fc55_A0                           1658687         /* Floating point value 0.001545 */
 #define BPF_Fs48000_Fc55_A1                                 0         /* Floating point value 0.000000 */
-#define BPF_Fs48000_Fc55_A2                          -1658687         /* Floating point value -0.001545 */
-#define BPF_Fs48000_Fc55_B1                       -2144072292         /* Floating point value -1.996823 */
+#define BPF_Fs48000_Fc55_A2                         (-1658687)        /* Floating point value -0.001545 */
+#define BPF_Fs48000_Fc55_B1                      (-2144072292)        /* Floating point value -1.996823 */
 #define BPF_Fs48000_Fc55_B2                        1070386036         /* Floating point value 0.996875 */
 
  /* Coefficients for centre frequency 66Hz */
 #define BPF_Fs8000_Fc66_A0                           13580189         /* Floating point value 0.012648 */
 #define BPF_Fs8000_Fc66_A1                                  0         /* Floating point value 0.000000 */
-#define BPF_Fs8000_Fc66_A2                          -13580189         /* Floating point value -0.012648 */
-#define BPF_Fs8000_Fc66_B1                        -2117161175         /* Floating point value -1.971760 */
+#define BPF_Fs8000_Fc66_A2                         (-13580189)        /* Floating point value -0.012648 */
+#define BPF_Fs8000_Fc66_B1                       (-2117161175)        /* Floating point value -1.971760 */
 #define BPF_Fs8000_Fc66_B2                         1046266945         /* Floating point value 0.974412 */
 #define BPF_Fs11025_Fc66_A0                           9888559         /* Floating point value 0.009209 */
 #define BPF_Fs11025_Fc66_A1                                 0         /* Floating point value 0.000000 */
-#define BPF_Fs11025_Fc66_A2                          -9888559         /* Floating point value -0.009209 */
-#define BPF_Fs11025_Fc66_B1                       -2125972738         /* Floating point value -1.979966 */
+#define BPF_Fs11025_Fc66_A2                         (-9888559)        /* Floating point value -0.009209 */
+#define BPF_Fs11025_Fc66_B1                      (-2125972738)        /* Floating point value -1.979966 */
 #define BPF_Fs11025_Fc66_B2                        1053735698         /* Floating point value 0.981368 */
 #define BPF_Fs12000_Fc66_A0                           9091954         /* Floating point value 0.008468 */
 #define BPF_Fs12000_Fc66_A1                                 0         /* Floating point value 0.000000 */
-#define BPF_Fs12000_Fc66_A2                          -9091954         /* Floating point value -0.008468 */
-#define BPF_Fs12000_Fc66_B1                       -2127818004         /* Floating point value -1.981685 */
+#define BPF_Fs12000_Fc66_A2                         (-9091954)        /* Floating point value -0.008468 */
+#define BPF_Fs12000_Fc66_B1                      (-2127818004)        /* Floating point value -1.981685 */
 #define BPF_Fs12000_Fc66_B2                        1055347356         /* Floating point value 0.982869 */
 #define BPF_Fs16000_Fc66_A0                           6833525         /* Floating point value 0.006364 */
 #define BPF_Fs16000_Fc66_A1                                 0         /* Floating point value 0.000000 */
-#define BPF_Fs16000_Fc66_A2                          -6833525         /* Floating point value -0.006364 */
-#define BPF_Fs16000_Fc66_B1                       -2132941739         /* Floating point value -1.986457 */
+#define BPF_Fs16000_Fc66_A2                         (-6833525)        /* Floating point value -0.006364 */
+#define BPF_Fs16000_Fc66_B1                      (-2132941739)        /* Floating point value -1.986457 */
 #define BPF_Fs16000_Fc66_B2                        1059916517         /* Floating point value 0.987124 */
 #define BPF_Fs22050_Fc66_A0                           4967309         /* Floating point value 0.004626 */
 #define BPF_Fs22050_Fc66_A1                                 0         /* Floating point value 0.000000 */
-#define BPF_Fs22050_Fc66_A2                          -4967309         /* Floating point value -0.004626 */
-#define BPF_Fs22050_Fc66_B1                       -2137056003         /* Floating point value -1.990288 */
+#define BPF_Fs22050_Fc66_A2                         (-4967309)        /* Floating point value -0.004626 */
+#define BPF_Fs22050_Fc66_B1                      (-2137056003)        /* Floating point value -1.990288 */
 #define BPF_Fs22050_Fc66_B2                        1063692170         /* Floating point value 0.990641 */
 #define BPF_Fs24000_Fc66_A0                           4565445         /* Floating point value 0.004252 */
 #define BPF_Fs24000_Fc66_A1                                 0         /* Floating point value 0.000000 */
-#define BPF_Fs24000_Fc66_A2                          -4565445         /* Floating point value -0.004252 */
-#define BPF_Fs24000_Fc66_B1                       -2137927842         /* Floating point value -1.991100 */
+#define BPF_Fs24000_Fc66_A2                         (-4565445)        /* Floating point value -0.004252 */
+#define BPF_Fs24000_Fc66_B1                      (-2137927842)        /* Floating point value -1.991100 */
 #define BPF_Fs24000_Fc66_B2                        1064505202         /* Floating point value 0.991398 */
 #define BPF_Fs32000_Fc66_A0                           3427761         /* Floating point value 0.003192 */
 #define BPF_Fs32000_Fc66_A1                                 0         /* Floating point value 0.000000 */
-#define BPF_Fs32000_Fc66_A2                          -3427761         /* Floating point value -0.003192 */
-#define BPF_Fs32000_Fc66_B1                       -2140369007         /* Floating point value -1.993374 */
+#define BPF_Fs32000_Fc66_A2                         (-3427761)        /* Floating point value -0.003192 */
+#define BPF_Fs32000_Fc66_B1                      (-2140369007)        /* Floating point value -1.993374 */
 #define BPF_Fs32000_Fc66_B2                        1066806920         /* Floating point value 0.993541 */
 #define BPF_Fs44100_Fc66_A0                           2489466         /* Floating point value 0.002318 */
 #define BPF_Fs44100_Fc66_A1                                 0         /* Floating point value 0.000000 */
-#define BPF_Fs44100_Fc66_A2                          -2489466         /* Floating point value -0.002318 */
-#define BPF_Fs44100_Fc66_B1                       -2142352342         /* Floating point value -1.995221 */
+#define BPF_Fs44100_Fc66_A2                         (-2489466)        /* Floating point value -0.002318 */
+#define BPF_Fs44100_Fc66_B1                      (-2142352342)        /* Floating point value -1.995221 */
 #define BPF_Fs44100_Fc66_B2                        1068705240         /* Floating point value 0.995309 */
 #define BPF_Fs48000_Fc66_A0                           2287632         /* Floating point value 0.002131 */
 #define BPF_Fs48000_Fc66_A1                                 0         /* Floating point value 0.000000 */
-#define BPF_Fs48000_Fc66_A2                          -2287632         /* Floating point value -0.002131 */
-#define BPF_Fs48000_Fc66_B1                       -2142775436         /* Floating point value -1.995615 */
+#define BPF_Fs48000_Fc66_A2                         (-2287632)        /* Floating point value -0.002131 */
+#define BPF_Fs48000_Fc66_B1                      (-2142775436)        /* Floating point value -1.995615 */
 #define BPF_Fs48000_Fc66_B2                        1069113581         /* Floating point value 0.995690 */
 
  /* Coefficients for centre frequency 78Hz */
 #define BPF_Fs8000_Fc78_A0                           19941180         /* Floating point value 0.018572 */
 #define BPF_Fs8000_Fc78_A1                                  0         /* Floating point value 0.000000 */
-#define BPF_Fs8000_Fc78_A2                          -19941180         /* Floating point value -0.018572 */
-#define BPF_Fs8000_Fc78_B1                        -2103186749         /* Floating point value -1.958745 */
+#define BPF_Fs8000_Fc78_A2                         (-19941180)        /* Floating point value -0.018572 */
+#define BPF_Fs8000_Fc78_B1                       (-2103186749)        /* Floating point value -1.958745 */
 #define BPF_Fs8000_Fc78_B2                         1033397648         /* Floating point value 0.962427 */
 #define BPF_Fs11025_Fc78_A0                          14543934         /* Floating point value 0.013545 */
 #define BPF_Fs11025_Fc78_A1                                 0         /* Floating point value 0.000000 */
-#define BPF_Fs11025_Fc78_A2                         -14543934         /* Floating point value -0.013545 */
-#define BPF_Fs11025_Fc78_B1                       -2115966638         /* Floating point value -1.970647 */
+#define BPF_Fs11025_Fc78_A2                        (-14543934)        /* Floating point value -0.013545 */
+#define BPF_Fs11025_Fc78_B1                      (-2115966638)        /* Floating point value -1.970647 */
 #define BPF_Fs11025_Fc78_B2                        1044317135         /* Floating point value 0.972596 */
 #define BPF_Fs12000_Fc78_A0                          13376999         /* Floating point value 0.012458 */
 #define BPF_Fs12000_Fc78_A1                                 0         /* Floating point value 0.000000 */
-#define BPF_Fs12000_Fc78_A2                         -13376999         /* Floating point value -0.012458 */
-#define BPF_Fs12000_Fc78_B1                       -2118651708         /* Floating point value -1.973148 */
+#define BPF_Fs12000_Fc78_A2                        (-13376999)        /* Floating point value -0.012458 */
+#define BPF_Fs12000_Fc78_B1                      (-2118651708)        /* Floating point value -1.973148 */
 #define BPF_Fs12000_Fc78_B2                        1046678029         /* Floating point value 0.974795 */
 #define BPF_Fs16000_Fc78_A0                          10064222         /* Floating point value 0.009373 */
 #define BPF_Fs16000_Fc78_A1                                 0         /* Floating point value 0.000000 */
-#define BPF_Fs16000_Fc78_A2                         -10064222         /* Floating point value -0.009373 */
-#define BPF_Fs16000_Fc78_B1                       -2126124342         /* Floating point value -1.980108 */
+#define BPF_Fs16000_Fc78_A2                        (-10064222)        /* Floating point value -0.009373 */
+#define BPF_Fs16000_Fc78_B1                      (-2126124342)        /* Floating point value -1.980108 */
 #define BPF_Fs16000_Fc78_B2                        1053380304         /* Floating point value 0.981037 */
 #define BPF_Fs22050_Fc78_A0                           7321780         /* Floating point value 0.006819 */
 #define BPF_Fs22050_Fc78_A1                                 0         /* Floating point value 0.000000 */
-#define BPF_Fs22050_Fc78_A2                          -7321780         /* Floating point value -0.006819 */
-#define BPF_Fs22050_Fc78_B1                       -2132143771         /* Floating point value -1.985714 */
+#define BPF_Fs22050_Fc78_A2                         (-7321780)        /* Floating point value -0.006819 */
+#define BPF_Fs22050_Fc78_B1                      (-2132143771)        /* Floating point value -1.985714 */
 #define BPF_Fs22050_Fc78_B2                        1058928700         /* Floating point value 0.986204 */
 #define BPF_Fs24000_Fc78_A0                           6730640         /* Floating point value 0.006268 */
 #define BPF_Fs24000_Fc78_A1                                 0         /* Floating point value 0.000000 */
-#define BPF_Fs24000_Fc78_A2                          -6730640         /* Floating point value -0.006268 */
-#define BPF_Fs24000_Fc78_B1                       -2133421607         /* Floating point value -1.986904 */
+#define BPF_Fs24000_Fc78_A2                         (-6730640)        /* Floating point value -0.006268 */
+#define BPF_Fs24000_Fc78_B1                      (-2133421607)        /* Floating point value -1.986904 */
 #define BPF_Fs24000_Fc78_B2                        1060124669         /* Floating point value 0.987318 */
 #define BPF_Fs32000_Fc78_A0                           5055965         /* Floating point value 0.004709 */
 #define BPF_Fs32000_Fc78_A1                                 0         /* Floating point value 0.000000 */
-#define BPF_Fs32000_Fc78_A2                          -5055965         /* Floating point value -0.004709 */
-#define BPF_Fs32000_Fc78_B1                       -2137003977         /* Floating point value -1.990240 */
+#define BPF_Fs32000_Fc78_A2                         (-5055965)        /* Floating point value -0.004709 */
+#define BPF_Fs32000_Fc78_B1                      (-2137003977)        /* Floating point value -1.990240 */
 #define BPF_Fs32000_Fc78_B2                        1063512802         /* Floating point value 0.990473 */
 #define BPF_Fs44100_Fc78_A0                           3673516         /* Floating point value 0.003421 */
 #define BPF_Fs44100_Fc78_A1                                 0         /* Floating point value 0.000000 */
-#define BPF_Fs44100_Fc78_A2                          -3673516         /* Floating point value -0.003421 */
-#define BPF_Fs44100_Fc78_B1                       -2139919394         /* Floating point value -1.992955 */
+#define BPF_Fs44100_Fc78_A2                         (-3673516)        /* Floating point value -0.003421 */
+#define BPF_Fs44100_Fc78_B1                      (-2139919394)        /* Floating point value -1.992955 */
 #define BPF_Fs44100_Fc78_B2                        1066309718         /* Floating point value 0.993078 */
 #define BPF_Fs48000_Fc78_A0                           3375990         /* Floating point value 0.003144 */
 #define BPF_Fs48000_Fc78_A1                                 0         /* Floating point value 0.000000 */
-#define BPF_Fs48000_Fc78_A2                          -3375990         /* Floating point value -0.003144 */
-#define BPF_Fs48000_Fc78_B1                       -2140541906         /* Floating point value -1.993535 */
+#define BPF_Fs48000_Fc78_A2                         (-3375990)        /* Floating point value -0.003144 */
+#define BPF_Fs48000_Fc78_B1                      (-2140541906)        /* Floating point value -1.993535 */
 #define BPF_Fs48000_Fc78_B2                        1066911660         /* Floating point value 0.993639 */
 
  /* Coefficients for centre frequency 90Hz */
 #define BPF_Fs8000_Fc90_A0                           24438548         /* Floating point value 0.022760 */
 #define BPF_Fs8000_Fc90_A1                                  0         /* Floating point value 0.000000 */
-#define BPF_Fs8000_Fc90_A2                          -24438548         /* Floating point value -0.022760 */
-#define BPF_Fs8000_Fc90_B1                        -2092801347         /* Floating point value -1.949073 */
+#define BPF_Fs8000_Fc90_A2                         (-24438548)        /* Floating point value -0.022760 */
+#define BPF_Fs8000_Fc90_B1                       (-2092801347)        /* Floating point value -1.949073 */
 #define BPF_Fs8000_Fc90_B2                         1024298757         /* Floating point value 0.953953 */
 #define BPF_Fs11025_Fc90_A0                          17844385         /* Floating point value 0.016619 */
 #define BPF_Fs11025_Fc90_A1                                 0         /* Floating point value 0.000000 */
-#define BPF_Fs11025_Fc90_A2                         -17844385         /* Floating point value -0.016619 */
-#define BPF_Fs11025_Fc90_B1                       -2108604921         /* Floating point value -1.963791 */
+#define BPF_Fs11025_Fc90_A2                        (-17844385)        /* Floating point value -0.016619 */
+#define BPF_Fs11025_Fc90_B1                      (-2108604921)        /* Floating point value -1.963791 */
 #define BPF_Fs11025_Fc90_B2                        1037639797         /* Floating point value 0.966377 */
 #define BPF_Fs12000_Fc90_A0                          16416707         /* Floating point value 0.015289 */
 #define BPF_Fs12000_Fc90_A1                                 0         /* Floating point value 0.000000 */
-#define BPF_Fs12000_Fc90_A2                         -16416707         /* Floating point value -0.015289 */
-#define BPF_Fs12000_Fc90_B1                       -2111922936         /* Floating point value -1.966882 */
+#define BPF_Fs12000_Fc90_A2                        (-16416707)        /* Floating point value -0.015289 */
+#define BPF_Fs12000_Fc90_B1                      (-2111922936)        /* Floating point value -1.966882 */
 #define BPF_Fs12000_Fc90_B2                        1040528216         /* Floating point value 0.969067 */
 #define BPF_Fs16000_Fc90_A0                          12359883         /* Floating point value 0.011511 */
 #define BPF_Fs16000_Fc90_A1                                 0         /* Floating point value 0.000000 */
-#define BPF_Fs16000_Fc90_A2                         -12359883         /* Floating point value -0.011511 */
-#define BPF_Fs16000_Fc90_B1                       -2121152162         /* Floating point value -1.975477 */
+#define BPF_Fs16000_Fc90_A2                        (-12359883)        /* Floating point value -0.011511 */
+#define BPF_Fs16000_Fc90_B1                      (-2121152162)        /* Floating point value -1.975477 */
 #define BPF_Fs16000_Fc90_B2                        1048735817         /* Floating point value 0.976711 */
 #define BPF_Fs22050_Fc90_A0                           8997173         /* Floating point value 0.008379 */
 #define BPF_Fs22050_Fc90_A1                                 0         /* Floating point value 0.000000 */
-#define BPF_Fs22050_Fc90_A2                          -8997173         /* Floating point value -0.008379 */
-#define BPF_Fs22050_Fc90_B1                       -2128580762         /* Floating point value -1.982395 */
+#define BPF_Fs22050_Fc90_A2                         (-8997173)        /* Floating point value -0.008379 */
+#define BPF_Fs22050_Fc90_B1                      (-2128580762)        /* Floating point value -1.982395 */
 #define BPF_Fs22050_Fc90_B2                        1055539113         /* Floating point value 0.983047 */
 #define BPF_Fs24000_Fc90_A0                           8271818         /* Floating point value 0.007704 */
 #define BPF_Fs24000_Fc90_A1                                 0         /* Floating point value 0.000000 */
-#define BPF_Fs24000_Fc90_A2                          -8271818         /* Floating point value -0.007704 */
-#define BPF_Fs24000_Fc90_B1                       -2130157013         /* Floating point value -1.983863 */
+#define BPF_Fs24000_Fc90_A2                         (-8271818)        /* Floating point value -0.007704 */
+#define BPF_Fs24000_Fc90_B1                      (-2130157013)        /* Floating point value -1.983863 */
 #define BPF_Fs24000_Fc90_B2                        1057006621         /* Floating point value 0.984414 */
 #define BPF_Fs32000_Fc90_A0                           6215918         /* Floating point value 0.005789 */
 #define BPF_Fs32000_Fc90_A1                                 0         /* Floating point value 0.000000 */
-#define BPF_Fs32000_Fc90_A2                          -6215918         /* Floating point value -0.005789 */
-#define BPF_Fs32000_Fc90_B1                       -2134574521         /* Floating point value -1.987977 */
+#define BPF_Fs32000_Fc90_A2                         (-6215918)        /* Floating point value -0.005789 */
+#define BPF_Fs32000_Fc90_B1                      (-2134574521)        /* Floating point value -1.987977 */
 #define BPF_Fs32000_Fc90_B2                        1061166033         /* Floating point value 0.988288 */
 #define BPF_Fs44100_Fc90_A0                           4517651         /* Floating point value 0.004207 */
 #define BPF_Fs44100_Fc90_A1                                 0         /* Floating point value 0.000000 */
-#define BPF_Fs44100_Fc90_A2                          -4517651         /* Floating point value -0.004207 */
-#define BPF_Fs44100_Fc90_B1                       -2138167926         /* Floating point value -1.991324 */
+#define BPF_Fs44100_Fc90_A2                         (-4517651)        /* Floating point value -0.004207 */
+#define BPF_Fs44100_Fc90_B1                      (-2138167926)        /* Floating point value -1.991324 */
 #define BPF_Fs44100_Fc90_B2                        1064601898         /* Floating point value 0.991488 */
 #define BPF_Fs48000_Fc90_A0                           4152024         /* Floating point value 0.003867 */
 #define BPF_Fs48000_Fc90_A1                                 0         /* Floating point value 0.000000 */
-#define BPF_Fs48000_Fc90_A2                          -4152024         /* Floating point value -0.003867 */
-#define BPF_Fs48000_Fc90_B1                       -2138935002         /* Floating point value -1.992038 */
+#define BPF_Fs48000_Fc90_A2                         (-4152024)        /* Floating point value -0.003867 */
+#define BPF_Fs48000_Fc90_B1                      (-2138935002)        /* Floating point value -1.992038 */
 #define BPF_Fs48000_Fc90_B2                        1065341620         /* Floating point value 0.992177 */
 
 
diff --git a/media/libeffects/lvm/lib/Bass/src/LVDBE_Control.c b/media/libeffects/lvm/lib/Bass/src/LVDBE_Control.c
index ab2a832..b6632a3 100644
--- a/media/libeffects/lvm/lib/Bass/src/LVDBE_Control.c
+++ b/media/libeffects/lvm/lib/Bass/src/LVDBE_Control.c
@@ -334,10 +334,10 @@
                      pParams);                          /* New parameters */
 
         LVC_Mixer_SetTimeConstant(&pBypassMixer_Instance->MixerStream[0],
-            LVDBE_BYPASS_MIXER_TC,pParams->SampleRate,2);
+            LVDBE_BYPASS_MIXER_TC,(LVM_Fs_en)pParams->SampleRate,2);
 
         LVC_Mixer_SetTimeConstant(&pBypassMixer_Instance->MixerStream[1],
-            LVDBE_BYPASS_MIXER_TC,pParams->SampleRate,2);
+            LVDBE_BYPASS_MIXER_TC,(LVM_Fs_en)pParams->SampleRate,2);
 
 
     }
diff --git a/media/libeffects/lvm/lib/Bass/src/LVDBE_Init.c b/media/libeffects/lvm/lib/Bass/src/LVDBE_Init.c
index 35e5bc8..a3623bc 100644
--- a/media/libeffects/lvm/lib/Bass/src/LVDBE_Init.c
+++ b/media/libeffects/lvm/lib/Bass/src/LVDBE_Init.c
@@ -270,7 +270,7 @@
     pBypassMixer_Instance->MixerStream[0].CallbackSet=0;
     LVC_Mixer_Init(&pBypassMixer_Instance->MixerStream[0],0,0);
     LVC_Mixer_SetTimeConstant(&pBypassMixer_Instance->MixerStream[0],
-        LVDBE_BYPASS_MIXER_TC,pInstance->Params.SampleRate,2);
+        LVDBE_BYPASS_MIXER_TC,(LVM_Fs_en)pInstance->Params.SampleRate,2);
     /*
      * Setup the mixer gain for the unprocessed path
      */
@@ -280,8 +280,7 @@
     pBypassMixer_Instance->MixerStream[1].CallbackSet=0;
     LVC_Mixer_Init(&pBypassMixer_Instance->MixerStream[1],0x00007FFF,0x00007FFF);
     LVC_Mixer_SetTimeConstant(&pBypassMixer_Instance->MixerStream[1],
-        LVDBE_BYPASS_MIXER_TC,pInstance->Params.SampleRate,2);
+        LVDBE_BYPASS_MIXER_TC,(LVM_Fs_en)pInstance->Params.SampleRate,2);
 
     return(LVDBE_SUCCESS);
 }
-
diff --git a/media/libeffects/lvm/lib/Bundle/src/LVM_Coeffs.h b/media/libeffects/lvm/lib/Bundle/src/LVM_Coeffs.h
index f578db9..2712b2c 100644
--- a/media/libeffects/lvm/lib/Bundle/src/LVM_Coeffs.h
+++ b/media/libeffects/lvm/lib/Bundle/src/LVM_Coeffs.h
@@ -74,63 +74,63 @@
 #define HPF_Fs22050_Gain6_B2                                0         /* Floating point value 0.000000 */
 #define HPF_Fs22050_Gain6_Shift                             1         /* Shift value */
                                                                     /* Gain =  7.000000 dB */
-#define HPF_Fs22050_Gain7_A0                             -164         /* Floating point value -0.005002 */
+#define HPF_Fs22050_Gain7_A0                            (-164)        /* Floating point value -0.005002 */
 #define HPF_Fs22050_Gain7_A1                            11311         /* Floating point value 0.345199 */
 #define HPF_Fs22050_Gain7_A2                                0         /* Floating point value 0.000000 */
 #define HPF_Fs22050_Gain7_B1                            12125         /* Floating point value 0.370033 */
 #define HPF_Fs22050_Gain7_B2                                0         /* Floating point value 0.000000 */
 #define HPF_Fs22050_Gain7_Shift                             2         /* Shift value */
                                                                     /* Gain =  8.000000 dB */
-#define HPF_Fs22050_Gain8_A0                             -864         /* Floating point value -0.026368 */
+#define HPF_Fs22050_Gain8_A0                            (-864)        /* Floating point value -0.026368 */
 #define HPF_Fs22050_Gain8_A1                            12012         /* Floating point value 0.366565 */
 #define HPF_Fs22050_Gain8_A2                                0         /* Floating point value 0.000000 */
 #define HPF_Fs22050_Gain8_B1                            12125         /* Floating point value 0.370033 */
 #define HPF_Fs22050_Gain8_B2                                0         /* Floating point value 0.000000 */
 #define HPF_Fs22050_Gain8_Shift                             2         /* Shift value */
                                                                     /* Gain =  9.000000 dB */
-#define HPF_Fs22050_Gain9_A0                            -1650         /* Floating point value -0.050340 */
+#define HPF_Fs22050_Gain9_A0                           (-1650)        /* Floating point value -0.050340 */
 #define HPF_Fs22050_Gain9_A1                            12797         /* Floating point value 0.390537 */
 #define HPF_Fs22050_Gain9_A2                                0         /* Floating point value 0.000000 */
 #define HPF_Fs22050_Gain9_B1                            12125         /* Floating point value 0.370033 */
 #define HPF_Fs22050_Gain9_B2                                0         /* Floating point value 0.000000 */
 #define HPF_Fs22050_Gain9_Shift                             2         /* Shift value */
                                                                     /* Gain =  10.000000 dB */
-#define HPF_Fs22050_Gain10_A0                           -2531         /* Floating point value -0.077238 */
+#define HPF_Fs22050_Gain10_A0                          (-2531)        /* Floating point value -0.077238 */
 #define HPF_Fs22050_Gain10_A1                           13679         /* Floating point value 0.417435 */
 #define HPF_Fs22050_Gain10_A2                               0         /* Floating point value 0.000000 */
 #define HPF_Fs22050_Gain10_B1                           12125         /* Floating point value 0.370033 */
 #define HPF_Fs22050_Gain10_B2                               0         /* Floating point value 0.000000 */
 #define HPF_Fs22050_Gain10_Shift                            2         /* Shift value */
                                                                     /* Gain =  11.000000 dB */
-#define HPF_Fs22050_Gain11_A0                           -3520         /* Floating point value -0.107417 */
+#define HPF_Fs22050_Gain11_A0                          (-3520)        /* Floating point value -0.107417 */
 #define HPF_Fs22050_Gain11_A1                           14667         /* Floating point value 0.447615 */
 #define HPF_Fs22050_Gain11_A2                               0         /* Floating point value 0.000000 */
 #define HPF_Fs22050_Gain11_B1                           12125         /* Floating point value 0.370033 */
 #define HPF_Fs22050_Gain11_B2                               0         /* Floating point value 0.000000 */
 #define HPF_Fs22050_Gain11_Shift                            2         /* Shift value */
                                                                     /* Gain =  12.000000 dB */
-#define HPF_Fs22050_Gain12_A0                           -4629         /* Floating point value -0.141279 */
+#define HPF_Fs22050_Gain12_A0                          (-4629)        /* Floating point value -0.141279 */
 #define HPF_Fs22050_Gain12_A1                           15777         /* Floating point value 0.481477 */
 #define HPF_Fs22050_Gain12_A2                               0         /* Floating point value 0.000000 */
 #define HPF_Fs22050_Gain12_B1                           12125         /* Floating point value 0.370033 */
 #define HPF_Fs22050_Gain12_B2                               0         /* Floating point value 0.000000 */
 #define HPF_Fs22050_Gain12_Shift                            2         /* Shift value */
                                                                     /* Gain =  13.000000 dB */
-#define HPF_Fs22050_Gain13_A0                           -2944         /* Floating point value -0.089849 */
+#define HPF_Fs22050_Gain13_A0                          (-2944)        /* Floating point value -0.089849 */
 #define HPF_Fs22050_Gain13_A1                            8531         /* Floating point value 0.260352 */
 #define HPF_Fs22050_Gain13_A2                               0         /* Floating point value 0.000000 */
 #define HPF_Fs22050_Gain13_B1                           12125         /* Floating point value 0.370033 */
 #define HPF_Fs22050_Gain13_B2                               0         /* Floating point value 0.000000 */
 #define HPF_Fs22050_Gain13_Shift                            3         /* Shift value */
                                                                     /* Gain =  14.000000 dB */
-#define HPF_Fs22050_Gain14_A0                           -3644         /* Floating point value -0.111215 */
+#define HPF_Fs22050_Gain14_A0                          (-3644)        /* Floating point value -0.111215 */
 #define HPF_Fs22050_Gain14_A1                            9231         /* Floating point value 0.281718 */
 #define HPF_Fs22050_Gain14_A2                               0         /* Floating point value 0.000000 */
 #define HPF_Fs22050_Gain14_B1                           12125         /* Floating point value 0.370033 */
 #define HPF_Fs22050_Gain14_B2                               0         /* Floating point value 0.000000 */
 #define HPF_Fs22050_Gain14_Shift                            3         /* Shift value */
                                                                     /* Gain =  15.000000 dB */
-#define HPF_Fs22050_Gain15_A0                           -4430         /* Floating point value -0.135187 */
+#define HPF_Fs22050_Gain15_A0                          (-4430)        /* Floating point value -0.135187 */
 #define HPF_Fs22050_Gain15_A1                           10017         /* Floating point value 0.305690 */
 #define HPF_Fs22050_Gain15_A2                               0         /* Floating point value 0.000000 */
 #define HPF_Fs22050_Gain15_B1                           12125         /* Floating point value 0.370033 */
@@ -168,77 +168,77 @@
 #define HPF_Fs24000_Gain4_B2                                0         /* Floating point value 0.000000 */
 #define HPF_Fs24000_Gain4_Shift                             1         /* Shift value */
                                                                     /* Gain =  5.000000 dB */
-#define HPF_Fs24000_Gain5_A0                             -275         /* Floating point value -0.008383 */
+#define HPF_Fs24000_Gain5_A0                            (-275)        /* Floating point value -0.008383 */
 #define HPF_Fs24000_Gain5_A1                            20860         /* Floating point value 0.636589 */
 #define HPF_Fs24000_Gain5_A2                                0         /* Floating point value 0.000000 */
 #define HPF_Fs24000_Gain5_B1                             8780         /* Floating point value 0.267949 */
 #define HPF_Fs24000_Gain5_B2                                0         /* Floating point value 0.000000 */
 #define HPF_Fs24000_Gain5_Shift                             1         /* Shift value */
                                                                     /* Gain =  6.000000 dB */
-#define HPF_Fs24000_Gain6_A0                            -1564         /* Floating point value -0.047733 */
+#define HPF_Fs24000_Gain6_A0                           (-1564)        /* Floating point value -0.047733 */
 #define HPF_Fs24000_Gain6_A1                            22149         /* Floating point value 0.675938 */
 #define HPF_Fs24000_Gain6_A2                                0         /* Floating point value 0.000000 */
 #define HPF_Fs24000_Gain6_B1                             8780         /* Floating point value 0.267949 */
 #define HPF_Fs24000_Gain6_B2                                0         /* Floating point value 0.000000 */
 #define HPF_Fs24000_Gain6_Shift                             1         /* Shift value */
                                                                     /* Gain =  7.000000 dB */
-#define HPF_Fs24000_Gain7_A0                            -1509         /* Floating point value -0.046051 */
+#define HPF_Fs24000_Gain7_A0                           (-1509)        /* Floating point value -0.046051 */
 #define HPF_Fs24000_Gain7_A1                            11826         /* Floating point value 0.360899 */
 #define HPF_Fs24000_Gain7_A2                                0         /* Floating point value 0.000000 */
 #define HPF_Fs24000_Gain7_B1                             8780         /* Floating point value 0.267949 */
 #define HPF_Fs24000_Gain7_B2                                0         /* Floating point value 0.000000 */
 #define HPF_Fs24000_Gain7_Shift                             2         /* Shift value */
                                                                     /* Gain =  8.000000 dB */
-#define HPF_Fs24000_Gain8_A0                            -2323         /* Floating point value -0.070878 */
+#define HPF_Fs24000_Gain8_A0                           (-2323)        /* Floating point value -0.070878 */
 #define HPF_Fs24000_Gain8_A1                            12640         /* Floating point value 0.385727 */
 #define HPF_Fs24000_Gain8_A2                                0         /* Floating point value 0.000000 */
 #define HPF_Fs24000_Gain8_B1                             8780         /* Floating point value 0.267949 */
 #define HPF_Fs24000_Gain8_B2                                0         /* Floating point value 0.000000 */
 #define HPF_Fs24000_Gain8_Shift                             2         /* Shift value */
                                                                     /* Gain =  9.000000 dB */
-#define HPF_Fs24000_Gain9_A0                            -3235         /* Floating point value -0.098736 */
+#define HPF_Fs24000_Gain9_A0                           (-3235)        /* Floating point value -0.098736 */
 #define HPF_Fs24000_Gain9_A1                            13552         /* Floating point value 0.413584 */
 #define HPF_Fs24000_Gain9_A2                                0         /* Floating point value 0.000000 */
 #define HPF_Fs24000_Gain9_B1                             8780         /* Floating point value 0.267949 */
 #define HPF_Fs24000_Gain9_B2                                0         /* Floating point value 0.000000 */
 #define HPF_Fs24000_Gain9_Shift                             2         /* Shift value */
                                                                     /* Gain =  10.000000 dB */
-#define HPF_Fs24000_Gain10_A0                           -4260         /* Floating point value -0.129992 */
+#define HPF_Fs24000_Gain10_A0                          (-4260)        /* Floating point value -0.129992 */
 #define HPF_Fs24000_Gain10_A1                           14577         /* Floating point value 0.444841 */
 #define HPF_Fs24000_Gain10_A2                               0         /* Floating point value 0.000000 */
 #define HPF_Fs24000_Gain10_B1                            8780         /* Floating point value 0.267949 */
 #define HPF_Fs24000_Gain10_B2                               0         /* Floating point value 0.000000 */
 #define HPF_Fs24000_Gain10_Shift                            2         /* Shift value */
                                                                     /* Gain =  11.000000 dB */
-#define HPF_Fs24000_Gain11_A0                           -5409         /* Floating point value -0.165062 */
+#define HPF_Fs24000_Gain11_A0                          (-5409)        /* Floating point value -0.165062 */
 #define HPF_Fs24000_Gain11_A1                           15726         /* Floating point value 0.479911 */
 #define HPF_Fs24000_Gain11_A2                               0         /* Floating point value 0.000000 */
 #define HPF_Fs24000_Gain11_B1                            8780         /* Floating point value 0.267949 */
 #define HPF_Fs24000_Gain11_B2                               0         /* Floating point value 0.000000 */
 #define HPF_Fs24000_Gain11_Shift                            2         /* Shift value */
                                                                     /* Gain =  12.000000 dB */
-#define HPF_Fs24000_Gain12_A0                           -6698         /* Floating point value -0.204411 */
+#define HPF_Fs24000_Gain12_A0                          (-6698)        /* Floating point value -0.204411 */
 #define HPF_Fs24000_Gain12_A1                           17015         /* Floating point value 0.519260 */
 #define HPF_Fs24000_Gain12_A2                               0         /* Floating point value 0.000000 */
 #define HPF_Fs24000_Gain12_B1                            8780         /* Floating point value 0.267949 */
 #define HPF_Fs24000_Gain12_B2                               0         /* Floating point value 0.000000 */
 #define HPF_Fs24000_Gain12_Shift                            2         /* Shift value */
                                                                     /* Gain =  13.000000 dB */
-#define HPF_Fs24000_Gain13_A0                           -4082         /* Floating point value -0.124576 */
+#define HPF_Fs24000_Gain13_A0                          (-4082)        /* Floating point value -0.124576 */
 #define HPF_Fs24000_Gain13_A1                            9253         /* Floating point value 0.282374 */
 #define HPF_Fs24000_Gain13_A2                               0         /* Floating point value 0.000000 */
 #define HPF_Fs24000_Gain13_B1                            8780         /* Floating point value 0.267949 */
 #define HPF_Fs24000_Gain13_B2                               0         /* Floating point value 0.000000 */
 #define HPF_Fs24000_Gain13_Shift                            3         /* Shift value */
                                                                     /* Gain =  14.000000 dB */
-#define HPF_Fs24000_Gain14_A0                           -4896         /* Floating point value -0.149404 */
+#define HPF_Fs24000_Gain14_A0                          (-4896)        /* Floating point value -0.149404 */
 #define HPF_Fs24000_Gain14_A1                           10066         /* Floating point value 0.307202 */
 #define HPF_Fs24000_Gain14_A2                               0         /* Floating point value 0.000000 */
 #define HPF_Fs24000_Gain14_B1                            8780         /* Floating point value 0.267949 */
 #define HPF_Fs24000_Gain14_B2                               0         /* Floating point value 0.000000 */
 #define HPF_Fs24000_Gain14_Shift                            3         /* Shift value */
                                                                     /* Gain =  15.000000 dB */
-#define HPF_Fs24000_Gain15_A0                           -5808         /* Floating point value -0.177261 */
+#define HPF_Fs24000_Gain15_A0                          (-5808)        /* Floating point value -0.177261 */
 #define HPF_Fs24000_Gain15_A1                           10979         /* Floating point value 0.335059 */
 #define HPF_Fs24000_Gain15_A2                               0         /* Floating point value 0.000000 */
 #define HPF_Fs24000_Gain15_B1                            8780         /* Floating point value 0.267949 */
@@ -249,105 +249,105 @@
 /* Coefficients for sample rate 32000Hz */
                                                                     /* Gain =  1.000000 dB */
 #define HPF_Fs32000_Gain1_A0                            17225         /* Floating point value 0.525677 */
-#define HPF_Fs32000_Gain1_A1                             -990         /* Floating point value -0.030227 */
+#define HPF_Fs32000_Gain1_A1                            (-990)        /* Floating point value -0.030227 */
 #define HPF_Fs32000_Gain1_A2                                0         /* Floating point value 0.000000 */
 #define HPF_Fs32000_Gain1_B1                                0         /* Floating point value -0.000000 */
 #define HPF_Fs32000_Gain1_B2                                0         /* Floating point value 0.000000 */
 #define HPF_Fs32000_Gain1_Shift                             1         /* Shift value */
                                                                     /* Gain =  2.000000 dB */
 #define HPF_Fs32000_Gain2_A0                            18337         /* Floating point value 0.559593 */
-#define HPF_Fs32000_Gain2_A1                            -2102         /* Floating point value -0.064142 */
+#define HPF_Fs32000_Gain2_A1                           (-2102)        /* Floating point value -0.064142 */
 #define HPF_Fs32000_Gain2_A2                                0         /* Floating point value 0.000000 */
 #define HPF_Fs32000_Gain2_B1                                0         /* Floating point value -0.000000 */
 #define HPF_Fs32000_Gain2_B2                                0         /* Floating point value 0.000000 */
 #define HPF_Fs32000_Gain2_Shift                             1         /* Shift value */
                                                                     /* Gain =  3.000000 dB */
 #define HPF_Fs32000_Gain3_A0                            19584         /* Floating point value 0.597646 */
-#define HPF_Fs32000_Gain3_A1                            -3349         /* Floating point value -0.102196 */
+#define HPF_Fs32000_Gain3_A1                           (-3349)        /* Floating point value -0.102196 */
 #define HPF_Fs32000_Gain3_A2                                0         /* Floating point value 0.000000 */
 #define HPF_Fs32000_Gain3_B1                                0         /* Floating point value -0.000000 */
 #define HPF_Fs32000_Gain3_B2                                0         /* Floating point value 0.000000 */
 #define HPF_Fs32000_Gain3_Shift                             1         /* Shift value */
                                                                     /* Gain =  4.000000 dB */
 #define HPF_Fs32000_Gain4_A0                            20983         /* Floating point value 0.640343 */
-#define HPF_Fs32000_Gain4_A1                            -4748         /* Floating point value -0.144893 */
+#define HPF_Fs32000_Gain4_A1                           (-4748)        /* Floating point value -0.144893 */
 #define HPF_Fs32000_Gain4_A2                                0         /* Floating point value 0.000000 */
 #define HPF_Fs32000_Gain4_B1                                0         /* Floating point value -0.000000 */
 #define HPF_Fs32000_Gain4_B2                                0         /* Floating point value 0.000000 */
 #define HPF_Fs32000_Gain4_Shift                             1         /* Shift value */
                                                                     /* Gain =  5.000000 dB */
 #define HPF_Fs32000_Gain5_A0                            22553         /* Floating point value 0.688250 */
-#define HPF_Fs32000_Gain5_A1                            -6318         /* Floating point value -0.192799 */
+#define HPF_Fs32000_Gain5_A1                           (-6318)        /* Floating point value -0.192799 */
 #define HPF_Fs32000_Gain5_A2                                0         /* Floating point value 0.000000 */
 #define HPF_Fs32000_Gain5_B1                                0         /* Floating point value -0.000000 */
 #define HPF_Fs32000_Gain5_B2                                0         /* Floating point value 0.000000 */
 #define HPF_Fs32000_Gain5_Shift                             1         /* Shift value */
                                                                     /* Gain =  6.000000 dB */
 #define HPF_Fs32000_Gain6_A0                            24314         /* Floating point value 0.742002 */
-#define HPF_Fs32000_Gain6_A1                            -8079         /* Floating point value -0.246551 */
+#define HPF_Fs32000_Gain6_A1                           (-8079)        /* Floating point value -0.246551 */
 #define HPF_Fs32000_Gain6_A2                                0         /* Floating point value 0.000000 */
 #define HPF_Fs32000_Gain6_B1                                0         /* Floating point value -0.000000 */
 #define HPF_Fs32000_Gain6_B2                                0         /* Floating point value 0.000000 */
 #define HPF_Fs32000_Gain6_Shift                             1         /* Shift value */
                                                                     /* Gain =  7.000000 dB */
 #define HPF_Fs32000_Gain7_A0                            13176         /* Floating point value 0.402109 */
-#define HPF_Fs32000_Gain7_A1                            -5040         /* Floating point value -0.153795 */
+#define HPF_Fs32000_Gain7_A1                           (-5040)        /* Floating point value -0.153795 */
 #define HPF_Fs32000_Gain7_A2                                0         /* Floating point value 0.000000 */
 #define HPF_Fs32000_Gain7_B1                                0         /* Floating point value -0.000000 */
 #define HPF_Fs32000_Gain7_B2                                0         /* Floating point value 0.000000 */
 #define HPF_Fs32000_Gain7_Shift                             2         /* Shift value */
                                                                     /* Gain =  8.000000 dB */
 #define HPF_Fs32000_Gain8_A0                            14288         /* Floating point value 0.436024 */
-#define HPF_Fs32000_Gain8_A1                            -6151         /* Floating point value -0.187711 */
+#define HPF_Fs32000_Gain8_A1                           (-6151)        /* Floating point value -0.187711 */
 #define HPF_Fs32000_Gain8_A2                                0         /* Floating point value 0.000000 */
 #define HPF_Fs32000_Gain8_B1                                0         /* Floating point value -0.000000 */
 #define HPF_Fs32000_Gain8_B2                                0         /* Floating point value 0.000000 */
 #define HPF_Fs32000_Gain8_Shift                             2         /* Shift value */
                                                                     /* Gain =  9.000000 dB */
 #define HPF_Fs32000_Gain9_A0                            15535         /* Floating point value 0.474078 */
-#define HPF_Fs32000_Gain9_A1                            -7398         /* Floating point value -0.225764 */
+#define HPF_Fs32000_Gain9_A1                           (-7398)        /* Floating point value -0.225764 */
 #define HPF_Fs32000_Gain9_A2                                0         /* Floating point value 0.000000 */
 #define HPF_Fs32000_Gain9_B1                                0         /* Floating point value -0.000000 */
 #define HPF_Fs32000_Gain9_B2                                0         /* Floating point value 0.000000 */
 #define HPF_Fs32000_Gain9_Shift                             2         /* Shift value */
                                                                     /* Gain =  10.000000 dB */
 #define HPF_Fs32000_Gain10_A0                           16934         /* Floating point value 0.516774 */
-#define HPF_Fs32000_Gain10_A1                           -8797         /* Floating point value -0.268461 */
+#define HPF_Fs32000_Gain10_A1                          (-8797)        /* Floating point value -0.268461 */
 #define HPF_Fs32000_Gain10_A2                               0         /* Floating point value 0.000000 */
 #define HPF_Fs32000_Gain10_B1                               0         /* Floating point value -0.000000 */
 #define HPF_Fs32000_Gain10_B2                               0         /* Floating point value 0.000000 */
 #define HPF_Fs32000_Gain10_Shift                            2         /* Shift value */
                                                                     /* Gain =  11.000000 dB */
 #define HPF_Fs32000_Gain11_A0                           18503         /* Floating point value 0.564681 */
-#define HPF_Fs32000_Gain11_A1                          -10367         /* Floating point value -0.316368 */
+#define HPF_Fs32000_Gain11_A1                         (-10367)        /* Floating point value -0.316368 */
 #define HPF_Fs32000_Gain11_A2                               0         /* Floating point value 0.000000 */
 #define HPF_Fs32000_Gain11_B1                               0         /* Floating point value -0.000000 */
 #define HPF_Fs32000_Gain11_B2                               0         /* Floating point value 0.000000 */
 #define HPF_Fs32000_Gain11_Shift                            2         /* Shift value */
                                                                     /* Gain =  12.000000 dB */
 #define HPF_Fs32000_Gain12_A0                           20265         /* Floating point value 0.618433 */
-#define HPF_Fs32000_Gain12_A1                          -12128         /* Floating point value -0.370120 */
+#define HPF_Fs32000_Gain12_A1                         (-12128)        /* Floating point value -0.370120 */
 #define HPF_Fs32000_Gain12_A2                               0         /* Floating point value 0.000000 */
 #define HPF_Fs32000_Gain12_B1                               0         /* Floating point value -0.000000 */
 #define HPF_Fs32000_Gain12_B2                               0         /* Floating point value 0.000000 */
 #define HPF_Fs32000_Gain12_Shift                            2         /* Shift value */
                                                                     /* Gain =  13.000000 dB */
 #define HPF_Fs32000_Gain13_A0                           11147         /* Floating point value 0.340178 */
-#define HPF_Fs32000_Gain13_A1                           -7069         /* Floating point value -0.215726 */
+#define HPF_Fs32000_Gain13_A1                          (-7069)        /* Floating point value -0.215726 */
 #define HPF_Fs32000_Gain13_A2                               0         /* Floating point value 0.000000 */
 #define HPF_Fs32000_Gain13_B1                               0         /* Floating point value -0.000000 */
 #define HPF_Fs32000_Gain13_B2                               0         /* Floating point value 0.000000 */
 #define HPF_Fs32000_Gain13_Shift                            3         /* Shift value */
                                                                     /* Gain =  14.000000 dB */
 #define HPF_Fs32000_Gain14_A0                           12258         /* Floating point value 0.374093 */
-#define HPF_Fs32000_Gain14_A1                           -8180         /* Floating point value -0.249642 */
+#define HPF_Fs32000_Gain14_A1                          (-8180)        /* Floating point value -0.249642 */
 #define HPF_Fs32000_Gain14_A2                               0         /* Floating point value 0.000000 */
 #define HPF_Fs32000_Gain14_B1                               0         /* Floating point value -0.000000 */
 #define HPF_Fs32000_Gain14_B2                               0         /* Floating point value 0.000000 */
 #define HPF_Fs32000_Gain14_Shift                            3         /* Shift value */
                                                                     /* Gain =  15.000000 dB */
 #define HPF_Fs32000_Gain15_A0                           13505         /* Floating point value 0.412147 */
-#define HPF_Fs32000_Gain15_A1                           -9427         /* Floating point value -0.287695 */
+#define HPF_Fs32000_Gain15_A1                          (-9427)        /* Floating point value -0.287695 */
 #define HPF_Fs32000_Gain15_A2                               0         /* Floating point value 0.000000 */
 #define HPF_Fs32000_Gain15_B1                               0         /* Floating point value -0.000000 */
 #define HPF_Fs32000_Gain15_B2                               0         /* Floating point value 0.000000 */
@@ -357,107 +357,107 @@
 /* Coefficients for sample rate 44100Hz */
                                                                     /* Gain =  1.000000 dB */
 #define HPF_Fs44100_Gain1_A0                            17442         /* Floating point value 0.532294 */
-#define HPF_Fs44100_Gain1_A1                            -4761         /* Floating point value -0.145294 */
+#define HPF_Fs44100_Gain1_A1                           (-4761)        /* Floating point value -0.145294 */
 #define HPF_Fs44100_Gain1_A2                                0         /* Floating point value 0.000000 */
-#define HPF_Fs44100_Gain1_B1                            -7173         /* Floating point value -0.218894 */
+#define HPF_Fs44100_Gain1_B1                           (-7173)        /* Floating point value -0.218894 */
 #define HPF_Fs44100_Gain1_B2                                0         /* Floating point value 0.000000 */
 #define HPF_Fs44100_Gain1_Shift                             1         /* Shift value */
                                                                     /* Gain =  2.000000 dB */
 #define HPF_Fs44100_Gain2_A0                            18797         /* Floating point value 0.573633 */
-#define HPF_Fs44100_Gain2_A1                            -6116         /* Floating point value -0.186634 */
+#define HPF_Fs44100_Gain2_A1                           (-6116)        /* Floating point value -0.186634 */
 #define HPF_Fs44100_Gain2_A2                                0         /* Floating point value 0.000000 */
-#define HPF_Fs44100_Gain2_B1                            -7173         /* Floating point value -0.218894 */
+#define HPF_Fs44100_Gain2_B1                           (-7173)        /* Floating point value -0.218894 */
 #define HPF_Fs44100_Gain2_B2                                0         /* Floating point value 0.000000 */
 #define HPF_Fs44100_Gain2_Shift                             1         /* Shift value */
                                                                     /* Gain =  3.000000 dB */
 #define HPF_Fs44100_Gain3_A0                            20317         /* Floating point value 0.620016 */
-#define HPF_Fs44100_Gain3_A1                            -7635         /* Floating point value -0.233017 */
+#define HPF_Fs44100_Gain3_A1                           (-7635)        /* Floating point value -0.233017 */
 #define HPF_Fs44100_Gain3_A2                                0         /* Floating point value 0.000000 */
-#define HPF_Fs44100_Gain3_B1                            -7173         /* Floating point value -0.218894 */
+#define HPF_Fs44100_Gain3_B1                           (-7173)        /* Floating point value -0.218894 */
 #define HPF_Fs44100_Gain3_B2                                0         /* Floating point value 0.000000 */
 #define HPF_Fs44100_Gain3_Shift                             1         /* Shift value */
                                                                     /* Gain =  4.000000 dB */
 #define HPF_Fs44100_Gain4_A0                            22022         /* Floating point value 0.672059 */
-#define HPF_Fs44100_Gain4_A1                            -9341         /* Floating point value -0.285060 */
+#define HPF_Fs44100_Gain4_A1                           (-9341)        /* Floating point value -0.285060 */
 #define HPF_Fs44100_Gain4_A2                                0         /* Floating point value 0.000000 */
-#define HPF_Fs44100_Gain4_B1                            -7173         /* Floating point value -0.218894 */
+#define HPF_Fs44100_Gain4_B1                           (-7173)        /* Floating point value -0.218894 */
 #define HPF_Fs44100_Gain4_B2                                0         /* Floating point value 0.000000 */
 #define HPF_Fs44100_Gain4_Shift                             1         /* Shift value */
                                                                     /* Gain =  5.000000 dB */
 #define HPF_Fs44100_Gain5_A0                            23935         /* Floating point value 0.730452 */
-#define HPF_Fs44100_Gain5_A1                           -11254         /* Floating point value -0.343453 */
+#define HPF_Fs44100_Gain5_A1                          (-11254)        /* Floating point value -0.343453 */
 #define HPF_Fs44100_Gain5_A2                                0         /* Floating point value 0.000000 */
-#define HPF_Fs44100_Gain5_B1                            -7173         /* Floating point value -0.218894 */
+#define HPF_Fs44100_Gain5_B1                           (-7173)        /* Floating point value -0.218894 */
 #define HPF_Fs44100_Gain5_B2                                0         /* Floating point value 0.000000 */
 #define HPF_Fs44100_Gain5_Shift                             1         /* Shift value */
                                                                     /* Gain =  6.000000 dB */
 #define HPF_Fs44100_Gain6_A0                            26082         /* Floating point value 0.795970 */
-#define HPF_Fs44100_Gain6_A1                           -13401         /* Floating point value -0.408971 */
+#define HPF_Fs44100_Gain6_A1                          (-13401)        /* Floating point value -0.408971 */
 #define HPF_Fs44100_Gain6_A2                                0         /* Floating point value 0.000000 */
-#define HPF_Fs44100_Gain6_B1                            -7173         /* Floating point value -0.218894 */
+#define HPF_Fs44100_Gain6_B1                           (-7173)        /* Floating point value -0.218894 */
 #define HPF_Fs44100_Gain6_B2                                0         /* Floating point value 0.000000 */
 #define HPF_Fs44100_Gain6_Shift                             1         /* Shift value */
                                                                     /* Gain =  7.000000 dB */
 #define HPF_Fs44100_Gain7_A0                            14279         /* Floating point value 0.435774 */
-#define HPF_Fs44100_Gain7_A1                            -7924         /* Floating point value -0.241815 */
+#define HPF_Fs44100_Gain7_A1                           (-7924)        /* Floating point value -0.241815 */
 #define HPF_Fs44100_Gain7_A2                                0         /* Floating point value 0.000000 */
-#define HPF_Fs44100_Gain7_B1                            -7173         /* Floating point value -0.218894 */
+#define HPF_Fs44100_Gain7_B1                           (-7173)        /* Floating point value -0.218894 */
 #define HPF_Fs44100_Gain7_B2                                0         /* Floating point value 0.000000 */
 #define HPF_Fs44100_Gain7_Shift                             2         /* Shift value */
                                                                     /* Gain =  8.000000 dB */
 #define HPF_Fs44100_Gain8_A0                            15634         /* Floating point value 0.477113 */
-#define HPF_Fs44100_Gain8_A1                            -9278         /* Floating point value -0.283154 */
+#define HPF_Fs44100_Gain8_A1                           (-9278)        /* Floating point value -0.283154 */
 #define HPF_Fs44100_Gain8_A2                                0         /* Floating point value 0.000000 */
-#define HPF_Fs44100_Gain8_B1                            -7173         /* Floating point value -0.218894 */
+#define HPF_Fs44100_Gain8_B1                           (-7173)        /* Floating point value -0.218894 */
 #define HPF_Fs44100_Gain8_B2                                0         /* Floating point value 0.000000 */
 #define HPF_Fs44100_Gain8_Shift                             2         /* Shift value */
                                                                     /* Gain =  9.000000 dB */
 #define HPF_Fs44100_Gain9_A0                            17154         /* Floating point value 0.523496 */
-#define HPF_Fs44100_Gain9_A1                           -10798         /* Floating point value -0.329537 */
+#define HPF_Fs44100_Gain9_A1                          (-10798)        /* Floating point value -0.329537 */
 #define HPF_Fs44100_Gain9_A2                                0         /* Floating point value 0.000000 */
-#define HPF_Fs44100_Gain9_B1                            -7173         /* Floating point value -0.218894 */
+#define HPF_Fs44100_Gain9_B1                           (-7173)        /* Floating point value -0.218894 */
 #define HPF_Fs44100_Gain9_B2                                0         /* Floating point value 0.000000 */
 #define HPF_Fs44100_Gain9_Shift                             2         /* Shift value */
                                                                     /* Gain =  10.000000 dB */
 #define HPF_Fs44100_Gain10_A0                           18859         /* Floating point value 0.575539 */
-#define HPF_Fs44100_Gain10_A1                          -12504         /* Floating point value -0.381580 */
+#define HPF_Fs44100_Gain10_A1                         (-12504)        /* Floating point value -0.381580 */
 #define HPF_Fs44100_Gain10_A2                               0         /* Floating point value 0.000000 */
-#define HPF_Fs44100_Gain10_B1                           -7173         /* Floating point value -0.218894 */
+#define HPF_Fs44100_Gain10_B1                          (-7173)        /* Floating point value -0.218894 */
 #define HPF_Fs44100_Gain10_B2                               0         /* Floating point value 0.000000 */
 #define HPF_Fs44100_Gain10_Shift                            2         /* Shift value */
                                                                     /* Gain =  11.000000 dB */
 #define HPF_Fs44100_Gain11_A0                           20773         /* Floating point value 0.633932 */
-#define HPF_Fs44100_Gain11_A1                          -14417         /* Floating point value -0.439973 */
+#define HPF_Fs44100_Gain11_A1                         (-14417)        /* Floating point value -0.439973 */
 #define HPF_Fs44100_Gain11_A2                               0         /* Floating point value 0.000000 */
-#define HPF_Fs44100_Gain11_B1                           -7173         /* Floating point value -0.218894 */
+#define HPF_Fs44100_Gain11_B1                          (-7173)        /* Floating point value -0.218894 */
 #define HPF_Fs44100_Gain11_B2                               0         /* Floating point value 0.000000 */
 #define HPF_Fs44100_Gain11_Shift                            2         /* Shift value */
                                                                     /* Gain =  12.000000 dB */
 #define HPF_Fs44100_Gain12_A0                           22920         /* Floating point value 0.699450 */
-#define HPF_Fs44100_Gain12_A1                          -16564         /* Floating point value -0.505491 */
+#define HPF_Fs44100_Gain12_A1                         (-16564)        /* Floating point value -0.505491 */
 #define HPF_Fs44100_Gain12_A2                               0         /* Floating point value 0.000000 */
-#define HPF_Fs44100_Gain12_B1                           -7173         /* Floating point value -0.218894 */
+#define HPF_Fs44100_Gain12_B1                          (-7173)        /* Floating point value -0.218894 */
 #define HPF_Fs44100_Gain12_B2                               0         /* Floating point value 0.000000 */
 #define HPF_Fs44100_Gain12_Shift                            2         /* Shift value */
                                                                     /* Gain =  13.000000 dB */
 #define HPF_Fs44100_Gain13_A0                           12694         /* Floating point value 0.387399 */
-#define HPF_Fs44100_Gain13_A1                           -9509         /* Floating point value -0.290189 */
+#define HPF_Fs44100_Gain13_A1                          (-9509)        /* Floating point value -0.290189 */
 #define HPF_Fs44100_Gain13_A2                               0         /* Floating point value 0.000000 */
-#define HPF_Fs44100_Gain13_B1                           -7173         /* Floating point value -0.218894 */
+#define HPF_Fs44100_Gain13_B1                          (-7173)        /* Floating point value -0.218894 */
 #define HPF_Fs44100_Gain13_B2                               0         /* Floating point value 0.000000 */
 #define HPF_Fs44100_Gain13_Shift                            3         /* Shift value */
                                                                     /* Gain =  14.000000 dB */
 #define HPF_Fs44100_Gain14_A0                           14049         /* Floating point value 0.428738 */
-#define HPF_Fs44100_Gain14_A1                          -10864         /* Floating point value -0.331528 */
+#define HPF_Fs44100_Gain14_A1                         (-10864)        /* Floating point value -0.331528 */
 #define HPF_Fs44100_Gain14_A2                               0         /* Floating point value 0.000000 */
-#define HPF_Fs44100_Gain14_B1                           -7173         /* Floating point value -0.218894 */
+#define HPF_Fs44100_Gain14_B1                          (-7173)        /* Floating point value -0.218894 */
 #define HPF_Fs44100_Gain14_B2                               0         /* Floating point value 0.000000 */
 #define HPF_Fs44100_Gain14_Shift                            3         /* Shift value */
                                                                     /* Gain =  15.000000 dB */
 #define HPF_Fs44100_Gain15_A0                           15569         /* Floating point value 0.475121 */
-#define HPF_Fs44100_Gain15_A1                          -12383         /* Floating point value -0.377912 */
+#define HPF_Fs44100_Gain15_A1                         (-12383)        /* Floating point value -0.377912 */
 #define HPF_Fs44100_Gain15_A2                               0         /* Floating point value 0.000000 */
-#define HPF_Fs44100_Gain15_B1                           -7173         /* Floating point value -0.218894 */
+#define HPF_Fs44100_Gain15_B1                          (-7173)        /* Floating point value -0.218894 */
 #define HPF_Fs44100_Gain15_B2                               0         /* Floating point value 0.000000 */
 #define HPF_Fs44100_Gain15_Shift                            3         /* Shift value */
 
@@ -465,107 +465,107 @@
 /* Coefficients for sample rate 48000Hz */
                                                                     /* Gain =  1.000000 dB */
 #define HPF_Fs48000_Gain1_A0                            17491         /* Floating point value 0.533777 */
-#define HPF_Fs48000_Gain1_A1                            -5606         /* Floating point value -0.171082 */
+#define HPF_Fs48000_Gain1_A1                           (-5606)        /* Floating point value -0.171082 */
 #define HPF_Fs48000_Gain1_A2                                0         /* Floating point value 0.000000 */
-#define HPF_Fs48000_Gain1_B1                            -8780         /* Floating point value -0.267949 */
+#define HPF_Fs48000_Gain1_B1                           (-8780)        /* Floating point value -0.267949 */
 #define HPF_Fs48000_Gain1_B2                                0         /* Floating point value 0.000000 */
 #define HPF_Fs48000_Gain1_Shift                             1         /* Shift value */
                                                                     /* Gain =  2.000000 dB */
 #define HPF_Fs48000_Gain2_A0                            18900         /* Floating point value 0.576779 */
-#define HPF_Fs48000_Gain2_A1                            -7015         /* Floating point value -0.214085 */
+#define HPF_Fs48000_Gain2_A1                           (-7015)        /* Floating point value -0.214085 */
 #define HPF_Fs48000_Gain2_A2                                0         /* Floating point value 0.000000 */
-#define HPF_Fs48000_Gain2_B1                            -8780         /* Floating point value -0.267949 */
+#define HPF_Fs48000_Gain2_B1                           (-8780)        /* Floating point value -0.267949 */
 #define HPF_Fs48000_Gain2_B2                                0         /* Floating point value 0.000000 */
 #define HPF_Fs48000_Gain2_Shift                             1         /* Shift value */
                                                                     /* Gain =  3.000000 dB */
 #define HPF_Fs48000_Gain3_A0                            20481         /* Floating point value 0.625029 */
-#define HPF_Fs48000_Gain3_A1                            -8596         /* Floating point value -0.262335 */
+#define HPF_Fs48000_Gain3_A1                           (-8596)        /* Floating point value -0.262335 */
 #define HPF_Fs48000_Gain3_A2                                0         /* Floating point value 0.000000 */
-#define HPF_Fs48000_Gain3_B1                            -8780         /* Floating point value -0.267949 */
+#define HPF_Fs48000_Gain3_B1                           (-8780)        /* Floating point value -0.267949 */
 #define HPF_Fs48000_Gain3_B2                                0         /* Floating point value 0.000000 */
 #define HPF_Fs48000_Gain3_Shift                             1         /* Shift value */
                                                                     /* Gain =  4.000000 dB */
 #define HPF_Fs48000_Gain4_A0                            22255         /* Floating point value 0.679167 */
-#define HPF_Fs48000_Gain4_A1                           -10370         /* Floating point value -0.316472 */
+#define HPF_Fs48000_Gain4_A1                          (-10370)        /* Floating point value -0.316472 */
 #define HPF_Fs48000_Gain4_A2                                0         /* Floating point value 0.000000 */
-#define HPF_Fs48000_Gain4_B1                            -8780         /* Floating point value -0.267949 */
+#define HPF_Fs48000_Gain4_B1                           (-8780)        /* Floating point value -0.267949 */
 #define HPF_Fs48000_Gain4_B2                                0         /* Floating point value 0.000000 */
 #define HPF_Fs48000_Gain4_Shift                             1         /* Shift value */
                                                                     /* Gain =  5.000000 dB */
 #define HPF_Fs48000_Gain5_A0                            24245         /* Floating point value 0.739910 */
-#define HPF_Fs48000_Gain5_A1                           -12361         /* Floating point value -0.377215 */
+#define HPF_Fs48000_Gain5_A1                          (-12361)        /* Floating point value -0.377215 */
 #define HPF_Fs48000_Gain5_A2                                0         /* Floating point value 0.000000 */
-#define HPF_Fs48000_Gain5_B1                            -8780         /* Floating point value -0.267949 */
+#define HPF_Fs48000_Gain5_B1                           (-8780)        /* Floating point value -0.267949 */
 #define HPF_Fs48000_Gain5_B2                                0         /* Floating point value 0.000000 */
 #define HPF_Fs48000_Gain5_Shift                             1         /* Shift value */
                                                                     /* Gain =  6.000000 dB */
 #define HPF_Fs48000_Gain6_A0                            26479         /* Floating point value 0.808065 */
-#define HPF_Fs48000_Gain6_A1                           -14594         /* Floating point value -0.445370 */
+#define HPF_Fs48000_Gain6_A1                          (-14594)        /* Floating point value -0.445370 */
 #define HPF_Fs48000_Gain6_A2                                0         /* Floating point value 0.000000 */
-#define HPF_Fs48000_Gain6_B1                            -8780         /* Floating point value -0.267949 */
+#define HPF_Fs48000_Gain6_B1                           (-8780)        /* Floating point value -0.267949 */
 #define HPF_Fs48000_Gain6_B2                                0         /* Floating point value 0.000000 */
 #define HPF_Fs48000_Gain6_Shift                             1         /* Shift value */
                                                                     /* Gain =  7.000000 dB */
 #define HPF_Fs48000_Gain7_A0                            14527         /* Floating point value 0.443318 */
-#define HPF_Fs48000_Gain7_A1                            -8570         /* Floating point value -0.261540 */
+#define HPF_Fs48000_Gain7_A1                           (-8570)        /* Floating point value -0.261540 */
 #define HPF_Fs48000_Gain7_A2                                0         /* Floating point value 0.000000 */
-#define HPF_Fs48000_Gain7_B1                            -8780         /* Floating point value -0.267949 */
+#define HPF_Fs48000_Gain7_B1                           (-8780)        /* Floating point value -0.267949 */
 #define HPF_Fs48000_Gain7_B2                                0         /* Floating point value 0.000000 */
 #define HPF_Fs48000_Gain7_Shift                             2         /* Shift value */
                                                                     /* Gain =  8.000000 dB */
 #define HPF_Fs48000_Gain8_A0                            15936         /* Floating point value 0.486321 */
-#define HPF_Fs48000_Gain8_A1                            -9979         /* Floating point value -0.304543 */
+#define HPF_Fs48000_Gain8_A1                           (-9979)        /* Floating point value -0.304543 */
 #define HPF_Fs48000_Gain8_A2                                0         /* Floating point value 0.000000 */
-#define HPF_Fs48000_Gain8_B1                            -8780         /* Floating point value -0.267949 */
+#define HPF_Fs48000_Gain8_B1                           (-8780)        /* Floating point value -0.267949 */
 #define HPF_Fs48000_Gain8_B2                                0         /* Floating point value 0.000000 */
 #define HPF_Fs48000_Gain8_Shift                             2         /* Shift value */
                                                                     /* Gain =  9.000000 dB */
 #define HPF_Fs48000_Gain9_A0                            17517         /* Floating point value 0.534571 */
-#define HPF_Fs48000_Gain9_A1                           -11560         /* Floating point value -0.352793 */
+#define HPF_Fs48000_Gain9_A1                          (-11560)        /* Floating point value -0.352793 */
 #define HPF_Fs48000_Gain9_A2                                0         /* Floating point value 0.000000 */
-#define HPF_Fs48000_Gain9_B1                            -8780         /* Floating point value -0.267949 */
+#define HPF_Fs48000_Gain9_B1                           (-8780)        /* Floating point value -0.267949 */
 #define HPF_Fs48000_Gain9_B2                                0         /* Floating point value 0.000000 */
 #define HPF_Fs48000_Gain9_Shift                             2         /* Shift value */
                                                                     /* Gain =  10.000000 dB */
 #define HPF_Fs48000_Gain10_A0                           19291         /* Floating point value 0.588708 */
-#define HPF_Fs48000_Gain10_A1                          -13334         /* Floating point value -0.406930 */
+#define HPF_Fs48000_Gain10_A1                         (-13334)        /* Floating point value -0.406930 */
 #define HPF_Fs48000_Gain10_A2                               0         /* Floating point value 0.000000 */
-#define HPF_Fs48000_Gain10_B1                           -8780         /* Floating point value -0.267949 */
+#define HPF_Fs48000_Gain10_B1                          (-8780)        /* Floating point value -0.267949 */
 #define HPF_Fs48000_Gain10_B2                               0         /* Floating point value 0.000000 */
 #define HPF_Fs48000_Gain10_Shift                            2         /* Shift value */
                                                                     /* Gain =  11.000000 dB */
 #define HPF_Fs48000_Gain11_A0                           21281         /* Floating point value 0.649452 */
-#define HPF_Fs48000_Gain11_A1                          -15325         /* Floating point value -0.467674 */
+#define HPF_Fs48000_Gain11_A1                         (-15325)        /* Floating point value -0.467674 */
 #define HPF_Fs48000_Gain11_A2                               0         /* Floating point value 0.000000 */
-#define HPF_Fs48000_Gain11_B1                           -8780         /* Floating point value -0.267949 */
+#define HPF_Fs48000_Gain11_B1                          (-8780)        /* Floating point value -0.267949 */
 #define HPF_Fs48000_Gain11_B2                               0         /* Floating point value 0.000000 */
 #define HPF_Fs48000_Gain11_Shift                            2         /* Shift value */
                                                                     /* Gain =  12.000000 dB */
 #define HPF_Fs48000_Gain12_A0                           23515         /* Floating point value 0.717607 */
-#define HPF_Fs48000_Gain12_A1                          -17558         /* Floating point value -0.535829 */
+#define HPF_Fs48000_Gain12_A1                         (-17558)        /* Floating point value -0.535829 */
 #define HPF_Fs48000_Gain12_A2                               0         /* Floating point value 0.000000 */
-#define HPF_Fs48000_Gain12_B1                           -8780         /* Floating point value -0.267949 */
+#define HPF_Fs48000_Gain12_B1                          (-8780)        /* Floating point value -0.267949 */
 #define HPF_Fs48000_Gain12_B2                               0         /* Floating point value 0.000000 */
 #define HPF_Fs48000_Gain12_Shift                            2         /* Shift value */
                                                                     /* Gain =  13.000000 dB */
 #define HPF_Fs48000_Gain13_A0                           13041         /* Floating point value 0.397982 */
-#define HPF_Fs48000_Gain13_A1                          -10056         /* Floating point value -0.306877 */
+#define HPF_Fs48000_Gain13_A1                         (-10056)        /* Floating point value -0.306877 */
 #define HPF_Fs48000_Gain13_A2                               0         /* Floating point value 0.000000 */
-#define HPF_Fs48000_Gain13_B1                           -8780         /* Floating point value -0.267949 */
+#define HPF_Fs48000_Gain13_B1                          (-8780)        /* Floating point value -0.267949 */
 #define HPF_Fs48000_Gain13_B2                               0         /* Floating point value 0.000000 */
 #define HPF_Fs48000_Gain13_Shift                            3         /* Shift value */
                                                                     /* Gain =  14.000000 dB */
 #define HPF_Fs48000_Gain14_A0                           14450         /* Floating point value 0.440984 */
-#define HPF_Fs48000_Gain14_A1                          -11465         /* Floating point value -0.349880 */
+#define HPF_Fs48000_Gain14_A1                         (-11465)        /* Floating point value -0.349880 */
 #define HPF_Fs48000_Gain14_A2                               0         /* Floating point value 0.000000 */
-#define HPF_Fs48000_Gain14_B1                           -8780         /* Floating point value -0.267949 */
+#define HPF_Fs48000_Gain14_B1                          (-8780)        /* Floating point value -0.267949 */
 #define HPF_Fs48000_Gain14_B2                               0         /* Floating point value 0.000000 */
 #define HPF_Fs48000_Gain14_Shift                            3         /* Shift value */
                                                                     /* Gain =  15.000000 dB */
 #define HPF_Fs48000_Gain15_A0                           16031         /* Floating point value 0.489234 */
-#define HPF_Fs48000_Gain15_A1                          -13046         /* Floating point value -0.398130 */
+#define HPF_Fs48000_Gain15_A1                         (-13046)        /* Floating point value -0.398130 */
 #define HPF_Fs48000_Gain15_A2                               0         /* Floating point value 0.000000 */
-#define HPF_Fs48000_Gain15_B1                           -8780         /* Floating point value -0.267949 */
+#define HPF_Fs48000_Gain15_B1                          (-8780)        /* Floating point value -0.267949 */
 #define HPF_Fs48000_Gain15_B2                               0         /* Floating point value 0.000000 */
 #define HPF_Fs48000_Gain15_Shift                            3         /* Shift value */
 
diff --git a/media/libeffects/lvm/lib/Bundle/src/LVM_Private.h b/media/libeffects/lvm/lib/Bundle/src/LVM_Private.h
index 2d1cf42..2e85f77 100644
--- a/media/libeffects/lvm/lib/Bundle/src/LVM_Private.h
+++ b/media/libeffects/lvm/lib/Bundle/src/LVM_Private.h
@@ -81,7 +81,7 @@
 #define LVM_TE_MIN_EFFECTLEVEL          0         /*TE Minimum EffectLevel*/
 #define LVM_TE_MAX_EFFECTLEVEL          15        /*TE Maximum Effect level*/
 
-#define LVM_VC_MIN_EFFECTLEVEL          -96       /*VC Minimum EffectLevel*/
+#define LVM_VC_MIN_EFFECTLEVEL          (-96)     /*VC Minimum EffectLevel*/
 #define LVM_VC_MAX_EFFECTLEVEL          0         /*VC Maximum Effect level*/
 
 #define LVM_BE_MIN_EFFECTLEVEL          0         /*BE Minimum EffectLevel*/
@@ -89,7 +89,7 @@
 
 #define LVM_EQNB_MIN_BAND_FREQ          20        /*EQNB Minimum Band Frequency*/
 #define LVM_EQNB_MAX_BAND_FREQ          24000     /*EQNB Maximum Band Frequency*/
-#define LVM_EQNB_MIN_BAND_GAIN          -15       /*EQNB Minimum Band Frequency*/
+#define LVM_EQNB_MIN_BAND_GAIN          (-15)     /*EQNB Minimum Band Frequency*/
 #define LVM_EQNB_MAX_BAND_GAIN          15        /*EQNB Maximum Band Frequency*/
 #define LVM_EQNB_MIN_QFACTOR            25        /*EQNB Minimum Q Factor*/
 #define LVM_EQNB_MAX_QFACTOR            1200      /*EQNB Maximum Q Factor*/
@@ -103,7 +103,7 @@
 
 #define LVM_VC_MIXER_TIME              100       /*VC mixer time*/
 #define LVM_VC_BALANCE_MAX             96        /*VC balance max value*/
-#define LVM_VC_BALANCE_MIN             -96       /*VC balance min value*/
+#define LVM_VC_BALANCE_MIN             (-96)     /*VC balance min value*/
 
 /* Algorithm masks */
 #define LVM_CS_MASK                     1
diff --git a/media/libeffects/lvm/lib/Common/lib/LVM_Types.h b/media/libeffects/lvm/lib/Common/lib/LVM_Types.h
index 0c6fb25..68c55f7 100644
--- a/media/libeffects/lvm/lib/Common/lib/LVM_Types.h
+++ b/media/libeffects/lvm/lib/Common/lib/LVM_Types.h
@@ -73,10 +73,10 @@
 #define LVM_MEM_EXTERNAL        8                   /* External (slow) access memory */
 
 /* Platform specific */
-#define LVM_PERSISTENT          LVM_MEM_PARTITION0+LVM_MEM_PERSISTENT+LVM_MEM_INTERNAL
-#define LVM_PERSISTENT_DATA     LVM_MEM_PARTITION1+LVM_MEM_PERSISTENT+LVM_MEM_INTERNAL
-#define LVM_PERSISTENT_COEF     LVM_MEM_PARTITION2+LVM_MEM_PERSISTENT+LVM_MEM_INTERNAL
-#define LVM_SCRATCH             LVM_MEM_PARTITION3+LVM_MEM_SCRATCH+LVM_MEM_INTERNAL
+#define LVM_PERSISTENT          (LVM_MEM_PARTITION0+LVM_MEM_PERSISTENT+LVM_MEM_INTERNAL)
+#define LVM_PERSISTENT_DATA     (LVM_MEM_PARTITION1+LVM_MEM_PERSISTENT+LVM_MEM_INTERNAL)
+#define LVM_PERSISTENT_COEF     (LVM_MEM_PARTITION2+LVM_MEM_PERSISTENT+LVM_MEM_INTERNAL)
+#define LVM_SCRATCH             (LVM_MEM_PARTITION3+LVM_MEM_SCRATCH+LVM_MEM_INTERNAL)
 
 /****************************************************************************************/
 /*                                                                                      */
diff --git a/media/libeffects/lvm/lib/Eq/src/LVEQNB_Coeffs.h b/media/libeffects/lvm/lib/Eq/src/LVEQNB_Coeffs.h
index 87d7145..95212f2 100644
--- a/media/libeffects/lvm/lib/Eq/src/LVEQNB_Coeffs.h
+++ b/media/libeffects/lvm/lib/Eq/src/LVEQNB_Coeffs.h
@@ -27,21 +27,21 @@
 /************************************************************************************/
 
 #define LVEQNB_GAINSHIFT                                   11         /* As a power of 2 */
-#define LVEQNB_Gain_Neg15_dB                            -1684         /* Floating point value -0.822172 */
-#define LVEQNB_Gain_Neg14_dB                            -1639         /* Floating point value -0.800474 */
-#define LVEQNB_Gain_Neg13_dB                            -1590         /* Floating point value -0.776128 */
-#define LVEQNB_Gain_Neg12_dB                            -1534         /* Floating point value -0.748811 */
-#define LVEQNB_Gain_Neg11_dB                            -1471         /* Floating point value -0.718162 */
-#define LVEQNB_Gain_Neg10_dB                            -1400         /* Floating point value -0.683772 */
-#define LVEQNB_Gain_Neg9_dB                             -1321         /* Floating point value -0.645187 */
-#define LVEQNB_Gain_Neg8_dB                             -1233         /* Floating point value -0.601893 */
-#define LVEQNB_Gain_Neg7_dB                             -1133         /* Floating point value -0.553316 */
-#define LVEQNB_Gain_Neg6_dB                             -1022         /* Floating point value -0.498813 */
-#define LVEQNB_Gain_Neg5_dB                              -896         /* Floating point value -0.437659 */
-#define LVEQNB_Gain_Neg4_dB                              -756         /* Floating point value -0.369043 */
-#define LVEQNB_Gain_Neg3_dB                              -598         /* Floating point value -0.292054 */
-#define LVEQNB_Gain_Neg2_dB                              -421         /* Floating point value -0.205672 */
-#define LVEQNB_Gain_Neg1_dB                              -223         /* Floating point value -0.108749 */
+#define LVEQNB_Gain_Neg15_dB                           (-1684)        /* Floating point value -0.822172 */
+#define LVEQNB_Gain_Neg14_dB                           (-1639)        /* Floating point value -0.800474 */
+#define LVEQNB_Gain_Neg13_dB                           (-1590)        /* Floating point value -0.776128 */
+#define LVEQNB_Gain_Neg12_dB                           (-1534)        /* Floating point value -0.748811 */
+#define LVEQNB_Gain_Neg11_dB                           (-1471)        /* Floating point value -0.718162 */
+#define LVEQNB_Gain_Neg10_dB                           (-1400)        /* Floating point value -0.683772 */
+#define LVEQNB_Gain_Neg9_dB                            (-1321)        /* Floating point value -0.645187 */
+#define LVEQNB_Gain_Neg8_dB                            (-1233)        /* Floating point value -0.601893 */
+#define LVEQNB_Gain_Neg7_dB                            (-1133)        /* Floating point value -0.553316 */
+#define LVEQNB_Gain_Neg6_dB                            (-1022)        /* Floating point value -0.498813 */
+#define LVEQNB_Gain_Neg5_dB                             (-896)        /* Floating point value -0.437659 */
+#define LVEQNB_Gain_Neg4_dB                             (-756)        /* Floating point value -0.369043 */
+#define LVEQNB_Gain_Neg3_dB                             (-598)        /* Floating point value -0.292054 */
+#define LVEQNB_Gain_Neg2_dB                             (-421)        /* Floating point value -0.205672 */
+#define LVEQNB_Gain_Neg1_dB                             (-223)        /* Floating point value -0.108749 */
 #define LVEQNB_Gain_0_dB                                    0         /* Floating point value 0.000000 */
 #define LVEQNB_Gain_1_dB                                  250         /* Floating point value 0.122018 */
 #define LVEQNB_Gain_2_dB                                  530         /* Floating point value 0.258925 */
diff --git a/media/libeffects/lvm/lib/SpectrumAnalyzer/src/LVPSA_Private.h b/media/libeffects/lvm/lib/SpectrumAnalyzer/src/LVPSA_Private.h
index 1d8bedd..03522fb 100644
--- a/media/libeffects/lvm/lib/SpectrumAnalyzer/src/LVPSA_Private.h
+++ b/media/libeffects/lvm/lib/SpectrumAnalyzer/src/LVPSA_Private.h
@@ -52,7 +52,7 @@
 #define LVPSA_NBANDSMIN                  1      /* Minimum number of frequency band                                 */
 #define LVPSA_NBANDSMAX                  30     /* Maximum number of frequency band                                 */
 #define LVPSA_MAXCENTERFREQ              20000  /* Maximum possible center frequency                                */
-#define LVPSA_MINPOSTGAIN                -15    /* Minimum possible post gain                                       */
+#define LVPSA_MINPOSTGAIN              (-15)    /* Minimum possible post gain                                       */
 #define LVPSA_MAXPOSTGAIN                15     /* Maximum possible post gain                                       */
 #define LVPSA_MINQFACTOR                 25     /* Minimum possible Q factor                                        */
 #define LVPSA_MAXQFACTOR                 1200   /* Maximum possible Q factor                                        */
diff --git a/media/libeffects/lvm/lib/StereoWidening/src/LVCS_Headphone_Coeffs.h b/media/libeffects/lvm/lib/StereoWidening/src/LVCS_Headphone_Coeffs.h
index 1d55281..3e640cb 100644
--- a/media/libeffects/lvm/lib/StereoWidening/src/LVCS_Headphone_Coeffs.h
+++ b/media/libeffects/lvm/lib/StereoWidening/src/LVCS_Headphone_Coeffs.h
@@ -27,127 +27,127 @@
 
 /* Stereo Enhancer coefficients for 8000 Hz sample rate, scaled with 0.161258 */
 #define CS_MIDDLE_8000_A0                          7462         /* Floating point value 0.227720 */
-#define CS_MIDDLE_8000_A1                         -7049         /* Floating point value -0.215125 */
+#define CS_MIDDLE_8000_A1                        (-7049)        /* Floating point value -0.215125 */
 #define CS_MIDDLE_8000_A2                             0         /* Floating point value 0.000000 */
-#define CS_MIDDLE_8000_B1                        -30209         /* Floating point value -0.921899 */
+#define CS_MIDDLE_8000_B1                       (-30209)        /* Floating point value -0.921899 */
 #define CS_MIDDLE_8000_B2                             0         /* Floating point value 0.000000 */
 #define CS_MIDDLE_8000_SCALE                         15
 #define CS_SIDE_8000_A0                           20036         /* Floating point value 0.611441 */
-#define CS_SIDE_8000_A1                          -12463         /* Floating point value -0.380344 */
-#define CS_SIDE_8000_A2                           -7573         /* Floating point value -0.231097 */
-#define CS_SIDE_8000_B1                          -20397         /* Floating point value -0.622470 */
-#define CS_SIDE_8000_B2                           -4285         /* Floating point value -0.130759 */
+#define CS_SIDE_8000_A1                         (-12463)        /* Floating point value -0.380344 */
+#define CS_SIDE_8000_A2                          (-7573)        /* Floating point value -0.231097 */
+#define CS_SIDE_8000_B1                         (-20397)        /* Floating point value -0.622470 */
+#define CS_SIDE_8000_B2                          (-4285)        /* Floating point value -0.130759 */
 #define CS_SIDE_8000_SCALE                           15
 
 /* Stereo Enhancer coefficients for 11025Hz sample rate, scaled with 0.162943 */
 #define CS_MIDDLE_11025_A0                         7564         /* Floating point value 0.230838 */
-#define CS_MIDDLE_11025_A1                        -7260         /* Floating point value -0.221559 */
+#define CS_MIDDLE_11025_A1                       (-7260)        /* Floating point value -0.221559 */
 #define CS_MIDDLE_11025_A2                            0         /* Floating point value 0.000000 */
-#define CS_MIDDLE_11025_B1                       -30902         /* Floating point value -0.943056 */
+#define CS_MIDDLE_11025_B1                      (-30902)        /* Floating point value -0.943056 */
 #define CS_MIDDLE_11025_B2                            0         /* Floating point value 0.000000 */
 #define CS_MIDDLE_11025_SCALE                        15
 #define CS_SIDE_11025_A0                          18264         /* Floating point value 0.557372 */
-#define CS_SIDE_11025_A1                         -12828         /* Floating point value -0.391490 */
-#define CS_SIDE_11025_A2                          -5436         /* Floating point value -0.165881 */
-#define CS_SIDE_11025_B1                         -28856         /* Floating point value -0.880608 */
+#define CS_SIDE_11025_A1                        (-12828)        /* Floating point value -0.391490 */
+#define CS_SIDE_11025_A2                         (-5436)        /* Floating point value -0.165881 */
+#define CS_SIDE_11025_B1                        (-28856)        /* Floating point value -0.880608 */
 #define CS_SIDE_11025_B2                           1062         /* Floating point value 0.032397 */
 #define CS_SIDE_11025_SCALE                          15
 
 /* Stereo Enhancer coefficients for 12000Hz sample rate, scaled with 0.162191 */
 #define CS_MIDDLE_12000_A0                         7534         /* Floating point value 0.229932 */
-#define CS_MIDDLE_12000_A1                        -7256         /* Floating point value -0.221436 */
+#define CS_MIDDLE_12000_A1                       (-7256)        /* Floating point value -0.221436 */
 #define CS_MIDDLE_12000_A2                            0         /* Floating point value 0.000000 */
-#define CS_MIDDLE_12000_B1                       -31051         /* Floating point value -0.947616 */
+#define CS_MIDDLE_12000_B1                      (-31051)        /* Floating point value -0.947616 */
 #define CS_MIDDLE_12000_B2                            0         /* Floating point value 0.000000 */
 #define CS_MIDDLE_12000_SCALE                        15
 #define CS_SIDE_12000_A0                          18298         /* Floating point value 0.558398 */
-#define CS_SIDE_12000_A1                         -12852         /* Floating point value -0.392211 */
-#define CS_SIDE_12000_A2                          -5446         /* Floating point value -0.166187 */
-#define CS_SIDE_12000_B1                         -29247         /* Floating point value -0.892550 */
+#define CS_SIDE_12000_A1                        (-12852)        /* Floating point value -0.392211 */
+#define CS_SIDE_12000_A2                         (-5446)        /* Floating point value -0.166187 */
+#define CS_SIDE_12000_B1                        (-29247)        /* Floating point value -0.892550 */
 #define CS_SIDE_12000_B2                           1077         /* Floating point value 0.032856 */
 #define CS_SIDE_12000_SCALE                          15
 
 /* Stereo Enhancer coefficients for 16000Hz sample rate, scaled with 0.162371 */
 #define CS_MIDDLE_16000_A0                         7558         /* Floating point value 0.230638 */
-#define CS_MIDDLE_16000_A1                        -7348         /* Floating point value -0.224232 */
+#define CS_MIDDLE_16000_A1                       (-7348)        /* Floating point value -0.224232 */
 #define CS_MIDDLE_16000_A2                            0         /* Floating point value 0.000000 */
-#define CS_MIDDLE_16000_B1                       -31475         /* Floating point value -0.960550 */
+#define CS_MIDDLE_16000_B1                      (-31475)        /* Floating point value -0.960550 */
 #define CS_MIDDLE_16000_B2                            0         /* Floating point value 0.000000 */
 #define CS_MIDDLE_16000_SCALE                        15
 #define CS_SIDE_16000_A0                           8187         /* Floating point value 0.499695 */
-#define CS_SIDE_16000_A1                          -5825         /* Floating point value -0.355543 */
-#define CS_SIDE_16000_A2                          -2362         /* Floating point value -0.144152 */
-#define CS_SIDE_16000_B1                         -17216         /* Floating point value -1.050788 */
+#define CS_SIDE_16000_A1                         (-5825)        /* Floating point value -0.355543 */
+#define CS_SIDE_16000_A2                         (-2362)        /* Floating point value -0.144152 */
+#define CS_SIDE_16000_B1                        (-17216)        /* Floating point value -1.050788 */
 #define CS_SIDE_16000_B2                           2361         /* Floating point value 0.144104 */
 #define CS_SIDE_16000_SCALE                          14
 
 /* Stereo Enhancer coefficients for 22050Hz sample rate, scaled with 0.160781 */
 #define CS_MIDDLE_22050_A0                         7496         /* Floating point value 0.228749 */
-#define CS_MIDDLE_22050_A1                        -7344         /* Floating point value -0.224128 */
+#define CS_MIDDLE_22050_A1                       (-7344)        /* Floating point value -0.224128 */
 #define CS_MIDDLE_22050_A2                            0         /* Floating point value 0.000000 */
-#define CS_MIDDLE_22050_B1                       -31826         /* Floating point value -0.971262 */
+#define CS_MIDDLE_22050_B1                      (-31826)        /* Floating point value -0.971262 */
 #define CS_MIDDLE_22050_B2                            0         /* Floating point value 0.000000 */
 #define CS_MIDDLE_22050_SCALE                        15
 #define CS_SIDE_22050_A0                           7211         /* Floating point value 0.440112 */
-#define CS_SIDE_22050_A1                          -4278         /* Floating point value -0.261096 */
-#define CS_SIDE_22050_A2                          -2933         /* Floating point value -0.179016 */
-#define CS_SIDE_22050_B1                         -18297         /* Floating point value -1.116786 */
+#define CS_SIDE_22050_A1                         (-4278)        /* Floating point value -0.261096 */
+#define CS_SIDE_22050_A2                         (-2933)        /* Floating point value -0.179016 */
+#define CS_SIDE_22050_B1                        (-18297)        /* Floating point value -1.116786 */
 #define CS_SIDE_22050_B2                           2990         /* Floating point value 0.182507 */
 #define CS_SIDE_22050_SCALE                          14
 
 /* Stereo Enhancer coefficients for 24000Hz sample rate, scaled with 0.161882 */
 #define CS_MIDDLE_24000_A0                         7550         /* Floating point value 0.230395 */
-#define CS_MIDDLE_24000_A1                        -7409         /* Floating point value -0.226117 */
+#define CS_MIDDLE_24000_A1                       (-7409)        /* Floating point value -0.226117 */
 #define CS_MIDDLE_24000_A2                            0         /* Floating point value 0.000000 */
-#define CS_MIDDLE_24000_B1                       -31902         /* Floating point value -0.973573 */
+#define CS_MIDDLE_24000_B1                      (-31902)        /* Floating point value -0.973573 */
 #define CS_MIDDLE_24000_B2                            0         /* Floating point value 0.000000 */
 #define CS_MIDDLE_24000_SCALE                        15
 #define CS_SIDE_24000_A0                           6796         /* Floating point value 0.414770 */
-#define CS_SIDE_24000_A1                          -4705         /* Floating point value -0.287182 */
-#define CS_SIDE_24000_A2                          -2090         /* Floating point value -0.127588 */
-#define CS_SIDE_24000_B1                         -20147         /* Floating point value -1.229648 */
+#define CS_SIDE_24000_A1                         (-4705)        /* Floating point value -0.287182 */
+#define CS_SIDE_24000_A2                         (-2090)        /* Floating point value -0.127588 */
+#define CS_SIDE_24000_B1                        (-20147)        /* Floating point value -1.229648 */
 #define CS_SIDE_24000_B2                           4623         /* Floating point value 0.282177 */
 #define CS_SIDE_24000_SCALE                          14
 
 /* Stereo Enhancer coefficients for 32000Hz sample rate, scaled with 0.160322 */
 #define CS_MIDDLE_32000_A0                         7484         /* Floating point value 0.228400 */
-#define CS_MIDDLE_32000_A1                        -7380         /* Floating point value -0.225214 */
+#define CS_MIDDLE_32000_A1                       (-7380)        /* Floating point value -0.225214 */
 #define CS_MIDDLE_32000_A2                            0         /* Floating point value 0.000000 */
-#define CS_MIDDLE_32000_B1                       -32117         /* Floating point value -0.980126 */
+#define CS_MIDDLE_32000_B1                      (-32117)        /* Floating point value -0.980126 */
 #define CS_MIDDLE_32000_B2                            0         /* Floating point value 0.000000 */
 #define CS_MIDDLE_32000_SCALE                        15
 #define CS_SIDE_32000_A0                           5973         /* Floating point value 0.364579 */
-#define CS_SIDE_32000_A1                          -3397         /* Floating point value -0.207355 */
-#define CS_SIDE_32000_A2                          -2576         /* Floating point value -0.157224 */
-#define CS_SIDE_32000_B1                         -20877         /* Floating point value -1.274231 */
+#define CS_SIDE_32000_A1                         (-3397)        /* Floating point value -0.207355 */
+#define CS_SIDE_32000_A2                         (-2576)        /* Floating point value -0.157224 */
+#define CS_SIDE_32000_B1                        (-20877)        /* Floating point value -1.274231 */
 #define CS_SIDE_32000_B2                           5120         /* Floating point value 0.312495 */
 #define CS_SIDE_32000_SCALE                          14
 
 /* Stereo Enhancer coefficients for 44100Hz sample rate, scaled with 0.163834 */
 #define CS_MIDDLE_44100_A0                         7654         /* Floating point value 0.233593 */
-#define CS_MIDDLE_44100_A1                        -7577         /* Floating point value -0.231225 */
+#define CS_MIDDLE_44100_A1                       (-7577)        /* Floating point value -0.231225 */
 #define CS_MIDDLE_44100_A2                            0         /* Floating point value 0.000000 */
-#define CS_MIDDLE_44100_B1                       -32294         /* Floating point value -0.985545 */
+#define CS_MIDDLE_44100_B1                      (-32294)        /* Floating point value -0.985545 */
 #define CS_MIDDLE_44100_B2                            0         /* Floating point value 0.000000 */
 #define CS_MIDDLE_44100_SCALE                        15
 #define CS_SIDE_44100_A0                           4662         /* Floating point value 0.284573 */
-#define CS_SIDE_44100_A1                          -4242         /* Floating point value -0.258910 */
-#define CS_SIDE_44100_A2                           -420         /* Floating point value -0.025662 */
-#define CS_SIDE_44100_B1                         -25760         /* Floating point value -1.572248 */
+#define CS_SIDE_44100_A1                         (-4242)        /* Floating point value -0.258910 */
+#define CS_SIDE_44100_A2                          (-420)        /* Floating point value -0.025662 */
+#define CS_SIDE_44100_B1                        (-25760)        /* Floating point value -1.572248 */
 #define CS_SIDE_44100_B2                           9640         /* Floating point value 0.588399 */
 #define CS_SIDE_44100_SCALE                          14
 
 /* Stereo Enhancer coefficients for 48000Hz sample rate, scaled with 0.164402 */
 #define CS_MIDDLE_48000_A0                         7682         /* Floating point value 0.234445 */
-#define CS_MIDDLE_48000_A1                        -7611         /* Floating point value -0.232261 */
+#define CS_MIDDLE_48000_A1                       (-7611)        /* Floating point value -0.232261 */
 #define CS_MIDDLE_48000_A2                            0         /* Floating point value 0.000000 */
-#define CS_MIDDLE_48000_B1                       -32333         /* Floating point value -0.986713 */
+#define CS_MIDDLE_48000_B1                      (-32333)        /* Floating point value -0.986713 */
 #define CS_MIDDLE_48000_B2                            0         /* Floating point value 0.000000 */
 #define CS_MIDDLE_48000_SCALE                        15
 #define CS_SIDE_48000_A0                           4466         /* Floating point value 0.272606 */
-#define CS_SIDE_48000_A1                          -4374         /* Floating point value -0.266952 */
-#define CS_SIDE_48000_A2                            -93         /* Floating point value -0.005654 */
-#define CS_SIDE_48000_B1                         -26495         /* Floating point value -1.617141 */
+#define CS_SIDE_48000_A1                         (-4374)        /* Floating point value -0.266952 */
+#define CS_SIDE_48000_A2                           (-93)        /* Floating point value -0.005654 */
+#define CS_SIDE_48000_B1                        (-26495)        /* Floating point value -1.617141 */
 #define CS_SIDE_48000_B2                          10329         /* Floating point value 0.630405 */
 #define CS_SIDE_48000_SCALE                          14
 
@@ -171,73 +171,73 @@
 
 /* Reverb coefficients for 8000 Hz sample rate, scaled with 1.038030 */
 #define CS_REVERB_8000_A0                         21865         /* Floating point value 0.667271 */
-#define CS_REVERB_8000_A1                        -21865         /* Floating point value -0.667271 */
+#define CS_REVERB_8000_A1                       (-21865)        /* Floating point value -0.667271 */
 #define CS_REVERB_8000_A2                             0         /* Floating point value 0.000000 */
-#define CS_REVERB_8000_B1                        -21895         /* Floating point value -0.668179 */
+#define CS_REVERB_8000_B1                       (-21895)        /* Floating point value -0.668179 */
 #define CS_REVERB_8000_B2                             0         /* Floating point value 0.000000 */
 #define CS_REVERB_8000_SCALE                         15
 
 /* Reverb coefficients for 11025Hz sample rate, scaled with 1.038030 */
 #define CS_REVERB_11025_A0                        22926         /* Floating point value 0.699638 */
-#define CS_REVERB_11025_A1                       -22926         /* Floating point value -0.699638 */
+#define CS_REVERB_11025_A1                      (-22926)        /* Floating point value -0.699638 */
 #define CS_REVERB_11025_A2                            0         /* Floating point value 0.000000 */
-#define CS_REVERB_11025_B1                       -24546         /* Floating point value -0.749096 */
+#define CS_REVERB_11025_B1                      (-24546)        /* Floating point value -0.749096 */
 #define CS_REVERB_11025_B2                            0         /* Floating point value 0.000000 */
 #define CS_REVERB_11025_SCALE                        15
 
 /* Reverb coefficients for 12000Hz sample rate, scaled with 1.038030 */
 #define CS_REVERB_12000_A0                        23165         /* Floating point value 0.706931 */
-#define CS_REVERB_12000_A1                       -23165         /* Floating point value -0.706931 */
+#define CS_REVERB_12000_A1                      (-23165)        /* Floating point value -0.706931 */
 #define CS_REVERB_12000_A2                            0         /* Floating point value 0.000000 */
-#define CS_REVERB_12000_B1                       -25144         /* Floating point value -0.767327 */
+#define CS_REVERB_12000_B1                      (-25144)        /* Floating point value -0.767327 */
 #define CS_REVERB_12000_B2                            0         /* Floating point value 0.000000 */
 #define CS_REVERB_12000_SCALE                        15
 
 /* Reverb coefficients for 16000Hz sample rate, scaled with 1.038030 */
 #define CS_REVERB_16000_A0                        23864         /* Floating point value 0.728272 */
-#define CS_REVERB_16000_A1                       -23864         /* Floating point value -0.728272 */
+#define CS_REVERB_16000_A1                      (-23864)        /* Floating point value -0.728272 */
 #define CS_REVERB_16000_A2                            0         /* Floating point value 0.000000 */
-#define CS_REVERB_16000_B1                       -26892         /* Floating point value -0.820679 */
+#define CS_REVERB_16000_B1                      (-26892)        /* Floating point value -0.820679 */
 #define CS_REVERB_16000_B2                            0         /* Floating point value 0.000000 */
 #define CS_REVERB_16000_SCALE                        15
 
 /* Reverb coefficients for 22050Hz sample rate, scaled with 1.038030 */
 #define CS_REVERB_22050_A0                        16921         /* Floating point value 0.516396 */
 #define CS_REVERB_22050_A1                            0         /* Floating point value 0.000000 */
-#define CS_REVERB_22050_A2                       -16921         /* Floating point value -0.516396 */
-#define CS_REVERB_22050_B1                       -16991         /* Floating point value -0.518512 */
-#define CS_REVERB_22050_B2                        -9535         /* Floating point value -0.290990 */
+#define CS_REVERB_22050_A2                      (-16921)        /* Floating point value -0.516396 */
+#define CS_REVERB_22050_B1                      (-16991)        /* Floating point value -0.518512 */
+#define CS_REVERB_22050_B2                       (-9535)        /* Floating point value -0.290990 */
 #define CS_REVERB_22050_SCALE                        15
 
 /* Reverb coefficients for 24000Hz sample rate, scaled with 1.038030 */
 #define CS_REVERB_24000_A0                        15714         /* Floating point value 0.479565 */
 #define CS_REVERB_24000_A1                            0         /* Floating point value 0.000000 */
-#define CS_REVERB_24000_A2                       -15714         /* Floating point value -0.479565 */
-#define CS_REVERB_24000_B1                       -20898         /* Floating point value -0.637745 */
-#define CS_REVERB_24000_B2                        -6518         /* Floating point value -0.198912 */
+#define CS_REVERB_24000_A2                      (-15714)        /* Floating point value -0.479565 */
+#define CS_REVERB_24000_B1                      (-20898)        /* Floating point value -0.637745 */
+#define CS_REVERB_24000_B2                       (-6518)        /* Floating point value -0.198912 */
 #define CS_REVERB_24000_SCALE                        15
 
 /* Reverb coefficients for 32000Hz sample rate, scaled with 1.038030 */
 #define CS_REVERB_32000_A0                        12463         /* Floating point value 0.380349 */
 #define CS_REVERB_32000_A1                            0         /* Floating point value 0.000000 */
-#define CS_REVERB_32000_A2                       -12463         /* Floating point value -0.380349 */
-#define CS_REVERB_32000_B1                       -31158         /* Floating point value -0.950873 */
+#define CS_REVERB_32000_A2                      (-12463)        /* Floating point value -0.380349 */
+#define CS_REVERB_32000_B1                      (-31158)        /* Floating point value -0.950873 */
 #define CS_REVERB_32000_B2                         1610         /* Floating point value 0.049127 */
 #define CS_REVERB_32000_SCALE                        15
 
 /* Reverb coefficients for 44100Hz sample rate, scaled with 1.038030 */
 #define CS_REVERB_44100_A0                         4872         /* Floating point value 0.297389 */
 #define CS_REVERB_44100_A1                            0         /* Floating point value 0.000000 */
-#define CS_REVERB_44100_A2                        -4872         /* Floating point value -0.297389 */
-#define CS_REVERB_44100_B1                       -19668         /* Floating point value -1.200423 */
+#define CS_REVERB_44100_A2                       (-4872)        /* Floating point value -0.297389 */
+#define CS_REVERB_44100_B1                      (-19668)        /* Floating point value -1.200423 */
 #define CS_REVERB_44100_B2                         4203         /* Floating point value 0.256529 */
 #define CS_REVERB_44100_SCALE                        14
 
 /* Reverb coefficients for 48000Hz sample rate, scaled with 1.038030 */
 #define CS_REVERB_48000_A0                         4566         /* Floating point value 0.278661 */
 #define CS_REVERB_48000_A1                            0         /* Floating point value 0.000000 */
-#define CS_REVERB_48000_A2                        -4566         /* Floating point value -0.278661 */
-#define CS_REVERB_48000_B1                       -20562         /* Floating point value -1.254993 */
+#define CS_REVERB_48000_A2                       (-4566)        /* Floating point value -0.278661 */
+#define CS_REVERB_48000_B1                      (-20562)        /* Floating point value -1.254993 */
 #define CS_REVERB_48000_B2                         4970         /* Floating point value 0.303347 */
 #define CS_REVERB_48000_SCALE                        14
 
@@ -257,128 +257,128 @@
 
 /* Equaliser coefficients for 8000 Hz sample rate, CS scaled with 1.038497 and CSEX scaled with 0.775480 */
 #define CS_EQUALISER_8000_A0                      20698         /* Floating point value 1.263312 */
-#define CS_EQUALISER_8000_A1                      -9859         /* Floating point value -0.601748 */
-#define CS_EQUALISER_8000_A2                      -4599         /* Floating point value -0.280681 */
-#define CS_EQUALISER_8000_B1                      -7797         /* Floating point value -0.475865 */
-#define CS_EQUALISER_8000_B2                      -6687         /* Floating point value -0.408154 */
+#define CS_EQUALISER_8000_A1                     (-9859)        /* Floating point value -0.601748 */
+#define CS_EQUALISER_8000_A2                     (-4599)        /* Floating point value -0.280681 */
+#define CS_EQUALISER_8000_B1                     (-7797)        /* Floating point value -0.475865 */
+#define CS_EQUALISER_8000_B2                     (-6687)        /* Floating point value -0.408154 */
 #define CS_EQUALISER_8000_SCALE                      14
 #define CSEX_EQUALISER_8000_A0                    30912         /* Floating point value 0.943357 */
-#define CSEX_EQUALISER_8000_A1                   -14724         /* Floating point value -0.449345 */
-#define CSEX_EQUALISER_8000_A2                    -6868         /* Floating point value -0.209594 */
-#define CSEX_EQUALISER_8000_B1                   -15593         /* Floating point value -0.475865 */
-#define CSEX_EQUALISER_8000_B2                   -13374         /* Floating point value -0.408154 */
+#define CSEX_EQUALISER_8000_A1                  (-14724)        /* Floating point value -0.449345 */
+#define CSEX_EQUALISER_8000_A2                   (-6868)        /* Floating point value -0.209594 */
+#define CSEX_EQUALISER_8000_B1                  (-15593)        /* Floating point value -0.475865 */
+#define CSEX_EQUALISER_8000_B2                  (-13374)        /* Floating point value -0.408154 */
 #define CSEX_EQUALISER_8000_SCALE                    15
 
 /* Equaliser coefficients for 11025Hz sample rate, CS scaled with 1.027761 and CSEX scaled with 0.767463 */
 #define CS_EQUALISER_11025_A0                     18041         /* Floating point value 1.101145 */
 #define CS_EQUALISER_11025_A1                      2278         /* Floating point value 0.139020 */
-#define CS_EQUALISER_11025_A2                    -14163         /* Floating point value -0.864423 */
+#define CS_EQUALISER_11025_A2                   (-14163)        /* Floating point value -0.864423 */
 #define CS_EQUALISER_11025_B1                       402         /* Floating point value 0.024541 */
-#define CS_EQUALISER_11025_B2                    -14892         /* Floating point value -0.908930 */
+#define CS_EQUALISER_11025_B2                   (-14892)        /* Floating point value -0.908930 */
 #define CS_EQUALISER_11025_SCALE                     14
 #define CSEX_EQUALISER_11025_A0                   31983         /* Floating point value 0.976058 */
-#define CSEX_EQUALISER_11025_A1                  -22784         /* Floating point value -0.695326 */
-#define CSEX_EQUALISER_11025_A2                   -2976         /* Floating point value -0.090809 */
-#define CSEX_EQUALISER_11025_B1                  -20008         /* Floating point value -0.610594 */
-#define CSEX_EQUALISER_11025_B2                  -10196         /* Floating point value -0.311149 */
+#define CSEX_EQUALISER_11025_A1                 (-22784)        /* Floating point value -0.695326 */
+#define CSEX_EQUALISER_11025_A2                  (-2976)        /* Floating point value -0.090809 */
+#define CSEX_EQUALISER_11025_B1                 (-20008)        /* Floating point value -0.610594 */
+#define CSEX_EQUALISER_11025_B2                 (-10196)        /* Floating point value -0.311149 */
 #define CSEX_EQUALISER_11025_SCALE                   15
 
 /* Equaliser coefficients for 12000Hz sample rate, CS scaled with 1.032521 and CSEX scaled with 0.771017 */
 #define CS_EQUALISER_12000_A0                     20917         /* Floating point value 1.276661 */
-#define CS_EQUALISER_12000_A1                    -16671         /* Floating point value -1.017519 */
-#define CS_EQUALISER_12000_A2                      -723         /* Floating point value -0.044128 */
-#define CS_EQUALISER_12000_B1                    -11954         /* Floating point value -0.729616 */
-#define CS_EQUALISER_12000_B2                     -3351         /* Floating point value -0.204532 */
+#define CS_EQUALISER_12000_A1                   (-16671)        /* Floating point value -1.017519 */
+#define CS_EQUALISER_12000_A2                     (-723)        /* Floating point value -0.044128 */
+#define CS_EQUALISER_12000_B1                   (-11954)        /* Floating point value -0.729616 */
+#define CS_EQUALISER_12000_B2                    (-3351)        /* Floating point value -0.204532 */
 #define CS_EQUALISER_12000_SCALE                     14
 #define CSEX_EQUALISER_12000_A0                   16500         /* Floating point value 1.007095 */
-#define CSEX_EQUALISER_12000_A1                  -14285         /* Floating point value -0.871912 */
+#define CSEX_EQUALISER_12000_A1                 (-14285)        /* Floating point value -0.871912 */
 #define CSEX_EQUALISER_12000_A2                     381         /* Floating point value 0.023232 */
-#define CSEX_EQUALISER_12000_B1                  -12220         /* Floating point value -0.745857 */
-#define CSEX_EQUALISER_12000_B2                   -3099         /* Floating point value -0.189171 */
+#define CSEX_EQUALISER_12000_B1                 (-12220)        /* Floating point value -0.745857 */
+#define CSEX_EQUALISER_12000_B2                  (-3099)        /* Floating point value -0.189171 */
 #define CSEX_EQUALISER_12000_SCALE                   14
 
 /* Equaliser coefficients for 16000Hz sample rate, CS scaled with 1.031378 and CSEX scaled with 0.770164 */
 #define CS_EQUALISER_16000_A0                     20998         /* Floating point value 1.281629 */
-#define CS_EQUALISER_16000_A1                    -17627         /* Floating point value -1.075872 */
-#define CS_EQUALISER_16000_A2                      -678         /* Floating point value -0.041365 */
-#define CS_EQUALISER_16000_B1                    -11882         /* Floating point value -0.725239 */
-#define CS_EQUALISER_16000_B2                     -3676         /* Floating point value -0.224358 */
+#define CS_EQUALISER_16000_A1                   (-17627)        /* Floating point value -1.075872 */
+#define CS_EQUALISER_16000_A2                     (-678)        /* Floating point value -0.041365 */
+#define CS_EQUALISER_16000_B1                   (-11882)        /* Floating point value -0.725239 */
+#define CS_EQUALISER_16000_B2                    (-3676)        /* Floating point value -0.224358 */
 #define CS_EQUALISER_16000_SCALE                     14
 #define CSEX_EQUALISER_16000_A0                   17713         /* Floating point value 1.081091 */
-#define CSEX_EQUALISER_16000_A1                  -14208         /* Floating point value -0.867183 */
-#define CSEX_EQUALISER_16000_A2                   -1151         /* Floating point value -0.070247 */
-#define CSEX_EQUALISER_16000_B1                   -8440         /* Floating point value -0.515121 */
-#define CSEX_EQUALISER_16000_B2                   -6978         /* Floating point value -0.425893 */
+#define CSEX_EQUALISER_16000_A1                 (-14208)        /* Floating point value -0.867183 */
+#define CSEX_EQUALISER_16000_A2                  (-1151)        /* Floating point value -0.070247 */
+#define CSEX_EQUALISER_16000_B1                  (-8440)        /* Floating point value -0.515121 */
+#define CSEX_EQUALISER_16000_B2                  (-6978)        /* Floating point value -0.425893 */
 #define CSEX_EQUALISER_16000_SCALE                   14
 
 /* Equaliser coefficients for 22050Hz sample rate, CS scaled with 1.041576 and CSEX scaled with 0.777779 */
 #define CS_EQUALISER_22050_A0                     22751         /* Floating point value 1.388605 */
-#define CS_EQUALISER_22050_A1                    -21394         /* Floating point value -1.305799 */
+#define CS_EQUALISER_22050_A1                   (-21394)        /* Floating point value -1.305799 */
 #define CS_EQUALISER_22050_A2                       654         /* Floating point value 0.039922 */
-#define CS_EQUALISER_22050_B1                    -11788         /* Floating point value -0.719494 */
-#define CS_EQUALISER_22050_B2                     -3985         /* Floating point value -0.243245 */
+#define CS_EQUALISER_22050_B1                   (-11788)        /* Floating point value -0.719494 */
+#define CS_EQUALISER_22050_B2                    (-3985)        /* Floating point value -0.243245 */
 #define CS_EQUALISER_22050_SCALE                     14
 #define CSEX_EQUALISER_22050_A0                   20855         /* Floating point value 1.272910 */
-#define CSEX_EQUALISER_22050_A1                  -21971         /* Floating point value -1.341014 */
+#define CSEX_EQUALISER_22050_A1                 (-21971)        /* Floating point value -1.341014 */
 #define CSEX_EQUALISER_22050_A2                    2744         /* Floating point value 0.167462 */
-#define CSEX_EQUALISER_22050_B1                  -10063         /* Floating point value -0.614219 */
-#define CSEX_EQUALISER_22050_B2                   -5659         /* Floating point value -0.345384 */
+#define CSEX_EQUALISER_22050_B1                 (-10063)        /* Floating point value -0.614219 */
+#define CSEX_EQUALISER_22050_B2                  (-5659)        /* Floating point value -0.345384 */
 #define CSEX_EQUALISER_22050_SCALE                   14
 
 /* Equaliser coefficients for 24000Hz sample rate, CS scaled with 1.034495 and CSEX scaled with 0.772491 */
 #define CS_EQUALISER_24000_A0                     23099         /* Floating point value 1.409832 */
-#define CS_EQUALISER_24000_A1                    -23863         /* Floating point value -1.456506 */
+#define CS_EQUALISER_24000_A1                   (-23863)        /* Floating point value -1.456506 */
 #define CS_EQUALISER_24000_A2                      2481         /* Floating point value 0.151410 */
-#define CS_EQUALISER_24000_B1                    -13176         /* Floating point value -0.804201 */
-#define CS_EQUALISER_24000_B2                     -2683         /* Floating point value -0.163783 */
+#define CS_EQUALISER_24000_B1                   (-13176)        /* Floating point value -0.804201 */
+#define CS_EQUALISER_24000_B2                    (-2683)        /* Floating point value -0.163783 */
 #define CS_EQUALISER_24000_SCALE                     14
 #define CSEX_EQUALISER_24000_A0                   21286         /* Floating point value 1.299198 */
-#define CSEX_EQUALISER_24000_A1                  -23797         /* Floating point value -1.452447 */
+#define CSEX_EQUALISER_24000_A1                 (-23797)        /* Floating point value -1.452447 */
 #define CSEX_EQUALISER_24000_A2                    3940         /* Floating point value 0.240489 */
-#define CSEX_EQUALISER_24000_B1                  -10966         /* Floating point value -0.669303 */
-#define CSEX_EQUALISER_24000_B2                   -4833         /* Floating point value -0.294984 */
+#define CSEX_EQUALISER_24000_B1                 (-10966)        /* Floating point value -0.669303 */
+#define CSEX_EQUALISER_24000_B2                  (-4833)        /* Floating point value -0.294984 */
 #define CSEX_EQUALISER_24000_SCALE                   14
 
 /* Equaliser coefficients for 32000Hz sample rate, CS scaled with 1.044559 and CSEX scaled with 0.780006 */
 #define CS_EQUALISER_32000_A0                     25575         /* Floating point value 1.560988 */
-#define CS_EQUALISER_32000_A1                    -30765         /* Floating point value -1.877724 */
+#define CS_EQUALISER_32000_A1                   (-30765)        /* Floating point value -1.877724 */
 #define CS_EQUALISER_32000_A2                      6386         /* Floating point value 0.389741 */
-#define CS_EQUALISER_32000_B1                    -14867         /* Floating point value -0.907410 */
-#define CS_EQUALISER_32000_B2                     -1155         /* Floating point value -0.070489 */
+#define CS_EQUALISER_32000_B1                   (-14867)        /* Floating point value -0.907410 */
+#define CS_EQUALISER_32000_B2                    (-1155)        /* Floating point value -0.070489 */
 #define CS_EQUALISER_32000_SCALE                     14
 #define CSEX_EQUALISER_32000_A0                   14623         /* Floating point value 1.785049 */
-#define CSEX_EQUALISER_32000_A1                  -18297         /* Floating point value -2.233497 */
+#define CSEX_EQUALISER_32000_A1                 (-18297)        /* Floating point value -2.233497 */
 #define CSEX_EQUALISER_32000_A2                    4313         /* Floating point value 0.526431 */
-#define CSEX_EQUALISER_32000_B1                   -3653         /* Floating point value -0.445939 */
-#define CSEX_EQUALISER_32000_B2                   -4280         /* Floating point value -0.522446 */
+#define CSEX_EQUALISER_32000_B1                  (-3653)        /* Floating point value -0.445939 */
+#define CSEX_EQUALISER_32000_B2                  (-4280)        /* Floating point value -0.522446 */
 #define CSEX_EQUALISER_32000_SCALE                   13
 
 /* Equaliser coefficients for 44100Hz sample rate, CS scaled with 1.022170 and CSEX scaled with 0.763288 */
 #define CS_EQUALISER_44100_A0                     13304         /* Floating point value 1.623993 */
-#define CS_EQUALISER_44100_A1                    -18602         /* Floating point value -2.270743 */
+#define CS_EQUALISER_44100_A1                   (-18602)        /* Floating point value -2.270743 */
 #define CS_EQUALISER_44100_A2                      5643         /* Floating point value 0.688829 */
-#define CS_EQUALISER_44100_B1                     -9152         /* Floating point value -1.117190 */
+#define CS_EQUALISER_44100_B1                    (-9152)        /* Floating point value -1.117190 */
 #define CS_EQUALISER_44100_B2                      1067         /* Floating point value 0.130208 */
 #define CS_EQUALISER_44100_SCALE                     13
 #define CSEX_EQUALISER_44100_A0                   16616         /* Floating point value 2.028315 */
-#define CSEX_EQUALISER_44100_A1                  -23613         /* Floating point value -2.882459 */
+#define CSEX_EQUALISER_44100_A1                 (-23613)        /* Floating point value -2.882459 */
 #define CSEX_EQUALISER_44100_A2                    7410         /* Floating point value 0.904535 */
-#define CSEX_EQUALISER_44100_B1                   -4860         /* Floating point value -0.593308 */
-#define CSEX_EQUALISER_44100_B2                   -3161         /* Floating point value -0.385816 */
+#define CSEX_EQUALISER_44100_B1                  (-4860)        /* Floating point value -0.593308 */
+#define CSEX_EQUALISER_44100_B2                  (-3161)        /* Floating point value -0.385816 */
 #define CSEX_EQUALISER_44100_SCALE                   13
 
 /* Equaliser coefficients for 48000Hz sample rate, CS scaled with 1.018635 and CSEX scaled with 0.760648 */
 #define CS_EQUALISER_48000_A0                     13445         /* Floating point value 1.641177 */
-#define CS_EQUALISER_48000_A1                    -19372         /* Floating point value -2.364687 */
+#define CS_EQUALISER_48000_A1                   (-19372)        /* Floating point value -2.364687 */
 #define CS_EQUALISER_48000_A2                      6225         /* Floating point value 0.759910 */
-#define CS_EQUALISER_48000_B1                     -9558         /* Floating point value -1.166774 */
+#define CS_EQUALISER_48000_B1                    (-9558)        /* Floating point value -1.166774 */
 #define CS_EQUALISER_48000_B2                      1459         /* Floating point value 0.178074 */
 #define CS_EQUALISER_48000_SCALE                     13
 #define CSEX_EQUALISER_48000_A0                   17200         /* Floating point value 2.099655 */
-#define CSEX_EQUALISER_48000_A1                  -25110         /* Floating point value -3.065220 */
+#define CSEX_EQUALISER_48000_A1                 (-25110)        /* Floating point value -3.065220 */
 #define CSEX_EQUALISER_48000_A2                    8277         /* Floating point value 1.010417 */
-#define CSEX_EQUALISER_48000_B1                   -5194         /* Floating point value -0.634021 */
-#define CSEX_EQUALISER_48000_B2                   -2845         /* Floating point value -0.347332 */
+#define CSEX_EQUALISER_48000_B1                  (-5194)        /* Floating point value -0.634021 */
+#define CSEX_EQUALISER_48000_B2                  (-2845)        /* Floating point value -0.347332 */
 #define CSEX_EQUALISER_48000_SCALE                   13
 
 
diff --git a/media/libeffects/lvm/wrapper/Android.mk b/media/libeffects/lvm/wrapper/Android.mk
index 68ba34c..4e38e3d 100644
--- a/media/libeffects/lvm/wrapper/Android.mk
+++ b/media/libeffects/lvm/wrapper/Android.mk
@@ -18,6 +18,7 @@
 LOCAL_STATIC_LIBRARIES += libmusicbundle
 
 LOCAL_SHARED_LIBRARIES := \
+     liblog \
      libcutils \
      libdl
 
@@ -47,6 +48,7 @@
 LOCAL_STATIC_LIBRARIES += libreverb
 
 LOCAL_SHARED_LIBRARIES := \
+     liblog \
      libcutils \
      libdl
 
diff --git a/media/libeffects/lvm/wrapper/Bundle/EffectBundle.cpp b/media/libeffects/lvm/wrapper/Bundle/EffectBundle.cpp
index a1892e4..d7b5f65 100644
--- a/media/libeffects/lvm/wrapper/Bundle/EffectBundle.cpp
+++ b/media/libeffects/lvm/wrapper/Bundle/EffectBundle.cpp
@@ -16,7 +16,7 @@
  */
 
 #define LOG_TAG "Bundle"
-#define ARRAY_SIZE(array) (sizeof array / sizeof array[0])
+#define ARRAY_SIZE(array) (sizeof (array) / sizeof (array)[0])
 //#define LOG_NDEBUG 0
 
 #include <assert.h>
@@ -34,19 +34,19 @@
 extern "C" const struct effect_interface_s gLvmEffectInterface;
 
 #define LVM_ERROR_CHECK(LvmStatus, callingFunc, calledFunc){\
-        if (LvmStatus == LVM_NULLADDRESS){\
+        if ((LvmStatus) == LVM_NULLADDRESS){\
             ALOGV("\tLVM_ERROR : Parameter error - "\
                     "null pointer returned by %s in %s\n\n\n\n", callingFunc, calledFunc);\
         }\
-        if (LvmStatus == LVM_ALIGNMENTERROR){\
+        if ((LvmStatus) == LVM_ALIGNMENTERROR){\
             ALOGV("\tLVM_ERROR : Parameter error - "\
                     "bad alignment returned by %s in %s\n\n\n\n", callingFunc, calledFunc);\
         }\
-        if (LvmStatus == LVM_INVALIDNUMSAMPLES){\
+        if ((LvmStatus) == LVM_INVALIDNUMSAMPLES){\
             ALOGV("\tLVM_ERROR : Parameter error - "\
                     "bad number of samples returned by %s in %s\n\n\n\n", callingFunc, calledFunc);\
         }\
-        if (LvmStatus == LVM_OUTOFRANGE){\
+        if ((LvmStatus) == LVM_OUTOFRANGE){\
             ALOGV("\tLVM_ERROR : Parameter error - "\
                     "out of range returned by %s in %s\n", callingFunc, calledFunc);\
         }\
diff --git a/media/libeffects/lvm/wrapper/Reverb/EffectReverb.cpp b/media/libeffects/lvm/wrapper/Reverb/EffectReverb.cpp
index 4dc8b45..f7dcdda 100644
--- a/media/libeffects/lvm/wrapper/Reverb/EffectReverb.cpp
+++ b/media/libeffects/lvm/wrapper/Reverb/EffectReverb.cpp
@@ -16,7 +16,7 @@
  */
 
 #define LOG_TAG "Reverb"
-#define ARRAY_SIZE(array) (sizeof array / sizeof array[0])
+#define ARRAY_SIZE(array) (sizeof (array) / sizeof (array)[0])
 //#define LOG_NDEBUG 0
 
 #include <assert.h>
@@ -34,15 +34,15 @@
 extern "C" const struct effect_interface_s gReverbInterface;
 
 #define LVM_ERROR_CHECK(LvmStatus, callingFunc, calledFunc){\
-        if (LvmStatus == LVREV_NULLADDRESS){\
+        if ((LvmStatus) == LVREV_NULLADDRESS){\
             ALOGV("\tLVREV_ERROR : Parameter error - "\
                     "null pointer returned by %s in %s\n\n\n\n", callingFunc, calledFunc);\
         }\
-        if (LvmStatus == LVREV_INVALIDNUMSAMPLES){\
+        if ((LvmStatus) == LVREV_INVALIDNUMSAMPLES){\
             ALOGV("\tLVREV_ERROR : Parameter error - "\
                     "bad number of samples returned by %s in %s\n\n\n\n", callingFunc, calledFunc);\
         }\
-        if (LvmStatus == LVREV_OUTOFRANGE){\
+        if ((LvmStatus) == LVREV_OUTOFRANGE){\
             ALOGV("\tLVREV_ERROR : Parameter error - "\
                     "out of range returned by %s in %s\n", callingFunc, calledFunc);\
         }\
diff --git a/media/libeffects/lvm/wrapper/Reverb/EffectReverb.h b/media/libeffects/lvm/wrapper/Reverb/EffectReverb.h
index 7c15b18..8165f5a 100644
--- a/media/libeffects/lvm/wrapper/Reverb/EffectReverb.h
+++ b/media/libeffects/lvm/wrapper/Reverb/EffectReverb.h
@@ -30,7 +30,7 @@
 #define LVREV_MAX_REVERB_LEVEL  2000
 #define LVREV_MAX_FRAME_SIZE    2560
 #define LVREV_CUP_LOAD_ARM9E    470    // Expressed in 0.1 MIPS
-#define LVREV_MEM_USAGE         71+(LVREV_MAX_FRAME_SIZE>>7)     // Expressed in kB
+#define LVREV_MEM_USAGE         (71+(LVREV_MAX_FRAME_SIZE>>7))     // Expressed in kB
 //#define LVM_PCM
 
 typedef struct _LPFPair_t
diff --git a/media/libeffects/preprocessing/Android.mk b/media/libeffects/preprocessing/Android.mk
index 4e4b094..bd67aa1 100644
--- a/media/libeffects/preprocessing/Android.mk
+++ b/media/libeffects/preprocessing/Android.mk
@@ -16,8 +16,6 @@
     external/webrtc/webrtc/modules/audio_processing/include \
     $(call include-path-for, audio-effects)
 
-LOCAL_C_INCLUDES += $(call include-path-for, speex)
-
 LOCAL_SHARED_LIBRARIES := \
     libwebrtc_audio_preprocessing \
     libspeexresampler \
diff --git a/media/libmedia/Android.bp b/media/libmedia/Android.bp
new file mode 100644
index 0000000..7fde4b2
--- /dev/null
+++ b/media/libmedia/Android.bp
@@ -0,0 +1,10 @@
+cc_library_static {
+    name: "libmedia_helper",
+    srcs: ["AudioParameter.cpp"],
+    cflags: [
+        "-Werror",
+        "-Wno-error=deprecated-declarations",
+        "-Wall",
+    ],
+    clang: true,
+}
diff --git a/media/libmedia/Android.mk b/media/libmedia/Android.mk
index 2bdfd43..202b5f8 100644
--- a/media/libmedia/Android.mk
+++ b/media/libmedia/Android.mk
@@ -3,18 +3,6 @@
 include $(CLEAR_VARS)
 
 LOCAL_SRC_FILES:= \
-    AudioParameter.cpp
-LOCAL_MODULE:= libmedia_helper
-LOCAL_MODULE_TAGS := optional
-
-LOCAL_CFLAGS += -Werror -Wno-error=deprecated-declarations -Wall
-LOCAL_CLANG := true
-
-include $(BUILD_STATIC_LIBRARY)
-
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES:= \
     AudioTrack.cpp \
     AudioTrackShared.cpp \
     IAudioFlinger.cpp \
@@ -80,6 +68,8 @@
         libcamera_client libstagefright_foundation \
         libgui libdl libaudioutils libnbaio
 
+LOCAL_EXPORT_SHARED_LIBRARY_HEADERS := libbinder
+
 LOCAL_WHOLE_STATIC_LIBRARIES := libmedia_helper
 
 # for memory heap analysis
diff --git a/media/libmedia/AudioSystem.cpp b/media/libmedia/AudioSystem.cpp
index 808b3ab..33974e0 100644
--- a/media/libmedia/AudioSystem.cpp
+++ b/media/libmedia/AudioSystem.cpp
@@ -1166,7 +1166,7 @@
     return aps->getPhoneState();
 }
 
-status_t AudioSystem::registerPolicyMixes(Vector<AudioMix> mixes, bool registration)
+status_t AudioSystem::registerPolicyMixes(const Vector<AudioMix>& mixes, bool registration)
 {
     const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
     if (aps == 0) return PERMISSION_DENIED;
diff --git a/media/libmedia/AudioTrack.cpp b/media/libmedia/AudioTrack.cpp
index 7663fef..c96f16a 100644
--- a/media/libmedia/AudioTrack.cpp
+++ b/media/libmedia/AudioTrack.cpp
@@ -2498,7 +2498,7 @@
     // This is sometimes caused by erratic reports of the available space in the ALSA drivers.
     if (status == NO_ERROR) {
         if (previousTimestampValid) {
-#define TIME_TO_NANOS(time) ((int64_t)time.tv_sec * 1000000000 + time.tv_nsec)
+#define TIME_TO_NANOS(time) ((int64_t)(time).tv_sec * 1000000000 + (time).tv_nsec)
             const int64_t previousTimeNanos = TIME_TO_NANOS(mPreviousTimestamp.mTime);
             const int64_t currentTimeNanos = TIME_TO_NANOS(timestamp.mTime);
 #undef TIME_TO_NANOS
diff --git a/media/libmedia/IAudioFlinger.cpp b/media/libmedia/IAudioFlinger.cpp
index 900d418..65fdedb 100644
--- a/media/libmedia/IAudioFlinger.cpp
+++ b/media/libmedia/IAudioFlinger.cpp
@@ -90,7 +90,7 @@
 class BpAudioFlinger : public BpInterface<IAudioFlinger>
 {
 public:
-    BpAudioFlinger(const sp<IBinder>& impl)
+    explicit BpAudioFlinger(const sp<IBinder>& impl)
         : BpInterface<IAudioFlinger>(impl)
     {
     }
diff --git a/media/libmedia/IAudioFlingerClient.cpp b/media/libmedia/IAudioFlingerClient.cpp
index 8dca9e9..b2dbc4c 100644
--- a/media/libmedia/IAudioFlingerClient.cpp
+++ b/media/libmedia/IAudioFlingerClient.cpp
@@ -34,7 +34,7 @@
 class BpAudioFlingerClient : public BpInterface<IAudioFlingerClient>
 {
 public:
-    BpAudioFlingerClient(const sp<IBinder>& impl)
+    explicit BpAudioFlingerClient(const sp<IBinder>& impl)
         : BpInterface<IAudioFlingerClient>(impl)
     {
     }
diff --git a/media/libmedia/IAudioPolicyService.cpp b/media/libmedia/IAudioPolicyService.cpp
index 6405d6d..946da8a 100644
--- a/media/libmedia/IAudioPolicyService.cpp
+++ b/media/libmedia/IAudioPolicyService.cpp
@@ -83,7 +83,7 @@
 class BpAudioPolicyService : public BpInterface<IAudioPolicyService>
 {
 public:
-    BpAudioPolicyService(const sp<IBinder>& impl)
+    explicit BpAudioPolicyService(const sp<IBinder>& impl)
         : BpInterface<IAudioPolicyService>(impl)
     {
     }
@@ -704,7 +704,7 @@
         return (audio_mode_t)reply.readInt32();
     }
 
-    virtual status_t registerPolicyMixes(Vector<AudioMix> mixes, bool registration)
+    virtual status_t registerPolicyMixes(const Vector<AudioMix>& mixes, bool registration)
     {
         Parcel data, reply;
         data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
diff --git a/media/libmedia/IAudioPolicyServiceClient.cpp b/media/libmedia/IAudioPolicyServiceClient.cpp
index 5f931e5..98a0521 100644
--- a/media/libmedia/IAudioPolicyServiceClient.cpp
+++ b/media/libmedia/IAudioPolicyServiceClient.cpp
@@ -52,7 +52,7 @@
 class BpAudioPolicyServiceClient : public BpInterface<IAudioPolicyServiceClient>
 {
 public:
-    BpAudioPolicyServiceClient(const sp<IBinder>& impl)
+    explicit BpAudioPolicyServiceClient(const sp<IBinder>& impl)
         : BpInterface<IAudioPolicyServiceClient>(impl)
     {
     }
diff --git a/media/libmedia/IAudioRecord.cpp b/media/libmedia/IAudioRecord.cpp
index ae66436..1331c0d 100644
--- a/media/libmedia/IAudioRecord.cpp
+++ b/media/libmedia/IAudioRecord.cpp
@@ -37,7 +37,7 @@
 class BpAudioRecord : public BpInterface<IAudioRecord>
 {
 public:
-    BpAudioRecord(const sp<IBinder>& impl)
+    explicit BpAudioRecord(const sp<IBinder>& impl)
         : BpInterface<IAudioRecord>(impl)
     {
     }
diff --git a/media/libmedia/IAudioTrack.cpp b/media/libmedia/IAudioTrack.cpp
index 636e3bb..89e0fcc 100644
--- a/media/libmedia/IAudioTrack.cpp
+++ b/media/libmedia/IAudioTrack.cpp
@@ -44,7 +44,7 @@
 class BpAudioTrack : public BpInterface<IAudioTrack>
 {
 public:
-    BpAudioTrack(const sp<IBinder>& impl)
+    explicit BpAudioTrack(const sp<IBinder>& impl)
         : BpInterface<IAudioTrack>(impl)
     {
     }
diff --git a/media/libmedia/ICrypto.cpp b/media/libmedia/ICrypto.cpp
index 302e6ee..7b261be 100644
--- a/media/libmedia/ICrypto.cpp
+++ b/media/libmedia/ICrypto.cpp
@@ -39,7 +39,7 @@
 };
 
 struct BpCrypto : public BpInterface<ICrypto> {
-    BpCrypto(const sp<IBinder> &impl)
+    explicit BpCrypto(const sp<IBinder> &impl)
         : BpInterface<ICrypto>(impl) {
     }
 
diff --git a/media/libmedia/IDataSource.cpp b/media/libmedia/IDataSource.cpp
index 51c9938..7df3b65 100644
--- a/media/libmedia/IDataSource.cpp
+++ b/media/libmedia/IDataSource.cpp
@@ -39,7 +39,8 @@
 };
 
 struct BpDataSource : public BpInterface<IDataSource> {
-    BpDataSource(const sp<IBinder>& impl) : BpInterface<IDataSource>(impl) {}
+    explicit BpDataSource(const sp<IBinder>& impl)
+        : BpInterface<IDataSource>(impl) {}
 
     virtual sp<IMemory> getIMemory() {
         Parcel data, reply;
diff --git a/media/libmedia/IDrm.cpp b/media/libmedia/IDrm.cpp
index 51a1130..c4558c6 100644
--- a/media/libmedia/IDrm.cpp
+++ b/media/libmedia/IDrm.cpp
@@ -59,7 +59,7 @@
 };
 
 struct BpDrm : public BpInterface<IDrm> {
-    BpDrm(const sp<IBinder> &impl)
+    explicit BpDrm(const sp<IBinder> &impl)
         : BpInterface<IDrm>(impl) {
     }
 
diff --git a/media/libmedia/IDrmClient.cpp b/media/libmedia/IDrmClient.cpp
index 490c6ed..444201f 100644
--- a/media/libmedia/IDrmClient.cpp
+++ b/media/libmedia/IDrmClient.cpp
@@ -35,7 +35,7 @@
 class BpDrmClient: public BpInterface<IDrmClient>
 {
 public:
-    BpDrmClient(const sp<IBinder>& impl)
+    explicit BpDrmClient(const sp<IBinder>& impl)
         : BpInterface<IDrmClient>(impl)
     {
     }
diff --git a/media/libmedia/IEffect.cpp b/media/libmedia/IEffect.cpp
index faf5795..115ca75 100644
--- a/media/libmedia/IEffect.cpp
+++ b/media/libmedia/IEffect.cpp
@@ -36,7 +36,7 @@
 class BpEffect: public BpInterface<IEffect>
 {
 public:
-    BpEffect(const sp<IBinder>& impl)
+    explicit BpEffect(const sp<IBinder>& impl)
         : BpInterface<IEffect>(impl)
     {
     }
diff --git a/media/libmedia/IEffectClient.cpp b/media/libmedia/IEffectClient.cpp
index 1322e72..3f2c67d 100644
--- a/media/libmedia/IEffectClient.cpp
+++ b/media/libmedia/IEffectClient.cpp
@@ -33,7 +33,7 @@
 class BpEffectClient: public BpInterface<IEffectClient>
 {
 public:
-    BpEffectClient(const sp<IBinder>& impl)
+    explicit BpEffectClient(const sp<IBinder>& impl)
         : BpInterface<IEffectClient>(impl)
     {
     }
diff --git a/media/libmedia/IHDCP.cpp b/media/libmedia/IHDCP.cpp
index f3a8902..21e35f6 100644
--- a/media/libmedia/IHDCP.cpp
+++ b/media/libmedia/IHDCP.cpp
@@ -37,7 +37,7 @@
 };
 
 struct BpHDCPObserver : public BpInterface<IHDCPObserver> {
-    BpHDCPObserver(const sp<IBinder> &impl)
+    explicit BpHDCPObserver(const sp<IBinder> &impl)
         : BpInterface<IHDCPObserver>(impl) {
     }
 
@@ -58,7 +58,7 @@
 IMPLEMENT_META_INTERFACE(HDCPObserver, "android.hardware.IHDCPObserver");
 
 struct BpHDCP : public BpInterface<IHDCP> {
-    BpHDCP(const sp<IBinder> &impl)
+    explicit BpHDCP(const sp<IBinder> &impl)
         : BpInterface<IHDCP>(impl) {
     }
 
diff --git a/media/libmedia/IMediaCodecList.cpp b/media/libmedia/IMediaCodecList.cpp
index 737f50c..806f46d 100644
--- a/media/libmedia/IMediaCodecList.cpp
+++ b/media/libmedia/IMediaCodecList.cpp
@@ -38,7 +38,7 @@
 class BpMediaCodecList: public BpInterface<IMediaCodecList>
 {
 public:
-    BpMediaCodecList(const sp<IBinder>& impl)
+    explicit BpMediaCodecList(const sp<IBinder>& impl)
         : BpInterface<IMediaCodecList>(impl)
     {
     }
diff --git a/media/libmedia/IMediaHTTPConnection.cpp b/media/libmedia/IMediaHTTPConnection.cpp
index 0dda0be9..e4b717b 100644
--- a/media/libmedia/IMediaHTTPConnection.cpp
+++ b/media/libmedia/IMediaHTTPConnection.cpp
@@ -38,7 +38,7 @@
 };
 
 struct BpMediaHTTPConnection : public BpInterface<IMediaHTTPConnection> {
-    BpMediaHTTPConnection(const sp<IBinder> &impl)
+    explicit BpMediaHTTPConnection(const sp<IBinder> &impl)
         : BpInterface<IMediaHTTPConnection>(impl) {
     }
 
diff --git a/media/libmedia/IMediaHTTPService.cpp b/media/libmedia/IMediaHTTPService.cpp
index 0c16a2b..062a07a 100644
--- a/media/libmedia/IMediaHTTPService.cpp
+++ b/media/libmedia/IMediaHTTPService.cpp
@@ -30,7 +30,7 @@
 };
 
 struct BpMediaHTTPService : public BpInterface<IMediaHTTPService> {
-    BpMediaHTTPService(const sp<IBinder> &impl)
+    explicit BpMediaHTTPService(const sp<IBinder> &impl)
         : BpInterface<IMediaHTTPService>(impl) {
     }
 
diff --git a/media/libmedia/IMediaLogService.cpp b/media/libmedia/IMediaLogService.cpp
index 1536337..bc445ff 100644
--- a/media/libmedia/IMediaLogService.cpp
+++ b/media/libmedia/IMediaLogService.cpp
@@ -34,7 +34,7 @@
 class BpMediaLogService : public BpInterface<IMediaLogService>
 {
 public:
-    BpMediaLogService(const sp<IBinder>& impl)
+    explicit BpMediaLogService(const sp<IBinder>& impl)
         : BpInterface<IMediaLogService>(impl)
     {
     }
diff --git a/media/libmedia/IMediaMetadataRetriever.cpp b/media/libmedia/IMediaMetadataRetriever.cpp
index 0bee8d3..7058ee8 100644
--- a/media/libmedia/IMediaMetadataRetriever.cpp
+++ b/media/libmedia/IMediaMetadataRetriever.cpp
@@ -75,7 +75,7 @@
 class BpMediaMetadataRetriever: public BpInterface<IMediaMetadataRetriever>
 {
 public:
-    BpMediaMetadataRetriever(const sp<IBinder>& impl)
+    explicit BpMediaMetadataRetriever(const sp<IBinder>& impl)
         : BpInterface<IMediaMetadataRetriever>(impl)
     {
     }
diff --git a/media/libmedia/IMediaPlayer.cpp b/media/libmedia/IMediaPlayer.cpp
index 519a1fd..f8345e4 100644
--- a/media/libmedia/IMediaPlayer.cpp
+++ b/media/libmedia/IMediaPlayer.cpp
@@ -72,7 +72,7 @@
 class BpMediaPlayer: public BpInterface<IMediaPlayer>
 {
 public:
-    BpMediaPlayer(const sp<IBinder>& impl)
+    explicit BpMediaPlayer(const sp<IBinder>& impl)
         : BpInterface<IMediaPlayer>(impl)
     {
     }
diff --git a/media/libmedia/IMediaPlayerClient.cpp b/media/libmedia/IMediaPlayerClient.cpp
index d608386..bbf8475 100644
--- a/media/libmedia/IMediaPlayerClient.cpp
+++ b/media/libmedia/IMediaPlayerClient.cpp
@@ -30,7 +30,7 @@
 class BpMediaPlayerClient: public BpInterface<IMediaPlayerClient>
 {
 public:
-    BpMediaPlayerClient(const sp<IBinder>& impl)
+    explicit BpMediaPlayerClient(const sp<IBinder>& impl)
         : BpInterface<IMediaPlayerClient>(impl)
     {
     }
diff --git a/media/libmedia/IMediaPlayerService.cpp b/media/libmedia/IMediaPlayerService.cpp
index 7590c1b..a01852c 100644
--- a/media/libmedia/IMediaPlayerService.cpp
+++ b/media/libmedia/IMediaPlayerService.cpp
@@ -50,7 +50,7 @@
 class BpMediaPlayerService: public BpInterface<IMediaPlayerService>
 {
 public:
-    BpMediaPlayerService(const sp<IBinder>& impl)
+    explicit BpMediaPlayerService(const sp<IBinder>& impl)
         : BpInterface<IMediaPlayerService>(impl)
     {
     }
diff --git a/media/libmedia/IMediaRecorder.cpp b/media/libmedia/IMediaRecorder.cpp
index cded55c..a6860e2 100644
--- a/media/libmedia/IMediaRecorder.cpp
+++ b/media/libmedia/IMediaRecorder.cpp
@@ -63,7 +63,7 @@
 class BpMediaRecorder: public BpInterface<IMediaRecorder>
 {
 public:
-    BpMediaRecorder(const sp<IBinder>& impl)
+    explicit BpMediaRecorder(const sp<IBinder>& impl)
     : BpInterface<IMediaRecorder>(impl)
     {
     }
diff --git a/media/libmedia/IMediaRecorderClient.cpp b/media/libmedia/IMediaRecorderClient.cpp
index 6795d23..a76f934 100644
--- a/media/libmedia/IMediaRecorderClient.cpp
+++ b/media/libmedia/IMediaRecorderClient.cpp
@@ -30,7 +30,7 @@
 class BpMediaRecorderClient: public BpInterface<IMediaRecorderClient>
 {
 public:
-    BpMediaRecorderClient(const sp<IBinder>& impl)
+    explicit BpMediaRecorderClient(const sp<IBinder>& impl)
         : BpInterface<IMediaRecorderClient>(impl)
     {
     }
diff --git a/media/libmedia/IOMX.cpp b/media/libmedia/IOMX.cpp
index 1090a83..ddfb6f1 100644
--- a/media/libmedia/IOMX.cpp
+++ b/media/libmedia/IOMX.cpp
@@ -66,7 +66,7 @@
 
 class BpOMX : public BpInterface<IOMX> {
 public:
-    BpOMX(const sp<IBinder> &impl)
+    explicit BpOMX(const sp<IBinder> &impl)
         : BpInterface<IOMX>(impl) {
     }
 
@@ -630,7 +630,7 @@
 ////////////////////////////////////////////////////////////////////////////////
 
 #define CHECK_OMX_INTERFACE(interface, data, reply) \
-        do { if (!data.enforceInterface(interface::getInterfaceDescriptor())) { \
+        do { if (!(data).enforceInterface(interface::getInterfaceDescriptor())) { \
             ALOGW("Call incorrectly routed to " #interface); \
             return PERMISSION_DENIED; \
         } } while (0)
@@ -1231,7 +1231,7 @@
 
 class BpOMXObserver : public BpInterface<IOMXObserver> {
 public:
-    BpOMXObserver(const sp<IBinder> &impl)
+    explicit BpOMXObserver(const sp<IBinder> &impl)
         : BpInterface<IOMXObserver>(impl) {
     }
 
diff --git a/media/libmedia/IRemoteDisplay.cpp b/media/libmedia/IRemoteDisplay.cpp
index 869d11a..85c7bd6 100644
--- a/media/libmedia/IRemoteDisplay.cpp
+++ b/media/libmedia/IRemoteDisplay.cpp
@@ -30,7 +30,7 @@
 class BpRemoteDisplay: public BpInterface<IRemoteDisplay>
 {
 public:
-    BpRemoteDisplay(const sp<IBinder>& impl)
+    explicit BpRemoteDisplay(const sp<IBinder>& impl)
         : BpInterface<IRemoteDisplay>(impl)
     {
     }
diff --git a/media/libmedia/IRemoteDisplayClient.cpp b/media/libmedia/IRemoteDisplayClient.cpp
index bedeb6c..ca67665 100644
--- a/media/libmedia/IRemoteDisplayClient.cpp
+++ b/media/libmedia/IRemoteDisplayClient.cpp
@@ -32,7 +32,7 @@
 class BpRemoteDisplayClient: public BpInterface<IRemoteDisplayClient>
 {
 public:
-    BpRemoteDisplayClient(const sp<IBinder>& impl)
+    explicit BpRemoteDisplayClient(const sp<IBinder>& impl)
         : BpInterface<IRemoteDisplayClient>(impl)
     {
     }
diff --git a/media/libmedia/IResourceManagerClient.cpp b/media/libmedia/IResourceManagerClient.cpp
index b3f56e8..1fea479 100644
--- a/media/libmedia/IResourceManagerClient.cpp
+++ b/media/libmedia/IResourceManagerClient.cpp
@@ -31,7 +31,7 @@
 class BpResourceManagerClient: public BpInterface<IResourceManagerClient>
 {
 public:
-    BpResourceManagerClient(const sp<IBinder> &impl)
+    explicit BpResourceManagerClient(const sp<IBinder> &impl)
         : BpInterface<IResourceManagerClient>(impl)
     {
     }
diff --git a/media/libmedia/IResourceManagerService.cpp b/media/libmedia/IResourceManagerService.cpp
index 6cb4440..95f7d2e 100644
--- a/media/libmedia/IResourceManagerService.cpp
+++ b/media/libmedia/IResourceManagerService.cpp
@@ -58,7 +58,7 @@
 class BpResourceManagerService : public BpInterface<IResourceManagerService>
 {
 public:
-    BpResourceManagerService(const sp<IBinder> &impl)
+    explicit BpResourceManagerService(const sp<IBinder> &impl)
         : BpInterface<IResourceManagerService>(impl)
     {
     }
diff --git a/media/libmedia/IStreamSource.cpp b/media/libmedia/IStreamSource.cpp
index 8c0905c..ba0a272 100644
--- a/media/libmedia/IStreamSource.cpp
+++ b/media/libmedia/IStreamSource.cpp
@@ -51,7 +51,7 @@
 };
 
 struct BpStreamSource : public BpInterface<IStreamSource> {
-    BpStreamSource(const sp<IBinder> &impl)
+    explicit BpStreamSource(const sp<IBinder> &impl)
         : BpInterface<IStreamSource>(impl) {
     }
 
@@ -145,7 +145,7 @@
 ////////////////////////////////////////////////////////////////////////////////
 
 struct BpStreamListener : public BpInterface<IStreamListener> {
-    BpStreamListener(const sp<IBinder> &impl)
+    explicit BpStreamListener(const sp<IBinder> &impl)
         : BpInterface<IStreamListener>(impl) {
     }
 
diff --git a/media/libmedia/MediaUtils.cpp b/media/libmedia/MediaUtils.cpp
index a02ca65..dc2bc82 100644
--- a/media/libmedia/MediaUtils.cpp
+++ b/media/libmedia/MediaUtils.cpp
@@ -31,6 +31,11 @@
     size_t numberOfBytes,
     size_t percentageOfTotalMem) {
 
+    if (running_with_asan()) {
+        ALOGW("Running with ASan, skip enforcing memory limitations.");
+        return;
+    }
+
     long pageSize = sysconf(_SC_PAGESIZE);
     long numPages = sysconf(_SC_PHYS_PAGES);
     size_t maxMem = SIZE_MAX;
diff --git a/media/libmedia/MediaUtils.h b/media/libmedia/MediaUtils.h
index f80dd30..a678bcc 100644
--- a/media/libmedia/MediaUtils.h
+++ b/media/libmedia/MediaUtils.h
@@ -19,6 +19,12 @@
 
 namespace android {
 
+extern "C" void __asan_init(void) __attribute__((weak));
+
+static inline int running_with_asan() {
+    return &__asan_init != 0;
+}
+
 /**
    Limit the amount of memory a process can allocate using setrlimit(RLIMIT_AS).
    The value to use will be read from the specified system property, or if the
diff --git a/media/libmediaplayerservice/Android.mk b/media/libmediaplayerservice/Android.mk
index 8d86366..98ccc42 100644
--- a/media/libmediaplayerservice/Android.mk
+++ b/media/libmediaplayerservice/Android.mk
@@ -43,6 +43,8 @@
     libstagefright_rtsp         \
     libstagefright_timedtext    \
 
+LOCAL_EXPORT_SHARED_LIBRARY_HEADERS := libmedia
+
 LOCAL_C_INCLUDES :=                                                 \
     $(TOP)/frameworks/av/media/libstagefright/include               \
     $(TOP)/frameworks/av/media/libstagefright/rtsp                  \
@@ -53,7 +55,6 @@
     $(TOP)/frameworks/native/include/media/openmax                  \
     $(TOP)/frameworks/native/include/media/hardware                 \
     $(TOP)/external/tremolo/Tremolo                                 \
-    libcore/include                                                 \
 
 LOCAL_CFLAGS += -Werror -Wno-error=deprecated-declarations -Wall
 LOCAL_CLANG := true
diff --git a/media/libmediaplayerservice/HDCP.h b/media/libmediaplayerservice/HDCP.h
index 26ddc86..83c61b5 100644
--- a/media/libmediaplayerservice/HDCP.h
+++ b/media/libmediaplayerservice/HDCP.h
@@ -24,7 +24,7 @@
 namespace android {
 
 struct HDCP : public BnHDCP {
-    HDCP(bool createEncryptionModule);
+    explicit HDCP(bool createEncryptionModule);
     virtual ~HDCP();
 
     virtual status_t setObserver(const sp<IHDCPObserver> &observer);
diff --git a/media/libmediaplayerservice/MediaPlayerService.cpp b/media/libmediaplayerservice/MediaPlayerService.cpp
index bd16e91..95c91d1 100644
--- a/media/libmediaplayerservice/MediaPlayerService.cpp
+++ b/media/libmediaplayerservice/MediaPlayerService.cpp
@@ -307,7 +307,7 @@
     return recorder;
 }
 
-void MediaPlayerService::removeMediaRecorderClient(wp<MediaRecorderClient> client)
+void MediaPlayerService::removeMediaRecorderClient(const wp<MediaRecorderClient>& client)
 {
     Mutex::Autolock lock(mLock);
     mMediaRecorderClients.remove(client);
@@ -552,7 +552,7 @@
     return NO_ERROR;
 }
 
-void MediaPlayerService::removeClient(wp<Client> client)
+void MediaPlayerService::removeClient(const wp<Client>& client)
 {
     Mutex::Autolock lock(mLock);
     mClients.remove(client);
diff --git a/media/libmediaplayerservice/MediaPlayerService.h b/media/libmediaplayerservice/MediaPlayerService.h
index 7a41d9c..601b046 100644
--- a/media/libmediaplayerservice/MediaPlayerService.h
+++ b/media/libmediaplayerservice/MediaPlayerService.h
@@ -169,7 +169,7 @@
         class CallbackData {
             friend AudioOutput;
         public:
-            CallbackData(AudioOutput *cookie) {
+            explicit CallbackData(AudioOutput *cookie) {
                 mData = cookie;
                 mSwitching = false;
             }
@@ -212,7 +212,7 @@
 
     // IMediaPlayerService interface
     virtual sp<IMediaRecorder>  createMediaRecorder(const String16 &opPackageName);
-    void    removeMediaRecorderClient(wp<MediaRecorderClient> client);
+    void    removeMediaRecorderClient(const wp<MediaRecorderClient>& client);
     virtual sp<IMediaMetadataRetriever> createMetadataRetriever();
 
     virtual sp<IMediaPlayer>    create(const sp<IMediaPlayerClient>& client,
@@ -226,7 +226,7 @@
             const sp<IRemoteDisplayClient>& client, const String8& iface);
     virtual status_t            dump(int fd, const Vector<String16>& args);
 
-            void                removeClient(wp<Client> client);
+            void                removeClient(const wp<Client>& client);
             bool                hasClient(wp<Client> client);
 
     enum {
diff --git a/media/libmediaplayerservice/StagefrightRecorder.cpp b/media/libmediaplayerservice/StagefrightRecorder.cpp
index bd1fd7c..cdb0a7b 100644
--- a/media/libmediaplayerservice/StagefrightRecorder.cpp
+++ b/media/libmediaplayerservice/StagefrightRecorder.cpp
@@ -1493,7 +1493,7 @@
 }
 
 status_t StagefrightRecorder::setupVideoEncoder(
-        sp<MediaSource> cameraSource,
+        const sp<MediaSource> &cameraSource,
         sp<MediaCodecSource> *source) {
     source->clear();
 
diff --git a/media/libmediaplayerservice/StagefrightRecorder.h b/media/libmediaplayerservice/StagefrightRecorder.h
index d7f43bc..4dbd039 100644
--- a/media/libmediaplayerservice/StagefrightRecorder.h
+++ b/media/libmediaplayerservice/StagefrightRecorder.h
@@ -44,7 +44,7 @@
 struct ALooper;
 
 struct StagefrightRecorder : public MediaRecorderBase {
-    StagefrightRecorder(const String16 &opPackageName);
+    explicit StagefrightRecorder(const String16 &opPackageName);
     virtual ~StagefrightRecorder();
 
     virtual status_t init();
@@ -59,9 +59,9 @@
     virtual status_t setPreviewSurface(const sp<IGraphicBufferProducer>& surface);
     virtual status_t setInputSurface(const sp<IGraphicBufferConsumer>& surface);
     virtual status_t setOutputFile(int fd, int64_t offset, int64_t length);
-    virtual status_t setParameters(const String8& params);
-    virtual status_t setListener(const sp<IMediaRecorderClient>& listener);
-    virtual status_t setClientName(const String16& clientName);
+    virtual status_t setParameters(const String8 &params);
+    virtual status_t setListener(const sp<IMediaRecorderClient> &listener);
+    virtual status_t setClientName(const String16 &clientName);
     virtual status_t prepare();
     virtual status_t start();
     virtual status_t pause();
@@ -70,7 +70,7 @@
     virtual status_t close();
     virtual status_t reset();
     virtual status_t getMaxAmplitude(int *max);
-    virtual status_t dump(int fd, const Vector<String16>& args) const;
+    virtual status_t dump(int fd, const Vector<String16> &args) const;
     // Querying a SurfaceMediaSourcer
     virtual sp<IGraphicBufferProducer> querySurfaceMediaSource() const;
 
@@ -158,7 +158,7 @@
     status_t setupMediaSource(sp<MediaSource> *mediaSource);
     status_t setupCameraSource(sp<CameraSource> *cameraSource);
     status_t setupAudioEncoder(const sp<MediaWriter>& writer);
-    status_t setupVideoEncoder(sp<MediaSource> cameraSource, sp<MediaCodecSource> *source);
+    status_t setupVideoEncoder(const sp<MediaSource>& cameraSource, sp<MediaCodecSource> *source);
 
     // Encoding parameter handling utilities
     status_t setParameter(const String8 &key, const String8 &value);
diff --git a/media/libmediaplayerservice/nuplayer/Android.mk b/media/libmediaplayerservice/nuplayer/Android.mk
index cd20837..3ea2159 100644
--- a/media/libmediaplayerservice/nuplayer/Android.mk
+++ b/media/libmediaplayerservice/nuplayer/Android.mk
@@ -34,6 +34,8 @@
 
 LOCAL_CLANG := true
 
+LOCAL_SHARED_LIBRARIES := libmedia
+
 LOCAL_MODULE:= libstagefright_nuplayer
 
 LOCAL_MODULE_TAGS := eng
diff --git a/media/libmediaplayerservice/nuplayer/GenericSource.cpp b/media/libmediaplayerservice/nuplayer/GenericSource.cpp
index af2d0f3..6b88404 100644
--- a/media/libmediaplayerservice/nuplayer/GenericSource.cpp
+++ b/media/libmediaplayerservice/nuplayer/GenericSource.cpp
@@ -741,8 +741,8 @@
         uint32_t sendWhat,
         media_track_type type,
         int32_t curGen,
-        sp<AnotherPacketSource> packets,
-        sp<AMessage> msg) {
+        const sp<AnotherPacketSource>& packets,
+        const sp<AMessage>& msg) {
     int32_t msgGeneration;
     CHECK(msg->findInt32("generation", &msgGeneration));
     if (msgGeneration != curGen) {
@@ -775,8 +775,8 @@
         uint32_t what,
         media_track_type type,
         int32_t curGen,
-        sp<AnotherPacketSource> packets,
-        sp<AMessage> msg) {
+        const sp<AnotherPacketSource>& packets,
+        const sp<AMessage>& msg) {
     int32_t msgGeneration;
     CHECK(msg->findInt32("generation", &msgGeneration));
     if (msgGeneration != curGen) {
@@ -851,7 +851,7 @@
     }
 }
 
-void NuPlayer::GenericSource::onGetFormatMeta(sp<AMessage> msg) const {
+void NuPlayer::GenericSource::onGetFormatMeta(const sp<AMessage>& msg) const {
     int32_t audio;
     CHECK(msg->findInt32("audio", &audio));
 
@@ -1023,7 +1023,7 @@
     }
 }
 
-void NuPlayer::GenericSource::onGetSelectedTrack(sp<AMessage> msg) const {
+void NuPlayer::GenericSource::onGetSelectedTrack(const sp<AMessage>& msg) const {
     int32_t tmpType;
     CHECK(msg->findInt32("type", &tmpType));
     media_track_type type = (media_track_type)tmpType;
@@ -1079,7 +1079,7 @@
     return err;
 }
 
-void NuPlayer::GenericSource::onSelectTrack(sp<AMessage> msg) {
+void NuPlayer::GenericSource::onSelectTrack(const sp<AMessage>& msg) {
     int32_t trackIndex, select;
     int64_t timeUs;
     CHECK(msg->findInt32("trackIndex", &trackIndex));
@@ -1199,7 +1199,7 @@
     return err;
 }
 
-void NuPlayer::GenericSource::onSeek(sp<AMessage> msg) {
+void NuPlayer::GenericSource::onSeek(const sp<AMessage>& msg) {
     int64_t seekTimeUs;
     CHECK(msg->findInt64("seekTimeUs", &seekTimeUs));
 
@@ -1358,7 +1358,7 @@
     }
 }
 
-void NuPlayer::GenericSource::onReadBuffer(sp<AMessage> msg) {
+void NuPlayer::GenericSource::onReadBuffer(const sp<AMessage>& msg) {
     int32_t tmpType;
     CHECK(msg->findInt32("trackType", &tmpType));
     media_track_type trackType = (media_track_type)tmpType;
diff --git a/media/libmediaplayerservice/nuplayer/GenericSource.h b/media/libmediaplayerservice/nuplayer/GenericSource.h
index 2fd703e..0957778 100644
--- a/media/libmediaplayerservice/nuplayer/GenericSource.h
+++ b/media/libmediaplayerservice/nuplayer/GenericSource.h
@@ -117,7 +117,7 @@
     // When necessary, it will send out buffering events to the player.
     struct BufferingMonitor : public AHandler {
     public:
-        BufferingMonitor(const sp<AMessage> &notify);
+        explicit BufferingMonitor(const sp<AMessage> &notify);
 
         // Set up state.
         void prepare(const sp<NuCachedSource2> &cachedSource,
@@ -248,23 +248,23 @@
     void finishPrepareAsync();
     status_t startSources();
 
-    void onGetFormatMeta(sp<AMessage> msg) const;
+    void onGetFormatMeta(const sp<AMessage>& msg) const;
     sp<MetaData> doGetFormatMeta(bool audio) const;
 
-    void onGetSelectedTrack(sp<AMessage> msg) const;
+    void onGetSelectedTrack(const sp<AMessage>& msg) const;
     ssize_t doGetSelectedTrack(media_track_type type) const;
 
-    void onSelectTrack(sp<AMessage> msg);
+    void onSelectTrack(const sp<AMessage>& msg);
     status_t doSelectTrack(size_t trackIndex, bool select, int64_t timeUs);
 
-    void onSeek(sp<AMessage> msg);
+    void onSeek(const sp<AMessage>& msg);
     status_t doSeek(int64_t seekTimeUs);
 
     void onPrepareAsync();
 
     void fetchTextData(
             uint32_t what, media_track_type type,
-            int32_t curGen, sp<AnotherPacketSource> packets, sp<AMessage> msg);
+            int32_t curGen, const sp<AnotherPacketSource>& packets, const sp<AMessage>& msg);
 
     void sendGlobalTextData(
             uint32_t what,
@@ -272,7 +272,7 @@
 
     void sendTextData(
             uint32_t what, media_track_type type,
-            int32_t curGen, sp<AnotherPacketSource> packets, sp<AMessage> msg);
+            int32_t curGen, const sp<AnotherPacketSource>& packets, const sp<AMessage>& msg);
 
     sp<ABuffer> mediaBufferToABuffer(
             MediaBuffer *mbuf,
@@ -281,7 +281,7 @@
             int64_t *actualTimeUs = NULL);
 
     void postReadBuffer(media_track_type trackType);
-    void onReadBuffer(sp<AMessage> msg);
+    void onReadBuffer(const sp<AMessage>& msg);
     void readBuffer(
             media_track_type trackType,
             int64_t seekTimeUs = -1ll, int64_t *actualTimeUs = NULL, bool formatChange = false);
diff --git a/media/libmediaplayerservice/nuplayer/NuPlayer.cpp b/media/libmediaplayerservice/nuplayer/NuPlayer.cpp
index dc4e5d4..4e16fba 100644
--- a/media/libmediaplayerservice/nuplayer/NuPlayer.cpp
+++ b/media/libmediaplayerservice/nuplayer/NuPlayer.cpp
@@ -69,7 +69,7 @@
 };
 
 struct NuPlayer::SeekAction : public Action {
-    SeekAction(int64_t seekTimeUs)
+    explicit SeekAction(int64_t seekTimeUs)
         : mSeekTimeUs(seekTimeUs) {
     }
 
@@ -84,7 +84,7 @@
 };
 
 struct NuPlayer::ResumeDecoderAction : public Action {
-    ResumeDecoderAction(bool needNotify)
+    explicit ResumeDecoderAction(bool needNotify)
         : mNeedNotify(needNotify) {
     }
 
@@ -99,7 +99,7 @@
 };
 
 struct NuPlayer::SetSurfaceAction : public Action {
-    SetSurfaceAction(const sp<Surface> &surface)
+    explicit SetSurfaceAction(const sp<Surface> &surface)
         : mSurface(surface) {
     }
 
@@ -131,7 +131,7 @@
 };
 
 struct NuPlayer::PostMessageAction : public Action {
-    PostMessageAction(const sp<AMessage> &msg)
+    explicit PostMessageAction(const sp<AMessage> &msg)
         : mMessage(msg) {
     }
 
@@ -150,7 +150,7 @@
 struct NuPlayer::SimpleAction : public Action {
     typedef void (NuPlayer::*ActionFunc)();
 
-    SimpleAction(ActionFunc func)
+    explicit SimpleAction(ActionFunc func)
         : mFunc(func) {
     }
 
@@ -428,7 +428,7 @@
 
 
 void NuPlayer::writeTrackInfo(
-        Parcel* reply, const sp<AMessage> format) const {
+        Parcel* reply, const sp<AMessage>& format) const {
     if (format == NULL) {
         ALOGE("NULL format");
         return;
@@ -1802,8 +1802,10 @@
     // Make sure we don't continue to scan sources until we finish flushing.
     ++mScanSourcesGeneration;
     if (mScanSourcesPending) {
-        mDeferredActions.push_back(
-                new SimpleAction(&NuPlayer::performScanSources));
+        if (!needShutdown) {
+            mDeferredActions.push_back(
+                    new SimpleAction(&NuPlayer::performScanSources));
+        }
         mScanSourcesPending = false;
     }
 
diff --git a/media/libmediaplayerservice/nuplayer/NuPlayer.h b/media/libmediaplayerservice/nuplayer/NuPlayer.h
index ae17c76..a002f6f 100644
--- a/media/libmediaplayerservice/nuplayer/NuPlayer.h
+++ b/media/libmediaplayerservice/nuplayer/NuPlayer.h
@@ -33,7 +33,7 @@
 struct NuPlayerDriver;
 
 struct NuPlayer : public AHandler {
-    NuPlayer(pid_t pid);
+    explicit NuPlayer(pid_t pid);
 
     void setUID(uid_t uid);
 
@@ -280,7 +280,7 @@
     void sendTimedMetaData(const sp<ABuffer> &buffer);
     void sendTimedTextData(const sp<ABuffer> &buffer);
 
-    void writeTrackInfo(Parcel* reply, const sp<AMessage> format) const;
+    void writeTrackInfo(Parcel* reply, const sp<AMessage>& format) const;
 
     DISALLOW_EVIL_CONSTRUCTORS(NuPlayer);
 };
diff --git a/media/libmediaplayerservice/nuplayer/NuPlayerCCDecoder.cpp b/media/libmediaplayerservice/nuplayer/NuPlayerCCDecoder.cpp
index 13716cf..978d360 100644
--- a/media/libmediaplayerservice/nuplayer/NuPlayerCCDecoder.cpp
+++ b/media/libmediaplayerservice/nuplayer/NuPlayerCCDecoder.cpp
@@ -256,6 +256,12 @@
             payload_size += last_byte;
         } while (last_byte == 0xFF);
 
+        if (payload_size > SIZE_MAX / 8
+                || !br.atLeastNumBitsLeft(payload_size * 8)) {
+            ALOGV("Malformed SEI payload");
+            break;
+        }
+
         // sei_payload()
         if (payload_type == 4) {
             bool isCC = false;
diff --git a/media/libmediaplayerservice/nuplayer/NuPlayerCCDecoder.h b/media/libmediaplayerservice/nuplayer/NuPlayerCCDecoder.h
index a297334..f310f37 100644
--- a/media/libmediaplayerservice/nuplayer/NuPlayerCCDecoder.h
+++ b/media/libmediaplayerservice/nuplayer/NuPlayerCCDecoder.h
@@ -33,7 +33,7 @@
         kTrackTypeCEA708,
     };
 
-    CCDecoder(const sp<AMessage> &notify);
+    explicit CCDecoder(const sp<AMessage> &notify);
 
     size_t getTrackCount() const;
     sp<AMessage> getTrackInfo(size_t index) const;
diff --git a/media/libmediaplayerservice/nuplayer/NuPlayerDecoderBase.h b/media/libmediaplayerservice/nuplayer/NuPlayerDecoderBase.h
index a334ec5..9966144 100644
--- a/media/libmediaplayerservice/nuplayer/NuPlayerDecoderBase.h
+++ b/media/libmediaplayerservice/nuplayer/NuPlayerDecoderBase.h
@@ -30,7 +30,7 @@
 class Surface;
 
 struct NuPlayer::DecoderBase : public AHandler {
-    DecoderBase(const sp<AMessage> &notify);
+    explicit DecoderBase(const sp<AMessage> &notify);
 
     void configure(const sp<AMessage> &format);
     void init();
diff --git a/media/libmediaplayerservice/nuplayer/NuPlayerDriver.h b/media/libmediaplayerservice/nuplayer/NuPlayerDriver.h
index 26d3a60..58008f0 100644
--- a/media/libmediaplayerservice/nuplayer/NuPlayerDriver.h
+++ b/media/libmediaplayerservice/nuplayer/NuPlayerDriver.h
@@ -24,7 +24,7 @@
 struct NuPlayer;
 
 struct NuPlayerDriver : public MediaPlayerInterface {
-    NuPlayerDriver(pid_t pid);
+    explicit NuPlayerDriver(pid_t pid);
 
     virtual status_t initCheck();
 
diff --git a/media/libmediaplayerservice/nuplayer/NuPlayerSource.h b/media/libmediaplayerservice/nuplayer/NuPlayerSource.h
index 0176eafa..3a96138 100644
--- a/media/libmediaplayerservice/nuplayer/NuPlayerSource.h
+++ b/media/libmediaplayerservice/nuplayer/NuPlayerSource.h
@@ -59,7 +59,7 @@
 
     // The provides message is used to notify the player about various
     // events.
-    Source(const sp<AMessage> &notify)
+    explicit Source(const sp<AMessage> &notify)
         : mNotify(notify) {
     }
 
diff --git a/media/libnbaio/Android.bp b/media/libnbaio/Android.bp
new file mode 100644
index 0000000..615b541
--- /dev/null
+++ b/media/libnbaio/Android.bp
@@ -0,0 +1,36 @@
+cc_library_shared {
+    name: "libnbaio",
+    srcs: [
+        "AudioBufferProviderSource.cpp",
+        "AudioStreamOutSink.cpp",
+        "AudioStreamInSource.cpp",
+        "NBAIO.cpp",
+        "MonoPipe.cpp",
+        "MonoPipeReader.cpp",
+        "Pipe.cpp",
+        "PipeReader.cpp",
+        "SourceAudioBufferProvider.cpp",
+
+        "NBLog.cpp",
+    ],
+
+    // libsndfile license is incompatible; uncomment to use for local debug only
+    // srcs: [
+    //     "LibsndfileSink.cpp",
+    //     "LibsndfileSource.cpp",
+    // ],
+    // static_libs: ["libsndfile"],
+
+    shared_libs: [
+        "libaudioutils",
+        "libbinder",
+        "libcutils",
+        "libutils",
+        "liblog",
+    ],
+
+    cflags: [
+        "-Werror",
+        "-Wall",
+    ],
+}
diff --git a/media/libnbaio/Android.mk b/media/libnbaio/Android.mk
deleted file mode 100644
index e2f416b..0000000
--- a/media/libnbaio/Android.mk
+++ /dev/null
@@ -1,36 +0,0 @@
-LOCAL_PATH := $(call my-dir)
-
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES := \
-    AudioBufferProviderSource.cpp   \
-    AudioStreamOutSink.cpp          \
-    AudioStreamInSource.cpp         \
-    NBAIO.cpp                       \
-    MonoPipe.cpp                    \
-    MonoPipeReader.cpp              \
-    Pipe.cpp                        \
-    PipeReader.cpp                  \
-    SourceAudioBufferProvider.cpp
-
-LOCAL_SRC_FILES += NBLog.cpp
-
-# libsndfile license is incompatible; uncomment to use for local debug only
-#LOCAL_SRC_FILES += LibsndfileSink.cpp LibsndfileSource.cpp
-#LOCAL_C_INCLUDES += path/to/libsndfile/src
-#LOCAL_STATIC_LIBRARIES += libsndfile
-
-LOCAL_MODULE := libnbaio
-
-LOCAL_SHARED_LIBRARIES := \
-    libaudioutils \
-    libbinder \
-    libcutils \
-    libutils \
-    liblog
-
-LOCAL_C_INCLUDES := $(call include-path-for, audio-utils)
-
-LOCAL_CFLAGS := -Werror -Wall
-
-include $(BUILD_SHARED_LIBRARY)
diff --git a/media/libstagefright/ACodec.cpp b/media/libstagefright/ACodec.cpp
index 37fd5a5..e7057ce 100644
--- a/media/libstagefright/ACodec.cpp
+++ b/media/libstagefright/ACodec.cpp
@@ -216,7 +216,7 @@
 ////////////////////////////////////////////////////////////////////////////////
 
 struct ACodec::BaseState : public AState {
-    BaseState(ACodec *codec, const sp<AState> &parentState = NULL);
+    explicit BaseState(ACodec *codec, const sp<AState> &parentState = NULL);
 
 protected:
     enum PortMode {
@@ -267,7 +267,7 @@
 ////////////////////////////////////////////////////////////////////////////////
 
 struct ACodec::DeathNotifier : public IBinder::DeathRecipient {
-    DeathNotifier(const sp<AMessage> &notify)
+    explicit DeathNotifier(const sp<AMessage> &notify)
         : mNotify(notify) {
     }
 
@@ -285,7 +285,7 @@
 };
 
 struct ACodec::UninitializedState : public ACodec::BaseState {
-    UninitializedState(ACodec *codec);
+    explicit UninitializedState(ACodec *codec);
 
 protected:
     virtual bool onMessageReceived(const sp<AMessage> &msg);
@@ -303,7 +303,7 @@
 ////////////////////////////////////////////////////////////////////////////////
 
 struct ACodec::LoadedState : public ACodec::BaseState {
-    LoadedState(ACodec *codec);
+    explicit LoadedState(ACodec *codec);
 
 protected:
     virtual bool onMessageReceived(const sp<AMessage> &msg);
@@ -326,7 +326,7 @@
 ////////////////////////////////////////////////////////////////////////////////
 
 struct ACodec::LoadedToIdleState : public ACodec::BaseState {
-    LoadedToIdleState(ACodec *codec);
+    explicit LoadedToIdleState(ACodec *codec);
 
 protected:
     virtual bool onMessageReceived(const sp<AMessage> &msg);
@@ -342,7 +342,7 @@
 ////////////////////////////////////////////////////////////////////////////////
 
 struct ACodec::IdleToExecutingState : public ACodec::BaseState {
-    IdleToExecutingState(ACodec *codec);
+    explicit IdleToExecutingState(ACodec *codec);
 
 protected:
     virtual bool onMessageReceived(const sp<AMessage> &msg);
@@ -356,7 +356,7 @@
 ////////////////////////////////////////////////////////////////////////////////
 
 struct ACodec::ExecutingState : public ACodec::BaseState {
-    ExecutingState(ACodec *codec);
+    explicit ExecutingState(ACodec *codec);
 
     void submitRegularOutputBuffers();
     void submitOutputMetaBuffers();
@@ -386,7 +386,7 @@
 ////////////////////////////////////////////////////////////////////////////////
 
 struct ACodec::OutputPortSettingsChangedState : public ACodec::BaseState {
-    OutputPortSettingsChangedState(ACodec *codec);
+    explicit OutputPortSettingsChangedState(ACodec *codec);
 
 protected:
     virtual PortMode getPortMode(OMX_U32 portIndex);
@@ -403,7 +403,7 @@
 ////////////////////////////////////////////////////////////////////////////////
 
 struct ACodec::ExecutingToIdleState : public ACodec::BaseState {
-    ExecutingToIdleState(ACodec *codec);
+    explicit ExecutingToIdleState(ACodec *codec);
 
 protected:
     virtual bool onMessageReceived(const sp<AMessage> &msg);
@@ -425,7 +425,7 @@
 ////////////////////////////////////////////////////////////////////////////////
 
 struct ACodec::IdleToLoadedState : public ACodec::BaseState {
-    IdleToLoadedState(ACodec *codec);
+    explicit IdleToLoadedState(ACodec *codec);
 
 protected:
     virtual bool onMessageReceived(const sp<AMessage> &msg);
@@ -440,7 +440,7 @@
 ////////////////////////////////////////////////////////////////////////////////
 
 struct ACodec::FlushingState : public ACodec::BaseState {
-    FlushingState(ACodec *codec);
+    explicit FlushingState(ACodec *codec);
 
 protected:
     virtual bool onMessageReceived(const sp<AMessage> &msg);
@@ -494,7 +494,8 @@
 ////////////////////////////////////////////////////////////////////////////////
 
 ACodec::ACodec()
-    : mQuirks(0),
+    : mSampleRate(0),
+      mQuirks(0),
       mNode(0),
       mUsingNativeWindow(false),
       mNativeWindowUsageBits(0),
@@ -2782,6 +2783,7 @@
     } else {
         ALOGW("did not set AudioAndroidAacPresentation due to error %d when setting AudioAac", res);
     }
+    mSampleRate = sampleRate;
     return res;
 }
 
@@ -5473,8 +5475,14 @@
     CHECK(mOutputFormat->findString("mime", &mime));
 
     if (mime == MEDIA_MIMETYPE_AUDIO_RAW && (mEncoderDelay || mEncoderPadding)) {
-        int32_t channelCount;
+        int32_t channelCount, sampleRate;
         CHECK(mOutputFormat->findInt32("channel-count", &channelCount));
+        CHECK(mOutputFormat->findInt32("sample-rate", &sampleRate));
+        if (mSampleRate != 0 && sampleRate != 0) {
+            mEncoderDelay = mEncoderDelay * sampleRate / mSampleRate;
+            mEncoderPadding = mEncoderPadding * sampleRate / mSampleRate;
+            mSampleRate = sampleRate;
+        }
         if (mSkipCutBuffer != NULL) {
             size_t prevbufsize = mSkipCutBuffer->size();
             if (prevbufsize != 0) {
diff --git a/media/libstagefright/Android.bp b/media/libstagefright/Android.bp
new file mode 100644
index 0000000..3d9341b
--- /dev/null
+++ b/media/libstagefright/Android.bp
@@ -0,0 +1 @@
+subdirs = ["foundation"]
diff --git a/media/libstagefright/Android.mk b/media/libstagefright/Android.mk
index 3848502..98bcc56 100644
--- a/media/libstagefright/Android.mk
+++ b/media/libstagefright/Android.mk
@@ -124,6 +124,8 @@
         libdl \
         libRScpp \
 
+LOCAL_EXPORT_SHARED_LIBRARY_HEADERS := libmedia
+
 LOCAL_CFLAGS += -Wno-multichar -Werror -Wno-error=deprecated-declarations -Wall
 
 # enable experiments only in userdebug and eng builds
diff --git a/media/libstagefright/CameraSource.cpp b/media/libstagefright/CameraSource.cpp
index 893da89..408ad7a 100644
--- a/media/libstagefright/CameraSource.cpp
+++ b/media/libstagefright/CameraSource.cpp
@@ -47,7 +47,7 @@
 static const int64_t CAMERA_SOURCE_TIMEOUT_NS = 3000000000LL;
 
 struct CameraSourceListener : public CameraListener {
-    CameraSourceListener(const sp<CameraSource> &source);
+    explicit CameraSourceListener(const sp<CameraSource> &source);
 
     virtual void notify(int32_t msgType, int32_t ext1, int32_t ext2);
     virtual void postData(int32_t msgType, const sp<IMemory> &dataPtr,
diff --git a/media/libstagefright/DataURISource.cpp b/media/libstagefright/DataURISource.cpp
index 2a61c3a..3dc345f 100644
--- a/media/libstagefright/DataURISource.cpp
+++ b/media/libstagefright/DataURISource.cpp
@@ -28,7 +28,7 @@
         return NULL;
     }
 
-    char *commaPos = strrchr(uri, ',');
+    const char *commaPos = strrchr(uri, ',');
 
     if (commaPos == NULL) {
         return NULL;
diff --git a/media/libstagefright/FLACExtractor.cpp b/media/libstagefright/FLACExtractor.cpp
index 13b66f3..1af7dc1 100644
--- a/media/libstagefright/FLACExtractor.cpp
+++ b/media/libstagefright/FLACExtractor.cpp
@@ -73,7 +73,7 @@
 class FLACParser : public RefBase {
 
 public:
-    FLACParser(
+    explicit FLACParser(
         const sp<DataSource> &dataSource,
         // If metadata pointers aren't provided, we don't fill them
         const sp<MetaData> &fileMetadata = 0,
diff --git a/media/libstagefright/MPEG2TSWriter.cpp b/media/libstagefright/MPEG2TSWriter.cpp
index a9e8846..931b280 100644
--- a/media/libstagefright/MPEG2TSWriter.cpp
+++ b/media/libstagefright/MPEG2TSWriter.cpp
@@ -35,7 +35,7 @@
 namespace android {
 
 struct MPEG2TSWriter::SourceInfo : public AHandler {
-    SourceInfo(const sp<IMediaSource> &source);
+    explicit SourceInfo(const sp<IMediaSource> &source);
 
     void start(const sp<AMessage> &notify);
     void stop();
diff --git a/media/libstagefright/MPEG4Extractor.cpp b/media/libstagefright/MPEG4Extractor.cpp
index 0395c77..7a818ec 100644
--- a/media/libstagefright/MPEG4Extractor.cpp
+++ b/media/libstagefright/MPEG4Extractor.cpp
@@ -184,7 +184,7 @@
 // Each MPEG4DataSource caches the sampletable metadata for a single track.
 
 struct MPEG4DataSource : public DataSource {
-    MPEG4DataSource(const sp<DataSource> &source);
+    explicit MPEG4DataSource(const sp<DataSource> &source);
 
     virtual status_t initCheck() const;
     virtual ssize_t readAt(off64_t offset, void *data, size_t size);
@@ -601,7 +601,7 @@
 
 // Reads an encoded integer 7 bits at a time until it encounters the high bit clear.
 static int32_t readSize(off64_t offset,
-        const sp<DataSource> DataSource, uint8_t *numOfBytes) {
+        const sp<DataSource> &DataSource, uint8_t *numOfBytes) {
     uint32_t size = 0;
     uint8_t data;
     bool moreData = true;
diff --git a/media/libstagefright/MPEG4Writer.cpp b/media/libstagefright/MPEG4Writer.cpp
index 5e96c2b..c9bcfc3 100644
--- a/media/libstagefright/MPEG4Writer.cpp
+++ b/media/libstagefright/MPEG4Writer.cpp
@@ -643,7 +643,7 @@
     if (mMaxFileDurationLimitUs != 0) {
         if (bitRate > 0) {
             int64_t size2 =
-                ((mMaxFileDurationLimitUs * bitRate * 6) / 1000 / 8000000);
+                ((mMaxFileDurationLimitUs / 1000) * bitRate * 6) / 8000000;
             if (mMaxFileSizeLimitBytes != 0 && mIsFileSizeLimitExplicitlyRequested) {
                 // When both file size and duration limits are set,
                 // we use the smaller limit of the two.
@@ -3085,7 +3085,7 @@
         mOwner->writeInt16(primaries);
         mOwner->writeInt16(transfer);
         mOwner->writeInt16(coeffs);
-        mOwner->writeInt8(fullRange ? 128 : 0);
+        mOwner->writeInt8(int8_t(fullRange ? 0x80 : 0x0));
         mOwner->endBox(); // colr
     }
 }
diff --git a/media/libstagefright/MediaCodec.cpp b/media/libstagefright/MediaCodec.cpp
index e476424..b088775 100644
--- a/media/libstagefright/MediaCodec.cpp
+++ b/media/libstagefright/MediaCodec.cpp
@@ -53,7 +53,7 @@
 
 namespace android {
 
-static int64_t getId(sp<IResourceManagerClient> client) {
+static int64_t getId(const sp<IResourceManagerClient> &client) {
     return (int64_t) client.get();
 }
 
@@ -65,7 +65,7 @@
 static const int kMaxReclaimWaitTimeInUs = 500000;  // 0.5s
 
 struct ResourceManagerClient : public BnResourceManagerClient {
-    ResourceManagerClient(MediaCodec* codec) : mMediaCodec(codec) {}
+    explicit ResourceManagerClient(MediaCodec* codec) : mMediaCodec(codec) {}
 
     virtual bool reclaimResource() {
         sp<MediaCodec> codec = mMediaCodec.promote();
@@ -142,7 +142,7 @@
 
 void MediaCodec::ResourceManagerServiceProxy::addResource(
         int64_t clientId,
-        const sp<IResourceManagerClient> client,
+        const sp<IResourceManagerClient> &client,
         const Vector<MediaResource> &resources) {
     Mutex::Autolock _l(mLock);
     if (mService == NULL) {
@@ -2569,7 +2569,7 @@
 
 //static
 size_t MediaCodec::CreateFramesRenderedMessage(
-        std::list<FrameRenderTracker::Info> done, sp<AMessage> &msg) {
+        const std::list<FrameRenderTracker::Info> &done, sp<AMessage> &msg) {
     size_t index = 0;
 
     for (std::list<FrameRenderTracker::Info>::const_iterator it = done.cbegin();
diff --git a/media/libstagefright/MediaCodecList.cpp b/media/libstagefright/MediaCodecList.cpp
index 0fb5072..8afb7e9 100644
--- a/media/libstagefright/MediaCodecList.cpp
+++ b/media/libstagefright/MediaCodecList.cpp
@@ -182,7 +182,7 @@
 
 void MediaCodecList::parseTopLevelXMLFile(const char *codecs_xml, bool ignore_errors) {
     // get href_base
-    char *href_base_end = strrchr(codecs_xml, '/');
+    const char *href_base_end = strrchr(codecs_xml, '/');
     if (href_base_end != NULL) {
         mHrefBase = AString(codecs_xml, href_base_end - codecs_xml + 1);
     }
@@ -888,18 +888,18 @@
     return -ENOENT;
 }
 
-static status_t limitFoundMissingAttr(AString name, const char *attr, bool found = true) {
+static status_t limitFoundMissingAttr(const AString &name, const char *attr, bool found = true) {
     ALOGE("limit '%s' with %s'%s' attribute", name.c_str(),
             (found ? "" : "no "), attr);
     return -EINVAL;
 }
 
-static status_t limitError(AString name, const char *msg) {
+static status_t limitError(const AString &name, const char *msg) {
     ALOGE("limit '%s' %s", name.c_str(), msg);
     return -EINVAL;
 }
 
-static status_t limitInvalidAttr(AString name, const char *attr, AString value) {
+static status_t limitInvalidAttr(const AString &name, const char *attr, const AString &value) {
     ALOGE("limit '%s' with invalid '%s' attribute (%s)", name.c_str(),
             attr, value.c_str());
     return -EINVAL;
@@ -1165,7 +1165,9 @@
         CHECK(info != NULL);
         AString componentName = info->getCodecName();
 
-        if (!((flags & kHardwareCodecsOnly) && !isSoftwareCodec(componentName))) {
+        if ((flags & kHardwareCodecsOnly) && isSoftwareCodec(componentName)) {
+            ALOGV("skipping SW codec '%s'", componentName.c_str());
+        } else {
             matches->push(componentName);
             ALOGV("matching '%s'", componentName.c_str());
         }
diff --git a/media/libstagefright/MediaCodecListOverrides.cpp b/media/libstagefright/MediaCodecListOverrides.cpp
index 4ec36b5..33795f3 100644
--- a/media/libstagefright/MediaCodecListOverrides.cpp
+++ b/media/libstagefright/MediaCodecListOverrides.cpp
@@ -49,7 +49,7 @@
 static const int kMaxInstances = 32;
 
 // TODO: move MediaCodecInfo to C++. Until then, some temp methods to parse out info.
-static bool getMeasureSize(sp<MediaCodecInfo::Capabilities> caps, int32_t *width, int32_t *height) {
+static bool getMeasureSize(const sp<MediaCodecInfo::Capabilities> &caps, int32_t *width, int32_t *height) {
     AString sizeRange;
     if (!caps->getDetails()->findString("size-range", &sizeRange)) {
         return false;
@@ -72,7 +72,7 @@
     return (*width > 0) && (*height > 0);
 }
 
-static void getMeasureBitrate(sp<MediaCodecInfo::Capabilities> caps, int32_t *bitrate) {
+static void getMeasureBitrate(const sp<MediaCodecInfo::Capabilities> &caps, int32_t *bitrate) {
     // Until have native MediaCodecInfo, we cannot get bitrates based on profile/levels.
     // We use 200000 as default value for our measurement.
     *bitrate = 200000;
@@ -90,7 +90,7 @@
 }
 
 static sp<AMessage> getMeasureFormat(
-        bool isEncoder, AString mime, sp<MediaCodecInfo::Capabilities> caps) {
+        bool isEncoder, const AString &mime, const sp<MediaCodecInfo::Capabilities> &caps) {
     sp<AMessage> format = new AMessage();
     format->setString("mime", mime);
 
@@ -128,7 +128,7 @@
 }
 
 static size_t doProfileEncoderInputBuffers(
-        AString name, AString mime, sp<MediaCodecInfo::Capabilities> caps) {
+        const AString &name, const AString &mime, const sp<MediaCodecInfo::Capabilities> &caps) {
     ALOGV("doProfileEncoderInputBuffers: name %s, mime %s", name.c_str(), mime.c_str());
 
     sp<AMessage> format = getMeasureFormat(true /* isEncoder */, mime, caps);
@@ -183,7 +183,7 @@
 }
 
 static size_t doProfileCodecs(
-        bool isEncoder, AString name, AString mime, sp<MediaCodecInfo::Capabilities> caps) {
+        bool isEncoder, const AString &name, const AString &mime, const sp<MediaCodecInfo::Capabilities> &caps) {
     sp<AMessage> format = getMeasureFormat(isEncoder, mime, caps);
     if (format == NULL) {
         return 0;
@@ -337,7 +337,7 @@
     global_results->add(kPolicySupportsMultipleSecureCodecs, supportMultipleSecureCodecs);
 }
 
-static AString globalResultsToXml(const CodecSettings& results) {
+static AString globalResultsToXml(const CodecSettings &results) {
     AString ret;
     for (size_t i = 0; i < results.size(); ++i) {
         AString setting = AStringPrintf(
@@ -349,7 +349,7 @@
     return ret;
 }
 
-static AString codecResultsToXml(const KeyedVector<AString, CodecSettings>& results) {
+static AString codecResultsToXml(const KeyedVector<AString, CodecSettings> &results) {
     AString ret;
     for (size_t i = 0; i < results.size(); ++i) {
         AString name;
@@ -362,7 +362,7 @@
                               name.c_str(),
                               mime.c_str());
         ret.append(codec);
-        CodecSettings settings = results.valueAt(i);
+        const CodecSettings &settings = results.valueAt(i);
         for (size_t i = 0; i < settings.size(); ++i) {
             // WARNING: we assume all the settings are "Limit". Currently we have only one type
             // of setting in this case, which is "max-supported-instances".
@@ -379,9 +379,9 @@
 
 void exportResultsToXML(
         const char *fileName,
-        const CodecSettings& global_results,
-        const KeyedVector<AString, CodecSettings>& encoder_results,
-        const KeyedVector<AString, CodecSettings>& decoder_results) {
+        const CodecSettings &global_results,
+        const KeyedVector<AString, CodecSettings> &encoder_results,
+        const KeyedVector<AString, CodecSettings> &decoder_results) {
     if (global_results.size() == 0 && encoder_results.size() == 0 && decoder_results.size() == 0) {
         return;
     }
diff --git a/media/libstagefright/MediaCodecSource.cpp b/media/libstagefright/MediaCodecSource.cpp
index ea5ef06..35c07ca 100644
--- a/media/libstagefright/MediaCodecSource.cpp
+++ b/media/libstagefright/MediaCodecSource.cpp
@@ -47,7 +47,7 @@
 const int kStopTimeoutUs = 300000; // allow 1 sec for shutting down encoder
 
 struct MediaCodecSource::Puller : public AHandler {
-    Puller(const sp<MediaSource> &source);
+    explicit Puller(const sp<MediaSource> &source);
 
     void interruptSource();
     status_t start(const sp<MetaData> &meta, const sp<AMessage> &notify);
diff --git a/media/libstagefright/NuCachedSource2.cpp b/media/libstagefright/NuCachedSource2.cpp
index 453db03..afd6ffb 100644
--- a/media/libstagefright/NuCachedSource2.cpp
+++ b/media/libstagefright/NuCachedSource2.cpp
@@ -31,7 +31,7 @@
 namespace android {
 
 struct PageCache {
-    PageCache(size_t pageSize);
+    explicit PageCache(size_t pageSize);
     ~PageCache();
 
     struct Page {
diff --git a/media/libstagefright/OggExtractor.cpp b/media/libstagefright/OggExtractor.cpp
index 37e8e9c..0343786 100644
--- a/media/libstagefright/OggExtractor.cpp
+++ b/media/libstagefright/OggExtractor.cpp
@@ -46,7 +46,7 @@
 namespace android {
 
 struct OggSource : public MediaSource {
-    OggSource(const sp<OggExtractor> &extractor);
+    explicit OggSource(const sp<OggExtractor> &extractor);
 
     virtual sp<MetaData> getFormat();
 
@@ -164,7 +164,7 @@
 };
 
 struct MyVorbisExtractor : public MyOggExtractor {
-    MyVorbisExtractor(const sp<DataSource> &source)
+    explicit MyVorbisExtractor(const sp<DataSource> &source)
         : MyOggExtractor(source,
                 MEDIA_MIMETYPE_AUDIO_VORBIS,
                 /* numHeaders */ 3,
@@ -192,7 +192,7 @@
     static const int32_t kOpusSampleRate = 48000;
     static const int64_t kOpusSeekPreRollUs = 80000; // 80 ms
 
-    MyOpusExtractor(const sp<DataSource> &source)
+    explicit MyOpusExtractor(const sp<DataSource> &source)
         : MyOggExtractor(source, MEDIA_MIMETYPE_AUDIO_OPUS, /*numHeaders*/ 2, kOpusSeekPreRollUs),
           mChannelCount(0),
           mCodecDelay(0),
diff --git a/media/libstagefright/SampleTable.cpp b/media/libstagefright/SampleTable.cpp
index eb1f193..47d360c 100644
--- a/media/libstagefright/SampleTable.cpp
+++ b/media/libstagefright/SampleTable.cpp
@@ -215,6 +215,11 @@
 status_t SampleTable::setSampleToChunkParams(
         off64_t data_offset, size_t data_size) {
     if (mSampleToChunkOffset >= 0) {
+        // already set
+        return ERROR_MALFORMED;
+    }
+
+    if (data_offset < 0) {
         return ERROR_MALFORMED;
     }
 
diff --git a/media/libstagefright/SurfaceMediaSource.cpp b/media/libstagefright/SurfaceMediaSource.cpp
index 15ff569..4f1ef30 100644
--- a/media/libstagefright/SurfaceMediaSource.cpp
+++ b/media/libstagefright/SurfaceMediaSource.cpp
@@ -112,7 +112,7 @@
     Mutex::Autolock lock(mMutex);
 
     result.append(buffer);
-    mConsumer->dump(result, "");
+    mConsumer->dumpState(result, "");
 }
 
 status_t SurfaceMediaSource::setFrameRate(int32_t fps)
diff --git a/media/libstagefright/Utils.cpp b/media/libstagefright/Utils.cpp
index 1c76ad7..36be7a0 100644
--- a/media/libstagefright/Utils.cpp
+++ b/media/libstagefright/Utils.cpp
@@ -1070,7 +1070,7 @@
     return res != NULL && res < data + length - 4 ? res : &data[length];
 }
 
-static size_t reassembleAVCC(const sp<ABuffer> &csd0, const sp<ABuffer> csd1, char *avcc) {
+static size_t reassembleAVCC(const sp<ABuffer> &csd0, const sp<ABuffer> &csd1, char *avcc) {
     avcc[0] = 1;        // version
     avcc[1] = 0x64;     // profile (default to high)
     avcc[2] = 0;        // constraints (default to none)
@@ -1713,7 +1713,7 @@
             || (t0.mSeq == t1.mSeq && t0.mTimeUs < t1.mTimeUs);
 }
 
-void writeToAMessage(sp<AMessage> msg, const AudioPlaybackRate &rate) {
+void writeToAMessage(const sp<AMessage> &msg, const AudioPlaybackRate &rate) {
     msg->setFloat("speed", rate.mSpeed);
     msg->setFloat("pitch", rate.mPitch);
     msg->setInt32("audio-fallback-mode", rate.mFallbackMode);
@@ -1728,7 +1728,7 @@
     CHECK(msg->findInt32("audio-stretch-mode", (int32_t *)&rate->mStretchMode));
 }
 
-void writeToAMessage(sp<AMessage> msg, const AVSyncSettings &sync, float videoFpsHint) {
+void writeToAMessage(const sp<AMessage> &msg, const AVSyncSettings &sync, float videoFpsHint) {
     msg->setInt32("sync-source", sync.mSource);
     msg->setInt32("audio-adjust-mode", sync.mAudioAdjustMode);
     msg->setFloat("tolerance", sync.mTolerance);
diff --git a/media/libstagefright/codecs/aacdec/SoftAAC2.cpp b/media/libstagefright/codecs/aacdec/SoftAAC2.cpp
index ff76bc8..1c5e3c6 100644
--- a/media/libstagefright/codecs/aacdec/SoftAAC2.cpp
+++ b/media/libstagefright/codecs/aacdec/SoftAAC2.cpp
@@ -36,7 +36,7 @@
 #define DRC_DEFAULT_MOBILE_DRC_CUT   127 /* maximum compression of dynamic range for mobile conf */
 #define DRC_DEFAULT_MOBILE_DRC_BOOST 127 /* maximum compression of dynamic range for mobile conf */
 #define DRC_DEFAULT_MOBILE_DRC_HEAVY 1   /* switch for heavy compression for mobile conf */
-#define DRC_DEFAULT_MOBILE_ENC_LEVEL -1 /* encoder target level; -1 => the value is unknown, otherwise dB step value (e.g. 64 for -16 dB) */
+#define DRC_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
 #define PROP_DRC_OVERRIDE_REF_LEVEL  "aac_drc_reference_level"
diff --git a/media/libstagefright/codecs/aacenc/Android.mk b/media/libstagefright/codecs/aacenc/Android.mk
index 266f01b..71c374b 100644
--- a/media/libstagefright/codecs/aacenc/Android.mk
+++ b/media/libstagefright/codecs/aacenc/Android.mk
@@ -64,7 +64,10 @@
 
 LOCAL_STATIC_LIBRARIES :=
 
-LOCAL_SHARED_LIBRARIES :=
+# libstagefright links this static library, so it probably isn't appropriate to
+# link libstagefright.  However, this library includes libstagefright headers,
+# and needs libbinder to be able to do so correctly.
+LOCAL_SHARED_LIBRARIES := libbinder
 
 LOCAL_C_INCLUDES := \
 	frameworks/av/include \
diff --git a/media/libstagefright/codecs/aacenc/basic_op/oper_32b.c b/media/libstagefright/codecs/aacenc/basic_op/oper_32b.c
index 4fd16a1..78f032b 100644
--- a/media/libstagefright/codecs/aacenc/basic_op/oper_32b.c
+++ b/media/libstagefright/codecs/aacenc/basic_op/oper_32b.c
@@ -234,10 +234,10 @@
 }
 
 #define step(shift) \
-    if ((0x40000000l >> shift) + root <= value)       \
+    if ((0x40000000l >> (shift)) + root <= value)       \
     {                                                 \
-        value -= (0x40000000l >> shift) + root;       \
-        root = (root >> 1) | (0x40000000l >> shift);  \
+        value -= (0x40000000l >> (shift)) + root;       \
+        root = (root >> 1) | (0x40000000l >> (shift));  \
     } else {                                          \
         root = root >> 1;                             \
     }
diff --git a/media/libstagefright/codecs/aacenc/basic_op/typedefs.h b/media/libstagefright/codecs/aacenc/basic_op/typedefs.h
index 6059237..80d350d 100644
--- a/media/libstagefright/codecs/aacenc/basic_op/typedefs.h
+++ b/media/libstagefright/codecs/aacenc/basic_op/typedefs.h
@@ -89,11 +89,11 @@
 #endif
 
 #ifndef min
-#define min(a,b) ( a < b ? a : b)
+#define min(a,b) ( (a) < (b) ? (a) : (b))
 #endif
 
 #ifndef max
-#define max(a,b) ( a > b ? a : b)
+#define max(a,b) ( (a) > (b) ? (a) : (b))
 #endif
 
 #ifdef ARM_INASM
diff --git a/media/libstagefright/codecs/aacenc/inc/psy_const.h b/media/libstagefright/codecs/aacenc/inc/psy_const.h
index 19fb9b2..0b9f8c3 100644
--- a/media/libstagefright/codecs/aacenc/inc/psy_const.h
+++ b/media/libstagefright/codecs/aacenc/inc/psy_const.h
@@ -73,7 +73,7 @@
 #define TRANSFORM_OFFSET_LONG    0
 #define TRANSFORM_OFFSET_SHORT   448
 
-#define LOG_NORM_PCM          -15
+#define LOG_NORM_PCM          (-15)
 
 #define NUM_SAMPLE_RATES	12
 
diff --git a/media/libstagefright/codecs/aacenc/src/bit_cnt.c b/media/libstagefright/codecs/aacenc/src/bit_cnt.c
index 9fe511c..65b035e 100644
--- a/media/libstagefright/codecs/aacenc/src/bit_cnt.c
+++ b/media/libstagefright/codecs/aacenc/src/bit_cnt.c
@@ -23,10 +23,10 @@
 #include "bit_cnt.h"
 #include "aac_rom.h"
 
-#define HI_LTAB(a) (a>>8)
-#define LO_LTAB(a) (a & 0xff)
+#define HI_LTAB(a) ((a)>>8)
+#define LO_LTAB(a) ((a) & 0xff)
 
-#define EXPAND(a)  ((((Word32)(a&0xff00)) << 8)|(Word32)(a&0xff))
+#define EXPAND(a)  ((((Word32)((a)&0xff00)) << 8)|(Word32)((a)&0xff))
 
 
 /*****************************************************************************
diff --git a/media/libstagefright/codecs/aacenc/src/transform.c b/media/libstagefright/codecs/aacenc/src/transform.c
index 0080810..5de2b96 100644
--- a/media/libstagefright/codecs/aacenc/src/transform.c
+++ b/media/libstagefright/codecs/aacenc/src/transform.c
@@ -30,8 +30,8 @@
 #define SQRT1_2 0x5a82799a	/* sqrt(1/2) in Q31 */
 #define swap2(p0,p1) \
 	t = p0; t1 = *(&(p0)+1);	\
-	p0 = p1; *(&(p0)+1) = *(&(p1)+1);	\
-	p1 = t; *(&(p1)+1) = t1
+	(p0) = p1; *(&(p0)+1) = *(&(p1)+1);	\
+	(p1) = t; *(&(p1)+1) = t1
 
 /*********************************************************************************
 *
diff --git a/media/libstagefright/codecs/amrnb/common/src/az_lsp.cpp b/media/libstagefright/codecs/amrnb/common/src/az_lsp.cpp
index 459c3c3..f3098f5 100644
--- a/media/libstagefright/codecs/amrnb/common/src/az_lsp.cpp
+++ b/media/libstagefright/codecs/amrnb/common/src/az_lsp.cpp
@@ -103,7 +103,7 @@
 ; Include all pre-processor statements here. Include conditional
 ; compile variables also.
 ----------------------------------------------------------------------------*/
-#define NC   M/2                  /* M = LPC order, NC = M/2 */
+#define NC   (M/2)                  /* M = LPC order, NC = M/2 */
 
 /*----------------------------------------------------------------------------
 ; LOCAL FUNCTION DEFINITIONS
diff --git a/media/libstagefright/codecs/amrnb/common/src/gc_pred.cpp b/media/libstagefright/codecs/amrnb/common/src/gc_pred.cpp
index 1c8a700..731dc52 100644
--- a/media/libstagefright/codecs/amrnb/common/src/gc_pred.cpp
+++ b/media/libstagefright/codecs/amrnb/common/src/gc_pred.cpp
@@ -69,8 +69,8 @@
 #define MEAN_ENER_MR122  783741L  /* 36/(20*log10(2)) (Q17) */
 
 /* minimum quantized energy: -14 dB */
-#define MIN_ENERGY       -14336       /* 14                 Q10 */
-#define MIN_ENERGY_MR122  -2381       /* 14 / (20*log10(2)) Q10 */
+#define MIN_ENERGY       (-14336)       /* 14                 Q10 */
+#define MIN_ENERGY_MR122  (-2381)       /* 14 / (20*log10(2)) Q10 */
 
 /*----------------------------------------------------------------------------
 ; LOCAL FUNCTION DEFINITIONS
diff --git a/media/libstagefright/codecs/amrwb/src/dtx.h b/media/libstagefright/codecs/amrwb/src/dtx.h
index a81f089..cf686a0 100644
--- a/media/libstagefright/codecs/amrwb/src/dtx.h
+++ b/media/libstagefright/codecs/amrwb/src/dtx.h
@@ -77,7 +77,7 @@
 #define DTX_HANG_CONST 7                   /* yields eight frames of SP HANGOVER  */
 #define INV_MED_THRESH 14564
 #define ISF_GAP  128                       /* 50 */
-#define ONE_MINUS_ISF_GAP 16384 - ISF_GAP
+#define ONE_MINUS_ISF_GAP (16384 - ISF_GAP)
 
 #define ISF_GAP   128
 #define ISF_DITH_GAP   448
diff --git a/media/libstagefright/codecs/amrwb/src/homing_amr_wb_dec.cpp b/media/libstagefright/codecs/amrwb/src/homing_amr_wb_dec.cpp
index f032a08..dde3e43 100644
--- a/media/libstagefright/codecs/amrwb/src/homing_amr_wb_dec.cpp
+++ b/media/libstagefright/codecs/amrwb/src/homing_amr_wb_dec.cpp
@@ -105,15 +105,15 @@
 #define NUM_OF_SPMODES 9
 
 #define PRML 15
-#define PRMN_7k NBBITS_7k/PRML + 1
-#define PRMN_9k NBBITS_9k/PRML + 1
-#define PRMN_12k NBBITS_12k/PRML + 1
-#define PRMN_14k NBBITS_14k/PRML + 1
-#define PRMN_16k NBBITS_16k/PRML + 1
-#define PRMN_18k NBBITS_18k/PRML + 1
-#define PRMN_20k NBBITS_20k/PRML + 1
-#define PRMN_23k NBBITS_23k/PRML + 1
-#define PRMN_24k NBBITS_24k/PRML + 1
+#define PRMN_7k (NBBITS_7k/PRML + 1)
+#define PRMN_9k (NBBITS_9k/PRML + 1)
+#define PRMN_12k (NBBITS_12k/PRML + 1)
+#define PRMN_14k (NBBITS_14k/PRML + 1)
+#define PRMN_16k (NBBITS_16k/PRML + 1)
+#define PRMN_18k (NBBITS_18k/PRML + 1)
+#define PRMN_20k (NBBITS_20k/PRML + 1)
+#define PRMN_23k (NBBITS_23k/PRML + 1)
+#define PRMN_24k (NBBITS_24k/PRML + 1)
 
 /*----------------------------------------------------------------------------
 ; LOCAL FUNCTION DEFINITIONS
diff --git a/media/libstagefright/codecs/amrwb/src/pvamrwb_math_op.h b/media/libstagefright/codecs/amrwb/src/pvamrwb_math_op.h
index 8951e5c..2143c9a 100644
--- a/media/libstagefright/codecs/amrwb/src/pvamrwb_math_op.h
+++ b/media/libstagefright/codecs/amrwb/src/pvamrwb_math_op.h
@@ -119,8 +119,8 @@
 #define norm_s( x)    (normalize_amr_wb(  x) - 16)
 
 
-#define extract_h( x)    (int16)(x>>16)
-#define L_deposit_h( x)    (int32)(x<<16)
+#define extract_h( x)    (int16)((x)>>16)
+#define L_deposit_h( x)    (int32)((x)<<16)
 
 
 #ifdef __cplusplus
diff --git a/media/libstagefright/codecs/amrwb/src/pvamrwbdecoder_basic_op.h b/media/libstagefright/codecs/amrwb/src/pvamrwbdecoder_basic_op.h
index df239d2..88ff9bc 100644
--- a/media/libstagefright/codecs/amrwb/src/pvamrwbdecoder_basic_op.h
+++ b/media/libstagefright/codecs/amrwb/src/pvamrwbdecoder_basic_op.h
@@ -56,8 +56,8 @@
 #define MAX_32 (int32)0x7fffffffL
 #define MIN_32 (int32)0x80000000L
 
-#define MAX_16 (int16)+32767    /* 0x7fff */
-#define MIN_16 (int16)-32768    /* 0x8000 */
+#define MAX_16 ((int16)+32767)    /* 0x7fff */
+#define MIN_16 ((int16)-32768)    /* 0x8000 */
 
 
 
diff --git a/media/libstagefright/codecs/amrwb/src/pvamrwbdecoder_cnst.h b/media/libstagefright/codecs/amrwb/src/pvamrwbdecoder_cnst.h
index ecf1bf3..3981ce3 100644
--- a/media/libstagefright/codecs/amrwb/src/pvamrwbdecoder_cnst.h
+++ b/media/libstagefright/codecs/amrwb/src/pvamrwbdecoder_cnst.h
@@ -130,7 +130,7 @@
 
 #define EHF_MASK (int16)0x0008            /* homing frame pattern                       */
 
-#define BIT_0     (int16)-127
+#define BIT_0     ((int16)-127)
 #define BIT_1     (int16)127
 #define BIT_0_ITU (int16)0x007F
 #define BIT_1_ITU (int16)0x0081
diff --git a/media/libstagefright/codecs/amrwbenc/inc/basic_op.h b/media/libstagefright/codecs/amrwbenc/inc/basic_op.h
index 8165f69..80ad7f1 100644
--- a/media/libstagefright/codecs/amrwbenc/inc/basic_op.h
+++ b/media/libstagefright/codecs/amrwbenc/inc/basic_op.h
@@ -25,8 +25,8 @@
 #define MAX_32 (Word32)0x7fffffffL
 #define MIN_32 (Word32)0x80000000L
 
-#define MAX_16 (Word16)+32767   /* 0x7fff */
-#define MIN_16 (Word16)-32768   /* 0x8000 */
+#define MAX_16 ((Word16)+32767)   /* 0x7fff */
+#define MIN_16 ((Word16)-32768)   /* 0x8000 */
 
 
 #define  static_vo  static __inline
@@ -41,23 +41,23 @@
 #define L_negate(L_var1) (((L_var1) == (MIN_32)) ? (MAX_32) : (-(L_var1)))                 /* Long negate,     2*/
 
 
-#define extract_h(a)            ((Word16)(a >> 16))
-#define extract_l(x)                (Word16)((x))
-#define add1(a,b)           (a + b)
-#define vo_L_msu(a,b,c)         ( a - (( b * c ) << 1) )
+#define extract_h(a)            ((Word16)((a) >> 16))
+#define extract_l(x)            (Word16)((x))
+#define add1(a,b)               ((a) + (b))
+#define vo_L_msu(a,b,c)         ((a) - (((b) * (c)) << 1))
 #define vo_mult32(a, b)         ((a) * (b))
-#define vo_mult(a,b)            (( a * b ) >> 15 )
-#define vo_L_mult(a,b)              (((a) * (b)) << 1)
-#define vo_shr_r(var1, var2)        ((var1+((Word16)(1L<<(var2-1))))>>var2)
-#define vo_sub(a,b)         (a - b)
+#define vo_mult(a,b)            (((a) * (b)) >> 15)
+#define vo_L_mult(a,b)          (((a) * (b)) << 1)
+#define vo_shr_r(var1, var2)    (((var1)+((Word16)(1L<<((var2)-1))))>>(var2))
+#define vo_sub(a,b)             ((a) - (b))
 #define vo_L_deposit_h(a)       ((Word32)((a) << 16))
-#define vo_round(a)         ((((a) >> 15) + 1) >> 1)
+#define vo_round(a)             ((((a) >> 15) + 1) >> 1)
 #define vo_extract_l(a)         ((Word16)(a))
-#define vo_L_add(a,b)           (a + b)
-#define vo_L_sub(a,b)           (a - b)
-#define vo_mult_r(a,b)          (((( a * b ) >> 14) + 1 ) >> 1 )
-#define vo_negate(a)                (-a)
-#define vo_L_shr_r(L_var1, var2)        ((L_var1+((Word32)(1L<<(var2-1))))>>var2)
+#define vo_L_add(a,b)           ((a) + (b))
+#define vo_L_sub(a,b)           ((a) - (b))
+#define vo_mult_r(a,b)          (((( (a) * (b) ) >> 14) + 1 ) >> 1 )
+#define vo_negate(a)            (-(a))
+#define vo_L_shr_r(L_var1, var2) (((L_var1)+((Word32)(1L<<((var2)-1))))>>(var2))
 
 
 /*___________________________________________________________________________
@@ -765,7 +765,7 @@
                 break;
             }
         }
-        L_var1 <<=1 ;
+        L_var1 *= 2 ;
         L_var_out = L_var1;
     }
     return (L_var_out);
diff --git a/media/libstagefright/codecs/amrwbenc/inc/bits.h b/media/libstagefright/codecs/amrwbenc/inc/bits.h
index ff9c0c1..57e71f7 100644
--- a/media/libstagefright/codecs/amrwbenc/inc/bits.h
+++ b/media/libstagefright/codecs/amrwbenc/inc/bits.h
@@ -42,7 +42,7 @@
 #define NBBITS_SID    35
 #define NB_BITS_MAX   NBBITS_24k
 
-#define BIT_0     (Word16)-127
+#define BIT_0     ((Word16)-127)
 #define BIT_1     (Word16)127
 #define BIT_0_ITU (Word16)0x007F
 #define BIT_1_ITU (Word16)0x0081
diff --git a/media/libstagefright/codecs/amrwbenc/inc/dtx.h b/media/libstagefright/codecs/amrwbenc/inc/dtx.h
index 82a9bf4..7d7ebd8 100644
--- a/media/libstagefright/codecs/amrwbenc/inc/dtx.h
+++ b/media/libstagefright/codecs/amrwbenc/inc/dtx.h
@@ -31,7 +31,7 @@
 #define DTX_HANG_CONST 7                   /* yields eight frames of SP HANGOVER  */
 #define INV_MED_THRESH 14564
 #define ISF_GAP  128                       /* 50 */
-#define ONE_MINUS_ISF_GAP 16384 - ISF_GAP
+#define ONE_MINUS_ISF_GAP (16384 - ISF_GAP)
 #define ISF_GAP   128
 #define ISF_DITH_GAP   448
 #define ISF_FACTOR_LOW 256
diff --git a/media/libstagefright/codecs/amrwbenc/inc/homing.tab b/media/libstagefright/codecs/amrwbenc/inc/homing.tab
index e399fb8..6408d3a 100644
--- a/media/libstagefright/codecs/amrwbenc/inc/homing.tab
+++ b/media/libstagefright/codecs/amrwbenc/inc/homing.tab
@@ -21,15 +21,15 @@
 #define NUM_OF_SPMODES 9
 
 #define PRML 15
-#define PRMN_7k NBBITS_7k/PRML + 1
-#define PRMN_9k NBBITS_9k/PRML + 1
-#define PRMN_12k NBBITS_12k/PRML + 1
-#define PRMN_14k NBBITS_14k/PRML + 1
-#define PRMN_16k NBBITS_16k/PRML + 1
-#define PRMN_18k NBBITS_18k/PRML + 1
-#define PRMN_20k NBBITS_20k/PRML + 1
-#define PRMN_23k NBBITS_23k/PRML + 1
-#define PRMN_24k NBBITS_24k/PRML + 1
+#define PRMN_7k (NBBITS_7k/PRML + 1)
+#define PRMN_9k (NBBITS_9k/PRML + 1)
+#define PRMN_12k (NBBITS_12k/PRML + 1)
+#define PRMN_14k (NBBITS_14k/PRML + 1)
+#define PRMN_16k (NBBITS_16k/PRML + 1)
+#define PRMN_18k (NBBITS_18k/PRML + 1)
+#define PRMN_20k (NBBITS_20k/PRML + 1)
+#define PRMN_23k (NBBITS_23k/PRML + 1)
+#define PRMN_24k (NBBITS_24k/PRML + 1)
 
 static const Word16 dfh_M7k[PRMN_7k] =
 {
diff --git a/media/libstagefright/codecs/amrwbenc/inc/stream.h b/media/libstagefright/codecs/amrwbenc/inc/stream.h
index ec1a700..fbaae9e 100644
--- a/media/libstagefright/codecs/amrwbenc/inc/stream.h
+++ b/media/libstagefright/codecs/amrwbenc/inc/stream.h
@@ -26,7 +26,7 @@
 #define __STREAM_H__
 
 #include "voMem.h"
-#define Frame_Maxsize  1024 * 2  //Work Buffer 10K
+#define Frame_Maxsize  (1024 * 2)  //Work Buffer 10K
 #define Frame_MaxByte  640        //AMR_WB Encoder one frame 320 samples = 640 Bytes
 #define MIN(a,b)     ((a) < (b)? (a) : (b))
 
diff --git a/media/libstagefright/codecs/avc/enc/src/avcenc_int.h b/media/libstagefright/codecs/avc/enc/src/avcenc_int.h
index 3fe08a1..22042a5 100644
--- a/media/libstagefright/codecs/avc/enc/src/avcenc_int.h
+++ b/media/libstagefright/codecs/avc/enc/src/avcenc_int.h
@@ -43,7 +43,7 @@
 #define MAX_QP          51
 #define SHIFT_QP        12
 #define  LAMBDA_ACCURACY_BITS         16
-#define  LAMBDA_FACTOR(lambda)        ((int)((double)(1<<LAMBDA_ACCURACY_BITS)*lambda+0.5))
+#define  LAMBDA_FACTOR(lambda)        ((int)((double)(1<<LAMBDA_ACCURACY_BITS)*(lambda)+0.5))
 
 
 #define DISABLE_THRESHOLDING  0
@@ -55,8 +55,8 @@
 #define MAX_VALUE       999999   //!< used for start value for some variables
 
 #define  WEIGHTED_COST(factor,bits)   (((factor)*(bits))>>LAMBDA_ACCURACY_BITS)
-#define  MV_COST(f,s,cx,cy,px,py)     (WEIGHTED_COST(f,mvbits[((cx)<<(s))-px]+mvbits[((cy)<<(s))-py]))
-#define  MV_COST_S(f,cx,cy,px,py)     (WEIGHTED_COST(f,mvbits[cx-px]+mvbits[cy-py]))
+#define  MV_COST(f,s,cx,cy,px,py)     (WEIGHTED_COST(f,mvbits[((cx)<<(s))-(px)]+mvbits[((cy)<<((s)))-(py)]))
+#define  MV_COST_S(f,cx,cy,px,py)     (WEIGHTED_COST(f,mvbits[(cx)-(px)]+mvbits[(cy)-(py)]))
 
 /* for sub-pel search and interpolation */
 #define SUBPEL_PRED_BLK_SIZE 576 // 24x24
diff --git a/media/libstagefright/codecs/avc/enc/src/findhalfpel.cpp b/media/libstagefright/codecs/avc/enc/src/findhalfpel.cpp
index d0bbee2..941ae5a 100644
--- a/media/libstagefright/codecs/avc/enc/src/findhalfpel.cpp
+++ b/media/libstagefright/codecs/avc/enc/src/findhalfpel.cpp
@@ -23,13 +23,13 @@
 
 #define PREF_16_VEC 129     /* 1MV bias versus 4MVs*/
 
-#define CLIP_RESULT(x)      if((uint)x > 0xFF){ \
-                 x = 0xFF & (~(x>>31));}
+#define CLIP_RESULT(x)      if((uint)(x) > 0xFF){ \
+                 (x) = 0xFF & (~((x)>>31));}
 
-#define CLIP_UPPER16(x)     if((uint)x >= 0x20000000){ \
-        x = 0xFF0000 & (~(x>>31));} \
+#define CLIP_UPPER16(x)     if((uint)(x) >= 0x20000000){ \
+        (x) = 0xFF0000 & (~((x)>>31));} \
         else { \
-        x = (x>>5)&0xFF0000; \
+        (x) = ((x)>>5)&0xFF0000; \
         }
 
 /*=====================================================================
diff --git a/media/libstagefright/codecs/avc/enc/src/intra_est.cpp b/media/libstagefright/codecs/avc/enc/src/intra_est.cpp
index 17e5985..e397805 100644
--- a/media/libstagefright/codecs/avc/enc/src/intra_est.cpp
+++ b/media/libstagefright/codecs/avc/enc/src/intra_est.cpp
@@ -25,8 +25,8 @@
 #define FIXED_I4_MODE   AVC_I4_Diagonal_Down_Left
 #define FIXED_INTRA_CHROMA_MODE AVC_IC_DC
 
-#define CLIP_RESULT(x)      if((uint)x > 0xFF){ \
-                 x = 0xFF & (~(x>>31));}
+#define CLIP_RESULT(x)      if((uint)(x) > 0xFF){ \
+                 (x) = 0xFF & (~((x)>>31));}
 
 
 bool IntraDecisionABE(AVCEncObject *encvid, int min_cost, uint8 *curL, int picPitch)
diff --git a/media/libstagefright/codecs/avc/enc/src/motion_comp.cpp b/media/libstagefright/codecs/avc/enc/src/motion_comp.cpp
index a390f88..d19125f 100644
--- a/media/libstagefright/codecs/avc/enc/src/motion_comp.cpp
+++ b/media/libstagefright/codecs/avc/enc/src/motion_comp.cpp
@@ -19,8 +19,8 @@
 #include "avcenc_int.h"
 
 
-#define CLIP_RESULT(x)      if((uint)x > 0xFF){ \
-                 x = 0xFF & (~(x>>31));}
+#define CLIP_RESULT(x)      if((uint)(x) > 0xFF){ \
+                 (x) = 0xFF & (~((x)>>31));}
 
 /* (blkwidth << 2) + (dy << 1) + dx */
 static void (*const eChromaMC_SIMD[8])(uint8 *, int , int , int , uint8 *, int, int , int) =
diff --git a/media/libstagefright/codecs/avcdec/SoftAVCDec.h b/media/libstagefright/codecs/avcdec/SoftAVCDec.h
index 154ca38..b333190 100644
--- a/media/libstagefright/codecs/avcdec/SoftAVCDec.h
+++ b/media/libstagefright/codecs/avcdec/SoftAVCDec.h
@@ -46,8 +46,8 @@
 
 /** Compute difference between start and end */
 #define TIME_DIFF(start, end, diff) \
-    diff = ((end.tv_sec - start.tv_sec) * 1000000) + \
-            (end.tv_usec - start.tv_usec);
+    diff = (((end).tv_sec - (start).tv_sec) * 1000000) + \
+            ((end).tv_usec - (start).tv_usec);
 
 struct SoftAVC : public SoftVideoDecoderOMXComponent {
     SoftAVC(const char *name, const OMX_CALLBACKTYPE *callbacks,
diff --git a/media/libstagefright/codecs/avcenc/SoftAVCEnc.h b/media/libstagefright/codecs/avcenc/SoftAVCEnc.h
index cf6f899..4d30ba0 100644
--- a/media/libstagefright/codecs/avcenc/SoftAVCEnc.h
+++ b/media/libstagefright/codecs/avcenc/SoftAVCEnc.h
@@ -111,8 +111,8 @@
 
 /** Compute difference between start and end */
 #define TIME_DIFF(start, end, diff) \
-    diff = ((end.tv_sec - start.tv_sec) * 1000000) + \
-            (end.tv_usec - start.tv_usec);
+    diff = (((end).tv_sec - (start).tv_sec) * 1000000) + \
+            ((end).tv_usec - (start).tv_usec);
 
 #define ive_aligned_malloc(alignment, size) memalign(alignment, size)
 #define ive_aligned_free(buf) free(buf)
diff --git a/media/libstagefright/codecs/common/include/voAAC.h b/media/libstagefright/codecs/common/include/voAAC.h
index 9ecb142..0a02feb 100644
--- a/media/libstagefright/codecs/common/include/voAAC.h
+++ b/media/libstagefright/codecs/common/include/voAAC.h
@@ -50,7 +50,7 @@
 
 /* AAC Param ID */
 #define VO_PID_AAC_Mdoule				0x42211000
-#define VO_PID_AAC_ENCPARAM				VO_PID_AAC_Mdoule | 0x0040  /*!< get/set AAC encoder parameter, the parameter is a pointer to AACENC_PARAM */
+#define VO_PID_AAC_ENCPARAM				(VO_PID_AAC_Mdoule | 0x0040)  /*!< get/set AAC encoder parameter, the parameter is a pointer to AACENC_PARAM */
 
 /* AAC decoder error ID */
 #define VO_ERR_AAC_Mdoule				0x82210000
diff --git a/media/libstagefright/codecs/common/include/voAudio.h b/media/libstagefright/codecs/common/include/voAudio.h
index d8628ee..98d3f44 100644
--- a/media/libstagefright/codecs/common/include/voAudio.h
+++ b/media/libstagefright/codecs/common/include/voAudio.h
@@ -38,9 +38,9 @@
 #define VO_PID_AUDIO_CHANNELMODE	(VO_PID_AUDIO_BASE | 0X0005)		/*!< The channel mode of audio */
 
 #define	VO_ERR_AUDIO_BASE			0x82000000
-#define VO_ERR_AUDIO_UNSCHANNEL		VO_ERR_AUDIO_BASE | 0x0001
-#define VO_ERR_AUDIO_UNSSAMPLERATE	VO_ERR_AUDIO_BASE | 0x0002
-#define VO_ERR_AUDIO_UNSFEATURE		VO_ERR_AUDIO_BASE | 0x0003
+#define VO_ERR_AUDIO_UNSCHANNEL		(VO_ERR_AUDIO_BASE | 0x0001)
+#define VO_ERR_AUDIO_UNSSAMPLERATE	(VO_ERR_AUDIO_BASE | 0x0002)
+#define VO_ERR_AUDIO_UNSFEATURE		(VO_ERR_AUDIO_BASE | 0x0003)
 
 
 /**
diff --git a/media/libstagefright/codecs/common/include/voIndex.h b/media/libstagefright/codecs/common/include/voIndex.h
index 320a2f8..97b21f3 100644
--- a/media/libstagefright/codecs/common/include/voIndex.h
+++ b/media/libstagefright/codecs/common/include/voIndex.h
@@ -31,26 +31,26 @@
 
 /* Define the module ID */
 #define _MAKE_SOURCE_ID(id, name) \
-VO_INDEX_SRC_##name = _VO_INDEX_SOURCE | id,
+VO_INDEX_SRC_##name = _VO_INDEX_SOURCE | (id),
 
 #define _MAKE_CODEC_ID(id, name) \
-VO_INDEX_DEC_##name = _VO_INDEX_DEC | id, \
-VO_INDEX_ENC_##name = _VO_INDEX_ENC | id,
+VO_INDEX_DEC_##name = _VO_INDEX_DEC | (id), \
+VO_INDEX_ENC_##name = _VO_INDEX_ENC | (id),
 
 #define _MAKE_EFFECT_ID(id, name) \
-VO_INDEX_EFT_##name = _VO_INDEX_EFFECT | id,
+VO_INDEX_EFT_##name = _VO_INDEX_EFFECT | (id),
 
 #define _MAKE_SINK_ID(id, name) \
-VO_INDEX_SNK_##name = _VO_INDEX_SINK | id,
+VO_INDEX_SNK_##name = _VO_INDEX_SINK | (id),
 
 #define _MAKE_FILTER_ID(id, name) \
-VO_INDEX_FLT_##name = _VO_INDEX_FILTER | id,
+VO_INDEX_FLT_##name = _VO_INDEX_FILTER | (id),
 
 #define _MAKE_OMX_ID(id, name) \
-VO_INDEX_OMX_##name = _VO_INDEX_OMX | id,
+VO_INDEX_OMX_##name = _VO_INDEX_OMX | (id),
 
 #define _MAKE_MFW_ID(id, name) \
-VO_INDEX_MFW_##name = _VO_INDEX_MFW | id,
+VO_INDEX_MFW_##name = _VO_INDEX_MFW | (id),
 
 enum
 {
diff --git a/media/libstagefright/codecs/common/include/voMem.h b/media/libstagefright/codecs/common/include/voMem.h
index 8dfb634..2b5aef1 100644
--- a/media/libstagefright/codecs/common/include/voMem.h
+++ b/media/libstagefright/codecs/common/include/voMem.h
@@ -53,8 +53,8 @@
 { \
 	VO_MEM_INFO voMemInfo; \
 	voMemInfo.Size=nSize; \
-	pMemOP->Alloc(ID, &voMemInfo); \
-	pBuff=(VO_PBYTE)voMemInfo.VBuffer; \
+	(pMemOP)->Alloc(ID, &voMemInfo); \
+	(pBuff)=(VO_PBYTE)voMemInfo.VBuffer; \
 }
 
 
diff --git a/media/libstagefright/codecs/hevcdec/SoftHEVC.h b/media/libstagefright/codecs/hevcdec/SoftHEVC.h
index 20a836b..e7c2127 100644
--- a/media/libstagefright/codecs/hevcdec/SoftHEVC.h
+++ b/media/libstagefright/codecs/hevcdec/SoftHEVC.h
@@ -46,8 +46,8 @@
 
 /** Compute difference between start and end */
 #define TIME_DIFF(start, end, diff) \
-    diff = ((end.tv_sec - start.tv_sec) * 1000000) + \
-            (end.tv_usec - start.tv_usec);
+    diff = (((end).tv_sec - (start).tv_sec) * 1000000) + \
+            ((end).tv_usec - (start).tv_usec);
 
 struct SoftHEVC: public SoftVideoDecoderOMXComponent {
     SoftHEVC(const char *name, const OMX_CALLBACKTYPE *callbacks,
diff --git a/media/libstagefright/codecs/m4v_h263/dec/include/m4vh263_decoder_pv_types.h b/media/libstagefright/codecs/m4v_h263/dec/include/m4vh263_decoder_pv_types.h
index ec6871f..711ec58 100644
--- a/media/libstagefright/codecs/m4v_h263/dec/include/m4vh263_decoder_pv_types.h
+++ b/media/libstagefright/codecs/m4v_h263/dec/include/m4vh263_decoder_pv_types.h
@@ -51,7 +51,7 @@
 {
     public:
         OsclAOStatus();
-        OsclAOStatus(int32 aStatus);
+        explicit OsclAOStatus(int32 aStatus);
         int32 operator=(int32 aStatus);
         int32 operator==(int32 aStatus) const;
         int32 operator!=(int32 aStatus) const;
diff --git a/media/libstagefright/codecs/m4v_h263/dec/src/idct.h b/media/libstagefright/codecs/m4v_h263/dec/src/idct.h
index 8edb654..484631b 100644
--- a/media/libstagefright/codecs/m4v_h263/dec/src/idct.h
+++ b/media/libstagefright/codecs/m4v_h263/dec/src/idct.h
@@ -80,9 +80,9 @@
 #define W7 565                  /* 2048*sqrt(2)*cos(7*pi/16) */
 #define W1mW7 2276
 #define W1pW7 3406
-#define W5mW3 -799
-#define mW3mW5 -4017
-#define mW2mW6 -3784
+#define W5mW3 (-799)
+#define mW3mW5 (-4017)
+#define mW2mW6 (-3784)
 #define W2mW6 1568
 
 /* left shift by 11 is to maintain the accuracy of the decimal point */
diff --git a/media/libstagefright/codecs/m4v_h263/dec/src/motion_comp.h b/media/libstagefright/codecs/m4v_h263/dec/src/motion_comp.h
index 0c12f20..68281ba 100644
--- a/media/libstagefright/codecs/m4v_h263/dec/src/motion_comp.h
+++ b/media/libstagefright/codecs/m4v_h263/dec/src/motion_comp.h
@@ -54,20 +54,20 @@
 {
 #endif
 
-#define CLIP_RESULT(x)      if(x & -256){x = 0xFF & (~(x>>31));}
+#define CLIP_RESULT(x)      if((x) & -256){(x) = 0xFF & (~((x)>>31));}
 #define ADD_AND_CLIP1(x)    x += (pred_word&0xFF); CLIP_RESULT(x);
 #define ADD_AND_CLIP2(x)    x += ((pred_word>>8)&0xFF); CLIP_RESULT(x);
 #define ADD_AND_CLIP3(x)    x += ((pred_word>>16)&0xFF); CLIP_RESULT(x);
 #define ADD_AND_CLIP4(x)    x += ((pred_word>>24)&0xFF); CLIP_RESULT(x);
 
-#define ADD_AND_CLIP(x,y)    {  x9 = ~(x>>8); \
+#define ADD_AND_CLIP(x,y)    {  x9 = ~((x)>>8); \
                             if(x9!=-1){ \
                                 x9 = ((uint32)x9)>>24; \
-                                y = x9|(y<<8); \
+                                (y) = x9|((y)<<8); \
                             } \
                             else \
                             {    \
-                                y =  x|(y<<8); \
+                                (y) =  (x)|((y)<<8); \
                             } \
                             }
 
diff --git a/media/libstagefright/codecs/m4v_h263/dec/src/mp4def.h b/media/libstagefright/codecs/m4v_h263/dec/src/mp4def.h
index 3388d89..20f458d 100644
--- a/media/libstagefright/codecs/m4v_h263/dec/src/mp4def.h
+++ b/media/libstagefright/codecs/m4v_h263/dec/src/mp4def.h
@@ -47,7 +47,7 @@
 /* You don't want to use ((x>UB)?UB:(x<LB)?LB:x) for the clipping */
 /*    because it will use one extra comparison if the compiler is */
 /*    not well-optimized.    04/19/2000.                        */
-#define CLIP_THE_RANGE(x,LB,UB) if (x<LB) x = LB; else if (x>UB) x = UB
+#define CLIP_THE_RANGE(x,LB,UB) if ((x)<(LB)) (x) = (LB); else if ((x)>(UB)) (x) = (UB)
 
 #define MODE_INTRA      0x08 //01000
 #define MODE_INTRA_Q    0x09 //01001
@@ -72,7 +72,7 @@
 #define START_CODE_LENGTH       32
 
 /* 11/30/98 */
-#define NoMarkerFound -1
+#define NoMarkerFound (-1)
 #define FoundRM     1   /* Resync Marker */
 #define FoundVSC    2   /* VOP_START_CODE. */
 #define FoundGSC    3   /* GROUP_START_CODE */
@@ -153,7 +153,7 @@
 
 
 /* macro utility */
-#define  ZERO_OUT_64BYTES(x)    { *((uint32*)x) = *(((uint32*)(x))+1) =  \
+#define  ZERO_OUT_64BYTES(x)    { *((uint32*)(x)) = *(((uint32*)(x))+1) =  \
         *(((uint32*)(x))+2) = *(((uint32*)(x))+3) =  \
         *(((uint32*)(x))+4) = *(((uint32*)(x))+5) =  \
         *(((uint32*)(x))+6) = *(((uint32*)(x))+7) =  \
diff --git a/media/libstagefright/codecs/m4v_h263/dec/src/post_proc.h b/media/libstagefright/codecs/m4v_h263/dec/src/post_proc.h
index 091fdaf..a8ab37f 100644
--- a/media/libstagefright/codecs/m4v_h263/dec/src/post_proc.h
+++ b/media/libstagefright/codecs/m4v_h263/dec/src/post_proc.h
@@ -32,9 +32,9 @@
 ; DEFINES
 ; Include all pre-processor statements here.
 ----------------------------------------------------------------------------*/
-#define UPDATE_PV_MAXPV_MIN(p,max,min) if ((p) > max) max=(p); else if ((p) < min) min = (p);
+#define UPDATE_PV_MAXPV_MIN(p,max,min) if ((p) > (max)) (max)=(p); else if ((p) < (min)) (min) = (p);
 
-#define     INDEX(x,thr)    (((x)>=thr)?1:0)
+#define     INDEX(x,thr)    (((x)>=(thr))?1:0)
 #define     BLKSIZE     8
 #define     MBSIZE      16
 #define     DERING_THR  16
diff --git a/media/libstagefright/codecs/m4v_h263/dec/src/vlc_decode.h b/media/libstagefright/codecs/m4v_h263/dec/src/vlc_decode.h
index a804606..e242820 100644
--- a/media/libstagefright/codecs/m4v_h263/dec/src/vlc_decode.h
+++ b/media/libstagefright/codecs/m4v_h263/dec/src/vlc_decode.h
@@ -79,10 +79,10 @@
 #include "mp4lib_int.h"
 
 #define VLC_ERROR_DETECTED(x) ((x) < 0)
-#define VLC_IO_ERROR    -1
-#define VLC_CODE_ERROR  -2
-#define VLC_MB_STUFFING -4
-#define VLC_NO_LAST_BIT -5
+#define VLC_IO_ERROR    (-1)
+#define VLC_CODE_ERROR  (-2)
+#define VLC_MB_STUFFING (-4)
+#define VLC_NO_LAST_BIT (-5)
 
 #define VLC_ESCAPE_CODE  7167
 
diff --git a/media/libstagefright/codecs/m4v_h263/enc/src/fastidct.cpp b/media/libstagefright/codecs/m4v_h263/enc/src/fastidct.cpp
index 21d7427..688effc 100644
--- a/media/libstagefright/codecs/m4v_h263/enc/src/fastidct.cpp
+++ b/media/libstagefright/codecs/m4v_h263/enc/src/fastidct.cpp
@@ -55,7 +55,7 @@
         }
 
 
-#define CLIP_RESULT(x)      if((UInt)x > 0xFF){x = 0xFF & (~(x>>31));}
+#define CLIP_RESULT(x)      if((UInt)(x) > 0xFF){(x) = 0xFF & (~((x)>>31));}
 #define ADD_AND_CLIP1(x)    x += (pred_word&0xFF); CLIP_RESULT(x);
 #define ADD_AND_CLIP2(x)    x += ((pred_word>>8)&0xFF); CLIP_RESULT(x);
 #define ADD_AND_CLIP3(x)    x += ((pred_word>>16)&0xFF); CLIP_RESULT(x);
diff --git a/media/libstagefright/codecs/mp3dec/src/pv_mp3dec_fxd_op_c_equivalent.h b/media/libstagefright/codecs/mp3dec/src/pv_mp3dec_fxd_op_c_equivalent.h
index ba43820..337bff0 100644
--- a/media/libstagefright/codecs/mp3dec/src/pv_mp3dec_fxd_op_c_equivalent.h
+++ b/media/libstagefright/codecs/mp3dec/src/pv_mp3dec_fxd_op_c_equivalent.h
@@ -44,9 +44,9 @@
 #endif
 
 #include "pvmp3_audio_type_defs.h"
-#define Qfmt_31(a)   (Int32)((float)a*0x7FFFFFFF)
+#define Qfmt_31(a)   (Int32)((float)(a)*0x7FFFFFFF)
 
-#define Qfmt15(x)   (Int16)(x*((Int32)1<<15) + (x>=0?0.5F:-0.5F))
+#define Qfmt15(x)   (Int16)((x)*((Int32)1<<15) + ((x)>=0?0.5F:-0.5F))
 
 
 
diff --git a/media/libstagefright/codecs/mp3dec/src/pvmp3_alias_reduction.cpp b/media/libstagefright/codecs/mp3dec/src/pvmp3_alias_reduction.cpp
index 32c76c6..af738ba 100644
--- a/media/libstagefright/codecs/mp3dec/src/pvmp3_alias_reduction.cpp
+++ b/media/libstagefright/codecs/mp3dec/src/pvmp3_alias_reduction.cpp
@@ -109,7 +109,7 @@
 ----------------------------------------------------------------------------*/
 #define NUM_BUTTERFLIES 8
 
-#define Q31_fmt(a)    (int32(double(0x7FFFFFFF)*a))
+#define Q31_fmt(a)    (int32(double(0x7FFFFFFF)*(a)))
 
 /*----------------------------------------------------------------------------
 ; LOCAL FUNCTION DEFINITIONS
diff --git a/media/libstagefright/codecs/mp3dec/src/pvmp3_dct_16.cpp b/media/libstagefright/codecs/mp3dec/src/pvmp3_dct_16.cpp
index a71efc4..9b9ae4b 100644
--- a/media/libstagefright/codecs/mp3dec/src/pvmp3_dct_16.cpp
+++ b/media/libstagefright/codecs/mp3dec/src/pvmp3_dct_16.cpp
@@ -109,7 +109,7 @@
 ; Include all pre-processor statements here. Include conditional
 ; compile variables also.
 ----------------------------------------------------------------------------*/
-#define Qfmt(a)   (int32)(a*((int32)1<<27))
+#define Qfmt(a)   (int32)((a)*((int32)1<<27))
 
 /*----------------------------------------------------------------------------
 ; LOCAL FUNCTION DEFINITIONS
diff --git a/media/libstagefright/codecs/mp3dec/src/pvmp3_dct_6.cpp b/media/libstagefright/codecs/mp3dec/src/pvmp3_dct_6.cpp
index 4c5fb03..1f8018a 100644
--- a/media/libstagefright/codecs/mp3dec/src/pvmp3_dct_6.cpp
+++ b/media/libstagefright/codecs/mp3dec/src/pvmp3_dct_6.cpp
@@ -79,7 +79,7 @@
 ; Include all pre-processor statements here. Include conditional
 ; compile variables also.
 ----------------------------------------------------------------------------*/
-#define Qfmt30(a)   (Int32)(a*((Int32)1<<30) + (a>=0?0.5F:-0.5F))
+#define Qfmt30(a)   (Int32)((a)*((Int32)1<<30) + ((a)>=0?0.5F:-0.5F))
 
 #define cos_pi_6     Qfmt30(  0.86602540378444f)
 #define cos_2_pi_6   Qfmt30(  0.5f)
diff --git a/media/libstagefright/codecs/mp3dec/src/pvmp3_dct_9.cpp b/media/libstagefright/codecs/mp3dec/src/pvmp3_dct_9.cpp
index ce3ec64..d30ce4a 100644
--- a/media/libstagefright/codecs/mp3dec/src/pvmp3_dct_9.cpp
+++ b/media/libstagefright/codecs/mp3dec/src/pvmp3_dct_9.cpp
@@ -77,7 +77,7 @@
 ; Include all pre-processor statements here. Include conditional
 ; compile variables also.
 ----------------------------------------------------------------------------*/
-#define Qfmt31(a)   (int32)(a*(0x7FFFFFFF))
+#define Qfmt31(a)   (int32)((a)*(0x7FFFFFFF))
 
 #define cos_pi_9    Qfmt31( 0.93969262078591f)
 #define cos_2pi_9   Qfmt31( 0.76604444311898f)
diff --git a/media/libstagefright/codecs/mp3dec/src/pvmp3_dec_defs.h b/media/libstagefright/codecs/mp3dec/src/pvmp3_dec_defs.h
index 6cf8e3e..2be9ab9 100644
--- a/media/libstagefright/codecs/mp3dec/src/pvmp3_dec_defs.h
+++ b/media/libstagefright/codecs/mp3dec/src/pvmp3_dec_defs.h
@@ -53,7 +53,7 @@
 ; MACROS
 ; Define module specific macros here
 ----------------------------------------------------------------------------*/
-#define module(x, POW2)   ((x)&(POW2-1))
+#define module(x, POW2)   ((x)&((POW2)-1))
 
 /*----------------------------------------------------------------------------
 ; DEFINES
@@ -75,7 +75,7 @@
 #define MPEG_1              0
 #define MPEG_2              1
 #define MPEG_2_5            2
-#define INVALID_VERSION     -1
+#define INVALID_VERSION   (-1)
 
 /* MPEG Header Definitions - Mode Values */
 
diff --git a/media/libstagefright/codecs/mp3dec/src/pvmp3_dequantize_sample.cpp b/media/libstagefright/codecs/mp3dec/src/pvmp3_dequantize_sample.cpp
index 69e1987..639df81 100644
--- a/media/libstagefright/codecs/mp3dec/src/pvmp3_dequantize_sample.cpp
+++ b/media/libstagefright/codecs/mp3dec/src/pvmp3_dequantize_sample.cpp
@@ -108,8 +108,8 @@
 ; Include all pre-processor statements here. Include conditional
 ; compile variables also.
 ----------------------------------------------------------------------------*/
-#define Q30_fmt(a)(int32(double(0x40000000)*a))
-#define Q29_fmt(a)(int32(double(0x20000000)*a))
+#define Q30_fmt(a)(int32(double(0x40000000)*(a)))
+#define Q29_fmt(a)(int32(double(0x20000000)*(a)))
 
 /*----------------------------------------------------------------------------
 ; LOCAL FUNCTION DEFINITIONS
diff --git a/media/libstagefright/codecs/mp3dec/src/pvmp3_equalizer.cpp b/media/libstagefright/codecs/mp3dec/src/pvmp3_equalizer.cpp
index f4a4efb..61aef30 100644
--- a/media/libstagefright/codecs/mp3dec/src/pvmp3_equalizer.cpp
+++ b/media/libstagefright/codecs/mp3dec/src/pvmp3_equalizer.cpp
@@ -98,7 +98,7 @@
 #define LEVEL_45__dB  0.005524271f
 #define LEVEL_60__dB  0.000976562f
 
-#define Qmf31( x)    (int32)(x*(float)0x7FFFFFFF)
+#define Qmf31( x)    (int32)((x)*(float)0x7FFFFFFF)
 
 
 /*----------------------------------------------------------------------------
diff --git a/media/libstagefright/codecs/mp3dec/src/pvmp3_get_scale_factors.cpp b/media/libstagefright/codecs/mp3dec/src/pvmp3_get_scale_factors.cpp
index f1a3ff8..d4a2060 100644
--- a/media/libstagefright/codecs/mp3dec/src/pvmp3_get_scale_factors.cpp
+++ b/media/libstagefright/codecs/mp3dec/src/pvmp3_get_scale_factors.cpp
@@ -86,7 +86,7 @@
 ; Include all pre-processor statements here. Include conditional
 ; compile variables also.
 ----------------------------------------------------------------------------*/
-#define Qfmt_28(a)(int32(double(0x10000000)*a))
+#define Qfmt_28(a)(int32(double(0x10000000)*(a)))
 
 /*----------------------------------------------------------------------------
 ; LOCAL FUNCTION DEFINITIONS
diff --git a/media/libstagefright/codecs/mp3dec/src/pvmp3_mdct_18.h b/media/libstagefright/codecs/mp3dec/src/pvmp3_mdct_18.h
index e497aee..2f2f65c 100644
--- a/media/libstagefright/codecs/mp3dec/src/pvmp3_mdct_18.h
+++ b/media/libstagefright/codecs/mp3dec/src/pvmp3_mdct_18.h
@@ -59,9 +59,9 @@
 ; DEFINES
 ; Include all pre-processor statements here.
 ----------------------------------------------------------------------------*/
-#define Qfmt(a)    (Int32)(a*((Int32)1<<28) )
-#define Qfmt1(a)   (Int32)(a*((Int32)0x7FFFFFFF))
-#define Qfmt2(a)   (Int32)(a*((Int32)1<<27))
+#define Qfmt(a)    (Int32)((a)*((Int32)1<<28) )
+#define Qfmt1(a)   (Int32)((a)*((Int32)0x7FFFFFFF))
+#define Qfmt2(a)   (Int32)((a)*((Int32)1<<27))
 
 /*----------------------------------------------------------------------------
 ; EXTERNAL VARIABLES REFERENCES
diff --git a/media/libstagefright/codecs/mp3dec/src/pvmp3_mdct_6.cpp b/media/libstagefright/codecs/mp3dec/src/pvmp3_mdct_6.cpp
index 6a72aad..8d80e8f 100644
--- a/media/libstagefright/codecs/mp3dec/src/pvmp3_mdct_6.cpp
+++ b/media/libstagefright/codecs/mp3dec/src/pvmp3_mdct_6.cpp
@@ -81,7 +81,7 @@
 ; compile variables also.
 ----------------------------------------------------------------------------*/
 #define QFORMAT    29
-#define Qfmt29(a)   (int32)(a*((int32)1<<QFORMAT) + (a>=0?0.5F:-0.5F))
+#define Qfmt29(a)   (int32)((a)*((int32)1<<QFORMAT) + ((a)>=0?0.5F:-0.5F))
 
 /*----------------------------------------------------------------------------
 ; LOCAL FUNCTION DEFINITIONS
diff --git a/media/libstagefright/codecs/mp3dec/src/pvmp3_mdct_6.h b/media/libstagefright/codecs/mp3dec/src/pvmp3_mdct_6.h
index 6ba53d7..af4f286 100644
--- a/media/libstagefright/codecs/mp3dec/src/pvmp3_mdct_6.h
+++ b/media/libstagefright/codecs/mp3dec/src/pvmp3_mdct_6.h
@@ -59,9 +59,9 @@
 ; DEFINES
 ; Include all pre-processor statements here.
 ----------------------------------------------------------------------------*/
-#define Qfmt(a)    (Int32)(a*((Int32)1<<28) )
-#define Qfmt1(a)   (Int32)(a*((Int32)0x7FFFFFFF))
-#define Qfmt2(a)   (Int32)(a*((Int32)1<<27))
+#define Qfmt(a)    (Int32)((a)*((Int32)1<<28) )
+#define Qfmt1(a)   (Int32)((a)*((Int32)0x7FFFFFFF))
+#define Qfmt2(a)   (Int32)((a)*((Int32)1<<27))
 
 /*----------------------------------------------------------------------------
 ; EXTERNAL VARIABLES REFERENCES
diff --git a/media/libstagefright/codecs/mp3dec/src/pvmp3_mpeg2_stereo_proc.cpp b/media/libstagefright/codecs/mp3dec/src/pvmp3_mpeg2_stereo_proc.cpp
index c79062c..a70e716 100644
--- a/media/libstagefright/codecs/mp3dec/src/pvmp3_mpeg2_stereo_proc.cpp
+++ b/media/libstagefright/codecs/mp3dec/src/pvmp3_mpeg2_stereo_proc.cpp
@@ -123,7 +123,7 @@
 ; compile variables also.
 ----------------------------------------------------------------------------*/
 
-#define Q31_fmt(a)    (int32(double(0x7FFFFFFF)*a))
+#define Q31_fmt(a)    (int32(double(0x7FFFFFFF)*(a)))
 
 /*----------------------------------------------------------------------------
 ; LOCAL FUNCTION DEFINITIONS
diff --git a/media/libstagefright/codecs/mp3dec/src/pvmp3_stereo_proc.cpp b/media/libstagefright/codecs/mp3dec/src/pvmp3_stereo_proc.cpp
index d69a46d..10edfc3 100644
--- a/media/libstagefright/codecs/mp3dec/src/pvmp3_stereo_proc.cpp
+++ b/media/libstagefright/codecs/mp3dec/src/pvmp3_stereo_proc.cpp
@@ -140,7 +140,7 @@
 ----------------------------------------------------------------------------*/
 #define N31 31
 
-#define Q31_fmt(a)    (int32(double(0x7FFFFFFF)*a))
+#define Q31_fmt(a)    (int32(double(0x7FFFFFFF)*(a)))
 
 /*----------------------------------------------------------------------------
 ; LOCAL FUNCTION DEFINITIONS
diff --git a/media/libstagefright/codecs/mp3dec/src/pvmp3_tables.cpp b/media/libstagefright/codecs/mp3dec/src/pvmp3_tables.cpp
index 90e524a..91113e3 100644
--- a/media/libstagefright/codecs/mp3dec/src/pvmp3_tables.cpp
+++ b/media/libstagefright/codecs/mp3dec/src/pvmp3_tables.cpp
@@ -136,7 +136,7 @@
 
 };
 
-#define INV_Q31( x)   (int32)(0x7FFFFFFF/(float)x - 1.0f)
+#define INV_Q31( x)   (int32)(0x7FFFFFFF/(float)(x) - 1.0f)
 
 const int32 mp3_shortwindBandWidths[9][13] =
 {
@@ -161,7 +161,7 @@
 };
 
 
-#define Q30_fmt(a)    (int32((0x40000000)*a))
+#define Q30_fmt(a)    (int32((0x40000000)*(a)))
 
 const int32 pqmfSynthWin[(HAN_SIZE/2) + 8] =
 {
diff --git a/media/libstagefright/codecs/mp3dec/src/pvmp3_tables.h b/media/libstagefright/codecs/mp3dec/src/pvmp3_tables.h
index b54c5bf..8f8509c 100644
--- a/media/libstagefright/codecs/mp3dec/src/pvmp3_tables.h
+++ b/media/libstagefright/codecs/mp3dec/src/pvmp3_tables.h
@@ -52,7 +52,7 @@
 /*----------------------------------------------------------------------------
 ; DEFINES AND SIMPLE TYPEDEF'S
 ----------------------------------------------------------------------------*/
-#define Qfmt_28(a) (int32(double(0x10000000)*a))
+#define Qfmt_28(a) (int32(double(0x10000000)*(a)))
 
 /*----------------------------------------------------------------------------
 ; SIMPLE TYPEDEF'S
diff --git a/media/libstagefright/codecs/mpeg2dec/SoftMPEG2.h b/media/libstagefright/codecs/mpeg2dec/SoftMPEG2.h
index 700ef5f..1921a23 100644
--- a/media/libstagefright/codecs/mpeg2dec/SoftMPEG2.h
+++ b/media/libstagefright/codecs/mpeg2dec/SoftMPEG2.h
@@ -49,8 +49,8 @@
 
 /** Compute difference between start and end */
 #define TIME_DIFF(start, end, diff) \
-    diff = ((end.tv_sec - start.tv_sec) * 1000000) + \
-            (end.tv_usec - start.tv_usec);
+    diff = (((end).tv_sec - (start).tv_sec) * 1000000) + \
+            ((end).tv_usec - (start).tv_usec);
 
 struct SoftMPEG2 : public SoftVideoDecoderOMXComponent {
     SoftMPEG2(
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_cavlc.c b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_cavlc.c
index 91d78bd..422d7ba 100644
--- a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_cavlc.c
+++ b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_cavlc.c
@@ -60,7 +60,7 @@
 #define INFO(vlc) (((vlc) >> 4) & 0xF)  /* 4 MSB bits contain information */
 /* macro to obtain trailing ones from the coeff token information word,
  * bits [5,10] */
-#define TRAILING_ONES(coeffToken) ((coeffToken>>5) & 0x3F)
+#define TRAILING_ONES(coeffToken) (((coeffToken)>>5) & 0x3F)
 /* macro to obtain total coeff from the coeff token information word,
  * bits [11,15] */
 #define TOTAL_COEFF(coeffToken) (((coeffToken) >> 11) & 0x1F)
@@ -323,45 +323,45 @@
 /* macro to initialize stream buffer cache, fills the buffer (32 bits) */
 #define BUFFER_INIT(value, bits) \
 { \
-    bits = 32; \
-    value = h264bsdShowBits32(pStrmData); \
+    (bits) = 32; \
+    (value) = h264bsdShowBits32(pStrmData); \
 }
 
 /* macro to read numBits bits from the buffer, bits will be written to
  * outVal. Refills the buffer if not enough bits left */
 #define BUFFER_SHOW(value, bits, outVal, numBits) \
 { \
-    if (bits < (numBits)) \
+    if ((bits) < (numBits)) \
     { \
-        if(h264bsdFlushBits(pStrmData,32-bits) == END_OF_STREAM) \
+        if(h264bsdFlushBits(pStrmData,32-(bits)) == END_OF_STREAM) \
             return(HANTRO_NOK); \
-        value = h264bsdShowBits32(pStrmData); \
-        bits = 32; \
+        (value) = h264bsdShowBits32(pStrmData); \
+        (bits) = 32; \
     } \
-    (outVal) = value >> (32 - (numBits)); \
+    (outVal) = (value) >> (32 - (numBits)); \
 }
 
 /* macro to flush numBits bits from the buffer */
 #define BUFFER_FLUSH(value, bits, numBits) \
 { \
-    value <<= (numBits); \
-    bits -= (numBits); \
+    (value) <<= (numBits); \
+    (bits) -= (numBits); \
 }
 
 /* macro to read and flush  numBits bits from the buffer, bits will be written
  * to outVal. Refills the buffer if not enough bits left */
 #define BUFFER_GET(value, bits, outVal, numBits) \
 { \
-    if (bits < (numBits)) \
+    if ((bits) < (numBits)) \
     { \
-        if(h264bsdFlushBits(pStrmData,32-bits) == END_OF_STREAM) \
+        if(h264bsdFlushBits(pStrmData,32-(bits)) == END_OF_STREAM) \
             return(HANTRO_NOK); \
-        value = h264bsdShowBits32(pStrmData); \
-        bits = 32; \
+        (value) = h264bsdShowBits32(pStrmData); \
+        (bits) = 32; \
     } \
-    (outVal) = value >> (32 - (numBits)); \
-    value <<= (numBits); \
-    bits -= (numBits); \
+    (outVal) = (value) >> (32 - (numBits)); \
+    (value) <<= (numBits); \
+    (bits) -= (numBits); \
 }
 
 /*------------------------------------------------------------------------------
diff --git a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_util.h b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_util.h
index 9f0eb7d..f43cf82 100644
--- a/media/libstagefright/codecs/on2/h264dec/source/h264bsd_util.h
+++ b/media/libstagefright/codecs/on2/h264dec/source/h264bsd_util.h
@@ -151,7 +151,7 @@
 }
 
 #define ALIGN(ptr, bytePos) \
-        (ptr + ( ((bytePos - (uintptr_t)ptr) & (bytePos - 1)) / sizeof(*ptr) ))
+        ((ptr) + ( (((bytePos) - (uintptr_t)(ptr)) & ((bytePos) - 1)) / sizeof(*(ptr)) ))
 
 extern const u32 h264bsdQpC[52];
 
diff --git a/media/libstagefright/filters/Android.mk b/media/libstagefright/filters/Android.mk
index 179f054..bd75a88 100644
--- a/media/libstagefright/filters/Android.mk
+++ b/media/libstagefright/filters/Android.mk
@@ -23,6 +23,8 @@
 LOCAL_CFLAGS += -Wno-multichar -Werror -Wall
 LOCAL_CLANG := true
 
+LOCAL_SHARED_LIBRARIES := libmedia
+
 LOCAL_MODULE:= libstagefright_mediafilter
 
 include $(BUILD_STATIC_LIBRARY)
diff --git a/media/libstagefright/foundation/ADebug.cpp b/media/libstagefright/foundation/ADebug.cpp
index 2c5f544..1a5b2a3 100644
--- a/media/libstagefright/foundation/ADebug.cpp
+++ b/media/libstagefright/foundation/ADebug.cpp
@@ -49,7 +49,7 @@
             ++current;
         }
         // check for :
-        char *colon = strchr(current, ':');
+        const char *colon = strchr(current, ':');
 
         // get level
         char *end;
diff --git a/media/libstagefright/foundation/ALooperRoster.cpp b/media/libstagefright/foundation/ALooperRoster.cpp
index 9ed53e7..5f11fb6 100644
--- a/media/libstagefright/foundation/ALooperRoster.cpp
+++ b/media/libstagefright/foundation/ALooperRoster.cpp
@@ -34,7 +34,7 @@
 }
 
 ALooper::handler_id ALooperRoster::registerHandler(
-        const sp<ALooper> looper, const sp<AHandler> &handler) {
+        const sp<ALooper> &looper, const sp<AHandler> &handler) {
     Mutex::Autolock autoLock(mLock);
 
     if (handler->id() != 0) {
diff --git a/media/libstagefright/foundation/AMessage.cpp b/media/libstagefright/foundation/AMessage.cpp
index a4583d6..0406f6a 100644
--- a/media/libstagefright/foundation/AMessage.cpp
+++ b/media/libstagefright/foundation/AMessage.cpp
@@ -252,7 +252,8 @@
     item->u.FIELDNAME = value;                                          \
 }                                                                       \
                                                                         \
-bool AMessage::find##NAME(const char *name, TYPENAME *value) const {    \
+/* NOLINT added to avoid incorrect warning/fix from clang.tidy */       \
+bool AMessage::find##NAME(const char *name, TYPENAME *value) const {  /* NOLINT */ \
     const Item *item = findItem(name, kType##NAME);                     \
     if (item) {                                                         \
         *value = item->u.FIELDNAME;                                     \
diff --git a/media/libstagefright/foundation/ANetworkSession.cpp b/media/libstagefright/foundation/ANetworkSession.cpp
index 46314eb..f8b7b41 100644
--- a/media/libstagefright/foundation/ANetworkSession.cpp
+++ b/media/libstagefright/foundation/ANetworkSession.cpp
@@ -53,7 +53,7 @@
 static const int32_t kMaxUDPRetries = 200;
 
 struct ANetworkSession::NetworkThread : public Thread {
-    NetworkThread(ANetworkSession *session);
+    explicit NetworkThread(ANetworkSession *session);
 
 protected:
     virtual ~NetworkThread();
diff --git a/media/libstagefright/foundation/Android.bp b/media/libstagefright/foundation/Android.bp
new file mode 100644
index 0000000..f7bd3f2
--- /dev/null
+++ b/media/libstagefright/foundation/Android.bp
@@ -0,0 +1,51 @@
+cc_library_shared {
+    name: "libstagefright_foundation",
+
+    srcs: [
+        "AAtomizer.cpp",
+        "ABitReader.cpp",
+        "ABuffer.cpp",
+        "ADebug.cpp",
+        "AHandler.cpp",
+        "AHierarchicalStateMachine.cpp",
+        "ALooper.cpp",
+        "ALooperRoster.cpp",
+        "AMessage.cpp",
+        "ANetworkSession.cpp",
+        "AString.cpp",
+        "AStringUtils.cpp",
+        "AWakeLock.cpp",
+        "ColorUtils.cpp",
+        "MediaBuffer.cpp",
+        "MediaBufferGroup.cpp",
+        "MetaData.cpp",
+        "ParsedMessage.cpp",
+        "base64.cpp",
+        "hexdump.cpp",
+    ],
+
+    include_dirs: ["frameworks/av/include/media/stagefright/foundation"],
+
+    shared_libs: [
+        "libbinder",
+        "libutils",
+        "libcutils",
+        "liblog",
+        "libpowermanager",
+    ],
+
+    export_shared_lib_headers: ["libbinder"],
+
+    cflags: [
+        "-Wno-multichar",
+        "-Werror",
+        "-Wall",
+    ],
+    clang: true,
+    sanitize: {
+        misc_undefined: [
+            "unsigned-integer-overflow",
+            "signed-integer-overflow",
+        ],
+    },
+}
diff --git a/media/libstagefright/foundation/Android.mk b/media/libstagefright/foundation/Android.mk
deleted file mode 100644
index 3c3ed59..0000000
--- a/media/libstagefright/foundation/Android.mk
+++ /dev/null
@@ -1,44 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES:=                 \
-    AAtomizer.cpp                 \
-    ABitReader.cpp                \
-    ABuffer.cpp                   \
-    ADebug.cpp                    \
-    AHandler.cpp                  \
-    AHierarchicalStateMachine.cpp \
-    ALooper.cpp                   \
-    ALooperRoster.cpp             \
-    AMessage.cpp                  \
-    ANetworkSession.cpp           \
-    AString.cpp                   \
-    AStringUtils.cpp              \
-    AWakeLock.cpp                 \
-    ColorUtils.cpp                \
-    MediaBuffer.cpp               \
-    MediaBufferGroup.cpp          \
-    MetaData.cpp                  \
-    ParsedMessage.cpp             \
-    base64.cpp                    \
-    hexdump.cpp
-
-LOCAL_C_INCLUDES:= \
-    frameworks/av/include/media/stagefright/foundation
-
-LOCAL_SHARED_LIBRARIES := \
-        libbinder         \
-        libutils          \
-        libcutils         \
-        liblog            \
-        libpowermanager
-
-LOCAL_CFLAGS += -Wno-multichar -Werror -Wall
-LOCAL_CLANG := true
-LOCAL_SANITIZE := unsigned-integer-overflow signed-integer-overflow
-
-LOCAL_MODULE:= libstagefright_foundation
-
-
-
-include $(BUILD_SHARED_LIBRARY)
diff --git a/media/libstagefright/httplive/Android.mk b/media/libstagefright/httplive/Android.mk
index f904212..2c985fc 100644
--- a/media/libstagefright/httplive/Android.mk
+++ b/media/libstagefright/httplive/Android.mk
@@ -18,6 +18,7 @@
 LOCAL_SANITIZE := unsigned-integer-overflow signed-integer-overflow
 
 LOCAL_SHARED_LIBRARIES := \
+        liblog \
         libbinder \
         libcrypto \
         libcutils \
diff --git a/media/libstagefright/httplive/LiveSession.cpp b/media/libstagefright/httplive/LiveSession.cpp
index cebf95c..e24d08d 100644
--- a/media/libstagefright/httplive/LiveSession.cpp
+++ b/media/libstagefright/httplive/LiveSession.cpp
@@ -1175,7 +1175,7 @@
 #endif
 
 bool LiveSession::UriIsSameAsIndex(const AString &uri, int32_t i, bool newUri) {
-    ALOGI("[timed_id3] i %d UriIsSameAsIndex newUri %s, %s", i,
+    ALOGV("[timed_id3] i %d UriIsSameAsIndex newUri %s, %s", i,
             newUri ? "true" : "false",
             newUri ? mStreams[i].mNewUri.c_str() : mStreams[i].mUri.c_str());
     return i >= 0
diff --git a/media/libstagefright/httplive/LiveSession.h b/media/libstagefright/httplive/LiveSession.h
index 90d56d0..de7cefd 100644
--- a/media/libstagefright/httplive/LiveSession.h
+++ b/media/libstagefright/httplive/LiveSession.h
@@ -165,7 +165,7 @@
         int64_t mLastSampleDurationUs;
         StreamItem()
             : StreamItem("") {}
-        StreamItem(const char *type)
+        explicit StreamItem(const char *type)
             : mType(type),
               mSeekMode(kSeekModeExactPosition) {
                   reset();
diff --git a/media/libstagefright/httplive/M3UParser.cpp b/media/libstagefright/httplive/M3UParser.cpp
index c04549a..71feb9a 100644
--- a/media/libstagefright/httplive/M3UParser.cpp
+++ b/media/libstagefright/httplive/M3UParser.cpp
@@ -46,7 +46,7 @@
         FLAG_HAS_URI            = 16,
     };
 
-    MediaGroup(Type type);
+    explicit MediaGroup(Type type);
 
     Type type() const;
 
@@ -498,8 +498,8 @@
     if (url[0] == '/') {
         // URL is an absolute path.
 
-        char *protocolEnd = strstr(baseURL, "//") + 2;
-        char *pathStart = strchr(protocolEnd, '/');
+        const char *protocolEnd = strstr(baseURL, "//") + 2;
+        const char *pathStart = strchr(protocolEnd, '/');
 
         if (pathStart != NULL) {
             out->setTo(baseURL, pathStart - baseURL);
diff --git a/media/libstagefright/id3/Android.mk b/media/libstagefright/id3/Android.mk
index 2cfba44..bd2e459 100644
--- a/media/libstagefright/id3/Android.mk
+++ b/media/libstagefright/id3/Android.mk
@@ -8,6 +8,8 @@
 LOCAL_CLANG := true
 LOCAL_SANITIZE := unsigned-integer-overflow signed-integer-overflow
 
+LOCAL_SHARED_LIBRARIES := libmedia
+
 LOCAL_MODULE := libstagefright_id3
 
 include $(BUILD_STATIC_LIBRARY)
diff --git a/media/libstagefright/id3/ID3.cpp b/media/libstagefright/id3/ID3.cpp
index 3942158..aaf6b3d 100644
--- a/media/libstagefright/id3/ID3.cpp
+++ b/media/libstagefright/id3/ID3.cpp
@@ -534,6 +534,9 @@
     }
     size_t n = mFrameSize - getHeaderLength() - 1;
     if (otherdata) {
+        if (n < 5) {
+            return;
+        }
         // skip past the encoding, language, and the 0 separator
         frameData += 4;
         int32_t i = n - 4;
diff --git a/media/libstagefright/include/AMRExtractor.h b/media/libstagefright/include/AMRExtractor.h
index ba2b674..8abcb12 100644
--- a/media/libstagefright/include/AMRExtractor.h
+++ b/media/libstagefright/include/AMRExtractor.h
@@ -29,7 +29,7 @@
 
 class AMRExtractor : public MediaExtractor {
 public:
-    AMRExtractor(const sp<DataSource> &source);
+    explicit AMRExtractor(const sp<DataSource> &source);
 
     virtual size_t countTracks();
     virtual sp<IMediaSource> getTrack(size_t index);
diff --git a/media/libstagefright/include/CallbackDataSource.h b/media/libstagefright/include/CallbackDataSource.h
index d2187d5..80cd1f7 100644
--- a/media/libstagefright/include/CallbackDataSource.h
+++ b/media/libstagefright/include/CallbackDataSource.h
@@ -29,7 +29,7 @@
 // DataSource because it calls back to the IDataSource for data.
 class CallbackDataSource : public DataSource {
 public:
-    CallbackDataSource(const sp<IDataSource>& iDataSource);
+    explicit CallbackDataSource(const sp<IDataSource>& iDataSource);
     virtual ~CallbackDataSource();
 
     // DataSource implementation.
@@ -59,7 +59,7 @@
 // impact on time taken for filetype sniffing and metadata extraction.
 class TinyCacheSource : public DataSource {
 public:
-    TinyCacheSource(const sp<DataSource>& source);
+    explicit TinyCacheSource(const sp<DataSource>& source);
 
     virtual status_t initCheck() const;
     virtual ssize_t readAt(off64_t offset, void* data, size_t size);
diff --git a/media/libstagefright/include/FLACExtractor.h b/media/libstagefright/include/FLACExtractor.h
index 5d030b1..51bc139 100644
--- a/media/libstagefright/include/FLACExtractor.h
+++ b/media/libstagefright/include/FLACExtractor.h
@@ -29,7 +29,7 @@
 
 public:
     // Extractor assumes ownership of source
-    FLACExtractor(const sp<DataSource> &source);
+    explicit FLACExtractor(const sp<DataSource> &source);
 
     virtual size_t countTracks();
     virtual sp<IMediaSource> getTrack(size_t index);
diff --git a/media/libstagefright/include/ID3.h b/media/libstagefright/include/ID3.h
index c2c4a6d..11682f8 100644
--- a/media/libstagefright/include/ID3.h
+++ b/media/libstagefright/include/ID3.h
@@ -35,7 +35,7 @@
         ID3_V2_4,
     };
 
-    ID3(const sp<DataSource> &source, bool ignoreV1 = false, off64_t offset = 0);
+    explicit ID3(const sp<DataSource> &source, bool ignoreV1 = false, off64_t offset = 0);
     ID3(const uint8_t *data, size_t size, bool ignoreV1 = false);
     ~ID3();
 
diff --git a/media/libstagefright/include/MPEG2PSExtractor.h b/media/libstagefright/include/MPEG2PSExtractor.h
index c8abfb6..f5471b3 100644
--- a/media/libstagefright/include/MPEG2PSExtractor.h
+++ b/media/libstagefright/include/MPEG2PSExtractor.h
@@ -31,7 +31,7 @@
 class String8;
 
 struct MPEG2PSExtractor : public MediaExtractor {
-    MPEG2PSExtractor(const sp<DataSource> &source);
+    explicit MPEG2PSExtractor(const sp<DataSource> &source);
 
     virtual size_t countTracks();
     virtual sp<IMediaSource> getTrack(size_t index);
diff --git a/media/libstagefright/include/MPEG2TSExtractor.h b/media/libstagefright/include/MPEG2TSExtractor.h
index 34b9606..93e9a4b 100644
--- a/media/libstagefright/include/MPEG2TSExtractor.h
+++ b/media/libstagefright/include/MPEG2TSExtractor.h
@@ -37,7 +37,7 @@
 class String8;
 
 struct MPEG2TSExtractor : public MediaExtractor {
-    MPEG2TSExtractor(const sp<DataSource> &source);
+    explicit MPEG2TSExtractor(const sp<DataSource> &source);
 
     virtual size_t countTracks();
     virtual sp<IMediaSource> getTrack(size_t index);
diff --git a/media/libstagefright/include/MPEG4Extractor.h b/media/libstagefright/include/MPEG4Extractor.h
index 836cb08..89ad137 100644
--- a/media/libstagefright/include/MPEG4Extractor.h
+++ b/media/libstagefright/include/MPEG4Extractor.h
@@ -50,7 +50,7 @@
 class MPEG4Extractor : public MediaExtractor {
 public:
     // Extractor assumes ownership of "source".
-    MPEG4Extractor(const sp<DataSource> &source);
+    explicit MPEG4Extractor(const sp<DataSource> &source);
 
     virtual size_t countTracks();
     virtual sp<IMediaSource> getTrack(size_t index);
diff --git a/media/libstagefright/include/MidiExtractor.h b/media/libstagefright/include/MidiExtractor.h
index 5a7d90e..94d2d08 100644
--- a/media/libstagefright/include/MidiExtractor.h
+++ b/media/libstagefright/include/MidiExtractor.h
@@ -53,7 +53,7 @@
 
 public:
     // Extractor assumes ownership of source
-    MidiExtractor(const sp<DataSource> &source);
+    explicit MidiExtractor(const sp<DataSource> &source);
 
     virtual size_t countTracks();
     virtual sp<IMediaSource> getTrack(size_t index);
diff --git a/media/libstagefright/include/OMXNodeInstance.h b/media/libstagefright/include/OMXNodeInstance.h
index 94cf15a..6411267 100644
--- a/media/libstagefright/include/OMXNodeInstance.h
+++ b/media/libstagefright/include/OMXNodeInstance.h
@@ -257,10 +257,10 @@
             OMX::buffer_id buffer, OMX_BUFFERHEADERTYPE *header, bool updateCodecBuffer);
 
     status_t createGraphicBufferSource(
-            OMX_U32 portIndex, sp<IGraphicBufferConsumer> consumer /* nullable */,
+            OMX_U32 portIndex, const sp<IGraphicBufferConsumer> &consumer /* nullable */,
             MetadataBufferType *type);
     sp<GraphicBufferSource> getGraphicBufferSource();
-    void setGraphicBufferSource(const sp<GraphicBufferSource>& bufferSource);
+    void setGraphicBufferSource(const sp<GraphicBufferSource> &bufferSource);
 
     // Handles |msg|, and may modify it. Returns true iff completely handled it and
     // |msg| does not need to be sent to the event listener.
diff --git a/media/libstagefright/include/OggExtractor.h b/media/libstagefright/include/OggExtractor.h
index 592c264..55aafed 100644
--- a/media/libstagefright/include/OggExtractor.h
+++ b/media/libstagefright/include/OggExtractor.h
@@ -31,7 +31,7 @@
 struct OggSource;
 
 struct OggExtractor : public MediaExtractor {
-    OggExtractor(const sp<DataSource> &source);
+    explicit OggExtractor(const sp<DataSource> &source);
 
     virtual size_t countTracks();
     virtual sp<IMediaSource> getTrack(size_t index);
diff --git a/media/libstagefright/include/SampleIterator.h b/media/libstagefright/include/SampleIterator.h
index 2ef41ae..6a3fd3b 100644
--- a/media/libstagefright/include/SampleIterator.h
+++ b/media/libstagefright/include/SampleIterator.h
@@ -25,7 +25,7 @@
 class SampleTable;
 
 struct SampleIterator {
-    SampleIterator(SampleTable *table);
+    explicit SampleIterator(SampleTable *table);
 
     status_t seekTo(uint32_t sampleIndex);
 
diff --git a/media/libstagefright/include/SampleTable.h b/media/libstagefright/include/SampleTable.h
index 2100ca6..eb1a674 100644
--- a/media/libstagefright/include/SampleTable.h
+++ b/media/libstagefright/include/SampleTable.h
@@ -32,7 +32,7 @@
 
 class SampleTable : public RefBase {
 public:
-    SampleTable(const sp<DataSource> &source);
+    explicit SampleTable(const sp<DataSource> &source);
 
     bool isValid() const;
 
diff --git a/media/libstagefright/include/WAVExtractor.h b/media/libstagefright/include/WAVExtractor.h
index 91ee870..12ad441 100644
--- a/media/libstagefright/include/WAVExtractor.h
+++ b/media/libstagefright/include/WAVExtractor.h
@@ -30,7 +30,7 @@
 class WAVExtractor : public MediaExtractor {
 public:
     // Extractor assumes ownership of "source".
-    WAVExtractor(const sp<DataSource> &source);
+    explicit WAVExtractor(const sp<DataSource> &source);
 
     virtual size_t countTracks();
     virtual sp<IMediaSource> getTrack(size_t index);
diff --git a/media/libstagefright/include/WVMExtractor.h b/media/libstagefright/include/WVMExtractor.h
index 5b91072..65cb99a 100644
--- a/media/libstagefright/include/WVMExtractor.h
+++ b/media/libstagefright/include/WVMExtractor.h
@@ -43,7 +43,7 @@
 
 class WVMExtractor : public MediaExtractor {
 public:
-    WVMExtractor(const sp<DataSource> &source);
+    explicit WVMExtractor(const sp<DataSource> &source);
 
     virtual size_t countTracks();
     virtual sp<IMediaSource> getTrack(size_t index);
diff --git a/media/libstagefright/include/avc_utils.h b/media/libstagefright/include/avc_utils.h
index 235ee63..b2ef360 100644
--- a/media/libstagefright/include/avc_utils.h
+++ b/media/libstagefright/include/avc_utils.h
@@ -37,8 +37,8 @@
 };
 
 struct NALPosition {
-    size_t nalOffset;
-    size_t nalSize;
+    uint32_t nalOffset;
+    uint32_t nalSize;
 };
 
 // Optionally returns sample aspect ratio as well.
diff --git a/media/libstagefright/matroska/Android.mk b/media/libstagefright/matroska/Android.mk
index b0cbf08..89d7ff2 100644
--- a/media/libstagefright/matroska/Android.mk
+++ b/media/libstagefright/matroska/Android.mk
@@ -13,6 +13,8 @@
 LOCAL_CLANG := true
 LOCAL_SANITIZE := unsigned-integer-overflow signed-integer-overflow
 
+LOCAL_SHARED_LIBRARIES := libmedia
+
 LOCAL_MODULE:= libstagefright_matroska
 
 include $(BUILD_STATIC_LIBRARY)
diff --git a/media/libstagefright/matroska/MatroskaExtractor.cpp b/media/libstagefright/matroska/MatroskaExtractor.cpp
index 0f9430e..8e82486 100644
--- a/media/libstagefright/matroska/MatroskaExtractor.cpp
+++ b/media/libstagefright/matroska/MatroskaExtractor.cpp
@@ -40,7 +40,7 @@
 namespace android {
 
 struct DataSourceReader : public mkvparser::IMkvReader {
-    DataSourceReader(const sp<DataSource> &source)
+    explicit DataSourceReader(const sp<DataSource> &source)
         : mSource(source) {
     }
 
diff --git a/media/libstagefright/matroska/MatroskaExtractor.h b/media/libstagefright/matroska/MatroskaExtractor.h
index 665e68e..588bd39 100644
--- a/media/libstagefright/matroska/MatroskaExtractor.h
+++ b/media/libstagefright/matroska/MatroskaExtractor.h
@@ -34,7 +34,7 @@
 struct MatroskaSource;
 
 struct MatroskaExtractor : public MediaExtractor {
-    MatroskaExtractor(const sp<DataSource> &source);
+    explicit MatroskaExtractor(const sp<DataSource> &source);
 
     virtual size_t countTracks();
 
diff --git a/media/libstagefright/mpeg2ts/ATSParser.h b/media/libstagefright/mpeg2ts/ATSParser.h
index 9d9102d..2b166f0 100644
--- a/media/libstagefright/mpeg2ts/ATSParser.h
+++ b/media/libstagefright/mpeg2ts/ATSParser.h
@@ -64,7 +64,7 @@
 
     // Event is used to signal sync point event at feedTSPacket().
     struct SyncEvent {
-        SyncEvent(off64_t offset);
+        explicit SyncEvent(off64_t offset);
 
         void init(off64_t offset, const sp<MediaSource> &source,
                 int64_t timeUs);
@@ -89,7 +89,7 @@
         int64_t mTimeUs;
     };
 
-    ATSParser(uint32_t flags = 0);
+    explicit ATSParser(uint32_t flags = 0);
 
     // Feed a TS packet into the parser. uninitialized event with the start
     // offset of this TS packet goes in, and if the parser detects PES with
diff --git a/media/libstagefright/mpeg2ts/Android.mk b/media/libstagefright/mpeg2ts/Android.mk
index 70afde9..66722a8 100644
--- a/media/libstagefright/mpeg2ts/Android.mk
+++ b/media/libstagefright/mpeg2ts/Android.mk
@@ -17,6 +17,8 @@
 LOCAL_CLANG := true
 LOCAL_SANITIZE := unsigned-integer-overflow signed-integer-overflow
 
+LOCAL_SHARED_LIBRARIES := libmedia
+
 LOCAL_MODULE:= libstagefright_mpeg2ts
 
 ifeq ($(TARGET_ARCH),arm)
diff --git a/media/libstagefright/mpeg2ts/AnotherPacketSource.h b/media/libstagefright/mpeg2ts/AnotherPacketSource.h
index 28a0e89..dd6849e 100644
--- a/media/libstagefright/mpeg2ts/AnotherPacketSource.h
+++ b/media/libstagefright/mpeg2ts/AnotherPacketSource.h
@@ -30,7 +30,7 @@
 struct ABuffer;
 
 struct AnotherPacketSource : public MediaSource {
-    AnotherPacketSource(const sp<MetaData> &meta);
+    explicit AnotherPacketSource(const sp<MetaData> &meta);
 
     void setFormat(const sp<MetaData> &meta);
 
diff --git a/media/libstagefright/mpeg2ts/ESQueue.h b/media/libstagefright/mpeg2ts/ESQueue.h
index e9f96b7..56f0706 100644
--- a/media/libstagefright/mpeg2ts/ESQueue.h
+++ b/media/libstagefright/mpeg2ts/ESQueue.h
@@ -44,7 +44,7 @@
         // Data appended to the queue is always at access unit boundaries.
         kFlag_AlignedData = 1,
     };
-    ElementaryStreamQueue(Mode mode, uint32_t flags = 0);
+    explicit ElementaryStreamQueue(Mode mode, uint32_t flags = 0);
 
     status_t appendData(const void *data, size_t size, int64_t timeUs);
     void signalEOS();
diff --git a/media/libstagefright/omx/GraphicBufferSource.cpp b/media/libstagefright/omx/GraphicBufferSource.cpp
index 93d6584..1d819b5 100644
--- a/media/libstagefright/omx/GraphicBufferSource.cpp
+++ b/media/libstagefright/omx/GraphicBufferSource.cpp
@@ -938,11 +938,12 @@
  * frameNum: frame number of the frame being released
  * buffer: GraphicBuffer pointer to release (note this must not be & as we
  *         will clear the original mBufferSlot in persistent case)
+ *         Use NOLINT to supress warning on the copy of 'buffer'.
  * fence: fence of the frame being released
  */
 void GraphicBufferSource::releaseBuffer(
         int &id, uint64_t frameNum,
-        const sp<GraphicBuffer> buffer, const sp<Fence> &fence) {
+        const sp<GraphicBuffer> buffer, const sp<Fence> &fence) {  // NOLINT
     ALOGV("releaseBuffer: slot=%d", id);
     if (mIsPersistent) {
         mConsumer->detachBuffer(id);
diff --git a/media/libstagefright/omx/OMX.cpp b/media/libstagefright/omx/OMX.cpp
index 2e989b5..f7058d7 100644
--- a/media/libstagefright/omx/OMX.cpp
+++ b/media/libstagefright/omx/OMX.cpp
@@ -48,7 +48,7 @@
 // Note that deriving CallbackDispatcher from Thread does not work.
 
 struct OMX::CallbackDispatcherThread : public Thread {
-    CallbackDispatcherThread(CallbackDispatcher *dispatcher)
+    explicit CallbackDispatcherThread(CallbackDispatcher *dispatcher)
         : mDispatcher(dispatcher) {
     }
 
@@ -64,7 +64,7 @@
 ////////////////////////////////////////////////////////////////////////////////
 
 struct OMX::CallbackDispatcher : public RefBase {
-    CallbackDispatcher(OMXNodeInstance *owner);
+    explicit CallbackDispatcher(OMXNodeInstance *owner);
 
     // Posts |msg| to the listener's queue. If |realTime| is true, the listener thread is notified
     // that a new message is available on the queue. Otherwise, the message stays on the queue, but
diff --git a/media/libstagefright/omx/OMXNodeInstance.cpp b/media/libstagefright/omx/OMXNodeInstance.cpp
index 5f903a9..8c10310 100644
--- a/media/libstagefright/omx/OMXNodeInstance.cpp
+++ b/media/libstagefright/omx/OMXNodeInstance.cpp
@@ -93,7 +93,7 @@
 namespace android {
 
 struct BufferMeta {
-    BufferMeta(
+    explicit BufferMeta(
             const sp<IMemory> &mem, OMX_U32 portIndex, bool copyToOmx,
             bool copyFromOmx, OMX_U8 *backup)
         : mMem(mem),
@@ -103,7 +103,7 @@
           mBackup(backup) {
     }
 
-    BufferMeta(size_t size, OMX_U32 portIndex)
+    explicit BufferMeta(size_t size, OMX_U32 portIndex)
         : mSize(size),
           mCopyFromOmx(false),
           mCopyToOmx(false),
@@ -111,7 +111,7 @@
           mBackup(NULL) {
     }
 
-    BufferMeta(const sp<GraphicBuffer> &graphicBuffer, OMX_U32 portIndex)
+    explicit BufferMeta(const sp<GraphicBuffer> &graphicBuffer, OMX_U32 portIndex)
         : mGraphicBuffer(graphicBuffer),
           mCopyFromOmx(false),
           mCopyToOmx(false),
@@ -1067,7 +1067,7 @@
 }
 
 status_t OMXNodeInstance::createGraphicBufferSource(
-        OMX_U32 portIndex, sp<IGraphicBufferConsumer> bufferConsumer, MetadataBufferType *type) {
+        OMX_U32 portIndex, const sp<IGraphicBufferConsumer> &bufferConsumer, MetadataBufferType *type) {
     status_t err;
 
     // only allow graphic source on input port, when there are no allocated buffers yet
diff --git a/media/libstagefright/rtsp/AAVCAssembler.h b/media/libstagefright/rtsp/AAVCAssembler.h
index bf389ec..e19480c 100644
--- a/media/libstagefright/rtsp/AAVCAssembler.h
+++ b/media/libstagefright/rtsp/AAVCAssembler.h
@@ -29,7 +29,7 @@
 struct AMessage;
 
 struct AAVCAssembler : public ARTPAssembler {
-    AAVCAssembler(const sp<AMessage> &notify);
+    explicit AAVCAssembler(const sp<AMessage> &notify);
 
 protected:
     virtual ~AAVCAssembler();
diff --git a/media/libstagefright/rtsp/AH263Assembler.h b/media/libstagefright/rtsp/AH263Assembler.h
index 2b6c625..1448661 100644
--- a/media/libstagefright/rtsp/AH263Assembler.h
+++ b/media/libstagefright/rtsp/AH263Assembler.h
@@ -29,7 +29,7 @@
 struct AMessage;
 
 struct AH263Assembler : public ARTPAssembler {
-    AH263Assembler(const sp<AMessage> &notify);
+    explicit AH263Assembler(const sp<AMessage> &notify);
 
 protected:
     virtual ~AH263Assembler();
diff --git a/media/libstagefright/rtsp/ARTPConnection.h b/media/libstagefright/rtsp/ARTPConnection.h
index edbcc35..d5f7c2e 100644
--- a/media/libstagefright/rtsp/ARTPConnection.h
+++ b/media/libstagefright/rtsp/ARTPConnection.h
@@ -32,7 +32,7 @@
         kRegularlyRequestFIR = 2,
     };
 
-    ARTPConnection(uint32_t flags = 0);
+    explicit ARTPConnection(uint32_t flags = 0);
 
     void addStream(
             int rtpSocket, int rtcpSocket,
diff --git a/media/libstagefright/rtsp/ARTPWriter.h b/media/libstagefright/rtsp/ARTPWriter.h
index 62abd0a..3c7042e 100644
--- a/media/libstagefright/rtsp/ARTPWriter.h
+++ b/media/libstagefright/rtsp/ARTPWriter.h
@@ -35,7 +35,7 @@
 class MediaBuffer;
 
 struct ARTPWriter : public MediaWriter {
-    ARTPWriter(int fd);
+    explicit ARTPWriter(int fd);
 
     virtual status_t addSource(const sp<IMediaSource> &source);
     virtual bool reachedEOS();
diff --git a/media/libstagefright/rtsp/ARTSPConnection.h b/media/libstagefright/rtsp/ARTSPConnection.h
index 1fe9c99..8df2676 100644
--- a/media/libstagefright/rtsp/ARTSPConnection.h
+++ b/media/libstagefright/rtsp/ARTSPConnection.h
@@ -33,7 +33,7 @@
 };
 
 struct ARTSPConnection : public AHandler {
-    ARTSPConnection(bool uidValid = false, uid_t uid = 0);
+    explicit ARTSPConnection(bool uidValid = false, uid_t uid = 0);
 
     void connect(const char *url, const sp<AMessage> &reply);
     void disconnect(const sp<AMessage> &reply);
diff --git a/media/libstagefright/rtsp/Android.mk b/media/libstagefright/rtsp/Android.mk
index bdda19c..35301ce 100644
--- a/media/libstagefright/rtsp/Android.mk
+++ b/media/libstagefright/rtsp/Android.mk
@@ -19,7 +19,7 @@
         ASessionDescription.cpp     \
         SDPLoader.cpp               \
 
-LOCAL_SHARED_LIBRARIES += libcrypto
+LOCAL_SHARED_LIBRARIES += libcrypto libmedia
 
 LOCAL_C_INCLUDES:= \
 	$(TOP)/frameworks/av/media/libstagefright \
diff --git a/media/libstagefright/tests/DummyRecorder.h b/media/libstagefright/tests/DummyRecorder.h
index cd4d0ee..0759777 100644
--- a/media/libstagefright/tests/DummyRecorder.h
+++ b/media/libstagefright/tests/DummyRecorder.h
@@ -43,7 +43,7 @@
     // static function to wrap the actual thread entry point
     static void *threadWrapper(void *pthis);
 
-    DummyRecorder(const sp<MediaSource> &source) : mSource(source)
+    explicit DummyRecorder(const sp<MediaSource> &source) : mSource(source)
                                                     , mStarted(false) {}
     ~DummyRecorder( ) {}
 
diff --git a/media/libstagefright/tests/MediaCodecListOverrides_test.cpp b/media/libstagefright/tests/MediaCodecListOverrides_test.cpp
index ab547be..2599608 100644
--- a/media/libstagefright/tests/MediaCodecListOverrides_test.cpp
+++ b/media/libstagefright/tests/MediaCodecListOverrides_test.cpp
@@ -74,11 +74,11 @@
     void verifyProfileResults(const KeyedVector<AString, CodecSettings> &results) {
         EXPECT_LT(0u, results.size());
         for (size_t i = 0; i < results.size(); ++i) {
-            AString key = results.keyAt(i);
-            CodecSettings settings = results.valueAt(i);
+            const AString &key = results.keyAt(i);
+            const CodecSettings &settings = results.valueAt(i);
             EXPECT_EQ(1u, settings.size());
             EXPECT_TRUE(settings.keyAt(0) == "max-supported-instances");
-            AString valueS = settings.valueAt(0);
+            const AString &valueS = settings.valueAt(0);
             int32_t value = strtol(valueS.c_str(), NULL, 10);
             EXPECT_LT(0, value);
             ALOGV("profileCodecs results %s %s", key.c_str(), valueS.c_str());
diff --git a/media/libstagefright/tests/SurfaceMediaSource_test.cpp b/media/libstagefright/tests/SurfaceMediaSource_test.cpp
index ad1e684..d419133 100644
--- a/media/libstagefright/tests/SurfaceMediaSource_test.cpp
+++ b/media/libstagefright/tests/SurfaceMediaSource_test.cpp
@@ -593,7 +593,7 @@
 struct SimpleDummyRecorder {
         sp<MediaSource> mSource;
 
-        SimpleDummyRecorder
+        explicit SimpleDummyRecorder
                 (const sp<MediaSource> &source): mSource(source) {}
 
         status_t start() { return mSource->start();}
diff --git a/media/libstagefright/timedtext/Android.mk b/media/libstagefright/timedtext/Android.mk
index f2c6365..8d128b8 100644
--- a/media/libstagefright/timedtext/Android.mk
+++ b/media/libstagefright/timedtext/Android.mk
@@ -12,6 +12,8 @@
         $(TOP)/frameworks/av/include/media/stagefright/timedtext \
         $(TOP)/frameworks/av/media/libstagefright
 
+LOCAL_SHARED_LIBRARIES := libmedia
+
 LOCAL_MODULE:= libstagefright_timedtext
 
 include $(BUILD_STATIC_LIBRARY)
diff --git a/media/libstagefright/webm/WebmElement.h b/media/libstagefright/webm/WebmElement.h
index 4e90793..ffbba1b 100644
--- a/media/libstagefright/webm/WebmElement.h
+++ b/media/libstagefright/webm/WebmElement.h
@@ -114,14 +114,14 @@
 
 struct EbmlVoid : public WebmElement {
     const uint64_t mSizeWidth;
-    EbmlVoid(uint64_t totalSize);
+    explicit EbmlVoid(uint64_t totalSize);
     int serializePayloadSize(uint8_t *buf);
     void serializePayload(uint8_t *buf);
 };
 
 struct WebmMaster : public WebmElement {
     const List<sp<WebmElement> > mChildren;
-    WebmMaster(uint64_t id);
+    explicit WebmMaster(uint64_t id);
     WebmMaster(uint64_t id, const List<sp<WebmElement> > &children);
     int serializePayloadSize(uint8_t *buf);
     void serializePayload(uint8_t *buf);
diff --git a/media/libstagefright/webm/WebmWriter.cpp b/media/libstagefright/webm/WebmWriter.cpp
index e58964d..25d6821 100644
--- a/media/libstagefright/webm/WebmWriter.cpp
+++ b/media/libstagefright/webm/WebmWriter.cpp
@@ -493,7 +493,7 @@
     }
 
     sp<WebmElement> elems[] = { ebml, segment, seekHead, info, tracks, cues };
-    size_t nElems = sizeof(elems) / sizeof(elems[0]);
+    static const size_t nElems = sizeof(elems) / sizeof(elems[0]);
     uint64_t offsets[nElems];
     uint64_t sizes[nElems];
     for (uint32_t i = 0; i < nElems; i++) {
diff --git a/media/libstagefright/webm/WebmWriter.h b/media/libstagefright/webm/WebmWriter.h
index dd1fba3..9f3b19f 100644
--- a/media/libstagefright/webm/WebmWriter.h
+++ b/media/libstagefright/webm/WebmWriter.h
@@ -36,7 +36,7 @@
 
 class WebmWriter : public MediaWriter {
 public:
-    WebmWriter(int fd);
+    explicit WebmWriter(int fd);
     ~WebmWriter() { reset(); }
 
 
diff --git a/media/libstagefright/wifi-display/source/TSPacketizer.h b/media/libstagefright/wifi-display/source/TSPacketizer.h
index 4a664ee..0dcb179 100644
--- a/media/libstagefright/wifi-display/source/TSPacketizer.h
+++ b/media/libstagefright/wifi-display/source/TSPacketizer.h
@@ -36,7 +36,7 @@
         EMIT_HDCP20_DESCRIPTOR = 1,
         EMIT_HDCP21_DESCRIPTOR = 2,
     };
-    TSPacketizer(uint32_t flags);
+    explicit TSPacketizer(uint32_t flags);
 
     // Returns trackIndex or error.
     ssize_t addTrack(const sp<AMessage> &format);
diff --git a/media/libstagefright/wifi-display/source/WifiDisplaySource.cpp b/media/libstagefright/wifi-display/source/WifiDisplaySource.cpp
index e26165e..f0a4ded 100644
--- a/media/libstagefright/wifi-display/source/WifiDisplaySource.cpp
+++ b/media/libstagefright/wifi-display/source/WifiDisplaySource.cpp
@@ -782,7 +782,7 @@
             return;
         }
 
-        char *commaPos = strchr(s, ',');
+        const char *commaPos = strchr(s, ',');
         if (commaPos != NULL) {
             s = commaPos + 1;
 
@@ -1669,7 +1669,7 @@
 }
 
 struct WifiDisplaySource::HDCPObserver : public BnHDCPObserver {
-    HDCPObserver(const sp<AMessage> &notify);
+    explicit HDCPObserver(const sp<AMessage> &notify);
 
     virtual void notify(
             int msg, int ext1, int ext2, const Parcel *obj);
diff --git a/media/mediaserver/Android.mk b/media/mediaserver/Android.mk
index 1738df8..f3f3b1a 100644
--- a/media/mediaserver/Android.mk
+++ b/media/mediaserver/Android.mk
@@ -19,6 +19,7 @@
 	libcamera_client \
 	libcameraservice \
 	libresourcemanagerservice \
+	liblog \
 	libcutils \
 	libmedia \
 	libmediaplayerservice \
diff --git a/media/mtp/MtpObjectInfo.h b/media/mtp/MtpObjectInfo.h
index 86780f1..188f21c 100644
--- a/media/mtp/MtpObjectInfo.h
+++ b/media/mtp/MtpObjectInfo.h
@@ -47,7 +47,7 @@
     char*               mKeywords;
 
 public:
-                        MtpObjectInfo(MtpObjectHandle handle);
+    explicit            MtpObjectInfo(MtpObjectHandle handle);
     virtual             ~MtpObjectInfo();
 
     bool                read(MtpDataPacket& packet);
diff --git a/media/mtp/MtpPacket.h b/media/mtp/MtpPacket.h
index 0e96309..4da53bf 100644
--- a/media/mtp/MtpPacket.h
+++ b/media/mtp/MtpPacket.h
@@ -36,7 +36,7 @@
     size_t              mPacketSize;
 
 public:
-                        MtpPacket(int bufferSize);
+    explicit            MtpPacket(int bufferSize);
     virtual             ~MtpPacket();
 
     // sets packet size to the default container size and sets buffer to zero
diff --git a/media/mtp/MtpStorageInfo.h b/media/mtp/MtpStorageInfo.h
index 35a8189..3b70675 100644
--- a/media/mtp/MtpStorageInfo.h
+++ b/media/mtp/MtpStorageInfo.h
@@ -36,7 +36,7 @@
     char*               mVolumeIdentifier;
 
 public:
-                        MtpStorageInfo(MtpStorageID id);
+    explicit            MtpStorageInfo(MtpStorageID id);
     virtual             ~MtpStorageInfo();
 
     bool                read(MtpDataPacket& packet);
diff --git a/media/mtp/MtpStringBuffer.h b/media/mtp/MtpStringBuffer.h
index 85d91e8..bcf2a48 100644
--- a/media/mtp/MtpStringBuffer.h
+++ b/media/mtp/MtpStringBuffer.h
@@ -38,8 +38,8 @@
 
 public:
                     MtpStringBuffer();
-                    MtpStringBuffer(const char* src);
-                    MtpStringBuffer(const uint16_t* src);
+    explicit        MtpStringBuffer(const char* src);
+    explicit        MtpStringBuffer(const uint16_t* src);
                     MtpStringBuffer(const MtpStringBuffer& src);
     virtual         ~MtpStringBuffer();
 
diff --git a/media/ndk/Android.bp b/media/ndk/Android.bp
new file mode 100644
index 0000000..1ac1eeb
--- /dev/null
+++ b/media/ndk/Android.bp
@@ -0,0 +1,23 @@
+// Copyright (C) 2016 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.
+
+// Headers module is in frameworks/av/Android.bp because modules are not allowed
+// to refer to headers in parent directories and the headers live in
+// frameworks/av/include.
+
+ndk_library {
+    name: "libmediandk.ndk",
+    symbol_file: "libmediandk.map.txt",
+    first_version: "21",
+}
diff --git a/media/ndk/NdkImageReaderPriv.h b/media/ndk/NdkImageReaderPriv.h
index 48f0953..8b540fa 100644
--- a/media/ndk/NdkImageReaderPriv.h
+++ b/media/ndk/NdkImageReaderPriv.h
@@ -112,7 +112,7 @@
 
     struct FrameListener : public ConsumerBase::FrameAvailableListener {
       public:
-        FrameListener(AImageReader* parent) : mReader(parent) {}
+        explicit FrameListener(AImageReader* parent) : mReader(parent) {}
 
         void onFrameAvailable(const BufferItem& item) override;
 
diff --git a/media/ndk/NdkMediaCodec.cpp b/media/ndk/NdkMediaCodec.cpp
index 50b490d..3d1eca1 100644
--- a/media/ndk/NdkMediaCodec.cpp
+++ b/media/ndk/NdkMediaCodec.cpp
@@ -59,7 +59,7 @@
 private:
     AMediaCodec* mCodec;
 public:
-    CodecHandler(AMediaCodec *codec);
+    explicit CodecHandler(AMediaCodec *codec);
     virtual void onMessageReceived(const sp<AMessage> &msg);
 };
 
diff --git a/media/ndk/libmediandk.map.txt b/media/ndk/libmediandk.map.txt
new file mode 100644
index 0000000..7db4d06
--- /dev/null
+++ b/media/ndk/libmediandk.map.txt
@@ -0,0 +1,141 @@
+LIBMEDIANDK {
+  global:
+    AImageReader_acquireLatestImage; # introduced=24
+    AImageReader_acquireNextImage; # introduced=24
+    AImageReader_delete; # introduced=24
+    AImageReader_getFormat; # introduced=24
+    AImageReader_getHeight; # introduced=24
+    AImageReader_getMaxImages; # introduced=24
+    AImageReader_getWidth; # introduced=24
+    AImageReader_getWindow; # introduced=24
+    AImageReader_new; # introduced=24
+    AImageReader_setImageListener; # introduced=24
+    AImage_delete; # introduced=24
+    AImage_getCropRect; # introduced=24
+    AImage_getFormat; # introduced=24
+    AImage_getHeight; # introduced=24
+    AImage_getNumberOfPlanes; # introduced=24
+    AImage_getPlaneData; # introduced=24
+    AImage_getPlanePixelStride; # introduced=24
+    AImage_getPlaneRowStride; # introduced=24
+    AImage_getTimestamp; # introduced=24
+    AImage_getWidth; # introduced=24
+    AMEDIAFORMAT_KEY_AAC_PROFILE; # var
+    AMEDIAFORMAT_KEY_BIT_RATE; # var
+    AMEDIAFORMAT_KEY_CHANNEL_COUNT; # var
+    AMEDIAFORMAT_KEY_CHANNEL_MASK; # var
+    AMEDIAFORMAT_KEY_COLOR_FORMAT; # var
+    AMEDIAFORMAT_KEY_DURATION; # var
+    AMEDIAFORMAT_KEY_FLAC_COMPRESSION_LEVEL; # var
+    AMEDIAFORMAT_KEY_FRAME_RATE; # var
+    AMEDIAFORMAT_KEY_HEIGHT; # var
+    AMEDIAFORMAT_KEY_IS_ADTS; # var
+    AMEDIAFORMAT_KEY_IS_AUTOSELECT; # var
+    AMEDIAFORMAT_KEY_IS_DEFAULT; # var
+    AMEDIAFORMAT_KEY_IS_FORCED_SUBTITLE; # var
+    AMEDIAFORMAT_KEY_I_FRAME_INTERVAL; # var
+    AMEDIAFORMAT_KEY_LANGUAGE; # var
+    AMEDIAFORMAT_KEY_MAX_HEIGHT; # var
+    AMEDIAFORMAT_KEY_MAX_INPUT_SIZE; # var
+    AMEDIAFORMAT_KEY_MAX_WIDTH; # var
+    AMEDIAFORMAT_KEY_MIME; # var
+    AMEDIAFORMAT_KEY_PUSH_BLANK_BUFFERS_ON_STOP; # var
+    AMEDIAFORMAT_KEY_REPEAT_PREVIOUS_FRAME_AFTER; # var
+    AMEDIAFORMAT_KEY_SAMPLE_RATE; # var
+    AMEDIAFORMAT_KEY_STRIDE; # var
+    AMEDIAFORMAT_KEY_WIDTH; # var
+    AMediaCodecCryptoInfo_delete;
+    AMediaCodecCryptoInfo_getClearBytes;
+    AMediaCodecCryptoInfo_getEncryptedBytes;
+    AMediaCodecCryptoInfo_getIV;
+    AMediaCodecCryptoInfo_getKey;
+    AMediaCodecCryptoInfo_getMode;
+    AMediaCodecCryptoInfo_getNumSubSamples;
+    AMediaCodecCryptoInfo_new;
+    AMediaCodecCryptoInfo_setPattern; # introduced=24
+    AMediaCodec_configure;
+    AMediaCodec_createCodecByName;
+    AMediaCodec_createDecoderByType;
+    AMediaCodec_createEncoderByType;
+    AMediaCodec_delete;
+    AMediaCodec_dequeueInputBuffer;
+    AMediaCodec_dequeueOutputBuffer;
+    AMediaCodec_flush;
+    AMediaCodec_getInputBuffer;
+    AMediaCodec_getOutputBuffer;
+    AMediaCodec_getOutputFormat;
+    AMediaCodec_queueInputBuffer;
+    AMediaCodec_queueSecureInputBuffer;
+    AMediaCodec_releaseOutputBuffer;
+    AMediaCodec_releaseOutputBufferAtTime;
+    AMediaCodec_setOutputSurface; # introduced=24
+    AMediaCodec_start;
+    AMediaCodec_stop;
+    AMediaCrypto_delete;
+    AMediaCrypto_isCryptoSchemeSupported;
+    AMediaCrypto_new;
+    AMediaCrypto_requiresSecureDecoderComponent;
+    AMediaDrm_closeSession;
+    AMediaDrm_createByUUID;
+    AMediaDrm_decrypt;
+    AMediaDrm_encrypt;
+    AMediaDrm_getKeyRequest;
+    AMediaDrm_getPropertyByteArray;
+    AMediaDrm_getPropertyString;
+    AMediaDrm_getProvisionRequest;
+    AMediaDrm_getSecureStops;
+    AMediaDrm_isCryptoSchemeSupported;
+    AMediaDrm_openSession;
+    AMediaDrm_provideKeyResponse;
+    AMediaDrm_provideProvisionResponse;
+    AMediaDrm_queryKeyStatus;
+    AMediaDrm_release;
+    AMediaDrm_releaseSecureStops;
+    AMediaDrm_removeKeys;
+    AMediaDrm_restoreKeys;
+    AMediaDrm_setOnEventListener;
+    AMediaDrm_setPropertyByteArray;
+    AMediaDrm_setPropertyString;
+    AMediaDrm_sign;
+    AMediaDrm_verify;
+    AMediaExtractor_advance;
+    AMediaExtractor_delete;
+    AMediaExtractor_getPsshInfo;
+    AMediaExtractor_getSampleCryptoInfo;
+    AMediaExtractor_getSampleFlags;
+    AMediaExtractor_getSampleTime;
+    AMediaExtractor_getSampleTrackIndex;
+    AMediaExtractor_getTrackCount;
+    AMediaExtractor_getTrackFormat;
+    AMediaExtractor_new;
+    AMediaExtractor_readSampleData;
+    AMediaExtractor_seekTo;
+    AMediaExtractor_selectTrack;
+    AMediaExtractor_setDataSource;
+    AMediaExtractor_setDataSourceFd;
+    AMediaExtractor_unselectTrack;
+    AMediaFormat_delete;
+    AMediaFormat_getBuffer;
+    AMediaFormat_getFloat;
+    AMediaFormat_getInt32;
+    AMediaFormat_getInt64;
+    AMediaFormat_getSize;
+    AMediaFormat_getString;
+    AMediaFormat_new;
+    AMediaFormat_setBuffer;
+    AMediaFormat_setFloat;
+    AMediaFormat_setInt32;
+    AMediaFormat_setInt64;
+    AMediaFormat_setString;
+    AMediaFormat_toString;
+    AMediaMuxer_addTrack;
+    AMediaMuxer_delete;
+    AMediaMuxer_new;
+    AMediaMuxer_setLocation;
+    AMediaMuxer_setOrientationHint;
+    AMediaMuxer_start;
+    AMediaMuxer_stop;
+    AMediaMuxer_writeSampleData;
+  local:
+    *;
+};
diff --git a/media/utils/ISchedulingPolicyService.cpp b/media/utils/ISchedulingPolicyService.cpp
index f55bc02..f5bfe20 100644
--- a/media/utils/ISchedulingPolicyService.cpp
+++ b/media/utils/ISchedulingPolicyService.cpp
@@ -32,7 +32,7 @@
 class BpSchedulingPolicyService : public BpInterface<ISchedulingPolicyService>
 {
 public:
-    BpSchedulingPolicyService(const sp<IBinder>& impl)
+    explicit BpSchedulingPolicyService(const sp<IBinder>& impl)
         : BpInterface<ISchedulingPolicyService>(impl)
     {
     }
diff --git a/radio/IRadio.cpp b/radio/IRadio.cpp
index 242df77..0881a91 100644
--- a/radio/IRadio.cpp
+++ b/radio/IRadio.cpp
@@ -44,7 +44,7 @@
 class BpRadio: public BpInterface<IRadio>
 {
 public:
-    BpRadio(const sp<IBinder>& impl)
+    explicit BpRadio(const sp<IBinder>& impl)
         : BpInterface<IRadio>(impl)
     {
     }
diff --git a/radio/IRadioClient.cpp b/radio/IRadioClient.cpp
index 033ca49..ca21949 100644
--- a/radio/IRadioClient.cpp
+++ b/radio/IRadioClient.cpp
@@ -33,7 +33,7 @@
 {
 
 public:
-    BpRadioClient(const sp<IBinder>& impl)
+    explicit BpRadioClient(const sp<IBinder>& impl)
         : BpInterface<IRadioClient>(impl)
     {
     }
diff --git a/radio/IRadioService.cpp b/radio/IRadioService.cpp
index 81acf9e..960aab4 100644
--- a/radio/IRadioService.cpp
+++ b/radio/IRadioService.cpp
@@ -45,7 +45,7 @@
 class BpRadioService: public BpInterface<IRadioService>
 {
 public:
-    BpRadioService(const sp<IBinder>& impl)
+    explicit BpRadioService(const sp<IBinder>& impl)
         : BpInterface<IRadioService>(impl)
     {
     }
diff --git a/services/audioflinger/Android.mk b/services/audioflinger/Android.mk
index 8b831f0..e7fc381 100644
--- a/services/audioflinger/Android.mk
+++ b/services/audioflinger/Android.mk
@@ -36,7 +36,6 @@
 LOCAL_C_INCLUDES := \
     $(TOPDIR)frameworks/av/services/audiopolicy \
     $(TOPDIR)external/sonic \
-    libcore/include \
     $(call include-path-for, audio-effects) \
     $(call include-path-for, audio-utils)
 
diff --git a/services/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cpp
index 1785a03..60093cc 100644
--- a/services/audioflinger/AudioFlinger.cpp
+++ b/services/audioflinger/AudioFlinger.cpp
@@ -1423,11 +1423,15 @@
         mAudioFlinger(audioFlinger),
         mPid(pid)
 {
-    size_t heapSize = kClientSharedHeapSizeBytes;
-    // Increase heap size on non low ram devices to limit risk of reconnection failure for
-    // invalidated tracks
-    if (!audioFlinger->isLowRamDevice()) {
-        heapSize *= kClientSharedHeapSizeMultiplier;
+    size_t heapSize = property_get_int32("ro.af.client_heap_size_kbyte", 0);
+    heapSize *= 1024;
+    if (!heapSize) {
+        heapSize = kClientSharedHeapSizeBytes;
+        // Increase heap size on non low ram devices to limit risk of reconnection failure for
+        // invalidated tracks
+        if (!audioFlinger->isLowRamDevice()) {
+            heapSize *= kClientSharedHeapSizeMultiplier;
+        }
     }
     mMemoryDealer = new MemoryDealer(heapSize, "AudioFlinger::Client");
 }
@@ -2024,7 +2028,7 @@
     return NO_ERROR;
 }
 
-void AudioFlinger::closeOutputFinish(sp<PlaybackThread> thread)
+void AudioFlinger::closeOutputFinish(const sp<PlaybackThread>& thread)
 {
     AudioStreamOut *out = thread->clearOutput();
     ALOG_ASSERT(out != NULL, "out shouldn't be NULL");
@@ -2033,7 +2037,7 @@
     delete out;
 }
 
-void AudioFlinger::closeOutputInternal_l(sp<PlaybackThread> thread)
+void AudioFlinger::closeOutputInternal_l(const sp<PlaybackThread>& thread)
 {
     mPlaybackThreads.removeItem(thread->mId);
     thread->exit();
@@ -2294,7 +2298,7 @@
     return NO_ERROR;
 }
 
-void AudioFlinger::closeInputFinish(sp<RecordThread> thread)
+void AudioFlinger::closeInputFinish(const sp<RecordThread>& thread)
 {
     thread->exit();
     AudioStreamIn *in = thread->clearInput();
@@ -2304,7 +2308,7 @@
     delete in;
 }
 
-void AudioFlinger::closeInputInternal_l(sp<RecordThread> thread)
+void AudioFlinger::closeInputInternal_l(const sp<RecordThread>& thread)
 {
     mRecordThreads.removeItem(thread->mId);
     closeInputFinish(thread);
@@ -2560,7 +2564,7 @@
                                     audio_session_t triggerSession,
                                     audio_session_t listenerSession,
                                     sync_event_callback_t callBack,
-                                    wp<RefBase> cookie)
+                                    const wp<RefBase>& cookie)
 {
     Mutex::Autolock _l(mLock);
 
diff --git a/services/audioflinger/AudioFlinger.h b/services/audioflinger/AudioFlinger.h
index c56dcc1..c4b89f8 100644
--- a/services/audioflinger/AudioFlinger.h
+++ b/services/audioflinger/AudioFlinger.h
@@ -318,7 +318,7 @@
                                         audio_session_t triggerSession,
                                         audio_session_t listenerSession,
                                         sync_event_callback_t callBack,
-                                        wp<RefBase> cookie);
+                                        const wp<RefBase>& cookie);
 
 private:
 
@@ -485,7 +485,7 @@
     // server side of the client's IAudioTrack
     class TrackHandle : public android::BnAudioTrack {
     public:
-                            TrackHandle(const sp<PlaybackThread::Track>& track);
+        explicit            TrackHandle(const sp<PlaybackThread::Track>& track);
         virtual             ~TrackHandle();
         virtual sp<IMemory> getCblk() const;
         virtual status_t    start();
@@ -507,7 +507,7 @@
     // server side of the client's IAudioRecord
     class RecordHandle : public android::BnAudioRecord {
     public:
-        RecordHandle(const sp<RecordThread::RecordTrack>& recordTrack);
+        explicit RecordHandle(const sp<RecordThread::RecordTrack>& recordTrack);
         virtual             ~RecordHandle();
         virtual status_t    start(int /*AudioSystem::sync_event_t*/ event,
                 audio_session_t triggerSession);
@@ -540,8 +540,8 @@
                                               const String8& address,
                                               audio_output_flags_t flags);
 
-              void closeOutputFinish(sp<PlaybackThread> thread);
-              void closeInputFinish(sp<RecordThread> thread);
+              void closeOutputFinish(const sp<PlaybackThread>& thread);
+              void closeInputFinish(const sp<RecordThread>& thread);
 
               // no range check, AudioFlinger::mLock held
               bool streamMute_l(audio_stream_type_t stream) const
@@ -712,9 +712,9 @@
 
     // for use from destructor
     status_t    closeOutput_nonvirtual(audio_io_handle_t output);
-    void        closeOutputInternal_l(sp<PlaybackThread> thread);
+    void        closeOutputInternal_l(const sp<PlaybackThread>& thread);
     status_t    closeInput_nonvirtual(audio_io_handle_t input);
-    void        closeInputInternal_l(sp<RecordThread> thread);
+    void        closeInputInternal_l(const sp<RecordThread>& thread);
     void        setAudioHwSyncForSession_l(PlaybackThread *thread, audio_session_t sessionId);
 
     status_t    checkStreamType(audio_stream_type_t stream) const;
diff --git a/services/audioflinger/AudioMixer.cpp b/services/audioflinger/AudioMixer.cpp
index 0be7199..582a5e8 100644
--- a/services/audioflinger/AudioMixer.cpp
+++ b/services/audioflinger/AudioMixer.cpp
@@ -1679,8 +1679,8 @@
 
 // Needs to derive a compile time constant (constexpr).  Could be targeted to go
 // to a MONOVOL mixtype based on MAX_NUM_VOLUMES, but that's an unnecessary complication.
-#define MIXTYPE_MONOVOL(mixtype) (mixtype == MIXTYPE_MULTI ? MIXTYPE_MULTI_MONOVOL : \
-        mixtype == MIXTYPE_MULTI_SAVEONLY ? MIXTYPE_MULTI_SAVEONLY_MONOVOL : mixtype)
+#define MIXTYPE_MONOVOL(mixtype) ((mixtype) == MIXTYPE_MULTI ? MIXTYPE_MULTI_MONOVOL : \
+        (mixtype) == MIXTYPE_MULTI_SAVEONLY ? MIXTYPE_MULTI_SAVEONLY_MONOVOL : (mixtype))
 
 /* MIXTYPE     (see AudioMixerOps.h MIXTYPE_* enumeration)
  * TO: int32_t (Q4.27) or float
diff --git a/services/audioflinger/AudioResamplerDyn.cpp b/services/audioflinger/AudioResamplerDyn.cpp
index e615700..b7ca5d9 100644
--- a/services/audioflinger/AudioResamplerDyn.cpp
+++ b/services/audioflinger/AudioResamplerDyn.cpp
@@ -520,7 +520,7 @@
         //        inFrameCount, outputIndex, outFrameCount, phaseFraction, phaseWrapLimit);
 
         // check inputIndex overflow
-        ALOG_ASSERT(inputIndex <= mBuffer.frameCount, "inputIndex%d > frameCount%d",
+        ALOG_ASSERT(inputIndex <= mBuffer.frameCount, "inputIndex%zu > frameCount%zu",
                 inputIndex, mBuffer.frameCount);
         // Buffer is empty, fetch a new one if necessary (inFrameCount > 0).
         // We may not fetch a new buffer if the existing data is sufficient.
@@ -591,7 +591,7 @@
         // We arrive here when we're finished or when the input buffer runs out.
         // Regardless we need to release the input buffer if we've acquired it.
         if (inputIndex > 0) {  // we've acquired a buffer (alternatively could check frameCount)
-            ALOG_ASSERT(inputIndex == frameCount, "inputIndex(%d) != frameCount(%d)",
+            ALOG_ASSERT(inputIndex == frameCount, "inputIndex(%zu) != frameCount(%zu)",
                     inputIndex, frameCount);  // must have been fully read.
             inputIndex = 0;
             provider->releaseBuffer(&mBuffer);
@@ -603,7 +603,7 @@
     // inputIndex must be zero in all three cases:
     // (1) the buffer never was been acquired; (2) the buffer was
     // released at "done:"; or (3) getNextBuffer() failed.
-    ALOG_ASSERT(inputIndex == 0, "Releasing: inputindex:%d frameCount:%d  phaseFraction:%u",
+    ALOG_ASSERT(inputIndex == 0, "Releasing: inputindex:%zu frameCount:%zu  phaseFraction:%u",
             inputIndex, mBuffer.frameCount, phaseFraction);
     ALOG_ASSERT(mBuffer.frameCount == 0); // there must be no frames in the buffer
     mInBuffer.setImpulse(impulse);
diff --git a/services/audioflinger/AudioWatchdog.h b/services/audioflinger/AudioWatchdog.h
index 4657530..7b69fc6 100644
--- a/services/audioflinger/AudioWatchdog.h
+++ b/services/audioflinger/AudioWatchdog.h
@@ -41,7 +41,7 @@
 class AudioWatchdog : public Thread {
 
 public:
-    AudioWatchdog(unsigned periodMs = 50) : Thread(false /*canCallJava*/), mPaused(false),
+    explicit AudioWatchdog(unsigned periodMs = 50) : Thread(false /*canCallJava*/), mPaused(false),
             mPeriodNs(periodMs * 1000000), mMaxCycleNs(mPeriodNs * 2),
             // mOldTs
             // mLogTs initialized below
diff --git a/services/audioflinger/AutoPark.h b/services/audioflinger/AutoPark.h
index e539e47..9ac7b65 100644
--- a/services/audioflinger/AutoPark.h
+++ b/services/audioflinger/AutoPark.h
@@ -21,7 +21,7 @@
 public:
 
     // Park the specific FastThread, which can be nullptr, in hot idle if not currently idling
-    AutoPark(const sp<T>& fastThread) : mFastThread(fastThread)
+    explicit AutoPark(const sp<T>& fastThread) : mFastThread(fastThread)
     {
         mPreviousCommand = FastThreadState::HOT_IDLE;
         if (fastThread != nullptr) {
diff --git a/services/audioflinger/Effects.cpp b/services/audioflinger/Effects.cpp
index 9711f2d..e2fad6f 100644
--- a/services/audioflinger/Effects.cpp
+++ b/services/audioflinger/Effects.cpp
@@ -1473,7 +1473,7 @@
 }
 
 // Must be called with EffectChain::mLock locked
-void AudioFlinger::EffectChain::clearInputBuffer_l(sp<ThreadBase> thread)
+void AudioFlinger::EffectChain::clearInputBuffer_l(const sp<ThreadBase>& thread)
 {
     // TODO: This will change in the future, depending on multichannel
     // and sample format changes for effects.
diff --git a/services/audioflinger/Effects.h b/services/audioflinger/Effects.h
index 818bf94..96cb607 100644
--- a/services/audioflinger/Effects.h
+++ b/services/audioflinger/Effects.h
@@ -370,7 +370,7 @@
     // types or implementations from the suspend/restore mechanism.
     bool isEffectEligibleForSuspend(const effect_descriptor_t& desc);
 
-    void clearInputBuffer_l(sp<ThreadBase> thread);
+    void clearInputBuffer_l(const sp<ThreadBase>& thread);
 
     void setThread(const sp<ThreadBase>& thread);
 
diff --git a/services/audioflinger/LinearMap.h b/services/audioflinger/LinearMap.h
index fca14dd..2220a0c 100644
--- a/services/audioflinger/LinearMap.h
+++ b/services/audioflinger/LinearMap.h
@@ -134,7 +134,7 @@
         FIND_METHOD_START_VALUE,             // No samples in history, using start value
     };
 
-    LinearMap(size_t size)
+    explicit LinearMap(size_t size)
             : mSize(size),
               mPos(0), // a circular buffer, so could start anywhere. the first sample is at 1.
               mSamples(0),
diff --git a/services/audioflinger/PatchPanel.h b/services/audioflinger/PatchPanel.h
index 16ec278..d37c0d3 100644
--- a/services/audioflinger/PatchPanel.h
+++ b/services/audioflinger/PatchPanel.h
@@ -24,7 +24,7 @@
 
     class Patch;
 
-    PatchPanel(const sp<AudioFlinger>& audioFlinger);
+    explicit PatchPanel(const sp<AudioFlinger>& audioFlinger);
     virtual ~PatchPanel();
 
     /* List connected audio ports and their attributes */
@@ -54,7 +54,7 @@
 
     class Patch {
     public:
-        Patch(const struct audio_patch *patch) :
+        explicit Patch(const struct audio_patch *patch) :
             mAudioPatch(*patch), mHandle(AUDIO_PATCH_HANDLE_NONE),
             mHalHandle(AUDIO_PATCH_HANDLE_NONE), mRecordPatchHandle(AUDIO_PATCH_HANDLE_NONE),
             mPlaybackPatchHandle(AUDIO_PATCH_HANDLE_NONE) {}
diff --git a/services/audioflinger/Threads.cpp b/services/audioflinger/Threads.cpp
index 0f403ae..8a4fbb5 100644
--- a/services/audioflinger/Threads.cpp
+++ b/services/audioflinger/Threads.cpp
@@ -97,7 +97,7 @@
 }
 
 #ifndef ARRAY_SIZE
-#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
+#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
 #endif
 
 namespace android {
@@ -1153,7 +1153,7 @@
             mSuspendedSessions.valueAt(index);
 
     for (size_t i = 0; i < sessionEffects.size(); i++) {
-        sp<SuspendedSessionDesc> desc = sessionEffects.valueAt(i);
+        const sp<SuspendedSessionDesc>& desc = sessionEffects.valueAt(i);
         for (int j = 0; j < desc->mRefCount; j++) {
             if (sessionEffects.keyAt(i) == EffectChain::kKeyForSuspendAll) {
                 chain->setEffectSuspendedAll_l(true);
@@ -2934,14 +2934,14 @@
 }
 
 status_t AudioFlinger::PlaybackThread::attachAuxEffect(
-        const sp<AudioFlinger::PlaybackThread::Track> track, int EffectId)
+        const sp<AudioFlinger::PlaybackThread::Track>& track, int EffectId)
 {
     Mutex::Autolock _l(mLock);
     return attachAuxEffect_l(track, EffectId);
 }
 
 status_t AudioFlinger::PlaybackThread::attachAuxEffect_l(
-        const sp<AudioFlinger::PlaybackThread::Track> track, int EffectId)
+        const sp<AudioFlinger::PlaybackThread::Track>& track, int EffectId)
 {
     status_t status = NO_ERROR;
 
diff --git a/services/audioflinger/Threads.h b/services/audioflinger/Threads.h
index f353f3b..a55655f 100644
--- a/services/audioflinger/Threads.h
+++ b/services/audioflinger/Threads.h
@@ -97,7 +97,7 @@
         sp<ConfigEventData> mData;     // event specific parameter data
 
     protected:
-        ConfigEvent(int type, bool requiresSystemReady = false) :
+        explicit ConfigEvent(int type, bool requiresSystemReady = false) :
             mType(type), mStatus(NO_ERROR), mWaitStatus(false),
             mRequiresSystemReady(requiresSystemReady), mData(NULL) {}
     };
@@ -149,7 +149,7 @@
 
     class SetParameterConfigEventData : public ConfigEventData {
     public:
-        SetParameterConfigEventData(String8 keyValuePairs) :
+        explicit SetParameterConfigEventData(String8 keyValuePairs) :
             mKeyValuePairs(keyValuePairs) {}
 
         virtual  void dump(char *buffer, size_t size) {
@@ -161,7 +161,7 @@
 
     class SetParameterConfigEvent : public ConfigEvent {
     public:
-        SetParameterConfigEvent(String8 keyValuePairs) :
+        explicit SetParameterConfigEvent(String8 keyValuePairs) :
             ConfigEvent(CFG_EVENT_SET_PARAMETER) {
             mData = new SetParameterConfigEventData(keyValuePairs);
             mWaitStatus = true;
@@ -196,7 +196,7 @@
 
     class ReleaseAudioPatchConfigEventData : public ConfigEventData {
     public:
-        ReleaseAudioPatchConfigEventData(const audio_patch_handle_t handle) :
+        explicit ReleaseAudioPatchConfigEventData(const audio_patch_handle_t handle) :
             mHandle(handle) {}
 
         virtual  void dump(char *buffer, size_t size) {
@@ -208,7 +208,7 @@
 
     class ReleaseAudioPatchConfigEvent : public ConfigEvent {
     public:
-        ReleaseAudioPatchConfigEvent(const audio_patch_handle_t handle) :
+        explicit ReleaseAudioPatchConfigEvent(const audio_patch_handle_t handle) :
             ConfigEvent(CFG_EVENT_RELEASE_AUDIO_PATCH) {
             mData = new ReleaseAudioPatchConfigEventData(handle);
             mWaitStatus = true;
@@ -218,7 +218,7 @@
 
     class PMDeathRecipient : public IBinder::DeathRecipient {
     public:
-                    PMDeathRecipient(const wp<ThreadBase>& thread) : mThread(thread) {}
+        explicit    PMDeathRecipient(const wp<ThreadBase>& thread) : mThread(thread) {}
         virtual     ~PMDeathRecipient() {}
 
         // IBinder::DeathRecipient
@@ -618,9 +618,9 @@
                     return reinterpret_cast<int16_t *>(mSinkBuffer); };
 
     virtual     void detachAuxEffect_l(int effectId);
-                status_t attachAuxEffect(const sp<AudioFlinger::PlaybackThread::Track> track,
+                status_t attachAuxEffect(const sp<AudioFlinger::PlaybackThread::Track>& track,
                         int EffectId);
-                status_t attachAuxEffect_l(const sp<AudioFlinger::PlaybackThread::Track> track,
+                status_t attachAuxEffect_l(const sp<AudioFlinger::PlaybackThread::Track>& track,
                         int EffectId);
 
                 virtual status_t addEffectChain_l(const sp<EffectChain>& chain);
@@ -1040,7 +1040,7 @@
 class AsyncCallbackThread : public Thread {
 public:
 
-    AsyncCallbackThread(const wp<PlaybackThread>& playbackThread);
+    explicit AsyncCallbackThread(const wp<PlaybackThread>& playbackThread);
 
     virtual             ~AsyncCallbackThread();
 
@@ -1125,7 +1125,7 @@
     class ResamplerBufferProvider : public AudioBufferProvider
     {
     public:
-        ResamplerBufferProvider(RecordTrack* recordTrack) :
+        explicit ResamplerBufferProvider(RecordTrack* recordTrack) :
             mRecordTrack(recordTrack),
             mRsmpInUnrel(0), mRsmpInFront(0) { }
         virtual ~ResamplerBufferProvider() { }
diff --git a/services/audiopolicy/AudioPolicyInterface.h b/services/audiopolicy/AudioPolicyInterface.h
index a215b95..bb8a8fa 100644
--- a/services/audiopolicy/AudioPolicyInterface.h
+++ b/services/audiopolicy/AudioPolicyInterface.h
@@ -220,7 +220,7 @@
 
     virtual status_t releaseSoundTriggerSession(audio_session_t session) = 0;
 
-    virtual status_t registerPolicyMixes(Vector<AudioMix> mixes) = 0;
+    virtual status_t registerPolicyMixes(const Vector<AudioMix>& mixes) = 0;
     virtual status_t unregisterPolicyMixes(Vector<AudioMix> mixes) = 0;
 
     virtual status_t startAudioSource(const struct audio_port_config *source,
diff --git a/services/audiopolicy/common/managerdefinitions/Android.mk b/services/audiopolicy/common/managerdefinitions/Android.mk
index d7da0ad..02118c4 100644
--- a/services/audiopolicy/common/managerdefinitions/Android.mk
+++ b/services/audiopolicy/common/managerdefinitions/Android.mk
@@ -25,9 +25,12 @@
 
 LOCAL_SHARED_LIBRARIES := \
     libcutils \
+    libmedia \
     libutils \
     liblog \
 
+LOCAL_EXPORT_SHARED_LIBRARY_HEADERS := libmedia
+
 LOCAL_C_INCLUDES := \
     $(LOCAL_PATH)/include \
     $(TOPDIR)frameworks/av/services/audiopolicy/common/include \
diff --git a/services/audiopolicy/common/managerdefinitions/include/AudioInputDescriptor.h b/services/audiopolicy/common/managerdefinitions/include/AudioInputDescriptor.h
index f2b39f2..e689320 100644
--- a/services/audiopolicy/common/managerdefinitions/include/AudioInputDescriptor.h
+++ b/services/audiopolicy/common/managerdefinitions/include/AudioInputDescriptor.h
@@ -34,7 +34,7 @@
 class AudioInputDescriptor: public AudioPortConfig, public AudioSessionInfoProvider
 {
 public:
-    AudioInputDescriptor(const sp<IOProfile>& profile);
+    explicit AudioInputDescriptor(const sp<IOProfile>& profile);
     void setIoHandle(audio_io_handle_t ioHandle);
     audio_port_handle_t getId() const;
     audio_module_handle_t getModuleHandle() const;
diff --git a/services/audiopolicy/common/managerdefinitions/include/AudioOutputDescriptor.h b/services/audiopolicy/common/managerdefinitions/include/AudioOutputDescriptor.h
index dd3f8ae..35bb021 100644
--- a/services/audiopolicy/common/managerdefinitions/include/AudioOutputDescriptor.h
+++ b/services/audiopolicy/common/managerdefinitions/include/AudioOutputDescriptor.h
@@ -45,7 +45,7 @@
 
     audio_port_handle_t getId() const;
     virtual audio_devices_t device() const;
-    virtual bool sharesHwModuleWith(const sp<AudioOutputDescriptor> outputDesc);
+    virtual bool sharesHwModuleWith(const sp<AudioOutputDescriptor>& outputDesc);
     virtual audio_devices_t supportedDevices();
     virtual bool isDuplicated() const { return false; }
     virtual uint32_t latency() { return 0; }
@@ -102,7 +102,7 @@
     void setIoHandle(audio_io_handle_t ioHandle);
 
     virtual audio_devices_t device() const;
-    virtual bool sharesHwModuleWith(const sp<AudioOutputDescriptor> outputDesc);
+    virtual bool sharesHwModuleWith(const sp<AudioOutputDescriptor>& outputDesc);
     virtual audio_devices_t supportedDevices();
     virtual uint32_t latency();
     virtual bool isDuplicated() const { return (mOutput1 != NULL && mOutput2 != NULL); }
diff --git a/services/audiopolicy/common/managerdefinitions/include/AudioPolicyMix.h b/services/audiopolicy/common/managerdefinitions/include/AudioPolicyMix.h
index 8f5ebef..c9652de 100644
--- a/services/audiopolicy/common/managerdefinitions/include/AudioPolicyMix.h
+++ b/services/audiopolicy/common/managerdefinitions/include/AudioPolicyMix.h
@@ -52,11 +52,11 @@
 class AudioPolicyMixCollection : public DefaultKeyedVector<String8, sp<AudioPolicyMix> >
 {
 public:
-    status_t getAudioPolicyMix(String8 address, sp<AudioPolicyMix> &policyMix) const;
+    status_t getAudioPolicyMix(const String8& address, sp<AudioPolicyMix> &policyMix) const;
 
-    status_t registerMix(String8 address, AudioMix mix, sp<SwAudioOutputDescriptor> desc);
+    status_t registerMix(const String8& address, AudioMix mix, sp<SwAudioOutputDescriptor> desc);
 
-    status_t unregisterMix(String8 address);
+    status_t unregisterMix(const String8& address);
 
     void closeOutput(sp<SwAudioOutputDescriptor> &desc);
 
diff --git a/services/audiopolicy/common/managerdefinitions/include/AudioPort.h b/services/audiopolicy/common/managerdefinitions/include/AudioPort.h
index 211ec98..d00d49f 100644
--- a/services/audiopolicy/common/managerdefinitions/include/AudioPort.h
+++ b/services/audiopolicy/common/managerdefinitions/include/AudioPort.h
@@ -71,7 +71,7 @@
 
     virtual void toAudioPort(struct audio_port *port) const;
 
-    virtual void importAudioPort(const sp<AudioPort> port);
+    virtual void importAudioPort(const sp<AudioPort>& port);
 
     void addAudioProfile(const sp<AudioProfile> &profile) { mProfiles.add(profile); }
 
diff --git a/services/audiopolicy/common/managerdefinitions/include/AudioRoute.h b/services/audiopolicy/common/managerdefinitions/include/AudioRoute.h
index 67e197f..df54f48 100644
--- a/services/audiopolicy/common/managerdefinitions/include/AudioRoute.h
+++ b/services/audiopolicy/common/managerdefinitions/include/AudioRoute.h
@@ -36,7 +36,7 @@
 class AudioRoute  : public virtual RefBase
 {
 public:
-    AudioRoute(audio_route_type_t type) : mType(type) {}
+    explicit AudioRoute(audio_route_type_t type) : mType(type) {}
 
     void setSources(const AudioPortVector &sources) { mSources = sources; }
     const AudioPortVector &getSources() const { return mSources; }
diff --git a/services/audiopolicy/common/managerdefinitions/include/DeviceDescriptor.h b/services/audiopolicy/common/managerdefinitions/include/DeviceDescriptor.h
index ed2450c..9a52d22 100644
--- a/services/audiopolicy/common/managerdefinitions/include/DeviceDescriptor.h
+++ b/services/audiopolicy/common/managerdefinitions/include/DeviceDescriptor.h
@@ -30,7 +30,7 @@
 {
 public:
      // Note that empty name refers by convention to a generic device.
-    DeviceDescriptor(audio_devices_t type, const String8 &tagName = String8(""));
+    explicit DeviceDescriptor(audio_devices_t type, const String8 &tagName = String8(""));
 
     virtual ~DeviceDescriptor() {}
 
@@ -48,7 +48,7 @@
     // AudioPort
     virtual void attach(const sp<HwModule>& module);
     virtual void toAudioPort(struct audio_port *port) const;
-    virtual void importAudioPort(const sp<AudioPort> port);
+    virtual void importAudioPort(const sp<AudioPort>& port);
 
     audio_port_handle_t getId() const;
     status_t dump(int fd, int spaces, int index, bool verbose = true) const;
@@ -76,11 +76,11 @@
 
     audio_devices_t types() const { return mDeviceTypes; }
 
-    sp<DeviceDescriptor> getDevice(audio_devices_t type, String8 address) const;
+    sp<DeviceDescriptor> getDevice(audio_devices_t type, const String8& address) const;
     DeviceVector getDevicesFromType(audio_devices_t types) const;
     sp<DeviceDescriptor> getDeviceFromId(audio_port_handle_t id) const;
     sp<DeviceDescriptor> getDeviceFromTagName(const String8 &tagName) const;
-    DeviceVector getDevicesFromTypeAddr(audio_devices_t type, String8 address) const;
+    DeviceVector getDevicesFromTypeAddr(audio_devices_t type, const String8& address) const;
 
     audio_devices_t getDevicesFromHwModule(audio_module_handle_t moduleHandle) const;
 
diff --git a/services/audiopolicy/common/managerdefinitions/include/HwModule.h b/services/audiopolicy/common/managerdefinitions/include/HwModule.h
index dd2993d..3a31672 100644
--- a/services/audiopolicy/common/managerdefinitions/include/HwModule.h
+++ b/services/audiopolicy/common/managerdefinitions/include/HwModule.h
@@ -40,7 +40,7 @@
 class HwModule : public RefBase
 {
 public:
-    HwModule(const char *name, uint32_t halVersion = AUDIO_DEVICE_API_VERSION_MIN);
+    explicit HwModule(const char *name, uint32_t halVersion = AUDIO_DEVICE_API_VERSION_MIN);
     ~HwModule();
 
     const char *getName() const { return mName.string(); }
@@ -66,12 +66,12 @@
     status_t addInputProfile(const sp<IOProfile> &profile);
     status_t addProfile(const sp<IOProfile> &profile);
 
-    status_t addOutputProfile(String8 name, const audio_config_t *config,
-            audio_devices_t device, String8 address);
-    status_t removeOutputProfile(String8 name);
-    status_t addInputProfile(String8 name, const audio_config_t *config,
-            audio_devices_t device, String8 address);
-    status_t removeInputProfile(String8 name);
+    status_t addOutputProfile(const String8& name, const audio_config_t *config,
+            audio_devices_t device, const String8& address);
+    status_t removeOutputProfile(const String8& name);
+    status_t addInputProfile(const String8& name, const audio_config_t *config,
+            audio_devices_t device, const String8& address);
+    status_t removeInputProfile(const String8& name);
 
     audio_module_handle_t getHandle() const { return mHandle; }
 
diff --git a/services/audiopolicy/common/managerdefinitions/include/IOProfile.h b/services/audiopolicy/common/managerdefinitions/include/IOProfile.h
index dd20e93..ec04ef7 100644
--- a/services/audiopolicy/common/managerdefinitions/include/IOProfile.h
+++ b/services/audiopolicy/common/managerdefinitions/include/IOProfile.h
@@ -44,7 +44,7 @@
     // For input, flags is interpreted as audio_input_flags_t.
     // TODO: merge audio_output_flags_t and audio_input_flags_t.
     bool isCompatibleProfile(audio_devices_t device,
-                             String8 address,
+                             const String8& address,
                              uint32_t samplingRate,
                              uint32_t *updatedSamplingRate,
                              audio_format_t format,
@@ -110,13 +110,13 @@
 class InputProfile : public IOProfile
 {
 public:
-    InputProfile(const String8 &name) : IOProfile(name, AUDIO_PORT_ROLE_SINK) {}
+    explicit InputProfile(const String8 &name) : IOProfile(name, AUDIO_PORT_ROLE_SINK) {}
 };
 
 class OutputProfile : public IOProfile
 {
 public:
-    OutputProfile(const String8 &name) : IOProfile(name, AUDIO_PORT_ROLE_SOURCE) {}
+    explicit OutputProfile(const String8 &name) : IOProfile(name, AUDIO_PORT_ROLE_SOURCE) {}
 };
 
 }; // namespace android
diff --git a/services/audiopolicy/common/managerdefinitions/include/SessionRoute.h b/services/audiopolicy/common/managerdefinitions/include/SessionRoute.h
index b4feaf0..75bfd9d 100644
--- a/services/audiopolicy/common/managerdefinitions/include/SessionRoute.h
+++ b/services/audiopolicy/common/managerdefinitions/include/SessionRoute.h
@@ -86,7 +86,7 @@
         MAPTYPE_OUTPUT = 1
     } session_route_map_type_t;
 
-    SessionRouteMap(session_route_map_type_t mapType) :
+    explicit SessionRouteMap(session_route_map_type_t mapType) :
         mMapType(mapType)
     {}
 
@@ -106,7 +106,7 @@
     void addRoute(audio_session_t session,
                   audio_stream_type_t streamType,
                   audio_source_t source,
-                  sp<DeviceDescriptor> deviceDescriptor,
+                  const sp<DeviceDescriptor>& deviceDescriptor,
                   uid_t uid);
 
 private:
diff --git a/services/audiopolicy/common/managerdefinitions/src/AudioOutputDescriptor.cpp b/services/audiopolicy/common/managerdefinitions/src/AudioOutputDescriptor.cpp
index 79bbc54..1dbc3d0 100644
--- a/services/audiopolicy/common/managerdefinitions/src/AudioOutputDescriptor.cpp
+++ b/services/audiopolicy/common/managerdefinitions/src/AudioOutputDescriptor.cpp
@@ -75,7 +75,7 @@
 }
 
 bool AudioOutputDescriptor::sharesHwModuleWith(
-        const sp<AudioOutputDescriptor> outputDesc)
+        const sp<AudioOutputDescriptor>& outputDesc)
 {
     if (outputDesc->isDuplicated()) {
         return sharesHwModuleWith(outputDesc->subOutput1()) ||
@@ -264,7 +264,7 @@
 }
 
 bool SwAudioOutputDescriptor::sharesHwModuleWith(
-        const sp<AudioOutputDescriptor> outputDesc)
+        const sp<AudioOutputDescriptor>& outputDesc)
 {
     if (isDuplicated()) {
         return mOutput1->sharesHwModuleWith(outputDesc) || mOutput2->sharesHwModuleWith(outputDesc);
diff --git a/services/audiopolicy/common/managerdefinitions/src/AudioPolicyMix.cpp b/services/audiopolicy/common/managerdefinitions/src/AudioPolicyMix.cpp
index 7ee98b6..02833a9 100644
--- a/services/audiopolicy/common/managerdefinitions/src/AudioPolicyMix.cpp
+++ b/services/audiopolicy/common/managerdefinitions/src/AudioPolicyMix.cpp
@@ -51,7 +51,7 @@
     return &mMix;
 }
 
-status_t AudioPolicyMixCollection::registerMix(String8 address, AudioMix mix,
+status_t AudioPolicyMixCollection::registerMix(const String8& address, AudioMix mix,
                                                sp<SwAudioOutputDescriptor> desc)
 {
     ssize_t index = indexOfKey(address);
@@ -70,7 +70,7 @@
     return NO_ERROR;
 }
 
-status_t AudioPolicyMixCollection::unregisterMix(String8 address)
+status_t AudioPolicyMixCollection::unregisterMix(const String8& address)
 {
     ssize_t index = indexOfKey(address);
     if (index < 0) {
@@ -82,7 +82,7 @@
     return NO_ERROR;
 }
 
-status_t AudioPolicyMixCollection::getAudioPolicyMix(String8 address,
+status_t AudioPolicyMixCollection::getAudioPolicyMix(const String8& address,
                                                      sp<AudioPolicyMix> &policyMix) const
 {
     ssize_t index = indexOfKey(address);
diff --git a/services/audiopolicy/common/managerdefinitions/src/AudioPort.cpp b/services/audiopolicy/common/managerdefinitions/src/AudioPort.cpp
index 17ed537..31bf95c 100644
--- a/services/audiopolicy/common/managerdefinitions/src/AudioPort.cpp
+++ b/services/audiopolicy/common/managerdefinitions/src/AudioPort.cpp
@@ -127,7 +127,7 @@
     port->num_gains = i;
 }
 
-void AudioPort::importAudioPort(const sp<AudioPort> port)
+void AudioPort::importAudioPort(const sp<AudioPort>& port)
 {
     size_t indexToImport;
     for (indexToImport = 0; indexToImport < port->mProfiles.size(); indexToImport++) {
diff --git a/services/audiopolicy/common/managerdefinitions/src/DeviceDescriptor.cpp b/services/audiopolicy/common/managerdefinitions/src/DeviceDescriptor.cpp
index 50453ad..ba2b9e3 100644
--- a/services/audiopolicy/common/managerdefinitions/src/DeviceDescriptor.cpp
+++ b/services/audiopolicy/common/managerdefinitions/src/DeviceDescriptor.cpp
@@ -128,7 +128,7 @@
     return devices;
 }
 
-sp<DeviceDescriptor> DeviceVector::getDevice(audio_devices_t type, String8 address) const
+sp<DeviceDescriptor> DeviceVector::getDevice(audio_devices_t type, const String8& address) const
 {
     sp<DeviceDescriptor> device;
     for (size_t i = 0; i < size(); i++) {
@@ -177,7 +177,7 @@
 }
 
 DeviceVector DeviceVector::getDevicesFromTypeAddr(
-        audio_devices_t type, String8 address) const
+        audio_devices_t type, const String8& address) const
 {
     DeviceVector devices;
     for (size_t i = 0; i < size(); i++) {
@@ -263,7 +263,7 @@
     strncpy(port->ext.device.address, mAddress.string(), AUDIO_DEVICE_MAX_ADDRESS_LEN);
 }
 
-void DeviceDescriptor::importAudioPort(const sp<AudioPort> port) {
+void DeviceDescriptor::importAudioPort(const sp<AudioPort>& port) {
     AudioPort::importAudioPort(port);
     port->pickAudioProfile(mSamplingRate, mChannelMask, mFormat);
 }
diff --git a/services/audiopolicy/common/managerdefinitions/src/HwModule.cpp b/services/audiopolicy/common/managerdefinitions/src/HwModule.cpp
index a85c07f..7a942cd 100644
--- a/services/audiopolicy/common/managerdefinitions/src/HwModule.cpp
+++ b/services/audiopolicy/common/managerdefinitions/src/HwModule.cpp
@@ -42,8 +42,8 @@
     }
 }
 
-status_t HwModule::addOutputProfile(String8 name, const audio_config_t *config,
-                                    audio_devices_t device, String8 address)
+status_t HwModule::addOutputProfile(const String8 &name, const audio_config_t *config,
+                                    audio_devices_t device, const String8 &address)
 {
     sp<IOProfile> profile = new OutputProfile(name);
 
@@ -93,7 +93,7 @@
     }
 }
 
-status_t HwModule::removeOutputProfile(String8 name)
+status_t HwModule::removeOutputProfile(const String8& name)
 {
     for (size_t i = 0; i < mOutputProfiles.size(); i++) {
         if (mOutputProfiles[i]->getName() == name) {
@@ -105,8 +105,8 @@
     return NO_ERROR;
 }
 
-status_t HwModule::addInputProfile(String8 name, const audio_config_t *config,
-                                   audio_devices_t device, String8 address)
+status_t HwModule::addInputProfile(const String8& name, const audio_config_t *config,
+                                   audio_devices_t device, const String8& address)
 {
     sp<IOProfile> profile = new InputProfile(name);
     profile->addAudioProfile(new AudioProfile(config->format, config->channel_mask,
@@ -122,7 +122,7 @@
     return addInputProfile(profile);
 }
 
-status_t HwModule::removeInputProfile(String8 name)
+status_t HwModule::removeInputProfile(const String8& name)
 {
     for (size_t i = 0; i < mInputProfiles.size(); i++) {
         if (mInputProfiles[i]->getName() == name) {
diff --git a/services/audiopolicy/common/managerdefinitions/src/IOProfile.cpp b/services/audiopolicy/common/managerdefinitions/src/IOProfile.cpp
index abf2dd4..57f2534 100644
--- a/services/audiopolicy/common/managerdefinitions/src/IOProfile.cpp
+++ b/services/audiopolicy/common/managerdefinitions/src/IOProfile.cpp
@@ -28,7 +28,7 @@
 // Sampling rate, format and channel mask must be specified in order to
 // get a valid a match
 bool IOProfile::isCompatibleProfile(audio_devices_t device,
-                                    String8 address,
+                                    const String8& address,
                                     uint32_t samplingRate,
                                     uint32_t *updatedSamplingRate,
                                     audio_format_t format,
diff --git a/services/audiopolicy/common/managerdefinitions/src/SessionRoute.cpp b/services/audiopolicy/common/managerdefinitions/src/SessionRoute.cpp
index 7ecfa44..689f4e6 100644
--- a/services/audiopolicy/common/managerdefinitions/src/SessionRoute.cpp
+++ b/services/audiopolicy/common/managerdefinitions/src/SessionRoute.cpp
@@ -90,7 +90,7 @@
 void SessionRouteMap::addRoute(audio_session_t session,
                                audio_stream_type_t streamType,
                                audio_source_t source,
-                               sp<DeviceDescriptor> descriptor,
+                               const sp<DeviceDescriptor>& descriptor,
                                uid_t uid)
 {
     if (mMapType == MAPTYPE_INPUT && streamType != SessionRoute::STREAM_TYPE_NA) {
diff --git a/services/audiopolicy/enginedefault/Android.mk b/services/audiopolicy/enginedefault/Android.mk
index 85d1822..b247e21 100755
--- a/services/audiopolicy/enginedefault/Android.mk
+++ b/services/audiopolicy/enginedefault/Android.mk
@@ -40,6 +40,7 @@
     libxml2
 
 LOCAL_SHARED_LIBRARIES += \
+    liblog \
     libcutils \
     libutils \
     libaudioutils \
diff --git a/services/audiopolicy/enginedefault/src/Engine.h b/services/audiopolicy/enginedefault/src/Engine.h
index 606ad28..57538c4 100755
--- a/services/audiopolicy/enginedefault/src/Engine.h
+++ b/services/audiopolicy/enginedefault/src/Engine.h
@@ -43,7 +43,7 @@
     class ManagerInterfaceImpl : public AudioPolicyManagerInterface
     {
     public:
-        ManagerInterfaceImpl(Engine *policyEngine)
+        explicit ManagerInterfaceImpl(Engine *policyEngine)
             : mPolicyEngine(policyEngine) {}
 
         virtual void setObserver(AudioPolicyManagerObserver *observer)
diff --git a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
index 968b80f..a8bdf86 100644
--- a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
+++ b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
@@ -64,6 +64,17 @@
     return setDeviceConnectionStateInt(device, state, device_address, device_name);
 }
 
+void AudioPolicyManager::broadcastDeviceConnectionState(audio_devices_t device,
+                                                        audio_policy_dev_state_t state,
+                                                        const String8 &device_address)
+{
+    AudioParameter param(device_address);
+    const String8 key(state == AUDIO_POLICY_DEVICE_STATE_AVAILABLE ?
+                AUDIO_PARAMETER_DEVICE_CONNECT : AUDIO_PARAMETER_DEVICE_DISCONNECT);
+    param.addInt(key, device);
+    mpClientInterface->setParameters(AUDIO_IO_HANDLE_NONE, param.toString());
+}
+
 status_t AudioPolicyManager::setDeviceConnectionStateInt(audio_devices_t device,
                                                          audio_policy_dev_state_t state,
                                                          const char *device_address,
@@ -112,8 +123,15 @@
                 return NO_MEMORY;
             }
 
+            // Before checking outputs, broadcast connect event to allow HAL to retrieve dynamic
+            // parameters on newly connected devices (instead of opening the outputs...)
+            broadcastDeviceConnectionState(device, state, devDesc->mAddress);
+
             if (checkOutputsForDevice(devDesc, state, outputs, devDesc->mAddress) != NO_ERROR) {
                 mAvailableOutputDevices.remove(devDesc);
+
+                broadcastDeviceConnectionState(device, AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE,
+                                               devDesc->mAddress);
                 return INVALID_OPERATION;
             }
             // Propagate device availability to Engine
@@ -125,11 +143,6 @@
             ALOGV("setDeviceConnectionState() checkOutputsForDevice() returned %zu outputs",
                   outputs.size());
 
-            // Send connect to HALs
-            AudioParameter param = AudioParameter(devDesc->mAddress);
-            param.addInt(String8(AUDIO_PARAMETER_DEVICE_CONNECT), device);
-            mpClientInterface->setParameters(AUDIO_IO_HANDLE_NONE, param.toString());
-
             } break;
         // handle output device disconnection
         case AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE: {
@@ -141,9 +154,7 @@
             ALOGV("setDeviceConnectionState() disconnecting output device %x", device);
 
             // Send Disconnect to HALs
-            AudioParameter param = AudioParameter(devDesc->mAddress);
-            param.addInt(String8(AUDIO_PARAMETER_DEVICE_DISCONNECT), device);
-            mpClientInterface->setParameters(AUDIO_IO_HANDLE_NONE, param.toString());
+            broadcastDeviceConnectionState(device, state, devDesc->mAddress);
 
             // remove device from available output devices
             mAvailableOutputDevices.remove(devDesc);
@@ -226,7 +237,14 @@
                       device);
                 return INVALID_OPERATION;
             }
+
+            // Before checking intputs, broadcast connect event to allow HAL to retrieve dynamic
+            // parameters on newly connected devices (instead of opening the inputs...)
+            broadcastDeviceConnectionState(device, state, devDesc->mAddress);
+
             if (checkInputsForDevice(devDesc, state, inputs, devDesc->mAddress) != NO_ERROR) {
+                broadcastDeviceConnectionState(device, AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE,
+                                               devDesc->mAddress);
                 return INVALID_OPERATION;
             }
 
@@ -237,11 +255,6 @@
                 return NO_MEMORY;
             }
 
-            // Set connect to HALs
-            AudioParameter param = AudioParameter(devDesc->mAddress);
-            param.addInt(String8(AUDIO_PARAMETER_DEVICE_CONNECT), device);
-            mpClientInterface->setParameters(AUDIO_IO_HANDLE_NONE, param.toString());
-
             // Propagate device availability to Engine
             mEngine->setDeviceConnectionState(devDesc, state);
         } break;
@@ -256,9 +269,7 @@
             ALOGV("setDeviceConnectionState() disconnecting input device %x", device);
 
             // Set Disconnect to HALs
-            AudioParameter param = AudioParameter(devDesc->mAddress);
-            param.addInt(String8(AUDIO_PARAMETER_DEVICE_DISCONNECT), device);
-            mpClientInterface->setParameters(AUDIO_IO_HANDLE_NONE, param.toString());
+            broadcastDeviceConnectionState(device, state, devDesc->mAddress);
 
             checkInputsForDevice(devDesc, state, inputs, devDesc->mAddress);
             mAvailableInputDevices.remove(devDesc);
@@ -1148,7 +1159,7 @@
     return status;
 }
 
-status_t AudioPolicyManager::startSource(sp<AudioOutputDescriptor> outputDesc,
+status_t AudioPolicyManager::startSource(const sp<AudioOutputDescriptor>& outputDesc,
                                              audio_stream_type_t stream,
                                              audio_devices_t device,
                                              const char *address,
@@ -1286,7 +1297,7 @@
     return stopSource(outputDesc, stream, forceDeviceUpdate);
 }
 
-status_t AudioPolicyManager::stopSource(sp<AudioOutputDescriptor> outputDesc,
+status_t AudioPolicyManager::stopSource(const sp<AudioOutputDescriptor>& outputDesc,
                                             audio_stream_type_t stream,
                                             bool forceDeviceUpdate)
 {
@@ -2094,7 +2105,7 @@
 //  - 2 if none found, look for a mix matching the attributes usage
 //  - 3 if none found, default to device and output selection by policy rules.
 
-status_t AudioPolicyManager::registerPolicyMixes(Vector<AudioMix> mixes)
+status_t AudioPolicyManager::registerPolicyMixes(const Vector<AudioMix>& mixes)
 {
     ALOGV("registerPolicyMixes() %zu mix(es)", mixes.size());
     status_t res = NO_ERROR;
@@ -3633,7 +3644,7 @@
 
 // ---
 
-void AudioPolicyManager::addOutput(audio_io_handle_t output, sp<SwAudioOutputDescriptor> outputDesc)
+void AudioPolicyManager::addOutput(audio_io_handle_t output, const sp<SwAudioOutputDescriptor>& outputDesc)
 {
     outputDesc->setIoHandle(output);
     mOutputs.add(output, outputDesc);
@@ -3646,16 +3657,16 @@
     mOutputs.removeItem(output);
 }
 
-void AudioPolicyManager::addInput(audio_io_handle_t input, sp<AudioInputDescriptor> inputDesc)
+void AudioPolicyManager::addInput(audio_io_handle_t input, const sp<AudioInputDescriptor>& inputDesc)
 {
     inputDesc->setIoHandle(input);
     mInputs.add(input, inputDesc);
     nextAudioPortGeneration();
 }
 
-void AudioPolicyManager::findIoHandlesByAddress(sp<SwAudioOutputDescriptor> desc /*in*/,
+void AudioPolicyManager::findIoHandlesByAddress(const sp<SwAudioOutputDescriptor>& desc /*in*/,
         const audio_devices_t device /*in*/,
-        const String8 address /*in*/,
+        const String8& address /*in*/,
         SortedVector<audio_io_handle_t>& outputs /*out*/) {
     sp<DeviceDescriptor> devDesc =
         desc->mProfile->getSupportedDeviceByAddress(device, address);
@@ -3666,10 +3677,10 @@
     }
 }
 
-status_t AudioPolicyManager::checkOutputsForDevice(const sp<DeviceDescriptor> devDesc,
+status_t AudioPolicyManager::checkOutputsForDevice(const sp<DeviceDescriptor>& devDesc,
                                                    audio_policy_dev_state_t state,
                                                    SortedVector<audio_io_handle_t>& outputs,
-                                                   const String8 address)
+                                                   const String8& address)
 {
     audio_devices_t device = devDesc->type();
     sp<SwAudioOutputDescriptor> desc;
@@ -3912,10 +3923,10 @@
     return NO_ERROR;
 }
 
-status_t AudioPolicyManager::checkInputsForDevice(const sp<DeviceDescriptor> devDesc,
+status_t AudioPolicyManager::checkInputsForDevice(const sp<DeviceDescriptor>& devDesc,
                                                   audio_policy_dev_state_t state,
                                                   SortedVector<audio_io_handle_t>& inputs,
-                                                  const String8 address)
+                                                  const String8& address)
 {
     audio_devices_t device = devDesc->type();
     sp<AudioInputDescriptor> desc;
@@ -4156,7 +4167,7 @@
 
 SortedVector<audio_io_handle_t> AudioPolicyManager::getOutputsForDevice(
                                                                 audio_devices_t device,
-                                                                SwAudioOutputCollection openOutputs)
+                                                                const SwAudioOutputCollection& openOutputs)
 {
     SortedVector<audio_io_handle_t> outputs;
 
@@ -4567,7 +4578,7 @@
     mPreviousOutputs = mOutputs;
 }
 
-uint32_t AudioPolicyManager::checkDeviceMuteStrategies(sp<AudioOutputDescriptor> outputDesc,
+uint32_t AudioPolicyManager::checkDeviceMuteStrategies(const sp<AudioOutputDescriptor>& outputDesc,
                                                        audio_devices_t prevDevice,
                                                        uint32_t delayMs)
 {
@@ -4889,7 +4900,7 @@
 }
 
 sp<IOProfile> AudioPolicyManager::getInputProfile(audio_devices_t device,
-                                                  String8 address,
+                                                  const String8& address,
                                                   uint32_t& samplingRate,
                                                   audio_format_t& format,
                                                   audio_channel_mask_t& channelMask,
@@ -5275,7 +5286,7 @@
     return true;
 }
 
-bool AudioPolicyManager::isStrategyActive(const sp<AudioOutputDescriptor> outputDesc,
+bool AudioPolicyManager::isStrategyActive(const sp<AudioOutputDescriptor>& outputDesc,
                                           routing_strategy strategy, uint32_t inPastMs,
                                           nsecs_t sysTime) const
 {
diff --git a/services/audiopolicy/managerdefault/AudioPolicyManager.h b/services/audiopolicy/managerdefault/AudioPolicyManager.h
index 71bcd5f..5c2b673 100644
--- a/services/audiopolicy/managerdefault/AudioPolicyManager.h
+++ b/services/audiopolicy/managerdefault/AudioPolicyManager.h
@@ -83,7 +83,7 @@
 {
 
 public:
-                AudioPolicyManager(AudioPolicyClientInterface *clientInterface);
+        explicit AudioPolicyManager(AudioPolicyClientInterface *clientInterface);
         virtual ~AudioPolicyManager();
 
         // AudioPolicyInterface
@@ -222,7 +222,7 @@
             return mSoundTriggerSessions.releaseSession(session);
         }
 
-        virtual status_t registerPolicyMixes(Vector<AudioMix> mixes);
+        virtual status_t registerPolicyMixes(const Vector<AudioMix>& mixes);
         virtual status_t unregisterPolicyMixes(Vector<AudioMix> mixes);
 
         virtual status_t startAudioSource(const struct audio_port_config *source,
@@ -273,9 +273,9 @@
             return mDefaultOutputDevice;
         }
 protected:
-        void addOutput(audio_io_handle_t output, sp<SwAudioOutputDescriptor> outputDesc);
+        void addOutput(audio_io_handle_t output, const sp<SwAudioOutputDescriptor>& outputDesc);
         void removeOutput(audio_io_handle_t output);
-        void addInput(audio_io_handle_t input, sp<AudioInputDescriptor> inputDesc);
+        void addInput(audio_io_handle_t input, const sp<AudioInputDescriptor>& inputDesc);
 
         // return appropriate device for streams handled by the specified strategy according to current
         // phone state, connected devices...
@@ -291,7 +291,7 @@
         virtual audio_devices_t getDeviceForStrategy(routing_strategy strategy,
                                                      bool fromCache);
 
-        bool isStrategyActive(const sp<AudioOutputDescriptor> outputDesc, routing_strategy strategy,
+        bool isStrategyActive(const sp<AudioOutputDescriptor>& outputDesc, routing_strategy strategy,
                               uint32_t inPastMs = 0, nsecs_t sysTime = 0) const;
 
         // change the route of the specified output. Returns the number of ms we have slept to
@@ -362,15 +362,15 @@
         // when a device is disconnected, checks if an output is not used any more and
         // returns its handle if any.
         // transfers the audio tracks and effects from one output thread to another accordingly.
-        status_t checkOutputsForDevice(const sp<DeviceDescriptor> devDesc,
+        status_t checkOutputsForDevice(const sp<DeviceDescriptor>& devDesc,
                                        audio_policy_dev_state_t state,
                                        SortedVector<audio_io_handle_t>& outputs,
-                                       const String8 address);
+                                       const String8& address);
 
-        status_t checkInputsForDevice(const sp<DeviceDescriptor> devDesc,
+        status_t checkInputsForDevice(const sp<DeviceDescriptor>& devDesc,
                                       audio_policy_dev_state_t state,
                                       SortedVector<audio_io_handle_t>& inputs,
-                                      const String8 address);
+                                      const String8& address);
 
         // close an output and its companion duplicating output.
         void closeOutput(audio_io_handle_t output);
@@ -423,7 +423,7 @@
 #endif //AUDIO_POLICY_TEST
 
         SortedVector<audio_io_handle_t> getOutputsForDevice(audio_devices_t device,
-                                                            SwAudioOutputCollection openOutputs);
+                                                            const SwAudioOutputCollection& openOutputs);
         bool vectorsEqual(SortedVector<audio_io_handle_t>& outputs1,
                                            SortedVector<audio_io_handle_t>& outputs2);
 
@@ -431,7 +431,7 @@
         // if muting, wait for the audio in pcm buffer to be drained before proceeding
         // if unmuting, unmute only after the specified delay
         // Returns the number of ms waited
-        virtual uint32_t  checkDeviceMuteStrategies(sp<AudioOutputDescriptor> outputDesc,
+        virtual uint32_t  checkDeviceMuteStrategies(const sp<AudioOutputDescriptor>& outputDesc,
                                             audio_devices_t prevDevice,
                                             uint32_t delayMs);
 
@@ -440,7 +440,7 @@
                                        audio_format_t format);
         // samplingRate, format, channelMask are in/out and so may be modified
         sp<IOProfile> getInputProfile(audio_devices_t device,
-                                      String8 address,
+                                      const String8& address,
                                       uint32_t& samplingRate,
                                       audio_format_t& format,
                                       audio_channel_mask_t& channelMask,
@@ -481,12 +481,12 @@
 
         // if argument "device" is different from AUDIO_DEVICE_NONE,  startSource() will force
         // the re-evaluation of the output device.
-        status_t startSource(sp<AudioOutputDescriptor> outputDesc,
+        status_t startSource(const sp<AudioOutputDescriptor>& outputDesc,
                              audio_stream_type_t stream,
                              audio_devices_t device,
                              const char *address,
                              uint32_t *delayMs);
-        status_t stopSource(sp<AudioOutputDescriptor> outputDesc,
+        status_t stopSource(const sp<AudioOutputDescriptor>& outputDesc,
                             audio_stream_type_t stream,
                             bool forceDeviceUpdate);
 
@@ -594,6 +594,15 @@
         void updateAudioProfiles(audio_devices_t device, audio_io_handle_t ioHandle,
                 AudioProfileVector &profiles);
 
+        // Notify the policy client of any change of device state with AUDIO_IO_HANDLE_NONE,
+        // so that the client interprets it as global to audio hardware interfaces.
+        // It can give a chance to HAL implementer to retrieve dynamic capabilities associated
+        // to this device for example.
+        // TODO avoid opening stream to retrieve capabilities of a profile.
+        void broadcastDeviceConnectionState(audio_devices_t device,
+                                            audio_policy_dev_state_t state,
+                                            const String8 &device_address);
+
         // updates device caching and output for streams that can influence the
         //    routing of notifications
         void handleNotificationRoutingForStream(audio_stream_type_t stream);
@@ -602,9 +611,9 @@
         //   in mProfile->mSupportedDevices) matches the device whose address is to be matched.
         // see deviceDistinguishesOnAddress(audio_devices_t) for whether the device type is one
         //   where addresses are used to distinguish between one connected device and another.
-        void findIoHandlesByAddress(sp<SwAudioOutputDescriptor> desc /*in*/,
+        void findIoHandlesByAddress(const sp<SwAudioOutputDescriptor>& desc /*in*/,
                 const audio_devices_t device /*in*/,
-                const String8 address /*in*/,
+                const String8& address /*in*/,
                 SortedVector<audio_io_handle_t>& outputs /*out*/);
         uint32_t curAudioPortGeneration() const { return mAudioPortGeneration; }
         // internal method to return the output handle for the given device and format
diff --git a/services/audiopolicy/service/AudioPolicyClientImplLegacy.cpp b/services/audiopolicy/service/AudioPolicyClientImplLegacy.cpp
index 151d066..dabffe6 100644
--- a/services/audiopolicy/service/AudioPolicyClientImplLegacy.cpp
+++ b/services/audiopolicy/service/AudioPolicyClientImplLegacy.cpp
@@ -56,7 +56,7 @@
     sp<IAudioFlinger> af = AudioSystem::get_audio_flinger();
     if (af == 0) {
         ALOGW("%s: could not get AudioFlinger", __func__);
-        return 0;
+        return AUDIO_MODULE_HANDLE_NONE;
     }
 
     return af->loadHwModule(name);
diff --git a/services/audiopolicy/service/AudioPolicyEffects.h b/services/audiopolicy/service/AudioPolicyEffects.h
index ee9bd50..afdaf98 100644
--- a/services/audiopolicy/service/AudioPolicyEffects.h
+++ b/services/audiopolicy/service/AudioPolicyEffects.h
@@ -135,7 +135,7 @@
     // class to store voctor of AudioEffects
     class EffectVector {
     public:
-        EffectVector(audio_session_t session) : mSessionId(session), mRefCount(0) {}
+        explicit EffectVector(audio_session_t session) : mSessionId(session), mRefCount(0) {}
         /*virtual*/ ~EffectVector() {}
 
         // Enable or disable all effects in effect vector
diff --git a/services/audiopolicy/service/AudioPolicyInterfaceImpl.cpp b/services/audiopolicy/service/AudioPolicyInterfaceImpl.cpp
index c9b3abc..451ce84 100644
--- a/services/audiopolicy/service/AudioPolicyInterfaceImpl.cpp
+++ b/services/audiopolicy/service/AudioPolicyInterfaceImpl.cpp
@@ -678,7 +678,7 @@
     return mAudioPolicyManager->releaseSoundTriggerSession(session);
 }
 
-status_t AudioPolicyService::registerPolicyMixes(Vector<AudioMix> mixes, bool registration)
+status_t AudioPolicyService::registerPolicyMixes(const Vector<AudioMix>& mixes, bool registration)
 {
     Mutex::Autolock _l(mLock);
     if(!modifyAudioRoutingAllowed()) {
diff --git a/services/audiopolicy/service/AudioPolicyInterfaceImplLegacy.cpp b/services/audiopolicy/service/AudioPolicyInterfaceImplLegacy.cpp
index 7c9315d..946c380 100644
--- a/services/audiopolicy/service/AudioPolicyInterfaceImplLegacy.cpp
+++ b/services/audiopolicy/service/AudioPolicyInterfaceImplLegacy.cpp
@@ -602,7 +602,7 @@
     return INVALID_OPERATION;
 }
 
-status_t AudioPolicyService::registerPolicyMixes(Vector<AudioMix> mixes __unused,
+status_t AudioPolicyService::registerPolicyMixes(const Vector<AudioMix>& mixes __unused,
                                                  bool registration __unused)
 {
     return INVALID_OPERATION;
diff --git a/services/audiopolicy/service/AudioPolicyService.cpp b/services/audiopolicy/service/AudioPolicyService.cpp
index d24e9a0..52ed73e 100644
--- a/services/audiopolicy/service/AudioPolicyService.cpp
+++ b/services/audiopolicy/service/AudioPolicyService.cpp
@@ -221,14 +221,14 @@
     }
 }
 
-void AudioPolicyService::onDynamicPolicyMixStateUpdate(String8 regId, int32_t state)
+void AudioPolicyService::onDynamicPolicyMixStateUpdate(const String8& regId, int32_t state)
 {
     ALOGV("AudioPolicyService::onDynamicPolicyMixStateUpdate(%s, %d)",
             regId.string(), state);
     mOutputCommandThread->dynamicPolicyMixStateUpdateCommand(regId, state);
 }
 
-void AudioPolicyService::doOnDynamicPolicyMixStateUpdate(String8 regId, int32_t state)
+void AudioPolicyService::doOnDynamicPolicyMixStateUpdate(const String8& regId, int32_t state)
 {
     Mutex::Autolock _l(mNotificationClientsLock);
     for (size_t i = 0; i < mNotificationClients.size(); i++) {
@@ -310,7 +310,7 @@
 }
 
 void AudioPolicyService::NotificationClient::onDynamicPolicyMixStateUpdate(
-        String8 regId, int32_t state)
+        const String8& regId, int32_t state)
 {
     if (mAudioPolicyServiceClient != 0) {
         mAudioPolicyServiceClient->onDynamicPolicyMixStateUpdate(regId, state);
@@ -857,7 +857,7 @@
 }
 
 void AudioPolicyService::AudioCommandThread::dynamicPolicyMixStateUpdateCommand(
-        String8 regId, int32_t state)
+        const String8& regId, int32_t state)
 {
     sp<AudioCommand> command = new AudioCommand();
     command->mCommand = DYN_POLICY_MIX_STATE_UPDATE;
diff --git a/services/audiopolicy/service/AudioPolicyService.h b/services/audiopolicy/service/AudioPolicyService.h
index 0b2cb35..def6405 100644
--- a/services/audiopolicy/service/AudioPolicyService.h
+++ b/services/audiopolicy/service/AudioPolicyService.h
@@ -196,7 +196,7 @@
 
     virtual audio_mode_t getPhoneState();
 
-    virtual status_t registerPolicyMixes(Vector<AudioMix> mixes, bool registration);
+    virtual status_t registerPolicyMixes(const Vector<AudioMix>& mixes, bool registration);
 
     virtual status_t startAudioSource(const struct audio_port_config *source,
                                       const audio_attributes_t *attributes,
@@ -227,8 +227,8 @@
             void onAudioPatchListUpdate();
             void doOnAudioPatchListUpdate();
 
-            void onDynamicPolicyMixStateUpdate(String8 regId, int32_t state);
-            void doOnDynamicPolicyMixStateUpdate(String8 regId, int32_t state);
+            void onDynamicPolicyMixStateUpdate(const String8& regId, int32_t state);
+            void doOnDynamicPolicyMixStateUpdate(const String8& regId, int32_t state);
             void onRecordingConfigurationUpdate(int event, audio_session_t session,
                     audio_source_t source, const audio_config_base_t *clientConfig,
                     const audio_config_base_t *deviceConfig, audio_patch_handle_t patchHandle);
@@ -305,7 +305,7 @@
                     void        updateAudioPatchListCommand();
                     status_t    setAudioPortConfigCommand(const struct audio_port_config *config,
                                                           int delayMs);
-                    void        dynamicPolicyMixStateUpdateCommand(String8 regId, int32_t state);
+                    void        dynamicPolicyMixStateUpdateCommand(const String8& regId, int32_t state);
                     void        recordingConfigurationUpdateCommand(
                                                         int event, audio_session_t session,
                                                         audio_source_t source,
@@ -424,7 +424,7 @@
     class AudioPolicyClient : public AudioPolicyClientInterface
     {
      public:
-        AudioPolicyClient(AudioPolicyService *service) : mAudioPolicyService(service) {}
+        explicit AudioPolicyClient(AudioPolicyService *service) : mAudioPolicyService(service) {}
         virtual ~AudioPolicyClient() {}
 
         //
@@ -539,7 +539,7 @@
 
                             void      onAudioPortListUpdate();
                             void      onAudioPatchListUpdate();
-                            void      onDynamicPolicyMixStateUpdate(String8 regId, int32_t state);
+                            void      onDynamicPolicyMixStateUpdate(const String8& regId, int32_t state);
                             void      onRecordingConfigurationUpdate(
                                         int event, audio_session_t session,
                                         audio_source_t source,
diff --git a/services/camera/libcameraservice/Android.mk b/services/camera/libcameraservice/Android.mk
index 8d7f71c..89a1bb6 100644
--- a/services/camera/libcameraservice/Android.mk
+++ b/services/camera/libcameraservice/Android.mk
@@ -70,6 +70,8 @@
     libjpeg \
     libmemunreachable
 
+LOCAL_EXPORT_SHARED_LIBRARY_HEADERS := libbinder
+
 LOCAL_C_INCLUDES += \
     system/media/private/camera/include \
     frameworks/native/include/media/openmax \
diff --git a/services/camera/libcameraservice/CameraFlashlight.cpp b/services/camera/libcameraservice/CameraFlashlight.cpp
index ad08a68..6314ba5 100644
--- a/services/camera/libcameraservice/CameraFlashlight.cpp
+++ b/services/camera/libcameraservice/CameraFlashlight.cpp
@@ -812,7 +812,7 @@
 }
 
 status_t CameraHardwareInterfaceFlashControl::initializePreviewWindow(
-        sp<CameraHardwareInterface> device, int32_t width, int32_t height) {
+        const sp<CameraHardwareInterface>& device, int32_t width, int32_t height) {
     status_t res;
     BufferQueue::createBufferQueue(&mProducer, &mConsumer);
 
diff --git a/services/camera/libcameraservice/CameraFlashlight.h b/services/camera/libcameraservice/CameraFlashlight.h
index 5cde372..59fc87d 100644
--- a/services/camera/libcameraservice/CameraFlashlight.h
+++ b/services/camera/libcameraservice/CameraFlashlight.h
@@ -193,7 +193,7 @@
         status_t disconnectCameraDevice();
 
         // initialize the preview window
-        status_t initializePreviewWindow(sp<CameraHardwareInterface> device,
+        status_t initializePreviewWindow(const sp<CameraHardwareInterface>& device,
                 int32_t width, int32_t height);
 
         // start preview and enable torch
diff --git a/services/camera/libcameraservice/CameraService.cpp b/services/camera/libcameraservice/CameraService.cpp
index d0df6d1..dd9029e 100644
--- a/services/camera/libcameraservice/CameraService.cpp
+++ b/services/camera/libcameraservice/CameraService.cpp
@@ -31,6 +31,7 @@
 #include <android/hardware/ICamera.h>
 #include <android/hardware/ICameraClient.h>
 
+#include <android-base/macros.h>
 #include <binder/AppOpsManager.h>
 #include <binder/IPCThreadState.h>
 #include <binder/IServiceManager.h>
@@ -103,7 +104,7 @@
     sp<CameraService> cs = const_cast<CameraService*>(
             static_cast<const CameraService*>(callbacks));
 
-    cs->onDeviceStatusChanged(static_cast<camera_device_status_t>(camera_id),
+    cs->onDeviceStatusChanged(camera_id,
             static_cast<camera_device_status_t>(new_status));
 }
 
@@ -272,12 +273,14 @@
 }
 
 sp<ICameraServiceProxy> CameraService::getCameraServiceProxy() {
+    sp<ICameraServiceProxy> proxyBinder = nullptr;
+#ifndef __BRILLO__
     sp<IServiceManager> sm = defaultServiceManager();
     sp<IBinder> binder = sm->getService(String16("media.camera.proxy"));
-    if (binder == nullptr) {
-        return nullptr;
+    if (binder != nullptr) {
+        proxyBinder = interface_cast<ICameraServiceProxy>(binder);
     }
-    sp<ICameraServiceProxy> proxyBinder = interface_cast<ICameraServiceProxy>(binder);
+#endif
     return proxyBinder;
 }
 
@@ -296,7 +299,7 @@
     gCameraService = nullptr;
 }
 
-void CameraService::onDeviceStatusChanged(camera_device_status_t  cameraId,
+void CameraService::onDeviceStatusChanged(int  cameraId,
         camera_device_status_t newStatus) {
     ALOGI("%s: Status changed for cameraId=%d, newStatus=%d", __FUNCTION__,
           cameraId, newStatus);
@@ -924,6 +927,53 @@
         const String8& clientName8, /*inout*/int& clientUid, /*inout*/int& clientPid,
         /*out*/int& originalClientPid) const {
 
+#ifdef __BRILLO__
+    UNUSED(clientName8);
+    UNUSED(clientUid);
+    UNUSED(clientPid);
+    UNUSED(originalClientPid);
+#else
+    Status allowed = validateClientPermissionsLocked(cameraId, clientName8, clientUid, clientPid,
+            originalClientPid);
+    if (!allowed.isOk()) {
+        return allowed;
+    }
+#endif  // __BRILLO__
+
+    int callingPid = getCallingPid();
+
+    if (!mModule) {
+        ALOGE("CameraService::connect X (PID %d) rejected (camera HAL module not loaded)",
+                callingPid);
+        return STATUS_ERROR_FMT(ERROR_DISCONNECTED,
+                "No camera HAL module available to open camera device \"%s\"", cameraId.string());
+    }
+
+    if (getCameraState(cameraId) == nullptr) {
+        ALOGE("CameraService::connect X (PID %d) rejected (invalid camera ID %s)", callingPid,
+                cameraId.string());
+        return STATUS_ERROR_FMT(ERROR_DISCONNECTED,
+                "No camera device with ID \"%s\" available", cameraId.string());
+    }
+
+    status_t err = checkIfDeviceIsUsable(cameraId);
+    if (err != NO_ERROR) {
+        switch(err) {
+            case -ENODEV:
+            case -EBUSY:
+                return STATUS_ERROR_FMT(ERROR_DISCONNECTED,
+                        "No camera device with ID \"%s\" currently available", cameraId.string());
+            default:
+                return STATUS_ERROR_FMT(ERROR_INVALID_OPERATION,
+                        "Unknown error connecting to ID \"%s\"", cameraId.string());
+        }
+    }
+    return Status::ok();
+}
+
+Status CameraService::validateClientPermissionsLocked(const String8& cameraId,
+        const String8& clientName8, int& clientUid, int& clientPid,
+        /*out*/int& originalClientPid) const {
     int callingPid = getCallingPid();
     int callingUid = getCallingUid();
 
@@ -967,20 +1017,6 @@
     originalClientPid = clientPid;
     clientPid = callingPid;
 
-    if (!mModule) {
-        ALOGE("CameraService::connect X (PID %d) rejected (camera HAL module not loaded)",
-                callingPid);
-        return STATUS_ERROR_FMT(ERROR_DISCONNECTED,
-                "No camera HAL module available to open camera device \"%s\"", cameraId.string());
-    }
-
-    if (getCameraState(cameraId) == nullptr) {
-        ALOGE("CameraService::connect X (PID %d) rejected (invalid camera ID %s)", callingPid,
-                cameraId.string());
-        return STATUS_ERROR_FMT(ERROR_DISCONNECTED,
-                "No camera device with ID \"%s\" available", cameraId.string());
-    }
-
     userid_t clientUserId = multiuser_get_user_id(clientUid);
 
     // Only allow clients who are being used by the current foreground device user, unless calling
@@ -994,18 +1030,6 @@
                 clientUserId, cameraId.string());
     }
 
-    status_t err = checkIfDeviceIsUsable(cameraId);
-    if (err != NO_ERROR) {
-        switch(err) {
-            case -ENODEV:
-            case -EBUSY:
-                return STATUS_ERROR_FMT(ERROR_DISCONNECTED,
-                        "No camera device with ID \"%s\" currently available", cameraId.string());
-            default:
-                return STATUS_ERROR_FMT(ERROR_INVALID_OPERATION,
-                        "Unknown error connecting to ID \"%s\"", cameraId.string());
-        }
-    }
     return Status::ok();
 }
 
@@ -2348,7 +2372,7 @@
 void CameraService::ClientEventListener::onClientAdded(
         const resource_policy::ClientDescriptor<String8,
         sp<CameraService::BasicClient>>& descriptor) {
-    auto basicClient = descriptor.getValue();
+    const auto& basicClient = descriptor.getValue();
     if (basicClient.get() != nullptr) {
         BatteryNotifier& notifier(BatteryNotifier::getInstance());
         notifier.noteStartCamera(descriptor.getKey(),
@@ -2359,7 +2383,7 @@
 void CameraService::ClientEventListener::onClientRemoved(
         const resource_policy::ClientDescriptor<String8,
         sp<CameraService::BasicClient>>& descriptor) {
-    auto basicClient = descriptor.getValue();
+    const auto& basicClient = descriptor.getValue();
     if (basicClient.get() != nullptr) {
         BatteryNotifier& notifier(BatteryNotifier::getInstance());
         notifier.noteStopCamera(descriptor.getKey(),
diff --git a/services/camera/libcameraservice/CameraService.h b/services/camera/libcameraservice/CameraService.h
index 11b1351..b35f35c 100644
--- a/services/camera/libcameraservice/CameraService.h
+++ b/services/camera/libcameraservice/CameraService.h
@@ -95,7 +95,7 @@
 
     /////////////////////////////////////////////////////////////////////
     // HAL Callbacks
-    virtual void        onDeviceStatusChanged(camera_device_status_t cameraId,
+    virtual void        onDeviceStatusChanged(int cameraId,
                                               camera_device_status_t newStatus);
     virtual void        onTorchStatusChanged(const String8& cameraId,
                                              int32_t newStatus);
@@ -265,7 +265,7 @@
 
         class OpsCallback : public BnAppOpsCallback {
         public:
-            OpsCallback(wp<BasicClient> client);
+            explicit OpsCallback(wp<BasicClient> client);
             virtual void opChanged(int32_t op, const String16& packageName);
 
         private:
@@ -495,7 +495,9 @@
     // mediaserver to connect to camera (using MediaRecorder to connect to camera). In that case,
     // clientPid is the PID of mediaserver and originalClientPid is the PID of the application.
     binder::Status validateConnectLocked(const String8& cameraId, const String8& clientName8,
-          /*inout*/int& clientUid, /*inout*/int& clientPid, /*out*/int& originalClientPid) const;
+            /*inout*/int& clientUid, /*inout*/int& clientPid, /*out*/int& originalClientPid) const;
+    binder::Status validateClientPermissionsLocked(const String8& cameraId, const String8& clientName8,
+            /*inout*/int& clientUid, /*inout*/int& clientPid, /*out*/int& originalClientPid) const;
 
     // Handle active client evictions, and update service state.
     // Only call with with mServiceLock held.
diff --git a/services/camera/libcameraservice/api1/Camera2Client.cpp b/services/camera/libcameraservice/api1/Camera2Client.cpp
index 005dd69..bcd62d6 100644
--- a/services/camera/libcameraservice/api1/Camera2Client.cpp
+++ b/services/camera/libcameraservice/api1/Camera2Client.cpp
@@ -526,7 +526,7 @@
 }
 
 status_t Camera2Client::setPreviewWindowL(const sp<IBinder>& binder,
-        sp<Surface> window) {
+        const sp<Surface>& window) {
     ATRACE_CALL();
     status_t res;
 
@@ -1903,12 +1903,12 @@
 }
 
 status_t Camera2Client::registerFrameListener(int32_t minId, int32_t maxId,
-        wp<camera2::FrameProcessor::FilteredListener> listener, bool sendPartials) {
+        const wp<camera2::FrameProcessor::FilteredListener>& listener, bool sendPartials) {
     return mFrameProcessor->registerListener(minId, maxId, listener, sendPartials);
 }
 
 status_t Camera2Client::removeFrameListener(int32_t minId, int32_t maxId,
-        wp<camera2::FrameProcessor::FilteredListener> listener) {
+        const wp<camera2::FrameProcessor::FilteredListener>& listener) {
     return mFrameProcessor->removeListener(minId, maxId, listener);
 }
 
diff --git a/services/camera/libcameraservice/api1/Camera2Client.h b/services/camera/libcameraservice/api1/Camera2Client.h
index 3cb9e4f..e2129f5 100644
--- a/services/camera/libcameraservice/api1/Camera2Client.h
+++ b/services/camera/libcameraservice/api1/Camera2Client.h
@@ -126,10 +126,10 @@
     int getZslStreamId() const;
 
     status_t registerFrameListener(int32_t minId, int32_t maxId,
-            wp<camera2::FrameProcessor::FilteredListener> listener,
+            const wp<camera2::FrameProcessor::FilteredListener>& listener,
             bool sendPartials = true);
     status_t removeFrameListener(int32_t minId, int32_t maxId,
-            wp<camera2::FrameProcessor::FilteredListener> listener);
+            const wp<camera2::FrameProcessor::FilteredListener>& listener);
 
     status_t stopStream();
 
@@ -160,7 +160,7 @@
     typedef camera2::Parameters Parameters;
 
     status_t setPreviewWindowL(const sp<IBinder>& binder,
-            sp<Surface> window);
+            const sp<Surface>& window);
     status_t startPreviewL(Parameters &params, bool restart);
     void     stopPreviewL();
     status_t startRecordingL(Parameters &params, bool restart);
diff --git a/services/camera/libcameraservice/api1/client2/CallbackProcessor.cpp b/services/camera/libcameraservice/api1/client2/CallbackProcessor.cpp
index b4b269a..3f4017f 100644
--- a/services/camera/libcameraservice/api1/client2/CallbackProcessor.cpp
+++ b/services/camera/libcameraservice/api1/client2/CallbackProcessor.cpp
@@ -55,7 +55,7 @@
 }
 
 status_t CallbackProcessor::setCallbackWindow(
-        sp<Surface> callbackWindow) {
+        const sp<Surface>& callbackWindow) {
     ATRACE_CALL();
     status_t res;
 
diff --git a/services/camera/libcameraservice/api1/client2/CallbackProcessor.h b/services/camera/libcameraservice/api1/client2/CallbackProcessor.h
index a22442f..5231688 100644
--- a/services/camera/libcameraservice/api1/client2/CallbackProcessor.h
+++ b/services/camera/libcameraservice/api1/client2/CallbackProcessor.h
@@ -41,13 +41,13 @@
 class CallbackProcessor:
             public Thread, public CpuConsumer::FrameAvailableListener {
   public:
-    CallbackProcessor(sp<Camera2Client> client);
+    explicit CallbackProcessor(sp<Camera2Client> client);
     ~CallbackProcessor();
 
     void onFrameAvailable(const BufferItem& item);
 
     // Set to NULL to disable the direct-to-app callback window
-    status_t setCallbackWindow(sp<Surface> callbackWindow);
+    status_t setCallbackWindow(const sp<Surface>& callbackWindow);
     status_t updateStream(const Parameters &params);
     status_t deleteStream();
     int getStreamId() const;
diff --git a/services/camera/libcameraservice/api1/client2/Camera2Heap.h b/services/camera/libcameraservice/api1/client2/Camera2Heap.h
index 9c72d76..fe3afcb 100644
--- a/services/camera/libcameraservice/api1/client2/Camera2Heap.h
+++ b/services/camera/libcameraservice/api1/client2/Camera2Heap.h
@@ -26,7 +26,7 @@
 // Utility class for managing a set of IMemory blocks
 class Camera2Heap : public RefBase {
   public:
-    Camera2Heap(size_t buf_size, uint_t num_buffers = 1,
+    explicit Camera2Heap(size_t buf_size, uint_t num_buffers = 1,
             const char *name = NULL) :
             mBufSize(buf_size),
             mNumBufs(num_buffers) {
diff --git a/services/camera/libcameraservice/api1/client2/CaptureSequencer.cpp b/services/camera/libcameraservice/api1/client2/CaptureSequencer.cpp
index 05adb29..b65f1c7 100644
--- a/services/camera/libcameraservice/api1/client2/CaptureSequencer.cpp
+++ b/services/camera/libcameraservice/api1/client2/CaptureSequencer.cpp
@@ -59,7 +59,7 @@
     ALOGV("%s: Exit", __FUNCTION__);
 }
 
-void CaptureSequencer::setZslProcessor(wp<ZslProcessor> processor) {
+void CaptureSequencer::setZslProcessor(const wp<ZslProcessor>& processor) {
     Mutex::Autolock l(mInputMutex);
     mZslProcessor = processor;
 }
@@ -132,7 +132,7 @@
 }
 
 void CaptureSequencer::onCaptureAvailable(nsecs_t timestamp,
-        sp<MemoryBase> captureBuffer, bool captureError) {
+        const sp<MemoryBase>& captureBuffer, bool captureError) {
     ATRACE_CALL();
     ALOGV("%s", __FUNCTION__);
     Mutex::Autolock l(mInputMutex);
@@ -709,7 +709,7 @@
 }
 
 /*static*/ void CaptureSequencer::shutterNotifyLocked(const Parameters &params,
-            sp<Camera2Client> client, int msgType) {
+            const sp<Camera2Client>& client, int msgType) {
     ATRACE_CALL();
 
     if (params.state == Parameters::STILL_CAPTURE
diff --git a/services/camera/libcameraservice/api1/client2/CaptureSequencer.h b/services/camera/libcameraservice/api1/client2/CaptureSequencer.h
index a7c61d2..f2e3750 100644
--- a/services/camera/libcameraservice/api1/client2/CaptureSequencer.h
+++ b/services/camera/libcameraservice/api1/client2/CaptureSequencer.h
@@ -44,11 +44,11 @@
             virtual public Thread,
             virtual public FrameProcessor::FilteredListener {
   public:
-    CaptureSequencer(wp<Camera2Client> client);
+    explicit CaptureSequencer(wp<Camera2Client> client);
     ~CaptureSequencer();
 
     // Get reference to the ZslProcessor, which holds the ZSL buffers and frames
-    void setZslProcessor(wp<ZslProcessor> processor);
+    void setZslProcessor(const wp<ZslProcessor>& processor);
 
     // Begin still image capture
     status_t startCapture(int msgType);
@@ -69,7 +69,7 @@
     virtual void onResultAvailable(const CaptureResult &result);
 
     // Notifications from the JPEG processor
-    void onCaptureAvailable(nsecs_t timestamp, sp<MemoryBase> captureBuffer, bool captureError);
+    void onCaptureAvailable(nsecs_t timestamp, const sp<MemoryBase>& captureBuffer, bool captureError);
 
     void dump(int fd, const Vector<String16>& args);
 
@@ -172,7 +172,7 @@
 
     // Emit Shutter/Raw callback to java, and maybe play a shutter sound
     static void shutterNotifyLocked(const Parameters &params,
-            sp<Camera2Client> client, int msgType);
+            const sp<Camera2Client>& client, int msgType);
 };
 
 }; // namespace camera2
diff --git a/services/camera/libcameraservice/api1/client2/FrameProcessor.cpp b/services/camera/libcameraservice/api1/client2/FrameProcessor.cpp
index 4d12015..394eb4c 100644
--- a/services/camera/libcameraservice/api1/client2/FrameProcessor.cpp
+++ b/services/camera/libcameraservice/api1/client2/FrameProcessor.cpp
@@ -389,7 +389,7 @@
 }
 
 
-void FrameProcessor::callbackFaceDetection(sp<Camera2Client> client,
+void FrameProcessor::callbackFaceDetection(const sp<Camera2Client>& client,
                                      const camera_frame_metadata &metadata) {
 
     camera_frame_metadata *metadata_ptr =
diff --git a/services/camera/libcameraservice/api1/client2/FrameProcessor.h b/services/camera/libcameraservice/api1/client2/FrameProcessor.h
index a5b81a7..62a4e91 100644
--- a/services/camera/libcameraservice/api1/client2/FrameProcessor.h
+++ b/services/camera/libcameraservice/api1/client2/FrameProcessor.h
@@ -107,7 +107,7 @@
     int32_t mLast3AFrameNumber;
 
     // Emit FaceDetection event to java if faces changed
-    void callbackFaceDetection(sp<Camera2Client> client,
+    void callbackFaceDetection(const sp<Camera2Client>& client,
                                const camera_frame_metadata &metadata);
 };
 
diff --git a/services/camera/libcameraservice/api1/client2/JpegCompressor.cpp b/services/camera/libcameraservice/api1/client2/JpegCompressor.cpp
index 9ecab71..01951a0 100644
--- a/services/camera/libcameraservice/api1/client2/JpegCompressor.cpp
+++ b/services/camera/libcameraservice/api1/client2/JpegCompressor.cpp
@@ -36,7 +36,7 @@
     Mutex::Autolock lock(mMutex);
 }
 
-status_t JpegCompressor::start(Vector<CpuConsumer::LockedBuffer*> buffers,
+status_t JpegCompressor::start(const Vector<CpuConsumer::LockedBuffer*>& buffers,
         nsecs_t captureTime) {
     ALOGV("%s", __FUNCTION__);
     Mutex::Autolock busyLock(mBusyMutex);
diff --git a/services/camera/libcameraservice/api1/client2/JpegCompressor.h b/services/camera/libcameraservice/api1/client2/JpegCompressor.h
index df5da54..589a2fd 100644
--- a/services/camera/libcameraservice/api1/client2/JpegCompressor.h
+++ b/services/camera/libcameraservice/api1/client2/JpegCompressor.h
@@ -48,7 +48,7 @@
 
     // Start compressing COMPRESSED format buffers; JpegCompressor takes
     // ownership of the Buffers vector.
-    status_t start(Vector<CpuConsumer::LockedBuffer*> buffers,
+    status_t start(const Vector<CpuConsumer::LockedBuffer*>& buffers,
             nsecs_t captureTime);
 
     status_t cancel();
diff --git a/services/camera/libcameraservice/api1/client2/Parameters.h b/services/camera/libcameraservice/api1/client2/Parameters.h
index f4bb34c..798aab5 100644
--- a/services/camera/libcameraservice/api1/client2/Parameters.h
+++ b/services/camera/libcameraservice/api1/client2/Parameters.h
@@ -412,7 +412,7 @@
     template<typename S, typename P>
     class BaseLock {
       public:
-        BaseLock(S &p):
+        explicit BaseLock(S &p):
                 mParameters(p.mParameters),
                 mSharedParameters(p) {
             mSharedParameters.mLock.lock();
diff --git a/services/camera/libcameraservice/api1/client2/StreamingProcessor.cpp b/services/camera/libcameraservice/api1/client2/StreamingProcessor.cpp
index de42fb2..bf92a2b 100644
--- a/services/camera/libcameraservice/api1/client2/StreamingProcessor.cpp
+++ b/services/camera/libcameraservice/api1/client2/StreamingProcessor.cpp
@@ -58,7 +58,7 @@
     deleteRecordingStream();
 }
 
-status_t StreamingProcessor::setPreviewWindow(sp<Surface> window) {
+status_t StreamingProcessor::setPreviewWindow(const sp<Surface>& window) {
     ATRACE_CALL();
     status_t res;
 
@@ -72,7 +72,7 @@
     return OK;
 }
 
-status_t StreamingProcessor::setRecordingWindow(sp<Surface> window) {
+status_t StreamingProcessor::setRecordingWindow(const sp<Surface>& window) {
     ATRACE_CALL();
     status_t res;
 
diff --git a/services/camera/libcameraservice/api1/client2/StreamingProcessor.h b/services/camera/libcameraservice/api1/client2/StreamingProcessor.h
index 57e6389..22231d5 100644
--- a/services/camera/libcameraservice/api1/client2/StreamingProcessor.h
+++ b/services/camera/libcameraservice/api1/client2/StreamingProcessor.h
@@ -39,11 +39,11 @@
  */
 class StreamingProcessor : public virtual VirtualLightRefBase {
   public:
-    StreamingProcessor(sp<Camera2Client> client);
+    explicit StreamingProcessor(sp<Camera2Client> client);
     ~StreamingProcessor();
 
-    status_t setPreviewWindow(sp<Surface> window);
-    status_t setRecordingWindow(sp<Surface> window);
+    status_t setPreviewWindow(const sp<Surface>& window);
+    status_t setRecordingWindow(const sp<Surface>& window);
 
     bool haveValidPreviewWindow() const;
     bool haveValidRecordingWindow() const;
diff --git a/services/camera/libcameraservice/api2/CameraDeviceClient.cpp b/services/camera/libcameraservice/api2/CameraDeviceClient.cpp
index a7fe5e7..b4f8e21 100644
--- a/services/camera/libcameraservice/api2/CameraDeviceClient.cpp
+++ b/services/camera/libcameraservice/api2/CameraDeviceClient.cpp
@@ -530,7 +530,8 @@
     }
 
     // Round dimensions to the nearest dimensions available for this format
-    if (flexibleConsumer && !CameraDeviceClient::roundBufferDimensionNearest(width, height,
+    if (flexibleConsumer && isPublicFormat(format) &&
+            !CameraDeviceClient::roundBufferDimensionNearest(width, height,
             format, dataSpace, mDevice->info(), /*out*/&width, /*out*/&height)) {
         String8 msg = String8::format("Camera %d: No supported stream configurations with "
                 "format %#x defined, failed to create output stream", mCameraId, format);
@@ -714,6 +715,37 @@
     return res;
 }
 
+bool CameraDeviceClient::isPublicFormat(int32_t format)
+{
+    switch(format) {
+        case HAL_PIXEL_FORMAT_RGBA_8888:
+        case HAL_PIXEL_FORMAT_RGBX_8888:
+        case HAL_PIXEL_FORMAT_RGB_888:
+        case HAL_PIXEL_FORMAT_RGB_565:
+        case HAL_PIXEL_FORMAT_BGRA_8888:
+        case HAL_PIXEL_FORMAT_YV12:
+        case HAL_PIXEL_FORMAT_Y8:
+        case HAL_PIXEL_FORMAT_Y16:
+        case HAL_PIXEL_FORMAT_RAW16:
+        case HAL_PIXEL_FORMAT_RAW10:
+        case HAL_PIXEL_FORMAT_RAW12:
+        case HAL_PIXEL_FORMAT_RAW_OPAQUE:
+        case HAL_PIXEL_FORMAT_BLOB:
+        case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED:
+        case HAL_PIXEL_FORMAT_YCbCr_420_888:
+        case HAL_PIXEL_FORMAT_YCbCr_422_888:
+        case HAL_PIXEL_FORMAT_YCbCr_444_888:
+        case HAL_PIXEL_FORMAT_FLEX_RGB_888:
+        case HAL_PIXEL_FORMAT_FLEX_RGBA_8888:
+        case HAL_PIXEL_FORMAT_YCbCr_422_SP:
+        case HAL_PIXEL_FORMAT_YCrCb_420_SP:
+        case HAL_PIXEL_FORMAT_YCbCr_422_I:
+            return true;
+        default:
+            return false;
+    }
+}
+
 bool CameraDeviceClient::roundBufferDimensionNearest(int32_t width, int32_t height,
         int32_t format, android_dataspace dataSpace, const CameraMetadata& info,
         /*out*/int32_t* outWidth, /*out*/int32_t* outHeight) {
diff --git a/services/camera/libcameraservice/api2/CameraDeviceClient.h b/services/camera/libcameraservice/api2/CameraDeviceClient.h
index dde23fb..de283ea 100644
--- a/services/camera/libcameraservice/api2/CameraDeviceClient.h
+++ b/services/camera/libcameraservice/api2/CameraDeviceClient.h
@@ -208,6 +208,9 @@
             android_dataspace dataSpace, const CameraMetadata& info,
             /*out*/int32_t* outWidth, /*out*/int32_t* outHeight);
 
+    //check if format is not custom format
+    static bool isPublicFormat(int32_t format);
+
     // IGraphicsBufferProducer binder -> Stream ID for output streams
     KeyedVector<sp<IBinder>, int> mStreamMap;
 
diff --git a/services/camera/libcameraservice/common/Camera2ClientBase.h b/services/camera/libcameraservice/common/Camera2ClientBase.h
index 4f60034..dbbf638 100644
--- a/services/camera/libcameraservice/common/Camera2ClientBase.h
+++ b/services/camera/libcameraservice/common/Camera2ClientBase.h
@@ -93,13 +93,13 @@
       public:
         class Lock {
           public:
-            Lock(SharedCameraCallbacks &client);
+            explicit Lock(SharedCameraCallbacks &client);
             ~Lock();
             sp<TCamCallbacks> &mRemoteCallback;
           private:
             SharedCameraCallbacks &mSharedClient;
         };
-        SharedCameraCallbacks(const sp<TCamCallbacks>& client);
+        explicit SharedCameraCallbacks(const sp<TCamCallbacks>& client);
         SharedCameraCallbacks& operator=(const sp<TCamCallbacks>& client);
         void clear();
       private:
diff --git a/services/camera/libcameraservice/common/CameraModule.h b/services/camera/libcameraservice/common/CameraModule.h
index 1a1c274..d131a26 100644
--- a/services/camera/libcameraservice/common/CameraModule.h
+++ b/services/camera/libcameraservice/common/CameraModule.h
@@ -32,7 +32,7 @@
  */
 class CameraModule {
 public:
-    CameraModule(camera_module_t *module);
+    explicit CameraModule(camera_module_t *module);
     virtual ~CameraModule();
 
     // Must be called after construction
diff --git a/services/camera/libcameraservice/common/FrameProcessorBase.cpp b/services/camera/libcameraservice/common/FrameProcessorBase.cpp
index 29eb78f..2ef3057 100644
--- a/services/camera/libcameraservice/common/FrameProcessorBase.cpp
+++ b/services/camera/libcameraservice/common/FrameProcessorBase.cpp
@@ -47,7 +47,7 @@
 }
 
 status_t FrameProcessorBase::registerListener(int32_t minId,
-        int32_t maxId, wp<FilteredListener> listener, bool sendPartials) {
+        int32_t maxId, const wp<FilteredListener>& listener, bool sendPartials) {
     Mutex::Autolock l(mInputMutex);
     List<RangeListener>::iterator item = mRangeListeners.begin();
     while (item != mRangeListeners.end()) {
@@ -70,7 +70,7 @@
 
 status_t FrameProcessorBase::removeListener(int32_t minId,
                                            int32_t maxId,
-                                           wp<FilteredListener> listener) {
+                                           const wp<FilteredListener>& listener) {
     Mutex::Autolock l(mInputMutex);
     List<RangeListener>::iterator item = mRangeListeners.begin();
     while (item != mRangeListeners.end()) {
diff --git a/services/camera/libcameraservice/common/FrameProcessorBase.h b/services/camera/libcameraservice/common/FrameProcessorBase.h
index a618d84..00763a4 100644
--- a/services/camera/libcameraservice/common/FrameProcessorBase.h
+++ b/services/camera/libcameraservice/common/FrameProcessorBase.h
@@ -36,7 +36,7 @@
  */
 class FrameProcessorBase: public Thread {
   public:
-    FrameProcessorBase(wp<CameraDeviceBase> device);
+    explicit FrameProcessorBase(wp<CameraDeviceBase> device);
     virtual ~FrameProcessorBase();
 
     struct FilteredListener: virtual public RefBase {
@@ -48,10 +48,10 @@
     // the same range of IDs has no effect.
     // sendPartials controls whether partial results will be sent.
     status_t registerListener(int32_t minId, int32_t maxId,
-                              wp<FilteredListener> listener,
+                              const wp<FilteredListener>& listener,
                               bool sendPartials = true);
     status_t removeListener(int32_t minId, int32_t maxId,
-                            wp<FilteredListener> listener);
+                            const wp<FilteredListener>& listener);
 
     void dump(int fd, const Vector<String16>& args);
   protected:
diff --git a/services/camera/libcameraservice/device1/CameraHardwareInterface.h b/services/camera/libcameraservice/device1/CameraHardwareInterface.h
index bce0762..952bae1 100644
--- a/services/camera/libcameraservice/device1/CameraHardwareInterface.h
+++ b/services/camera/libcameraservice/device1/CameraHardwareInterface.h
@@ -73,7 +73,7 @@
 
 class CameraHardwareInterface : public virtual RefBase {
 public:
-    CameraHardwareInterface(const char *name):
+    explicit CameraHardwareInterface(const char *name):
             mDevice(nullptr),
             mName(name),
             mPreviewScalingMode(NOT_SET),
@@ -543,9 +543,9 @@
             commonInitialization();
         }
 
-        CameraHeapMemory(size_t buf_size, uint_t num_buffers = 1) :
-                         mBufSize(buf_size),
-                         mNumBufs(num_buffers)
+        explicit CameraHeapMemory(size_t buf_size, uint_t num_buffers = 1) :
+                                  mBufSize(buf_size),
+                                  mNumBufs(num_buffers)
         {
             mHeap = new MemoryHeapBase(buf_size * num_buffers);
             commonInitialization();
@@ -606,9 +606,9 @@
                 reinterpret_cast<CameraHardwareInterface *>(user);
         return __this->mPreviewWindow.get();
     }
-#define anw(n) __to_anw(((struct camera_preview_window *)n)->user)
+#define anw(n) __to_anw(((struct camera_preview_window *)(n))->user)
 #define hwi(n) reinterpret_cast<CameraHardwareInterface *>(\
-        ((struct camera_preview_window *)n)->user)
+        ((struct camera_preview_window *)(n))->user)
 
     static int __dequeue_buffer(struct preview_stream_ops* w,
                                 buffer_handle_t** buffer, int *stride)
diff --git a/services/camera/libcameraservice/device3/Camera3BufferManager.h b/services/camera/libcameraservice/device3/Camera3BufferManager.h
index ab6541e..b5b86a3 100644
--- a/services/camera/libcameraservice/device3/Camera3BufferManager.h
+++ b/services/camera/libcameraservice/device3/Camera3BufferManager.h
@@ -44,7 +44,7 @@
  */
 class Camera3BufferManager: public virtual RefBase {
 public:
-    Camera3BufferManager(const sp<IGraphicBufferAlloc>& allocator = NULL);
+    explicit Camera3BufferManager(const sp<IGraphicBufferAlloc>& allocator = NULL);
 
     virtual ~Camera3BufferManager();
 
@@ -195,7 +195,7 @@
     struct GraphicBufferEntry {
         sp<GraphicBuffer> graphicBuffer;
         int fenceFd;
-        GraphicBufferEntry(const sp<GraphicBuffer>& gb = 0, int fd = -1) :
+        explicit GraphicBufferEntry(const sp<GraphicBuffer>& gb = 0, int fd = -1) :
             graphicBuffer(gb),
             fenceFd(fd) {}
     };
diff --git a/services/camera/libcameraservice/device3/Camera3Device.cpp b/services/camera/libcameraservice/device3/Camera3Device.cpp
index 48a2a99..73a4124 100644
--- a/services/camera/libcameraservice/device3/Camera3Device.cpp
+++ b/services/camera/libcameraservice/device3/Camera3Device.cpp
@@ -2892,7 +2892,7 @@
     return OK;
 }
 
-bool Camera3Device::RequestThread::isRepeatingRequestLocked(const sp<CaptureRequest> requestIn) {
+bool Camera3Device::RequestThread::isRepeatingRequestLocked(const sp<CaptureRequest>& requestIn) {
     if (mRepeatingRequests.empty()) {
         return false;
     }
@@ -3013,7 +3013,7 @@
  * AE_PRECAPTURE_TRIGGER_CANCEL to AE_PRECAPTURE_TRIGGER_IDLE but doesn't add AE_LOCK_ON to the
  * request.
  */
-void Camera3Device::RequestThread::handleAePrecaptureCancelRequest(sp<CaptureRequest> request) {
+void Camera3Device::RequestThread::handleAePrecaptureCancelRequest(const sp<CaptureRequest>& request) {
     request->mAeTriggerCancelOverride.applyAeLock = false;
     request->mAeTriggerCancelOverride.applyAePrecaptureTrigger = false;
 
diff --git a/services/camera/libcameraservice/device3/Camera3Device.h b/services/camera/libcameraservice/device3/Camera3Device.h
index 17893a9..33429a6 100644
--- a/services/camera/libcameraservice/device3/Camera3Device.h
+++ b/services/camera/libcameraservice/device3/Camera3Device.h
@@ -65,7 +65,7 @@
             private camera3_callback_ops {
   public:
 
-    Camera3Device(int id);
+    explicit Camera3Device(int id);
 
     virtual ~Camera3Device();
 
@@ -220,7 +220,7 @@
     struct Size {
         uint32_t width;
         uint32_t height;
-        Size(uint32_t w = 0, uint32_t h = 0) : width(w), height(h){}
+        explicit Size(uint32_t w = 0, uint32_t h = 0) : width(w), height(h){}
     };
     // Map from format to size.
     Vector<Size>               mSupportedOpaqueInputSizes;
@@ -589,10 +589,10 @@
         void               setErrorState(const char *fmt, ...);
 
         // If the input request is in mRepeatingRequests. Must be called with mRequestLock hold
-        bool isRepeatingRequestLocked(const sp<CaptureRequest>);
+        bool isRepeatingRequestLocked(const sp<CaptureRequest>&);
 
         // Handle AE precapture trigger cancel for devices <= CAMERA_DEVICE_API_VERSION_3_2.
-        void handleAePrecaptureCancelRequest(sp<CaptureRequest> request);
+        void handleAePrecaptureCancelRequest(const sp<CaptureRequest>& request);
 
         // Clear repeating requests. Must be called with mRequestLock held.
         status_t clearRepeatingRequestsLocked(/*out*/ int64_t *lastFrameNumber = NULL);
diff --git a/services/camera/libcameraservice/device3/Camera3DummyStream.h b/services/camera/libcameraservice/device3/Camera3DummyStream.h
index 639619e..18e8a23 100644
--- a/services/camera/libcameraservice/device3/Camera3DummyStream.h
+++ b/services/camera/libcameraservice/device3/Camera3DummyStream.h
@@ -42,7 +42,7 @@
      * Set up a dummy stream; doesn't actually connect to anything, and uses
      * a default dummy format and size.
      */
-    Camera3DummyStream(int id);
+    explicit Camera3DummyStream(int id);
 
     virtual ~Camera3DummyStream();
 
diff --git a/services/camera/libcameraservice/device3/Camera3OutputStream.h b/services/camera/libcameraservice/device3/Camera3OutputStream.h
index d450a69..12d497e 100644
--- a/services/camera/libcameraservice/device3/Camera3OutputStream.h
+++ b/services/camera/libcameraservice/device3/Camera3OutputStream.h
@@ -46,7 +46,7 @@
     uint32_t combinedUsage;
     size_t totalBufferCount;
     bool isConfigured;
-    StreamInfo(int id = CAMERA3_STREAM_ID_INVALID,
+    explicit StreamInfo(int id = CAMERA3_STREAM_ID_INVALID,
             int setId = CAMERA3_STREAM_SET_ID_INVALID,
             uint32_t w = 0,
             uint32_t h = 0,
diff --git a/services/camera/libcameraservice/device3/Camera3ZslStream.cpp b/services/camera/libcameraservice/device3/Camera3ZslStream.cpp
index 7414c4c..ea138b7 100644
--- a/services/camera/libcameraservice/device3/Camera3ZslStream.cpp
+++ b/services/camera/libcameraservice/device3/Camera3ZslStream.cpp
@@ -40,7 +40,7 @@
         SELECT_NEITHER = 0,
     };
 
-    TimestampFinder(nsecs_t timestamp) : mTimestamp(timestamp) {}
+    explicit TimestampFinder(nsecs_t timestamp) : mTimestamp(timestamp) {}
     ~TimestampFinder() {}
 
     template <typename T>
diff --git a/services/camera/libcameraservice/device3/StatusTracker.h b/services/camera/libcameraservice/device3/StatusTracker.h
index 49cecb3..3a1d85c 100644
--- a/services/camera/libcameraservice/device3/StatusTracker.h
+++ b/services/camera/libcameraservice/device3/StatusTracker.h
@@ -45,7 +45,7 @@
  */
 class StatusTracker: public Thread {
   public:
-    StatusTracker(wp<Camera3Device> parent);
+    explicit StatusTracker(wp<Camera3Device> parent);
     ~StatusTracker();
 
     // An always-invalid component ID
diff --git a/services/camera/libcameraservice/utils/AutoConditionLock.h b/services/camera/libcameraservice/utils/AutoConditionLock.h
index b7f167b..cdbb01b 100644
--- a/services/camera/libcameraservice/utils/AutoConditionLock.h
+++ b/services/camera/libcameraservice/utils/AutoConditionLock.h
@@ -37,7 +37,7 @@
     /**
      * Construct the ConditionManger with the given Mutex.
      */
-    WaitableMutexWrapper(Mutex* mutex);
+    explicit WaitableMutexWrapper(Mutex* mutex);
 
     virtual ~WaitableMutexWrapper();
 private:
@@ -88,7 +88,7 @@
     static std::unique_ptr<AutoConditionLock> waitAndAcquire(
             const std::shared_ptr<WaitableMutexWrapper>& manager);
 private:
-    AutoConditionLock(const std::shared_ptr<WaitableMutexWrapper>& manager);
+    explicit AutoConditionLock(const std::shared_ptr<WaitableMutexWrapper>& manager);
 
     std::shared_ptr<WaitableMutexWrapper> mManager;
     Mutex::Autolock mAutoLock;
diff --git a/services/camera/libcameraservice/utils/ClientManager.h b/services/camera/libcameraservice/utils/ClientManager.h
index 7ae58d5..830c50b 100644
--- a/services/camera/libcameraservice/utils/ClientManager.h
+++ b/services/camera/libcameraservice/utils/ClientManager.h
@@ -216,7 +216,7 @@
     static constexpr int32_t DEFAULT_MAX_COST = 100;
 
     ClientManager();
-    ClientManager(int32_t totalCost);
+    explicit ClientManager(int32_t totalCost);
 
     /**
      * Add a given ClientDescriptor to the managed list.  ClientDescriptors for clients that
diff --git a/services/mediaresourcemanager/ResourceManagerService.cpp b/services/mediaresourcemanager/ResourceManagerService.cpp
index 3ed0189..7346f51 100644
--- a/services/mediaresourcemanager/ResourceManagerService.cpp
+++ b/services/mediaresourcemanager/ResourceManagerService.cpp
@@ -43,7 +43,7 @@
     return itemsStr;
 }
 
-static bool hasResourceType(MediaResource::Type type, Vector<MediaResource> resources) {
+static bool hasResourceType(MediaResource::Type type, const Vector<MediaResource>& resources) {
     for (size_t i = 0; i < resources.size(); ++i) {
         if (resources[i].mType == type) {
             return true;
@@ -52,7 +52,7 @@
     return false;
 }
 
-static bool hasResourceType(MediaResource::Type type, ResourceInfos infos) {
+static bool hasResourceType(MediaResource::Type type, const ResourceInfos& infos) {
     for (size_t i = 0; i < infos.size(); ++i) {
         if (hasResourceType(type, infos[i].resources)) {
             return true;
@@ -76,7 +76,7 @@
 
 static ResourceInfo& getResourceInfoForEdit(
         int64_t clientId,
-        const sp<IResourceManagerClient> client,
+        const sp<IResourceManagerClient>& client,
         ResourceInfos& infos) {
     for (size_t i = 0; i < infos.size(); ++i) {
         if (infos[i].clientId == clientId) {
diff --git a/services/mediaresourcemanager/ResourceManagerService.h b/services/mediaresourcemanager/ResourceManagerService.h
index 8f6fe9a..2a4a6b2 100644
--- a/services/mediaresourcemanager/ResourceManagerService.h
+++ b/services/mediaresourcemanager/ResourceManagerService.h
@@ -52,7 +52,7 @@
     virtual status_t dump(int fd, const Vector<String16>& args);
 
     ResourceManagerService();
-    ResourceManagerService(sp<ProcessInfoInterface> processInfo);
+    explicit ResourceManagerService(sp<ProcessInfoInterface> processInfo);
 
     // IResourceManagerService interface
     virtual void config(const Vector<MediaResourcePolicy> &policies);
diff --git a/services/mediaresourcemanager/ServiceLog.h b/services/mediaresourcemanager/ServiceLog.h
index a6f16eb..380e86a 100644
--- a/services/mediaresourcemanager/ServiceLog.h
+++ b/services/mediaresourcemanager/ServiceLog.h
@@ -30,7 +30,7 @@
 class ServiceLog : public RefBase {
 public:
     ServiceLog();
-    ServiceLog(size_t maxNum);
+    explicit ServiceLog(size_t maxNum);
 
     void add(const String8 &log);
     String8 toString(const char *linePrefix = NULL) const;
diff --git a/services/mediaresourcemanager/test/ResourceManagerService_test.cpp b/services/mediaresourcemanager/test/ResourceManagerService_test.cpp
index 62b7711..ed0b0ef 100644
--- a/services/mediaresourcemanager/test/ResourceManagerService_test.cpp
+++ b/services/mediaresourcemanager/test/ResourceManagerService_test.cpp
@@ -29,7 +29,7 @@
 
 namespace android {
 
-static int64_t getId(sp<IResourceManagerClient> client) {
+static int64_t getId(const sp<IResourceManagerClient>& client) {
     return (int64_t) client.get();
 }
 
diff --git a/services/radio/RadioService.h b/services/radio/RadioService.h
index 49feda6..ac3481e 100644
--- a/services/radio/RadioService.h
+++ b/services/radio/RadioService.h
@@ -103,7 +103,7 @@
     class CallbackThread : public Thread {
     public:
 
-        CallbackThread(const wp<ModuleClient>& moduleClient);
+        explicit CallbackThread(const wp<ModuleClient>& moduleClient);
 
         virtual ~CallbackThread();
 
diff --git a/services/soundtrigger/SoundTriggerHwService.cpp b/services/soundtrigger/SoundTriggerHwService.cpp
index eebc487..6a52b9c 100644
--- a/services/soundtrigger/SoundTriggerHwService.cpp
+++ b/services/soundtrigger/SoundTriggerHwService.cpp
@@ -164,7 +164,7 @@
 }
 
 
-void SoundTriggerHwService::detachModule(sp<Module> module)
+void SoundTriggerHwService::detachModule(const sp<Module>& module)
 {
     ALOGV("detachModule");
     AutoMutex lock(mServiceLock);
diff --git a/services/soundtrigger/SoundTriggerHwService.h b/services/soundtrigger/SoundTriggerHwService.h
index 2619a5f..13a577a 100644
--- a/services/soundtrigger/SoundTriggerHwService.h
+++ b/services/soundtrigger/SoundTriggerHwService.h
@@ -125,7 +125,7 @@
 
        sound_trigger_hw_device *hwDevice() const { return mHwDevice; }
        struct sound_trigger_module_descriptor descriptor() { return mDescriptor; }
-       void setClient(sp<ISoundTriggerClient> client) { mClient = client; }
+       void setClient(const sp<ISoundTriggerClient>& client) { mClient = client; }
        void clearClient() { mClient.clear(); }
        sp<ISoundTriggerClient> client() const { return mClient; }
        wp<SoundTriggerHwService> service() const { return mService; }
@@ -156,7 +156,7 @@
     class CallbackThread : public Thread {
     public:
 
-        CallbackThread(const wp<SoundTriggerHwService>& service);
+        explicit CallbackThread(const wp<SoundTriggerHwService>& service);
 
         virtual             ~CallbackThread();
 
@@ -176,7 +176,7 @@
         Vector< sp<CallbackEvent> > mEventQueue;
     };
 
-           void detachModule(sp<Module> module);
+           void detachModule(const sp<Module>& module);
 
     static void recognitionCallback(struct sound_trigger_recognition_event *event, void *cookie);
            sp<IMemory> prepareRecognitionEvent_l(struct sound_trigger_recognition_event *event);
diff --git a/soundtrigger/ISoundTrigger.cpp b/soundtrigger/ISoundTrigger.cpp
index 4df2068..25332a4 100644
--- a/soundtrigger/ISoundTrigger.cpp
+++ b/soundtrigger/ISoundTrigger.cpp
@@ -37,7 +37,7 @@
 class BpSoundTrigger: public BpInterface<ISoundTrigger>
 {
 public:
-    BpSoundTrigger(const sp<IBinder>& impl)
+    explicit BpSoundTrigger(const sp<IBinder>& impl)
         : BpInterface<ISoundTrigger>(impl)
     {
     }
diff --git a/soundtrigger/ISoundTriggerClient.cpp b/soundtrigger/ISoundTriggerClient.cpp
index e0d3add..1385631 100644
--- a/soundtrigger/ISoundTriggerClient.cpp
+++ b/soundtrigger/ISoundTriggerClient.cpp
@@ -35,7 +35,7 @@
 {
 
 public:
-    BpSoundTriggerClient(const sp<IBinder>& impl)
+    explicit BpSoundTriggerClient(const sp<IBinder>& impl)
         : BpInterface<ISoundTriggerClient>(impl)
     {
     }
diff --git a/soundtrigger/ISoundTriggerHwService.cpp b/soundtrigger/ISoundTriggerHwService.cpp
index e37bae3..d44f5cb 100644
--- a/soundtrigger/ISoundTriggerHwService.cpp
+++ b/soundtrigger/ISoundTriggerHwService.cpp
@@ -45,7 +45,7 @@
 class BpSoundTriggerHwService: public BpInterface<ISoundTriggerHwService>
 {
 public:
-    BpSoundTriggerHwService(const sp<IBinder>& impl)
+    explicit BpSoundTriggerHwService(const sp<IBinder>& impl)
         : BpInterface<ISoundTriggerHwService>(impl)
     {
     }