-
Notifications
You must be signed in to change notification settings - Fork 2
/
ndigoAdditional.go
220 lines (179 loc) · 6.65 KB
/
ndigoAdditional.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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
package ndigo
/*
#cgo CFLAGS: -Wno-deprecated-declarations
#cgo linux LDFLAGS: -L/usr/local/lib -lndi
#cgo darwin LDFLAGS: -Wl,-rpath,/Library/NDI\ SDK\ for\ Apple/lib/macOS -L/Library/NDI\ SDK\ for\ Apple/lib/macOS -lndi
#cgo windows LDFLAGS: -LC:/Program\ Files/NDI/NDI\ 5\ Runtime/v5 -lProcessing.NDI.Lib.x64
#include <stdlib.h>
#include "include/Processing.NDI.Lib.h"
#include "cgo_helpers.h"
*/
import "C"
import (
"fmt"
"runtime"
"strconv"
"unsafe"
)
type SourceType2 struct {
Name string
URLAddress string
}
func FindGetCurrentSources2(instance FindInstanceType) []*SourceType2 {
var pNoSources C.uint32_t
pSources := C.NDIlib_find_get_current_sources(C.NDIlib_find_instance_t(instance), &pNoSources)
if pNoSources == 0 {
return nil
}
sources := (*[1 << 28]C.NDIlib_source_t)(unsafe.Pointer(pSources))[:pNoSources:pNoSources]
result := make([]*SourceType2, pNoSources)
for i, source := range sources {
result[i] = &SourceType2{
Name: C.GoString(source.p_ndi_name),
URLAddress: C.GoString(*(**C.char)(unsafe.Pointer(&source.anon0))),
}
}
return result
}
func FindWaitForSources2(instance FindInstanceType, timeoutInMS uint32) bool {
return (bool)(C.NDIlib_find_wait_for_sources(C.NDIlib_find_instance_t(instance), C.uint32_t(timeoutInMS)))
}
func SendGetTally2(pInstance SendInstanceType, pTally *TallyType, timeoutInMs uint32) bool {
var tally C.NDIlib_tally_t
__ret := C.NDIlib_send_get_tally(C.NDIlib_send_instance_t(pInstance), &tally, 1000)
//now apply OnPreview and onProgram....
pTally.OnPreview = (bool)(tally.on_preview)
pTally.OnProgram = (bool)(tally.on_program)
__v := (bool)(__ret)
return __v
}
func RecvGetQueue2(pInstance RecvInstanceType, pTotal *RecvQueueType) {
var total C.NDIlib_recv_queue_t
cpInstance, cpInstanceAllocMap := *(*C.NDIlib_recv_instance_t)(unsafe.Pointer(&pInstance)), cgoAllocsUnknown
C.NDIlib_recv_get_queue(cpInstance, &total)
runtime.KeepAlive(cpInstanceAllocMap)
pTotal.VideoFrames = int32(total.video_frames)
pTotal.AudioFrames = int32(total.audio_frames)
pTotal.MetadataFrames = int32(total.metadata_frames)
}
type VideoFrameV2Type2 C.NDIlib_video_frame_v2_t
func (t VideoFrameV2Type2) FrameFormatType() int {
return int(t.frame_format_type)
}
func (t VideoFrameV2Type2) Timecode() int64 {
return int64(t.timecode * 100)
}
func (t VideoFrameV2Type2) Timestamp() int64 {
return int64(t.timestamp * 100)
}
func (t VideoFrameV2Type2) FrameFourCC() FourCCVideoType {
return FourCCVideoType(t.FourCC)
}
func (t VideoFrameV2Type2) Xres() int {
return int(t.xres)
}
func (t VideoFrameV2Type2) Yres() int {
return int(t.yres)
}
func (t VideoFrameV2Type2) LineStrideInBytesOrDataSizeInBytes() int {
//if t.FourCC is not compressed then its line stride...
//if t.FourCC is compressed then its Data Size
s := *(**C.int)(unsafe.Pointer(&t.anon0))
intVar, _ := strconv.Atoi(fmt.Sprintf("%d", s))
return intVar
}
func (t VideoFrameV2Type2) Data() []byte {
// lineStrideOrDataSize := t.LineStrideInBytesOrDataSizeInBytes()
size := (t.Xres() * t.Yres() * 2)
v := make([]byte, size)
d := (*[1 << 30]byte)(unsafe.Pointer(t.p_data)) // Read
copy(v, d[:])
return v
// b := v[:lineStrideOrDataSize]
// return b
// size := (t.Xres() * t.Yres() * 2)
//I need to stop C.GoString from doing bad things and rmeoving chars
//str := C.GoString((*C.char)(unsafe.Pointer(t.p_data)))
//if the image is pure black.... C.GoString has rather rudely removed those blacks.
//tmp := []byte(str)
//return tmp
}
func (t VideoFrameV2Type2) FrameRateN() int {
return int(t.frame_rate_N)
}
func (t VideoFrameV2Type2) FrameRateD() int {
return int(t.frame_rate_D)
}
type AudioFrameV3Type2 C.NDIlib_audio_frame_v3_t
func (t AudioFrameV3Type2) NoSamples() int {
return int(t.no_samples)
}
func (t AudioFrameV3Type2) NoChannels() int {
return int(t.no_channels)
}
func (t AudioFrameV3Type2) SampleRate() int {
return int(t.sample_rate)
}
func (t AudioFrameV3Type2) FrameFourCC() FourCCAudioType {
return FourCCAudioType(t.FourCC)
}
func (t AudioFrameV3Type2) ChannelStrideInBytesOrDataSizeInBytes() int {
//if t.FourCC is not compressed then its channel stride...
//if t.FourCC is compressed then its Data Size
s := *(**C.int)(unsafe.Pointer(&t.anon0))
intVar, _ := strconv.Atoi(fmt.Sprintf("%d", s))
return intVar
}
func (t AudioFrameV3Type2) Data() []byte {
//return []byte(C.GoString((*C.char)(unsafe.Pointer(t.p_data))))
// samples := t.NoSamples()
// channels := t.NoChannels()
channelStride := *(*C.int)(unsafe.Pointer(&t.anon0[0]))
size := (channelStride * t.no_channels)
// log.Printf("channelStride: %d, samples: %d, channels: %d, size: %d", channelStride, samples, channels, size)
return C.GoBytes(unsafe.Pointer(t.p_data), C.int(size))
// v := make([]byte, size)
// d := (*[1 << 30]byte)(unsafe.Pointer(t.p_data)) // Read
// copy(v, d[:])
// return v
}
func (t AudioFrameV3Type2) Timestamp() int64 {
return int64(t.timestamp * 100)
}
type MetadataFrameType2 C.NDIlib_metadata_frame_t
func RecvCaptureV32(pInstance RecvInstanceType, pVideoData *VideoFrameV2Type2, pAudioData *AudioFrameV3Type2, pMetadata *MetadataFrameType2, timeoutInMs uint32) FrameType {
cpInstance, cpInstanceAllocMap := *(*C.NDIlib_recv_instance_t)(unsafe.Pointer(&pInstance)), cgoAllocsUnknown
// cpVideoData, cpVideoDataAllocMap := pVideoData.PassRef()
// cpAudioData, cpAudioDataAllocMap := pAudioData.PassRef()
// cpMetadata, cpMetadataAllocMap := pMetadata.PassRef()
var videoFrame C.NDIlib_video_frame_v2_t
var audioFrame C.NDIlib_audio_frame_v3_t
var metadataFrame C.NDIlib_metadata_frame_t
ctimeoutInMs, ctimeoutInMsAllocMap := (C.uint32_t)(timeoutInMs), cgoAllocsUnknown
__ret := C.NDIlib_recv_capture_v3(cpInstance, &videoFrame, &audioFrame, &metadataFrame, ctimeoutInMs)
runtime.KeepAlive(ctimeoutInMsAllocMap)
runtime.KeepAlive(cpInstanceAllocMap)
__v := (FrameType)(__ret)
if pVideoData != nil {
*pVideoData = VideoFrameV2Type2(videoFrame)
}
if pAudioData != nil {
*pAudioData = AudioFrameV3Type2(audioFrame)
}
if pMetadata != nil {
*pMetadata = MetadataFrameType2(metadataFrame)
}
return __v
}
func RecvFreeVideoV22(instance RecvInstanceType, videoFrame *VideoFrameV2Type2) {
C.NDIlib_recv_free_video_v2(C.NDIlib_recv_instance_t(instance), (*C.NDIlib_video_frame_v2_t)(videoFrame))
}
func RecvFreeAudioV32(instance RecvInstanceType, audioFrame *AudioFrameV3Type2) {
C.NDIlib_recv_free_audio_v3(C.NDIlib_recv_instance_t(instance), (*C.NDIlib_audio_frame_v3_t)(audioFrame))
}
func RecvFreeMetadata2(instance RecvInstanceType, metadataFrame *MetadataFrameType2) {
C.NDIlib_recv_free_metadata(C.NDIlib_recv_instance_t(instance), (*C.NDIlib_metadata_frame_t)(metadataFrame))
}
func GetRedistUrl() string {
return string(C.NDILIB_REDIST_URL)
}