* Create a camera object for onboard BACK_FACING camera */
| 51 | * Create a camera object for onboard BACK_FACING camera |
| 52 | */ |
| 53 | void CameraEngine::CreateCamera(void) { |
| 54 | // Camera needed to be requested at the run-time from Java SDK |
| 55 | // if Not granted, do nothing. |
| 56 | if (!cameraGranted_ || !app_->window) { |
| 57 | LOGW("Camera Sample requires Full Camera access"); |
| 58 | return; |
| 59 | } |
| 60 | |
| 61 | int32_t displayRotation = GetDisplayRotation(); |
| 62 | rotation_ = displayRotation; |
| 63 | |
| 64 | camera_ = new NDKCamera(); |
| 65 | ASSERT(camera_, "Failed to Create CameraObject"); |
| 66 | |
| 67 | int32_t facing = 0, angle = 0, imageRotation = 0; |
| 68 | if (camera_->GetSensorOrientation(&facing, &angle)) { |
| 69 | if (facing == ACAMERA_LENS_FACING_FRONT) { |
| 70 | imageRotation = (angle + rotation_) % 360; |
| 71 | imageRotation = (360 - imageRotation) % 360; |
| 72 | } else { |
| 73 | imageRotation = (angle - rotation_ + 360) % 360; |
| 74 | } |
| 75 | } |
| 76 | LOGI("Phone Rotation: %d, Present Rotation Angle: %d", rotation_, |
| 77 | imageRotation); |
| 78 | ImageFormat view{0, 0, 0}, capture{0, 0, 0}; |
| 79 | camera_->MatchCaptureSizeRequest(app_->window, &view, &capture); |
| 80 | |
| 81 | ASSERT(view.width && view.height, "Could not find supportable resolution"); |
| 82 | |
| 83 | // Request the necessary nativeWindow to OS |
| 84 | bool portraitNativeWindow = |
| 85 | (savedNativeWinRes_.width < savedNativeWinRes_.height); |
| 86 | ANativeWindow_setBuffersGeometry( |
| 87 | app_->window, portraitNativeWindow ? view.height : view.width, |
| 88 | portraitNativeWindow ? view.width : view.height, WINDOW_FORMAT_RGBA_8888); |
| 89 | |
| 90 | yuvReader_ = new ImageReader(&view, AIMAGE_FORMAT_YUV_420_888); |
| 91 | yuvReader_->SetPresentRotation(imageRotation); |
| 92 | jpgReader_ = new ImageReader(&capture, AIMAGE_FORMAT_JPEG); |
| 93 | jpgReader_->SetPresentRotation(imageRotation); |
| 94 | jpgReader_->RegisterCallback(this, [](void* ctx, const char* str) -> void { |
| 95 | reinterpret_cast<CameraEngine*>(ctx)->OnPhotoTaken(str); |
| 96 | }); |
| 97 | |
| 98 | // now we could create session |
| 99 | camera_->CreateSession(yuvReader_->GetNativeWindow(), |
| 100 | jpgReader_->GetNativeWindow(), imageRotation); |
| 101 | } |
| 102 | |
| 103 | void CameraEngine::DeleteCamera(void) { |
| 104 | cameraReady_ = false; |
nothing calls this directly
no test coverage detected