michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef DOM_CAMERA_ICAMERACONTROL_H michael@0: #define DOM_CAMERA_ICAMERACONTROL_H michael@0: michael@0: #include "nsCOMPtr.h" michael@0: #include "nsString.h" michael@0: #include "nsAutoPtr.h" michael@0: #include "nsISupportsImpl.h" michael@0: michael@0: struct DeviceStorageFileDescriptor; michael@0: michael@0: class nsIFile; michael@0: michael@0: namespace mozilla { michael@0: michael@0: class CameraControlListener; michael@0: class RecorderProfileManager; michael@0: michael@0: // XXXmikeh - In some future patch this should move into the ICameraControl michael@0: // class as well, and the names updated to the 'k'-style; michael@0: // e.g. kParamPreviewSize, etc. michael@0: enum { michael@0: // current settings michael@0: CAMERA_PARAM_PREVIEWSIZE, michael@0: CAMERA_PARAM_PREVIEWFORMAT, michael@0: CAMERA_PARAM_PREVIEWFRAMERATE, michael@0: CAMERA_PARAM_VIDEOSIZE, michael@0: CAMERA_PARAM_PICTURE_SIZE, michael@0: CAMERA_PARAM_PICTURE_FILEFORMAT, michael@0: CAMERA_PARAM_PICTURE_ROTATION, michael@0: CAMERA_PARAM_PICTURE_LOCATION, michael@0: CAMERA_PARAM_PICTURE_DATETIME, michael@0: CAMERA_PARAM_EFFECT, michael@0: CAMERA_PARAM_WHITEBALANCE, michael@0: CAMERA_PARAM_SCENEMODE, michael@0: CAMERA_PARAM_FLASHMODE, michael@0: CAMERA_PARAM_FOCUSMODE, michael@0: CAMERA_PARAM_ZOOM, michael@0: CAMERA_PARAM_METERINGAREAS, michael@0: CAMERA_PARAM_FOCUSAREAS, michael@0: CAMERA_PARAM_FOCALLENGTH, michael@0: CAMERA_PARAM_FOCUSDISTANCENEAR, michael@0: CAMERA_PARAM_FOCUSDISTANCEOPTIMUM, michael@0: CAMERA_PARAM_FOCUSDISTANCEFAR, michael@0: CAMERA_PARAM_EXPOSURECOMPENSATION, michael@0: CAMERA_PARAM_THUMBNAILSIZE, michael@0: CAMERA_PARAM_THUMBNAILQUALITY, michael@0: CAMERA_PARAM_SENSORANGLE, michael@0: CAMERA_PARAM_ISOMODE, michael@0: CAMERA_PARAM_LUMINANCE, michael@0: CAMERA_PARAM_SCENEMODE_HDR_RETURNNORMALPICTURE, michael@0: michael@0: // supported features michael@0: CAMERA_PARAM_SUPPORTED_PREVIEWSIZES, michael@0: CAMERA_PARAM_SUPPORTED_PICTURESIZES, michael@0: CAMERA_PARAM_SUPPORTED_VIDEOSIZES, michael@0: CAMERA_PARAM_SUPPORTED_PICTUREFORMATS, michael@0: CAMERA_PARAM_SUPPORTED_WHITEBALANCES, michael@0: CAMERA_PARAM_SUPPORTED_SCENEMODES, michael@0: CAMERA_PARAM_SUPPORTED_EFFECTS, michael@0: CAMERA_PARAM_SUPPORTED_FLASHMODES, michael@0: CAMERA_PARAM_SUPPORTED_FOCUSMODES, michael@0: CAMERA_PARAM_SUPPORTED_MAXFOCUSAREAS, michael@0: CAMERA_PARAM_SUPPORTED_MAXMETERINGAREAS, michael@0: CAMERA_PARAM_SUPPORTED_MINEXPOSURECOMPENSATION, michael@0: CAMERA_PARAM_SUPPORTED_MAXEXPOSURECOMPENSATION, michael@0: CAMERA_PARAM_SUPPORTED_EXPOSURECOMPENSATIONSTEP, michael@0: CAMERA_PARAM_SUPPORTED_ZOOM, michael@0: CAMERA_PARAM_SUPPORTED_ZOOMRATIOS, michael@0: CAMERA_PARAM_SUPPORTED_MAXDETECTEDFACES, michael@0: CAMERA_PARAM_SUPPORTED_JPEG_THUMBNAIL_SIZES, michael@0: CAMERA_PARAM_SUPPORTED_ISOMODES michael@0: }; michael@0: michael@0: class ICameraControl michael@0: { michael@0: public: michael@0: NS_INLINE_DECL_THREADSAFE_REFCOUNTING(ICameraControl) michael@0: michael@0: static nsresult GetNumberOfCameras(int32_t& aDeviceCount); michael@0: static nsresult GetCameraName(uint32_t aDeviceNum, nsCString& aDeviceName); michael@0: static nsresult GetListOfCameras(nsTArray& aList); michael@0: michael@0: enum Mode { michael@0: kUnspecifiedMode, michael@0: kPictureMode, michael@0: kVideoMode, michael@0: }; michael@0: michael@0: struct Size { michael@0: uint32_t width; michael@0: uint32_t height; michael@0: }; michael@0: michael@0: struct Region { michael@0: int32_t top; michael@0: int32_t left; michael@0: int32_t bottom; michael@0: int32_t right; michael@0: uint32_t weight; michael@0: }; michael@0: michael@0: struct Position { michael@0: double latitude; michael@0: double longitude; michael@0: double altitude; michael@0: double timestamp; michael@0: }; michael@0: michael@0: struct StartRecordingOptions { michael@0: uint32_t rotation; michael@0: uint32_t maxFileSizeBytes; michael@0: uint32_t maxVideoLengthMs; michael@0: bool autoEnableLowLightTorch; michael@0: }; michael@0: michael@0: struct Configuration { michael@0: Mode mMode; michael@0: Size mPreviewSize; michael@0: nsString mRecorderProfile; michael@0: }; michael@0: michael@0: struct Point michael@0: { michael@0: int32_t x; michael@0: int32_t y; michael@0: }; michael@0: michael@0: struct Face { michael@0: uint32_t id; michael@0: uint32_t score; michael@0: Region bound; michael@0: bool hasLeftEye; michael@0: Point leftEye; michael@0: bool hasRightEye; michael@0: Point rightEye; michael@0: bool hasMouth; michael@0: Point mouth; michael@0: }; michael@0: michael@0: static already_AddRefed Create(uint32_t aCameraId); michael@0: michael@0: virtual nsresult Start(const Configuration* aInitialConfig = nullptr) = 0; michael@0: virtual nsresult Stop() = 0; michael@0: michael@0: virtual nsresult SetConfiguration(const Configuration& aConfig) = 0; michael@0: michael@0: virtual void AddListener(CameraControlListener* aListener) = 0; michael@0: virtual void RemoveListener(CameraControlListener* aListener) = 0; michael@0: michael@0: virtual nsresult StartPreview() = 0; michael@0: virtual nsresult StopPreview() = 0; michael@0: virtual nsresult AutoFocus() = 0; michael@0: virtual nsresult TakePicture() = 0; michael@0: virtual nsresult StartRecording(DeviceStorageFileDescriptor *aFileDescriptor, michael@0: const StartRecordingOptions* aOptions = nullptr) = 0; michael@0: virtual nsresult StopRecording() = 0; michael@0: virtual nsresult StartFaceDetection() = 0; michael@0: virtual nsresult StopFaceDetection() = 0; michael@0: virtual nsresult ResumeContinuousFocus() = 0; michael@0: michael@0: virtual nsresult Set(uint32_t aKey, const nsAString& aValue) = 0; michael@0: virtual nsresult Get(uint32_t aKey, nsAString& aValue) = 0; michael@0: virtual nsresult Set(uint32_t aKey, double aValue) = 0; michael@0: virtual nsresult Get(uint32_t aKey, double& aValue) = 0; michael@0: virtual nsresult Set(uint32_t aKey, int32_t aValue) = 0; michael@0: virtual nsresult Get(uint32_t aKey, int32_t& aValue) = 0; michael@0: virtual nsresult Set(uint32_t aKey, int64_t aValue) = 0; michael@0: virtual nsresult Get(uint32_t aKey, int64_t& aValue) = 0; michael@0: virtual nsresult Set(uint32_t aKey, const Size& aValue) = 0; michael@0: virtual nsresult Get(uint32_t aKey, Size& aValue) = 0; michael@0: virtual nsresult Set(uint32_t aKey, const nsTArray& aRegions) = 0; michael@0: virtual nsresult Get(uint32_t aKey, nsTArray& aRegions) = 0; michael@0: michael@0: virtual nsresult SetLocation(const Position& aLocation) = 0; michael@0: michael@0: virtual nsresult Get(uint32_t aKey, nsTArray& aSizes) = 0; michael@0: virtual nsresult Get(uint32_t aKey, nsTArray& aValues) = 0; michael@0: virtual nsresult Get(uint32_t aKey, nsTArray& aValues) = 0; michael@0: michael@0: virtual already_AddRefed GetRecorderProfileManager() = 0; michael@0: virtual uint32_t GetCameraId() = 0; michael@0: michael@0: virtual void Shutdown() = 0; michael@0: michael@0: protected: michael@0: virtual ~ICameraControl() { } michael@0: michael@0: friend class ICameraControlParameterSetAutoEnter; michael@0: michael@0: virtual void BeginBatchParameterSet() = 0; michael@0: virtual void EndBatchParameterSet() = 0; michael@0: }; michael@0: michael@0: // Helper class to make it easy to update a batch of camera parameters; michael@0: // the parameters are applied atomically when this object goes out of michael@0: // scope. michael@0: class ICameraControlParameterSetAutoEnter michael@0: { michael@0: public: michael@0: ICameraControlParameterSetAutoEnter(ICameraControl* aCameraControl) michael@0: : mCameraControl(aCameraControl) michael@0: { michael@0: mCameraControl->BeginBatchParameterSet(); michael@0: } michael@0: virtual ~ICameraControlParameterSetAutoEnter() michael@0: { michael@0: mCameraControl->EndBatchParameterSet(); michael@0: } michael@0: michael@0: protected: michael@0: nsRefPtr mCameraControl; michael@0: }; michael@0: michael@0: } // namespace mozilla michael@0: michael@0: #endif // DOM_CAMERA_ICAMERACONTROL_H