昨天刚好闪光灯弄过来,今天简单的做下总结。大概的说下,具体我也没有深入研究,不过效果确实是有了。
首先找到Android拍照的时候所执行的函数代码在:
packages/apps/Camera/src/com/android/camera/Camera.java
找到这个地方:
mCameraDevice.setParameters(mParameters);
mCameraDevice.takePicture(mShutterCallback, mRawPictureCallback,
mPostViewPictureCallback, new JpegPictureCallback(loc));
mPreviewing = false;
据我理解,这里就是拍照的时候所执行的,而这里应该是调用的camera库里的takepicture下面我们找到库文件:
device/samsung/proprietary/libcamera
库文件就在这里,下面我们进入SeccameraHWInterface.cpp文件查找takepicture如下:
status_t CameraHardwareSec::takePicture()
{
LOGV("%s :", __func__);
stopPreview();
Mutex::Autolock lock(mStateLock);
if (mCaptureInProgress) {
LOGE("%s : capture already in progress", __func__);
return INVALID_OPERATION;
}
if (mPictureThread->run("CameraPictureThread", PRIORITY_DEFAULT) != NO_ERROR) {
LOGE("%s : couldn't run picture thread", __func__);
return INVALID_OPERATION;
}
mCaptureInProgress = true;
return NO_ERROR;
}
里面的mPictureThread->run就是拍照的东西了,具体我就不分析了。接下来我们找下闪光灯的接口
在SecCamera.h里你会发现下面三个函数接口:
bool getFlashSupport(void);
int setFlashMode(int flash_mode);
int getFlashMode(void);
其中setFlashMode即为设置闪光灯的接口,找到这个函数
在SecCamera.cpp里如下:
int SecCamera::setFlashMode(int flash_mode)
{
LOGV("%s(flash_mode(%d))", __func__, flash_mode);
if (flash_mode <= FLASH_MODE_BASE || FLASH_MODE_MAX <= flash_mode) {
LOGE("ERR(%s):Invalid flash_mode (%d)", __func__, flash_mode);
return -1;
}
if (m_params->flash_mode != flash_mode) {
m_params->flash_mode = flash_mode;
if (m_flag_camera_start) {
if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_FLASH_MODE, flash_mode) < 0) {
LOGE("ERR(%s):Fail on V4L2_CID_CAMERA_FLASH_MODE", __func__);
return -1;
}
}
}
return 0;
}
这里又会调用fimc_v4l2_s_ctrl函数代码如下:
static int fimc_v4l2_s_ctrl(int fp, unsigned int id, unsigned int value)
{
struct v4l2_control ctrl;
int ret;
ctrl.id = id;
ctrl.value = value;
//LOGD("%s :--------------------------value is %d",__func__,value);//add dao
ret = ioctl(fp, VIDIOC_S_CTRL, &ctrl);
if (ret < 0) {
LOGE("ERR(%s):VIDIOC_S_CTRL(id = %#x (%d), value = %d) failed ret = %d\n",
__func__, id, id-V4L2_CID_PRIVATE_BASE, value, ret);
return ret;
}
return ctrl.value;
}
在这里进行了ioctl下面我们到内核里面去看看。
在内核下面的drivers/media/video/v4l2-ioctl.c有如下代码:
case VIDIOC_S_CTRL:
{
struct v4l2_control *p = arg;
struct v4l2_ext_controls ctrls;
struct v4l2_ext_control ctrl;
if (!ops->vidioc_s_ctrl && !ops->vidioc_s_ext_ctrls)
break;
dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value);
if (ops->vidioc_s_ctrl) {
ret = ops->vidioc_s_ctrl(file, fh, p);
break;
}
if (!ops->vidioc_s_ext_ctrls)
break;
ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
ctrls.count = 1;
ctrls.controls = &ctrl;
ctrl.id = p->id;
ctrl.value = p->value;
if (check_ext_ctrls(&ctrls, 1))
ret = ops->vidioc_s_ext_ctrls(file, fh, &ctrls);
break;
}