|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
|
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
4 |
|
5 #ifndef DOM_CAMERA_ICAMERACONTROL_H |
|
6 #define DOM_CAMERA_ICAMERACONTROL_H |
|
7 |
|
8 #include "nsCOMPtr.h" |
|
9 #include "nsString.h" |
|
10 #include "nsAutoPtr.h" |
|
11 #include "nsISupportsImpl.h" |
|
12 |
|
13 struct DeviceStorageFileDescriptor; |
|
14 |
|
15 class nsIFile; |
|
16 |
|
17 namespace mozilla { |
|
18 |
|
19 class CameraControlListener; |
|
20 class RecorderProfileManager; |
|
21 |
|
22 // XXXmikeh - In some future patch this should move into the ICameraControl |
|
23 // class as well, and the names updated to the 'k'-style; |
|
24 // e.g. kParamPreviewSize, etc. |
|
25 enum { |
|
26 // current settings |
|
27 CAMERA_PARAM_PREVIEWSIZE, |
|
28 CAMERA_PARAM_PREVIEWFORMAT, |
|
29 CAMERA_PARAM_PREVIEWFRAMERATE, |
|
30 CAMERA_PARAM_VIDEOSIZE, |
|
31 CAMERA_PARAM_PICTURE_SIZE, |
|
32 CAMERA_PARAM_PICTURE_FILEFORMAT, |
|
33 CAMERA_PARAM_PICTURE_ROTATION, |
|
34 CAMERA_PARAM_PICTURE_LOCATION, |
|
35 CAMERA_PARAM_PICTURE_DATETIME, |
|
36 CAMERA_PARAM_EFFECT, |
|
37 CAMERA_PARAM_WHITEBALANCE, |
|
38 CAMERA_PARAM_SCENEMODE, |
|
39 CAMERA_PARAM_FLASHMODE, |
|
40 CAMERA_PARAM_FOCUSMODE, |
|
41 CAMERA_PARAM_ZOOM, |
|
42 CAMERA_PARAM_METERINGAREAS, |
|
43 CAMERA_PARAM_FOCUSAREAS, |
|
44 CAMERA_PARAM_FOCALLENGTH, |
|
45 CAMERA_PARAM_FOCUSDISTANCENEAR, |
|
46 CAMERA_PARAM_FOCUSDISTANCEOPTIMUM, |
|
47 CAMERA_PARAM_FOCUSDISTANCEFAR, |
|
48 CAMERA_PARAM_EXPOSURECOMPENSATION, |
|
49 CAMERA_PARAM_THUMBNAILSIZE, |
|
50 CAMERA_PARAM_THUMBNAILQUALITY, |
|
51 CAMERA_PARAM_SENSORANGLE, |
|
52 CAMERA_PARAM_ISOMODE, |
|
53 CAMERA_PARAM_LUMINANCE, |
|
54 CAMERA_PARAM_SCENEMODE_HDR_RETURNNORMALPICTURE, |
|
55 |
|
56 // supported features |
|
57 CAMERA_PARAM_SUPPORTED_PREVIEWSIZES, |
|
58 CAMERA_PARAM_SUPPORTED_PICTURESIZES, |
|
59 CAMERA_PARAM_SUPPORTED_VIDEOSIZES, |
|
60 CAMERA_PARAM_SUPPORTED_PICTUREFORMATS, |
|
61 CAMERA_PARAM_SUPPORTED_WHITEBALANCES, |
|
62 CAMERA_PARAM_SUPPORTED_SCENEMODES, |
|
63 CAMERA_PARAM_SUPPORTED_EFFECTS, |
|
64 CAMERA_PARAM_SUPPORTED_FLASHMODES, |
|
65 CAMERA_PARAM_SUPPORTED_FOCUSMODES, |
|
66 CAMERA_PARAM_SUPPORTED_MAXFOCUSAREAS, |
|
67 CAMERA_PARAM_SUPPORTED_MAXMETERINGAREAS, |
|
68 CAMERA_PARAM_SUPPORTED_MINEXPOSURECOMPENSATION, |
|
69 CAMERA_PARAM_SUPPORTED_MAXEXPOSURECOMPENSATION, |
|
70 CAMERA_PARAM_SUPPORTED_EXPOSURECOMPENSATIONSTEP, |
|
71 CAMERA_PARAM_SUPPORTED_ZOOM, |
|
72 CAMERA_PARAM_SUPPORTED_ZOOMRATIOS, |
|
73 CAMERA_PARAM_SUPPORTED_MAXDETECTEDFACES, |
|
74 CAMERA_PARAM_SUPPORTED_JPEG_THUMBNAIL_SIZES, |
|
75 CAMERA_PARAM_SUPPORTED_ISOMODES |
|
76 }; |
|
77 |
|
78 class ICameraControl |
|
79 { |
|
80 public: |
|
81 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(ICameraControl) |
|
82 |
|
83 static nsresult GetNumberOfCameras(int32_t& aDeviceCount); |
|
84 static nsresult GetCameraName(uint32_t aDeviceNum, nsCString& aDeviceName); |
|
85 static nsresult GetListOfCameras(nsTArray<nsString>& aList); |
|
86 |
|
87 enum Mode { |
|
88 kUnspecifiedMode, |
|
89 kPictureMode, |
|
90 kVideoMode, |
|
91 }; |
|
92 |
|
93 struct Size { |
|
94 uint32_t width; |
|
95 uint32_t height; |
|
96 }; |
|
97 |
|
98 struct Region { |
|
99 int32_t top; |
|
100 int32_t left; |
|
101 int32_t bottom; |
|
102 int32_t right; |
|
103 uint32_t weight; |
|
104 }; |
|
105 |
|
106 struct Position { |
|
107 double latitude; |
|
108 double longitude; |
|
109 double altitude; |
|
110 double timestamp; |
|
111 }; |
|
112 |
|
113 struct StartRecordingOptions { |
|
114 uint32_t rotation; |
|
115 uint32_t maxFileSizeBytes; |
|
116 uint32_t maxVideoLengthMs; |
|
117 bool autoEnableLowLightTorch; |
|
118 }; |
|
119 |
|
120 struct Configuration { |
|
121 Mode mMode; |
|
122 Size mPreviewSize; |
|
123 nsString mRecorderProfile; |
|
124 }; |
|
125 |
|
126 struct Point |
|
127 { |
|
128 int32_t x; |
|
129 int32_t y; |
|
130 }; |
|
131 |
|
132 struct Face { |
|
133 uint32_t id; |
|
134 uint32_t score; |
|
135 Region bound; |
|
136 bool hasLeftEye; |
|
137 Point leftEye; |
|
138 bool hasRightEye; |
|
139 Point rightEye; |
|
140 bool hasMouth; |
|
141 Point mouth; |
|
142 }; |
|
143 |
|
144 static already_AddRefed<ICameraControl> Create(uint32_t aCameraId); |
|
145 |
|
146 virtual nsresult Start(const Configuration* aInitialConfig = nullptr) = 0; |
|
147 virtual nsresult Stop() = 0; |
|
148 |
|
149 virtual nsresult SetConfiguration(const Configuration& aConfig) = 0; |
|
150 |
|
151 virtual void AddListener(CameraControlListener* aListener) = 0; |
|
152 virtual void RemoveListener(CameraControlListener* aListener) = 0; |
|
153 |
|
154 virtual nsresult StartPreview() = 0; |
|
155 virtual nsresult StopPreview() = 0; |
|
156 virtual nsresult AutoFocus() = 0; |
|
157 virtual nsresult TakePicture() = 0; |
|
158 virtual nsresult StartRecording(DeviceStorageFileDescriptor *aFileDescriptor, |
|
159 const StartRecordingOptions* aOptions = nullptr) = 0; |
|
160 virtual nsresult StopRecording() = 0; |
|
161 virtual nsresult StartFaceDetection() = 0; |
|
162 virtual nsresult StopFaceDetection() = 0; |
|
163 virtual nsresult ResumeContinuousFocus() = 0; |
|
164 |
|
165 virtual nsresult Set(uint32_t aKey, const nsAString& aValue) = 0; |
|
166 virtual nsresult Get(uint32_t aKey, nsAString& aValue) = 0; |
|
167 virtual nsresult Set(uint32_t aKey, double aValue) = 0; |
|
168 virtual nsresult Get(uint32_t aKey, double& aValue) = 0; |
|
169 virtual nsresult Set(uint32_t aKey, int32_t aValue) = 0; |
|
170 virtual nsresult Get(uint32_t aKey, int32_t& aValue) = 0; |
|
171 virtual nsresult Set(uint32_t aKey, int64_t aValue) = 0; |
|
172 virtual nsresult Get(uint32_t aKey, int64_t& aValue) = 0; |
|
173 virtual nsresult Set(uint32_t aKey, const Size& aValue) = 0; |
|
174 virtual nsresult Get(uint32_t aKey, Size& aValue) = 0; |
|
175 virtual nsresult Set(uint32_t aKey, const nsTArray<Region>& aRegions) = 0; |
|
176 virtual nsresult Get(uint32_t aKey, nsTArray<Region>& aRegions) = 0; |
|
177 |
|
178 virtual nsresult SetLocation(const Position& aLocation) = 0; |
|
179 |
|
180 virtual nsresult Get(uint32_t aKey, nsTArray<Size>& aSizes) = 0; |
|
181 virtual nsresult Get(uint32_t aKey, nsTArray<nsString>& aValues) = 0; |
|
182 virtual nsresult Get(uint32_t aKey, nsTArray<double>& aValues) = 0; |
|
183 |
|
184 virtual already_AddRefed<RecorderProfileManager> GetRecorderProfileManager() = 0; |
|
185 virtual uint32_t GetCameraId() = 0; |
|
186 |
|
187 virtual void Shutdown() = 0; |
|
188 |
|
189 protected: |
|
190 virtual ~ICameraControl() { } |
|
191 |
|
192 friend class ICameraControlParameterSetAutoEnter; |
|
193 |
|
194 virtual void BeginBatchParameterSet() = 0; |
|
195 virtual void EndBatchParameterSet() = 0; |
|
196 }; |
|
197 |
|
198 // Helper class to make it easy to update a batch of camera parameters; |
|
199 // the parameters are applied atomically when this object goes out of |
|
200 // scope. |
|
201 class ICameraControlParameterSetAutoEnter |
|
202 { |
|
203 public: |
|
204 ICameraControlParameterSetAutoEnter(ICameraControl* aCameraControl) |
|
205 : mCameraControl(aCameraControl) |
|
206 { |
|
207 mCameraControl->BeginBatchParameterSet(); |
|
208 } |
|
209 virtual ~ICameraControlParameterSetAutoEnter() |
|
210 { |
|
211 mCameraControl->EndBatchParameterSet(); |
|
212 } |
|
213 |
|
214 protected: |
|
215 nsRefPtr<ICameraControl> mCameraControl; |
|
216 }; |
|
217 |
|
218 } // namespace mozilla |
|
219 |
|
220 #endif // DOM_CAMERA_ICAMERACONTROL_H |