Android Camera2 HAL3 高通Qualcomm Camera底层initialize代码流程

 

本文列出代码调用流程,作为参考,要想了解高通驱动架构需要结核实际理解代码,不要一味的沉浸在代码中,这样是没有任何效果的。

当相机打开成功后会紧接着执行initialize,代码流程如下

/*initialize_flow*/
#if 1	
/*************************initialize_flow_start******************************************************************/
QCamera3HWI.cpp
int (*initialize)(const struct camera3_device *,const camera3_callback_ops_t *callback_ops);
int QCamera3HardwareInterface::initialize(const struct camera3_device *device,const camera3_callback_ops_t *callback_ops)
	int rc = hw->initialize(callback_ops);
		int QCamera3HardwareInterface::initialize(const struct camera3_callback_ops *callback_ops)
			rc = initParameters();
				int QCamera3HardwareInterface::initParameters()
					rc = mParamHeap->allocate(sizeof(metadata_buffer_t));/*Allocate Set Param Buffer*/
					rc = mCameraHandle->ops->map_buf(mCameraHandle->camera_handle,
													CAM_MAPPING_BUF_TYPE_PARM_BUF,
													mParamHeap->getFd(0),
													sizeof(metadata_buffer_t),
													(metadata_buffer_t *) DATA_PTR(mParamHeap,0));
					mParameters = (metadata_buffer_t *) DATA_PTR(mParamHeap,0);
					mPrevParameters = (metadata_buffer_t *)malloc(sizeof(metadata_buffer_t));
			mCallbackOps = callback_ops;
			mChannelHandle = mCameraHandle->ops->add_channel(mCameraHandle->camera_handle, NULL, NULL, this);/*mm_camera_interface.c*/
				static uint32_t mm_camera_intf_add_channel(uint32_t camera_handle,mm_camera_channel_attr_t *attr,mm_camera_buf_notify_t channel_cb,void *userdata)
					uint32_t handle = get_main_camera_handle(camera_handle);
					uint32_t aux_handle = get_aux_camera_handle(camera_handle);
					if (handle)/*主摄像头*/
						my_obj = mm_camera_util_get_camera_by_handler(handle);/*参考open_camera*/
						ch_id = mm_camera_add_channel(my_obj, attr, channel_cb, userdata);/* attr == NULL , channel_cb == NULL  */
							uint32_t mm_camera_add_channel(mm_camera_obj_t *my_obj,mm_camera_channel_attr_t *attr,mm_camera_buf_notify_t channel_cb,void *userdata)
								for(ch_idx = 0; ch_idx < MM_CAMERA_CHANNEL_MAX; ch_idx++)
									if (MM_CHANNEL_STATE_NOTUSED == my_obj->ch[ch_idx].state)
										ch_obj = &my_obj->ch[ch_idx];
								ch_hdl = mm_camera_util_generate_handler_by_num(my_obj->my_num, ch_idx); /* 生成相机句柄 */
								ch_obj->my_hdl = ch_hdl;
								ch_obj->state = MM_CHANNEL_STATE_STOPPED;
								ch_obj->cam_obj = my_obj;
								ch_obj->sessionid = my_obj->sessionid;
								mm_channel_init(ch_obj, attr, channel_cb, userdata);
									/*mm_camera_channel.c*/int32_t mm_channel_init(mm_channel_t *my_obj,mm_camera_channel_attr_t *attr,mm_camera_buf_notify_t channel_cb,void *userdata)
										my_obj->bundle.super_buf_notify_cb = channel_cb;/* NULL */
										my_obj->bundle.user_data = userdata;/* QCamera3HardwareInterface */
										mm_muxer_frame_sync_queue_init(&my_obj->frame_sync.superbuf_queue);
										mm_camera_poll_thread_launch(&my_obj->poll_thread[0],MM_CAMERA_POLL_TYPE_DATA);
											/*主要是启动一个线程,进入mm_camera_thread.c*/
											int32_t mm_camera_poll_thread_launch(mm_camera_poll_thread_t * poll_cb,mm_camera_poll_thread_type_t poll_type)
												pthread_create(&poll_cb->pid, NULL, mm_camera_poll_thread, (void *)poll_cb);
													mm_camera_poll_thread()/* 线程的执行函数 mm_camera_thread.c */
													/*线程启动后就开始等待 */
													    if(!poll_cb->status) {
															pthread_cond_wait(&poll_cb->cond_v, &poll_cb->mutex);
														}
										/* change state to stopped state */
										my_obj->state = MM_CHANNEL_STATE_STOPPED;
					if (aux_handle)/*辅助摄像头*/
						my_obj = mm_camera_util_get_camera_head(aux_handle);/*参考open_camera*/
						aux_ch_id = mm_camera_muxer_add_channel(aux_handle, attr,channel_cb, userdata, ch_id, my_obj);/* attr == NULL , channel_cb == NULL  */
							/*mm_camera_muxer.c*/uint32_t mm_camera_muxer_add_channel(uint32_t camera_handle, *attr,  channel_cb,void *userdata, uint32_t m_ch_id, mm_camera_obj_t *cam_obj)
								my_obj = mm_muxer_util_get_camera_by_obj(camera_handle, cam_obj);/*参考opencamera*/
								if(my_obj)
									ch_id = mm_camera_add_channel(my_obj, attr, channel_cb, userdata);/*同上主摄像机的add_channel*/
									if (ch_id > 0 && m_ch_id > 0)
										memset(&frame_sync, 0, sizeof(frame_sync));
										frame_sync.a_cam_obj = my_obj;
										frame_sync.a_ch_id = ch_id;
										frame_sync.userdata = userdata;
										frame_sync.a_stream_id = 0;
										frame_sync.is_res_shared = 1;
										if (attr != NULL) {
											frame_sync.attr = *attr;
											frame_sync.is_active = 1;
										}
										pthread_mutex_lock(&cam_obj->cam_lock);
										mm_camera_reg_frame_sync(cam_obj, m_ch_id,0, &frame_sync);
/*************************initialize_flow_end******************************************************************/
#endif

 

你可能感兴趣的:(android,c++,驱动程序)