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

Commit c638dfa1 authored by Lajos Molnar's avatar Lajos Molnar
Browse files

Codec2: Finalize C2Component APIs and add C2ComponentFactory

- rename getXYZ methods that are not strictly getters
- add override to all virtual overrides
- rename integral C2 types to lower case with _t suffix
  (e.g. c2_status_t and c2_node_id_t)
- rename C2ComponentInfo and C2Allocator::Info to Traits
- add missing configuration API members to C2ComponentStore
- add _nb/_sm markers to work and configuration methods
- replace flags for drain/flush with enums
- add C2Component::setListener_sm
- use C2ComponentFactory to create component in codec2 cmd

Bug: 64121714
Test: unittest
Change-Id: I98ce71a9de23c7ff5ed7abc4d48822d0bfa6a29e
parent b6549b62
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -66,7 +66,7 @@ enum {
 * mitigate binary breaks by adhering to the following conventions:
 *
 * - at most one vtable with placeholder virtual methods
 * - all optional/placeholder virtual methods returning a C2Status, with C2_OMITTED not requiring
 * - all optional/placeholder virtual methods returning a c2_status_t, with C2_OMITTED not requiring
 *   any update to input/output arguments.
 * - limiting symbol export of inline methods
 * - use of pimpl (or shared-pimpl)
@@ -106,9 +106,9 @@ typedef std::string C2String;
typedef const char *C2StringLiteral;

/**
 * C2Status: status codes used.
 * c2_status_t: status codes used.
 */
enum C2Status : int32_t {
enum c2_status_t : int32_t {

/*
 * Use android status constants if available. Otherwise, define the android status constants as
+41 −37
Original line number Diff line number Diff line
@@ -91,7 +91,7 @@ public:
     * \retval C2_REFUSED       no permission to wait for the fence (unexpected - system)
     * \retval C2_CORRUPTED     some unknown error prevented waiting for the fence (unexpected)
     */
    C2Status wait(nsecs_t timeoutNs);
    c2_status_t wait(nsecs_t timeoutNs);

    /**
     * Used to check if this fence is valid (if there is a chance for it to be signaled.)
@@ -158,7 +158,7 @@ public:
     * \retval C2_REFUSED       no permission to signal the fence (unexpected - system)
     * \retval C2_CORRUPTED     some unknown error prevented signaling the fence(s) (unexpected)
     */
    C2Status fire();
    c2_status_t fire();

    /**
     * Trigger this event from the merging of the supplied fences. This means that it will be
@@ -172,7 +172,7 @@ public:
     * \retval C2_REFUSED       no permission to merge the fence (unexpected - system)
     * \retval C2_CORRUPTED     some unknown error prevented merging the fence(s) (unexpected)
     */
    C2Status merge(std::vector<C2Fence> fences);
    c2_status_t merge(std::vector<C2Fence> fences);

    /**
     * Abandons the event and any associated fence(s).
@@ -186,7 +186,7 @@ public:
     * \retval C2_REFUSED       no permission to abandon the fence (unexpected - system)
     * \retval C2_CORRUPTED     some unknown error prevented signaling the fence(s) (unexpected)
     */
    C2Status abandon();
    c2_status_t abandon();

private:
    class Impl;
@@ -200,12 +200,12 @@ private:
 * Interface for objects that encapsulate an updatable status value.
 */
struct _C2InnateStatus {
    inline C2Status status() const { return mStatus; }
    inline c2_status_t status() const { return mStatus; }

protected:
    _C2InnateStatus(C2Status status) : mStatus(status) { }
    _C2InnateStatus(c2_status_t status) : mStatus(status) { }

    C2Status mStatus; // this status is updatable by the object
    c2_status_t mStatus; // this status is updatable by the object
};

/// @}
@@ -230,10 +230,10 @@ public:
    }

protected:
    C2Acquirable(C2Status error, C2Fence fence, T t) : C2Fence(fence), mInitialError(error), mT(t) { }
    C2Acquirable(c2_status_t error, C2Fence fence, T t) : C2Fence(fence), mInitialError(error), mT(t) { }

private:
    C2Status mInitialError;
    c2_status_t mInitialError;
    T mT; // TODO: move instead of copy
};

@@ -449,11 +449,11 @@ public:
    /**
     * \return error during the creation/mapping of this view.
     */
    C2Status error() const;
    c2_status_t error() const;

protected:
    C2ReadView(const _C2LinearCapacityAspect *parent, const uint8_t *data);
    explicit C2ReadView(C2Status error);
    explicit C2ReadView(c2_status_t error);

private:
    class Impl;
@@ -482,11 +482,11 @@ public:
    /**
     * \return error during the creation/mapping of this view.
     */
    C2Status error() const;
    c2_status_t error() const;

protected:
    C2WriteView(const _C2LinearRangeAspect *parent, uint8_t *base);
    explicit C2WriteView(C2Status error);
    explicit C2WriteView(c2_status_t error);

private:
    class Impl;
@@ -631,7 +631,7 @@ public:
     * \retval C2_TIMED_OUT     the reservation timed out \todo when?
     * \retval C2_CORRUPTED     some unknown error prevented reserving space. (unexpected)
     */
    C2Status reserve(size_t size, C2Fence *fence /* nullable */);
    c2_status_t reserve(size_t size, C2Fence *fence /* nullable */);

    /**
     * Abandons a portion of this segment. This will move to the beginning of this segment.
@@ -644,7 +644,7 @@ public:
     * \retval C2_TIMED_OUT     the operation timed out (unexpected)
     * \retval C2_CORRUPTED     some unknown error prevented abandoning the data (unexpected)
     */
    C2Status abandon(size_t size);
    c2_status_t abandon(size_t size);

    /**
     * Share a portion as block(s) with consumers (these are moved to the used section).
@@ -661,7 +661,7 @@ public:
     * \retval C2_TIMED_OUT     the operation timed out (unexpected)
     * \retval C2_CORRUPTED     some unknown error prevented sharing the data (unexpected)
     */
    C2Status share(size_t size, C2Fence fence, std::list<C2ConstLinearBlock> &blocks);
    c2_status_t share(size_t size, C2Fence fence, std::list<C2ConstLinearBlock> &blocks);

    /**
     * Returns the beginning offset of this segment from the start of this circular block.
@@ -695,7 +695,7 @@ public:
    /**
     * \return error during the creation/mapping of this view.
     */
    C2Status error() const;
    c2_status_t error() const;
};

/**
@@ -716,7 +716,7 @@ public:
     * \param size    number of bytes to commit to the next segment
     * \param fence   fence used for the commit (the fence must signal before the data is committed)
     */
    C2Status commit(size_t size, C2Fence fence);
    c2_status_t commit(size_t size, C2Fence fence);

    /**
     * Maps this block into memory and returns a write view for it.
@@ -1016,14 +1016,14 @@ public:
    /**
     * \return error during the creation/mapping of this view.
     */
    C2Status error() const;
    c2_status_t error() const;

protected:
    C2GraphicView(
            const _C2PlanarCapacityAspect *parent,
            uint8_t *const *data,
            const C2PlaneLayout& layout);
    explicit C2GraphicView(C2Status error);
    explicit C2GraphicView(c2_status_t error);

private:
    class Impl;
@@ -1224,7 +1224,7 @@ public:
     * \retval C2_NO_MEMORY not enough memory to register for this callback
     * \retval C2_CORRUPTED an unknown error prevented the registration (unexpected)
     */
    C2Status registerOnDestroyNotify(OnDestroyNotify onDestroyNotify, void *arg = nullptr);
    c2_status_t registerOnDestroyNotify(OnDestroyNotify onDestroyNotify, void *arg = nullptr);

    /**
     * Unregisters a previously registered pre-destroy notification.
@@ -1236,7 +1236,7 @@ public:
     * \retval C2_NOT_FOUND the notification was not found
     * \retval C2_CORRUPTED an unknown error prevented the registration (unexpected)
     */
    C2Status unregisterOnDestroyNotify(OnDestroyNotify onDestroyNotify, void *arg = nullptr);
    c2_status_t unregisterOnDestroyNotify(OnDestroyNotify onDestroyNotify, void *arg = nullptr);

    ///@}

@@ -1262,7 +1262,7 @@ public:
     * \retval C2_NO_MEMORY not enough memory to attach the metadata (this return value is not
     *                      used if the same kind of metadata is already attached to the buffer).
     */
    C2Status setInfo(const std::shared_ptr<C2Info> &info);
    c2_status_t setInfo(const std::shared_ptr<C2Info> &info);

    /**
     * Checks if there is a certain type of metadata attached to this buffer.
@@ -1385,7 +1385,7 @@ public:
     *                      the usage flags are invalid (caller error)
     * \retval C2_CORRUPTED some unknown error prevented the operation from completing (unexpected)
     */
    virtual C2Status map(
    virtual c2_status_t map(
            size_t offset, size_t size, C2MemoryUsage usage, int *fenceFd /* nullable */,
            void **addr /* nonnull */) = 0;

@@ -1409,7 +1409,7 @@ public:
     * \retval C2_CORRUPTED some unknown error prevented the operation from completing (unexpected)
     * \retval C2_REFUSED   no permission to unmap the portion (unexpected - system)
     */
    virtual C2Status unmap(void *addr, size_t size, int *fenceFd /* nullable */) = 0;
    virtual c2_status_t unmap(void *addr, size_t size, int *fenceFd /* nullable */) = 0;

    /**
     * Returns true if this is a valid allocation.
@@ -1472,7 +1472,7 @@ public:
     * \retval C2_CORRUPTED some unknown error prevented the operation from completing (unexpected)

     */
    virtual C2Status map(
    virtual c2_status_t map(
            C2Rect rect, C2MemoryUsage usage, int *fenceFd,
            // TODO: return <addr, size> buffers with plane sizes
            C2PlaneLayout *layout /* nonnull */, uint8_t **addr /* nonnull */) = 0;
@@ -1492,7 +1492,7 @@ public:
     * \retval C2_CORRUPTED some unknown error prevented the operation from completing (unexpected)
     * \retval C2_REFUSED   no permission to unmap the section (unexpected - system)
     */
    virtual C2Status unmap(C2Fence *fenceFd /* nullable */) = 0;
    virtual c2_status_t unmap(C2Fence *fenceFd /* nullable */) = 0;

    /**
     * Returns true if this is a valid allocation.
@@ -1544,8 +1544,10 @@ public:

    /**
     * Information about an allocator.
     *
     * Allocators don't have a query API so all queriable information is stored here.
     */
    struct Info {
    struct Traits {
        C2String name;              ///< allocator name
        id_t id;                    ///< allocator ID
        type_t supportedTypes;      ///< supported allocation types
@@ -1574,13 +1576,15 @@ public:
    virtual id_t getId() const = 0;

    /**
     * Returns the allocator information.
     * Returns the allocator traits.
     *
     * This method MUST be "non-blocking" and return within 1ms.
     *
     * Allocators don't have a full-fledged query API, only this method.
     *
     * \return allocator information
     */
    virtual std::shared_ptr<const Info> getInfo() const = 0;
    virtual std::shared_ptr<const Traits> getTraits() const = 0;

    /**
     * Allocates a 1D allocation of given |capacity| and |usage|. If successful, the allocation is
@@ -1604,7 +1608,7 @@ public:
     * \retval C2_OMITTED   this allocator does not support 1D allocations
     * \retval C2_CORRUPTED some unknown, unrecoverable error occured during allocation (unexpected)
     */
    virtual C2Status newLinearAllocation(
    virtual c2_status_t newLinearAllocation(
            uint32_t capacity __unused, C2MemoryUsage usage __unused,
            std::shared_ptr<C2LinearAllocation> *allocation /* nonnull */) {
        *allocation = nullptr;
@@ -1627,7 +1631,7 @@ public:
     * \retval C2_OMITTED   this allocator does not support 1D allocations
     * \retval C2_CORRUPTED some unknown, unrecoverable error occured during allocation (unexpected)
     */
    virtual C2Status priorLinearAllocation(
    virtual c2_status_t priorLinearAllocation(
            const C2Handle *handle __unused,
            std::shared_ptr<C2LinearAllocation> *allocation /* nonnull */) {
        *allocation = nullptr;
@@ -1660,7 +1664,7 @@ public:
     * \retval C2_OMITTED   this allocator does not support 2D allocations
     * \retval C2_CORRUPTED some unknown, unrecoverable error occured during allocation (unexpected)
     */
    virtual C2Status newGraphicAllocation(
    virtual c2_status_t newGraphicAllocation(
            uint32_t width __unused, uint32_t height __unused, uint32_t format __unused,
            C2MemoryUsage usage __unused,
            std::shared_ptr<C2GraphicAllocation> *allocation /* nonnull */) {
@@ -1684,7 +1688,7 @@ public:
     * \retval C2_OMITTED   this allocator does not support 2D allocations
     * \retval C2_CORRUPTED some unknown, unrecoverable error occured during recreation (unexpected)
     */
    virtual C2Status priorGraphicAllocation(
    virtual c2_status_t priorGraphicAllocation(
            const C2Handle *handle __unused,
            std::shared_ptr<C2GraphicAllocation> *allocation /* nonnull */) {
        *allocation = nullptr;
@@ -1764,7 +1768,7 @@ public:
     * \retval C2_OMITTED   this pool does not support linear blocks
     * \retval C2_CORRUPTED some unknown, unrecoverable error occured during operation (unexpected)
     */
    virtual C2Status fetchLinearBlock(
    virtual c2_status_t fetchLinearBlock(
            uint32_t capacity __unused, C2MemoryUsage usage __unused,
            std::shared_ptr<C2LinearBlock> *block /* nonnull */) {
        *block = nullptr;
@@ -1792,7 +1796,7 @@ public:
     * \retval C2_OMITTED   this pool does not support circular blocks
     * \retval C2_CORRUPTED some unknown, unrecoverable error occured during operation (unexpected)
     */
    virtual C2Status fetchCircularBlock(
    virtual c2_status_t fetchCircularBlock(
            uint32_t capacity __unused, C2MemoryUsage usage __unused,
            std::shared_ptr<C2CircularBlock> *block /* nonnull */) {
        *block = nullptr;
@@ -1823,7 +1827,7 @@ public:
     * \retval C2_OMITTED   this pool does not support 2D blocks
     * \retval C2_CORRUPTED some unknown, unrecoverable error occured during operation (unexpected)
     */
    virtual C2Status fetchGraphicBlock(
    virtual c2_status_t fetchGraphicBlock(
            uint32_t width __unused, uint32_t height __unused, uint32_t format __unused,
            C2MemoryUsage usage __unused,
            std::shared_ptr<C2GraphicBlock> *block /* nonnull */) {
+269 −97

File changed.

Preview size limit exceeded, changes collapsed.

+12 −11
Original line number Diff line number Diff line
@@ -75,14 +75,9 @@ struct C2SettingResult {
//  WORK
// ================================================================================================

// node_id-s
typedef uint32_t node_id;

enum flags_t : uint32_t {
    BUFFERFLAG_CODEC_CONFIG  = (1 << 0),
    BUFFERFLAG_DROP_FRAME    = (1 << 1),
    BUFFERFLAG_END_OF_STREAM = (1 << 2),
};
// c2_node_id_t-s
typedef uint32_t c2_node_id_t;
typedef c2_node_id_t c2_node_id_t;

enum {
    kParamIndexWorkOrdinal,
@@ -101,6 +96,12 @@ struct C2WorkOrdinalStruct {

struct C2BufferPack {
//public:
    enum flags_t : uint32_t {
        FLAG_CODEC_CONFIG  = (1 << 0),
        FLAG_DROP_FRAME    = (1 << 1),
        FLAG_END_OF_STREAM = (1 << 2),
    };

    flags_t  flags;
    C2WorkOrdinalStruct ordinal;
    std::vector<std::shared_ptr<C2Buffer>> buffers;
@@ -113,7 +114,7 @@ struct C2BufferPack {
struct C2Worklet {
//public:
    // IN
    node_id component;
    c2_node_id_t component;

    std::list<std::unique_ptr<C2Param>> tunings; //< tunings to be applied before processing this
                                                 // worklet
@@ -165,13 +166,13 @@ struct C2Work {
    std::list<std::unique_ptr<C2Worklet>> worklets;

    uint32_t worklets_processed;
    C2Status result;
    c2_status_t result;
};

struct C2WorkOutline {
//public:
    C2WorkOrdinalStruct ordinal;
    std::list<node_id> chain;
    std::list<c2_node_id_t> chain;
};

/// @}
+15 −15
Original line number Diff line number Diff line
@@ -72,7 +72,7 @@ protected:

    // If a parameter is writable this is called.
    // Test one filed |writableField| for given writable parameter |param|.
    // |validValues| contains all values obtained from getSupportedValues() for |writableField|.
    // |validValues| contains all values obtained from querySupportedValues() for |writableField|.
    // The test checks validity for config() with each value, and make sure values are config-ed
    // by query() them out. |invalidValues| contains some values which are not in |validValues|.
    // The test expects C2_BAD_VALUE while config() with these values,
@@ -112,11 +112,11 @@ private:
    // check if a component has a parameter whose type is |T|.
    // If a component has, the value should be copied into an argument, that is
    // |p| in queryOnStack() and |heapParams| in queryOnHeap().
    // The return value is C2Status (e.g. C2_OK).
    template <typename T> C2Status queryOnStack(T *const p);
    // The return value is c2_status_t (e.g. C2_OK).
    template <typename T> c2_status_t queryOnStack(T *const p);

    template <typename T>
    C2Status queryOnHeap(const T &p,
    c2_status_t queryOnHeap(const T &p,
                         std::vector<std::unique_ptr<C2Param>> *const heapParams);

    // Get a value whose type is |T| in a component. The value is copied to |param|.
@@ -139,7 +139,7 @@ private:
    // Execute an interface's config_nb(). |T| is a single parameter type, not std::vector.
    // config() creates std::vector<C2Param *const> {p} and passes it to config_nb().
    template <typename T>
    C2Status
    c2_status_t
    config(T *const p,
           std::vector<std::unique_ptr<C2SettingResult>> *const failures);

@@ -150,7 +150,7 @@ private:
    // Test if config works correctly for writable parameters.
    // This changes the parameter's value to |newParam|.
    // |stConfig| is a return value of config().
    template <typename T> void configWritableParamValidValue(const T &newParam, C2Status *stConfig);
    template <typename T> void configWritableParamValidValue(const T &newParam, c2_status_t *stConfig);

    // Test if config works correctly in the case an invalid value |newParam| is tried to write
    // to an writable parameter.
@@ -194,13 +194,13 @@ template <> std::unique_ptr<C2PortMimeConfig::input> makeParam() {
        }                                               \
    } while (false)

template <typename T> C2Status C2CompIntfTest::queryOnStack(T *const p) {
template <typename T> c2_status_t C2CompIntfTest::queryOnStack(T *const p) {
    std::vector<C2Param *const> stackParams{p};
    return mIntf->query_nb(stackParams, {}, nullptr);
}

template <typename T>
C2Status C2CompIntfTest::queryOnHeap(
c2_status_t C2CompIntfTest::queryOnHeap(
        const T &p, std::vector<std::unique_ptr<C2Param>> *const heapParams) {
    uint32_t index = p.type();
    if (p.forStream()) {
@@ -258,7 +258,7 @@ template <typename T> void C2CompIntfTest::queryUnsupportedParam() {
}

template <typename T>
C2Status C2CompIntfTest::config(
c2_status_t C2CompIntfTest::config(
        T *const p, std::vector<std::unique_ptr<C2SettingResult>> *const failures) {
    std::vector<C2Param *const> params{p};
    return mIntf->config_nb(params, failures);
@@ -286,7 +286,7 @@ void C2CompIntfTest::configReadOnlyParam(const T &newParam) {
}

template <typename T>
void C2CompIntfTest::configWritableParamValidValue(const T &newParam, C2Status *configResult) {
void C2CompIntfTest::configWritableParamValidValue(const T &newParam, c2_status_t *configResult) {
    std::unique_ptr<T> p = makeParamFrom(newParam);

    std::vector<C2Param *const> params{p.get()};
@@ -297,7 +297,7 @@ void C2CompIntfTest::configWritableParamValidValue(const T &newParam, C2Status *
    // because there may be dependent limitations between fields or between parameters.
    // TODO(hiroh): I have to fill the return value. Comments in C2Component.h doesn't mention
    // about the return value when conflict happens. I set C2_BAD_VALUE to it temporarily now.
    C2Status stConfig = mIntf->config_nb(params, &failures);
    c2_status_t stConfig = mIntf->config_nb(params, &failures);
    if (stConfig == C2_OK) {
        EXPECT_EQ(0u, failures.size());
    } else {
@@ -481,7 +481,7 @@ void C2CompIntfTest::testWritableParam(
        TParam *const param, TRealField *const writableField,
        const std::vector<TField> &validValues,
        const std::vector<TField> &invalidValues) {
    C2Status stConfig;
    c2_status_t stConfig;

    // Get the parameter's value in the beginning in order to reset the value at the end.
    TRACED_FAILURE(getValue(param));
@@ -555,7 +555,7 @@ void C2CompIntfTest::checkParamPermission(
    std::vector<std::unique_ptr<C2SettingResult>> failures;
    // Config does not change the parameter, because param is the present param.
    // This config is executed to find out if a parameter is read-only or writable.
    C2Status stStack = config(param.get(), &failures);
    c2_status_t stStack = config(param.get(), &failures);
    if (stStack == C2_BAD_VALUE) {
        // Read-only
        std::unique_ptr<T> newParam = makeParam<T>();
@@ -594,7 +594,7 @@ void C2CompIntfTest::outputResults(const std::string &name) {
                    C2ParamField(param.get(), &field_type_name_::field_name_)) \
        };                                                              \
        ASSERT_EQ(C2_OK,                                                \
                  mIntf->getSupportedValues(validValueInfos));          \
                  mIntf->querySupportedValues_nb(validValueInfos));     \
        ASSERT_EQ(1u, validValueInfos.size());                          \
        std::vector<decltype(param->field_name_)> validValues;          \
        std::vector<decltype(param->field_name_)> invalidValues;        \
@@ -640,7 +640,7 @@ void C2CompIntfTest::testMain(std::shared_ptr<C2ComponentInterface> intf,
    setComponent(intf);

    std::vector<std::shared_ptr<C2ParamDescriptor>> supportedParams;
    ASSERT_EQ(C2_OK, mIntf->getSupportedParams(&supportedParams));
    ASSERT_EQ(C2_OK, mIntf->querySupportedParams_nb(&supportedParams));

    EACH_TEST_SELF(C2ComponentLatencyInfo, TEST_U32_WRITABLE_FIELD);
    EACH_TEST_SELF(C2ComponentTemporalInfo, TEST_U32_WRITABLE_FIELD);
Loading