blob: a0de0b00b31209e6c1f1b4c684c0ce92cc53d70b [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
20#include "hardware/camera_common.h"
21#include "utils/KeyedVector.h"
22#include "gui/GLConsumer.h"
23#include "gui/Surface.h"
24#include "common/CameraDeviceBase.h"
25
26namespace android {
27
28/**
29 * FlashControlBase is a base class for flash control. It defines the functions
30 * that a flash control for each camera module/device version should implement.
31 */
32class FlashControlBase : public virtual VirtualLightRefBase {
33 public:
34 virtual ~FlashControlBase();
35
36 // Whether a camera device has a flash unit. Calling this function may
37 // cause the torch mode to be turned off in HAL v1 devices. If
38 // previously-on torch mode is turned off,
39 // callbacks.torch_mode_status_change() should be invoked.
40 virtual status_t hasFlashUnit(const String16& cameraId,
41 bool *hasFlash) = 0;
42
43 // set the torch mode to on or off.
44 virtual status_t setTorchMode(const String16& cameraId,
45 bool enabled) = 0;
46};
47
48/**
49 * CameraFlashlight can be used by camera service to control flashflight.
50 */
51class CameraFlashlight : public virtual VirtualLightRefBase {
52 public:
53 CameraFlashlight(CameraModule& cameraModule,
54 const camera_module_callbacks_t& callbacks);
55 virtual ~CameraFlashlight();
56
57 // set the torch mode to on or off.
58 status_t setTorchMode(const String16& cameraId, bool enabled);
59
60 // Whether a camera device has a flash unit. Calling this function may
61 // cause the torch mode to be turned off in HAL v1 devices.
62 bool hasFlashUnit(const String16& cameraId);
63
64 // Notify CameraFlashlight that camera service is going to open a camera
65 // device. CameraFlashlight will free the resources that may cause the
66 // camera open to fail. Camera service must call this function before
67 // opening a camera device.
68 status_t prepareDeviceOpen();
69
70 private:
71 // create flashlight control based on camera module API and camera
72 // device API versions.
73 status_t createFlashlightControl(const String16& cameraId);
74
75 sp<FlashControlBase> mFlashControl;
76 CameraModule *mCameraModule;
77 const camera_module_callbacks_t *mCallbacks;
78
79 Mutex mLock;
80};
81
82/**
83 * Flash control for camera module v2.4 and above.
84 */
85class FlashControl : public FlashControlBase {
86 public:
87 FlashControl(CameraModule& cameraModule,
88 const camera_module_callbacks_t& callbacks);
89 virtual ~FlashControl();
90
91 // FlashControlBase
92 status_t hasFlashUnit(const String16& cameraId, bool *hasFlash);
93 status_t setTorchMode(const String16& cameraId, bool enabled);
94
95 private:
96 CameraModule *mCameraModule;
97
98 Mutex mLock;
99};
100
101/**
102 * Flash control for camera module <= v2.3 and camera HAL v2-v3
103 */
104class CameraDeviceClientFlashControl : public FlashControlBase {
105 public:
106 CameraDeviceClientFlashControl(CameraModule& cameraModule,
107 const camera_module_callbacks_t& callbacks);
108 virtual ~CameraDeviceClientFlashControl();
109
110 // FlashControlBase
111 status_t setTorchMode(const String16& cameraId, bool enabled);
112 status_t hasFlashUnit(const String16& cameraId, bool *hasFlash);
113
114 private:
115 // connect to a camera device
116 status_t connectCameraDevice(const String16& cameraId);
117
118 // initialize a surface
119 status_t initializeSurface(int32_t width, int32_t height);
120
121 // submit a request with the given torch mode
122 status_t submitTorchRequest(bool enabled);
123
124 // get the smallest surface size of IMPLEMENTATION_DEFINED
125 status_t getSmallestSurfaceSize(const camera_info& info, int32_t *width,
126 int32_t *height);
127
128 status_t hasFlashUnitLocked(const String16& cameraId, bool *hasFlash);
129
130 CameraModule *mCameraModule;
131 const camera_module_callbacks_t *mCallbacks;
132 String16 mCameraId;
133 bool mTorchEnabled;
134 CameraMetadata *mMetadata;
135
136 sp<CameraDeviceBase> mDevice;
137
138 sp<IGraphicBufferProducer> mProducer;
139 sp<IGraphicBufferConsumer> mConsumer;
140 sp<GLConsumer> mSurfaceTexture;
141 sp<ANativeWindow> mAnw;
142 int32_t mStreamId;
143
144 Mutex mLock;
145};
146
147} // namespace android
148
149#endif