-
Notifications
You must be signed in to change notification settings - Fork 110
/
camera.go
137 lines (120 loc) · 4.09 KB
/
camera.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package inject
import (
"context"
"github.com/pkg/errors"
"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"
)
// Camera is an injected camera.
type Camera struct {
camera.Camera
name resource.Name
RTPPassthroughSource rtppassthrough.Source
DoFunc func(ctx context.Context, cmd map[string]interface{}) (map[string]interface{}, 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
}
// NewCamera returns a new injected camera.
func NewCamera(name string) *Camera {
return &Camera{name: camera.Named(name)}
}
// Name returns the name of the resource.
func (c *Camera) Name() resource.Name {
return c.name
}
// NextPointCloud calls the injected NextPointCloud or the real version.
func (c *Camera) NextPointCloud(ctx context.Context) (pointcloud.PointCloud, error) {
if c.NextPointCloudFunc != nil {
return c.NextPointCloudFunc(ctx)
}
if c.Camera != nil {
return c.Camera.NextPointCloud(ctx)
}
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")
}
// Projector calls the injected Projector or the real version.
func (c *Camera) Projector(ctx context.Context) (transform.Projector, error) {
if c.ProjectorFunc != nil {
return c.ProjectorFunc(ctx)
}
if c.Camera != nil {
return c.Camera.Projector(ctx)
}
return nil, errors.New("Projector unimplemented")
}
// Properties calls the injected Properties or the real version.
func (c *Camera) Properties(ctx context.Context) (camera.Properties, error) {
if c.PropertiesFunc == nil {
return c.Camera.Properties(ctx)
}
return c.PropertiesFunc(ctx)
}
// Images calls the injected Images or the real version.
func (c *Camera) Images(ctx context.Context) ([]camera.NamedImage, resource.ResponseMetadata, error) {
if c.ImagesFunc != nil {
return c.ImagesFunc(ctx)
}
if c.Camera != nil {
return c.Camera.Images(ctx)
}
return nil, resource.ResponseMetadata{}, errors.New("Images unimplemented")
}
// Close calls the injected Close or the real version.
func (c *Camera) Close(ctx context.Context) error {
if c.CloseFunc != nil {
return c.CloseFunc(ctx)
}
if c.Camera != nil {
return c.Camera.Close(ctx)
}
return nil
}
// DoCommand calls the injected DoCommand or the real version.
func (c *Camera) DoCommand(ctx context.Context, cmd map[string]interface{}) (map[string]interface{}, error) {
if c.DoFunc != nil {
return c.DoFunc(ctx, cmd)
}
return c.Camera.DoCommand(ctx, cmd)
}
// SubscribeRTP calls the injected RTPPassthroughSource or returns an error if unimplemented.
func (c *Camera) SubscribeRTP(
ctx context.Context,
bufferSize int,
packetsCB rtppassthrough.PacketCallback,
) (rtppassthrough.Subscription, error) {
if c.RTPPassthroughSource != nil {
return c.RTPPassthroughSource.SubscribeRTP(ctx, bufferSize, packetsCB)
}
return rtppassthrough.NilSubscription, errors.New("SubscribeRTP unimplemented")
}
// Unsubscribe calls the injected RTPPassthroughSource or returns an error if unimplemented.
func (c *Camera) Unsubscribe(ctx context.Context, id rtppassthrough.SubscriptionID) error {
if c.RTPPassthroughSource != nil {
return c.RTPPassthroughSource.Unsubscribe(ctx, id)
}
return errors.New("Unsubscribe unimplemented")
}