Skip to content

Commit 070ea38

Browse files
authoredApr 29, 2024··
Merge pull request #913 from robvanoostenrijk/master
Added FreeBSD binaries
2 parents cf4f646 + f73ee41 commit 070ea38

File tree

4 files changed

+195
-0
lines changed

4 files changed

+195
-0
lines changed
 

‎.github/workflows/build.yml

+14
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,20 @@ jobs:
9898
uses: actions/upload-artifact@v4
9999
with: { name: go2rtc_mac_arm64, path: go2rtc }
100100

101+
- name: Build go2rtc_freebsd_amd64
102+
env: { GOOS: freebsd, GOARCH: amd64 }
103+
run: go build -ldflags "-s -w" -trimpath
104+
- name: Upload go2rtc_freebsd_amd64
105+
uses: actions/upload-artifact@v3
106+
with: { name: go2rtc_freebsd_amd64, path: go2rtc }
107+
108+
- name: Build go2rtc_freebsd_arm64
109+
env: { GOOS: freebsd, GOARCH: arm64 }
110+
run: go build -ldflags "-s -w" -trimpath
111+
- name: Upload go2rtc_freebsd_arm64
112+
uses: actions/upload-artifact@v3
113+
with: { name: go2rtc_freebsd_arm64, path: go2rtc }
114+
101115
docker-master:
102116
name: Build docker master
103117
runs-on: ubuntu-latest
+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
package device
2+
3+
import (
4+
"net/url"
5+
"os"
6+
"os/exec"
7+
"regexp"
8+
"strings"
9+
10+
"github.com/AlexxIT/go2rtc/internal/api"
11+
"github.com/AlexxIT/go2rtc/pkg/core"
12+
)
13+
14+
func queryToInput(query url.Values) string {
15+
if video := query.Get("video"); video != "" {
16+
// https://ffmpeg.org/ffmpeg-devices.html#video4linux2_002c-v4l2
17+
input := "-f v4l2"
18+
19+
for key, value := range query {
20+
switch key {
21+
case "resolution":
22+
input += " -video_size " + value[0]
23+
case "video_size", "pixel_format", "input_format", "framerate", "use_libv4l2":
24+
input += " -" + key + " " + value[0]
25+
}
26+
}
27+
28+
return input + " -i " + indexToItem(videos, video)
29+
}
30+
31+
if audio := query.Get("audio"); audio != "" {
32+
input := "-f oss"
33+
34+
for key, value := range query {
35+
switch key {
36+
case "channels", "sample_rate":
37+
input += " -" + key + " " + value[0]
38+
}
39+
}
40+
41+
return input + " -i " + indexToItem(audios, audio)
42+
}
43+
44+
return ""
45+
}
46+
47+
func initDevices() {
48+
files, err := os.ReadDir("/dev")
49+
if err != nil {
50+
return
51+
}
52+
53+
for _, file := range files {
54+
if !strings.HasPrefix(file.Name(), core.KindVideo) {
55+
continue
56+
}
57+
58+
name := "/dev/" + file.Name()
59+
60+
cmd := exec.Command(
61+
Bin, "-hide_banner", "-f", "v4l2", "-list_formats", "all", "-i", name,
62+
)
63+
b, _ := cmd.CombinedOutput()
64+
65+
// [video4linux2,v4l2 @ 0x860b92280] Raw : yuyv422 : YUYV 4:2:2 : 640x480 160x120 176x144 320x176 320x240 352x288 432x240 544x288 640x360 752x416 800x448 800x600 864x480 960x544 960x720 1024x576 1184x656 1280x720 1280x960
66+
// [video4linux2,v4l2 @ 0x860b92280] Compressed: mjpeg : Motion-JPEG : 640x480 160x120 176x144 320x176 320x240 352x288 432x240 544x288 640x360 752x416 800x448 800x600 864x480 960x544 960x720 1024x576 1184x656 1280x720 1280x960
67+
re := regexp.MustCompile("(Raw *|Compressed): +(.+?) : +(.+?) : (.+)")
68+
m := re.FindAllStringSubmatch(string(b), -1)
69+
for _, i := range m {
70+
size, _, _ := strings.Cut(i[4], " ")
71+
stream := &api.Source{
72+
Name: i[3],
73+
Info: i[4],
74+
URL: "ffmpeg:device?video=" + name + "&input_format=" + i[2] + "&video_size=" + size,
75+
}
76+
77+
if i[1] != "Compressed" {
78+
stream.URL += "#video=h264#hardware"
79+
}
80+
81+
videos = append(videos, name)
82+
streams = append(streams, stream)
83+
}
84+
}
85+
86+
err = exec.Command(Bin, "-f", "oss", "-i", "/dev/dsp", "-t", "1", "-f", "null", "-").Run()
87+
if err == nil {
88+
stream := &api.Source{
89+
Name: "OSS default",
90+
Info: " ",
91+
URL: "ffmpeg:device?audio=default&channels=1&sample_rate=16000&#audio=opus",
92+
}
93+
94+
audios = append(audios, "default")
95+
streams = append(streams, stream)
96+
}
97+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package hardware
2+
3+
import (
4+
"runtime"
5+
6+
"github.com/AlexxIT/go2rtc/internal/api"
7+
)
8+
9+
const (
10+
ProbeV4L2M2MH264 = "-f lavfi -i testsrc2 -t 1 -c h264_v4l2m2m -f null -"
11+
ProbeV4L2M2MH265 = "-f lavfi -i testsrc2 -t 1 -c hevc_v4l2m2m -f null -"
12+
ProbeRKMPPH264 = "-f lavfi -i testsrc2 -t 1 -c h264_rkmpp_encoder -f null -"
13+
ProbeRKMPPH265 = "-f lavfi -i testsrc2 -t 1 -c hevc_rkmpp_encoder -f null -"
14+
)
15+
16+
func ProbeAll(bin string) []*api.Source {
17+
return []*api.Source{
18+
{
19+
Name: runToString(bin, ProbeV4L2M2MH264),
20+
URL: "ffmpeg:...#video=h264#hardware=" + EngineV4L2M2M,
21+
},
22+
{
23+
Name: runToString(bin, ProbeV4L2M2MH265),
24+
URL: "ffmpeg:...#video=h265#hardware=" + EngineV4L2M2M,
25+
},
26+
{
27+
Name: runToString(bin, ProbeRKMPPH264),
28+
URL: "ffmpeg:...#video=h264#hardware=" + EngineRKMPP,
29+
},
30+
{
31+
Name: runToString(bin, ProbeRKMPPH265),
32+
URL: "ffmpeg:...#video=h265#hardware=" + EngineRKMPP,
33+
},
34+
}
35+
}
36+
37+
func ProbeHardware(bin, name string) string {
38+
if runtime.GOARCH == "arm64" || runtime.GOARCH == "arm" {
39+
switch name {
40+
case "h264":
41+
if run(bin, ProbeV4L2M2MH264) {
42+
return EngineV4L2M2M
43+
}
44+
if run(bin, ProbeRKMPPH264) {
45+
return EngineRKMPP
46+
}
47+
case "h265":
48+
if run(bin, ProbeV4L2M2MH265) {
49+
return EngineV4L2M2M
50+
}
51+
if run(bin, ProbeRKMPPH265) {
52+
return EngineRKMPP
53+
}
54+
}
55+
56+
return EngineSoftware
57+
}
58+
59+
return EngineSoftware
60+
}

‎pkg/mdns/syscall_freebsd.go

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package mdns
2+
3+
import (
4+
"syscall"
5+
)
6+
7+
func SetsockoptInt(fd uintptr, level, opt int, value int) (err error) {
8+
// change SO_REUSEADDR and REUSEPORT flags simultaneously for BSD-like OS
9+
// https://github.com/AlexxIT/go2rtc/issues/626
10+
// https://stackoverflow.com/questions/14388706/how-do-so-reuseaddr-and-so-reuseport-differ/14388707
11+
if opt == syscall.SO_REUSEADDR {
12+
if err = syscall.SetsockoptInt(int(fd), level, opt, value); err != nil {
13+
return
14+
}
15+
16+
opt = syscall.SO_REUSEPORT
17+
}
18+
19+
return syscall.SetsockoptInt(int(fd), level, opt, value)
20+
}
21+
22+
func SetsockoptIPMreq(fd uintptr, level, opt int, mreq *syscall.IPMreq) (err error) {
23+
return syscall.SetsockoptIPMreq(int(fd), level, opt, mreq)
24+
}

0 commit comments

Comments
 (0)
Please sign in to comment.