-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathrtc_rtp_parameters.dart
226 lines (191 loc) · 6.41 KB
/
rtc_rtp_parameters.dart
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
import 'enums.dart';
import 'rtc_rtcp_parameters.dart';
class RTCRTPCodec {
RTCRTPCodec(
{this.payloadType,
this.name,
this.kind,
this.clockRate,
this.numChannels,
this.parameters});
factory RTCRTPCodec.fromMap(Map<dynamic, dynamic> map) {
return RTCRTPCodec(
payloadType: map['payloadType'],
name: map['name'],
kind: map['kind'],
clockRate: map['clockRate'],
numChannels: map['numChannels'] ?? 1,
parameters: map['parameters']);
}
// Payload type used to identify this codec in RTP packets.
int? payloadType;
/// Name used to identify the codec. Equivalent to MIME subtype.
String? name;
/// The media type of this codec. Equivalent to MIME top-level type.
String? kind;
/// Clock rate in Hertz.
int? clockRate;
/// The number of audio channels used. Set to null for video codecs.
int? numChannels;
/// The "format specific parameters" field from the "a=fmtp" line in the SDP
Map<dynamic, dynamic>? parameters;
Map<String, dynamic> toMap() {
return {
'payloadType': payloadType,
'name': name,
'kind': kind,
'clockRate': clockRate,
'numChannels': numChannels,
'parameters': parameters,
};
}
}
class RTCRtpEncoding {
RTCRtpEncoding({
this.rid,
this.active = true,
this.maxBitrate,
this.maxFramerate,
this.minBitrate,
this.numTemporalLayers = 1,
this.scaleResolutionDownBy = 1.0,
this.ssrc,
this.scalabilityMode,
});
factory RTCRtpEncoding.fromMap(Map<dynamic, dynamic> map) => RTCRtpEncoding(
rid: map['rid'],
active: map['active'],
maxBitrate: map['maxBitrate'],
maxFramerate: map['maxFramerate'],
minBitrate: map['minBitrate'],
numTemporalLayers: map['numTemporalLayers'],
scaleResolutionDownBy: map['scaleResolutionDownBy'],
ssrc: map['ssrc'],
scalabilityMode: map['scalabilityMode'],
);
/// If non-null, this represents the RID that identifies this encoding layer.
/// RIDs are used to identify layers in simulcast.
String? rid;
/// Set to true to cause this encoding to be sent, and false for it not to
/// be sent.
bool active;
/// If non-null, this represents the Transport Independent Application
/// Specific maximum bandwidth defined in RFC3890. If null, there is no
/// maximum bitrate.
int? maxBitrate;
/// The minimum bitrate in bps for video.
int? minBitrate;
/// The max framerate in fps for video.
int? maxFramerate;
/// The number of temporal layers for video.
int? numTemporalLayers;
/// If non-null, scale the width and height down by this factor for video. If null,
/// implementation default scaling factor will be used.
double? scaleResolutionDownBy;
/// SSRC to be used by this encoding.
/// Can't be changed between getParameters/setParameters.
int? ssrc;
String? scalabilityMode;
Map<String, dynamic> toMap() => {
'active': active,
if (rid != null) 'rid': rid,
if (maxBitrate != null) 'maxBitrate': maxBitrate,
if (maxFramerate != null) 'maxFramerate': maxFramerate,
if (minBitrate != null) 'minBitrate': minBitrate,
if (numTemporalLayers != null) 'numTemporalLayers': numTemporalLayers,
if (scaleResolutionDownBy != null)
'scaleResolutionDownBy': scaleResolutionDownBy,
if (scalabilityMode != null) 'scalabilityMode': scalabilityMode,
if (ssrc != null) 'ssrc': ssrc,
};
}
class RTCHeaderExtension {
RTCHeaderExtension({this.uri, this.id, this.encrypted});
factory RTCHeaderExtension.fromMap(Map<dynamic, dynamic> map) {
return RTCHeaderExtension(
uri: map['uri'], id: map['id'], encrypted: map['encrypted']);
}
/// The URI of the RTP header extension, as defined in RFC5285.
String? uri;
/// The value put in the RTP packet to identify the header extension.
int? id;
/// Whether the header extension is encrypted or not.
bool? encrypted;
Map<String, dynamic> toMap() {
return {
'uri': uri,
'id': id,
'encrypted': encrypted,
};
}
}
class RTCRtpParameters {
RTCRtpParameters({
this.transactionId,
this.rtcp,
this.headerExtensions,
this.encodings,
this.codecs,
this.degradationPreference,
});
factory RTCRtpParameters.fromMap(Map<dynamic, dynamic> map) {
var encodings = <RTCRtpEncoding>[];
dynamic encodingsMap = map['encodings'];
encodingsMap.forEach((params) {
encodings.add(RTCRtpEncoding.fromMap(params));
});
var headerExtensions = <RTCHeaderExtension>[];
dynamic headerExtensionsMap = map['headerExtensions'];
headerExtensionsMap.forEach((params) {
headerExtensions.add(RTCHeaderExtension.fromMap(params));
});
var codecs = <RTCRTPCodec>[];
dynamic codecsMap = map['codecs'];
codecsMap.forEach((params) {
codecs.add(RTCRTPCodec.fromMap(params));
});
var degradationPreference = map['degradationPreference'];
var rtcp = RTCRTCPParameters.fromMap(map['rtcp']);
return RTCRtpParameters(
transactionId: map['transactionId'],
rtcp: rtcp,
headerExtensions: headerExtensions,
encodings: encodings,
degradationPreference:
degradationPreferenceforString(degradationPreference),
codecs: codecs);
}
String? transactionId;
RTCRTCPParameters? rtcp;
List<RTCHeaderExtension>? headerExtensions;
List<RTCRtpEncoding>? encodings;
RTCDegradationPreference? degradationPreference;
/// Codec parameters can't currently be changed between getParameters and
/// setParameters. Though in the future it will be possible to reorder them or
/// remove them.
List<RTCRTPCodec>? codecs;
Map<String, dynamic> toMap() {
var headerExtensionsList = <dynamic>[];
headerExtensions?.forEach((params) {
headerExtensionsList.add(params.toMap());
});
var encodingList = <dynamic>[];
encodings?.forEach((params) {
encodingList.add(params.toMap());
});
var codecsList = <dynamic>[];
codecs?.forEach((params) {
codecsList.add(params.toMap());
});
return {
'transactionId': transactionId,
if (rtcp != null) 'rtcp': rtcp!.toMap(),
'headerExtensions': headerExtensionsList,
'encodings': encodingList,
'codecs': codecsList,
if (degradationPreference != null)
'degradationPreference':
typeRTCDegradationPreferenceString[degradationPreference!],
};
}
}