Merge "Switch to a thread pool for aio operations"
diff --git a/camera/ndk/include/camera/NdkCameraCaptureSession.h b/camera/ndk/include/camera/NdkCameraCaptureSession.h
index d96f538..b544b50 100644
--- a/camera/ndk/include/camera/NdkCameraCaptureSession.h
+++ b/camera/ndk/include/camera/NdkCameraCaptureSession.h
@@ -33,10 +33,12 @@
  * Do not #include files that aren't part of the NDK.
  */
 #include <sys/cdefs.h>
+#include <stdbool.h>
 
 #include <android/native_window.h>
 #include "NdkCameraError.h"
 #include "NdkCameraMetadata.h"
+#include "NdkCaptureRequest.h"
 
 #ifndef _NDK_CAMERA_CAPTURE_SESSION_H
 #define _NDK_CAMERA_CAPTURE_SESSION_H
diff --git a/camera/ndk/include/camera/NdkCameraDevice.h b/camera/ndk/include/camera/NdkCameraDevice.h
index 6c9e85a..2c65529 100644
--- a/camera/ndk/include/camera/NdkCameraDevice.h
+++ b/camera/ndk/include/camera/NdkCameraDevice.h
@@ -153,6 +153,11 @@
 } ACameraDevice_StateCallbacks;
 
 /**
+ * For backward compatiblity.
+ */
+typedef ACameraDevice_StateCallbacks ACameraDevice_stateCallbacks;
+
+/**
  * Close the connection and free this ACameraDevice synchronously. Access to the ACameraDevice
  * after calling this method will cause a crash.
  *
diff --git a/camera/ndk/include/camera/NdkCameraMetadata.h b/camera/ndk/include/camera/NdkCameraMetadata.h
index f2aec98..bdb1587 100644
--- a/camera/ndk/include/camera/NdkCameraMetadata.h
+++ b/camera/ndk/include/camera/NdkCameraMetadata.h
@@ -36,6 +36,7 @@
 #ifndef _NDK_CAMERA_METADATA_H
 #define _NDK_CAMERA_METADATA_H
 
+#include <stdint.h>
 #include <sys/cdefs.h>
 
 #include "NdkCameraError.h"
diff --git a/include/common_time/ICommonClock.h b/include/common_time/ICommonClock.h
deleted file mode 100644
index d7073f1..0000000
--- a/include/common_time/ICommonClock.h
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * Copyright (C) 2011 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.
- */
-
-#ifndef ANDROID_ICOMMONCLOCK_H
-#define ANDROID_ICOMMONCLOCK_H
-
-#include <stdint.h>
-#include <linux/socket.h>
-
-#include <binder/IInterface.h>
-#include <binder/IServiceManager.h>
-
-namespace android {
-
-class ICommonClockListener : public IInterface {
-  public:
-    DECLARE_META_INTERFACE(CommonClockListener);
-
-    virtual void onTimelineChanged(uint64_t timelineID) = 0;
-};
-
-class BnCommonClockListener : public BnInterface<ICommonClockListener> {
-  public:
-    virtual status_t onTransact(uint32_t code, const Parcel& data,
-                                Parcel* reply, uint32_t flags = 0);
-};
-
-class ICommonClock : public IInterface {
-  public:
-    DECLARE_META_INTERFACE(CommonClock);
-
-    // Name of the ICommonClock service registered with the service manager.
-    static const String16 kServiceName;
-
-    // a reserved invalid timeline ID
-    static const uint64_t kInvalidTimelineID;
-
-    // a reserved invalid error estimate
-    static const int32_t kErrorEstimateUnknown;
-
-    enum State {
-        // the device just came up and is trying to discover the master
-        STATE_INITIAL,
-
-        // the device is a client of a master
-        STATE_CLIENT,
-
-        // the device is acting as master
-        STATE_MASTER,
-
-        // the device has lost contact with its master and needs to participate
-        // in the election of a new master
-        STATE_RONIN,
-
-        // the device is waiting for announcement of the newly elected master
-        STATE_WAIT_FOR_ELECTION,
-    };
-
-    virtual status_t isCommonTimeValid(bool* valid, uint32_t* timelineID) = 0;
-    virtual status_t commonTimeToLocalTime(int64_t commonTime,
-                                           int64_t* localTime) = 0;
-    virtual status_t localTimeToCommonTime(int64_t localTime,
-                                           int64_t* commonTime) = 0;
-    virtual status_t getCommonTime(int64_t* commonTime) = 0;
-    virtual status_t getCommonFreq(uint64_t* freq) = 0;
-    virtual status_t getLocalTime(int64_t* localTime) = 0;
-    virtual status_t getLocalFreq(uint64_t* freq) = 0;
-    virtual status_t getEstimatedError(int32_t* estimate) = 0;
-    virtual status_t getTimelineID(uint64_t* id) = 0;
-    virtual status_t getState(State* state) = 0;
-    virtual status_t getMasterAddr(struct sockaddr_storage* addr) = 0;
-
-    virtual status_t registerListener(
-            const sp<ICommonClockListener>& listener) = 0;
-    virtual status_t unregisterListener(
-            const sp<ICommonClockListener>& listener) = 0;
-
-    // Simple helper to make it easier to connect to the CommonClock service.
-    static inline sp<ICommonClock> getInstance() {
-        sp<IBinder> binder = defaultServiceManager()->checkService(
-                ICommonClock::kServiceName);
-        sp<ICommonClock> clk = interface_cast<ICommonClock>(binder);
-        return clk;
-    }
-};
-
-class BnCommonClock : public BnInterface<ICommonClock> {
-  public:
-    virtual status_t onTransact(uint32_t code, const Parcel& data,
-                                Parcel* reply, uint32_t flags = 0);
-};
-
-};  // namespace android
-
-#endif  // ANDROID_ICOMMONCLOCK_H
diff --git a/include/common_time/ICommonTimeConfig.h b/include/common_time/ICommonTimeConfig.h
deleted file mode 100644
index 497b666..0000000
--- a/include/common_time/ICommonTimeConfig.h
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Copyright (C) 2012 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.
- */
-
-#ifndef ANDROID_ICOMMONTIMECONFIG_H
-#define ANDROID_ICOMMONTIMECONFIG_H
-
-#include <stdint.h>
-#include <linux/socket.h>
-
-#include <binder/IInterface.h>
-#include <binder/IServiceManager.h>
-
-namespace android {
-
-class String16;
-
-class ICommonTimeConfig : public IInterface {
-  public:
-    DECLARE_META_INTERFACE(CommonTimeConfig);
-
-    // Name of the ICommonTimeConfig service registered with the service
-    // manager.
-    static const String16 kServiceName;
-
-    virtual status_t getMasterElectionPriority(uint8_t *priority) = 0;
-    virtual status_t setMasterElectionPriority(uint8_t priority) = 0;
-    virtual status_t getMasterElectionEndpoint(struct sockaddr_storage *addr) = 0;
-    virtual status_t setMasterElectionEndpoint(const struct sockaddr_storage *addr) = 0;
-    virtual status_t getMasterElectionGroupId(uint64_t *id) = 0;
-    virtual status_t setMasterElectionGroupId(uint64_t id) = 0;
-    virtual status_t getInterfaceBinding(String16& ifaceName) = 0;
-    virtual status_t setInterfaceBinding(const String16& ifaceName) = 0;
-    virtual status_t getMasterAnnounceInterval(int *interval) = 0;
-    virtual status_t setMasterAnnounceInterval(int interval) = 0;
-    virtual status_t getClientSyncInterval(int *interval) = 0;
-    virtual status_t setClientSyncInterval(int interval) = 0;
-    virtual status_t getPanicThreshold(int *threshold) = 0;
-    virtual status_t setPanicThreshold(int threshold) = 0;
-    virtual status_t getAutoDisable(bool *autoDisable) = 0;
-    virtual status_t setAutoDisable(bool autoDisable) = 0;
-    virtual status_t forceNetworklessMasterMode() = 0;
-
-    // Simple helper to make it easier to connect to the CommonTimeConfig service.
-    static inline sp<ICommonTimeConfig> getInstance() {
-        sp<IBinder> binder = defaultServiceManager()->checkService(
-                ICommonTimeConfig::kServiceName);
-        sp<ICommonTimeConfig> clk = interface_cast<ICommonTimeConfig>(binder);
-        return clk;
-    }
-};
-
-class BnCommonTimeConfig : public BnInterface<ICommonTimeConfig> {
-  public:
-    virtual status_t onTransact(uint32_t code, const Parcel& data,
-                                Parcel* reply, uint32_t flags = 0);
-};
-
-};  // namespace android
-
-#endif  // ANDROID_ICOMMONTIMECONFIG_H
diff --git a/include/common_time/cc_helper.h b/include/common_time/cc_helper.h
deleted file mode 100644
index 8c4d5c0..0000000
--- a/include/common_time/cc_helper.h
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright (C) 2011 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.
- */
-
-#ifndef __CC_HELPER_H__
-#define __CC_HELPER_H__
-
-#include <stdint.h>
-#include <common_time/ICommonClock.h>
-#include <utils/threads.h>
-
-namespace android {
-
-// CCHelper is a simple wrapper class to help with centralizing access to the
-// Common Clock service and implementing lifetime managment, as well as to
-// implement a simple policy of making a basic attempt to reconnect to the
-// common clock service when things go wrong.
-//
-// On platforms which run the native common_time service in auto-disable mode,
-// the service will go into networkless mode whenever it has no active clients.
-// It tracks active clients using registered CommonClockListeners (the callback
-// interface for onTimelineChanged) since this provides a convienent death
-// handler notification for when the service's clients die unexpectedly.  This
-// means that users of the common time service should really always have a
-// CommonClockListener, unless they know that the time service is not running in
-// auto disabled mode, or that there is at least one other registered listener
-// active in the system.  The CCHelper makes this a little easier by sharing a
-// ref counted ICommonClock interface across all clients and automatically
-// registering and unregistering a listener whenever there are CCHelper
-// instances active in the process.
-class CCHelper {
-  public:
-    CCHelper();
-    ~CCHelper();
-
-    status_t isCommonTimeValid(bool* valid, uint32_t* timelineID);
-    status_t commonTimeToLocalTime(int64_t commonTime, int64_t* localTime);
-    status_t localTimeToCommonTime(int64_t localTime, int64_t* commonTime);
-    status_t getCommonTime(int64_t* commonTime);
-    status_t getCommonFreq(uint64_t* freq);
-    status_t getLocalTime(int64_t* localTime);
-    status_t getLocalFreq(uint64_t* freq);
-
-  private:
-    class CommonClockListener : public BnCommonClockListener {
-      public:
-        void onTimelineChanged(uint64_t timelineID);
-    };
-
-    static bool verifyClock_l();
-
-    static Mutex lock_;
-    static sp<ICommonClock> common_clock_;
-    static sp<ICommonClockListener> common_clock_listener_;
-    static uint32_t ref_count_;
-};
-
-
-}  // namespace android
-#endif  // __CC_HELPER_H__
diff --git a/include/common_time/local_clock.h b/include/common_time/local_clock.h
deleted file mode 100644
index 384c3de..0000000
--- a/include/common_time/local_clock.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright (C) 2011 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.
- */
-
-
-#ifndef __LOCAL_CLOCK_H__
-#define __LOCAL_CLOCK_H__
-
-#include <stdint.h>
-
-#include <hardware/local_time_hal.h>
-#include <utils/Errors.h>
-#include <utils/threads.h>
-
-namespace android {
-
-class LocalClock {
-  public:
-    LocalClock();
-
-    bool initCheck();
-
-    int64_t  getLocalTime();
-    uint64_t getLocalFreq();
-    status_t setLocalSlew(int16_t rate);
-    int32_t  getDebugLog(struct local_time_debug_event* records,
-                         int max_records);
-
-  private:
-    static Mutex dev_lock_;
-    static local_time_hw_device_t* dev_;
-};
-
-}  // namespace android
-#endif  // __LOCAL_CLOCK_H__
diff --git a/media/audioserver/audioserver.rc b/media/audioserver/audioserver.rc
index 9d42bce..366f52a 100644
--- a/media/audioserver/audioserver.rc
+++ b/media/audioserver/audioserver.rc
@@ -2,7 +2,8 @@
     class main
     user audioserver
     # media gid needed for /dev/fm (radio) and for /data/misc/media (tee)
-    group audio camera drmrpc inet media mediadrm net_bt net_bt_admin net_bw_acct
+    group audio camera drmrpc inet media mediadrm net_bt net_bt_admin net_bw_acct wakelock
+    capabilities BLOCK_SUSPEND
     ioprio rt 4
     writepid /dev/cpuset/foreground/tasks /dev/stune/foreground/tasks
     onrestart restart audio-hal-2-0
diff --git a/media/common_time/Android.mk b/media/common_time/Android.mk
deleted file mode 100644
index aaa0db2..0000000
--- a/media/common_time/Android.mk
+++ /dev/null
@@ -1,24 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-#
-# libcommon_time_client
-# (binder marshalers for ICommonClock as well as common clock and local clock
-# helper code)
-#
-
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := libcommon_time_client
-LOCAL_MODULE_TAGS := optional
-LOCAL_SRC_FILES := cc_helper.cpp \
-                   local_clock.cpp \
-                   ICommonClock.cpp \
-                   ICommonTimeConfig.cpp \
-                   utils.cpp
-LOCAL_SHARED_LIBRARIES := libbinder \
-                          libhardware \
-                          libutils \
-                          liblog
-
-LOCAL_CFLAGS := -Wall -Werror
-
-include $(BUILD_SHARED_LIBRARY)
diff --git a/media/common_time/ICommonClock.cpp b/media/common_time/ICommonClock.cpp
deleted file mode 100644
index f1f1fca..0000000
--- a/media/common_time/ICommonClock.cpp
+++ /dev/null
@@ -1,433 +0,0 @@
-/*
- * Copyright (C) 2012 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.
- */
-
-#include <sys/socket.h>
-
-#include <common_time/ICommonClock.h>
-#include <binder/Parcel.h>
-
-#include "utils.h"
-
-namespace android {
-
-/***** ICommonClock *****/
-
-enum {
-    IS_COMMON_TIME_VALID = IBinder::FIRST_CALL_TRANSACTION,
-    COMMON_TIME_TO_LOCAL_TIME,
-    LOCAL_TIME_TO_COMMON_TIME,
-    GET_COMMON_TIME,
-    GET_COMMON_FREQ,
-    GET_LOCAL_TIME,
-    GET_LOCAL_FREQ,
-    GET_ESTIMATED_ERROR,
-    GET_TIMELINE_ID,
-    GET_STATE,
-    GET_MASTER_ADDRESS,
-    REGISTER_LISTENER,
-    UNREGISTER_LISTENER,
-};
-
-const String16 ICommonClock::kServiceName("common_time.clock");
-const uint64_t ICommonClock::kInvalidTimelineID = 0;
-const int32_t ICommonClock::kErrorEstimateUnknown = 0x7FFFFFFF;
-
-class BpCommonClock : public BpInterface<ICommonClock>
-{
-  public:
-    explicit BpCommonClock(const sp<IBinder>& impl)
-        : BpInterface<ICommonClock>(impl) {}
-
-    virtual status_t isCommonTimeValid(bool* valid, uint32_t* timelineID) {
-        Parcel data, reply;
-        data.writeInterfaceToken(ICommonClock::getInterfaceDescriptor());
-        status_t status = remote()->transact(IS_COMMON_TIME_VALID,
-                                             data,
-                                             &reply);
-        if (status == OK) {
-            status = reply.readInt32();
-            if (status == OK) {
-                *valid = reply.readInt32();
-                *timelineID = reply.readInt32();
-            }
-        }
-        return status;
-    }
-
-    virtual status_t commonTimeToLocalTime(int64_t commonTime,
-            int64_t* localTime) {
-        Parcel data, reply;
-        data.writeInterfaceToken(ICommonClock::getInterfaceDescriptor());
-        data.writeInt64(commonTime);
-        status_t status = remote()->transact(COMMON_TIME_TO_LOCAL_TIME,
-                data, &reply);
-        if (status == OK) {
-            status = reply.readInt32();
-            if (status == OK) {
-                *localTime = reply.readInt64();
-            }
-        }
-        return status;
-    }
-
-    virtual status_t localTimeToCommonTime(int64_t localTime,
-            int64_t* commonTime) {
-        Parcel data, reply;
-        data.writeInterfaceToken(ICommonClock::getInterfaceDescriptor());
-        data.writeInt64(localTime);
-        status_t status = remote()->transact(LOCAL_TIME_TO_COMMON_TIME,
-                data, &reply);
-        if (status == OK) {
-            status = reply.readInt32();
-            if (status == OK) {
-                *commonTime = reply.readInt64();
-            }
-        }
-        return status;
-    }
-
-    virtual status_t getCommonTime(int64_t* commonTime) {
-        Parcel data, reply;
-        data.writeInterfaceToken(ICommonClock::getInterfaceDescriptor());
-        status_t status = remote()->transact(GET_COMMON_TIME, data, &reply);
-        if (status == OK) {
-            status = reply.readInt32();
-            if (status == OK) {
-                *commonTime = reply.readInt64();
-            }
-        }
-        return status;
-    }
-
-    virtual status_t getCommonFreq(uint64_t* freq) {
-        Parcel data, reply;
-        data.writeInterfaceToken(ICommonClock::getInterfaceDescriptor());
-        status_t status = remote()->transact(GET_COMMON_FREQ, data, &reply);
-        if (status == OK) {
-            status = reply.readInt32();
-            if (status == OK) {
-                *freq = reply.readInt64();
-            }
-        }
-        return status;
-    }
-
-    virtual status_t getLocalTime(int64_t* localTime) {
-        Parcel data, reply;
-        data.writeInterfaceToken(ICommonClock::getInterfaceDescriptor());
-        status_t status = remote()->transact(GET_LOCAL_TIME, data, &reply);
-        if (status == OK) {
-            status = reply.readInt32();
-            if (status == OK) {
-                *localTime = reply.readInt64();
-            }
-        }
-        return status;
-    }
-
-    virtual status_t getLocalFreq(uint64_t* freq) {
-        Parcel data, reply;
-        data.writeInterfaceToken(ICommonClock::getInterfaceDescriptor());
-        status_t status = remote()->transact(GET_LOCAL_FREQ, data, &reply);
-        if (status == OK) {
-            status = reply.readInt32();
-            if (status == OK) {
-                *freq = reply.readInt64();
-            }
-        }
-        return status;
-    }
-
-    virtual status_t getEstimatedError(int32_t* estimate) {
-        Parcel data, reply;
-        data.writeInterfaceToken(ICommonClock::getInterfaceDescriptor());
-        status_t status = remote()->transact(GET_ESTIMATED_ERROR, data, &reply);
-        if (status == OK) {
-            status = reply.readInt32();
-            if (status == OK) {
-                *estimate = reply.readInt32();
-            }
-        }
-        return status;
-    }
-
-    virtual status_t getTimelineID(uint64_t* id) {
-        Parcel data, reply;
-        data.writeInterfaceToken(ICommonClock::getInterfaceDescriptor());
-        status_t status = remote()->transact(GET_TIMELINE_ID, data, &reply);
-        if (status == OK) {
-            status = reply.readInt32();
-            if (status == OK) {
-                *id = static_cast<uint64_t>(reply.readInt64());
-            }
-        }
-        return status;
-    }
-
-    virtual status_t getState(State* state) {
-        Parcel data, reply;
-        data.writeInterfaceToken(ICommonClock::getInterfaceDescriptor());
-        status_t status = remote()->transact(GET_STATE, data, &reply);
-        if (status == OK) {
-            status = reply.readInt32();
-            if (status == OK) {
-                *state = static_cast<State>(reply.readInt32());
-            }
-        }
-        return status;
-    }
-
-    virtual status_t getMasterAddr(struct sockaddr_storage* addr) {
-        Parcel data, reply;
-        data.writeInterfaceToken(ICommonClock::getInterfaceDescriptor());
-        status_t status = remote()->transact(GET_MASTER_ADDRESS, data, &reply);
-        if (status == OK) {
-            status = reply.readInt32();
-            if (status == OK)
-                deserializeSockaddr(&reply, addr);
-        }
-        return status;
-    }
-
-    virtual status_t registerListener(
-            const sp<ICommonClockListener>& listener) {
-        Parcel data, reply;
-        data.writeInterfaceToken(ICommonClock::getInterfaceDescriptor());
-        data.writeStrongBinder(IInterface::asBinder(listener));
-
-        status_t status = remote()->transact(REGISTER_LISTENER, data, &reply);
-
-        if (status == OK) {
-            status = reply.readInt32();
-        }
-
-        return status;
-    }
-
-    virtual status_t unregisterListener(
-            const sp<ICommonClockListener>& listener) {
-        Parcel data, reply;
-        data.writeInterfaceToken(ICommonClock::getInterfaceDescriptor());
-        data.writeStrongBinder(IInterface::asBinder(listener));
-        status_t status = remote()->transact(UNREGISTER_LISTENER, data, &reply);
-
-        if (status == OK) {
-            status = reply.readInt32();
-        }
-
-        return status;
-    }
-};
-
-IMPLEMENT_META_INTERFACE(CommonClock, "android.os.ICommonClock");
-
-status_t BnCommonClock::onTransact(uint32_t code,
-                                   const Parcel& data,
-                                   Parcel* reply,
-                                   uint32_t flags) {
-    switch(code) {
-        case IS_COMMON_TIME_VALID: {
-            CHECK_INTERFACE(ICommonClock, data, reply);
-            bool valid;
-            uint32_t timelineID;
-            status_t status = isCommonTimeValid(&valid, &timelineID);
-            reply->writeInt32(status);
-            if (status == OK) {
-                reply->writeInt32(valid);
-                reply->writeInt32(timelineID);
-            }
-            return OK;
-        } break;
-
-        case COMMON_TIME_TO_LOCAL_TIME: {
-            CHECK_INTERFACE(ICommonClock, data, reply);
-            int64_t commonTime = data.readInt64();
-            int64_t localTime;
-            status_t status = commonTimeToLocalTime(commonTime, &localTime);
-            reply->writeInt32(status);
-            if (status == OK) {
-                reply->writeInt64(localTime);
-            }
-            return OK;
-        } break;
-
-        case LOCAL_TIME_TO_COMMON_TIME: {
-            CHECK_INTERFACE(ICommonClock, data, reply);
-            int64_t localTime = data.readInt64();
-            int64_t commonTime;
-            status_t status = localTimeToCommonTime(localTime, &commonTime);
-            reply->writeInt32(status);
-            if (status == OK) {
-                reply->writeInt64(commonTime);
-            }
-            return OK;
-        } break;
-
-        case GET_COMMON_TIME: {
-            CHECK_INTERFACE(ICommonClock, data, reply);
-            int64_t commonTime;
-            status_t status = getCommonTime(&commonTime);
-            reply->writeInt32(status);
-            if (status == OK) {
-                reply->writeInt64(commonTime);
-            }
-            return OK;
-        } break;
-
-        case GET_COMMON_FREQ: {
-            CHECK_INTERFACE(ICommonClock, data, reply);
-            uint64_t freq;
-            status_t status = getCommonFreq(&freq);
-            reply->writeInt32(status);
-            if (status == OK) {
-                reply->writeInt64(freq);
-            }
-            return OK;
-        } break;
-
-        case GET_LOCAL_TIME: {
-            CHECK_INTERFACE(ICommonClock, data, reply);
-            int64_t localTime;
-            status_t status = getLocalTime(&localTime);
-            reply->writeInt32(status);
-            if (status == OK) {
-                reply->writeInt64(localTime);
-            }
-            return OK;
-        } break;
-
-        case GET_LOCAL_FREQ: {
-            CHECK_INTERFACE(ICommonClock, data, reply);
-            uint64_t freq;
-            status_t status = getLocalFreq(&freq);
-            reply->writeInt32(status);
-            if (status == OK) {
-                reply->writeInt64(freq);
-            }
-            return OK;
-        } break;
-
-        case GET_ESTIMATED_ERROR: {
-            CHECK_INTERFACE(ICommonClock, data, reply);
-            int32_t error;
-            status_t status = getEstimatedError(&error);
-            reply->writeInt32(status);
-            if (status == OK) {
-                reply->writeInt32(error);
-            }
-            return OK;
-        } break;
-
-        case GET_TIMELINE_ID: {
-            CHECK_INTERFACE(ICommonClock, data, reply);
-            uint64_t id;
-            status_t status = getTimelineID(&id);
-            reply->writeInt32(status);
-            if (status == OK) {
-                reply->writeInt64(static_cast<int64_t>(id));
-            }
-            return OK;
-        } break;
-
-        case GET_STATE: {
-            CHECK_INTERFACE(ICommonClock, data, reply);
-            State state;
-            status_t status = getState(&state);
-            reply->writeInt32(status);
-            if (status == OK) {
-                reply->writeInt32(static_cast<int32_t>(state));
-            }
-            return OK;
-        } break;
-
-        case GET_MASTER_ADDRESS: {
-            CHECK_INTERFACE(ICommonClock, data, reply);
-            struct sockaddr_storage addr;
-            status_t status = getMasterAddr(&addr);
-
-            if ((status == OK) && !canSerializeSockaddr(&addr)) {
-                status = UNKNOWN_ERROR;
-            }
-
-            reply->writeInt32(status);
-
-            if (status == OK) {
-                serializeSockaddr(reply, &addr);
-            }
-
-            return OK;
-        } break;
-
-        case REGISTER_LISTENER: {
-            CHECK_INTERFACE(ICommonClock, data, reply);
-            sp<ICommonClockListener> listener =
-                interface_cast<ICommonClockListener>(data.readStrongBinder());
-            status_t status = registerListener(listener);
-            reply->writeInt32(status);
-            return OK;
-        } break;
-
-        case UNREGISTER_LISTENER: {
-            CHECK_INTERFACE(ICommonClock, data, reply);
-            sp<ICommonClockListener> listener =
-                interface_cast<ICommonClockListener>(data.readStrongBinder());
-            status_t status = unregisterListener(listener);
-            reply->writeInt32(status);
-            return OK;
-        } break;
-    }
-    return BBinder::onTransact(code, data, reply, flags);
-}
-
-/***** ICommonClockListener *****/
-
-enum {
-    ON_TIMELINE_CHANGED = IBinder::FIRST_CALL_TRANSACTION,
-};
-
-class BpCommonClockListener : public BpInterface<ICommonClockListener>
-{
-  public:
-    explicit BpCommonClockListener(const sp<IBinder>& impl)
-        : BpInterface<ICommonClockListener>(impl) {}
-
-    virtual void onTimelineChanged(uint64_t timelineID) {
-        Parcel data, reply;
-        data.writeInterfaceToken(
-                ICommonClockListener::getInterfaceDescriptor());
-        data.writeInt64(timelineID);
-        remote()->transact(ON_TIMELINE_CHANGED, data, &reply);
-    }
-};
-
-IMPLEMENT_META_INTERFACE(CommonClockListener,
-                         "android.os.ICommonClockListener");
-
-status_t BnCommonClockListener::onTransact(
-        uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) {
-    switch(code) {
-        case ON_TIMELINE_CHANGED: {
-            CHECK_INTERFACE(ICommonClockListener, data, reply);
-            uint32_t timelineID = data.readInt64();
-            onTimelineChanged(timelineID);
-            return NO_ERROR;
-        } break;
-    }
-
-    return BBinder::onTransact(code, data, reply, flags);
-}
-
-}; // namespace android
diff --git a/media/common_time/ICommonTimeConfig.cpp b/media/common_time/ICommonTimeConfig.cpp
deleted file mode 100644
index e587b39..0000000
--- a/media/common_time/ICommonTimeConfig.cpp
+++ /dev/null
@@ -1,509 +0,0 @@
-/*
- * Copyright (C) 2011 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.
- */
-
-#include <sys/socket.h>
-
-#include <common_time/ICommonTimeConfig.h>
-#include <binder/Parcel.h>
-
-#include "utils.h"
-
-namespace android {
-
-/***** ICommonTimeConfig *****/
-
-enum {
-    GET_MASTER_ELECTION_PRIORITY = IBinder::FIRST_CALL_TRANSACTION,
-    SET_MASTER_ELECTION_PRIORITY,
-    GET_MASTER_ELECTION_ENDPOINT,
-    SET_MASTER_ELECTION_ENDPOINT,
-    GET_MASTER_ELECTION_GROUP_ID,
-    SET_MASTER_ELECTION_GROUP_ID,
-    GET_INTERFACE_BINDING,
-    SET_INTERFACE_BINDING,
-    GET_MASTER_ANNOUNCE_INTERVAL,
-    SET_MASTER_ANNOUNCE_INTERVAL,
-    GET_CLIENT_SYNC_INTERVAL,
-    SET_CLIENT_SYNC_INTERVAL,
-    GET_PANIC_THRESHOLD,
-    SET_PANIC_THRESHOLD,
-    GET_AUTO_DISABLE,
-    SET_AUTO_DISABLE,
-    FORCE_NETWORKLESS_MASTER_MODE,
-};
-
-const String16 ICommonTimeConfig::kServiceName("common_time.config");
-
-class BpCommonTimeConfig : public BpInterface<ICommonTimeConfig>
-{
-  public:
-    explicit BpCommonTimeConfig(const sp<IBinder>& impl)
-        : BpInterface<ICommonTimeConfig>(impl) {}
-
-    virtual status_t getMasterElectionPriority(uint8_t *priority) {
-        Parcel data, reply;
-        data.writeInterfaceToken(ICommonTimeConfig::getInterfaceDescriptor());
-        status_t status = remote()->transact(GET_MASTER_ELECTION_PRIORITY,
-                                             data,
-                                             &reply);
-        if (status == OK) {
-            status = reply.readInt32();
-            if (status == OK) {
-                *priority = static_cast<uint8_t>(reply.readInt32());
-            }
-        }
-
-        return status;
-    }
-
-    virtual status_t setMasterElectionPriority(uint8_t priority) {
-        Parcel data, reply;
-        data.writeInterfaceToken(ICommonTimeConfig::getInterfaceDescriptor());
-        data.writeInt32(static_cast<int32_t>(priority));
-        status_t status = remote()->transact(SET_MASTER_ELECTION_PRIORITY,
-                                             data,
-                                             &reply);
-        if (status == OK) {
-            status = reply.readInt32();
-        }
-
-        return status;
-    }
-
-    virtual status_t getMasterElectionEndpoint(struct sockaddr_storage *addr) {
-        Parcel data, reply;
-        data.writeInterfaceToken(ICommonTimeConfig::getInterfaceDescriptor());
-        status_t status = remote()->transact(GET_MASTER_ELECTION_ENDPOINT,
-                                             data,
-                                             &reply);
-        if (status == OK) {
-            status = reply.readInt32();
-            if (status == OK) {
-                deserializeSockaddr(&reply, addr);
-            }
-        }
-
-        return status;
-    }
-
-    virtual status_t setMasterElectionEndpoint(
-            const struct sockaddr_storage *addr) {
-        Parcel data, reply;
-        data.writeInterfaceToken(ICommonTimeConfig::getInterfaceDescriptor());
-        if (!canSerializeSockaddr(addr))
-            return BAD_VALUE;
-        if (NULL == addr) {
-            data.writeInt32(0);
-        } else {
-            data.writeInt32(1);
-            serializeSockaddr(&data, addr);
-        }
-        status_t status = remote()->transact(SET_MASTER_ELECTION_ENDPOINT,
-                                             data,
-                                             &reply);
-        if (status == OK) {
-            status = reply.readInt32();
-        }
-
-        return status;
-    }
-
-    virtual status_t getMasterElectionGroupId(uint64_t *id) {
-        Parcel data, reply;
-        data.writeInterfaceToken(ICommonTimeConfig::getInterfaceDescriptor());
-        status_t status = remote()->transact(GET_MASTER_ELECTION_GROUP_ID,
-                                             data,
-                                             &reply);
-
-        if (status == OK) {
-            status = reply.readInt32();
-            if (status == OK) {
-                *id = static_cast<uint64_t>(reply.readInt64());
-            }
-        }
-
-        return status;
-    }
-
-    virtual status_t setMasterElectionGroupId(uint64_t id) {
-        Parcel data, reply;
-        data.writeInterfaceToken(ICommonTimeConfig::getInterfaceDescriptor());
-        data.writeInt64(id);
-        status_t status = remote()->transact(SET_MASTER_ELECTION_GROUP_ID,
-                                             data,
-                                             &reply);
-
-        if (status == OK) {
-            status = reply.readInt32();
-        }
-
-        return status;
-    }
-
-    virtual status_t getInterfaceBinding(String16& ifaceName) {
-        Parcel data, reply;
-        data.writeInterfaceToken(ICommonTimeConfig::getInterfaceDescriptor());
-        status_t status = remote()->transact(GET_INTERFACE_BINDING,
-                                             data,
-                                             &reply);
-        if (status == OK) {
-            status = reply.readInt32();
-            if (status == OK) {
-                ifaceName = reply.readString16();
-            }
-        }
-
-        return status;
-    }
-
-    virtual status_t setInterfaceBinding(const String16& ifaceName) {
-        Parcel data, reply;
-        data.writeInterfaceToken(ICommonTimeConfig::getInterfaceDescriptor());
-        data.writeString16(ifaceName);
-        status_t status = remote()->transact(SET_INTERFACE_BINDING,
-                                             data,
-                                             &reply);
-        if (status == OK) {
-            status = reply.readInt32();
-        }
-
-        return status;
-    }
-
-    virtual status_t getMasterAnnounceInterval(int *interval) {
-        Parcel data, reply;
-        data.writeInterfaceToken(ICommonTimeConfig::getInterfaceDescriptor());
-        status_t status = remote()->transact(GET_MASTER_ANNOUNCE_INTERVAL,
-                                             data,
-                                             &reply);
-        if (status == OK) {
-            status = reply.readInt32();
-            if (status == OK) {
-                *interval = reply.readInt32();
-            }
-        }
-
-        return status;
-    }
-
-    virtual status_t setMasterAnnounceInterval(int interval) {
-        Parcel data, reply;
-        data.writeInterfaceToken(ICommonTimeConfig::getInterfaceDescriptor());
-        data.writeInt32(interval);
-        status_t status = remote()->transact(SET_MASTER_ANNOUNCE_INTERVAL,
-                                             data,
-                                             &reply);
-        if (status == OK) {
-            status = reply.readInt32();
-        }
-
-        return status;
-    }
-
-    virtual status_t getClientSyncInterval(int *interval) {
-        Parcel data, reply;
-        data.writeInterfaceToken(ICommonTimeConfig::getInterfaceDescriptor());
-        status_t status = remote()->transact(GET_CLIENT_SYNC_INTERVAL,
-                                             data,
-                                             &reply);
-        if (status == OK) {
-            status = reply.readInt32();
-            if (status == OK) {
-                *interval = reply.readInt32();
-            }
-        }
-
-        return status;
-    }
-
-    virtual status_t setClientSyncInterval(int interval) {
-        Parcel data, reply;
-        data.writeInterfaceToken(ICommonTimeConfig::getInterfaceDescriptor());
-        data.writeInt32(interval);
-        status_t status = remote()->transact(SET_CLIENT_SYNC_INTERVAL,
-                                             data,
-                                             &reply);
-        if (status == OK) {
-            status = reply.readInt32();
-        }
-
-        return status;
-    }
-
-    virtual status_t getPanicThreshold(int *threshold) {
-        Parcel data, reply;
-        data.writeInterfaceToken(ICommonTimeConfig::getInterfaceDescriptor());
-        status_t status = remote()->transact(GET_PANIC_THRESHOLD,
-                                             data,
-                                             &reply);
-        if (status == OK) {
-            status = reply.readInt32();
-            if (status == OK) {
-                *threshold = reply.readInt32();
-            }
-        }
-
-        return status;
-    }
-
-    virtual status_t setPanicThreshold(int threshold) {
-        Parcel data, reply;
-        data.writeInterfaceToken(ICommonTimeConfig::getInterfaceDescriptor());
-        data.writeInt32(threshold);
-        status_t status = remote()->transact(SET_PANIC_THRESHOLD,
-                                             data,
-                                             &reply);
-        if (status == OK) {
-            status = reply.readInt32();
-        }
-
-        return status;
-    }
-
-    virtual status_t getAutoDisable(bool *autoDisable) {
-        Parcel data, reply;
-        data.writeInterfaceToken(ICommonTimeConfig::getInterfaceDescriptor());
-        status_t status = remote()->transact(GET_AUTO_DISABLE,
-                                             data,
-                                             &reply);
-        if (status == OK) {
-            status = reply.readInt32();
-            if (status == OK) {
-                *autoDisable = (0 != reply.readInt32());
-            }
-        }
-
-        return status;
-    }
-
-    virtual status_t setAutoDisable(bool autoDisable) {
-        Parcel data, reply;
-        data.writeInterfaceToken(ICommonTimeConfig::getInterfaceDescriptor());
-        data.writeInt32(autoDisable ? 1 : 0);
-        status_t status = remote()->transact(SET_AUTO_DISABLE,
-                                             data,
-                                             &reply);
-
-        if (status == OK) {
-            status = reply.readInt32();
-        }
-
-        return status;
-    }
-
-    virtual status_t forceNetworklessMasterMode() {
-        Parcel data, reply;
-        data.writeInterfaceToken(ICommonTimeConfig::getInterfaceDescriptor());
-        status_t status = remote()->transact(FORCE_NETWORKLESS_MASTER_MODE,
-                                             data,
-                                             &reply);
-
-        if (status == OK) {
-            status = reply.readInt32();
-        }
-
-        return status;
-    }
-};
-
-IMPLEMENT_META_INTERFACE(CommonTimeConfig, "android.os.ICommonTimeConfig");
-
-status_t BnCommonTimeConfig::onTransact(uint32_t code,
-                                   const Parcel& data,
-                                   Parcel* reply,
-                                   uint32_t flags) {
-    switch(code) {
-        case GET_MASTER_ELECTION_PRIORITY: {
-            CHECK_INTERFACE(ICommonTimeConfig, data, reply);
-            uint8_t priority;
-            status_t status = getMasterElectionPriority(&priority);
-            reply->writeInt32(status);
-            if (status == OK) {
-                reply->writeInt32(static_cast<int32_t>(priority));
-            }
-            return OK;
-        } break;
-
-        case SET_MASTER_ELECTION_PRIORITY: {
-            CHECK_INTERFACE(ICommonTimeConfig, data, reply);
-            uint8_t priority = static_cast<uint8_t>(data.readInt32());
-            status_t status = setMasterElectionPriority(priority);
-            reply->writeInt32(status);
-            return OK;
-        } break;
-
-        case GET_MASTER_ELECTION_ENDPOINT: {
-            CHECK_INTERFACE(ICommonTimeConfig, data, reply);
-            struct sockaddr_storage addr;
-            status_t status = getMasterElectionEndpoint(&addr);
-
-            if ((status == OK) && !canSerializeSockaddr(&addr)) {
-                status = UNKNOWN_ERROR;
-            }
-
-            reply->writeInt32(status);
-
-            if (status == OK) {
-                serializeSockaddr(reply, &addr);
-            }
-
-            return OK;
-        } break;
-
-        case SET_MASTER_ELECTION_ENDPOINT: {
-            CHECK_INTERFACE(ICommonTimeConfig, data, reply);
-            struct sockaddr_storage addr;
-            int hasAddr = data.readInt32();
-
-            status_t status;
-            if (hasAddr) {
-                deserializeSockaddr(&data, &addr);
-                status = setMasterElectionEndpoint(&addr);
-            } else {
-                status = setMasterElectionEndpoint(&addr);
-            }
-
-            reply->writeInt32(status);
-            return OK;
-        } break;
-
-        case GET_MASTER_ELECTION_GROUP_ID: {
-            CHECK_INTERFACE(ICommonTimeConfig, data, reply);
-            uint64_t id;
-            status_t status = getMasterElectionGroupId(&id);
-            reply->writeInt32(status);
-            if (status == OK) {
-                reply->writeInt64(id);
-            }
-            return OK;
-        } break;
-
-        case SET_MASTER_ELECTION_GROUP_ID: {
-            CHECK_INTERFACE(ICommonTimeConfig, data, reply);
-            uint64_t id = static_cast<uint64_t>(data.readInt64());
-            status_t status = setMasterElectionGroupId(id);
-            reply->writeInt32(status);
-            return OK;
-        } break;
-
-        case GET_INTERFACE_BINDING: {
-            CHECK_INTERFACE(ICommonTimeConfig, data, reply);
-            String16 ret;
-            status_t status = getInterfaceBinding(ret);
-            reply->writeInt32(status);
-            if (status == OK) {
-                reply->writeString16(ret);
-            }
-            return OK;
-        } break;
-
-        case SET_INTERFACE_BINDING: {
-            CHECK_INTERFACE(ICommonTimeConfig, data, reply);
-            String16 ifaceName;
-            ifaceName = data.readString16();
-            status_t status = setInterfaceBinding(ifaceName);
-            reply->writeInt32(status);
-            return OK;
-        } break;
-
-        case GET_MASTER_ANNOUNCE_INTERVAL: {
-            CHECK_INTERFACE(ICommonTimeConfig, data, reply);
-            int interval;
-            status_t status = getMasterAnnounceInterval(&interval);
-            reply->writeInt32(status);
-            if (status == OK) {
-                reply->writeInt32(interval);
-            }
-            return OK;
-        } break;
-
-        case SET_MASTER_ANNOUNCE_INTERVAL: {
-            CHECK_INTERFACE(ICommonTimeConfig, data, reply);
-            int interval = data.readInt32();
-            status_t status = setMasterAnnounceInterval(interval);
-            reply->writeInt32(status);
-            return OK;
-        } break;
-
-        case GET_CLIENT_SYNC_INTERVAL: {
-            CHECK_INTERFACE(ICommonTimeConfig, data, reply);
-            int interval;
-            status_t status = getClientSyncInterval(&interval);
-            reply->writeInt32(status);
-            if (status == OK) {
-                reply->writeInt32(interval);
-            }
-            return OK;
-        } break;
-
-        case SET_CLIENT_SYNC_INTERVAL: {
-            CHECK_INTERFACE(ICommonTimeConfig, data, reply);
-            int interval = data.readInt32();
-            status_t status = setClientSyncInterval(interval);
-            reply->writeInt32(status);
-            return OK;
-        } break;
-
-        case GET_PANIC_THRESHOLD: {
-            CHECK_INTERFACE(ICommonTimeConfig, data, reply);
-            int threshold;
-            status_t status = getPanicThreshold(&threshold);
-            reply->writeInt32(status);
-            if (status == OK) {
-                reply->writeInt32(threshold);
-            }
-            return OK;
-        } break;
-
-        case SET_PANIC_THRESHOLD: {
-            CHECK_INTERFACE(ICommonTimeConfig, data, reply);
-            int threshold = data.readInt32();
-            status_t status = setPanicThreshold(threshold);
-            reply->writeInt32(status);
-            return OK;
-        } break;
-
-        case GET_AUTO_DISABLE: {
-            CHECK_INTERFACE(ICommonTimeConfig, data, reply);
-            bool autoDisable;
-            status_t status = getAutoDisable(&autoDisable);
-            reply->writeInt32(status);
-            if (status == OK) {
-                reply->writeInt32(autoDisable ? 1 : 0);
-            }
-            return OK;
-        } break;
-
-        case SET_AUTO_DISABLE: {
-            CHECK_INTERFACE(ICommonTimeConfig, data, reply);
-            bool autoDisable = (0 != data.readInt32());
-            status_t status = setAutoDisable(autoDisable);
-            reply->writeInt32(status);
-            return OK;
-        } break;
-
-        case FORCE_NETWORKLESS_MASTER_MODE: {
-            CHECK_INTERFACE(ICommonTimeConfig, data, reply);
-            status_t status = forceNetworklessMasterMode();
-            reply->writeInt32(status);
-            return OK;
-        } break;
-    }
-    return BBinder::onTransact(code, data, reply, flags);
-}
-
-}; // namespace android
-
diff --git a/media/common_time/MODULE_LICENSE_APACHE2 b/media/common_time/MODULE_LICENSE_APACHE2
deleted file mode 100644
index e69de29..0000000
--- a/media/common_time/MODULE_LICENSE_APACHE2
+++ /dev/null
diff --git a/media/common_time/NOTICE b/media/common_time/NOTICE
deleted file mode 100644
index c5b1efa..0000000
--- a/media/common_time/NOTICE
+++ /dev/null
@@ -1,190 +0,0 @@
-
-   Copyright (c) 2005-2008, 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.
-
-   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.
-
-
-                                 Apache License
-                           Version 2.0, January 2004
-                        http://www.apache.org/licenses/
-
-   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
-
-   1. Definitions.
-
-      "License" shall mean the terms and conditions for use, reproduction,
-      and distribution as defined by Sections 1 through 9 of this document.
-
-      "Licensor" shall mean the copyright owner or entity authorized by
-      the copyright owner that is granting the License.
-
-      "Legal Entity" shall mean the union of the acting entity and all
-      other entities that control, are controlled by, or are under common
-      control with that entity. For the purposes of this definition,
-      "control" means (i) the power, direct or indirect, to cause the
-      direction or management of such entity, whether by contract or
-      otherwise, or (ii) ownership of fifty percent (50%) or more of the
-      outstanding shares, or (iii) beneficial ownership of such entity.
-
-      "You" (or "Your") shall mean an individual or Legal Entity
-      exercising permissions granted by this License.
-
-      "Source" form shall mean the preferred form for making modifications,
-      including but not limited to software source code, documentation
-      source, and configuration files.
-
-      "Object" form shall mean any form resulting from mechanical
-      transformation or translation of a Source form, including but
-      not limited to compiled object code, generated documentation,
-      and conversions to other media types.
-
-      "Work" shall mean the work of authorship, whether in Source or
-      Object form, made available under the License, as indicated by a
-      copyright notice that is included in or attached to the work
-      (an example is provided in the Appendix below).
-
-      "Derivative Works" shall mean any work, whether in Source or Object
-      form, that is based on (or derived from) the Work and for which the
-      editorial revisions, annotations, elaborations, or other modifications
-      represent, as a whole, an original work of authorship. For the purposes
-      of this License, Derivative Works shall not include works that remain
-      separable from, or merely link (or bind by name) to the interfaces of,
-      the Work and Derivative Works thereof.
-
-      "Contribution" shall mean any work of authorship, including
-      the original version of the Work and any modifications or additions
-      to that Work or Derivative Works thereof, that is intentionally
-      submitted to Licensor for inclusion in the Work by the copyright owner
-      or by an individual or Legal Entity authorized to submit on behalf of
-      the copyright owner. For the purposes of this definition, "submitted"
-      means any form of electronic, verbal, or written communication sent
-      to the Licensor or its representatives, including but not limited to
-      communication on electronic mailing lists, source code control systems,
-      and issue tracking systems that are managed by, or on behalf of, the
-      Licensor for the purpose of discussing and improving the Work, but
-      excluding communication that is conspicuously marked or otherwise
-      designated in writing by the copyright owner as "Not a Contribution."
-
-      "Contributor" shall mean Licensor and any individual or Legal Entity
-      on behalf of whom a Contribution has been received by Licensor and
-      subsequently incorporated within the Work.
-
-   2. Grant of Copyright License. Subject to the terms and conditions of
-      this License, each Contributor hereby grants to You a perpetual,
-      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
-      copyright license to reproduce, prepare Derivative Works of,
-      publicly display, publicly perform, sublicense, and distribute the
-      Work and such Derivative Works in Source or Object form.
-
-   3. Grant of Patent License. Subject to the terms and conditions of
-      this License, each Contributor hereby grants to You a perpetual,
-      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
-      (except as stated in this section) patent license to make, have made,
-      use, offer to sell, sell, import, and otherwise transfer the Work,
-      where such license applies only to those patent claims licensable
-      by such Contributor that are necessarily infringed by their
-      Contribution(s) alone or by combination of their Contribution(s)
-      with the Work to which such Contribution(s) was submitted. If You
-      institute patent litigation against any entity (including a
-      cross-claim or counterclaim in a lawsuit) alleging that the Work
-      or a Contribution incorporated within the Work constitutes direct
-      or contributory patent infringement, then any patent licenses
-      granted to You under this License for that Work shall terminate
-      as of the date such litigation is filed.
-
-   4. Redistribution. You may reproduce and distribute copies of the
-      Work or Derivative Works thereof in any medium, with or without
-      modifications, and in Source or Object form, provided that You
-      meet the following conditions:
-
-      (a) You must give any other recipients of the Work or
-          Derivative Works a copy of this License; and
-
-      (b) You must cause any modified files to carry prominent notices
-          stating that You changed the files; and
-
-      (c) You must retain, in the Source form of any Derivative Works
-          that You distribute, all copyright, patent, trademark, and
-          attribution notices from the Source form of the Work,
-          excluding those notices that do not pertain to any part of
-          the Derivative Works; and
-
-      (d) If the Work includes a "NOTICE" text file as part of its
-          distribution, then any Derivative Works that You distribute must
-          include a readable copy of the attribution notices contained
-          within such NOTICE file, excluding those notices that do not
-          pertain to any part of the Derivative Works, in at least one
-          of the following places: within a NOTICE text file distributed
-          as part of the Derivative Works; within the Source form or
-          documentation, if provided along with the Derivative Works; or,
-          within a display generated by the Derivative Works, if and
-          wherever such third-party notices normally appear. The contents
-          of the NOTICE file are for informational purposes only and
-          do not modify the License. You may add Your own attribution
-          notices within Derivative Works that You distribute, alongside
-          or as an addendum to the NOTICE text from the Work, provided
-          that such additional attribution notices cannot be construed
-          as modifying the License.
-
-      You may add Your own copyright statement to Your modifications and
-      may provide additional or different license terms and conditions
-      for use, reproduction, or distribution of Your modifications, or
-      for any such Derivative Works as a whole, provided Your use,
-      reproduction, and distribution of the Work otherwise complies with
-      the conditions stated in this License.
-
-   5. Submission of Contributions. Unless You explicitly state otherwise,
-      any Contribution intentionally submitted for inclusion in the Work
-      by You to the Licensor shall be under the terms and conditions of
-      this License, without any additional terms or conditions.
-      Notwithstanding the above, nothing herein shall supersede or modify
-      the terms of any separate license agreement you may have executed
-      with Licensor regarding such Contributions.
-
-   6. Trademarks. This License does not grant permission to use the trade
-      names, trademarks, service marks, or product names of the Licensor,
-      except as required for reasonable and customary use in describing the
-      origin of the Work and reproducing the content of the NOTICE file.
-
-   7. Disclaimer of Warranty. Unless required by applicable law or
-      agreed to in writing, Licensor provides the Work (and each
-      Contributor provides its Contributions) on an "AS IS" BASIS,
-      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
-      implied, including, without limitation, any warranties or conditions
-      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
-      PARTICULAR PURPOSE. You are solely responsible for determining the
-      appropriateness of using or redistributing the Work and assume any
-      risks associated with Your exercise of permissions under this License.
-
-   8. Limitation of Liability. In no event and under no legal theory,
-      whether in tort (including negligence), contract, or otherwise,
-      unless required by applicable law (such as deliberate and grossly
-      negligent acts) or agreed to in writing, shall any Contributor be
-      liable to You for damages, including any direct, indirect, special,
-      incidental, or consequential damages of any character arising as a
-      result of this License or out of the use or inability to use the
-      Work (including but not limited to damages for loss of goodwill,
-      work stoppage, computer failure or malfunction, or any and all
-      other commercial damages or losses), even if such Contributor
-      has been advised of the possibility of such damages.
-
-   9. Accepting Warranty or Additional Liability. While redistributing
-      the Work or Derivative Works thereof, You may choose to offer,
-      and charge a fee for, acceptance of support, warranty, indemnity,
-      or other liability obligations and/or rights consistent with this
-      License. However, in accepting such obligations, You may act only
-      on Your own behalf and on Your sole responsibility, not on behalf
-      of any other Contributor, and only if You agree to indemnify,
-      defend, and hold each Contributor harmless for any liability
-      incurred by, or claims asserted against, such Contributor by reason
-      of your accepting any such warranty or additional liability.
-
-   END OF TERMS AND CONDITIONS
-
diff --git a/media/common_time/cc_helper.cpp b/media/common_time/cc_helper.cpp
deleted file mode 100644
index 6a7de74..0000000
--- a/media/common_time/cc_helper.cpp
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * Copyright (C) 2011 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.
- */
-
-#include <stdint.h>
-
-#include <common_time/cc_helper.h>
-#include <common_time/ICommonClock.h>
-#include <utils/threads.h>
-
-namespace android {
-
-Mutex CCHelper::lock_;
-sp<ICommonClock> CCHelper::common_clock_;
-sp<ICommonClockListener> CCHelper::common_clock_listener_;
-uint32_t CCHelper::ref_count_ = 0;
-
-bool CCHelper::verifyClock_l() {
-    bool ret = false;
-
-    if (common_clock_ == NULL) {
-        common_clock_ = ICommonClock::getInstance();
-        if (common_clock_ == NULL)
-            goto bailout;
-    }
-
-    if (ref_count_ > 0) {
-        if (common_clock_listener_ == NULL) {
-            common_clock_listener_ = new CommonClockListener();
-            if (common_clock_listener_ == NULL)
-                goto bailout;
-
-            if (OK != common_clock_->registerListener(common_clock_listener_))
-                goto bailout;
-        }
-    }
-
-    ret = true;
-
-bailout:
-    if (!ret) {
-        common_clock_listener_ = NULL;
-        common_clock_ = NULL;
-    }
-    return ret;
-}
-
-CCHelper::CCHelper() {
-    Mutex::Autolock lock(&lock_);
-    ref_count_++;
-    verifyClock_l();
-}
-
-CCHelper::~CCHelper() {
-    Mutex::Autolock lock(&lock_);
-
-    assert(ref_count_ > 0);
-    ref_count_--;
-
-    // If we were the last CCHelper instance in the system, and we had
-    // previously register a listener, unregister it now so that the common time
-    // service has the chance to go into auto-disabled mode.
-    if (!ref_count_ &&
-       (common_clock_ != NULL) &&
-       (common_clock_listener_ != NULL)) {
-        common_clock_->unregisterListener(common_clock_listener_);
-        common_clock_listener_ = NULL;
-    }
-}
-
-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.
-}
-
-// Helper methods which attempts to make calls to the common time binder
-// service.  If the first attempt fails with DEAD_OBJECT, the helpers will
-// attempt to make a connection to the service again (assuming that the process
-// hosting the service had crashed and the client proxy we are holding is dead)
-// If the second attempt fails, or no connection can be made, the we let the
-// error propagate up the stack and let the caller deal with the situation as
-// best they can.
-#define CCHELPER_METHOD(decl, call)                 \
-    status_t CCHelper::decl {                       \
-        Mutex::Autolock lock(&lock_);               \
-                                                    \
-        if (!verifyClock_l())                       \
-            return DEAD_OBJECT;                     \
-                                                    \
-        status_t status = common_clock_->call;      \
-        if (DEAD_OBJECT == status) {                \
-            if (!verifyClock_l())                   \
-                return DEAD_OBJECT;                 \
-            status = common_clock_->call;           \
-        }                                           \
-                                                    \
-        return status;                              \
-    }
-
-#define VERIFY_CLOCK()
-
-CCHELPER_METHOD(isCommonTimeValid(bool* valid, uint32_t* timelineID),
-                isCommonTimeValid(valid, timelineID))
-CCHELPER_METHOD(commonTimeToLocalTime(int64_t commonTime, int64_t* localTime),
-                commonTimeToLocalTime(commonTime, localTime))
-CCHELPER_METHOD(localTimeToCommonTime(int64_t localTime, int64_t* commonTime),
-                localTimeToCommonTime(localTime, commonTime))
-CCHELPER_METHOD(getCommonTime(int64_t* commonTime),
-                getCommonTime(commonTime))
-CCHELPER_METHOD(getCommonFreq(uint64_t* freq),
-                getCommonFreq(freq))
-CCHELPER_METHOD(getLocalTime(int64_t* localTime),
-                getLocalTime(localTime))
-CCHELPER_METHOD(getLocalFreq(uint64_t* freq),
-                getLocalFreq(freq))
-
-}  // namespace android
diff --git a/media/common_time/local_clock.cpp b/media/common_time/local_clock.cpp
deleted file mode 100644
index a7c61fc..0000000
--- a/media/common_time/local_clock.cpp
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * Copyright (C) 2011 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.
- */
-
-#define LOG_TAG "common_time"
-#include <utils/Log.h>
-
-#include <assert.h>
-#include <stdint.h>
-
-#include <common_time/local_clock.h>
-#include <hardware/hardware.h>
-#include <hardware/local_time_hal.h>
-#include <utils/Errors.h>
-#include <utils/threads.h>
-
-namespace android {
-
-Mutex LocalClock::dev_lock_;
-local_time_hw_device_t* LocalClock::dev_ = NULL;
-
-LocalClock::LocalClock() {
-    int res;
-    const hw_module_t* mod;
-
-    AutoMutex lock(&dev_lock_);
-
-    if (dev_ != NULL)
-        return;
-
-    res = hw_get_module_by_class(LOCAL_TIME_HARDWARE_MODULE_ID, NULL, &mod);
-    if (res) {
-        ALOGE("Failed to open local time HAL module (res = %d)", res);
-    } else {
-        res = local_time_hw_device_open(mod, &dev_);
-        if (res) {
-            ALOGE("Failed to open local time HAL device (res = %d)", res);
-            dev_ = NULL;
-        }
-    }
-}
-
-bool LocalClock::initCheck() {
-    return (NULL != dev_);
-}
-
-int64_t LocalClock::getLocalTime() {
-    assert(NULL != dev_);
-    assert(NULL != dev_->get_local_time);
-
-    return dev_->get_local_time(dev_);
-}
-
-uint64_t LocalClock::getLocalFreq() {
-    assert(NULL != dev_);
-    assert(NULL != dev_->get_local_freq);
-
-    return dev_->get_local_freq(dev_);
-}
-
-status_t LocalClock::setLocalSlew(int16_t rate) {
-    assert(NULL != dev_);
-
-    if (!dev_->set_local_slew)
-        return INVALID_OPERATION;
-
-    return static_cast<status_t>(dev_->set_local_slew(dev_, rate));
-}
-
-int32_t LocalClock::getDebugLog(struct local_time_debug_event* records,
-                                int max_records) {
-    assert(NULL != dev_);
-
-    if (!dev_->get_debug_log)
-        return INVALID_OPERATION;
-
-    return dev_->get_debug_log(dev_, records, max_records);
-}
-
-}  // namespace android
diff --git a/media/common_time/utils.cpp b/media/common_time/utils.cpp
deleted file mode 100644
index 91cf2fd..0000000
--- a/media/common_time/utils.cpp
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Copyright (C) 2012 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.
- */
-
-#include <arpa/inet.h>
-#include <linux/socket.h>
-
-#include <binder/Parcel.h>
-
-namespace android {
-
-bool canSerializeSockaddr(const struct sockaddr_storage* addr) {
-    switch (addr->ss_family) {
-        case AF_INET:
-        case AF_INET6:
-            return true;
-        default:
-            return false;
-    }
-}
-
-void serializeSockaddr(Parcel* p, const struct sockaddr_storage* addr) {
-    switch (addr->ss_family) {
-        case AF_INET: {
-            const struct sockaddr_in* s =
-                reinterpret_cast<const struct sockaddr_in*>(addr);
-            p->writeInt32(AF_INET);
-            p->writeInt32(ntohl(s->sin_addr.s_addr));
-            p->writeInt32(static_cast<int32_t>(ntohs(s->sin_port)));
-        } break;
-
-        case AF_INET6: {
-            const struct sockaddr_in6* s =
-                reinterpret_cast<const struct sockaddr_in6*>(addr);
-            const int32_t* a =
-                reinterpret_cast<const int32_t*>(s->sin6_addr.s6_addr);
-            p->writeInt32(AF_INET6);
-            p->writeInt32(ntohl(a[0]));
-            p->writeInt32(ntohl(a[1]));
-            p->writeInt32(ntohl(a[2]));
-            p->writeInt32(ntohl(a[3]));
-            p->writeInt32(static_cast<int32_t>(ntohs(s->sin6_port)));
-            p->writeInt32(ntohl(s->sin6_flowinfo));
-            p->writeInt32(ntohl(s->sin6_scope_id));
-        } break;
-    }
-}
-
-void deserializeSockaddr(const Parcel* p, struct sockaddr_storage* addr) {
-    memset(addr, 0, sizeof(*addr));
-
-    addr->ss_family = p->readInt32();
-    switch(addr->ss_family) {
-        case AF_INET: {
-            struct sockaddr_in* s =
-                reinterpret_cast<struct sockaddr_in*>(addr);
-            s->sin_addr.s_addr = htonl(p->readInt32());
-            s->sin_port = htons(static_cast<uint16_t>(p->readInt32()));
-        } break;
-
-        case AF_INET6: {
-            struct sockaddr_in6* s =
-                reinterpret_cast<struct sockaddr_in6*>(addr);
-            int32_t* a = reinterpret_cast<int32_t*>(s->sin6_addr.s6_addr);
-
-            a[0] = htonl(p->readInt32());
-            a[1] = htonl(p->readInt32());
-            a[2] = htonl(p->readInt32());
-            a[3] = htonl(p->readInt32());
-            s->sin6_port = htons(static_cast<uint16_t>(p->readInt32()));
-            s->sin6_flowinfo = htonl(p->readInt32());
-            s->sin6_scope_id = htonl(p->readInt32());
-        } break;
-    }
-}
-
-}  // namespace android
diff --git a/media/common_time/utils.h b/media/common_time/utils.h
deleted file mode 100644
index ce79d0d..0000000
--- a/media/common_time/utils.h
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (C) 2012 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.
- */
-
-#ifndef ANDROID_LIBCOMMONCLOCK_UTILS_H
-#define ANDROID_LIBCOMMONCLOCK_UTILS_H
-
-#include <linux/socket.h>
-
-#include <binder/Parcel.h>
-#include <utils/Errors.h>
-
-namespace android {
-
-extern bool canSerializeSockaddr(const struct sockaddr_storage* addr);
-extern void serializeSockaddr(Parcel* p, const struct sockaddr_storage* addr);
-extern status_t deserializeSockaddr(const Parcel* p,
-                                    struct sockaddr_storage* addr);
-
-};  // namespace android
-
-#endif  // ANDROID_LIBCOMMONCLOCK_UTILS_H
diff --git a/media/libaudioclient/ToneGenerator.cpp b/media/libaudioclient/ToneGenerator.cpp
index cfb5be6..5338059 100644
--- a/media/libaudioclient/ToneGenerator.cpp
+++ b/media/libaudioclient/ToneGenerator.cpp
@@ -1029,7 +1029,7 @@
     bool lResult = false;
     status_t lStatus;
 
-    if ((toneType < 0) || (toneType >= NUM_TONES))
+    if (toneType >= NUM_TONES)
         return lResult;
 
     toneType = getToneForRegion(toneType);
diff --git a/media/libmedia/Android.bp b/media/libmedia/Android.bp
index a462f3a..8580f57 100644
--- a/media/libmedia/Android.bp
+++ b/media/libmedia/Android.bp
@@ -127,6 +127,7 @@
     vndk: {
         enabled: true,
     },
+    double_loadable: true,
 
     defaults: ["libmedia_omx_defaults"],
 }
diff --git a/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.cpp b/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.cpp
index bd866cb..a52303f 100644
--- a/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.cpp
+++ b/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.cpp
@@ -355,8 +355,12 @@
 
         // AudioSink has rendered some frames.
         int64_t nowUs = ALooper::GetNowUs();
-        int64_t nowMediaUs = mAudioSink->getPlayedOutDurationUs(nowUs)
-                + mAudioFirstAnchorTimeMediaUs;
+        int64_t playedOutDurationUs = mAudioSink->getPlayedOutDurationUs(nowUs);
+        if (playedOutDurationUs == 0) {
+            *mediaUs = mAudioFirstAnchorTimeMediaUs;
+            return OK;
+        }
+        int64_t nowMediaUs = playedOutDurationUs + mAudioFirstAnchorTimeMediaUs;
         mMediaClock->updateAnchor(nowMediaUs, nowUs, -1);
     }
 
diff --git a/media/libstagefright/Android.bp b/media/libstagefright/Android.bp
index ac4e819..b764c98 100644
--- a/media/libstagefright/Android.bp
+++ b/media/libstagefright/Android.bp
@@ -98,7 +98,6 @@
         "libstagefright_flacdec",
         "libstagefright_foundation",
         "libstagefright_xmlparser",
-        "libdl",
         "libRScpp",
         "libhidlbase",
         "libhidlmemory",
diff --git a/media/libstagefright/VideoFrameScheduler.cpp b/media/libstagefright/VideoFrameScheduler.cpp
index 03226c7..6819bba 100644
--- a/media/libstagefright/VideoFrameScheduler.cpp
+++ b/media/libstagefright/VideoFrameScheduler.cpp
@@ -129,6 +129,11 @@
         numSamplesToUse = mNumSamples;
     }
 
+    if ((period >> kPrecision) == 0 ) {
+        ALOGW("Period is 0, or after including precision is 0 - would cause div0, returning");
+        return false;
+    }
+
     int64_t sumX = 0;
     int64_t sumXX = 0;
     int64_t sumXY = 0;
diff --git a/media/libstagefright/codec2/tests/C2Param_test.cpp b/media/libstagefright/codec2/tests/C2Param_test.cpp
index ec82c84..786e988 100644
--- a/media/libstagefright/codec2/tests/C2Param_test.cpp
+++ b/media/libstagefright/codec2/tests/C2Param_test.cpp
@@ -2479,11 +2479,11 @@
             for (const FD::named_value_type &p : f.namedValues()) {
                 cout << sep << p.first << "=";
                 switch (f.type()) {
-                case C2Value::INT32: cout << get(p.second, (int32_t *)0); break;
-                case C2Value::INT64: cout << get(p.second, (int64_t *)0); break;
-                case C2Value::UINT32: cout << get(p.second, (uint32_t *)0); break;
-                case C2Value::UINT64: cout << get(p.second, (uint64_t *)0); break;
-                case C2Value::FLOAT: cout << get(p.second, (float *)0); break;
+                case C2FieldDescriptor::INT32: cout << get(p.second, (int32_t *)0); break;
+                case C2FieldDescriptor::INT64: cout << get(p.second, (int64_t *)0); break;
+                case C2FieldDescriptor::UINT32: cout << get(p.second, (uint32_t *)0); break;
+                case C2FieldDescriptor::UINT64: cout << get(p.second, (uint64_t *)0); break;
+                case C2FieldDescriptor::FLOAT: cout << get(p.second, (float *)0); break;
                 default: cout << "???"; break;
                 }
                 sep = ",";
diff --git a/media/libstagefright/codecs/m4v_h263/dec/src/pvdec_api.cpp b/media/libstagefright/codecs/m4v_h263/dec/src/pvdec_api.cpp
index 8d5d071..75ca846 100644
--- a/media/libstagefright/codecs/m4v_h263/dec/src/pvdec_api.cpp
+++ b/media/libstagefright/codecs/m4v_h263/dec/src/pvdec_api.cpp
@@ -107,6 +107,7 @@
 #else
         if ((size_t)nLayers > SIZE_MAX / sizeof(Vol *)) {
             status = PV_FALSE;
+            oscl_free(video);
             goto fail;
         }
 
@@ -115,7 +116,8 @@
         if (video->vol == NULL) status = PV_FALSE;
         video->memoryUsage += nLayers * sizeof(Vol *);
 
-
+        /* be sure not to leak any previous state */
+        PVCleanUpVideoDecoder(decCtrl);
         /* we need to setup this pointer for the application to */
         /*    pass it around.                                   */
         decCtrl->videoDecoderData = (void *) video;
diff --git a/media/libstagefright/colorconversion/ColorConverter.cpp b/media/libstagefright/colorconversion/ColorConverter.cpp
index 0982006..a0654c7 100644
--- a/media/libstagefright/colorconversion/ColorConverter.cpp
+++ b/media/libstagefright/colorconversion/ColorConverter.cpp
@@ -577,7 +577,8 @@
     uint16_t *dst_ptr = (uint16_t *)dst.mBits
         + dst.mCropTop * dst.mWidth + dst.mCropLeft;
 
-    const uint8_t *src_y = (const uint8_t *)src.mBits;
+    const uint8_t *src_y =
+        (const uint8_t *)src.mBits + src.mCropTop * src.mWidth + src.mCropLeft;
 
     const uint8_t *src_u =
         (const uint8_t *)src_y + src.mWidth * (src.mHeight - src.mCropTop / 2);
diff --git a/media/libstagefright/foundation/AString.cpp b/media/libstagefright/foundation/AString.cpp
index 04fac19..c6ef75f 100644
--- a/media/libstagefright/foundation/AString.cpp
+++ b/media/libstagefright/foundation/AString.cpp
@@ -31,7 +31,7 @@
 namespace android {
 
 // static
-const char *AString::kEmptyString = "";
+constexpr const char *AString::kEmptyString;
 
 AString::AString()
     : mData((char *)kEmptyString),
diff --git a/media/libstagefright/foundation/Android.bp b/media/libstagefright/foundation/Android.bp
index 221af1d..a07fcb0 100644
--- a/media/libstagefright/foundation/Android.bp
+++ b/media/libstagefright/foundation/Android.bp
@@ -10,6 +10,7 @@
     vndk: {
         enabled: true,
     },
+    double_loadable: true,
     include_dirs: [
         "frameworks/av/include",
         "frameworks/native/include",
diff --git a/media/libstagefright/foundation/include/media/stagefright/foundation/AString.h b/media/libstagefright/foundation/include/media/stagefright/foundation/AString.h
index ff086b3..0f6299c 100644
--- a/media/libstagefright/foundation/include/media/stagefright/foundation/AString.h
+++ b/media/libstagefright/foundation/include/media/stagefright/foundation/AString.h
@@ -93,7 +93,7 @@
     status_t writeToParcel(Parcel *parcel) const;
 
 private:
-    static const char *kEmptyString;
+    constexpr static const char *kEmptyString = "";
 
     char *mData;
     size_t mSize;
diff --git a/media/ndk/include/media/NdkMediaCodec.h b/media/ndk/include/media/NdkMediaCodec.h
index 144de2d..33cd7af 100644
--- a/media/ndk/include/media/NdkMediaCodec.h
+++ b/media/ndk/include/media/NdkMediaCodec.h
@@ -14,6 +14,15 @@
  * limitations under the License.
  */
 
+/**
+ * @addtogroup Media
+ * @{
+ */
+
+/**
+ * @file NdkMediaCodec.h
+ */
+
 /*
  * This file defines an NDK API.
  * Do not remove methods.
@@ -366,3 +375,5 @@
 __END_DECLS
 
 #endif //_NDK_MEDIA_CODEC_H
+
+/** @} */
diff --git a/media/ndk/include/media/NdkMediaCrypto.h b/media/ndk/include/media/NdkMediaCrypto.h
index d31dbdc..6f2926e 100644
--- a/media/ndk/include/media/NdkMediaCrypto.h
+++ b/media/ndk/include/media/NdkMediaCrypto.h
@@ -14,6 +14,14 @@
  * limitations under the License.
  */
 
+/**
+ * @addtogroup Media
+ * @{
+ */
+
+/**
+ * @file NdkMediaCrypto.h
+ */
 
 /*
  * This file defines an NDK API.
@@ -54,3 +62,5 @@
 __END_DECLS
 
 #endif // _NDK_MEDIA_CRYPTO_H
+
+/** @} */
diff --git a/media/ndk/include/media/NdkMediaDrm.h b/media/ndk/include/media/NdkMediaDrm.h
index 9e9f4c3..d45dc20 100644
--- a/media/ndk/include/media/NdkMediaDrm.h
+++ b/media/ndk/include/media/NdkMediaDrm.h
@@ -14,6 +14,15 @@
  * limitations under the License.
  */
 
+/**
+ * @addtogroup Media
+ * @{
+ */
+
+/**
+ * @file NdkMediaDrm.h
+ */
+
 /*
  * This file defines an NDK API.
  * Do not remove methods.
@@ -451,3 +460,5 @@
 __END_DECLS
 
 #endif //_NDK_MEDIA_DRM_H
+
+/** @} */
diff --git a/media/ndk/include/media/NdkMediaError.h b/media/ndk/include/media/NdkMediaError.h
index da61b64..7afb681 100644
--- a/media/ndk/include/media/NdkMediaError.h
+++ b/media/ndk/include/media/NdkMediaError.h
@@ -14,6 +14,14 @@
  * limitations under the License.
  */
 
+/**
+ * @addtogroup Media
+ * @{
+ */
+
+/**
+ * @file NdkMediaError.h
+ */
 
 /*
  * This file defines an NDK API.
@@ -66,3 +74,5 @@
 __END_DECLS
 
 #endif // _NDK_MEDIA_ERROR_H
+
+/** @} */
diff --git a/media/ndk/include/media/NdkMediaExtractor.h b/media/ndk/include/media/NdkMediaExtractor.h
index bf0e46d..ad8f9da 100644
--- a/media/ndk/include/media/NdkMediaExtractor.h
+++ b/media/ndk/include/media/NdkMediaExtractor.h
@@ -14,6 +14,14 @@
  * limitations under the License.
  */
 
+/**
+ * @addtogroup Media
+ * @{
+ */
+
+/**
+ * @file NdkMediaExtractor.h
+ */
 
 /*
  * This file defines an NDK API.
@@ -163,3 +171,5 @@
 __END_DECLS
 
 #endif // _NDK_MEDIA_EXTRACTOR_H
+
+/** @} */
diff --git a/media/ndk/include/media/NdkMediaFormat.h b/media/ndk/include/media/NdkMediaFormat.h
index 018ab76..6c01d35 100644
--- a/media/ndk/include/media/NdkMediaFormat.h
+++ b/media/ndk/include/media/NdkMediaFormat.h
@@ -14,6 +14,15 @@
  * limitations under the License.
  */
 
+/**
+ * @addtogroup Media
+ * @{
+ */
+
+/**
+ * @file NdkMediaFormat.h
+ */
+
 /*
  * This file defines an NDK API.
  * Do not remove methods.
@@ -110,3 +119,5 @@
 __END_DECLS
 
 #endif // _NDK_MEDIA_FORMAT_H
+
+/** @} */
diff --git a/media/ndk/include/media/NdkMediaMuxer.h b/media/ndk/include/media/NdkMediaMuxer.h
index 1ecd1ca..dc9e0ac 100644
--- a/media/ndk/include/media/NdkMediaMuxer.h
+++ b/media/ndk/include/media/NdkMediaMuxer.h
@@ -14,6 +14,14 @@
  * limitations under the License.
  */
 
+/**
+ * @addtogroup Media
+ * @{
+ */
+
+/**
+ * @file NdkMediaMuxer.h
+ */
 
 /*
  * This file defines an NDK API.
@@ -118,3 +126,5 @@
 __END_DECLS
 
 #endif // _NDK_MEDIA_MUXER_H
+
+/** @} */
diff --git a/services/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cpp
index 91f4d37..fbc17c8 100644
--- a/services/audioflinger/AudioFlinger.cpp
+++ b/services/audioflinger/AudioFlinger.cpp
@@ -39,8 +39,8 @@
 #include <memunreachable/memunreachable.h>
 #include <utils/String16.h>
 #include <utils/threads.h>
-#include <utils/Atomic.h>
 
+#include <cutils/atomic.h>
 #include <cutils/properties.h>
 
 #include <system/audio.h>
@@ -3041,16 +3041,21 @@
         bool pinned = (sessionId > AUDIO_SESSION_OUTPUT_MIX) && isSessionAcquired_l(sessionId);
         handle = thread->createEffect_l(client, effectClient, priority, sessionId,
                 &desc, enabled, &lStatus, pinned);
-        if (handle != 0 && id != NULL) {
-            *id = handle->id();
-        }
-        if (handle == 0) {
+        if (lStatus != NO_ERROR && lStatus != ALREADY_EXISTS) {
             // remove local strong reference to Client with mClientLock held
             Mutex::Autolock _cl(mClientLock);
             client.clear();
+        } else {
+            // handle must be valid here, but check again to be safe.
+            if (handle.get() != nullptr && id != nullptr) *id = handle->id();
         }
     }
 
+    if (lStatus != NO_ERROR && lStatus != ALREADY_EXISTS) {
+        // handle must be cleared outside lock.
+        handle.clear();
+    }
+
 Exit:
     *status = lStatus;
     return handle;
diff --git a/services/audioflinger/AudioFlinger.h b/services/audioflinger/AudioFlinger.h
index 63898a0..c64752f 100644
--- a/services/audioflinger/AudioFlinger.h
+++ b/services/audioflinger/AudioFlinger.h
@@ -27,6 +27,7 @@
 
 #include <android-base/macros.h>
 
+#include <cutils/atomic.h>
 #include <cutils/compiler.h>
 #include <cutils/properties.h>
 
@@ -39,7 +40,6 @@
 #include <media/MmapStreamInterface.h>
 #include <media/MmapStreamCallback.h>
 
-#include <utils/Atomic.h>
 #include <utils/Errors.h>
 #include <utils/threads.h>
 #include <utils/SortedVector.h>
diff --git a/services/audioflinger/Threads.cpp b/services/audioflinger/Threads.cpp
index 2aa14e6..e78445e 100644
--- a/services/audioflinger/Threads.cpp
+++ b/services/audioflinger/Threads.cpp
@@ -1354,7 +1354,7 @@
         if (chainCreated) {
             removeEffectChain_l(chain);
         }
-        handle.clear();
+        // handle must be cleared by caller to avoid deadlock.
     }
 
     *status = lStatus;
diff --git a/services/audiopolicy/common/managerdefinitions/include/AudioOutputDescriptor.h b/services/audiopolicy/common/managerdefinitions/include/AudioOutputDescriptor.h
index c09cb5a..3726c06 100644
--- a/services/audiopolicy/common/managerdefinitions/include/AudioOutputDescriptor.h
+++ b/services/audiopolicy/common/managerdefinitions/include/AudioOutputDescriptor.h
@@ -179,6 +179,16 @@
      */
     audio_io_handle_t getA2dpOutput() const;
 
+    /**
+     * returns true if primary HAL supports A2DP Offload
+     */
+    bool isA2dpOffloadedOnPrimary() const;
+
+    /**
+     * returns true if A2DP is supported (either via hardware offload or software encoding)
+     */
+    bool isA2dpSupported() const;
+
     sp<SwAudioOutputDescriptor> getOutputFromId(audio_port_handle_t id) const;
 
     sp<SwAudioOutputDescriptor> getPrimaryOutput() const;
diff --git a/services/audiopolicy/common/managerdefinitions/src/AudioOutputDescriptor.cpp b/services/audiopolicy/common/managerdefinitions/src/AudioOutputDescriptor.cpp
index 8593444..3819af8 100644
--- a/services/audiopolicy/common/managerdefinitions/src/AudioOutputDescriptor.cpp
+++ b/services/audiopolicy/common/managerdefinitions/src/AudioOutputDescriptor.cpp
@@ -486,6 +486,29 @@
     return 0;
 }
 
+bool SwAudioOutputCollection::isA2dpOffloadedOnPrimary() const
+{
+    sp<SwAudioOutputDescriptor> primaryOutput = getPrimaryOutput();
+
+    if ((primaryOutput != NULL) && (primaryOutput->mProfile != NULL)
+        && (primaryOutput->mProfile->mModule != NULL)) {
+        sp<HwModule> primaryHwModule = primaryOutput->mProfile->mModule;
+        Vector <sp<IOProfile>> primaryHwModuleOutputProfiles =
+                                   primaryHwModule->getOutputProfiles();
+        for (size_t i = 0; i < primaryHwModuleOutputProfiles.size(); i++) {
+            if (primaryHwModuleOutputProfiles[i]->supportDevice(AUDIO_DEVICE_OUT_ALL_A2DP)) {
+                return true;
+            }
+        }
+    }
+    return false;
+}
+
+bool SwAudioOutputCollection::isA2dpSupported() const
+{
+    return (isA2dpOffloadedOnPrimary() || (getA2dpOutput() != 0));
+}
+
 sp<SwAudioOutputDescriptor> SwAudioOutputCollection::getPrimaryOutput() const
 {
     for (size_t i = 0; i < size(); i++) {
diff --git a/services/audiopolicy/enginedefault/src/Engine.cpp b/services/audiopolicy/enginedefault/src/Engine.cpp
index 9bdb98c..43205a2 100644
--- a/services/audiopolicy/enginedefault/src/Engine.cpp
+++ b/services/audiopolicy/enginedefault/src/Engine.cpp
@@ -347,7 +347,7 @@
             // when not in a phone call, phone strategy should route STREAM_VOICE_CALL to A2DP
             if (!isInCall() &&
                     (mForceUse[AUDIO_POLICY_FORCE_FOR_MEDIA] != AUDIO_POLICY_FORCE_NO_BT_A2DP) &&
-                    (outputs.getA2dpOutput() != 0)) {
+                     outputs.isA2dpSupported()) {
                 device = availableOutputDevicesType & AUDIO_DEVICE_OUT_BLUETOOTH_A2DP;
                 if (device) break;
                 device = availableOutputDevicesType & AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES;
@@ -381,7 +381,7 @@
             // A2DP speaker when forcing to speaker output
             if (!isInCall() &&
                     (mForceUse[AUDIO_POLICY_FORCE_FOR_MEDIA] != AUDIO_POLICY_FORCE_NO_BT_A2DP) &&
-                    (outputs.getA2dpOutput() != 0)) {
+                     outputs.isA2dpSupported()) {
                 device = availableOutputDevicesType & AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER;
                 if (device) break;
             }
@@ -491,7 +491,7 @@
         }
         if ((device2 == AUDIO_DEVICE_NONE) &&
                 (mForceUse[AUDIO_POLICY_FORCE_FOR_MEDIA] != AUDIO_POLICY_FORCE_NO_BT_A2DP) &&
-                (outputs.getA2dpOutput() != 0)) {
+                 outputs.isA2dpSupported()) {
             device2 = availableOutputDevicesType & AUDIO_DEVICE_OUT_BLUETOOTH_A2DP;
             if (device2 == AUDIO_DEVICE_NONE) {
                 device2 = availableOutputDevicesType & AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES;
diff --git a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
index bdfaf2f..b646c8e 100644
--- a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
+++ b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
@@ -26,6 +26,8 @@
 
 #define AUDIO_POLICY_XML_CONFIG_FILE_PATH_MAX_LENGTH 128
 #define AUDIO_POLICY_XML_CONFIG_FILE_NAME "audio_policy_configuration.xml"
+#define AUDIO_POLICY_A2DP_OFFLOAD_DISABLED_XML_CONFIG_FILE_NAME \
+        "audio_policy_configuration_a2dp_offload_disabled.xml"
 
 #include <inttypes.h>
 #include <math.h>
@@ -1338,6 +1340,11 @@
         }
     }
 
+    if (stream == AUDIO_STREAM_ENFORCED_AUDIBLE &&
+            mEngine->getForceUse(AUDIO_POLICY_FORCE_FOR_SYSTEM) == AUDIO_POLICY_FORCE_SYSTEM_ENFORCED) {
+        setStrategyMute(STRATEGY_SONIFICATION, true, outputDesc);
+    }
+
     return NO_ERROR;
 }
 
@@ -1433,6 +1440,12 @@
             // update the outputs if stopping one with a stream that can affect notification routing
             handleNotificationRoutingForStream(stream);
         }
+
+        if (stream == AUDIO_STREAM_ENFORCED_AUDIBLE &&
+                mEngine->getForceUse(AUDIO_POLICY_FORCE_FOR_SYSTEM) == AUDIO_POLICY_FORCE_SYSTEM_ENFORCED) {
+            setStrategyMute(STRATEGY_SONIFICATION, false, outputDesc);
+        }
+
         if (stream == AUDIO_STREAM_MUSIC) {
             selectOutputForMusicEffects();
         }
@@ -3561,18 +3574,25 @@
 
 static status_t deserializeAudioPolicyXmlConfig(AudioPolicyConfig &config) {
     char audioPolicyXmlConfigFile[AUDIO_POLICY_XML_CONFIG_FILE_PATH_MAX_LENGTH];
+    std::vector<const char*> fileNames;
     status_t ret;
 
-    for (int i = 0; i < kConfigLocationListSize; i++) {
-        PolicySerializer serializer;
-        snprintf(audioPolicyXmlConfigFile,
-                 sizeof(audioPolicyXmlConfigFile),
-                 "%s/%s",
-                 kConfigLocationList[i],
-                 AUDIO_POLICY_XML_CONFIG_FILE_NAME);
-        ret = serializer.deserialize(audioPolicyXmlConfigFile, config);
-        if (ret == NO_ERROR) {
-            break;
+    if (property_get_bool("ro.bluetooth.a2dp_offload.supported", false) &&
+        property_get_bool("persist.bluetooth.a2dp_offload.disabled", false)) {
+        // A2DP offload supported but disabled: try to use special XML file
+        fileNames.push_back(AUDIO_POLICY_A2DP_OFFLOAD_DISABLED_XML_CONFIG_FILE_NAME);
+    }
+    fileNames.push_back(AUDIO_POLICY_XML_CONFIG_FILE_NAME);
+
+    for (const char* fileName : fileNames) {
+        for (int i = 0; i < kConfigLocationListSize; i++) {
+            PolicySerializer serializer;
+            snprintf(audioPolicyXmlConfigFile, sizeof(audioPolicyXmlConfigFile),
+                     "%s/%s", kConfigLocationList[i], fileName);
+            ret = serializer.deserialize(audioPolicyXmlConfigFile, config);
+            if (ret == NO_ERROR) {
+                return ret;
+            }
         }
     }
     return ret;
@@ -4666,7 +4686,7 @@
 void AudioPolicyManager::checkA2dpSuspend()
 {
     audio_io_handle_t a2dpOutput = mOutputs.getA2dpOutput();
-    if (a2dpOutput == 0) {
+    if (a2dpOutput == 0 || mOutputs.isA2dpOffloadedOnPrimary()) {
         mA2dpSuspended = false;
         return;
     }
diff --git a/services/camera/libcameraservice/api1/client2/Parameters.cpp b/services/camera/libcameraservice/api1/client2/Parameters.cpp
index 050c3f7..0380779 100644
--- a/services/camera/libcameraservice/api1/client2/Parameters.cpp
+++ b/services/camera/libcameraservice/api1/client2/Parameters.cpp
@@ -1198,6 +1198,35 @@
 
     fastInfo.maxJpegSize = getMaxSize(getAvailableJpegSizes());
 
+    isZslReprocessPresent = false;
+    camera_metadata_ro_entry_t availableCapabilities =
+        staticInfo(ANDROID_REQUEST_AVAILABLE_CAPABILITIES);
+    if (0 < availableCapabilities.count) {
+        const uint8_t *caps = availableCapabilities.data.u8;
+        for (size_t i = 0; i < availableCapabilities.count; i++) {
+            if (ANDROID_REQUEST_AVAILABLE_CAPABILITIES_PRIVATE_REPROCESSING ==
+                caps[i]) {
+                isZslReprocessPresent = true;
+                break;
+            }
+        }
+    }
+    if (isZslReprocessPresent) {
+        Vector<StreamConfiguration> scs = getStreamConfigurations();
+        Size maxPrivInputSize = {0, 0};
+        for (const auto& sc : scs) {
+            if (sc.isInput == ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS_INPUT &&
+                    sc.format == HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED) {
+                if (sc.width * sc.height > maxPrivInputSize.width * maxPrivInputSize.height) {
+                    maxPrivInputSize = {sc.width, sc.height};
+                }
+            }
+        }
+        fastInfo.maxZslSize = maxPrivInputSize;
+    } else {
+        fastInfo.maxZslSize = {0, 0};
+    }
+
     return OK;
 }
 
diff --git a/services/camera/libcameraservice/api1/client2/Parameters.h b/services/camera/libcameraservice/api1/client2/Parameters.h
index 17e3d75..c333641 100644
--- a/services/camera/libcameraservice/api1/client2/Parameters.h
+++ b/services/camera/libcameraservice/api1/client2/Parameters.h
@@ -236,6 +236,7 @@
         float minFocalLength;
         bool useFlexibleYuv;
         Size maxJpegSize;
+        Size maxZslSize;
     } fastInfo;
 
     // Quirks information; these are short-lived flags to enable workarounds for
diff --git a/services/camera/libcameraservice/api1/client2/ZslProcessor.cpp b/services/camera/libcameraservice/api1/client2/ZslProcessor.cpp
index b0607fb..5be6134 100644
--- a/services/camera/libcameraservice/api1/client2/ZslProcessor.cpp
+++ b/services/camera/libcameraservice/api1/client2/ZslProcessor.cpp
@@ -231,63 +231,9 @@
         return INVALID_OPERATION;
     }
 
-    if ((mZslStreamId != NO_STREAM) || (mInputStreamId != NO_STREAM)) {
-        // Check if stream parameters have to change
-        CameraDeviceBase::StreamInfo streamInfo;
-        res = device->getStreamInfo(mZslStreamId, &streamInfo);
-        if (res != OK) {
-            ALOGE("%s: Camera %d: Error querying capture output stream info: "
-                    "%s (%d)", __FUNCTION__,
-                    client->getCameraId(), strerror(-res), res);
-            return res;
-        }
-        if (streamInfo.width != (uint32_t)params.fastInfo.arrayWidth ||
-                streamInfo.height != (uint32_t)params.fastInfo.arrayHeight) {
-            if (mZslStreamId != NO_STREAM) {
-                ALOGV("%s: Camera %d: Deleting stream %d since the buffer "
-                      "dimensions changed",
-                    __FUNCTION__, client->getCameraId(), mZslStreamId);
-                res = device->deleteStream(mZslStreamId);
-                if (res == -EBUSY) {
-                    ALOGV("%s: Camera %d: Device is busy, call updateStream again "
-                          " after it becomes idle", __FUNCTION__, mId);
-                    return res;
-                } else if(res != OK) {
-                    ALOGE("%s: Camera %d: Unable to delete old output stream "
-                            "for ZSL: %s (%d)", __FUNCTION__,
-                            client->getCameraId(), strerror(-res), res);
-                    return res;
-                }
-                mZslStreamId = NO_STREAM;
-            }
-
-            if (mInputStreamId != NO_STREAM) {
-                ALOGV("%s: Camera %d: Deleting stream %d since the buffer "
-                      "dimensions changed",
-                    __FUNCTION__, client->getCameraId(), mInputStreamId);
-                res = device->deleteStream(mInputStreamId);
-                if (res == -EBUSY) {
-                    ALOGV("%s: Camera %d: Device is busy, call updateStream again "
-                          " after it becomes idle", __FUNCTION__, mId);
-                    return res;
-                } else if(res != OK) {
-                    ALOGE("%s: Camera %d: Unable to delete old output stream "
-                            "for ZSL: %s (%d)", __FUNCTION__,
-                            client->getCameraId(), strerror(-res), res);
-                    return res;
-                }
-                mInputStreamId = NO_STREAM;
-            }
-            if (nullptr != mInputProducer.get()) {
-                mInputProducer->disconnect(NATIVE_WINDOW_API_CPU);
-                mInputProducer.clear();
-            }
-        }
-    }
-
     if (mInputStreamId == NO_STREAM) {
-        res = device->createInputStream(params.fastInfo.arrayWidth,
-            params.fastInfo.arrayHeight, HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED,
+        res = device->createInputStream(params.fastInfo.maxZslSize.width,
+            params.fastInfo.maxZslSize.height, HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED,
             &mInputStreamId);
         if (res != OK) {
             ALOGE("%s: Camera %d: Can't create input stream: "
@@ -309,8 +255,8 @@
         mProducer->setName(String8("Camera2-ZslRingBufferConsumer"));
         sp<Surface> outSurface = new Surface(producer);
 
-        res = device->createStream(outSurface, params.fastInfo.arrayWidth,
-            params.fastInfo.arrayHeight, HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED,
+        res = device->createStream(outSurface, params.fastInfo.maxZslSize.width,
+            params.fastInfo.maxZslSize.height, HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED,
             HAL_DATASPACE_UNKNOWN, CAMERA3_STREAM_ROTATION_0, &mZslStreamId);
         if (res != OK) {
             ALOGE("%s: Camera %d: Can't create ZSL stream: "
diff --git a/services/mediaanalytics/Android.mk b/services/mediaanalytics/Android.mk
index 9e2813e..735a63f 100644
--- a/services/mediaanalytics/Android.mk
+++ b/services/mediaanalytics/Android.mk
@@ -39,8 +39,7 @@
     $(TOP)/frameworks/av/include/camera                             \
     $(TOP)/frameworks/native/include/media/openmax                  \
     $(TOP)/frameworks/native/include/media/hardware                 \
-    $(TOP)/external/tremolo/Tremolo                                 \
-    libcore/include
+    $(TOP)/external/tremolo/Tremolo
 
 
 LOCAL_MODULE:= mediametrics
diff --git a/services/mediaextractor/Android.mk b/services/mediaextractor/Android.mk
index d41da39..3b883e7 100644
--- a/services/mediaextractor/Android.mk
+++ b/services/mediaextractor/Android.mk
@@ -26,7 +26,7 @@
 include $(BUILD_EXECUTABLE)
 
 # service seccomp filter
-ifeq ($(TARGET_ARCH), $(filter $(TARGET_ARCH), arm arm64 x86))
+ifeq ($(TARGET_ARCH), $(filter $(TARGET_ARCH), arm arm64 x86 x86_64))
 include $(CLEAR_VARS)
 LOCAL_MODULE := mediaextractor.policy
 LOCAL_MODULE_CLASS := ETC
diff --git a/services/mediaextractor/seccomp_policy/mediaextractor-x86_64.policy b/services/mediaextractor/seccomp_policy/mediaextractor-x86_64.policy
new file mode 100755
index 0000000..63c7780
--- /dev/null
+++ b/services/mediaextractor/seccomp_policy/mediaextractor-x86_64.policy
@@ -0,0 +1,57 @@
+# Organized by frequency of systemcall - in descending order for
+# best performance.
+ioctl: 1
+futex: 1
+prctl: 1
+write: 1
+getpriority: 1
+close: 1
+dup: 1
+munmap: 1
+mmap: 1
+madvise: 1
+openat: 1
+clock_gettime: 1
+writev: 1
+brk: 1
+mprotect: 1
+read: 1
+lseek: 1
+clone: 1
+getuid: 1
+setpriority: 1
+sigaltstack: 1
+newfstatat: 1
+restart_syscall: 1
+exit: 1
+exit_group: 1
+rt_sigreturn: 1
+faccessat: 1
+sched_setscheduler: 1
+getrlimit: 1
+nanosleep: 1
+
+# for FileSource
+readlinkat: 1
+
+# for attaching to debuggerd on process crash
+tgkill: 1
+socket: arg0 == 1
+connect: 1
+fcntl: 1
+rt_sigprocmask: 1
+rt_sigaction: 1
+rt_tgsigqueueinfo: 1
+geteuid: 1
+getgid: 1
+getegid: 1
+getgroups: 1
+getdents64: 1
+pipe2: 1
+ppoll: 1
+
+# Required by AddressSanitizer
+gettid: 1
+sched_yield: 1
+getpid: 1
+gettid: 1