高通 mm_qcamera_app test 学习2
交叉编译mm_camera_test成功后,开始重点学习这个APP实现的过程
mm_camera_lib_handle的句柄如下
typedef struct {
mm_camera_app_t app_ctx;
mm_camera_test_obj_t test_obj;
mm_camera_lib_params current_params;
int stream_running;
tuningserver_t tsctrl;
} mm_camera_lib_ctx;
这个函数实现发送指令和相关设置参数德功能
int mm_camera_lib_send_command(mm_camera_lib_handle *handle,
mm_camera_lib_commands cmd,
void *in_data,
__unused void *out_data)
{
uint32_t width, height;
int rc = MM_CAMERA_OK;
cam_capability_t *camera_cap = NULL;
mm_camera_lib_snapshot_params *dim = NULL;
if ( NULL == handle ) {
LOGE(" Invalid handle");
rc = MM_CAMERA_E_INVALID_INPUT;
goto EXIT;
}
camera_cap = (cam_capability_t *) handle->test_obj.cap_buf.mem_info.data;/* capability struct definition for HAL 1 在HAL层实现了一些iso 自动曝光的开关设置 这里进行获取*/
switch(cmd) {
case MM_CAMERA_LIB_FPS_RANGE:
if ( NULL != in_data ) {
cam_fps_range_t range = *(( cam_fps_range_t * )in_data);
rc = setFPSRange(&handle->test_obj, range);
if (rc != MM_CAMERA_OK) {
LOGE("setFPSRange() err=%d\n",
rc);
goto EXIT;
}
}
break;
case MM_CAMERA_LIB_EZTUNE_ENABLE://tuning使能
if ( NULL != in_data) {
int enable_eztune = *(( int * )in_data);
if ( ( enable_eztune != handle->test_obj.enable_EZTune) &&
handle->stream_running ) {
rc = mm_camera_lib_stop_stream(handle);
if (rc != MM_CAMERA_OK) {
LOGE("mm_camera_lib_stop_stream() err=%d\n",
rc);
goto EXIT;
}
handle->test_obj.enable_EZTune= enable_eztune;
rc = mm_camera_lib_start_stream(handle);
if (rc != MM_CAMERA_OK) {
LOGE("mm_camera_lib_start_stream() err=%d\n",
rc);
goto EXIT;
}
} else {
handle->test_obj.enable_EZTune= enable_eztune;
}
}
break;
case MM_CAMERA_LIB_IRMODE://ir mode
if ( NULL != in_data) {
int enable_ir = *(( int * )in_data);
if (enable_ir != handle->test_obj.enable_ir) {
handle->test_obj.enable_ir = enable_ir;
rc = setIRMode(&handle->test_obj, enable_ir);
if (rc != MM_CAMERA_OK) {
LOGE("setZoom() err=%d\n",
rc);
goto EXIT;
}
}
}
break;
case MM_CAMERA_LIB_SHDR_MODE://动态模式
if ( NULL != in_data) {
int enable_shdr= *(( int * )in_data);
if (enable_shdr != handle->test_obj.enable_ir) {
handle->test_obj.enable_ir = enable_shdr;
rc = setsHDRMode(&handle->test_obj, enable_shdr);
if (rc != MM_CAMERA_OK) {
LOGE("setHDR() err=%d\n",
rc);
goto EXIT;
}
}
}
break;
case MM_CAMERA_LIB_FLASH:
if ( NULL != in_data ) {
cam_flash_mode_t flash = *(( int * )in_data);
rc = setFlash(&handle->test_obj, flash);
if (rc != MM_CAMERA_OK) {
LOGE("setFlash() err=%d\n",
rc);
goto EXIT;
}
}
break;
case MM_CAMERA_LIB_SPL_EFFECT:
if (NULL != in_data) {
cam_effect_mode_type effect = *(( int * )in_data);
rc = setEffect(&handle->test_obj, effect);
if (rc != MM_CAMERA_OK) {
LOGE("setEffect() err=%d\n",
rc);
goto EXIT;
}
}
break;
case MM_CAMERA_LIB_BESTSHOT:
if ( NULL != in_data ) {
cam_scene_mode_type scene = *(( int * )in_data);
rc = setScene(&handle->test_obj, scene);
if (rc != MM_CAMERA_OK) {
LOGE("setScene() err=%d\n",
rc);
goto EXIT;
}
}
break;
case MM_CAMERA_LIB_ZOOM://放大
if ( NULL != in_data ) {
int zoom = *(( int * )in_data);
rc = setZoom(&handle->test_obj, zoom);
if (rc != MM_CAMERA_OK) {
LOGE("setZoom() err=%d\n",
rc);
goto EXIT;
}
}
break;
case MM_CAMERA_LIB_ISO://iso设置
if ( NULL != in_data ) {
cam_iso_mode_type iso = *(( int * )in_data);
rc = setISO(&handle->test_obj, iso);
if (rc != MM_CAMERA_OK) {
LOGE("setISO() err=%d\n",
rc);
goto EXIT;
}
}
break;
case MM_CAMERA_LIB_SHARPNESS:
if ( NULL != in_data ) {
int sharpness = *(( int * )in_data);
rc = setSharpness(&handle->test_obj, sharpness);
if (rc != MM_CAMERA_OK) {
LOGE("setSharpness() err=%d\n",
rc);
goto EXIT;
}
}
break;
case MM_CAMERA_LIB_SATURATION:
if ( NULL != in_data ) {
int saturation = *(( int * )in_data);
rc = setSaturation(&handle->test_obj, saturation);
if (rc != MM_CAMERA_OK) {
LOGE("setSaturation() err=%d\n",
rc);
goto EXIT;
}
}
break;
case MM_CAMERA_LIB_CONTRAST:
if ( NULL != in_data ) {
int contrast = *(( int * )in_data);
rc = setContrast(&handle->test_obj, contrast);
if (rc != MM_CAMERA_OK) {
LOGE("setContrast() err=%d\n",
rc);
goto EXIT;
}
}
break;
case MM_CAMERA_LIB_SET_TINTLESS:
if ( NULL != in_data ) {
int tintless = *(( int * )in_data);
rc = setTintless(&handle->test_obj, tintless);
if (rc != MM_CAMERA_OK) {
LOGE("enlabe/disable:%d tintless() err=%d\n",
tintless, rc);
goto EXIT;
}
}
break;
case MM_CAMERA_LIB_BRIGHTNESS:
if ( NULL != in_data ) {
int brightness = *(( int * )in_data);
rc = setBrightness(&handle->test_obj, brightness);
if (rc != MM_CAMERA_OK) {
LOGE("setBrightness() err=%d\n",
rc);
goto EXIT;
}
}
break;
case MM_CAMERA_LIB_EXPOSURE_METERING://baoguang
if ( NULL != in_data ) {
cam_auto_exposure_mode_type exp = *(( int * )in_data);
rc = setExposureMetering(&handle->test_obj, exp);
if (rc != MM_CAMERA_OK) {
LOGE("setExposureMetering() err=%d\n",
rc);
goto EXIT;
}
}
break;
case MM_CAMERA_LIB_MN_WB:
if ( NULL != in_data ) {
cam_manual_wb_parm_t *manual_info = (( cam_manual_wb_parm_t* )in_data);
rc = setManualWhiteBalance(&handle->test_obj, manual_info);
if (rc != MM_CAMERA_OK) {
LOGE("etManualWhiteBalance() err=%d\n",
rc);
goto EXIT;
}
}
break;
case MM_CAMERA_LIB_WB:
if ( NULL != in_data ) {
cam_wb_mode_type wb = *(( int * )in_data);
rc = setWhiteBalance(&handle->test_obj, wb);
if (rc != MM_CAMERA_OK) {
LOGE("setWhiteBalance() err=%d\n",
rc);
goto EXIT;
}
}
break;
case MM_CAMERA_LIB_ANTIBANDING:
if ( NULL != in_data ) {
int antibanding = *(( int * )in_data);
rc = setAntibanding(&handle->test_obj, antibanding);
if (rc != MM_CAMERA_OK) {
LOGE("setAntibanding() err=%d\n",
rc);
goto EXIT;
}
}
break;
case MM_CAMERA_LIB_FLIP:
if ( NULL != in_data ) {
int mode = *(( int * )in_data);
rc = setFlipMode(&handle->test_obj, mode);
if (rc != MM_CAMERA_OK) {
LOGE("setFlipMode() err=%d\n",
rc);
goto EXIT;
}
}
break;
case MM_CAMERA_LIB_EV:
if ( NULL != in_data ) {
int ev = *(( int * )in_data);
rc = setEVCompensation(&handle->test_obj, ev);
if (rc != MM_CAMERA_OK) {
LOGE("setEVCompensation() err=%d\n",
rc);
goto EXIT;
}
}
break;
case MM_CAMERA_LIB_ZSL_ENABLE:
if ( NULL != in_data) {
dim = ( mm_camera_lib_snapshot_params * ) in_data;
if ( ( dim->isZSL!= handle->test_obj.zsl_enabled ) &&
handle->stream_running ) {
rc = mm_camera_lib_stop_stream(handle);
if (rc != MM_CAMERA_OK) {
LOGE("mm_camera_lib_stop_stream() err=%d\n",
rc);
goto EXIT;
}
handle->test_obj.zsl_enabled = dim->isZSL;
handle->test_obj.buffer_width = dim->width;
handle->test_obj.buffer_height = dim->height;
rc = mm_camera_lib_start_stream(handle);
if (rc != MM_CAMERA_OK) {
LOGE("mm_camera_lib_start_stream() err=%d\n",
rc);
goto EXIT;
}
} else {
handle->test_obj.zsl_enabled = dim->isZSL;
}
}
break;
case MM_CAMERA_LIB_RAW_CAPTURE:
if ( 0 == handle->stream_running ) {
LOGE(" Streaming is not enabled!");
rc = MM_CAMERA_E_INVALID_OPERATION;
goto EXIT;
}
rc = mm_camera_lib_stop_stream(handle);
if (rc != MM_CAMERA_OK) {
LOGE("mm_camera_lib_stop_stream() err=%d\n",
rc);
goto EXIT;
}
width = handle->test_obj.buffer_width;
height = handle->test_obj.buffer_height;
handle->test_obj.buffer_width =
(uint32_t)camera_cap->raw_dim[0].width;
handle->test_obj.buffer_height =
(uint32_t)camera_cap->raw_dim[0].height;
handle->test_obj.buffer_format = DEFAULT_RAW_FORMAT;
LOGE("MM_CAMERA_LIB_RAW_CAPTURE %dx%d\n",
camera_cap->raw_dim[0].width,
camera_cap->raw_dim[0].height);
rc = mm_app_start_capture_raw(&handle->test_obj, 1);
if (rc != MM_CAMERA_OK) {
LOGE("mm_app_start_capture() err=%d\n",
rc);
goto EXIT;
}
mm_camera_app_wait();
rc = mm_app_stop_capture_raw(&handle->test_obj);
if (rc != MM_CAMERA_OK) {
LOGE("mm_app_stop_capture() err=%d\n",
rc);
goto EXIT;
}
handle->test_obj.buffer_width = width;
handle->test_obj.buffer_height = height;
handle->test_obj.buffer_format = DEFAULT_SNAPSHOT_FORMAT;
rc = mm_camera_lib_start_stream(handle);
if (rc != MM_CAMERA_OK) {
LOGE("mm_camera_lib_start_stream() err=%d\n",
rc);
goto EXIT;
}
break;
case MM_CAMERA_LIB_JPEG_CAPTURE:
if ( 0 == handle->stream_running ) {
LOGE(" Streaming is not enabled!");
rc = MM_CAMERA_E_INVALID_OPERATION;
goto EXIT;
}
if ( NULL != in_data ) {
dim = ( mm_camera_lib_snapshot_params * ) in_data;
}
rc = tuneserver_capture(handle, dim);
if (rc != MM_CAMERA_OK) {
LOGE("capture error %d\n", rc);
goto EXIT;
}
break;
case MM_CAMERA_LIB_SET_FOCUS_MODE: {
cam_focus_mode_type mode = *((cam_focus_mode_type *)in_data);
handle->current_params.af_mode = mode;
rc = setFocusMode(&handle->test_obj, mode);
if (rc != MM_CAMERA_OK) {
LOGE("autofocus error\n");
goto EXIT;
}
break;
}
case MM_CAMERA_LIB_DO_AF:
if (handle->test_obj.focus_supported) {
rc = handle->test_obj.cam->ops->do_auto_focus(handle->test_obj.cam->camera_handle);
if (rc != MM_CAMERA_OK) {
LOGE("autofocus error\n");
goto EXIT;
}
/*Waiting for Auto Focus Done Call Back*/
mm_camera_app_wait();
}
break;
case MM_CAMERA_LIB_CANCEL_AF:
rc = handle->test_obj.cam->ops->cancel_auto_focus(handle->test_obj.cam->camera_handle);
if (rc != MM_CAMERA_OK) {
LOGE("autofocus error\n");
goto EXIT;
}
break;
case MM_CAMERA_LIB_LOCK_AWB:
rc = setAwbLock(&handle->test_obj, 1);
if (rc != MM_CAMERA_OK) {
LOGE("AWB locking failed\n");
goto EXIT;
}
break;
case MM_CAMERA_LIB_UNLOCK_AWB:
rc = setAwbLock(&handle->test_obj, 0);
if (rc != MM_CAMERA_OK) {
LOGE("AE unlocking failed\n");
goto EXIT;
}
break;
case MM_CAMERA_LIB_LOCK_AE:
rc = setAecLock(&handle->test_obj, 1);
if (rc != MM_CAMERA_OK) {
LOGE("AE locking failed\n");
goto EXIT;
}
break;
case MM_CAMERA_LIB_UNLOCK_AE:
rc = setAecLock(&handle->test_obj, 0);
if (rc != MM_CAMERA_OK) {
LOGE("AE unlocking failed\n");
goto EXIT;
}
break;
case MM_CAMERA_LIB_SET_3A_COMMAND: {
rc = set3Acommand(&handle->test_obj, (cam_eztune_cmd_data_t *)in_data);
if (rc != MM_CAMERA_OK) {
LOGE("3A set command error\n");
goto EXIT;
}
break;
}
case MM_CAMERA_LIB_SET_AUTOFOCUS_TUNING: {
rc = setAutoFocusTuning(&handle->test_obj, in_data);
if (rc != MM_CAMERA_OK) {
LOGE("Set AF tuning failed\n");
goto EXIT;
}
break;
}
case MM_CAMERA_LIB_SET_VFE_COMMAND: {
rc = setVfeCommand(&handle->test_obj, in_data);
if (rc != MM_CAMERA_OK) {
LOGE("Set vfe command failed\n");
goto EXIT;
}
break;
}
case MM_CAMERA_LIB_SET_POSTPROC_COMMAND: {
rc = setPPCommand(&handle->test_obj, in_data);
if (rc != MM_CAMERA_OK) {
LOGE("Set pp command failed\n");
goto EXIT;
}
break;
}
case MM_CAMERA_LIB_WNR_ENABLE: {
rc = setWNR(&handle->test_obj, *((uint8_t *)in_data));
if ( rc != MM_CAMERA_OK) {
LOGE("Set wnr enable failed\n");
goto EXIT;
}
}
case MM_CAMERA_LIB_NO_ACTION:
default:
break;
};
EXIT:
return rc;
}
通过case实现功能设置,实际上这里通过lib调用hal层的接口实现。
我们看拍照的接口
/** tuneserver_capture
* @lib_handle: the camera handle object
* @dim: snapshot dimensions
*
* makes JPEG capture
*
* Return: >=0 on success, -1 on failure.
**/
int tuneserver_capture(mm_camera_lib_handle *lib_handle,
mm_camera_lib_snapshot_params *dim)
{
int rc = 0;
printf("Take jpeg snapshot\n");
if ( lib_handle->stream_running ) {//先判断是否有视频流
if ( lib_handle->test_obj.zsl_enabled) {
if ( NULL != dim) {
if ( ( lib_handle->test_obj.buffer_width != dim->width) ||
( lib_handle->test_obj.buffer_height = dim->height ) ) {
lib_handle->test_obj.buffer_width = dim->width;
lib_handle->test_obj.buffer_height = dim->height;
rc = mm_camera_lib_stop_stream(lib_handle);
if (rc != MM_CAMERA_OK) {
LOGE("mm_camera_lib_stop_stream() err=%d\n",
rc);
goto EXIT;
}
rc = mm_camera_lib_start_stream(lib_handle);
if (rc != MM_CAMERA_OK) {
LOGE("mm_camera_lib_start_stream() err=%d\n",
rc);
goto EXIT;
}
}
}
lib_handle->test_obj.encodeJpeg = 1;
mm_camera_app_wait();
} else {
// For standard 2D capture streaming has to be disabled first
rc = mm_camera_lib_stop_stream(lib_handle);
if (rc != MM_CAMERA_OK) {
LOGE("mm_camera_lib_stop_stream() err=%d\n",
rc);
goto EXIT;
}
if ( NULL != dim ) {
lib_handle->test_obj.buffer_width = dim->width;
lib_handle->test_obj.buffer_height = dim->height;
}
rc = mm_app_start_capture(&lib_handle->test_obj, 1);
if (rc != MM_CAMERA_OK) {
LOGE("mm_app_start_capture() err=%d\n",
rc);
goto EXIT;
}
mm_camera_app_wait();
rc = mm_app_stop_capture(&lib_handle->test_obj);
if (rc != MM_CAMERA_OK) {
LOGE("mm_app_stop_capture() err=%d\n",
rc);
goto EXIT;
}
// Restart streaming after capture is done
rc = mm_camera_lib_start_stream(lib_handle);
if (rc != MM_CAMERA_OK) {
LOGE("mm_camera_lib_start_stream() err=%d\n",
rc);
goto EXIT;
}
}
}
EXIT:
return rc;
}
int mm_app_start_capture(mm_camera_test_obj_t *test_obj,
uint8_t num_snapshots)
{
int32_t rc = MM_CAMERA_OK;
mm_camera_channel_t *channel = NULL;
mm_camera_stream_t *s_main = NULL;
mm_camera_stream_t *s_post = NULL;
mm_camera_channel_attr_t attr;
memset(&attr, 0, sizeof(mm_camera_channel_attr_t));
attr.notify_mode = MM_CAMERA_SUPER_BUF_NOTIFY_CONTINUOUS;
attr.max_unmatched_frames = 3;
channel = mm_app_add_channel(test_obj,
MM_CHANNEL_TYPE_CAPTURE,
&attr,
mm_app_snapshot_notify_cb,
test_obj);
if (NULL == channel) {
LOGE(" add channel failed");
return -MM_CAMERA_E_GENERAL;
}
s_main = mm_app_add_snapshot_stream(test_obj,
channel,
mm_app_snapshot_notify_cb,
(void *)test_obj,
CAPTURE_BUF_NUM,
num_snapshots);
if (NULL == s_main) {
LOGE(" add main snapshot stream failed\n");
mm_app_del_channel(test_obj, channel);
return rc;
}
s_post = mm_app_add_postview_stream(test_obj,
channel,
NULL,
NULL,
CAPTURE_BUF_NUM,
num_snapshots);
if (NULL == s_main) {
LOGE(" add main postview stream failed\n");
mm_app_del_channel(test_obj, channel);
return rc;
}
rc = mm_app_start_channel(test_obj, channel);
if (MM_CAMERA_OK != rc) {
LOGE("start zsl failed rc=%d\n", rc);
mm_app_del_stream(test_obj, channel, s_main);
mm_app_del_channel(test_obj, channel);
return rc;
}
return rc;
}