1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_CameraCapabilities_h__
8 #define mozilla_dom_CameraCapabilities_h__
11 #include "nsAutoPtr.h"
12 #include "base/basictypes.h"
13 #include "mozilla/Attributes.h"
14 #include "mozilla/ErrorResult.h"
15 #include "mozilla/dom/CameraManagerBinding.h"
16 #include "nsCycleCollectionParticipant.h"
17 #include "nsWrapperCache.h"
18 #include "nsPIDOMWindow.h"
19 #include "nsHashKeys.h"
20 #include "nsRefPtrHashtable.h"
21 #include "nsDataHashtable.h"
22 #include "ICameraControl.h"
30 * CameraRecorderVideoProfile
32 class CameraRecorderVideoProfile MOZ_FINAL
: public nsISupports
33 , public nsWrapperCache
36 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
37 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(CameraRecorderVideoProfile
)
39 explicit CameraRecorderVideoProfile(nsISupports
* aParent
,
40 const ICameraControl::RecorderProfile::Video
& aProfile
);
41 nsISupports
* GetParentObject() const { return mParent
; }
42 virtual JSObject
* WrapObject(JSContext
* aCx
) MOZ_OVERRIDE
;
44 uint32_t BitsPerSecond() const { return mBitrate
; }
45 uint32_t FramesPerSecond() const { return mFramerate
; }
46 void GetCodec(nsAString
& aCodec
) const { aCodec
= mCodec
; }
48 void GetSize(dom::CameraSize
& aSize
) const { aSize
= mSize
; }
50 // XXXmikeh - legacy, remove these when the Camera app is updated
51 uint32_t Width() const { return mSize
.mWidth
; }
52 uint32_t Height() const { return mSize
.mHeight
; }
55 virtual ~CameraRecorderVideoProfile();
57 nsCOMPtr
<nsISupports
> mParent
;
59 const nsString mCodec
;
62 dom::CameraSize mSize
;
65 DISALLOW_EVIL_CONSTRUCTORS(CameraRecorderVideoProfile
);
69 * CameraRecorderAudioProfile
71 class CameraRecorderAudioProfile MOZ_FINAL
: public nsISupports
72 , public nsWrapperCache
75 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
76 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(CameraRecorderAudioProfile
)
78 explicit CameraRecorderAudioProfile(nsISupports
* aParent
,
79 const ICameraControl::RecorderProfile::Audio
& aProfile
);
80 nsISupports
* GetParentObject() const { return mParent
; }
81 virtual JSObject
* WrapObject(JSContext
* aCx
) MOZ_OVERRIDE
;
83 uint32_t BitsPerSecond() const { return mBitrate
; }
84 uint32_t SamplesPerSecond() const { return mSamplerate
; }
85 uint32_t Channels() const { return mChannels
; }
86 void GetCodec(nsAString
& aCodec
) const { aCodec
= mCodec
; }
89 virtual ~CameraRecorderAudioProfile();
91 nsCOMPtr
<nsISupports
> mParent
;
93 const nsString mCodec
;
99 DISALLOW_EVIL_CONSTRUCTORS(CameraRecorderAudioProfile
);
103 * CameraRecorderProfile
105 class CameraRecorderProfile MOZ_FINAL
: public nsISupports
106 , public nsWrapperCache
109 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
110 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(CameraRecorderProfile
)
112 explicit CameraRecorderProfile(nsISupports
* aParent
,
113 const ICameraControl::RecorderProfile
& aProfile
);
114 nsISupports
* GetParentObject() const { return mParent
; }
115 virtual JSObject
* WrapObject(JSContext
* aCx
) MOZ_OVERRIDE
;
117 void GetMimeType(nsAString
& aMimeType
) const { aMimeType
= mMimeType
; }
119 CameraRecorderVideoProfile
* Video() { return mVideo
; }
120 CameraRecorderAudioProfile
* Audio() { return mAudio
; }
122 void GetName(nsAString
& aName
) const { aName
= mName
; }
125 GetContainerFormat(nsAString
& aContainerFormat
) const
127 aContainerFormat
= mContainerFormat
;
131 virtual ~CameraRecorderProfile();
133 nsCOMPtr
<nsISupports
> mParent
;
135 const nsString mName
;
136 const nsString mContainerFormat
;
137 const nsString mMimeType
;
139 nsRefPtr
<CameraRecorderVideoProfile
> mVideo
;
140 nsRefPtr
<CameraRecorderAudioProfile
> mAudio
;
143 DISALLOW_EVIL_CONSTRUCTORS(CameraRecorderProfile
);
147 * CameraRecorderProfiles
149 template<class T
> class CameraClosedListenerProxy
;
151 class CameraRecorderProfiles MOZ_FINAL
: public nsISupports
152 , public nsWrapperCache
155 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
156 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(CameraRecorderProfiles
)
158 explicit CameraRecorderProfiles(nsISupports
* aParent
,
159 ICameraControl
* aCameraControl
);
160 nsISupports
* GetParentObject() const { return mParent
; }
161 virtual JSObject
* WrapObject(JSContext
* aCx
) MOZ_OVERRIDE
;
163 CameraRecorderProfile
* NamedGetter(const nsAString
& aName
, bool& aFound
);
164 bool NameIsEnumerable(const nsAString
& aName
);
165 void GetSupportedNames(unsigned aFlags
, nsTArray
<nsString
>& aNames
);
167 virtual void OnHardwareClosed();
170 virtual ~CameraRecorderProfiles();
172 nsCOMPtr
<nsISupports
> mParent
;
173 nsRefPtr
<ICameraControl
> mCameraControl
;
174 nsRefPtrHashtable
<nsStringHashKey
, CameraRecorderProfile
> mProfiles
;
175 nsRefPtr
<CameraClosedListenerProxy
<CameraRecorderProfiles
>> mListener
;
178 DISALLOW_EVIL_CONSTRUCTORS(CameraRecorderProfiles
);
184 class CameraCapabilities MOZ_FINAL
: public nsISupports
185 , public nsWrapperCache
188 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
189 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(CameraCapabilities
)
191 // Because this header's filename doesn't match its C++ or DOM-facing
192 // classname, we can't rely on the [Func="..."] WebIDL tag to implicitly
193 // include the right header for us; instead we must explicitly include a
194 // HasSupport() method in each header. We can get rid of these with the
195 // Great Renaming proposed in bug 983177.
196 static bool HasSupport(JSContext
* aCx
, JSObject
* aGlobal
);
198 explicit CameraCapabilities(nsPIDOMWindow
* aWindow
,
199 ICameraControl
* aCameraControl
);
201 nsPIDOMWindow
* GetParentObject() const { return mWindow
; }
203 virtual JSObject
* WrapObject(JSContext
* aCx
) MOZ_OVERRIDE
;
205 void GetPreviewSizes(nsTArray
<CameraSize
>& aRetVal
);
206 void GetPictureSizes(nsTArray
<CameraSize
>& aRetVal
);
207 void GetThumbnailSizes(nsTArray
<CameraSize
>& aRetVal
);
208 void GetVideoSizes(nsTArray
<CameraSize
>& aRetVal
);
209 void GetFileFormats(nsTArray
<nsString
>& aRetVal
);
210 void GetWhiteBalanceModes(nsTArray
<nsString
>& aRetVal
);
211 void GetSceneModes(nsTArray
<nsString
>& aRetVal
);
212 void GetEffects(nsTArray
<nsString
>& aRetVal
);
213 void GetFlashModes(nsTArray
<nsString
>& aRetVal
);
214 void GetFocusModes(nsTArray
<nsString
>& aRetVal
);
215 void GetZoomRatios(nsTArray
<double>& aRetVal
);
216 uint32_t MaxFocusAreas();
217 uint32_t MaxMeteringAreas();
218 uint32_t MaxDetectedFaces();
219 double MinExposureCompensation();
220 double MaxExposureCompensation();
221 double ExposureCompensationStep();
222 void GetIsoModes(nsTArray
<nsString
>& aRetVal
);
223 void GetMeteringModes(nsTArray
<nsString
>& aRetVal
);
225 CameraRecorderProfiles
* RecorderProfiles();
227 virtual void OnHardwareClosed();
230 ~CameraCapabilities();
232 nsresult
TranslateToDictionary(uint32_t aKey
, nsTArray
<CameraSize
>& aSizes
);
234 nsRefPtr
<nsPIDOMWindow
> mWindow
;
235 nsRefPtr
<ICameraControl
> mCameraControl
;
236 nsRefPtr
<CameraClosedListenerProxy
<CameraCapabilities
>> mListener
;
239 DISALLOW_EVIL_CONSTRUCTORS(CameraCapabilities
);
243 } // namespace mozilla
245 #endif // mozilla_dom_CameraCapabilities_h__