Line data Source code
1 :
2 : /* This Source Code Form is subject to the terms of the Mozilla Public
3 : * License, v. 2.0. If a copy of the MPL was not distributed with this file,
4 : * You can obtain one at http://mozilla.org/MPL/2.0/. */
5 :
6 : #ifndef CODEC_CONFIG_H_
7 : #define CODEC_CONFIG_H_
8 :
9 : #include <string>
10 : #include <vector>
11 :
12 : #include "signaling/src/common/EncodingConstraints.h"
13 :
14 : namespace mozilla {
15 :
16 : /**
17 : * Minimalistic Audio Codec Config Params
18 : */
19 0 : struct AudioCodecConfig
20 : {
21 : /*
22 : * The data-types for these properties mimic the
23 : * corresponding webrtc::CodecInst data-types.
24 : */
25 : int mType;
26 : std::string mName;
27 : int mFreq;
28 : int mPacSize;
29 : int mChannels;
30 : int mRate;
31 :
32 : bool mFECEnabled;
33 : bool mDtmfEnabled;
34 :
35 : // OPUS-specific
36 : int mMaxPlaybackRate;
37 :
38 : /* Default constructor is not provided since as a consumer, we
39 : * can't decide the default configuration for the codec
40 : */
41 0 : explicit AudioCodecConfig(int type, std::string name,
42 : int freq, int pacSize,
43 : int channels, int rate, bool FECEnabled)
44 0 : : mType(type),
45 : mName(name),
46 : mFreq(freq),
47 : mPacSize(pacSize),
48 : mChannels(channels),
49 : mRate(rate),
50 : mFECEnabled(FECEnabled),
51 : mDtmfEnabled(false),
52 0 : mMaxPlaybackRate(0)
53 : {
54 0 : }
55 : };
56 :
57 : /*
58 : * Minimalistic video codec configuration
59 : * More to be added later depending on the use-case
60 : */
61 :
62 : #define MAX_SPROP_LEN 128
63 :
64 : // used for holding SDP negotiation results
65 : struct VideoCodecConfigH264
66 : {
67 : char sprop_parameter_sets[MAX_SPROP_LEN];
68 : int packetization_mode;
69 : int profile_level_id;
70 : int tias_bw;
71 : };
72 :
73 :
74 : // class so the std::strings can get freed more easily/reliably
75 0 : class VideoCodecConfig
76 : {
77 : public:
78 : /*
79 : * The data-types for these properties mimic the
80 : * corresponding webrtc::VideoCodec data-types.
81 : */
82 : int mType; // payload type
83 : std::string mName;
84 :
85 : std::vector<std::string> mAckFbTypes;
86 : std::vector<std::string> mNackFbTypes;
87 : std::vector<std::string> mCcmFbTypes;
88 : // Don't pass mOtherFbTypes from JsepVideoCodecDescription because we'd have
89 : // to drag SdpRtcpFbAttributeList::Feedback along too.
90 : bool mRembFbSet;
91 : bool mFECFbSet;
92 :
93 : int mULPFECPayloadType;
94 : int mREDPayloadType;
95 : int mREDRTXPayloadType;
96 :
97 : uint32_t mTias;
98 : EncodingConstraints mEncodingConstraints;
99 0 : struct SimulcastEncoding {
100 : std::string rid;
101 : EncodingConstraints constraints;
102 0 : bool operator==(const SimulcastEncoding& aOther) const {
103 0 : return rid == aOther.rid &&
104 0 : constraints == aOther.constraints;
105 : }
106 : };
107 : std::vector<SimulcastEncoding> mSimulcastEncodings;
108 : std::string mSpropParameterSets;
109 : uint8_t mProfile;
110 : uint8_t mConstraints;
111 : uint8_t mLevel;
112 : uint8_t mPacketizationMode;
113 : // TODO: add external negotiated SPS/PPS
114 :
115 0 : bool operator==(const VideoCodecConfig& aRhs) const {
116 0 : if (mType != aRhs.mType ||
117 0 : mName != aRhs.mName ||
118 0 : mAckFbTypes != aRhs.mAckFbTypes ||
119 0 : mNackFbTypes != aRhs.mNackFbTypes ||
120 0 : mCcmFbTypes != aRhs.mCcmFbTypes ||
121 0 : mRembFbSet != aRhs.mRembFbSet ||
122 0 : mFECFbSet != aRhs.mFECFbSet ||
123 0 : mULPFECPayloadType != aRhs.mULPFECPayloadType ||
124 0 : mREDPayloadType != aRhs.mREDPayloadType ||
125 0 : mREDRTXPayloadType != aRhs.mREDRTXPayloadType ||
126 0 : mTias != aRhs.mTias ||
127 0 : !(mEncodingConstraints == aRhs.mEncodingConstraints) ||
128 0 : !(mSimulcastEncodings == aRhs.mSimulcastEncodings) ||
129 0 : mSpropParameterSets != aRhs.mSpropParameterSets ||
130 0 : mProfile != aRhs.mProfile ||
131 0 : mConstraints != aRhs.mConstraints ||
132 0 : mLevel != aRhs.mLevel ||
133 0 : mPacketizationMode != aRhs.mPacketizationMode) {
134 0 : return false;
135 : }
136 :
137 0 : return true;
138 : }
139 :
140 0 : VideoCodecConfig(int type,
141 : std::string name,
142 : const EncodingConstraints& constraints,
143 0 : const struct VideoCodecConfigH264 *h264 = nullptr) :
144 : mType(type),
145 : mName(name),
146 : mFECFbSet(false),
147 : mULPFECPayloadType(123),
148 : mREDPayloadType(122),
149 : mREDRTXPayloadType(-1),
150 : mTias(0),
151 : mEncodingConstraints(constraints),
152 : mProfile(0x42),
153 : mConstraints(0xE0),
154 : mLevel(0x0C),
155 0 : mPacketizationMode(1)
156 : {
157 0 : if (h264) {
158 0 : mProfile = (h264->profile_level_id & 0x00FF0000) >> 16;
159 0 : mConstraints = (h264->profile_level_id & 0x0000FF00) >> 8;
160 0 : mLevel = (h264->profile_level_id & 0x000000FF);
161 0 : mPacketizationMode = h264->packetization_mode;
162 0 : mSpropParameterSets = h264->sprop_parameter_sets;
163 : }
164 0 : }
165 :
166 0 : bool ResolutionEquals(const VideoCodecConfig& aConfig) const
167 : {
168 0 : if (mSimulcastEncodings.size() != aConfig.mSimulcastEncodings.size()) {
169 0 : return false;
170 : }
171 0 : for (size_t i = 0; i < mSimulcastEncodings.size(); ++i) {
172 0 : if (!mSimulcastEncodings[i].constraints.ResolutionEquals(
173 0 : aConfig.mSimulcastEncodings[i].constraints)) {
174 0 : return false;
175 : }
176 : }
177 0 : return true;
178 : }
179 :
180 : // Nothing seems to use this right now. Do we intend to support this
181 : // someday?
182 : bool RtcpFbAckIsSet(const std::string& type) const
183 : {
184 : for (auto i = mAckFbTypes.begin(); i != mAckFbTypes.end(); ++i) {
185 : if (*i == type) {
186 : return true;
187 : }
188 : }
189 : return false;
190 : }
191 :
192 0 : bool RtcpFbNackIsSet(const std::string& type) const
193 : {
194 0 : for (auto i = mNackFbTypes.begin(); i != mNackFbTypes.end(); ++i) {
195 0 : if (*i == type) {
196 0 : return true;
197 : }
198 : }
199 0 : return false;
200 : }
201 :
202 0 : bool RtcpFbCcmIsSet(const std::string& type) const
203 : {
204 0 : for (auto i = mCcmFbTypes.begin(); i != mCcmFbTypes.end(); ++i) {
205 0 : if (*i == type) {
206 0 : return true;
207 : }
208 : }
209 0 : return false;
210 : }
211 :
212 0 : bool RtcpFbRembIsSet() const { return mRembFbSet; }
213 :
214 0 : bool RtcpFbFECIsSet() const { return mFECFbSet; }
215 :
216 : };
217 : }
218 : #endif
|