-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathframe_decompressor_mjpeg.go
55 lines (43 loc) · 1.02 KB
/
frame_decompressor_mjpeg.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
package camera
import (
"fmt"
"image"
"io"
"github.com/mattn/go-mjpeg"
)
type frameDecompressorMJPEG struct {
Format Format
FrameWriter io.WriteCloser
MJPEGDecoder *mjpeg.Decoder
}
var _ FrameDecompressor = (*frameDecompressorMJPEG)(nil)
func newFrameDecompressorMJPEG() *frameDecompressorMJPEG {
r, w := io.Pipe()
return &frameDecompressorMJPEG{
FrameWriter: w,
MJPEGDecoder: mjpeg.NewDecoder(r, "image/jpeg"),
}
}
func (d *frameDecompressorMJPEG) Close() error {
return d.FrameWriter.Close()
}
func (d *frameDecompressorMJPEG) NewImage() image.Image {
return nil
}
func (d *frameDecompressorMJPEG) WriteCompressed(
compressed FramesCompressed,
) error {
_, err := d.FrameWriter.Write(compressed.Bytes())
return err
}
func (d *frameDecompressorMJPEG) DecompressNext() (Frame, error) {
img, err := d.MJPEGDecoder.Decode()
if err != nil {
return nil, fmt.Errorf("unable to decode the frame: %w", err)
}
return imageWrapper{img}, nil
}
func (d *frameDecompressorMJPEG) ReleaseFrame(
frame Frame,
) {
}