-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix race condition on perfect negotiation
- Loading branch information
Yohan Totting
committed
Aug 7, 2023
1 parent
98fd915
commit 9fcb2c5
Showing
6 changed files
with
299 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package sfu | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/pion/webrtc/v3" | ||
) | ||
|
||
type queue struct { | ||
opChan chan interface{} | ||
} | ||
|
||
type negotiationQueue struct { | ||
Client *Client | ||
SDP webrtc.SessionDescription | ||
AnswerChan chan webrtc.SessionDescription | ||
ErrorChan chan error | ||
} | ||
|
||
type renegotiateQueue struct { | ||
Client *Client | ||
} | ||
|
||
type allowRemoteRenegotiationQueue struct { | ||
Client *Client | ||
} | ||
|
||
func NewQueue(ctx context.Context) *queue { | ||
q := &queue{ | ||
opChan: make(chan interface{}), | ||
} | ||
|
||
go q.run(ctx) | ||
|
||
return q | ||
} | ||
|
||
func (q *queue) Push(item interface{}) { | ||
go func() { | ||
q.opChan <- item | ||
}() | ||
} | ||
|
||
func (q *queue) run(ctx context.Context) { | ||
ctxx, cancel := context.WithCancel(ctx) | ||
defer cancel() | ||
|
||
for { | ||
select { | ||
case <-ctxx.Done(): | ||
return | ||
case item := <-q.opChan: | ||
switch opItem := item.(type) { | ||
case negotiationQueue: | ||
answer, err := opItem.Client.negotiateQueuOp(opItem.SDP) | ||
if err != nil { | ||
opItem.ErrorChan <- err | ||
continue | ||
} | ||
|
||
opItem.AnswerChan <- *answer | ||
case renegotiateQueue: | ||
opItem.Client.renegotiateQueuOp() | ||
case allowRemoteRenegotiationQueue: | ||
opItem.Client.allowRemoteRenegotiationQueuOp() | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.