From: Hraban Luyat Date: Sun, 5 Jul 2015 19:33:27 +0000 (+0100) Subject: Close routine for opus stream X-Git-Tag: v2.0.0~98 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=673f160c38830f8ce637cafda9c0bfb29f115d31;p=go-opus.git Close routine for opus stream --- diff --git a/stream.go b/stream.go index 31f8dae..5e0c863 100644 --- a/stream.go +++ b/stream.go @@ -81,6 +81,9 @@ func (s *Stream) Init(read io.Reader) error { } func (s *Stream) Read() ([]int16, error) { + if s.oggfile == nil { + return nil, fmt.Errorf("opus stream is uninitialized or already closed") + } pcm := make([]int16, xMAX_FRAME_SIZE) n := C.op_read( s.oggfile, @@ -92,3 +95,11 @@ func (s *Stream) Read() ([]int16, error) { } return pcm[:n], nil } + +func (s *Stream) Close() error { + if s.oggfile == nil { + return fmt.Errorf("opus stream is uninitialized or already closed") + } + C.op_free(s.oggfile) + return nil +}