forked from henrym/go-vlc
-
Notifications
You must be signed in to change notification settings - Fork 1
/
callback.go
89 lines (75 loc) · 2.35 KB
/
callback.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// This work is subject to the CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
// license. Its contents can be found at:
// http://creativecommons.org/publicdomain/zero/1.0
package vlc
//#include <stdlib.h>
//#include <vlc/vlc.h>
import "C"
import (
"unsafe"
)
// Used when hooking/unhooking events.
type eventData struct {
id int
t C.libvlc_event_type_t
f EventHandler
d interface{}
}
// Event callback handler.
type EventHandler func(evt *Event, userdata interface{})
//export goEventCB
func goEventCB(ep unsafe.Pointer, userdata unsafe.Pointer) {
e := (*C.libvlc_event_t)(ep)
evt := &Event{Type: EventType(e._type)}
evt.b.Write(e.u[:])
idptr := (*int)(userdata)
eventsLock.RLock()
ed, ok := events[*idptr]
eventsLock.RUnlock()
if !ok {
return // event data not found
}
ed.f(evt, ed.d)
}
// Used in Player.SetCallbacks() to render video to a custom memory location.
type memRenderReq struct {
lh LockHandler
uh UnlockHandler
dh DisplayHandler
ud interface{}
}
// Whenever a new video frame needs to be decoded, the lock callback is
// invoked. Depending on the video chroma, one or three pixel planes of
// adequate dimensions must be returned. Those planes must be aligned on
// 32-bytes boundaries.
//
// void* (*lock) (void** plane, void* userdata)
type LockHandler func(plane uintptr, userdata interface{}) uintptr
//export goLockCB
func goLockCB(userdata, plane unsafe.Pointer) unsafe.Pointer {
if req := (*memRenderReq)(userdata); req.lh != nil {
return unsafe.Pointer(req.lh(uintptr(plane), req.ud))
}
return nil
}
// When the video frame is decoded, the unlock callback is invoked. The
// second parameter to the callback is the return value of the lock callback.
// The third parameter conveys the pixel planes for convenience.
//
// void (*unlock) (void* picture, void* const* plane, void* userdata)
type UnlockHandler func(picture, plane uintptr, userdata interface{})
//export goUnlockCB
func goUnlockCB(userdata, picture, plane unsafe.Pointer) {
if req := (*memRenderReq)(userdata); req.uh != nil {
req.uh(uintptr(picture), uintptr(plane), req.ud)
}
}
type DisplayHandler func(picture uintptr, userdata interface{})
//export goDisplayCB
//
// void (*display) (void* picture, void* userdata)
func goDisplayCB(userdata, picture unsafe.Pointer) {
if req := (*memRenderReq)(userdata); req.dh != nil {
req.dh(uintptr(picture), req.ud)
}
}