dom/camera/CameraControlImpl.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/camera/CameraControlImpl.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,133 @@
     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_CAMERACONTROLIMPL_H
     1.9 +#define DOM_CAMERA_CAMERACONTROLIMPL_H
    1.10 +
    1.11 +#include "nsTArray.h"
    1.12 +#include "nsWeakPtr.h"
    1.13 +#include "mozilla/Attributes.h"
    1.14 +#include "mozilla/ReentrantMonitor.h"
    1.15 +#include "nsIFile.h"
    1.16 +#include "nsProxyRelease.h"
    1.17 +#include "AutoRwLock.h"
    1.18 +#include "nsIDOMDeviceStorage.h"
    1.19 +#include "ICameraControl.h"
    1.20 +#include "CameraCommon.h"
    1.21 +#include "DeviceStorage.h"
    1.22 +#include "DeviceStorageFileDescriptor.h"
    1.23 +#include "CameraControlListener.h"
    1.24 +
    1.25 +namespace mozilla {
    1.26 +
    1.27 +namespace layers {
    1.28 +  class Image;
    1.29 +}
    1.30 +
    1.31 +class RecorderProfileManager;
    1.32 +
    1.33 +class CameraControlImpl : public ICameraControl
    1.34 +{
    1.35 +public:
    1.36 +  CameraControlImpl(uint32_t aCameraId);
    1.37 +  virtual void AddListener(CameraControlListener* aListener) MOZ_OVERRIDE;
    1.38 +  virtual void RemoveListener(CameraControlListener* aListener) MOZ_OVERRIDE;
    1.39 +
    1.40 +  virtual nsresult Start(const Configuration* aConfig = nullptr) MOZ_OVERRIDE;
    1.41 +  virtual nsresult Stop() MOZ_OVERRIDE;
    1.42 +
    1.43 +  virtual nsresult SetConfiguration(const Configuration& aConfig) MOZ_OVERRIDE;
    1.44 +  virtual nsresult StartPreview() MOZ_OVERRIDE;
    1.45 +  virtual nsresult StopPreview() MOZ_OVERRIDE;
    1.46 +  virtual nsresult AutoFocus() MOZ_OVERRIDE;
    1.47 +  virtual nsresult StartFaceDetection() MOZ_OVERRIDE;
    1.48 +  virtual nsresult StopFaceDetection() MOZ_OVERRIDE;
    1.49 +  virtual nsresult TakePicture() MOZ_OVERRIDE;
    1.50 +  virtual nsresult StartRecording(DeviceStorageFileDescriptor* aFileDescriptor,
    1.51 +                                  const StartRecordingOptions* aOptions) MOZ_OVERRIDE;
    1.52 +  virtual nsresult StopRecording() MOZ_OVERRIDE;
    1.53 +  virtual nsresult ResumeContinuousFocus() MOZ_OVERRIDE;
    1.54 +
    1.55 +  already_AddRefed<RecorderProfileManager> GetRecorderProfileManager();
    1.56 +  uint32_t GetCameraId() { return mCameraId; }
    1.57 +
    1.58 +  virtual void Shutdown() MOZ_OVERRIDE;
    1.59 +
    1.60 +  // Event handlers called directly from outside this class.
    1.61 +  void OnShutter();
    1.62 +  void OnClosed();
    1.63 +  void OnError(CameraControlListener::CameraErrorContext aContext,
    1.64 +               CameraControlListener::CameraError aError);
    1.65 +  void OnAutoFocusMoving(bool aIsMoving);
    1.66 +
    1.67 +protected:
    1.68 +  // Event handlers.
    1.69 +  void OnAutoFocusComplete(bool aAutoFocusSucceeded);
    1.70 +  void OnFacesDetected(const nsTArray<Face>& aFaces);
    1.71 +  void OnTakePictureComplete(uint8_t* aData, uint32_t aLength, const nsAString& aMimeType);
    1.72 +
    1.73 +  bool OnNewPreviewFrame(layers::Image* aImage, uint32_t aWidth, uint32_t aHeight);
    1.74 +  void OnRecorderStateChange(CameraControlListener::RecorderState aState,
    1.75 +                             int32_t aStatus = -1, int32_t aTrackNumber = -1);
    1.76 +  void OnPreviewStateChange(CameraControlListener::PreviewState aState);
    1.77 +  void OnHardwareStateChange(CameraControlListener::HardwareState aState);
    1.78 +  void OnConfigurationChange();
    1.79 +
    1.80 +  // When we create a new CameraThread, we keep a static reference to it so
    1.81 +  // that multiple CameraControl instances can find and reuse it; but we
    1.82 +  // don't want that reference to keep the thread object around unnecessarily,
    1.83 +  // so we make it a weak reference. The strong dynamic references will keep
    1.84 +  // the thread object alive as needed.
    1.85 +  static nsWeakPtr sCameraThread;
    1.86 +  nsCOMPtr<nsIThread> mCameraThread;
    1.87 +
    1.88 +  virtual ~CameraControlImpl();
    1.89 +
    1.90 +  virtual void BeginBatchParameterSet() MOZ_OVERRIDE { }
    1.91 +  virtual void EndBatchParameterSet() MOZ_OVERRIDE { }
    1.92 +
    1.93 +  // Manage camera event listeners.
    1.94 +  void AddListenerImpl(already_AddRefed<CameraControlListener> aListener);
    1.95 +  void RemoveListenerImpl(CameraControlListener* aListener);
    1.96 +  nsTArray<nsRefPtr<CameraControlListener> > mListeners;
    1.97 +  PRRWLock* mListenerLock;
    1.98 +
    1.99 +  class ControlMessage;
   1.100 +  class ListenerMessage;
   1.101 +
   1.102 +  virtual nsresult StartImpl(const Configuration* aConfig = nullptr) = 0;
   1.103 +  virtual nsresult StopImpl() = 0;
   1.104 +  virtual nsresult SetConfigurationImpl(const Configuration& aConfig) = 0;
   1.105 +  virtual nsresult StartPreviewImpl() = 0;
   1.106 +  virtual nsresult StopPreviewImpl() = 0;
   1.107 +  virtual nsresult AutoFocusImpl() = 0;
   1.108 +  virtual nsresult StartFaceDetectionImpl() = 0;
   1.109 +  virtual nsresult StopFaceDetectionImpl() = 0;
   1.110 +  virtual nsresult TakePictureImpl() = 0;
   1.111 +  virtual nsresult StartRecordingImpl(DeviceStorageFileDescriptor* aFileDescriptor,
   1.112 +                                      const StartRecordingOptions* aOptions) = 0;
   1.113 +  virtual nsresult StopRecordingImpl() = 0;
   1.114 +  virtual nsresult ResumeContinuousFocusImpl() = 0;
   1.115 +  virtual nsresult PushParametersImpl() = 0;
   1.116 +  virtual nsresult PullParametersImpl() = 0;
   1.117 +  virtual already_AddRefed<RecorderProfileManager> GetRecorderProfileManagerImpl() = 0;
   1.118 +
   1.119 +  void OnShutterInternal();
   1.120 +  void OnClosedInternal();
   1.121 +
   1.122 +  uint32_t mCameraId;
   1.123 +
   1.124 +  CameraControlListener::CameraListenerConfiguration mCurrentConfiguration;
   1.125 +
   1.126 +  CameraControlListener::PreviewState   mPreviewState;
   1.127 +  CameraControlListener::HardwareState  mHardwareState;
   1.128 +
   1.129 +private:
   1.130 +  CameraControlImpl(const CameraControlImpl&) MOZ_DELETE;
   1.131 +  CameraControlImpl& operator=(const CameraControlImpl&) MOZ_DELETE;
   1.132 +};
   1.133 +
   1.134 +} // namespace mozilla
   1.135 +
   1.136 +#endif // DOM_CAMERA_CAMERACONTROLIMPL_H

mercurial