Bumping gaia.json for 2 gaia revision(s) a=gaia-bump
[gecko.git] / dom / camera / GonkCameraControl.h
blob7203d39b6dd1f76d4308b9ff42292255363215dc
1 /*
2 * Copyright (C) 2012-2014 Mozilla Foundation
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef DOM_CAMERA_GONKCAMERACONTROL_H
18 #define DOM_CAMERA_GONKCAMERACONTROL_H
20 #include "base/basictypes.h"
21 #include <media/MediaProfiles.h>
22 #include "mozilla/ReentrantMonitor.h"
23 #include "DeviceStorage.h"
24 #include "CameraControlImpl.h"
25 #include "CameraCommon.h"
26 #include "GonkRecorder.h"
27 #include "GonkCameraHwMgr.h"
28 #include "GonkCameraParameters.h"
30 namespace android {
31 class GonkCameraHardware;
32 class MediaProfiles;
33 class GonkRecorder;
36 namespace mozilla {
38 namespace layers {
39 class TextureClient;
40 class ImageContainer;
43 class GonkRecorderProfile;
44 class GonkRecorderProfileManager;
46 class nsGonkCameraControl : public CameraControlImpl
48 public:
49 nsGonkCameraControl(uint32_t aCameraId);
51 void OnAutoFocusComplete(bool aSuccess);
52 void OnFacesDetected(camera_frame_metadata_t* aMetaData);
53 void OnTakePictureComplete(uint8_t* aData, uint32_t aLength);
54 void OnTakePictureError();
55 void OnRateLimitPreview(bool aLimit);
56 void OnNewPreviewFrame(layers::TextureClient* aBuffer);
57 void OnRecorderEvent(int msg, int ext1, int ext2);
58 void OnSystemError(CameraControlListener::SystemContext aWhere, nsresult aError);
60 // See ICameraControl.h for getter/setter return values.
61 virtual nsresult Set(uint32_t aKey, const nsAString& aValue) MOZ_OVERRIDE;
62 virtual nsresult Get(uint32_t aKey, nsAString& aValue) MOZ_OVERRIDE;
63 virtual nsresult Set(uint32_t aKey, double aValue) MOZ_OVERRIDE;
64 virtual nsresult Get(uint32_t aKey, double& aValue) MOZ_OVERRIDE;
65 virtual nsresult Set(uint32_t aKey, int32_t aValue) MOZ_OVERRIDE;
66 virtual nsresult Get(uint32_t aKey, int32_t& aValue) MOZ_OVERRIDE;
67 virtual nsresult Set(uint32_t aKey, int64_t aValue) MOZ_OVERRIDE;
68 virtual nsresult Get(uint32_t aKey, int64_t& aValue) MOZ_OVERRIDE;
69 virtual nsresult Set(uint32_t aKey, bool aValue) MOZ_OVERRIDE;
70 virtual nsresult Get(uint32_t aKey, bool& aValue) MOZ_OVERRIDE;
71 virtual nsresult Set(uint32_t aKey, const Size& aValue) MOZ_OVERRIDE;
72 virtual nsresult Get(uint32_t aKey, Size& aValue) MOZ_OVERRIDE;
73 virtual nsresult Set(uint32_t aKey, const nsTArray<Region>& aRegions) MOZ_OVERRIDE;
74 virtual nsresult Get(uint32_t aKey, nsTArray<Region>& aRegions) MOZ_OVERRIDE;
76 virtual nsresult SetLocation(const Position& aLocation) MOZ_OVERRIDE;
78 virtual nsresult Get(uint32_t aKey, nsTArray<Size>& aSizes) MOZ_OVERRIDE;
79 virtual nsresult Get(uint32_t aKey, nsTArray<nsString>& aValues) MOZ_OVERRIDE;
80 virtual nsresult Get(uint32_t aKey, nsTArray<double>& aValues) MOZ_OVERRIDE;
82 nsresult PushParameters();
83 nsresult PullParameters();
85 protected:
86 ~nsGonkCameraControl();
88 using CameraControlImpl::OnRateLimitPreview;
89 using CameraControlImpl::OnNewPreviewFrame;
90 using CameraControlImpl::OnAutoFocusComplete;
91 using CameraControlImpl::OnFacesDetected;
92 using CameraControlImpl::OnTakePictureComplete;
93 using CameraControlImpl::OnConfigurationChange;
94 using CameraControlImpl::OnUserError;
96 virtual void BeginBatchParameterSet() MOZ_OVERRIDE;
97 virtual void EndBatchParameterSet() MOZ_OVERRIDE;
99 nsresult Initialize();
101 nsresult SetConfigurationInternal(const Configuration& aConfig);
102 nsresult SetPictureConfiguration(const Configuration& aConfig);
103 nsresult SetVideoConfiguration(const Configuration& aConfig);
105 template<class T> nsresult SetAndPush(uint32_t aKey, const T& aValue);
107 // See CameraControlImpl.h for these methods' return values.
108 virtual nsresult StartImpl(const Configuration* aInitialConfig = nullptr) MOZ_OVERRIDE;
109 virtual nsresult SetConfigurationImpl(const Configuration& aConfig) MOZ_OVERRIDE;
110 virtual nsresult StopImpl() MOZ_OVERRIDE;
111 virtual nsresult StartPreviewImpl() MOZ_OVERRIDE;
112 virtual nsresult StopPreviewImpl() MOZ_OVERRIDE;
113 virtual nsresult AutoFocusImpl() MOZ_OVERRIDE;
114 virtual nsresult StartFaceDetectionImpl() MOZ_OVERRIDE;
115 virtual nsresult StopFaceDetectionImpl() MOZ_OVERRIDE;
116 virtual nsresult TakePictureImpl() MOZ_OVERRIDE;
117 virtual nsresult StartRecordingImpl(DeviceStorageFileDescriptor* aFileDescriptor,
118 const StartRecordingOptions* aOptions = nullptr) MOZ_OVERRIDE;
119 virtual nsresult StopRecordingImpl() MOZ_OVERRIDE;
120 virtual nsresult ResumeContinuousFocusImpl() MOZ_OVERRIDE;
121 virtual nsresult PushParametersImpl() MOZ_OVERRIDE;
122 virtual nsresult PullParametersImpl() MOZ_OVERRIDE;
123 virtual already_AddRefed<RecorderProfileManager> GetRecorderProfileManagerImpl() MOZ_OVERRIDE;
124 already_AddRefed<GonkRecorderProfileManager> GetGonkRecorderProfileManager();
126 nsresult SetupRecording(int aFd, int aRotation, uint64_t aMaxFileSizeBytes,
127 uint64_t aMaxVideoLengthMs);
128 nsresult SetupRecordingFlash(bool aAutoEnableLowLightTorch);
129 nsresult SetPreviewSize(const Size& aSize);
130 nsresult SetVideoSize(const Size& aSize);
131 nsresult PausePreview();
132 nsresult GetSupportedSize(const Size& aSize, const nsTArray<Size>& supportedSizes, Size& best);
134 friend class SetPictureSize;
135 friend class SetThumbnailSize;
136 nsresult SetPictureSize(const Size& aSize);
137 nsresult SetPictureSizeImpl(const Size& aSize);
138 nsresult SetThumbnailSize(const Size& aSize);
139 nsresult UpdateThumbnailSize();
140 nsresult SetThumbnailSizeImpl(const Size& aSize);
142 int32_t RationalizeRotation(int32_t aRotation);
144 uint32_t mCameraId;
145 android::sp<android::GonkCameraHardware> mCameraHw;
147 Size mLastPictureSize;
148 Size mLastThumbnailSize;
149 Size mLastRecorderSize;
150 uint32_t mPreviewFps;
151 bool mResumePreviewAfterTakingPicture;
152 bool mFlashSupported;
153 bool mLuminanceSupported;
154 bool mAutoFlashModeOverridden;
155 bool mSeparateVideoAndPreviewSizesSupported;
156 Atomic<uint32_t> mDeferConfigUpdate;
157 GonkCameraParameters mParams;
159 nsRefPtr<mozilla::layers::ImageContainer> mImageContainer;
161 android::MediaProfiles* mMediaProfiles;
162 nsRefPtr<android::GonkRecorder> mRecorder;
163 // Touching mRecorder happens inside this monitor because the destructor
164 // can run on any thread, and we need to be able to clean up properly if
165 // GonkCameraControl goes away.
166 ReentrantMonitor mRecorderMonitor;
168 // Camcorder profile settings for the desired quality level
169 nsRefPtr<GonkRecorderProfileManager> mProfileManager;
170 nsRefPtr<GonkRecorderProfile> mRecorderProfile;
172 nsRefPtr<DeviceStorageFile> mVideoFile;
173 nsString mFileFormat;
175 // Guards against calling StartPreviewImpl() while in OnTakePictureComplete().
176 ReentrantMonitor mReentrantMonitor;
178 private:
179 nsGonkCameraControl(const nsGonkCameraControl&) MOZ_DELETE;
180 nsGonkCameraControl& operator=(const nsGonkCameraControl&) MOZ_DELETE;
183 // camera driver callbacks
184 void OnRateLimitPreview(nsGonkCameraControl* gc, bool aLimit);
185 void OnTakePictureComplete(nsGonkCameraControl* gc, uint8_t* aData, uint32_t aLength);
186 void OnTakePictureError(nsGonkCameraControl* gc);
187 void OnAutoFocusComplete(nsGonkCameraControl* gc, bool aSuccess);
188 void OnAutoFocusMoving(nsGonkCameraControl* gc, bool aIsMoving);
189 void OnFacesDetected(nsGonkCameraControl* gc, camera_frame_metadata_t* aMetaData);
190 void OnNewPreviewFrame(nsGonkCameraControl* gc, layers::TextureClient* aBuffer);
191 void OnShutter(nsGonkCameraControl* gc);
192 void OnClosed(nsGonkCameraControl* gc);
193 void OnSystemError(nsGonkCameraControl* gc,
194 CameraControlListener::SystemContext aWhere,
195 int32_t aArg1, int32_t aArg2);
197 } // namespace mozilla
199 #endif // DOM_CAMERA_GONKCAMERACONTROL_H