2012-10-24 02:30:28 +04:00
|
|
|
/* 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_GONK_RECORDER_PROFILES_H
|
|
|
|
#define DOM_CAMERA_GONK_RECORDER_PROFILES_H
|
|
|
|
|
|
|
|
#include <media/MediaProfiles.h>
|
2014-02-15 02:41:07 +04:00
|
|
|
#include "ICameraControl.h"
|
2014-10-31 20:19:06 +03:00
|
|
|
#include "nsClassHashtable.h"
|
|
|
|
#include "nsRefPtrHashtable.h"
|
2012-10-24 02:30:28 +04:00
|
|
|
|
2014-05-15 01:33:00 +04:00
|
|
|
#ifndef CHECK_SETARG_RETURN
|
|
|
|
#define CHECK_SETARG_RETURN(x, rv) \
|
2012-10-24 02:30:28 +04:00
|
|
|
do { \
|
|
|
|
if (x) { \
|
|
|
|
DOM_CAMERA_LOGE(#x " failed\n"); \
|
2014-05-15 01:33:00 +04:00
|
|
|
return rv; \
|
2012-10-24 02:30:28 +04:00
|
|
|
} \
|
|
|
|
} while(0)
|
|
|
|
#endif
|
|
|
|
|
2014-05-15 01:33:00 +04:00
|
|
|
#ifndef CHECK_SETARG
|
|
|
|
#define CHECK_SETARG(x) CHECK_SETARG_RETURN(x, NS_ERROR_NOT_AVAILABLE)
|
|
|
|
#endif
|
2012-10-24 02:30:28 +04:00
|
|
|
|
|
|
|
namespace android {
|
2014-10-31 20:19:06 +03:00
|
|
|
class GonkRecorder;
|
2012-10-24 02:30:28 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
/**
|
2014-10-31 20:19:06 +03:00
|
|
|
* class GonkRecorderProfileBase
|
2012-10-24 02:30:28 +04:00
|
|
|
*/
|
2014-10-31 20:19:06 +03:00
|
|
|
template<class A, class V>
|
|
|
|
class GonkRecorderProfileBase : public ICameraControl::RecorderProfile
|
2012-10-24 02:30:28 +04:00
|
|
|
{
|
|
|
|
public:
|
2014-12-03 02:14:17 +03:00
|
|
|
GonkRecorderProfileBase(uint32_t aCameraId, int aQuality)
|
|
|
|
: RecorderProfile()
|
|
|
|
, mAudio(aCameraId, aQuality)
|
|
|
|
, mVideo(aCameraId, aQuality)
|
2014-10-31 20:19:06 +03:00
|
|
|
{ }
|
|
|
|
|
|
|
|
virtual const Audio& GetAudio() const MOZ_OVERRIDE { return mAudio; }
|
|
|
|
virtual const Video& GetVideo() const MOZ_OVERRIDE { return mVideo; }
|
2012-10-24 02:30:28 +04:00
|
|
|
|
|
|
|
protected:
|
2014-10-31 20:19:06 +03:00
|
|
|
virtual ~GonkRecorderProfileBase() { }
|
|
|
|
A mAudio;
|
|
|
|
V mVideo;
|
2012-10-24 02:30:28 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2014-10-31 20:19:06 +03:00
|
|
|
* class GonkRecorderVideo
|
2012-10-24 02:30:28 +04:00
|
|
|
*/
|
2014-10-31 20:19:06 +03:00
|
|
|
class GonkRecorderVideo : public ICameraControl::RecorderProfile::Video
|
2012-10-24 02:30:28 +04:00
|
|
|
{
|
|
|
|
public:
|
2014-12-03 02:14:17 +03:00
|
|
|
GonkRecorderVideo(uint32_t aCameraId, int aQuality);
|
2014-10-31 20:19:06 +03:00
|
|
|
virtual ~GonkRecorderVideo() { }
|
|
|
|
|
|
|
|
android::video_encoder GetPlatformEncoder() const { return mPlatformEncoder; }
|
|
|
|
bool IsValid() const { return mIsValid; }
|
2012-10-24 02:30:28 +04:00
|
|
|
|
|
|
|
protected:
|
2014-10-31 20:19:06 +03:00
|
|
|
int GetProfileParameter(const char* aParameter);
|
|
|
|
static bool Translate(android::video_encoder aCodec, nsAString& aCodecName);
|
|
|
|
|
|
|
|
uint32_t mCameraId;
|
2014-12-03 02:14:17 +03:00
|
|
|
int mQuality;
|
2014-10-31 20:19:06 +03:00
|
|
|
bool mIsValid;
|
|
|
|
android::video_encoder mPlatformEncoder;
|
2012-10-24 02:30:28 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2014-10-31 20:19:06 +03:00
|
|
|
* class GonkRecorderAudio
|
2012-10-24 02:30:28 +04:00
|
|
|
*/
|
2014-10-31 20:19:06 +03:00
|
|
|
class GonkRecorderAudio : public ICameraControl::RecorderProfile::Audio
|
2012-10-24 02:30:28 +04:00
|
|
|
{
|
|
|
|
public:
|
2014-12-03 02:14:17 +03:00
|
|
|
GonkRecorderAudio(uint32_t aCameraId, int aQuality);
|
2014-10-31 20:19:06 +03:00
|
|
|
virtual ~GonkRecorderAudio() { }
|
2012-10-24 02:30:28 +04:00
|
|
|
|
2014-10-31 20:19:06 +03:00
|
|
|
android::audio_encoder GetPlatformEncoder() const { return mPlatformEncoder; }
|
|
|
|
bool IsValid() const { return mIsValid; }
|
2012-10-24 02:30:28 +04:00
|
|
|
|
|
|
|
protected:
|
2014-10-31 20:19:06 +03:00
|
|
|
int GetProfileParameter(const char* aParameter);
|
|
|
|
static bool Translate(android::audio_encoder aCodec, nsAString& aCodecName);
|
2012-10-24 02:30:28 +04:00
|
|
|
|
2014-10-31 20:19:06 +03:00
|
|
|
uint32_t mCameraId;
|
2014-12-03 02:14:17 +03:00
|
|
|
int mQuality;
|
2014-10-31 20:19:06 +03:00
|
|
|
bool mIsValid;
|
|
|
|
android::audio_encoder mPlatformEncoder;
|
2012-10-24 02:30:28 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2014-10-31 20:19:06 +03:00
|
|
|
* class GonkRecorderProfile
|
2012-10-24 02:30:28 +04:00
|
|
|
*/
|
2014-10-31 20:19:06 +03:00
|
|
|
class GonkRecorderProfile;
|
|
|
|
typedef nsRefPtrHashtable<nsStringHashKey, GonkRecorderProfile> ProfileHashtable;
|
|
|
|
|
|
|
|
class GonkRecorderProfile
|
|
|
|
: public GonkRecorderProfileBase<GonkRecorderAudio, GonkRecorderVideo>
|
2012-10-24 02:30:28 +04:00
|
|
|
{
|
|
|
|
public:
|
2014-10-31 20:19:06 +03:00
|
|
|
static nsresult GetAll(uint32_t aCameraId,
|
|
|
|
nsTArray<nsRefPtr<ICameraControl::RecorderProfile>>& aProfiles);
|
|
|
|
|
|
|
|
// Configures the specified recorder using the specified profile.
|
|
|
|
//
|
|
|
|
// Return values:
|
|
|
|
// - NS_OK on success;
|
|
|
|
// - NS_ERROR_INVALID_ARG if the profile isn't supported;
|
|
|
|
// - NS_ERROR_NOT_AVAILABLE if the recorder rejected the profile.
|
|
|
|
static nsresult ConfigureRecorder(android::GonkRecorder& aRecorder,
|
|
|
|
uint32_t aCameraId,
|
|
|
|
const nsAString& aProfileName);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
GonkRecorderProfile(uint32_t aCameraId,
|
2014-12-03 02:14:17 +03:00
|
|
|
int aQuality);
|
2012-10-24 02:30:28 +04:00
|
|
|
|
2014-10-31 20:19:06 +03:00
|
|
|
int GetProfileParameter(const char* aParameter);
|
2012-10-24 02:30:28 +04:00
|
|
|
|
2014-10-31 20:19:06 +03:00
|
|
|
bool Translate(android::output_format aContainer, nsAString& aContainerName);
|
|
|
|
bool GetMimeType(android::output_format aContainer, nsAString& aMimeType);
|
|
|
|
bool IsValid() const { return mIsValid; };
|
2012-10-24 02:30:28 +04:00
|
|
|
|
2014-10-31 20:19:06 +03:00
|
|
|
nsresult ConfigureRecorder(android::GonkRecorder& aRecorder);
|
2014-12-03 02:14:17 +03:00
|
|
|
static already_AddRefed<GonkRecorderProfile> CreateProfile(uint32_t aCameraId,
|
|
|
|
int aQuality);
|
2014-10-31 20:19:06 +03:00
|
|
|
static ProfileHashtable* GetProfileHashtable(uint32_t aCameraId);
|
|
|
|
static PLDHashOperator Enumerate(const nsAString& aProfileName,
|
|
|
|
GonkRecorderProfile* aProfile,
|
|
|
|
void* aUserArg);
|
2012-10-24 02:30:28 +04:00
|
|
|
|
2014-10-31 20:19:06 +03:00
|
|
|
uint32_t mCameraId;
|
2014-12-03 02:14:17 +03:00
|
|
|
int mQuality;
|
2014-10-31 20:19:06 +03:00
|
|
|
bool mIsValid;
|
|
|
|
android::output_format mOutputFormat;
|
2012-10-24 02:30:28 +04:00
|
|
|
|
2014-10-31 20:19:06 +03:00
|
|
|
static nsClassHashtable<nsUint32HashKey, ProfileHashtable> sProfiles;
|
2012-10-24 02:30:28 +04:00
|
|
|
|
2014-10-31 20:19:06 +03:00
|
|
|
private:
|
|
|
|
DISALLOW_EVIL_CONSTRUCTORS(GonkRecorderProfile);
|
2012-10-24 02:30:28 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
}; // namespace mozilla
|
|
|
|
|
|
|
|
#endif // DOM_CAMERA_GONK_RECORDER_PROFILES_H
|