// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
// SPDX-License-Identifier: MIT

package report

import (
	
	

	
	
	
)

type senderStream struct {
	ssrc      uint32
	clockRate float64
	m         sync.Mutex

	useLatestPacket bool

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

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

func ( *senderStream) ( time.Time,  *rtp.Header,  []byte) {
	.m.Lock()
	defer .m.Unlock()

	 := .SequenceNumber - .lastRTPSN
	if .useLatestPacket || .packetCount == 0 || ( > 0 &&  < (1<<15)) {
		// Told to consider every packet, or this was the first packet, or it's in-order
		.lastRTPSN = .SequenceNumber
		.lastRTPTimeRTP = .Timestamp
		.lastRTPTimeTime = 
	}

	.packetCount++
	.octetCount += uint32(len()) //nolint:gosec // G115
}

func ( *senderStream) ( time.Time) *rtcp.SenderReport {
	.m.Lock()
	defer .m.Unlock()

	return &rtcp.SenderReport{
		SSRC:        .ssrc,
		NTPTime:     ntp.ToNTP(),
		RTPTime:     .lastRTPTimeRTP + uint32(.Sub(.lastRTPTimeTime).Seconds()*.clockRate),
		PacketCount: .packetCount,
		OctetCount:  .octetCount,
	}
}