camera api1预览显示设置流程

设置流程:

Camera.java

public final void setPreviewDisplay(SurfaceHolder holder) throws IOException {

if (holder != null) {

setPreviewSurface(holder.getSurface());

} else {

setPreviewSurface((Surface)null);

}

}

Android_hardware_camera.cpp

static void android_hardware_Camera_setPreviewSurface(JNIEnv *env, jobject thiz, jobject jSurface)

{

camera->setPreviewTarget(gbp)

}

Camera.cpp

status_t Camera::setPreviewTarget(const sp<IGraphicBufferProducer>& bufferProducer)

{

c->setPreviewTarget(bufferProducer);

}

Cameraclient.cpp

status_t CameraClient::setPreviewTarget(

const sp<IGraphicBufferProducer>& bufferProducer)

{

LOG1("setPreviewTarget(%p) (pid %d)", bufferProducer.get(),

getCallingPid());

sp<IBinder> binder;

sp<ANativeWindow> window;

if (bufferProducer != 0) {

binder = IInterface::asBinder(bufferProducer);

// Using controlledByApp flag to ensure that the buffer queue remains in

// async mode for the old camera API, where many applications depend

// on that behavior.

window = new Surface(bufferProducer, /*controlledByApp*/ true);

}

return setPreviewWindow(binder, window);

}

status_t CameraClient::setPreviewWindow(const sp<IBinder>& binder,

const sp<ANativeWindow>& window)

{

mHardware->setPreviewWindow(window);

}

Camerahardwareinterface.cpp

status_t CameraHardwareInterface::setPreviewWindow(const sp<ANativeWindow>& buf)

{

mHidlDevice->setPreviewWindow(buf.get() ? this : nullptr)

}

cameraDevice.cpp

Return<Status> CameraDevice::setPreviewWindow(const sp<ICameraDevicePreviewCallback>& window)//这个window是Camerahardwareinterface的对象

{

ALOGV("%s(%s)", __FUNCTION__, mCameraId.c_str());

Mutex::Autolock _l(mLock);

if (!mDevice) {

ALOGE("%s called while camera is not opened", __FUNCTION__);

return Status::OPERATION_NOT_SUPPORTED;

}

{

Mutex::Autolock _l(mHalPreviewWindow.mPreviewCallbackLock);

mHalPreviewWindow.mPreviewCallback = window;

}

if (mDevice->ops->set_preview_window) {

return getHidlStatus(mDevice->ops->set_preview_window(mDevice,

(window == nullptr) ? nullptr : &mHalPreviewWindow));

}

return Status::INTERNAL_ERROR; // HAL should provide set_preview_window

}

而mHalPreviewWindow的函数指针是在这个函数初始化的:

void CameraDevice::initHalPreviewWindow()

{

mHalPreviewWindow.cancel_buffer = sCancelBuffer;

mHalPreviewWindow.lock_buffer = sLockBuffer;

mHalPreviewWindow.dequeue_buffer = sDequeueBuffer;

mHalPreviewWindow.enqueue_buffer = sEnqueueBuffer;

mHalPreviewWindow.set_buffer_count = sSetBufferCount;

mHalPreviewWindow.set_buffers_geometry = sSetBuffersGeometry;

mHalPreviewWindow.set_crop = sSetCrop;

mHalPreviewWindow.set_timestamp = sSetTimestamp;

mHalPreviewWindow.set_usage = sSetUsage;

mHalPreviewWindow.set_swap_interval = sSetSwapInterval;

mHalPreviewWindow.get_min_undequeued_buffer_count =

sGetMinUndequeuedBufferCount;

}

Qcamera2HWI.cpp

int QCamera2HardwareInterface::set_preview_window(struct camera_device *device,

struct preview_stream_ops *window)

{

hw->processAPI(QCAMERA_SM_EVT_SET_PREVIEW_WINDOW, (void *)window);

}

int QCamera2HardwareInterface::setPreviewWindow(

struct preview_stream_ops *window)

{

mPreviewWindow = window;

return NO_ERROR;

}

QCameraMemory *QCamera2HardwareInterface::allocateStreamBuf(

cam_stream_type_t stream_type, size_t size, int stride, int scanline,

uint8_t &bufferCnt)

{

grallocMemory->setWindowInfo(mPreviewWindow,

dim.width,dim.height, stride, scanline,

mParameters.getPreviewHalPixelFormat(),

maxFPS, usage);

}

QcameraMem.cpp

void QCameraGrallocMemory::setWindowInfo(preview_stream_ops_t *window,

int width, int height, int stride, int scanline, int format, int maxFPS, int usage)

{

mWindow = window;

mWidth = width;

mHeight = height;

mStride = stride;

mScanline = scanline;

mFormat = format;

mUsage = usage;

setMaxFPS(maxFPS);

}

接下来是preview内存的管理:

int QCameraGrallocMemory::allocate(uint8_t count, size_t /*size*/,

uint32_t /*isSecure*/)

{

//从显示模块的AnativeWindow获取buffer

mWindow->dequeue_buffer(mWindow, &mBufferHandle[cnt], &stride);

//将获取的buffer共享到camera

mMemInfo[cnt].main_ion_fd = open("/dev/ion", O_RDONLY);

ioctl(mMemInfo[cnt].main_ion_fd, ION_IOC_IMPORT, &ion_info_fd)

//获取buffer地址

mCameraMemory[cnt] = mGetMemory(mPrivateHandle[cnt]->fd,

(size_t)mPrivateHandle[cnt]->size,

1,

mCallbackCookie);

}

Qcamerastream.cpp

int32_t QCameraStream::mapNewBuffer(uint32_t index)

{

LOGH("E - index = %d", index);

int rc = NO_ERROR;

if (mStreamBufs == NULL) {

LOGE("Invalid Operation");

return INVALID_OPERATION;

}

ssize_t bufSize = mStreamBufs->getSize(index);

if (BAD_INDEX == bufSize) {

LOGE("Failed to retrieve buffer size (bad index)");

return INVALID_OPERATION;

}

cam_buf_map_type_list bufMapList;

rc = QCameraBufferMaps::makeSingletonBufMapList(

CAM_MAPPING_BUF_TYPE_STREAM_BUF, 0 /*stream id*/, index,

-1 /*plane index*/, 0 /*cookie*/, mStreamBufs->getFd(index),

bufSize, bufMapList, mStreamBufs->getPtr(index));

if (rc == NO_ERROR) {

rc = m_MemOpsTbl.bundled_map_ops(&bufMapList, m_MemOpsTbl.userdata);

}

if (rc < 0) {

LOGE("map_stream_buf failed: %d", rc);

rc = INVALID_OPERATION;

} else {// 类型mm_camera_buf_def_t *mBufDefs;

mStreamBufs->getBufDef(mFrameLenOffset, mBufDefs[index], index);

}

LOGH("X - rc = %d", rc);

return rc;

}

(0)

相关推荐