60 lines
1.1 KiB
Go
60 lines
1.1 KiB
Go
package ndi
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/bitfocus/gondi"
|
|
"os"
|
|
)
|
|
|
|
var NDI_LIB_PATH = ""
|
|
|
|
func discovery() {
|
|
var (
|
|
libndi = ""
|
|
libndiEnv = os.Getenv("LIBNDI")
|
|
)
|
|
if libndiEnv != "" {
|
|
libndi = libndiEnv
|
|
} else if NDI_LIB_PATH != "" {
|
|
libndi = fmt.Sprintf("%s/lib/libndi.so", NDI_LIB_PATH)
|
|
} else {
|
|
fmt.Println("LIBNDI environment variable is not set")
|
|
return
|
|
}
|
|
|
|
fmt.Println("Initializing NDI")
|
|
if err := gondi.InitLibrary(libndi); err != nil {
|
|
fmt.Println("Failed to initialize NDI library:", err)
|
|
return
|
|
}
|
|
|
|
version := gondi.GetVersion()
|
|
fmt.Printf("NDI version: %s\n", version)
|
|
|
|
findInstance, err := gondi.NewFindInstance(true, "", "")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
defer findInstance.Destroy()
|
|
|
|
// Wait for sources to appear
|
|
fmt.Println("Looking for sources...")
|
|
for {
|
|
more := findInstance.WaitForSources(5000)
|
|
if !more {
|
|
break
|
|
}
|
|
}
|
|
|
|
// Fetch the sources
|
|
sources := findInstance.GetCurrentSources()
|
|
|
|
if len(sources) == 0 {
|
|
fmt.Println("No sources found")
|
|
return
|
|
}
|
|
|
|
for _, source := range sources {
|
|
fmt.Printf("Found source: %q: %q\n", source.Name(), source.Address())
|
|
}
|
|
}
|