@@ -16,7 +16,7 @@ const transportCCURI = "http://www.ietf.org/id/draft-holmer-rmcat-transport-wide
16
16
type ccfbAttributesKeyType uint32
17
17
18
18
// CCFBAttributesKey is the key which can be used to retrieve the Report objects
19
- // from the interceptor.Attributes
19
+ // from the interceptor.Attributes.
20
20
const CCFBAttributesKey ccfbAttributesKeyType = iota
21
21
22
22
// A Report contains Arrival and Departure (from the remote end) times of a RTCP
@@ -33,60 +33,65 @@ type history interface {
33
33
getReportForAck ([]acknowledgement ) []PacketReport
34
34
}
35
35
36
- // Option can be used to set initial options on CCFB interceptors
36
+ // Option can be used to set initial options on CCFB interceptors.
37
37
type Option func (* Interceptor ) error
38
38
39
39
// HistorySize sets the size of the history of outgoing packets.
40
40
func HistorySize (size int ) Option {
41
41
return func (i * Interceptor ) error {
42
42
i .historySize = size
43
+
43
44
return nil
44
45
}
45
46
}
46
47
47
48
func timeFactory (f func () time.Time ) Option {
48
49
return func (i * Interceptor ) error {
49
50
i .timestamp = f
51
+
50
52
return nil
51
53
}
52
54
}
53
55
54
56
func historyFactory (f func (int ) history ) Option {
55
57
return func (i * Interceptor ) error {
56
58
i .historyFactory = f
59
+
57
60
return nil
58
61
}
59
62
}
60
63
61
64
func ccfbConverterFactory (f func (ts time.Time , feedback * rtcp.CCFeedbackReport ) (time.Time , map [uint32 ][]acknowledgement )) Option {
62
65
return func (i * Interceptor ) error {
63
66
i .convertCCFB = f
67
+
64
68
return nil
65
69
}
66
70
}
67
71
68
72
func twccConverterFactory (f func (feedback * rtcp.TransportLayerCC ) (time.Time , map [uint32 ][]acknowledgement )) Option {
69
73
return func (i * Interceptor ) error {
70
74
i .convertTWCC = f
75
+
71
76
return nil
72
77
}
73
78
}
74
79
75
- // InterceptorFactory is a factory for CCFB interceptors
80
+ // InterceptorFactory is a factory for CCFB interceptors.
76
81
type InterceptorFactory struct {
77
82
opts []Option
78
83
}
79
84
80
- // NewInterceptor returns a new CCFB InterceptorFactory
85
+ // NewInterceptor returns a new CCFB InterceptorFactory.
81
86
func NewInterceptor (opts ... Option ) (* InterceptorFactory , error ) {
82
87
return & InterceptorFactory {
83
88
opts : opts ,
84
89
}, nil
85
90
}
86
91
87
- // NewInterceptor returns a new ccfb.Interceptor
92
+ // NewInterceptor returns a new ccfb.Interceptor.
88
93
func (f * InterceptorFactory ) NewInterceptor (_ string ) (interceptor.Interceptor , error ) {
89
- i := & Interceptor {
94
+ in := & Interceptor {
90
95
NoOp : interceptor.NoOp {},
91
96
lock : sync.Mutex {},
92
97
log : logging .NewDefaultLoggerFactory ().NewLogger ("ccfb_interceptor" ),
@@ -100,11 +105,12 @@ func (f *InterceptorFactory) NewInterceptor(_ string) (interceptor.Interceptor,
100
105
},
101
106
}
102
107
for _ , opt := range f .opts {
103
- if err := opt (i ); err != nil {
108
+ if err := opt (in ); err != nil {
104
109
return nil , err
105
110
}
106
111
}
107
- return i , nil
112
+
113
+ return in , nil
108
114
}
109
115
110
116
// Interceptor implements a congestion control feedback receiver. It keeps track
@@ -129,13 +135,17 @@ type Interceptor struct {
129
135
}
130
136
131
137
// BindLocalStream implements interceptor.Interceptor.
132
- func (i * Interceptor ) BindLocalStream (info * interceptor.StreamInfo , writer interceptor.RTPWriter ) interceptor.RTPWriter {
138
+ func (i * Interceptor ) BindLocalStream (
139
+ info * interceptor.StreamInfo ,
140
+ writer interceptor.RTPWriter ,
141
+ ) interceptor.RTPWriter {
133
142
var twccHdrExtID uint8
134
143
var useTWCC bool
135
144
for _ , e := range info .RTPHeaderExtensions {
136
145
if e .URI == transportCCURI {
137
146
twccHdrExtID = uint8 (e .ID ) // nolint:gosec
138
147
useTWCC = true
148
+
139
149
break
140
150
}
141
151
}
@@ -162,7 +172,11 @@ func (i *Interceptor) BindLocalStream(info *interceptor.StreamInfo, writer inter
162
172
if useTWCC {
163
173
var twccHdrExt rtp.TransportCCExtension
164
174
if err := twccHdrExt .Unmarshal (header .GetExtension (twccHdrExtID )); err != nil {
165
- i .log .Warnf ("CCFB configured for TWCC, but failed to get TWCC header extension from outgoing packet. Falling back to saving history for CCFB feedback reports. err: %v" , err )
175
+ i .log .Warnf (
176
+ "CCFB configured for TWCC, but failed to get TWCC header extension from outgoing packet." +
177
+ "Falling back to saving history for CCFB feedback reports. err: %v" ,
178
+ err ,
179
+ )
166
180
if _ , ok := i .ssrcToHistory [ssrc ]; ! ok {
167
181
i .ssrcToHistory [ssrc ] = i .historyFactory (i .historySize )
168
182
}
@@ -174,6 +188,7 @@ func (i *Interceptor) BindLocalStream(info *interceptor.StreamInfo, writer inter
174
188
if err := i .ssrcToHistory [ssrc ].add (seqNr , header .MarshalSize ()+ len (payload ), i .timestamp ()); err != nil {
175
189
return 0 , err
176
190
}
191
+
177
192
return writer .Write (header , payload , attributes )
178
193
})
179
194
}
@@ -226,6 +241,7 @@ func (i *Interceptor) BindRTCPReader(reader interceptor.RTCPReader) interceptor.
226
241
})
227
242
}
228
243
attr .Set (CCFBAttributesKey , res )
244
+
229
245
return n , attr , err
230
246
})
231
247
}
0 commit comments