Move hybrid interface from libbinder to libhidl/transport.

Also, merge android.hardware.media.omx@1.0-impl into libstagefright_omx.

Test: With CtsMediaTestCases.apk installed,
adb shell am instrument -e size small -w
'android.media.cts/android.support.test.runner.AndroidJUnitRunner'
Test: Manual use of Camera, Photos, Play Movies and YouTube apps.
Test: Manual use of screen mirroring.

Bug: 33854657
Change-Id: Ie927bcafd86dc7e9509bb8b76bb3b51f9a423cc7
diff --git a/camera/cameraserver/Android.mk b/camera/cameraserver/Android.mk
index f0a0db0..d32e252 100644
--- a/camera/cameraserver/Android.mk
+++ b/camera/cameraserver/Android.mk
@@ -24,6 +24,7 @@
 	liblog \
 	libutils \
 	libui \
+	libgui \
 	libbinder \
 	libhidltransport \
 	android.hardware.camera.common@1.0 \
diff --git a/include/media/omx/1.0/Conversion.h b/include/media/omx/1.0/Conversion.h
index f3f8441..9816fe1 100644
--- a/include/media/omx/1.0/Conversion.h
+++ b/include/media/omx/1.0/Conversion.h
@@ -30,8 +30,8 @@
 #include <binder/Status.h>
 #include <ui/FenceTime.h>
 #include <cutils/native_handle.h>
-#include <gui/IGraphicBufferProducer.h>
 
+#include <ui/GraphicBuffer.h>
 #include <media/OMXFenceParcelable.h>
 #include <media/OMXBuffer.h>
 #include <media/hardware/VideoAPI.h>
@@ -40,10 +40,8 @@
 #include <android/hardware/media/omx/1.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/IOmxBufferProducer.h>
 #include <android/hardware/media/omx/1.0/IOmxBufferSource.h>
 #include <android/hardware/media/omx/1.0/IOmxObserver.h>
-#include <android/hardware/media/omx/1.0/IOmxProducerListener.h>
 #include <android/hardware/media/omx/1.0/IGraphicBufferSource.h>
 
 #include <android/IGraphicBufferSource.h>
@@ -95,9 +93,6 @@
 using ::android::hardware::media::omx::V1_0::IOmxBufferSource;
 using ::android::IOMXBufferSource;
 
-using ::android::hardware::media::omx::V1_0::IOmxBufferProducer;
-using ::android::IGraphicBufferProducer;
-
 // native_handle_t helper functions.
 
 /**
@@ -894,1279 +889,6 @@
 #endif
 }
 
-/**
- * Conversion functions for types outside media
- * ============================================
- *
- * Some objects in libui and libgui that were made to go through binder calls do
- * not expose ways to read or write their fields to the public. To pass an
- * object of this kind through the HIDL boundary, translation functions need to
- * work around the access restriction by using the publicly available
- * `flatten()` and `unflatten()` functions.
- *
- * All `flatten()` and `unflatten()` overloads follow the same convention as
- * follows:
- *
- *     status_t flatten(ObjectType const& object,
- *                      [OtherType const& other, ...]
- *                      void*& buffer, size_t& size,
- *                      int*& fds, size_t& numFds)
- *
- *     status_t unflatten(ObjectType* object,
- *                        [OtherType* other, ...,]
- *                        void*& buffer, size_t& size,
- *                        int*& fds, size_t& numFds)
- *
- * The number of `other` parameters varies depending on the `ObjectType`. For
- * example, in the process of unflattening an object that contains
- * `hidl_handle`, `other` is needed to hold `native_handle_t` objects that will
- * be created.
- *
- * The last four parameters always work the same way in all overloads of
- * `flatten()` and `unflatten()`:
- * - For `flatten()`, `buffer` is the pointer to the non-fd buffer to be filled,
- *   `size` is the size (in bytes) of the non-fd buffer pointed to by `buffer`,
- *   `fds` is the pointer to the fd buffer to be filled, and `numFds` is the
- *   size (in ints) of the fd buffer pointed to by `fds`.
- * - For `unflatten()`, `buffer` is the pointer to the non-fd buffer to be read
- *   from, `size` is the size (in bytes) of the non-fd buffer pointed to by
- *   `buffer`, `fds` is the pointer to the fd buffer to be read from, and
- *   `numFds` is the size (in ints) of the fd buffer pointed to by `fds`.
- * - After a successful call to `flatten()` or `unflatten()`, `buffer` and `fds`
- *   will be advanced, while `size` and `numFds` will be decreased to reflect
- *   how much storage/data of the two buffers (fd and non-fd) have been used.
- * - After an unsuccessful call, the values of `buffer`, `size`, `fds` and
- *   `numFds` are invalid.
- *
- * The return value of a successful `flatten()` or `unflatten()` call will be
- * `OK` (also aliased as `NO_ERROR`). Any other values indicate a failure.
- *
- * For each object type that supports flattening, there will be two accompanying
- * functions: `getFlattenedSize()` and `getFdCount()`. `getFlattenedSize()` will
- * return the size of the non-fd buffer that the object will need for
- * flattening. `getFdCount()` will return the size of the fd buffer that the
- * object will need for flattening.
- *
- * The set of these four functions, `getFlattenedSize()`, `getFdCount()`,
- * `flatten()` and `unflatten()`, are similar to functions of the same name in
- * the abstract class `Flattenable`. The only difference is that functions in
- * this file are not member functions of the object type. For example, we write
- *
- *     flatten(x, buffer, size, fds, numFds)
- *
- * instead of
- *
- *     x.flatten(buffer, size, fds, numFds)
- *
- * because we cannot modify the type of `x`.
- *
- * There is one exception to the naming convention: `hidl_handle` that
- * represents a fence. The four functions for this "Fence" type have the word
- * "Fence" attched to their names because the object type, which is
- * `hidl_handle`, does not carry the special meaning that the object itself can
- * only contain zero or one file descriptor.
- */
-
-// Ref: frameworks/native/libs/ui/Fence.cpp
-
-/**
- * \brief Return the size of the non-fd buffer required to flatten a fence.
- *
- * \param[in] fence The input fence of type `hidl_handle`.
- * \return The required size of the flat buffer.
- *
- * The current version of this function always returns 4, which is the number of
- * bytes required to store the number of file descriptors contained in the fd
- * part of the flat buffer.
- */
-inline size_t getFenceFlattenedSize(hidl_handle const& /* fence */) {
-    return 4;
-};
-
-/**
- * \brief Return the number of file descriptors contained in a fence.
- *
- * \param[in] fence The input fence of type `hidl_handle`.
- * \return `0` if \p fence does not contain a valid file descriptor, or `1`
- * otherwise.
- */
-inline size_t getFenceFdCount(hidl_handle const& fence) {
-    return native_handle_read_fd(fence) == -1 ? 0 : 1;
-}
-
-/**
- * \brief Unflatten `Fence` to `hidl_handle`.
- *
- * \param[out] fence The destination `hidl_handle`.
- * \param[out] nh The underlying native handle.
- * \param[in,out] buffer The pointer to the flat non-fd buffer.
- * \param[in,out] size The size of the flat non-fd buffer.
- * \param[in,out] fds The pointer to the flat fd buffer.
- * \param[in,out] numFds The size of the flat fd buffer.
- * \return `NO_ERROR` on success; other value on failure.
- *
- * If the return value is `NO_ERROR`, \p nh will point to a newly created
- * native handle, which needs to be deleted with `native_handle_delete()`
- * afterwards.
- */
-inline status_t unflattenFence(hidl_handle* fence, native_handle_t** nh,
-        void const*& buffer, size_t& size, int const*& fds, size_t& numFds) {
-    if (size < 4) {
-        return NO_MEMORY;
-    }
-
-    uint32_t numFdsInHandle;
-    FlattenableUtils::read(buffer, size, numFdsInHandle);
-
-    if (numFdsInHandle > 1) {
-        return BAD_VALUE;
-    }
-
-    if (numFds < numFdsInHandle) {
-        return NO_MEMORY;
-    }
-
-    if (numFdsInHandle) {
-        *nh = native_handle_create_from_fd(*fds);
-        if (*nh == nullptr) {
-            return NO_MEMORY;
-        }
-        *fence = *nh;
-        ++fds;
-        --numFds;
-    } else {
-        *nh = nullptr;
-        *fence = hidl_handle();
-    }
-
-    return NO_ERROR;
-}
-
-/**
- * \brief Flatten `hidl_handle` as `Fence`.
- *
- * \param[in] t The source `hidl_handle`.
- * \param[in,out] buffer The pointer to the flat non-fd buffer.
- * \param[in,out] size The size of the flat non-fd buffer.
- * \param[in,out] fds The pointer to the flat fd buffer.
- * \param[in,out] numFds The size of the flat fd buffer.
- * \return `NO_ERROR` on success; other value on failure.
- */
-inline status_t flattenFence(hidl_handle const& fence,
-        void*& buffer, size_t& size, int*& fds, size_t& numFds) {
-    if (size < getFenceFlattenedSize(fence) ||
-            numFds < getFenceFdCount(fence)) {
-        return NO_MEMORY;
-    }
-    // Cast to uint32_t since the size of a size_t can vary between 32- and
-    // 64-bit processes
-    FlattenableUtils::write(buffer, size,
-            static_cast<uint32_t>(getFenceFdCount(fence)));
-    int fd = native_handle_read_fd(fence);
-    if (fd != -1) {
-        *fds = fd;
-        ++fds;
-        --numFds;
-    }
-    return NO_ERROR;
-}
-
-/**
- * \brief Wrap `Fence` in `hidl_handle`.
- *
- * \param[out] t The wrapper of type `hidl_handle`.
- * \param[out] nh The native handle pointed to by \p t.
- * \param[in] l The source `Fence`.
- *
- * On success, \p nh will hold a newly created native handle, which must be
- * deleted manually with `native_handle_delete()` afterwards.
- */
-// wrap: Fence -> hidl_handle
-inline bool wrapAs(hidl_handle* t, native_handle_t** nh, Fence const& l) {
-    size_t const baseSize = l.getFlattenedSize();
-    std::unique_ptr<uint8_t[]> baseBuffer(
-            new (std::nothrow) uint8_t[baseSize]);
-    if (!baseBuffer) {
-        return false;
-    }
-
-    size_t const baseNumFds = l.getFdCount();
-    std::unique_ptr<int[]> baseFds(
-            new (std::nothrow) int[baseNumFds]);
-    if (!baseFds) {
-        return false;
-    }
-
-    void* buffer = static_cast<void*>(baseBuffer.get());
-    size_t size = baseSize;
-    int* fds = static_cast<int*>(baseFds.get());
-    size_t numFds = baseNumFds;
-    if (l.flatten(buffer, size, fds, numFds) != NO_ERROR) {
-        return false;
-    }
-
-    void const* constBuffer = static_cast<void const*>(baseBuffer.get());
-    size = baseSize;
-    int const* constFds = static_cast<int const*>(baseFds.get());
-    numFds = baseNumFds;
-    if (unflattenFence(t, nh, constBuffer, size, constFds, numFds)
-            != NO_ERROR) {
-        return false;
-    }
-
-    return true;
-}
-
-/**
- * \brief Convert `hidl_handle` to `Fence`.
- *
- * \param[out] l The destination `Fence`. `l` must not have been used
- * (`l->isValid()` must return `false`) before this function is called.
- * \param[in] t The source `hidl_handle`.
- *
- * If \p t contains a valid file descriptor, it will be duplicated.
- */
-// convert: hidl_handle -> Fence
-inline bool convertTo(Fence* l, hidl_handle const& t) {
-    int fd = native_handle_read_fd(t);
-    if (fd != -1) {
-        fd = dup(fd);
-        if (fd == -1) {
-            return false;
-        }
-    }
-    native_handle_t* nh = native_handle_create_from_fd(fd);
-    if (nh == nullptr) {
-        if (fd != -1) {
-            close(fd);
-        }
-        return false;
-    }
-
-    size_t const baseSize = getFenceFlattenedSize(t);
-    std::unique_ptr<uint8_t[]> baseBuffer(
-            new (std::nothrow) uint8_t[baseSize]);
-    if (!baseBuffer) {
-        native_handle_delete(nh);
-        return false;
-    }
-
-    size_t const baseNumFds = getFenceFdCount(t);
-    std::unique_ptr<int[]> baseFds(
-            new (std::nothrow) int[baseNumFds]);
-    if (!baseFds) {
-        native_handle_delete(nh);
-        return false;
-    }
-
-    void* buffer = static_cast<void*>(baseBuffer.get());
-    size_t size = baseSize;
-    int* fds = static_cast<int*>(baseFds.get());
-    size_t numFds = baseNumFds;
-    if (flattenFence(hidl_handle(nh), buffer, size, fds, numFds) != NO_ERROR) {
-        native_handle_delete(nh);
-        return false;
-    }
-    native_handle_delete(nh);
-
-    void const* constBuffer = static_cast<void const*>(baseBuffer.get());
-    size = baseSize;
-    int const* constFds = static_cast<int const*>(baseFds.get());
-    numFds = baseNumFds;
-    if (l->unflatten(constBuffer, size, constFds, numFds) != NO_ERROR) {
-        return false;
-    }
-
-    return true;
-}
-
-// Ref: frameworks/native/libs/ui/FenceTime.cpp: FenceTime::Snapshot
-
-/**
- * \brief Return the size of the non-fd buffer required to flatten
- * `FenceTimeSnapshot`.
- *
- * \param[in] t The input `FenceTimeSnapshot`.
- * \return The required size of the flat buffer.
- */
-inline size_t getFlattenedSize(
-        IOmxBufferProducer::FenceTimeSnapshot const& t) {
-    constexpr size_t min = sizeof(t.state);
-    switch (t.state) {
-        case IOmxBufferProducer::FenceTimeSnapshot::State::EMPTY:
-            return min;
-        case IOmxBufferProducer::FenceTimeSnapshot::State::FENCE:
-            return min + getFenceFlattenedSize(t.fence);
-        case IOmxBufferProducer::FenceTimeSnapshot::State::SIGNAL_TIME:
-            return min + sizeof(
-                    ::android::FenceTime::Snapshot::signalTime);
-    }
-    return 0;
-}
-
-/**
- * \brief Return the number of file descriptors contained in
- * `FenceTimeSnapshot`.
- *
- * \param[in] t The input `FenceTimeSnapshot`.
- * \return The number of file descriptors contained in \p snapshot.
- */
-inline size_t getFdCount(
-        IOmxBufferProducer::FenceTimeSnapshot const& t) {
-    return t.state ==
-            IOmxBufferProducer::FenceTimeSnapshot::State::FENCE ?
-            getFenceFdCount(t.fence) : 0;
-}
-
-/**
- * \brief Flatten `FenceTimeSnapshot`.
- *
- * \param[in] t The source `FenceTimeSnapshot`.
- * \param[in,out] buffer The pointer to the flat non-fd buffer.
- * \param[in,out] size The size of the flat non-fd buffer.
- * \param[in,out] fds The pointer to the flat fd buffer.
- * \param[in,out] numFds The size of the flat fd buffer.
- * \return `NO_ERROR` on success; other value on failure.
- *
- * This function will duplicate the file descriptor in `t.fence` if `t.state ==
- * FENCE`.
- */
-inline status_t flatten(IOmxBufferProducer::FenceTimeSnapshot const& t,
-        void*& buffer, size_t& size, int*& fds, size_t& numFds) {
-    if (size < getFlattenedSize(t)) {
-        return NO_MEMORY;
-    }
-
-    switch (t.state) {
-        case IOmxBufferProducer::FenceTimeSnapshot::State::EMPTY:
-            FlattenableUtils::write(buffer, size,
-                    ::android::FenceTime::Snapshot::State::EMPTY);
-            return NO_ERROR;
-        case IOmxBufferProducer::FenceTimeSnapshot::State::FENCE:
-            FlattenableUtils::write(buffer, size,
-                    ::android::FenceTime::Snapshot::State::FENCE);
-            return flattenFence(t.fence, buffer, size, fds, numFds);
-        case IOmxBufferProducer::FenceTimeSnapshot::State::SIGNAL_TIME:
-            FlattenableUtils::write(buffer, size,
-                    ::android::FenceTime::Snapshot::State::SIGNAL_TIME);
-            FlattenableUtils::write(buffer, size, t.signalTimeNs);
-            return NO_ERROR;
-    }
-    return NO_ERROR;
-}
-
-/**
- * \brief Unflatten `FenceTimeSnapshot`.
- *
- * \param[out] t The destination `FenceTimeSnapshot`.
- * \param[out] nh The underlying native handle.
- * \param[in,out] buffer The pointer to the flat non-fd buffer.
- * \param[in,out] size The size of the flat non-fd buffer.
- * \param[in,out] fds The pointer to the flat fd buffer.
- * \param[in,out] numFds The size of the flat fd buffer.
- * \return `NO_ERROR` on success; other value on failure.
- *
- * If the return value is `NO_ERROR` and the constructed snapshot contains a
- * file descriptor, \p nh will be created to hold that file descriptor. In this
- * case, \p nh needs to be deleted with `native_handle_delete()` afterwards.
- */
-inline status_t unflatten(
-        IOmxBufferProducer::FenceTimeSnapshot* t, native_handle_t** nh,
-        void const*& buffer, size_t& size, int const*& fds, size_t& numFds) {
-    if (size < sizeof(t->state)) {
-        return NO_MEMORY;
-    }
-
-    *nh = nullptr;
-    ::android::FenceTime::Snapshot::State state;
-    FlattenableUtils::read(buffer, size, state);
-    switch (state) {
-        case ::android::FenceTime::Snapshot::State::EMPTY:
-            t->state = IOmxBufferProducer::FenceTimeSnapshot::State::EMPTY;
-            return NO_ERROR;
-        case ::android::FenceTime::Snapshot::State::FENCE:
-            t->state = IOmxBufferProducer::FenceTimeSnapshot::State::FENCE;
-            return unflattenFence(&t->fence, nh, buffer, size, fds, numFds);
-        case ::android::FenceTime::Snapshot::State::SIGNAL_TIME:
-            t->state = IOmxBufferProducer::FenceTimeSnapshot::State::SIGNAL_TIME;
-            if (size < sizeof(t->signalTimeNs)) {
-                return NO_MEMORY;
-            }
-            FlattenableUtils::read(buffer, size, t->signalTimeNs);
-            return NO_ERROR;
-    }
-    return NO_ERROR;
-}
-
-// Ref: frameworks/native/libs/gui/FrameTimestamps.cpp: FrameEventsDelta
-
-/**
- * \brief Return a lower bound on the size of the non-fd buffer required to
- * flatten `FrameEventsDelta`.
- *
- * \param[in] t The input `FrameEventsDelta`.
- * \return A lower bound on the size of the flat buffer.
- */
-constexpr size_t minFlattenedSize(
-        IOmxBufferProducer::FrameEventsDelta const& /* t */) {
-    return sizeof(uint64_t) + // mFrameNumber
-            sizeof(uint8_t) + // mIndex
-            sizeof(uint8_t) + // mAddPostCompositeCalled
-            sizeof(uint8_t) + // mAddRetireCalled
-            sizeof(uint8_t) + // mAddReleaseCalled
-            sizeof(nsecs_t) + // mPostedTime
-            sizeof(nsecs_t) + // mRequestedPresentTime
-            sizeof(nsecs_t) + // mLatchTime
-            sizeof(nsecs_t) + // mFirstRefreshStartTime
-            sizeof(nsecs_t); // mLastRefreshStartTime
-}
-
-/**
- * \brief Return the size of the non-fd buffer required to flatten
- * `FrameEventsDelta`.
- *
- * \param[in] t The input `FrameEventsDelta`.
- * \return The required size of the flat buffer.
- */
-inline size_t getFlattenedSize(
-        IOmxBufferProducer::FrameEventsDelta const& t) {
-    return minFlattenedSize(t) +
-            getFlattenedSize(t.gpuCompositionDoneFence) +
-            getFlattenedSize(t.displayPresentFence) +
-            getFlattenedSize(t.displayRetireFence) +
-            getFlattenedSize(t.releaseFence);
-};
-
-/**
- * \brief Return the number of file descriptors contained in
- * `FrameEventsDelta`.
- *
- * \param[in] t The input `FrameEventsDelta`.
- * \return The number of file descriptors contained in \p t.
- */
-inline size_t getFdCount(
-        IOmxBufferProducer::FrameEventsDelta const& t) {
-    return getFdCount(t.gpuCompositionDoneFence) +
-            getFdCount(t.displayPresentFence) +
-            getFdCount(t.displayRetireFence) +
-            getFdCount(t.releaseFence);
-};
-
-/**
- * \brief Unflatten `FrameEventsDelta`.
- *
- * \param[out] t The destination `FrameEventsDelta`.
- * \param[out] nh The underlying array of native handles.
- * \param[in,out] buffer The pointer to the flat non-fd buffer.
- * \param[in,out] size The size of the flat non-fd buffer.
- * \param[in,out] fds The pointer to the flat fd buffer.
- * \param[in,out] numFds The size of the flat fd buffer.
- * \return `NO_ERROR` on success; other value on failure.
- *
- * If the return value is `NO_ERROR`, \p nh will have length 4, and it will be
- * populated with `nullptr` or newly created handles. Each non-null slot in \p
- * nh will need to be deleted manually with `native_handle_delete()`.
- */
-inline status_t unflatten(IOmxBufferProducer::FrameEventsDelta* t,
-        std::vector<native_handle_t*>* nh,
-        void const*& buffer, size_t& size, int const*& fds, size_t& numFds) {
-    if (size < minFlattenedSize(*t)) {
-        return NO_MEMORY;
-    }
-    FlattenableUtils::read(buffer, size, t->frameNumber);
-
-    // These were written as uint8_t for alignment.
-    uint8_t temp = 0;
-    FlattenableUtils::read(buffer, size, temp);
-    size_t index = static_cast<size_t>(temp);
-    if (index >= ::android::FrameEventHistory::MAX_FRAME_HISTORY) {
-        return BAD_VALUE;
-    }
-    t->index = static_cast<uint32_t>(index);
-
-    FlattenableUtils::read(buffer, size, temp);
-    t->addPostCompositeCalled = static_cast<bool>(temp);
-    FlattenableUtils::read(buffer, size, temp);
-    t->addRetireCalled = static_cast<bool>(temp);
-    FlattenableUtils::read(buffer, size, temp);
-    t->addReleaseCalled = static_cast<bool>(temp);
-
-    FlattenableUtils::read(buffer, size, t->postedTimeNs);
-    FlattenableUtils::read(buffer, size, t->requestedPresentTimeNs);
-    FlattenableUtils::read(buffer, size, t->latchTimeNs);
-    FlattenableUtils::read(buffer, size, t->firstRefreshStartTimeNs);
-    FlattenableUtils::read(buffer, size, t->lastRefreshStartTimeNs);
-    FlattenableUtils::read(buffer, size, t->dequeueReadyTime);
-
-    // Fences
-    IOmxBufferProducer::FenceTimeSnapshot* tSnapshot[4];
-    tSnapshot[0] = &t->gpuCompositionDoneFence;
-    tSnapshot[1] = &t->displayPresentFence;
-    tSnapshot[2] = &t->displayRetireFence;
-    tSnapshot[3] = &t->releaseFence;
-    nh->resize(4);
-    for (size_t snapshotIndex = 0; snapshotIndex < 4; ++snapshotIndex) {
-        status_t status = unflatten(
-                tSnapshot[snapshotIndex], &((*nh)[snapshotIndex]),
-                buffer, size, fds, numFds);
-        if (status != NO_ERROR) {
-            while (snapshotIndex > 0) {
-                --snapshotIndex;
-                if ((*nh)[snapshotIndex] != nullptr) {
-                    native_handle_delete((*nh)[snapshotIndex]);
-                }
-            }
-            return status;
-        }
-    }
-    return NO_ERROR;
-}
-
-/**
- * \brief Flatten `FrameEventsDelta`.
- *
- * \param[in] t The source `FrameEventsDelta`.
- * \param[in,out] buffer The pointer to the flat non-fd buffer.
- * \param[in,out] size The size of the flat non-fd buffer.
- * \param[in,out] fds The pointer to the flat fd buffer.
- * \param[in,out] numFds The size of the flat fd buffer.
- * \return `NO_ERROR` on success; other value on failure.
- *
- * This function will duplicate file descriptors contained in \p t.
- */
-// Ref: frameworks/native/libs/gui/FrameTimestamp.cpp:
-//      FrameEventsDelta::flatten
-inline status_t flatten(IOmxBufferProducer::FrameEventsDelta const& t,
-        void*& buffer, size_t& size, int*& fds, size_t numFds) {
-    // Check that t.index is within a valid range.
-    if (t.index >= static_cast<uint32_t>(FrameEventHistory::MAX_FRAME_HISTORY)
-            || t.index > std::numeric_limits<uint8_t>::max()) {
-        return BAD_VALUE;
-    }
-
-    FlattenableUtils::write(buffer, size, t.frameNumber);
-
-    // These are static_cast to uint8_t for alignment.
-    FlattenableUtils::write(buffer, size, static_cast<uint8_t>(t.index));
-    FlattenableUtils::write(
-            buffer, size, static_cast<uint8_t>(t.addPostCompositeCalled));
-    FlattenableUtils::write(
-            buffer, size, static_cast<uint8_t>(t.addRetireCalled));
-    FlattenableUtils::write(
-            buffer, size, static_cast<uint8_t>(t.addReleaseCalled));
-
-    FlattenableUtils::write(buffer, size, t.postedTimeNs);
-    FlattenableUtils::write(buffer, size, t.requestedPresentTimeNs);
-    FlattenableUtils::write(buffer, size, t.latchTimeNs);
-    FlattenableUtils::write(buffer, size, t.firstRefreshStartTimeNs);
-    FlattenableUtils::write(buffer, size, t.lastRefreshStartTimeNs);
-    FlattenableUtils::write(buffer, size, t.dequeueReadyTime);
-
-    // Fences
-    IOmxBufferProducer::FenceTimeSnapshot const* tSnapshot[4];
-    tSnapshot[0] = &t.gpuCompositionDoneFence;
-    tSnapshot[1] = &t.displayPresentFence;
-    tSnapshot[2] = &t.displayRetireFence;
-    tSnapshot[3] = &t.releaseFence;
-    for (size_t snapshotIndex = 0; snapshotIndex < 4; ++snapshotIndex) {
-        status_t status = flatten(
-                *(tSnapshot[snapshotIndex]), buffer, size, fds, numFds);
-        if (status != NO_ERROR) {
-            return status;
-        }
-    }
-    return NO_ERROR;
-}
-
-// Ref: frameworks/native/libs/gui/FrameTimestamps.cpp: FrameEventHistoryDelta
-
-/**
- * \brief Return the size of the non-fd buffer required to flatten
- * `IOmxBufferProducer::FrameEventHistoryDelta`.
- *
- * \param[in] t The input `IOmxBufferProducer::FrameEventHistoryDelta`.
- * \return The required size of the flat buffer.
- */
-inline size_t getFlattenedSize(
-        IOmxBufferProducer::FrameEventHistoryDelta const& t) {
-    size_t size = 4 + // mDeltas.size()
-            sizeof(t.compositorTiming);
-    for (size_t i = 0; i < t.deltas.size(); ++i) {
-        size += getFlattenedSize(t.deltas[i]);
-    }
-    return size;
-}
-
-/**
- * \brief Return the number of file descriptors contained in
- * `IOmxBufferProducer::FrameEventHistoryDelta`.
- *
- * \param[in] t The input `IOmxBufferProducer::FrameEventHistoryDelta`.
- * \return The number of file descriptors contained in \p t.
- */
-inline size_t getFdCount(
-        IOmxBufferProducer::FrameEventHistoryDelta const& t) {
-    size_t numFds = 0;
-    for (size_t i = 0; i < t.deltas.size(); ++i) {
-        numFds += getFdCount(t.deltas[i]);
-    }
-    return numFds;
-}
-
-/**
- * \brief Unflatten `FrameEventHistoryDelta`.
- *
- * \param[out] t The destination `FrameEventHistoryDelta`.
- * \param[out] nh The underlying array of arrays of native handles.
- * \param[in,out] buffer The pointer to the flat non-fd buffer.
- * \param[in,out] size The size of the flat non-fd buffer.
- * \param[in,out] fds The pointer to the flat fd buffer.
- * \param[in,out] numFds The size of the flat fd buffer.
- * \return `NO_ERROR` on success; other value on failure.
- *
- * If the return value is `NO_ERROR`, \p nh will be populated with `nullptr` or
- * newly created handles. The second dimension of \p nh will be 4. Each non-null
- * slot in \p nh will need to be deleted manually with `native_handle_delete()`.
- */
-inline status_t unflatten(
-        IOmxBufferProducer::FrameEventHistoryDelta* t,
-        std::vector<std::vector<native_handle_t*> >* nh,
-        void const*& buffer, size_t& size, int const*& fds, size_t& numFds) {
-    if (size < 4) {
-        return NO_MEMORY;
-    }
-
-    FlattenableUtils::read(buffer, size, t->compositorTiming);
-
-    uint32_t deltaCount = 0;
-    FlattenableUtils::read(buffer, size, deltaCount);
-    if (static_cast<size_t>(deltaCount) >
-            ::android::FrameEventHistory::MAX_FRAME_HISTORY) {
-        return BAD_VALUE;
-    }
-    t->deltas.resize(deltaCount);
-    nh->resize(deltaCount);
-    for (size_t deltaIndex = 0; deltaIndex < deltaCount; ++deltaIndex) {
-        status_t status = unflatten(
-                &(t->deltas[deltaIndex]), &((*nh)[deltaIndex]),
-                buffer, size, fds, numFds);
-        if (status != NO_ERROR) {
-            return status;
-        }
-    }
-    return NO_ERROR;
-}
-
-/**
- * \brief Flatten `FrameEventHistoryDelta`.
- *
- * \param[in] t The source `FrameEventHistoryDelta`.
- * \param[in,out] buffer The pointer to the flat non-fd buffer.
- * \param[in,out] size The size of the flat non-fd buffer.
- * \param[in,out] fds The pointer to the flat fd buffer.
- * \param[in,out] numFds The size of the flat fd buffer.
- * \return `NO_ERROR` on success; other value on failure.
- *
- * This function will duplicate file descriptors contained in \p t.
- */
-inline status_t flatten(
-        IOmxBufferProducer::FrameEventHistoryDelta const& t,
-        void*& buffer, size_t& size, int*& fds, size_t& numFds) {
-    if (t.deltas.size() > ::android::FrameEventHistory::MAX_FRAME_HISTORY) {
-        return BAD_VALUE;
-    }
-    if (size < getFlattenedSize(t)) {
-        return NO_MEMORY;
-    }
-
-    FlattenableUtils::write(buffer, size, t.compositorTiming);
-
-    FlattenableUtils::write(buffer, size, static_cast<uint32_t>(t.deltas.size()));
-    for (size_t deltaIndex = 0; deltaIndex < t.deltas.size(); ++deltaIndex) {
-        status_t status = flatten(t.deltas[deltaIndex], buffer, size, fds, numFds);
-        if (status != NO_ERROR) {
-            return status;
-        }
-    }
-    return NO_ERROR;
-}
-
-/**
- * \brief Wrap `::android::FrameEventHistoryData` in
- * `IOmxBufferProducer::FrameEventHistoryDelta`.
- *
- * \param[out] t The wrapper of type
- * `IOmxBufferProducer::FrameEventHistoryDelta`.
- * \param[out] nh The array of array of native handles that are referred to by
- * members of \p t.
- * \param[in] l The source `::android::FrameEventHistoryDelta`.
- *
- * On success, each member of \p nh will be either `nullptr` or a newly created
- * native handle. All the non-`nullptr` elements must be deleted individually
- * with `native_handle_delete()`.
- */
-inline bool wrapAs(IOmxBufferProducer::FrameEventHistoryDelta* t,
-        std::vector<std::vector<native_handle_t*> >* nh,
-        ::android::FrameEventHistoryDelta const& l) {
-
-    size_t const baseSize = l.getFlattenedSize();
-    std::unique_ptr<uint8_t[]> baseBuffer(
-            new (std::nothrow) uint8_t[baseSize]);
-    if (!baseBuffer) {
-        return false;
-    }
-
-    size_t const baseNumFds = l.getFdCount();
-    std::unique_ptr<int[]> baseFds(
-            new (std::nothrow) int[baseNumFds]);
-    if (!baseFds) {
-        return false;
-    }
-
-    void* buffer = static_cast<void*>(baseBuffer.get());
-    size_t size = baseSize;
-    int* fds = baseFds.get();
-    size_t numFds = baseNumFds;
-    if (l.flatten(buffer, size, fds, numFds) != NO_ERROR) {
-        return false;
-    }
-
-    void const* constBuffer = static_cast<void const*>(baseBuffer.get());
-    size = baseSize;
-    int const* constFds = static_cast<int const*>(baseFds.get());
-    numFds = baseNumFds;
-    if (unflatten(t, nh, constBuffer, size, constFds, numFds) != NO_ERROR) {
-        return false;
-    }
-
-    return true;
-}
-
-/**
- * \brief Convert `IOmxBufferProducer::FrameEventHistoryDelta` to
- * `::android::FrameEventHistoryDelta`.
- *
- * \param[out] l The destination `::android::FrameEventHistoryDelta`.
- * \param[in] t The source `IOmxBufferProducer::FrameEventHistoryDelta`.
- *
- * This function will duplicate all file descriptors contained in \p t.
- */
-inline bool convertTo(
-        ::android::FrameEventHistoryDelta* l,
-        IOmxBufferProducer::FrameEventHistoryDelta const& t) {
-
-    size_t const baseSize = getFlattenedSize(t);
-    std::unique_ptr<uint8_t[]> baseBuffer(
-            new (std::nothrow) uint8_t[baseSize]);
-    if (!baseBuffer) {
-        return false;
-    }
-
-    size_t const baseNumFds = getFdCount(t);
-    std::unique_ptr<int[]> baseFds(
-            new (std::nothrow) int[baseNumFds]);
-    if (!baseFds) {
-        return false;
-    }
-
-    void* buffer = static_cast<void*>(baseBuffer.get());
-    size_t size = baseSize;
-    int* fds = static_cast<int*>(baseFds.get());
-    size_t numFds = baseNumFds;
-    if (flatten(t, buffer, size, fds, numFds) != NO_ERROR) {
-        return false;
-    }
-
-    void const* constBuffer = static_cast<void const*>(baseBuffer.get());
-    size = baseSize;
-    int const* constFds = static_cast<int const*>(baseFds.get());
-    numFds = baseNumFds;
-    if (l->unflatten(constBuffer, size, constFds, numFds) != NO_ERROR) {
-        return false;
-    }
-
-    return true;
-}
-
-// Ref: frameworks/native/libs/ui/Region.cpp
-
-/**
- * \brief Return the size of the buffer required to flatten `Region`.
- *
- * \param[in] t The input `Region`.
- * \return The required size of the flat buffer.
- */
-inline size_t getFlattenedSize(Region const& t) {
-    return sizeof(uint32_t) + t.size() * sizeof(::android::Rect);
-}
-
-/**
- * \brief Unflatten `Region`.
- *
- * \param[out] t The destination `Region`.
- * \param[in,out] buffer The pointer to the flat buffer.
- * \param[in,out] size The size of the flat buffer.
- * \return `NO_ERROR` on success; other value on failure.
- */
-inline status_t unflatten(Region* t, void const*& buffer, size_t& size) {
-    if (size < sizeof(uint32_t)) {
-        return NO_MEMORY;
-    }
-
-    uint32_t numRects = 0;
-    FlattenableUtils::read(buffer, size, numRects);
-    if (size < numRects * sizeof(Rect)) {
-        return NO_MEMORY;
-    }
-    if (numRects > (UINT32_MAX / sizeof(Rect))) {
-        return NO_MEMORY;
-    }
-
-    t->resize(numRects);
-    for (size_t r = 0; r < numRects; ++r) {
-        ::android::Rect rect(::android::Rect::EMPTY_RECT);
-        status_t status = rect.unflatten(buffer, size);
-        if (status != NO_ERROR) {
-            return status;
-        }
-        FlattenableUtils::advance(buffer, size, sizeof(rect));
-        (*t)[r] = Rect{
-                static_cast<int32_t>(rect.left),
-                static_cast<int32_t>(rect.top),
-                static_cast<int32_t>(rect.right),
-                static_cast<int32_t>(rect.bottom)};
-    }
-    return NO_ERROR;
-}
-
-/**
- * \brief Flatten `Region`.
- *
- * \param[in] t The source `Region`.
- * \param[in,out] buffer The pointer to the flat buffer.
- * \param[in,out] size The size of the flat buffer.
- * \return `NO_ERROR` on success; other value on failure.
- */
-inline status_t flatten(Region const& t, void*& buffer, size_t& size) {
-    if (size < getFlattenedSize(t)) {
-        return NO_MEMORY;
-    }
-
-    FlattenableUtils::write(buffer, size, static_cast<uint32_t>(t.size()));
-    for (size_t r = 0; r < t.size(); ++r) {
-        ::android::Rect rect(
-                static_cast<int32_t>(t[r].left),
-                static_cast<int32_t>(t[r].top),
-                static_cast<int32_t>(t[r].right),
-                static_cast<int32_t>(t[r].bottom));
-        status_t status = rect.flatten(buffer, size);
-        if (status != NO_ERROR) {
-            return status;
-        }
-        FlattenableUtils::advance(buffer, size, sizeof(rect));
-    }
-    return NO_ERROR;
-}
-
-/**
- * \brief Convert `::android::Region` to `Region`.
- *
- * \param[out] t The destination `Region`.
- * \param[in] l The source `::android::Region`.
- */
-// convert: ::android::Region -> Region
-inline bool convertTo(Region* t, ::android::Region const& l) {
-    size_t const baseSize = l.getFlattenedSize();
-    std::unique_ptr<uint8_t[]> baseBuffer(
-            new (std::nothrow) uint8_t[baseSize]);
-    if (!baseBuffer) {
-        return false;
-    }
-
-    void* buffer = static_cast<void*>(baseBuffer.get());
-    size_t size = baseSize;
-    if (l.flatten(buffer, size) != NO_ERROR) {
-        return false;
-    }
-
-    void const* constBuffer = static_cast<void const*>(baseBuffer.get());
-    size = baseSize;
-    if (unflatten(t, constBuffer, size) != NO_ERROR) {
-        return false;
-    }
-
-    return true;
-}
-
-/**
- * \brief Convert `Region` to `::android::Region`.
- *
- * \param[out] l The destination `::android::Region`.
- * \param[in] t The source `Region`.
- */
-// convert: Region -> ::android::Region
-inline bool convertTo(::android::Region* l, Region const& t) {
-    size_t const baseSize = getFlattenedSize(t);
-    std::unique_ptr<uint8_t[]> baseBuffer(
-            new (std::nothrow) uint8_t[baseSize]);
-    if (!baseBuffer) {
-        return false;
-    }
-
-    void* buffer = static_cast<void*>(baseBuffer.get());
-    size_t size = baseSize;
-    if (flatten(t, buffer, size) != NO_ERROR) {
-        return false;
-    }
-
-    void const* constBuffer = static_cast<void const*>(baseBuffer.get());
-    size = baseSize;
-    if (l->unflatten(constBuffer, size) != NO_ERROR) {
-        return false;
-    }
-
-    return true;
-}
-
-// Ref: frameworks/native/libs/gui/IGraphicBufferProducer.cpp:
-//      IGraphicBufferProducer::QueueBufferInput
-
-/**
- * \brief Return a lower bound on the size of the buffer required to flatten
- * `IOmxBufferProducer::QueueBufferInput`.
- *
- * \param[in] t The input `IOmxBufferProducer::QueueBufferInput`.
- * \return A lower bound on the size of the flat buffer.
- */
-constexpr size_t minFlattenedSize(
-        IOmxBufferProducer::QueueBufferInput const& /* t */) {
-    return sizeof(int64_t) + // timestamp
-            sizeof(int) + // isAutoTimestamp
-            sizeof(android_dataspace) + // dataSpace
-            sizeof(::android::Rect) + // crop
-            sizeof(int) + // scalingMode
-            sizeof(uint32_t) + // transform
-            sizeof(uint32_t) + // stickyTransform
-            sizeof(bool); // getFrameTimestamps
-}
-
-/**
- * \brief Return the size of the buffer required to flatten
- * `IOmxBufferProducer::QueueBufferInput`.
- *
- * \param[in] t The input `IOmxBufferProducer::QueueBufferInput`.
- * \return The required size of the flat buffer.
- */
-inline size_t getFlattenedSize(IOmxBufferProducer::QueueBufferInput const& t) {
-    return minFlattenedSize(t) +
-            getFenceFlattenedSize(t.fence) +
-            getFlattenedSize(t.surfaceDamage);
-}
-
-/**
- * \brief Return the number of file descriptors contained in
- * `IOmxBufferProducer::QueueBufferInput`.
- *
- * \param[in] t The input `IOmxBufferProducer::QueueBufferInput`.
- * \return The number of file descriptors contained in \p t.
- */
-inline size_t getFdCount(
-        IOmxBufferProducer::QueueBufferInput const& t) {
-    return getFenceFdCount(t.fence);
-}
-
-/**
- * \brief Flatten `IOmxBufferProducer::QueueBufferInput`.
- *
- * \param[in] t The source `IOmxBufferProducer::QueueBufferInput`.
- * \param[out] nh The native handle cloned from `t.fence`.
- * \param[in,out] buffer The pointer to the flat non-fd buffer.
- * \param[in,out] size The size of the flat non-fd buffer.
- * \param[in,out] fds The pointer to the flat fd buffer.
- * \param[in,out] numFds The size of the flat fd buffer.
- * \return `NO_ERROR` on success; other value on failure.
- *
- * This function will duplicate the file descriptor in `t.fence`. */
-inline status_t flatten(IOmxBufferProducer::QueueBufferInput const& t,
-        native_handle_t** nh,
-        void*& buffer, size_t& size, int*& fds, size_t& numFds) {
-    if (size < getFlattenedSize(t)) {
-        return NO_MEMORY;
-    }
-
-    FlattenableUtils::write(buffer, size, t.timestamp);
-    FlattenableUtils::write(buffer, size, static_cast<int>(t.isAutoTimestamp));
-    FlattenableUtils::write(buffer, size,
-            static_cast<android_dataspace_t>(t.dataSpace));
-    FlattenableUtils::write(buffer, size, ::android::Rect(
-            static_cast<int32_t>(t.crop.left),
-            static_cast<int32_t>(t.crop.top),
-            static_cast<int32_t>(t.crop.right),
-            static_cast<int32_t>(t.crop.bottom)));
-    FlattenableUtils::write(buffer, size, static_cast<int>(t.scalingMode));
-    FlattenableUtils::write(buffer, size, t.transform);
-    FlattenableUtils::write(buffer, size, t.stickyTransform);
-    FlattenableUtils::write(buffer, size, t.getFrameTimestamps);
-
-    *nh = t.fence.getNativeHandle() == nullptr ?
-            nullptr : native_handle_clone(t.fence);
-    status_t status = flattenFence(hidl_handle(*nh), buffer, size, fds, numFds);
-    if (status != NO_ERROR) {
-        return status;
-    }
-    return flatten(t.surfaceDamage, buffer, size);
-}
-
-/**
- * \brief Unflatten `IOmxBufferProducer::QueueBufferInput`.
- *
- * \param[out] t The destination `IOmxBufferProducer::QueueBufferInput`.
- * \param[out] nh The underlying native handle for `t->fence`.
- * \param[in,out] buffer The pointer to the flat non-fd buffer.
- * \param[in,out] size The size of the flat non-fd buffer.
- * \param[in,out] fds The pointer to the flat fd buffer.
- * \param[in,out] numFds The size of the flat fd buffer.
- * \return `NO_ERROR` on success; other value on failure.
- *
- * If the return value is `NO_ERROR` and `t->fence` contains a valid file
- * descriptor, \p nh will be a newly created native handle holding that file
- * descriptor. \p nh needs to be deleted with `native_handle_delete()`
- * afterwards.
- */
-inline status_t unflatten(
-        IOmxBufferProducer::QueueBufferInput* t, native_handle_t** nh,
-        void const*& buffer, size_t& size, int const*& fds, size_t& numFds) {
-    if (size < minFlattenedSize(*t)) {
-        return NO_MEMORY;
-    }
-
-    FlattenableUtils::read(buffer, size, t->timestamp);
-    int lIsAutoTimestamp;
-    FlattenableUtils::read(buffer, size, lIsAutoTimestamp);
-    t->isAutoTimestamp = static_cast<int32_t>(lIsAutoTimestamp);
-    android_dataspace_t lDataSpace;
-    FlattenableUtils::read(buffer, size, lDataSpace);
-    t->dataSpace = static_cast<Dataspace>(lDataSpace);
-    Rect lCrop;
-    FlattenableUtils::read(buffer, size, lCrop);
-    t->crop = Rect{
-            static_cast<int32_t>(lCrop.left),
-            static_cast<int32_t>(lCrop.top),
-            static_cast<int32_t>(lCrop.right),
-            static_cast<int32_t>(lCrop.bottom)};
-    int lScalingMode;
-    FlattenableUtils::read(buffer, size, lScalingMode);
-    t->scalingMode = static_cast<int32_t>(lScalingMode);
-    FlattenableUtils::read(buffer, size, t->transform);
-    FlattenableUtils::read(buffer, size, t->stickyTransform);
-    FlattenableUtils::read(buffer, size, t->getFrameTimestamps);
-
-    status_t status = unflattenFence(&(t->fence), nh,
-            buffer, size, fds, numFds);
-    if (status != NO_ERROR) {
-        return status;
-    }
-    return unflatten(&(t->surfaceDamage), buffer, size);
-}
-
-/**
- * \brief Wrap `IGraphicBufferProducer::QueueBufferInput` in
- * `IOmxBufferProducer::QueueBufferInput`.
- *
- * \param[out] t The wrapper of type
- * `IOmxBufferProducer::QueueBufferInput`.
- * \param[out] nh The underlying native handle for `t->fence`.
- * \param[in] l The source `IGraphicBufferProducer::QueueBufferInput`.
- *
- * If the return value is `true` and `t->fence` contains a valid file
- * descriptor, \p nh will be a newly created native handle holding that file
- * descriptor. \p nh needs to be deleted with `native_handle_delete()`
- * afterwards.
- */
-inline bool wrapAs(
-        IOmxBufferProducer::QueueBufferInput* t,
-        native_handle_t** nh,
-        IGraphicBufferProducer::QueueBufferInput const& l) {
-
-    size_t const baseSize = l.getFlattenedSize();
-    std::unique_ptr<uint8_t[]> baseBuffer(
-            new (std::nothrow) uint8_t[baseSize]);
-    if (!baseBuffer) {
-        return false;
-    }
-
-    size_t const baseNumFds = l.getFdCount();
-    std::unique_ptr<int[]> baseFds(
-            new (std::nothrow) int[baseNumFds]);
-    if (!baseFds) {
-        return false;
-    }
-
-    void* buffer = static_cast<void*>(baseBuffer.get());
-    size_t size = baseSize;
-    int* fds = baseFds.get();
-    size_t numFds = baseNumFds;
-    if (l.flatten(buffer, size, fds, numFds) != NO_ERROR) {
-        return false;
-    }
-
-    void const* constBuffer = static_cast<void const*>(baseBuffer.get());
-    size = baseSize;
-    int const* constFds = static_cast<int const*>(baseFds.get());
-    numFds = baseNumFds;
-    if (unflatten(t, nh, constBuffer, size, constFds, numFds) != NO_ERROR) {
-        return false;
-    }
-
-    return true;
-}
-
-/**
- * \brief Convert `IOmxBufferProducer::QueueBufferInput` to
- * `IGraphicBufferProducer::QueueBufferInput`.
- *
- * \param[out] l The destination `IGraphicBufferProducer::QueueBufferInput`.
- * \param[in] t The source `IOmxBufferProducer::QueueBufferInput`.
- *
- * If `t.fence` has a valid file descriptor, it will be duplicated.
- */
-inline bool convertTo(
-        IGraphicBufferProducer::QueueBufferInput* l,
-        IOmxBufferProducer::QueueBufferInput const& t) {
-
-    size_t const baseSize = getFlattenedSize(t);
-    std::unique_ptr<uint8_t[]> baseBuffer(
-            new (std::nothrow) uint8_t[baseSize]);
-    if (!baseBuffer) {
-        return false;
-    }
-
-    size_t const baseNumFds = getFdCount(t);
-    std::unique_ptr<int[]> baseFds(
-            new (std::nothrow) int[baseNumFds]);
-    if (!baseFds) {
-        return false;
-    }
-
-    void* buffer = static_cast<void*>(baseBuffer.get());
-    size_t size = baseSize;
-    int* fds = baseFds.get();
-    size_t numFds = baseNumFds;
-    native_handle_t* nh;
-    if (flatten(t, &nh, buffer, size, fds, numFds) != NO_ERROR) {
-        return false;
-    }
-
-    void const* constBuffer = static_cast<void const*>(baseBuffer.get());
-    size = baseSize;
-    int const* constFds = static_cast<int const*>(baseFds.get());
-    numFds = baseNumFds;
-    if (l->unflatten(constBuffer, size, constFds, numFds) != NO_ERROR) {
-        native_handle_close(nh);
-        native_handle_delete(nh);
-        return false;
-    }
-
-    native_handle_delete(nh);
-    return true;
-}
-
-// Ref: frameworks/native/libs/gui/IGraphicBufferProducer.cpp:
-//      IGraphicBufferProducer::QueueBufferOutput
-
-/**
- * \brief Wrap `IGraphicBufferProducer::QueueBufferOutput` in
- * `IOmxBufferProducer::QueueBufferOutput`.
- *
- * \param[out] t The wrapper of type
- * `IOmxBufferProducer::QueueBufferOutput`.
- * \param[out] nh The array of array of native handles that are referred to by
- * members of \p t.
- * \param[in] l The source `IGraphicBufferProducer::QueueBufferOutput`.
- *
- * On success, each member of \p nh will be either `nullptr` or a newly created
- * native handle. All the non-`nullptr` elements must be deleted individually
- * with `native_handle_delete()`.
- */
-// wrap: IGraphicBufferProducer::QueueBufferOutput ->
-// IOmxBufferProducer::QueueBufferOutput
-inline bool wrapAs(IOmxBufferProducer::QueueBufferOutput* t,
-        std::vector<std::vector<native_handle_t*> >* nh,
-        IGraphicBufferProducer::QueueBufferOutput const& l) {
-    if (!wrapAs(&(t->frameTimestamps), nh, l.frameTimestamps)) {
-        return false;
-    }
-    t->width = l.width;
-    t->height = l.height;
-    t->transformHint = l.transformHint;
-    t->numPendingBuffers = l.numPendingBuffers;
-    t->nextFrameNumber = l.nextFrameNumber;
-    t->bufferReplaced = l.bufferReplaced;
-    return true;
-}
-
-/**
- * \brief Convert `IOmxBufferProducer::QueueBufferOutput` to
- * `IGraphicBufferProducer::QueueBufferOutput`.
- *
- * \param[out] l The destination `IGraphicBufferProducer::QueueBufferOutput`.
- * \param[in] t The source `IOmxBufferProducer::QueueBufferOutput`.
- *
- * This function will duplicate all file descriptors contained in \p t.
- */
-// convert: IOmxBufferProducer::QueueBufferOutput ->
-// IGraphicBufferProducer::QueueBufferOutput
-inline bool convertTo(
-        IGraphicBufferProducer::QueueBufferOutput* l,
-        IOmxBufferProducer::QueueBufferOutput const& t) {
-    if (!convertTo(&(l->frameTimestamps), t.frameTimestamps)) {
-        return false;
-    }
-    l->width = t.width;
-    l->height = t.height;
-    l->transformHint = t.transformHint;
-    l->numPendingBuffers = t.numPendingBuffers;
-    l->nextFrameNumber = t.nextFrameNumber;
-    l->bufferReplaced = t.bufferReplaced;
-    return true;
-}
-
-/**
- * \brief Convert `IGraphicBufferProducer::DisconnectMode` to
- * `IOmxBufferProducer::DisconnectMode`.
- *
- * \param[in] l The source `IGraphicBufferProducer::DisconnectMode`.
- * \return The corresponding `IOmxBufferProducer::DisconnectMode`.
- */
-inline IOmxBufferProducer::DisconnectMode toOmxDisconnectMode(
-        IGraphicBufferProducer::DisconnectMode l) {
-    switch (l) {
-        case IGraphicBufferProducer::DisconnectMode::Api:
-            return IOmxBufferProducer::DisconnectMode::API;
-        case IGraphicBufferProducer::DisconnectMode::AllLocal:
-            return IOmxBufferProducer::DisconnectMode::ALL_LOCAL;
-    }
-    return IOmxBufferProducer::DisconnectMode::API;
-}
-
-/**
- * \brief Convert `IOmxBufferProducer::DisconnectMode` to
- * `IGraphicBufferProducer::DisconnectMode`.
- *
- * \param[in] l The source `IOmxBufferProducer::DisconnectMode`.
- * \return The corresponding `IGraphicBufferProducer::DisconnectMode`.
- */
-inline IGraphicBufferProducer::DisconnectMode toGuiDisconnectMode(
-        IOmxBufferProducer::DisconnectMode t) {
-    switch (t) {
-        case IOmxBufferProducer::DisconnectMode::API:
-            return IGraphicBufferProducer::DisconnectMode::Api;
-        case IOmxBufferProducer::DisconnectMode::ALL_LOCAL:
-            return IGraphicBufferProducer::DisconnectMode::AllLocal;
-    }
-    return IGraphicBufferProducer::DisconnectMode::Api;
-}
-
 }  // namespace utils
 }  // namespace V1_0
 }  // namespace omx
diff --git a/include/media/omx/1.0/WOmx.h b/include/media/omx/1.0/WOmx.h
index 9268bd6..f13546e 100644
--- a/include/media/omx/1.0/WOmx.h
+++ b/include/media/omx/1.0/WOmx.h
@@ -22,6 +22,7 @@
 
 #include <media/IOMX.h>
 
+#include <hidl/HybridInterface.h>
 #include <android/hardware/media/omx/1.0/IOmx.h>
 
 namespace android {
diff --git a/include/media/omx/1.0/WOmxBufferProducer.h b/include/media/omx/1.0/WOmxBufferProducer.h
deleted file mode 100644
index 54b9078..0000000
--- a/include/media/omx/1.0/WOmxBufferProducer.h
+++ /dev/null
@@ -1,142 +0,0 @@
-/*
- * Copyright 2016, The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef ANDROID_HARDWARE_MEDIA_OMX_V1_0_WOMXBUFFERPRODUCER_H
-#define ANDROID_HARDWARE_MEDIA_OMX_V1_0_WOMXBUFFERPRODUCER_H
-
-#include <hidl/MQDescriptor.h>
-#include <hidl/Status.h>
-
-#include <binder/Binder.h>
-#include <gui/IGraphicBufferProducer.h>
-#include <gui/IProducerListener.h>
-
-#include <android/hardware/media/omx/1.0/IOmxBufferProducer.h>
-
-namespace android {
-namespace hardware {
-namespace media {
-namespace omx {
-namespace V1_0 {
-namespace utils {
-
-using ::android::hardware::graphics::common::V1_0::PixelFormat;
-using ::android::hardware::media::omx::V1_0::IOmxBufferProducer;
-using ::android::hardware::media::omx::V1_0::IOmxProducerListener;
-using ::android::hardware::media::omx::V1_0::Status;
-using ::android::hardware::media::V1_0::AnwBuffer;
-using ::android::hidl::base::V1_0::IBase;
-using ::android::hardware::hidl_array;
-using ::android::hardware::hidl_memory;
-using ::android::hardware::hidl_string;
-using ::android::hardware::hidl_vec;
-using ::android::hardware::Return;
-using ::android::hardware::Void;
-using ::android::sp;
-
-using ::android::IGraphicBufferProducer;
-using ::android::BnGraphicBufferProducer;
-using ::android::IProducerListener;
-
-struct TWOmxBufferProducer : public IOmxBufferProducer {
-    sp<IGraphicBufferProducer> mBase;
-    TWOmxBufferProducer(sp<IGraphicBufferProducer> const& base);
-    Return<void> requestBuffer(int32_t slot, requestBuffer_cb _hidl_cb)
-            override;
-    Return<Status> setMaxDequeuedBufferCount(int32_t maxDequeuedBuffers)
-            override;
-    Return<Status> setAsyncMode(bool async) override;
-    Return<void> dequeueBuffer(
-            uint32_t width, uint32_t height, PixelFormat format, uint32_t usage,
-            bool getFrameTimestamps, dequeueBuffer_cb _hidl_cb) override;
-    Return<Status> detachBuffer(int32_t slot) override;
-    Return<void> detachNextBuffer(detachNextBuffer_cb _hidl_cb) override;
-    Return<void> attachBuffer(const AnwBuffer& buffer, attachBuffer_cb _hidl_cb)
-            override;
-    Return<void> queueBuffer(
-            int32_t slot, const IOmxBufferProducer::QueueBufferInput& input,
-            queueBuffer_cb _hidl_cb) override;
-    Return<Status> cancelBuffer(int32_t slot, const hidl_handle& fence)
-            override;
-    Return<void> query(int32_t what, query_cb _hidl_cb) override;
-    Return<void> connect(const sp<IOmxProducerListener>& listener,
-            int32_t api, bool producerControlledByApp,
-            connect_cb _hidl_cb) override;
-    Return<Status> disconnect(
-            int32_t api,
-            IOmxBufferProducer::DisconnectMode mode) override;
-    Return<Status> setSidebandStream(const hidl_handle& stream) override;
-    Return<void> allocateBuffers(
-            uint32_t width, uint32_t height,
-            PixelFormat format, uint32_t usage) override;
-    Return<Status> allowAllocation(bool allow) override;
-    Return<Status> setGenerationNumber(uint32_t generationNumber) override;
-    Return<void> getConsumerName(getConsumerName_cb _hidl_cb) override;
-    Return<Status> setSharedBufferMode(bool sharedBufferMode) override;
-    Return<Status> setAutoRefresh(bool autoRefresh) override;
-    Return<Status> setDequeueTimeout(int64_t timeoutNs) override;
-    Return<void> getLastQueuedBuffer(getLastQueuedBuffer_cb _hidl_cb) override;
-    Return<void> getFrameTimestamps(getFrameTimestamps_cb _hidl_cb) override;
-    Return<void> getUniqueId(getUniqueId_cb _hidl_cb) override;
-};
-
-struct LWOmxBufferProducer : public BnGraphicBufferProducer {
-    sp<IOmxBufferProducer> mBase;
-    LWOmxBufferProducer(sp<IOmxBufferProducer> const& base);
-
-    status_t requestBuffer(int slot, sp<GraphicBuffer>* buf) override;
-    status_t setMaxDequeuedBufferCount(int maxDequeuedBuffers) override;
-    status_t setAsyncMode(bool async) override;
-    status_t dequeueBuffer(int* slot, sp<Fence>* fence, uint32_t w,
-            uint32_t h, ::android::PixelFormat format, uint32_t usage,
-            FrameEventHistoryDelta* outTimestamps) override;
-    status_t detachBuffer(int slot) override;
-    status_t detachNextBuffer(sp<GraphicBuffer>* outBuffer, sp<Fence>* outFence)
-            override;
-    status_t attachBuffer(int* outSlot, const sp<GraphicBuffer>& buffer)
-            override;
-    status_t queueBuffer(int slot,
-            const QueueBufferInput& input,
-            QueueBufferOutput* output) override;
-    status_t cancelBuffer(int slot, const sp<Fence>& fence) override;
-    int query(int what, int* value) override;
-    status_t connect(const sp<IProducerListener>& listener, int api,
-            bool producerControlledByApp, QueueBufferOutput* output) override;
-    status_t disconnect(int api, DisconnectMode mode = DisconnectMode::Api)
-            override;
-    status_t setSidebandStream(const sp<NativeHandle>& stream) override;
-    void allocateBuffers(uint32_t width, uint32_t height,
-            ::android::PixelFormat format, uint32_t usage) override;
-    status_t allowAllocation(bool allow) override;
-    status_t setGenerationNumber(uint32_t generationNumber) override;
-    String8 getConsumerName() const override;
-    status_t setSharedBufferMode(bool sharedBufferMode) override;
-    status_t setAutoRefresh(bool autoRefresh) override;
-    status_t setDequeueTimeout(nsecs_t timeout) override;
-    status_t getLastQueuedBuffer(sp<GraphicBuffer>* outBuffer,
-          sp<Fence>* outFence, float outTransformMatrix[16]) override;
-    void getFrameTimestamps(FrameEventHistoryDelta* outDelta) override;
-    status_t getUniqueId(uint64_t* outId) const override;
-};
-
-}  // namespace utils
-}  // namespace V1_0
-}  // namespace omx
-}  // namespace media
-}  // namespace hardware
-}  // namespace android
-
-#endif  // ANDROID_HARDWARE_MEDIA_OMX_V1_0_WOMXBUFFERPRODUCER_H
diff --git a/include/media/omx/1.0/WOmxNode.h b/include/media/omx/1.0/WOmxNode.h
index 3176a65..1d575e7 100644
--- a/include/media/omx/1.0/WOmxNode.h
+++ b/include/media/omx/1.0/WOmxNode.h
@@ -20,9 +20,9 @@
 #include <hidl/MQDescriptor.h>
 #include <hidl/Status.h>
 
-#include <binder/HalToken.h>
 #include <utils/Errors.h>
 #include <media/IOMX.h>
+#include <hidl/HybridInterface.h>
 
 #include <android/hardware/media/omx/1.0/IOmxNode.h>
 #include <android/hardware/media/omx/1.0/IOmxObserver.h>
diff --git a/include/media/omx/1.0/WOmxProducerListener.h b/include/media/omx/1.0/WOmxProducerListener.h
deleted file mode 100644
index 7d20887..0000000
--- a/include/media/omx/1.0/WOmxProducerListener.h
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Copyright 2016, The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef ANDROID_HARDWARE_MEDIA_OMX_V1_0_WOMXPRODUCERLISTENER_H
-#define ANDROID_HARDWARE_MEDIA_OMX_V1_0_WOMXPRODUCERLISTENER_H
-
-#include <hidl/MQDescriptor.h>
-#include <hidl/Status.h>
-
-#include <binder/IBinder.h>
-#include <gui/IProducerListener.h>
-
-#include <android/hardware/media/omx/1.0/IOmxProducerListener.h>
-
-namespace android {
-namespace hardware {
-namespace media {
-namespace omx {
-namespace V1_0 {
-namespace utils {
-
-using ::android::hardware::media::omx::V1_0::IOmxProducerListener;
-using ::android::hidl::base::V1_0::IBase;
-using ::android::hardware::hidl_array;
-using ::android::hardware::hidl_memory;
-using ::android::hardware::hidl_string;
-using ::android::hardware::hidl_vec;
-using ::android::hardware::Return;
-using ::android::hardware::Void;
-using ::android::sp;
-
-using ::android::IProducerListener;
-using ::android::BnProducerListener;
-
-struct TWOmxProducerListener : public IOmxProducerListener {
-    sp<IProducerListener> mBase;
-    TWOmxProducerListener(sp<IProducerListener> const& base);
-    Return<void> onBufferReleased() override;
-    Return<bool> needsReleaseNotify() override;
-};
-
-class LWOmxProducerListener : public BnProducerListener {
-public:
-    sp<IOmxProducerListener> mBase;
-    LWOmxProducerListener(sp<IOmxProducerListener> const& base);
-    void onBufferReleased() override;
-    bool needsReleaseNotify() override;
-};
-
-}  // namespace utils
-}  // namespace V1_0
-}  // namespace omx
-}  // namespace media
-}  // namespace hardware
-}  // namespace android
-
-#endif  // ANDROID_HARDWARE_MEDIA_OMX_V1_0_WOMXPRODUCERLISTENER_H
diff --git a/media/libmedia/Android.mk b/media/libmedia/Android.mk
index c057cf5..8a1ce22 100644
--- a/media/libmedia/Android.mk
+++ b/media/libmedia/Android.mk
@@ -57,11 +57,9 @@
     StringArray.cpp \
     omx/1.0/WGraphicBufferSource.cpp \
     omx/1.0/WOmx.cpp \
-    omx/1.0/WOmxBufferProducer.cpp \
     omx/1.0/WOmxBufferSource.cpp \
     omx/1.0/WOmxNode.cpp \
     omx/1.0/WOmxObserver.cpp \
-    omx/1.0/WOmxProducerListener.cpp \
 
 LOCAL_SHARED_LIBRARIES := \
         libui liblog libcutils libutils libbinder libsonivox libicuuc libicui18n libexpat \
@@ -75,7 +73,9 @@
         libhidlmemory \
         android.hidl.base@1.0 \
         android.hidl.memory@1.0 \
+        android.hidl.token@1.0-utils \
         android.hardware.graphics.common@1.0 \
+        android.hardware.graphics.bufferqueue@1.0 \
         android.hardware.media@1.0 \
         android.hardware.media.omx@1.0 \
 
@@ -83,6 +83,7 @@
         libbinder \
         libsonivox \
         libmediadrm \
+        android.hidl.token@1.0-utils \
         android.hardware.media.omx@1.0 \
         android.hidl.memory@1.0 \
 
@@ -104,7 +105,7 @@
 
 LOCAL_EXPORT_C_INCLUDE_DIRS := \
     frameworks/av/include/media \
-    frameworks/av/media/libmedia/aidl
+    frameworks/av/media/libmedia/aidl \
 
 LOCAL_CFLAGS += -Werror -Wno-error=deprecated-declarations -Wall
 LOCAL_SANITIZE := unsigned-integer-overflow signed-integer-overflow cfi
diff --git a/media/libmedia/include/IOMX.h b/media/libmedia/include/IOMX.h
index b4fc04c..62067c7 100644
--- a/media/libmedia/include/IOMX.h
+++ b/media/libmedia/include/IOMX.h
@@ -19,13 +19,13 @@
 #define ANDROID_IOMX_H_
 
 #include <binder/IInterface.h>
-#include <binder/HalToken.h>
 #include <utils/List.h>
 #include <utils/String8.h>
 #include <cutils/native_handle.h>
 
 #include <list>
 
+#include <hidl/HybridInterface.h>
 #include <media/hardware/MetadataBufferType.h>
 #include <android/hardware/media/omx/1.0/IOmxNode.h>
 
diff --git a/media/libmedia/omx/1.0/WOmx.cpp b/media/libmedia/omx/1.0/WOmx.cpp
index 8e4e147..ce624fa 100644
--- a/media/libmedia/omx/1.0/WOmx.cpp
+++ b/media/libmedia/omx/1.0/WOmx.cpp
@@ -14,10 +14,10 @@
  * limitations under the License.
  */
 
+#include <gui/bufferqueue/1.0/H2BGraphicBufferProducer.h>
 #include <media/omx/1.0/WOmx.h>
 #include <media/omx/1.0/WOmxNode.h>
 #include <media/omx/1.0/WOmxObserver.h>
-#include <media/omx/1.0/WOmxBufferProducer.h>
 #include <media/omx/1.0/WGraphicBufferSource.h>
 #include <media/omx/1.0/Conversion.h>
 
@@ -28,6 +28,11 @@
 namespace V1_0 {
 namespace utils {
 
+using ::android::hardware::graphics::bufferqueue::V1_0::utils::
+        H2BGraphicBufferProducer;
+typedef ::android::hardware::graphics::bufferqueue::V1_0::IGraphicBufferProducer
+        HGraphicBufferProducer;
+
 // LWOmx
 LWOmx::LWOmx(sp<IOmx> const& base) : mBase(base) {
 }
@@ -70,10 +75,10 @@
     status_t transStatus = toStatusT(mBase->createInputSurface(
             [&fnStatus, bufferProducer, bufferSource] (
                     Status status,
-                    sp<IOmxBufferProducer> const& tProducer,
+                    sp<HGraphicBufferProducer> const& tProducer,
                     sp<IGraphicBufferSource> const& tSource) {
                 fnStatus = toStatusT(status);
-                *bufferProducer = new LWOmxBufferProducer(tProducer);
+                *bufferProducer = new H2BGraphicBufferProducer(tProducer);
                 *bufferSource = new LWGraphicBufferSource(tSource);
             }));
     return transStatus == NO_ERROR ? fnStatus : transStatus;
diff --git a/media/libmedia/omx/1.0/WOmxBufferProducer.cpp b/media/libmedia/omx/1.0/WOmxBufferProducer.cpp
deleted file mode 100644
index 03499f2..0000000
--- a/media/libmedia/omx/1.0/WOmxBufferProducer.cpp
+++ /dev/null
@@ -1,610 +0,0 @@
-/*
- * Copyright 2016, The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define LOG_TAG "WOmxBufferProducer-utils"
-
-#include <utils/Log.h>
-
-#include <media/omx/1.0/WOmxBufferProducer.h>
-#include <media/omx/1.0/WOmxProducerListener.h>
-#include <media/omx/1.0/Conversion.h>
-
-namespace android {
-namespace hardware {
-namespace media {
-namespace omx {
-namespace V1_0 {
-namespace utils {
-
-// TWOmxBufferProducer
-TWOmxBufferProducer::TWOmxBufferProducer(
-        sp<IGraphicBufferProducer> const& base):
-    mBase(base) {
-}
-
-Return<void> TWOmxBufferProducer::requestBuffer(
-        int32_t slot, requestBuffer_cb _hidl_cb) {
-    sp<GraphicBuffer> buf;
-    status_t status = mBase->requestBuffer(slot, &buf);
-    AnwBuffer anwBuffer;
-    wrapAs(&anwBuffer, *buf);
-    _hidl_cb(toStatus(status), anwBuffer);
-    return Void();
-}
-
-Return<Status> TWOmxBufferProducer::setMaxDequeuedBufferCount(
-        int32_t maxDequeuedBuffers) {
-    return toStatus(mBase->setMaxDequeuedBufferCount(
-            static_cast<int>(maxDequeuedBuffers)));
-}
-
-Return<Status> TWOmxBufferProducer::setAsyncMode(bool async) {
-    return toStatus(mBase->setAsyncMode(async));
-}
-
-Return<void> TWOmxBufferProducer::dequeueBuffer(
-        uint32_t width, uint32_t height,
-        PixelFormat format, uint32_t usage,
-        bool getFrameTimestamps, dequeueBuffer_cb _hidl_cb) {
-    int slot;
-    sp<Fence> fence;
-    ::android::FrameEventHistoryDelta outTimestamps;
-    status_t status = mBase->dequeueBuffer(
-            &slot, &fence,
-            width, height,
-            static_cast<::android::PixelFormat>(format), usage,
-            getFrameTimestamps ? &outTimestamps : nullptr);
-    hidl_handle tFence;
-    FrameEventHistoryDelta tOutTimestamps;
-
-    native_handle_t* nh = nullptr;
-    if ((fence == nullptr) || !wrapAs(&tFence, &nh, *fence)) {
-        ALOGE("TWOmxBufferProducer::dequeueBuffer - Invalid output fence");
-        _hidl_cb(toStatus(status),
-                 static_cast<int32_t>(slot),
-                 tFence,
-                 tOutTimestamps);
-        return Void();
-    }
-    std::vector<std::vector<native_handle_t*> > nhAA;
-    if (getFrameTimestamps && !wrapAs(&tOutTimestamps, &nhAA, outTimestamps)) {
-        ALOGE("TWOmxBufferProducer::dequeueBuffer - Invalid output timestamps");
-        _hidl_cb(toStatus(status),
-                 static_cast<int32_t>(slot),
-                 tFence,
-                 tOutTimestamps);
-        native_handle_delete(nh);
-        return Void();
-    }
-
-    _hidl_cb(toStatus(status),
-            static_cast<int32_t>(slot),
-            tFence,
-            tOutTimestamps);
-    native_handle_delete(nh);
-    if (getFrameTimestamps) {
-        for (auto& nhA : nhAA) {
-            for (auto& handle : nhA) {
-                native_handle_delete(handle);
-            }
-        }
-    }
-    return Void();
-}
-
-Return<Status> TWOmxBufferProducer::detachBuffer(int32_t slot) {
-    return toStatus(mBase->detachBuffer(slot));
-}
-
-Return<void> TWOmxBufferProducer::detachNextBuffer(
-        detachNextBuffer_cb _hidl_cb) {
-    sp<GraphicBuffer> outBuffer;
-    sp<Fence> outFence;
-    status_t status = mBase->detachNextBuffer(&outBuffer, &outFence);
-    AnwBuffer tBuffer;
-    hidl_handle tFence;
-
-    if (outBuffer == nullptr) {
-        ALOGE("TWOmxBufferProducer::detachNextBuffer - Invalid output buffer");
-        _hidl_cb(toStatus(status), tBuffer, tFence);
-        return Void();
-    }
-    wrapAs(&tBuffer, *outBuffer);
-    native_handle_t* nh = nullptr;
-    if ((outFence != nullptr) && !wrapAs(&tFence, &nh, *outFence)) {
-        ALOGE("TWOmxBufferProducer::detachNextBuffer - Invalid output fence");
-        _hidl_cb(toStatus(status), tBuffer, tFence);
-        return Void();
-    }
-
-    _hidl_cb(toStatus(status), tBuffer, tFence);
-    native_handle_delete(nh);
-    return Void();
-}
-
-Return<void> TWOmxBufferProducer::attachBuffer(
-        const AnwBuffer& buffer,
-        attachBuffer_cb _hidl_cb) {
-    int outSlot;
-    sp<GraphicBuffer> lBuffer = new GraphicBuffer();
-    if (!convertTo(lBuffer.get(), buffer)) {
-        ALOGE("TWOmxBufferProducer::attachBuffer - "
-                "Invalid input native window buffer");
-        _hidl_cb(toStatus(BAD_VALUE), -1);
-        return Void();
-    }
-    status_t status = mBase->attachBuffer(&outSlot, lBuffer);
-
-    _hidl_cb(toStatus(status), static_cast<int32_t>(outSlot));
-    return Void();
-}
-
-Return<void> TWOmxBufferProducer::queueBuffer(
-        int32_t slot, const QueueBufferInput& input,
-        queueBuffer_cb _hidl_cb) {
-    QueueBufferOutput tOutput;
-    IGraphicBufferProducer::QueueBufferInput lInput(
-            0, false, HAL_DATASPACE_UNKNOWN,
-            ::android::Rect(0, 0, 1, 1),
-            NATIVE_WINDOW_SCALING_MODE_FREEZE,
-            0, ::android::Fence::NO_FENCE);
-    if (!convertTo(&lInput, input)) {
-        ALOGE("TWOmxBufferProducer::queueBuffer - Invalid input");
-        _hidl_cb(toStatus(BAD_VALUE), tOutput);
-        return Void();
-    }
-    IGraphicBufferProducer::QueueBufferOutput lOutput;
-    status_t status = mBase->queueBuffer(
-            static_cast<int>(slot), lInput, &lOutput);
-
-    std::vector<std::vector<native_handle_t*> > nhAA;
-    if (!wrapAs(&tOutput, &nhAA, lOutput)) {
-        ALOGE("TWOmxBufferProducer::queueBuffer - Invalid output");
-        _hidl_cb(toStatus(BAD_VALUE), tOutput);
-        return Void();
-    }
-
-    _hidl_cb(toStatus(status), tOutput);
-    for (auto& nhA : nhAA) {
-        for (auto& nh : nhA) {
-            native_handle_delete(nh);
-        }
-    }
-    return Void();
-}
-
-Return<Status> TWOmxBufferProducer::cancelBuffer(
-        int32_t slot, const hidl_handle& fence) {
-    sp<Fence> lFence = new Fence();
-    if (!convertTo(lFence.get(), fence)) {
-        ALOGE("TWOmxBufferProducer::cancelBuffer - Invalid input fence");
-        return toStatus(BAD_VALUE);
-    }
-    return toStatus(mBase->cancelBuffer(static_cast<int>(slot), lFence));
-}
-
-Return<void> TWOmxBufferProducer::query(int32_t what, query_cb _hidl_cb) {
-    int lValue;
-    int lReturn = mBase->query(static_cast<int>(what), &lValue);
-    _hidl_cb(static_cast<int32_t>(lReturn), static_cast<int32_t>(lValue));
-    return Void();
-}
-
-Return<void> TWOmxBufferProducer::connect(
-        const sp<IOmxProducerListener>& listener,
-        int32_t api, bool producerControlledByApp, connect_cb _hidl_cb) {
-    sp<IProducerListener> lListener = listener == nullptr ?
-            nullptr : new LWOmxProducerListener(listener);
-    IGraphicBufferProducer::QueueBufferOutput lOutput;
-    status_t status = mBase->connect(lListener,
-            static_cast<int>(api),
-            producerControlledByApp,
-            &lOutput);
-
-    QueueBufferOutput tOutput;
-    std::vector<std::vector<native_handle_t*> > nhAA;
-    if (!wrapAs(&tOutput, &nhAA, lOutput)) {
-        ALOGE("TWOmxBufferProducer::connect - Invalid output");
-        _hidl_cb(toStatus(status), tOutput);
-        return Void();
-    }
-
-    _hidl_cb(toStatus(status), tOutput);
-    for (auto& nhA : nhAA) {
-        for (auto& nh : nhA) {
-            native_handle_delete(nh);
-        }
-    }
-    return Void();
-}
-
-Return<Status> TWOmxBufferProducer::disconnect(
-        int32_t api, DisconnectMode mode) {
-    return toStatus(mBase->disconnect(
-            static_cast<int>(api),
-            toGuiDisconnectMode(mode)));
-}
-
-Return<Status> TWOmxBufferProducer::setSidebandStream(const hidl_handle& stream) {
-    return toStatus(mBase->setSidebandStream(NativeHandle::create(
-            native_handle_clone(stream), true)));
-}
-
-Return<void> TWOmxBufferProducer::allocateBuffers(
-        uint32_t width, uint32_t height, PixelFormat format, uint32_t usage) {
-    mBase->allocateBuffers(
-            width, height,
-            static_cast<::android::PixelFormat>(format),
-            usage);
-    return Void();
-}
-
-Return<Status> TWOmxBufferProducer::allowAllocation(bool allow) {
-    return toStatus(mBase->allowAllocation(allow));
-}
-
-Return<Status> TWOmxBufferProducer::setGenerationNumber(uint32_t generationNumber) {
-    return toStatus(mBase->setGenerationNumber(generationNumber));
-}
-
-Return<void> TWOmxBufferProducer::getConsumerName(getConsumerName_cb _hidl_cb) {
-    _hidl_cb(mBase->getConsumerName().string());
-    return Void();
-}
-
-Return<Status> TWOmxBufferProducer::setSharedBufferMode(bool sharedBufferMode) {
-    return toStatus(mBase->setSharedBufferMode(sharedBufferMode));
-}
-
-Return<Status> TWOmxBufferProducer::setAutoRefresh(bool autoRefresh) {
-    return toStatus(mBase->setAutoRefresh(autoRefresh));
-}
-
-Return<Status> TWOmxBufferProducer::setDequeueTimeout(int64_t timeoutNs) {
-    return toStatus(mBase->setDequeueTimeout(timeoutNs));
-}
-
-Return<void> TWOmxBufferProducer::getLastQueuedBuffer(
-        getLastQueuedBuffer_cb _hidl_cb) {
-    sp<GraphicBuffer> lOutBuffer = new GraphicBuffer();
-    sp<Fence> lOutFence = new Fence();
-    float lOutTransformMatrix[16];
-    status_t status = mBase->getLastQueuedBuffer(
-            &lOutBuffer, &lOutFence, lOutTransformMatrix);
-
-    AnwBuffer tOutBuffer;
-    if (lOutBuffer != nullptr) {
-        wrapAs(&tOutBuffer, *lOutBuffer);
-    }
-    hidl_handle tOutFence;
-    native_handle_t* nh = nullptr;
-    if ((lOutFence == nullptr) || !wrapAs(&tOutFence, &nh, *lOutFence)) {
-        ALOGE("TWOmxBufferProducer::getLastQueuedBuffer - "
-                "Invalid output fence");
-        _hidl_cb(toStatus(status),
-                tOutBuffer,
-                tOutFence,
-                hidl_array<float, 16>());
-        return Void();
-    }
-    hidl_array<float, 16> tOutTransformMatrix(lOutTransformMatrix);
-
-    _hidl_cb(toStatus(status), tOutBuffer, tOutFence, tOutTransformMatrix);
-    native_handle_delete(nh);
-    return Void();
-}
-
-Return<void> TWOmxBufferProducer::getFrameTimestamps(
-        getFrameTimestamps_cb _hidl_cb) {
-    ::android::FrameEventHistoryDelta lDelta;
-    mBase->getFrameTimestamps(&lDelta);
-
-    FrameEventHistoryDelta tDelta;
-    std::vector<std::vector<native_handle_t*> > nhAA;
-    if (!wrapAs(&tDelta, &nhAA, lDelta)) {
-        ALOGE("TWOmxBufferProducer::getFrameTimestamps - "
-                "Invalid output frame timestamps");
-        _hidl_cb(tDelta);
-        return Void();
-    }
-
-    _hidl_cb(tDelta);
-    for (auto& nhA : nhAA) {
-        for (auto& nh : nhA) {
-            native_handle_delete(nh);
-        }
-    }
-    return Void();
-}
-
-Return<void> TWOmxBufferProducer::getUniqueId(getUniqueId_cb _hidl_cb) {
-    uint64_t outId;
-    status_t status = mBase->getUniqueId(&outId);
-    _hidl_cb(toStatus(status), outId);
-    return Void();
-}
-
-// LWOmxBufferProducer
-
-LWOmxBufferProducer::LWOmxBufferProducer(sp<IOmxBufferProducer> const& base) :
-    mBase(base) {
-}
-
-status_t LWOmxBufferProducer::requestBuffer(int slot, sp<GraphicBuffer>* buf) {
-    *buf = new GraphicBuffer();
-    status_t fnStatus;
-    status_t transStatus = toStatusT(mBase->requestBuffer(
-            static_cast<int32_t>(slot),
-            [&fnStatus, &buf] (Status status, AnwBuffer const& buffer) {
-                fnStatus = toStatusT(status);
-                if (!convertTo(buf->get(), buffer)) {
-                    fnStatus = fnStatus == NO_ERROR ? BAD_VALUE : fnStatus;
-                }
-            }));
-    return transStatus == NO_ERROR ? fnStatus : transStatus;
-}
-
-status_t LWOmxBufferProducer::setMaxDequeuedBufferCount(
-        int maxDequeuedBuffers) {
-    return toStatusT(mBase->setMaxDequeuedBufferCount(
-            static_cast<int32_t>(maxDequeuedBuffers)));
-}
-
-status_t LWOmxBufferProducer::setAsyncMode(bool async) {
-    return toStatusT(mBase->setAsyncMode(async));
-}
-
-status_t LWOmxBufferProducer::dequeueBuffer(
-        int* slot, sp<Fence>* fence,
-        uint32_t w, uint32_t h, ::android::PixelFormat format,
-        uint32_t usage, FrameEventHistoryDelta* outTimestamps) {
-    *fence = new Fence();
-    status_t fnStatus;
-    status_t transStatus = toStatusT(mBase->dequeueBuffer(
-            w, h, static_cast<PixelFormat>(format), usage,
-            outTimestamps != nullptr,
-            [&fnStatus, slot, fence, outTimestamps] (
-                    Status status,
-                    int32_t tSlot,
-                    hidl_handle const& tFence,
-                    IOmxBufferProducer::FrameEventHistoryDelta const& tTs) {
-                fnStatus = toStatusT(status);
-                *slot = tSlot;
-                if (!convertTo(fence->get(), tFence)) {
-                    ALOGE("LWOmxBufferProducer::dequeueBuffer - "
-                            "Invalid output fence");
-                    fnStatus = fnStatus == NO_ERROR ? BAD_VALUE : fnStatus;
-                }
-                if (outTimestamps && !convertTo(outTimestamps, tTs)) {
-                    ALOGE("LWOmxBufferProducer::dequeueBuffer - "
-                            "Invalid output timestamps");
-                    fnStatus = fnStatus == NO_ERROR ? BAD_VALUE : fnStatus;
-                }
-            }));
-    return transStatus == NO_ERROR ? fnStatus : transStatus;
-}
-
-status_t LWOmxBufferProducer::detachBuffer(int slot) {
-    return toStatusT(mBase->detachBuffer(static_cast<int>(slot)));
-}
-
-status_t LWOmxBufferProducer::detachNextBuffer(
-        sp<GraphicBuffer>* outBuffer, sp<Fence>* outFence) {
-    *outBuffer = new GraphicBuffer();
-    *outFence = new Fence();
-    status_t fnStatus;
-    status_t transStatus = toStatusT(mBase->detachNextBuffer(
-            [&fnStatus, outBuffer, outFence] (
-                    Status status,
-                    AnwBuffer const& tBuffer,
-                    hidl_handle const& tFence) {
-                fnStatus = toStatusT(status);
-                if (!convertTo(outFence->get(), tFence)) {
-                    ALOGE("LWOmxBufferProducer::detachNextBuffer - "
-                            "Invalid output fence");
-                    fnStatus = fnStatus == NO_ERROR ? BAD_VALUE : fnStatus;
-                }
-                if (!convertTo(outBuffer->get(), tBuffer)) {
-                    ALOGE("LWOmxBufferProducer::detachNextBuffer - "
-                            "Invalid output buffer");
-                    fnStatus = fnStatus == NO_ERROR ? BAD_VALUE : fnStatus;
-                }
-            }));
-    return transStatus == NO_ERROR ? fnStatus : transStatus;
-}
-
-status_t LWOmxBufferProducer::attachBuffer(
-        int* outSlot, const sp<GraphicBuffer>& buffer) {
-    AnwBuffer tBuffer;
-    wrapAs(&tBuffer, *buffer);
-    status_t fnStatus;
-    status_t transStatus = toStatusT(mBase->attachBuffer(tBuffer,
-            [&fnStatus, outSlot] (Status status, int32_t slot) {
-                fnStatus = toStatusT(status);
-                *outSlot = slot;
-            }));
-    return transStatus == NO_ERROR ? fnStatus : transStatus;
-}
-
-status_t LWOmxBufferProducer::queueBuffer(
-        int slot,
-        const QueueBufferInput& input,
-        QueueBufferOutput* output) {
-    IOmxBufferProducer::QueueBufferInput tInput;
-    native_handle_t* nh;
-    if (!wrapAs(&tInput, &nh, input)) {
-        ALOGE("LWOmxBufferProducer::queueBuffer - Invalid input");
-        return BAD_VALUE;
-    }
-    status_t fnStatus;
-    status_t transStatus = toStatusT(mBase->queueBuffer(slot, tInput,
-            [&fnStatus, output] (
-                    Status status,
-                    IOmxBufferProducer::QueueBufferOutput const& tOutput) {
-                fnStatus = toStatusT(status);
-                if (!convertTo(output, tOutput)) {
-                    ALOGE("LWOmxBufferProducer::queueBuffer - "
-                            "Invalid output");
-                    fnStatus = fnStatus == NO_ERROR ? BAD_VALUE : fnStatus;
-                }
-            }));
-    native_handle_delete(nh);
-    return transStatus == NO_ERROR ? fnStatus : transStatus;
-}
-
-status_t LWOmxBufferProducer::cancelBuffer(int slot, const sp<Fence>& fence) {
-    hidl_handle tFence;
-    native_handle_t* nh = nullptr;
-    if ((fence == nullptr) || !wrapAs(&tFence, &nh, *fence)) {
-        ALOGE("LWOmxBufferProducer::cancelBuffer - Invalid input fence");
-        return BAD_VALUE;
-    }
-
-    status_t status = toStatusT(mBase->cancelBuffer(
-            static_cast<int32_t>(slot), tFence));
-    native_handle_delete(nh);
-    return status;
-}
-
-int LWOmxBufferProducer::query(int what, int* value) {
-    int result;
-    status_t transStatus = toStatusT(mBase->query(
-            static_cast<int32_t>(what),
-            [&result, value] (int32_t tResult, int32_t tValue) {
-                result = static_cast<int>(tResult);
-                *value = static_cast<int>(tValue);
-            }));
-    return transStatus == NO_ERROR ? result : static_cast<int>(transStatus);
-}
-
-status_t LWOmxBufferProducer::connect(
-        const sp<IProducerListener>& listener, int api,
-        bool producerControlledByApp, QueueBufferOutput* output) {
-    sp<IOmxProducerListener> tListener = listener == nullptr ?
-            nullptr : new TWOmxProducerListener(listener);
-    status_t fnStatus;
-    status_t transStatus = toStatusT(mBase->connect(
-            tListener, static_cast<int32_t>(api), producerControlledByApp,
-            [&fnStatus, output] (
-                    Status status,
-                    IOmxBufferProducer::QueueBufferOutput const& tOutput) {
-                fnStatus = toStatusT(status);
-                if (!convertTo(output, tOutput)) {
-                    ALOGE("LWOmxBufferProducer::connect - Invalid output");
-                    fnStatus = fnStatus == NO_ERROR ? BAD_VALUE : fnStatus;
-                }
-            }));
-    return transStatus == NO_ERROR ? fnStatus : transStatus;
-}
-
-status_t LWOmxBufferProducer::disconnect(int api, DisconnectMode mode) {
-    return toStatusT(mBase->disconnect(
-            static_cast<int32_t>(api), toOmxDisconnectMode(mode)));
-}
-
-status_t LWOmxBufferProducer::setSidebandStream(
-        const sp<NativeHandle>& stream) {
-    return toStatusT(mBase->setSidebandStream(stream->handle()));
-}
-
-void LWOmxBufferProducer::allocateBuffers(uint32_t width, uint32_t height,
-        ::android::PixelFormat format, uint32_t usage) {
-    mBase->allocateBuffers(
-            width, height, static_cast<PixelFormat>(format), usage);
-}
-
-status_t LWOmxBufferProducer::allowAllocation(bool allow) {
-    return toStatusT(mBase->allowAllocation(allow));
-}
-
-status_t LWOmxBufferProducer::setGenerationNumber(uint32_t generationNumber) {
-    return toStatusT(mBase->setGenerationNumber(generationNumber));
-}
-
-String8 LWOmxBufferProducer::getConsumerName() const {
-    String8 lName;
-    mBase->getConsumerName([&lName] (hidl_string const& name) {
-                lName = name.c_str();
-            });
-    return lName;
-}
-
-status_t LWOmxBufferProducer::setSharedBufferMode(bool sharedBufferMode) {
-    return toStatusT(mBase->setSharedBufferMode(sharedBufferMode));
-}
-
-status_t LWOmxBufferProducer::setAutoRefresh(bool autoRefresh) {
-    return toStatusT(mBase->setAutoRefresh(autoRefresh));
-}
-
-status_t LWOmxBufferProducer::setDequeueTimeout(nsecs_t timeout) {
-    return toStatusT(mBase->setDequeueTimeout(static_cast<int64_t>(timeout)));
-}
-
-status_t LWOmxBufferProducer::getLastQueuedBuffer(
-        sp<GraphicBuffer>* outBuffer,
-        sp<Fence>* outFence,
-        float outTransformMatrix[16]) {
-    status_t fnStatus;
-    status_t transStatus = toStatusT(mBase->getLastQueuedBuffer(
-            [&fnStatus, outBuffer, outFence, &outTransformMatrix] (
-                    Status status,
-                    AnwBuffer const& buffer,
-                    hidl_handle const& fence,
-                    hidl_array<float, 16> const& transformMatrix) {
-                fnStatus = toStatusT(status);
-                *outBuffer = new GraphicBuffer();
-                if (!convertTo(outBuffer->get(), buffer)) {
-                    ALOGE("LWOmxBufferProducer::getLastQueuedBuffer - "
-                            "Invalid output buffer");
-                    fnStatus = fnStatus == NO_ERROR ? BAD_VALUE : fnStatus;
-                }
-                *outFence = new Fence();
-                if (!convertTo(outFence->get(), fence)) {
-                    ALOGE("LWOmxBufferProducer::getLastQueuedBuffer - "
-                            "Invalid output fence");
-                    fnStatus = fnStatus == NO_ERROR ? BAD_VALUE : fnStatus;
-                }
-                std::copy(transformMatrix.data(),
-                        transformMatrix.data() + 16,
-                        outTransformMatrix);
-            }));
-    return transStatus == NO_ERROR ? fnStatus : transStatus;
-}
-
-void LWOmxBufferProducer::getFrameTimestamps(FrameEventHistoryDelta* outDelta) {
-    mBase->getFrameTimestamps([outDelta] (
-            IOmxBufferProducer::FrameEventHistoryDelta const& tDelta) {
-                convertTo(outDelta, tDelta);
-            });
-}
-
-status_t LWOmxBufferProducer::getUniqueId(uint64_t* outId) const {
-    status_t fnStatus;
-    status_t transStatus = toStatusT(mBase->getUniqueId(
-            [&fnStatus, outId] (Status status, uint64_t id) {
-                fnStatus = toStatusT(status);
-                *outId = id;
-            }));
-    return transStatus == NO_ERROR ? fnStatus : transStatus;
-}
-
-}  // namespace utils
-}  // namespace V1_0
-}  // namespace omx
-}  // namespace media
-}  // namespace hardware
-}  // namespace android
diff --git a/media/libmedia/omx/1.0/WOmxProducerListener.cpp b/media/libmedia/omx/1.0/WOmxProducerListener.cpp
deleted file mode 100644
index 3ee381f..0000000
--- a/media/libmedia/omx/1.0/WOmxProducerListener.cpp
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright 2016, The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <media/omx/1.0/WOmxProducerListener.h>
-
-namespace android {
-namespace hardware {
-namespace media {
-namespace omx {
-namespace V1_0 {
-namespace utils {
-
-// TWOmxProducerListener
-TWOmxProducerListener::TWOmxProducerListener(
-        sp<IProducerListener> const& base):
-    mBase(base) {
-}
-
-Return<void> TWOmxProducerListener::onBufferReleased() {
-    mBase->onBufferReleased();
-    return Void();
-}
-
-Return<bool> TWOmxProducerListener::needsReleaseNotify() {
-    return mBase->needsReleaseNotify();
-}
-
-// LWOmxProducerListener
-LWOmxProducerListener::LWOmxProducerListener(
-        sp<IOmxProducerListener> const& base):
-    mBase(base) {
-}
-
-void LWOmxProducerListener::onBufferReleased() {
-    mBase->onBufferReleased();
-}
-
-bool LWOmxProducerListener::needsReleaseNotify() {
-    return static_cast<bool>(mBase->needsReleaseNotify());
-}
-
-}  // namespace utils
-}  // namespace V1_0
-}  // namespace omx
-}  // namespace media
-}  // namespace hardware
-}  // namespace android
diff --git a/media/libmediaplayerservice/nuplayer/Android.mk b/media/libmediaplayerservice/nuplayer/Android.mk
index 56c558d..08c3cf8 100644
--- a/media/libmediaplayerservice/nuplayer/Android.mk
+++ b/media/libmediaplayerservice/nuplayer/Android.mk
@@ -36,6 +36,7 @@
 LOCAL_SHARED_LIBRARIES :=       \
     libbinder                   \
     libui                       \
+    libgui                      \
     libmedia                    \
     libmediadrm                 \
 
diff --git a/media/libstagefright/omx/hal/1.0/impl/Conversion.h b/media/libstagefright/omx/1.0/Conversion.h
similarity index 90%
rename from media/libstagefright/omx/hal/1.0/impl/Conversion.h
rename to media/libstagefright/omx/1.0/Conversion.h
index a6fed2e..fd91574 100644
--- a/media/libstagefright/omx/hal/1.0/impl/Conversion.h
+++ b/media/libstagefright/omx/1.0/Conversion.h
@@ -37,14 +37,13 @@
 #include <VideoAPI.h>
 
 #include <android/hidl/memory/1.0/IMemory.h>
+#include <android/hardware/graphics/bufferqueue/1.0/IProducerListener.h>
 #include <android/hardware/media/omx/1.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/IOmxBufferProducer.h>
 #include <android/hardware/media/omx/1.0/IOmxBufferSource.h>
-#include <android/hardware/media/omx/1.0/IOmxObserver.h>
-#include <android/hardware/media/omx/1.0/IOmxProducerListener.h>
 #include <android/hardware/media/omx/1.0/IGraphicBufferSource.h>
+#include <android/hardware/media/omx/1.0/IOmxObserver.h>
 
 #include <android/IGraphicBufferSource.h>
 #include <android/IOMXBufferSource.h>
@@ -95,8 +94,10 @@
 using ::android::hardware::media::omx::V1_0::IOmxBufferSource;
 using ::android::IOMXBufferSource;
 
-using ::android::hardware::media::omx::V1_0::IOmxBufferProducer;
-using ::android::IGraphicBufferProducer;
+typedef ::android::hardware::graphics::bufferqueue::V1_0::IGraphicBufferProducer
+        HGraphicBufferProducer;
+typedef ::android::IGraphicBufferProducer
+        BGraphicBufferProducer;
 
 // native_handle_t helper functions.
 
@@ -1191,14 +1192,14 @@
  * \return The required size of the flat buffer.
  */
 inline size_t getFlattenedSize(
-        IOmxBufferProducer::FenceTimeSnapshot const& t) {
+        HGraphicBufferProducer::FenceTimeSnapshot const& t) {
     constexpr size_t min = sizeof(t.state);
     switch (t.state) {
-        case IOmxBufferProducer::FenceTimeSnapshot::State::EMPTY:
+        case HGraphicBufferProducer::FenceTimeSnapshot::State::EMPTY:
             return min;
-        case IOmxBufferProducer::FenceTimeSnapshot::State::FENCE:
+        case HGraphicBufferProducer::FenceTimeSnapshot::State::FENCE:
             return min + getFenceFlattenedSize(t.fence);
-        case IOmxBufferProducer::FenceTimeSnapshot::State::SIGNAL_TIME:
+        case HGraphicBufferProducer::FenceTimeSnapshot::State::SIGNAL_TIME:
             return min + sizeof(
                     ::android::FenceTime::Snapshot::signalTime);
     }
@@ -1213,9 +1214,9 @@
  * \return The number of file descriptors contained in \p snapshot.
  */
 inline size_t getFdCount(
-        IOmxBufferProducer::FenceTimeSnapshot const& t) {
+        HGraphicBufferProducer::FenceTimeSnapshot const& t) {
     return t.state ==
-            IOmxBufferProducer::FenceTimeSnapshot::State::FENCE ?
+            HGraphicBufferProducer::FenceTimeSnapshot::State::FENCE ?
             getFenceFdCount(t.fence) : 0;
 }
 
@@ -1232,22 +1233,22 @@
  * This function will duplicate the file descriptor in `t.fence` if `t.state ==
  * FENCE`.
  */
-inline status_t flatten(IOmxBufferProducer::FenceTimeSnapshot const& t,
+inline status_t flatten(HGraphicBufferProducer::FenceTimeSnapshot const& t,
         void*& buffer, size_t& size, int*& fds, size_t& numFds) {
     if (size < getFlattenedSize(t)) {
         return NO_MEMORY;
     }
 
     switch (t.state) {
-        case IOmxBufferProducer::FenceTimeSnapshot::State::EMPTY:
+        case HGraphicBufferProducer::FenceTimeSnapshot::State::EMPTY:
             FlattenableUtils::write(buffer, size,
                     ::android::FenceTime::Snapshot::State::EMPTY);
             return NO_ERROR;
-        case IOmxBufferProducer::FenceTimeSnapshot::State::FENCE:
+        case HGraphicBufferProducer::FenceTimeSnapshot::State::FENCE:
             FlattenableUtils::write(buffer, size,
                     ::android::FenceTime::Snapshot::State::FENCE);
             return flattenFence(t.fence, buffer, size, fds, numFds);
-        case IOmxBufferProducer::FenceTimeSnapshot::State::SIGNAL_TIME:
+        case HGraphicBufferProducer::FenceTimeSnapshot::State::SIGNAL_TIME:
             FlattenableUtils::write(buffer, size,
                     ::android::FenceTime::Snapshot::State::SIGNAL_TIME);
             FlattenableUtils::write(buffer, size, t.signalTimeNs);
@@ -1272,7 +1273,7 @@
  * case, \p nh needs to be deleted with `native_handle_delete()` afterwards.
  */
 inline status_t unflatten(
-        IOmxBufferProducer::FenceTimeSnapshot* t, native_handle_t** nh,
+        HGraphicBufferProducer::FenceTimeSnapshot* t, native_handle_t** nh,
         void const*& buffer, size_t& size, int const*& fds, size_t& numFds) {
     if (size < sizeof(t->state)) {
         return NO_MEMORY;
@@ -1283,13 +1284,13 @@
     FlattenableUtils::read(buffer, size, state);
     switch (state) {
         case ::android::FenceTime::Snapshot::State::EMPTY:
-            t->state = IOmxBufferProducer::FenceTimeSnapshot::State::EMPTY;
+            t->state = HGraphicBufferProducer::FenceTimeSnapshot::State::EMPTY;
             return NO_ERROR;
         case ::android::FenceTime::Snapshot::State::FENCE:
-            t->state = IOmxBufferProducer::FenceTimeSnapshot::State::FENCE;
+            t->state = HGraphicBufferProducer::FenceTimeSnapshot::State::FENCE;
             return unflattenFence(&t->fence, nh, buffer, size, fds, numFds);
         case ::android::FenceTime::Snapshot::State::SIGNAL_TIME:
-            t->state = IOmxBufferProducer::FenceTimeSnapshot::State::SIGNAL_TIME;
+            t->state = HGraphicBufferProducer::FenceTimeSnapshot::State::SIGNAL_TIME;
             if (size < sizeof(t->signalTimeNs)) {
                 return NO_MEMORY;
             }
@@ -1309,7 +1310,7 @@
  * \return A lower bound on the size of the flat buffer.
  */
 constexpr size_t minFlattenedSize(
-        IOmxBufferProducer::FrameEventsDelta const& /* t */) {
+        HGraphicBufferProducer::FrameEventsDelta const& /* t */) {
     return sizeof(uint64_t) + // mFrameNumber
             sizeof(uint8_t) + // mIndex
             sizeof(uint8_t) + // mAddPostCompositeCalled
@@ -1330,7 +1331,7 @@
  * \return The required size of the flat buffer.
  */
 inline size_t getFlattenedSize(
-        IOmxBufferProducer::FrameEventsDelta const& t) {
+        HGraphicBufferProducer::FrameEventsDelta const& t) {
     return minFlattenedSize(t) +
             getFlattenedSize(t.gpuCompositionDoneFence) +
             getFlattenedSize(t.displayPresentFence) +
@@ -1346,7 +1347,7 @@
  * \return The number of file descriptors contained in \p t.
  */
 inline size_t getFdCount(
-        IOmxBufferProducer::FrameEventsDelta const& t) {
+        HGraphicBufferProducer::FrameEventsDelta const& t) {
     return getFdCount(t.gpuCompositionDoneFence) +
             getFdCount(t.displayPresentFence) +
             getFdCount(t.displayRetireFence) +
@@ -1368,7 +1369,7 @@
  * populated with `nullptr` or newly created handles. Each non-null slot in \p
  * nh will need to be deleted manually with `native_handle_delete()`.
  */
-inline status_t unflatten(IOmxBufferProducer::FrameEventsDelta* t,
+inline status_t unflatten(HGraphicBufferProducer::FrameEventsDelta* t,
         std::vector<native_handle_t*>* nh,
         void const*& buffer, size_t& size, int const*& fds, size_t& numFds) {
     if (size < minFlattenedSize(*t)) {
@@ -1400,7 +1401,7 @@
     FlattenableUtils::read(buffer, size, t->dequeueReadyTime);
 
     // Fences
-    IOmxBufferProducer::FenceTimeSnapshot* tSnapshot[4];
+    HGraphicBufferProducer::FenceTimeSnapshot* tSnapshot[4];
     tSnapshot[0] = &t->gpuCompositionDoneFence;
     tSnapshot[1] = &t->displayPresentFence;
     tSnapshot[2] = &t->displayRetireFence;
@@ -1437,7 +1438,7 @@
  */
 // Ref: frameworks/native/libs/gui/FrameTimestamp.cpp:
 //      FrameEventsDelta::flatten
-inline status_t flatten(IOmxBufferProducer::FrameEventsDelta const& t,
+inline status_t flatten(HGraphicBufferProducer::FrameEventsDelta const& t,
         void*& buffer, size_t& size, int*& fds, size_t numFds) {
     // Check that t.index is within a valid range.
     if (t.index >= static_cast<uint32_t>(FrameEventHistory::MAX_FRAME_HISTORY)
@@ -1464,7 +1465,7 @@
     FlattenableUtils::write(buffer, size, t.dequeueReadyTime);
 
     // Fences
-    IOmxBufferProducer::FenceTimeSnapshot const* tSnapshot[4];
+    HGraphicBufferProducer::FenceTimeSnapshot const* tSnapshot[4];
     tSnapshot[0] = &t.gpuCompositionDoneFence;
     tSnapshot[1] = &t.displayPresentFence;
     tSnapshot[2] = &t.displayRetireFence;
@@ -1483,13 +1484,13 @@
 
 /**
  * \brief Return the size of the non-fd buffer required to flatten
- * `IOmxBufferProducer::FrameEventHistoryDelta`.
+ * `HGraphicBufferProducer::FrameEventHistoryDelta`.
  *
- * \param[in] t The input `IOmxBufferProducer::FrameEventHistoryDelta`.
+ * \param[in] t The input `HGraphicBufferProducer::FrameEventHistoryDelta`.
  * \return The required size of the flat buffer.
  */
 inline size_t getFlattenedSize(
-        IOmxBufferProducer::FrameEventHistoryDelta const& t) {
+        HGraphicBufferProducer::FrameEventHistoryDelta const& t) {
     size_t size = 4 + // mDeltas.size()
             sizeof(t.compositorTiming);
     for (size_t i = 0; i < t.deltas.size(); ++i) {
@@ -1500,13 +1501,13 @@
 
 /**
  * \brief Return the number of file descriptors contained in
- * `IOmxBufferProducer::FrameEventHistoryDelta`.
+ * `HGraphicBufferProducer::FrameEventHistoryDelta`.
  *
- * \param[in] t The input `IOmxBufferProducer::FrameEventHistoryDelta`.
+ * \param[in] t The input `HGraphicBufferProducer::FrameEventHistoryDelta`.
  * \return The number of file descriptors contained in \p t.
  */
 inline size_t getFdCount(
-        IOmxBufferProducer::FrameEventHistoryDelta const& t) {
+        HGraphicBufferProducer::FrameEventHistoryDelta const& t) {
     size_t numFds = 0;
     for (size_t i = 0; i < t.deltas.size(); ++i) {
         numFds += getFdCount(t.deltas[i]);
@@ -1530,7 +1531,7 @@
  * slot in \p nh will need to be deleted manually with `native_handle_delete()`.
  */
 inline status_t unflatten(
-        IOmxBufferProducer::FrameEventHistoryDelta* t,
+        HGraphicBufferProducer::FrameEventHistoryDelta* t,
         std::vector<std::vector<native_handle_t*> >* nh,
         void const*& buffer, size_t& size, int const*& fds, size_t& numFds) {
     if (size < 4) {
@@ -1571,7 +1572,7 @@
  * This function will duplicate file descriptors contained in \p t.
  */
 inline status_t flatten(
-        IOmxBufferProducer::FrameEventHistoryDelta const& t,
+        HGraphicBufferProducer::FrameEventHistoryDelta const& t,
         void*& buffer, size_t& size, int*& fds, size_t& numFds) {
     if (t.deltas.size() > ::android::FrameEventHistory::MAX_FRAME_HISTORY) {
         return BAD_VALUE;
@@ -1594,10 +1595,10 @@
 
 /**
  * \brief Wrap `::android::FrameEventHistoryData` in
- * `IOmxBufferProducer::FrameEventHistoryDelta`.
+ * `HGraphicBufferProducer::FrameEventHistoryDelta`.
  *
  * \param[out] t The wrapper of type
- * `IOmxBufferProducer::FrameEventHistoryDelta`.
+ * `HGraphicBufferProducer::FrameEventHistoryDelta`.
  * \param[out] nh The array of array of native handles that are referred to by
  * members of \p t.
  * \param[in] l The source `::android::FrameEventHistoryDelta`.
@@ -1606,7 +1607,7 @@
  * native handle. All the non-`nullptr` elements must be deleted individually
  * with `native_handle_delete()`.
  */
-inline bool wrapAs(IOmxBufferProducer::FrameEventHistoryDelta* t,
+inline bool wrapAs(HGraphicBufferProducer::FrameEventHistoryDelta* t,
         std::vector<std::vector<native_handle_t*> >* nh,
         ::android::FrameEventHistoryDelta const& l) {
 
@@ -1644,17 +1645,17 @@
 }
 
 /**
- * \brief Convert `IOmxBufferProducer::FrameEventHistoryDelta` to
+ * \brief Convert `HGraphicBufferProducer::FrameEventHistoryDelta` to
  * `::android::FrameEventHistoryDelta`.
  *
  * \param[out] l The destination `::android::FrameEventHistoryDelta`.
- * \param[in] t The source `IOmxBufferProducer::FrameEventHistoryDelta`.
+ * \param[in] t The source `HGraphicBufferProducer::FrameEventHistoryDelta`.
  *
  * This function will duplicate all file descriptors contained in \p t.
  */
 inline bool convertTo(
         ::android::FrameEventHistoryDelta* l,
-        IOmxBufferProducer::FrameEventHistoryDelta const& t) {
+        HGraphicBufferProducer::FrameEventHistoryDelta const& t) {
 
     size_t const baseSize = getFlattenedSize(t);
     std::unique_ptr<uint8_t[]> baseBuffer(
@@ -1829,18 +1830,18 @@
     return true;
 }
 
-// Ref: frameworks/native/libs/gui/IGraphicBufferProducer.cpp:
-//      IGraphicBufferProducer::QueueBufferInput
+// Ref: frameworks/native/libs/gui/BGraphicBufferProducer.cpp:
+//      BGraphicBufferProducer::QueueBufferInput
 
 /**
  * \brief Return a lower bound on the size of the buffer required to flatten
- * `IOmxBufferProducer::QueueBufferInput`.
+ * `HGraphicBufferProducer::QueueBufferInput`.
  *
- * \param[in] t The input `IOmxBufferProducer::QueueBufferInput`.
+ * \param[in] t The input `HGraphicBufferProducer::QueueBufferInput`.
  * \return A lower bound on the size of the flat buffer.
  */
 constexpr size_t minFlattenedSize(
-        IOmxBufferProducer::QueueBufferInput const& /* t */) {
+        HGraphicBufferProducer::QueueBufferInput const& /* t */) {
     return sizeof(int64_t) + // timestamp
             sizeof(int) + // isAutoTimestamp
             sizeof(android_dataspace) + // dataSpace
@@ -1853,12 +1854,12 @@
 
 /**
  * \brief Return the size of the buffer required to flatten
- * `IOmxBufferProducer::QueueBufferInput`.
+ * `HGraphicBufferProducer::QueueBufferInput`.
  *
- * \param[in] t The input `IOmxBufferProducer::QueueBufferInput`.
+ * \param[in] t The input `HGraphicBufferProducer::QueueBufferInput`.
  * \return The required size of the flat buffer.
  */
-inline size_t getFlattenedSize(IOmxBufferProducer::QueueBufferInput const& t) {
+inline size_t getFlattenedSize(HGraphicBufferProducer::QueueBufferInput const& t) {
     return minFlattenedSize(t) +
             getFenceFlattenedSize(t.fence) +
             getFlattenedSize(t.surfaceDamage);
@@ -1866,20 +1867,20 @@
 
 /**
  * \brief Return the number of file descriptors contained in
- * `IOmxBufferProducer::QueueBufferInput`.
+ * `HGraphicBufferProducer::QueueBufferInput`.
  *
- * \param[in] t The input `IOmxBufferProducer::QueueBufferInput`.
+ * \param[in] t The input `HGraphicBufferProducer::QueueBufferInput`.
  * \return The number of file descriptors contained in \p t.
  */
 inline size_t getFdCount(
-        IOmxBufferProducer::QueueBufferInput const& t) {
+        HGraphicBufferProducer::QueueBufferInput const& t) {
     return getFenceFdCount(t.fence);
 }
 
 /**
- * \brief Flatten `IOmxBufferProducer::QueueBufferInput`.
+ * \brief Flatten `HGraphicBufferProducer::QueueBufferInput`.
  *
- * \param[in] t The source `IOmxBufferProducer::QueueBufferInput`.
+ * \param[in] t The source `HGraphicBufferProducer::QueueBufferInput`.
  * \param[out] nh The native handle cloned from `t.fence`.
  * \param[in,out] buffer The pointer to the flat non-fd buffer.
  * \param[in,out] size The size of the flat non-fd buffer.
@@ -1888,7 +1889,7 @@
  * \return `NO_ERROR` on success; other value on failure.
  *
  * This function will duplicate the file descriptor in `t.fence`. */
-inline status_t flatten(IOmxBufferProducer::QueueBufferInput const& t,
+inline status_t flatten(HGraphicBufferProducer::QueueBufferInput const& t,
         native_handle_t** nh,
         void*& buffer, size_t& size, int*& fds, size_t& numFds) {
     if (size < getFlattenedSize(t)) {
@@ -1919,9 +1920,9 @@
 }
 
 /**
- * \brief Unflatten `IOmxBufferProducer::QueueBufferInput`.
+ * \brief Unflatten `HGraphicBufferProducer::QueueBufferInput`.
  *
- * \param[out] t The destination `IOmxBufferProducer::QueueBufferInput`.
+ * \param[out] t The destination `HGraphicBufferProducer::QueueBufferInput`.
  * \param[out] nh The underlying native handle for `t->fence`.
  * \param[in,out] buffer The pointer to the flat non-fd buffer.
  * \param[in,out] size The size of the flat non-fd buffer.
@@ -1935,7 +1936,7 @@
  * afterwards.
  */
 inline status_t unflatten(
-        IOmxBufferProducer::QueueBufferInput* t, native_handle_t** nh,
+        HGraphicBufferProducer::QueueBufferInput* t, native_handle_t** nh,
         void const*& buffer, size_t& size, int const*& fds, size_t& numFds) {
     if (size < minFlattenedSize(*t)) {
         return NO_MEMORY;
@@ -1971,13 +1972,13 @@
 }
 
 /**
- * \brief Wrap `IGraphicBufferProducer::QueueBufferInput` in
- * `IOmxBufferProducer::QueueBufferInput`.
+ * \brief Wrap `BGraphicBufferProducer::QueueBufferInput` in
+ * `HGraphicBufferProducer::QueueBufferInput`.
  *
  * \param[out] t The wrapper of type
- * `IOmxBufferProducer::QueueBufferInput`.
+ * `HGraphicBufferProducer::QueueBufferInput`.
  * \param[out] nh The underlying native handle for `t->fence`.
- * \param[in] l The source `IGraphicBufferProducer::QueueBufferInput`.
+ * \param[in] l The source `BGraphicBufferProducer::QueueBufferInput`.
  *
  * If the return value is `true` and `t->fence` contains a valid file
  * descriptor, \p nh will be a newly created native handle holding that file
@@ -1985,9 +1986,9 @@
  * afterwards.
  */
 inline bool wrapAs(
-        IOmxBufferProducer::QueueBufferInput* t,
+        HGraphicBufferProducer::QueueBufferInput* t,
         native_handle_t** nh,
-        IGraphicBufferProducer::QueueBufferInput const& l) {
+        BGraphicBufferProducer::QueueBufferInput const& l) {
 
     size_t const baseSize = l.getFlattenedSize();
     std::unique_ptr<uint8_t[]> baseBuffer(
@@ -2023,17 +2024,17 @@
 }
 
 /**
- * \brief Convert `IOmxBufferProducer::QueueBufferInput` to
- * `IGraphicBufferProducer::QueueBufferInput`.
+ * \brief Convert `HGraphicBufferProducer::QueueBufferInput` to
+ * `BGraphicBufferProducer::QueueBufferInput`.
  *
- * \param[out] l The destination `IGraphicBufferProducer::QueueBufferInput`.
- * \param[in] t The source `IOmxBufferProducer::QueueBufferInput`.
+ * \param[out] l The destination `BGraphicBufferProducer::QueueBufferInput`.
+ * \param[in] t The source `HGraphicBufferProducer::QueueBufferInput`.
  *
  * If `t.fence` has a valid file descriptor, it will be duplicated.
  */
 inline bool convertTo(
-        IGraphicBufferProducer::QueueBufferInput* l,
-        IOmxBufferProducer::QueueBufferInput const& t) {
+        BGraphicBufferProducer::QueueBufferInput* l,
+        HGraphicBufferProducer::QueueBufferInput const& t) {
 
     size_t const baseSize = getFlattenedSize(t);
     std::unique_ptr<uint8_t[]> baseBuffer(
@@ -2072,28 +2073,28 @@
     return true;
 }
 
-// Ref: frameworks/native/libs/gui/IGraphicBufferProducer.cpp:
-//      IGraphicBufferProducer::QueueBufferOutput
+// Ref: frameworks/native/libs/gui/BGraphicBufferProducer.cpp:
+//      BGraphicBufferProducer::QueueBufferOutput
 
 /**
- * \brief Wrap `IGraphicBufferProducer::QueueBufferOutput` in
- * `IOmxBufferProducer::QueueBufferOutput`.
+ * \brief Wrap `BGraphicBufferProducer::QueueBufferOutput` in
+ * `HGraphicBufferProducer::QueueBufferOutput`.
  *
  * \param[out] t The wrapper of type
- * `IOmxBufferProducer::QueueBufferOutput`.
+ * `HGraphicBufferProducer::QueueBufferOutput`.
  * \param[out] nh The array of array of native handles that are referred to by
  * members of \p t.
- * \param[in] l The source `IGraphicBufferProducer::QueueBufferOutput`.
+ * \param[in] l The source `BGraphicBufferProducer::QueueBufferOutput`.
  *
  * On success, each member of \p nh will be either `nullptr` or a newly created
  * native handle. All the non-`nullptr` elements must be deleted individually
  * with `native_handle_delete()`.
  */
-// wrap: IGraphicBufferProducer::QueueBufferOutput ->
-// IOmxBufferProducer::QueueBufferOutput
-inline bool wrapAs(IOmxBufferProducer::QueueBufferOutput* t,
+// wrap: BGraphicBufferProducer::QueueBufferOutput ->
+// HGraphicBufferProducer::QueueBufferOutput
+inline bool wrapAs(HGraphicBufferProducer::QueueBufferOutput* t,
         std::vector<std::vector<native_handle_t*> >* nh,
-        IGraphicBufferProducer::QueueBufferOutput const& l) {
+        BGraphicBufferProducer::QueueBufferOutput const& l) {
     if (!wrapAs(&(t->frameTimestamps), nh, l.frameTimestamps)) {
         return false;
     }
@@ -2107,19 +2108,19 @@
 }
 
 /**
- * \brief Convert `IOmxBufferProducer::QueueBufferOutput` to
- * `IGraphicBufferProducer::QueueBufferOutput`.
+ * \brief Convert `HGraphicBufferProducer::QueueBufferOutput` to
+ * `BGraphicBufferProducer::QueueBufferOutput`.
  *
- * \param[out] l The destination `IGraphicBufferProducer::QueueBufferOutput`.
- * \param[in] t The source `IOmxBufferProducer::QueueBufferOutput`.
+ * \param[out] l The destination `BGraphicBufferProducer::QueueBufferOutput`.
+ * \param[in] t The source `HGraphicBufferProducer::QueueBufferOutput`.
  *
  * This function will duplicate all file descriptors contained in \p t.
  */
-// convert: IOmxBufferProducer::QueueBufferOutput ->
-// IGraphicBufferProducer::QueueBufferOutput
+// convert: HGraphicBufferProducer::QueueBufferOutput ->
+// BGraphicBufferProducer::QueueBufferOutput
 inline bool convertTo(
-        IGraphicBufferProducer::QueueBufferOutput* l,
-        IOmxBufferProducer::QueueBufferOutput const& t) {
+        BGraphicBufferProducer::QueueBufferOutput* l,
+        HGraphicBufferProducer::QueueBufferOutput const& t) {
     if (!convertTo(&(l->frameTimestamps), t.frameTimestamps)) {
         return false;
     }
@@ -2133,39 +2134,39 @@
 }
 
 /**
- * \brief Convert `IGraphicBufferProducer::DisconnectMode` to
- * `IOmxBufferProducer::DisconnectMode`.
+ * \brief Convert `BGraphicBufferProducer::DisconnectMode` to
+ * `HGraphicBufferProducer::DisconnectMode`.
  *
- * \param[in] l The source `IGraphicBufferProducer::DisconnectMode`.
- * \return The corresponding `IOmxBufferProducer::DisconnectMode`.
+ * \param[in] l The source `BGraphicBufferProducer::DisconnectMode`.
+ * \return The corresponding `HGraphicBufferProducer::DisconnectMode`.
  */
-inline IOmxBufferProducer::DisconnectMode toOmxDisconnectMode(
-        IGraphicBufferProducer::DisconnectMode l) {
+inline HGraphicBufferProducer::DisconnectMode toOmxDisconnectMode(
+        BGraphicBufferProducer::DisconnectMode l) {
     switch (l) {
-        case IGraphicBufferProducer::DisconnectMode::Api:
-            return IOmxBufferProducer::DisconnectMode::API;
-        case IGraphicBufferProducer::DisconnectMode::AllLocal:
-            return IOmxBufferProducer::DisconnectMode::ALL_LOCAL;
+        case BGraphicBufferProducer::DisconnectMode::Api:
+            return HGraphicBufferProducer::DisconnectMode::API;
+        case BGraphicBufferProducer::DisconnectMode::AllLocal:
+            return HGraphicBufferProducer::DisconnectMode::ALL_LOCAL;
     }
-    return IOmxBufferProducer::DisconnectMode::API;
+    return HGraphicBufferProducer::DisconnectMode::API;
 }
 
 /**
- * \brief Convert `IOmxBufferProducer::DisconnectMode` to
- * `IGraphicBufferProducer::DisconnectMode`.
+ * \brief Convert `HGraphicBufferProducer::DisconnectMode` to
+ * `BGraphicBufferProducer::DisconnectMode`.
  *
- * \param[in] l The source `IOmxBufferProducer::DisconnectMode`.
- * \return The corresponding `IGraphicBufferProducer::DisconnectMode`.
+ * \param[in] l The source `HGraphicBufferProducer::DisconnectMode`.
+ * \return The corresponding `BGraphicBufferProducer::DisconnectMode`.
  */
-inline IGraphicBufferProducer::DisconnectMode toGuiDisconnectMode(
-        IOmxBufferProducer::DisconnectMode t) {
+inline BGraphicBufferProducer::DisconnectMode toGuiDisconnectMode(
+        HGraphicBufferProducer::DisconnectMode t) {
     switch (t) {
-        case IOmxBufferProducer::DisconnectMode::API:
-            return IGraphicBufferProducer::DisconnectMode::Api;
-        case IOmxBufferProducer::DisconnectMode::ALL_LOCAL:
-            return IGraphicBufferProducer::DisconnectMode::AllLocal;
+        case HGraphicBufferProducer::DisconnectMode::API:
+            return BGraphicBufferProducer::DisconnectMode::Api;
+        case HGraphicBufferProducer::DisconnectMode::ALL_LOCAL:
+            return BGraphicBufferProducer::DisconnectMode::AllLocal;
     }
-    return IGraphicBufferProducer::DisconnectMode::Api;
+    return BGraphicBufferProducer::DisconnectMode::Api;
 }
 
 }  // namespace implementation
diff --git a/media/libstagefright/omx/hal/1.0/impl/Omx.cpp b/media/libstagefright/omx/1.0/Omx.cpp
similarity index 96%
rename from media/libstagefright/omx/hal/1.0/impl/Omx.cpp
rename to media/libstagefright/omx/1.0/Omx.cpp
index 0ef7c8c..134c661 100644
--- a/media/libstagefright/omx/hal/1.0/impl/Omx.cpp
+++ b/media/libstagefright/omx/1.0/Omx.cpp
@@ -22,13 +22,13 @@
 #include <OMX_Core.h>
 #include <OMX_AsString.h>
 
-#include "../../../OMXUtils.h"
-#include "../../../OMXMaster.h"
-#include "../../../GraphicBufferSource.h"
+#include "../OMXUtils.h"
+#include "../OMXMaster.h"
+#include "../GraphicBufferSource.h"
 
 #include "WOmxNode.h"
 #include "WOmxObserver.h"
-#include "WOmxBufferProducer.h"
+#include "WGraphicBufferProducer.h"
 #include "WGraphicBufferSource.h"
 #include "Conversion.h"
 
@@ -52,7 +52,6 @@
 
 Return<void> Omx::listNodes(listNodes_cb _hidl_cb) {
     std::list<::android::IOMX::ComponentInfo> list;
-    OMX_U32 index = 0;
     char componentName[256];
     for (OMX_U32 index = 0;
             mMaster->enumerateComponents(
@@ -136,7 +135,7 @@
     bufferProducer = graphicBufferSource->getIGraphicBufferProducer();
 
     _hidl_cb(toStatus(OK),
-            new TWOmxBufferProducer(bufferProducer),
+            new TWGraphicBufferProducer(bufferProducer),
             new TWGraphicBufferSource(graphicBufferSource));
     return Void();
 }
diff --git a/media/libstagefright/omx/hal/1.0/impl/Omx.h b/media/libstagefright/omx/1.0/Omx.h
similarity index 97%
rename from media/libstagefright/omx/hal/1.0/impl/Omx.h
rename to media/libstagefright/omx/1.0/Omx.h
index 3e9ea73..001e8cb 100644
--- a/media/libstagefright/omx/hal/1.0/impl/Omx.h
+++ b/media/libstagefright/omx/1.0/Omx.h
@@ -20,7 +20,7 @@
 #include <hidl/MQDescriptor.h>
 #include <hidl/Status.h>
 
-#include "../../../../include/OMXNodeInstance.h"
+#include "../../include/OMXNodeInstance.h"
 
 #include <android/hardware/media/omx/1.0/IOmx.h>
 
diff --git a/media/libstagefright/omx/1.0/WGraphicBufferProducer.cpp b/media/libstagefright/omx/1.0/WGraphicBufferProducer.cpp
new file mode 100644
index 0000000..36bd624
--- /dev/null
+++ b/media/libstagefright/omx/1.0/WGraphicBufferProducer.cpp
@@ -0,0 +1,353 @@
+/*
+ * Copyright 2016, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define LOG_TAG "WGraphicBufferProducer-impl"
+
+#include <android-base/logging.h>
+
+#include "WGraphicBufferProducer.h"
+#include "WProducerListener.h"
+#include "Conversion.h"
+
+namespace android {
+namespace hardware {
+namespace media {
+namespace omx {
+namespace V1_0 {
+namespace implementation {
+
+// TWGraphicBufferProducer
+TWGraphicBufferProducer::TWGraphicBufferProducer(
+        sp<BGraphicBufferProducer> const& base):
+    mBase(base) {
+}
+
+Return<void> TWGraphicBufferProducer::requestBuffer(
+        int32_t slot, requestBuffer_cb _hidl_cb) {
+    sp<GraphicBuffer> buf;
+    status_t status = mBase->requestBuffer(slot, &buf);
+    AnwBuffer anwBuffer;
+    wrapAs(&anwBuffer, *buf);
+    _hidl_cb(static_cast<int32_t>(status), anwBuffer);
+    return Void();
+}
+
+Return<int32_t> TWGraphicBufferProducer::setMaxDequeuedBufferCount(
+        int32_t maxDequeuedBuffers) {
+    return static_cast<int32_t>(mBase->setMaxDequeuedBufferCount(
+            static_cast<int>(maxDequeuedBuffers)));
+}
+
+Return<int32_t> TWGraphicBufferProducer::setAsyncMode(bool async) {
+    return static_cast<int32_t>(mBase->setAsyncMode(async));
+}
+
+Return<void> TWGraphicBufferProducer::dequeueBuffer(
+        uint32_t width, uint32_t height,
+        PixelFormat format, uint32_t usage,
+        bool getFrameTimestamps, dequeueBuffer_cb _hidl_cb) {
+    int slot;
+    sp<Fence> fence;
+    ::android::FrameEventHistoryDelta outTimestamps;
+    status_t status = mBase->dequeueBuffer(
+            &slot, &fence,
+            width, height,
+            static_cast<::android::PixelFormat>(format), usage,
+            getFrameTimestamps ? &outTimestamps : nullptr);
+    hidl_handle tFence;
+    FrameEventHistoryDelta tOutTimestamps;
+
+    native_handle_t* nh = nullptr;
+    if ((fence == nullptr) || !wrapAs(&tFence, &nh, *fence)) {
+        LOG(ERROR) << "TWGraphicBufferProducer::dequeueBuffer - "
+                "Invalid output fence";
+        _hidl_cb(static_cast<int32_t>(status),
+                 static_cast<int32_t>(slot),
+                 tFence,
+                 tOutTimestamps);
+        return Void();
+    }
+    std::vector<std::vector<native_handle_t*> > nhAA;
+    if (getFrameTimestamps && !wrapAs(&tOutTimestamps, &nhAA, outTimestamps)) {
+        LOG(ERROR) << "TWGraphicBufferProducer::dequeueBuffer - "
+                "Invalid output timestamps";
+        _hidl_cb(static_cast<int32_t>(status),
+                 static_cast<int32_t>(slot),
+                 tFence,
+                 tOutTimestamps);
+        native_handle_delete(nh);
+        return Void();
+    }
+
+    _hidl_cb(static_cast<int32_t>(status),
+            static_cast<int32_t>(slot),
+            tFence,
+            tOutTimestamps);
+    native_handle_delete(nh);
+    if (getFrameTimestamps) {
+        for (auto& nhA : nhAA) {
+            for (auto& handle : nhA) {
+                native_handle_delete(handle);
+            }
+        }
+    }
+    return Void();
+}
+
+Return<int32_t> TWGraphicBufferProducer::detachBuffer(int32_t slot) {
+    return static_cast<int32_t>(mBase->detachBuffer(slot));
+}
+
+Return<void> TWGraphicBufferProducer::detachNextBuffer(
+        detachNextBuffer_cb _hidl_cb) {
+    sp<GraphicBuffer> outBuffer;
+    sp<Fence> outFence;
+    status_t status = mBase->detachNextBuffer(&outBuffer, &outFence);
+    AnwBuffer tBuffer;
+    hidl_handle tFence;
+
+    if (outBuffer == nullptr) {
+        LOG(ERROR) << "TWGraphicBufferProducer::detachNextBuffer - "
+                "Invalid output buffer";
+        _hidl_cb(static_cast<int32_t>(status), tBuffer, tFence);
+        return Void();
+    }
+    wrapAs(&tBuffer, *outBuffer);
+    native_handle_t* nh = nullptr;
+    if ((outFence != nullptr) && !wrapAs(&tFence, &nh, *outFence)) {
+        LOG(ERROR) << "TWGraphicBufferProducer::detachNextBuffer - "
+                "Invalid output fence";
+        _hidl_cb(static_cast<int32_t>(status), tBuffer, tFence);
+        return Void();
+    }
+
+    _hidl_cb(static_cast<int32_t>(status), tBuffer, tFence);
+    native_handle_delete(nh);
+    return Void();
+}
+
+Return<void> TWGraphicBufferProducer::attachBuffer(
+        const AnwBuffer& buffer,
+        attachBuffer_cb _hidl_cb) {
+    int outSlot;
+    sp<GraphicBuffer> lBuffer = new GraphicBuffer();
+    if (!convertTo(lBuffer.get(), buffer)) {
+        LOG(ERROR) << "TWGraphicBufferProducer::attachBuffer - "
+                "Invalid input native window buffer";
+        _hidl_cb(static_cast<int32_t>(BAD_VALUE), -1);
+        return Void();
+    }
+    status_t status = mBase->attachBuffer(&outSlot, lBuffer);
+
+    _hidl_cb(static_cast<int32_t>(status), static_cast<int32_t>(outSlot));
+    return Void();
+}
+
+Return<void> TWGraphicBufferProducer::queueBuffer(
+        int32_t slot, const QueueBufferInput& input,
+        queueBuffer_cb _hidl_cb) {
+    QueueBufferOutput tOutput;
+    BGraphicBufferProducer::QueueBufferInput lInput(
+            0, false, HAL_DATASPACE_UNKNOWN,
+            ::android::Rect(0, 0, 1, 1),
+            NATIVE_WINDOW_SCALING_MODE_FREEZE,
+            0, ::android::Fence::NO_FENCE);
+    if (!convertTo(&lInput, input)) {
+        LOG(ERROR) << "TWGraphicBufferProducer::queueBuffer - "
+                "Invalid input";
+        _hidl_cb(static_cast<int32_t>(BAD_VALUE), tOutput);
+        return Void();
+    }
+    BGraphicBufferProducer::QueueBufferOutput lOutput;
+    status_t status = mBase->queueBuffer(
+            static_cast<int>(slot), lInput, &lOutput);
+
+    std::vector<std::vector<native_handle_t*> > nhAA;
+    if (!wrapAs(&tOutput, &nhAA, lOutput)) {
+        LOG(ERROR) << "TWGraphicBufferProducer::queueBuffer - "
+                "Invalid output";
+        _hidl_cb(static_cast<int32_t>(BAD_VALUE), tOutput);
+        return Void();
+    }
+
+    _hidl_cb(static_cast<int32_t>(status), tOutput);
+    for (auto& nhA : nhAA) {
+        for (auto& nh : nhA) {
+            native_handle_delete(nh);
+        }
+    }
+    return Void();
+}
+
+Return<int32_t> TWGraphicBufferProducer::cancelBuffer(
+        int32_t slot, const hidl_handle& fence) {
+    sp<Fence> lFence = new Fence();
+    if (!convertTo(lFence.get(), fence)) {
+        LOG(ERROR) << "TWGraphicBufferProducer::cancelBuffer - "
+                "Invalid input fence";
+        return static_cast<int32_t>(BAD_VALUE);
+    }
+    return static_cast<int32_t>(mBase->cancelBuffer(static_cast<int>(slot), lFence));
+}
+
+Return<void> TWGraphicBufferProducer::query(int32_t what, query_cb _hidl_cb) {
+    int lValue;
+    int lReturn = mBase->query(static_cast<int>(what), &lValue);
+    _hidl_cb(static_cast<int32_t>(lReturn), static_cast<int32_t>(lValue));
+    return Void();
+}
+
+Return<void> TWGraphicBufferProducer::connect(
+        const sp<HProducerListener>& listener,
+        int32_t api, bool producerControlledByApp, connect_cb _hidl_cb) {
+    sp<BProducerListener> lListener = listener == nullptr ?
+            nullptr : new LWProducerListener(listener);
+    BGraphicBufferProducer::QueueBufferOutput lOutput;
+    status_t status = mBase->connect(lListener,
+            static_cast<int>(api),
+            producerControlledByApp,
+            &lOutput);
+
+    QueueBufferOutput tOutput;
+    std::vector<std::vector<native_handle_t*> > nhAA;
+    if (!wrapAs(&tOutput, &nhAA, lOutput)) {
+        LOG(ERROR) << "TWGraphicBufferProducer::connect - "
+                "Invalid output";
+        _hidl_cb(static_cast<int32_t>(status), tOutput);
+        return Void();
+    }
+
+    _hidl_cb(static_cast<int32_t>(status), tOutput);
+    for (auto& nhA : nhAA) {
+        for (auto& nh : nhA) {
+            native_handle_delete(nh);
+        }
+    }
+    return Void();
+}
+
+Return<int32_t> TWGraphicBufferProducer::disconnect(
+        int32_t api, DisconnectMode mode) {
+    return static_cast<int32_t>(mBase->disconnect(
+            static_cast<int>(api),
+            toGuiDisconnectMode(mode)));
+}
+
+Return<int32_t> TWGraphicBufferProducer::setSidebandStream(const hidl_handle& stream) {
+    return static_cast<int32_t>(mBase->setSidebandStream(NativeHandle::create(
+            native_handle_clone(stream), true)));
+}
+
+Return<void> TWGraphicBufferProducer::allocateBuffers(
+        uint32_t width, uint32_t height, PixelFormat format, uint32_t usage) {
+    mBase->allocateBuffers(
+            width, height,
+            static_cast<::android::PixelFormat>(format),
+            usage);
+    return Void();
+}
+
+Return<int32_t> TWGraphicBufferProducer::allowAllocation(bool allow) {
+    return static_cast<int32_t>(mBase->allowAllocation(allow));
+}
+
+Return<int32_t> TWGraphicBufferProducer::setGenerationNumber(uint32_t generationNumber) {
+    return static_cast<int32_t>(mBase->setGenerationNumber(generationNumber));
+}
+
+Return<void> TWGraphicBufferProducer::getConsumerName(getConsumerName_cb _hidl_cb) {
+    _hidl_cb(mBase->getConsumerName().string());
+    return Void();
+}
+
+Return<int32_t> TWGraphicBufferProducer::setSharedBufferMode(bool sharedBufferMode) {
+    return static_cast<int32_t>(mBase->setSharedBufferMode(sharedBufferMode));
+}
+
+Return<int32_t> TWGraphicBufferProducer::setAutoRefresh(bool autoRefresh) {
+    return static_cast<int32_t>(mBase->setAutoRefresh(autoRefresh));
+}
+
+Return<int32_t> TWGraphicBufferProducer::setDequeueTimeout(int64_t timeoutNs) {
+    return static_cast<int32_t>(mBase->setDequeueTimeout(timeoutNs));
+}
+
+Return<void> TWGraphicBufferProducer::getLastQueuedBuffer(
+        getLastQueuedBuffer_cb _hidl_cb) {
+    sp<GraphicBuffer> lOutBuffer = new GraphicBuffer();
+    sp<Fence> lOutFence = new Fence();
+    float lOutTransformMatrix[16];
+    status_t status = mBase->getLastQueuedBuffer(
+            &lOutBuffer, &lOutFence, lOutTransformMatrix);
+
+    AnwBuffer tOutBuffer;
+    if (lOutBuffer != nullptr) {
+        wrapAs(&tOutBuffer, *lOutBuffer);
+    }
+    hidl_handle tOutFence;
+    native_handle_t* nh = nullptr;
+    if ((lOutFence == nullptr) || !wrapAs(&tOutFence, &nh, *lOutFence)) {
+        LOG(ERROR) << "TWGraphicBufferProducer::getLastQueuedBuffer - "
+                "Invalid output fence";
+        _hidl_cb(static_cast<int32_t>(status),
+                tOutBuffer,
+                tOutFence,
+                hidl_array<float, 16>());
+        return Void();
+    }
+    hidl_array<float, 16> tOutTransformMatrix(lOutTransformMatrix);
+
+    _hidl_cb(static_cast<int32_t>(status), tOutBuffer, tOutFence, tOutTransformMatrix);
+    native_handle_delete(nh);
+    return Void();
+}
+
+Return<void> TWGraphicBufferProducer::getFrameTimestamps(
+        getFrameTimestamps_cb _hidl_cb) {
+    ::android::FrameEventHistoryDelta lDelta;
+    mBase->getFrameTimestamps(&lDelta);
+
+    FrameEventHistoryDelta tDelta;
+    std::vector<std::vector<native_handle_t*> > nhAA;
+    if (!wrapAs(&tDelta, &nhAA, lDelta)) {
+        LOG(ERROR) << "TWGraphicBufferProducer::getFrameTimestamps - "
+                "Invalid output frame timestamps";
+        _hidl_cb(tDelta);
+        return Void();
+    }
+
+    _hidl_cb(tDelta);
+    for (auto& nhA : nhAA) {
+        for (auto& nh : nhA) {
+            native_handle_delete(nh);
+        }
+    }
+    return Void();
+}
+
+Return<void> TWGraphicBufferProducer::getUniqueId(getUniqueId_cb _hidl_cb) {
+    uint64_t outId;
+    status_t status = mBase->getUniqueId(&outId);
+    _hidl_cb(static_cast<int32_t>(status), outId);
+    return Void();
+}
+
+}  // namespace implementation
+}  // namespace V1_0
+}  // namespace omx
+}  // namespace media
+}  // namespace hardware
+}  // namespace android
diff --git a/media/libstagefright/omx/1.0/WGraphicBufferProducer.h b/media/libstagefright/omx/1.0/WGraphicBufferProducer.h
new file mode 100644
index 0000000..4a3fe0c
--- /dev/null
+++ b/media/libstagefright/omx/1.0/WGraphicBufferProducer.h
@@ -0,0 +1,105 @@
+/*
+ * Copyright 2016, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_HARDWARE_MEDIA_OMX_V1_0_WGRAPHICBUFFERPRODUCER_H
+#define ANDROID_HARDWARE_MEDIA_OMX_V1_0_WGRAPHICBUFFERPRODUCER_H
+
+#include <hidl/MQDescriptor.h>
+#include <hidl/Status.h>
+
+#include <binder/Binder.h>
+#include <gui/IGraphicBufferProducer.h>
+#include <gui/IProducerListener.h>
+
+#include <android/hardware/graphics/bufferqueue/1.0/IGraphicBufferProducer.h>
+
+namespace android {
+namespace hardware {
+namespace media {
+namespace omx {
+namespace V1_0 {
+namespace implementation {
+
+using ::android::hardware::graphics::common::V1_0::PixelFormat;
+using ::android::hardware::media::V1_0::AnwBuffer;
+using ::android::hidl::base::V1_0::IBase;
+using ::android::hardware::hidl_array;
+using ::android::hardware::hidl_memory;
+using ::android::hardware::hidl_string;
+using ::android::hardware::hidl_vec;
+using ::android::hardware::Return;
+using ::android::hardware::Void;
+using ::android::sp;
+
+typedef ::android::hardware::graphics::bufferqueue::V1_0::
+        IGraphicBufferProducer HGraphicBufferProducer;
+typedef ::android::hardware::graphics::bufferqueue::V1_0::
+        IProducerListener HProducerListener;
+
+typedef ::android::IGraphicBufferProducer BGraphicBufferProducer;
+typedef ::android::IProducerListener BProducerListener;
+using ::android::BnGraphicBufferProducer;
+
+struct TWGraphicBufferProducer : public HGraphicBufferProducer {
+    sp<BGraphicBufferProducer> mBase;
+    TWGraphicBufferProducer(sp<BGraphicBufferProducer> const& base);
+    Return<void> requestBuffer(int32_t slot, requestBuffer_cb _hidl_cb)
+            override;
+    Return<int32_t> setMaxDequeuedBufferCount(int32_t maxDequeuedBuffers)
+            override;
+    Return<int32_t> setAsyncMode(bool async) override;
+    Return<void> dequeueBuffer(
+            uint32_t width, uint32_t height, PixelFormat format, uint32_t usage,
+            bool getFrameTimestamps, dequeueBuffer_cb _hidl_cb) override;
+    Return<int32_t> detachBuffer(int32_t slot) override;
+    Return<void> detachNextBuffer(detachNextBuffer_cb _hidl_cb) override;
+    Return<void> attachBuffer(const AnwBuffer& buffer, attachBuffer_cb _hidl_cb)
+            override;
+    Return<void> queueBuffer(
+            int32_t slot, const HGraphicBufferProducer::QueueBufferInput& input,
+            queueBuffer_cb _hidl_cb) override;
+    Return<int32_t> cancelBuffer(int32_t slot, const hidl_handle& fence)
+            override;
+    Return<void> query(int32_t what, query_cb _hidl_cb) override;
+    Return<void> connect(const sp<HProducerListener>& listener,
+            int32_t api, bool producerControlledByApp,
+            connect_cb _hidl_cb) override;
+    Return<int32_t> disconnect(
+            int32_t api,
+            HGraphicBufferProducer::DisconnectMode mode) override;
+    Return<int32_t> setSidebandStream(const hidl_handle& stream) override;
+    Return<void> allocateBuffers(
+            uint32_t width, uint32_t height,
+            PixelFormat format, uint32_t usage) override;
+    Return<int32_t> allowAllocation(bool allow) override;
+    Return<int32_t> setGenerationNumber(uint32_t generationNumber) override;
+    Return<void> getConsumerName(getConsumerName_cb _hidl_cb) override;
+    Return<int32_t> setSharedBufferMode(bool sharedBufferMode) override;
+    Return<int32_t> setAutoRefresh(bool autoRefresh) override;
+    Return<int32_t> setDequeueTimeout(int64_t timeoutNs) override;
+    Return<void> getLastQueuedBuffer(getLastQueuedBuffer_cb _hidl_cb) override;
+    Return<void> getFrameTimestamps(getFrameTimestamps_cb _hidl_cb) override;
+    Return<void> getUniqueId(getUniqueId_cb _hidl_cb) override;
+};
+
+}  // namespace implementation
+}  // namespace V1_0
+}  // namespace omx
+}  // namespace media
+}  // namespace hardware
+}  // namespace android
+
+#endif  // ANDROID_HARDWARE_MEDIA_OMX_V1_0_WOMXBUFFERPRODUCER_H
diff --git a/media/libstagefright/omx/hal/1.0/impl/WGraphicBufferSource.cpp b/media/libstagefright/omx/1.0/WGraphicBufferSource.cpp
similarity index 100%
rename from media/libstagefright/omx/hal/1.0/impl/WGraphicBufferSource.cpp
rename to media/libstagefright/omx/1.0/WGraphicBufferSource.cpp
diff --git a/media/libstagefright/omx/hal/1.0/impl/WGraphicBufferSource.h b/media/libstagefright/omx/1.0/WGraphicBufferSource.h
similarity index 98%
rename from media/libstagefright/omx/hal/1.0/impl/WGraphicBufferSource.h
rename to media/libstagefright/omx/1.0/WGraphicBufferSource.h
index 8cf11ca..73b86b8 100644
--- a/media/libstagefright/omx/hal/1.0/impl/WGraphicBufferSource.h
+++ b/media/libstagefright/omx/1.0/WGraphicBufferSource.h
@@ -28,7 +28,7 @@
 
 #include <android/BnGraphicBufferSource.h>
 
-#include "../../../GraphicBufferSource.h"
+#include "../GraphicBufferSource.h"
 
 namespace android {
 namespace hardware {
diff --git a/media/libstagefright/omx/hal/1.0/impl/WOmxBufferSource.cpp b/media/libstagefright/omx/1.0/WOmxBufferSource.cpp
similarity index 100%
rename from media/libstagefright/omx/hal/1.0/impl/WOmxBufferSource.cpp
rename to media/libstagefright/omx/1.0/WOmxBufferSource.cpp
diff --git a/media/libstagefright/omx/hal/1.0/impl/WOmxBufferSource.h b/media/libstagefright/omx/1.0/WOmxBufferSource.h
similarity index 100%
rename from media/libstagefright/omx/hal/1.0/impl/WOmxBufferSource.h
rename to media/libstagefright/omx/1.0/WOmxBufferSource.h
diff --git a/media/libstagefright/omx/hal/1.0/impl/WOmxNode.cpp b/media/libstagefright/omx/1.0/WOmxNode.cpp
similarity index 100%
rename from media/libstagefright/omx/hal/1.0/impl/WOmxNode.cpp
rename to media/libstagefright/omx/1.0/WOmxNode.cpp
diff --git a/media/libstagefright/omx/hal/1.0/impl/WOmxNode.h b/media/libstagefright/omx/1.0/WOmxNode.h
similarity index 98%
rename from media/libstagefright/omx/hal/1.0/impl/WOmxNode.h
rename to media/libstagefright/omx/1.0/WOmxNode.h
index 75816ba..8ca3e67 100644
--- a/media/libstagefright/omx/hal/1.0/impl/WOmxNode.h
+++ b/media/libstagefright/omx/1.0/WOmxNode.h
@@ -22,7 +22,7 @@
 
 #include <utils/Errors.h>
 
-#include "../../../../include/OMXNodeInstance.h"
+#include "../../include/OMXNodeInstance.h"
 
 #include <android/hardware/media/omx/1.0/IOmxNode.h>
 #include <android/hardware/media/omx/1.0/IOmxObserver.h>
diff --git a/media/libstagefright/omx/hal/1.0/impl/WOmxObserver.cpp b/media/libstagefright/omx/1.0/WOmxObserver.cpp
similarity index 100%
rename from media/libstagefright/omx/hal/1.0/impl/WOmxObserver.cpp
rename to media/libstagefright/omx/1.0/WOmxObserver.cpp
diff --git a/media/libstagefright/omx/hal/1.0/impl/WOmxObserver.h b/media/libstagefright/omx/1.0/WOmxObserver.h
similarity index 100%
rename from media/libstagefright/omx/hal/1.0/impl/WOmxObserver.h
rename to media/libstagefright/omx/1.0/WOmxObserver.h
diff --git a/media/libstagefright/omx/hal/1.0/impl/WOmxProducerListener.cpp b/media/libstagefright/omx/1.0/WProducerListener.cpp
similarity index 69%
rename from media/libstagefright/omx/hal/1.0/impl/WOmxProducerListener.cpp
rename to media/libstagefright/omx/1.0/WProducerListener.cpp
index a5eed35..be0d4d5 100644
--- a/media/libstagefright/omx/hal/1.0/impl/WOmxProducerListener.cpp
+++ b/media/libstagefright/omx/1.0/WProducerListener.cpp
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-#include "WOmxProducerListener.h"
+#include "WProducerListener.h"
 
 namespace android {
 namespace hardware {
@@ -23,32 +23,32 @@
 namespace V1_0 {
 namespace implementation {
 
-// TWOmxProducerListener
-TWOmxProducerListener::TWOmxProducerListener(
-        sp<IProducerListener> const& base):
+// TWProducerListener
+TWProducerListener::TWProducerListener(
+        sp<BProducerListener> const& base):
     mBase(base) {
 }
 
-Return<void> TWOmxProducerListener::onBufferReleased() {
+Return<void> TWProducerListener::onBufferReleased() {
     mBase->onBufferReleased();
     return Void();
 }
 
-Return<bool> TWOmxProducerListener::needsReleaseNotify() {
+Return<bool> TWProducerListener::needsReleaseNotify() {
     return mBase->needsReleaseNotify();
 }
 
-// LWOmxProducerListener
-LWOmxProducerListener::LWOmxProducerListener(
-        sp<IOmxProducerListener> const& base):
+// LWProducerListener
+LWProducerListener::LWProducerListener(
+        sp<HProducerListener> const& base):
     mBase(base) {
 }
 
-void LWOmxProducerListener::onBufferReleased() {
+void LWProducerListener::onBufferReleased() {
     mBase->onBufferReleased();
 }
 
-bool LWOmxProducerListener::needsReleaseNotify() {
+bool LWProducerListener::needsReleaseNotify() {
     return static_cast<bool>(mBase->needsReleaseNotify());
 }
 
diff --git a/media/libstagefright/omx/hal/1.0/impl/WOmxProducerListener.h b/media/libstagefright/omx/1.0/WProducerListener.h
similarity index 76%
rename from media/libstagefright/omx/hal/1.0/impl/WOmxProducerListener.h
rename to media/libstagefright/omx/1.0/WProducerListener.h
index e60032e..a75e48a 100644
--- a/media/libstagefright/omx/hal/1.0/impl/WOmxProducerListener.h
+++ b/media/libstagefright/omx/1.0/WProducerListener.h
@@ -23,7 +23,7 @@
 #include <binder/IBinder.h>
 #include <gui/IProducerListener.h>
 
-#include <android/hardware/media/omx/1.0/IOmxProducerListener.h>
+#include <android/hardware/graphics/bufferqueue/1.0/IProducerListener.h>
 
 namespace android {
 namespace hardware {
@@ -32,7 +32,6 @@
 namespace V1_0 {
 namespace implementation {
 
-using ::android::hardware::media::omx::V1_0::IOmxProducerListener;
 using ::android::hidl::base::V1_0::IBase;
 using ::android::hardware::hidl_array;
 using ::android::hardware::hidl_memory;
@@ -42,20 +41,23 @@
 using ::android::hardware::Void;
 using ::android::sp;
 
-using ::android::IProducerListener;
+typedef ::android::hardware::graphics::bufferqueue::V1_0::IProducerListener
+        HProducerListener;
+typedef ::android::IProducerListener
+        BProducerListener;
 using ::android::BnProducerListener;
 
-struct TWOmxProducerListener : public IOmxProducerListener {
-    sp<IProducerListener> mBase;
-    TWOmxProducerListener(sp<IProducerListener> const& base);
+struct TWProducerListener : public HProducerListener {
+    sp<BProducerListener> mBase;
+    TWProducerListener(sp<BProducerListener> const& base);
     Return<void> onBufferReleased() override;
     Return<bool> needsReleaseNotify() override;
 };
 
-class LWOmxProducerListener : public BnProducerListener {
+class LWProducerListener : public BnProducerListener {
 public:
-    sp<IOmxProducerListener> mBase;
-    LWOmxProducerListener(sp<IOmxProducerListener> const& base);
+    sp<HProducerListener> mBase;
+    LWProducerListener(sp<HProducerListener> const& base);
     void onBufferReleased() override;
     bool needsReleaseNotify() override;
 };
diff --git a/media/libstagefright/omx/Android.mk b/media/libstagefright/omx/Android.mk
index 9cba3d0..b1508dc 100644
--- a/media/libstagefright/omx/Android.mk
+++ b/media/libstagefright/omx/Android.mk
@@ -1,19 +1,26 @@
 LOCAL_PATH:= $(call my-dir)
 include $(CLEAR_VARS)
 
-LOCAL_SRC_FILES:=                     \
-        FrameDropper.cpp              \
-        GraphicBufferSource.cpp       \
-        BWGraphicBufferSource.cpp      \
-        OMX.cpp                       \
-        OMXMaster.cpp                 \
-        OMXNodeInstance.cpp           \
-        OMXUtils.cpp                  \
-        SimpleSoftOMXComponent.cpp    \
-        SoftOMXComponent.cpp          \
-        SoftOMXPlugin.cpp             \
-        SoftVideoDecoderOMXComponent.cpp \
-        SoftVideoEncoderOMXComponent.cpp \
+LOCAL_SRC_FILES:=                          \
+        FrameDropper.cpp                   \
+        GraphicBufferSource.cpp            \
+        BWGraphicBufferSource.cpp          \
+        OMX.cpp                            \
+        OMXMaster.cpp                      \
+        OMXNodeInstance.cpp                \
+        OMXUtils.cpp                       \
+        SimpleSoftOMXComponent.cpp         \
+        SoftOMXComponent.cpp               \
+        SoftOMXPlugin.cpp                  \
+        SoftVideoDecoderOMXComponent.cpp   \
+        SoftVideoEncoderOMXComponent.cpp   \
+        1.0/Omx.cpp                        \
+        1.0/WGraphicBufferProducer.cpp     \
+        1.0/WProducerListener.cpp          \
+        1.0/WGraphicBufferSource.cpp       \
+        1.0/WOmxNode.cpp                   \
+        1.0/WOmxObserver.cpp               \
+        1.0/WOmxBufferSource.cpp           \
 
 LOCAL_C_INCLUDES += \
         $(TOP)/frameworks/av/media/libstagefright \
@@ -21,25 +28,34 @@
         $(TOP)/frameworks/native/include/media/openmax \
         $(TOP)/system/libhidl/base/include \
 
-LOCAL_SHARED_LIBRARIES :=               \
-        libbinder                       \
-        libmedia                        \
-        libutils                        \
-        liblog                          \
-        libui                           \
-        libgui                          \
-        libcutils                       \
-        libstagefright_foundation       \
-        libdl                           \
-        libhidlbase                     \
-        libhidlmemory                   \
-        android.hidl.memory@1.0         \
+LOCAL_SHARED_LIBRARIES :=                         \
+        libbase                                   \
+        libbinder                                 \
+        libmedia                                  \
+        libutils                                  \
+        liblog                                    \
+        libui                                     \
+        libgui                                    \
+        libcutils                                 \
+        libstagefright_foundation                 \
+        libdl                                     \
+        libhidlbase                               \
+        libhidlmemory                             \
+        android.hidl.base@1.0                     \
+        android.hidl.memory@1.0                   \
+        android.hardware.media@1.0                \
+        android.hardware.media.omx@1.0            \
+        android.hardware.graphics.common@1.0      \
+        android.hardware.graphics.bufferqueue@1.0 \
+
+LOCAL_EXPORT_C_INCLUDES := \
+        $(TOP)/frameworks/av/include
 
 LOCAL_EXPORT_SHARED_LIBRARY_HEADERS := \
         android.hidl.memory@1.0
 
 LOCAL_MODULE:= libstagefright_omx
-LOCAL_CFLAGS += -Werror -Wall
+LOCAL_CFLAGS += -Werror -Wall -Wno-unused-parameter -Wno-documentation
 LOCAL_SANITIZE := unsigned-integer-overflow signed-integer-overflow cfi
 LOCAL_SANITIZE_DIAG := cfi
 
diff --git a/media/libstagefright/omx/hal/1.0/Android.mk b/media/libstagefright/omx/hal/1.0/Android.mk
deleted file mode 100644
index c14e909..0000000
--- a/media/libstagefright/omx/hal/1.0/Android.mk
+++ /dev/null
@@ -1,3 +0,0 @@
-LOCAL_PATH := $(call my-dir)
-include $(call all-makefiles-under,$(LOCAL_PATH))
-
diff --git a/media/libstagefright/omx/hal/1.0/impl/WOmxBufferProducer.cpp b/media/libstagefright/omx/hal/1.0/impl/WOmxBufferProducer.cpp
deleted file mode 100644
index b6b9a3b..0000000
--- a/media/libstagefright/omx/hal/1.0/impl/WOmxBufferProducer.cpp
+++ /dev/null
@@ -1,621 +0,0 @@
-/*
- * Copyright 2016, The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define LOG_TAG "WOmxBufferProducer-impl"
-
-#include <android-base/logging.h>
-
-#include "WOmxBufferProducer.h"
-#include "WOmxProducerListener.h"
-#include "Conversion.h"
-
-namespace android {
-namespace hardware {
-namespace media {
-namespace omx {
-namespace V1_0 {
-namespace implementation {
-
-// TWOmxBufferProducer
-TWOmxBufferProducer::TWOmxBufferProducer(
-        sp<IGraphicBufferProducer> const& base):
-    mBase(base) {
-}
-
-Return<void> TWOmxBufferProducer::requestBuffer(
-        int32_t slot, requestBuffer_cb _hidl_cb) {
-    sp<GraphicBuffer> buf;
-    status_t status = mBase->requestBuffer(slot, &buf);
-    AnwBuffer anwBuffer;
-    wrapAs(&anwBuffer, *buf);
-    _hidl_cb(toStatus(status), anwBuffer);
-    return Void();
-}
-
-Return<Status> TWOmxBufferProducer::setMaxDequeuedBufferCount(
-        int32_t maxDequeuedBuffers) {
-    return toStatus(mBase->setMaxDequeuedBufferCount(
-            static_cast<int>(maxDequeuedBuffers)));
-}
-
-Return<Status> TWOmxBufferProducer::setAsyncMode(bool async) {
-    return toStatus(mBase->setAsyncMode(async));
-}
-
-Return<void> TWOmxBufferProducer::dequeueBuffer(
-        uint32_t width, uint32_t height,
-        PixelFormat format, uint32_t usage,
-        bool getFrameTimestamps, dequeueBuffer_cb _hidl_cb) {
-    int slot;
-    sp<Fence> fence;
-    ::android::FrameEventHistoryDelta outTimestamps;
-    status_t status = mBase->dequeueBuffer(
-            &slot, &fence,
-            width, height,
-            static_cast<::android::PixelFormat>(format), usage,
-            getFrameTimestamps ? &outTimestamps : nullptr);
-    hidl_handle tFence;
-    FrameEventHistoryDelta tOutTimestamps;
-
-    native_handle_t* nh = nullptr;
-    if ((fence == nullptr) || !wrapAs(&tFence, &nh, *fence)) {
-        LOG(ERROR) << "TWOmxBufferProducer::dequeueBuffer - "
-                "Invalid output fence";
-        _hidl_cb(toStatus(status),
-                 static_cast<int32_t>(slot),
-                 tFence,
-                 tOutTimestamps);
-        return Void();
-    }
-    std::vector<std::vector<native_handle_t*> > nhAA;
-    if (getFrameTimestamps && !wrapAs(&tOutTimestamps, &nhAA, outTimestamps)) {
-        LOG(ERROR) << "TWOmxBufferProducer::dequeueBuffer - "
-                "Invalid output timestamps";
-        _hidl_cb(toStatus(status),
-                 static_cast<int32_t>(slot),
-                 tFence,
-                 tOutTimestamps);
-        native_handle_delete(nh);
-        return Void();
-    }
-
-    _hidl_cb(toStatus(status),
-            static_cast<int32_t>(slot),
-            tFence,
-            tOutTimestamps);
-    native_handle_delete(nh);
-    if (getFrameTimestamps) {
-        for (auto& nhA : nhAA) {
-            for (auto& handle : nhA) {
-                native_handle_delete(handle);
-            }
-        }
-    }
-    return Void();
-}
-
-Return<Status> TWOmxBufferProducer::detachBuffer(int32_t slot) {
-    return toStatus(mBase->detachBuffer(slot));
-}
-
-Return<void> TWOmxBufferProducer::detachNextBuffer(
-        detachNextBuffer_cb _hidl_cb) {
-    sp<GraphicBuffer> outBuffer;
-    sp<Fence> outFence;
-    status_t status = mBase->detachNextBuffer(&outBuffer, &outFence);
-    AnwBuffer tBuffer;
-    hidl_handle tFence;
-
-    if (outBuffer == nullptr) {
-        LOG(ERROR) << "TWOmxBufferProducer::detachNextBuffer - "
-                "Invalid output buffer";
-        _hidl_cb(toStatus(status), tBuffer, tFence);
-        return Void();
-    }
-    wrapAs(&tBuffer, *outBuffer);
-    native_handle_t* nh = nullptr;
-    if ((outFence != nullptr) && !wrapAs(&tFence, &nh, *outFence)) {
-        LOG(ERROR) << "TWOmxBufferProducer::detachNextBuffer - "
-                "Invalid output fence";
-        _hidl_cb(toStatus(status), tBuffer, tFence);
-        return Void();
-    }
-
-    _hidl_cb(toStatus(status), tBuffer, tFence);
-    native_handle_delete(nh);
-    return Void();
-}
-
-Return<void> TWOmxBufferProducer::attachBuffer(
-        const AnwBuffer& buffer,
-        attachBuffer_cb _hidl_cb) {
-    int outSlot;
-    sp<GraphicBuffer> lBuffer = new GraphicBuffer();
-    if (!convertTo(lBuffer.get(), buffer)) {
-        LOG(ERROR) << "TWOmxBufferProducer::attachBuffer - "
-                "Invalid input native window buffer";
-        _hidl_cb(toStatus(BAD_VALUE), -1);
-        return Void();
-    }
-    status_t status = mBase->attachBuffer(&outSlot, lBuffer);
-
-    _hidl_cb(toStatus(status), static_cast<int32_t>(outSlot));
-    return Void();
-}
-
-Return<void> TWOmxBufferProducer::queueBuffer(
-        int32_t slot, const QueueBufferInput& input,
-        queueBuffer_cb _hidl_cb) {
-    QueueBufferOutput tOutput;
-    IGraphicBufferProducer::QueueBufferInput lInput(
-            0, false, HAL_DATASPACE_UNKNOWN,
-            ::android::Rect(0, 0, 1, 1),
-            NATIVE_WINDOW_SCALING_MODE_FREEZE,
-            0, ::android::Fence::NO_FENCE);
-    if (!convertTo(&lInput, input)) {
-        LOG(ERROR) << "TWOmxBufferProducer::queueBuffer - "
-                "Invalid input";
-        _hidl_cb(toStatus(BAD_VALUE), tOutput);
-        return Void();
-    }
-    IGraphicBufferProducer::QueueBufferOutput lOutput;
-    status_t status = mBase->queueBuffer(
-            static_cast<int>(slot), lInput, &lOutput);
-
-    std::vector<std::vector<native_handle_t*> > nhAA;
-    if (!wrapAs(&tOutput, &nhAA, lOutput)) {
-        LOG(ERROR) << "TWOmxBufferProducer::queueBuffer - "
-                "Invalid output";
-        _hidl_cb(toStatus(BAD_VALUE), tOutput);
-        return Void();
-    }
-
-    _hidl_cb(toStatus(status), tOutput);
-    for (auto& nhA : nhAA) {
-        for (auto& nh : nhA) {
-            native_handle_delete(nh);
-        }
-    }
-    return Void();
-}
-
-Return<Status> TWOmxBufferProducer::cancelBuffer(
-        int32_t slot, const hidl_handle& fence) {
-    sp<Fence> lFence = new Fence();
-    if (!convertTo(lFence.get(), fence)) {
-        LOG(ERROR) << "TWOmxBufferProducer::cancelBuffer - "
-                "Invalid input fence";
-        return toStatus(BAD_VALUE);
-    }
-    return toStatus(mBase->cancelBuffer(static_cast<int>(slot), lFence));
-}
-
-Return<void> TWOmxBufferProducer::query(int32_t what, query_cb _hidl_cb) {
-    int lValue;
-    int lReturn = mBase->query(static_cast<int>(what), &lValue);
-    _hidl_cb(static_cast<int32_t>(lReturn), static_cast<int32_t>(lValue));
-    return Void();
-}
-
-Return<void> TWOmxBufferProducer::connect(
-        const sp<IOmxProducerListener>& listener,
-        int32_t api, bool producerControlledByApp, connect_cb _hidl_cb) {
-    sp<IProducerListener> lListener = listener == nullptr ?
-            nullptr : new LWOmxProducerListener(listener);
-    IGraphicBufferProducer::QueueBufferOutput lOutput;
-    status_t status = mBase->connect(lListener,
-            static_cast<int>(api),
-            producerControlledByApp,
-            &lOutput);
-
-    QueueBufferOutput tOutput;
-    std::vector<std::vector<native_handle_t*> > nhAA;
-    if (!wrapAs(&tOutput, &nhAA, lOutput)) {
-        LOG(ERROR) << "TWOmxBufferProducer::connect - "
-                "Invalid output";
-        _hidl_cb(toStatus(status), tOutput);
-        return Void();
-    }
-
-    _hidl_cb(toStatus(status), tOutput);
-    for (auto& nhA : nhAA) {
-        for (auto& nh : nhA) {
-            native_handle_delete(nh);
-        }
-    }
-    return Void();
-}
-
-Return<Status> TWOmxBufferProducer::disconnect(
-        int32_t api, DisconnectMode mode) {
-    return toStatus(mBase->disconnect(
-            static_cast<int>(api),
-            toGuiDisconnectMode(mode)));
-}
-
-Return<Status> TWOmxBufferProducer::setSidebandStream(const hidl_handle& stream) {
-    return toStatus(mBase->setSidebandStream(NativeHandle::create(
-            native_handle_clone(stream), true)));
-}
-
-Return<void> TWOmxBufferProducer::allocateBuffers(
-        uint32_t width, uint32_t height, PixelFormat format, uint32_t usage) {
-    mBase->allocateBuffers(
-            width, height,
-            static_cast<::android::PixelFormat>(format),
-            usage);
-    return Void();
-}
-
-Return<Status> TWOmxBufferProducer::allowAllocation(bool allow) {
-    return toStatus(mBase->allowAllocation(allow));
-}
-
-Return<Status> TWOmxBufferProducer::setGenerationNumber(uint32_t generationNumber) {
-    return toStatus(mBase->setGenerationNumber(generationNumber));
-}
-
-Return<void> TWOmxBufferProducer::getConsumerName(getConsumerName_cb _hidl_cb) {
-    _hidl_cb(mBase->getConsumerName().string());
-    return Void();
-}
-
-Return<Status> TWOmxBufferProducer::setSharedBufferMode(bool sharedBufferMode) {
-    return toStatus(mBase->setSharedBufferMode(sharedBufferMode));
-}
-
-Return<Status> TWOmxBufferProducer::setAutoRefresh(bool autoRefresh) {
-    return toStatus(mBase->setAutoRefresh(autoRefresh));
-}
-
-Return<Status> TWOmxBufferProducer::setDequeueTimeout(int64_t timeoutNs) {
-    return toStatus(mBase->setDequeueTimeout(timeoutNs));
-}
-
-Return<void> TWOmxBufferProducer::getLastQueuedBuffer(
-        getLastQueuedBuffer_cb _hidl_cb) {
-    sp<GraphicBuffer> lOutBuffer = new GraphicBuffer();
-    sp<Fence> lOutFence = new Fence();
-    float lOutTransformMatrix[16];
-    status_t status = mBase->getLastQueuedBuffer(
-            &lOutBuffer, &lOutFence, lOutTransformMatrix);
-
-    AnwBuffer tOutBuffer;
-    if (lOutBuffer != nullptr) {
-        wrapAs(&tOutBuffer, *lOutBuffer);
-    }
-    hidl_handle tOutFence;
-    native_handle_t* nh = nullptr;
-    if ((lOutFence == nullptr) || !wrapAs(&tOutFence, &nh, *lOutFence)) {
-        LOG(ERROR) << "TWOmxBufferProducer::getLastQueuedBuffer - "
-                "Invalid output fence";
-        _hidl_cb(toStatus(status),
-                tOutBuffer,
-                tOutFence,
-                hidl_array<float, 16>());
-        return Void();
-    }
-    hidl_array<float, 16> tOutTransformMatrix(lOutTransformMatrix);
-
-    _hidl_cb(toStatus(status), tOutBuffer, tOutFence, tOutTransformMatrix);
-    native_handle_delete(nh);
-    return Void();
-}
-
-Return<void> TWOmxBufferProducer::getFrameTimestamps(
-        getFrameTimestamps_cb _hidl_cb) {
-    ::android::FrameEventHistoryDelta lDelta;
-    mBase->getFrameTimestamps(&lDelta);
-
-    FrameEventHistoryDelta tDelta;
-    std::vector<std::vector<native_handle_t*> > nhAA;
-    if (!wrapAs(&tDelta, &nhAA, lDelta)) {
-        LOG(ERROR) << "TWOmxBufferProducer::getFrameTimestamps - "
-                "Invalid output frame timestamps";
-        _hidl_cb(tDelta);
-        return Void();
-    }
-
-    _hidl_cb(tDelta);
-    for (auto& nhA : nhAA) {
-        for (auto& nh : nhA) {
-            native_handle_delete(nh);
-        }
-    }
-    return Void();
-}
-
-Return<void> TWOmxBufferProducer::getUniqueId(getUniqueId_cb _hidl_cb) {
-    uint64_t outId;
-    status_t status = mBase->getUniqueId(&outId);
-    _hidl_cb(toStatus(status), outId);
-    return Void();
-}
-
-// LWOmxBufferProducer
-
-LWOmxBufferProducer::LWOmxBufferProducer(sp<IOmxBufferProducer> const& base) :
-    mBase(base) {
-}
-
-status_t LWOmxBufferProducer::requestBuffer(int slot, sp<GraphicBuffer>* buf) {
-    *buf = new GraphicBuffer();
-    status_t fnStatus;
-    status_t transStatus = toStatusT(mBase->requestBuffer(
-            static_cast<int32_t>(slot),
-            [&fnStatus, &buf] (Status status, AnwBuffer const& buffer) {
-                fnStatus = toStatusT(status);
-                if (!convertTo(buf->get(), buffer)) {
-                    fnStatus = fnStatus == NO_ERROR ? BAD_VALUE : fnStatus;
-                }
-            }));
-    return transStatus == NO_ERROR ? fnStatus : transStatus;
-}
-
-status_t LWOmxBufferProducer::setMaxDequeuedBufferCount(
-        int maxDequeuedBuffers) {
-    return toStatusT(mBase->setMaxDequeuedBufferCount(
-            static_cast<int32_t>(maxDequeuedBuffers)));
-}
-
-status_t LWOmxBufferProducer::setAsyncMode(bool async) {
-    return toStatusT(mBase->setAsyncMode(async));
-}
-
-status_t LWOmxBufferProducer::dequeueBuffer(
-        int* slot, sp<Fence>* fence,
-        uint32_t w, uint32_t h, ::android::PixelFormat format,
-        uint32_t usage, FrameEventHistoryDelta* outTimestamps) {
-    *fence = new Fence();
-    status_t fnStatus;
-    status_t transStatus = toStatusT(mBase->dequeueBuffer(
-            w, h, static_cast<PixelFormat>(format), usage,
-            outTimestamps != nullptr,
-            [&fnStatus, slot, fence, outTimestamps] (
-                    Status status,
-                    int32_t tSlot,
-                    hidl_handle const& tFence,
-                    IOmxBufferProducer::FrameEventHistoryDelta const& tTs) {
-                fnStatus = toStatusT(status);
-                *slot = tSlot;
-                if (!convertTo(fence->get(), tFence)) {
-                    LOG(ERROR) << "LWOmxBufferProducer::dequeueBuffer - "
-                            "Invalid output fence";
-                    fnStatus = fnStatus == NO_ERROR ? BAD_VALUE : fnStatus;
-                }
-                if (outTimestamps && !convertTo(outTimestamps, tTs)) {
-                    LOG(ERROR) << "LWOmxBufferProducer::dequeueBuffer - "
-                            "Invalid output timestamps";
-                    fnStatus = fnStatus == NO_ERROR ? BAD_VALUE : fnStatus;
-                }
-            }));
-    return transStatus == NO_ERROR ? fnStatus : transStatus;
-}
-
-status_t LWOmxBufferProducer::detachBuffer(int slot) {
-    return toStatusT(mBase->detachBuffer(static_cast<int>(slot)));
-}
-
-status_t LWOmxBufferProducer::detachNextBuffer(
-        sp<GraphicBuffer>* outBuffer, sp<Fence>* outFence) {
-    *outBuffer = new GraphicBuffer();
-    *outFence = new Fence();
-    status_t fnStatus;
-    status_t transStatus = toStatusT(mBase->detachNextBuffer(
-            [&fnStatus, outBuffer, outFence] (
-                    Status status,
-                    AnwBuffer const& tBuffer,
-                    hidl_handle const& tFence) {
-                fnStatus = toStatusT(status);
-                if (!convertTo(outFence->get(), tFence)) {
-                    LOG(ERROR) << "LWOmxBufferProducer::detachNextBuffer - "
-                            "Invalid output fence";
-                    fnStatus = fnStatus == NO_ERROR ? BAD_VALUE : fnStatus;
-                }
-                if (!convertTo(outBuffer->get(), tBuffer)) {
-                    LOG(ERROR) << "LWOmxBufferProducer::detachNextBuffer - "
-                            "Invalid output buffer";
-                    fnStatus = fnStatus == NO_ERROR ? BAD_VALUE : fnStatus;
-                }
-            }));
-    return transStatus == NO_ERROR ? fnStatus : transStatus;
-}
-
-status_t LWOmxBufferProducer::attachBuffer(
-        int* outSlot, const sp<GraphicBuffer>& buffer) {
-    AnwBuffer tBuffer;
-    wrapAs(&tBuffer, *buffer);
-    status_t fnStatus;
-    status_t transStatus = toStatusT(mBase->attachBuffer(tBuffer,
-            [&fnStatus, outSlot] (Status status, int32_t slot) {
-                fnStatus = toStatusT(status);
-                *outSlot = slot;
-            }));
-    return transStatus == NO_ERROR ? fnStatus : transStatus;
-}
-
-status_t LWOmxBufferProducer::queueBuffer(
-        int slot,
-        const QueueBufferInput& input,
-        QueueBufferOutput* output) {
-    IOmxBufferProducer::QueueBufferInput tInput;
-    native_handle_t* nh;
-    if (!wrapAs(&tInput, &nh, input)) {
-        LOG(ERROR) << "LWOmxBufferProducer::queueBuffer - "
-                "Invalid input";
-        return BAD_VALUE;
-    }
-    status_t fnStatus;
-    status_t transStatus = toStatusT(mBase->queueBuffer(slot, tInput,
-            [&fnStatus, output] (
-                    Status status,
-                    IOmxBufferProducer::QueueBufferOutput const& tOutput) {
-                fnStatus = toStatusT(status);
-                if (!convertTo(output, tOutput)) {
-                    LOG(ERROR) << "LWOmxBufferProducer::queueBuffer - "
-                            "Invalid output";
-                    fnStatus = fnStatus == NO_ERROR ? BAD_VALUE : fnStatus;
-                }
-            }));
-    native_handle_delete(nh);
-    return transStatus == NO_ERROR ? fnStatus : transStatus;
-}
-
-status_t LWOmxBufferProducer::cancelBuffer(int slot, const sp<Fence>& fence) {
-    hidl_handle tFence;
-    native_handle_t* nh = nullptr;
-    if ((fence == nullptr) || !wrapAs(&tFence, &nh, *fence)) {
-        LOG(ERROR) << "LWOmxBufferProducer::cancelBuffer - "
-                "Invalid input fence";
-        return BAD_VALUE;
-    }
-
-    status_t status = toStatusT(mBase->cancelBuffer(
-            static_cast<int32_t>(slot), tFence));
-    native_handle_delete(nh);
-    return status;
-}
-
-int LWOmxBufferProducer::query(int what, int* value) {
-    int result;
-    status_t transStatus = toStatusT(mBase->query(
-            static_cast<int32_t>(what),
-            [&result, value] (int32_t tResult, int32_t tValue) {
-                result = static_cast<int>(tResult);
-                *value = static_cast<int>(tValue);
-            }));
-    return transStatus == NO_ERROR ? result : static_cast<int>(transStatus);
-}
-
-status_t LWOmxBufferProducer::connect(
-        const sp<IProducerListener>& listener, int api,
-        bool producerControlledByApp, QueueBufferOutput* output) {
-    sp<IOmxProducerListener> tListener = listener == nullptr ?
-            nullptr : new TWOmxProducerListener(listener);
-    status_t fnStatus;
-    status_t transStatus = toStatusT(mBase->connect(
-            tListener, static_cast<int32_t>(api), producerControlledByApp,
-            [&fnStatus, output] (
-                    Status status,
-                    IOmxBufferProducer::QueueBufferOutput const& tOutput) {
-                fnStatus = toStatusT(status);
-                if (!convertTo(output, tOutput)) {
-                    LOG(ERROR) << "LWOmxBufferProducer::connect - "
-                            "Invalid output";
-                    fnStatus = fnStatus == NO_ERROR ? BAD_VALUE : fnStatus;
-                }
-            }));
-    return transStatus == NO_ERROR ? fnStatus : transStatus;
-}
-
-status_t LWOmxBufferProducer::disconnect(int api, DisconnectMode mode) {
-    return toStatusT(mBase->disconnect(
-            static_cast<int32_t>(api), toOmxDisconnectMode(mode)));
-}
-
-status_t LWOmxBufferProducer::setSidebandStream(
-        const sp<NativeHandle>& stream) {
-    return toStatusT(mBase->setSidebandStream(stream->handle()));
-}
-
-void LWOmxBufferProducer::allocateBuffers(uint32_t width, uint32_t height,
-        ::android::PixelFormat format, uint32_t usage) {
-    mBase->allocateBuffers(
-            width, height, static_cast<PixelFormat>(format), usage);
-}
-
-status_t LWOmxBufferProducer::allowAllocation(bool allow) {
-    return toStatusT(mBase->allowAllocation(allow));
-}
-
-status_t LWOmxBufferProducer::setGenerationNumber(uint32_t generationNumber) {
-    return toStatusT(mBase->setGenerationNumber(generationNumber));
-}
-
-String8 LWOmxBufferProducer::getConsumerName() const {
-    String8 lName;
-    mBase->getConsumerName([&lName] (hidl_string const& name) {
-                lName = name.c_str();
-            });
-    return lName;
-}
-
-status_t LWOmxBufferProducer::setSharedBufferMode(bool sharedBufferMode) {
-    return toStatusT(mBase->setSharedBufferMode(sharedBufferMode));
-}
-
-status_t LWOmxBufferProducer::setAutoRefresh(bool autoRefresh) {
-    return toStatusT(mBase->setAutoRefresh(autoRefresh));
-}
-
-status_t LWOmxBufferProducer::setDequeueTimeout(nsecs_t timeout) {
-    return toStatusT(mBase->setDequeueTimeout(static_cast<int64_t>(timeout)));
-}
-
-status_t LWOmxBufferProducer::getLastQueuedBuffer(
-        sp<GraphicBuffer>* outBuffer,
-        sp<Fence>* outFence,
-        float outTransformMatrix[16]) {
-    status_t fnStatus;
-    status_t transStatus = toStatusT(mBase->getLastQueuedBuffer(
-            [&fnStatus, outBuffer, outFence, &outTransformMatrix] (
-                    Status status,
-                    AnwBuffer const& buffer,
-                    hidl_handle const& fence,
-                    hidl_array<float, 16> const& transformMatrix) {
-                fnStatus = toStatusT(status);
-                *outBuffer = new GraphicBuffer();
-                if (!convertTo(outBuffer->get(), buffer)) {
-                    LOG(ERROR) << "LWOmxBufferProducer::getLastQueuedBuffer - "
-                            "Invalid output buffer";
-                    fnStatus = fnStatus == NO_ERROR ? BAD_VALUE : fnStatus;
-                }
-                *outFence = new Fence();
-                if (!convertTo(outFence->get(), fence)) {
-                    LOG(ERROR) << "LWOmxBufferProducer::getLastQueuedBuffer - "
-                            "Invalid output fence";
-                    fnStatus = fnStatus == NO_ERROR ? BAD_VALUE : fnStatus;
-                }
-                std::copy(transformMatrix.data(),
-                        transformMatrix.data() + 16,
-                        outTransformMatrix);
-            }));
-    return transStatus == NO_ERROR ? fnStatus : transStatus;
-}
-
-void LWOmxBufferProducer::getFrameTimestamps(FrameEventHistoryDelta* outDelta) {
-    mBase->getFrameTimestamps([outDelta] (
-            IOmxBufferProducer::FrameEventHistoryDelta const& tDelta) {
-                convertTo(outDelta, tDelta);
-            });
-}
-
-status_t LWOmxBufferProducer::getUniqueId(uint64_t* outId) const {
-    status_t fnStatus;
-    status_t transStatus = toStatusT(mBase->getUniqueId(
-            [&fnStatus, outId] (Status status, uint64_t id) {
-                fnStatus = toStatusT(status);
-                *outId = id;
-            }));
-    return transStatus == NO_ERROR ? fnStatus : transStatus;
-}
-
-}  // namespace implementation
-}  // namespace V1_0
-}  // namespace omx
-}  // namespace media
-}  // namespace hardware
-}  // namespace android
diff --git a/media/libstagefright/omx/hal/1.0/impl/WOmxBufferProducer.h b/media/libstagefright/omx/hal/1.0/impl/WOmxBufferProducer.h
deleted file mode 100644
index 8520160..0000000
--- a/media/libstagefright/omx/hal/1.0/impl/WOmxBufferProducer.h
+++ /dev/null
@@ -1,142 +0,0 @@
-/*
- * Copyright 2016, The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef ANDROID_HARDWARE_MEDIA_OMX_V1_0_WOMXBUFFERPRODUCER_H
-#define ANDROID_HARDWARE_MEDIA_OMX_V1_0_WOMXBUFFERPRODUCER_H
-
-#include <hidl/MQDescriptor.h>
-#include <hidl/Status.h>
-
-#include <binder/Binder.h>
-#include <gui/IGraphicBufferProducer.h>
-#include <gui/IProducerListener.h>
-
-#include <android/hardware/media/omx/1.0/IOmxBufferProducer.h>
-
-namespace android {
-namespace hardware {
-namespace media {
-namespace omx {
-namespace V1_0 {
-namespace implementation {
-
-using ::android::hardware::graphics::common::V1_0::PixelFormat;
-using ::android::hardware::media::omx::V1_0::IOmxBufferProducer;
-using ::android::hardware::media::omx::V1_0::IOmxProducerListener;
-using ::android::hardware::media::omx::V1_0::Status;
-using ::android::hardware::media::V1_0::AnwBuffer;
-using ::android::hidl::base::V1_0::IBase;
-using ::android::hardware::hidl_array;
-using ::android::hardware::hidl_memory;
-using ::android::hardware::hidl_string;
-using ::android::hardware::hidl_vec;
-using ::android::hardware::Return;
-using ::android::hardware::Void;
-using ::android::sp;
-
-using ::android::IGraphicBufferProducer;
-using ::android::BnGraphicBufferProducer;
-using ::android::IProducerListener;
-
-struct TWOmxBufferProducer : public IOmxBufferProducer {
-    sp<IGraphicBufferProducer> mBase;
-    TWOmxBufferProducer(sp<IGraphicBufferProducer> const& base);
-    Return<void> requestBuffer(int32_t slot, requestBuffer_cb _hidl_cb)
-            override;
-    Return<Status> setMaxDequeuedBufferCount(int32_t maxDequeuedBuffers)
-            override;
-    Return<Status> setAsyncMode(bool async) override;
-    Return<void> dequeueBuffer(
-            uint32_t width, uint32_t height, PixelFormat format, uint32_t usage,
-            bool getFrameTimestamps, dequeueBuffer_cb _hidl_cb) override;
-    Return<Status> detachBuffer(int32_t slot) override;
-    Return<void> detachNextBuffer(detachNextBuffer_cb _hidl_cb) override;
-    Return<void> attachBuffer(const AnwBuffer& buffer, attachBuffer_cb _hidl_cb)
-            override;
-    Return<void> queueBuffer(
-            int32_t slot, const IOmxBufferProducer::QueueBufferInput& input,
-            queueBuffer_cb _hidl_cb) override;
-    Return<Status> cancelBuffer(int32_t slot, const hidl_handle& fence)
-            override;
-    Return<void> query(int32_t what, query_cb _hidl_cb) override;
-    Return<void> connect(const sp<IOmxProducerListener>& listener,
-            int32_t api, bool producerControlledByApp,
-            connect_cb _hidl_cb) override;
-    Return<Status> disconnect(
-            int32_t api,
-            IOmxBufferProducer::DisconnectMode mode) override;
-    Return<Status> setSidebandStream(const hidl_handle& stream) override;
-    Return<void> allocateBuffers(
-            uint32_t width, uint32_t height,
-            PixelFormat format, uint32_t usage) override;
-    Return<Status> allowAllocation(bool allow) override;
-    Return<Status> setGenerationNumber(uint32_t generationNumber) override;
-    Return<void> getConsumerName(getConsumerName_cb _hidl_cb) override;
-    Return<Status> setSharedBufferMode(bool sharedBufferMode) override;
-    Return<Status> setAutoRefresh(bool autoRefresh) override;
-    Return<Status> setDequeueTimeout(int64_t timeoutNs) override;
-    Return<void> getLastQueuedBuffer(getLastQueuedBuffer_cb _hidl_cb) override;
-    Return<void> getFrameTimestamps(getFrameTimestamps_cb _hidl_cb) override;
-    Return<void> getUniqueId(getUniqueId_cb _hidl_cb) override;
-};
-
-struct LWOmxBufferProducer : public BnGraphicBufferProducer {
-    sp<IOmxBufferProducer> mBase;
-    LWOmxBufferProducer(sp<IOmxBufferProducer> const& base);
-
-    status_t requestBuffer(int slot, sp<GraphicBuffer>* buf) override;
-    status_t setMaxDequeuedBufferCount(int maxDequeuedBuffers) override;
-    status_t setAsyncMode(bool async) override;
-    status_t dequeueBuffer(int* slot, sp<Fence>* fence, uint32_t w,
-            uint32_t h, ::android::PixelFormat format, uint32_t usage,
-            FrameEventHistoryDelta* outTimestamps) override;
-    status_t detachBuffer(int slot) override;
-    status_t detachNextBuffer(sp<GraphicBuffer>* outBuffer, sp<Fence>* outFence)
-            override;
-    status_t attachBuffer(int* outSlot, const sp<GraphicBuffer>& buffer)
-            override;
-    status_t queueBuffer(int slot,
-            const QueueBufferInput& input,
-            QueueBufferOutput* output) override;
-    status_t cancelBuffer(int slot, const sp<Fence>& fence) override;
-    int query(int what, int* value) override;
-    status_t connect(const sp<IProducerListener>& listener, int api,
-            bool producerControlledByApp, QueueBufferOutput* output) override;
-    status_t disconnect(int api, DisconnectMode mode = DisconnectMode::Api)
-            override;
-    status_t setSidebandStream(const sp<NativeHandle>& stream) override;
-    void allocateBuffers(uint32_t width, uint32_t height,
-            ::android::PixelFormat format, uint32_t usage) override;
-    status_t allowAllocation(bool allow) override;
-    status_t setGenerationNumber(uint32_t generationNumber) override;
-    String8 getConsumerName() const override;
-    status_t setSharedBufferMode(bool sharedBufferMode) override;
-    status_t setAutoRefresh(bool autoRefresh) override;
-    status_t setDequeueTimeout(nsecs_t timeout) override;
-    status_t getLastQueuedBuffer(sp<GraphicBuffer>* outBuffer,
-          sp<Fence>* outFence, float outTransformMatrix[16]) override;
-    void getFrameTimestamps(FrameEventHistoryDelta* outDelta) override;
-    status_t getUniqueId(uint64_t* outId) const override;
-};
-
-}  // namespace implementation
-}  // namespace V1_0
-}  // namespace omx
-}  // namespace media
-}  // namespace hardware
-}  // namespace android
-
-#endif  // ANDROID_HARDWARE_MEDIA_OMX_V1_0_WOMXBUFFERPRODUCER_H
diff --git a/media/libstagefright/omx/tests/OMXHarness.cpp b/media/libstagefright/omx/tests/OMXHarness.cpp
index 8817cf9..cbca461 100644
--- a/media/libstagefright/omx/tests/OMXHarness.cpp
+++ b/media/libstagefright/omx/tests/OMXHarness.cpp
@@ -40,7 +40,7 @@
 #include <media/stagefright/SimpleDecodingSource.h>
 #include <media/OMXBuffer.h>
 #include <android/hardware/media/omx/1.0/IOmx.h>
-#include <omx/hal/1.0/utils/WOmx.h>
+#include <media/omx/1.0/WOmx.h>
 
 #define DEFAULT_TIMEOUT         500000
 
diff --git a/services/mediacodec/Android.mk b/services/mediacodec/Android.mk
index 8814cf2..5cb7f92 100644
--- a/services/mediacodec/Android.mk
+++ b/services/mediacodec/Android.mk
@@ -34,8 +34,8 @@
     libcutils \
     libhwbinder \
     libhidltransport \
+    libstagefright_omx \
     android.hardware.media.omx@1.0 \
-    android.hardware.media.omx@1.0-impl \
     android.hidl.memory@1.0
 LOCAL_C_INCLUDES := \
     $(TOP)/frameworks/av/media/libstagefright \
diff --git a/services/mediacodec/main_codecservice.cpp b/services/mediacodec/main_codecservice.cpp
index ef305b4..38717b5 100644
--- a/services/mediacodec/main_codecservice.cpp
+++ b/services/mediacodec/main_codecservice.cpp
@@ -33,7 +33,7 @@
 
 #include <android/hardware/media/omx/1.0/IOmx.h>
 #include <hidl/HidlTransportSupport.h>
-#include <omx/hal/1.0/impl/Omx.h>
+#include <omx/1.0/Omx.h>
 
 using namespace android;