Chien-Yu Chen | 3068d73 | 2015-02-09 13:29:57 -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 | #ifndef ANDROID_SERVERS_CAMERA_CAMERAFLASHLIGHT_H |
| 18 | #define ANDROID_SERVERS_CAMERA_CAMERAFLASHLIGHT_H |
| 19 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 20 | #include <gui/GLConsumer.h> |
| 21 | #include <gui/Surface.h> |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 22 | #include <utils/KeyedVector.h> |
| 23 | #include <utils/SortedVector.h> |
| 24 | #include "common/CameraProviderManager.h" |
Chien-Yu Chen | 3068d73 | 2015-02-09 13:29:57 -0800 | [diff] [blame] | 25 | #include "common/CameraDeviceBase.h" |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 26 | |
Chien-Yu Chen | 3068d73 | 2015-02-09 13:29:57 -0800 | [diff] [blame] | 27 | namespace android { |
| 28 | |
| 29 | /** |
| 30 | * FlashControlBase is a base class for flash control. It defines the functions |
| 31 | * that a flash control for each camera module/device version should implement. |
| 32 | */ |
| 33 | class FlashControlBase : public virtual VirtualLightRefBase { |
| 34 | public: |
| 35 | virtual ~FlashControlBase(); |
| 36 | |
| 37 | // Whether a camera device has a flash unit. Calling this function may |
| 38 | // cause the torch mode to be turned off in HAL v1 devices. If |
| 39 | // previously-on torch mode is turned off, |
| 40 | // callbacks.torch_mode_status_change() should be invoked. |
Chien-Yu Chen | 88da526 | 2015-02-17 13:56:46 -0800 | [diff] [blame] | 41 | virtual status_t hasFlashUnit(const String8& cameraId, |
Chien-Yu Chen | 3068d73 | 2015-02-09 13:29:57 -0800 | [diff] [blame] | 42 | bool *hasFlash) = 0; |
| 43 | |
| 44 | // set the torch mode to on or off. |
Chien-Yu Chen | 88da526 | 2015-02-17 13:56:46 -0800 | [diff] [blame] | 45 | virtual status_t setTorchMode(const String8& cameraId, |
Chien-Yu Chen | 3068d73 | 2015-02-09 13:29:57 -0800 | [diff] [blame] | 46 | bool enabled) = 0; |
| 47 | }; |
| 48 | |
| 49 | /** |
| 50 | * CameraFlashlight can be used by camera service to control flashflight. |
| 51 | */ |
| 52 | class CameraFlashlight : public virtual VirtualLightRefBase { |
| 53 | public: |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 54 | CameraFlashlight(sp<CameraProviderManager> providerManager, |
Yin-Chia Yeh | c3e9d6f | 2018-02-06 10:56:32 -0800 | [diff] [blame] | 55 | CameraProviderManager::StatusListener* callbacks); |
Chien-Yu Chen | 3068d73 | 2015-02-09 13:29:57 -0800 | [diff] [blame] | 56 | virtual ~CameraFlashlight(); |
| 57 | |
Chien-Yu Chen | 88da526 | 2015-02-17 13:56:46 -0800 | [diff] [blame] | 58 | // Find all flash units. This must be called before other methods. All |
| 59 | // camera devices must be closed when it's called because HAL v1 devices |
| 60 | // need to be opened to query available flash modes. |
| 61 | status_t findFlashUnits(); |
Chien-Yu Chen | 3068d73 | 2015-02-09 13:29:57 -0800 | [diff] [blame] | 62 | |
Chien-Yu Chen | 88da526 | 2015-02-17 13:56:46 -0800 | [diff] [blame] | 63 | // Whether a camera device has a flash unit. Before findFlashUnits() is |
| 64 | // called, this function always returns false. |
| 65 | bool hasFlashUnit(const String8& cameraId); |
| 66 | |
| 67 | // set the torch mode to on or off. |
| 68 | status_t setTorchMode(const String8& cameraId, bool enabled); |
Chien-Yu Chen | 3068d73 | 2015-02-09 13:29:57 -0800 | [diff] [blame] | 69 | |
| 70 | // Notify CameraFlashlight that camera service is going to open a camera |
| 71 | // device. CameraFlashlight will free the resources that may cause the |
| 72 | // camera open to fail. Camera service must call this function before |
| 73 | // opening a camera device. |
Chien-Yu Chen | 88da526 | 2015-02-17 13:56:46 -0800 | [diff] [blame] | 74 | status_t prepareDeviceOpen(const String8& cameraId); |
| 75 | |
| 76 | // Notify CameraFlashlight that camera service has closed a camera |
| 77 | // device. CameraFlashlight may invoke callbacks for torch mode |
| 78 | // available depending on the implementation. |
| 79 | status_t deviceClosed(const String8& cameraId); |
Chien-Yu Chen | 3068d73 | 2015-02-09 13:29:57 -0800 | [diff] [blame] | 80 | |
| 81 | private: |
| 82 | // create flashlight control based on camera module API and camera |
| 83 | // device API versions. |
Chien-Yu Chen | 88da526 | 2015-02-17 13:56:46 -0800 | [diff] [blame] | 84 | status_t createFlashlightControl(const String8& cameraId); |
| 85 | |
| 86 | // mLock should be locked. |
| 87 | bool hasFlashUnitLocked(const String8& cameraId); |
Chien-Yu Chen | 3068d73 | 2015-02-09 13:29:57 -0800 | [diff] [blame] | 88 | |
Yin-Chia Yeh | dc3134e | 2017-03-23 15:26:59 -0700 | [diff] [blame] | 89 | // Check if flash control is in backward compatible mode (simulated torch API by |
| 90 | // opening cameras) |
| 91 | bool isBackwardCompatibleMode(const String8& cameraId); |
| 92 | |
Chien-Yu Chen | 3068d73 | 2015-02-09 13:29:57 -0800 | [diff] [blame] | 93 | sp<FlashControlBase> mFlashControl; |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 94 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 95 | sp<CameraProviderManager> mProviderManager; |
| 96 | |
Yin-Chia Yeh | c3e9d6f | 2018-02-06 10:56:32 -0800 | [diff] [blame] | 97 | CameraProviderManager::StatusListener* mCallbacks; |
Chien-Yu Chen | 88da526 | 2015-02-17 13:56:46 -0800 | [diff] [blame] | 98 | SortedVector<String8> mOpenedCameraIds; |
Chien-Yu Chen | 3068d73 | 2015-02-09 13:29:57 -0800 | [diff] [blame] | 99 | |
Chien-Yu Chen | 88da526 | 2015-02-17 13:56:46 -0800 | [diff] [blame] | 100 | // camera id -> if it has a flash unit |
| 101 | KeyedVector<String8, bool> mHasFlashlightMap; |
| 102 | bool mFlashlightMapInitialized; |
| 103 | |
| 104 | Mutex mLock; // protect CameraFlashlight API |
Chien-Yu Chen | 3068d73 | 2015-02-09 13:29:57 -0800 | [diff] [blame] | 105 | }; |
| 106 | |
| 107 | /** |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 108 | * Flash control for camera provider v2.4 and above. |
| 109 | */ |
| 110 | class ProviderFlashControl : public FlashControlBase { |
| 111 | public: |
| 112 | ProviderFlashControl(sp<CameraProviderManager> providerManager); |
| 113 | virtual ~ProviderFlashControl(); |
| 114 | |
| 115 | // FlashControlBase |
| 116 | status_t hasFlashUnit(const String8& cameraId, bool *hasFlash); |
| 117 | status_t setTorchMode(const String8& cameraId, bool enabled); |
| 118 | |
| 119 | private: |
| 120 | sp<CameraProviderManager> mProviderManager; |
| 121 | |
| 122 | Mutex mLock; |
| 123 | }; |
| 124 | |
Chien-Yu Chen | 3068d73 | 2015-02-09 13:29:57 -0800 | [diff] [blame] | 125 | } // namespace android |
| 126 | |
| 127 | #endif |