-
/*========================================================*/
-
/* @ fn SampleTest_FillBufferDone :: Application callback*/
-
/*========================================================*/
-
OMX_ERRORTYPE OMXCameraAdapter::OMXCameraAdapterFillBufferDone(OMX_IN OMX_HANDLETYPE hComponent,
-
OMX_IN OMX_BUFFERHEADERTYPE* pBuffHeader)
-
{
-
-
status_t stat = NO_ERROR;
-
status_t res1, res2;
-
OMXCameraPortParameters *pPortParam;
-
OMX_ERRORTYPE eError = OMX_ErrorNone;
-
CameraFrame::FrameType typeOfFrame = CameraFrame::ALL_FRAMES;
-
unsigned int refCount = 0;
-
BaseCameraAdapter::AdapterState state, nextState;
-
BaseCameraAdapter::getState(state);
-
BaseCameraAdapter::getNextState(nextState);
-
sp<CameraMetadataResult> metadataResult = NULL;
-
unsigned int mask = 0xFFFF;
-
CameraFrame cameraFrame;
-
OMX_OTHER_EXTRADATATYPE *extraData;
-
OMX_TI_ANCILLARYDATATYPE *ancillaryData = NULL;
-
bool snapshotFrame = false;
-
-
if ( NULL == pBuffHeader ) {
-
return OMX_ErrorBadParameter;
-
}
-
-
#ifdef CAMERAHAL_OMX_PROFILING
-
-
storeProfilingData(pBuffHeader);
-
-
#endif
-
-
res1 = res2 = NO_ERROR;
-
-
if ( !pBuffHeader || !pBuffHeader->pBuffer ) {
-
CAMHAL_LOGEA("NULL Buffer from OMX");
-
return OMX_ErrorNone;
-
}
-
这里这个pPortParm到底应该是哪个port的param呢??其实是不一定的
-
1.如果这个消息是preview port 的fillbufferdone,那么自然这里这个pPortParm指针指向的就是preview port 的param
-
2.如果这个消息是measurement port 的fillbufferdone,那么自然这里这个pPortParm指针指向的就是measurement port 的param
-
pPortParam = &(mCameraAdapterParameters.mCameraPortParams[pBuffHeader->nOutputPortIndex]);
-
-
// Find buffer and mark it as filled,首先比对,比对ok后标记为filldone
-
for (int i = 0; i < pPortParam->mNumBufs; i++) {
-
if (pPortParam->mBufferHeader[i] == pBuffHeader) {
-
pPortParam->mStatus[i] = OMXCameraPortParameters::DONE;
-
}
-
}
-
从这里开始就要进行分类处理了,对应不同output port type有不同的处理方法
-
1.OMX_CAMERA_PORT_VIDEO_OUT_PREVIEW(对应preview过程)
-
if (pBuffHeader->nOutputPortIndex == OMX_CAMERA_PORT_VIDEO_OUT_PREVIEW)
-
{
-
-
if ( ( PREVIEW_ACTIVE & state ) != PREVIEW_ACTIVE )
-
{
-
return OMX_ErrorNone;
-
}
-
从这里开始我们暂时不做过多研究,只是对preview环境的一些初始化
-
if ( mWaitingForSnapshot ) {
-
extraData = getExtradata(pBuffHeader->pPlatformPrivate,
-
(OMX_EXTRADATATYPE) OMX_AncillaryData);
-
-
if ( NULL != extraData ) {
-
ancillaryData = (OMX_TI_ANCILLARYDATATYPE*) extraData->data;
-
if ((OMX_2D_Snap == ancillaryData->eCameraView)
-
|| (OMX_3D_Left_Snap == ancillaryData->eCameraView)
-
|| (OMX_3D_Right_Snap == ancillaryData->eCameraView)) {
-
snapshotFrame = OMX_TRUE;
-
} else {
-
snapshotFrame = OMX_FALSE;
-
}
-
mPending3Asettings |= SetFocus;
-
}
-
}
-
-
///Prepare the frames to be sent - initialize CameraFrame object and reference count
-
// TODO(XXX): ancillary data for snapshot frame is not being sent for video snapshot
-
// if we are waiting for a snapshot and in video mode...go ahead and send
-
// this frame as a snapshot
-
if( mWaitingForSnapshot && (mCapturedFrames > 0) &&
-
(snapshotFrame || (mCapMode == VIDEO_MODE)))
-
{
-
typeOfFrame = CameraFrame::SNAPSHOT_FRAME;
-
mask = (unsigned int)CameraFrame::SNAPSHOT_FRAME;
-
-
// video snapshot gets ancillary data and wb info from last snapshot frame
-
mCaptureAncillaryData = ancillaryData;
-
mWhiteBalanceData = NULL;
-
extraData = getExtradata(pBuffHeader->pPlatformPrivate,
-
(OMX_EXTRADATATYPE) OMX_WhiteBalance);
-
if ( NULL != extraData )
-
{
-
mWhiteBalanceData = (OMX_TI_WHITEBALANCERESULTTYPE*) extraData->data;
-
}
-
}
-
else
-
{
-
typeOfFrame = CameraFrame::PREVIEW_FRAME_SYNC;
-
mask = (unsigned int)CameraFrame::PREVIEW_FRAME_SYNC;
-
}
-
-
if (mRecording)
-
{
-
mask |= (unsigned int)CameraFrame::VIDEO_FRAME_SYNC;
-
mFramesWithEncoder++;
-
}
-
-
//LOGV("FBD pBuffer = 0x%x", pBuffHeader->pBuffer);
-
-
if( mWaitingForSnapshot )
-
{
-
if (!mBracketingEnabled &&
-
((HIGH_SPEED == mCapMode) || (VIDEO_MODE == mCapMode)) )
-
{
-
notifyShutterSubscribers();
-
}
-
}
-
这里这个sendCallBacks还是要好好研究一下的
-
stat = sendCallBacks(cameraFrame, pBuffHeader, mask, pPortParam);
-
mFramesWithDisplay++;
-
-
mFramesWithDucati--;
-
下面暂不做研究
-
#ifdef CAMERAHAL_DEBUG
-
if(mBuffersWithDucati.indexOfKey((uint32_t)pBuffHeader->pBuffer)<0)
-
{
-
LOGE("Buffer was never with Ducati!! %p", pBuffHeader->pBuffer);
-
for(unsigned int i=0;i<mBuffersWithDucati.size();i++) LOGE("0x%x", mBuffersWithDucati.keyAt(i));
-
}
-
mBuffersWithDucati.removeItem((int)pBuffHeader->pBuffer);
-
#endif
-
-
if(mDebugFcs)
-
CAMHAL_LOGEB("C[%d] D[%d] E[%d]", mFramesWithDucati, mFramesWithDisplay, mFramesWithEncoder);
-
-
recalculateFPS();
-
-
createPreviewMetadata(pBuffHeader, metadataResult, pPortParam->mWidth, pPortParam->mHeight);
-
if ( NULL != metadataResult.get() ) {
-
notifyMetadataSubscribers(metadataResult);
-
metadataResult.clear();
-
}
-
-
{
-
Mutex::Autolock lock(mFaceDetectionLock);
-
if ( mFDSwitchAlgoPriority ) {
-
-
//Disable region priority and enable face priority for AF
-
setAlgoPriority(REGION_PRIORITY, FOCUS_ALGO, false);
-
setAlgoPriority(FACE_PRIORITY, FOCUS_ALGO , true);
-
-
//Disable Region priority and enable Face priority
-
setAlgoPriority(REGION_PRIORITY, EXPOSURE_ALGO, false);
-
setAlgoPriority(FACE_PRIORITY, EXPOSURE_ALGO, true);
-
mFDSwitchAlgoPriority = false;
-
}
-
}
-
-
sniffDccFileDataSave(pBuffHeader);
-
-
stat |= advanceZoom();
-
-
// On the fly update to 3A settings not working
-
// Do not update 3A here if we are in the middle of a capture
-
// or in the middle of transitioning to it
-
if( mPending3Asettings &&
-
( (nextState & CAPTURE_ACTIVE) == 0 ) &&
-
( (state & CAPTURE_ACTIVE) == 0 ) ) {
-
apply3Asettings(mParameters3A);
-
}
-
-
}
-
2.OMX_CAMERA_PORT_VIDEO_OUT_MEASUREMENT
-
else if( pBuffHeader->nOutputPortIndex == OMX_CAMERA_PORT_VIDEO_OUT_MEASUREMENT )
-
{
-
typeOfFrame = CameraFrame::FRAME_DATA_SYNC;
-
mask = (unsigned int)CameraFrame::FRAME_DATA_SYNC;
-
-
stat = sendCallBacks(cameraFrame, pBuffHeader, mask, pPortParam);
-
}
-
3.OMX_CAMERA_PORT_IMAGE_OUT_IMAGE
-
else if( pBuffHeader->nOutputPortIndex == OMX_CAMERA_PORT_IMAGE_OUT_IMAGE )
-
{
-
OMX_COLOR_FORMATTYPE pixFormat;
-
const char *valstr = NULL;
-
-
pixFormat = pPortParam->mColorFormat;
-
-
if ( OMX_COLOR_FormatUnused == pixFormat )
-
{
-
typeOfFrame = CameraFrame::IMAGE_FRAME;
-
mask = (unsigned int) CameraFrame::IMAGE_FRAME;
-
} else if ( pixFormat == OMX_COLOR_FormatCbYCrY &&
-
((mPictureFormatFromClient &&
-
!strcmp(mPictureFormatFromClient,
-
CameraParameters::PIXEL_FORMAT_JPEG)) ||
-
!mPictureFormatFromClient) ) {
-
// signals to callbacks that this needs to be coverted to jpeg
-
// before returning to framework
-
typeOfFrame = CameraFrame::IMAGE_FRAME;
-
mask = (unsigned int) CameraFrame::IMAGE_FRAME;
-
cameraFrame.mQuirks |= CameraFrame::ENCODE_RAW_YUV422I_TO_JPEG;
-
cameraFrame.mQuirks |= CameraFrame::FORMAT_YUV422I_UYVY;
-
-
// populate exif data and pass to subscribers via quirk
-
// subscriber is in charge of freeing exif data
-
ExifElementsTable* exif = new ExifElementsTable();
-
setupEXIF_libjpeg(exif, mCaptureAncillaryData, mWhiteBalanceData);
-
cameraFrame.mQuirks |= CameraFrame::HAS_EXIF_DATA;
-
cameraFrame.mCookie2 = (void*) exif;
-
} else {
-
typeOfFrame = CameraFrame::RAW_FRAME;
-
mask = (unsigned int) CameraFrame::RAW_FRAME;
-
}
-
-
pPortParam->mImageType = typeOfFrame;
-
-
if((mCapturedFrames>0) && !mCaptureSignalled)
-
{
-
mCaptureSignalled = true;
-
mCaptureSem.Signal();
-
}
-
-
if( ( CAPTURE_ACTIVE & state ) != CAPTURE_ACTIVE )
-
{
-
goto EXIT;
-
}
-
-
{
-
Mutex::Autolock lock(mBracketingLock);
-
if ( mBracketingEnabled )
-
{
-
doBracketing(pBuffHeader, typeOfFrame);
-
return eError;
-
}
-
}
-
-
if (mZoomBracketingEnabled) {
-
doZoom(mZoomBracketingValues[mCurrentZoomBracketing]);
-
CAMHAL_LOGDB("Current Zoom Bracketing: %d", mZoomBracketingValues[mCurrentZoomBracketing]);
-
mCurrentZoomBracketing++;
-
if (mCurrentZoomBracketing == ARRAY_SIZE(mZoomBracketingValues)) {
-
mZoomBracketingEnabled = false;
-
}
-
}
-
-
if ( 1 > mCapturedFrames )
-
{
-
goto EXIT;
-
}
-
-
#ifdef OMAP_ENHANCEMENT_CPCAM
-
setMetaData(cameraFrame.mMetaData, pBuffHeader->pPlatformPrivate);
-
#endif
-
-
CAMHAL_LOGDB("Captured Frames: %d", mCapturedFrames);
-
-
mCapturedFrames--;
-
-
#ifdef CAMERAHAL_USE_RAW_IMAGE_SAVING
-
if (mYuvCapture) {
-
struct timeval timeStampUsec;
-
gettimeofday(&timeStampUsec, NULL);
-
-
time_t saveTime;
-
time(&saveTime);
-
const struct tm * const timeStamp = gmtime(&saveTime);
-
-
char filename[256];
-
snprintf(filename,256, "%s/yuv_%d_%d_%d_%lu.yuv",
-
kYuvImagesOutputDirPath,
-
timeStamp->tm_hour,
-
timeStamp->tm_min,
-
timeStamp->tm_sec,
-
timeStampUsec.tv_usec);
-
-
const status_t saveBufferStatus = saveBufferToFile(((CameraBuffer*)pBuffHeader->pAppPrivate)->mapped,
-
pBuffHeader->nFilledLen, filename);
-
-
if (saveBufferStatus != OK) {
-
CAMHAL_LOGE("ERROR: %d, while saving yuv!", saveBufferStatus);
-
} else {
-
CAMHAL_LOGD("yuv_%d_%d_%d_%lu.yuv successfully saved in %s",
-
timeStamp->tm_hour,
-
timeStamp->tm_min,
-
timeStamp->tm_sec,
-
timeStampUsec.tv_usec,
-
kYuvImagesOutputDirPath);
-
}
-
}
-
#endif
-
-
stat = sendCallBacks(cameraFrame, pBuffHeader, mask, pPortParam);
-
}
-
4.OMX_CAMERA_PORT_VIDEO_OUT_VIDEO
-
else if (pBuffHeader->nOutputPortIndex == OMX_CAMERA_PORT_VIDEO_OUT_VIDEO) {
-
typeOfFrame = CameraFrame::RAW_FRAME;
-
pPortParam->mImageType = typeOfFrame;
-
{
-
Mutex::Autolock lock(mLock);
-
if( ( CAPTURE_ACTIVE & state ) != CAPTURE_ACTIVE ) {
-
goto EXIT;
-
}
-
}
-
-
CAMHAL_LOGD("RAW buffer done on video port, length = %d", pBuffHeader->nFilledLen);
-
-
mask = (unsigned int) CameraFrame::RAW_FRAME;
-
-
#ifdef CAMERAHAL_USE_RAW_IMAGE_SAVING
-
if ( mRawCapture ) {
-
struct timeval timeStampUsec;
-
gettimeofday(&timeStampUsec, NULL);
-
-
time_t saveTime;
-
time(&saveTime);
-
const struct tm * const timeStamp = gmtime(&saveTime);
-
-
char filename[256];
-
snprintf(filename,256, "%s/raw_%d_%d_%d_%lu.raw",
-
kRawImagesOutputDirPath,
-
timeStamp->tm_hour,
-
timeStamp->tm_min,
-
timeStamp->tm_sec,
-
timeStampUsec.tv_usec);
-
-
const status_t saveBufferStatus = saveBufferToFile( ((CameraBuffer*)pBuffHeader->pAppPrivate)->mapped,
-
pBuffHeader->nFilledLen, filename);
-
-
if (saveBufferStatus != OK) {
-
CAMHAL_LOGE("ERROR: %d , while saving raw!", saveBufferStatus);
-
} else {
-
CAMHAL_LOGD("raw_%d_%d_%d_%lu.raw successfully saved in %s",
-
timeStamp->tm_hour,
-
timeStamp->tm_min,
-
timeStamp->tm_sec,
-
timeStampUsec.tv_usec,
-
kRawImagesOutputDirPath);
-
stat = sendCallBacks(cameraFrame, pBuffHeader, mask, pPortParam);
-
}
-
}
-
#endif
-
} else {
-
CAMHAL_LOGEA("Frame received for non-(preview/capture/measure) port. This is yet to be supported");
-
goto EXIT;
-
}
这里在上面的操作完成之后都会进行下面的方法returnFrame,这个returnFrame同样要好好分析一下
-
if ( NO_ERROR != stat )
-
{
-
CameraBuffer *camera_buffer;
-
-
camera_buffer = (CameraBuffer *)pBuffHeader->pAppPrivate;
-
-
CAMHAL_LOGDB("sendFrameToSubscribers error: %d", stat);
-
returnFrame(camera_buffer, typeOfFrame);
-
}
-
-
return eError;
-
-
EXIT:
-
-
CAMHAL_LOGEB("Exiting function %s because of ret %d eError=%x", __FUNCTION__, stat, eError);
-
-
if ( NO_ERROR != stat )
-
{
-
if ( NULL != mErrorNotifier )
-
{
-
mErrorNotifier->errorNotify(CAMERA_ERROR_UNKNOWN);
-
}
-
}
-
-
return eError;
-
}
首先看一下sendCallbacks方法的实现