1
Fork 0
mirror of https://github.com/jech/galene.git synced 2024-11-22 16:45:58 +01:00

Use sendonly transceiver for down tracks, embed receiver in track.

This commit is contained in:
Juliusz Chroboczek 2021-08-01 13:33:01 +02:00
parent 63cfce9eec
commit efb298f002
2 changed files with 22 additions and 16 deletions

View file

@ -354,6 +354,7 @@ func (down *rtpDownConnection) flushICECandidates() error {
type rtpUpTrack struct { type rtpUpTrack struct {
track *webrtc.TrackRemote track *webrtc.TrackRemote
receiver *webrtc.RTPReceiver
conn *rtpUpConnection conn *rtpUpConnection
rate *estimator.Estimator rate *estimator.Estimator
cache *packetcache.Cache cache *packetcache.Cache
@ -630,6 +631,7 @@ func newUpConn(c group.Client, id string, label string, offer string) (*rtpUpCon
track := &rtpUpTrack{ track := &rtpUpTrack{
track: remote, track: remote,
receiver: receiver,
conn: up, conn: up,
cache: packetcache.New(minPacketCache(remote)), cache: packetcache.New(minPacketCache(remote)),
rate: estimator.New(time.Second), rate: estimator.New(time.Second),
@ -642,7 +644,7 @@ func newUpConn(c group.Client, id string, label string, offer string) (*rtpUpCon
go readLoop(track) go readLoop(track)
go rtcpUpListener(up, track, receiver) go rtcpUpListener(track)
up.mu.Unlock() up.mu.Unlock()
@ -769,12 +771,12 @@ func (track *rtpUpTrack) GetPacket(seqno uint16, result []byte, nack bool) uint1
return 0 return 0
} }
func rtcpUpListener(conn *rtpUpConnection, track *rtpUpTrack, r *webrtc.RTPReceiver) { func rtcpUpListener(track *rtpUpTrack) {
buf := make([]byte, 1500) buf := make([]byte, 1500)
for { for {
firstSR := false firstSR := false
n, _, err := r.ReadSimulcast(buf, track.track.RID()) n, _, err := track.receiver.ReadSimulcast(buf, track.track.RID())
if err != nil { if err != nil {
if err != io.EOF && err != io.ErrClosedPipe { if err != io.EOF && err != io.ErrClosedPipe {
log.Printf("Read RTCP: %v", err) log.Printf("Read RTCP: %v", err)
@ -825,7 +827,7 @@ func rtcpUpListener(conn *rtpUpConnection, track *rtpUpTrack, r *webrtc.RTPRecei
if firstSR { if firstSR {
// this is the first SR we got for at least one track, // this is the first SR we got for at least one track,
// quickly propagate the time offsets downstream // quickly propagate the time offsets downstream
local := conn.getLocal() local := track.conn.getLocal()
for _, l := range local { for _, l := range local {
l, ok := l.(*rtpDownConnection) l, ok := l.(*rtpDownConnection)
if ok { if ok {
@ -1093,13 +1095,13 @@ func (track *rtpDownTrack) updateRate(loss uint8, now uint64) {
track.maxBitrate.Set(rate, now) track.maxBitrate.Set(rate, now)
} }
func rtcpDownListener(track *rtpDownTrack, s *webrtc.RTPSender) { func rtcpDownListener(track *rtpDownTrack) {
lastFirSeqno := uint8(0) lastFirSeqno := uint8(0)
buf := make([]byte, 1500) buf := make([]byte, 1500)
for { for {
n, _, err := s.Read(buf) n, _, err := track.sender.Read(buf)
if err != nil { if err != nil {
if err != io.EOF && err != io.ErrClosedPipe { if err != io.EOF && err != io.ErrClosedPipe {
log.Printf("Read RTCP: %v", err) log.Printf("Read RTCP: %v", err)

View file

@ -380,19 +380,23 @@ func addDownTrackUnlocked(conn *rtpDownConnection, remoteTrack *rtpUpTrack, remo
return err return err
} }
sender, err := conn.pc.AddTrack(local) transceiver, err := conn.pc.AddTransceiverFromTrack(local,
webrtc.RTPTransceiverInit{
Direction: webrtc.RTPTransceiverDirectionSendonly,
},
)
if err != nil { if err != nil {
return err return err
} }
parms := sender.GetParameters() parms := transceiver.Sender().GetParameters()
if len(parms.Encodings) != 1 { if len(parms.Encodings) != 1 {
return errors.New("got multiple encodings") return errors.New("got multiple encodings")
} }
track := &rtpDownTrack{ track := &rtpDownTrack{
track: local, track: local,
sender: sender, sender: transceiver.Sender(),
ssrc: parms.Encodings[0].SSRC, ssrc: parms.Encodings[0].SSRC,
conn: conn, conn: conn,
remote: remoteTrack, remote: remoteTrack,
@ -405,7 +409,7 @@ func addDownTrackUnlocked(conn *rtpDownConnection, remoteTrack *rtpUpTrack, remo
conn.tracks = append(conn.tracks, track) conn.tracks = append(conn.tracks, track)
go rtcpDownListener(track, sender) go rtcpDownListener(track)
return nil return nil
} }