blob: d6eff24104efc42b5127e847640ec241ea188c52 [file] [log] [blame]
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -08001/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17//#define LOG_NDEBUG 0
18#define LOG_TAG "NdkCameraCaptureSession"
19#define ATRACE_TAG ATRACE_TAG_CAMERA
20
21#include <utils/Log.h>
22#include <utils/Mutex.h>
23#include <utils/StrongPointer.h>
24#include <utils/Trace.h>
25
26#include "NdkCameraDevice.h"
Yin-Chia Yehead91462016-01-06 16:45:08 -080027#include <NdkCaptureRequest.h>
28#include <NdkCameraCaptureSession.h>
29#include "impl/ACameraCaptureSession.h"
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080030
31using namespace android;
32
33EXPORT
Yin-Chia Yehead91462016-01-06 16:45:08 -080034void ACameraCaptureSession_close(ACameraCaptureSession* session) {
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080035 ATRACE_CALL();
Yin-Chia Yehead91462016-01-06 16:45:08 -080036 if (session != nullptr) {
37 session->closeByApp();
38 }
39 return;
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080040}
41
42EXPORT
43camera_status_t ACameraCaptureSession_getDevice(
Yin-Chia Yehead91462016-01-06 16:45:08 -080044 ACameraCaptureSession* session, ACameraDevice **device) {
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080045 ATRACE_CALL();
Yin-Chia Yehead91462016-01-06 16:45:08 -080046 if (session == nullptr || device == nullptr) {
47 ALOGE("%s: Error: invalid input: session %p, device %p",
48 __FUNCTION__, session, device);
49 return ACAMERA_ERROR_INVALID_PARAMETER;
50 }
51
52 if (session->isClosed()) {
53 ALOGE("%s: session %p is already closed", __FUNCTION__, session);
54 *device = nullptr;
55 return ACAMERA_ERROR_SESSION_CLOSED;
56 }
57
58 *device = session->getDevice();
59 if (*device == nullptr) {
60 // Should not reach here
61 ALOGE("%s: unknown failure: device is null", __FUNCTION__);
62 return ACAMERA_ERROR_UNKNOWN;
63 }
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080064 return ACAMERA_OK;
65}
66
67EXPORT
68camera_status_t ACameraCaptureSession_capture(
Yin-Chia Yehead91462016-01-06 16:45:08 -080069 ACameraCaptureSession* session, /*optional*/ACameraCaptureSession_captureCallbacks* cbs,
70 int numRequests, ACaptureRequest** requests,
71 /*optional*/int* captureSequenceId) {
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080072 ATRACE_CALL();
Yin-Chia Yehead91462016-01-06 16:45:08 -080073 if (session == nullptr || requests == nullptr || numRequests < 1) {
74 ALOGE("%s: Error: invalid input: session %p, numRequest %d, requests %p",
75 __FUNCTION__, session, numRequests, requests);
76 return ACAMERA_ERROR_INVALID_PARAMETER;
77 }
78
79 if (session->isClosed()) {
80 ALOGE("%s: session %p is already closed", __FUNCTION__, session);
81 *captureSequenceId = CAPTURE_SEQUENCE_ID_NONE;
82 return ACAMERA_ERROR_SESSION_CLOSED;
83 }
84
85 return session->capture(cbs, numRequests, requests, captureSequenceId);
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080086}
87
88EXPORT
89camera_status_t ACameraCaptureSession_setRepeatingRequest(
Yin-Chia Yehead91462016-01-06 16:45:08 -080090 ACameraCaptureSession* session, /*optional*/ACameraCaptureSession_captureCallbacks* cbs,
91 int numRequests, ACaptureRequest** requests,
92 /*optional*/int* captureSequenceId) {
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080093 ATRACE_CALL();
Yin-Chia Yehead91462016-01-06 16:45:08 -080094 if (session == nullptr || requests == nullptr || numRequests < 1) {
95 ALOGE("%s: Error: invalid input: session %p, numRequest %d, requests %p",
96 __FUNCTION__, session, numRequests, requests);
97 return ACAMERA_ERROR_INVALID_PARAMETER;
98 }
99
100 if (session->isClosed()) {
101 ALOGE("%s: session %p is already closed", __FUNCTION__, session);
102 *captureSequenceId = CAPTURE_SEQUENCE_ID_NONE;
103 return ACAMERA_ERROR_SESSION_CLOSED;
104 }
105
106 return session->setRepeatingRequest(cbs, numRequests, requests, captureSequenceId);
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800107}
108
109EXPORT
Yin-Chia Yehead91462016-01-06 16:45:08 -0800110camera_status_t ACameraCaptureSession_stopRepeating(ACameraCaptureSession* session) {
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800111 ATRACE_CALL();
Yin-Chia Yehead91462016-01-06 16:45:08 -0800112 if (session == nullptr) {
113 ALOGE("%s: Error: session is null", __FUNCTION__);
114 return ACAMERA_ERROR_INVALID_PARAMETER;
115 }
116
117 if (session->isClosed()) {
118 ALOGE("%s: session %p is already closed", __FUNCTION__, session);
119 return ACAMERA_ERROR_SESSION_CLOSED;
120 }
121 return session->stopRepeating();
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800122}
123
124EXPORT
Yin-Chia Yeh309d05d2016-03-28 10:15:31 -0700125camera_status_t ACameraCaptureSession_abortCaptures(ACameraCaptureSession* session) {
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800126 ATRACE_CALL();
Yin-Chia Yeh309d05d2016-03-28 10:15:31 -0700127 if (session == nullptr) {
128 ALOGE("%s: Error: session is null", __FUNCTION__);
129 return ACAMERA_ERROR_INVALID_PARAMETER;
130 }
131
132 if (session->isClosed()) {
133 ALOGE("%s: session %p is already closed", __FUNCTION__, session);
134 return ACAMERA_ERROR_SESSION_CLOSED;
135 }
136 return session->abortCaptures();
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800137}