1
0
mirror of https://github.com/mgerb/go-discord-bot synced 2026-01-09 16:42:48 +00:00
Files
go-discord-bot/server/rtp/stream.go
2018-05-30 19:27:09 -05:00

41 lines
744 B
Go

package rtp
import (
"time"
"github.com/bwmarrin/discordgo"
)
// Stream -
type Stream struct {
StartTime time.Time
StartingTimestamp uint32
LatestTimestamp uint32
Packets []*discordgo.Packet
}
// GetTimeDiff -
func (s *Stream) GetTimeDiff() uint32 {
return s.LatestTimestamp - s.StartingTimestamp
}
func (s *Stream) GetTimeOffset(startTime int64) int64 {
return s.StartTime.Unix() - startTime
}
// PushPacket -
func (s *Stream) PushPacket(packet *discordgo.Packet) {
if s.StartTime.Unix() == 0 {
s.StartTime = time.Now()
}
if s.StartingTimestamp == 0 && packet.Timestamp != 0 {
s.StartingTimestamp = packet.Timestamp
}
s.LatestTimestamp = packet.Timestamp
s.Packets = append(s.Packets, packet)
}