1
0
mirror of https://github.com/mgerb/go-discord-bot synced 2026-01-11 17:42:48 +00:00
This commit is contained in:
2018-05-30 19:27:09 -05:00
parent af8448e028
commit 1f9706060a
3 changed files with 87 additions and 1 deletions

36
server/rtp/rtp.go Normal file
View File

@@ -0,0 +1,36 @@
// rtp packet processing
package rtp
import (
"time"
"github.com/bwmarrin/discordgo"
)
// RTP -
type RTP struct {
StartTime time.Time
Streams map[uint32]*Stream
}
// New -
func New() *RTP {
return &RTP{
StartTime: time.Now(),
Streams: map[uint32]*Stream{},
}
}
// PushPacket -
func (r *RTP) PushPacket(packet *discordgo.Packet) {
if _, ok := r.Streams[packet.SSRC]; !ok {
r.Streams[packet.SSRC] = new(Stream)
}
r.Streams[packet.SSRC].PushPacket(packet)
}
// GetStream -
func (r *RTP) GetStream(ssrc uint32) *Stream {
return r.Streams[ssrc]
}

40
server/rtp/stream.go Normal file
View File

@@ -0,0 +1,40 @@
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)
}