-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix pli missed cause by two goroutine compete rtcp reader
There were two goroutine to read rtcp when publishing a LocalSampleTrack, one is publication to calculate rtt and the other is LocalSampleTrack itself, cause pli hander rely on LocalSampleTrack's rtcp callback might miss pli request.
- Loading branch information
1 parent
12e24f8
commit c7a4620
Showing
6 changed files
with
100 additions
and
39 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,66 @@ | ||
package interceptor | ||
|
||
import ( | ||
"github.com/livekit/mediatransportutil" | ||
"github.com/pion/interceptor" | ||
"github.com/pion/rtcp" | ||
) | ||
|
||
type RTTInterceptorFactory struct { | ||
onRttUpdate func(rtt uint32) | ||
} | ||
|
||
func NewRTTInterceptorFactory(onRttUpdate func(rtt uint32)) *RTTInterceptorFactory { | ||
return &RTTInterceptorFactory{ | ||
onRttUpdate: onRttUpdate, | ||
} | ||
} | ||
|
||
func (r *RTTInterceptorFactory) NewInterceptor(_ string) (interceptor.Interceptor, error) { | ||
return NewRTTInterceptor(r.onRttUpdate), nil | ||
} | ||
|
||
type RTTInterceptor struct { | ||
interceptor.NoOp | ||
|
||
onRttUpdate func(rtt uint32) | ||
} | ||
|
||
func NewRTTInterceptor(onRttUpdate func(rtt uint32)) *RTTInterceptor { | ||
return &RTTInterceptor{ | ||
onRttUpdate: onRttUpdate, | ||
} | ||
} | ||
|
||
func (r *RTTInterceptor) BindRTCPReader(reader interceptor.RTCPReader) interceptor.RTCPReader { | ||
return interceptor.RTCPReaderFunc(func(b []byte, a interceptor.Attributes) (int, interceptor.Attributes, error) { | ||
i, attr, err := reader.Read(b, a) | ||
if err != nil { | ||
return 0, nil, err | ||
} | ||
|
||
if attr == nil { | ||
attr = make(interceptor.Attributes) | ||
} | ||
pkts, err := attr.GetRTCPPackets(b[:i]) | ||
if err != nil { | ||
return 0, nil, err | ||
} | ||
|
||
rttCaculate: | ||
for _, packet := range pkts { | ||
if rr, ok := packet.(*rtcp.ReceiverReport); ok { | ||
for _, report := range rr.Reports { | ||
rtt, err := mediatransportutil.GetRttMsFromReceiverReportOnly(&report) | ||
if err == nil && rtt != 0 { | ||
r.onRttUpdate(rtt) | ||
} | ||
|
||
break rttCaculate | ||
} | ||
} | ||
} | ||
|
||
return i, attr, err | ||
}) | ||
} |
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