Skip to content

Commit

Permalink
[RSDK-9458] Remove 'Stream' from Camera interface I - cosmetic + test…
Browse files Browse the repository at this point in the history
… changes (#4710)
  • Loading branch information
randhid authored Jan 16, 2025
1 parent 89dbfcb commit b6b0a96
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 46 deletions.
11 changes: 0 additions & 11 deletions components/camera/camera.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
5 changes: 0 additions & 5 deletions components/camera/replaypcd/replaypcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 5 additions & 1 deletion components/camera/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions components/camera/videosourcewrappers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions robot/web/stream/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions robot/web/stream/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
27 changes: 4 additions & 23 deletions testutils/inject/camera.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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.
Expand All @@ -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 {
Expand Down

0 comments on commit b6b0a96

Please sign in to comment.