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

Commit e5a1a62e authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes I4e0bd3c3,Ic62acf3a

* changes:
  Revert "Revert "Allow empty IOmxStore implementation""
  Remove dependency on non-Treble OMX
parents 10edfcf7 c0010ab1
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -10,7 +10,7 @@ LOCAL_SRC_FILES:= \
LOCAL_SHARED_LIBRARIES := \
        libstagefright libmedia libmedia_omx libmediaextractor libutils libbinder \
        libstagefright_foundation libjpeg libui libgui libcutils liblog \
        libhidlmemory \
        libhidlbase \
        android.hardware.media.omx@1.0 \

LOCAL_C_INCLUDES:= \
+18 −33
Original line number Diff line number Diff line
@@ -36,7 +36,6 @@
#include <media/MediaSource.h>
#include <media/ICrypto.h>
#include <media/IMediaHTTPService.h>
#include <media/IMediaCodecService.h>
#include <media/IMediaPlayerService.h>
#include <media/stagefright/foundation/ABuffer.h>
#include <media/stagefright/foundation/ALooper.h>
@@ -68,7 +67,6 @@
#include <gui/SurfaceComposerClient.h>

#include <android/hardware/media/omx/1.0/IOmx.h>
#include <media/omx/1.0/WOmx.h>

using namespace android;

@@ -912,37 +910,24 @@ int main(int argc, char **argv) {
    }

    if (listComponents) {
        sp<IOMX> omx;
        if (property_get_bool("persist.media.treble_omx", true)) {
        using ::android::hardware::hidl_vec;
        using ::android::hardware::hidl_string;
        using namespace ::android::hardware::media::omx::V1_0;
            sp<IOmx> tOmx = IOmx::getService();
        sp<IOmx> omx = IOmx::getService();
        CHECK(omx.get() != nullptr);

            CHECK(tOmx.get() != NULL);

            omx = new utils::LWOmx(tOmx);
        } else {
            sp<IServiceManager> sm = defaultServiceManager();
            sp<IBinder> binder = sm->getService(String16("media.codec"));
            sp<IMediaCodecService> service = interface_cast<IMediaCodecService>(binder);

            CHECK(service.get() != NULL);

            omx = service->getOMX();
        hidl_vec<IOmx::ComponentInfo> nodeList;
        auto transStatus = omx->listNodes([](
                const auto& status, const auto& nodeList) {
                    CHECK(status == Status::OK);
                    for (const auto& info : nodeList) {
                        printf("%s\t Roles: ", info.mName.c_str());
                        for (const auto& role : info.mRoles) {
                            printf("%s\t", role.c_str());
                        }
        CHECK(omx.get() != NULL);

        List<IOMX::ComponentInfo> list;
        omx->listNodes(&list);

        for (List<IOMX::ComponentInfo>::iterator it = list.begin();
             it != list.end(); ++it) {
            printf("%s\t Roles: ", (*it).mName.string());
            for (List<String8>::iterator itRoles = (*it).mRoles.begin() ;
                    itRoles != (*it).mRoles.end() ; ++itRoles) {
                printf("%s\t", (*itRoles).string());
            }
            printf("\n");
                    }
                });
        CHECK(transStatus.isOk());
    }

    sp<SurfaceComposerClient> composerClient;
+0 −2
Original line number Diff line number Diff line
@@ -45,9 +45,7 @@ cc_library_shared {
        "aidl/android/IOMXBufferSource.aidl",

        "IMediaCodecList.cpp",
        "IMediaCodecService.cpp",
        "IOMX.cpp",
        "IOMXStore.cpp",
        "MediaCodecBuffer.cpp",
        "MediaCodecInfo.cpp",
        "OMXBuffer.cpp",
+0 −86
Original line number Diff line number Diff line
/*
**
** Copyright 2015, 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 "IMediaCodecService"
//#define LOG_NDEBUG 0

#include <utils/Log.h>
#include <stdint.h>
#include <sys/types.h>
#include <binder/Parcel.h>
#include <media/IMediaCodecService.h>

namespace android {

enum {
    GET_OMX = IBinder::FIRST_CALL_TRANSACTION,
    GET_OMX_STORE
};

class BpMediaCodecService : public BpInterface<IMediaCodecService>
{
public:
    explicit BpMediaCodecService(const sp<IBinder>& impl)
        : BpInterface<IMediaCodecService>(impl)
    {
    }

    virtual sp<IOMX> getOMX() {
        Parcel data, reply;
        data.writeInterfaceToken(IMediaCodecService::getInterfaceDescriptor());
        remote()->transact(GET_OMX, data, &reply);
        return interface_cast<IOMX>(reply.readStrongBinder());
    }

    virtual sp<IOMXStore> getOMXStore() {
        Parcel data, reply;
        data.writeInterfaceToken(IMediaCodecService::getInterfaceDescriptor());
        remote()->transact(GET_OMX_STORE, data, &reply);
        return interface_cast<IOMXStore>(reply.readStrongBinder());
    }

};

IMPLEMENT_META_INTERFACE(MediaCodecService, "android.media.IMediaCodecService");

// ----------------------------------------------------------------------

status_t BnMediaCodecService::onTransact(
    uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
{
    switch (code) {

        case GET_OMX: {
            CHECK_INTERFACE(IMediaCodecService, data, reply);
            sp<IOMX> omx = getOMX();
            reply->writeStrongBinder(IInterface::asBinder(omx));
            return NO_ERROR;
        }
        case GET_OMX_STORE: {
            CHECK_INTERFACE(IMediaCodecService, data, reply);
            sp<IOMXStore> omxStore = getOMXStore();
            reply->writeStrongBinder(IInterface::asBinder(omxStore));
            return NO_ERROR;
        }
        default:
            return BBinder::onTransact(code, data, reply, flags);
    }
}

// ----------------------------------------------------------------------------

} // namespace android

media/libmedia/IOMXStore.cpp

deleted100644 → 0
+0 −367
Original line number Diff line number Diff line
/*
 * Copyright (c) 2009 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_NDEBUG 0
#define LOG_TAG "IOMXStore"

#include <utils/Log.h>

#include <media/IOMX.h>
#include <media/IOMXStore.h>
#include <android/hardware/media/omx/1.0/IOmxStore.h>

#include <binder/IInterface.h>
#include <binder/IBinder.h>
#include <binder/Parcel.h>

#include <vector>
#include <string>

namespace android {

namespace {

enum {
    CONNECT = IBinder::FIRST_CALL_TRANSACTION,
    LIST_SERVICE_ATTRIBUTES,
    GET_NODE_PREFIX,
    LIST_ROLES,
    GET_OMX,
};

// Forward declarations of std::vector<T> <-> Parcel conversion funcitons that
// depend on writeToParcel() and readToParcel() for T <-> Parcel.

template <typename T>
status_t writeToParcel(const std::vector<T>& v, Parcel* p);

template <typename T>
status_t readFromParcel(std::vector<T>* v, const Parcel& p);

// std::string <-> Parcel

status_t writeToParcel(const std::string& s, Parcel* p) {
    if (s.size() > INT32_MAX) {
        return BAD_VALUE;
    }
    return p->writeByteArray(
            s.size(), reinterpret_cast<const uint8_t*>(s.c_str()));
}

status_t readFromParcel(std::string* s, const Parcel& p) {
    int32_t len;
    status_t status = p.readInt32(&len);
    if (status != NO_ERROR) {
        return status;
    } else if ((len < 0) || (static_cast<uint64_t>(len) > SIZE_MAX)) {
        return BAD_VALUE;
    }
    s->resize(len);
    if (len == 0) {
        return NO_ERROR;
    }
    return p.read(static_cast<void*>(&s->front()), static_cast<size_t>(len));
}

// IOMXStore::Attribute <-> Parcel

status_t writeToParcel(const IOMXStore::Attribute& a, Parcel* p) {
    status_t status = writeToParcel(a.key, p);
    if (status != NO_ERROR) {
        return status;
    }
    return writeToParcel(a.value, p);
}

status_t readFromParcel(IOMXStore::Attribute* a, const Parcel& p) {
    status_t status = readFromParcel(&(a->key), p);
    if (status != NO_ERROR) {
        return status;
    }
    return readFromParcel(&(a->value), p);
}

// IOMXStore::NodeInfo <-> Parcel

status_t writeToParcel(const IOMXStore::NodeInfo& n, Parcel* p) {
    status_t status = writeToParcel(n.name, p);
    if (status != NO_ERROR) {
        return status;
    }
    status = writeToParcel(n.owner, p);
    if (status != NO_ERROR) {
        return status;
    }
    return writeToParcel(n.attributes, p);
}

status_t readFromParcel(IOMXStore::NodeInfo* n, const Parcel& p) {
    status_t status = readFromParcel(&(n->name), p);
    if (status != NO_ERROR) {
        return status;
    }
    status = readFromParcel(&(n->owner), p);
    if (status != NO_ERROR) {
        return status;
    }
    return readFromParcel(&(n->attributes), p);
}

// IOMXStore::RoleInfo <-> Parcel

status_t writeToParcel(const IOMXStore::RoleInfo& r, Parcel* p) {
    status_t status = writeToParcel(r.role, p);
    if (status != NO_ERROR) {
        return status;
    }
    status = writeToParcel(r.type, p);
    if (status != NO_ERROR) {
        return status;
    }
    status = p->writeBool(r.isEncoder);
    if (status != NO_ERROR) {
        return status;
    }
    status = p->writeBool(r.preferPlatformNodes);
    if (status != NO_ERROR) {
        return status;
    }
    return writeToParcel(r.nodes, p);
}

status_t readFromParcel(IOMXStore::RoleInfo* r, const Parcel& p) {
    status_t status = readFromParcel(&(r->role), p);
    if (status != NO_ERROR) {
        return status;
    }
    status = readFromParcel(&(r->type), p);
    if (status != NO_ERROR) {
        return status;
    }
    status = p.readBool(&(r->isEncoder));
    if (status != NO_ERROR) {
        return status;
    }
    status = p.readBool(&(r->preferPlatformNodes));
    if (status != NO_ERROR) {
        return status;
    }
    return readFromParcel(&(r->nodes), p);
}

// std::vector<NodeInfo> <-> Parcel
// std::vector<RoleInfo> <-> Parcel

template <typename T>
status_t writeToParcel(const std::vector<T>& v, Parcel* p) {
    status_t status = p->writeVectorSize(v);
    if (status != NO_ERROR) {
        return status;
    }
    for (const T& x : v) {
        status = writeToParcel(x, p);
        if (status != NO_ERROR) {
            return status;
        }
    }
    return NO_ERROR;
}

template <typename T>
status_t readFromParcel(std::vector<T>* v, const Parcel& p) {
    status_t status = p.resizeOutVector(v);
    if (status != NO_ERROR) {
        return status;
    }
    for (T& x : *v) {
        status = readFromParcel(&x, p);
        if (status != NO_ERROR) {
            return status;
        }
    }
    return NO_ERROR;
}

} // unnamed namespace

////////////////////////////////////////////////////////////////////////////////

class BpOMXStore : public BpInterface<IOMXStore> {
public:
    explicit BpOMXStore(const sp<IBinder> &impl)
        : BpInterface<IOMXStore>(impl) {
    }

    status_t listServiceAttributes(
            std::vector<Attribute>* attributes) override {
        Parcel data, reply;
        status_t status;
        status = data.writeInterfaceToken(IOMXStore::getInterfaceDescriptor());
        if (status != NO_ERROR) {
            return status;
        }
        status = remote()->transact(LIST_SERVICE_ATTRIBUTES, data, &reply);
        if (status != NO_ERROR) {
            return status;
        }
        return readFromParcel(attributes, reply);
    }

    status_t getNodePrefix(std::string* prefix) override {
        Parcel data, reply;
        status_t status;
        status = data.writeInterfaceToken(IOMXStore::getInterfaceDescriptor());
        if (status != NO_ERROR) {
            return status;
        }
        status = remote()->transact(GET_NODE_PREFIX, data, &reply);
        if (status != NO_ERROR) {
            return status;
        }
        return readFromParcel(prefix, reply);
    }

    status_t listRoles(std::vector<RoleInfo>* roleList) override {
        Parcel data, reply;
        status_t status;
        status = data.writeInterfaceToken(IOMXStore::getInterfaceDescriptor());
        if (status != NO_ERROR) {
            return status;
        }
        status = remote()->transact(LIST_ROLES, data, &reply);
        if (status != NO_ERROR) {
            return status;
        }
        return readFromParcel(roleList, reply);
    }

    status_t getOmx(const std::string& name, sp<IOMX>* omx) override {
        Parcel data, reply;
        status_t status;
        status = data.writeInterfaceToken(IOMXStore::getInterfaceDescriptor());
        if (status != NO_ERROR) {
            return status;
        }
        status = writeToParcel(name, &data);
        if (status != NO_ERROR) {
            return status;
        }
        status = remote()->transact(GET_OMX, data, &reply);
        if (status != NO_ERROR) {
            return status;
        }
        return reply.readStrongBinder(omx);
    }

};

IMPLEMENT_META_INTERFACE(OMXStore, "android.hardware.IOMXStore");

////////////////////////////////////////////////////////////////////////////////

#define CHECK_OMX_INTERFACE(interface, data, reply) \
        do { if (!(data).enforceInterface(interface::getInterfaceDescriptor())) { \
            ALOGW("Call incorrectly routed to " #interface); \
            return PERMISSION_DENIED; \
        } } while (0)

status_t BnOMXStore::onTransact(
    uint32_t code, const Parcel &data, Parcel *reply, uint32_t flags) {
    switch (code) {
        case LIST_SERVICE_ATTRIBUTES: {
            CHECK_OMX_INTERFACE(IOMXStore, data, reply);
            status_t status;
            std::vector<Attribute> attributes;

            status = listServiceAttributes(&attributes);
            if (status != NO_ERROR) {
                ALOGE("listServiceAttributes() fails with status %d",
                        static_cast<int>(status));
                return NO_ERROR;
            }
            status = writeToParcel(attributes, reply);
            if (status != NO_ERROR) {
                ALOGE("listServiceAttributes() fails to send reply");
                return NO_ERROR;
            }
            return NO_ERROR;
        }
        case GET_NODE_PREFIX: {
            CHECK_OMX_INTERFACE(IOMXStore, data, reply);
            status_t status;
            std::string prefix;

            status = getNodePrefix(&prefix);
            if (status != NO_ERROR) {
                ALOGE("getNodePrefix() fails with status %d",
                        static_cast<int>(status));
                return NO_ERROR;
            }
            status = writeToParcel(prefix, reply);
            if (status != NO_ERROR) {
                ALOGE("getNodePrefix() fails to send reply");
                return NO_ERROR;
            }
            return NO_ERROR;
        }
        case LIST_ROLES: {
            CHECK_OMX_INTERFACE(IOMXStore, data, reply);
            status_t status;
            std::vector<RoleInfo> roleList;

            status = listRoles(&roleList);
            if (status != NO_ERROR) {
                ALOGE("listRoles() fails with status %d",
                        static_cast<int>(status));
                return NO_ERROR;
            }
            status = writeToParcel(roleList, reply);
            if (status != NO_ERROR) {
                ALOGE("listRoles() fails to send reply");
                return NO_ERROR;
            }
            return NO_ERROR;
        }
        case GET_OMX: {
            CHECK_OMX_INTERFACE(IOMXStore, data, reply);
            status_t status;
            std::string name;
            sp<IOMX> omx;

            status = readFromParcel(&name, data);
            if (status != NO_ERROR) {
                ALOGE("getOmx() fails to retrieve name");
                return NO_ERROR;
            }
            status = getOmx(name, &omx);
            if (status != NO_ERROR) {
                ALOGE("getOmx() fails with status %d",
                        static_cast<int>(status));
                return NO_ERROR;
            }
            status = reply->writeStrongBinder(IInterface::asBinder(omx));
            if (status != NO_ERROR) {
                ALOGE("getOmx() fails to send reply");
                return NO_ERROR;
            }
            return NO_ERROR;
        }
        default:
            return BBinder::onTransact(code, data, reply, flags);
    }
}

}  // namespace android
Loading