1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #ifndef DOM_CAMERA_CAMERA_RECORDER_PROFILES_H
6 #define DOM_CAMERA_CAMERA_RECORDER_PROFILES_H
8 #include "nsISupportsImpl.h"
9 #include "nsMimeTypes.h"
10 #include "nsAutoPtr.h"
13 #include "DictionaryHelpers.h"
14 #include "CameraCommon.h"
19 class CameraControlImpl
;
21 class RecorderVideoProfile
24 RecorderVideoProfile(uint32_t aCameraId
, uint32_t aQualityIndex
);
25 virtual ~RecorderVideoProfile();
27 int GetBitrate() const { return mBitrate
; }
28 int GetFramerate() const { return mFramerate
; }
29 int GetWidth() const { return mWidth
; }
30 int GetHeight() const { return mHeight
; }
38 Codec
GetCodec() const { return mCodec
; }
39 const char* GetCodecName() const
42 case H263
: return "h263";
43 case H264
: return "h264";
44 case MPEG4SP
: return "mpeg4sp";
45 default: return nullptr;
49 nsresult
GetJsObject(JSContext
* aCx
, JSObject
** aObject
);
53 uint32_t mQualityIndex
;
61 class RecorderAudioProfile
64 RecorderAudioProfile(uint32_t aCameraId
, uint32_t aQualityIndex
);
65 virtual ~RecorderAudioProfile();
67 int GetBitrate() const { return mBitrate
; }
68 int GetSamplerate() const { return mSamplerate
; }
69 int GetChannels() const { return mChannels
; }
79 Codec
GetCodec() const { return mCodec
; }
80 const char* GetCodecName() const
83 case AMRNB
: return "amrnb";
84 case AMRWB
: return "amrwb";
85 case AAC
: return "aac";
86 default: return nullptr;
90 nsresult
GetJsObject(JSContext
* aCx
, JSObject
** aObject
);
94 uint32_t mQualityIndex
;
101 class RecorderProfile
104 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(RecorderProfile
)
106 RecorderProfile(uint32_t aCameraId
, uint32_t aQualityIndex
);
108 virtual const RecorderVideoProfile
* GetVideoProfile() const = 0;
109 virtual const RecorderAudioProfile
* GetAudioProfile() const = 0;
110 const char* GetName() const { return mName
; }
117 FileFormat
GetFileFormat() const { return mFileFormat
; }
118 const char* GetFileFormatName() const
120 switch (mFileFormat
) {
121 case THREE_GPP
: return "3gp";
122 case MPEG4
: return "mp4";
123 default: return nullptr;
126 const char* GetFileMimeType() const
128 switch (mFileFormat
) {
129 case THREE_GPP
: return VIDEO_3GPP
;
130 case MPEG4
: return VIDEO_MP4
;
131 default: return nullptr;
135 virtual nsresult
GetJsObject(JSContext
* aCx
, JSObject
** aObject
) = 0;
138 virtual ~RecorderProfile();
141 uint32_t mQualityIndex
;
143 FileFormat mFileFormat
;
146 template <class Audio
, class Video
>
147 class RecorderProfileBase
: public RecorderProfile
150 RecorderProfileBase(uint32_t aCameraId
, uint32_t aQualityIndex
)
151 : RecorderProfile(aCameraId
, aQualityIndex
)
152 , mVideo(aCameraId
, aQualityIndex
)
153 , mAudio(aCameraId
, aQualityIndex
)
155 DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__
, __LINE__
, this);
158 virtual ~RecorderProfileBase()
160 DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__
, __LINE__
, this);
163 const RecorderVideoProfile
* GetVideoProfile() const { return &mVideo
; }
164 const RecorderAudioProfile
* GetAudioProfile() const { return &mAudio
; }
166 nsresult
GetJsObject(JSContext
* aCx
, JSObject
** aObject
)
168 NS_ENSURE_TRUE(aObject
, NS_ERROR_INVALID_ARG
);
170 const char* format
= GetFileFormatName();
172 // the profile must have a file format
173 return NS_ERROR_FAILURE
;
176 JS::Rooted
<JSObject
*> o(aCx
, JS_NewObject(aCx
, nullptr, nullptr, nullptr));
178 return NS_ERROR_OUT_OF_MEMORY
;
181 JS::Rooted
<JSString
*> s(aCx
, JS_NewStringCopyZ(aCx
, format
));
182 JS::Rooted
<JS::Value
> v(aCx
, STRING_TO_JSVAL(s
));
183 if (!JS_SetProperty(aCx
, o
, "format", v
)) {
184 return NS_ERROR_FAILURE
;
187 JS::Rooted
<JSObject
*> video(aCx
);
188 nsresult rv
= mVideo
.GetJsObject(aCx
, video
.address());
189 NS_ENSURE_SUCCESS(rv
, rv
);
190 v
= OBJECT_TO_JSVAL(video
);
191 if (!JS_SetProperty(aCx
, o
, "video", v
)) {
192 return NS_ERROR_FAILURE
;
195 JS::Rooted
<JSObject
*> audio(aCx
);
196 rv
= mAudio
.GetJsObject(aCx
, audio
.address());
197 NS_ENSURE_SUCCESS(rv
, rv
);
198 v
= OBJECT_TO_JSVAL(audio
);
199 if (!JS_SetProperty(aCx
, o
, "audio", v
)) {
200 return NS_ERROR_FAILURE
;
212 class RecorderProfileManager
215 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(RecorderProfileManager
)
217 virtual bool IsSupported(uint32_t aQualityIndex
) const { return true; }
218 virtual already_AddRefed
<RecorderProfile
> Get(uint32_t aQualityIndex
) const = 0;
220 uint32_t GetMaxQualityIndex() const { return mMaxQualityIndex
; }
221 nsresult
GetJsObject(JSContext
* aCx
, JSObject
** aObject
) const;
224 RecorderProfileManager(uint32_t aCameraId
);
225 virtual ~RecorderProfileManager();
228 uint32_t mMaxQualityIndex
;
231 } // namespace mozilla
233 #endif // DOM_CAMERA_CAMERA_RECORDER_PROFILES_H