@@ -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,66 @@ 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
64+ // nolint
6165func ccfbConverterFactory (f func (ts time.Time , feedback * rtcp.CCFeedbackReport ) (time.Time , map [uint32 ][]acknowledgement )) Option {
6266 return func (i * Interceptor ) error {
6367 i .convertCCFB = f
68+
6469 return nil
6570 }
6671}
6772
6873func twccConverterFactory (f func (feedback * rtcp.TransportLayerCC ) (time.Time , map [uint32 ][]acknowledgement )) Option {
6974 return func (i * Interceptor ) error {
7075 i .convertTWCC = f
76+
7177 return nil
7278 }
7379}
7480
75- // InterceptorFactory is a factory for CCFB interceptors
81+ // InterceptorFactory is a factory for CCFB interceptors.
7682type InterceptorFactory struct {
7783 opts []Option
7884}
7985
80- // NewInterceptor returns a new CCFB InterceptorFactory
86+ // NewInterceptor returns a new CCFB InterceptorFactory.
8187func NewInterceptor (opts ... Option ) (* InterceptorFactory , error ) {
8288 return & InterceptorFactory {
8389 opts : opts ,
8490 }, nil
8591}
8692
87- // NewInterceptor returns a new ccfb.Interceptor
93+ // NewInterceptor returns a new ccfb.Interceptor.
8894func (f * InterceptorFactory ) NewInterceptor (_ string ) (interceptor.Interceptor , error ) {
89- i := & Interceptor {
95+ in := & Interceptor {
9096 NoOp : interceptor.NoOp {},
9197 lock : sync.Mutex {},
9298 log : logging .NewDefaultLoggerFactory ().NewLogger ("ccfb_interceptor" ),
@@ -100,11 +106,12 @@ func (f *InterceptorFactory) NewInterceptor(_ string) (interceptor.Interceptor,
100106 },
101107 }
102108 for _ , opt := range f .opts {
103- if err := opt (i ); err != nil {
109+ if err := opt (in ); err != nil {
104110 return nil , err
105111 }
106112 }
107- return i , nil
113+
114+ return in , nil
108115}
109116
110117// Interceptor implements a congestion control feedback receiver. It keeps track
@@ -129,13 +136,17 @@ type Interceptor struct {
129136}
130137
131138// BindLocalStream implements interceptor.Interceptor.
132- func (i * Interceptor ) BindLocalStream (info * interceptor.StreamInfo , writer interceptor.RTPWriter ) interceptor.RTPWriter {
139+ func (i * Interceptor ) BindLocalStream (
140+ info * interceptor.StreamInfo ,
141+ writer interceptor.RTPWriter ,
142+ ) interceptor.RTPWriter {
133143 var twccHdrExtID uint8
134144 var useTWCC bool
135145 for _ , e := range info .RTPHeaderExtensions {
136146 if e .URI == transportCCURI {
137147 twccHdrExtID = uint8 (e .ID ) // nolint:gosec
138148 useTWCC = true
149+
139150 break
140151 }
141152 }
@@ -149,6 +160,7 @@ func (i *Interceptor) BindLocalStream(info *interceptor.StreamInfo, writer inter
149160 }
150161 i .ssrcToHistory [ssrc ] = i .historyFactory (i .historySize )
151162
163+ // nolint
152164 return interceptor .RTPWriterFunc (func (header * rtp.Header , payload []byte , attributes interceptor.Attributes ) (int , error ) {
153165 i .lock .Lock ()
154166 defer i .lock .Unlock ()
@@ -162,7 +174,11 @@ func (i *Interceptor) BindLocalStream(info *interceptor.StreamInfo, writer inter
162174 if useTWCC {
163175 var twccHdrExt rtp.TransportCCExtension
164176 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 )
177+ i .log .Warnf (
178+ "CCFB configured for TWCC, but failed to get TWCC header extension from outgoing packet." +
179+ "Falling back to saving history for CCFB feedback reports. err: %v" ,
180+ err ,
181+ )
166182 if _ , ok := i .ssrcToHistory [ssrc ]; ! ok {
167183 i .ssrcToHistory [ssrc ] = i .historyFactory (i .historySize )
168184 }
@@ -174,6 +190,7 @@ func (i *Interceptor) BindLocalStream(info *interceptor.StreamInfo, writer inter
174190 if err := i .ssrcToHistory [ssrc ].add (seqNr , header .MarshalSize ()+ len (payload ), i .timestamp ()); err != nil {
175191 return 0 , err
176192 }
193+
177194 return writer .Write (header , payload , attributes )
178195 })
179196}
@@ -226,6 +243,7 @@ func (i *Interceptor) BindRTCPReader(reader interceptor.RTCPReader) interceptor.
226243 })
227244 }
228245 attr .Set (CCFBAttributesKey , res )
246+
229247 return n , attr , err
230248 })
231249}
0 commit comments