dom/camera/CameraRecorderProfiles.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial