forked from fzwoch/obs-golang-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin.go
161 lines (130 loc) · 3.87 KB
/
plugin.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package main
// #cgo pkg-config: libobs
//
// #include <obs/obs-module.h>
//
// typedef char* (*get_name_t)(uintptr_t type_data);
// extern char* get_name(uintptr_t type_data);
//
// typedef uintptr_t (*create_t)(obs_data_t* settings, obs_source_t* source);
// extern uintptr_t create(obs_data_t* settings, obs_source_t* source);
//
// typedef void (*destroy_t)(uintptr_t data);
// extern void destroy(uintptr_t data);
//
// typedef obs_properties_t* (*get_properties_t)(uintptr_t data);
// extern obs_properties_t* get_properties(uintptr_t data);
//
// typedef void (*get_defaults_t)(obs_data_t* settings);
// extern void get_defaults(obs_data_t* settings);
//
// typedef void (*video_render_t)(uintptr_t data, gs_effect_t* effect);
// extern void video_render(uintptr_t data, gs_effect_t* effect);
//
// typedef uint32_t (*get_width_t)(uintptr_t data);
// extern uint32_t get_width(uintptr_t data);
//
// typedef uint32_t (*get_height_t)(uintptr_t data);
// extern uint32_t get_height(uintptr_t data);
//
// typedef void (*update_t)(uintptr_t data, obs_data_t* settings);
// extern void update(uintptr_t data, obs_data_t* settings);
//
// typedef void (*show_t)(uintptr_t data);
// extern void show(uintptr_t data);
//
// typedef void (*hide_t)(uintptr_t data);
// extern void hide(uintptr_t data);
import "C"
import (
"runtime/cgo"
"unsafe"
)
type ctx struct {
source *C.obs_source_t
settings *C.obs_data_t
}
var obsModulePointer *C.obs_module_t
//export obs_module_set_pointer
func obs_module_set_pointer(module *C.obs_module_t) {
obsModulePointer = module
}
//export obs_current_module
func obs_current_module() *C.obs_module_t {
return obsModulePointer
}
//export obs_module_ver
func obs_module_ver() C.uint32_t {
return C.LIBOBS_API_VER
}
var obs_plugin_id *C.char = C.CString("obs-golang-plugin")
var source = C.struct_obs_source_info{
id: obs_plugin_id,
_type: C.OBS_SOURCE_TYPE_INPUT,
output_flags: C.OBS_SOURCE_ASYNC_VIDEO | C.OBS_SOURCE_AUDIO | C.OBS_SOURCE_DO_NOT_DUPLICATE,
get_name: C.get_name_t(unsafe.Pointer(C.get_name)),
create: C.create_t(unsafe.Pointer(C.create)),
destroy: C.destroy_t(unsafe.Pointer(C.destroy)),
get_properties: C.get_properties_t(unsafe.Pointer(C.get_properties)),
get_defaults: C.get_defaults_t(unsafe.Pointer(C.get_defaults)),
video_render: C.video_render_t(unsafe.Pointer(C.video_render)),
get_width: C.get_width_t(unsafe.Pointer(C.get_width)),
get_height: C.get_height_t(unsafe.Pointer(C.get_height)),
update: C.update_t(unsafe.Pointer(C.update)),
show: C.show_t(unsafe.Pointer(C.show)),
hide: C.hide_t(unsafe.Pointer(C.hide)),
}
var obs_plugin_name *C.char = C.CString("OBS Golang Plugin")
//export get_name
func get_name(typeData C.uintptr_t) *C.char {
return obs_plugin_name
}
//export create
func create(settings *C.obs_data_t, source *C.obs_source_t) C.uintptr_t {
ctx := ctx{
source: source,
settings: settings,
}
return C.uintptr_t(cgo.NewHandle(ctx))
}
//export destroy
func destroy(data C.uintptr_t) {
cgo.Handle(data).Delete()
}
//export get_properties
func get_properties(data C.uintptr_t) *C.obs_properties_t {
properties := C.obs_properties_create()
return properties
}
//export get_defaults
func get_defaults(settings *C.obs_data_t) {
}
//export video_render
func video_render(data C.uintptr_t, effect *C.gs_effect_t) {
ctx := cgo.Handle(data).Value().(ctx)
// do something with ctx
_ = ctx
}
//export get_width
func get_width(data C.uintptr_t) C.uint32_t {
return 0
}
//export get_height
func get_height(data C.uintptr_t) C.uint32_t {
return 0
}
//export update
func update(data C.uintptr_t, settings *C.obs_data_t) {
}
//export show
func show(data C.uintptr_t) {
}
//export hide
func hide(data C.uintptr_t) {
}
//export obs_module_load
func obs_module_load() C.bool {
C.obs_register_source_s(&source, C.sizeof_struct_obs_source_info)
return true
}
func main() {}