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

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

Codec2: C2Component API rework plus rename

- C2ComponentInterface::config_nb, query_nb and querySupportedValues_nb
as well as C2Component::setListener_sm are not variable blocking and
take mayBlock.
- added c2_blocking_t and C2_BLOCKING error value
- defined C2Component::kind_t, domain_t and rank_t
- removed C2ComponentInterface:: and C2ComponentStore::commit_sm
- C2Component::release() and reset() now returns c2_status_t
- added C2Component::DRAIN_COMPONENT_NO_EOS
- renamed types according to final naming conventions

Change-Id: Iaf3f9f0ae20239ed9c9ce5de72405428672e4571
parent 25333a47
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -182,7 +182,7 @@ void CCodec::allocate(const AString &componentName) {
    mListener.reset(new CCodecListener(mChannel));
    mListener.reset(new CCodecListener(mChannel));


    std::shared_ptr<C2Component> comp(new C2SoftAvcDec(componentName.c_str(), 0));
    std::shared_ptr<C2Component> comp(new C2SoftAvcDec(componentName.c_str(), 0));
    comp->setListener_sm(mListener);
    comp->setListener_vb(mListener, C2_DONT_BLOCK);
    {
    {
        Mutexed<State>::Locked state(mState);
        Mutexed<State>::Locked state(mState);
        if (state->mState != ALLOCATING) {
        if (state->mState != ALLOCATING) {
+13 −4
Original line number Original line Diff line number Diff line
@@ -29,12 +29,19 @@ SimpleC2Component::SimpleC2Component(
    : mIntf(intf) {
    : mIntf(intf) {
}
}


c2_status_t SimpleC2Component::setListener_sm(const std::shared_ptr<C2Component::Listener> &listener) {
c2_status_t SimpleC2Component::setListener_vb(
        const std::shared_ptr<C2Component::Listener> &listener, c2_blocking_t mayBlock) {
    Mutexed<ExecState>::Locked state(mExecState);
    Mutexed<ExecState>::Locked state(mExecState);
    if (state->mState == RUNNING) {
    if (state->mState == RUNNING) {
        if (listener) {
            return C2_BAD_STATE;
            return C2_BAD_STATE;
        } else if (!mayBlock) {
            return C2_BLOCKING;
        }
    }
    }
    state->mListener = listener;
    state->mListener = listener;
    // TODO: wait for listener change to have taken place before returning
    // (e.g. if there is an ongoing listener callback)
    return C2_OK;
    return C2_OK;
}
}


@@ -167,7 +174,7 @@ c2_status_t SimpleC2Component::stop() {
    return C2_OK;
    return C2_OK;
}
}


void SimpleC2Component::reset() {
c2_status_t SimpleC2Component::reset() {
    {
    {
        Mutexed<ExecState>::Locked state(mExecState);
        Mutexed<ExecState>::Locked state(mExecState);
        state->mState = UNINITIALIZED;
        state->mState = UNINITIALIZED;
@@ -181,15 +188,17 @@ void SimpleC2Component::reset() {
        pending->clear();
        pending->clear();
    }
    }
    onReset();
    onReset();
    return C2_OK;
}
}


void SimpleC2Component::release() {
c2_status_t SimpleC2Component::release() {
    {
    {
        Mutexed<ExecState>::Locked state(mExecState);
        Mutexed<ExecState>::Locked state(mExecState);
        mExitRequested = true;
        mExitRequested = true;
        state->mThread.join();
        state->mThread.join();
    }
    }
    onRelease();
    onRelease();
    return C2_OK;
}
}


std::shared_ptr<C2ComponentInterface> SimpleC2Component::intf() {
std::shared_ptr<C2ComponentInterface> SimpleC2Component::intf() {
+20 −0
Original line number Original line Diff line number Diff line
@@ -128,6 +128,7 @@ enum c2_status_t : int32_t {
    TIMED_OUT           = -ETIMEDOUT,
    TIMED_OUT           = -ETIMEDOUT,
    UNKNOWN_ERROR       = -EFAULT,
    UNKNOWN_ERROR       = -EFAULT,
    UNKNOWN_TRANSACTION = -EBADMSG,
    UNKNOWN_TRANSACTION = -EBADMSG,
    WOULD_BLOCK         = -EWOULDBLOCK,
#endif
#endif


    C2_OK        = OK,                   ///< operation completed successfully
    C2_OK        = OK,                   ///< operation completed successfully
@@ -141,6 +142,7 @@ enum c2_status_t : int32_t {
    C2_DUPLICATE = ALREADY_EXISTS,       ///< object already exists
    C2_DUPLICATE = ALREADY_EXISTS,       ///< object already exists
    C2_NOT_FOUND = NAME_NOT_FOUND,       ///< object not found
    C2_NOT_FOUND = NAME_NOT_FOUND,       ///< object not found
    C2_BAD_STATE = INVALID_OPERATION,    ///< operation is not permitted in the current state
    C2_BAD_STATE = INVALID_OPERATION,    ///< operation is not permitted in the current state
    C2_BLOCKING  = WOULD_BLOCK,          ///< operation would block but blocking is not permitted


    // bad environment
    // bad environment
    C2_NO_MEMORY = NO_MEMORY,            ///< not enough memory to complete operation
    C2_NO_MEMORY = NO_MEMORY,            ///< not enough memory to complete operation
@@ -156,6 +158,24 @@ enum c2_status_t : int32_t {
    C2_NO_INIT   = NO_INIT,              ///< status has not been initialized
    C2_NO_INIT   = NO_INIT,              ///< status has not been initialized
};
};


/**
 * Type that describes the desired blocking behavior for variable blocking calls. Blocking in this
 * API is used in a somewhat modified meaning such that operations that merely update variables
 * protected by mutexes are still considered "non-blocking" (always used in quotes).
 */
enum c2_blocking_t : int32_t {
    /**
     * The operation SHALL be "non-blocking". This means that it shall not perform any file
     * operations, or call/wait on other processes. It may use a protected region as long as the
     * mutex is never used to protect code that is otherwise "may block".
     */
    C2_DONT_BLOCK = false,
    /**
     * The operation MAY be temporarily blocking.
     */
    C2_MAY_BLOCK = true,
};

/// @}
/// @}


/// \defgroup utils Utilities
/// \defgroup utils Utilities
+202 −161

File changed.

Preview size limit exceeded, changes collapsed.

+12 −10
Original line number Original line Diff line number Diff line
@@ -35,17 +35,19 @@ public:
    virtual ~SimpleC2Component() = default;
    virtual ~SimpleC2Component() = default;


    // C2Component
    // C2Component
    virtual c2_status_t setListener_sm(const std::shared_ptr<C2Component::Listener> &listener) final;
    // From C2Component
    virtual c2_status_t queue_nb(std::list<std::unique_ptr<C2Work>> * const items) final;
    virtual c2_status_t setListener_vb(
    virtual c2_status_t announce_nb(const std::vector<C2WorkOutline> &items) final;
            const std::shared_ptr<Listener> &listener, c2_blocking_t mayBlock) override;
    virtual c2_status_t queue_nb(std::list<std::unique_ptr<C2Work>>* const items) override;
    virtual c2_status_t announce_nb(const std::vector<C2WorkOutline> &items) override;
    virtual c2_status_t flush_sm(
    virtual c2_status_t flush_sm(
            flush_mode_t flushThrough, std::list<std::unique_ptr<C2Work>>* const flushedWork) final;
            flush_mode_t mode, std::list<std::unique_ptr<C2Work>>* const flushedWork) override;
    virtual c2_status_t drain_nb(drain_mode_t drainThrough) final;
    virtual c2_status_t drain_nb(drain_mode_t mode) override;
    virtual c2_status_t start() final;
    virtual c2_status_t start() override;
    virtual c2_status_t stop() final;
    virtual c2_status_t stop() override;
    virtual void reset() final;
    virtual c2_status_t reset() override;
    virtual void release() final;
    virtual c2_status_t release() override;
    virtual std::shared_ptr<C2ComponentInterface> intf() final;
    virtual std::shared_ptr<C2ComponentInterface> intf() override;


    // for thread
    // for thread
    inline bool exitRequested() { return mExitRequested; }
    inline bool exitRequested() { return mExitRequested; }
Loading