Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 223b8e36 authored by Pawin Vongmasa's avatar Pawin Vongmasa
Browse files

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
parent 0d3a5edf
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -11,7 +11,6 @@ LOCAL_SRC_FILES := \
    WOmxObserver.cpp \
    WOmxProducerListener.cpp \
    Omx.cpp \
    OmxNode.cpp \

LOCAL_SHARED_LIBRARIES := \
    libmedia \
@@ -27,6 +26,7 @@ LOCAL_SHARED_LIBRARIES := \
    libcutils \
    libbinder \
    liblog \
    libbase \
    android.hardware.media.omx@1.0 \
    android.hardware.graphics.common@1.0 \
    android.hardware.media@1.0 \
+0 −19
Original line number Diff line number Diff line
@@ -176,25 +176,6 @@ inline int native_handle_read_fd(native_handle_t const* nh, int index = 0) {
 * `convertTo()` do.
 */

/**
 * \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`.
 *
+10 −6
Original line number Diff line number Diff line
@@ -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 @@ Return<void> Omx::allocateNode(
            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 @@ Return<void> Omx::createInputSurface(createInputSurface_cb _hidl_cb) {
    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 @@ void Omx::serviceDied(uint64_t /* cookie */, wp<IBase> const& who) {
        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;
        }
+0 −129
Original line number Diff line number Diff line
/*
 * 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
+0 −94
Original line number Diff line number Diff line
/*
 * 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
Loading