forked from Floorp-Projects/Floorp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGonkRecorderProfiles.h
153 lines (124 loc) · 4.43 KB
/
GonkRecorderProfiles.h
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
/* 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>
#include "ICameraControl.h"
#include "nsClassHashtable.h"
#include "nsRefPtrHashtable.h"
#ifndef CHECK_SETARG_RETURN
#define CHECK_SETARG_RETURN(x, rv) \
do { \
if (x) { \
DOM_CAMERA_LOGE(#x " failed\n"); \
return rv; \
} \
} while(0)
#endif
#ifndef CHECK_SETARG
#define CHECK_SETARG(x) CHECK_SETARG_RETURN(x, NS_ERROR_NOT_AVAILABLE)
#endif
namespace android {
class GonkRecorder;
};
namespace mozilla {
/**
* class GonkRecorderProfileBase
*/
template<class A, class V>
class GonkRecorderProfileBase : public ICameraControl::RecorderProfile
{
public:
GonkRecorderProfileBase(uint32_t aCameraId, int aQuality)
: RecorderProfile()
, mAudio(aCameraId, aQuality)
, mVideo(aCameraId, aQuality)
{ }
virtual const Audio& GetAudio() const MOZ_OVERRIDE { return mAudio; }
virtual const Video& GetVideo() const MOZ_OVERRIDE { return mVideo; }
protected:
virtual ~GonkRecorderProfileBase() { }
A mAudio;
V mVideo;
};
/**
* class GonkRecorderVideo
*/
class GonkRecorderVideo : public ICameraControl::RecorderProfile::Video
{
public:
GonkRecorderVideo(uint32_t aCameraId, int aQuality);
virtual ~GonkRecorderVideo() { }
android::video_encoder GetPlatformEncoder() const { return mPlatformEncoder; }
bool IsValid() const { return mIsValid; }
protected:
int GetProfileParameter(const char* aParameter);
static bool Translate(android::video_encoder aCodec, nsAString& aCodecName);
uint32_t mCameraId;
int mQuality;
bool mIsValid;
android::video_encoder mPlatformEncoder;
};
/**
* class GonkRecorderAudio
*/
class GonkRecorderAudio : public ICameraControl::RecorderProfile::Audio
{
public:
GonkRecorderAudio(uint32_t aCameraId, int aQuality);
virtual ~GonkRecorderAudio() { }
android::audio_encoder GetPlatformEncoder() const { return mPlatformEncoder; }
bool IsValid() const { return mIsValid; }
protected:
int GetProfileParameter(const char* aParameter);
static bool Translate(android::audio_encoder aCodec, nsAString& aCodecName);
uint32_t mCameraId;
int mQuality;
bool mIsValid;
android::audio_encoder mPlatformEncoder;
};
/**
* class GonkRecorderProfile
*/
class GonkRecorderProfile;
typedef nsRefPtrHashtable<nsStringHashKey, GonkRecorderProfile> ProfileHashtable;
class GonkRecorderProfile
: public GonkRecorderProfileBase<GonkRecorderAudio, GonkRecorderVideo>
{
public:
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,
int aQuality);
int GetProfileParameter(const char* aParameter);
bool Translate(android::output_format aContainer, nsAString& aContainerName);
bool GetMimeType(android::output_format aContainer, nsAString& aMimeType);
bool IsValid() const { return mIsValid; };
nsresult ConfigureRecorder(android::GonkRecorder& aRecorder);
static already_AddRefed<GonkRecorderProfile> CreateProfile(uint32_t aCameraId,
int aQuality);
static ProfileHashtable* GetProfileHashtable(uint32_t aCameraId);
static PLDHashOperator Enumerate(const nsAString& aProfileName,
GonkRecorderProfile* aProfile,
void* aUserArg);
uint32_t mCameraId;
int mQuality;
bool mIsValid;
android::output_format mOutputFormat;
static nsClassHashtable<nsUint32HashKey, ProfileHashtable> sProfiles;
private:
DISALLOW_EVIL_CONSTRUCTORS(GonkRecorderProfile);
};
}; // namespace mozilla
#endif // DOM_CAMERA_GONK_RECORDER_PROFILES_H