MCPcopy Create free account
hub / github.com/android/ndk-samples / CreateSession

Method CreateSession

camera/texture-view/src/main/cpp/camera_manager.cpp:233–282  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

231}
232
233void NDKCamera::CreateSession(ANativeWindow* previewWindow,
234 ANativeWindow* jpgWindow, bool manualPreview,
235 int32_t imageRotation) {
236 // Create output from this app's ANativeWindow, and add into output container
237 requests_[PREVIEW_REQUEST_IDX].outputNativeWindow_ = previewWindow;
238 requests_[PREVIEW_REQUEST_IDX].template_ = TEMPLATE_PREVIEW;
239 requests_[JPG_CAPTURE_REQUEST_IDX].outputNativeWindow_ = jpgWindow;
240 requests_[JPG_CAPTURE_REQUEST_IDX].template_ = TEMPLATE_STILL_CAPTURE;
241
242 CALL_CONTAINER(create(&outputContainer_));
243 for (auto& req : requests_) {
244 if (!req.outputNativeWindow_) continue;
245
246 ANativeWindow_acquire(req.outputNativeWindow_);
247 CALL_OUTPUT(create(req.outputNativeWindow_, &req.sessionOutput_));
248 CALL_CONTAINER(add(outputContainer_, req.sessionOutput_));
249 CALL_TARGET(create(req.outputNativeWindow_, &req.target_));
250 CALL_DEV(createCaptureRequest(cameras_[activeCameraId_].device_,
251 req.template_, &req.request_));
252 CALL_REQUEST(addTarget(req.request_, req.target_));
253 }
254
255 // Create a capture session for the given preview request
256 captureSessionState_ = CaptureSessionState::READY;
257 CALL_DEV(createCaptureSession(cameras_[activeCameraId_].device_,
258 outputContainer_, GetSessionListener(),
259 &captureSession_));
260
261 if (jpgWindow) {
262 ACaptureRequest_setEntry_i32(requests_[JPG_CAPTURE_REQUEST_IDX].request_,
263 ACAMERA_JPEG_ORIENTATION, 1, &imageRotation);
264 }
265
266 if (!manualPreview) {
267 return;
268 }
269 /*
270 * Only preview request is in manual mode, JPG is always in Auto mode
271 * JPG capture mode could also be switch into manual mode and control
272 * the capture parameters, this sample leaves JPG capture to be auto mode
273 * (auto control has better effect than author's manual control)
274 */
275 uint8_t aeModeOff = ACAMERA_CONTROL_AE_MODE_OFF;
276 CALL_REQUEST(setEntry_u8(requests_[PREVIEW_REQUEST_IDX].request_,
277 ACAMERA_CONTROL_AE_MODE, 1, &aeModeOff));
278 CALL_REQUEST(setEntry_i32(requests_[PREVIEW_REQUEST_IDX].request_,
279 ACAMERA_SENSOR_SENSITIVITY, 1, &sensitivity_));
280 CALL_REQUEST(setEntry_i64(requests_[PREVIEW_REQUEST_IDX].request_,
281 ACAMERA_SENSOR_EXPOSURE_TIME, 1, &exposureTime_));
282}
283
284void NDKCamera::CreateSession(ANativeWindow* previewWindow) {
285 CreateSession(previewWindow, nullptr, false, 0);

Callers 1

CreateCameraSessionMethod · 0.45

Calls 1

addFunction · 0.85

Tested by

no test coverage detected