@@ -16,7 +16,7 @@ const transportCCURI = "http://www.ietf.org/id/draft-holmer-rmcat-transport-wide
1616type ccfbAttributesKeyType uint32
1717
1818// CCFBAttributesKey is the key which can be used to retrieve the Report objects
19- // from the interceptor.Attributes
19+ // from the interceptor.Attributes.
2020const CCFBAttributesKey ccfbAttributesKeyType = iota
2121
2222// A Report contains Arrival and Departure (from the remote end) times of a RTCP
@@ -33,60 +33,65 @@ type history interface {
3333 getReportForAck ([]acknowledgement ) []PacketReport
3434}
3535
36- // Option can be used to set initial options on CCFB interceptors
36+ // Option can be used to set initial options on CCFB interceptors.
3737type Option func (* Interceptor ) error
3838
3939// HistorySize sets the size of the history of outgoing packets.
4040func HistorySize (size int ) Option {
4141 return func (i * Interceptor ) error {
4242 i .historySize = size
43+
4344 return nil
4445 }
4546}
4647
4748func timeFactory (f func () time.Time ) Option {
4849 return func (i * Interceptor ) error {
4950 i .timestamp = f
51+
5052 return nil
5153 }
5254}
5355
5456func historyFactory (f func (int ) history ) Option {
5557 return func (i * Interceptor ) error {
5658 i .historyFactory = f
59+
5760 return nil
5861 }
5962}
6063
6164func ccfbConverterFactory (f func (ts time.Time , feedback * rtcp.CCFeedbackReport ) (time.Time , map [uint32 ][]acknowledgement )) Option {
6265 return func (i * Interceptor ) error {
6366 i .convertCCFB = f
67+
6468 return nil
6569 }
6670}
6771
6872func twccConverterFactory (f func (feedback * rtcp.TransportLayerCC ) (time.Time , map [uint32 ][]acknowledgement )) Option {
6973 return func (i * Interceptor ) error {
7074 i .convertTWCC = f
75+
7176 return nil
7277 }
7378}
7479
75- // InterceptorFactory is a factory for CCFB interceptors
80+ // InterceptorFactory is a factory for CCFB interceptors.
7681type InterceptorFactory struct {
7782 opts []Option
7883}
7984
80- // NewInterceptor returns a new CCFB InterceptorFactory
85+ // NewInterceptor returns a new CCFB InterceptorFactory.
8186func NewInterceptor (opts ... Option ) (* InterceptorFactory , error ) {
8287 return & InterceptorFactory {
8388 opts : opts ,
8489 }, nil
8590}
8691
87- // NewInterceptor returns a new ccfb.Interceptor
92+ // NewInterceptor returns a new ccfb.Interceptor.
8893func (f * InterceptorFactory ) NewInterceptor (_ string ) (interceptor.Interceptor , error ) {
89- i := & Interceptor {
94+ in := & Interceptor {
9095 NoOp : interceptor.NoOp {},
9196 lock : sync.Mutex {},
9297 log : logging .NewDefaultLoggerFactory ().NewLogger ("ccfb_interceptor" ),
@@ -100,11 +105,12 @@ func (f *InterceptorFactory) NewInterceptor(_ string) (interceptor.Interceptor,
100105 },
101106 }
102107 for _ , opt := range f .opts {
103- if err := opt (i ); err != nil {
108+ if err := opt (in ); err != nil {
104109 return nil , err
105110 }
106111 }
107- return i , nil
112+
113+ return in , nil
108114}
109115
110116// Interceptor implements a congestion control feedback receiver. It keeps track
@@ -129,13 +135,17 @@ type Interceptor struct {
129135}
130136
131137// 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 {
133142 var twccHdrExtID uint8
134143 var useTWCC bool
135144 for _ , e := range info .RTPHeaderExtensions {
136145 if e .URI == transportCCURI {
137146 twccHdrExtID = uint8 (e .ID ) // nolint:gosec
138147 useTWCC = true
148+
139149 break
140150 }
141151 }
@@ -162,7 +172,11 @@ func (i *Interceptor) BindLocalStream(info *interceptor.StreamInfo, writer inter
162172 if useTWCC {
163173 var twccHdrExt rtp.TransportCCExtension
164174 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+ )
166180 if _ , ok := i .ssrcToHistory [ssrc ]; ! ok {
167181 i .ssrcToHistory [ssrc ] = i .historyFactory (i .historySize )
168182 }
@@ -174,6 +188,7 @@ func (i *Interceptor) BindLocalStream(info *interceptor.StreamInfo, writer inter
174188 if err := i .ssrcToHistory [ssrc ].add (seqNr , header .MarshalSize ()+ len (payload ), i .timestamp ()); err != nil {
175189 return 0 , err
176190 }
191+
177192 return writer .Write (header , payload , attributes )
178193 })
179194}
@@ -226,6 +241,7 @@ func (i *Interceptor) BindRTCPReader(reader interceptor.RTCPReader) interceptor.
226241 })
227242 }
228243 attr .Set (CCFBAttributesKey , res )
244+
229245 return n , attr , err
230246 })
231247}
0 commit comments