Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ionorg/ion-sfu
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.4.1
Choose a base ref
...
head repository: ionorg/ion-sfu
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.4.2
Choose a head ref
  • 1 commit
  • 5 files changed
  • 1 contributor

Commits on Nov 17, 2020

  1. Copy the full SHA
    31f8d63 View commit details
Showing with 12 additions and 21 deletions.
  1. +1 −4 pkg/peer.go
  2. +6 −10 pkg/publisher.go
  3. +1 −0 pkg/receiver.go
  4. +0 −4 pkg/simplesender.go
  5. +4 −3 pkg/subscriber.go
5 changes: 1 addition & 4 deletions pkg/peer.go
Original file line number Diff line number Diff line change
@@ -61,8 +61,6 @@ func (p *Peer) Join(sid string, sdp webrtc.SessionDescription) (*webrtc.SessionD
log.Debugf("peer already exists")
return nil, ErrTransportExists
}
p.Lock()
defer p.Unlock()

me := MediaEngine{}
err := me.PopulateFromSDP(sdp)
@@ -151,8 +149,7 @@ func (p *Peer) Answer(sdp webrtc.SessionDescription) (*webrtc.SessionDescription
if p.subscriber == nil {
return nil, ErrNoTransportEstablished
}
p.Lock()
defer p.Unlock()

log.Infof("peer %s got offer", p.id)

if p.publisher.SignalingState() != webrtc.SignalingStateStable {
16 changes: 6 additions & 10 deletions pkg/publisher.go
Original file line number Diff line number Diff line change
@@ -2,14 +2,13 @@ package sfu

import (
"sync"
"sync/atomic"

log "github.com/pion/ion-log"
"github.com/pion/webrtc/v3"
)

type Publisher struct {
sync.Mutex

id string
pc *webrtc.PeerConnection

@@ -18,7 +17,7 @@ type Publisher struct {
candidates []webrtc.ICECandidateInit

onTrackHandler func(*webrtc.Track, *webrtc.RTPReceiver)
onICEConnectionStateChangeHandler func(webrtc.ICEConnectionState)
onICEConnectionStateChangeHandler atomic.Value // func(webrtc.ICEConnectionState)

closeOnce sync.Once
}
@@ -64,11 +63,10 @@ func NewPublisher(session *Session, id string, me MediaEngine, cfg WebRTCTranspo
p.router.Stop()
})
}
p.Lock()
if p.onICEConnectionStateChangeHandler != nil {
p.onICEConnectionStateChangeHandler(connectionState)

if handler, ok := p.onICEConnectionStateChangeHandler.Load().(func()); ok && handler != nil {
handler()
}
p.Unlock()
})

return p, nil
@@ -109,9 +107,7 @@ func (p *Publisher) OnICECandidate(f func(c *webrtc.ICECandidate)) {
}

func (p *Publisher) OnICEConnectionStateChange(f func(connectionState webrtc.ICEConnectionState)) {
p.Lock()
p.onICEConnectionStateChangeHandler = f
p.Unlock()
p.onICEConnectionStateChangeHandler.Store(f)
}

func (p *Publisher) SignalingState() webrtc.SignalingState {
1 change: 1 addition & 0 deletions pkg/receiver.go
Original file line number Diff line number Diff line change
@@ -34,6 +34,7 @@ type Receiver interface {
// WebRTCReceiver receives a video track
type WebRTCReceiver struct {
sync.RWMutex

rtcpMu sync.RWMutex
receiver *webrtc.RTPReceiver
track *webrtc.Track
4 changes: 0 additions & 4 deletions pkg/simplesender.go
Original file line number Diff line number Diff line change
@@ -122,10 +122,6 @@ func (s *SimpleSender) WriteRTP(pkt *rtp.Packet) {
s.sdesMidHdrCtr++
}

if pkt.SequenceNumber%500 == 0 {
log.Tracef("rtp write sender %s with ssrc %d", s.id, s.track.SSRC())
}

if err := s.track.WriteRTP(&rtp.Packet{Header: h, Payload: pkt.Payload}); err != nil {
if err == io.ErrClosedPipe {
return
7 changes: 4 additions & 3 deletions pkg/subscriber.go
Original file line number Diff line number Diff line change
@@ -160,10 +160,10 @@ func (s *Subscriber) SetRemoteDescription(desc webrtc.SessionDescription) error
return err
}

s.Lock()
defer s.Unlock()
if s.pendingSenders.Len() > 0 {
pendingStart := make([]Sender, 0, s.pendingSenders.Len())

s.Lock()
for _, md := range pd.MediaDescriptions {
if s.pendingSenders.Len() == 0 {
break
@@ -181,6 +181,8 @@ func (s *Subscriber) SetRemoteDescription(desc webrtc.SessionDescription) error
}
}
}
s.Unlock()

if len(pendingStart) > 0 {
defer func() {
if err == nil {
@@ -203,7 +205,6 @@ func (s *Subscriber) SetRemoteDescription(desc webrtc.SessionDescription) error
log.Errorf("SetRemoteDescription error: %v", err)
return err
}

return nil
}