blob: 540d84e43b9bd4880e837f99ac4e21f1e486d0df [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
Colin Cross7e8d4ba2017-05-04 16:17:42 -070026#include <camera/NdkCameraDevice.h>
27#include <camera/NdkCaptureRequest.h>
28#include <camera/NdkCameraCaptureSession.h>
Yin-Chia Yehead91462016-01-06 16:45:08 -080029#include "impl/ACameraCaptureSession.h"
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080030
Shuzhen Wang0ff9ae32018-12-05 18:06:12 -080031#include "impl/ACameraCaptureSession.inc"
32
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080033using namespace android;
34
35EXPORT
Yin-Chia Yehead91462016-01-06 16:45:08 -080036void ACameraCaptureSession_close(ACameraCaptureSession* session) {
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080037 ATRACE_CALL();
Yin-Chia Yehead91462016-01-06 16:45:08 -080038 if (session != nullptr) {
39 session->closeByApp();
40 }
41 return;
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080042}
43
44EXPORT
45camera_status_t ACameraCaptureSession_getDevice(
Yin-Chia Yehead91462016-01-06 16:45:08 -080046 ACameraCaptureSession* session, ACameraDevice **device) {
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080047 ATRACE_CALL();
Yin-Chia Yehead91462016-01-06 16:45:08 -080048 if (session == nullptr || device == nullptr) {
49 ALOGE("%s: Error: invalid input: session %p, device %p",
50 __FUNCTION__, session, device);
51 return ACAMERA_ERROR_INVALID_PARAMETER;
52 }
53
54 if (session->isClosed()) {
55 ALOGE("%s: session %p is already closed", __FUNCTION__, session);
56 *device = nullptr;
57 return ACAMERA_ERROR_SESSION_CLOSED;
58 }
59
60 *device = session->getDevice();
61 if (*device == nullptr) {
62 // Should not reach here
63 ALOGE("%s: unknown failure: device is null", __FUNCTION__);
64 return ACAMERA_ERROR_UNKNOWN;
65 }
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080066 return ACAMERA_OK;
67}
68
69EXPORT
70camera_status_t ACameraCaptureSession_capture(
Yin-Chia Yehead91462016-01-06 16:45:08 -080071 ACameraCaptureSession* session, /*optional*/ACameraCaptureSession_captureCallbacks* cbs,
72 int numRequests, ACaptureRequest** requests,
73 /*optional*/int* captureSequenceId) {
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080074 ATRACE_CALL();
Yin-Chia Yehead91462016-01-06 16:45:08 -080075 if (session == nullptr || requests == nullptr || numRequests < 1) {
76 ALOGE("%s: Error: invalid input: session %p, numRequest %d, requests %p",
77 __FUNCTION__, session, numRequests, requests);
78 return ACAMERA_ERROR_INVALID_PARAMETER;
79 }
80
81 if (session->isClosed()) {
82 ALOGE("%s: session %p is already closed", __FUNCTION__, session);
83 *captureSequenceId = CAPTURE_SEQUENCE_ID_NONE;
84 return ACAMERA_ERROR_SESSION_CLOSED;
85 }
86
Shuzhen Wang0ff9ae32018-12-05 18:06:12 -080087 return session->capture(
88 cbs, numRequests, requests, captureSequenceId);
89}
90
91EXPORT
92camera_status_t ACameraCaptureSession_logicalCamera_capture(
93 ACameraCaptureSession* session,
94 /*optional*/ACameraCaptureSession_logicalCamera_captureCallbacks* lcbs,
95 int numRequests, ACaptureRequest** requests,
96 /*optional*/int* captureSequenceId) {
97 ATRACE_CALL();
98 if (session == nullptr || requests == nullptr || numRequests < 1) {
99 ALOGE("%s: Error: invalid input: session %p, numRequest %d, requests %p",
100 __FUNCTION__, session, numRequests, requests);
101 return ACAMERA_ERROR_INVALID_PARAMETER;
102 }
103
104 if (session->isClosed()) {
105 ALOGE("%s: session %p is already closed", __FUNCTION__, session);
106 *captureSequenceId = CAPTURE_SEQUENCE_ID_NONE;
107 return ACAMERA_ERROR_SESSION_CLOSED;
108 }
109
110 return session->capture(
111 lcbs, numRequests, requests, captureSequenceId);
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800112}
113
114EXPORT
115camera_status_t ACameraCaptureSession_setRepeatingRequest(
Yin-Chia Yehead91462016-01-06 16:45:08 -0800116 ACameraCaptureSession* session, /*optional*/ACameraCaptureSession_captureCallbacks* cbs,
117 int numRequests, ACaptureRequest** requests,
118 /*optional*/int* captureSequenceId) {
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800119 ATRACE_CALL();
Yin-Chia Yehead91462016-01-06 16:45:08 -0800120 if (session == nullptr || requests == nullptr || numRequests < 1) {
121 ALOGE("%s: Error: invalid input: session %p, numRequest %d, requests %p",
122 __FUNCTION__, session, numRequests, requests);
123 return ACAMERA_ERROR_INVALID_PARAMETER;
124 }
125
126 if (session->isClosed()) {
127 ALOGE("%s: session %p is already closed", __FUNCTION__, session);
128 *captureSequenceId = CAPTURE_SEQUENCE_ID_NONE;
129 return ACAMERA_ERROR_SESSION_CLOSED;
130 }
131
132 return session->setRepeatingRequest(cbs, numRequests, requests, captureSequenceId);
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800133}
134
135EXPORT
Shuzhen Wang0ff9ae32018-12-05 18:06:12 -0800136camera_status_t ACameraCaptureSession_logicalCamera_setRepeatingRequest(
137 ACameraCaptureSession* session,
138 /*optional*/ACameraCaptureSession_logicalCamera_captureCallbacks* lcbs,
139 int numRequests, ACaptureRequest** requests,
140 /*optional*/int* captureSequenceId) {
141 ATRACE_CALL();
142 if (session == nullptr || requests == nullptr || numRequests < 1) {
143 ALOGE("%s: Error: invalid input: session %p, numRequest %d, requests %p",
144 __FUNCTION__, session, numRequests, requests);
145 return ACAMERA_ERROR_INVALID_PARAMETER;
146 }
147
148 if (session->isClosed()) {
149 ALOGE("%s: session %p is already closed", __FUNCTION__, session);
150 *captureSequenceId = CAPTURE_SEQUENCE_ID_NONE;
151 return ACAMERA_ERROR_SESSION_CLOSED;
152 }
153
154 return session->setRepeatingRequest(lcbs, numRequests, requests, captureSequenceId);
155}
156
157EXPORT
Yin-Chia Yehead91462016-01-06 16:45:08 -0800158camera_status_t ACameraCaptureSession_stopRepeating(ACameraCaptureSession* session) {
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800159 ATRACE_CALL();
Yin-Chia Yehead91462016-01-06 16:45:08 -0800160 if (session == nullptr) {
161 ALOGE("%s: Error: session is null", __FUNCTION__);
162 return ACAMERA_ERROR_INVALID_PARAMETER;
163 }
164
165 if (session->isClosed()) {
166 ALOGE("%s: session %p is already closed", __FUNCTION__, session);
167 return ACAMERA_ERROR_SESSION_CLOSED;
168 }
169 return session->stopRepeating();
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800170}
171
172EXPORT
Yin-Chia Yeh309d05d2016-03-28 10:15:31 -0700173camera_status_t ACameraCaptureSession_abortCaptures(ACameraCaptureSession* session) {
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800174 ATRACE_CALL();
Yin-Chia Yeh309d05d2016-03-28 10:15:31 -0700175 if (session == nullptr) {
176 ALOGE("%s: Error: session is null", __FUNCTION__);
177 return ACAMERA_ERROR_INVALID_PARAMETER;
178 }
179
180 if (session->isClosed()) {
181 ALOGE("%s: session %p is already closed", __FUNCTION__, session);
182 return ACAMERA_ERROR_SESSION_CLOSED;
183 }
184 return session->abortCaptures();
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800185}
Emilian Peev40ead602017-09-26 15:46:36 +0100186
187EXPORT
188camera_status_t ACameraCaptureSession_updateSharedOutput(ACameraCaptureSession* session,
189 ACaptureSessionOutput* output) {
190 ATRACE_CALL();
191 if (session == nullptr) {
192 ALOGE("%s: Error: session is null", __FUNCTION__);
193 return ACAMERA_ERROR_INVALID_PARAMETER;
194 }
195
196 if (session->isClosed()) {
197 ALOGE("%s: session %p is already closed", __FUNCTION__, session);
198 return ACAMERA_ERROR_SESSION_CLOSED;
199 }
200 return session->updateOutputConfiguration(output);
201}