Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 | #ifndef _ACAMERA_CAPTURE_SESSION_H |
| 17 | #define _ACAMERA_CAPTURE_SESSION_H |
| 18 | |
| 19 | #include <set> |
| 20 | #include <hardware/camera3.h> |
Colin Cross | 7e8d4ba | 2017-05-04 16:17:42 -0700 | [diff] [blame] | 21 | #include <camera/NdkCameraDevice.h> |
Jayant Chowdhary | 6df2607 | 2018-11-06 23:55:12 -0800 | [diff] [blame] | 22 | |
| 23 | #ifdef __ANDROID_VNDK__ |
| 24 | #include "ndk_vendor/impl/ACameraDevice.h" |
| 25 | #include "ndk_vendor/impl/ACameraCaptureSessionVendor.h" |
| 26 | #else |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 27 | #include "ACameraDevice.h" |
| 28 | |
| 29 | using namespace android; |
| 30 | |
| 31 | struct ACaptureSessionOutput { |
Jayant Chowdhary | 6df2607 | 2018-11-06 23:55:12 -0800 | [diff] [blame] | 32 | explicit ACaptureSessionOutput(ACameraWindowType* window, bool isShared = false) : |
Emilian Peev | 40ead60 | 2017-09-26 15:46:36 +0100 | [diff] [blame] | 33 | mWindow(window), mIsShared(isShared) {}; |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 34 | |
| 35 | bool operator == (const ACaptureSessionOutput& other) const { |
| 36 | return mWindow == other.mWindow; |
| 37 | } |
| 38 | bool operator != (const ACaptureSessionOutput& other) const { |
| 39 | return mWindow != other.mWindow; |
| 40 | } |
| 41 | bool operator < (const ACaptureSessionOutput& other) const { |
| 42 | return mWindow < other.mWindow; |
| 43 | } |
| 44 | bool operator > (const ACaptureSessionOutput& other) const { |
| 45 | return mWindow > other.mWindow; |
| 46 | } |
| 47 | |
Jayant Chowdhary | 6df2607 | 2018-11-06 23:55:12 -0800 | [diff] [blame] | 48 | ACameraWindowType* mWindow; |
| 49 | std::set<ACameraWindowType *> mSharedWindows; |
Emilian Peev | 40ead60 | 2017-09-26 15:46:36 +0100 | [diff] [blame] | 50 | bool mIsShared; |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 51 | int mRotation = CAMERA3_STREAM_ROTATION_0; |
| 52 | }; |
Jayant Chowdhary | 6df2607 | 2018-11-06 23:55:12 -0800 | [diff] [blame] | 53 | #endif |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 54 | |
| 55 | struct ACaptureSessionOutputContainer { |
| 56 | std::set<ACaptureSessionOutput> mOutputs; |
| 57 | }; |
| 58 | |
| 59 | /** |
| 60 | * ACameraCaptureSession opaque struct definition |
| 61 | * Leave outside of android namespace because it's NDK struct |
| 62 | */ |
| 63 | struct ACameraCaptureSession : public RefBase { |
| 64 | public: |
| 65 | ACameraCaptureSession( |
| 66 | int id, |
| 67 | const ACaptureSessionOutputContainer* outputs, |
| 68 | const ACameraCaptureSession_stateCallbacks* cb, |
Jayant Chowdhary | 6df2607 | 2018-11-06 23:55:12 -0800 | [diff] [blame] | 69 | android::acam::CameraDevice* device) : |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 70 | mId(id), mOutput(*outputs), mUserSessionCallback(*cb), |
| 71 | mDevice(device) {} |
| 72 | |
| 73 | // This can be called in app calling close() or after some app callback is finished |
| 74 | // Make sure the caller does not hold device or session lock! |
| 75 | ~ACameraCaptureSession(); |
| 76 | |
| 77 | // No API except Session_Close will work if device is closed |
| 78 | // A session will enter closed state when one of the following happens: |
| 79 | // 1. Explicitly closed by app |
| 80 | // 2. Replaced by a newer session |
| 81 | // 3. Device is closed |
| 82 | bool isClosed() { Mutex::Autolock _l(mSessionLock); return mIsClosed; } |
| 83 | |
| 84 | // Close the session and mark app no longer need this session. |
| 85 | void closeByApp(); |
| 86 | |
| 87 | camera_status_t stopRepeating(); |
| 88 | |
Yin-Chia Yeh | 309d05d | 2016-03-28 10:15:31 -0700 | [diff] [blame] | 89 | camera_status_t abortCaptures(); |
| 90 | |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 91 | camera_status_t setRepeatingRequest( |
| 92 | /*optional*/ACameraCaptureSession_captureCallbacks* cbs, |
| 93 | int numRequests, ACaptureRequest** requests, |
| 94 | /*optional*/int* captureSequenceId); |
| 95 | |
| 96 | camera_status_t capture( |
| 97 | /*optional*/ACameraCaptureSession_captureCallbacks* cbs, |
| 98 | int numRequests, ACaptureRequest** requests, |
| 99 | /*optional*/int* captureSequenceId); |
| 100 | |
Emilian Peev | 40ead60 | 2017-09-26 15:46:36 +0100 | [diff] [blame] | 101 | camera_status_t updateOutputConfiguration(ACaptureSessionOutput *output); |
| 102 | |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 103 | ACameraDevice* getDevice(); |
| 104 | |
| 105 | private: |
Jayant Chowdhary | 6df2607 | 2018-11-06 23:55:12 -0800 | [diff] [blame] | 106 | friend class android::acam::CameraDevice; |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 107 | |
| 108 | // Close session because app close camera device, camera device got ERROR_DISCONNECTED, |
| 109 | // or a new session is replacing this session. |
| 110 | void closeByDevice(); |
| 111 | |
Jayant Chowdhary | 6df2607 | 2018-11-06 23:55:12 -0800 | [diff] [blame] | 112 | sp<android::acam::CameraDevice> getDeviceSp(); |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 113 | |
| 114 | const int mId; |
| 115 | const ACaptureSessionOutputContainer mOutput; |
| 116 | const ACameraCaptureSession_stateCallbacks mUserSessionCallback; |
Jayant Chowdhary | 6df2607 | 2018-11-06 23:55:12 -0800 | [diff] [blame] | 117 | const wp<android::acam::CameraDevice> mDevice; |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 118 | bool mIsClosed = false; |
Yin-Chia Yeh | 085dd09 | 2016-03-02 14:16:31 -0800 | [diff] [blame] | 119 | bool mClosedByApp = false; |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 120 | Mutex mSessionLock; |
| 121 | }; |
| 122 | |
| 123 | #endif // _ACAMERA_CAPTURE_SESSION_H |