|
1 /* |
|
2 * Copyright (C) 2012-2014 Mozilla Foundation |
|
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 DOM_CAMERA_GONKCAMERACONTROL_H |
|
18 #define DOM_CAMERA_GONKCAMERACONTROL_H |
|
19 |
|
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" |
|
29 |
|
30 namespace android { |
|
31 class GonkCameraHardware; |
|
32 class MediaProfiles; |
|
33 class GonkRecorder; |
|
34 } |
|
35 |
|
36 namespace mozilla { |
|
37 |
|
38 namespace layers { |
|
39 class TextureClient; |
|
40 class ImageContainer; |
|
41 } |
|
42 |
|
43 class GonkRecorderProfile; |
|
44 class GonkRecorderProfileManager; |
|
45 |
|
46 class nsGonkCameraControl : public CameraControlImpl |
|
47 { |
|
48 public: |
|
49 nsGonkCameraControl(uint32_t aCameraId); |
|
50 |
|
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 OnNewPreviewFrame(layers::TextureClient* aBuffer); |
|
56 void OnRecorderEvent(int msg, int ext1, int ext2); |
|
57 void OnError(CameraControlListener::CameraErrorContext aWhere, |
|
58 CameraControlListener::CameraError aError); |
|
59 |
|
60 virtual nsresult Set(uint32_t aKey, const nsAString& aValue) MOZ_OVERRIDE; |
|
61 virtual nsresult Get(uint32_t aKey, nsAString& aValue) MOZ_OVERRIDE; |
|
62 virtual nsresult Set(uint32_t aKey, double aValue) MOZ_OVERRIDE; |
|
63 virtual nsresult Get(uint32_t aKey, double& aValue) MOZ_OVERRIDE; |
|
64 virtual nsresult Set(uint32_t aKey, int32_t aValue) MOZ_OVERRIDE; |
|
65 virtual nsresult Get(uint32_t aKey, int32_t& aValue) MOZ_OVERRIDE; |
|
66 virtual nsresult Set(uint32_t aKey, int64_t aValue) MOZ_OVERRIDE; |
|
67 virtual nsresult Get(uint32_t aKey, int64_t& aValue) MOZ_OVERRIDE; |
|
68 virtual nsresult Set(uint32_t aKey, const Size& aValue) MOZ_OVERRIDE; |
|
69 virtual nsresult Get(uint32_t aKey, Size& aValue) MOZ_OVERRIDE; |
|
70 virtual nsresult Set(uint32_t aKey, const nsTArray<Region>& aRegions) MOZ_OVERRIDE; |
|
71 virtual nsresult Get(uint32_t aKey, nsTArray<Region>& aRegions) MOZ_OVERRIDE; |
|
72 |
|
73 virtual nsresult SetLocation(const Position& aLocation) MOZ_OVERRIDE; |
|
74 |
|
75 virtual nsresult Get(uint32_t aKey, nsTArray<Size>& aSizes) MOZ_OVERRIDE; |
|
76 virtual nsresult Get(uint32_t aKey, nsTArray<nsString>& aValues) MOZ_OVERRIDE; |
|
77 virtual nsresult Get(uint32_t aKey, nsTArray<double>& aValues) MOZ_OVERRIDE; |
|
78 |
|
79 nsresult PushParameters(); |
|
80 nsresult PullParameters(); |
|
81 |
|
82 protected: |
|
83 ~nsGonkCameraControl(); |
|
84 |
|
85 using CameraControlImpl::OnNewPreviewFrame; |
|
86 using CameraControlImpl::OnAutoFocusComplete; |
|
87 using CameraControlImpl::OnFacesDetected; |
|
88 using CameraControlImpl::OnTakePictureComplete; |
|
89 using CameraControlImpl::OnConfigurationChange; |
|
90 using CameraControlImpl::OnError; |
|
91 |
|
92 virtual void BeginBatchParameterSet() MOZ_OVERRIDE; |
|
93 virtual void EndBatchParameterSet() MOZ_OVERRIDE; |
|
94 |
|
95 virtual nsresult StartImpl(const Configuration* aInitialConfig = nullptr) MOZ_OVERRIDE; |
|
96 virtual nsresult StopImpl() MOZ_OVERRIDE; |
|
97 nsresult Initialize(); |
|
98 |
|
99 virtual nsresult SetConfigurationImpl(const Configuration& aConfig) MOZ_OVERRIDE; |
|
100 nsresult SetConfigurationInternal(const Configuration& aConfig); |
|
101 nsresult SetPictureConfiguration(const Configuration& aConfig); |
|
102 nsresult SetVideoConfiguration(const Configuration& aConfig); |
|
103 |
|
104 template<class T> nsresult SetAndPush(uint32_t aKey, const T& aValue); |
|
105 |
|
106 virtual nsresult StartPreviewImpl() MOZ_OVERRIDE; |
|
107 virtual nsresult StopPreviewImpl() MOZ_OVERRIDE; |
|
108 virtual nsresult AutoFocusImpl() MOZ_OVERRIDE; |
|
109 virtual nsresult StartFaceDetectionImpl() MOZ_OVERRIDE; |
|
110 virtual nsresult StopFaceDetectionImpl() MOZ_OVERRIDE; |
|
111 virtual nsresult TakePictureImpl() MOZ_OVERRIDE; |
|
112 virtual nsresult StartRecordingImpl(DeviceStorageFileDescriptor* aFileDescriptor, |
|
113 const StartRecordingOptions* aOptions = nullptr) MOZ_OVERRIDE; |
|
114 virtual nsresult StopRecordingImpl() MOZ_OVERRIDE; |
|
115 virtual nsresult ResumeContinuousFocusImpl() MOZ_OVERRIDE; |
|
116 virtual nsresult PushParametersImpl() MOZ_OVERRIDE; |
|
117 virtual nsresult PullParametersImpl() MOZ_OVERRIDE; |
|
118 virtual already_AddRefed<RecorderProfileManager> GetRecorderProfileManagerImpl() MOZ_OVERRIDE; |
|
119 already_AddRefed<GonkRecorderProfileManager> GetGonkRecorderProfileManager(); |
|
120 |
|
121 nsresult SetupRecording(int aFd, int aRotation, int64_t aMaxFileSizeBytes, |
|
122 int64_t aMaxVideoLengthMs); |
|
123 nsresult SetupRecordingFlash(bool aAutoEnableLowLightTorch); |
|
124 nsresult SetupVideoMode(const nsAString& aProfile); |
|
125 nsresult SetPreviewSize(const Size& aSize); |
|
126 nsresult SetVideoSize(const Size& aSize); |
|
127 nsresult PausePreview(); |
|
128 nsresult GetSupportedSize(const Size& aSize, const nsTArray<Size>& supportedSizes, Size& best); |
|
129 |
|
130 friend class SetPictureSize; |
|
131 friend class SetThumbnailSize; |
|
132 nsresult SetPictureSize(const Size& aSize); |
|
133 nsresult SetPictureSizeImpl(const Size& aSize); |
|
134 nsresult SetThumbnailSize(const Size& aSize); |
|
135 nsresult UpdateThumbnailSize(); |
|
136 nsresult SetThumbnailSizeImpl(const Size& aSize); |
|
137 |
|
138 int32_t RationalizeRotation(int32_t aRotation); |
|
139 |
|
140 android::sp<android::GonkCameraHardware> mCameraHw; |
|
141 |
|
142 Size mLastPictureSize; |
|
143 Size mLastThumbnailSize; |
|
144 Size mLastRecorderSize; |
|
145 uint32_t mPreviewFps; |
|
146 bool mResumePreviewAfterTakingPicture; |
|
147 bool mFlashSupported; |
|
148 bool mLuminanceSupported; |
|
149 bool mAutoFlashModeOverridden; |
|
150 Atomic<uint32_t> mDeferConfigUpdate; |
|
151 GonkCameraParameters mParams; |
|
152 |
|
153 nsRefPtr<mozilla::layers::ImageContainer> mImageContainer; |
|
154 |
|
155 android::MediaProfiles* mMediaProfiles; |
|
156 nsRefPtr<android::GonkRecorder> mRecorder; |
|
157 |
|
158 // Camcorder profile settings for the desired quality level |
|
159 nsRefPtr<GonkRecorderProfileManager> mProfileManager; |
|
160 nsRefPtr<GonkRecorderProfile> mRecorderProfile; |
|
161 |
|
162 nsRefPtr<DeviceStorageFile> mVideoFile; |
|
163 nsString mFileFormat; |
|
164 |
|
165 // Guards against calling StartPreviewImpl() while in OnTakePictureComplete(). |
|
166 ReentrantMonitor mReentrantMonitor; |
|
167 |
|
168 private: |
|
169 nsGonkCameraControl(const nsGonkCameraControl&) MOZ_DELETE; |
|
170 nsGonkCameraControl& operator=(const nsGonkCameraControl&) MOZ_DELETE; |
|
171 }; |
|
172 |
|
173 // camera driver callbacks |
|
174 void OnTakePictureComplete(nsGonkCameraControl* gc, uint8_t* aData, uint32_t aLength); |
|
175 void OnTakePictureError(nsGonkCameraControl* gc); |
|
176 void OnAutoFocusComplete(nsGonkCameraControl* gc, bool aSuccess); |
|
177 void OnAutoFocusMoving(nsGonkCameraControl* gc, bool aIsMoving); |
|
178 void OnFacesDetected(nsGonkCameraControl* gc, camera_frame_metadata_t* aMetaData); |
|
179 void OnNewPreviewFrame(nsGonkCameraControl* gc, layers::TextureClient* aBuffer); |
|
180 void OnShutter(nsGonkCameraControl* gc); |
|
181 void OnClosed(nsGonkCameraControl* gc); |
|
182 void OnError(nsGonkCameraControl* gc, CameraControlListener::CameraError aError, |
|
183 int32_t aArg1, int32_t aArg2); |
|
184 |
|
185 } // namespace mozilla |
|
186 |
|
187 #endif // DOM_CAMERA_GONKCAMERACONTROL_H |