mirror of
https://github.com/m1k1o/neko.git
synced 2025-05-31 01:47:24 +02:00
WebRTC congestion control (#26)
* Add congestion control * Improve stream matching, add manual stream selection, add metrics * Use a ticker for bitrate estimation and make bandwidth drops switch to lower streams more aggressively * Missing signal response, fix video auto bug * Remove redundant mutex * Bitrate history queue * Get bitrate fn support h264 & float64 --------- Co-authored-by: Aleksandar Sukovic <aleksandar.sukovic@gmail.com>
This commit is contained in:
parent
e80ae8019e
commit
2364facd60
15 changed files with 738 additions and 222 deletions
|
@ -13,14 +13,17 @@ import (
|
|||
)
|
||||
|
||||
type WebRTCPeerCtx struct {
|
||||
mu sync.Mutex
|
||||
logger zerolog.Logger
|
||||
connection *webrtc.PeerConnection
|
||||
dataChannel *webrtc.DataChannel
|
||||
changeVideo func(bitrate int) error
|
||||
videoId func() string
|
||||
setPaused func(isPaused bool)
|
||||
iceTrickle bool
|
||||
mu sync.Mutex
|
||||
logger zerolog.Logger
|
||||
connection *webrtc.PeerConnection
|
||||
dataChannel *webrtc.DataChannel
|
||||
changeVideoFromBitrate func(bitrate int)
|
||||
changeVideoFromID func(id string) int
|
||||
videoId func() string
|
||||
setPaused func(isPaused bool)
|
||||
setVideoAuto func(auto bool)
|
||||
getVideoAuto func() bool
|
||||
iceTrickle bool
|
||||
}
|
||||
|
||||
func (peer *WebRTCPeerCtx) CreateOffer(ICERestart bool) (*webrtc.SessionDescription, error) {
|
||||
|
@ -115,7 +118,7 @@ func (peer *WebRTCPeerCtx) SetCandidate(candidate webrtc.ICECandidateInit) error
|
|||
return peer.connection.AddICECandidate(candidate)
|
||||
}
|
||||
|
||||
func (peer *WebRTCPeerCtx) SetVideoBitrate(bitrate int) error {
|
||||
func (peer *WebRTCPeerCtx) SetVideoBitrate(peerBitrate int) error {
|
||||
peer.mu.Lock()
|
||||
defer peer.mu.Unlock()
|
||||
|
||||
|
@ -123,12 +126,24 @@ func (peer *WebRTCPeerCtx) SetVideoBitrate(bitrate int) error {
|
|||
return types.ErrWebRTCConnectionNotFound
|
||||
}
|
||||
|
||||
peer.logger.Info().Int("bitrate", bitrate).Msg("change video bitrate")
|
||||
return peer.changeVideo(bitrate)
|
||||
peer.changeVideoFromBitrate(peerBitrate)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (peer *WebRTCPeerCtx) SetVideoID(videoID string) error {
|
||||
peer.mu.Lock()
|
||||
defer peer.mu.Unlock()
|
||||
|
||||
if peer.connection == nil {
|
||||
return types.ErrWebRTCConnectionNotFound
|
||||
}
|
||||
|
||||
peer.changeVideoFromID(videoID)
|
||||
return nil
|
||||
}
|
||||
|
||||
// TODO: Refactor.
|
||||
func (peer *WebRTCPeerCtx) GetVideoId() string {
|
||||
func (peer *WebRTCPeerCtx) GetVideoID() string {
|
||||
peer.mu.Lock()
|
||||
defer peer.mu.Unlock()
|
||||
|
||||
|
@ -215,3 +230,11 @@ func (peer *WebRTCPeerCtx) Destroy() {
|
|||
peer.connection = nil
|
||||
}
|
||||
}
|
||||
|
||||
func (peer *WebRTCPeerCtx) SetVideoAuto(auto bool) {
|
||||
peer.setVideoAuto(auto)
|
||||
}
|
||||
|
||||
func (peer *WebRTCPeerCtx) VideoAuto() bool {
|
||||
return peer.getVideoAuto()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue