CameraHardwareInterface.h定义了CameraService和CameraHAL之间的接口,在这个文件中定义了四个回调函数
typedef camera_memory_t* (*camera_request_memory)(int fd, size_t buf_size, unsigned int num_bufs,
void *user);
typedef void (*camera_notify_callback)(int32_t msg_type,
int32_t ext1,
int32_t ext2,
void *user);
typedef void (*camera_data_callback)(int32_t msg_type,
const camera_memory_t *data, unsigned int index,
camera_frame_metadata_t *metadata, void *user);
typedef void (*camera_data_timestamp_callback)(int64_t timestamp,
int32_t msg_type,
const camera_memory_t *data, unsigned int index,
void *user);
这四个回调函数在frameworks/av/services/camera/libcameraservice/CameraClient.cpp中实现。
camera_request_memory
Camera HAL通知CameraService申请buffer
@buf_size: buf的大小
@num_bufs:buf数目
msg_type的取值范围定义在 android/system/core/include/system/camera.h中
/** msgType in notifyCallback and dataCallback functions */
enum {
CAMERA_MSG_ERROR = 0x0001, // notifyCallback
CAMERA_MSG_SHUTTER = 0x0002, // notifyCallback
CAMERA_MSG_FOCUS = 0x0004, // notifyCallback
CAMERA_MSG_ZOOM = 0x0008, // notifyCallback
CAMERA_MSG_PREVIEW_FRAME = 0x0010, // dataCallback
CAMERA_MSG_VIDEO_FRAME = 0x0020, // data_timestamp_callback
CAMERA_MSG_POSTVIEW_FRAME = 0x0040, // dataCallback
CAMERA_MSG_RAW_IMAGE = 0x0080, // dataCallback
CAMERA_MSG_COMPRESSED_IMAGE = 0x0100, // dataCallback
CAMERA_MSG_RAW_IMAGE_NOTIFY = 0x0200, // dataCallback
// Preview frame metadata. This can be combined with
// CAMERA_MSG_PREVIEW_FRAME in dataCallback. For example, the apps can
// request FRAME and METADATA. Or the apps can request only FRAME or only
// METADATA.
CAMERA_MSG_PREVIEW_METADATA = 0x0400, // dataCallback
// Notify on autofocus start and stop. This is useful in continuous
// autofocus - FOCUS_MODE_CONTINUOUS_VIDEO and FOCUS_MODE_CONTINUOUS_PICTURE.
CAMERA_MSG_FOCUS_MOVE = 0x0800, // notifyCallback
CAMERA_MSG_ALL_MSGS = 0xFFFF
};
camera_notify_callback
用来传递一些消息: 如快门消息,自动对焦完成消息,出错消息,拍照编码结束等
参数@msg_type可以是:
camera_data_callback
该函数用于从camera HAL返回数据,
返回的数据可以是:
参数@msg_type可以是:
参数@data 用来返回图像数据
参数@metadata 用来返回图像的元数据
camera_data_timestamp_callback
该回调函数用来从Camera HAL返回帧数据以及对应的时间戳,这个callback用于录像的场景。
@timestamp:生成帧数据的时间戳
@msg_type: 取值为CAMERA_MSG_VIDEO_FRAME
@data:用来返回帧数据