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