michael@0: /* michael@0: * Copyright (C) 2012-2014 Mozilla Foundation michael@0: * michael@0: * Licensed under the Apache License, Version 2.0 (the "License"); michael@0: * you may not use this file except in compliance with the License. michael@0: * You may obtain a copy of the License at michael@0: * michael@0: * http://www.apache.org/licenses/LICENSE-2.0 michael@0: * michael@0: * Unless required by applicable law or agreed to in writing, software michael@0: * distributed under the License is distributed on an "AS IS" BASIS, michael@0: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. michael@0: * See the License for the specific language governing permissions and michael@0: * limitations under the License. michael@0: */ michael@0: michael@0: #ifndef DOM_CAMERA_GONKCAMERACONTROL_H michael@0: #define DOM_CAMERA_GONKCAMERACONTROL_H michael@0: michael@0: #include "base/basictypes.h" michael@0: #include michael@0: #include "mozilla/ReentrantMonitor.h" michael@0: #include "DeviceStorage.h" michael@0: #include "CameraControlImpl.h" michael@0: #include "CameraCommon.h" michael@0: #include "GonkRecorder.h" michael@0: #include "GonkCameraHwMgr.h" michael@0: #include "GonkCameraParameters.h" michael@0: michael@0: namespace android { michael@0: class GonkCameraHardware; michael@0: class MediaProfiles; michael@0: class GonkRecorder; michael@0: } michael@0: michael@0: namespace mozilla { michael@0: michael@0: namespace layers { michael@0: class TextureClient; michael@0: class ImageContainer; michael@0: } michael@0: michael@0: class GonkRecorderProfile; michael@0: class GonkRecorderProfileManager; michael@0: michael@0: class nsGonkCameraControl : public CameraControlImpl michael@0: { michael@0: public: michael@0: nsGonkCameraControl(uint32_t aCameraId); michael@0: michael@0: void OnAutoFocusComplete(bool aSuccess); michael@0: void OnFacesDetected(camera_frame_metadata_t* aMetaData); michael@0: void OnTakePictureComplete(uint8_t* aData, uint32_t aLength); michael@0: void OnTakePictureError(); michael@0: void OnNewPreviewFrame(layers::TextureClient* aBuffer); michael@0: void OnRecorderEvent(int msg, int ext1, int ext2); michael@0: void OnError(CameraControlListener::CameraErrorContext aWhere, michael@0: CameraControlListener::CameraError aError); michael@0: michael@0: virtual nsresult Set(uint32_t aKey, const nsAString& aValue) MOZ_OVERRIDE; michael@0: virtual nsresult Get(uint32_t aKey, nsAString& aValue) MOZ_OVERRIDE; michael@0: virtual nsresult Set(uint32_t aKey, double aValue) MOZ_OVERRIDE; michael@0: virtual nsresult Get(uint32_t aKey, double& aValue) MOZ_OVERRIDE; michael@0: virtual nsresult Set(uint32_t aKey, int32_t aValue) MOZ_OVERRIDE; michael@0: virtual nsresult Get(uint32_t aKey, int32_t& aValue) MOZ_OVERRIDE; michael@0: virtual nsresult Set(uint32_t aKey, int64_t aValue) MOZ_OVERRIDE; michael@0: virtual nsresult Get(uint32_t aKey, int64_t& aValue) MOZ_OVERRIDE; michael@0: virtual nsresult Set(uint32_t aKey, const Size& aValue) MOZ_OVERRIDE; michael@0: virtual nsresult Get(uint32_t aKey, Size& aValue) MOZ_OVERRIDE; michael@0: virtual nsresult Set(uint32_t aKey, const nsTArray& aRegions) MOZ_OVERRIDE; michael@0: virtual nsresult Get(uint32_t aKey, nsTArray& aRegions) MOZ_OVERRIDE; michael@0: michael@0: virtual nsresult SetLocation(const Position& aLocation) MOZ_OVERRIDE; michael@0: michael@0: virtual nsresult Get(uint32_t aKey, nsTArray& aSizes) MOZ_OVERRIDE; michael@0: virtual nsresult Get(uint32_t aKey, nsTArray& aValues) MOZ_OVERRIDE; michael@0: virtual nsresult Get(uint32_t aKey, nsTArray& aValues) MOZ_OVERRIDE; michael@0: michael@0: nsresult PushParameters(); michael@0: nsresult PullParameters(); michael@0: michael@0: protected: michael@0: ~nsGonkCameraControl(); michael@0: michael@0: using CameraControlImpl::OnNewPreviewFrame; michael@0: using CameraControlImpl::OnAutoFocusComplete; michael@0: using CameraControlImpl::OnFacesDetected; michael@0: using CameraControlImpl::OnTakePictureComplete; michael@0: using CameraControlImpl::OnConfigurationChange; michael@0: using CameraControlImpl::OnError; michael@0: michael@0: virtual void BeginBatchParameterSet() MOZ_OVERRIDE; michael@0: virtual void EndBatchParameterSet() MOZ_OVERRIDE; michael@0: michael@0: virtual nsresult StartImpl(const Configuration* aInitialConfig = nullptr) MOZ_OVERRIDE; michael@0: virtual nsresult StopImpl() MOZ_OVERRIDE; michael@0: nsresult Initialize(); michael@0: michael@0: virtual nsresult SetConfigurationImpl(const Configuration& aConfig) MOZ_OVERRIDE; michael@0: nsresult SetConfigurationInternal(const Configuration& aConfig); michael@0: nsresult SetPictureConfiguration(const Configuration& aConfig); michael@0: nsresult SetVideoConfiguration(const Configuration& aConfig); michael@0: michael@0: template nsresult SetAndPush(uint32_t aKey, const T& aValue); michael@0: michael@0: virtual nsresult StartPreviewImpl() MOZ_OVERRIDE; michael@0: virtual nsresult StopPreviewImpl() MOZ_OVERRIDE; michael@0: virtual nsresult AutoFocusImpl() MOZ_OVERRIDE; michael@0: virtual nsresult StartFaceDetectionImpl() MOZ_OVERRIDE; michael@0: virtual nsresult StopFaceDetectionImpl() MOZ_OVERRIDE; michael@0: virtual nsresult TakePictureImpl() MOZ_OVERRIDE; michael@0: virtual nsresult StartRecordingImpl(DeviceStorageFileDescriptor* aFileDescriptor, michael@0: const StartRecordingOptions* aOptions = nullptr) MOZ_OVERRIDE; michael@0: virtual nsresult StopRecordingImpl() MOZ_OVERRIDE; michael@0: virtual nsresult ResumeContinuousFocusImpl() MOZ_OVERRIDE; michael@0: virtual nsresult PushParametersImpl() MOZ_OVERRIDE; michael@0: virtual nsresult PullParametersImpl() MOZ_OVERRIDE; michael@0: virtual already_AddRefed GetRecorderProfileManagerImpl() MOZ_OVERRIDE; michael@0: already_AddRefed GetGonkRecorderProfileManager(); michael@0: michael@0: nsresult SetupRecording(int aFd, int aRotation, int64_t aMaxFileSizeBytes, michael@0: int64_t aMaxVideoLengthMs); michael@0: nsresult SetupRecordingFlash(bool aAutoEnableLowLightTorch); michael@0: nsresult SetupVideoMode(const nsAString& aProfile); michael@0: nsresult SetPreviewSize(const Size& aSize); michael@0: nsresult SetVideoSize(const Size& aSize); michael@0: nsresult PausePreview(); michael@0: nsresult GetSupportedSize(const Size& aSize, const nsTArray& supportedSizes, Size& best); michael@0: michael@0: friend class SetPictureSize; michael@0: friend class SetThumbnailSize; michael@0: nsresult SetPictureSize(const Size& aSize); michael@0: nsresult SetPictureSizeImpl(const Size& aSize); michael@0: nsresult SetThumbnailSize(const Size& aSize); michael@0: nsresult UpdateThumbnailSize(); michael@0: nsresult SetThumbnailSizeImpl(const Size& aSize); michael@0: michael@0: int32_t RationalizeRotation(int32_t aRotation); michael@0: michael@0: android::sp mCameraHw; michael@0: michael@0: Size mLastPictureSize; michael@0: Size mLastThumbnailSize; michael@0: Size mLastRecorderSize; michael@0: uint32_t mPreviewFps; michael@0: bool mResumePreviewAfterTakingPicture; michael@0: bool mFlashSupported; michael@0: bool mLuminanceSupported; michael@0: bool mAutoFlashModeOverridden; michael@0: Atomic mDeferConfigUpdate; michael@0: GonkCameraParameters mParams; michael@0: michael@0: nsRefPtr mImageContainer; michael@0: michael@0: android::MediaProfiles* mMediaProfiles; michael@0: nsRefPtr mRecorder; michael@0: michael@0: // Camcorder profile settings for the desired quality level michael@0: nsRefPtr mProfileManager; michael@0: nsRefPtr mRecorderProfile; michael@0: michael@0: nsRefPtr mVideoFile; michael@0: nsString mFileFormat; michael@0: michael@0: // Guards against calling StartPreviewImpl() while in OnTakePictureComplete(). michael@0: ReentrantMonitor mReentrantMonitor; michael@0: michael@0: private: michael@0: nsGonkCameraControl(const nsGonkCameraControl&) MOZ_DELETE; michael@0: nsGonkCameraControl& operator=(const nsGonkCameraControl&) MOZ_DELETE; michael@0: }; michael@0: michael@0: // camera driver callbacks michael@0: void OnTakePictureComplete(nsGonkCameraControl* gc, uint8_t* aData, uint32_t aLength); michael@0: void OnTakePictureError(nsGonkCameraControl* gc); michael@0: void OnAutoFocusComplete(nsGonkCameraControl* gc, bool aSuccess); michael@0: void OnAutoFocusMoving(nsGonkCameraControl* gc, bool aIsMoving); michael@0: void OnFacesDetected(nsGonkCameraControl* gc, camera_frame_metadata_t* aMetaData); michael@0: void OnNewPreviewFrame(nsGonkCameraControl* gc, layers::TextureClient* aBuffer); michael@0: void OnShutter(nsGonkCameraControl* gc); michael@0: void OnClosed(nsGonkCameraControl* gc); michael@0: void OnError(nsGonkCameraControl* gc, CameraControlListener::CameraError aError, michael@0: int32_t aArg1, int32_t aArg2); michael@0: michael@0: } // namespace mozilla michael@0: michael@0: #endif // DOM_CAMERA_GONKCAMERACONTROL_H