Skip to content

Commit

Permalink
Fast publish (#548)
Browse files Browse the repository at this point in the history
* Process fast publish option

* parallel negotiate with signal addtrackrequest
  • Loading branch information
cnderrauber authored Oct 23, 2024
1 parent 75642c8 commit 01461da
Showing 3 changed files with 19 additions and 20 deletions.
2 changes: 1 addition & 1 deletion engine.go
Original file line number Diff line number Diff line change
@@ -144,7 +144,7 @@ func (e *RTCEngine) Join(url string, token string, params *connectParams) (*live
e.client.Start()

// send offer
if !res.SubscriberPrimary {
if !res.SubscriberPrimary || res.FastPublish {
if publisher, ok := e.Publisher(); ok {
publisher.Negotiate()
} else {
35 changes: 17 additions & 18 deletions localparticipant.go
Original file line number Diff line number Diff line change
@@ -55,6 +55,11 @@ func (p *LocalParticipant) PublishTrack(track webrtc.TrackLocal, opts *TrackPubl
}
}

publisher, ok := p.engine.Publisher()
if !ok {
return nil, ErrNoPeerConnection
}

pub := NewLocalTrackPublication(kind, track, *opts, p.engine.client)
pub.onMuteChanged = p.onTrackMuted

@@ -88,21 +93,6 @@ func (p *LocalParticipant) PublishTrack(track webrtc.TrackLocal, opts *TrackPubl
return nil, err
}

pubChan := p.engine.TrackPublishedChan()
var pubRes *livekit.TrackPublishedResponse

select {
case pubRes = <-pubChan:
break
case <-time.After(trackPublishTimeout):
return nil, ErrTrackPublishTimeout
}

publisher, ok := p.engine.Publisher()
if !ok {
return nil, ErrNoPeerConnection
}

// add transceivers
transceiver, err := publisher.PeerConnection().AddTransceiverFromTrack(track, webrtc.RTPTransceiverInit{
Direction: webrtc.RTPTransceiverDirectionSendonly,
@@ -115,11 +105,21 @@ func (p *LocalParticipant) PublishTrack(track webrtc.TrackLocal, opts *TrackPubl
_, isSampleTrack := track.(*LocalTrack)
pub.setSender(transceiver.Sender(), !isSampleTrack)

publisher.Negotiate()

pubChan := p.engine.TrackPublishedChan()
var pubRes *livekit.TrackPublishedResponse

select {
case pubRes = <-pubChan:
break
case <-time.After(trackPublishTimeout):
return nil, ErrTrackPublishTimeout
}

pub.updateInfo(pubRes.Track)
p.addPublication(pub)

publisher.Negotiate()

p.engine.log.Infow("published track", "name", opts.Name, "source", opts.Source.String(), "trackID", pubRes.Track.Sid)

return pub, nil
@@ -497,7 +497,6 @@ func (p *LocalParticipant) onTrackMuted(pub *LocalTrackPublication, muted bool)
// `TrackPermission.AllTracks` are false), any newer published tracks
// will not grant permissions to any participants and will require a subsequent
// permissions update to allow subscription.
//
func (p *LocalParticipant) SetSubscriptionPermission(sp *livekit.SubscriptionPermission) {
p.lock.Lock()
p.subscriptionPermission = proto.Clone(sp).(*livekit.SubscriptionPermission)
2 changes: 1 addition & 1 deletion transport.go
Original file line number Diff line number Diff line change
@@ -38,7 +38,7 @@ import (
)

const (
negotiationFrequency = 150 * time.Millisecond
negotiationFrequency = 20 * time.Millisecond

dtlsRetransmissionInterval = 100 * time.Millisecond
iceDisconnectedTimeout = 10 * time.Second

0 comments on commit 01461da

Please sign in to comment.