add Video error return.

This commit is contained in:
Miroslav Šedivý 2021-02-05 18:07:58 +01:00
parent f62d36ac4f
commit 761f6d8a8f
3 changed files with 15 additions and 5 deletions

View File

@ -168,8 +168,9 @@ func (manager *CaptureManagerCtx) Audio() types.StreamManager {
return manager.audio
}
func (manager *CaptureManagerCtx) Video(videoID string) types.StreamManager {
return manager.videos[videoID]
func (manager *CaptureManagerCtx) Video(videoID string) (types.StreamManager, bool) {
video, ok := manager.videos[videoID]
return video, ok
}
func (manager *CaptureManagerCtx) VideoIDs() []string {

View File

@ -37,7 +37,7 @@ type CaptureManager interface {
Broadcast() BroadcastManager
Screencast() ScreencastManager
Audio() StreamManager
Video(videoID string) StreamManager
Video(videoID string) (StreamManager, bool)
VideoIDs() []string
StartStream()

View File

@ -57,7 +57,11 @@ func (manager *WebRTCManagerCtx) Start() {
videoIDs := manager.capture.VideoIDs()
manager.videoTracks = map[string]*webrtc.TrackLocalStaticSample{}
for _, videoID := range videoIDs {
video := manager.capture.Video(videoID)
video, ok := manager.capture.Video(videoID)
if !ok {
manager.logger.Warn().Str("videoID", videoID).Msg("video stream not found, skipping")
continue
}
track, err := webrtc.NewTrackLocalStaticSample(video.Codec().Capability, "video", "stream")
if err != nil {
@ -218,7 +222,12 @@ func (manager *WebRTCManagerCtx) mediaEngine() (*webrtc.MediaEngine, error) {
engine := &webrtc.MediaEngine{}
// all videos must have the same codec
videoCodec := manager.capture.Video(manager.defaultVideoID).Codec()
video, ok := manager.capture.Video(manager.defaultVideoID)
if !ok {
return nil, fmt.Errorf("default video track not found")
}
videoCodec := video.Codec()
if err := videoCodec.Register(engine); err != nil {
return nil, err
}