dom/camera/CameraControlListener.h
author Dave Townsend <dtownsend@oxymoronical.com>
Fri, 26 Sep 2014 08:32:55 -0700
changeset 230683 8f7dd750e75fafc6460edd7f9fe6455029419f6c
parent 213445 387df8864e0d90fbb3ee6ac79681d7fdac27bc86
child 237639 3fde6fc99b0a9ea3473849a00fca193c3c037d36
permissions -rw-r--r--
Bug 1068440: Uplift Add-on SDK to Firefox. https://github.com/mozilla/addon-sdk/compare/cc3242d1ca8c...cbf6cdd0d630

/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef DOM_CAMERA_CAMERACONTROLLISTENER_H
#define DOM_CAMERA_CAMERACONTROLLISTENER_H

#include <stdint.h>
#include "ICameraControl.h"

namespace mozilla {

namespace layers {
  class Image;
}

class CameraControlListener
{
public:
  CameraControlListener()
  {
    MOZ_COUNT_CTOR(CameraControlListener);
  }

protected:
  // Protected destructor, to discourage deletion outside of Release():
  virtual ~CameraControlListener()
  {
    MOZ_COUNT_DTOR(CameraControlListener);
  }

public:
  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(CameraControlListener);

  enum HardwareState
  {
    kHardwareOpen,
    kHardwareClosed
  };
  virtual void OnHardwareStateChange(HardwareState aState) { }

  enum PreviewState
  {
    kPreviewStopped,
    kPreviewPaused,
    kPreviewStarted
  };
  virtual void OnPreviewStateChange(PreviewState aState) { }

  enum RecorderState
  {
    kRecorderStopped,
    kRecorderStarted,
#ifdef MOZ_B2G_CAMERA
    kFileSizeLimitReached,
    kVideoLengthLimitReached,
    kTrackCompleted,
    kTrackFailed,
    kMediaRecorderFailed,
    kMediaServerFailed
#endif
  };
  enum { kNoTrackNumber = -1 };
  virtual void OnRecorderStateChange(RecorderState aState, int32_t aStatus, int32_t aTrackNum) { }

  virtual void OnShutter() { }
  virtual void OnRateLimitPreview(bool aLimit) { }
  virtual bool OnNewPreviewFrame(layers::Image* aFrame, uint32_t aWidth, uint32_t aHeight)
  {
    return false;
  }

  class CameraListenerConfiguration : public ICameraControl::Configuration
  {
  public:
    uint32_t mMaxMeteringAreas;
    uint32_t mMaxFocusAreas;
  };
  virtual void OnConfigurationChange(const CameraListenerConfiguration& aConfiguration) { }

  virtual void OnAutoFocusComplete(bool aAutoFocusSucceeded) { }
  virtual void OnAutoFocusMoving(bool aIsMoving) { }
  virtual void OnTakePictureComplete(uint8_t* aData, uint32_t aLength, const nsAString& aMimeType) { }
  virtual void OnFacesDetected(const nsTArray<ICameraControl::Face>& aFaces) { }

  enum UserContext
  {
    kInStartCamera,
    kInStopCamera,
    kInAutoFocus,
    kInStartFaceDetection,
    kInStopFaceDetection,
    kInTakePicture,
    kInStartRecording,
    kInStopRecording,
    kInSetConfiguration,
    kInStartPreview,
    kInStopPreview,
    kInSetPictureSize,
    kInSetThumbnailSize,
    kInResumeContinuousFocus,
    kInUnspecified
  };
  // Error handler for problems arising due to user-initiated actions.
  virtual void OnUserError(UserContext aContext, nsresult aError) { }

  enum SystemContext
  {
    kSystemService
  };
  // Error handler for problems arising due to system failures, not triggered
  // by something the CameraControl API user did.
  virtual void OnSystemError(SystemContext aContext, nsresult aError) { }
};

} // namespace mozilla

#endif // DOM_CAMERA_CAMERACONTROLLISTENER_H