Skip to content

[RSDK-9823] - Add TestStreamMediaBehavior and logic to support it #4893

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

Closed
wants to merge 4 commits into from

Conversation

hexbabe
Copy link
Member

@hexbabe hexbabe commented Apr 4, 2025

https://viam.atlassian.net/browse/RSDK-9823

Overview

Adds TestStreamMediaBehavior to check that calling SetStreamOptions actually changes the stream's resolution and that resetting it brings it back to the original state. Also confirms streams survive robot reconfigurations.

Potential Issues Sean P brought up

  • Couldn't put the test directly in the webstream package because of import cycles.
  • Didn't want to add client-side H264 decoding just for the test (dependency headaches).

Workarounds

Used the normal client APIs (SetStreamOptions, etc.) for the main flow.

Workaround 1 (Package Cycle):

Added a small interface (streamServerGetter) and helper methods (GetStreamServer, GetVideoSourceForTest) so the test (outside webstream) could peek at the server's video source properties after resize calls to confirm the internal change.

Workaround 2 (Reset Check):

Checking the internal video source properties immediately after the reset swap is results in a race condition (showed old dimensions).
So, we first check the intended state by looking up the camera resource directly on the server (robot.ResourceByName).

After that, to confirm the stream output reverted without decoding video, we compare the final RTP packet payload size to the initial size recorded at the start. Since the resized streams use different encoding paths, matching the original packet size strongly indicates the stream reverted to the original passthrough format.

@viambot viambot added the safe to test This pull request is marked safe to test from a trusted zone label Apr 4, 2025
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Apr 4, 2025
@hexbabe hexbabe requested a review from Copilot April 4, 2025 21:01
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Comment on lines 713 to 716
robot.Reconfigure(ctx, newCfg)
test.That(t, err, test.ShouldBeNil)

webSvc.Reconfigure(ctx, nil, resource.Config{})
Copy link
Preview

Copilot AI Apr 4, 2025

Choose a reason for hiding this comment

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

The error check on 'err' following robot.Reconfigure may be misleading since 'robot.Reconfigure' does not appear to assign a new error value. Consider capturing and verifying any errors returned by the reconfiguration functions if applicable.

Suggested change
robot.Reconfigure(ctx, newCfg)
test.That(t, err, test.ShouldBeNil)
webSvc.Reconfigure(ctx, nil, resource.Config{})
err := robot.Reconfigure(ctx, newCfg)
test.That(t, err, test.ShouldBeNil)
err = webSvc.Reconfigure(ctx, nil, resource.Config{})
test.That(t, err, test.ShouldBeNil)

Copilot is powered by AI, so mistakes are possible. Review output carefully before use.

@hexbabe hexbabe marked this pull request as ready for review April 4, 2025 21:21
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Apr 4, 2025
@hexbabe hexbabe requested a review from Copilot April 4, 2025 21:23
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (2)

robot/web/stream/stream_test.go:712

  • Assigning newCfg as an alias to origCfg may lead to unintended side effects if newCfg is modified later. Consider creating a deep copy of origCfg to avoid potential issues during reconfiguration.
newCfg := origCfg

robot/web/stream/stream_test.go:669

  • Using the original ctx for unsubscribe may be less appropriate if the subscription has its own context. Consider using the subscription-specific context (subCtx) or clarifying why the original ctx is preferred.
unsubscribeErr := rtpSource.Unsubscribe(ctx, sub.ID) // Use original ctx for unsubscribe

@hexbabe hexbabe requested review from nicksanford and seanavery April 7, 2025 14:35

ctx, robot, addr, webSvc, streamServer := setupRealRobot(t, origCfg, logger)
if streamServer == nil {
t.Skip("Skipping test; CGO may be disabled, stream server is nil")
Copy link
Member

Choose a reason for hiding this comment

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

When in CI is CGO disabled?

Copy link
Member

Choose a reason for hiding this comment

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

Doesn't this build directive make it impossible to build this without CGO?

Copy link
Member Author

Choose a reason for hiding this comment

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

you're right, read up on build directives.

// Pass a blank logger to setupRealRobot to prevent race conditions with test logger usage in background goroutines.
ctx, robot, addr, webSvc, streamServer := setupRealRobot(t, origCfg, logging.NewBlankLogger(""))
if streamServer == nil {
t.Fatal("stream server is nil. CGO may be disabled.")
Copy link
Member

Choose a reason for hiding this comment

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

Isn't this impossible given the build directive on line 1?

Comment on lines 599 to 602
props, err := camClient.Properties(ctx)
test.That(t, err, test.ShouldBeNil)
test.That(t, props.IntrinsicParams.Width, test.ShouldEqual, 1280)
test.That(t, props.IntrinsicParams.Height, test.ShouldEqual, 720)
Copy link
Member

Choose a reason for hiding this comment

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

What does this have to do with the stream server?

Copy link
Member

Choose a reason for hiding this comment

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

If you are trying to assert about the size of the image that the camera is returning, call Image(), decode the image, and assert on the dimensions.

Copy link
Member Author

Choose a reason for hiding this comment

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

Discussed offline why asserting on the image is not the right approach, Nick replied that we should be decoding RTP packets and checking the frame there. I want to confirm before trying that we should be making this file cgo and using the libav h264 decoder to decode the packets. @nicksanford

Copy link
Member

Choose a reason for hiding this comment

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

Confirmed.

If you do need to enable cgo in tests, make a new test file with just the stream server tests that depend on CGO (that can be be flagged off if we need to build RDK without cgo).

…vant); Add extended comment about orignal ctx usage
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Apr 9, 2025
Comment on lines +746 to +747
test.That(t, mediaProps.Width, test.ShouldEqual, 640)
test.That(t, mediaProps.Height, test.ShouldEqual, 360)
Copy link
Member Author

Choose a reason for hiding this comment

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

^

@hexbabe
Copy link
Member Author

hexbabe commented Apr 16, 2025

Closed. Won't do. See Jira.

@hexbabe hexbabe closed this Apr 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
safe to test This pull request is marked safe to test from a trusted zone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants