Learn to understand the Mutilmedia framework for some time, today idle down a little to tidy up. The OMXCodec.cpp class belongs to Libstagefright, which is quite omx on the entire mm PF for Awesomeplayer invocation, and omx.cpp,omxnoteinstance.cpp equal to OpenMAX in the OpenMAX IL, first of all Omxcodec and OMX callback event processing flow. Let's look at the timing diagram of the entire process:
From the timing diagram, first we want to establish a omxcodecobserver, the class is the inner class of Omxcodec, created in the CREATE function, and the corresponding omxcodec into their own observation range, the specific code is as follows:
Framework/base/media/libstagefright/omxcodec.cpp
Sp<mediasource> Omxcodec::create (
Const Sp<iomx> &OMX,
Const sp<metadata> &meta, BOOL Createencoder,
Const Sp<mediasource> &source,
const Char *matchcomponentname,
uint32_t flags) {
.....
sp<omxcodecobserver> observer = new Omxcodecobserver;
...............
Observer->setcodec (codec);
...................
}
Second, initialize its callback event and event dispatch handler function.
What are the main callback events of OMX? The Kcallbacks function in Framework/base/media/libstagefright/omx/omxnodeinstance.cpp is defined as follows:
Static
Omx_callbacktype omxnodeinstance::kcallbacks = {
&onevent, &onemptybufferdone, &onfillbufferdone
};
Where does the callback define it? Look at the framework/base/media/libstagefright/omx/omx.cpp.
status_t Omx::allocatenode (
.......................
Omxnodeinstance *instance = new Omxnodeinstance (this, observer);
Omx_componenttype *handle;
Omx_errortype err = mmaster->makecomponentinstance (
Name, &omxnodeinstance::kcallbacks,
instance, &handle);
..............
Mdispatchers.add (*node, new Callbackdispatcher (instance));
...................
}
That is, each component corresponds to a set of callback events.
What functions are returned by these callback? The specific definition in framework/base/media/libstagefright/openmax/omx_core.h
Callback EventHandler ()
#define Omx_sendcommand( \
Hcomponent, \
CMD, \
Nparam, \
Pcmddata) \
((omx_componenttype*) hcomponent)->sendcommand (\
Hcomponent, \
CMD, \
Nparam, \
Pcmddata)
Emptybufferdone call back.
#define Omx_emptythisbuffer( \
Hcomponent, \
pbuffer) \
((omx_componenttype*) hcomponent)->emptythisbuffer (\
Hcomponent, \
pbuffer)/* Macro End */
Fillbufferdone Call Back
#define Omx_fillthisbuffer( \
Hcomponent, \
pbuffer) \
((omx_componenttype*) hcomponent)->fillthisbuffer (\
Hcomponent, \
pbuffer)/* Macro End */
With the callback incident, how to dispatch it? In fact, we have defined our dispatch function in the Allocatenote function.
Mdispatchers.add (*node, new Callbackdispatcher (instance));
With Oberser, callback event, Callbackdispatcher, how does a callback event go from OMX to Omxcodec? Let's take a look at the emptybuffer process below, the timing diagram is as follows:
is not a bit like handle:)
Omxcodec and OMX Event processing flow