commit d672f04be261264052df0645c017ec9f183d862b Author: Garionion Date: Mon Apr 7 15:40:14 2025 +0200 initial commit diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..495433d --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1743827369, + "narHash": "sha256-rpqepOZ8Eo1zg+KJeWoq1HAOgoMCDloqv5r2EAa9TSA=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "42a1c966be226125b48c384171c44c651c236c22", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..317ca78 --- /dev/null +++ b/flake.nix @@ -0,0 +1,35 @@ +{ + description = "NDI Discovery Go program"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { self, nixpkgs, flake-utils, ... }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { system = system; config.allowUnfree = true; }; + in { + devShell = pkgs.mkShell { + buildInputs = [ + pkgs.go + pkgs.ndi + ]; + LIBNDI="${pkgs.ndi}/lib/libndi.so"; + CFLAGS="-I${pkgs.ndi}/include"; + LDFLAGS="-L${pkgs.ndi}/lib -lndi"; + }; + packages = { + ndi_discover = import ./package.nix { inherit pkgs; inherit self; }; + }; + defaultPackage = import ./package.nix { inherit pkgs; inherit self; }; + + apps = { + ndi_discover = { + type = "app"; + program = "${self.packages.${system}.ndi_discover}/bin/ndi_discover"; + }; + }; + }); +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..cbbcdc5 --- /dev/null +++ b/go.mod @@ -0,0 +1,7 @@ +module git.entr0py.de/garionion/catie + +go 1.24 + +require github.com/bitfocus/gondi v0.0.2 + +require github.com/ebitengine/purego v0.3.2 // indirect diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..ee47d87 --- /dev/null +++ b/go.sum @@ -0,0 +1,4 @@ +github.com/bitfocus/gondi v0.0.2 h1:Q/kscMhnp0iX+Vkz274vG1loBw2lKyq5yq4b1XjllTE= +github.com/bitfocus/gondi v0.0.2/go.mod h1:g/pdkw//j2qJD+l9Yv8xf3RtjnrwBrZQBmlYIJ8GXQs= +github.com/ebitengine/purego v0.3.2 h1:+pV+tskAkn/bxEcUzGtDfw2VAe3bRQ26kdzFjPPrCww= +github.com/ebitengine/purego v0.3.2/go.mod h1:iIjxzd6CiRiOG0UyXP+V1+jWqUXVjPKLAI0mRfJZTmQ= diff --git a/main.go b/main.go new file mode 100644 index 0000000..bdbc169 --- /dev/null +++ b/main.go @@ -0,0 +1,52 @@ +package main + +import ( + "fmt" + "os" + + "github.com/bitfocus/gondi" +) + +func main() { + libndi := os.Getenv("LIBNDI") + if libndi == "" { + 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()) + } +} diff --git a/package.nix b/package.nix new file mode 100644 index 0000000..0727f36 --- /dev/null +++ b/package.nix @@ -0,0 +1,26 @@ +{ pkgs ? import { }, self }: +with pkgs; +let + version = "0.0.1"; +in +pkgs.buildGo124Module { + pname = "catie"; + inherit version; + + src = self; + + buildInputs = [ + ndi + ]; + + buildFlags = [ + "CGO_CFLAGS=-I${pkgs.ndi}/include" + "CGO_LDFLAGS=-L${pkgs.ndi}/lib -lndi" + ]; + + tags = [ ]; + + #vendorHash = lib.fakeHash; + vendorHash = "sha256-d0dcW2uV+a2GLBcY3FgNXNeajiJjFLEyCgqwZsEpW60="; + proxyVendor = true; +} \ No newline at end of file