OMX 框架是android 音视频codec 的入口吧。 说到入口, 首先omx 就是在ACodec 被使用, 而且是以一个client 来使用, 所以omx 会有个service。这个分析就从这里开始好了。
bool ACodec::UninitializedState::onAllocateComponent(const sp<AMessage> &msg) {
ALOGV("onAllocateComponent");
CHECK(mCodec->mNode == NULL);
OMXClient client;
CHECK_EQ(client.connect(), (status_t)OK);
sp<IOMX> omx = client.interface();
....
mCodec->mQuirks = quirks;
mCodec->mOMX = omx; // omx client
mCodec->mNode = node; // node 很关键
所以在ACodec.cpp 的代码中会发现所以omx相关的操作都是mCodec->mOMX->xxxx, 主要对omx 的操作方法显然就可以从头文件一目了然了。
IOMX.h
#ifndef ANDROID_IOMX_H_
#define ANDROID_IOMX_H_
#include <binder/IInterface.h>
#include <gui/IGraphicBufferProducer.h>
#include <ui/GraphicBuffer.h>
#include <utils/List.h>
#include <utils/String8.h>
#include <OMX_Core.h>
#include <OMX_Video.h>
namespace android {
class IMemory;
class IOMXObserver;
class IOMXRenderer;
class Surface;
class IOMX : public IInterface {
public:
DECLARE_META_INTERFACE(OMX);
typedef uint32_t buffer_id;
typedef uint32_t node_id;
// Given a node_id and the calling process' pid, returns true iff
// the implementation of the OMX interface lives in the same
// process.
virtual bool livesLocally(node_id node, pid_t pid) = 0;
struct ComponentInfo {
String8 mName;
List<String8> mRoles;
};
virtual status_t listNodes(List<ComponentInfo> *list) = 0;
virtual status_t allocateNode(
const char *name, const sp<IOMXObserver> &observer,
node_id *node) = 0;
virtual status_t freeNode(node_id node) = 0;
virtual status_t sendCommand(
node_id node, OMX_COMMANDTYPE cmd, OMX_S32 param) = 0;
virtual status_t getParameter(
node_id node, OMX_INDEXTYPE index,
void *params, size_t size) = 0;
virtual status_t setParameter(
node_id node, OMX_INDEXTYPE index,
const void *params, size_t size) = 0;
virtual status_t getConfig(
node_id node, OMX_INDEXTYPE index,
void *params, size_t size) = 0;
virtual status_t setConfig(
node_id node, OMX_INDEXTYPE index,
const void *params, size_t size) = 0;
virtual status_t getState(
node_id node, OMX_STATETYPE* state)