class Camera : public BnCameraClient,public IBinder::DeathRecipient
constsp& Camera::getCameraService()
{
Mutex::Autolock _l(mLock);
if (mCameraService.get() == 0) {
sp sm = defaultServiceManager();
sp binder;
do {
binder =sm->getService(String16("media.camera"));
if (binder != 0)
break;
ALOGW("CameraService notpublished, waiting...");
usleep(500000); // 0.5 s
} while(true);
if (mDeathNotifier == NULL) {
mDeathNotifier = newDeathNotifier();
}
binder->linkToDeath(mDeathNotifier);
mCameraService =interface_cast(binder);
}
spCamera::connect(int cameraId)
{
ALOGV("connect");
sp c = new Camera();
const sp& cs =getCameraService();
if (cs != 0) {
c->mCamera = cs->connect(c, cameraId);
}
if (c->mCamera != 0) {
c->mCamera->asBinder()->linkToDeath(c);
c->mStatus = NO_ERROR;
} else {
c.clear();
}
return c;
}
class Client : public BnCamera
class CameraClient : public CameraService::Client
wp mClient[MAX_CAMERAS];
switch(deviceVersion) {
case CAMERA_DEVICE_API_VERSION_1_0:
client = new CameraClient(this,cameraClient, cameraId,
info.facing, callingPid, getpid());
break;
case CAMERA_DEVICE_API_VERSION_2_0:
client = new Camera2Client(this,cameraClient, cameraId,
info.facing, callingPid,getpid());
sp mHardware;
status_t CameraClient::initialize(camera_module_t *module) {
int callingPid = getCallingPid();
LOG1("CameraClient::initialize E (pid%d, id %d)", callingPid, mCameraId);
char camera_device_name[10];
status_t res;
snprintf(camera_device_name, sizeof(camera_device_name),"%d", mCameraId);
mHardware = new CameraHardwareInterface(camera_device_name);
res = mHardware->initialize(&module->common);
if (res != OK) {
ALOGE("%s: Camera %d: unable toinitialize device: %s (%d)",
__FUNCTION__, mCameraId,strerror(-res), res);
mHardware.clear();
return NO_INIT;
}
mHardware->setCallbacks(notifyCallback,
dataCallback,
dataCallbackTimestamp,
(void*)mCameraId);
//Enable zoom, error, focus, and metadata messages by default
enableMsgType(CAMERA_MSG_ERROR | CAMERA_MSG_ZOOM | CAMERA_MSG_FOCUS |
CAMERA_MSG_PREVIEW_METADATA | CAMERA_MSG_FOCUS_MOVE);
//!++
#ifdef MTK_CAMERA_BSP_SUPPORT
// Enable MTK-extended messages by default
enableMsgType(MTK_CAMERA_MSG_EXT_NOTIFY |MTK_CAMERA_MSG_EXT_DATA);
#endif
//!--
LOG1("CameraClient::initialize X (pid%d, id %d)", callingPid, mCameraId);
return OK;
}
void CameraService:: onFirstRef()
{
BnCameraService::onFirstRef();
if (hw_get_module(CAMERA_HARDWARE_MODULE_ID,
(const hw_module_t**)&mModule) < 0) {
ALOGE("Could not load camera HALmodule");
mNumberOfCameras = 0;
}
else {
mNumberOfCameras =mModule->get_number_of_cameras();
if (mNumberOfCameras > MAX_CAMERAS){
ALOGE("Number of cameras(%d)> MAX_CAMERAS(%d).",
mNumberOfCameras, MAX_CAMERAS);
mNumberOfCameras = MAX_CAMERAS;
}
for (int i = 0; i
转载:http://www.2cto.com/kf/201303/196681.html
可参考:http://blog.163.com/shawpin@126/blog/static/116663752201092394147937/