AwesomePlayer has a variable.
[Cpp]
OMXClient mClient;
Let's take a look at 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 &);
};
The OMXClient has an IOMX variable mOMX, which is used to communicate with the OMX service in binder mode.
The AwesomePlayer constructor calls
[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: The connect function obtains MediaPlayerService through the binder Mechanism, and then creates OMX instances through MediaPlayerService. In this way, the OMXClient obtains the OMX entry, and then obtains the services provided by OMX through the binder Mechanism.
That is to say, OMXClient is the openmax entry in android.
When you create audio/video decoding mVideoSource and mAudioSource, the sp <IOMX> mOMX instance in the OMXClient is sent to mVideoSource and mAudioSource to share the OMX entry.
That is to say, an AwesomePlayer corresponds to an IOMX variable. The audio/video decoder in AwesomePlayer shares this IOMX variable to obtain the OMX service.
[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]