Merge "Enable EOSTest_M test" into oc-mr1-dev
diff --git a/camera/Android.bp b/camera/Android.bp
index 83a2803..0240751 100644
--- a/camera/Android.bp
+++ b/camera/Android.bp
@@ -7,6 +7,7 @@
     "device/3.2",
     "device/3.2/default",
     "device/3.3",
+    "device/3.3/default",
     "metadata/3.2",
     "provider/2.4",
     "provider/2.4/default",
diff --git a/camera/device/3.2/default/CameraDevice.cpp b/camera/device/3.2/default/CameraDevice.cpp
index 637a1e6..295ee32 100644
--- a/camera/device/3.2/default/CameraDevice.cpp
+++ b/camera/device/3.2/default/CameraDevice.cpp
@@ -177,7 +177,7 @@
     if (callback == nullptr) {
         ALOGE("%s: cannot open camera %s. callback is null!",
                 __FUNCTION__, mCameraId.c_str());
-        _hidl_cb(Status::ILLEGAL_ARGUMENT, session);
+        _hidl_cb(Status::ILLEGAL_ARGUMENT, nullptr);
         return Void();
     }
 
@@ -186,7 +186,7 @@
         // this must be a disconnected camera
         ALOGE("%s: cannot open camera %s. camera is disconnected!",
                 __FUNCTION__, mCameraId.c_str());
-        _hidl_cb(Status::CAMERA_DISCONNECTED, session);
+        _hidl_cb(Status::CAMERA_DISCONNECTED, nullptr);
         return Void();
     } else {
         mLock.lock();
@@ -239,7 +239,7 @@
             return Void();
         }
 
-        session = new CameraDeviceSession(
+        session = createSession(
                 device, info.static_camera_characteristics, callback);
         if (session == nullptr) {
             ALOGE("%s: camera device session allocation failed", __FUNCTION__);
@@ -255,9 +255,19 @@
             return Void();
         }
         mSession = session;
+
+        IF_ALOGV() {
+            session->getInterface()->interfaceChain([](
+                ::android::hardware::hidl_vec<::android::hardware::hidl_string> interfaceChain) {
+                    ALOGV("Session interface chain:");
+                    for (auto iface : interfaceChain) {
+                        ALOGV("  %s", iface.c_str());
+                    }
+                });
+        }
         mLock.unlock();
     }
-    _hidl_cb(status, session);
+    _hidl_cb(status, session->getInterface());
     return Void();
 }
 
@@ -286,6 +296,13 @@
     session->dumpState(handle);
     return Void();
 }
+
+sp<CameraDeviceSession> CameraDevice::createSession(camera3_device_t* device,
+        const camera_metadata_t* deviceInfo,
+        const sp<ICameraDeviceCallback>& callback) {
+    return new CameraDeviceSession(device, deviceInfo, callback);
+}
+
 // End of methods from ::android::hardware::camera::device::V3_2::ICameraDevice.
 
 } // namespace implementation
diff --git a/camera/device/3.2/default/CameraDeviceSession.cpp b/camera/device/3.2/default/CameraDeviceSession.cpp
index fcd134f..d6a04bc 100644
--- a/camera/device/3.2/default/CameraDeviceSession.cpp
+++ b/camera/device/3.2/default/CameraDeviceSession.cpp
@@ -49,7 +49,6 @@
         mDerivePostRawSensKey(false),
         mNumPartialResults(1),
         mResultBatcher(callback) {
-
     mDeviceInfo = deviceInfo;
     camera_metadata_entry partialResultsCount =
             mDeviceInfo.find(ANDROID_REQUEST_PARTIAL_RESULT_COUNT);
@@ -328,7 +327,8 @@
     mStreamsToBatch = streamsToBatch;
 }
 
-void CameraDeviceSession::ResultBatcher::setResultMetadataQueue(std::shared_ptr<ResultMetadataQueue> q) {
+void CameraDeviceSession::ResultBatcher::setResultMetadataQueue(
+        std::shared_ptr<ResultMetadataQueue> q) {
     Mutex::Autolock _l(mLock);
     mResultMetadataQueue = q;
 }
@@ -387,7 +387,8 @@
     }
 }
 
-void CameraDeviceSession::ResultBatcher::sendBatchShutterCbsLocked(std::shared_ptr<InflightBatch> batch) {
+void CameraDeviceSession::ResultBatcher::sendBatchShutterCbsLocked(
+        std::shared_ptr<InflightBatch> batch) {
     if (batch->mShutterDelivered) {
         ALOGW("%s: batch shutter callback already sent!", __FUNCTION__);
         return;
@@ -441,7 +442,8 @@
     }
 }
 
-void CameraDeviceSession::ResultBatcher::sendBatchBuffersLocked(std::shared_ptr<InflightBatch> batch) {
+void CameraDeviceSession::ResultBatcher::sendBatchBuffersLocked(
+        std::shared_ptr<InflightBatch> batch) {
     sendBatchBuffersLocked(batch, mStreamsToBatch);
 }
 
@@ -736,7 +738,7 @@
 
 // Methods from ::android::hardware::camera::device::V3_2::ICameraDeviceSession follow.
 Return<void> CameraDeviceSession::constructDefaultRequestSettings(
-        RequestTemplate type, constructDefaultRequestSettings_cb _hidl_cb)  {
+        RequestTemplate type, ICameraDeviceSession::constructDefaultRequestSettings_cb _hidl_cb)  {
     Status status = initStatus();
     CameraMetadata outMetadata;
     const camera_metadata_t *rawRequest;
@@ -802,7 +804,8 @@
 }
 
 Return<void> CameraDeviceSession::configureStreams(
-        const StreamConfiguration& requestedConfiguration, configureStreams_cb _hidl_cb)  {
+        const StreamConfiguration& requestedConfiguration,
+        ICameraDeviceSession::configureStreams_cb _hidl_cb)  {
     Status status = initStatus();
     HalStreamConfiguration outStreams;
 
@@ -960,13 +963,13 @@
 }
 
 Return<void> CameraDeviceSession::getCaptureRequestMetadataQueue(
-    getCaptureRequestMetadataQueue_cb _hidl_cb) {
+    ICameraDeviceSession::getCaptureRequestMetadataQueue_cb _hidl_cb) {
     _hidl_cb(*mRequestMetadataQueue->getDesc());
     return Void();
 }
 
 Return<void> CameraDeviceSession::getCaptureResultMetadataQueue(
-    getCaptureResultMetadataQueue_cb _hidl_cb) {
+    ICameraDeviceSession::getCaptureResultMetadataQueue_cb _hidl_cb) {
     _hidl_cb(*mResultMetadataQueue->getDesc());
     return Void();
 }
@@ -974,7 +977,7 @@
 Return<void> CameraDeviceSession::processCaptureRequest(
         const hidl_vec<CaptureRequest>& requests,
         const hidl_vec<BufferCache>& cachesToRemove,
-        processCaptureRequest_cb _hidl_cb)  {
+        ICameraDeviceSession::processCaptureRequest_cb _hidl_cb)  {
     updateBufferCaches(cachesToRemove);
 
     uint32_t numRequestProcessed = 0;
diff --git a/camera/device/3.2/default/CameraDeviceSession.h b/camera/device/3.2/default/CameraDeviceSession.h
index 2fe189f..69e2e2c 100644
--- a/camera/device/3.2/default/CameraDeviceSession.h
+++ b/camera/device/3.2/default/CameraDeviceSession.h
@@ -55,6 +55,8 @@
 using ::android::sp;
 using ::android::Mutex;
 
+struct Camera3Stream;
+
 /**
  * Function pointer types with C calling convention to
  * use for HAL callback functions.
@@ -69,12 +71,12 @@
         const camera3_notify_msg_t *);
 }
 
-struct CameraDeviceSession : public ICameraDeviceSession, private camera3_callback_ops  {
+struct CameraDeviceSession : public virtual RefBase, protected camera3_callback_ops  {
 
     CameraDeviceSession(camera3_device_t*,
                         const camera_metadata_t* deviceInfo,
                         const sp<ICameraDeviceCallback>&);
-    ~CameraDeviceSession();
+    virtual ~CameraDeviceSession();
     // Call by CameraDevice to dump active device states
     void dumpState(const native_handle_t* fd);
     // Caller must use this method to check if CameraDeviceSession ctor failed
@@ -83,23 +85,35 @@
     void disconnect();
     bool isClosed();
 
-    // Methods from ::android::hardware::camera::device::V3_2::ICameraDeviceSession follow.
+    // Retrieve the HIDL interface, split into its own class to avoid inheritance issues when
+    // dealing with minor version revs and simultaneous implementation and interface inheritance
+    virtual sp<ICameraDeviceSession> getInterface() {
+        return new TrampolineSessionInterface_3_2(this);
+    }
+
+protected:
+
+    // Methods from ::android::hardware::camera::device::V3_2::ICameraDeviceSession follow
+
     Return<void> constructDefaultRequestSettings(
-            RequestTemplate type, constructDefaultRequestSettings_cb _hidl_cb) override;
+            RequestTemplate type,
+            ICameraDeviceSession::constructDefaultRequestSettings_cb _hidl_cb);
     Return<void> configureStreams(
-            const StreamConfiguration& requestedConfiguration, configureStreams_cb _hidl_cb) override;
+            const StreamConfiguration& requestedConfiguration,
+            ICameraDeviceSession::configureStreams_cb _hidl_cb);
     Return<void> getCaptureRequestMetadataQueue(
-        getCaptureRequestMetadataQueue_cb _hidl_cb) override;
+        ICameraDeviceSession::getCaptureRequestMetadataQueue_cb _hidl_cb);
     Return<void> getCaptureResultMetadataQueue(
-        getCaptureResultMetadataQueue_cb _hidl_cb) override;
+        ICameraDeviceSession::getCaptureResultMetadataQueue_cb _hidl_cb);
     Return<void> processCaptureRequest(
             const hidl_vec<CaptureRequest>& requests,
             const hidl_vec<BufferCache>& cachesToRemove,
-            processCaptureRequest_cb _hidl_cb) override;
-    Return<Status> flush() override;
-    Return<void> close() override;
+            ICameraDeviceSession::processCaptureRequest_cb _hidl_cb);
+    Return<Status> flush();
+    Return<void> close();
 
-private:
+protected:
+
     // protecting mClosed/mDisconnected/mInitFail
     mutable Mutex mStateLock;
     // device is closed either
@@ -302,6 +316,52 @@
      */
     static callbacks_process_capture_result_t sProcessCaptureResult;
     static callbacks_notify_t sNotify;
+
+private:
+
+    struct TrampolineSessionInterface_3_2 : public ICameraDeviceSession {
+        TrampolineSessionInterface_3_2(sp<CameraDeviceSession> parent) :
+                mParent(parent) {}
+
+        virtual Return<void> constructDefaultRequestSettings(
+                V3_2::RequestTemplate type,
+                V3_2::ICameraDeviceSession::constructDefaultRequestSettings_cb _hidl_cb) override {
+            return mParent->constructDefaultRequestSettings(type, _hidl_cb);
+        }
+
+        virtual Return<void> configureStreams(
+                const V3_2::StreamConfiguration& requestedConfiguration,
+                V3_2::ICameraDeviceSession::configureStreams_cb _hidl_cb) override {
+            return mParent->configureStreams(requestedConfiguration, _hidl_cb);
+        }
+
+        virtual Return<void> processCaptureRequest(const hidl_vec<V3_2::CaptureRequest>& requests,
+                const hidl_vec<V3_2::BufferCache>& cachesToRemove,
+                V3_2::ICameraDeviceSession::processCaptureRequest_cb _hidl_cb) override {
+            return mParent->processCaptureRequest(requests, cachesToRemove, _hidl_cb);
+        }
+
+        virtual Return<void> getCaptureRequestMetadataQueue(
+                V3_2::ICameraDeviceSession::getCaptureRequestMetadataQueue_cb _hidl_cb) override  {
+            return mParent->getCaptureRequestMetadataQueue(_hidl_cb);
+        }
+
+        virtual Return<void> getCaptureResultMetadataQueue(
+                V3_2::ICameraDeviceSession::getCaptureResultMetadataQueue_cb _hidl_cb) override  {
+            return mParent->getCaptureResultMetadataQueue(_hidl_cb);
+        }
+
+        virtual Return<Status> flush() override {
+            return mParent->flush();
+        }
+
+        virtual Return<void> close() override {
+            return mParent->close();
+        }
+
+    private:
+        sp<CameraDeviceSession> mParent;
+    };
 };
 
 }  // namespace implementation
diff --git a/camera/device/3.2/default/CameraDevice_3_2.h b/camera/device/3.2/default/CameraDevice_3_2.h
index 4e86067..9534707 100644
--- a/camera/device/3.2/default/CameraDevice_3_2.h
+++ b/camera/device/3.2/default/CameraDevice_3_2.h
@@ -80,7 +80,13 @@
     Return<void> dumpState(const ::android::hardware::hidl_handle& fd) override;
     /* End of Methods from ::android::hardware::camera::device::V3_2::ICameraDevice */
 
-private:
+protected:
+
+    // Overridden by child implementations for returning different versions of CameraDeviceSession
+    virtual sp<CameraDeviceSession> createSession(camera3_device_t*,
+            const camera_metadata_t* deviceInfo,
+            const sp<ICameraDeviceCallback>&);
+
     const sp<CameraModule> mModule;
     const std::string mCameraId;
     // const after ctor
diff --git a/camera/device/3.3/default/Android.bp b/camera/device/3.3/default/Android.bp
new file mode 100644
index 0000000..b1e9b46
--- /dev/null
+++ b/camera/device/3.3/default/Android.bp
@@ -0,0 +1,30 @@
+cc_library_shared {
+    name: "camera.device@3.3-impl",
+    defaults: ["hidl_defaults"],
+    proprietary: true,
+    srcs: ["CameraDevice.cpp",
+           "CameraDeviceSession.cpp",
+           "convert.cpp"],
+    shared_libs: [
+        "libhidlbase",
+        "libhidltransport",
+        "libutils",
+        "libcutils",
+        "camera.device@3.2-impl",
+        "android.hardware.camera.device@3.2",
+        "android.hardware.camera.device@3.3",
+        "android.hardware.camera.provider@2.4",
+        "android.hardware.graphics.mapper@2.0",
+        "liblog",
+        "libhardware",
+        "libcamera_metadata",
+        "libfmq"
+    ],
+    static_libs: [
+        "android.hardware.camera.common@1.0-helper"
+    ],
+    export_include_dirs: ["."],
+    export_shared_lib_headers: [
+        "libfmq",
+    ]
+}
diff --git a/camera/device/3.3/default/CameraDevice.cpp b/camera/device/3.3/default/CameraDevice.cpp
new file mode 100644
index 0000000..ce5e1de
--- /dev/null
+++ b/camera/device/3.3/default/CameraDevice.cpp
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2017 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 "CamDev@3.3-impl"
+#include <log/log.h>
+
+#include <utils/Vector.h>
+#include <utils/Trace.h>
+#include "CameraDevice_3_3.h"
+#include <include/convert.h>
+
+namespace android {
+namespace hardware {
+namespace camera {
+namespace device {
+namespace V3_3 {
+namespace implementation {
+
+using ::android::hardware::camera::common::V1_0::Status;
+using namespace ::android::hardware::camera::device;
+
+CameraDevice::CameraDevice(
+    sp<CameraModule> module, const std::string& cameraId,
+    const SortedVector<std::pair<std::string, std::string>>& cameraDeviceNames) :
+        V3_2::implementation::CameraDevice(module, cameraId, cameraDeviceNames) {
+}
+
+CameraDevice::~CameraDevice() {
+}
+
+sp<V3_2::implementation::CameraDeviceSession> CameraDevice::createSession(camera3_device_t* device,
+        const camera_metadata_t* deviceInfo,
+        const sp<V3_2::ICameraDeviceCallback>& callback) {
+    sp<CameraDeviceSession> session = new CameraDeviceSession(device, deviceInfo, callback);
+    IF_ALOGV() {
+        session->getInterface()->interfaceChain([](
+            ::android::hardware::hidl_vec<::android::hardware::hidl_string> interfaceChain) {
+                ALOGV("Session interface chain:");
+                for (auto iface : interfaceChain) {
+                    ALOGV("  %s", iface.c_str());
+                }
+            });
+    }
+    return session;
+}
+
+// End of methods from ::android::hardware::camera::device::V3_2::ICameraDevice.
+
+} // namespace implementation
+}  // namespace V3_3
+}  // namespace device
+}  // namespace camera
+}  // namespace hardware
+}  // namespace android
diff --git a/camera/device/3.3/default/CameraDeviceSession.cpp b/camera/device/3.3/default/CameraDeviceSession.cpp
new file mode 100644
index 0000000..f877895
--- /dev/null
+++ b/camera/device/3.3/default/CameraDeviceSession.cpp
@@ -0,0 +1,178 @@
+/*
+ * Copyright (C) 2017 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 "CamDevSession@3.3-impl"
+#include <android/log.h>
+
+#include <set>
+#include <utils/Trace.h>
+#include <hardware/gralloc.h>
+#include <hardware/gralloc1.h>
+#include "CameraDeviceSession.h"
+
+namespace android {
+namespace hardware {
+namespace camera {
+namespace device {
+namespace V3_3 {
+namespace implementation {
+
+CameraDeviceSession::CameraDeviceSession(
+    camera3_device_t* device,
+    const camera_metadata_t* deviceInfo,
+    const sp<V3_2::ICameraDeviceCallback>& callback) :
+        V3_2::implementation::CameraDeviceSession(device, deviceInfo, callback) {
+}
+
+CameraDeviceSession::~CameraDeviceSession() {
+}
+
+Return<void> CameraDeviceSession::configureStreams_3_3(
+        const StreamConfiguration& requestedConfiguration,
+        ICameraDeviceSession::configureStreams_3_3_cb _hidl_cb)  {
+    Status status = initStatus();
+    HalStreamConfiguration outStreams;
+
+    // hold the inflight lock for entire configureStreams scope since there must not be any
+    // inflight request/results during stream configuration.
+    Mutex::Autolock _l(mInflightLock);
+    if (!mInflightBuffers.empty()) {
+        ALOGE("%s: trying to configureStreams while there are still %zu inflight buffers!",
+                __FUNCTION__, mInflightBuffers.size());
+        _hidl_cb(Status::INTERNAL_ERROR, outStreams);
+        return Void();
+    }
+
+    if (!mInflightAETriggerOverrides.empty()) {
+        ALOGE("%s: trying to configureStreams while there are still %zu inflight"
+                " trigger overrides!", __FUNCTION__,
+                mInflightAETriggerOverrides.size());
+        _hidl_cb(Status::INTERNAL_ERROR, outStreams);
+        return Void();
+    }
+
+    if (!mInflightRawBoostPresent.empty()) {
+        ALOGE("%s: trying to configureStreams while there are still %zu inflight"
+                " boost overrides!", __FUNCTION__,
+                mInflightRawBoostPresent.size());
+        _hidl_cb(Status::INTERNAL_ERROR, outStreams);
+        return Void();
+    }
+
+    if (status != Status::OK) {
+        _hidl_cb(status, outStreams);
+        return Void();
+    }
+
+    camera3_stream_configuration_t stream_list;
+    hidl_vec<camera3_stream_t*> streams;
+
+    stream_list.operation_mode = (uint32_t) requestedConfiguration.operationMode;
+    stream_list.num_streams = requestedConfiguration.streams.size();
+    streams.resize(stream_list.num_streams);
+    stream_list.streams = streams.data();
+
+    for (uint32_t i = 0; i < stream_list.num_streams; i++) {
+        int id = requestedConfiguration.streams[i].id;
+
+        if (mStreamMap.count(id) == 0) {
+            Camera3Stream stream;
+            V3_2::implementation::convertFromHidl(requestedConfiguration.streams[i], &stream);
+            mStreamMap[id] = stream;
+            mStreamMap[id].data_space = mapToLegacyDataspace(
+                    mStreamMap[id].data_space);
+            mCirculatingBuffers.emplace(stream.mId, CirculatingBuffers{});
+        } else {
+            // width/height/format must not change, but usage/rotation might need to change
+            if (mStreamMap[id].stream_type !=
+                    (int) requestedConfiguration.streams[i].streamType ||
+                    mStreamMap[id].width != requestedConfiguration.streams[i].width ||
+                    mStreamMap[id].height != requestedConfiguration.streams[i].height ||
+                    mStreamMap[id].format != (int) requestedConfiguration.streams[i].format ||
+                    mStreamMap[id].data_space !=
+                            mapToLegacyDataspace( static_cast<android_dataspace_t> (
+                                    requestedConfiguration.streams[i].dataSpace))) {
+                ALOGE("%s: stream %d configuration changed!", __FUNCTION__, id);
+                _hidl_cb(Status::INTERNAL_ERROR, outStreams);
+                return Void();
+            }
+            mStreamMap[id].rotation = (int) requestedConfiguration.streams[i].rotation;
+            mStreamMap[id].usage = (uint32_t) requestedConfiguration.streams[i].usage;
+        }
+        streams[i] = &mStreamMap[id];
+    }
+
+    ATRACE_BEGIN("camera3->configure_streams");
+    status_t ret = mDevice->ops->configure_streams(mDevice, &stream_list);
+    ATRACE_END();
+
+    // In case Hal returns error most likely it was not able to release
+    // the corresponding resources of the deleted streams.
+    if (ret == OK) {
+        // delete unused streams, note we do this after adding new streams to ensure new stream
+        // will not have the same address as deleted stream, and HAL has a chance to reference
+        // the to be deleted stream in configure_streams call
+        for(auto it = mStreamMap.begin(); it != mStreamMap.end();) {
+            int id = it->first;
+            bool found = false;
+            for (const auto& stream : requestedConfiguration.streams) {
+                if (id == stream.id) {
+                    found = true;
+                    break;
+                }
+            }
+            if (!found) {
+                // Unmap all buffers of deleted stream
+                // in case the configuration call succeeds and HAL
+                // is able to release the corresponding resources too.
+                cleanupBuffersLocked(id);
+                it = mStreamMap.erase(it);
+            } else {
+                ++it;
+            }
+        }
+
+        // Track video streams
+        mVideoStreamIds.clear();
+        for (const auto& stream : requestedConfiguration.streams) {
+            if (stream.streamType == V3_2::StreamType::OUTPUT &&
+                stream.usage &
+                    graphics::common::V1_0::BufferUsage::VIDEO_ENCODER) {
+                mVideoStreamIds.push_back(stream.id);
+            }
+        }
+        mResultBatcher.setBatchedStreams(mVideoStreamIds);
+    }
+
+    if (ret == -EINVAL) {
+        status = Status::ILLEGAL_ARGUMENT;
+    } else if (ret != OK) {
+        status = Status::INTERNAL_ERROR;
+    } else {
+        convertToHidl(stream_list, &outStreams);
+        mFirstRequest = true;
+    }
+
+    _hidl_cb(status, outStreams);
+    return Void();
+}
+
+} // namespace implementation
+}  // namespace V3_3
+}  // namespace device
+}  // namespace camera
+}  // namespace hardware
+}  // namespace android
diff --git a/camera/device/3.3/default/CameraDeviceSession.h b/camera/device/3.3/default/CameraDeviceSession.h
new file mode 100644
index 0000000..dd52b35
--- /dev/null
+++ b/camera/device/3.3/default/CameraDeviceSession.h
@@ -0,0 +1,138 @@
+/*
+ * Copyright (C) 2017 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_HARDWARE_CAMERA_DEVICE_V3_3_CAMERADEVICE3SESSION_H
+#define ANDROID_HARDWARE_CAMERA_DEVICE_V3_3_CAMERADEVICE3SESSION_H
+
+#include <android/hardware/camera/device/3.2/ICameraDevice.h>
+#include <android/hardware/camera/device/3.3/ICameraDeviceSession.h>
+#include <../../3.2/default/CameraDeviceSession.h>
+#include <fmq/MessageQueue.h>
+#include <hidl/MQDescriptor.h>
+#include <hidl/Status.h>
+#include <include/convert.h>
+#include <deque>
+#include <map>
+#include <unordered_map>
+#include "CameraMetadata.h"
+#include "HandleImporter.h"
+#include "hardware/camera3.h"
+#include "hardware/camera_common.h"
+#include "utils/Mutex.h"
+
+namespace android {
+namespace hardware {
+namespace camera {
+namespace device {
+namespace V3_3 {
+namespace implementation {
+
+using namespace ::android::hardware::camera::device;
+using ::android::hardware::camera::device::V3_2::CaptureRequest;
+using ::android::hardware::camera::device::V3_2::StreamConfiguration;
+using ::android::hardware::camera::device::V3_3::HalStreamConfiguration;
+using ::android::hardware::camera::device::V3_3::ICameraDeviceSession;
+using ::android::hardware::camera::common::V1_0::Status;
+using ::android::hardware::camera::common::V1_0::helper::HandleImporter;
+using ::android::hardware::kSynchronizedReadWrite;
+using ::android::hardware::MessageQueue;
+using ::android::hardware::MQDescriptorSync;
+using ::android::hardware::Return;
+using ::android::hardware::Void;
+using ::android::hardware::hidl_vec;
+using ::android::hardware::hidl_string;
+using ::android::sp;
+using ::android::Mutex;
+
+struct CameraDeviceSession : public V3_2::implementation::CameraDeviceSession {
+
+    CameraDeviceSession(camera3_device_t*,
+            const camera_metadata_t* deviceInfo,
+            const sp<V3_2::ICameraDeviceCallback>&);
+    virtual ~CameraDeviceSession();
+
+    virtual sp<V3_2::ICameraDeviceSession> getInterface() override {
+        return new TrampolineSessionInterface_3_3(this);
+    }
+
+protected:
+    // Methods from v3.2 and earlier will trampoline to inherited implementation
+
+    // New methods for v3.3
+
+    Return<void> configureStreams_3_3(
+            const StreamConfiguration& requestedConfiguration,
+            ICameraDeviceSession::configureStreams_3_3_cb _hidl_cb);
+private:
+
+    struct TrampolineSessionInterface_3_3 : public ICameraDeviceSession {
+        TrampolineSessionInterface_3_3(sp<CameraDeviceSession> parent) :
+                mParent(parent) {}
+
+        virtual Return<void> constructDefaultRequestSettings(
+                V3_2::RequestTemplate type,
+                V3_3::ICameraDeviceSession::constructDefaultRequestSettings_cb _hidl_cb) override {
+            return mParent->constructDefaultRequestSettings(type, _hidl_cb);
+        }
+
+        virtual Return<void> configureStreams(
+                const V3_2::StreamConfiguration& requestedConfiguration,
+                V3_3::ICameraDeviceSession::configureStreams_cb _hidl_cb) override {
+            return mParent->configureStreams(requestedConfiguration, _hidl_cb);
+        }
+
+        virtual Return<void> processCaptureRequest(const hidl_vec<V3_2::CaptureRequest>& requests,
+                const hidl_vec<V3_2::BufferCache>& cachesToRemove,
+                V3_3::ICameraDeviceSession::processCaptureRequest_cb _hidl_cb) override {
+            return mParent->processCaptureRequest(requests, cachesToRemove, _hidl_cb);
+        }
+
+        virtual Return<void> getCaptureRequestMetadataQueue(
+                V3_3::ICameraDeviceSession::getCaptureRequestMetadataQueue_cb _hidl_cb) override  {
+            return mParent->getCaptureRequestMetadataQueue(_hidl_cb);
+        }
+
+        virtual Return<void> getCaptureResultMetadataQueue(
+                V3_3::ICameraDeviceSession::getCaptureResultMetadataQueue_cb _hidl_cb) override  {
+            return mParent->getCaptureResultMetadataQueue(_hidl_cb);
+        }
+
+        virtual Return<Status> flush() override {
+            return mParent->flush();
+        }
+
+        virtual Return<void> close() override {
+            return mParent->close();
+        }
+
+        virtual Return<void> configureStreams_3_3(
+                const StreamConfiguration& requestedConfiguration, configureStreams_3_3_cb _hidl_cb) override {
+            return mParent->configureStreams_3_3(requestedConfiguration, _hidl_cb);
+        }
+
+    private:
+        sp<CameraDeviceSession> mParent;
+    };
+};
+
+}  // namespace implementation
+}  // namespace V3_3
+}  // namespace device
+}  // namespace camera
+}  // namespace hardware
+}  // namespace android
+
+#endif  // ANDROID_HARDWARE_CAMERA_DEVICE_V3_3_CAMERADEVICE3SESSION_H
diff --git a/camera/device/3.3/default/CameraDevice_3_3.h b/camera/device/3.3/default/CameraDevice_3_3.h
new file mode 100644
index 0000000..18b3fe8
--- /dev/null
+++ b/camera/device/3.3/default/CameraDevice_3_3.h
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2017 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_HARDWARE_CAMERA_DEVICE_V3_3_CAMERADEVICE_H
+#define ANDROID_HARDWARE_CAMERA_DEVICE_V3_3_CAMERADEVICE_H
+
+#include "utils/Mutex.h"
+#include "CameraModule.h"
+#include "CameraMetadata.h"
+#include "CameraDeviceSession.h"
+#include <../../3.2/default/CameraDevice_3_2.h>
+
+#include <android/hardware/camera/device/3.2/ICameraDevice.h>
+#include <hidl/Status.h>
+#include <hidl/MQDescriptor.h>
+
+namespace android {
+namespace hardware {
+namespace camera {
+namespace device {
+namespace V3_3 {
+namespace implementation {
+
+using namespace ::android::hardware::camera::device;
+using ::android::hardware::camera::common::V1_0::helper::CameraModule;
+using ::android::hardware::Return;
+using ::android::hardware::Void;
+using ::android::hardware::hidl_vec;
+using ::android::hardware::hidl_string;
+using ::android::sp;
+
+/*
+ * The camera device HAL implementation is opened lazily (via the open call)
+ */
+struct CameraDevice : public V3_2::implementation::CameraDevice {
+
+    // Called by provider HAL.
+    // Provider HAL must ensure the uniqueness of CameraDevice object per cameraId, or there could
+    // be multiple CameraDevice trying to access the same physical camera.  Also, provider will have
+    // to keep track of all CameraDevice objects in order to notify CameraDevice when the underlying
+    // camera is detached.
+    // Delegates nearly all work to CameraDevice_3_2
+    CameraDevice(sp<CameraModule> module,
+                 const std::string& cameraId,
+                 const SortedVector<std::pair<std::string, std::string>>& cameraDeviceNames);
+    ~CameraDevice();
+
+protected:
+    virtual sp<V3_2::implementation::CameraDeviceSession> createSession(camera3_device_t*,
+            const camera_metadata_t* deviceInfo,
+            const sp<V3_2::ICameraDeviceCallback>&) override;
+
+};
+
+}  // namespace implementation
+}  // namespace V3_3
+}  // namespace device
+}  // namespace camera
+}  // namespace hardware
+}  // namespace android
+
+#endif  // ANDROID_HARDWARE_CAMERA_DEVICE_V3_3_CAMERADEVICE_H
diff --git a/camera/device/3.3/default/OWNERS b/camera/device/3.3/default/OWNERS
new file mode 100644
index 0000000..18acfee
--- /dev/null
+++ b/camera/device/3.3/default/OWNERS
@@ -0,0 +1,6 @@
+cychen@google.com
+epeev@google.com
+etalvala@google.com
+shuzhenwang@google.com
+yinchiayeh@google.com
+zhijunhe@google.com
diff --git a/camera/device/3.3/default/convert.cpp b/camera/device/3.3/default/convert.cpp
new file mode 100644
index 0000000..dae190b
--- /dev/null
+++ b/camera/device/3.3/default/convert.cpp
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2017 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 "android.hardware.camera.device@3.3-convert-impl"
+#include <log/log.h>
+
+#include "include/convert.h"
+
+namespace android {
+namespace hardware {
+namespace camera {
+namespace device {
+namespace V3_3 {
+namespace implementation {
+
+using ::android::hardware::graphics::common::V1_0::Dataspace;
+using ::android::hardware::graphics::common::V1_0::PixelFormat;
+using ::android::hardware::camera::device::V3_2::BufferUsageFlags;
+
+void convertToHidl(const Camera3Stream* src, HalStream* dst) {
+    dst->overrideDataSpace = src->data_space;
+    dst->v3_2.id = src->mId;
+    dst->v3_2.overrideFormat = (PixelFormat) src->format;
+    dst->v3_2.maxBuffers = src->max_buffers;
+    if (src->stream_type == CAMERA3_STREAM_OUTPUT) {
+        dst->v3_2.consumerUsage = (BufferUsageFlags)0;
+        dst->v3_2.producerUsage = (BufferUsageFlags)src->usage;
+    } else if (src->stream_type == CAMERA3_STREAM_INPUT) {
+        dst->v3_2.producerUsage = (BufferUsageFlags)0;
+        dst->v3_2.consumerUsage = (BufferUsageFlags)src->usage;
+    } else {
+        //Should not reach here per current HIDL spec, but we might end up adding
+        // bi-directional stream to HIDL.
+        ALOGW("%s: Stream type %d is not currently supported!",
+                __FUNCTION__, src->stream_type);
+    }
+}
+
+void convertToHidl(const camera3_stream_configuration_t& src, HalStreamConfiguration* dst) {
+    dst->streams.resize(src.num_streams);
+    for (uint32_t i = 0; i < src.num_streams; i++) {
+        convertToHidl(static_cast<Camera3Stream*>(src.streams[i]), &dst->streams[i]);
+    }
+    return;
+}
+
+}  // namespace implementation
+}  // namespace V3_3
+}  // namespace device
+}  // namespace camera
+}  // namespace hardware
+}  // namespace android
diff --git a/camera/device/3.3/default/include/convert.h b/camera/device/3.3/default/include/convert.h
new file mode 100644
index 0000000..23bb797
--- /dev/null
+++ b/camera/device/3.3/default/include/convert.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2017 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 HARDWARE_INTERFACES_CAMERA_DEVICE_V3_3_DEFAULT_INCLUDE_CONVERT_H_
+
+#define HARDWARE_INTERFACES_CAMERA_DEVICE_V3_3_DEFAULT_INCLUDE_CONVERT_H_
+
+#include <set>
+
+
+#include <android/hardware/graphics/common/1.0/types.h>
+#include <android/hardware/camera/device/3.3/types.h>
+#include "hardware/camera3.h"
+#include "../../3.2/default/include/convert.h"
+
+namespace android {
+namespace hardware {
+namespace camera {
+namespace device {
+namespace V3_3 {
+namespace implementation {
+
+using ::android::hardware::camera::device::V3_2::implementation::Camera3Stream;
+
+void convertToHidl(const Camera3Stream* src, HalStream* dst);
+
+void convertToHidl(const camera3_stream_configuration_t& src, HalStreamConfiguration* dst);
+
+}  // namespace implementation
+}  // namespace V3_3
+}  // namespace device
+}  // namespace camera
+}  // namespace hardware
+}  // namespace android
+
+#endif  // HARDWARE_INTERFACES_CAMERA_DEVICE_V3_3_DEFAULT_INCLUDE_CONVERT_H_
diff --git a/camera/provider/2.4/default/Android.bp b/camera/provider/2.4/default/Android.bp
index f2a2d2e..c0b3591 100644
--- a/camera/provider/2.4/default/Android.bp
+++ b/camera/provider/2.4/default/Android.bp
@@ -11,8 +11,10 @@
         "libcutils",
         "android.hardware.camera.device@1.0",
         "android.hardware.camera.device@3.2",
+        "android.hardware.camera.device@3.3",
         "camera.device@1.0-impl",
         "camera.device@3.2-impl",
+        "camera.device@3.3-impl",
         "android.hardware.camera.provider@2.4",
         "android.hardware.camera.common@1.0",
         "android.hardware.graphics.mapper@2.0",
@@ -43,6 +45,7 @@
         "libutils",
         "android.hardware.camera.device@1.0",
         "android.hardware.camera.device@3.2",
+        "android.hardware.camera.device@3.3",
         "android.hardware.camera.provider@2.4",
         "android.hardware.camera.common@1.0",
     ],
diff --git a/camera/provider/2.4/default/CameraProvider.cpp b/camera/provider/2.4/default/CameraProvider.cpp
index 19f7bdd..d50168a 100644
--- a/camera/provider/2.4/default/CameraProvider.cpp
+++ b/camera/provider/2.4/default/CameraProvider.cpp
@@ -15,11 +15,13 @@
  */
 
 #define LOG_TAG "CamProvider@2.4-impl"
+//#define LOG_NDEBUG 0
 #include <android/log.h>
 
 #include "CameraProvider.h"
 #include "CameraDevice_1_0.h"
-#include "CameraDevice_3_2.h"
+#include "CameraDevice_3_3.h"
+#include <cutils/properties.h>
 #include <string.h>
 #include <utils/Trace.h>
 
@@ -36,6 +38,7 @@
 // "device@<version>/legacy/<id>"
 const std::regex kDeviceNameRE("device@([0-9]+\\.[0-9]+)/legacy/(.+)");
 const char *kHAL3_2 = "3.2";
+const char *kHAL3_3 = "3.3";
 const char *kHAL1_0 = "1.0";
 const int kMaxCameraDeviceNameLen = 128;
 const int kMaxCameraIdLen = 16;
@@ -140,8 +143,9 @@
     if (!match) {
         return -1;
     }
-    if (deviceVersion == kHAL3_2) {
-        // maybe switched to 3.4 or define the hidl version enum later
+    if (deviceVersion == kHAL3_3) {
+        return CAMERA_DEVICE_API_VERSION_3_3;
+    } else if (deviceVersion == kHAL3_2) {
         return CAMERA_DEVICE_API_VERSION_3_2;
     } else if (deviceVersion == kHAL1_0) {
         return CAMERA_DEVICE_API_VERSION_1_0;
@@ -158,10 +162,12 @@
             deviceVersion != CAMERA_DEVICE_API_VERSION_3_4 ) {
         return hidl_string("");
     }
-    const char* versionStr = (deviceVersion == CAMERA_DEVICE_API_VERSION_1_0) ? kHAL1_0 : kHAL3_2;
+    bool isV1 = deviceVersion == CAMERA_DEVICE_API_VERSION_1_0;
+    int versionMajor = isV1 ? 1 : 3;
+    int versionMinor = isV1 ? 0 : mPreferredHal3MinorVersion;
     char deviceName[kMaxCameraDeviceNameLen];
-    snprintf(deviceName, sizeof(deviceName), "device@%s/legacy/%s",
-            versionStr, cameraId.c_str());
+    snprintf(deviceName, sizeof(deviceName), "device@%d.%d/legacy/%s",
+            versionMajor, versionMinor, cameraId.c_str());
     return deviceName;
 }
 
@@ -205,6 +211,19 @@
         return true;
     }
 
+    mPreferredHal3MinorVersion = property_get_int32("ro.camera.wrapper.hal3TrebleMinorVersion", 3);
+    ALOGV("Preferred HAL 3 minor version is %d", mPreferredHal3MinorVersion);
+    switch(mPreferredHal3MinorVersion) {
+        case 2:
+        case 3:
+            // OK
+            break;
+        default:
+            ALOGW("Unknown minor camera device HAL version %d in property "
+                    "'camera.wrapper.hal3TrebleMinorVersion', defaulting to 3", mPreferredHal3MinorVersion);
+            mPreferredHal3MinorVersion = 3;
+    }
+
     mNumberOfLegacyCameras = mModule->getNumberOfCameras();
     for (int i = 0; i < mNumberOfLegacyCameras; i++) {
         struct camera_info info;
@@ -461,23 +480,45 @@
         return Void();
     }
 
-    sp<android::hardware::camera::device::V3_2::implementation::CameraDevice> device =
-            new android::hardware::camera::device::V3_2::implementation::CameraDevice(
+    // Since some Treble HAL revisions can map to the same legacy HAL version(s), we default
+    // to the newest possible Treble HAL revision, but allow for override if needed via
+    // system property.
+    sp<android::hardware::camera::device::V3_2::ICameraDevice> device;
+    switch (mPreferredHal3MinorVersion) {
+        case 2: { // Map legacy camera device v3 HAL to Treble camera device HAL v3.2
+            ALOGV("Constructing v3.2 camera device");
+            sp<android::hardware::camera::device::V3_2::implementation::CameraDevice> deviceImpl =
+                    new android::hardware::camera::device::V3_2::implementation::CameraDevice(
                     mModule, cameraId, mCameraDeviceNames);
-
-    if (device == nullptr) {
-        ALOGE("%s: cannot allocate camera device for id %s", __FUNCTION__, cameraId.c_str());
-        _hidl_cb(Status::INTERNAL_ERROR, nullptr);
-        return Void();
+            if (deviceImpl == nullptr || deviceImpl->isInitFailed()) {
+                ALOGE("%s: camera device %s init failed!", __FUNCTION__, cameraId.c_str());
+                device = nullptr;
+                _hidl_cb(Status::INTERNAL_ERROR, nullptr);
+                return Void();
+            }
+            device = deviceImpl;
+            break;
+        }
+        case 3: { // Map legacy camera device v3 HAL to Treble camera device HAL v3.3
+            ALOGV("Constructing v3.3 camera device");
+            sp<android::hardware::camera::device::V3_2::implementation::CameraDevice> deviceImpl =
+                    new android::hardware::camera::device::V3_3::implementation::CameraDevice(
+                    mModule, cameraId, mCameraDeviceNames);
+            if (deviceImpl == nullptr || deviceImpl->isInitFailed()) {
+                ALOGE("%s: camera device %s init failed!", __FUNCTION__, cameraId.c_str());
+                device = nullptr;
+                _hidl_cb(Status::INTERNAL_ERROR, nullptr);
+                return Void();
+            }
+            device = deviceImpl;
+            break;
+        }
+        default:
+            ALOGE("%s: Unknown HAL minor version %d!", __FUNCTION__, mPreferredHal3MinorVersion);
+            device = nullptr;
+            _hidl_cb(Status::INTERNAL_ERROR, nullptr);
+            return Void();
     }
-
-    if (device->isInitFailed()) {
-        ALOGE("%s: camera device %s init failed!", __FUNCTION__, cameraId.c_str());
-        device = nullptr;
-        _hidl_cb(Status::INTERNAL_ERROR, nullptr);
-        return Void();
-    }
-
     _hidl_cb (Status::OK, device);
     return Void();
 }
diff --git a/camera/provider/2.4/default/CameraProvider.h b/camera/provider/2.4/default/CameraProvider.h
index 75971fa..4980711 100644
--- a/camera/provider/2.4/default/CameraProvider.h
+++ b/camera/provider/2.4/default/CameraProvider.h
@@ -82,6 +82,8 @@
     // (cameraId string, hidl device name) pairs
     SortedVector<std::pair<std::string, std::string>> mCameraDeviceNames;
 
+    int mPreferredHal3MinorVersion;
+
     // Must be queried before using any APIs.
     // APIs will only work when this returns true
     bool mInitFailed;
@@ -91,13 +93,13 @@
     bool setUpVendorTags();
     int checkCameraVersion(int id, camera_info info);
 
+    // create HIDL device name from camera ID and legacy device version
+    std::string getHidlDeviceName(std::string cameraId, int deviceVersion);
+
     // extract legacy camera ID/device version from a HIDL device name
     static std::string getLegacyCameraId(const hidl_string& deviceName);
     static int getCameraDeviceVersion(const hidl_string& deviceName);
 
-    // create HIDL device name from camera ID and device version
-    static std::string getHidlDeviceName(std::string cameraId, int deviceVersion);
-
     // convert conventional HAL status to HIDL Status
     static Status getHidlStatus(int);
 
diff --git a/current.txt b/current.txt
index 5207c6a..52fbfd1 100644
--- a/current.txt
+++ b/current.txt
@@ -245,5 +245,6 @@
 503da837d1a67cbdb7c08a033e927e5430ae1b159d98bf72c6336b4dcc5e76f5 android.hardware.cas.native@1.0::types
 619600109232ed64b827c8a11beed8070b1827ae464547d7aa146cf0473b4bca android.hardware.cas.native@1.0::IDescrambler
 0a159f81359cd4f71bbe00972ee8403ea79351fb7c0cd48be72ebb3e424dbaef android.hardware.radio@1.0::types
+09342041e17c429fce0034b9096d17849122111436a5f0053e7e59500e1cb89c android.hardware.media.omx@1.0::IOmxStore
 f4945e397b5dea41bb64518dfde59be71245d8a125fd1e0acffeb57ac7b08fed android.hardware.thermal@1.1::IThermal
 c8bc853546dd55584611def2a9fa1d99f657e3366c976d2f60fe6b8aa6d2cb87 android.hardware.thermal@1.1::IThermalCallback
diff --git a/media/omx/1.0/IOmxStore.hal b/media/omx/1.0/IOmxStore.hal
index a224b0e..3ec0535 100644
--- a/media/omx/1.0/IOmxStore.hal
+++ b/media/omx/1.0/IOmxStore.hal
@@ -39,7 +39,7 @@
      *   string:                arbitrary string
      *   size:                  <num>x<num>
      *   ratio:                 <num>:<num>
-     *   range<type>:           <type>-<type>
+     *   range<type>:           <type> | <type>-<type>
      *   list<type>:            <type> | <type>,<list<type>>
      */
     struct Attribute {
@@ -97,7 +97,7 @@
      *
      * Required node attributes for video nodes that are required by Android to
      * describe measured values for this device:
-     *   key: 'measured-frame-rate-<width>-<height>-range',
+     *   key: 'measured-frame-rate-<width>x<height>-range',
      *     value-type: range<num>; where width: num, height: num
      *
      * Optional node attributes for decoders to describe supported values:
@@ -111,7 +111,7 @@
      * Optional node attributes for encoders to describe supported values:
      *   key: 'complexity-default', value-type: num
      *   key: 'complexity-range', value-type: range<num>
-     *   key: 'feature-bitrate-control', value-type: list<enum<VBR,CBR,CQ>>
+     *   key: 'feature-bitrate-modes', value-type: list<enum<VBR,CBR,CQ>>
      *   key: 'feature-intra-refresh', value-type: enum<0,1>
      *   key: 'quality-default', value-type: num
      *   key: 'quality-range', value-type: range<num>
diff --git a/media/omx/1.0/vts/functional/audio/VtsHalMediaOmxV1_0TargetAudioDecTest.cpp b/media/omx/1.0/vts/functional/audio/VtsHalMediaOmxV1_0TargetAudioDecTest.cpp
index 8b9532a..b8a1634 100644
--- a/media/omx/1.0/vts/functional/audio/VtsHalMediaOmxV1_0TargetAudioDecTest.cpp
+++ b/media/omx/1.0/vts/functional/audio/VtsHalMediaOmxV1_0TargetAudioDecTest.cpp
@@ -171,7 +171,7 @@
             {"mp3", mp3}, {"amrnb", amrnb},       {"amrwb", amrwb},
             {"aac", aac}, {"vorbis", vorbis},     {"opus", opus},
             {"pcm", pcm}, {"g711alaw", g711alaw}, {"g711mlaw", g711mlaw},
-            {"gsm", gsm}, {"raw", raw},
+            {"gsm", gsm}, {"raw", raw},           {"flac", flac},
         };
         const size_t kNumStringToName =
             sizeof(kStringToName) / sizeof(kStringToName[0]);
@@ -204,6 +204,7 @@
             {g711mlaw, OMX_AUDIO_CodingG711},
             {gsm, OMX_AUDIO_CodingGSMFR},
             {raw, OMX_AUDIO_CodingPCM},
+            {flac, OMX_AUDIO_CodingFLAC},
         };
         static const size_t kNumCompToCoding =
             sizeof(kCompToCoding) / sizeof(kCompToCoding[0]);
@@ -300,6 +301,7 @@
         g711mlaw,
         gsm,
         raw,
+        flac,
         unknown_comp,
     };
 
@@ -430,6 +432,16 @@
             *nSampleRate = param.nSampleRate;
             break;
         }
+        case OMX_AUDIO_CodingFLAC: {
+            OMX_AUDIO_PARAM_FLACTYPE param;
+            status = getPortParam(omxNode, OMX_IndexParamAudioFlac,
+                                  kPortIndexInput, &param);
+            ASSERT_EQ(status,
+                      ::android::hardware::media::omx::V1_0::Status::OK);
+            *nChannels = param.nChannels;
+            *nSampleRate = param.nSampleRate;
+            break;
+        }
         default:
             ASSERT_TRUE(false);
             break;
@@ -471,6 +483,9 @@
          "bbb_gsm_1ch_8khz_13kbps.info"},
         {AudioDecHidlTest::standardComp::raw, "bbb_raw_1ch_8khz_s32le.raw",
          "bbb_raw_1ch_8khz_s32le.info"},
+        {AudioDecHidlTest::standardComp::flac,
+         "bbb_flac_stereo_680kbps_48000hz.flac",
+         "bbb_flac_stereo_680kbps_48000hz.info"},
     };
 
     for (size_t i = 0; i < sizeof(kCompToURL) / sizeof(kCompToURL[0]); ++i) {
@@ -627,39 +642,16 @@
                    AudioDecHidlTest::standardComp comp, bool signalEOS = true) {
     android::hardware::media::omx::V1_0::Status status;
     Message msg;
-
-    // dispatch output buffers
-    for (size_t i = 0; i < oBuffer->size(); i++) {
-        dispatchOutputBuffer(omxNode, oBuffer, i);
-    }
-    // dispatch input buffers
+    size_t index;
     uint32_t flags = 0;
     int frameID = offset;
-    for (size_t i = 0; (i < iBuffer->size()) && (frameID < (int)Info->size()) &&
-                       (frameID < (offset + range));
-         i++) {
-        char* ipBuffer = static_cast<char*>(
-            static_cast<void*>((*iBuffer)[i].mMemory->getPointer()));
-        ASSERT_LE((*Info)[frameID].bytesCount,
-                  static_cast<int>((*iBuffer)[i].mMemory->getSize()));
-        eleStream.read(ipBuffer, (*Info)[frameID].bytesCount);
-        ASSERT_EQ(eleStream.gcount(), (*Info)[frameID].bytesCount);
-        flags = (*Info)[frameID].flags;
-        if (signalEOS && ((frameID == (int)Info->size() - 1) ||
-                          (frameID == (offset + range - 1))))
-            flags |= OMX_BUFFERFLAG_EOS;
-        dispatchInputBuffer(omxNode, iBuffer, i, (*Info)[frameID].bytesCount,
-                            flags, (*Info)[frameID].timestamp);
-        frameID++;
-    }
-
     int timeOut = TIMEOUT_COUNTER_Q;
     bool iQueued, oQueued;
+
     while (1) {
         iQueued = oQueued = false;
         status =
             observer->dequeueMessage(&msg, DEFAULT_TIMEOUT_Q, iBuffer, oBuffer);
-
         // Port Reconfiguration
         if (status == android::hardware::media::omx::V1_0::Status::OK &&
             msg.type == Message::Type::EVENT) {
@@ -672,7 +664,6 @@
         if (frameID == (int)Info->size() || frameID == (offset + range)) break;
 
         // Dispatch input buffer
-        size_t index = 0;
         if ((index = getEmptyBufferID(iBuffer)) < iBuffer->size()) {
             char* ipBuffer = static_cast<char*>(
                 static_cast<void*>((*iBuffer)[index].mMemory->getPointer()));
@@ -681,6 +672,11 @@
             eleStream.read(ipBuffer, (*Info)[frameID].bytesCount);
             ASSERT_EQ(eleStream.gcount(), (*Info)[frameID].bytesCount);
             flags = (*Info)[frameID].flags;
+            // Indicate to omx core that the buffer contains a full frame worth
+            // of data
+            flags |= OMX_BUFFERFLAG_ENDOFFRAME;
+            // Indicate the omx core that this is the last buffer it needs to
+            // process
             if (signalEOS && ((frameID == (int)Info->size() - 1) ||
                               (frameID == (offset + range - 1))))
                 flags |= OMX_BUFFERFLAG_EOS;
@@ -690,10 +686,12 @@
             frameID++;
             iQueued = true;
         }
+        // Dispatch output buffer
         if ((index = getEmptyBufferID(oBuffer)) < oBuffer->size()) {
             dispatchOutputBuffer(omxNode, oBuffer, index);
             oQueued = true;
         }
+        // Reset Counters when either input or output buffer is dispatched
         if (iQueued || oQueued)
             timeOut = TIMEOUT_COUNTER_Q;
         else
diff --git a/media/omx/1.0/vts/functional/audio/VtsHalMediaOmxV1_0TargetAudioEncTest.cpp b/media/omx/1.0/vts/functional/audio/VtsHalMediaOmxV1_0TargetAudioEncTest.cpp
index 272b4ba..dd5f16a 100644
--- a/media/omx/1.0/vts/functional/audio/VtsHalMediaOmxV1_0TargetAudioEncTest.cpp
+++ b/media/omx/1.0/vts/functional/audio/VtsHalMediaOmxV1_0TargetAudioEncTest.cpp
@@ -376,44 +376,25 @@
                    bool signalEOS = true) {
     android::hardware::media::omx::V1_0::Status status;
     Message msg;
-
-    // dispatch output buffers
-    for (size_t i = 0; i < oBuffer->size(); i++) {
-        dispatchOutputBuffer(omxNode, oBuffer, i);
-    }
-    // dispatch input buffers
+    size_t index;
     int bytesCount = samplesPerFrame * nChannels * 2;
     int32_t timestampIncr =
         (int)(((float)samplesPerFrame / nSampleRate) * 1000000);
     uint64_t timestamp = 0;
     uint32_t flags = 0;
-    for (size_t i = 0; i < iBuffer->size() && nFrames != 0; i++) {
-        char* ipBuffer = static_cast<char*>(
-            static_cast<void*>((*iBuffer)[i].mMemory->getPointer()));
-        ASSERT_LE(bytesCount,
-                  static_cast<int>((*iBuffer)[i].mMemory->getSize()));
-        eleStream.read(ipBuffer, bytesCount);
-        if (eleStream.gcount() != bytesCount) break;
-        if (signalEOS && (nFrames == 1)) flags = OMX_BUFFERFLAG_EOS;
-        dispatchInputBuffer(omxNode, iBuffer, i, bytesCount, flags, timestamp);
-        timestamp += timestampIncr;
-        nFrames--;
-    }
-
     int timeOut = TIMEOUT_COUNTER_Q;
     bool iQueued, oQueued;
+
     while (1) {
         iQueued = oQueued = false;
         status =
             observer->dequeueMessage(&msg, DEFAULT_TIMEOUT_Q, iBuffer, oBuffer);
-
         if (status == android::hardware::media::omx::V1_0::Status::OK)
             ASSERT_TRUE(false);
 
         if (nFrames == 0) break;
 
         // Dispatch input buffer
-        size_t index = 0;
         if ((index = getEmptyBufferID(iBuffer)) < iBuffer->size()) {
             char* ipBuffer = static_cast<char*>(
                 static_cast<void*>((*iBuffer)[index].mMemory->getPointer()));
@@ -421,7 +402,8 @@
                       static_cast<int>((*iBuffer)[index].mMemory->getSize()));
             eleStream.read(ipBuffer, bytesCount);
             if (eleStream.gcount() != bytesCount) break;
-            if (signalEOS && (nFrames == 1)) flags = OMX_BUFFERFLAG_EOS;
+            flags = OMX_BUFFERFLAG_ENDOFFRAME;
+            if (signalEOS && (nFrames == 1)) flags |= OMX_BUFFERFLAG_EOS;
             dispatchInputBuffer(omxNode, iBuffer, index, bytesCount, flags,
                                 timestamp);
             timestamp += timestampIncr;
@@ -433,6 +415,7 @@
             dispatchOutputBuffer(omxNode, oBuffer, index);
             oQueued = true;
         }
+        // Reset Counters when either input or output buffer is dispatched
         if (iQueued || oQueued)
             timeOut = TIMEOUT_COUNTER_Q;
         else
diff --git a/media/omx/1.0/vts/functional/common/Android.bp b/media/omx/1.0/vts/functional/common/Android.bp
index af55e3a..cdc52fb 100644
--- a/media/omx/1.0/vts/functional/common/Android.bp
+++ b/media/omx/1.0/vts/functional/common/Android.bp
@@ -28,6 +28,7 @@
         "android.hidl.allocator@1.0",
         "android.hidl.memory@1.0",
         "android.hardware.media.omx@1.0",
+        "android.hardware.graphics.allocator@2.0",
     ],
 }
 
@@ -38,6 +39,8 @@
     // Link to these statically as they are not guaranteed to be on the device.
     static_libs: [
         "VtsHalMediaOmxV1_0CommonUtil",
+        "android.hardware.graphics.allocator@2.0",
+        "android.hardware.graphics.mapper@2.0",
         "android.hardware.graphics.bufferqueue@1.0",
         "android.hardware.graphics.common@1.0",
         "android.hardware.media.omx@1.0",
diff --git a/media/omx/1.0/vts/functional/common/media_hidl_test_common.cpp b/media/omx/1.0/vts/functional/common/media_hidl_test_common.cpp
index 1ef645c..9eab10c 100644
--- a/media/omx/1.0/vts/functional/common/media_hidl_test_common.cpp
+++ b/media/omx/1.0/vts/functional/common/media_hidl_test_common.cpp
@@ -22,6 +22,9 @@
 
 #include <android-base/logging.h>
 
+#include <android/hardware/graphics/allocator/2.0/IAllocator.h>
+#include <android/hardware/graphics/mapper/2.0/IMapper.h>
+#include <android/hardware/graphics/mapper/2.0/types.h>
 #include <android/hardware/media/omx/1.0/IOmx.h>
 #include <android/hardware/media/omx/1.0/IOmxNode.h>
 #include <android/hardware/media/omx/1.0/IOmxObserver.h>
@@ -29,7 +32,10 @@
 #include <android/hidl/allocator/1.0/IAllocator.h>
 #include <android/hidl/memory/1.0/IMapper.h>
 #include <android/hidl/memory/1.0/IMemory.h>
+#include <cutils/atomic.h>
 
+using ::android::hardware::graphics::common::V1_0::BufferUsage;
+using ::android::hardware::graphics::common::V1_0::PixelFormat;
 using ::android::hardware::media::omx::V1_0::IOmx;
 using ::android::hardware::media::omx::V1_0::IOmxObserver;
 using ::android::hardware::media::omx::V1_0::IOmxNode;
@@ -186,6 +192,73 @@
     return status;
 }
 
+void allocateGraphicBuffers(sp<IOmxNode> omxNode, OMX_U32 portIndex,
+                            BufferInfo* buffer, uint32_t nFrameWidth,
+                            uint32_t nFrameHeight, int32_t* nStride,
+                            int format) {
+    android::hardware::media::omx::V1_0::Status status;
+    sp<android::hardware::graphics::allocator::V2_0::IAllocator> allocator =
+        android::hardware::graphics::allocator::V2_0::IAllocator::getService();
+    ASSERT_NE(nullptr, allocator.get());
+
+    sp<android::hardware::graphics::mapper::V2_0::IMapper> mapper =
+        android::hardware::graphics::mapper::V2_0::IMapper::getService();
+    ASSERT_NE(mapper.get(), nullptr);
+
+    android::hardware::graphics::mapper::V2_0::IMapper::BufferDescriptorInfo
+        descriptorInfo;
+    uint32_t usage;
+
+    descriptorInfo.width = nFrameWidth;
+    descriptorInfo.height = nFrameHeight;
+    descriptorInfo.layerCount = 1;
+    descriptorInfo.format = static_cast<PixelFormat>(format);
+    descriptorInfo.usage = static_cast<uint64_t>(BufferUsage::CPU_READ_OFTEN);
+    omxNode->getGraphicBufferUsage(
+        portIndex,
+        [&status, &usage](android::hardware::media::omx::V1_0::Status _s,
+                          uint32_t _n1) {
+            status = _s;
+            usage = _n1;
+        });
+    if (status == android::hardware::media::omx::V1_0::Status::OK) {
+        descriptorInfo.usage |= usage;
+    }
+
+    ::android::hardware::hidl_vec<uint32_t> descriptor;
+    android::hardware::graphics::mapper::V2_0::Error error;
+    mapper->createDescriptor(
+        descriptorInfo, [&error, &descriptor](
+                            android::hardware::graphics::mapper::V2_0::Error _s,
+                            ::android::hardware::hidl_vec<uint32_t> _n1) {
+            error = _s;
+            descriptor = _n1;
+        });
+    EXPECT_EQ(error, android::hardware::graphics::mapper::V2_0::Error::NONE);
+
+    static volatile int32_t nextId = 0;
+    uint64_t id = static_cast<uint64_t>(getpid()) << 32;
+    allocator->allocate(
+        descriptor, 1,
+        [&](android::hardware::graphics::mapper::V2_0::Error _s, uint32_t _n1,
+            const ::android::hardware::hidl_vec<
+                ::android::hardware::hidl_handle>& _n2) {
+            ASSERT_EQ(android::hardware::graphics::mapper::V2_0::Error::NONE,
+                      _s);
+            *nStride = _n1;
+            buffer->omxBuffer.nativeHandle = _n2[0];
+            buffer->omxBuffer.attr.anwBuffer.width = nFrameWidth;
+            buffer->omxBuffer.attr.anwBuffer.height = nFrameHeight;
+            buffer->omxBuffer.attr.anwBuffer.stride = _n1;
+            buffer->omxBuffer.attr.anwBuffer.format = descriptorInfo.format;
+            buffer->omxBuffer.attr.anwBuffer.usage = descriptorInfo.usage;
+            buffer->omxBuffer.attr.anwBuffer.layerCount =
+                descriptorInfo.layerCount;
+            buffer->omxBuffer.attr.anwBuffer.id =
+                id | static_cast<uint32_t>(android_atomic_inc(&nextId));
+        });
+}
+
 // allocate buffers needed on a component port
 void allocateBuffer(sp<IOmxNode> omxNode, BufferInfo* buffer, OMX_U32 portIndex,
                     OMX_U32 nBufferSize, PortMode portMode) {
@@ -243,13 +316,32 @@
                 buffer->id = id;
             });
         ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
+    } else if (portMode == PortMode::PRESET_ANW_BUFFER) {
+        OMX_PARAM_PORTDEFINITIONTYPE portDef;
+        status = getPortParam(omxNode, OMX_IndexParamPortDefinition, portIndex,
+                              &portDef);
+        int32_t nStride;
+        buffer->owner = client;
+        buffer->omxBuffer.type = CodecBuffer::Type::ANW_BUFFER;
+        allocateGraphicBuffers(omxNode, portIndex, buffer,
+                               portDef.format.video.nFrameWidth,
+                               portDef.format.video.nFrameHeight, &nStride,
+                               portDef.format.video.eColorFormat);
+        omxNode->useBuffer(
+            portIndex, buffer->omxBuffer,
+            [&status, &buffer](android::hardware::media::omx::V1_0::Status _s,
+                               uint32_t id) {
+                status = _s;
+                buffer->id = id;
+            });
+        ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
     }
 }
 
 // allocate buffers needed on a component port
 void allocatePortBuffers(sp<IOmxNode> omxNode,
                          android::Vector<BufferInfo>* buffArray,
-                         OMX_U32 portIndex, PortMode portMode) {
+                         OMX_U32 portIndex, PortMode portMode, bool allocGrap) {
     android::hardware::media::omx::V1_0::Status status;
     OMX_PARAM_PORTDEFINITIONTYPE portDef;
 
@@ -263,6 +355,13 @@
         BufferInfo buffer;
         allocateBuffer(omxNode, &buffer, portIndex, portDef.nBufferSize,
                        portMode);
+        if (allocGrap && portMode == PortMode::DYNAMIC_ANW_BUFFER) {
+            int32_t nStride;
+            allocateGraphicBuffers(omxNode, portIndex, &buffer,
+                                   portDef.format.video.nFrameWidth,
+                                   portDef.format.video.nFrameHeight, &nStride,
+                                   portDef.format.video.eColorFormat);
+        }
         buffArray->push(buffer);
     }
 }
@@ -274,7 +373,7 @@
                              android::Vector<BufferInfo>* iBuffer,
                              android::Vector<BufferInfo>* oBuffer,
                              OMX_U32 kPortIndexInput, OMX_U32 kPortIndexOutput,
-                             PortMode* portMode) {
+                             PortMode* portMode, bool allocGrap) {
     android::hardware::media::omx::V1_0::Status status;
     Message msg;
     PortMode defaultPortMode[2], *pm;
@@ -293,14 +392,14 @@
     ASSERT_EQ(status, android::hardware::media::omx::V1_0::Status::TIMED_OUT);
 
     // allocate buffers on input port
-    allocatePortBuffers(omxNode, iBuffer, kPortIndexInput, pm[0]);
+    allocatePortBuffers(omxNode, iBuffer, kPortIndexInput, pm[0], allocGrap);
 
     // Dont switch states until the ports are populated
     status = observer->dequeueMessage(&msg, DEFAULT_TIMEOUT, iBuffer, oBuffer);
     ASSERT_EQ(status, android::hardware::media::omx::V1_0::Status::TIMED_OUT);
 
     // allocate buffers on output port
-    allocatePortBuffers(omxNode, oBuffer, kPortIndexOutput, pm[1]);
+    allocatePortBuffers(omxNode, oBuffer, kPortIndexOutput, pm[1], allocGrap);
 
     // As the ports are populated, check if the state transition is complete
     status = observer->dequeueMessage(&msg, DEFAULT_TIMEOUT, iBuffer, oBuffer);
@@ -440,6 +539,7 @@
             status =
                 omxNode->fillBuffer((*buffArray)[bufferIndex].id, t, fenceNh);
             break;
+        case PortMode::PRESET_ANW_BUFFER:
         case PortMode::PRESET_SECURE_BUFFER:
         case PortMode::PRESET_BYTE_BUFFER:
             t.sharedMemory = android::hardware::hidl_memory();
diff --git a/media/omx/1.0/vts/functional/common/media_hidl_test_common.h b/media/omx/1.0/vts/functional/common/media_hidl_test_common.h
index 94a0194..e23d781 100644
--- a/media/omx/1.0/vts/functional/common/media_hidl_test_common.h
+++ b/media/omx/1.0/vts/functional/common/media_hidl_test_common.h
@@ -133,6 +133,7 @@
                 if (it->type ==
                     android::hardware::media::omx::V1_0::Message::Type::EVENT) {
                     *msg = *it;
+                    if (callBack) callBack(*it, nullptr);
                     it = msgQueue.erase(it);
                     // OMX_EventBufferFlag event is sent when the component has
                     // processed a buffer with its EOS flag set. This event is
@@ -302,13 +303,15 @@
 void allocatePortBuffers(sp<IOmxNode> omxNode,
                          android::Vector<BufferInfo>* buffArray,
                          OMX_U32 portIndex,
-                         PortMode portMode = PortMode::PRESET_BYTE_BUFFER);
+                         PortMode portMode = PortMode::PRESET_BYTE_BUFFER,
+                         bool allocGrap = false);
 
 void changeStateLoadedtoIdle(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
                              android::Vector<BufferInfo>* iBuffer,
                              android::Vector<BufferInfo>* oBuffer,
                              OMX_U32 kPortIndexInput, OMX_U32 kPortIndexOutput,
-                             PortMode* portMode = nullptr);
+                             PortMode* portMode = nullptr,
+                             bool allocGrap = false);
 
 void changeStateIdletoLoaded(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
                              android::Vector<BufferInfo>* iBuffer,
diff --git a/media/omx/1.0/vts/functional/video/Android.bp b/media/omx/1.0/vts/functional/video/Android.bp
index e251a15..f0da2b3 100644
--- a/media/omx/1.0/vts/functional/video/Android.bp
+++ b/media/omx/1.0/vts/functional/video/Android.bp
@@ -21,10 +21,6 @@
         "VtsHalMediaOmxV1_0TargetVideoDecTest.cpp",
         "media_video_hidl_test_common.cpp"
     ],
-    static_libs: [
-        "android.hardware.graphics.allocator@2.0",
-        "android.hardware.graphics.mapper@2.0",
-    ],
 }
 
 cc_test {
@@ -36,6 +32,5 @@
     ],
     static_libs: [
         "libnativewindow",
-        "android.hardware.graphics.mapper@2.0",
     ],
 }
diff --git a/media/omx/1.0/vts/functional/video/VtsHalMediaOmxV1_0TargetVideoDecTest.cpp b/media/omx/1.0/vts/functional/video/VtsHalMediaOmxV1_0TargetVideoDecTest.cpp
index a3ecccc..6b01285 100644
--- a/media/omx/1.0/vts/functional/video/VtsHalMediaOmxV1_0TargetVideoDecTest.cpp
+++ b/media/omx/1.0/vts/functional/video/VtsHalMediaOmxV1_0TargetVideoDecTest.cpp
@@ -17,9 +17,6 @@
 #define LOG_TAG "media_omx_hidl_video_dec_test"
 #include <android-base/logging.h>
 
-#include <android/hardware/graphics/allocator/2.0/IAllocator.h>
-#include <android/hardware/graphics/mapper/2.0/IMapper.h>
-#include <android/hardware/graphics/mapper/2.0/types.h>
 #include <android/hardware/media/omx/1.0/IOmx.h>
 #include <android/hardware/media/omx/1.0/IOmxNode.h>
 #include <android/hardware/media/omx/1.0/IOmxObserver.h>
@@ -27,10 +24,7 @@
 #include <android/hidl/allocator/1.0/IAllocator.h>
 #include <android/hidl/memory/1.0/IMapper.h>
 #include <android/hidl/memory/1.0/IMemory.h>
-#include <cutils/atomic.h>
 
-using ::android::hardware::graphics::common::V1_0::BufferUsage;
-using ::android::hardware::graphics::common::V1_0::PixelFormat;
 using ::android::hardware::media::omx::V1_0::IOmx;
 using ::android::hardware::media::omx::V1_0::IOmxObserver;
 using ::android::hardware::media::omx::V1_0::IOmxNode;
@@ -219,6 +213,7 @@
         timestampUs = 0;
         timestampDevTest = false;
         isSecure = false;
+        portSettingsChange = false;
         size_t suffixLen = strlen(".secure");
         if (strlen(gEnv->getComponent().c_str()) >= suffixLen) {
             isSecure =
@@ -294,6 +289,13 @@
                 }
 #endif
             }
+        } else if (msg.type == Message::Type::EVENT) {
+            if (msg.data.eventData.event == OMX_EventPortSettingsChanged) {
+                if ((msg.data.eventData.data2 == OMX_IndexParamPortDefinition ||
+                     msg.data.eventData.data2 == 0)) {
+                    portSettingsChange = true;
+                }
+            }
         }
     }
 
@@ -321,6 +323,7 @@
     ::android::List<uint64_t> timestampUslist;
     bool timestampDevTest;
     bool isSecure;
+    bool portSettingsChange;
 
    protected:
     static void description(const std::string& description) {
@@ -368,122 +371,61 @@
     }
 }
 
+// number of elementary streams per component
+#define STREAM_COUNT 2
 // LookUpTable of clips and metadata for component testing
 void GetURLForComponent(VideoDecHidlTest::standardComp comp, char* mURL,
-                        char* info) {
+                        char* info, size_t streamIndex = 1) {
     struct CompToURL {
         VideoDecHidlTest::standardComp comp;
-        const char* mURL;
-        const char* info;
+        const char mURL[STREAM_COUNT][512];
+        const char info[STREAM_COUNT][512];
     };
+    ASSERT_TRUE(streamIndex < STREAM_COUNT);
+
     static const CompToURL kCompToURL[] = {
         {VideoDecHidlTest::standardComp::avc,
-         "bbb_avc_1920x1080_5000kbps_30fps.h264",
-         "bbb_avc_1920x1080_5000kbps_30fps.info"},
+         {"bbb_avc_176x144_300kbps_60fps.h264",
+          "bbb_avc_1920x1080_5000kbps_30fps.h264"},
+         {"bbb_avc_176x144_300kbps_60fps.info",
+          "bbb_avc_1920x1080_5000kbps_30fps.info"}},
         {VideoDecHidlTest::standardComp::hevc,
-         "bbb_hevc_640x360_1600kbps_30fps.hevc",
-         "bbb_hevc_640x360_1600kbps_30fps.info"},
+         {"bbb_hevc_176x144_176kbps_60fps.hevc",
+          "bbb_hevc_640x360_1600kbps_30fps.hevc"},
+         {"bbb_hevc_176x144_176kbps_60fps.info",
+          "bbb_hevc_640x360_1600kbps_30fps.info"}},
         {VideoDecHidlTest::standardComp::mpeg2,
-         "bbb_mpeg2_176x144_105kbps_25fps.m2v",
-         "bbb_mpeg2_176x144_105kbps_25fps.info"},
+         {"bbb_mpeg2_176x144_105kbps_25fps.m2v",
+          "bbb_mpeg2_352x288_1mbps_60fps.m2v"},
+         {"bbb_mpeg2_176x144_105kbps_25fps.info",
+          "bbb_mpeg2_352x288_1mbps_60fps.info"}},
         {VideoDecHidlTest::standardComp::h263,
-         "bbb_h263_352x288_300kbps_12fps.h263",
-         "bbb_h263_352x288_300kbps_12fps.info"},
+         {"", "bbb_h263_352x288_300kbps_12fps.h263"},
+         {"", "bbb_h263_352x288_300kbps_12fps.info"}},
         {VideoDecHidlTest::standardComp::mpeg4,
-         "bbb_mpeg4_1280x720_1000kbps_25fps.m4v",
-         "bbb_mpeg4_1280x720_1000kbps_25fps.info"},
-        {VideoDecHidlTest::standardComp::vp8, "bbb_vp8_640x360_2mbps_30fps.vp8",
-         "bbb_vp8_640x360_2mbps_30fps.info"},
+         {"", "bbb_mpeg4_1280x720_1000kbps_25fps.m4v"},
+         {"", "bbb_mpeg4_1280x720_1000kbps_25fps.info"}},
+        {VideoDecHidlTest::standardComp::vp8,
+         {"bbb_vp8_176x144_240kbps_60fps.vp8",
+          "bbb_vp8_640x360_2mbps_30fps.vp8"},
+         {"bbb_vp8_176x144_240kbps_60fps.info",
+          "bbb_vp8_640x360_2mbps_30fps.info"}},
         {VideoDecHidlTest::standardComp::vp9,
-         "bbb_vp9_640x360_1600kbps_30fps.vp9",
-         "bbb_vp9_640x360_1600kbps_30fps.info"},
+         {"bbb_vp9_176x144_285kbps_60fps.vp9",
+          "bbb_vp9_640x360_1600kbps_30fps.vp9"},
+         {"bbb_vp9_176x144_285kbps_60fps.info",
+          "bbb_vp9_640x360_1600kbps_30fps.info"}},
     };
 
     for (size_t i = 0; i < sizeof(kCompToURL) / sizeof(kCompToURL[0]); ++i) {
         if (kCompToURL[i].comp == comp) {
-            strcat(mURL, kCompToURL[i].mURL);
-            strcat(info, kCompToURL[i].info);
+            strcat(mURL, kCompToURL[i].mURL[streamIndex]);
+            strcat(info, kCompToURL[i].info[streamIndex]);
             return;
         }
     }
 }
 
-void allocateGraphicBuffers(sp<IOmxNode> omxNode, OMX_U32 portIndex,
-                            android::Vector<BufferInfo>* buffArray,
-                            uint32_t nFrameWidth, uint32_t nFrameHeight,
-                            int32_t* nStride, int format, uint32_t count) {
-    android::hardware::media::omx::V1_0::Status status;
-    sp<android::hardware::graphics::allocator::V2_0::IAllocator> allocator =
-        android::hardware::graphics::allocator::V2_0::IAllocator::getService();
-    ASSERT_NE(nullptr, allocator.get());
-
-    sp<android::hardware::graphics::mapper::V2_0::IMapper> mapper =
-        android::hardware::graphics::mapper::V2_0::IMapper::getService();
-    ASSERT_NE(mapper.get(), nullptr);
-
-    android::hardware::graphics::mapper::V2_0::IMapper::BufferDescriptorInfo
-        descriptorInfo;
-    uint32_t usage;
-
-    descriptorInfo.width = nFrameWidth;
-    descriptorInfo.height = nFrameHeight;
-    descriptorInfo.layerCount = 1;
-    descriptorInfo.format = static_cast<PixelFormat>(format);
-    descriptorInfo.usage = static_cast<uint64_t>(BufferUsage::CPU_READ_OFTEN);
-    omxNode->getGraphicBufferUsage(
-        portIndex,
-        [&status, &usage](android::hardware::media::omx::V1_0::Status _s,
-                          uint32_t _n1) {
-            status = _s;
-            usage = _n1;
-        });
-    if (status == android::hardware::media::omx::V1_0::Status::OK) {
-        descriptorInfo.usage |= usage;
-    }
-
-    ::android::hardware::hidl_vec<uint32_t> descriptor;
-    android::hardware::graphics::mapper::V2_0::Error error;
-    mapper->createDescriptor(
-        descriptorInfo, [&error, &descriptor](
-                            android::hardware::graphics::mapper::V2_0::Error _s,
-                            ::android::hardware::hidl_vec<uint32_t> _n1) {
-            error = _s;
-            descriptor = _n1;
-        });
-    EXPECT_EQ(error, android::hardware::graphics::mapper::V2_0::Error::NONE);
-
-    EXPECT_EQ(buffArray->size(), count);
-
-    static volatile int32_t nextId = 0;
-    uint64_t id = static_cast<uint64_t>(getpid()) << 32;
-    allocator->allocate(
-        descriptor, count,
-        [&](android::hardware::graphics::mapper::V2_0::Error _s, uint32_t _n1,
-            const ::android::hardware::hidl_vec<
-                ::android::hardware::hidl_handle>& _n2) {
-            ASSERT_EQ(android::hardware::graphics::mapper::V2_0::Error::NONE,
-                      _s);
-            *nStride = _n1;
-            ASSERT_EQ(count, _n2.size());
-            for (uint32_t i = 0; i < count; i++) {
-                buffArray->editItemAt(i).omxBuffer.nativeHandle = _n2[i];
-                buffArray->editItemAt(i).omxBuffer.attr.anwBuffer.width =
-                    nFrameWidth;
-                buffArray->editItemAt(i).omxBuffer.attr.anwBuffer.height =
-                    nFrameHeight;
-                buffArray->editItemAt(i).omxBuffer.attr.anwBuffer.stride = _n1;
-                buffArray->editItemAt(i).omxBuffer.attr.anwBuffer.format =
-                    descriptorInfo.format;
-                buffArray->editItemAt(i).omxBuffer.attr.anwBuffer.usage =
-                    descriptorInfo.usage;
-                buffArray->editItemAt(i).omxBuffer.attr.anwBuffer.layerCount =
-                    descriptorInfo.layerCount;
-                buffArray->editItemAt(i).omxBuffer.attr.anwBuffer.id =
-                    id | static_cast<uint32_t>(android_atomic_inc(&nextId));
-            }
-        });
-}
-
 // port settings reconfiguration during runtime. reconfigures frame dimensions
 void portReconfiguration(sp<IOmxNode> omxNode, sp<CodecObserver> observer,
                          android::Vector<BufferInfo>* iBuffer,
@@ -567,22 +509,7 @@
                     android::hardware::media::omx::V1_0::Status::TIMED_OUT);
 
                 allocatePortBuffers(omxNode, oBuffer, kPortIndexOutput,
-                                    oPortMode);
-                if (oPortMode != PortMode::PRESET_BYTE_BUFFER) {
-                    OMX_PARAM_PORTDEFINITIONTYPE portDef;
-
-                    status = getPortParam(omxNode, OMX_IndexParamPortDefinition,
-                                          kPortIndexOutput, &portDef);
-                    ASSERT_EQ(
-                        status,
-                        ::android::hardware::media::omx::V1_0::Status::OK);
-                    allocateGraphicBuffers(omxNode, kPortIndexOutput, oBuffer,
-                                           portDef.format.video.nFrameWidth,
-                                           portDef.format.video.nFrameHeight,
-                                           &portDef.format.video.nStride,
-                                           portDef.format.video.eColorFormat,
-                                           portDef.nBufferCountActual);
-                }
+                                    oPortMode, true);
                 status = observer->dequeueMessage(&msg, DEFAULT_TIMEOUT,
                                                   iBuffer, oBuffer);
                 ASSERT_EQ(status,
@@ -673,39 +600,16 @@
                    bool signalEOS = true) {
     android::hardware::media::omx::V1_0::Status status;
     Message msg;
-
-    // dispatch output buffers
-    for (size_t i = 0; i < oBuffer->size(); i++) {
-        dispatchOutputBuffer(omxNode, oBuffer, i, oPortMode);
-    }
-    // dispatch input buffers
+    size_t index;
     uint32_t flags = 0;
     int frameID = offset;
-    for (size_t i = 0; (i < iBuffer->size()) && (frameID < (int)Info->size()) &&
-                       (frameID < (offset + range));
-         i++) {
-        char* ipBuffer = static_cast<char*>(
-            static_cast<void*>((*iBuffer)[i].mMemory->getPointer()));
-        ASSERT_LE((*Info)[frameID].bytesCount,
-                  static_cast<int>((*iBuffer)[i].mMemory->getSize()));
-        eleStream.read(ipBuffer, (*Info)[frameID].bytesCount);
-        ASSERT_EQ(eleStream.gcount(), (*Info)[frameID].bytesCount);
-        flags = (*Info)[frameID].flags;
-        if (signalEOS && ((frameID == (int)Info->size() - 1) ||
-                          (frameID == (offset + range - 1))))
-            flags |= OMX_BUFFERFLAG_EOS;
-        dispatchInputBuffer(omxNode, iBuffer, i, (*Info)[frameID].bytesCount,
-                            flags, (*Info)[frameID].timestamp);
-        frameID++;
-    }
-
     int timeOut = TIMEOUT_COUNTER_Q;
     bool iQueued, oQueued;
+
     while (1) {
         iQueued = oQueued = false;
         status =
             observer->dequeueMessage(&msg, DEFAULT_TIMEOUT_Q, iBuffer, oBuffer);
-
         // Port Reconfiguration
         if (status == android::hardware::media::omx::V1_0::Status::OK &&
             msg.type == Message::Type::EVENT) {
@@ -717,7 +621,6 @@
         if (frameID == (int)Info->size() || frameID == (offset + range)) break;
 
         // Dispatch input buffer
-        size_t index = 0;
         if ((index = getEmptyBufferID(iBuffer)) < iBuffer->size()) {
             char* ipBuffer = static_cast<char*>(
                 static_cast<void*>((*iBuffer)[index].mMemory->getPointer()));
@@ -726,6 +629,11 @@
             eleStream.read(ipBuffer, (*Info)[frameID].bytesCount);
             ASSERT_EQ(eleStream.gcount(), (*Info)[frameID].bytesCount);
             flags = (*Info)[frameID].flags;
+            // Indicate to omx core that the buffer contains a full frame worth
+            // of data
+            flags |= OMX_BUFFERFLAG_ENDOFFRAME;
+            // Indicate the omx core that this is the last buffer it needs to
+            // process
             if (signalEOS && ((frameID == (int)Info->size() - 1) ||
                               (frameID == (offset + range - 1))))
                 flags |= OMX_BUFFERFLAG_EOS;
@@ -735,10 +643,12 @@
             frameID++;
             iQueued = true;
         }
+        // Dispatch output buffer
         if ((index = getEmptyBufferID(oBuffer)) < oBuffer->size()) {
             dispatchOutputBuffer(omxNode, oBuffer, index, oPortMode);
             oQueued = true;
         }
+        // Reset Counters when either input or output buffer is dispatched
         if (iQueued || oQueued)
             timeOut = TIMEOUT_COUNTER_Q;
         else
@@ -971,30 +881,14 @@
     setDefaultPortParam(omxNode, kPortIndexOutput, OMX_VIDEO_CodingUnused,
                         eColorFormat, nFrameWidth, nFrameHeight, 0, xFramerate);
 
-    // disabling adaptive playback.
-    omxNode->prepareForAdaptivePlayback(kPortIndexOutput, false, 1920, 1080);
-
     android::Vector<BufferInfo> iBuffer, oBuffer;
 
     // set state to idle
     changeStateLoadedtoIdle(omxNode, observer, &iBuffer, &oBuffer,
-                            kPortIndexInput, kPortIndexOutput, portMode);
+                            kPortIndexInput, kPortIndexOutput, portMode, true);
     // set state to executing
     changeStateIdletoExecute(omxNode, observer);
 
-    if (portMode[1] != PortMode::PRESET_BYTE_BUFFER) {
-        OMX_PARAM_PORTDEFINITIONTYPE portDef;
-
-        status = getPortParam(omxNode, OMX_IndexParamPortDefinition,
-                              kPortIndexOutput, &portDef);
-        ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
-        allocateGraphicBuffers(
-            omxNode, kPortIndexOutput, &oBuffer,
-            portDef.format.video.nFrameWidth, portDef.format.video.nFrameHeight,
-            &portDef.format.video.nStride, portDef.format.video.eColorFormat,
-            portDef.nBufferCountActual);
-    }
-
     // Port Reconfiguration
     eleStream.open(mURL, std::ifstream::binary);
     ASSERT_EQ(eleStream.is_open(), true);
@@ -1014,6 +908,148 @@
                             kPortIndexInput, kPortIndexOutput);
 }
 
+// Test for adaptive playback support
+TEST_F(VideoDecHidlTest, AdaptivePlaybackTest) {
+    description("Tests for Adaptive Playback support");
+    if (disableTest) return;
+    if (!(compName == avc || compName == hevc || compName == vp8 ||
+          compName == vp9 || compName == mpeg2))
+        return;
+    android::hardware::media::omx::V1_0::Status status;
+    uint32_t kPortIndexInput = 0, kPortIndexOutput = 1;
+    status = setRole(omxNode, gEnv->getRole().c_str());
+    ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
+    OMX_PORT_PARAM_TYPE params;
+    status = getParam(omxNode, OMX_IndexParamVideoInit, &params);
+    if (status == ::android::hardware::media::omx::V1_0::Status::OK) {
+        ASSERT_EQ(params.nPorts, 2U);
+        kPortIndexInput = params.nStartPortNumber;
+        kPortIndexOutput = kPortIndexInput + 1;
+    }
+
+    // set port mode
+    portMode[0] = PortMode::PRESET_BYTE_BUFFER;
+    portMode[1] = PortMode::DYNAMIC_ANW_BUFFER;
+    status = omxNode->setPortMode(kPortIndexInput, portMode[0]);
+    ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
+    status = omxNode->setPortMode(kPortIndexOutput, portMode[1]);
+    if (status != ::android::hardware::media::omx::V1_0::Status::OK) {
+        portMode[1] = PortMode::PRESET_BYTE_BUFFER;
+        status = omxNode->setPortMode(kPortIndexOutput, portMode[1]);
+        ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
+    }
+
+    // prepare for adaptive playback
+    uint32_t adaptiveMaxWidth = 320;
+    uint32_t adaptiveMaxHeight = 240;
+    status = omxNode->prepareForAdaptivePlayback(
+        kPortIndexOutput, true, adaptiveMaxWidth, adaptiveMaxHeight);
+    if (strncmp(gEnv->getComponent().c_str(), "OMX.google.", 11) == 0) {
+        // SoftOMX Decoders donot support graphic buffer modes. So for them
+        // support for adaptive play back is mandatory in Byte Buffer mode
+        ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
+    } else {
+        // for vendor codecs, support for adaptive play back is optional
+        // in byte buffer mode.
+        if (portMode[1] == PortMode::PRESET_BYTE_BUFFER) return;
+        if (status != ::android::hardware::media::omx::V1_0::Status::OK) return;
+    }
+
+    // TODO: Handle this better !!!
+    // Without the knowledge of the maximum resolution of the frame to be
+    // decoded it is not possible to choose the size of the input buffer.
+    // The value below is based on the info. files of clips in res folder.
+    status = setPortBufferSize(omxNode, kPortIndexInput, 482304);
+    ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
+
+    // set Port Params
+    uint32_t nFrameWidth, nFrameHeight, xFramerate;
+    getInputChannelInfo(omxNode, kPortIndexInput, &nFrameWidth, &nFrameHeight,
+                        &xFramerate);
+    // get default color format
+    OMX_COLOR_FORMATTYPE eColorFormat = OMX_COLOR_FormatUnused;
+    getDefaultColorFormat(omxNode, kPortIndexOutput, portMode[1],
+                          &eColorFormat);
+    ASSERT_NE(eColorFormat, OMX_COLOR_FormatUnused);
+    status =
+        setVideoPortFormat(omxNode, kPortIndexOutput, OMX_VIDEO_CodingUnused,
+                           eColorFormat, xFramerate);
+    EXPECT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
+    setDefaultPortParam(omxNode, kPortIndexOutput, OMX_VIDEO_CodingUnused,
+                        eColorFormat, nFrameWidth, nFrameHeight, 0, xFramerate);
+
+    android::Vector<BufferInfo> iBuffer, oBuffer;
+
+    // set state to idle
+    changeStateLoadedtoIdle(omxNode, observer, &iBuffer, &oBuffer,
+                            kPortIndexInput, kPortIndexOutput, portMode, true);
+    // set state to executing
+    changeStateIdletoExecute(omxNode, observer);
+
+    timestampDevTest = true;
+    uint32_t timestampOffset = 0;
+    for (uint32_t i = 0; i < STREAM_COUNT * 2; i++) {
+        std::ifstream eleStream, eleInfo;
+        char mURL[512], info[512];
+        android::Vector<FrameData> Info;
+        strcpy(mURL, gEnv->getRes().c_str());
+        strcpy(info, gEnv->getRes().c_str());
+        GetURLForComponent(compName, mURL, info, i % STREAM_COUNT);
+        eleInfo.open(info);
+        ASSERT_EQ(eleInfo.is_open(), true);
+        int bytesCount = 0;
+        uint32_t flags = 0;
+        uint32_t timestamp = 0;
+        uint32_t timestampMax = 0;
+        while (1) {
+            if (!(eleInfo >> bytesCount)) break;
+            eleInfo >> flags;
+            eleInfo >> timestamp;
+            timestamp += timestampOffset;
+            Info.push_back({bytesCount, flags, timestamp});
+            if (timestampDevTest && (flags != OMX_BUFFERFLAG_CODECCONFIG))
+                timestampUslist.push_back(timestamp);
+            if (timestampMax < timestamp) timestampMax = timestamp;
+        }
+        timestampOffset = timestampMax;
+        eleInfo.close();
+
+        // Port Reconfiguration
+        eleStream.open(mURL, std::ifstream::binary);
+        ASSERT_EQ(eleStream.is_open(), true);
+        decodeNFrames(omxNode, observer, &iBuffer, &oBuffer, kPortIndexInput,
+                      kPortIndexOutput, eleStream, &Info, 0, (int)Info.size(),
+                      portMode[1], false);
+        eleStream.close();
+
+        getInputChannelInfo(omxNode, kPortIndexInput, &nFrameWidth,
+                            &nFrameHeight, &xFramerate);
+        if ((nFrameWidth > adaptiveMaxWidth) ||
+            (nFrameHeight > adaptiveMaxHeight)) {
+            if (nFrameWidth > adaptiveMaxWidth) adaptiveMaxWidth = nFrameWidth;
+            if (nFrameHeight > adaptiveMaxHeight)
+                adaptiveMaxHeight = nFrameHeight;
+            EXPECT_TRUE(portSettingsChange);
+        } else {
+            // In DynamicANW Buffer mode, its ok to do a complete
+            // reconfiguration even if a partial reconfiguration is sufficient.
+            if (portMode[1] != PortMode::DYNAMIC_ANW_BUFFER)
+                EXPECT_FALSE(portSettingsChange);
+        }
+        portSettingsChange = false;
+    }
+    waitOnInputConsumption(omxNode, observer, &iBuffer, &oBuffer,
+                           kPortIndexInput, kPortIndexOutput, portMode[1]);
+    testEOS(omxNode, observer, &iBuffer, &oBuffer, true, eosFlag, portMode,
+            portReconfiguration, kPortIndexInput, kPortIndexOutput, nullptr);
+    if (timestampDevTest) EXPECT_EQ(timestampUslist.empty(), true);
+    // set state to idle
+    changeStateExecutetoIdle(omxNode, observer, &iBuffer, &oBuffer);
+    // set state to executing
+    changeStateIdletoLoaded(omxNode, observer, &iBuffer, &oBuffer,
+                            kPortIndexInput, kPortIndexOutput);
+}
+
 // end of sequence test
 TEST_F(VideoDecHidlTest, EOSTest_M) {
     description("Test End of stream monkeying");
@@ -1056,7 +1092,7 @@
 
     // set state to idle
     changeStateLoadedtoIdle(omxNode, observer, &iBuffer, &oBuffer,
-                            kPortIndexInput, kPortIndexOutput, portMode);
+                            kPortIndexInput, kPortIndexOutput, portMode, true);
     // set state to executing
     changeStateIdletoExecute(omxNode, observer);
 
@@ -1144,7 +1180,7 @@
 
     // set state to idle
     changeStateLoadedtoIdle(omxNode, observer, &iBuffer, &oBuffer,
-                            kPortIndexInput, kPortIndexOutput, portMode);
+                            kPortIndexInput, kPortIndexOutput, portMode, true);
     // set state to executing
     changeStateIdletoExecute(omxNode, observer);
 
@@ -1232,10 +1268,16 @@
     ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
 
     // set port mode
+    portMode[0] = PortMode::PRESET_BYTE_BUFFER;
+    portMode[1] = PortMode::PRESET_ANW_BUFFER;
     status = omxNode->setPortMode(kPortIndexInput, portMode[0]);
     ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
     status = omxNode->setPortMode(kPortIndexOutput, portMode[1]);
-    ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
+    if (status != ::android::hardware::media::omx::V1_0::Status::OK) {
+        portMode[1] = PortMode::PRESET_BYTE_BUFFER;
+        status = omxNode->setPortMode(kPortIndexOutput, portMode[1]);
+        ASSERT_EQ(status, ::android::hardware::media::omx::V1_0::Status::OK);
+    }
 
     // set Port Params
     uint32_t nFrameWidth, nFrameHeight, xFramerate;
@@ -1257,7 +1299,7 @@
 
     // set state to idle
     changeStateLoadedtoIdle(omxNode, observer, &iBuffer, &oBuffer,
-                            kPortIndexInput, kPortIndexOutput, portMode);
+                            kPortIndexInput, kPortIndexOutput, portMode, true);
     // set state to executing
     changeStateIdletoExecute(omxNode, observer);
 
@@ -1352,7 +1394,7 @@
 
     // set state to idle
     changeStateLoadedtoIdle(omxNode, observer, &iBuffer, &oBuffer,
-                            kPortIndexInput, kPortIndexOutput, portMode);
+                            kPortIndexInput, kPortIndexOutput, portMode, true);
     // set state to executing
     changeStateIdletoExecute(omxNode, observer);
 
diff --git a/media/omx/1.0/vts/functional/video/VtsHalMediaOmxV1_0TargetVideoEncTest.cpp b/media/omx/1.0/vts/functional/video/VtsHalMediaOmxV1_0TargetVideoEncTest.cpp
index fab5ef8..df90ccc 100644
--- a/media/omx/1.0/vts/functional/video/VtsHalMediaOmxV1_0TargetVideoEncTest.cpp
+++ b/media/omx/1.0/vts/functional/video/VtsHalMediaOmxV1_0TargetVideoEncTest.cpp
@@ -982,58 +982,25 @@
                    sp<CodecProducerListener> listener = nullptr) {
     android::hardware::media::omx::V1_0::Status status;
     Message msg;
-    uint32_t ipCount = 0;
+    uint64_t timestamp = 0;
+    uint32_t flags = 0;
+    int timeOut = TIMEOUT_COUNTER_Q;
+    bool iQueued, oQueued;
 
+    uint32_t ipCount = 0;
     if (ipCount == 0) {
         status = changeFrameRate(omxNode, portIndexOutput, (24U << 16));
         if (status == ::android::hardware::media::omx::V1_0::Status::OK)
             xFramerate = (24U << 16);
     }
-
-    // dispatch output buffers
-    for (size_t i = 0; i < oBuffer->size(); i++) {
-        dispatchOutputBuffer(omxNode, oBuffer, i);
-    }
-    // dispatch input buffers
     int32_t timestampIncr = (int)((float)1000000 / (xFramerate >> 16));
-    // timestamp scale = Nano sec
-    if (inputDataIsMeta) timestampIncr *= 1000;
-    uint64_t timestamp = 0;
-    uint32_t flags = 0;
-    for (size_t i = 0; i < iBuffer->size() && nFrames != 0; i++) {
-        if (inputDataIsMeta) {
-            if (listener->freeBuffers > listener->minUnDequeuedCount) {
-                if (dispatchGraphicBuffer(omxNode, producer, listener, iBuffer,
-                                          portIndexInput, eleStream, timestamp))
-                    break;
-                timestamp += timestampIncr;
-                nFrames--;
-                ipCount++;
-            }
-        } else {
-            char* ipBuffer = static_cast<char*>(
-                static_cast<void*>((*iBuffer)[i].mMemory->getPointer()));
-            ASSERT_LE(bytesCount,
-                      static_cast<int>((*iBuffer)[i].mMemory->getSize()));
-            if (fillByteBuffer(omxNode, ipBuffer, portIndexInput, eleStream))
-                break;
-            if (signalEOS && (nFrames == 1)) flags = OMX_BUFFERFLAG_EOS;
-            dispatchInputBuffer(omxNode, iBuffer, i, bytesCount, flags,
-                                timestamp);
-            if (timestampUslist) timestampUslist->push_back(timestamp);
-            timestamp += timestampIncr;
-            nFrames--;
-            ipCount++;
-        }
-    }
+    if (inputDataIsMeta) timestampIncr *= 1000;  // timestamp scale: Nano sec
 
-    int timeOut = TIMEOUT_COUNTER_Q;
-    bool iQueued, oQueued;
     while (1) {
         iQueued = oQueued = false;
         status =
             observer->dequeueMessage(&msg, DEFAULT_TIMEOUT_Q, iBuffer, oBuffer);
-
+        // Port Reconfiguration
         if (status == android::hardware::media::omx::V1_0::Status::OK) {
             ASSERT_EQ(msg.type, Message::Type::EVENT);
             if (msg.data.eventData.event == OMX_EventPortSettingsChanged) {
@@ -1075,7 +1042,8 @@
                 if (fillByteBuffer(omxNode, ipBuffer, portIndexInput,
                                    eleStream))
                     break;
-                if (signalEOS && (nFrames == 1)) flags = OMX_BUFFERFLAG_EOS;
+                flags = OMX_BUFFERFLAG_ENDOFFRAME;
+                if (signalEOS && (nFrames == 1)) flags |= OMX_BUFFERFLAG_EOS;
                 dispatchInputBuffer(omxNode, iBuffer, index, bytesCount, flags,
                                     timestamp);
                 if (timestampUslist) timestampUslist->push_back(timestamp);
@@ -1085,10 +1053,12 @@
                 iQueued = true;
             }
         }
+        // Dispatch output buffer
         if ((index = getEmptyBufferID(oBuffer)) < oBuffer->size()) {
             dispatchOutputBuffer(omxNode, oBuffer, index);
             oQueued = true;
         }
+        // Reset Counters when either input or output buffer is dispatched
         if (iQueued || oQueued)
             timeOut = TIMEOUT_COUNTER_Q;
         else
@@ -1097,6 +1067,7 @@
             EXPECT_TRUE(false) << "Wait on Input/Output is found indefinite";
             break;
         }
+        // Runtime Param Configuration
         if (ipCount == 15) {
             changeBitrate(omxNode, portIndexOutput, 768000);
             requestIDR(omxNode, portIndexOutput);
diff --git a/media/res/bbb_avc_176x144_300kbps_60fps.h264 b/media/res/bbb_avc_176x144_300kbps_60fps.h264
new file mode 100644
index 0000000..da1e75d
--- /dev/null
+++ b/media/res/bbb_avc_176x144_300kbps_60fps.h264
Binary files differ
diff --git a/media/res/bbb_avc_176x144_300kbps_60fps.info b/media/res/bbb_avc_176x144_300kbps_60fps.info
new file mode 100644
index 0000000..d88b540
--- /dev/null
+++ b/media/res/bbb_avc_176x144_300kbps_60fps.info
@@ -0,0 +1,62 @@
+28 128 0
+10 128 0
+4780 32 33333
+960 0 100000
+480 0 66666
+246 0 50000
+264 0 83333
+1160 0 166666
+404 0 133333
+237 0 116666
+193 0 150000
+936 0 233333
+384 0 200000
+199 0 183333
+275 0 216666
+1086 0 300000
+520 0 266666
+301 0 250000
+270 0 283333
+1232 0 366666
+559 0 333333
+287 0 316666
+274 0 350000
+1084 0 433333
+485 0 400000
+307 0 383333
+284 0 416666
+1052 0 500000
+504 0 466666
+298 0 450000
+327 0 483333
+1189 0 566666
+358 0 533333
+172 0 516666
+185 0 550000
+1115 0 633333
+463 0 600000
+218 0 583333
+255 0 616666
+1155 0 700000
+622 0 666666
+356 0 650000
+341 0 683333
+1240 0 766666
+610 0 733333
+341 0 716666
+380 0 750000
+1326 0 833333
+620 0 800000
+396 0 783333
+353 0 816666
+1196 0 900000
+623 0 866666
+375 0 850000
+362 0 883333
+1192 0 966666
+654 0 933333
+359 0 916666
+352 0 950000
+828 0 1016666
+436 0 983333
+401 0 1000000
diff --git a/media/res/bbb_flac_stereo_680kbps_48000hz.flac b/media/res/bbb_flac_stereo_680kbps_48000hz.flac
new file mode 100644
index 0000000..db94d8e
--- /dev/null
+++ b/media/res/bbb_flac_stereo_680kbps_48000hz.flac
Binary files differ
diff --git a/media/res/bbb_flac_stereo_680kbps_48000hz.info b/media/res/bbb_flac_stereo_680kbps_48000hz.info
new file mode 100644
index 0000000..c572430
--- /dev/null
+++ b/media/res/bbb_flac_stereo_680kbps_48000hz.info
@@ -0,0 +1,415 @@
+42 128 0
+1386 32 0
+2401 32 24000
+2321 32 48000
+2367 32 72000
+2370 32 96000
+2334 32 120000
+2396 32 144000
+2375 32 168000
+2431 32 192000
+2428 32 216000
+2334 32 240000
+2261 32 264000
+2124 32 288000
+2152 32 312000
+2295 32 336000
+2183 32 360000
+2393 32 384000
+2400 32 408000
+2246 32 432000
+2289 32 456000
+2400 32 480000
+2335 32 504000
+2294 32 528000
+2260 32 552000
+2206 32 576000
+2185 32 600000
+2155 32 624000
+2118 32 648000
+2094 32 672000
+2050 32 696000
+2059 32 720000
+2030 32 744000
+2022 32 768000
+2078 32 792000
+2082 32 816000
+2094 32 840000
+2111 32 864000
+2043 32 888000
+2023 32 912000
+2024 32 936000
+2056 32 960000
+2108 32 984000
+2138 32 1008000
+2140 32 1032000
+2111 32 1056000
+2110 32 1080000
+2137 32 1104000
+2157 32 1128000
+2174 32 1152000
+2200 32 1176000
+2203 32 1200000
+2237 32 1224000
+2261 32 1248000
+2215 32 1272000
+2133 32 1296000
+2091 32 1320000
+2088 32 1344000
+2122 32 1368000
+2139 32 1392000
+2146 32 1416000
+2231 32 1440000
+2282 32 1464000
+2273 32 1488000
+2304 32 1512000
+2292 32 1536000
+2255 32 1560000
+2181 32 1584000
+2081 32 1608000
+2012 32 1632000
+2011 32 1656000
+2066 32 1680000
+2069 32 1704000
+2120 32 1728000
+2141 32 1752000
+2148 32 1776000
+2181 32 1800000
+2176 32 1824000
+2240 32 1848000
+2297 32 1872000
+2325 32 1896000
+2336 32 1920000
+2329 32 1944000
+2299 32 1968000
+2322 32 1992000
+2347 32 2016000
+2287 32 2040000
+2286 32 2064000
+2269 32 2088000
+2320 32 2112000
+2305 32 2136000
+2384 32 2160000
+2429 32 2184000
+2370 32 2208000
+2365 32 2232000
+2361 32 2256000
+2370 32 2280000
+2393 32 2304000
+2342 32 2328000
+2325 32 2352000
+2334 32 2376000
+2316 32 2400000
+2317 32 2424000
+2305 32 2448000
+2360 32 2472000
+2331 32 2496000
+2332 32 2520000
+2361 32 2544000
+2417 32 2568000
+2438 32 2592000
+2403 32 2616000
+2386 32 2640000
+2382 32 2664000
+2350 32 2688000
+2355 32 2712000
+2383 32 2736000
+2384 32 2760000
+2383 32 2784000
+2373 32 2808000
+2374 32 2832000
+2347 32 2856000
+2353 32 2880000
+2381 32 2904000
+2401 32 2928000
+2401 32 2952000
+2385 32 2976000
+2382 32 3000000
+2328 32 3024000
+2303 32 3048000
+2272 32 3072000
+2270 32 3096000
+2312 32 3120000
+2273 32 3144000
+2330 32 3168000
+2339 32 3192000
+2296 32 3216000
+2317 32 3240000
+2440 32 3264000
+2353 32 3288000
+2346 32 3312000
+2303 32 3336000
+2308 32 3360000
+2287 32 3384000
+2316 32 3408000
+2367 32 3432000
+2335 32 3456000
+2350 32 3480000
+2395 32 3504000
+2408 32 3528000
+2413 32 3552000
+2415 32 3576000
+2468 32 3600000
+2437 32 3624000
+2372 32 3648000
+2371 32 3672000
+2341 32 3696000
+2328 32 3720000
+2273 32 3744000
+2244 32 3768000
+2233 32 3792000
+2229 32 3816000
+2252 32 3840000
+2236 32 3864000
+2217 32 3888000
+2179 32 3912000
+2251 32 3936000
+2192 32 3960000
+2199 32 3984000
+2212 32 4008000
+2190 32 4032000
+2102 32 4056000
+2120 32 4080000
+2167 32 4104000
+2024 32 4128000
+2010 32 4152000
+2067 32 4176000
+2035 32 4200000
+2051 32 4224000
+2012 32 4248000
+2066 32 4272000
+2025 32 4296000
+1987 32 4320000
+1972 32 4344000
+1966 32 4368000
+1999 32 4392000
+1987 32 4416000
+1922 32 4440000
+2020 32 4464000
+2072 32 4488000
+2021 32 4512000
+2017 32 4536000
+2099 32 4560000
+2064 32 4584000
+2109 32 4608000
+2093 32 4632000
+2090 32 4656000
+2148 32 4680000
+2184 32 4704000
+2179 32 4728000
+2152 32 4752000
+2143 32 4776000
+2159 32 4800000
+2123 32 4824000
+2129 32 4848000
+2147 32 4872000
+2192 32 4896000
+2051 32 4920000
+2116 32 4944000
+2124 32 4968000
+2088 32 4992000
+2073 32 5016000
+2146 32 5040000
+2133 32 5064000
+2073 32 5088000
+2059 32 5112000
+2044 32 5136000
+2012 32 5160000
+2034 32 5184000
+2053 32 5208000
+2013 32 5232000
+1981 32 5256000
+2094 32 5280000
+2076 32 5304000
+1968 32 5328000
+2028 32 5352000
+2031 32 5376000
+2020 32 5400000
+2019 32 5424000
+2030 32 5448000
+2015 32 5472000
+1962 32 5496000
+2070 32 5520000
+2087 32 5544000
+1964 32 5568000
+2069 32 5592000
+2034 32 5616000
+1994 32 5640000
+1985 32 5664000
+2030 32 5688000
+2066 32 5712000
+1954 32 5736000
+1733 32 5760000
+1649 32 5784000
+1652 32 5808000
+1631 32 5832000
+1656 32 5856000
+1672 32 5880000
+1667 32 5904000
+1696 32 5928000
+1672 32 5952000
+1701 32 5976000
+1651 32 6000000
+1674 32 6024000
+1695 32 6048000
+1702 32 6072000
+1707 32 6096000
+1694 32 6120000
+1727 32 6144000
+1730 32 6168000
+1708 32 6192000
+1704 32 6216000
+1735 32 6240000
+1758 32 6264000
+1753 32 6288000
+1748 32 6312000
+1763 32 6336000
+1737 32 6360000
+1783 32 6384000
+1839 32 6408000
+1861 32 6432000
+1832 32 6456000
+1947 32 6480000
+1939 32 6504000
+1926 32 6528000
+1896 32 6552000
+1909 32 6576000
+1869 32 6600000
+1900 32 6624000
+1896 32 6648000
+1883 32 6672000
+1903 32 6696000
+1895 32 6720000
+1865 32 6744000
+1878 32 6768000
+1881 32 6792000
+1861 32 6816000
+1791 32 6840000
+1787 32 6864000
+1798 32 6888000
+1811 32 6912000
+1824 32 6936000
+1895 32 6960000
+2079 32 6984000
+2034 32 7008000
+2038 32 7032000
+2018 32 7056000
+2030 32 7080000
+2067 32 7104000
+1982 32 7128000
+1911 32 7152000
+1904 32 7176000
+1874 32 7200000
+1876 32 7224000
+1944 32 7248000
+1977 32 7272000
+1977 32 7296000
+1979 32 7320000
+2012 32 7344000
+1961 32 7368000
+1773 32 7392000
+1780 32 7416000
+1801 32 7440000
+1892 32 7464000
+1869 32 7488000
+1936 32 7512000
+2154 32 7536000
+2226 32 7560000
+2159 32 7584000
+2253 32 7608000
+2286 32 7632000
+2214 32 7656000
+2111 32 7680000
+2027 32 7704000
+1994 32 7728000
+1882 32 7752000
+1887 32 7776000
+1993 32 7800000
+1962 32 7824000
+1982 32 7848000
+1966 32 7872000
+1962 32 7896000
+1928 32 7920000
+1878 32 7944000
+1857 32 7968000
+1885 32 7992000
+1919 32 8016000
+1904 32 8040000
+1909 32 8064000
+1909 32 8088000
+1933 32 8112000
+1824 32 8136000
+1756 32 8160000
+1733 32 8184000
+1705 32 8208000
+1755 32 8232000
+1756 32 8256000
+1725 32 8280000
+1761 32 8304000
+1736 32 8328000
+1706 32 8352000
+1662 32 8376000
+1604 32 8400000
+1613 32 8424000
+1692 32 8448000
+1736 32 8472000
+1779 32 8496000
+1768 32 8520000
+1758 32 8544000
+1708 32 8568000
+1642 32 8592000
+1645 32 8616000
+1581 32 8640000
+1651 32 8664000
+1731 32 8688000
+1743 32 8712000
+1717 32 8736000
+1715 32 8760000
+1646 32 8784000
+1551 32 8808000
+1563 32 8832000
+1649 32 8856000
+1742 32 8880000
+1724 32 8904000
+1676 32 8928000
+1664 32 8952000
+1587 32 8976000
+1497 32 9000000
+1503 32 9024000
+1644 32 9048000
+1658 32 9072000
+1680 32 9096000
+1611 32 9120000
+1694 32 9144000
+1668 32 9168000
+1677 32 9192000
+1604 32 9216000
+1567 32 9240000
+1639 32 9264000
+1552 32 9288000
+1486 32 9312000
+1494 32 9336000
+1480 32 9360000
+1509 32 9384000
+1457 32 9408000
+1423 32 9432000
+1459 32 9456000
+1444 32 9480000
+1424 32 9504000
+1413 32 9528000
+1498 32 9552000
+1455 32 9576000
+1393 32 9600000
+1638 32 9624000
+1919 32 9648000
+1979 32 9672000
+1894 32 9696000
+2002 32 9720000
+2062 32 9744000
+2098 32 9768000
+1919 32 9792000
+1738 32 9816000
+1890 32 9840000
+1971 32 9864000
+2429 32 9888000
+1861 32 9912000
diff --git a/media/res/bbb_hevc_176x144_176kbps_60fps.hevc b/media/res/bbb_hevc_176x144_176kbps_60fps.hevc
new file mode 100644
index 0000000..f82236f
--- /dev/null
+++ b/media/res/bbb_hevc_176x144_176kbps_60fps.hevc
Binary files differ
diff --git a/media/res/bbb_hevc_176x144_176kbps_60fps.info b/media/res/bbb_hevc_176x144_176kbps_60fps.info
new file mode 100644
index 0000000..702b853
--- /dev/null
+++ b/media/res/bbb_hevc_176x144_176kbps_60fps.info
@@ -0,0 +1,61 @@
+1695 128 0
+1938 32 33333
+471 0 83333
+153 0 66666
+99 0 50000
+657 0 150000
+260 0 116666
+115 0 100000
+99 0 133333
+622 0 216666
+211 0 183333
+79 0 166666
+95 0 200000
+597 0 283333
+288 0 250000
+145 0 233333
+147 0 266666
+676 0 350000
+284 0 316666
+144 0 300000
+131 0 333333
+658 0 416666
+270 0 383333
+101 0 366666
+151 0 400000
+529 0 483333
+257 0 450000
+98 0 433333
+160 0 466666
+664 0 566666
+186 0 533333
+147 0 500000
+67 0 516666
+78 0 550000
+575 0 633333
+230 0 600000
+134 0 583333
+114 0 616666
+629 0 700000
+224 0 666666
+138 0 650000
+129 0 683333
+645 0 750000
+264 0 733333
+145 0 716666
+705 0 816666
+365 0 783333
+156 0 766666
+160 0 800000
+725 0 883333
+330 0 850000
+138 0 833333
+162 0 866666
+638 0 950000
+337 0 916666
+170 0 900000
+133 0 933333
+432 0 1016666
+287 0 983333
+130 0 966666
+136 0 1000000
diff --git a/media/res/bbb_mpeg2_352x288_1mbps_60fps.info b/media/res/bbb_mpeg2_352x288_1mbps_60fps.info
new file mode 100644
index 0000000..d5290d7
--- /dev/null
+++ b/media/res/bbb_mpeg2_352x288_1mbps_60fps.info
@@ -0,0 +1,60 @@
+16680 32 16666
+17017 0 33333
+10534 0 50000
+10289 0 66666
+3698 0 83333
+2776 0 100000
+1936 0 116666
+1493 0 133333
+1217 0 150000
+993 0 166666
+805 0 183333
+857 0 200000
+5082 32 216666
+812 0 233333
+718 0 250000
+746 0 266666
+762 0 283333
+865 0 300000
+782 0 316666
+833 0 333333
+750 0 350000
+819 0 366666
+826 0 383333
+846 0 400000
+4522 32 416666
+678 0 433333
+718 0 450000
+803 0 466666
+769 0 483333
+762 0 500000
+587 0 516666
+635 0 533333
+658 0 550000
+714 0 566666
+677 0 583333
+699 0 600000
+4616 32 616666
+800 0 633333
+831 0 650000
+928 0 666666
+869 0 683333
+931 0 700000
+930 0 716666
+974 0 733333
+978 0 750000
+932 0 766666
+918 0 783333
+978 0 800000
+4655 32 816666
+897 0 833333
+896 0 850000
+883 0 866666
+949 0 883333
+965 0 900000
+951 0 916666
+901 0 933333
+965 0 950000
+955 0 966666
+948 0 983333
+968 0 1000000
diff --git a/media/res/bbb_mpeg2_352x288_1mbps_60fps.m2v b/media/res/bbb_mpeg2_352x288_1mbps_60fps.m2v
new file mode 100644
index 0000000..2f67c2b
--- /dev/null
+++ b/media/res/bbb_mpeg2_352x288_1mbps_60fps.m2v
Binary files differ
diff --git a/media/res/bbb_vp8_176x144_240kbps_60fps.info b/media/res/bbb_vp8_176x144_240kbps_60fps.info
new file mode 100644
index 0000000..559f425
--- /dev/null
+++ b/media/res/bbb_vp8_176x144_240kbps_60fps.info
@@ -0,0 +1,60 @@
+10271 32 0
+106 0 17000
+134 0 33000
+149 0 50000
+152 0 67000
+159 0 83000
+114 0 100000
+723 0 117000
+175 0 133000
+186 0 150000
+201 0 167000
+270 0 183000
+383 0 200000
+255 0 217000
+286 0 233000
+273 0 250000
+1224 0 267000
+220 0 283000
+231 0 300000
+192 0 317000
+182 0 333000
+289 0 350000
+204 0 367000
+237 0 383000
+187 0 400000
+898 0 417000
+231 0 433000
+266 0 450000
+278 0 467000
+205 0 483000
+255 0 500000
+169 0 517000
+233 0 533000
+1011 0 550000
+202 0 567000
+251 0 583000
+223 0 600000
+283 0 617000
+362 0 633000
+217 0 650000
+245 0 667000
+960 0 683000
+233 0 700000
+286 0 717000
+272 0 733000
+254 0 750000
+331 0 767000
+218 0 783000
+261 0 800000
+981 0 817000
+226 0 833000
+226 0 850000
+279 0 867000
+225 0 883000
+295 0 900000
+175 0 917000
+249 0 933000
+996 0 950000
+169 0 967000
+224 0 983000
diff --git a/media/res/bbb_vp8_176x144_240kbps_60fps.vp8 b/media/res/bbb_vp8_176x144_240kbps_60fps.vp8
new file mode 100644
index 0000000..6eba56c
--- /dev/null
+++ b/media/res/bbb_vp8_176x144_240kbps_60fps.vp8
Binary files differ
diff --git a/media/res/bbb_vp9_176x144_285kbps_60fps.info b/media/res/bbb_vp9_176x144_285kbps_60fps.info
new file mode 100644
index 0000000..2f7d35b
--- /dev/null
+++ b/media/res/bbb_vp9_176x144_285kbps_60fps.info
@@ -0,0 +1,60 @@
+6939 32 0
+6818 0 17000
+310 0 33000
+273 0 50000
+267 0 67000
+239 0 83000
+232 0 100000
+222 0 117000
+186 0 133000
+194 0 150000
+189 0 167000
+18 0 183000
+2014 0 200000
+297 0 217000
+287 0 233000
+237 0 250000
+263 0 267000
+238 0 283000
+257 0 300000
+229 0 317000
+187 0 333000
+191 0 350000
+18 0 367000
+2203 0 383000
+265 0 400000
+224 0 417000
+254 0 433000
+252 0 450000
+273 0 467000
+208 0 483000
+154 0 500000
+182 0 517000
+138 0 533000
+18 0 550000
+2502 0 567000
+286 0 583000
+304 0 600000
+341 0 617000
+259 0 633000
+275 0 650000
+222 0 667000
+254 0 683000
+253 0 700000
+225 0 717000
+18 0 733000
+2501 0 750000
+282 0 767000
+298 0 783000
+252 0 800000
+242 0 817000
+250 0 833000
+260 0 850000
+218 0 867000
+213 0 883000
+144 0 900000
+18 0 917000
+233 0 933000
+254 0 950000
+229 0 967000
+239 0 983000
diff --git a/media/res/bbb_vp9_176x144_285kbps_60fps.vp9 b/media/res/bbb_vp9_176x144_285kbps_60fps.vp9
new file mode 100644
index 0000000..2633c8a
--- /dev/null
+++ b/media/res/bbb_vp9_176x144_285kbps_60fps.vp9
Binary files differ
diff --git a/sensors/1.0/default/android.hardware.sensors@1.0-service.rc b/sensors/1.0/default/android.hardware.sensors@1.0-service.rc
index 059e5db..6e78082 100644
--- a/sensors/1.0/default/android.hardware.sensors@1.0-service.rc
+++ b/sensors/1.0/default/android.hardware.sensors@1.0-service.rc
@@ -1,5 +1,5 @@
 service sensors-hal-1-0 /vendor/bin/hw/android.hardware.sensors@1.0-service
     class hal
     user system
-    group system
-    capabilities SYS_NICE
+    group system wakelock
+    capabilities BLOCK_SUSPEND SYS_NICE