mirror of
https://github.com/jech/galene.git
synced 2024-11-10 02:35:58 +01:00
Maintain time offsets on the sender side.
This commit is contained in:
parent
917fa33d38
commit
f9edde6526
3 changed files with 37 additions and 29 deletions
1
conn.go
1
conn.go
|
@ -41,4 +41,5 @@ type downTrack interface {
|
||||||
WriteRTP(packat *rtp.Packet) error
|
WriteRTP(packat *rtp.Packet) error
|
||||||
Accumulate(bytes uint32)
|
Accumulate(bytes uint32)
|
||||||
GetMaxBitrate(now uint64) uint64
|
GetMaxBitrate(now uint64) uint64
|
||||||
|
setTimeOffset(ntp uint64, rtp uint32)
|
||||||
}
|
}
|
||||||
|
|
3
disk.go
3
disk.go
|
@ -204,6 +204,9 @@ func newDiskConn(directory, label string, up upConnection, remoteTracks []upTrac
|
||||||
return &conn, nil
|
return &conn, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *diskTrack) setTimeOffset(ntp uint64, rtp uint32) {
|
||||||
|
}
|
||||||
|
|
||||||
func clonePacket(packet *rtp.Packet) *rtp.Packet {
|
func clonePacket(packet *rtp.Packet) *rtp.Packet {
|
||||||
buf, err := packet.Marshal()
|
buf, err := packet.Marshal()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
62
rtpconn.go
62
rtpconn.go
|
@ -78,6 +78,8 @@ type rtpDownTrack struct {
|
||||||
stats *receiverStats
|
stats *receiverStats
|
||||||
srTime uint64
|
srTime uint64
|
||||||
srNTPTime uint64
|
srNTPTime uint64
|
||||||
|
remoteNTPTime uint64
|
||||||
|
remoteRTPTime uint32
|
||||||
rtt uint64
|
rtt uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,6 +100,11 @@ func (down *rtpDownTrack) GetMaxBitrate(now uint64) uint64 {
|
||||||
return br2
|
return br2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (down *rtpDownTrack) setTimeOffset(ntp uint64, rtp uint32) {
|
||||||
|
atomic.StoreUint64(&down.remoteNTPTime, ntp)
|
||||||
|
atomic.StoreUint32(&down.remoteRTPTime, rtp)
|
||||||
|
}
|
||||||
|
|
||||||
type rtpDownConnection struct {
|
type rtpDownConnection struct {
|
||||||
id string
|
id string
|
||||||
pc *webrtc.PeerConnection
|
pc *webrtc.PeerConnection
|
||||||
|
@ -554,11 +561,19 @@ func writeLoop(conn *rtpUpConnection, track *rtpUpTrack, ch <-chan packetIndex)
|
||||||
if action.add {
|
if action.add {
|
||||||
local = append(local, action.track)
|
local = append(local, action.track)
|
||||||
firSent = false
|
firSent = false
|
||||||
|
track.mu.Lock()
|
||||||
|
ntp := track.srNTPTime
|
||||||
|
rtp := track.srRTPTime
|
||||||
|
track.mu.Unlock()
|
||||||
|
if ntp != 0 {
|
||||||
|
action.track.setTimeOffset(ntp, rtp)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
found := false
|
found := false
|
||||||
for i, t := range local {
|
for i, t := range local {
|
||||||
if t == action.track {
|
if t == action.track {
|
||||||
local = append(local[:i], local[i+1:]...)
|
local = append(local[:i],
|
||||||
|
local[i+1:]...)
|
||||||
found = true
|
found = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -754,6 +769,10 @@ func rtcpUpListener(conn *rtpUpConnection, track *rtpUpTrack, r *webrtc.RTPRecei
|
||||||
track.srNTPTime = p.NTPTime
|
track.srNTPTime = p.NTPTime
|
||||||
track.srRTPTime = p.RTPTime
|
track.srRTPTime = p.RTPTime
|
||||||
track.mu.Unlock()
|
track.mu.Unlock()
|
||||||
|
local := track.getLocal()
|
||||||
|
for _, l := range local {
|
||||||
|
l.setTimeOffset(p.NTPTime, p.RTPTime)
|
||||||
|
}
|
||||||
case *rtcp.SourceDescription:
|
case *rtcp.SourceDescription:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -848,37 +867,22 @@ func sendSR(conn *rtpDownConnection) error {
|
||||||
|
|
||||||
for _, t := range conn.tracks {
|
for _, t := range conn.tracks {
|
||||||
clockrate := t.track.Codec().ClockRate
|
clockrate := t.track.Codec().ClockRate
|
||||||
remote := t.remote
|
|
||||||
|
|
||||||
var nowRTP uint32
|
var nowRTP uint32
|
||||||
|
|
||||||
switch r := remote.(type) {
|
remoteNTP := atomic.LoadUint64(&t.remoteNTPTime)
|
||||||
case *rtpUpTrack:
|
remoteRTP := atomic.LoadUint32(&t.remoteRTPTime)
|
||||||
r.mu.Lock()
|
if remoteNTP == 0 {
|
||||||
lastTime := r.srTime
|
// we never got a remote SR for this track
|
||||||
srNTPTime := r.srNTPTime
|
continue
|
||||||
srRTPTime := r.srRTPTime
|
}
|
||||||
r.mu.Unlock()
|
srTime := rtptime.NTPToTime(remoteNTP)
|
||||||
if lastTime == 0 {
|
d := now.Sub(srTime)
|
||||||
// we never got a remote SR, skip this track
|
if d > 0 && d < time.Hour {
|
||||||
continue
|
delay := rtptime.FromDuration(
|
||||||
}
|
d, clockrate,
|
||||||
if srNTPTime != 0 {
|
)
|
||||||
srTime := rtptime.NTPToTime(srNTPTime)
|
nowRTP = remoteRTP + uint32(delay)
|
||||||
d := now.Sub(srTime)
|
|
||||||
if d > 0 && d < time.Hour {
|
|
||||||
delay := rtptime.FromDuration(
|
|
||||||
d, clockrate,
|
|
||||||
)
|
|
||||||
nowRTP = srRTPTime + uint32(delay)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
ts, ok := remote.getTimestamp()
|
|
||||||
if !ok {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
nowRTP = ts
|
|
||||||
}
|
}
|
||||||
|
|
||||||
p, b := t.rate.Totals()
|
p, b := t.rate.Totals()
|
||||||
|
|
Loading…
Reference in a new issue