mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
peer configuration multiple codecs.
This commit is contained in:
parent
fa168a53c9
commit
beac1cb088
@ -15,6 +15,7 @@ import (
|
|||||||
|
|
||||||
"demodesk/neko/internal/config"
|
"demodesk/neko/internal/config"
|
||||||
"demodesk/neko/internal/types"
|
"demodesk/neko/internal/types"
|
||||||
|
"demodesk/neko/internal/types/codec"
|
||||||
"demodesk/neko/internal/types/event"
|
"demodesk/neko/internal/types/event"
|
||||||
"demodesk/neko/internal/types/message"
|
"demodesk/neko/internal/types/message"
|
||||||
"demodesk/neko/internal/webrtc/cursor"
|
"demodesk/neko/internal/webrtc/cursor"
|
||||||
@ -117,7 +118,10 @@ func (manager *WebRTCManagerCtx) CreatePeer(session types.Session, videoID strin
|
|||||||
return nil, types.ErrWebRTCVideoNotFound
|
return nil, types.ErrWebRTCVideoNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
connection, err := manager.newPeerConnection(videoStream.Codec(), logger)
|
connection, err := manager.newPeerConnection([]codec.RTPCodec{
|
||||||
|
videoStream.Codec(),
|
||||||
|
manager.capture.Audio().Codec(),
|
||||||
|
}, logger)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -244,9 +248,8 @@ func (manager *WebRTCManagerCtx) CreatePeer(session types.Session, videoID strin
|
|||||||
switch state {
|
switch state {
|
||||||
case webrtc.PeerConnectionStateConnected:
|
case webrtc.PeerConnectionStateConnected:
|
||||||
session.SetWebRTCConnected(peer, true)
|
session.SetWebRTCConnected(peer, true)
|
||||||
case webrtc.PeerConnectionStateDisconnected:
|
case webrtc.PeerConnectionStateDisconnected,
|
||||||
fallthrough
|
webrtc.PeerConnectionStateFailed:
|
||||||
case webrtc.PeerConnectionStateFailed:
|
|
||||||
connection.Close()
|
connection.Close()
|
||||||
case webrtc.PeerConnectionStateClosed:
|
case webrtc.PeerConnectionStateClosed:
|
||||||
manager.mu.Lock()
|
manager.mu.Lock()
|
||||||
|
@ -9,15 +9,24 @@ import (
|
|||||||
"github.com/rs/zerolog"
|
"github.com/rs/zerolog"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (manager *WebRTCManagerCtx) newPeerConnection(codec codec.RTPCodec, logger zerolog.Logger) (*webrtc.PeerConnection, error) {
|
func (manager *WebRTCManagerCtx) newPeerConnection(codecs []codec.RTPCodec, logger zerolog.Logger) (*webrtc.PeerConnection, error) {
|
||||||
// create media engine
|
// create media engine
|
||||||
engine, err := manager.mediaEngine(codec)
|
engine := &webrtc.MediaEngine{}
|
||||||
if err != nil {
|
for _, codec := range codecs {
|
||||||
return nil, err
|
if err := codec.Register(engine); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// create setting engine
|
// create setting engine
|
||||||
settings := manager.settingEngine(logger)
|
settings := webrtc.SettingEngine{
|
||||||
|
LoggerFactory: pionlog.New(logger),
|
||||||
|
}
|
||||||
|
|
||||||
|
_ = settings.SetEphemeralUDPPortRange(manager.config.EphemeralMin, manager.config.EphemeralMax)
|
||||||
|
settings.SetICETimeouts(disconnectedTimeout, failedTimeout, keepAliveInterval)
|
||||||
|
settings.SetNAT1To1IPs(manager.config.NAT1To1IPs, webrtc.ICECandidateTypeHost)
|
||||||
|
settings.SetLite(manager.config.ICELite)
|
||||||
|
|
||||||
// create interceptor registry
|
// create interceptor registry
|
||||||
registry := &interceptor.Registry{}
|
registry := &interceptor.Registry{}
|
||||||
@ -37,36 +46,6 @@ func (manager *WebRTCManagerCtx) newPeerConnection(codec codec.RTPCodec, logger
|
|||||||
return api.NewPeerConnection(configuration)
|
return api.NewPeerConnection(configuration)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (manager *WebRTCManagerCtx) mediaEngine(codec codec.RTPCodec) (*webrtc.MediaEngine, error) {
|
|
||||||
engine := &webrtc.MediaEngine{}
|
|
||||||
|
|
||||||
if err := codec.Register(engine); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
audioCodec := manager.capture.Audio().Codec()
|
|
||||||
if err := audioCodec.Register(engine); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return engine, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (manager *WebRTCManagerCtx) settingEngine(logger zerolog.Logger) webrtc.SettingEngine {
|
|
||||||
settings := webrtc.SettingEngine{
|
|
||||||
LoggerFactory: pionlog.New(logger),
|
|
||||||
}
|
|
||||||
|
|
||||||
//nolint
|
|
||||||
settings.SetEphemeralUDPPortRange(manager.config.EphemeralMin, manager.config.EphemeralMax)
|
|
||||||
settings.SetICETimeouts(disconnectedTimeout, failedTimeout, keepAliveInterval)
|
|
||||||
settings.SetNAT1To1IPs(manager.config.NAT1To1IPs, webrtc.ICECandidateTypeHost)
|
|
||||||
//settings.SetSRTPReplayProtectionWindow(512)
|
|
||||||
settings.SetLite(manager.config.ICELite)
|
|
||||||
|
|
||||||
return settings
|
|
||||||
}
|
|
||||||
|
|
||||||
func (manager *WebRTCManagerCtx) peerConfiguration() webrtc.Configuration {
|
func (manager *WebRTCManagerCtx) peerConfiguration() webrtc.Configuration {
|
||||||
if manager.config.ICELite {
|
if manager.config.ICELite {
|
||||||
return webrtc.Configuration{
|
return webrtc.Configuration{
|
||||||
|
Loading…
Reference in New Issue
Block a user