|
发表于 2018-7-13 21:04:37
只看该作者
29#
sp<ProcessState> proc(ProcessState::self());
ProcessState::self()->startThreadPool();
sp<ICameraService> cameraService;
getService(String16("media.camera"), &cameraService);
if (cameraService == NULL) {
LogD("get camera services is failed.");
return 1;
}
status_t err = NO_ERROR;
CameraInfo cameraInfo;
int32_t cameras = cameraService->getNumberOfCameras(), i = 0;
LogD("camera counts[%d].", cameras);
for (i=0; i<cameras; i++) {
err = cameraService->getCameraInfo(i, &cameraInfo);
if (err != NO_ERROR) {
LogD("get camera[%d] info is failed.", i);
break;
} else {
LogD("camera info[%d]: facing[%d], orientation[%d].",
i, cameraInfo.facing, cameraInfo.orientation);
}
if (cameraInfo.facing == CAMERA_FACING_BACK) {
break;
}
}
if (err != NO_ERROR) {
LogD("error code[%d].", err);
return 1;
} else if (i >= cameras) {
LogD("not find CAMERA_FACING_BACK");
return 1;
}
sp<Camera> camera = Camera::connect(i, String16("test"), Camera::USE_CALLING_UID);
if (camera == NULL) {
LogD("create camera is failed.");
return 0;
} else {
LogD("create camera is success.");
}
sp<SurfaceComposerClient> client = new SurfaceComposerClient();
int32_t width = 1920, height = 1080;
sp<SurfaceControl> surfaceControl = client->createSurface(String8("HDMI_TEST"),
width, height, PIXEL_FORMAT_BGRA_8888, 0);
sp<Surface> surface = surfaceControl->getSurface();
err = camera->setPreviewTarget(surface->getIGraphicBufferProducer());
if (err != NO_ERROR) {
LogD("camera set preview target is failed[%d].", err);
return 0;
}
err = camera->startPreview();
LogD("camera start preview[%d].", err);
SurfaceComposerClient::openGlobalTransaction();
err = surfaceControl->setLayer(100000);
SurfaceComposerClient::closeGlobalTransaction();
IPCThreadState::self()->joinThreadPool();
return 0; |
|