dom/camera/ICameraControl.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     3  * You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 #ifndef DOM_CAMERA_ICAMERACONTROL_H
     6 #define DOM_CAMERA_ICAMERACONTROL_H
     8 #include "nsCOMPtr.h"
     9 #include "nsString.h"
    10 #include "nsAutoPtr.h"
    11 #include "nsISupportsImpl.h"
    13 struct DeviceStorageFileDescriptor;
    15 class nsIFile;
    17 namespace mozilla {
    19 class CameraControlListener;
    20 class RecorderProfileManager;
    22 // XXXmikeh - In some future patch this should move into the ICameraControl
    23 //  class as well, and the names updated to the 'k'-style;
    24 //  e.g. kParamPreviewSize, etc.
    25 enum {
    26   // current settings
    27   CAMERA_PARAM_PREVIEWSIZE,
    28   CAMERA_PARAM_PREVIEWFORMAT,
    29   CAMERA_PARAM_PREVIEWFRAMERATE,
    30   CAMERA_PARAM_VIDEOSIZE,
    31   CAMERA_PARAM_PICTURE_SIZE,
    32   CAMERA_PARAM_PICTURE_FILEFORMAT,
    33   CAMERA_PARAM_PICTURE_ROTATION,
    34   CAMERA_PARAM_PICTURE_LOCATION,
    35   CAMERA_PARAM_PICTURE_DATETIME,
    36   CAMERA_PARAM_EFFECT,
    37   CAMERA_PARAM_WHITEBALANCE,
    38   CAMERA_PARAM_SCENEMODE,
    39   CAMERA_PARAM_FLASHMODE,
    40   CAMERA_PARAM_FOCUSMODE,
    41   CAMERA_PARAM_ZOOM,
    42   CAMERA_PARAM_METERINGAREAS,
    43   CAMERA_PARAM_FOCUSAREAS,
    44   CAMERA_PARAM_FOCALLENGTH,
    45   CAMERA_PARAM_FOCUSDISTANCENEAR,
    46   CAMERA_PARAM_FOCUSDISTANCEOPTIMUM,
    47   CAMERA_PARAM_FOCUSDISTANCEFAR,
    48   CAMERA_PARAM_EXPOSURECOMPENSATION,
    49   CAMERA_PARAM_THUMBNAILSIZE,
    50   CAMERA_PARAM_THUMBNAILQUALITY,
    51   CAMERA_PARAM_SENSORANGLE,
    52   CAMERA_PARAM_ISOMODE,
    53   CAMERA_PARAM_LUMINANCE,
    54   CAMERA_PARAM_SCENEMODE_HDR_RETURNNORMALPICTURE,
    56   // supported features
    57   CAMERA_PARAM_SUPPORTED_PREVIEWSIZES,
    58   CAMERA_PARAM_SUPPORTED_PICTURESIZES,
    59   CAMERA_PARAM_SUPPORTED_VIDEOSIZES,
    60   CAMERA_PARAM_SUPPORTED_PICTUREFORMATS,
    61   CAMERA_PARAM_SUPPORTED_WHITEBALANCES,
    62   CAMERA_PARAM_SUPPORTED_SCENEMODES,
    63   CAMERA_PARAM_SUPPORTED_EFFECTS,
    64   CAMERA_PARAM_SUPPORTED_FLASHMODES,
    65   CAMERA_PARAM_SUPPORTED_FOCUSMODES,
    66   CAMERA_PARAM_SUPPORTED_MAXFOCUSAREAS,
    67   CAMERA_PARAM_SUPPORTED_MAXMETERINGAREAS,
    68   CAMERA_PARAM_SUPPORTED_MINEXPOSURECOMPENSATION,
    69   CAMERA_PARAM_SUPPORTED_MAXEXPOSURECOMPENSATION,
    70   CAMERA_PARAM_SUPPORTED_EXPOSURECOMPENSATIONSTEP,
    71   CAMERA_PARAM_SUPPORTED_ZOOM,
    72   CAMERA_PARAM_SUPPORTED_ZOOMRATIOS,
    73   CAMERA_PARAM_SUPPORTED_MAXDETECTEDFACES,
    74   CAMERA_PARAM_SUPPORTED_JPEG_THUMBNAIL_SIZES,
    75   CAMERA_PARAM_SUPPORTED_ISOMODES
    76 };
    78 class ICameraControl
    79 {
    80 public:
    81   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(ICameraControl)
    83   static nsresult GetNumberOfCameras(int32_t& aDeviceCount);
    84   static nsresult GetCameraName(uint32_t aDeviceNum, nsCString& aDeviceName);
    85   static nsresult GetListOfCameras(nsTArray<nsString>& aList);
    87   enum Mode {
    88     kUnspecifiedMode,
    89     kPictureMode,
    90     kVideoMode,
    91   };
    93   struct Size {
    94     uint32_t  width;
    95     uint32_t  height;
    96   };
    98   struct Region {
    99     int32_t   top;
   100     int32_t   left;
   101     int32_t   bottom;
   102     int32_t   right;
   103     uint32_t  weight;
   104   };
   106   struct Position {
   107     double    latitude;
   108     double    longitude;
   109     double    altitude;
   110     double    timestamp;
   111   };
   113   struct StartRecordingOptions {
   114     uint32_t  rotation;
   115     uint32_t  maxFileSizeBytes;
   116     uint32_t  maxVideoLengthMs;
   117     bool      autoEnableLowLightTorch;
   118   };
   120   struct Configuration {
   121     Mode      mMode;
   122     Size      mPreviewSize;
   123     nsString  mRecorderProfile;
   124   };
   126   struct Point
   127   {
   128     int32_t   x;
   129     int32_t   y;
   130   };
   132   struct Face {
   133     uint32_t  id;
   134     uint32_t  score;
   135     Region    bound;
   136     bool      hasLeftEye;
   137     Point     leftEye;
   138     bool      hasRightEye;
   139     Point     rightEye;
   140     bool      hasMouth;
   141     Point     mouth;
   142   };
   144   static already_AddRefed<ICameraControl> Create(uint32_t aCameraId);
   146   virtual nsresult Start(const Configuration* aInitialConfig = nullptr) = 0;
   147   virtual nsresult Stop() = 0;
   149   virtual nsresult SetConfiguration(const Configuration& aConfig) = 0;
   151   virtual void AddListener(CameraControlListener* aListener) = 0;
   152   virtual void RemoveListener(CameraControlListener* aListener) = 0;
   154   virtual nsresult StartPreview() = 0;
   155   virtual nsresult StopPreview() = 0;
   156   virtual nsresult AutoFocus() = 0;
   157   virtual nsresult TakePicture() = 0;
   158   virtual nsresult StartRecording(DeviceStorageFileDescriptor *aFileDescriptor,
   159                                   const StartRecordingOptions* aOptions = nullptr) = 0;
   160   virtual nsresult StopRecording() = 0;
   161   virtual nsresult StartFaceDetection() = 0;
   162   virtual nsresult StopFaceDetection() = 0;
   163   virtual nsresult ResumeContinuousFocus() = 0;
   165   virtual nsresult Set(uint32_t aKey, const nsAString& aValue) = 0;
   166   virtual nsresult Get(uint32_t aKey, nsAString& aValue) = 0;
   167   virtual nsresult Set(uint32_t aKey, double aValue) = 0;
   168   virtual nsresult Get(uint32_t aKey, double& aValue) = 0;
   169   virtual nsresult Set(uint32_t aKey, int32_t aValue) = 0;
   170   virtual nsresult Get(uint32_t aKey, int32_t& aValue) = 0;
   171   virtual nsresult Set(uint32_t aKey, int64_t aValue) = 0;
   172   virtual nsresult Get(uint32_t aKey, int64_t& aValue) = 0;
   173   virtual nsresult Set(uint32_t aKey, const Size& aValue) = 0;
   174   virtual nsresult Get(uint32_t aKey, Size& aValue) = 0;
   175   virtual nsresult Set(uint32_t aKey, const nsTArray<Region>& aRegions) = 0;
   176   virtual nsresult Get(uint32_t aKey, nsTArray<Region>& aRegions) = 0;
   178   virtual nsresult SetLocation(const Position& aLocation) = 0;
   180   virtual nsresult Get(uint32_t aKey, nsTArray<Size>& aSizes) = 0;
   181   virtual nsresult Get(uint32_t aKey, nsTArray<nsString>& aValues) = 0;
   182   virtual nsresult Get(uint32_t aKey, nsTArray<double>& aValues) = 0;
   184   virtual already_AddRefed<RecorderProfileManager> GetRecorderProfileManager() = 0;
   185   virtual uint32_t GetCameraId() = 0;
   187   virtual void Shutdown() = 0;
   189 protected:
   190   virtual ~ICameraControl() { }
   192   friend class ICameraControlParameterSetAutoEnter;
   194   virtual void BeginBatchParameterSet() = 0;
   195   virtual void EndBatchParameterSet() = 0;
   196 };
   198 // Helper class to make it easy to update a batch of camera parameters;
   199 // the parameters are applied atomically when this object goes out of
   200 // scope.
   201 class ICameraControlParameterSetAutoEnter
   202 {
   203 public:
   204   ICameraControlParameterSetAutoEnter(ICameraControl* aCameraControl)
   205     : mCameraControl(aCameraControl)
   206   {
   207     mCameraControl->BeginBatchParameterSet();
   208   }
   209   virtual ~ICameraControlParameterSetAutoEnter()
   210   {
   211     mCameraControl->EndBatchParameterSet();
   212   }
   214 protected:
   215   nsRefPtr<ICameraControl> mCameraControl;
   216 };
   218 } // namespace mozilla
   220 #endif // DOM_CAMERA_ICAMERACONTROL_H

mercurial