Fix error handling in Treble OMX wrappers.

Certain cases of error were not handled properly.

Also, this CL gets rid of the native crash as seen in b/35616667.
(Casting still does not function properly.)

Test: As instructed in b/35616667. No native crashes occur.
Bug: 35616667
Change-Id: I34d48fd83517010e8caa1b9ab246d171db1d4d49
diff --git a/media/libstagefright/omx/hal/1.0/impl/Android.mk b/media/libstagefright/omx/hal/1.0/impl/Android.mk
index ced6e94..db0cb4e 100644
--- a/media/libstagefright/omx/hal/1.0/impl/Android.mk
+++ b/media/libstagefright/omx/hal/1.0/impl/Android.mk
@@ -11,7 +11,6 @@
     WOmxObserver.cpp \
     WOmxProducerListener.cpp \
     Omx.cpp \
-    OmxNode.cpp \
 
 LOCAL_SHARED_LIBRARIES := \
     libmedia \
@@ -27,6 +26,7 @@
     libcutils \
     libbinder \
     liblog \
+    libbase \
     android.hardware.media.omx@1.0 \
     android.hardware.graphics.common@1.0 \
     android.hardware.media@1.0 \
diff --git a/media/libstagefright/omx/hal/1.0/impl/Conversion.h b/media/libstagefright/omx/hal/1.0/impl/Conversion.h
index 1928875..d5cf029 100644
--- a/media/libstagefright/omx/hal/1.0/impl/Conversion.h
+++ b/media/libstagefright/omx/hal/1.0/impl/Conversion.h
@@ -177,25 +177,6 @@
  */
 
 /**
- * \brief Convert `binder::Status` to `Return<void>`.
- *
- * \param[in] l The source `binder::Status`.
- * \return The corresponding `Return<void>`.
- */
-// convert: ::android::binder::Status -> Return<void>
-inline Return<void> toHardwareStatus(
-        ::android::binder::Status const& l) {
-    if (l.exceptionCode() == ::android::binder::Status::EX_SERVICE_SPECIFIC) {
-        return ::android::hardware::Status::fromServiceSpecificError(
-                l.serviceSpecificErrorCode(),
-                l.exceptionMessage());
-    }
-    return ::android::hardware::Status::fromExceptionCode(
-            l.exceptionCode(),
-            l.exceptionMessage());
-}
-
-/**
  * \brief Convert `Return<void>` to `binder::Status`.
  *
  * \param[in] t The source `Return<void>`.
diff --git a/media/libstagefright/omx/hal/1.0/impl/Omx.cpp b/media/libstagefright/omx/hal/1.0/impl/Omx.cpp
index cacaa13..a9f29e9 100644
--- a/media/libstagefright/omx/hal/1.0/impl/Omx.cpp
+++ b/media/libstagefright/omx/hal/1.0/impl/Omx.cpp
@@ -14,8 +14,10 @@
  * limitations under the License.
  */
 
+#include <ios>
 #include <list>
 
+#include <android-base/logging.h>
 #include <gui/IGraphicBufferProducer.h>
 #include <OMX_Core.h>
 #include <OMX_AsString.h>
@@ -102,9 +104,10 @@
             instance.get(), &handle);
 
     if (err != OMX_ErrorNone) {
-        ALOGE("FAILED to allocate omx component '%s' err=%s(%#x)",
-                name.c_str(), asString(err), err);
-
+        LOG(ERROR) << "Failed to allocate omx component "
+                "'" << name.c_str() << "' "
+                " err=" << asString(err) <<
+                "(0x" << std::hex << unsigned(err) << ")";
         _hidl_cb(toStatus(StatusFromOMXError(err)), nullptr);
         return Void();
     }
@@ -125,8 +128,9 @@
     sp<GraphicBufferSource> graphicBufferSource = new GraphicBufferSource();
     status_t err = graphicBufferSource->initCheck();
     if (err != OK) {
-        ALOGE("Failed to create persistent input surface: %s (%d)",
-                strerror(-err), err);
+        LOG(ERROR) << "Failed to create persistent input surface: "
+                << strerror(-err) << " "
+                "(" << int(err) << ")";
         _hidl_cb(toStatus(err), nullptr, nullptr);
         return Void();
     }
@@ -147,7 +151,7 @@
         ssize_t index = mLiveNodes.indexOfKey(who);
 
         if (index < 0) {
-            ALOGE("b/27597103, nonexistent observer on serviceDied");
+            LOG(ERROR) << "b/27597103, nonexistent observer on serviceDied";
             android_errorWriteLog(0x534e4554, "27597103");
             return;
         }
diff --git a/media/libstagefright/omx/hal/1.0/impl/OmxNode.cpp b/media/libstagefright/omx/hal/1.0/impl/OmxNode.cpp
deleted file mode 100644
index 641b829..0000000
--- a/media/libstagefright/omx/hal/1.0/impl/OmxNode.cpp
+++ /dev/null
@@ -1,129 +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 "Conversion.h"
-
-#include "OmxNode.h"
-#include "WOmxObserver.h"
-
-namespace android {
-namespace hardware {
-namespace media {
-namespace omx {
-namespace V1_0 {
-namespace implementation {
-
-// Methods from ::android::hardware::media::omx::V1_0::IOmxNode follow.
-Return<Status> OmxNode::freeNode() {
-    // TODO implement
-    return ::android::hardware::media::omx::V1_0::Status {};
-}
-
-Return<Status> OmxNode::sendCommand(uint32_t cmd, int32_t param) {
-    // TODO implement
-    return ::android::hardware::media::omx::V1_0::Status {};
-}
-
-Return<void> OmxNode::getParameter(uint32_t index, const hidl_vec<uint8_t>& inParams, getParameter_cb _hidl_cb) {
-    // TODO implement
-    return Void();
-}
-
-Return<Status> OmxNode::setParameter(uint32_t index, const hidl_vec<uint8_t>& params) {
-    // TODO implement
-    return ::android::hardware::media::omx::V1_0::Status {};
-}
-
-Return<void> OmxNode::getConfig(uint32_t index, const hidl_vec<uint8_t>& inConfig, getConfig_cb _hidl_cb) {
-    // TODO implement
-    return Void();
-}
-
-Return<Status> OmxNode::setConfig(uint32_t index, const hidl_vec<uint8_t>& config) {
-    // TODO implement
-    return ::android::hardware::media::omx::V1_0::Status {};
-}
-
-Return<Status> OmxNode::setPortMode(uint32_t portIndex, PortMode mode) {
-    // TODO implement
-    return ::android::hardware::media::omx::V1_0::Status {};
-}
-
-Return<Status> OmxNode::prepareForAdaptivePlayback(uint32_t portIndex, bool enable, uint32_t maxFrameWidth, uint32_t maxFrameHeight) {
-    // TODO implement
-    return ::android::hardware::media::omx::V1_0::Status {};
-}
-
-Return<void> OmxNode::configureVideoTunnelMode(uint32_t portIndex, bool tunneled, uint32_t audioHwSync, configureVideoTunnelMode_cb _hidl_cb) {
-    // TODO implement
-    return Void();
-}
-
-Return<void> OmxNode::getGraphicBufferUsage(uint32_t portIndex, getGraphicBufferUsage_cb _hidl_cb) {
-    // TODO implement
-    return Void();
-}
-
-Return<Status> OmxNode::setInputSurface(const sp<IOmxBufferSource>& bufferSource) {
-    // TODO implement
-    return ::android::hardware::media::omx::V1_0::Status {};
-}
-
-Return<void> OmxNode::allocateSecureBuffer(uint32_t portIndex, uint64_t size, allocateSecureBuffer_cb _hidl_cb) {
-    // TODO implement
-    return Void();
-}
-
-Return<void> OmxNode::useBuffer(uint32_t portIndex, const CodecBuffer& omxBuffer, useBuffer_cb _hidl_cb) {
-    // TODO implement
-    return Void();
-}
-
-Return<Status> OmxNode::freeBuffer(uint32_t portIndex, uint32_t buffer) {
-    // TODO implement
-    return ::android::hardware::media::omx::V1_0::Status {};
-}
-
-Return<Status> OmxNode::fillBuffer(uint32_t buffer, const CodecBuffer& omxBuffer, const hidl_handle& fence) {
-    // TODO implement
-    return ::android::hardware::media::omx::V1_0::Status {};
-}
-
-Return<Status> OmxNode::emptyBuffer(uint32_t buffer, const CodecBuffer& omxBuffer, uint32_t flags, uint64_t timestampUs, const hidl_handle& fence) {
-    // TODO implement
-    return ::android::hardware::media::omx::V1_0::Status {};
-}
-
-Return<void> OmxNode::getExtensionIndex(const hidl_string& parameterName, getExtensionIndex_cb _hidl_cb) {
-    // TODO implement
-    return Void();
-}
-
-Return<Status> OmxNode::dispatchMessage(const Message& msg) {
-    // TODO implement
-    return ::android::hardware::media::omx::V1_0::Status {};
-}
-
-OmxNode::OmxNode(OmxNodeOwner* owner, sp<IOmxObserver> const& observer, char const* name) {
-    mLNode = new OMXNodeInstance(owner, new LWOmxObserver(observer), name);
-}
-
-}  // namespace implementation
-}  // namespace V1_0
-}  // namespace omx
-}  // namespace media
-}  // namespace hardware
-}  // namespace android
diff --git a/media/libstagefright/omx/hal/1.0/impl/OmxNode.h b/media/libstagefright/omx/hal/1.0/impl/OmxNode.h
deleted file mode 100644
index 706973e..0000000
--- a/media/libstagefright/omx/hal/1.0/impl/OmxNode.h
+++ /dev/null
@@ -1,94 +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_OMXNODE_H
-#define ANDROID_HARDWARE_MEDIA_OMX_V1_0_OMXNODE_H
-
-#include <android/hardware/media/omx/1.0/IOmxNode.h>
-#include <android/hardware/media/omx/1.0/IOmxObserver.h>
-#include <hidl/MQDescriptor.h>
-#include <hidl/Status.h>
-
-#include "../../../../include/OMXNodeInstance.h"
-
-namespace android {
-namespace hardware {
-namespace media {
-namespace omx {
-namespace V1_0 {
-namespace implementation {
-
-using ::android::hardware::media::omx::V1_0::CodecBuffer;
-using ::android::hardware::media::omx::V1_0::IOmxBufferSource;
-using ::android::hardware::media::omx::V1_0::IOmxNode;
-using ::android::hardware::media::omx::V1_0::IOmxObserver;
-using ::android::hardware::media::omx::V1_0::Message;
-using ::android::hardware::media::omx::V1_0::PortMode;
-using ::android::hardware::media::omx::V1_0::Status;
-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::OMXNodeInstance;
-using ::android::OmxNodeOwner;
-
-/**
- * Wrapper classes for conversion
- * ==============================
- *
- * Naming convention:
- * - LW = Legacy Wrapper --- It wraps a Treble object inside a legacy object.
- * - TW = Treble Wrapper --- It wraps a legacy object inside a Treble object.
- */
-
-struct OmxNode : public IOmxNode {
-    Return<Status> freeNode() override;
-    Return<Status> sendCommand(uint32_t cmd, int32_t param) override;
-    Return<void> getParameter(uint32_t index, const hidl_vec<uint8_t>& inParams, getParameter_cb _hidl_cb) override;
-    Return<Status> setParameter(uint32_t index, const hidl_vec<uint8_t>& params) override;
-    Return<void> getConfig(uint32_t index, const hidl_vec<uint8_t>& inConfig, getConfig_cb _hidl_cb) override;
-    Return<Status> setConfig(uint32_t index, const hidl_vec<uint8_t>& config) override;
-    Return<Status> setPortMode(uint32_t portIndex, PortMode mode) override;
-    Return<Status> prepareForAdaptivePlayback(uint32_t portIndex, bool enable, uint32_t maxFrameWidth, uint32_t maxFrameHeight) override;
-    Return<void> configureVideoTunnelMode(uint32_t portIndex, bool tunneled, uint32_t audioHwSync, configureVideoTunnelMode_cb _hidl_cb) override;
-    Return<void> getGraphicBufferUsage(uint32_t portIndex, getGraphicBufferUsage_cb _hidl_cb) override;
-    Return<Status> setInputSurface(const sp<IOmxBufferSource>& bufferSource) override;
-    Return<void> allocateSecureBuffer(uint32_t portIndex, uint64_t size, allocateSecureBuffer_cb _hidl_cb) override;
-    Return<void> useBuffer(uint32_t portIndex, const CodecBuffer& omxBuffer, useBuffer_cb _hidl_cb) override;
-    Return<Status> freeBuffer(uint32_t portIndex, uint32_t buffer) override;
-    Return<Status> fillBuffer(uint32_t buffer, const CodecBuffer& omxBuffer, const hidl_handle& fence) override;
-    Return<Status> emptyBuffer(uint32_t buffer, const CodecBuffer& omxBuffer, uint32_t flags, uint64_t timestampUs, const hidl_handle& fence) override;
-    Return<void> getExtensionIndex(const hidl_string& parameterName, getExtensionIndex_cb _hidl_cb) override;
-    Return<Status> dispatchMessage(const Message& msg) override;
-
-    OmxNode(OmxNodeOwner* owner, sp<IOmxObserver> const& observer, char const* name);
-protected:
-    sp<OMXNodeInstance> mLNode;
-};
-
-}  // namespace implementation
-}  // namespace V1_0
-}  // namespace omx
-}  // namespace media
-}  // namespace hardware
-}  // namespace android
-
-#endif  // ANDROID_HARDWARE_MEDIA_OMX_V1_0_OMXNODE_H
diff --git a/media/libstagefright/omx/hal/1.0/impl/WGraphicBufferSource.cpp b/media/libstagefright/omx/hal/1.0/impl/WGraphicBufferSource.cpp
index 3deb029..884e87b 100644
--- a/media/libstagefright/omx/hal/1.0/impl/WGraphicBufferSource.cpp
+++ b/media/libstagefright/omx/hal/1.0/impl/WGraphicBufferSource.cpp
@@ -125,7 +125,8 @@
 }
 
 Return<void> TWGraphicBufferSource::setStopTimeUs(int64_t stopTimeUs) {
-    return toHardwareStatus(mBase->setStopTimeUs(stopTimeUs));
+    mBase->setStopTimeUs(stopTimeUs);
+    return Void();
 }
 
 Return<void> TWGraphicBufferSource::setColorAspects(
diff --git a/media/libstagefright/omx/hal/1.0/impl/WOmxBufferProducer.cpp b/media/libstagefright/omx/hal/1.0/impl/WOmxBufferProducer.cpp
index 746a0d5..b6b9a3b 100644
--- a/media/libstagefright/omx/hal/1.0/impl/WOmxBufferProducer.cpp
+++ b/media/libstagefright/omx/hal/1.0/impl/WOmxBufferProducer.cpp
@@ -14,6 +14,10 @@
  * limitations under the License.
  */
 
+#define LOG_TAG "WOmxBufferProducer-impl"
+
+#include <android-base/logging.h>
+
 #include "WOmxBufferProducer.h"
 #include "WOmxProducerListener.h"
 #include "Conversion.h"
@@ -63,23 +67,29 @@
             width, height,
             static_cast<::android::PixelFormat>(format), usage,
             getFrameTimestamps ? &outTimestamps : nullptr);
-
     hidl_handle tFence;
-    native_handle_t* nh;
-    if (!wrapAs(&tFence, &nh, *fence)) {
-        return ::android::hardware::Status::fromExceptionCode(
-                ::android::hardware::Status::EX_BAD_PARCELABLE,
-                String8("TWOmxBufferProducer::dequeueBuffer(): "
-                "Cannot wrap Fence in hidl_handle"));
-    }
     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 ::android::hardware::Status::fromExceptionCode(
-                ::android::hardware::Status::EX_BAD_PARCELABLE,
-                String8("TWOmxBufferProducer::dequeueBuffer(): "
-                "Cannot wrap Fence in hidl_handle"));
+        return Void();
     }
 
     _hidl_cb(toStatus(status),
@@ -90,9 +100,7 @@
     if (getFrameTimestamps) {
         for (auto& nhA : nhAA) {
             for (auto& handle : nhA) {
-                if (handle != nullptr) {
-                    native_handle_delete(handle);
-                }
+                native_handle_delete(handle);
             }
         }
     }
@@ -108,16 +116,22 @@
     sp<GraphicBuffer> outBuffer;
     sp<Fence> outFence;
     status_t status = mBase->detachNextBuffer(&outBuffer, &outFence);
-
     AnwBuffer tBuffer;
-    wrapAs(&tBuffer, *outBuffer);
     hidl_handle tFence;
-    native_handle_t* nh;
-    if (!wrapAs(&tFence, &nh, *outFence)) {
-        return ::android::hardware::Status::fromExceptionCode(
-                ::android::hardware::Status::EX_BAD_PARCELABLE,
-                String8("TWOmxBufferProducer::detachNextBuffer(): "
-                "Cannot wrap Fence in hidl_handle"));
+
+    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);
@@ -131,10 +145,10 @@
     int outSlot;
     sp<GraphicBuffer> lBuffer = new GraphicBuffer();
     if (!convertTo(lBuffer.get(), buffer)) {
-        return ::android::hardware::Status::fromExceptionCode(
-                ::android::hardware::Status::EX_BAD_PARCELABLE,
-                String8("TWOmxBufferProducer::attachBuffer(): "
-                "Cannot convert AnwBuffer to GraphicBuffer"));
+        LOG(ERROR) << "TWOmxBufferProducer::attachBuffer - "
+                "Invalid input native window buffer";
+        _hidl_cb(toStatus(BAD_VALUE), -1);
+        return Void();
     }
     status_t status = mBase->attachBuffer(&outSlot, lBuffer);
 
@@ -145,38 +159,34 @@
 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)) {
-        return ::android::hardware::Status::fromExceptionCode(
-                ::android::hardware::Status::EX_BAD_PARCELABLE,
-                String8("TWOmxBufferProducer::queueBuffer(): "
-                "Cannot convert IOmxBufferProducer::QueueBufferInput "
-                "to IGraphicBufferProducer::QueueBufferInput"));
+        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);
 
-    QueueBufferOutput tOutput;
     std::vector<std::vector<native_handle_t*> > nhAA;
     if (!wrapAs(&tOutput, &nhAA, lOutput)) {
-        return ::android::hardware::Status::fromExceptionCode(
-                ::android::hardware::Status::EX_BAD_PARCELABLE,
-                String8("TWOmxBufferProducer::queueBuffer(): "
-                "Cannot wrap IGraphicBufferProducer::QueueBufferOutput "
-                "in IOmxBufferProducer::QueueBufferOutput"));
+        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) {
-            if (nh != nullptr) {
-                native_handle_delete(nh);
-            }
+            native_handle_delete(nh);
         }
     }
     return Void();
@@ -186,10 +196,9 @@
         int32_t slot, const hidl_handle& fence) {
     sp<Fence> lFence = new Fence();
     if (!convertTo(lFence.get(), fence)) {
-        return ::android::hardware::Status::fromExceptionCode(
-                ::android::hardware::Status::EX_BAD_PARCELABLE,
-                String8("TWOmxBufferProducer::cancelBuffer(): "
-                "Cannot convert hidl_handle to Fence"));
+        LOG(ERROR) << "TWOmxBufferProducer::cancelBuffer - "
+                "Invalid input fence";
+        return toStatus(BAD_VALUE);
     }
     return toStatus(mBase->cancelBuffer(static_cast<int>(slot), lFence));
 }
@@ -215,19 +224,16 @@
     QueueBufferOutput tOutput;
     std::vector<std::vector<native_handle_t*> > nhAA;
     if (!wrapAs(&tOutput, &nhAA, lOutput)) {
-        return ::android::hardware::Status::fromExceptionCode(
-                ::android::hardware::Status::EX_BAD_PARCELABLE,
-                String8("TWOmxBufferProducer::connect(): "
-                "Cannot wrap IGraphicBufferProducer::QueueBufferOutput "
-                "in IOmxBufferProducer::QueueBufferOutput"));
+        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) {
-            if (nh != nullptr) {
-                native_handle_delete(nh);
-            }
+            native_handle_delete(nh);
         }
     }
     return Void();
@@ -288,14 +294,19 @@
             &lOutBuffer, &lOutFence, lOutTransformMatrix);
 
     AnwBuffer tOutBuffer;
-    wrapAs(&tOutBuffer, *lOutBuffer);
+    if (lOutBuffer != nullptr) {
+        wrapAs(&tOutBuffer, *lOutBuffer);
+    }
     hidl_handle tOutFence;
-    native_handle_t* nh;
-    if (!wrapAs(&tOutFence, &nh, *lOutFence)) {
-        return ::android::hardware::Status::fromExceptionCode(
-                ::android::hardware::Status::EX_BAD_PARCELABLE,
-                String8("TWOmxBufferProducer::getLastQueuedBuffer(): "
-                "Cannot wrap Fence in hidl_handle"));
+    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);
 
@@ -312,19 +323,16 @@
     FrameEventHistoryDelta tDelta;
     std::vector<std::vector<native_handle_t*> > nhAA;
     if (!wrapAs(&tDelta, &nhAA, lDelta)) {
-        return ::android::hardware::Status::fromExceptionCode(
-                ::android::hardware::Status::EX_BAD_PARCELABLE,
-                String8("TWOmxBufferProducer::getFrameTimestamps(): "
-                "Cannot wrap ::android::FrameEventHistoryDelta "
-                "in FrameEventHistoryDelta"));
+        LOG(ERROR) << "TWOmxBufferProducer::getFrameTimestamps - "
+                "Invalid output frame timestamps";
+        _hidl_cb(tDelta);
+        return Void();
     }
 
     _hidl_cb(tDelta);
     for (auto& nhA : nhAA) {
         for (auto& nh : nhA) {
-            if (nh != nullptr) {
-                native_handle_delete(nh);
-            }
+            native_handle_delete(nh);
         }
     }
     return Void();
@@ -384,9 +392,13 @@
                 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;
                 }
             }));
@@ -409,9 +421,13 @@
                     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;
                 }
             }));
@@ -438,6 +454,8 @@
     IOmxBufferProducer::QueueBufferInput tInput;
     native_handle_t* nh;
     if (!wrapAs(&tInput, &nh, input)) {
+        LOG(ERROR) << "LWOmxBufferProducer::queueBuffer - "
+                "Invalid input";
         return BAD_VALUE;
     }
     status_t fnStatus;
@@ -447,6 +465,8 @@
                     IOmxBufferProducer::QueueBufferOutput const& tOutput) {
                 fnStatus = toStatusT(status);
                 if (!convertTo(output, tOutput)) {
+                    LOG(ERROR) << "LWOmxBufferProducer::queueBuffer - "
+                            "Invalid output";
                     fnStatus = fnStatus == NO_ERROR ? BAD_VALUE : fnStatus;
                 }
             }));
@@ -456,8 +476,10 @@
 
 status_t LWOmxBufferProducer::cancelBuffer(int slot, const sp<Fence>& fence) {
     hidl_handle tFence;
-    native_handle_t* nh;
-    if (!wrapAs(&tFence, &nh, *fence)) {
+    native_handle_t* nh = nullptr;
+    if ((fence == nullptr) || !wrapAs(&tFence, &nh, *fence)) {
+        LOG(ERROR) << "LWOmxBufferProducer::cancelBuffer - "
+                "Invalid input fence";
         return BAD_VALUE;
     }
 
@@ -491,6 +513,8 @@
                     IOmxBufferProducer::QueueBufferOutput const& tOutput) {
                 fnStatus = toStatusT(status);
                 if (!convertTo(output, tOutput)) {
+                    LOG(ERROR) << "LWOmxBufferProducer::connect - "
+                            "Invalid output";
                     fnStatus = fnStatus == NO_ERROR ? BAD_VALUE : fnStatus;
                 }
             }));
@@ -555,10 +579,14 @@
                 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(),
diff --git a/media/libstagefright/omx/hal/1.0/impl/WOmxBufferSource.cpp b/media/libstagefright/omx/hal/1.0/impl/WOmxBufferSource.cpp
index 1cf8bf9..803283a 100644
--- a/media/libstagefright/omx/hal/1.0/impl/WOmxBufferSource.cpp
+++ b/media/libstagefright/omx/hal/1.0/impl/WOmxBufferSource.cpp
@@ -95,8 +95,7 @@
         uint32_t buffer, hidl_handle const& fence) {
     OMXFenceParcelable fenceParcelable;
     if (!convertTo(&fenceParcelable, fence)) {
-      return ::android::hardware::Status::fromExceptionCode(
-              ::android::hardware::Status::EX_BAD_PARCELABLE);
+        return Void();
     }
     mBase->onInputBufferEmptied(int32_t(buffer), fenceParcelable);
     return Void();
diff --git a/media/libstagefright/omx/hal/1.0/impl/WOmxObserver.cpp b/media/libstagefright/omx/hal/1.0/impl/WOmxObserver.cpp
index cd5edf8..354db29 100644
--- a/media/libstagefright/omx/hal/1.0/impl/WOmxObserver.cpp
+++ b/media/libstagefright/omx/hal/1.0/impl/WOmxObserver.cpp
@@ -18,6 +18,7 @@
 
 #include <vector>
 
+#include <android-base/logging.h>
 #include <cutils/native_handle.h>
 #include <binder/Binder.h>
 
@@ -46,7 +47,7 @@
     }
     auto transResult = mBase->onMessages(tMessages);
     if (!transResult.isOk()) {
-        ALOGE("LWOmxObserver::onMessages transaction failed");
+        LOG(ERROR) << "LWOmxObserver::onMessages - Transaction failed";
     }
     for (auto& handle : handles) {
         native_handle_close(handle);
diff --git a/media/libstagefright/omx/hal/1.0/utils/Android.mk b/media/libstagefright/omx/hal/1.0/utils/Android.mk
index 729cb2e..c44ce25 100644
--- a/media/libstagefright/omx/hal/1.0/utils/Android.mk
+++ b/media/libstagefright/omx/hal/1.0/utils/Android.mk
@@ -25,6 +25,7 @@
     libcutils \
     libbinder \
     liblog \
+    libbase \
     android.hardware.media.omx@1.0 \
     android.hardware.graphics.common@1.0 \
     android.hardware.media@1.0 \
diff --git a/media/libstagefright/omx/hal/1.0/utils/Conversion.h b/media/libstagefright/omx/hal/1.0/utils/Conversion.h
index d8e1d9f..375c7f9 100644
--- a/media/libstagefright/omx/hal/1.0/utils/Conversion.h
+++ b/media/libstagefright/omx/hal/1.0/utils/Conversion.h
@@ -177,25 +177,6 @@
  */
 
 /**
- * \brief Convert `binder::Status` to `Return<void>`.
- *
- * \param[in] l The source `binder::Status`.
- * \return The corresponding `Return<void>`.
- */
-// convert: ::android::binder::Status -> Return<void>
-inline Return<void> toHardwareStatus(
-        ::android::binder::Status const& l) {
-    if (l.exceptionCode() == ::android::binder::Status::EX_SERVICE_SPECIFIC) {
-        return ::android::hardware::Status::fromServiceSpecificError(
-                l.serviceSpecificErrorCode(),
-                l.exceptionMessage());
-    }
-    return ::android::hardware::Status::fromExceptionCode(
-            l.exceptionCode(),
-            l.exceptionMessage());
-}
-
-/**
  * \brief Convert `Return<void>` to `binder::Status`.
  *
  * \param[in] t The source `Return<void>`.
diff --git a/media/libstagefright/omx/hal/1.0/utils/WGraphicBufferSource.cpp b/media/libstagefright/omx/hal/1.0/utils/WGraphicBufferSource.cpp
index 5238eb3..0ba6060 100644
--- a/media/libstagefright/omx/hal/1.0/utils/WGraphicBufferSource.cpp
+++ b/media/libstagefright/omx/hal/1.0/utils/WGraphicBufferSource.cpp
@@ -125,7 +125,8 @@
 }
 
 Return<void> TWGraphicBufferSource::setStopTimeUs(int64_t stopTimeUs) {
-    return toHardwareStatus(mBase->setStopTimeUs(stopTimeUs));
+    mBase->setStopTimeUs(stopTimeUs);
+    return Void();
 }
 
 Return<void> TWGraphicBufferSource::setColorAspects(
diff --git a/media/libstagefright/omx/hal/1.0/utils/WOmxBufferProducer.cpp b/media/libstagefright/omx/hal/1.0/utils/WOmxBufferProducer.cpp
index 7415b0e..e9a93b9 100644
--- a/media/libstagefright/omx/hal/1.0/utils/WOmxBufferProducer.cpp
+++ b/media/libstagefright/omx/hal/1.0/utils/WOmxBufferProducer.cpp
@@ -14,6 +14,10 @@
  * limitations under the License.
  */
 
+#define LOG_TAG "WOmxBufferProducer-utils"
+
+#include <android-base/logging.h>
+
 #include "WOmxBufferProducer.h"
 #include "WOmxProducerListener.h"
 #include "Conversion.h"
@@ -63,23 +67,29 @@
             width, height,
             static_cast<::android::PixelFormat>(format), usage,
             getFrameTimestamps ? &outTimestamps : nullptr);
-
     hidl_handle tFence;
-    native_handle_t* nh;
-    if (!wrapAs(&tFence, &nh, *fence)) {
-        return ::android::hardware::Status::fromExceptionCode(
-                ::android::hardware::Status::EX_BAD_PARCELABLE,
-                String8("TWOmxBufferProducer::dequeueBuffer(): "
-                "Cannot wrap Fence in hidl_handle"));
-    }
     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 ::android::hardware::Status::fromExceptionCode(
-                ::android::hardware::Status::EX_BAD_PARCELABLE,
-                String8("TWOmxBufferProducer::dequeueBuffer(): "
-                "Cannot wrap Fence in hidl_handle"));
+        return Void();
     }
 
     _hidl_cb(toStatus(status),
@@ -90,9 +100,7 @@
     if (getFrameTimestamps) {
         for (auto& nhA : nhAA) {
             for (auto& handle : nhA) {
-                if (handle != nullptr) {
-                    native_handle_delete(handle);
-                }
+                native_handle_delete(handle);
             }
         }
     }
@@ -108,16 +116,22 @@
     sp<GraphicBuffer> outBuffer;
     sp<Fence> outFence;
     status_t status = mBase->detachNextBuffer(&outBuffer, &outFence);
-
     AnwBuffer tBuffer;
-    wrapAs(&tBuffer, *outBuffer);
     hidl_handle tFence;
-    native_handle_t* nh;
-    if (!wrapAs(&tFence, &nh, *outFence)) {
-        return ::android::hardware::Status::fromExceptionCode(
-                ::android::hardware::Status::EX_BAD_PARCELABLE,
-                String8("TWOmxBufferProducer::detachNextBuffer(): "
-                "Cannot wrap Fence in hidl_handle"));
+
+    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);
@@ -131,10 +145,10 @@
     int outSlot;
     sp<GraphicBuffer> lBuffer = new GraphicBuffer();
     if (!convertTo(lBuffer.get(), buffer)) {
-        return ::android::hardware::Status::fromExceptionCode(
-                ::android::hardware::Status::EX_BAD_PARCELABLE,
-                String8("TWOmxBufferProducer::attachBuffer(): "
-                "Cannot convert AnwBuffer to GraphicBuffer"));
+        LOG(ERROR) << "TWOmxBufferProducer::attachBuffer - "
+                "Invalid input native window buffer";
+        _hidl_cb(toStatus(BAD_VALUE), -1);
+        return Void();
     }
     status_t status = mBase->attachBuffer(&outSlot, lBuffer);
 
@@ -145,38 +159,34 @@
 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)) {
-        return ::android::hardware::Status::fromExceptionCode(
-                ::android::hardware::Status::EX_BAD_PARCELABLE,
-                String8("TWOmxBufferProducer::queueBuffer(): "
-                "Cannot convert IOmxBufferProducer::QueueBufferInput "
-                "to IGraphicBufferProducer::QueueBufferInput"));
+        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);
 
-    QueueBufferOutput tOutput;
     std::vector<std::vector<native_handle_t*> > nhAA;
     if (!wrapAs(&tOutput, &nhAA, lOutput)) {
-        return ::android::hardware::Status::fromExceptionCode(
-                ::android::hardware::Status::EX_BAD_PARCELABLE,
-                String8("TWOmxBufferProducer::queueBuffer(): "
-                "Cannot wrap IGraphicBufferProducer::QueueBufferOutput "
-                "in IOmxBufferProducer::QueueBufferOutput"));
+        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) {
-            if (nh != nullptr) {
-                native_handle_delete(nh);
-            }
+            native_handle_delete(nh);
         }
     }
     return Void();
@@ -186,10 +196,9 @@
         int32_t slot, const hidl_handle& fence) {
     sp<Fence> lFence = new Fence();
     if (!convertTo(lFence.get(), fence)) {
-        return ::android::hardware::Status::fromExceptionCode(
-                ::android::hardware::Status::EX_BAD_PARCELABLE,
-                String8("TWOmxBufferProducer::cancelBuffer(): "
-                "Cannot convert hidl_handle to Fence"));
+        LOG(ERROR) << "TWOmxBufferProducer::cancelBuffer - "
+                "Invalid input fence";
+        return toStatus(BAD_VALUE);
     }
     return toStatus(mBase->cancelBuffer(static_cast<int>(slot), lFence));
 }
@@ -215,19 +224,16 @@
     QueueBufferOutput tOutput;
     std::vector<std::vector<native_handle_t*> > nhAA;
     if (!wrapAs(&tOutput, &nhAA, lOutput)) {
-        return ::android::hardware::Status::fromExceptionCode(
-                ::android::hardware::Status::EX_BAD_PARCELABLE,
-                String8("TWOmxBufferProducer::connect(): "
-                "Cannot wrap IGraphicBufferProducer::QueueBufferOutput "
-                "in IOmxBufferProducer::QueueBufferOutput"));
+        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) {
-            if (nh != nullptr) {
-                native_handle_delete(nh);
-            }
+            native_handle_delete(nh);
         }
     }
     return Void();
@@ -288,14 +294,19 @@
             &lOutBuffer, &lOutFence, lOutTransformMatrix);
 
     AnwBuffer tOutBuffer;
-    wrapAs(&tOutBuffer, *lOutBuffer);
+    if (lOutBuffer != nullptr) {
+        wrapAs(&tOutBuffer, *lOutBuffer);
+    }
     hidl_handle tOutFence;
-    native_handle_t* nh;
-    if (!wrapAs(&tOutFence, &nh, *lOutFence)) {
-        return ::android::hardware::Status::fromExceptionCode(
-                ::android::hardware::Status::EX_BAD_PARCELABLE,
-                String8("TWOmxBufferProducer::getLastQueuedBuffer(): "
-                "Cannot wrap Fence in hidl_handle"));
+    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);
 
@@ -312,19 +323,16 @@
     FrameEventHistoryDelta tDelta;
     std::vector<std::vector<native_handle_t*> > nhAA;
     if (!wrapAs(&tDelta, &nhAA, lDelta)) {
-        return ::android::hardware::Status::fromExceptionCode(
-                ::android::hardware::Status::EX_BAD_PARCELABLE,
-                String8("TWOmxBufferProducer::getFrameTimestamps(): "
-                "Cannot wrap ::android::FrameEventHistoryDelta "
-                "in FrameEventHistoryDelta"));
+        LOG(ERROR) << "TWOmxBufferProducer::getFrameTimestamps - "
+                "Invalid output frame timestamps";
+        _hidl_cb(tDelta);
+        return Void();
     }
 
     _hidl_cb(tDelta);
     for (auto& nhA : nhAA) {
         for (auto& nh : nhA) {
-            if (nh != nullptr) {
-                native_handle_delete(nh);
-            }
+            native_handle_delete(nh);
         }
     }
     return Void();
@@ -384,9 +392,13 @@
                 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;
                 }
             }));
@@ -409,9 +421,13 @@
                     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;
                 }
             }));
@@ -438,6 +454,8 @@
     IOmxBufferProducer::QueueBufferInput tInput;
     native_handle_t* nh;
     if (!wrapAs(&tInput, &nh, input)) {
+        LOG(ERROR) << "LWOmxBufferProducer::queueBuffer - "
+                "Invalid input";
         return BAD_VALUE;
     }
     status_t fnStatus;
@@ -447,6 +465,8 @@
                     IOmxBufferProducer::QueueBufferOutput const& tOutput) {
                 fnStatus = toStatusT(status);
                 if (!convertTo(output, tOutput)) {
+                    LOG(ERROR) << "LWOmxBufferProducer::queueBuffer - "
+                            "Invalid output";
                     fnStatus = fnStatus == NO_ERROR ? BAD_VALUE : fnStatus;
                 }
             }));
@@ -456,8 +476,10 @@
 
 status_t LWOmxBufferProducer::cancelBuffer(int slot, const sp<Fence>& fence) {
     hidl_handle tFence;
-    native_handle_t* nh;
-    if (!wrapAs(&tFence, &nh, *fence)) {
+    native_handle_t* nh = nullptr;
+    if ((fence == nullptr) || !wrapAs(&tFence, &nh, *fence)) {
+        LOG(ERROR) << "LWOmxBufferProducer::cancelBuffer - "
+                "Invalid input fence";
         return BAD_VALUE;
     }
 
@@ -491,6 +513,8 @@
                     IOmxBufferProducer::QueueBufferOutput const& tOutput) {
                 fnStatus = toStatusT(status);
                 if (!convertTo(output, tOutput)) {
+                    LOG(ERROR) << "LWOmxBufferProducer::connect - "
+                            "Invalid output";
                     fnStatus = fnStatus == NO_ERROR ? BAD_VALUE : fnStatus;
                 }
             }));
@@ -555,10 +579,14 @@
                 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(),
diff --git a/media/libstagefright/omx/hal/1.0/utils/WOmxBufferSource.cpp b/media/libstagefright/omx/hal/1.0/utils/WOmxBufferSource.cpp
index 7f58f78..fe565e6 100644
--- a/media/libstagefright/omx/hal/1.0/utils/WOmxBufferSource.cpp
+++ b/media/libstagefright/omx/hal/1.0/utils/WOmxBufferSource.cpp
@@ -95,8 +95,7 @@
         uint32_t buffer, hidl_handle const& fence) {
     OMXFenceParcelable fenceParcelable;
     if (!convertTo(&fenceParcelable, fence)) {
-      return ::android::hardware::Status::fromExceptionCode(
-              ::android::hardware::Status::EX_BAD_PARCELABLE);
+        return Void();
     }
     mBase->onInputBufferEmptied(int32_t(buffer), fenceParcelable);
     return Void();
diff --git a/media/libstagefright/omx/hal/1.0/utils/WOmxObserver.cpp b/media/libstagefright/omx/hal/1.0/utils/WOmxObserver.cpp
index 113c342..05ec37e 100644
--- a/media/libstagefright/omx/hal/1.0/utils/WOmxObserver.cpp
+++ b/media/libstagefright/omx/hal/1.0/utils/WOmxObserver.cpp
@@ -18,6 +18,7 @@
 
 #include <vector>
 
+#include <android-base/logging.h>
 #include <cutils/native_handle.h>
 #include <binder/Binder.h>
 
@@ -46,7 +47,7 @@
     }
     auto transResult = mBase->onMessages(tMessages);
     if (!transResult.isOk()) {
-        ALOGE("LWOmxObserver::onMessages transaction failed");
+        LOG(ERROR) << "LWOmxObserver::onMessages - Transaction failed";
     }
     for (auto& handle : handles) {
         native_handle_close(handle);