DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Implementation

Mercurial (31ec81b5d7bb)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef DOM_CAMERA_CAMERA_RECORDER_PROFILES_H
#define DOM_CAMERA_CAMERA_RECORDER_PROFILES_H

#include "nsISupportsImpl.h"
#include "nsMimeTypes.h"
#include "nsAutoPtr.h"
#include "nsTArray.h"
#include "jsapi.h"
#include "DictionaryHelpers.h"
#include "CameraCommon.h"


namespace mozilla {

class CameraControlImpl;

class RecorderVideoProfile
{
public:
  RecorderVideoProfile(uint32_t aCameraId, uint32_t aQualityIndex);
  virtual ~RecorderVideoProfile();

  int GetBitrate() const    { return mBitrate; }
  int GetFramerate() const  { return mFramerate; }
  int GetWidth() const      { return mWidth; }
  int GetHeight() const     { return mHeight; }

  enum Codec {
    H263,
    H264,
    MPEG4SP,
    UNKNOWN
  };
  Codec GetCodec() const    { return mCodec; }
  const char* GetCodecName() const
  {
    switch (mCodec) {
      case H263:    return "h263";
      case H264:    return "h264";
      case MPEG4SP: return "mpeg4sp";
      default:      return nullptr;
    }
  }

  nsresult GetJsObject(JSContext* aCx, JSObject** aObject);

protected:
  uint32_t mCameraId;
  uint32_t mQualityIndex;
  Codec mCodec;
  int mBitrate;
  int mFramerate;
  int mWidth;
  int mHeight;
};

class RecorderAudioProfile
{
public:
  RecorderAudioProfile(uint32_t aCameraId, uint32_t aQualityIndex);
  virtual ~RecorderAudioProfile();

  int GetBitrate() const    { return mBitrate; }
  int GetSamplerate() const { return mSamplerate; }
  int GetChannels() const   { return mChannels; }

  enum Codec {
    AMRNB,
    AMRWB,
    AAC,
    UNKNOWN
  };

public:
  Codec GetCodec() const    { return mCodec; }
  const char* GetCodecName() const
  {
    switch (mCodec) {
      case AMRNB: return "amrnb";
      case AMRWB: return "amrwb";
      case AAC:   return "aac";
      default:    return nullptr;
    }
  }

  nsresult GetJsObject(JSContext* aCx, JSObject** aObject);

protected:
  uint32_t mCameraId;
  uint32_t mQualityIndex;
  Codec mCodec;
  int mBitrate;
  int mSamplerate;
  int mChannels;
};

class RecorderProfile
{
public:
  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(RecorderProfile)

  RecorderProfile(uint32_t aCameraId, uint32_t aQualityIndex);

  virtual const RecorderVideoProfile* GetVideoProfile() const = 0;
  virtual const RecorderAudioProfile* GetAudioProfile() const = 0;
  const char* GetName() const { return mName; }

  enum FileFormat {
    THREE_GPP,
    MPEG4,
    UNKNOWN
  };
  FileFormat GetFileFormat() const { return mFileFormat; }
  const char* GetFileFormatName() const
  {
    switch (mFileFormat) {
      case THREE_GPP: return "3gp";
      case MPEG4:     return "mp4";
      default:        return nullptr;
    }
  }
  const char* GetFileMimeType() const
  {
    switch (mFileFormat) {
      case THREE_GPP: return VIDEO_3GPP;
      case MPEG4:     return VIDEO_MP4;
      default:        return nullptr;
    }
  }

  virtual nsresult GetJsObject(JSContext* aCx, JSObject** aObject) = 0;

protected:
  virtual ~RecorderProfile();

  uint32_t mCameraId;
  uint32_t mQualityIndex;
  const char* mName;
  FileFormat mFileFormat;
};

template <class Audio, class Video>
class RecorderProfileBase : public RecorderProfile
{
public:
  RecorderProfileBase(uint32_t aCameraId, uint32_t aQualityIndex)
    : RecorderProfile(aCameraId, aQualityIndex)
    , mVideo(aCameraId, aQualityIndex)
    , mAudio(aCameraId, aQualityIndex)
  {
    DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this);
  }

  virtual ~RecorderProfileBase()
  {
    DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this);
  }

  const RecorderVideoProfile* GetVideoProfile() const { return &mVideo; }
  const RecorderAudioProfile* GetAudioProfile() const { return &mAudio; }

  nsresult GetJsObject(JSContext* aCx, JSObject** aObject)
  {
    NS_ENSURE_TRUE(aObject, NS_ERROR_INVALID_ARG);

    const char* format = GetFileFormatName();
    if (!format) {
      // the profile must have a file format
      return NS_ERROR_FAILURE;
    }

    JS::Rooted<JSObject*> o(aCx, JS_NewObject(aCx, nullptr, nullptr, nullptr));
    if (!o) {
      return NS_ERROR_OUT_OF_MEMORY;
    }

    JS::Rooted<JSString*> s(aCx, JS_NewStringCopyZ(aCx, format));
    JS::Rooted<JS::Value> v(aCx, STRING_TO_JSVAL(s));
    if (!JS_SetProperty(aCx, o, "format", v)) {
      return NS_ERROR_FAILURE;
    }

    JS::Rooted<JSObject*> video(aCx);
    nsresult rv = mVideo.GetJsObject(aCx, video.address());
    NS_ENSURE_SUCCESS(rv, rv);
    v = OBJECT_TO_JSVAL(video);
    if (!JS_SetProperty(aCx, o, "video", v)) {
      return NS_ERROR_FAILURE;
    }

    JS::Rooted<JSObject*> audio(aCx);
    rv = mAudio.GetJsObject(aCx, audio.address());
    NS_ENSURE_SUCCESS(rv, rv);
    v = OBJECT_TO_JSVAL(audio);
    if (!JS_SetProperty(aCx, o, "audio", v)) {
      return NS_ERROR_FAILURE;
    }

    *aObject = o;
    return NS_OK;
  }

protected:
  Video mVideo;
  Audio mAudio;
};

class RecorderProfileManager
{
public:
  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(RecorderProfileManager)

  virtual bool IsSupported(uint32_t aQualityIndex) const { return true; }
  virtual already_AddRefed<RecorderProfile> Get(uint32_t aQualityIndex) const = 0;

  uint32_t GetMaxQualityIndex() const { return mMaxQualityIndex; }
  nsresult GetJsObject(JSContext* aCx, JSObject** aObject) const;

protected:
  RecorderProfileManager(uint32_t aCameraId);
  virtual ~RecorderProfileManager();

  uint32_t mCameraId;
  uint32_t mMaxQualityIndex;
};

} // namespace mozilla

#endif // DOM_CAMERA_CAMERA_RECORDER_PROFILES_H