mirror of
https://github.com/sipeed/NanoKVM.git
synced 2026-09-11 00:22:56 -05:00
fix(stream): isolate H264 subscribers
Keep slow WebRTC consumers from blocking the shared H264 source by dropping buffered frames until the next keyframe. Restore the WebRTC NACK and RTCP report interceptors while retaining a safe RTP MTU, and enable linker --as-needed for libkvm to remove unused OpenCV dependencies.
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -15,10 +15,11 @@ type H264Frame struct {
|
||||
}
|
||||
|
||||
type H264Subscription struct {
|
||||
frames chan H264Frame
|
||||
done chan struct{}
|
||||
closed atomic.Bool
|
||||
once sync.Once
|
||||
frames chan H264Frame
|
||||
done chan struct{}
|
||||
closed atomic.Bool
|
||||
once sync.Once
|
||||
waitingForKeyframe bool
|
||||
}
|
||||
|
||||
type H264Source struct {
|
||||
@@ -147,11 +148,38 @@ func (s *H264Subscription) send(frame H264Frame) bool {
|
||||
if s.closed.Load() {
|
||||
return false
|
||||
}
|
||||
if s.waitingForKeyframe {
|
||||
if frame.Result != 3 {
|
||||
return false
|
||||
}
|
||||
s.waitingForKeyframe = false
|
||||
}
|
||||
|
||||
select {
|
||||
case s.frames <- frame:
|
||||
return true
|
||||
case <-s.done:
|
||||
return false
|
||||
default:
|
||||
}
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-s.frames:
|
||||
case <-s.done:
|
||||
return false
|
||||
default:
|
||||
s.waitingForKeyframe = true
|
||||
if frame.Result != 3 {
|
||||
return false
|
||||
}
|
||||
s.waitingForKeyframe = false
|
||||
select {
|
||||
case s.frames <- frame:
|
||||
return true
|
||||
case <-s.done:
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,9 +164,16 @@ func createPeerConnection(iceServers []webrtc.ICEServer, mediaEngine *webrtc.Med
|
||||
|
||||
apiOptions := []func(api *webrtc.API){
|
||||
webrtc.WithSettingEngine(settingEngine),
|
||||
webrtc.WithInterceptorRegistry(&interceptor.Registry{}),
|
||||
}
|
||||
if mediaEngine != nil {
|
||||
registry := &interceptor.Registry{}
|
||||
if err := webrtc.ConfigureNack(mediaEngine, registry); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := webrtc.ConfigureRTCPReports(registry); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
apiOptions = append(apiOptions, webrtc.WithInterceptorRegistry(registry))
|
||||
apiOptions = append(apiOptions, webrtc.WithMediaEngine(mediaEngine))
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ func NewWebRTCManager() *WebRTCManager {
|
||||
m := &WebRTCManager{
|
||||
clients: make(map[*websocket.Conn]*Client),
|
||||
videoPacketizer: rtp.NewPacketizer(
|
||||
1450,
|
||||
1200,
|
||||
100,
|
||||
0x1234ABCD,
|
||||
&codecs.H264Payloader{},
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
list(APPEND ADD_REQUIREMENTS vision basic peripheral)
|
||||
list(APPEND ADD_INCLUDE "include")
|
||||
list(APPEND ADD_LINK_DEFINITIONS_PRIVATE -Wl,--as-needed)
|
||||
|
||||
append_srcs_dir(ADD_SRCS "src")
|
||||
|
||||
register_component(DYNAMIC)
|
||||
register_component(DYNAMIC)
|
||||
|
||||
Reference in New Issue
Block a user