mirror of
https://github.com/pion/mediadevices.git
synced 2026-04-22 15:57:27 +08:00
03900dcb1b
* wip * wip * Organize * Remove unnecessary change in camera_darwin.go filtering * wip * Make observer stop safe during startup * wip IsAvailable impl * Fix non-darwin builds * Lock bg loop to main thread and add comment * Remove fmt prints * Simplify isAvailable; Add timeout for Read darwin * Match comment with code * Change to singleton pattern; Add clearer safer state machine states; Change language from Stop to Destroy; Add new error for when observer is unavailable; * Add stubs for linux * Move cancel() up so its not dead code sometimes * Add stubs for Windows too * Remove StopObserver usage * Add camera tests * Add device observer tests * Fix multiple destroy calls bug; Call setup in start * Improve isAvailable * Improve string handling in device observer c * Add error handling in example * Add comment about setup vs start * Rename and organize device observer darwin * Explicitly case initial state for setup * Fix potential destroy goroutine leak; Use only modern build tag; Return err not nil for stubs; Improve comments * Close startDone channel on device observer stop not wait
30 lines
556 B
Go
30 lines
556 B
Go
package availability
|
|
|
|
import (
|
|
"errors"
|
|
)
|
|
|
|
var (
|
|
ErrObserverUnavailable = NewError("observer unavailable (not started or destroyed)")
|
|
ErrUnimplemented = NewError("not implemented")
|
|
ErrBusy = NewError("device or resource busy")
|
|
ErrNoDevice = NewError("no such device")
|
|
)
|
|
|
|
type errorString struct {
|
|
s string
|
|
}
|
|
|
|
func NewError(text string) error {
|
|
return &errorString{text}
|
|
}
|
|
|
|
func IsError(err error) bool {
|
|
var target *errorString
|
|
return errors.As(err, &target)
|
|
}
|
|
|
|
func (e *errorString) Error() string {
|
|
return e.s
|
|
}
|