mirror of
https://github.com/jech/galene.git
synced 2024-11-26 02:25:58 +01:00
Propagate CNAME.
This commit is contained in:
parent
5a91a7aae8
commit
aa876bcd0d
3 changed files with 72 additions and 26 deletions
1
conn.go
1
conn.go
|
@ -41,4 +41,5 @@ type downTrack interface {
|
|||
WriteRTP(packat *rtp.Packet) error
|
||||
Accumulate(bytes uint32)
|
||||
setTimeOffset(ntp uint64, rtp uint32)
|
||||
setCname(string)
|
||||
}
|
||||
|
|
3
disk.go
3
disk.go
|
@ -216,6 +216,9 @@ func newDiskConn(directory, label string, up upConnection, remoteTracks []upTrac
|
|||
func (t *diskTrack) setTimeOffset(ntp uint64, rtp uint32) {
|
||||
}
|
||||
|
||||
func (t *diskTrack) setCname(string) {
|
||||
}
|
||||
|
||||
func clonePacket(packet *rtp.Packet) *rtp.Packet {
|
||||
buf, err := packet.Marshal()
|
||||
if err != nil {
|
||||
|
|
58
rtpconn.go
58
rtpconn.go
|
@ -79,6 +79,7 @@ type rtpDownTrack struct {
|
|||
srNTPTime uint64
|
||||
remoteNTPTime uint64
|
||||
remoteRTPTime uint32
|
||||
cname atomic.Value
|
||||
rtt uint64
|
||||
}
|
||||
|
||||
|
@ -95,6 +96,10 @@ func (down *rtpDownTrack) setTimeOffset(ntp uint64, rtp uint32) {
|
|||
atomic.StoreUint32(&down.remoteRTPTime, rtp)
|
||||
}
|
||||
|
||||
func (down *rtpDownTrack) setCname(cname string) {
|
||||
down.cname.Store(cname)
|
||||
}
|
||||
|
||||
type rtpDownConnection struct {
|
||||
id string
|
||||
pc *webrtc.PeerConnection
|
||||
|
@ -187,6 +192,7 @@ type rtpUpTrack struct {
|
|||
writerDone chan struct{}
|
||||
|
||||
mu sync.Mutex
|
||||
cname string
|
||||
local []downTrack
|
||||
srTime uint64
|
||||
srNTPTime uint64
|
||||
|
@ -362,7 +368,7 @@ func getTrackMid(pc *webrtc.PeerConnection, track *webrtc.Track) string {
|
|||
|
||||
// called locked
|
||||
func (up *rtpUpConnection) complete() bool {
|
||||
for mid, _ := range up.labels {
|
||||
for mid := range up.labels {
|
||||
found := false
|
||||
for _, t := range up.tracks {
|
||||
m := getTrackMid(up.pc, t.track)
|
||||
|
@ -566,10 +572,14 @@ func writeLoop(conn *rtpUpConnection, track *rtpUpTrack, ch <-chan packetIndex)
|
|||
track.mu.Lock()
|
||||
ntp := track.srNTPTime
|
||||
rtp := track.srRTPTime
|
||||
cname := track.cname
|
||||
track.mu.Unlock()
|
||||
if ntp != 0 {
|
||||
action.track.setTimeOffset(ntp, rtp)
|
||||
}
|
||||
if cname != "" {
|
||||
action.track.setCname(cname)
|
||||
}
|
||||
} else {
|
||||
found := false
|
||||
for i, t := range local {
|
||||
|
@ -691,7 +701,7 @@ func sendFIR(pc *webrtc.PeerConnection, ssrc uint32, seqno uint8) error {
|
|||
return pc.WriteRTCP([]rtcp.Packet{
|
||||
&rtcp.FullIntraRequest{
|
||||
FIR: []rtcp.FIREntry{
|
||||
rtcp.FIREntry{
|
||||
{
|
||||
SSRC: ssrc,
|
||||
SequenceNumber: seqno,
|
||||
},
|
||||
|
@ -716,7 +726,7 @@ func sendNACK(pc *webrtc.PeerConnection, ssrc uint32, first uint16, bitmap uint1
|
|||
&rtcp.TransportLayerNack{
|
||||
MediaSSRC: ssrc,
|
||||
Nacks: []rtcp.NackPair{
|
||||
rtcp.NackPair{
|
||||
{
|
||||
first,
|
||||
rtcp.PacketBitmap(bitmap),
|
||||
},
|
||||
|
@ -763,6 +773,7 @@ func rtcpUpListener(conn *rtpUpConnection, track *rtpUpTrack, r *webrtc.RTPRecei
|
|||
now := rtptime.Jiffies()
|
||||
|
||||
for _, p := range ps {
|
||||
local := track.getLocal()
|
||||
switch p := p.(type) {
|
||||
case *rtcp.SenderReport:
|
||||
track.mu.Lock()
|
||||
|
@ -773,11 +784,26 @@ func rtcpUpListener(conn *rtpUpConnection, track *rtpUpTrack, r *webrtc.RTPRecei
|
|||
track.srNTPTime = p.NTPTime
|
||||
track.srRTPTime = p.RTPTime
|
||||
track.mu.Unlock()
|
||||
local := track.getLocal()
|
||||
for _, l := range local {
|
||||
l.setTimeOffset(p.NTPTime, p.RTPTime)
|
||||
}
|
||||
case *rtcp.SourceDescription:
|
||||
for _, c := range p.Chunks {
|
||||
if c.Source != track.track.SSRC() {
|
||||
continue
|
||||
}
|
||||
for _, i := range c.Items {
|
||||
if i.Type != rtcp.SDESCNAME {
|
||||
continue
|
||||
}
|
||||
track.mu.Lock()
|
||||
track.cname = i.Text
|
||||
track.mu.Unlock()
|
||||
for _, l := range local {
|
||||
l.setCname(i.Text)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -910,10 +936,7 @@ func sendSR(conn *rtpDownConnection) error {
|
|||
|
||||
remoteNTP := atomic.LoadUint64(&t.remoteNTPTime)
|
||||
remoteRTP := atomic.LoadUint32(&t.remoteRTPTime)
|
||||
if remoteNTP == 0 {
|
||||
// we never got a remote SR for this track
|
||||
continue
|
||||
}
|
||||
if remoteNTP != 0 {
|
||||
srTime := rtptime.NTPToTime(remoteNTP)
|
||||
d := now.Sub(srTime)
|
||||
if d > 0 && d < time.Hour {
|
||||
|
@ -936,6 +959,25 @@ func sendSR(conn *rtpDownConnection) error {
|
|||
atomic.StoreUint64(&t.srNTPTime, nowNTP)
|
||||
}
|
||||
|
||||
cname, ok := t.cname.Load().(string)
|
||||
if ok {
|
||||
item := rtcp.SourceDescriptionItem{
|
||||
Type: rtcp.SDESCNAME,
|
||||
Text: cname,
|
||||
}
|
||||
packets = append(packets,
|
||||
&rtcp.SourceDescription{
|
||||
Chunks: []rtcp.SourceDescriptionChunk{
|
||||
{
|
||||
Source: t.track.SSRC(),
|
||||
Items: []rtcp.SourceDescriptionItem{item},
|
||||
},
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if len(packets) == 0 {
|
||||
state := conn.pc.ConnectionState()
|
||||
if state == webrtc.PeerConnectionStateClosed {
|
||||
|
|
Loading…
Reference in a new issue