Use typed OpenAL device and context handles
This commit is contained in:
committed by
Brandon McGinty
parent
6b7e3cdc20
commit
4fe32ede70
@@ -245,7 +245,7 @@ Priority 3: configuration, UI, and binding hardening
|
|||||||
every line contains ']' when timestamps are hidden and can panic otherwise.
|
every line contains ']' when timestamps are hidden and can panic otherwise.
|
||||||
Track rune boundaries and use safe timestamp parsing/fallbacks.
|
Track rune boundaries and use safe timestamp parsing/fallbacks.
|
||||||
|
|
||||||
32. OpenAL binding needs API and unsafe hardening
|
[x] 32. OpenAL binding needs API and unsafe hardening
|
||||||
Files: gumble/go-openal/openal/*.go
|
Files: gumble/go-openal/openal/*.go
|
||||||
Many public slice APIs unconditionally use &slice[0] and panic for empty
|
Many public slice APIs unconditionally use &slice[0] and panic for empty
|
||||||
input (NewBuffers(0), Delete empty lists, SetData empty data, GetIntegerv
|
input (NewBuffers(0), Delete empty lists, SetData empty data, GetIntegerv
|
||||||
|
|||||||
@@ -105,13 +105,11 @@ func GetStrings(param int32) []string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Device struct {
|
type Device struct {
|
||||||
// Use uintptr instead of *C.ALCdevice.
|
handle *C.ALCdevice
|
||||||
// On Mac OS X, this value is 0x18 and might cause crash with a raw pointer.
|
|
||||||
handle uintptr
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *Device) getError() uint32 {
|
func (self *Device) getError() uint32 {
|
||||||
return uint32(C.alcGetError((*C.ALCdevice)(unsafe.Pointer(self.handle))))
|
return uint32(C.alcGetError(self.handle))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Err() returns the most recent error generated
|
// Err() returns the most recent error generated
|
||||||
@@ -144,12 +142,10 @@ func OpenDevice(name string) *Device {
|
|||||||
if h == nil {
|
if h == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return &Device{uintptr((unsafe.Pointer)(h))}
|
return &Device{h}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *Device) cHandle() *C.ALCdevice {
|
func (self *Device) cHandle() *C.ALCdevice { return self.handle }
|
||||||
return (*C.ALCdevice)(unsafe.Pointer(self.handle))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (self *Device) CloseDevice() bool {
|
func (self *Device) CloseDevice() bool {
|
||||||
//TODO: really a method? or not?
|
//TODO: really a method? or not?
|
||||||
@@ -163,7 +159,7 @@ func (self *Device) CreateContext() *Context {
|
|||||||
if c == nil {
|
if c == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return &Context{uintptr(unsafe.Pointer(c))}
|
return &Context{c}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *Device) GetIntegerv(param uint32, size uint32) (result []int32) {
|
func (self *Device) GetIntegerv(param uint32, size uint32) (result []int32) {
|
||||||
@@ -193,7 +189,7 @@ func CaptureOpenDevice(name string, freq uint32, format Format, size uint32) *Ca
|
|||||||
if h == nil {
|
if h == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return &CaptureDevice{Device{uintptr(unsafe.Pointer(h))}, uint32(format.SampleSize())}
|
return &CaptureDevice{Device{h}, uint32(format.SampleSize())}
|
||||||
}
|
}
|
||||||
|
|
||||||
// XXX: Override Device.CloseDevice to make sure the correct
|
// XXX: Override Device.CloseDevice to make sure the correct
|
||||||
@@ -273,9 +269,7 @@ func (self *CaptureDevice) CapturedSamples() (size uint32) {
|
|||||||
// of the OpenAL state machine. Only one context can
|
// of the OpenAL state machine. Only one context can
|
||||||
// be active in a given process.
|
// be active in a given process.
|
||||||
type Context struct {
|
type Context struct {
|
||||||
// Use uintptr instead of *C.ALCcontext
|
handle *C.ALCcontext
|
||||||
// On Mac OS X, this value is 0x19 and might cause crash with a raw pointer.
|
|
||||||
handle uintptr
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// A context that doesn't exist, useful for certain
|
// A context that doesn't exist, useful for certain
|
||||||
@@ -283,9 +277,7 @@ type Context struct {
|
|||||||
// details).
|
// details).
|
||||||
var NullContext Context
|
var NullContext Context
|
||||||
|
|
||||||
func (self *Context) cHandle() *C.ALCcontext {
|
func (self *Context) cHandle() *C.ALCcontext { return self.handle }
|
||||||
return (*C.ALCcontext)(unsafe.Pointer(self.handle))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Renamed, was MakeContextCurrent.
|
// Renamed, was MakeContextCurrent.
|
||||||
func (self *Context) Activate() bool {
|
func (self *Context) Activate() bool {
|
||||||
@@ -305,15 +297,15 @@ func (self *Context) Suspend() {
|
|||||||
// Renamed, was DestroyContext.
|
// Renamed, was DestroyContext.
|
||||||
func (self *Context) Destroy() {
|
func (self *Context) Destroy() {
|
||||||
C.alcDestroyContext(self.cHandle())
|
C.alcDestroyContext(self.cHandle())
|
||||||
self.handle = uintptr(unsafe.Pointer(nil))
|
self.handle = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Renamed, was GetContextsDevice.
|
// Renamed, was GetContextsDevice.
|
||||||
func (self *Context) GetDevice() *Device {
|
func (self *Context) GetDevice() *Device {
|
||||||
return &Device{uintptr(unsafe.Pointer(C.alcGetContextsDevice(self.cHandle())))}
|
return &Device{C.alcGetContextsDevice(self.cHandle())}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Renamed, was GetCurrentContext.
|
// Renamed, was GetCurrentContext.
|
||||||
func CurrentContext() *Context {
|
func CurrentContext() *Context {
|
||||||
return &Context{uintptr(unsafe.Pointer(C.alcGetCurrentContext()))}
|
return &Context{C.alcGetCurrentContext()}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user