go-pus/stream_errors.go
Randy Reddig 25a249fbd5 feat: build without libopusfile using go build tag
This patch introduces a new build tag `nolibopusfile` that conditionally
compiles out the code that imports `libopusfile`. This enables a static
binary build on Alpine Linux, which doesn’t have a static `libopusfile`.

Tests still work:

```sh
go test -tags nolibopusfile ./...
go test ./...
```

We could also have moved all libopusfile related code (i.e. Stream) into
a separate sub-package, but that would break backwards compatibility.
This feature is too unpopular to justify introducing a new major
version.

See also: https://github.com/hraban/opus/pull/24
2020-07-10 13:54:23 +01:00

76 lines
2 KiB
Go

// Copyright © 2015-2017 Go Opus Authors (see AUTHORS file)
//
// License for use of this code is detailed in the LICENSE file
// +build !nolibopusfile
package opus
/*
#cgo pkg-config: opusfile
#include <opusfile.h>
*/
import "C"
// StreamError represents an error from libopusfile.
type StreamError int
var _ error = StreamError(0)
// Libopusfile errors. The names are copied verbatim from the libopusfile
// library.
const (
ErrStreamFalse = StreamError(C.OP_FALSE)
ErrStreamEOF = StreamError(C.OP_EOF)
ErrStreamHole = StreamError(C.OP_HOLE)
ErrStreamRead = StreamError(C.OP_EREAD)
ErrStreamFault = StreamError(C.OP_EFAULT)
ErrStreamImpl = StreamError(C.OP_EIMPL)
ErrStreamInval = StreamError(C.OP_EINVAL)
ErrStreamNotFormat = StreamError(C.OP_ENOTFORMAT)
ErrStreamBadHeader = StreamError(C.OP_EBADHEADER)
ErrStreamVersion = StreamError(C.OP_EVERSION)
ErrStreamNotAudio = StreamError(C.OP_ENOTAUDIO)
ErrStreamBadPacked = StreamError(C.OP_EBADPACKET)
ErrStreamBadLink = StreamError(C.OP_EBADLINK)
ErrStreamNoSeek = StreamError(C.OP_ENOSEEK)
ErrStreamBadTimestamp = StreamError(C.OP_EBADTIMESTAMP)
)
func (i StreamError) Error() string {
switch i {
case ErrStreamFalse:
return "OP_FALSE"
case ErrStreamEOF:
return "OP_EOF"
case ErrStreamHole:
return "OP_HOLE"
case ErrStreamRead:
return "OP_EREAD"
case ErrStreamFault:
return "OP_EFAULT"
case ErrStreamImpl:
return "OP_EIMPL"
case ErrStreamInval:
return "OP_EINVAL"
case ErrStreamNotFormat:
return "OP_ENOTFORMAT"
case ErrStreamBadHeader:
return "OP_EBADHEADER"
case ErrStreamVersion:
return "OP_EVERSION"
case ErrStreamNotAudio:
return "OP_ENOTAUDIO"
case ErrStreamBadPacked:
return "OP_EBADPACKET"
case ErrStreamBadLink:
return "OP_EBADLINK"
case ErrStreamNoSeek:
return "OP_ENOSEEK"
case ErrStreamBadTimestamp:
return "OP_EBADTIMESTAMP"
default:
return "libopusfile error: %d (unknown code)"
}
}