Skip to content

Commit

Permalink
Fixing linter issues
Browse files Browse the repository at this point in the history
  • Loading branch information
pougetat committed Nov 2, 2023
1 parent 74fe9df commit 3f0d727
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 27 deletions.
30 changes: 18 additions & 12 deletions pkg/flexfec/encoder_interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,34 @@ import (
"github.com/pion/rtp"
)

// FecInterceptor implements FlexFec.
type FecInterceptor struct {
interceptor.NoOp
flexFecEncoder FlexEncoder
packetBuffer []rtp.Packet
minNumMediaPackets uint32
}

type FECEncoderOption func(d *FecInterceptor) error
// Option can be used to set initial options on Fec encoder interceptors.

Check warning on line 19 in pkg/flexfec/encoder_interceptor.go

View workflow job for this annotation

GitHub Actions / lint / Go

exported: comment on exported type FecOption should be of the form "FecOption ..." (with optional leading article) (revive)
type FecOption func(d *FecInterceptor) error

type FECInterceptorFactory struct {
opts []FECEncoderOption
// FecInterceptorFactory creates new FecInterceptors.
type FecInterceptorFactory struct {
opts []FecOption

Check failure on line 24 in pkg/flexfec/encoder_interceptor.go

View workflow job for this annotation

GitHub Actions / lint / Go

field `opts` is unused (unused)
}

func streamSupportFec(info *interceptor.StreamInfo) bool {

Check warning on line 27 in pkg/flexfec/encoder_interceptor.go

View workflow job for this annotation

GitHub Actions / lint / Go

unused-parameter: parameter 'info' seems to be unused, consider removing or renaming it as _ (revive)
// Need to check stream info to see if we should be sending FEC packets
if info.MimeType == "video/VP8" {
return true
}
return false
// TODO: Need to check stream info to see if we should be sending FEC packets

Check failure on line 28 in pkg/flexfec/encoder_interceptor.go

View workflow job for this annotation

GitHub Actions / lint / Go

pkg/flexfec/encoder_interceptor.go:28: Line contains TODO/BUG/FIXME: "TODO: Need to check stream info to see i..." (godox)
return true
}

func NewFECInterceptor(opts ...FECEncoderOption) (*FECInterceptorFactory, error) {
return &FECInterceptorFactory{}, nil
// NewFecInterceptor returns a new Fec interceptor factory.
func NewFecInterceptor(opts ...FecOption) (*FecInterceptorFactory, error) {

Check warning on line 33 in pkg/flexfec/encoder_interceptor.go

View workflow job for this annotation

GitHub Actions / lint / Go

unused-parameter: parameter 'opts' seems to be unused, consider removing or renaming it as _ (revive)
return &FecInterceptorFactory{}, nil
}

func (r *FECInterceptorFactory) NewInterceptor(_ string) (interceptor.Interceptor, error) {
// FlexEncoder implements the Fec encoding mechanism for the "Flex" variant of FlexFec.

Check warning on line 37 in pkg/flexfec/encoder_interceptor.go

View workflow job for this annotation

GitHub Actions / lint / Go

exported: comment on exported method FecInterceptorFactory.NewInterceptor should be of the form "NewInterceptor ..." (revive)
func (r *FecInterceptorFactory) NewInterceptor(_ string) (interceptor.Interceptor, error) {
// Hardcoded for now:
// Min num media packets to encode FEC -> 5
// Min num fec packets -> 1
Expand Down Expand Up @@ -71,7 +73,11 @@ func (r *FecInterceptor) BindLocalStream(info *interceptor.StreamInfo, writer in
fecPackets = r.flexFecEncoder.EncodeFec(r.packetBuffer, 2)

for _, fecPacket := range fecPackets {
writer.Write(&fecPacket.Header, fecPacket.Payload, attributes)
opResult, err := writer.Write(&fecPacket.Header, fecPacket.Payload, attributes)

if err != nil && opResult == 0 {
break
}
}
// Reset the packet buffer now that we've sent the corresponding FEC packets.
r.packetBuffer = nil
Expand Down
7 changes: 4 additions & 3 deletions pkg/flexfec/flexfec_coverage.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ func NewCoverage(mediaPackets []rtp.Packet, numFecPackets uint32) *ProtectionCov
return coverage
}

// UpdateCoverage updates the ProtectionCoverage object with new bitmasks accounting for the numFecPackets
// we want to use to protect the batch of media packets.
func (p *ProtectionCoverage) UpdateCoverage(mediaPackets []rtp.Packet, numFecPackets uint32) {
numMediaPackets := uint32(len(mediaPackets))

Expand Down Expand Up @@ -124,7 +126,6 @@ func (p *ProtectionCoverage) ExtractMask1(fecPacketIndex uint32) uint16 {
// ExtractMask2 returns the second section of the bitmask as defined by the FEC header.
// https://datatracker.ietf.org/doc/html/rfc8627#section-4.2.2.1
func (p *ProtectionCoverage) ExtractMask2(fecPacketIndex uint32) uint32 {
//return uint32(p.packetMasks[fecPacketIndex].GetBitValue(15, 45))
mask := p.packetMasks[fecPacketIndex]
// We remove the first 15 bits
mask2 := mask.Lo << 15
Expand All @@ -136,11 +137,11 @@ func (p *ProtectionCoverage) ExtractMask2(fecPacketIndex uint32) uint32 {
// ExtractMask3 returns the third section of the bitmask as defined by the FEC header.
// https://datatracker.ietf.org/doc/html/rfc8627#section-4.2.2.1
func (p *ProtectionCoverage) ExtractMask3(fecPacketIndex uint32) uint64 {

Check warning on line 139 in pkg/flexfec/flexfec_coverage.go

View workflow job for this annotation

GitHub Actions / lint / Go

unused-parameter: parameter 'fecPacketIndex' seems to be unused, consider removing or renaming it as _ (revive)
//return p.packetMasks[fecPacketIndex].GetBitValue(46, 109)
// return p.packetMasks[fecPacketIndex].GetBitValue(46, 109)
return 0
}

func (p *ProtectionCoverage) ExtractMask3_03(fecPacketIndex uint32) uint64 {

Check warning on line 144 in pkg/flexfec/flexfec_coverage.go

View workflow job for this annotation

GitHub Actions / lint / Go

unused-parameter: parameter 'fecPacketIndex' seems to be unused, consider removing or renaming it as _ (revive)
return 0
//return p.packetMasks[fecPacketIndex].GetBitValue(47, 109)
// return p.packetMasks[fecPacketIndex].GetBitValue(47, 109)
}
1 change: 1 addition & 0 deletions pkg/flexfec/flexfec_encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const (
BaseFecHeaderSize = 12
)

// FlexEncoder is the interface that FecInterceptor uses to encode Fec packets.
type FlexEncoder interface {
EncodeFec(mediaPackets []rtp.Packet, numFecPackets uint32) []rtp.Packet
}
Expand Down
9 changes: 4 additions & 5 deletions pkg/flexfec/flexfec_encoder_03.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ import (
)

const (
// BaseFecHeaderSize represents the minium FEC payload's header size including the
// BaseFec03HeaderSize represents the minium FEC payload's header size including the
// required first mask.
BaseFec03HeaderSize = 20
)

// FlexEncoder implements the Fec encoding mechanism for the "Flex" variant of FlexFec.
// FlexEncoder03 implements the Fec encoding mechanism for the "Flex" variant of FlexFec.
type FlexEncoder03 struct {
fecBaseSn uint16
payloadType uint8
ssrc uint32
coverage *ProtectionCoverage
}

// NewFlexEncoder returns a new FlexFecEncer.
// NewFlexEncoder03 returns a new FlexFecEncoder.
func NewFlexEncoder03(payloadType uint8, ssrc uint32) *FlexEncoder03 {
return &FlexEncoder03{
payloadType: payloadType,
Expand Down Expand Up @@ -180,9 +180,8 @@ func (flex *FlexEncoder03) encodeFlexFecHeader(mediaPackets *util.MediaPacketIte
if optionalMask2 == 0 {
flexFecHeader[18] |= 0b10000000
return flexFecHeader
} else {
binary.BigEndian.PutUint32(flexFecHeader[20:24], optionalMask2)
}
binary.BigEndian.PutUint32(flexFecHeader[20:24], optionalMask2)

if optionalMask3 == 0 {
flexFecHeader[20] |= 0b10000000
Expand Down
15 changes: 8 additions & 7 deletions pkg/flexfec/util/bitarray.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func (b *BitArray) SetBit(bitIndex uint32) {
}
}

// Reset clears the bitmask.
func (b *BitArray) Reset() {
b.Lo = 0
b.Hi = 0
Expand All @@ -33,12 +34,12 @@ func (b *BitArray) GetBit(bitIndex uint32) uint8 {
return 1
}
return 0
} else {
hiBitIndex := bitIndex - 64
result := (b.Hi & (uint64(0b1) << (63 - hiBitIndex)))
if result > 0 {
return 1
}
return 0
}

hiBitIndex := bitIndex - 64
result := (b.Hi & (uint64(0b1) << (63 - hiBitIndex)))
if result > 0 {
return 1
}
return 0
}

0 comments on commit 3f0d727

Please sign in to comment.