Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RSDK-9703] - Maintain dynamic resolution preference through reconfigures #4738

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions robot/web/stream/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,37 @@ func (server *Server) refreshVideoSources() {
}
existing, ok := server.videoSources[cam.Name().SDPTrackName()]
if ok {
// Check stream state for the camera to see if it is in resized mode.
// If it is in resized mode, we want to apply the resize transformation to the
// video source before swapping it.
streamState, ok := server.nameToStreamState[cam.Name().SDPTrackName()]
if ok && streamState.IsResized() {
server.logger.Debugf("stream %q is resized attempting to reapply resize transformation", cam.Name().SDPTrackName())
mediaProps, err := existing.MediaProperties(server.closedCtx)
if err != nil {
server.logger.Errorf("error getting media properties from resize source: %v", err)
} else {
// resizeVideoSource should always have a width and height set.
height, width := mediaProps.Height, mediaProps.Width
if height != 0 && width != 0 {
server.logger.Debugf(
"resizing video source to width %d and height %d",
width, height,
)
resizer := gostream.NewResizeVideoSource(cam, width, height)
existing.Swap(resizer)
continue
}
}
// If we can't get the media properties or the width and height are 0, we fall back to
// the original source and need to notify the stream state that the source is no longer
// resized.
server.logger.Warnf("falling back to original source for stream %q", cam.Name().SDPTrackName())
err = streamState.Reset()
if err != nil {
server.logger.Errorf("error resetting stream %q: %v", cam.Name().SDPTrackName(), err)
}
}
Comment on lines +661 to +691
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to test this within an existing test?

existing.Swap(cam)
continue
}
Expand Down
5 changes: 5 additions & 0 deletions robot/web/stream/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,3 +409,8 @@ func (state *StreamState) unsubscribeH264Passthrough(ctx context.Context, id rtp

return nil
}

// IsResized returns whether the stream is in a resized state.
func (state *StreamState) IsResized() bool {
return state.isResized
}
Comment on lines +414 to +416
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this thread safe?

Loading