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 #include "CameraRecorderProfiles.h"
7 #include "CameraCommon.h"
9 using namespace mozilla
;
12 * Video profile implementation.
14 RecorderVideoProfile::RecorderVideoProfile(uint32_t aCameraId
, uint32_t aQualityIndex
)
15 : mCameraId(aCameraId
)
16 , mQualityIndex(aQualityIndex
)
18 DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__
, __LINE__
, this);
21 RecorderVideoProfile::~RecorderVideoProfile()
23 DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__
, __LINE__
, this);
27 RecorderVideoProfile::GetJsObject(JSContext
* aCx
, JSObject
** aObject
)
29 NS_ENSURE_TRUE(aObject
, NS_ERROR_INVALID_ARG
);
31 JS::Rooted
<JSObject
*> o(aCx
, JS_NewObject(aCx
, nullptr, JS::NullPtr(), JS::NullPtr()));
32 NS_ENSURE_TRUE(o
, NS_ERROR_OUT_OF_MEMORY
);
34 const char* codec
= GetCodecName();
35 NS_ENSURE_TRUE(codec
, NS_ERROR_FAILURE
);
37 JS::Rooted
<JSString
*> s(aCx
, JS_NewStringCopyZ(aCx
, codec
));
38 JS::Rooted
<JS::Value
> v(aCx
, STRING_TO_JSVAL(s
));
39 if (!JS_SetProperty(aCx
, o
, "codec", v
)) {
40 return NS_ERROR_FAILURE
;
44 v
= INT_TO_JSVAL(mBitrate
);
45 if (!JS_SetProperty(aCx
, o
, "bitrate", v
)) {
46 return NS_ERROR_FAILURE
;
49 if (mFramerate
!= -1) {
50 v
= INT_TO_JSVAL(mFramerate
);
51 if (!JS_SetProperty(aCx
, o
, "framerate", v
)) {
52 return NS_ERROR_FAILURE
;
56 v
= INT_TO_JSVAL(mWidth
);
57 if (!JS_SetProperty(aCx
, o
, "width", v
)) {
58 return NS_ERROR_FAILURE
;
62 v
= INT_TO_JSVAL(mHeight
);
63 if (!JS_SetProperty(aCx
, o
, "height", v
)) {
64 return NS_ERROR_FAILURE
;
73 * Audio profile implementation.
75 RecorderAudioProfile::RecorderAudioProfile(uint32_t aCameraId
, uint32_t aQualityIndex
)
76 : mCameraId(aCameraId
)
77 , mQualityIndex(aQualityIndex
)
79 DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__
, __LINE__
, this);
82 RecorderAudioProfile::~RecorderAudioProfile()
84 DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__
, __LINE__
, this);
88 RecorderAudioProfile::GetJsObject(JSContext
* aCx
, JSObject
** aObject
)
90 NS_ENSURE_TRUE(aObject
, NS_ERROR_INVALID_ARG
);
92 JS::Rooted
<JSObject
*> o(aCx
, JS_NewObject(aCx
, nullptr, JS::NullPtr(), JS::NullPtr()));
93 NS_ENSURE_TRUE(o
, NS_ERROR_OUT_OF_MEMORY
);
95 const char* codec
= GetCodecName();
96 NS_ENSURE_TRUE(codec
, NS_ERROR_FAILURE
);
98 JS::Rooted
<JSString
*> s(aCx
, JS_NewStringCopyZ(aCx
, codec
));
99 JS::Rooted
<JS::Value
> v(aCx
, STRING_TO_JSVAL(s
));
100 if (!JS_SetProperty(aCx
, o
, "codec", v
)) {
101 return NS_ERROR_FAILURE
;
104 if (mBitrate
!= -1) {
105 v
= INT_TO_JSVAL(mBitrate
);
106 if (!JS_SetProperty(aCx
, o
, "bitrate", v
)) {
107 return NS_ERROR_FAILURE
;
110 if (mSamplerate
!= -1) {
111 v
= INT_TO_JSVAL(mSamplerate
);
112 if (!JS_SetProperty(aCx
, o
, "samplerate", v
)) {
113 return NS_ERROR_FAILURE
;
116 if (mChannels
!= -1) {
117 v
= INT_TO_JSVAL(mChannels
);
118 if (!JS_SetProperty(aCx
, o
, "channels", v
)) {
119 return NS_ERROR_FAILURE
;
130 RecorderProfile::RecorderProfile(uint32_t aCameraId
, uint32_t aQualityIndex
)
131 : mCameraId(aCameraId
)
132 , mQualityIndex(aQualityIndex
)
135 DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__
, __LINE__
, this);
138 RecorderProfile::~RecorderProfile()
140 DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__
, __LINE__
, this);
144 * Recorder profile manager implementation.
146 RecorderProfileManager::RecorderProfileManager(uint32_t aCameraId
)
147 : mCameraId(aCameraId
)
149 DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__
, __LINE__
, this);
152 RecorderProfileManager::~RecorderProfileManager()
154 DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__
, __LINE__
, this);
158 RecorderProfileManager::GetJsObject(JSContext
* aCx
, JSObject
** aObject
) const
160 NS_ENSURE_TRUE(aObject
, NS_ERROR_INVALID_ARG
);
162 JS::Rooted
<JSObject
*> o(aCx
, JS_NewObject(aCx
, nullptr, JS::NullPtr(), JS::NullPtr()));
164 return NS_ERROR_OUT_OF_MEMORY
;
167 for (uint32_t q
= 0; q
< GetMaxQualityIndex(); ++q
) {
168 if (!IsSupported(q
)) {
172 nsRefPtr
<RecorderProfile
> profile
= Get(q
);
174 return NS_ERROR_OUT_OF_MEMORY
;
177 const char* profileName
= profile
->GetName();
179 // don't allow anonymous recorder profiles
183 JS::Rooted
<JSObject
*> p(aCx
);
184 nsresult rv
= profile
->GetJsObject(aCx
, p
.address());
185 NS_ENSURE_SUCCESS(rv
, rv
);
186 JS::Rooted
<JS::Value
> v(aCx
, OBJECT_TO_JSVAL(p
));
188 if (!JS_SetProperty(aCx
, o
, profileName
, v
)) {
189 return NS_ERROR_FAILURE
;