Skip to content

Commit 666e569

Browse files
authored
[RSDK-9703] - Maintain dynamic resolution preference through reconfigures (viamrobotics#4738)
1 parent c473803 commit 666e569

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

robot/web/stream/server.go

+31
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,37 @@ func (server *Server) refreshVideoSources() {
658658
}
659659
existing, ok := server.videoSources[cam.Name().SDPTrackName()]
660660
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+
}
661692
existing.Swap(cam)
662693
continue
663694
}

robot/web/stream/state/state.go

+5
Original file line numberDiff line numberDiff line change
@@ -409,3 +409,8 @@ func (state *StreamState) unsubscribeH264Passthrough(ctx context.Context, id rtp
409409

410410
return nil
411411
}
412+
413+
// IsResized returns whether the stream is in a resized state.
414+
func (state *StreamState) IsResized() bool {
415+
return state.isResized
416+
}

0 commit comments

Comments
 (0)