Android多媒體開發【11】-- android中OpenMax的實現【2】AwesomePlayer中openma

來源:互聯網
上載者:User

AwesomePlayer 中有個變數
[cpp] 
OMXClient mClient; 
讓我們看看   OMXClient
[cpp] 
class OMXClient { 
public: 
    OMXClient(); 
 
    status_t connect(); 
    void disconnect(); 
 
    sp<IOMX> interface() { 
        return mOMX; 
    } 
 
private: 
    sp<IOMX> mOMX; 
 
    OMXClient(const OMXClient &); 
    OMXClient &operator=(const OMXClient &); 
}; 
OMXClient 有個IOMX 的變數 mOMX ,這個就是和OMX服務進行binder通訊的。
在 AwesomePlayer 的建構函式中會調用
[cpp] 
CHECK_EQ(mClient.connect(), (status_t)OK); 
[cpp] 
status_t OMXClient::connect() { 
    sp<IServiceManager> sm = defaultServiceManager(); 
    sp<IBinder> binder = sm->getService(String16("media.player")); 
    sp<IMediaPlayerService> service = interface_cast<IMediaPlayerService>(binder); 
 
    CHECK(service.get() != NULL); 
 
    mOMX = service->getOMX(); 
    CHECK(mOMX.get() != NULL); 
 
    if (!mOMX->livesLocally(NULL /* node */, getpid())) { 
        ALOGI("Using client-side OMX mux."); 
        mOMX = new MuxOMX(mOMX); 
    } 
 
    return OK; 

[cpp] view plaincopy
sp<IOMX> MediaPlayerService::getOMX() { 
    Mutex::Autolock autoLock(mLock); 
 
    if (mOMX.get() == NULL) { 
        mOMX = new OMX; 
    } 
 
    return mOMX; 

OMXClient::connect函數是通過binder機制 獲得到MediaPlayerService,然後通過MediaPlayerService來建立OMX的執行個體。這樣OMXClient就獲得到了OMX的入口,接下來就可以通過binder機制來獲得OMX提供的服務。
也就是說OMXClient 是android中 openmax 的入口。

在建立音視頻解碼mVideoSource、mAudioSource的時候會把OMXClient中的sp<IOMX> mOMX的執行個體 傳給mVideoSource、mAudioSource來共用使用這個OMX的入口。
也就是說一個AwesomePlayer對應著 一個IOMX 變數,AwesomePlayer中的音視頻解碼器共用這個IOMX變數來獲得OMX服務。
[cpp
sp<IOMX> interface() { 
      return mOMX; 
  } 
[cpp]  
mAudioSource = OMXCodec::Create( 
                mClient.interface(), mAudioTrack->getFormat(), 
                false, // createEncoder 
                mAudioTrack); 
[cpp] 
mVideoSource = OMXCodec::Create( 
            mClient.interface(), mVideoTrack->getFormat(), 
            false, // createEncoder 
            mVideoTrack, 
            NULL, flags, USE_SURFACE_ALLOC ? mNativeWindow : NULL); 
[cpp] 
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.