Exemple #1
0
cmr_int cmr_sensor_deinit(cmr_handle sensor_handle)
{
	CMR_LOGI("E");
	cmr_int             ret = CMR_CAMERA_SUCCESS;
	struct cmr_sensor_handle  *handle = (struct cmr_sensor_handle *)sensor_handle;

	if (!sensor_handle) {
		CMR_LOGE("X Invalid param!");
		return CMR_CAMERA_INVALID_PARAM;
	}

	/*destory thread*/
	ret = cmr_sns_destroy_thread(handle);
	if (ret) {
		CMR_LOGE("destory thread failed!");
		ret = CMR_CAMERA_FAIL;
		goto deinit_end;
	}

	/*release handle*/
	if (handle) {
		free(handle);
		handle = NULL;
	}

deinit_end:
	CMR_LOGI("X ret %ld", ret);
	return ret;
}
Exemple #2
0
cmr_int cmr_sensor_open(cmr_handle sensor_handle, cmr_u32 sensor_id_bits)
{
	CMR_MSG_INIT(message);
	cmr_int                   ret = CMR_CAMERA_SUCCESS;
	struct cmr_sensor_handle  *handle = (struct cmr_sensor_handle *)sensor_handle;
	cmr_u32                   cameraId = 0;
	CMR_LOGI("E");

	CHECK_HANDLE_VALID(handle);

	/*the open&close function should be sync*/
	message.msg_type     = CMR_SENSOR_EVT_OPEN;
	message.sync_flag    = CMR_MSG_SYNC_PROCESSED;
	message.data         = (void*)((unsigned long)sensor_id_bits);
	ret = cmr_thread_msg_send(handle->thread_cxt.thread_handle, &message);
	if (ret) {
		CMR_LOGE("X send msg failed!");
		return CMR_CAMERA_FAIL;
	} else {
		for (cameraId = 0; cameraId < CAMERA_ID_MAX; cameraId++) {
			if (sensor_id_bits & (1 << cameraId)) {
				break;
			}
		}
		if (handle->sensor_cxt[cameraId].fd_sensor == CMR_CAMERA_FD_INIT) {
			CMR_LOGE("camera %d open fail!", cameraId);
			ret = CMR_CAMERA_FAIL;
		}
	}
	CMR_LOGI("X ret %ld", ret);
	return ret;
}
int camera_set_sensormark(void)
{
	FILE                     *fp;
	uint32_t                 i = 0;
	uint32_t                 len = 0;
	uint8_t                  sensor_param[SENSOR_PARAM_NUM];
	int                      ret = CAMERA_SUCCESS;

	bzero(&sensor_param[0], sizeof(sensor_param));
	fp = fopen(SENSOR_PARA, "rb+");
	if (NULL == fp) {
		fp = fopen(SENSOR_PARA,"wb+");
		if (NULL == fp) {
			CMR_LOGE("open file error: %s",SENSOR_PARA);
		}
		memset(&sensor_param[0], 0xFF, SENSOR_PARAM_NUM);
	}

	if (NULL != fp) {
		len = fread(sensor_param, 1, SENSOR_PARAM_NUM, fp);
		CMR_LOGI(":param len %d", len);
		CMR_LOGI("sensor param: %d, %d, %d, %d, %d, %d, %d, %d",
			sensor_param[0], sensor_param[1], sensor_param[2], sensor_param[3],
			sensor_param[4], sensor_param[5], sensor_param[6], sensor_param[7]);
		fclose(fp);
	}

	Sensor_SetMark(sensor_param);

	return CAMERA_SUCCESS;
}
Exemple #4
0
/**---------------------------------------------------------------------------*
 **                         Local Functions Contents                          *
 **---------------------------------------------------------------------------*/
cmr_int cmr_sns_create_thread(struct cmr_sensor_handle *handle)
{
	CMR_MSG_INIT(message);
	cmr_int                  ret = CMR_CAMERA_SUCCESS;

	CHECK_HANDLE_VALID(handle);

	CMR_LOGI("is_inited %ld", handle->thread_cxt.is_inited);

	if (!handle->thread_cxt.is_inited) {
		ret = cmr_thread_create(&handle->thread_cxt.thread_handle,
					SENSOR_MSG_QUEUE_SIZE,
					cmr_sns_thread_proc,
					(void*)handle);
	}

end:
	if (ret) {
		handle->thread_cxt.is_inited = 0;
	} else {
		handle->thread_cxt.is_inited = 1;
	}

	CMR_LOGI("ret %ld", ret);
	return ret;
}
Exemple #5
0
cmr_int cmr_sensor_update_isparm_from_file(cmr_handle sensor_handle, cmr_uint sensor_id)
{
	CMR_MSG_INIT(message);
	cmr_int                  ret = CMR_CAMERA_SUCCESS;
	struct cmr_sensor_handle *handle = (struct cmr_sensor_handle *)sensor_handle;
	CMR_LOGI("E");

	CHECK_HANDLE_VALID(handle);

	ret = sensor_update_isparm_from_file(&handle->sensor_cxt[sensor_id], sensor_id);

#if 0
	message.msg_type     = CMR_SENSOR_EVT_ISPARAM_FROM_FILE;
	message.sub_msg_type = sensor_id;
	message.sync_flag    = CMR_MSG_SYNC_PROCESSED;
	ret = cmr_thread_msg_send(handle->thread_cxt.thread_handle, &message);
	if (ret) {
		CMR_LOGE("X send msg failed!");
		return CMR_CAMERA_FAIL;
	}
#endif
	CMR_LOGI("X ret %ld", ret);

	return ret;
}
static void getSecondsFromDouble(double d, uint32_t *numerator, uint32_t *denominator)
{
	d = fabs(d);
	double degrees = (int)d;
	double remainder = d - degrees;
	double minutes = (int)(remainder * 60.0);
	double seconds = (((remainder * 60.0) - minutes) * 60.0);
	uint32_t i = 0;
	uint32_t j = 0;
	uint32_t num = 0;
	char str[20];
	double value=1.0;

	sprintf(str,"%f",seconds);
	while(str[i++]!='.')
		;
	j = strlen(str)-1;
	while(str[j] == '0')
		--j;
	num = j - i + 1;
	CMR_LOGI("%s, i=%d, j=%d, num=%d \n", str, i, j, num);

	for (i=0; i<num; i++)
		value *=10.0;

	*numerator = seconds*value;
	*denominator = value;

	CMR_LOGI("data=%f, num=%d, denom=%d \n", seconds, *numerator, *denominator);
}
Exemple #7
0
/**---------------------------------------------------------------------------*
 **                         External Functions                                *
 **---------------------------------------------------------------------------*/
 cmr_int cmr_sensor_init(struct sensor_init_param *init_param_ptr, cmr_handle *sensor_handle)
{
	cmr_int             ret = CMR_CAMERA_SUCCESS;
	struct cmr_sensor_handle  *handle = NULL;
	CMR_LOGI("E");

	if (!init_param_ptr) {
		CMR_LOGE("Invalid param!");
		return CMR_CAMERA_INVALID_PARAM;
	}

	handle = (struct cmr_sensor_handle *)malloc(sizeof(struct cmr_sensor_handle));
	if (!handle) {
		CMR_LOGE("No mem!");
		return CMR_CAMERA_NO_MEM;
	}
	cmr_bzero(handle, sizeof(struct cmr_sensor_handle));

	/*save init param*/
	handle->oem_handle   = init_param_ptr->oem_handle;
	handle->sensor_bits  = init_param_ptr->sensor_bits;
	handle->private_data = init_param_ptr->private_data;
	handle->is_autotest  = init_param_ptr->is_autotest;
	CMR_LOGD("oem_handle: 0x%lx, sensor_bits: %ld, private_data: 0x%lx autotest %ld",
		(cmr_uint)handle->oem_handle, handle->sensor_bits, (cmr_uint)handle->private_data, handle->is_autotest);

	/*create thread*/
	ret = cmr_sns_create_thread(handle);
	if (ret) {
		CMR_LOGE("create thread failed!");
		ret = CMR_CAMERA_FAIL;
		goto init_end;
	}

	/*return handle*/
	*sensor_handle = (cmr_handle)handle;
	CMR_LOGI("handle 0x%lx created!", (cmr_uint)handle);

init_end:
	if (ret) {
		if (handle) {
			free(handle);
			handle = NULL;
		}
	}

	CMR_LOGV("X ret %ld", ret);
	return ret;
}
Exemple #8
0
cmr_int cmr_sns_close(struct cmr_sensor_handle *handle, cmr_u32 sensor_id_bits)
{
	cmr_int       ret = CMR_CAMERA_SUCCESS;
	cmr_u32       cameraId = 0;
	cmr_u32       cameraCnt = 0;

	CHECK_HANDLE_VALID(handle);

	/*close all signed camera sensor*/
	for (cameraId = 0; cameraId < CAMERA_ID_MAX; cameraId++) {
		if (0 != (sensor_id_bits & (1 << cameraId))) {
			ret = sensor_close_common(&handle->sensor_cxt[cameraId], cameraId);
			if (ret) {
				CMR_LOGE("camera %u open failed!", cameraId);
			} else {
				handle->sensor_bits &= ~(1 << cameraId);
				CMR_LOGI("close sensor ok");
				/*cmr_sns_af_init(&handle->sensor_cxt[cameraId]);*/
			}
		}
	}

	if (!handle->sensor_bits) {
		/*when all sensors are closed, the monitor and focus move thread should be returned off*/
		cmr_sns_kill_fmove_thread(handle);
		cmr_sns_kill_monitor_thread(handle);
	}
	/*todo, if close not success, how to handle the issue*/

	return ret;
}
Exemple #9
0
static cmr_int cmr_sns_fmove_proc(void *p_data)
{
	cmr_u32                   ret = CMR_CAMERA_SUCCESS;
	cmr_u32                   i = 0, cnt = 0;
	struct cmr_sensor_handle  *sensor_handle = (struct cmr_sensor_handle *)p_data;

	while (1) {
		CHECK_HANDLE_VALID(sensor_handle);
		usleep(10000);

		if (sensor_handle->fmove_thread_cxt.is_exit) {
			sensor_handle->fmove_thread_cxt.is_exit = 0;
			CMR_LOGI("EXIT !");
			break;
		}

		cnt ++;
		if (cnt >= SENSOR_CHECK_STATUS_INTERVAL) {
			cnt = 0;
			for (i = 0; i < CAMERA_ID_MAX; i++) {
				if (0 != ( sensor_handle->sensor_bits & (1<<i))) {
/*					CMR_LOGV("valid camera id =%d",i);*/
					cmr_sns_check_fmove(sensor_handle, i);
				}
			}
		}
	}

	return ret;
}
Exemple #10
0
static cmr_int cmr_sns_monitor_proc(void *p_data)
{
	cmr_u32                 ret = CMR_CAMERA_SUCCESS;
	cmr_u32                 i = 0, cnt = 0;
	struct cmr_sensor_handle  *sensor_handle = (struct cmr_sensor_handle *)p_data;

	while (1) {
		if (!sensor_handle) {
			CMR_LOGE("sensor_handle is NULL");
			return CMR_CAMERA_INVALID_PARAM;
		}
		usleep(10000);

		if (sensor_handle->monitor_thread_cxt.is_exit) {
			sensor_handle->monitor_thread_cxt.is_exit = 0;
			CMR_LOGI("EXIT!");
			break;
		}

		cnt ++;
		if (cnt >= SENSOR_CHECK_STATUS_INTERVAL) {
			cnt = 0;
			for (i = 0; i < CAMERA_ID_MAX; i++) {
				if (0 != ((1 << i) & sensor_handle->sensor_bits)) {
					cmr_sns_check_err(sensor_handle, i);
				}
			}
		}
	}

	return ret;
}
int camera_save_sensormark(void)
{
	FILE                     *fp;
	uint32_t                 i = 0;
	uint8_t                  is_saving= 0;
	uint8_t                  sensor_param[SENSOR_PARAM_NUM];
	int                      ret = CAMERA_SUCCESS;

	memset(&sensor_param[0], 0, SENSOR_PARAM_NUM);

	Sensor_GetMark(sensor_param, &is_saving);

	if (is_saving) {
		fp = fopen(SENSOR_PARA,"wb+");
		if (NULL != fp) {
			fwrite(sensor_param, 1, SENSOR_PARAM_NUM, fp);
			CMR_LOGI("sensor param: %d, %d, %d, %d, %d, %d, %d, %d",
				sensor_param[0], sensor_param[1], sensor_param[2], sensor_param[3],
				sensor_param[4], sensor_param[5], sensor_param[6], sensor_param[7]);
			fclose(fp);

		} else {
			CMR_LOGW("can not create SENSOR_PARA");
		}
	}

	return ret;
}
Exemple #12
0
cmr_int camera_get_trim_rect2(struct img_rect *src_trim_rect, float zoom_ratio, float dst_ratio,
											cmr_u32 sensor_w, cmr_u32 sensor_h, cmr_u8 rot)//for hal2.0 calculate crop again
{
	cmr_u32                  trim_width;
	cmr_u32                  trim_height;
	float                    minOutputRatio;
	float                    zoom_width, zoom_height, sensor_ratio;

	if (NULL == src_trim_rect) {
		CMR_LOGE("param error");
		return -CMR_CAMERA_INVALID_PARAM;
	} else if (src_trim_rect->width == 0 || src_trim_rect->height == 0) {
		CMR_LOGE("0x%lx w %d h %d", (cmr_uint)src_trim_rect, src_trim_rect->width, src_trim_rect->height);
		return -CMR_CAMERA_INVALID_PARAM;
	}
	minOutputRatio = dst_ratio;
	sensor_ratio = (float)sensor_w / (float)sensor_h;
	if (rot != IMG_ANGLE_0 && rot != IMG_ANGLE_180) {
		minOutputRatio = 1 / minOutputRatio;
	}
	if (minOutputRatio > sensor_ratio) {
		zoom_width = (float)sensor_w / zoom_ratio;
		zoom_height = zoom_width / minOutputRatio;
	} else {
		zoom_height = (float)sensor_h / zoom_ratio;
		zoom_width = zoom_height * minOutputRatio;
	}
	trim_width = (cmr_u32)zoom_width;
	trim_height = (cmr_u32)zoom_height;
	CMR_LOGI("sensor_ratio %f, minOutputRatio %f, zoom_ratio %f", sensor_ratio, minOutputRatio, zoom_ratio);
	CMR_LOGI("trim_width %d, trim_height %d", trim_width, trim_height);

	src_trim_rect->start_x += (src_trim_rect->width - trim_width) >> 1;
	src_trim_rect->start_y += (src_trim_rect->height - trim_height) >> 1;
	src_trim_rect->start_x = CAMERA_WIDTH(src_trim_rect->start_x);
	src_trim_rect->start_y = CAMERA_HEIGHT(src_trim_rect->start_y);
	src_trim_rect->width = CAMERA_WIDTH(trim_width);
	src_trim_rect->height = CAMERA_HEIGHT(trim_height);
	CMR_LOGI("zoom_level %f trim rect %d %d %d %d",
			zoom_ratio,
			src_trim_rect->start_x,
			src_trim_rect->start_y,
			src_trim_rect->width,
			src_trim_rect->height);

	return CMR_CAMERA_SUCCESS;
}
int camera_cap_path_done(struct camera_context *p_cxt)
{
	int                      ret = CAMERA_SUCCESS;
	int                      tmpval = 0;

	sem_post(&p_cxt->cap_path_sem);
	sem_getvalue(&p_cxt->cap_path_sem, &tmpval);
	CMR_LOGI("post cap path sem, val = %d", tmpval);
	return ret;
}
Exemple #14
0
static cmr_int cmr_sns_af_init(struct sensor_drv_context *sensor_cxt)
{
	SENSOR_EXT_FUN_PARAM_T   af_param;
	cmr_int                  ret = CMR_CAMERA_SUCCESS;

	CMR_LOGI("Enter");

	SENSOR_DRV_CHECK_ZERO(sensor_cxt);

	af_param.cmd = SENSOR_EXT_FUNC_INIT;
	af_param.param = SENSOR_EXT_FOCUS_TRIG;
	ret = cmr_sns_ioctl(sensor_cxt, SENSOR_FOCUS, (cmr_uint)&af_param);
	if (ret) {
		CMR_LOGE("Failed to init AF");
	} else {
		CMR_LOGI("OK to init auto focus");
	}

	return ret;
}
int camera_wait_cap_path(struct camera_context *p_cxt)
{
	int                      ret = CAMERA_SUCCESS;
	int                      tmpval = 0;
	struct camera_context    *cxt = camera_get_cxt();

	sem_wait(&p_cxt->cap_path_sem);
	sem_getvalue(&p_cxt->cap_path_sem, &tmpval);
	CMR_LOGI("got cap path sem, val = %d", tmpval);
	ret = cxt->err_code;
	return ret;
}
/****************************************************************************
* FunctionName: imx328_otp_set_i2c_address;
* Description : set i2c address.
* Input       : NA;
* Output      : NA;
* ReturnValue : 
                -EFAULT Set FAIL;
* Other       : NA;
***************************************************************************/
static int imx328_otp_set_i2c_address(struct msm_sensor_ctrl_t * s_ctrl,uint16_t i2c_addr,enum msm_camera_i2c_reg_addr_type addr_type)
{
    int rc = 0;

    CMR_LOGI("%s enter! i2c_addr = 0x%x.\n",__func__,i2c_addr);

    s_ctrl->sensor_i2c_client->addr_type = addr_type;

    if (s_ctrl->sensor_i2c_client->cci_client)
    {
        s_ctrl->sensor_i2c_client->cci_client->sid = (i2c_addr >> 1);
    }
Exemple #17
0
cmr_int cmr_sensor_close(cmr_handle sensor_handle, cmr_u32 sensor_id_bits)
{
	CMR_MSG_INIT(message);
	cmr_int             ret = CMR_CAMERA_SUCCESS;
	struct cmr_sensor_handle  *handle = (struct cmr_sensor_handle *)sensor_handle;
	CMR_LOGI("E");

	CHECK_HANDLE_VALID(handle);

	/*the open&close function should be sync*/
	message.msg_type     = CMR_SENSOR_EVT_CLOSE;
	message.sync_flag    = CMR_MSG_SYNC_PROCESSED;
	message.data         = (void*)((unsigned long)sensor_id_bits);
	ret = cmr_thread_msg_send(handle->thread_cxt.thread_handle, &message);
	if (ret) {
		CMR_LOGE("X send msg failed!");
		return CMR_CAMERA_FAIL;
	}
	CMR_LOGI("X ret %ld", ret);
	return ret;
}
Exemple #18
0
cmr_int cmr_sensor_set_mode_done(cmr_handle sensor_handle, cmr_uint sensor_id)
{
	cmr_int                  ret = CMR_CAMERA_SUCCESS;

	CMR_MSG_INIT(message);
	struct cmr_sensor_handle *handle = (struct cmr_sensor_handle*)sensor_handle;
	CMR_LOGI("E");

	CHECK_HANDLE_VALID(handle);

	message.msg_type     = CMR_SENSOR_EVT_SETMODONE;
	message.sub_msg_type = sensor_id;
	message.sync_flag    = CMR_MSG_SYNC_PROCESSED;
	ret = cmr_thread_msg_send(handle->thread_cxt.thread_handle, &message);
	if (ret) {
		CMR_LOGE("X send msg failed!");
		return CMR_CAMERA_FAIL;
	}
	CMR_LOGI("X ret %ld", ret);
	return ret;
}
Exemple #19
0
static cmr_int  cmr_sns_create_fmove_thread(struct cmr_sensor_handle *sensor_handle)
{
	cmr_int                  ret = CMR_CAMERA_SUCCESS;
	pthread_attr_t           attr;

	CHECK_HANDLE_VALID(sensor_handle);

	CMR_LOGI("E is_inited thread %p", (void *)sensor_handle->fmove_thread_cxt.thread_handle);
#if defined(CONFIG_CAMERA_CAF)
	if (!sensor_handle->fmove_thread_cxt.thread_handle) {
		pthread_attr_init(&attr);
		pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
		ret = pthread_create(&sensor_handle->fmove_thread_cxt.thread_handle,
					&attr,
					(void *(*)(void *))cmr_sns_fmove_proc,
					(void *)sensor_handle);
		pthread_attr_destroy(&attr);
	}
#endif
	CMR_LOGI("X ret %ld", ret);
	return ret;
}
Exemple #20
0
static cmr_int cmr_sns_kill_fmove_thread(struct cmr_sensor_handle *sensor_handle)
{
	cmr_int                  ret = CMR_CAMERA_SUCCESS;
	void                     *dummy;

	CHECK_HANDLE_VALID(sensor_handle);

	CMR_LOGI("E is_inited %p", (void *)sensor_handle->fmove_thread_cxt.thread_handle);

	if (sensor_handle->fmove_thread_cxt.thread_handle) {
		 sensor_handle->fmove_thread_cxt.is_exit = 1;
		while (1 == sensor_handle->fmove_thread_cxt.is_exit) {
			CMR_LOGW("Wait 10 ms");
			usleep(10000);
		}
		ret = pthread_join(sensor_handle->fmove_thread_cxt.thread_handle, &dummy);
		sensor_handle->fmove_thread_cxt.thread_handle = 0;
	}

	CMR_LOGI("X kill sensor monitor thread done!");
	return ret;
}
Exemple #21
0
cmr_int cmr_sensor_set_mode(cmr_handle sensor_handle, cmr_uint sensor_id, cmr_uint mode)
{
	CMR_MSG_INIT(message);
	cmr_int                  ret = CMR_CAMERA_SUCCESS;
	struct cmr_sensor_handle *handle = (struct cmr_sensor_handle *)sensor_handle;
	CMR_LOGI("E");

	CHECK_HANDLE_VALID(handle);

	/*the set mode function can be async control*/
	message.msg_type     = CMR_SENSOR_EVT_SETMODE;
	message.sub_msg_type = sensor_id;
	message.sync_flag    = CMR_MSG_SYNC_RECEIVED;
	message.data         = (void *)mode;
	ret = cmr_thread_msg_send(handle->thread_cxt.thread_handle, &message);
	if (ret) {
		CMR_LOGE("X send msg failed!");
		return CMR_CAMERA_FAIL;
	}
	CMR_LOGI("X ret %ld", ret);
	return ret;
}
Exemple #22
0
cmr_int cmr_sensor_stream_ctrl(cmr_handle sensor_handle, cmr_uint sensor_id, cmr_uint on_off)
{
	CMR_MSG_INIT(message);
	cmr_int             ret = CMR_CAMERA_SUCCESS;
	struct cmr_sensor_handle  *handle = (struct cmr_sensor_handle*)sensor_handle;
	CMR_LOGI("E");

	CHECK_HANDLE_VALID(handle);

	/*the open&close function should be sync*/
	message.msg_type     = CMR_SENSOR_EVT_STREAM;
	message.sub_msg_type = sensor_id;
	message.sync_flag    = CMR_MSG_SYNC_PROCESSED;
	message.data         = (void*)on_off;
	ret = cmr_thread_msg_send(handle->thread_cxt.thread_handle, &message);
	if (ret) {
		CMR_LOGE("X send msg failed!");
		return CMR_CAMERA_FAIL;
	}
	CMR_LOGI("X ret %ld", ret);
	return ret;
}
int camera_get_trim_rect(struct img_rect *src_trim_rect, uint32_t zoom_level, struct img_size *dst_size)
{
	uint32_t                 trim_width;
	uint32_t                 trim_height;
	uint32_t                 zoom_step_w = 0, zoom_step_h = 0;

	if (NULL == src_trim_rect || NULL == dst_size) {
		CMR_LOGE("0x%x, 0x%x", (uint32_t)src_trim_rect, (uint32_t)dst_size);
		return -CAMERA_INVALID_PARM;
	}

	trim_width = src_trim_rect->width;
	trim_height = src_trim_rect->height;

	if (0 == dst_size->width || 0 == dst_size->height) {
		CMR_LOGE("0x%x, 0x%x", dst_size->width, dst_size->height);
		return -CAMERA_INVALID_PARM;
	}

	if (dst_size->width * src_trim_rect->height < dst_size->height * src_trim_rect->width) {
		trim_width = dst_size->width * src_trim_rect->height / dst_size->height;
	} else {
		trim_height = dst_size->height * src_trim_rect->width / dst_size->width;
	}

	zoom_step_w = ZOOM_STEP(trim_width);
	zoom_step_w &= ~1;
	zoom_step_w *= zoom_level;

 	zoom_step_h = ZOOM_STEP(trim_height);
	zoom_step_h &= ~1;
	zoom_step_h *= zoom_level;
	trim_width = trim_width - zoom_step_w;
	trim_height = trim_height - zoom_step_h;

	src_trim_rect->start_x += (src_trim_rect->width - trim_width) >> 1;
	src_trim_rect->start_y += (src_trim_rect->height - trim_height) >> 1;
	src_trim_rect->start_x = CAMERA_WIDTH(src_trim_rect->start_x);
	src_trim_rect->start_y = CAMERA_HEIGHT(src_trim_rect->start_y);
	src_trim_rect->width = CAMERA_WIDTH(trim_width);
	src_trim_rect->height = CAMERA_HEIGHT(trim_height);
	CMR_LOGI("zoom_level %d, trim rect, %d %d %d %d",
		zoom_level,
		src_trim_rect->start_x,
		src_trim_rect->start_y,
		src_trim_rect->width,
		src_trim_rect->height);

	return CAMERA_SUCCESS;
}
Exemple #24
0
cmr_int camera_get_data_from_file(char *file_name, cmr_u32 img_fmt, cmr_u32 width, cmr_u32 height, struct img_addr *addr)
{
	FILE *fp = NULL;
	cmr_int ret = CMR_CAMERA_SUCCESS;

	CMR_LOGI("file_name:%s format %d width %d heght %d", file_name, img_fmt, width, height);
	if (IMG_DATA_TYPE_YUV420 == img_fmt ||
		IMG_DATA_TYPE_YUV422 == img_fmt) {
		return 0;
	} else if (IMG_DATA_TYPE_JPEG == img_fmt) {
		return 0;
	} else if (IMG_DATA_TYPE_RAW == img_fmt) {
		fp = fopen(file_name, "rb");
		if(NULL == fp){
			CMR_LOGI("can not open file: %s \n", file_name);
			return 0;
		}

		ret = fread((void*)addr->addr_y, 1, (uint32_t)(width * height * 5 / 4), fp);
		fclose(fp);
	}

	return ret;
}
Exemple #25
0
cmr_int cmr_sensor_ioctl(cmr_handle sensor_handle, cmr_u32 sensor_id, cmr_uint cmd, cmr_uint arg)
{
	CMR_MSG_INIT(message);
	cmr_int                  ret = CMR_CAMERA_SUCCESS;
	struct cmr_sns_ioctl_param      ioctl_param;
	struct cmr_sensor_handle *handle = (struct cmr_sensor_handle *)sensor_handle;
	CMR_LOGI("E");

	CHECK_HANDLE_VALID(handle);

	cmr_bzero(&ioctl_param, sizeof(ioctl_param));
	ioctl_param.cmd = cmd;
	ioctl_param.arg = arg;

	/*the set mode function can be async control*/
	message.msg_type     = CMR_SENSOR_EVT_IOCTL;
	message.sub_msg_type = sensor_id;
	message.sync_flag    = CMR_MSG_SYNC_PROCESSED;
	message.data         = (void *)malloc(sizeof(struct cmr_sns_ioctl_param));
	if (!message.data) {
		CMR_LOGE("No mem!");
		return CMR_CAMERA_NO_MEM;
	} else {
		message.alloc_flag = 1;
	}
	cmr_copy(message.data, &ioctl_param, sizeof(struct cmr_sns_ioctl_param));

	ret = cmr_thread_msg_send(handle->thread_cxt.thread_handle, &message);
	if (ret) {
		CMR_LOGE("send msg failed!");
		return CMR_CAMERA_FAIL;
	}

	CMR_LOGI("X ret %ld", ret);
	return ret;
}
Exemple #26
0
cmr_int camera_get_trim_rect(struct img_rect *src_trim_rect, cmr_uint zoom_level, struct img_size *dst_size)
{
	cmr_int                  ret = CMR_CAMERA_SUCCESS;
	cmr_uint                 trim_width = 0, trim_height = 0;
	cmr_uint                 zoom_step_w = 0, zoom_step_h = 0;

	if (!src_trim_rect || !dst_size) {
		CMR_LOGE("0x%lx 0x%lx", (cmr_uint)src_trim_rect, (cmr_uint)dst_size);
		ret = -CMR_CAMERA_INVALID_PARAM;
		goto exit;
	}

	trim_width = src_trim_rect->width;
	trim_height = src_trim_rect->height;

	if (0 == dst_size->width || 0 == dst_size->height) {
		CMR_LOGE("0x%x 0x%x", dst_size->width, dst_size->height);
		ret = -CMR_CAMERA_INVALID_PARAM;
		goto exit;
	}

	if (dst_size->width * src_trim_rect->height < dst_size->height * src_trim_rect->width) {
		trim_width = dst_size->width * src_trim_rect->height / dst_size->height;
	} else {
		trim_height = dst_size->height * src_trim_rect->width / dst_size->width;
	}

	zoom_step_w = ZOOM_STEP(trim_width);
	zoom_step_w &= ~1;
	zoom_step_w *= zoom_level;
	zoom_step_h = ZOOM_STEP(trim_height);
	zoom_step_h &= ~1;
	zoom_step_h *= zoom_level;
	trim_width = trim_width - zoom_step_w;
	trim_height = trim_height - zoom_step_h;

	src_trim_rect->start_x += (src_trim_rect->width - trim_width) >> 1;
	src_trim_rect->start_y += (src_trim_rect->height - trim_height) >> 1;
	src_trim_rect->start_x = CAMERA_WIDTH(src_trim_rect->start_x);
	src_trim_rect->start_y = CAMERA_HEIGHT(src_trim_rect->start_y);
	src_trim_rect->width = CAMERA_WIDTH(trim_width);
	src_trim_rect->height = CAMERA_HEIGHT(trim_height);
	CMR_LOGI("zoom_level %ld trim rect %d %d %d %d", zoom_level, src_trim_rect->start_x,
		      src_trim_rect->start_y, src_trim_rect->width, src_trim_rect->height);
exit:
	return ret;
}
Exemple #27
0
cmr_int cmr_sns_destroy_thread(struct cmr_sensor_handle *handle)
{
	CMR_MSG_INIT(message);
	cmr_int                  ret = CMR_CAMERA_SUCCESS;

	CHECK_HANDLE_VALID(handle);

	CMR_LOGI("is_inited %ld", handle->thread_cxt.is_inited);

	if (handle->thread_cxt.is_inited) {
		ret = cmr_thread_destroy(handle->thread_cxt.thread_handle);
		handle->thread_cxt.thread_handle = 0;
		handle->thread_cxt.is_inited = 0;
	}

	return ret ;
}
Exemple #28
0
cmr_int cmr_sensor_get_autotest_mode(cmr_handle sensor_handle, cmr_u32 sensor_id, cmr_uint *is_autotest)
{
	UNUSED(sensor_id);

	cmr_int                      ret = CMR_CAMERA_SUCCESS;
	struct cmr_sensor_handle *handle = (struct cmr_sensor_handle *)sensor_handle;

	if (!handle || !is_autotest) {
		CMR_LOGE("param err 0x%lx", (cmr_uint)sensor_handle);
		ret = -CMR_CAMERA_INVALID_PARAM;
		goto exit;
	}
	*is_autotest = handle->is_autotest;
	CMR_LOGI("auto test %d", (cmr_s32)*is_autotest);
exit:
	return ret;
}
Exemple #29
0
cmr_int cmr_sensor_get_exif(cmr_handle sensor_handle, cmr_uint sensor_id, EXIF_SPEC_PIC_TAKING_COND_T *sensor_exif_ptr)
{
	struct cmr_sensor_handle *handle = (struct cmr_sensor_handle *)sensor_handle;
	EXIF_SPEC_PIC_TAKING_COND_T  *cur_sensor_exif_ptr = NULL;

	CHECK_HANDLE_VALID(handle);
	sensor_get_exif_common(&handle->sensor_cxt[sensor_id], &cur_sensor_exif_ptr);

	CHECK_HANDLE_VALID(sensor_exif_ptr);

	if (cur_sensor_exif_ptr) {
		CMR_LOGI("get sensor context exif addr %p", cur_sensor_exif_ptr);
		cmr_copy(sensor_exif_ptr, cur_sensor_exif_ptr, sizeof(EXIF_SPEC_PIC_TAKING_COND_T));
	}

	return CMR_CAMERA_SUCCESS;
}
static uint32_t getDataFromDouble(double d, uint32_t type)/*0: dd, 1: mm, 2: ss*/
{
	d = fabs(d);
	double degrees = (int)d;
	double remainder = d - degrees;
	double minutes = (int)(remainder * 60.0);
	double seconds = (int)(((remainder * 60.0) - minutes) * 60.0);
	uint32_t retVal = 0;
	if (0 == type) {
		retVal = (int)degrees;
	} else if (1 == type) {
		retVal = (int)minutes;
	} else if (2 == type) {
		retVal = (int)seconds;
	}
	CMR_LOGI("GPS: type: %d, ret: 0x%x.", type, retVal);
	return retVal;
}