1、Android Multimedia框架总结(二十二)MediaCodec中C++中创建到start过程及状态变换 从今天开始,将深入源码中看看其c++过程,看下Agenda如下: mediacodec.h CreateByType initMediaCodec中BufferInfo内部类: configure过程 start BufferInfo在MediaCodec.h中对应是一个结构体 //create by 逆流的鱼yuiop on 2016/12/11 //blog地址: struct BufferInfo { uint32_t mBuf
2、ferID;
sp
3、p on 2016/12/11 //blog地址: namespace android { struct ABuffer; struct AMessage; struct AReplyToken; struct AString; struct CodecBase; struct IBatteryStats; struct ICrypto; class IMemory; struct MemoryDealer; class IResourceManagerClient; class IResourceManagerService; struct PersistentS
4、urface; struct SoftwareRenderer; struct Surface; struct MediaCodec : public AHandler { enum ConfigureFlags { CONFIGURE_FLAG_ENCODE = 1, }; enum BufferFlags { BUFFER_FLAG_SYNCFRAME = 1, BUFFER_FLAG_CODECCONFIG = 2, BUFFER_FLAG_EOS = 4,
5、
};
enum {
CB_INPUT_AVAILABLE = 1,
CB_OUTPUT_AVAILABLE = 2,
CB_ERROR = 3,
CB_OUTPUT_FORMAT_CHANGED = 4,
CB_RESOURCE_RECLAIMED = 5,
};
static const pid_t kNoPid = -1;
static sp 6、r> &looper, const char *mime, bool encoder, status_t *err = NULL,
pid_t pid = kNoPid);
static sp 7、eatePersistentInputSurface();
status_t configure(
const sp 8、dNotification(const sp 9、gured.
status_t stop();
// Resets the codec to the INITIALIZED state. Can be called after an error
// has occured to make the codec usable.
status_t reset();
// Client MUST call release before releasing final reference to this
// object.
status_t release();
s 10、tatus_t flush();
status_t queueInputBuffer(
size_t index,
size_t offset,
size_t size,
int64_t presentationTimeUs,
uint32_t flags,
AString *errorDetailMsg = NULL);
status_t queueSecureInputBuffer(
siz 11、e_t index,
size_t offset,
const CryptoPlugin::SubSample *subSamples,
size_t numSubSamples,
const uint8_t key[16],
const uint8_t iv[16],
CryptoPlugin::Mode mode,
int64_t presentationTimeUs,
uint32_ 12、t flags,
AString *errorDetailMsg = NULL);
status_t dequeueInputBuffer(size_t *index, int64_t timeoutUs = 0ll);
status_t dequeueOutputBuffer(
size_t *index,
size_t *offset,
size_t *size,
int64_t *presentationTimeUs,
13、 uint32_t *flags,
int64_t timeoutUs = 0ll);
status_t renderOutputBufferAndRelease(size_t index, int64_t timestampNs);
status_t renderOutputBufferAndRelease(size_t index);
status_t releaseOutputBuffer(size_t index);
status_t signalEndOfInputStream();
status_t g 14、etOutputFormat(sp 15、buffers) const;
status_t getOutputBuffer(size_t index, sp 16、me();
// Notification will be posted once there "is something to do", i.e.
// an input/output buffer has become available, a format change is
// pending, an error is pending.
void requestActivityNotification(const sp 17、e) const;
status_t setParameters(const sp 18、 static size_t CreateFramesRenderedMessage(
std::list 19、rce = false);
friend struct ResourceManagerClient;
private:
enum State {
UNINITIALIZED,
INITIALIZING,
INITIALIZED,
CONFIGURING,
CONFIGURED,
STARTING,
STARTED,
FLUSHING,
FLUSHED,
STOPPING,
RE 20、LEASING,
};
enum {
kPortIndexInput = 0,
kPortIndexOutput = 1,
};
enum {
kWhatInit = 'init',
kWhatConfigure = 'conf',
kWhatSetSurface = 'sSur',
k 21、WhatCreateInputSurface = 'cisf',
kWhatSetInputSurface = 'sisf',
kWhatStart = 'strt',
kWhatStop = 'stop',
kWhatRelease = 'rele',
kWhatDequeueInputBuffer 22、 = 'deqI',
kWhatQueueInputBuffer = 'queI',
kWhatDequeueOutputBuffer = 'deqO',
kWhatReleaseOutputBuffer = 'relO',
kWhatSignalEndOfInputStream = 'eois',
kWhatGetBuffers = 'getB',
23、 kWhatFlush = 'flus',
kWhatGetOutputFormat = 'getO',
kWhatGetInputFormat = 'getI',
kWhatDequeueInputTimedOut = 'dITO',
kWhatDequeueOutputTimedOut = 'dOTO',
kWhatCodecNotify 24、 = 'codc',
kWhatRequestIDRFrame = 'ridr',
kWhatRequestActivityNotification = 'racN',
kWhatGetName = 'getN',
kWhatSetParameters = 'setP',
kWhatSetCallback = 'setC',
25、
kWhatSetNotification = 'setN',
};
enum {
kFlagUsesSoftwareRenderer = 1,
kFlagOutputFormatChanged = 2,
kFlagOutputBuffersChanged = 4,
kFlagStickyError = 8,
kFlagDequeueInputPending 26、 16,
kFlagDequeueOutputPending = 32,
kFlagIsSecure = 64,
kFlagSawMediaServerDie = 128,
kFlagIsEncoder = 256,
kFlagGatherCodecSpecificData = 512,
kFlagIsAsync = 1024,
27、 kFlagIsComponentAllocated = 2048,
kFlagPushBlankBuffersOnShutdown = 4096,
};
struct BufferInfo {
uint32_t mBufferID;
sp 28、 sp 29、tual void binderDied(const wp 30、ource(const Vector 31、
AString mComponentName;
sp 32、redNotification;
sp 33、
// initial create parameters
AString mInitName;
bool mInitNameIsType;
bool mInitIsEncoder;
// configure parameter
sp 34、e
// operations, such as de/queueIn/OutputBuffer, start and
// stop/flush/reset/release.
Mutex mBufferLock;
List 35、32_t mDequeueOutputTimeoutGeneration;
sp 36、atic status_t PostAndAwaitResponse(
const sp 37、ffersToCodec();
void returnBuffersToCodecOnPort(int32_t portIndex);
size_t updateBuffers(int32_t portIndex, const sp 38、2_t portIndex);
status_t getBufferAndFormat(
size_t portIndex, size_t index,
sp 39、n> &replyID, bool newRequest = false);
void cancelPendingDequeueOperations();
void extractCSD(const sp 40、rface);
status_t disconnectFromSurface();
void postActivityNotificationIfPossible();
void onInputBufferAvailable();
void onOutputBufferAvailable();
void onError(status_t err, int32_t actionCode, const char *detail = NULL);
void onOutputFormatChanged();
status_t onS 41、etParameters(const sp 42、alue);
bool hasPendingBuffer(int portIndex);
bool hasPendingBuffer();
/* called to get the last codec error when the sticky flag is set.
* if no such codec error is found, returns UNKNOWN_ERROR.
*/
inline status_t getStickyError() const {
return mStickyError 43、 0 ? mStickyError : UNKNOWN_ERROR;
}
inline void setStickyError(status_t err) {
mFlags |= kFlagStickyError;
mStickyError = err;
}
DISALLOW_EVIL_CONSTRUCTORS(MediaCodec);
};
} // namespace android
CreateByType
//create by 逆流的鱼yuiop on 2016/12/11
//blog地 44、址:
// static
sp 45、ncoder);
if (err != NULL) {
*err = ret;
}
return ret == OK ? codec : NULL; // NULL deallocates codec.
}
接着到init过程
//create by 逆流的鱼yuiop on 2016/12/11
//blog地址:
status_t MediaCodec::init(const AString &name, bool nameIsType, bool encoder) {
mResourceManagerService- 46、>init();
// 保存 初始参数,到时用于reset
mInitName = name;
mInitNameIsType = nameIsType;
mInitIsEncoder = encoder;
// 目前视频解码器不能马上从OMX_FillThisBuffer返回,违反OpenMAX规格,直到提醒我们需要入驻另一个第三方的looper释放在事件队列中。
if (nameIsType || !strncasecmp(name.c_str(), "omx.", 4)) {//omx.匹配
mCodec = n 47、ew ACodec;//实例化ACodec
} else if (!nameIsType
&& !strncasecmp(name.c_str(), "android.filter.", 15)) {
mCodec = new MediaFilter;// 实例化MediaFilter
} else {
return NAME_NOT_FOUND;
}
bool secureCodec = false;
if (nameIsType && !strncasecmp(name.c_st 48、r(), "video/", 6)) {
mIsVideo = true;
} else {
AString tmp = name;
if (tmp.endsWith(".secure")) {
secureCodec = true;
tmp.erase(tmp.size() - 7, 7);
}
const sp 49、 (mcl == NULL) {
mCodec = NULL; // remove the codec.
return NO_INIT; // if called from Java should raise IOException
}
ssize_t codecIdx = mcl->findCodecByName(tmp.c_str());
if (codecIdx >= 0) {
const sp






