package twcc
import (
"errors"
"sync/atomic"
"github.com/pion/interceptor"
"github.com/pion/rtp"
)
var errHeaderIsNil = errors .New ("header is nil" )
type HeaderExtensionInterceptorFactory struct {}
func (h *HeaderExtensionInterceptorFactory ) NewInterceptor (_ string ) (interceptor .Interceptor , error ) {
return &HeaderExtensionInterceptor {}, nil
}
func NewHeaderExtensionInterceptor () (*HeaderExtensionInterceptorFactory , error ) {
return &HeaderExtensionInterceptorFactory {}, nil
}
type HeaderExtensionInterceptor struct {
interceptor .NoOp
nextSequenceNr uint32
}
const transportCCURI = "http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01"
func (h *HeaderExtensionInterceptor ) BindLocalStream (
info *interceptor .StreamInfo ,
writer interceptor .RTPWriter ,
) interceptor .RTPWriter {
var hdrExtID uint8
for _ , e := range info .RTPHeaderExtensions {
if e .URI == transportCCURI {
hdrExtID = uint8 (e .ID )
break
}
}
if hdrExtID == 0 {
return writer
}
return interceptor .RTPWriterFunc (
func (header *rtp .Header , payload []byte , attributes interceptor .Attributes ) (int , error ) {
sequenceNumber := atomic .AddUint32 (&h .nextSequenceNr , 1 ) - 1
tcc , err := (&rtp .TransportCCExtension {TransportSequence : uint16 (sequenceNumber )}).Marshal ()
if err != nil {
return 0 , err
}
if header == nil {
return 0 , errHeaderIsNil
}
err = header .SetExtension (hdrExtID , tcc )
if err != nil {
return 0 , err
}
return writer .Write (header , payload , attributes )
},
)
}
The pages are generated with Golds v0.8.2 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .