@@ -658,6 +658,37 @@ func (server *Server) refreshVideoSources() {
658
658
}
659
659
existing , ok := server .videoSources [cam .Name ().SDPTrackName ()]
660
660
if ok {
661
+ // Check stream state for the camera to see if it is in resized mode.
662
+ // If it is in resized mode, we want to apply the resize transformation to the
663
+ // video source before swapping it.
664
+ streamState , ok := server .nameToStreamState [cam .Name ().SDPTrackName ()]
665
+ if ok && streamState .IsResized () {
666
+ server .logger .Debugf ("stream %q is resized attempting to reapply resize transformation" , cam .Name ().SDPTrackName ())
667
+ mediaProps , err := existing .MediaProperties (server .closedCtx )
668
+ if err != nil {
669
+ server .logger .Errorf ("error getting media properties from resize source: %v" , err )
670
+ } else {
671
+ // resizeVideoSource should always have a width and height set.
672
+ height , width := mediaProps .Height , mediaProps .Width
673
+ if height != 0 && width != 0 {
674
+ server .logger .Debugf (
675
+ "resizing video source to width %d and height %d" ,
676
+ width , height ,
677
+ )
678
+ resizer := gostream .NewResizeVideoSource (cam , width , height )
679
+ existing .Swap (resizer )
680
+ continue
681
+ }
682
+ }
683
+ // If we can't get the media properties or the width and height are 0, we fall back to
684
+ // the original source and need to notify the stream state that the source is no longer
685
+ // resized.
686
+ server .logger .Warnf ("falling back to original source for stream %q" , cam .Name ().SDPTrackName ())
687
+ err = streamState .Reset ()
688
+ if err != nil {
689
+ server .logger .Errorf ("error resetting stream %q: %v" , cam .Name ().SDPTrackName (), err )
690
+ }
691
+ }
661
692
existing .Swap (cam )
662
693
continue
663
694
}
0 commit comments