Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 1 | /* |
| 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 Cross | 7e8d4ba | 2017-05-04 16:17:42 -0700 | [diff] [blame] | 26 | #include <camera/NdkCameraDevice.h> |
| 27 | #include <camera/NdkCaptureRequest.h> |
| 28 | #include <camera/NdkCameraCaptureSession.h> |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 29 | #include "impl/ACameraCaptureSession.h" |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 30 | |
| 31 | using namespace android; |
| 32 | |
| 33 | EXPORT |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 34 | void ACameraCaptureSession_close(ACameraCaptureSession* session) { |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 35 | ATRACE_CALL(); |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 36 | if (session != nullptr) { |
| 37 | session->closeByApp(); |
| 38 | } |
| 39 | return; |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | EXPORT |
| 43 | camera_status_t ACameraCaptureSession_getDevice( |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 44 | ACameraCaptureSession* session, ACameraDevice **device) { |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 45 | ATRACE_CALL(); |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 46 | 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 Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 64 | return ACAMERA_OK; |
| 65 | } |
| 66 | |
| 67 | EXPORT |
| 68 | camera_status_t ACameraCaptureSession_capture( |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 69 | ACameraCaptureSession* session, /*optional*/ACameraCaptureSession_captureCallbacks* cbs, |
| 70 | int numRequests, ACaptureRequest** requests, |
| 71 | /*optional*/int* captureSequenceId) { |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 72 | ATRACE_CALL(); |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 73 | 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 Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | EXPORT |
| 89 | camera_status_t ACameraCaptureSession_setRepeatingRequest( |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 90 | ACameraCaptureSession* session, /*optional*/ACameraCaptureSession_captureCallbacks* cbs, |
| 91 | int numRequests, ACaptureRequest** requests, |
| 92 | /*optional*/int* captureSequenceId) { |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 93 | ATRACE_CALL(); |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 94 | 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 Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | EXPORT |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 110 | camera_status_t ACameraCaptureSession_stopRepeating(ACameraCaptureSession* session) { |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 111 | ATRACE_CALL(); |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 112 | 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 Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | EXPORT |
Yin-Chia Yeh | 309d05d | 2016-03-28 10:15:31 -0700 | [diff] [blame] | 125 | camera_status_t ACameraCaptureSession_abortCaptures(ACameraCaptureSession* session) { |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 126 | ATRACE_CALL(); |
Yin-Chia Yeh | 309d05d | 2016-03-28 10:15:31 -0700 | [diff] [blame] | 127 | 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 Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 137 | } |