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