From b6b0a967c1064b253078aa157a4cfa0d6ad5e065 Mon Sep 17 00:00:00 2001 From: randhid <35934754+randhid@users.noreply.github.com> Date: Thu, 16 Jan 2025 14:46:58 -0500 Subject: [PATCH] [RSDK-9458] Remove 'Stream' from Camera interface I - cosmetic + test changes (#4710) --- components/camera/camera.go | 11 -------- components/camera/replaypcd/replaypcd_test.go | 5 ---- components/camera/server.go | 6 ++++- components/camera/videosourcewrappers.go | 4 +++ robot/web/stream/server.go | 6 ++--- robot/web/stream/state/state.go | 6 ++--- testutils/inject/camera.go | 27 +++---------------- 7 files changed, 19 insertions(+), 46 deletions(-) diff --git a/components/camera/camera.go b/components/camera/camera.go index 9523e6fa2a7..92abc38d07a 100644 --- a/components/camera/camera.go +++ b/components/camera/camera.go @@ -107,17 +107,6 @@ type Camera interface { // // For more information, see the [Images method docs]. // -// Stream example: -// -// myCamera, err := camera.FromRobot(machine, "my_camera") -// -// // gets the stream from a camera -// stream, err := myCamera.Stream(context.Background()) -// -// // gets an image from the camera stream -// img, release, err := stream.Next(context.Background()) -// defer release() -// // NextPointCloud example: // // myCamera, err := camera.FromRobot(machine, "my_camera") diff --git a/components/camera/replaypcd/replaypcd_test.go b/components/camera/replaypcd/replaypcd_test.go index 90b397edc21..39a60203010 100644 --- a/components/camera/replaypcd/replaypcd_test.go +++ b/components/camera/replaypcd/replaypcd_test.go @@ -660,11 +660,6 @@ func TestReplayPCDUnimplementedFunctions(t *testing.T) { replayCamera, _, serverClose, err := createNewReplayPCDCamera(ctx, t, replayCamCfg, true) test.That(t, err, test.ShouldBeNil) - t.Run("Stream", func(t *testing.T) { - _, err := replayCamera.Stream(ctx, nil) - test.That(t, err.Error(), test.ShouldEqual, "Stream is unimplemented") - }) - err = replayCamera.Close(ctx) test.That(t, err, test.ShouldBeNil) diff --git a/components/camera/server.go b/components/camera/server.go index 036d2135d9a..3bb14f54be4 100644 --- a/components/camera/server.go +++ b/components/camera/server.go @@ -32,7 +32,11 @@ type serviceServer struct { func NewRPCServiceServer(coll resource.APIResourceCollection[Camera]) interface{} { logger := logging.NewLogger("camserver") imgTypes := make(map[string]ImageType) - return &serviceServer{coll: coll, logger: logger, imgTypes: imgTypes} + return &serviceServer{ + coll: coll, + logger: logger, + imgTypes: imgTypes, + } } // GetImage returns an image from a camera of the underlying robot. If a specific MIME type diff --git a/components/camera/videosourcewrappers.go b/components/camera/videosourcewrappers.go index d1e989e7f79..4c29a066dd9 100644 --- a/components/camera/videosourcewrappers.go +++ b/components/camera/videosourcewrappers.go @@ -18,6 +18,7 @@ import ( "go.viam.com/rdk/rimage/transform" ) +// FromVideoSource is DEPRECATED!!! Please implement cameras according to the camera.Camera interface. // FromVideoSource creates a Camera resource from a VideoSource. // Note: this strips away Reconfiguration and DoCommand abilities. // If needed, implement the Camera another way. For example, a webcam @@ -79,6 +80,7 @@ func (vs *videoSource) Unsubscribe(ctx context.Context, id rtppassthrough.Subscr return errors.New("Unsubscribe unimplemented") } +// NewPinholeModelWithBrownConradyDistortion is DEPRECATED!!! Please implement cameras according to the camera.Camera interface. // NewPinholeModelWithBrownConradyDistortion creates a transform.PinholeCameraModel from // a *transform.PinholeCameraIntrinsics and a *transform.BrownConrady. // If *transform.BrownConrady is `nil`, transform.PinholeCameraModel.Distortion @@ -95,6 +97,7 @@ func NewPinholeModelWithBrownConradyDistortion(pinholeCameraIntrinsics *transfor return cameraModel } +// NewVideoSourceFromReader is DEPRECATED!!! Please implement cameras according to the camera.Camera interface. // NewVideoSourceFromReader creates a VideoSource either with or without a projector. The stream type // argument is for detecting whether or not the resulting camera supports return // of pointcloud data in the absence of an implemented NextPointCloud function. @@ -140,6 +143,7 @@ func NewVideoSourceFromReader( }, nil } +// WrapVideoSourceWithProjector is DEPRECATED!!! Please implement cameras according to the camera.Camera interface. // WrapVideoSourceWithProjector creates a Camera either with or without a projector. The stream type // argument is for detecting whether or not the resulting camera supports return // of pointcloud data in the absence of an implemented NextPointCloud function. diff --git a/robot/web/stream/server.go b/robot/web/stream/server.go index 66e36d25fe5..dd6646dc245 100644 --- a/robot/web/stream/server.go +++ b/robot/web/stream/server.go @@ -22,7 +22,7 @@ import ( "go.viam.com/rdk/logging" "go.viam.com/rdk/resource" "go.viam.com/rdk/robot" - streamCamera "go.viam.com/rdk/robot/web/stream/camera" + camerautils "go.viam.com/rdk/robot/web/stream/camera" "go.viam.com/rdk/robot/web/stream/state" rutils "go.viam.com/rdk/utils" ) @@ -170,7 +170,7 @@ func (server *Server) AddStream(ctx context.Context, req *streampb.AddStreamRequ } // return error if resource is neither a camera nor audioinput - _, isCamErr := streamCamera.Camera(server.robot, streamStateToAdd.Stream) + _, isCamErr := camerautils.Camera(server.robot, streamStateToAdd.Stream) _, isAudioErr := audioinput.FromRobot(server.robot, resource.SDPTrackNameToShortName(streamStateToAdd.Stream.Name())) if isCamErr != nil && isAudioErr != nil { return nil, errors.Errorf("stream is neither a camera nor audioinput. streamName: %v", streamStateToAdd.Stream) @@ -307,7 +307,7 @@ func (server *Server) RemoveStream(ctx context.Context, req *streampb.RemoveStre shortName := resource.SDPTrackNameToShortName(streamToRemove.Stream.Name()) _, isAudioResourceErr := audioinput.FromRobot(server.robot, shortName) - _, isCameraResourceErr := streamCamera.Camera(server.robot, streamToRemove.Stream) + _, isCameraResourceErr := camerautils.Camera(server.robot, streamToRemove.Stream) if isAudioResourceErr != nil && isCameraResourceErr != nil { return &streampb.RemoveStreamResponse{}, nil diff --git a/robot/web/stream/state/state.go b/robot/web/stream/state/state.go index de4c0c03cc8..b885907f12a 100644 --- a/robot/web/stream/state/state.go +++ b/robot/web/stream/state/state.go @@ -19,7 +19,7 @@ import ( "go.viam.com/rdk/gostream" "go.viam.com/rdk/logging" "go.viam.com/rdk/robot" - streamCamera "go.viam.com/rdk/robot/web/stream/camera" + camerautils "go.viam.com/rdk/robot/web/stream/camera" ) // ErrClosed indicates that the StreamState is already closed. @@ -332,7 +332,7 @@ func (state *StreamState) tick() { } func (state *StreamState) streamH264Passthrough() error { - cam, err := streamCamera.Camera(state.robot, state.Stream) + cam, err := camerautils.Camera(state.robot, state.Stream) if err != nil { return err } @@ -393,7 +393,7 @@ func (state *StreamState) streamH264Passthrough() error { } func (state *StreamState) unsubscribeH264Passthrough(ctx context.Context, id rtppassthrough.SubscriptionID) error { - cam, err := streamCamera.Camera(state.robot, state.Stream) + cam, err := camerautils.Camera(state.robot, state.Stream) if err != nil { return err } diff --git a/testutils/inject/camera.go b/testutils/inject/camera.go index 975bb9b58d0..c724e2cfd64 100644 --- a/testutils/inject/camera.go +++ b/testutils/inject/camera.go @@ -7,7 +7,6 @@ import ( "go.viam.com/rdk/components/camera" "go.viam.com/rdk/components/camera/rtppassthrough" - "go.viam.com/rdk/gostream" "go.viam.com/rdk/pointcloud" "go.viam.com/rdk/resource" "go.viam.com/rdk/rimage/transform" @@ -21,14 +20,10 @@ type Camera struct { DoFunc func(ctx context.Context, cmd map[string]interface{}) (map[string]interface{}, error) ImageFunc func(ctx context.Context, mimeType string, extra map[string]interface{}) ([]byte, camera.ImageMetadata, error) ImagesFunc func(ctx context.Context) ([]camera.NamedImage, resource.ResponseMetadata, error) - StreamFunc func( - ctx context.Context, - errHandlers ...gostream.ErrorHandler, - ) (gostream.VideoStream, error) - NextPointCloudFunc func(ctx context.Context) (pointcloud.PointCloud, error) - ProjectorFunc func(ctx context.Context) (transform.Projector, error) - PropertiesFunc func(ctx context.Context) (camera.Properties, error) - CloseFunc func(ctx context.Context) error + NextPointCloudFunc func(ctx context.Context) (pointcloud.PointCloud, error) + ProjectorFunc func(ctx context.Context) (transform.Projector, error) + PropertiesFunc func(ctx context.Context) (camera.Properties, error) + CloseFunc func(ctx context.Context) error } // NewCamera returns a new injected camera. @@ -52,20 +47,6 @@ func (c *Camera) NextPointCloud(ctx context.Context) (pointcloud.PointCloud, err return nil, errors.New("NextPointCloud unimplemented") } -// Stream calls the injected Stream or the real version. -func (c *Camera) Stream( - ctx context.Context, - errHandlers ...gostream.ErrorHandler, -) (gostream.VideoStream, error) { - if c.StreamFunc != nil { - return c.StreamFunc(ctx, errHandlers...) - } - if c.Camera != nil { - return c.Camera.Stream(ctx, errHandlers...) - } - return nil, errors.Wrap(ctx.Err(), "no stream function available") -} - // Image calls the injected Image or the real version. func (c *Camera) Image(ctx context.Context, mimeType string, extra map[string]interface{}) ([]byte, camera.ImageMetadata, error) { if c.ImageFunc != nil {