1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/camera/GonkCameraControl.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,187 @@ 1.4 +/* 1.5 + * Copyright (C) 2012-2014 Mozilla Foundation 1.6 + * 1.7 + * Licensed under the Apache License, Version 2.0 (the "License"); 1.8 + * you may not use this file except in compliance with the License. 1.9 + * You may obtain a copy of the License at 1.10 + * 1.11 + * http://www.apache.org/licenses/LICENSE-2.0 1.12 + * 1.13 + * Unless required by applicable law or agreed to in writing, software 1.14 + * distributed under the License is distributed on an "AS IS" BASIS, 1.15 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1.16 + * See the License for the specific language governing permissions and 1.17 + * limitations under the License. 1.18 + */ 1.19 + 1.20 +#ifndef DOM_CAMERA_GONKCAMERACONTROL_H 1.21 +#define DOM_CAMERA_GONKCAMERACONTROL_H 1.22 + 1.23 +#include "base/basictypes.h" 1.24 +#include <media/MediaProfiles.h> 1.25 +#include "mozilla/ReentrantMonitor.h" 1.26 +#include "DeviceStorage.h" 1.27 +#include "CameraControlImpl.h" 1.28 +#include "CameraCommon.h" 1.29 +#include "GonkRecorder.h" 1.30 +#include "GonkCameraHwMgr.h" 1.31 +#include "GonkCameraParameters.h" 1.32 + 1.33 +namespace android { 1.34 + class GonkCameraHardware; 1.35 + class MediaProfiles; 1.36 + class GonkRecorder; 1.37 +} 1.38 + 1.39 +namespace mozilla { 1.40 + 1.41 +namespace layers { 1.42 + class TextureClient; 1.43 + class ImageContainer; 1.44 +} 1.45 + 1.46 +class GonkRecorderProfile; 1.47 +class GonkRecorderProfileManager; 1.48 + 1.49 +class nsGonkCameraControl : public CameraControlImpl 1.50 +{ 1.51 +public: 1.52 + nsGonkCameraControl(uint32_t aCameraId); 1.53 + 1.54 + void OnAutoFocusComplete(bool aSuccess); 1.55 + void OnFacesDetected(camera_frame_metadata_t* aMetaData); 1.56 + void OnTakePictureComplete(uint8_t* aData, uint32_t aLength); 1.57 + void OnTakePictureError(); 1.58 + void OnNewPreviewFrame(layers::TextureClient* aBuffer); 1.59 + void OnRecorderEvent(int msg, int ext1, int ext2); 1.60 + void OnError(CameraControlListener::CameraErrorContext aWhere, 1.61 + CameraControlListener::CameraError aError); 1.62 + 1.63 + virtual nsresult Set(uint32_t aKey, const nsAString& aValue) MOZ_OVERRIDE; 1.64 + virtual nsresult Get(uint32_t aKey, nsAString& aValue) MOZ_OVERRIDE; 1.65 + virtual nsresult Set(uint32_t aKey, double aValue) MOZ_OVERRIDE; 1.66 + virtual nsresult Get(uint32_t aKey, double& aValue) MOZ_OVERRIDE; 1.67 + virtual nsresult Set(uint32_t aKey, int32_t aValue) MOZ_OVERRIDE; 1.68 + virtual nsresult Get(uint32_t aKey, int32_t& aValue) MOZ_OVERRIDE; 1.69 + virtual nsresult Set(uint32_t aKey, int64_t aValue) MOZ_OVERRIDE; 1.70 + virtual nsresult Get(uint32_t aKey, int64_t& aValue) MOZ_OVERRIDE; 1.71 + virtual nsresult Set(uint32_t aKey, const Size& aValue) MOZ_OVERRIDE; 1.72 + virtual nsresult Get(uint32_t aKey, Size& aValue) MOZ_OVERRIDE; 1.73 + virtual nsresult Set(uint32_t aKey, const nsTArray<Region>& aRegions) MOZ_OVERRIDE; 1.74 + virtual nsresult Get(uint32_t aKey, nsTArray<Region>& aRegions) MOZ_OVERRIDE; 1.75 + 1.76 + virtual nsresult SetLocation(const Position& aLocation) MOZ_OVERRIDE; 1.77 + 1.78 + virtual nsresult Get(uint32_t aKey, nsTArray<Size>& aSizes) MOZ_OVERRIDE; 1.79 + virtual nsresult Get(uint32_t aKey, nsTArray<nsString>& aValues) MOZ_OVERRIDE; 1.80 + virtual nsresult Get(uint32_t aKey, nsTArray<double>& aValues) MOZ_OVERRIDE; 1.81 + 1.82 + nsresult PushParameters(); 1.83 + nsresult PullParameters(); 1.84 + 1.85 +protected: 1.86 + ~nsGonkCameraControl(); 1.87 + 1.88 + using CameraControlImpl::OnNewPreviewFrame; 1.89 + using CameraControlImpl::OnAutoFocusComplete; 1.90 + using CameraControlImpl::OnFacesDetected; 1.91 + using CameraControlImpl::OnTakePictureComplete; 1.92 + using CameraControlImpl::OnConfigurationChange; 1.93 + using CameraControlImpl::OnError; 1.94 + 1.95 + virtual void BeginBatchParameterSet() MOZ_OVERRIDE; 1.96 + virtual void EndBatchParameterSet() MOZ_OVERRIDE; 1.97 + 1.98 + virtual nsresult StartImpl(const Configuration* aInitialConfig = nullptr) MOZ_OVERRIDE; 1.99 + virtual nsresult StopImpl() MOZ_OVERRIDE; 1.100 + nsresult Initialize(); 1.101 + 1.102 + virtual nsresult SetConfigurationImpl(const Configuration& aConfig) MOZ_OVERRIDE; 1.103 + nsresult SetConfigurationInternal(const Configuration& aConfig); 1.104 + nsresult SetPictureConfiguration(const Configuration& aConfig); 1.105 + nsresult SetVideoConfiguration(const Configuration& aConfig); 1.106 + 1.107 + template<class T> nsresult SetAndPush(uint32_t aKey, const T& aValue); 1.108 + 1.109 + virtual nsresult StartPreviewImpl() MOZ_OVERRIDE; 1.110 + virtual nsresult StopPreviewImpl() MOZ_OVERRIDE; 1.111 + virtual nsresult AutoFocusImpl() MOZ_OVERRIDE; 1.112 + virtual nsresult StartFaceDetectionImpl() MOZ_OVERRIDE; 1.113 + virtual nsresult StopFaceDetectionImpl() MOZ_OVERRIDE; 1.114 + virtual nsresult TakePictureImpl() MOZ_OVERRIDE; 1.115 + virtual nsresult StartRecordingImpl(DeviceStorageFileDescriptor* aFileDescriptor, 1.116 + const StartRecordingOptions* aOptions = nullptr) MOZ_OVERRIDE; 1.117 + virtual nsresult StopRecordingImpl() MOZ_OVERRIDE; 1.118 + virtual nsresult ResumeContinuousFocusImpl() MOZ_OVERRIDE; 1.119 + virtual nsresult PushParametersImpl() MOZ_OVERRIDE; 1.120 + virtual nsresult PullParametersImpl() MOZ_OVERRIDE; 1.121 + virtual already_AddRefed<RecorderProfileManager> GetRecorderProfileManagerImpl() MOZ_OVERRIDE; 1.122 + already_AddRefed<GonkRecorderProfileManager> GetGonkRecorderProfileManager(); 1.123 + 1.124 + nsresult SetupRecording(int aFd, int aRotation, int64_t aMaxFileSizeBytes, 1.125 + int64_t aMaxVideoLengthMs); 1.126 + nsresult SetupRecordingFlash(bool aAutoEnableLowLightTorch); 1.127 + nsresult SetupVideoMode(const nsAString& aProfile); 1.128 + nsresult SetPreviewSize(const Size& aSize); 1.129 + nsresult SetVideoSize(const Size& aSize); 1.130 + nsresult PausePreview(); 1.131 + nsresult GetSupportedSize(const Size& aSize, const nsTArray<Size>& supportedSizes, Size& best); 1.132 + 1.133 + friend class SetPictureSize; 1.134 + friend class SetThumbnailSize; 1.135 + nsresult SetPictureSize(const Size& aSize); 1.136 + nsresult SetPictureSizeImpl(const Size& aSize); 1.137 + nsresult SetThumbnailSize(const Size& aSize); 1.138 + nsresult UpdateThumbnailSize(); 1.139 + nsresult SetThumbnailSizeImpl(const Size& aSize); 1.140 + 1.141 + int32_t RationalizeRotation(int32_t aRotation); 1.142 + 1.143 + android::sp<android::GonkCameraHardware> mCameraHw; 1.144 + 1.145 + Size mLastPictureSize; 1.146 + Size mLastThumbnailSize; 1.147 + Size mLastRecorderSize; 1.148 + uint32_t mPreviewFps; 1.149 + bool mResumePreviewAfterTakingPicture; 1.150 + bool mFlashSupported; 1.151 + bool mLuminanceSupported; 1.152 + bool mAutoFlashModeOverridden; 1.153 + Atomic<uint32_t> mDeferConfigUpdate; 1.154 + GonkCameraParameters mParams; 1.155 + 1.156 + nsRefPtr<mozilla::layers::ImageContainer> mImageContainer; 1.157 + 1.158 + android::MediaProfiles* mMediaProfiles; 1.159 + nsRefPtr<android::GonkRecorder> mRecorder; 1.160 + 1.161 + // Camcorder profile settings for the desired quality level 1.162 + nsRefPtr<GonkRecorderProfileManager> mProfileManager; 1.163 + nsRefPtr<GonkRecorderProfile> mRecorderProfile; 1.164 + 1.165 + nsRefPtr<DeviceStorageFile> mVideoFile; 1.166 + nsString mFileFormat; 1.167 + 1.168 + // Guards against calling StartPreviewImpl() while in OnTakePictureComplete(). 1.169 + ReentrantMonitor mReentrantMonitor; 1.170 + 1.171 +private: 1.172 + nsGonkCameraControl(const nsGonkCameraControl&) MOZ_DELETE; 1.173 + nsGonkCameraControl& operator=(const nsGonkCameraControl&) MOZ_DELETE; 1.174 +}; 1.175 + 1.176 +// camera driver callbacks 1.177 +void OnTakePictureComplete(nsGonkCameraControl* gc, uint8_t* aData, uint32_t aLength); 1.178 +void OnTakePictureError(nsGonkCameraControl* gc); 1.179 +void OnAutoFocusComplete(nsGonkCameraControl* gc, bool aSuccess); 1.180 +void OnAutoFocusMoving(nsGonkCameraControl* gc, bool aIsMoving); 1.181 +void OnFacesDetected(nsGonkCameraControl* gc, camera_frame_metadata_t* aMetaData); 1.182 +void OnNewPreviewFrame(nsGonkCameraControl* gc, layers::TextureClient* aBuffer); 1.183 +void OnShutter(nsGonkCameraControl* gc); 1.184 +void OnClosed(nsGonkCameraControl* gc); 1.185 +void OnError(nsGonkCameraControl* gc, CameraControlListener::CameraError aError, 1.186 + int32_t aArg1, int32_t aArg2); 1.187 + 1.188 +} // namespace mozilla 1.189 + 1.190 +#endif // DOM_CAMERA_GONKCAMERACONTROL_H