summaryrefslogtreecommitdiff
path: root/vendor/github.com/pion/interceptor/pkg/report/sender_stream.go
blob: 851d70e5804c2d799673773b42b24f453709cf94 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package report

import (
	"sync"
	"time"

	"github.com/pion/rtp"
)

type senderStream struct {
	clockRate float64
	m         sync.Mutex

	// data from rtp packets
	lastRTPTimeRTP  uint32
	lastRTPTimeTime time.Time
	packetCount     uint32
	octetCount      uint32
}

func newSenderStream(clockRate uint32) *senderStream {
	return &senderStream{
		clockRate: float64(clockRate),
	}
}

func (stream *senderStream) processRTP(now time.Time, header *rtp.Header, payload []byte) {
	stream.m.Lock()
	defer stream.m.Unlock()

	// always update time to minimize errors
	stream.lastRTPTimeRTP = header.Timestamp
	stream.lastRTPTimeTime = now

	stream.packetCount++
	stream.octetCount += uint32(len(payload))
}