diff --git a/internal/api/api.go b/internal/api/api.go index e21b9074..00619564 100644 --- a/internal/api/api.go +++ b/internal/api/api.go @@ -220,14 +220,14 @@ type Source struct { Location string `json:"location,omitempty"` } -func ResponseSources(w http.ResponseWriter, sources []Source) { +func ResponseSources(w http.ResponseWriter, sources []*Source) { if len(sources) == 0 { http.Error(w, "no sources", http.StatusNotFound) return } var response = struct { - Sources []Source `json:"sources"` + Sources []*Source `json:"sources"` }{ Sources: sources, } diff --git a/internal/dvrip/dvrip.go b/internal/dvrip/dvrip.go index e892b6e6..0db0a80b 100644 --- a/internal/dvrip/dvrip.go +++ b/internal/dvrip/dvrip.go @@ -48,7 +48,7 @@ func apiDvrip(w http.ResponseWriter, r *http.Request) { api.ResponseSources(w, items) } -func discover() ([]api.Source, error) { +func discover() ([]*api.Source, error) { addr := &net.UDPAddr{ Port: Port, IP: net.IP{239, 255, 255, 250}, @@ -63,7 +63,7 @@ func discover() ([]api.Source, error) { go sendBroadcasts(conn) - var items []api.Source + var items []*api.Source for _, info := range getResponses(conn) { if info.HostIP == "" || info.HostName == "" { @@ -75,7 +75,7 @@ func discover() ([]api.Source, error) { continue } - items = append(items, api.Source{ + items = append(items, &api.Source{ Name: info.HostName, URL: "dvrip://user:pass@" + host + "?channel=0&subtype=0", }) diff --git a/internal/ffmpeg/device/device_darwin.go b/internal/ffmpeg/device/device_darwin.go index f707f6b0..ac9b5e43 100644 --- a/internal/ffmpeg/device/device_darwin.go +++ b/internal/ffmpeg/device/device_darwin.go @@ -79,7 +79,7 @@ func initDevices() { audios = append(audios, name) } - streams = append(streams, api.Source{ + streams = append(streams, &api.Source{ Name: name, URL: "ffmpeg:device?" + kind + "=" + name, }) } diff --git a/internal/ffmpeg/device/device_linux.go b/internal/ffmpeg/device/device_linux.go index 3651cc33..26a3f8f3 100644 --- a/internal/ffmpeg/device/device_linux.go +++ b/internal/ffmpeg/device/device_linux.go @@ -70,7 +70,7 @@ func initDevices() { m := re.FindAllStringSubmatch(string(b), -1) for _, i := range m { size, _, _ := strings.Cut(i[4], " ") - stream := api.Source{ + stream := &api.Source{ Name: i[3] + " | " + i[4], URL: "ffmpeg:device?video=" + name + "&input_format=" + i[2] + "&video_size=" + size, } @@ -86,7 +86,7 @@ func initDevices() { err = exec.Command(Bin, "-f", "alsa", "-i", "default", "-t", "1", "-f", "null", "-").Run() if err == nil { - stream := api.Source{ + stream := &api.Source{ Name: "ALSA default", URL: "ffmpeg:device?audio=default&channels=1&sample_rate=16000&#audio=opus", } diff --git a/internal/ffmpeg/device/device_windows.go b/internal/ffmpeg/device/device_windows.go index ec25e657..e522a482 100644 --- a/internal/ffmpeg/device/device_windows.go +++ b/internal/ffmpeg/device/device_windows.go @@ -80,7 +80,7 @@ func initDevices() { name := m[1] kind := m[2] - stream := api.Source{ + stream := &api.Source{ Name: name, URL: "ffmpeg:device?" + kind + "=" + name, } diff --git a/internal/ffmpeg/device/devices.go b/internal/ffmpeg/device/devices.go index 2c0e2d91..a51abd64 100644 --- a/internal/ffmpeg/device/devices.go +++ b/internal/ffmpeg/device/devices.go @@ -40,7 +40,7 @@ func GetInput(src string) (string, error) { var Bin string var videos, audios []string -var streams []api.Source +var streams []*api.Source var runonce sync.Once func apiDevices(w http.ResponseWriter, r *http.Request) { diff --git a/internal/ffmpeg/hardware/hardware_darwin.go b/internal/ffmpeg/hardware/hardware_darwin.go index 82722a7a..8392d2b1 100644 --- a/internal/ffmpeg/hardware/hardware_darwin.go +++ b/internal/ffmpeg/hardware/hardware_darwin.go @@ -7,8 +7,8 @@ import ( const ProbeVideoToolboxH264 = "-f lavfi -i testsrc2=size=svga -t 1 -c h264_videotoolbox -f null -" const ProbeVideoToolboxH265 = "-f lavfi -i testsrc2=size=svga -t 1 -c hevc_videotoolbox -f null -" -func ProbeAll(bin string) []api.Source { - return []api.Source{ +func ProbeAll(bin string) []*api.Source { + return []*api.Source{ { Name: runToString(bin, ProbeVideoToolboxH264), URL: "ffmpeg:...#video=h264#hardware=" + EngineVideoToolbox, diff --git a/internal/ffmpeg/hardware/hardware_linux.go b/internal/ffmpeg/hardware/hardware_linux.go index 3aa77862..5595e4c4 100644 --- a/internal/ffmpeg/hardware/hardware_linux.go +++ b/internal/ffmpeg/hardware/hardware_linux.go @@ -14,9 +14,9 @@ const ProbeVAAPIJPEG = "-init_hw_device vaapi -f lavfi -i testsrc2 -t 1 -vf form const ProbeCUDAH264 = "-init_hw_device cuda -f lavfi -i testsrc2 -t 1 -c h264_nvenc -f null -" const ProbeCUDAH265 = "-init_hw_device cuda -f lavfi -i testsrc2 -t 1 -c hevc_nvenc -f null -" -func ProbeAll(bin string) []api.Source { +func ProbeAll(bin string) []*api.Source { if runtime.GOARCH == "arm64" || runtime.GOARCH == "arm" { - return []api.Source{ + return []*api.Source{ { Name: runToString(bin, ProbeV4L2M2MH264), URL: "ffmpeg:...#video=h264#hardware=" + EngineV4L2M2M, @@ -28,7 +28,7 @@ func ProbeAll(bin string) []api.Source { } } - return []api.Source{ + return []*api.Source{ { Name: runToString(bin, ProbeVAAPIH264), URL: "ffmpeg:...#video=h264#hardware=" + EngineVAAPI, diff --git a/internal/ffmpeg/hardware/hardware_windows.go b/internal/ffmpeg/hardware/hardware_windows.go index 1d95cabe..c22639f5 100644 --- a/internal/ffmpeg/hardware/hardware_windows.go +++ b/internal/ffmpeg/hardware/hardware_windows.go @@ -8,8 +8,8 @@ const ProbeDXVA2JPEG = "-init_hw_device dxva2 -f lavfi -i testsrc2 -t 1 -c mjpeg const ProbeCUDAH264 = "-init_hw_device cuda -f lavfi -i testsrc2 -t 1 -c h264_nvenc -f null -" const ProbeCUDAH265 = "-init_hw_device cuda -f lavfi -i testsrc2 -t 1 -c hevc_nvenc -f null -" -func ProbeAll(bin string) []api.Source { - return []api.Source{ +func ProbeAll(bin string) []*api.Source { + return []*api.Source{ { Name: runToString(bin, ProbeDXVA2H264), URL: "ffmpeg:...#video=h264#hardware=" + EngineDXVA2, diff --git a/internal/hass/hass.go b/internal/hass/hass.go index 8b64a737..76ffc89d 100644 --- a/internal/hass/hass.go +++ b/internal/hass/hass.go @@ -75,9 +75,9 @@ func Init() { } }) - var items []api.Source + var items []*api.Source for name, url := range entities { - items = append(items, api.Source{ + items = append(items, &api.Source{ Name: name, URL: "hass:" + name, Location: url, }) } diff --git a/internal/nest/init.go b/internal/nest/init.go index a7087701..1281ccdc 100644 --- a/internal/nest/init.go +++ b/internal/nest/init.go @@ -42,12 +42,12 @@ func apiNest(w http.ResponseWriter, r *http.Request) { return } - var items []api.Source + var items []*api.Source for name, deviceID := range devices { query.Set("device_id", deviceID) - items = append(items, api.Source{ + items = append(items, &api.Source{ Name: name, URL: "nest:?" + query.Encode(), }) } diff --git a/internal/onvif/init.go b/internal/onvif/init.go index 7eb1a976..014c5e18 100644 --- a/internal/onvif/init.go +++ b/internal/onvif/init.go @@ -122,7 +122,7 @@ func onvifDeviceService(w http.ResponseWriter, r *http.Request) { func apiOnvif(w http.ResponseWriter, r *http.Request) { src := r.URL.Query().Get("src") - var items []api.Source + var items []*api.Source if src == "" { urls, err := onvif.DiscoveryStreamingURLs() @@ -150,7 +150,7 @@ func apiOnvif(w http.ResponseWriter, r *http.Request) { u.Path = "" } - items = append(items, api.Source{Name: u.Host, URL: u.String()}) + items = append(items, &api.Source{Name: u.Host, URL: u.String()}) } } else { client, err := onvif.NewClient(src) @@ -177,14 +177,14 @@ func apiOnvif(w http.ResponseWriter, r *http.Request) { } for i, token := range tokens { - items = append(items, api.Source{ + items = append(items, &api.Source{ Name: name + " stream" + strconv.Itoa(i), URL: src + "?subtype=" + token, }) } if len(tokens) > 0 && client.HasSnapshots() { - items = append(items, api.Source{ + items = append(items, &api.Source{ Name: name + " snapshot", URL: src + "?subtype=" + tokens[0] + "&snapshot", }) diff --git a/internal/roborock/roborock.go b/internal/roborock/roborock.go index 537ea2cd..27e29bb5 100644 --- a/internal/roborock/roborock.go +++ b/internal/roborock/roborock.go @@ -85,7 +85,7 @@ func apiHandle(w http.ResponseWriter, r *http.Request) { return } - var items []api.Source + var items []*api.Source for _, device := range devices { source := fmt.Sprintf( @@ -94,7 +94,7 @@ func apiHandle(w http.ResponseWriter, r *http.Request) { Auth.UserData.IoT.User, Auth.UserData.IoT.Pass, Auth.UserData.IoT.Domain, device.DID, device.Key, ) - items = append(items, api.Source{Name: device.Name, URL: source}) + items = append(items, &api.Source{Name: device.Name, URL: source}) } api.ResponseSources(w, items) diff --git a/internal/webtorrent/init.go b/internal/webtorrent/init.go index dcb0169d..25b7ef9b 100644 --- a/internal/webtorrent/init.go +++ b/internal/webtorrent/init.go @@ -111,11 +111,11 @@ func apiHandle(w http.ResponseWriter, r *http.Request) { } } else { // response all shares - var items []api.Source + var items []*api.Source for src, share := range shares { pwd := srv.GetSharePwd(share) source := fmt.Sprintf("webtorrent:?share=%s&pwd=%s", share, pwd) - items = append(items, api.Source{ID: src, URL: source}) + items = append(items, &api.Source{ID: src, URL: source}) } api.ResponseSources(w, items) }