-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimage_source_stream.go
47 lines (42 loc) · 1.16 KB
/
image_source_stream.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
package gostream
import (
"context"
)
// streamSource will stream a source of images forver to the view until the given context tells it to cancel.
func streamSource(ctx context.Context, once func(), is ImageSource, name string, view View) {
if once != nil {
once()
}
stream := view.ReserveStream(name)
select {
case <-ctx.Done():
return
case <-view.StreamingReady():
}
for {
select {
case <-ctx.Done():
return
default:
}
frame, release, err := is.Next(ctx)
if err != nil {
Logger.Debugw("error getting frame", "error", err)
continue
}
select {
case <-ctx.Done():
return
case stream.InputFrames() <- FrameReleasePair{frame, release}:
}
}
}
// StreamSource streams the given image source to the view forever until context signals cancelation.
func StreamSource(ctx context.Context, is ImageSource, view View) {
streamSource(ctx, nil, is, "", view)
}
// StreamNamedSource streams the given image source to the view forever until context signals cancelation.
// The given name is used to identify the stream.
func StreamNamedSource(ctx context.Context, is ImageSource, name string, view View) {
streamSource(ctx, nil, is, name, view)
}