forked from jiyeyuran/mediasoup-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrtp_parameters.go
404 lines (352 loc) · 12.1 KB
/
rtp_parameters.go
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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
package mediasoup
import (
"strings"
"github.com/jiyeyuran/mediasoup-go/h264"
)
/**
* The RTP capabilities define what mediasoup or an endpoint can receive at
* media level.
*/
type RtpCapabilities struct {
/**
* Supported media and RTX codecs.
*/
Codecs []*RtpCodecCapability `json:"codecs,omitempty"`
/**
* Supported RTP header extensions.
*/
HeaderExtensions []*RtpHeaderExtension `json:"headerExtensions,omitempty"`
/**
* Supported FEC mechanisms.
*/
FecMechanisms []string `json:"fecMechanisms,omitempty"`
}
/**
* Media kind ('audio' or 'video').
*/
type MediaKind string
const (
MediaKind_Audio MediaKind = "audio"
MediaKind_Video MediaKind = "video"
)
/**
* Provides information on the capabilities of a codec within the RTP
* capabilities. The list of media codecs supported by mediasoup and their
* settings is defined in the supportedRtpCapabilities.ts file.
*
* Exactly one RtpCodecCapability will be present for each supported combination
* of parameters that requires a distinct value of preferredPayloadType. For
* example
*
* - Multiple H264 codecs, each with their own distinct 'packetization-mode' and
* 'profile-level-id' values.
* - Multiple VP9 codecs, each with their own distinct 'profile-id' value.
*
* RtpCodecCapability entries in the mediaCodecs array of RouterOptions do not
* require preferredPayloadType field (if unset, mediasoup will choose a random
* one). If given, make sure it's in the 96-127 range.
*/
type RtpCodecCapability struct {
/**
* Media kind.
*/
Kind MediaKind `json:"kind"`
/**
* The codec MIME media type/subtype (e.g. 'audio/opus', 'video/VP8').
*/
MimeType string `json:"mimeType"`
/**
* The preferred RTP payload type.
*/
PreferredPayloadType byte `json:"preferredPayloadType,omitempty"`
/**
* Codec clock rate expressed in Hertz.
*/
ClockRate int `json:"clockRate"`
/**
* The int of channels supported (e.g. two for stereo). Just for audio.
* Default 1.
*/
Channels int `json:"channels,omitempty"`
/**
* Codec specific parameters. Some parameters (such as 'packetization-mode'
* and 'profile-level-id' in H264 or 'profile-id' in VP9) are critical for
* codec matching.
*/
Parameters RtpCodecSpecificParameters `json:"parameters,omitempty"`
/**
* Transport layer and codec-specific feedback messages for this codec.
*/
RtcpFeedback []RtcpFeedback `json:"rtcpFeedback,omitempty"`
}
func (r RtpCodecCapability) isRtxCodec() bool {
return strings.HasSuffix(strings.ToLower(r.MimeType), "/rtx")
}
/**
* Direction of RTP header extension.
*/
type RtpHeaderExtensionDirection string
const (
Direction_Sendrecv RtpHeaderExtensionDirection = "sendrecv"
Direction_Sendonly RtpHeaderExtensionDirection = "sendonly"
Direction_Recvonly RtpHeaderExtensionDirection = "recvonly"
Direction_Inactive RtpHeaderExtensionDirection = "inactive"
)
/**
* Provides information relating to supported header extensions. The list of
* RTP header extensions supported by mediasoup is defined in the
* supportedRtpCapabilities.ts file.
*
* mediasoup does not currently support encrypted RTP header extensions. The
* direction field is just present in mediasoup RTP capabilities (retrieved via
* router.rtpCapabilities or mediasoup.getSupportedRtpCapabilities()). It's
* ignored if present in endpoints' RTP capabilities.
*/
type RtpHeaderExtension struct {
/**
* Media kind. If empty string, it's valid for all kinds.
* Default any media kind.
*/
Kind MediaKind `json:"kind"`
/*
* The URI of the RTP header extension, as defined in RFC 5285.
*/
Uri string `json:"uri"`
/**
* The preferred numeric identifier that goes in the RTP packet. Must be
* unique.
*/
PreferredId int `json:"preferredId"`
/**
* If true, it is preferred that the value in the header be encrypted as per
* RFC 6904. Default false.
*/
PreferredEncrypt bool `json:"preferredEncrypt,omitempty"`
/**
* If 'sendrecv', mediasoup supports sending and receiving this RTP extension.
* 'sendonly' means that mediasoup can send (but not receive) it. 'recvonly'
* means that mediasoup can receive (but not send) it.
*/
Direction RtpHeaderExtensionDirection `json:"direction,omitempty"`
}
/**
* The RTP send parameters describe a media stream received by mediasoup from
* an endpoint through its corresponding mediasoup Producer. These parameters
* may include a mid value that the mediasoup transport will use to match
* received RTP packets based on their MID RTP extension value.
*
* mediasoup allows RTP send parameters with a single encoding and with multiple
* encodings (simulcast). In the latter case, each entry in the encodings array
* must include a ssrc field or a rid field (the RID RTP extension value). Check
* the Simulcast and SVC sections for more information.
*
* The RTP receive parameters describe a media stream as sent by mediasoup to
* an endpoint through its corresponding mediasoup Consumer. The mid value is
* unset (mediasoup does not include the MID RTP extension into RTP packets
* being sent to endpoints).
*
* There is a single entry in the encodings array (even if the corresponding
* producer uses simulcast). The consumer sends a single and continuous RTP
* stream to the endpoint and spatial/temporal layer selection is possible via
* consumer.setPreferredLayers().
*
* As an exception, previous bullet is not true when consuming a stream over a
* PipeTransport, in which all RTP streams from the associated producer are
* forwarded verbatim through the consumer.
*
* The RTP receive parameters will always have their ssrc values randomly
* generated for all of its encodings (and optional rtx { ssrc XXXX } if the
* endpoint supports RTX), regardless of the original RTP send parameters in
* the associated producer. This applies even if the producer's encodings have
* rid set.
*/
type RtpParameters struct {
/**
* The MID RTP extension value as defined in the BUNDLE specification.
*/
Mid string `json:"mid,omitempty"`
/**
* Media and RTX codecs in use.
*/
Codecs []*RtpCodecParameters `json:"codecs"`
/**
* RTP header extensions in use.
*/
HeaderExtensions []RtpHeaderExtensionParameters `json:"headerExtensions,omitempty"`
/**
* Transmitted RTP streams and their settings.
*/
Encodings []RtpEncodingParameters `json:"encodings,omitempty"`
/**
* Parameters used for RTCP.
*/
Rtcp RtcpParameters `json:"rtcp,omitempty"`
}
/**
* Provides information on codec settings within the RTP parameters. The list
* of media codecs supported by mediasoup and their settings is defined in the
* supportedRtpCapabilities.ts file.
*/
type RtpCodecParameters struct {
/**
* The codec MIME media type/subtype (e.g. 'audio/opus', 'video/VP8').
*/
MimeType string `json:"mimeType"`
/**
* The value that goes in the RTP Payload Type Field. Must be unique.
*/
PayloadType byte `json:"payloadType"`
/**
* Codec clock rate expressed in Hertz.
*/
ClockRate int `json:"clockRate"`
/**
* The int of channels supported (e.g. two for stereo). Just for audio.
* Default 1.
*/
Channels int `json:"channels,omitempty"`
/**
* Codec-specific parameters available for signaling. Some parameters (such
* as 'packetization-mode' and 'profile-level-id' in H264 or 'profile-id' in
* VP9) are critical for codec matching.
*/
Parameters RtpCodecSpecificParameters `json:"parameters,omitempty"`
/**
* Transport layer and codec-specific feedback messages for this codec.
*/
RtcpFeedback []RtcpFeedback `json:"rtcpFeedback,omitempty"`
}
func (r RtpCodecParameters) isRtxCodec() bool {
return strings.HasSuffix(strings.ToLower(r.MimeType), "/rtx")
}
/**
* RtpCodecSpecificParameters the Codec-specific parameters available for signaling. Some parameters (such
* as 'packetization-mode' and 'profile-level-id' in H264 or 'profile-id' in
* VP9) are critical for codec matching.
*/
type RtpCodecSpecificParameters struct {
h264.RtpParameter // used by h264 codec
ProfileId string `json:"profile-id,omitempty"` // used by vp9
Apt byte `json:"apt,omitempty"` // used by rtx codec
SpropStereo uint8 `json:"sprop-stereo,omitempty"` // used by audio, 1 or 0
Useinbandfec uint8 `json:"useinbandfec,omitempty"` // used by audio, 1 or 0
Usedtx uint8 `json:"usedtx,omitempty"` // used by audio, 1 or 0
Maxplaybackrate uint32 `json:"maxplaybackrate,omitempty"`
XGoogleMinBitrate uint32 `json:"x-google-min-bitrate,omitempty"`
XGoogleMaxBitrate uint32 `json:"x-google-max-bitrate,omitempty"`
XGoogleStartBitrate uint32 `json:"x-google-start-bitrate,omitempty"`
ChannelMapping string `json:"channel_mapping,omitempty"`
NumStreams uint8 `json:"num_streams,omitempty"`
CoupledStreams uint8 `json:"coupled_streams,omitempty"`
}
/**
* Provides information on RTCP feedback messages for a specific codec. Those
* messages can be transport layer feedback messages or codec-specific feedback
* messages. The list of RTCP feedbacks supported by mediasoup is defined in the
* supportedRtpCapabilities.ts file.
*/
type RtcpFeedback struct {
/**
* RTCP feedback type.
*/
Type string `json:"type"`
/**
* RTCP feedback parameter.
*/
Parameter string `json:"parameter,omitempty"`
}
/**
* Provides information relating to an encoding, which represents a media RTP
* stream and its associated RTX stream (if any).
*/
type RtpEncodingParameters struct {
/**
* The media SSRC.
*/
Ssrc uint32 `json:"ssrc,omitempty"`
/**
* The RID RTP extension value. Must be unique.
*/
Rid string `json:"rid,omitempty"`
/**
* Codec payload type this encoding affects. If unset, first media codec is
* chosen.
*/
CodecPayloadType byte `json:"codecPayloadType,omitempty"`
/**
* RTX stream information. It must contain a numeric ssrc field indicating
* the RTX SSRC.
*/
Rtx *RtpEncodingRtx `json:"rtx,omitempty"`
/**
* It indicates whether discontinuous RTP transmission will be used. Useful
* for audio (if the codec supports it) and for video screen sharing (when
* static content is being transmitted, this option disables the RTP
* inactivity checks in mediasoup). Default false.
*/
Dtx bool `json:"dtx,omitempty"`
/**
* int of spatial and temporal layers in the RTP stream (e.g. 'L1T3').
* See webrtc-svc.
*/
ScalabilityMode string `json:"scalabilityMode,omitempty"`
/**
* Others.
*/
ScaleResolutionDownBy int `json:"scaleResolutionDownBy,omitempty"`
MaxBitrate int `json:"maxBitrate,omitempty"`
}
// RtpEncodingRtx represents the associated RTX stream for RTP stream.
type RtpEncodingRtx struct {
Ssrc uint32 `json:"ssrc"`
}
/**
* Defines a RTP header extension within the RTP parameters. The list of RTP
* header extensions supported by mediasoup is defined in the
* supportedRtpCapabilities.ts file.
*
* mediasoup does not currently support encrypted RTP header extensions and no
* parameters are currently considered.
*/
type RtpHeaderExtensionParameters struct {
/**
* The URI of the RTP header extension, as defined in RFC 5285.
*/
Uri string `json:"uri"`
/**
* The numeric identifier that goes in the RTP packet. Must be unique.
*/
Id int `json:"id"`
/**
* If true, the value in the header is encrypted as per RFC 6904. Default false.
*/
Encrypt bool `json:"encrypt,omitempty"`
/**
* Configuration parameters for the header extension.
*/
Parameters *RtpCodecSpecificParameters `json:"parameters,omitempty"`
}
/**
* Provides information on RTCP settings within the RTP parameters.
*
* If no cname is given in a producer's RTP parameters, the mediasoup transport
* will choose a random one that will be used into RTCP SDES messages sent to
* all its associated consumers.
*
* mediasoup assumes reducedSize to always be true.
*/
type RtcpParameters struct {
/**
* The Canonical Name (CNAME) used by RTCP (e.g. in SDES messages).
*/
Cname string `json:"cname,omitempty"`
/**
* Whether reduced size RTCP RFC 5506 is configured (if true) or compound RTCP
* as specified in RFC 3550 (if false). Default true.
*/
ReducedSize *bool `json:"reducedSize,omitempty"`
/**
* Whether RTCP-mux is used. Default true.
*/
Mux *bool `json:"mux,omitempty"`
}