2012-09-05 05:01:56 +04: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-15 02:41:07 +04:00
|
|
|
#include "mozilla/dom/CameraControlBinding.h"
|
2014-10-03 12:19:00 +04:00
|
|
|
#include "mozilla/dom/Promise.h"
|
2012-09-05 05:01:56 +04:00
|
|
|
#include "ICameraControl.h"
|
|
|
|
#include "CameraCommon.h"
|
2014-02-15 02:41:07 +04:00
|
|
|
#include "DOMMediaStream.h"
|
2012-12-11 14:14:06 +04:00
|
|
|
#include "AudioChannelAgent.h"
|
2013-06-17 19:59:53 +04:00
|
|
|
#include "nsProxyRelease.h"
|
2013-10-23 15:11:18 +04:00
|
|
|
#include "nsHashPropertyBag.h"
|
2014-01-17 05:01:43 +04:00
|
|
|
#include "DeviceStorage.h"
|
2014-02-15 02:41:07 +04:00
|
|
|
#include "DOMCameraControlListener.h"
|
2014-12-13 05:18:03 +03:00
|
|
|
#include "nsWeakReference.h"
|
2014-10-31 20:54:02 +03:00
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
#include "nsITimer.h"
|
|
|
|
#endif
|
2012-09-05 05:01:56 +04:00
|
|
|
|
2013-07-07 00:55:10 +04:00
|
|
|
class nsDOMDeviceStorage;
|
|
|
|
class nsPIDOMWindow;
|
2014-02-15 02:41:07 +04:00
|
|
|
class nsIDOMBlob;
|
2013-07-07 00:55:10 +04:00
|
|
|
|
2012-09-05 05:01:56 +04:00
|
|
|
namespace mozilla {
|
2014-02-15 02:41:07 +04:00
|
|
|
|
2013-07-07 00:55:10 +04:00
|
|
|
namespace dom {
|
2014-02-15 02:41:07 +04:00
|
|
|
class CameraCapabilities;
|
2014-06-19 04:57:51 +04:00
|
|
|
struct CameraPictureOptions;
|
|
|
|
struct CameraStartRecordingOptions;
|
|
|
|
struct CameraRegion;
|
|
|
|
struct CameraSize;
|
2014-02-15 02:41:07 +04:00
|
|
|
template<typename T> class Optional;
|
2013-07-07 00:55:10 +04:00
|
|
|
}
|
|
|
|
class ErrorResult;
|
2014-02-15 02:41:07 +04:00
|
|
|
class StartRecordingHelper;
|
2012-09-05 05:01:56 +04:00
|
|
|
|
2014-12-13 05:18:03 +03:00
|
|
|
#define NS_DOM_CAMERA_CONTROL_CID \
|
|
|
|
{ 0x3700c096, 0xf920, 0x438d, \
|
|
|
|
{ 0x8b, 0x3f, 0x15, 0xb3, 0xc9, 0x96, 0x23, 0x62 } }
|
|
|
|
|
2012-09-05 05:01:56 +04:00
|
|
|
// Main camera control.
|
2015-03-21 19:28:04 +03:00
|
|
|
class nsDOMCameraControl final : public DOMMediaStream
|
2015-03-27 21:52:19 +03:00
|
|
|
, public nsSupportsWeakReference
|
2012-09-05 05:01:56 +04:00
|
|
|
{
|
|
|
|
public:
|
2014-12-13 05:18:03 +03:00
|
|
|
NS_DECLARE_STATIC_IID_ACCESSOR(NS_DOM_CAMERA_CONTROL_CID)
|
|
|
|
|
2014-02-28 21:56:23 +04:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsDOMCameraControl, DOMMediaStream)
|
2014-02-15 02:41:07 +04:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
|
2014-04-09 19:53:34 +04: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-15 02:41:07 +04:00
|
|
|
nsDOMCameraControl(uint32_t aCameraId,
|
|
|
|
const dom::CameraConfiguration& aInitialConfig,
|
2014-10-03 12:19:00 +04:00
|
|
|
dom::Promise* aPromise,
|
2014-02-15 02:41:07 +04:00
|
|
|
nsPIDOMWindow* aWindow);
|
2012-10-01 04:37:47 +04:00
|
|
|
|
|
|
|
void Shutdown();
|
2012-09-05 05:01:56 +04:00
|
|
|
|
2013-07-07 00:55:10 +04:00
|
|
|
nsPIDOMWindow* GetParentObject() const { return mWindow; }
|
|
|
|
|
2014-02-15 02:41:07 +04:00
|
|
|
// Attributes.
|
2013-07-07 00:55:10 +04: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);
|
|
|
|
double GetFocalLength(ErrorResult& aRv);
|
|
|
|
double GetFocusDistanceNear(ErrorResult& aRv);
|
|
|
|
double GetFocusDistanceOptimum(ErrorResult& aRv);
|
|
|
|
double GetFocusDistanceFar(ErrorResult& aRv);
|
2014-06-06 23:37:15 +04:00
|
|
|
void SetExposureCompensation(double aCompensation, ErrorResult& aRv);
|
2013-07-07 00:55:10 +04:00
|
|
|
double GetExposureCompensation(ErrorResult& aRv);
|
2013-12-06 18:47:29 +04:00
|
|
|
int32_t SensorAngle();
|
2014-02-15 02:41:07 +04:00
|
|
|
already_AddRefed<dom::CameraCapabilities> Capabilities();
|
2014-03-07 10:00:43 +04:00
|
|
|
void GetIsoMode(nsString& aMode, ErrorResult& aRv);
|
|
|
|
void SetIsoMode(const nsAString& aMode, ErrorResult& aRv);
|
2014-08-25 23:12:49 +04:00
|
|
|
double GetPictureQuality(ErrorResult& aRv);
|
|
|
|
void SetPictureQuality(double aQuality, ErrorResult& aRv);
|
2014-12-13 05:42:13 +03:00
|
|
|
void GetMeteringMode(nsString& aMode, ErrorResult& aRv);
|
|
|
|
void SetMeteringMode(const nsAString& aMode, ErrorResult& aRv);
|
2014-02-15 02:41:07 +04:00
|
|
|
|
|
|
|
// Methods.
|
2014-10-03 12:19:00 +04:00
|
|
|
already_AddRefed<dom::Promise> SetConfiguration(const dom::CameraConfiguration& aConfiguration,
|
|
|
|
ErrorResult& aRv);
|
2014-05-01 01:15:01 +04:00
|
|
|
void GetMeteringAreas(nsTArray<dom::CameraRegion>& aAreas, ErrorResult& aRv);
|
|
|
|
void SetMeteringAreas(const dom::Optional<dom::Sequence<dom::CameraRegion> >& aAreas, ErrorResult& aRv);
|
|
|
|
void GetFocusAreas(nsTArray<dom::CameraRegion>& aAreas, ErrorResult& aRv);
|
|
|
|
void SetFocusAreas(const dom::Optional<dom::Sequence<dom::CameraRegion> >& aAreas, ErrorResult& aRv);
|
|
|
|
void GetPictureSize(dom::CameraSize& aSize, ErrorResult& aRv);
|
|
|
|
void SetPictureSize(const dom::CameraSize& aSize, ErrorResult& aRv);
|
|
|
|
void GetThumbnailSize(dom::CameraSize& aSize, ErrorResult& aRv);
|
|
|
|
void SetThumbnailSize(const dom::CameraSize& aSize, ErrorResult& aRv);
|
2014-12-11 19:02:51 +03:00
|
|
|
already_AddRefed<dom::Promise> AutoFocus(ErrorResult& aRv);
|
2014-04-09 19:52:10 +04:00
|
|
|
void StartFaceDetection(ErrorResult& aRv);
|
|
|
|
void StopFaceDetection(ErrorResult& aRv);
|
2014-10-03 12:19:00 +04:00
|
|
|
already_AddRefed<dom::Promise> TakePicture(const dom::CameraPictureOptions& aOptions,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
already_AddRefed<dom::Promise> StartRecording(const dom::CameraStartRecordingOptions& aOptions,
|
|
|
|
nsDOMDeviceStorage& storageArea,
|
|
|
|
const nsAString& filename,
|
|
|
|
ErrorResult& aRv);
|
2013-07-07 00:55:10 +04:00
|
|
|
void StopRecording(ErrorResult& aRv);
|
|
|
|
void ResumePreview(ErrorResult& aRv);
|
2014-12-11 19:02:51 +03:00
|
|
|
already_AddRefed<dom::Promise> ReleaseHardware(ErrorResult& aRv);
|
2014-04-15 23:46:40 +04:00
|
|
|
void ResumeContinuousFocus(ErrorResult& aRv);
|
2014-02-15 02:41:07 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
2013-07-07 00:55:10 +04:00
|
|
|
|
2014-12-13 05:18:03 +03:00
|
|
|
operator nsISupports*() { return static_cast<DOMMediaStream*>(this); }
|
|
|
|
|
2014-10-31 20:54:02 +03:00
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
static void PreinitCameraHardware();
|
|
|
|
static void DiscardCachedCameraInstance(nsITimer* aTimer, void* aClosure);
|
|
|
|
#endif
|
|
|
|
|
2014-10-03 12:19:00 +04:00
|
|
|
IMPL_EVENT_HANDLER(facesdetected)
|
|
|
|
IMPL_EVENT_HANDLER(shutter)
|
|
|
|
IMPL_EVENT_HANDLER(close)
|
|
|
|
IMPL_EVENT_HANDLER(recorderstatechange)
|
|
|
|
IMPL_EVENT_HANDLER(previewstatechange)
|
|
|
|
IMPL_EVENT_HANDLER(focus)
|
|
|
|
IMPL_EVENT_HANDLER(picture)
|
|
|
|
IMPL_EVENT_HANDLER(configurationchange)
|
|
|
|
|
2012-09-05 05:01:56 +04:00
|
|
|
protected:
|
|
|
|
virtual ~nsDOMCameraControl();
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class DOMCameraConfiguration final : public dom::CameraConfiguration
|
2014-02-15 02:41:07 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_INLINE_DECL_REFCOUNTING(DOMCameraConfiguration)
|
|
|
|
|
|
|
|
DOMCameraConfiguration();
|
2014-09-02 02:26:43 +04:00
|
|
|
explicit DOMCameraConfiguration(const dom::CameraConfiguration& aConfiguration);
|
2014-02-15 02:41:07 +04:00
|
|
|
|
|
|
|
// Additional configuration options that aren't exposed to the DOM
|
|
|
|
uint32_t mMaxFocusAreas;
|
|
|
|
uint32_t mMaxMeteringAreas;
|
|
|
|
|
2014-04-02 20:21:03 +04:00
|
|
|
private:
|
|
|
|
// Private destructor, to discourage deletion outside of Release():
|
2014-02-15 02:41:07 +04:00
|
|
|
~DOMCameraConfiguration();
|
|
|
|
};
|
|
|
|
|
|
|
|
friend class DOMCameraControlListener;
|
|
|
|
friend class mozilla::StartRecordingHelper;
|
|
|
|
|
|
|
|
void OnCreatedFileDescriptor(bool aSucceeded);
|
|
|
|
|
|
|
|
void OnAutoFocusComplete(bool aAutoFocusSucceeded);
|
2014-04-09 19:12:25 +04:00
|
|
|
void OnAutoFocusMoving(bool aIsMoving);
|
2014-02-15 02:41:07 +04:00
|
|
|
void OnTakePictureComplete(nsIDOMBlob* aPicture);
|
2014-04-09 19:52:10 +04:00
|
|
|
void OnFacesDetected(const nsTArray<ICameraControl::Face>& aFaces);
|
2014-02-15 02:41:07 +04:00
|
|
|
|
2014-12-13 06:51:29 +03:00
|
|
|
void OnGetCameraComplete();
|
2014-11-25 22:45:00 +03:00
|
|
|
void OnHardwareStateChange(DOMCameraControlListener::HardwareState aState, nsresult aReason);
|
2014-02-15 02:41:07 +04:00
|
|
|
void OnPreviewStateChange(DOMCameraControlListener::PreviewState aState);
|
|
|
|
void OnRecorderStateChange(CameraControlListener::RecorderState aState, int32_t aStatus, int32_t aTrackNum);
|
|
|
|
void OnConfigurationChange(DOMCameraConfiguration* aConfiguration);
|
|
|
|
void OnShutter();
|
2014-04-26 00:28:15 +04:00
|
|
|
void OnUserError(CameraControlListener::UserContext aContext, nsresult aError);
|
2014-02-15 02:41:07 +04:00
|
|
|
|
|
|
|
bool IsWindowStillActive();
|
2014-12-13 06:51:29 +03:00
|
|
|
nsresult SelectPreviewSize(const dom::CameraSize& aRequestedPreviewSize, ICameraControl::Size& aSelectedPreviewSize);
|
2012-09-05 05:01:56 +04:00
|
|
|
|
2015-06-13 01:51:38 +03:00
|
|
|
void ReleaseAudioChannelAgent();
|
2013-11-26 10:22:22 +04:00
|
|
|
nsresult NotifyRecordingStatusChange(const nsString& aMsg);
|
2013-07-07 00:55:10 +04:00
|
|
|
|
2014-10-03 12:19:00 +04:00
|
|
|
already_AddRefed<dom::Promise> CreatePromise(ErrorResult& aRv);
|
|
|
|
void AbortPromise(nsRefPtr<dom::Promise>& aPromise);
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void EventListenerAdded(nsIAtom* aType) override;
|
2014-10-03 12:19:00 +04:00
|
|
|
void DispatchPreviewStateEvent(DOMCameraControlListener::PreviewState aState);
|
|
|
|
void DispatchStateEvent(const nsString& aType, const nsString& aState);
|
|
|
|
|
2014-02-15 02:41:07 +04:00
|
|
|
nsRefPtr<ICameraControl> mCameraControl; // non-DOM camera control
|
2014-02-14 09:28:57 +04:00
|
|
|
|
2014-02-14 17:27:44 +04:00
|
|
|
// An agent used to join audio channel service.
|
2014-02-15 02:41:07 +04:00
|
|
|
nsCOMPtr<nsIAudioChannelAgent> mAudioChannelAgent;
|
|
|
|
|
2014-05-01 01:15:01 +04:00
|
|
|
nsresult Set(uint32_t aKey, const dom::Optional<dom::Sequence<dom::CameraRegion> >& aValue, uint32_t aLimit);
|
|
|
|
nsresult Get(uint32_t aKey, nsTArray<dom::CameraRegion>& aValue);
|
2014-02-15 02:41:07 +04:00
|
|
|
|
|
|
|
nsRefPtr<DOMCameraConfiguration> mCurrentConfiguration;
|
|
|
|
nsRefPtr<dom::CameraCapabilities> mCapabilities;
|
|
|
|
|
2014-10-03 12:19:00 +04:00
|
|
|
// camera control pending promises
|
|
|
|
nsRefPtr<dom::Promise> mGetCameraPromise;
|
|
|
|
nsRefPtr<dom::Promise> mAutoFocusPromise;
|
|
|
|
nsRefPtr<dom::Promise> mTakePicturePromise;
|
|
|
|
nsRefPtr<dom::Promise> mStartRecordingPromise;
|
|
|
|
nsRefPtr<dom::Promise> mReleasePromise;
|
|
|
|
nsRefPtr<dom::Promise> mSetConfigurationPromise;
|
|
|
|
|
2014-02-15 02:41:07 +04: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
|
2014-07-03 03:55:00 +04:00
|
|
|
nsRefPtr<CameraPreviewMediaStream> mInput;
|
2014-02-15 02:41:07 +04:00
|
|
|
|
|
|
|
// set once when this object is created
|
|
|
|
nsCOMPtr<nsPIDOMWindow> mWindow;
|
|
|
|
|
|
|
|
dom::CameraStartRecordingOptions mOptions;
|
|
|
|
nsRefPtr<DeviceStorageFileDescriptor> mDSFileDescriptor;
|
2014-10-03 12:19:00 +04:00
|
|
|
DOMCameraControlListener::PreviewState mPreviewState;
|
2015-06-13 01:51:38 +03:00
|
|
|
bool mRecording;
|
2014-12-13 06:51:29 +03:00
|
|
|
bool mSetInitialConfig;
|
|
|
|
|
2014-10-31 20:54:02 +03:00
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
// cached camera control, to improve start-up time
|
|
|
|
static StaticRefPtr<ICameraControl> sCachedCameraControl;
|
|
|
|
static nsresult sCachedCameraControlStartResult;
|
|
|
|
static nsCOMPtr<nsITimer> sDiscardCachedCameraControlTimer;
|
|
|
|
#endif
|
|
|
|
|
2014-02-15 02:41:07 +04:00
|
|
|
private:
|
2015-01-07 02:35:02 +03:00
|
|
|
nsDOMCameraControl(const nsDOMCameraControl&) = delete;
|
|
|
|
nsDOMCameraControl& operator=(const nsDOMCameraControl&) = delete;
|
2012-09-05 05:01:56 +04:00
|
|
|
};
|
|
|
|
|
2014-12-13 05:18:03 +03:00
|
|
|
NS_DEFINE_STATIC_IID_ACCESSOR(nsDOMCameraControl, NS_DOM_CAMERA_CONTROL_CID)
|
|
|
|
|
2012-09-05 05:01:56 +04:00
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // DOM_CAMERA_DOMCAMERACONTROL_H
|