Android ACodec消息机制一

    ACodec有一个BaseState和派生出来的其他State. FlushingState,ExecutingState等,用于处理各种消息。

    struct ACodec::BaseStage : public AState

    struct ACodec: public AHierarchicalStateMachine[AHierarchicalStateMachine用于将收到的消息传递给哪个state]

//AHandler.cpp

void AHandler::deliverMessage(const sp<AMessage> &msg)

{

    onMessageReceived(msg);

    ...

}


//ACodec.h

virtual void onMessageReceived(const sp<AMessage> &msg)

{

    handleMessage(msg);

}


void AHierarchicalStateMachine::changeState(const sp<AState> &state)

{

    sp<AState> cur = mState;

    cur = state;

}


void AHierarchicalStateMachine::handleMessage(const sp<AMessage> &msg)

{

    sp<AState> cur = mState;

    while(cur != NULL && !cur->onMessageReceived(msg)){}

}


    当有消息来的时候,如果派生类有重写,则会调到重写的方法里,如果没有,则会调到BaseState.

    ACodec收到的消息分两种,一种是MediaCodec传过来的,一种是OMX Component传过来的。分别对应onMessageReceived和onOMXMessage.

    onOMXMessage里面又分4种:EVENT,EMPTY_BUFFER_DONE,FILL_BUFFER_DONE,FRAME_RENDERED.


    ACodec是如何实现同OMXNodeInstance实现消息传递:

    ACodec将CodecObserver observer对象通过omx->allocateNode()传递到OMXNodeInstance.

    OMXNodeInstance将kCallbacks(OnEvent,OnEmptyBufferDone,OnFillBufferDone)传递给OMX Component.

    当OMX Component有消息notify上来时,OMXNodeInstance最先收到,然后调用OMX.cpp。将消息在OMX.cpp里面将OMX Component thread转换到CallbackDispatcher线程中处理。CallbackDispatcher又将消息反调到OMXNodeInstance. 最后调用mObserver->onMessage()回到ACodec中

    

发布了20 篇原创文章 · 获赞 1 · 访问量 2万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览