dom/camera/ICameraControl.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/camera/ICameraControl.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,220 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     1.6 + * You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +#ifndef DOM_CAMERA_ICAMERACONTROL_H
     1.9 +#define DOM_CAMERA_ICAMERACONTROL_H
    1.10 +
    1.11 +#include "nsCOMPtr.h"
    1.12 +#include "nsString.h"
    1.13 +#include "nsAutoPtr.h"
    1.14 +#include "nsISupportsImpl.h"
    1.15 +
    1.16 +struct DeviceStorageFileDescriptor;
    1.17 +
    1.18 +class nsIFile;
    1.19 +
    1.20 +namespace mozilla {
    1.21 +
    1.22 +class CameraControlListener;
    1.23 +class RecorderProfileManager;
    1.24 +
    1.25 +// XXXmikeh - In some future patch this should move into the ICameraControl
    1.26 +//  class as well, and the names updated to the 'k'-style;
    1.27 +//  e.g. kParamPreviewSize, etc.
    1.28 +enum {
    1.29 +  // current settings
    1.30 +  CAMERA_PARAM_PREVIEWSIZE,
    1.31 +  CAMERA_PARAM_PREVIEWFORMAT,
    1.32 +  CAMERA_PARAM_PREVIEWFRAMERATE,
    1.33 +  CAMERA_PARAM_VIDEOSIZE,
    1.34 +  CAMERA_PARAM_PICTURE_SIZE,
    1.35 +  CAMERA_PARAM_PICTURE_FILEFORMAT,
    1.36 +  CAMERA_PARAM_PICTURE_ROTATION,
    1.37 +  CAMERA_PARAM_PICTURE_LOCATION,
    1.38 +  CAMERA_PARAM_PICTURE_DATETIME,
    1.39 +  CAMERA_PARAM_EFFECT,
    1.40 +  CAMERA_PARAM_WHITEBALANCE,
    1.41 +  CAMERA_PARAM_SCENEMODE,
    1.42 +  CAMERA_PARAM_FLASHMODE,
    1.43 +  CAMERA_PARAM_FOCUSMODE,
    1.44 +  CAMERA_PARAM_ZOOM,
    1.45 +  CAMERA_PARAM_METERINGAREAS,
    1.46 +  CAMERA_PARAM_FOCUSAREAS,
    1.47 +  CAMERA_PARAM_FOCALLENGTH,
    1.48 +  CAMERA_PARAM_FOCUSDISTANCENEAR,
    1.49 +  CAMERA_PARAM_FOCUSDISTANCEOPTIMUM,
    1.50 +  CAMERA_PARAM_FOCUSDISTANCEFAR,
    1.51 +  CAMERA_PARAM_EXPOSURECOMPENSATION,
    1.52 +  CAMERA_PARAM_THUMBNAILSIZE,
    1.53 +  CAMERA_PARAM_THUMBNAILQUALITY,
    1.54 +  CAMERA_PARAM_SENSORANGLE,
    1.55 +  CAMERA_PARAM_ISOMODE,
    1.56 +  CAMERA_PARAM_LUMINANCE,
    1.57 +  CAMERA_PARAM_SCENEMODE_HDR_RETURNNORMALPICTURE,
    1.58 +
    1.59 +  // supported features
    1.60 +  CAMERA_PARAM_SUPPORTED_PREVIEWSIZES,
    1.61 +  CAMERA_PARAM_SUPPORTED_PICTURESIZES,
    1.62 +  CAMERA_PARAM_SUPPORTED_VIDEOSIZES,
    1.63 +  CAMERA_PARAM_SUPPORTED_PICTUREFORMATS,
    1.64 +  CAMERA_PARAM_SUPPORTED_WHITEBALANCES,
    1.65 +  CAMERA_PARAM_SUPPORTED_SCENEMODES,
    1.66 +  CAMERA_PARAM_SUPPORTED_EFFECTS,
    1.67 +  CAMERA_PARAM_SUPPORTED_FLASHMODES,
    1.68 +  CAMERA_PARAM_SUPPORTED_FOCUSMODES,
    1.69 +  CAMERA_PARAM_SUPPORTED_MAXFOCUSAREAS,
    1.70 +  CAMERA_PARAM_SUPPORTED_MAXMETERINGAREAS,
    1.71 +  CAMERA_PARAM_SUPPORTED_MINEXPOSURECOMPENSATION,
    1.72 +  CAMERA_PARAM_SUPPORTED_MAXEXPOSURECOMPENSATION,
    1.73 +  CAMERA_PARAM_SUPPORTED_EXPOSURECOMPENSATIONSTEP,
    1.74 +  CAMERA_PARAM_SUPPORTED_ZOOM,
    1.75 +  CAMERA_PARAM_SUPPORTED_ZOOMRATIOS,
    1.76 +  CAMERA_PARAM_SUPPORTED_MAXDETECTEDFACES,
    1.77 +  CAMERA_PARAM_SUPPORTED_JPEG_THUMBNAIL_SIZES,
    1.78 +  CAMERA_PARAM_SUPPORTED_ISOMODES
    1.79 +};
    1.80 +
    1.81 +class ICameraControl
    1.82 +{
    1.83 +public:
    1.84 +  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(ICameraControl)
    1.85 +
    1.86 +  static nsresult GetNumberOfCameras(int32_t& aDeviceCount);
    1.87 +  static nsresult GetCameraName(uint32_t aDeviceNum, nsCString& aDeviceName);
    1.88 +  static nsresult GetListOfCameras(nsTArray<nsString>& aList);
    1.89 +
    1.90 +  enum Mode {
    1.91 +    kUnspecifiedMode,
    1.92 +    kPictureMode,
    1.93 +    kVideoMode,
    1.94 +  };
    1.95 +
    1.96 +  struct Size {
    1.97 +    uint32_t  width;
    1.98 +    uint32_t  height;
    1.99 +  };
   1.100 +
   1.101 +  struct Region {
   1.102 +    int32_t   top;
   1.103 +    int32_t   left;
   1.104 +    int32_t   bottom;
   1.105 +    int32_t   right;
   1.106 +    uint32_t  weight;
   1.107 +  };
   1.108 +
   1.109 +  struct Position {
   1.110 +    double    latitude;
   1.111 +    double    longitude;
   1.112 +    double    altitude;
   1.113 +    double    timestamp;
   1.114 +  };
   1.115 +
   1.116 +  struct StartRecordingOptions {
   1.117 +    uint32_t  rotation;
   1.118 +    uint32_t  maxFileSizeBytes;
   1.119 +    uint32_t  maxVideoLengthMs;
   1.120 +    bool      autoEnableLowLightTorch;
   1.121 +  };
   1.122 +
   1.123 +  struct Configuration {
   1.124 +    Mode      mMode;
   1.125 +    Size      mPreviewSize;
   1.126 +    nsString  mRecorderProfile;
   1.127 +  };
   1.128 +
   1.129 +  struct Point
   1.130 +  {
   1.131 +    int32_t   x;
   1.132 +    int32_t   y;
   1.133 +  };
   1.134 +
   1.135 +  struct Face {
   1.136 +    uint32_t  id;
   1.137 +    uint32_t  score;
   1.138 +    Region    bound;
   1.139 +    bool      hasLeftEye;
   1.140 +    Point     leftEye;
   1.141 +    bool      hasRightEye;
   1.142 +    Point     rightEye;
   1.143 +    bool      hasMouth;
   1.144 +    Point     mouth;
   1.145 +  };
   1.146 +
   1.147 +  static already_AddRefed<ICameraControl> Create(uint32_t aCameraId);
   1.148 +
   1.149 +  virtual nsresult Start(const Configuration* aInitialConfig = nullptr) = 0;
   1.150 +  virtual nsresult Stop() = 0;
   1.151 +
   1.152 +  virtual nsresult SetConfiguration(const Configuration& aConfig) = 0;
   1.153 +
   1.154 +  virtual void AddListener(CameraControlListener* aListener) = 0;
   1.155 +  virtual void RemoveListener(CameraControlListener* aListener) = 0;
   1.156 +
   1.157 +  virtual nsresult StartPreview() = 0;
   1.158 +  virtual nsresult StopPreview() = 0;
   1.159 +  virtual nsresult AutoFocus() = 0;
   1.160 +  virtual nsresult TakePicture() = 0;
   1.161 +  virtual nsresult StartRecording(DeviceStorageFileDescriptor *aFileDescriptor,
   1.162 +                                  const StartRecordingOptions* aOptions = nullptr) = 0;
   1.163 +  virtual nsresult StopRecording() = 0;
   1.164 +  virtual nsresult StartFaceDetection() = 0;
   1.165 +  virtual nsresult StopFaceDetection() = 0;
   1.166 +  virtual nsresult ResumeContinuousFocus() = 0;
   1.167 +
   1.168 +  virtual nsresult Set(uint32_t aKey, const nsAString& aValue) = 0;
   1.169 +  virtual nsresult Get(uint32_t aKey, nsAString& aValue) = 0;
   1.170 +  virtual nsresult Set(uint32_t aKey, double aValue) = 0;
   1.171 +  virtual nsresult Get(uint32_t aKey, double& aValue) = 0;
   1.172 +  virtual nsresult Set(uint32_t aKey, int32_t aValue) = 0;
   1.173 +  virtual nsresult Get(uint32_t aKey, int32_t& aValue) = 0;
   1.174 +  virtual nsresult Set(uint32_t aKey, int64_t aValue) = 0;
   1.175 +  virtual nsresult Get(uint32_t aKey, int64_t& aValue) = 0;
   1.176 +  virtual nsresult Set(uint32_t aKey, const Size& aValue) = 0;
   1.177 +  virtual nsresult Get(uint32_t aKey, Size& aValue) = 0;
   1.178 +  virtual nsresult Set(uint32_t aKey, const nsTArray<Region>& aRegions) = 0;
   1.179 +  virtual nsresult Get(uint32_t aKey, nsTArray<Region>& aRegions) = 0;
   1.180 +
   1.181 +  virtual nsresult SetLocation(const Position& aLocation) = 0;
   1.182 +
   1.183 +  virtual nsresult Get(uint32_t aKey, nsTArray<Size>& aSizes) = 0;
   1.184 +  virtual nsresult Get(uint32_t aKey, nsTArray<nsString>& aValues) = 0;
   1.185 +  virtual nsresult Get(uint32_t aKey, nsTArray<double>& aValues) = 0;
   1.186 +
   1.187 +  virtual already_AddRefed<RecorderProfileManager> GetRecorderProfileManager() = 0;
   1.188 +  virtual uint32_t GetCameraId() = 0;
   1.189 +
   1.190 +  virtual void Shutdown() = 0;
   1.191 +
   1.192 +protected:
   1.193 +  virtual ~ICameraControl() { }
   1.194 +
   1.195 +  friend class ICameraControlParameterSetAutoEnter;
   1.196 +
   1.197 +  virtual void BeginBatchParameterSet() = 0;
   1.198 +  virtual void EndBatchParameterSet() = 0;
   1.199 +};
   1.200 +
   1.201 +// Helper class to make it easy to update a batch of camera parameters;
   1.202 +// the parameters are applied atomically when this object goes out of
   1.203 +// scope.
   1.204 +class ICameraControlParameterSetAutoEnter
   1.205 +{
   1.206 +public:
   1.207 +  ICameraControlParameterSetAutoEnter(ICameraControl* aCameraControl)
   1.208 +    : mCameraControl(aCameraControl)
   1.209 +  {
   1.210 +    mCameraControl->BeginBatchParameterSet();
   1.211 +  }
   1.212 +  virtual ~ICameraControlParameterSetAutoEnter()
   1.213 +  {
   1.214 +    mCameraControl->EndBatchParameterSet();
   1.215 +  }
   1.216 +
   1.217 +protected:
   1.218 +  nsRefPtr<ICameraControl> mCameraControl;
   1.219 +};
   1.220 +
   1.221 +} // namespace mozilla
   1.222 +
   1.223 +#endif // DOM_CAMERA_ICAMERACONTROL_H

mercurial