2012-09-04 18:01:56 -07:00
|
|
|
/* 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_DOMCAMERACONTROL_H
|
|
|
|
#define DOM_CAMERA_DOMCAMERACONTROL_H
|
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2014-02-14 14:41:07 -08:00
|
|
|
#include "mozilla/dom/CameraControlBinding.h"
|
2012-09-04 18:01:56 -07:00
|
|
|
#include "ICameraControl.h"
|
|
|
|
#include "CameraCommon.h"
|
2014-02-14 14:41:07 -08:00
|
|
|
#include "DOMMediaStream.h"
|
2012-12-11 02:14:06 -08:00
|
|
|
#include "AudioChannelAgent.h"
|
2013-06-17 08:59:53 -07:00
|
|
|
#include "nsProxyRelease.h"
|
2013-10-23 04:11:18 -07:00
|
|
|
#include "nsHashPropertyBag.h"
|
2014-01-16 17:01:43 -08:00
|
|
|
#include "DeviceStorage.h"
|
2014-02-14 14:41:07 -08:00
|
|
|
#include "DOMCameraControlListener.h"
|
2012-09-04 18:01:56 -07:00
|
|
|
|
2013-07-06 13:55:10 -07:00
|
|
|
class nsDOMDeviceStorage;
|
|
|
|
class nsPIDOMWindow;
|
2014-02-14 14:41:07 -08:00
|
|
|
class nsIDOMBlob;
|
2013-07-06 13:55:10 -07:00
|
|
|
|
2012-09-04 18:01:56 -07:00
|
|
|
namespace mozilla {
|
2014-02-14 14:41:07 -08:00
|
|
|
|
2013-07-06 13:55:10 -07:00
|
|
|
namespace dom {
|
2014-02-14 14:41:07 -08:00
|
|
|
class CameraCapabilities;
|
|
|
|
class CameraPictureOptions;
|
|
|
|
class CameraStartRecordingOptions;
|
|
|
|
template<typename T> class Optional;
|
2013-07-06 13:55:10 -07:00
|
|
|
}
|
|
|
|
class ErrorResult;
|
2014-02-14 14:41:07 -08:00
|
|
|
class StartRecordingHelper;
|
2012-09-04 18:01:56 -07:00
|
|
|
|
|
|
|
// Main camera control.
|
2014-02-14 14:41:07 -08:00
|
|
|
class nsDOMCameraControl MOZ_FINAL : public DOMMediaStream
|
2012-09-04 18:01:56 -07:00
|
|
|
{
|
|
|
|
public:
|
2014-02-28 09:56:23 -08:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsDOMCameraControl, DOMMediaStream)
|
2014-02-14 14:41:07 -08:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
|
2014-04-09 08:53:34 -07:00
|
|
|
// Because this header's filename doesn't match its C++ or DOM-facing
|
|
|
|
// classname, we can't rely on the [Func="..."] WebIDL tag to implicitly
|
|
|
|
// include the right header for us; instead we must explicitly include a
|
|
|
|
// HasSupport() method in each header. We can get rid of these with the
|
|
|
|
// Great Renaming proposed in bug 983177.
|
|
|
|
static bool HasSupport(JSContext* aCx, JSObject* aGlobal);
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
nsDOMCameraControl(uint32_t aCameraId,
|
|
|
|
const dom::CameraConfiguration& aInitialConfig,
|
|
|
|
dom::GetCameraCallback* aOnSuccess,
|
|
|
|
dom::CameraErrorCallback* aOnError,
|
|
|
|
nsPIDOMWindow* aWindow);
|
2012-09-30 17:37:47 -07:00
|
|
|
|
|
|
|
void Shutdown();
|
2012-09-04 18:01:56 -07:00
|
|
|
|
2013-07-06 13:55:10 -07:00
|
|
|
nsPIDOMWindow* GetParentObject() const { return mWindow; }
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
// Attributes.
|
2013-07-06 13:55:10 -07:00
|
|
|
void GetEffect(nsString& aEffect, ErrorResult& aRv);
|
|
|
|
void SetEffect(const nsAString& aEffect, ErrorResult& aRv);
|
|
|
|
void GetWhiteBalanceMode(nsString& aMode, ErrorResult& aRv);
|
|
|
|
void SetWhiteBalanceMode(const nsAString& aMode, ErrorResult& aRv);
|
|
|
|
void GetSceneMode(nsString& aMode, ErrorResult& aRv);
|
|
|
|
void SetSceneMode(const nsAString& aMode, ErrorResult& aRv);
|
|
|
|
void GetFlashMode(nsString& aMode, ErrorResult& aRv);
|
|
|
|
void SetFlashMode(const nsAString& aMode, ErrorResult& aRv);
|
|
|
|
void GetFocusMode(nsString& aMode, ErrorResult& aRv);
|
|
|
|
void SetFocusMode(const nsAString& aMode, ErrorResult& aRv);
|
|
|
|
double GetZoom(ErrorResult& aRv);
|
|
|
|
void SetZoom(double aZoom, ErrorResult& aRv);
|
|
|
|
JS::Value GetMeteringAreas(JSContext* aCx, ErrorResult& aRv);
|
|
|
|
void SetMeteringAreas(JSContext* aCx, JS::Handle<JS::Value> aAreas, ErrorResult& aRv);
|
|
|
|
JS::Value GetFocusAreas(JSContext* aCx, ErrorResult& aRv);
|
|
|
|
void SetFocusAreas(JSContext* aCx, JS::Handle<JS::Value> aAreas, ErrorResult& aRv);
|
2013-10-30 12:41:08 -07:00
|
|
|
JS::Value GetPictureSize(JSContext* aCx, ErrorResult& aRv);
|
|
|
|
void SetPictureSize(JSContext* aCx, JS::Handle<JS::Value> aSize, ErrorResult& aRv);
|
|
|
|
JS::Value GetThumbnailSize(JSContext* aCx, ErrorResult& aRv);
|
|
|
|
void SetThumbnailSize(JSContext* aCx, JS::Handle<JS::Value> aSize, ErrorResult& aRv);
|
2013-07-06 13:55:10 -07:00
|
|
|
double GetFocalLength(ErrorResult& aRv);
|
|
|
|
double GetFocusDistanceNear(ErrorResult& aRv);
|
|
|
|
double GetFocusDistanceOptimum(ErrorResult& aRv);
|
|
|
|
double GetFocusDistanceFar(ErrorResult& aRv);
|
|
|
|
void SetExposureCompensation(const dom::Optional<double>& aCompensation, ErrorResult& aRv);
|
|
|
|
double GetExposureCompensation(ErrorResult& aRv);
|
2013-12-06 06:47:29 -08:00
|
|
|
int32_t SensorAngle();
|
2014-02-14 14:41:07 -08:00
|
|
|
already_AddRefed<dom::CameraCapabilities> Capabilities();
|
2014-03-06 22:00:43 -08:00
|
|
|
void GetIsoMode(nsString& aMode, ErrorResult& aRv);
|
|
|
|
void SetIsoMode(const nsAString& aMode, ErrorResult& aRv);
|
2014-02-14 14:41:07 -08:00
|
|
|
|
|
|
|
// Unsolicited event handlers.
|
2014-04-09 08:52:10 -07:00
|
|
|
dom::CameraShutterCallback* GetOnShutter();
|
2014-02-14 14:41:07 -08:00
|
|
|
void SetOnShutter(dom::CameraShutterCallback* aCb);
|
2014-04-09 08:52:10 -07:00
|
|
|
dom::CameraClosedCallback* GetOnClosed();
|
2014-02-14 14:41:07 -08:00
|
|
|
void SetOnClosed(dom::CameraClosedCallback* aCb);
|
2014-04-09 08:52:10 -07:00
|
|
|
dom::CameraRecorderStateChange* GetOnRecorderStateChange();
|
2014-02-14 14:41:07 -08:00
|
|
|
void SetOnRecorderStateChange(dom::CameraRecorderStateChange* aCb);
|
2014-04-09 08:52:10 -07:00
|
|
|
dom::CameraPreviewStateChange* GetOnPreviewStateChange();
|
2014-02-14 14:41:07 -08:00
|
|
|
void SetOnPreviewStateChange(dom::CameraPreviewStateChange* aCb);
|
2014-04-09 08:52:10 -07:00
|
|
|
dom::CameraAutoFocusMovingCallback* GetOnAutoFocusMoving();
|
2014-04-09 08:12:25 -07:00
|
|
|
void SetOnAutoFocusMoving(dom::CameraAutoFocusMovingCallback* aCb);
|
2014-04-09 08:52:10 -07:00
|
|
|
dom::CameraFaceDetectionCallback* GetOnFacesDetected();
|
|
|
|
void SetOnFacesDetected(dom::CameraFaceDetectionCallback* aCb);
|
2014-02-14 14:41:07 -08:00
|
|
|
|
|
|
|
// Methods.
|
|
|
|
void SetConfiguration(const dom::CameraConfiguration& aConfiguration,
|
|
|
|
const dom::Optional<dom::OwningNonNull<dom::CameraSetConfigurationCallback> >& aOnSuccess,
|
|
|
|
const dom::Optional<dom::OwningNonNull<dom::CameraErrorCallback> >& aOnError,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
void AutoFocus(dom::CameraAutoFocusCallback& aOnSuccess,
|
|
|
|
const dom::Optional<dom::OwningNonNull<dom::CameraErrorCallback> >& aOnError,
|
|
|
|
ErrorResult& aRv);
|
2014-04-09 08:52:10 -07:00
|
|
|
void StartFaceDetection(ErrorResult& aRv);
|
|
|
|
void StopFaceDetection(ErrorResult& aRv);
|
2014-02-14 14:41:07 -08:00
|
|
|
void TakePicture(const dom::CameraPictureOptions& aOptions,
|
|
|
|
dom::CameraTakePictureCallback& aOnSuccess,
|
|
|
|
const dom::Optional<dom::OwningNonNull<dom::CameraErrorCallback> >& aOnError,
|
2013-07-06 13:55:10 -07:00
|
|
|
ErrorResult& aRv);
|
2014-02-14 14:41:07 -08:00
|
|
|
void StartRecording(const dom::CameraStartRecordingOptions& aOptions,
|
|
|
|
nsDOMDeviceStorage& storageArea,
|
|
|
|
const nsAString& filename,
|
|
|
|
dom::CameraStartRecordingCallback& aOnSuccess,
|
|
|
|
const dom::Optional<dom::OwningNonNull<dom::CameraErrorCallback> >& aOnError,
|
|
|
|
ErrorResult& aRv);
|
2013-07-06 13:55:10 -07:00
|
|
|
void StopRecording(ErrorResult& aRv);
|
|
|
|
void ResumePreview(ErrorResult& aRv);
|
2014-02-14 14:41:07 -08:00
|
|
|
void ReleaseHardware(const dom::Optional<dom::OwningNonNull<dom::CameraReleaseCallback> >& aOnSuccess,
|
|
|
|
const dom::Optional<dom::OwningNonNull<dom::CameraErrorCallback> >& aOnError,
|
|
|
|
ErrorResult& aRv);
|
2014-04-15 12:46:40 -07:00
|
|
|
void ResumeContinuousFocus(ErrorResult& aRv);
|
2014-02-14 14:41:07 -08:00
|
|
|
|
2014-04-08 15:27:18 -07:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
|
2013-07-06 13:55:10 -07:00
|
|
|
|
2012-09-04 18:01:56 -07:00
|
|
|
protected:
|
|
|
|
virtual ~nsDOMCameraControl();
|
|
|
|
|
2014-04-02 09:21:03 -07:00
|
|
|
class DOMCameraConfiguration MOZ_FINAL : public dom::CameraConfiguration
|
2014-02-14 14:41:07 -08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_INLINE_DECL_REFCOUNTING(DOMCameraConfiguration)
|
|
|
|
|
|
|
|
DOMCameraConfiguration();
|
|
|
|
DOMCameraConfiguration(const dom::CameraConfiguration& aConfiguration);
|
|
|
|
|
|
|
|
// Additional configuration options that aren't exposed to the DOM
|
|
|
|
uint32_t mMaxFocusAreas;
|
|
|
|
uint32_t mMaxMeteringAreas;
|
|
|
|
|
2014-04-02 09:21:03 -07:00
|
|
|
private:
|
|
|
|
// Private destructor, to discourage deletion outside of Release():
|
2014-02-14 14:41:07 -08:00
|
|
|
~DOMCameraConfiguration();
|
|
|
|
};
|
|
|
|
|
|
|
|
friend class DOMCameraControlListener;
|
|
|
|
friend class mozilla::StartRecordingHelper;
|
|
|
|
|
|
|
|
void OnCreatedFileDescriptor(bool aSucceeded);
|
|
|
|
|
|
|
|
void OnAutoFocusComplete(bool aAutoFocusSucceeded);
|
2014-04-09 08:12:25 -07:00
|
|
|
void OnAutoFocusMoving(bool aIsMoving);
|
2014-02-14 14:41:07 -08:00
|
|
|
void OnTakePictureComplete(nsIDOMBlob* aPicture);
|
2014-04-09 08:52:10 -07:00
|
|
|
void OnFacesDetected(const nsTArray<ICameraControl::Face>& aFaces);
|
2014-02-14 14:41:07 -08:00
|
|
|
|
|
|
|
void OnHardwareStateChange(DOMCameraControlListener::HardwareState aState);
|
|
|
|
void OnPreviewStateChange(DOMCameraControlListener::PreviewState aState);
|
|
|
|
void OnRecorderStateChange(CameraControlListener::RecorderState aState, int32_t aStatus, int32_t aTrackNum);
|
|
|
|
void OnConfigurationChange(DOMCameraConfiguration* aConfiguration);
|
|
|
|
void OnShutter();
|
|
|
|
void OnError(CameraControlListener::CameraErrorContext aContext, const nsAString& mError);
|
|
|
|
|
|
|
|
bool IsWindowStillActive();
|
2012-09-04 18:01:56 -07:00
|
|
|
|
2013-11-25 22:22:22 -08:00
|
|
|
nsresult NotifyRecordingStatusChange(const nsString& aMsg);
|
2013-07-06 13:55:10 -07:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
nsRefPtr<ICameraControl> mCameraControl; // non-DOM camera control
|
2014-02-13 21:28:57 -08:00
|
|
|
|
2014-02-14 05:27:44 -08:00
|
|
|
// An agent used to join audio channel service.
|
2014-02-14 14:41:07 -08:00
|
|
|
nsCOMPtr<nsIAudioChannelAgent> mAudioChannelAgent;
|
|
|
|
|
|
|
|
nsresult Set(JSContext* aCx, uint32_t aKey, const JS::Value& aValue, uint32_t aLimit);
|
|
|
|
nsresult Get(JSContext* aCx, uint32_t aKey, JS::Value* aValue);
|
|
|
|
|
|
|
|
nsRefPtr<DOMCameraConfiguration> mCurrentConfiguration;
|
|
|
|
nsRefPtr<dom::CameraCapabilities> mCapabilities;
|
|
|
|
|
|
|
|
// solicited camera control event handlers
|
2014-03-17 17:23:03 -07:00
|
|
|
nsRefPtr<dom::GetCameraCallback> mGetCameraOnSuccessCb;
|
|
|
|
nsRefPtr<dom::CameraErrorCallback> mGetCameraOnErrorCb;
|
|
|
|
nsRefPtr<dom::CameraAutoFocusCallback> mAutoFocusOnSuccessCb;
|
|
|
|
nsRefPtr<dom::CameraErrorCallback> mAutoFocusOnErrorCb;
|
|
|
|
nsRefPtr<dom::CameraTakePictureCallback> mTakePictureOnSuccessCb;
|
|
|
|
nsRefPtr<dom::CameraErrorCallback> mTakePictureOnErrorCb;
|
|
|
|
nsRefPtr<dom::CameraStartRecordingCallback> mStartRecordingOnSuccessCb;
|
|
|
|
nsRefPtr<dom::CameraErrorCallback> mStartRecordingOnErrorCb;
|
|
|
|
nsRefPtr<dom::CameraReleaseCallback> mReleaseOnSuccessCb;
|
|
|
|
nsRefPtr<dom::CameraErrorCallback> mReleaseOnErrorCb;
|
|
|
|
nsRefPtr<dom::CameraSetConfigurationCallback> mSetConfigurationOnSuccessCb;
|
|
|
|
nsRefPtr<dom::CameraErrorCallback> mSetConfigurationOnErrorCb;
|
2014-02-14 14:41:07 -08:00
|
|
|
|
|
|
|
// unsolicited event handlers
|
2014-03-17 17:23:03 -07:00
|
|
|
nsRefPtr<dom::CameraShutterCallback> mOnShutterCb;
|
|
|
|
nsRefPtr<dom::CameraClosedCallback> mOnClosedCb;
|
|
|
|
nsRefPtr<dom::CameraRecorderStateChange> mOnRecorderStateChangeCb;
|
|
|
|
nsRefPtr<dom::CameraPreviewStateChange> mOnPreviewStateChangeCb;
|
2014-04-09 08:12:25 -07:00
|
|
|
nsRefPtr<dom::CameraAutoFocusMovingCallback> mOnAutoFocusMovingCb;
|
2014-04-09 08:52:10 -07:00
|
|
|
nsRefPtr<dom::CameraFaceDetectionCallback> mOnFacesDetectedCb;
|
2014-02-14 14:41:07 -08:00
|
|
|
|
|
|
|
// Camera event listener; we only need this weak reference so that
|
|
|
|
// we can remove the listener from the camera when we're done
|
|
|
|
// with it.
|
|
|
|
DOMCameraControlListener* mListener;
|
|
|
|
|
|
|
|
// our viewfinder stream
|
|
|
|
CameraPreviewMediaStream* mInput;
|
|
|
|
|
|
|
|
// set once when this object is created
|
|
|
|
nsCOMPtr<nsPIDOMWindow> mWindow;
|
|
|
|
|
|
|
|
dom::CameraStartRecordingOptions mOptions;
|
|
|
|
nsRefPtr<DeviceStorageFileDescriptor> mDSFileDescriptor;
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsDOMCameraControl(const nsDOMCameraControl&) MOZ_DELETE;
|
|
|
|
nsDOMCameraControl& operator=(const nsDOMCameraControl&) MOZ_DELETE;
|
2012-09-04 18:01:56 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // DOM_CAMERA_DOMCAMERACONTROL_H
|