dom/camera/CameraRecorderProfiles.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
michael@0 3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 #ifndef DOM_CAMERA_CAMERA_RECORDER_PROFILES_H
michael@0 6 #define DOM_CAMERA_CAMERA_RECORDER_PROFILES_H
michael@0 7
michael@0 8 #include "nsISupportsImpl.h"
michael@0 9 #include "nsMimeTypes.h"
michael@0 10 #include "nsAutoPtr.h"
michael@0 11 #include "nsTArray.h"
michael@0 12 #include "jsapi.h"
michael@0 13 #include "CameraCommon.h"
michael@0 14
michael@0 15 namespace mozilla {
michael@0 16
michael@0 17 class CameraControlImpl;
michael@0 18
michael@0 19 class RecorderVideoProfile
michael@0 20 {
michael@0 21 public:
michael@0 22 RecorderVideoProfile(uint32_t aCameraId, uint32_t aQualityIndex);
michael@0 23 virtual ~RecorderVideoProfile();
michael@0 24
michael@0 25 int GetBitrate() const { return mBitrate; }
michael@0 26 int GetFramerate() const { return mFramerate; }
michael@0 27 int GetWidth() const { return mWidth; }
michael@0 28 int GetHeight() const { return mHeight; }
michael@0 29
michael@0 30 enum Codec {
michael@0 31 H263,
michael@0 32 H264,
michael@0 33 MPEG4SP,
michael@0 34 UNKNOWN
michael@0 35 };
michael@0 36 Codec GetCodec() const { return mCodec; }
michael@0 37 const char* GetCodecName() const
michael@0 38 {
michael@0 39 switch (mCodec) {
michael@0 40 case H263: return "h263";
michael@0 41 case H264: return "h264";
michael@0 42 case MPEG4SP: return "mpeg4sp";
michael@0 43 default: return nullptr;
michael@0 44 }
michael@0 45 }
michael@0 46
michael@0 47 nsresult GetJsObject(JSContext* aCx, JSObject** aObject);
michael@0 48
michael@0 49 protected:
michael@0 50 uint32_t mCameraId;
michael@0 51 uint32_t mQualityIndex;
michael@0 52 Codec mCodec;
michael@0 53 int mBitrate;
michael@0 54 int mFramerate;
michael@0 55 int mWidth;
michael@0 56 int mHeight;
michael@0 57 };
michael@0 58
michael@0 59 class RecorderAudioProfile
michael@0 60 {
michael@0 61 public:
michael@0 62 RecorderAudioProfile(uint32_t aCameraId, uint32_t aQualityIndex);
michael@0 63 virtual ~RecorderAudioProfile();
michael@0 64
michael@0 65 int GetBitrate() const { return mBitrate; }
michael@0 66 int GetSamplerate() const { return mSamplerate; }
michael@0 67 int GetChannels() const { return mChannels; }
michael@0 68
michael@0 69 enum Codec {
michael@0 70 AMRNB,
michael@0 71 AMRWB,
michael@0 72 AAC,
michael@0 73 UNKNOWN
michael@0 74 };
michael@0 75
michael@0 76 public:
michael@0 77 Codec GetCodec() const { return mCodec; }
michael@0 78 const char* GetCodecName() const
michael@0 79 {
michael@0 80 switch (mCodec) {
michael@0 81 case AMRNB: return "amrnb";
michael@0 82 case AMRWB: return "amrwb";
michael@0 83 case AAC: return "aac";
michael@0 84 default: return nullptr;
michael@0 85 }
michael@0 86 }
michael@0 87
michael@0 88 nsresult GetJsObject(JSContext* aCx, JSObject** aObject);
michael@0 89
michael@0 90 protected:
michael@0 91 uint32_t mCameraId;
michael@0 92 uint32_t mQualityIndex;
michael@0 93 Codec mCodec;
michael@0 94 int mBitrate;
michael@0 95 int mSamplerate;
michael@0 96 int mChannels;
michael@0 97 };
michael@0 98
michael@0 99 class RecorderProfile
michael@0 100 {
michael@0 101 public:
michael@0 102 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(RecorderProfile)
michael@0 103
michael@0 104 RecorderProfile(uint32_t aCameraId, uint32_t aQualityIndex);
michael@0 105
michael@0 106 virtual const RecorderVideoProfile* GetVideoProfile() const = 0;
michael@0 107 virtual const RecorderAudioProfile* GetAudioProfile() const = 0;
michael@0 108 const char* GetName() const { return mName; }
michael@0 109
michael@0 110 enum FileFormat {
michael@0 111 THREE_GPP,
michael@0 112 MPEG4,
michael@0 113 UNKNOWN
michael@0 114 };
michael@0 115 FileFormat GetFileFormat() const { return mFileFormat; }
michael@0 116 const char* GetFileFormatName() const
michael@0 117 {
michael@0 118 switch (mFileFormat) {
michael@0 119 case THREE_GPP: return "3gp";
michael@0 120 case MPEG4: return "mp4";
michael@0 121 default: return nullptr;
michael@0 122 }
michael@0 123 }
michael@0 124 const char* GetFileMimeType() const
michael@0 125 {
michael@0 126 switch (mFileFormat) {
michael@0 127 case THREE_GPP: return VIDEO_3GPP;
michael@0 128 case MPEG4: return VIDEO_MP4;
michael@0 129 default: return nullptr;
michael@0 130 }
michael@0 131 }
michael@0 132
michael@0 133 virtual nsresult GetJsObject(JSContext* aCx, JSObject** aObject) = 0;
michael@0 134
michael@0 135 protected:
michael@0 136 virtual ~RecorderProfile();
michael@0 137
michael@0 138 uint32_t mCameraId;
michael@0 139 uint32_t mQualityIndex;
michael@0 140 const char* mName;
michael@0 141 FileFormat mFileFormat;
michael@0 142 };
michael@0 143
michael@0 144 template <class Audio, class Video>
michael@0 145 class RecorderProfileBase : public RecorderProfile
michael@0 146 {
michael@0 147 public:
michael@0 148 RecorderProfileBase(uint32_t aCameraId, uint32_t aQualityIndex)
michael@0 149 : RecorderProfile(aCameraId, aQualityIndex)
michael@0 150 , mVideo(aCameraId, aQualityIndex)
michael@0 151 , mAudio(aCameraId, aQualityIndex)
michael@0 152 {
michael@0 153 DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this);
michael@0 154 }
michael@0 155
michael@0 156 virtual ~RecorderProfileBase()
michael@0 157 {
michael@0 158 DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this);
michael@0 159 }
michael@0 160
michael@0 161 const RecorderVideoProfile* GetVideoProfile() const { return &mVideo; }
michael@0 162 const RecorderAudioProfile* GetAudioProfile() const { return &mAudio; }
michael@0 163
michael@0 164 nsresult GetJsObject(JSContext* aCx, JSObject** aObject)
michael@0 165 {
michael@0 166 NS_ENSURE_TRUE(aObject, NS_ERROR_INVALID_ARG);
michael@0 167
michael@0 168 const char* format = GetFileFormatName();
michael@0 169 if (!format) {
michael@0 170 // the profile must have a file format
michael@0 171 return NS_ERROR_FAILURE;
michael@0 172 }
michael@0 173
michael@0 174 JS::Rooted<JSObject*> o(aCx, JS_NewObject(aCx, nullptr, JS::NullPtr(), JS::NullPtr()));
michael@0 175 if (!o) {
michael@0 176 return NS_ERROR_OUT_OF_MEMORY;
michael@0 177 }
michael@0 178
michael@0 179 JS::Rooted<JSString*> s(aCx, JS_NewStringCopyZ(aCx, format));
michael@0 180 JS::Rooted<JS::Value> v(aCx, STRING_TO_JSVAL(s));
michael@0 181 if (!JS_SetProperty(aCx, o, "format", v)) {
michael@0 182 return NS_ERROR_FAILURE;
michael@0 183 }
michael@0 184
michael@0 185 JS::Rooted<JSObject*> video(aCx);
michael@0 186 nsresult rv = mVideo.GetJsObject(aCx, video.address());
michael@0 187 NS_ENSURE_SUCCESS(rv, rv);
michael@0 188 v = OBJECT_TO_JSVAL(video);
michael@0 189 if (!JS_SetProperty(aCx, o, "video", v)) {
michael@0 190 return NS_ERROR_FAILURE;
michael@0 191 }
michael@0 192
michael@0 193 JS::Rooted<JSObject*> audio(aCx);
michael@0 194 rv = mAudio.GetJsObject(aCx, audio.address());
michael@0 195 NS_ENSURE_SUCCESS(rv, rv);
michael@0 196 v = OBJECT_TO_JSVAL(audio);
michael@0 197 if (!JS_SetProperty(aCx, o, "audio", v)) {
michael@0 198 return NS_ERROR_FAILURE;
michael@0 199 }
michael@0 200
michael@0 201 *aObject = o;
michael@0 202 return NS_OK;
michael@0 203 }
michael@0 204
michael@0 205 protected:
michael@0 206 Video mVideo;
michael@0 207 Audio mAudio;
michael@0 208 };
michael@0 209
michael@0 210 class RecorderProfileManager
michael@0 211 {
michael@0 212 public:
michael@0 213 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(RecorderProfileManager)
michael@0 214
michael@0 215 virtual bool IsSupported(uint32_t aQualityIndex) const { return true; }
michael@0 216 virtual already_AddRefed<RecorderProfile> Get(uint32_t aQualityIndex) const = 0;
michael@0 217
michael@0 218 uint32_t GetMaxQualityIndex() const { return mMaxQualityIndex; }
michael@0 219 nsresult GetJsObject(JSContext* aCx, JSObject** aObject) const;
michael@0 220
michael@0 221 protected:
michael@0 222 RecorderProfileManager(uint32_t aCameraId);
michael@0 223 virtual ~RecorderProfileManager();
michael@0 224
michael@0 225 uint32_t mCameraId;
michael@0 226 uint32_t mMaxQualityIndex;
michael@0 227 };
michael@0 228
michael@0 229 } // namespace mozilla
michael@0 230
michael@0 231 #endif // DOM_CAMERA_CAMERA_RECORDER_PROFILES_H

mercurial