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

Commit e8e98159 authored by Wonsik Kim's avatar Wonsik Kim
Browse files

codec2 hal: Codec2Client AIDL implementation

- Implement Codec2Client API on top of AIDL implementation
- TODO: input surface implementation is missing
- Fix libmediaplayerservice Codec2Client dependency

Bug: 251850069
Test: presubmit
Change-Id: I30c3cf24b408d20e4cae1c7e3d98bad8a7301e74
parent b96354fc
Loading
Loading
Loading
Loading
+3 −4
Original line number Diff line number Diff line
@@ -157,14 +157,13 @@ namespace media {
namespace c2 {
namespace utils {

// TODO: read it from aconfig flags
bool IsEnabled() { return false; }

const char* asString(Status status, const char* def) {
    return asString(static_cast<c2_status_t>(status.status), def);
}

namespace /* unnamed */ {

} // unnamed namespace

// C2FieldSupportedValuesQuery -> FieldSupportedValuesQuery
bool ToAidl(
        FieldSupportedValuesQuery* d,
+4 −1
Original line number Diff line number Diff line
@@ -37,11 +37,14 @@ namespace media {
namespace c2 {
namespace utils {

// Returns true iff AIDL c2 HAL is enabled
bool IsEnabled();

// Make asString() and operator<< work with Status as well as c2_status_t.
C2_DECLARE_AS_STRING_AND_DEFINE_STREAM_OUT(Status);

/**
 * All objcpy() functions will return a boolean value indicating whether the
 * All To/FromAidl() functions will return a boolean value indicating whether the
 * conversion succeeds or not.
 */

+6 −0
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ cc_library {
        "android.hardware.media.c2@1.0",
        "android.hardware.media.c2@1.1",
        "android.hardware.media.c2@1.2",
        "android.hardware.media.bufferpool2-V1-ndk",
        "android.hardware.media.c2-V1-ndk",
        "libbase",
        "libbinder",
@@ -56,11 +57,16 @@ cc_library {
        "libhidlbase",
        "liblog",
        "libnativewindow",
        "libstagefright_aidl_bufferpool2",
        "libstagefright_bufferpool@2.0.1",
        "libui",
        "libutils",
    ],

    static_libs: [
        "libaidlcommonsupport",
    ],

    export_include_dirs: [
        "include",
    ],
+646 −203

File changed.

Preview size limit exceeded, changes collapsed.

+60 −35
Original line number Diff line number Diff line
@@ -95,6 +95,11 @@ namespace android::hardware::media::bufferpool::V2_0 {
struct IClientManager;
}  // namespace android::hardware::media::bufferpool::V2_0

namespace aidl::android::hardware::media::bufferpool2 {
class IClientManager;
}  // namespace aidl::android::hardware::media::c2


namespace android::hardware::graphics::bufferqueue::V1_0 {
struct IGraphicBufferProducer;
}  // android::hardware::graphics::bufferqueue::V1_0
@@ -173,12 +178,12 @@ private:

struct Codec2Client : public Codec2ConfigurableClient {

    typedef ::android::hardware::media::c2::V1_0::IComponentStore Base1_0;
    typedef ::android::hardware::media::c2::V1_1::IComponentStore Base1_1;
    typedef ::android::hardware::media::c2::V1_2::IComponentStore Base1_2;
    typedef Base1_0 Base;
    typedef ::android::hardware::media::c2::V1_0::IComponentStore HidlBase1_0;
    typedef ::android::hardware::media::c2::V1_1::IComponentStore HidlBase1_1;
    typedef ::android::hardware::media::c2::V1_2::IComponentStore HidlBase1_2;
    typedef HidlBase1_0 HidlBase;

    typedef ::android::hardware::media::c2::V1_0::IConfigurable IConfigurable;
    typedef ::aidl::android::hardware::media::c2::IComponentStore AidlBase;

    struct Listener;

@@ -194,10 +199,11 @@ struct Codec2Client : public Codec2ConfigurableClient {

    typedef Codec2Client Store;

    sp<Base> const& getBase() const;
    sp<Base1_0> const& getBase1_0() const;
    sp<Base1_1> const& getBase1_1() const;
    sp<Base1_2> const& getBase1_2() const;
    sp<HidlBase> const& getHidlBase() const;
    sp<HidlBase1_0> const& getHidlBase1_0() const;
    sp<HidlBase1_1> const& getHidlBase1_1() const;
    sp<HidlBase1_2> const& getHidlBase1_2() const;
    ::ndk::SpAIBinder getAidlBase() const;

    std::string const& getServiceName() const;

@@ -266,14 +272,19 @@ struct Codec2Client : public Codec2ConfigurableClient {

    // base and/or configurable cannot be null.
    Codec2Client(
            sp<Base> const& base,
            sp<IConfigurable> const& configurable,
            sp<HidlBase> const& base,
            sp<Codec2ConfigurableClient::HidlBase> const& configurable,
            size_t serviceIndex);
    Codec2Client(
            std::shared_ptr<AidlBase> const& base,
            std::shared_ptr<Codec2ConfigurableClient::AidlBase> const& configurable,
            size_t serviceIndex);

protected:
    sp<Base1_0> mBase1_0;
    sp<Base1_1> mBase1_1;
    sp<Base1_2> mBase1_2;
    sp<HidlBase1_0> mHidlBase1_0;
    sp<HidlBase1_1> mHidlBase1_1;
    sp<HidlBase1_2> mHidlBase1_2;
    std::shared_ptr<AidlBase> mAidlBase;

    // Finds the first store where the predicate returns C2_OK and returns the
    // last predicate result. The predicate will be tried on all stores. The
@@ -301,8 +312,11 @@ protected:
    mutable std::vector<C2Component::Traits> mTraitsList;

    sp<::android::hardware::media::bufferpool::V2_0::IClientManager>
            mHostPoolManager;
            mHidlHostPoolManager;
    std::shared_ptr<::aidl::android::hardware::media::bufferpool2::IClientManager>
            mAidlHostPoolManager;

    static std::vector<std::string> CacheServiceNames();
    static std::shared_ptr<Codec2Client> _CreateFromIndex(size_t index);

    std::vector<C2Component::Traits> _listComponents(bool* success) const;
@@ -312,12 +326,15 @@ protected:

struct Codec2Client::Interface : public Codec2Client::Configurable {

    typedef ::android::hardware::media::c2::V1_0::IComponentInterface Base;
    typedef ::android::hardware::media::c2::V1_0::IComponentInterface HidlBase;
    typedef ::aidl::android::hardware::media::c2::IComponentInterface AidlBase;

    Interface(const sp<Base>& base);
    Interface(const sp<HidlBase>& base);
    Interface(const std::shared_ptr<AidlBase>& base);

protected:
    sp<Base> mBase;
    sp<HidlBase> mHidlBase;
    std::shared_ptr<AidlBase> mAidlBase;
};

struct Codec2Client::Listener {
@@ -356,16 +373,17 @@ struct Codec2Client::Listener {
            int32_t slotId,
            int64_t timestampNs) = 0;

    virtual ~Listener();

    virtual ~Listener() = default;
};

struct Codec2Client::Component : public Codec2Client::Configurable {

    typedef ::android::hardware::media::c2::V1_0::IComponent Base1_0;
    typedef ::android::hardware::media::c2::V1_1::IComponent Base1_1;
    typedef ::android::hardware::media::c2::V1_2::IComponent Base1_2;
    typedef Base1_0 Base;
    typedef ::android::hardware::media::c2::V1_0::IComponent HidlBase1_0;
    typedef ::android::hardware::media::c2::V1_1::IComponent HidlBase1_1;
    typedef ::android::hardware::media::c2::V1_2::IComponent HidlBase1_2;
    typedef HidlBase1_0 HidlBase;

    typedef ::aidl::android::hardware::media::c2::IComponent AidlBase;

    c2_status_t createBlockPool(
            C2Allocator::id_t id,
@@ -469,19 +487,23 @@ struct Codec2Client::Component : public Codec2Client::Configurable {
    c2_status_t disconnectFromInputSurface();

    // base cannot be null.
    Component(const sp<Base>& base);
    Component(const sp<Base1_1>& base);
    Component(const sp<Base1_2>& base);
    Component(const sp<HidlBase>& base);
    Component(const sp<HidlBase1_1>& base);
    Component(const sp<HidlBase1_2>& base);
    Component(const std::shared_ptr<AidlBase>& base);

    ~Component();

protected:
    sp<Base1_0> mBase1_0;
    sp<Base1_1> mBase1_1;
    sp<Base1_2> mBase1_2;
    sp<HidlBase1_0> mHidlBase1_0;
    sp<HidlBase1_1> mHidlBase1_1;
    sp<HidlBase1_2> mHidlBase1_2;
    std::shared_ptr<AidlBase> mAidlBase;

    struct BufferPoolSender;
    std::unique_ptr<BufferPoolSender> mBufferPoolSender;
    struct HidlBufferPoolSender;
    struct AidlBufferPoolSender;
    std::unique_ptr<HidlBufferPoolSender> mHidlBufferPoolSender;
    std::unique_ptr<AidlBufferPoolSender> mAidlBufferPoolSender;

    struct OutputBufferQueue;
    std::unique_ptr<OutputBufferQueue> mOutputBufferQueue;
@@ -491,6 +513,10 @@ protected:
    // In order to prevent the race condition mutex is added.
    std::mutex mOutputMutex;

    class AidlDeathManager;
    static AidlDeathManager *GetAidlDeathManager();
    std::optional<size_t> mAidlDeathSeq;

    static c2_status_t setDeathListener(
            const std::shared_ptr<Component>& component,
            const std::shared_ptr<Listener>& listener);
@@ -499,16 +525,15 @@ protected:
    friend struct Codec2Client;

    struct HidlListener;
    struct AidlListener;
    void handleOnWorkDone(const std::list<std::unique_ptr<C2Work>> &workItems);

};

struct Codec2Client::InputSurface : public Codec2Client::Configurable {
public:
    typedef ::android::hardware::media::c2::V1_0::IInputSurface Base;

    typedef ::android::hardware::media::c2::V1_0::IInputSurfaceConnection
            ConnectionBase;
    typedef ::android::hardware::media::c2::V1_0::IInputSurfaceConnection ConnectionBase;

    typedef Codec2Client::InputSurfaceConnection Connection;

Loading