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
234
235
236
237
|
/* 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 CODEC_CONFIG_H_
#define CODEC_CONFIG_H_
#include <string>
#include <vector>
#include "common/EncodingConstraints.h"
namespace mozilla {
/**
* Minimalistic Audio Codec Config Params
*/
struct AudioCodecConfig {
/*
* The data-types for these properties mimic the
* corresponding webrtc::CodecInst data-types.
*/
int mType;
std::string mName;
int mFreq;
int mChannels;
bool mFECEnabled;
bool mDtmfEnabled;
uint32_t mFrameSizeMs;
uint32_t mMaxFrameSizeMs;
uint32_t mMinFrameSizeMs;
// OPUS-specific
bool mDTXEnabled;
uint32_t mMaxAverageBitrate;
int mMaxPlaybackRate;
bool mCbrEnabled;
AudioCodecConfig(int type, std::string name, int freq, int channels,
bool FECEnabled)
: mType(type),
mName(name),
mFreq(freq),
mChannels(channels),
mFECEnabled(FECEnabled),
mDtmfEnabled(false),
mFrameSizeMs(0),
mMaxFrameSizeMs(0),
mMinFrameSizeMs(0),
mDTXEnabled(false),
mMaxAverageBitrate(0),
mMaxPlaybackRate(0),
mCbrEnabled(false) {}
bool operator==(const AudioCodecConfig& aOther) const {
return mType == aOther.mType && mName == aOther.mName &&
mFreq == aOther.mFreq && mChannels == aOther.mChannels &&
mFECEnabled == aOther.mFECEnabled &&
mDtmfEnabled == aOther.mDtmfEnabled &&
mFrameSizeMs == aOther.mFrameSizeMs &&
mMaxFrameSizeMs == aOther.mMaxFrameSizeMs &&
mMinFrameSizeMs == aOther.mMinFrameSizeMs &&
mDTXEnabled == aOther.mDTXEnabled &&
mMaxAverageBitrate == aOther.mMaxAverageBitrate &&
mMaxPlaybackRate == aOther.mMaxPlaybackRate &&
mCbrEnabled == aOther.mCbrEnabled;
}
};
/*
* Minimalistic video codec configuration
* More to be added later depending on the use-case
*/
#define MAX_SPROP_LEN 128
// used for holding SDP negotiation results
struct VideoCodecConfigH264 {
char sprop_parameter_sets[MAX_SPROP_LEN];
int packetization_mode;
int profile_level_id;
int tias_bw;
bool operator==(const VideoCodecConfigH264& aOther) const {
return strncmp(sprop_parameter_sets, aOther.sprop_parameter_sets,
MAX_SPROP_LEN) == 0 &&
packetization_mode == aOther.packetization_mode &&
profile_level_id == aOther.profile_level_id &&
tias_bw == aOther.tias_bw;
}
};
// class so the std::strings can get freed more easily/reliably
class VideoCodecConfig {
public:
/*
* The data-types for these properties mimic the
* corresponding webrtc::VideoCodec data-types.
*/
int mType; // payload type
std::string mName;
std::vector<std::string> mAckFbTypes;
std::vector<std::string> mNackFbTypes;
std::vector<std::string> mCcmFbTypes;
// Don't pass mOtherFbTypes from JsepVideoCodecDescription because we'd have
// to drag SdpRtcpFbAttributeList::Feedback along too.
bool mRembFbSet;
bool mFECFbSet;
bool mTransportCCFbSet;
int mULPFECPayloadType;
int mREDPayloadType;
int mREDRTXPayloadType;
int mRTXPayloadType;
uint32_t mTias;
EncodingConstraints mEncodingConstraints;
struct Encoding {
std::string rid;
EncodingConstraints constraints;
bool active = true;
// TODO(bug 1744116): Use = default here
bool operator==(const Encoding& aOther) const {
return rid == aOther.rid && constraints == aOther.constraints &&
active == aOther.active;
}
};
std::vector<Encoding> mEncodings;
std::string mSpropParameterSets;
uint8_t mProfile;
uint8_t mConstraints;
uint8_t mLevel;
uint8_t mPacketizationMode;
// TODO: add external negotiated SPS/PPS
// TODO(bug 1744116): Use = default here
bool operator==(const VideoCodecConfig& aRhs) const {
return mType == aRhs.mType && mName == aRhs.mName &&
mAckFbTypes == aRhs.mAckFbTypes &&
mNackFbTypes == aRhs.mNackFbTypes &&
mCcmFbTypes == aRhs.mCcmFbTypes && mRembFbSet == aRhs.mRembFbSet &&
mFECFbSet == aRhs.mFECFbSet &&
mTransportCCFbSet == aRhs.mTransportCCFbSet &&
mULPFECPayloadType == aRhs.mULPFECPayloadType &&
mREDPayloadType == aRhs.mREDPayloadType &&
mREDRTXPayloadType == aRhs.mREDRTXPayloadType &&
mRTXPayloadType == aRhs.mRTXPayloadType && mTias == aRhs.mTias &&
mEncodingConstraints == aRhs.mEncodingConstraints &&
mEncodings == aRhs.mEncodings &&
mSpropParameterSets == aRhs.mSpropParameterSets &&
mProfile == aRhs.mProfile && mConstraints == aRhs.mConstraints &&
mLevel == aRhs.mLevel &&
mPacketizationMode == aRhs.mPacketizationMode;
}
VideoCodecConfig(int type, std::string name,
const EncodingConstraints& constraints,
const struct VideoCodecConfigH264* h264 = nullptr)
: mType(type),
mName(name),
mRembFbSet(false),
mFECFbSet(false),
mTransportCCFbSet(false),
mULPFECPayloadType(-1),
mREDPayloadType(-1),
mREDRTXPayloadType(-1),
mRTXPayloadType(-1),
mTias(0),
mEncodingConstraints(constraints),
mProfile(0x42),
mConstraints(0xE0),
mLevel(0x0C),
mPacketizationMode(1) {
if (h264) {
mProfile = (h264->profile_level_id & 0x00FF0000) >> 16;
mConstraints = (h264->profile_level_id & 0x0000FF00) >> 8;
mLevel = (h264->profile_level_id & 0x000000FF);
mPacketizationMode = h264->packetization_mode;
mSpropParameterSets = h264->sprop_parameter_sets;
}
}
bool ResolutionEquals(const VideoCodecConfig& aConfig) const {
if (mEncodings.size() != aConfig.mEncodings.size()) {
return false;
}
for (size_t i = 0; i < mEncodings.size(); ++i) {
if (!mEncodings[i].constraints.ResolutionEquals(
aConfig.mEncodings[i].constraints)) {
return false;
}
}
return true;
}
// Nothing seems to use this right now. Do we intend to support this
// someday?
bool RtcpFbAckIsSet(const std::string& type) const {
for (auto i = mAckFbTypes.begin(); i != mAckFbTypes.end(); ++i) {
if (*i == type) {
return true;
}
}
return false;
}
bool RtcpFbNackIsSet(const std::string& type) const {
for (auto i = mNackFbTypes.begin(); i != mNackFbTypes.end(); ++i) {
if (*i == type) {
return true;
}
}
return false;
}
bool RtcpFbCcmIsSet(const std::string& type) const {
for (auto i = mCcmFbTypes.begin(); i != mCcmFbTypes.end(); ++i) {
if (*i == type) {
return true;
}
}
return false;
}
bool RtcpFbRembIsSet() const { return mRembFbSet; }
bool RtcpFbFECIsSet() const { return mFECFbSet; }
bool RtcpFbTransportCCIsSet() const { return mTransportCCFbSet; }
bool RtxPayloadTypeIsSet() const { return mRTXPayloadType != -1; }
};
} // namespace mozilla
#endif
|