blob: b97fa5f3402ba76cfdd68f4f257e0ff8de5d9601 [file] [log] [blame]
Chien-Yu Chen3068d732015-02-09 13:29:57 -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#ifndef ANDROID_SERVERS_CAMERA_CAMERAFLASHLIGHT_H
18#define ANDROID_SERVERS_CAMERA_CAMERAFLASHLIGHT_H
19
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -080020#include <gui/GLConsumer.h>
21#include <gui/Surface.h>
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -080022#include <utils/KeyedVector.h>
23#include <utils/SortedVector.h>
24#include "common/CameraProviderManager.h"
Chien-Yu Chen3068d732015-02-09 13:29:57 -080025#include "common/CameraDeviceBase.h"
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -080026
Chien-Yu Chen3068d732015-02-09 13:29:57 -080027namespace 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 */
33class 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 Chen88da5262015-02-17 13:56:46 -080041 virtual status_t hasFlashUnit(const String8& cameraId,
Chien-Yu Chen3068d732015-02-09 13:29:57 -080042 bool *hasFlash) = 0;
43
44 // set the torch mode to on or off.
Chien-Yu Chen88da5262015-02-17 13:56:46 -080045 virtual status_t setTorchMode(const String8& cameraId,
Chien-Yu Chen3068d732015-02-09 13:29:57 -080046 bool enabled) = 0;
47};
48
49/**
50 * CameraFlashlight can be used by camera service to control flashflight.
51 */
52class CameraFlashlight : public virtual VirtualLightRefBase {
53 public:
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -080054 CameraFlashlight(sp<CameraProviderManager> providerManager,
Yin-Chia Yehc3e9d6f2018-02-06 10:56:32 -080055 CameraProviderManager::StatusListener* callbacks);
Chien-Yu Chen3068d732015-02-09 13:29:57 -080056 virtual ~CameraFlashlight();
57
Chien-Yu Chen88da5262015-02-17 13:56:46 -080058 // 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 Chen3068d732015-02-09 13:29:57 -080062
Chien-Yu Chen88da5262015-02-17 13:56:46 -080063 // 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 Chen3068d732015-02-09 13:29:57 -080069
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 Chen88da5262015-02-17 13:56:46 -080074 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 Chen3068d732015-02-09 13:29:57 -080080
81 private:
82 // create flashlight control based on camera module API and camera
83 // device API versions.
Chien-Yu Chen88da5262015-02-17 13:56:46 -080084 status_t createFlashlightControl(const String8& cameraId);
85
86 // mLock should be locked.
87 bool hasFlashUnitLocked(const String8& cameraId);
Chien-Yu Chen3068d732015-02-09 13:29:57 -080088
Yin-Chia Yehdc3134e2017-03-23 15:26:59 -070089 // 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 Chen3068d732015-02-09 13:29:57 -080093 sp<FlashControlBase> mFlashControl;
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -080094
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -080095 sp<CameraProviderManager> mProviderManager;
96
Yin-Chia Yehc3e9d6f2018-02-06 10:56:32 -080097 CameraProviderManager::StatusListener* mCallbacks;
Chien-Yu Chen88da5262015-02-17 13:56:46 -080098 SortedVector<String8> mOpenedCameraIds;
Chien-Yu Chen3068d732015-02-09 13:29:57 -080099
Chien-Yu Chen88da5262015-02-17 13:56:46 -0800100 // 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 Chen3068d732015-02-09 13:29:57 -0800105};
106
107/**
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -0800108 * Flash control for camera provider v2.4 and above.
109 */
110class 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 Chen3068d732015-02-09 13:29:57 -0800125} // namespace android
126
127#endif