mirror of
https://github.com/pion/mediadevices.git
synced 2025-09-27 04:46:10 +08:00

* Fixes frame.FormatI420 in avfoundation * Fixes avfoundation: frame size which causes panic when using NV12 * avfoundation: uses CVPixelBufferGetDataSize() as frame buffer size frame: fix frame size checking for YUY2, UYVY * add camera_darwin_test
55 lines
769 B
Go
55 lines
769 B
Go
package avfoundation
|
|
|
|
import "C"
|
|
import (
|
|
"sync"
|
|
"unsafe"
|
|
)
|
|
|
|
var mu sync.Mutex
|
|
var nextID handleID
|
|
|
|
type dataCb func(data []byte)
|
|
|
|
var handles = make(map[handleID]dataCb)
|
|
|
|
type handleID int
|
|
|
|
//export onData
|
|
func onData(userData unsafe.Pointer, buf unsafe.Pointer, length C.int) {
|
|
handleNum := (*C.int)(userData)
|
|
cb, ok := lookup(handleID(*handleNum))
|
|
if ok {
|
|
data := C.GoBytes(buf, length)
|
|
cb(data)
|
|
}
|
|
}
|
|
|
|
func register(fn dataCb) handleID {
|
|
mu.Lock()
|
|
defer mu.Unlock()
|
|
|
|
nextID++
|
|
for handles[nextID] != nil {
|
|
nextID++
|
|
}
|
|
handles[nextID] = fn
|
|
|
|
return nextID
|
|
}
|
|
|
|
func lookup(i handleID) (cb dataCb, ok bool) {
|
|
mu.Lock()
|
|
defer mu.Unlock()
|
|
|
|
cb, ok = handles[i]
|
|
return
|
|
}
|
|
|
|
func unregister(i handleID) {
|
|
mu.Lock()
|
|
defer mu.Unlock()
|
|
|
|
delete(handles, i)
|
|
}
|