Skip to content

Commit

Permalink
retain buffers while decoders alive
Browse files Browse the repository at this point in the history
  • Loading branch information
brian-armstrong-discord committed Feb 3, 2019
1 parent e5a3a6a commit 2c95337
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions avcodec.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
type avCodecDecoder struct {
decoder C.avcodec_decoder
mat C.opencv_mat
buf []byte
hasDecoded bool
maybeMP4 bool
}
Expand All @@ -41,6 +42,7 @@ func newAVCodecDecoder(buf []byte) (*avCodecDecoder, error) {
return &avCodecDecoder{
decoder: decoder,
mat: mat,
buf: buf,
maybeMP4: isMP4(buf),
}, nil
}
Expand Down Expand Up @@ -93,6 +95,7 @@ func (d *avCodecDecoder) DecodeTo(f *Framebuffer) error {
func (d *avCodecDecoder) Close() {
C.avcodec_decoder_release(d.decoder)
C.opencv_mat_release(d.mat)
d.buf = nil
}

func init() {
Expand Down
3 changes: 3 additions & 0 deletions giflib.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
type gifDecoder struct {
decoder C.giflib_decoder
mat C.opencv_mat
buf []byte
frameIndex int
}

Expand Down Expand Up @@ -64,6 +65,7 @@ func newGifDecoder(buf []byte) (*gifDecoder, error) {
return &gifDecoder{
decoder: decoder,
mat: mat,
buf: buf,
frameIndex: 0,
}, nil
}
Expand Down Expand Up @@ -91,6 +93,7 @@ func (d *gifDecoder) FrameHeader() (*ImageHeader, error) {
func (d *gifDecoder) Close() {
C.giflib_decoder_release(d.decoder)
C.opencv_mat_release(d.mat)
d.buf = nil
}

func (d *gifDecoder) Description() string {
Expand Down
3 changes: 3 additions & 0 deletions opencv.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ type Framebuffer struct {
type openCVDecoder struct {
decoder C.opencv_decoder
mat C.opencv_mat
buf []byte
hasReadHeader bool
hasDecoded bool
}
Expand Down Expand Up @@ -250,6 +251,7 @@ func newOpenCVDecoder(buf []byte) (*openCVDecoder, error) {
return &openCVDecoder{
mat: mat,
decoder: decoder,
buf: buf,
}, nil
}

Expand All @@ -274,6 +276,7 @@ func (d *openCVDecoder) Header() (*ImageHeader, error) {
func (d *openCVDecoder) Close() {
C.opencv_decoder_release(d.decoder)
C.opencv_mat_release(d.mat)
d.buf = nil
}

func (d *openCVDecoder) Description() string {
Expand Down

0 comments on commit 2c95337

Please sign in to comment.