package rfc8888
import (
"time"
"github.com/pion/interceptor/internal/ntp"
"github.com/pion/rtcp"
)
type packetReport struct {
arrivalTime time .Time
ecn uint8
}
type Recorder struct {
ssrc uint32
streams map [uint32 ]*streamLog
}
func NewRecorder () *Recorder {
return &Recorder {
streams : map [uint32 ]*streamLog {},
}
}
func (r *Recorder ) AddPacket (ts time .Time , ssrc uint32 , seq uint16 , ecn uint8 ) {
stream , ok := r .streams [ssrc ]
if !ok {
stream = newStreamLog (ssrc )
r .streams [ssrc ] = stream
}
stream .add (ts , seq , ecn )
}
func (r *Recorder ) BuildReport (now time .Time , maxSize int ) *rtcp .CCFeedbackReport {
report := &rtcp .CCFeedbackReport {
SenderSSRC : r .ssrc ,
ReportBlocks : []rtcp .CCFeedbackReportBlock {},
ReportTimestamp : ntp .ToNTP32 (now ),
}
maxReportBlocks := (maxSize - 12 - (8 * len (r .streams ))) / 2
var maxReportBlocksPerStream int
if len (r .streams ) > 1 {
maxReportBlocksPerStream = maxReportBlocks / (len (r .streams ) - 1 )
} else {
maxReportBlocksPerStream = maxReportBlocks
}
for i , log := range r .streams {
if len (r .streams ) > 1 && int (i ) == len (r .streams )-1 {
maxReportBlocksPerStream = maxReportBlocks % len (r .streams )
}
block := log .metricsAfter (now , int64 (maxReportBlocksPerStream ))
report .ReportBlocks = append (report .ReportBlocks , block )
}
return report
}
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 .