mirror of
https://github.com/bluenviron/mediamtx
synced 2025-01-10 17:09:56 +00:00
parent
c1bcd0c7eb
commit
32d6cb4435
@ -202,7 +202,7 @@ func TestConfErrors(t *testing.T) {
|
||||
" source: rpiCamera\n" +
|
||||
" cam2:\n" +
|
||||
" source: rpiCamera\n",
|
||||
"'rpiCamera' is used as source in two paths ('cam1' and 'cam2')",
|
||||
"'rpiCamera' with same camera ID 0 is used as source in two paths, 'cam1' and 'cam2'",
|
||||
},
|
||||
} {
|
||||
t.Run(ca.name, func(t *testing.T) {
|
||||
|
@ -195,8 +195,10 @@ func (pconf *PathConf) checkAndFillMissing(conf *Conf, name string) error {
|
||||
}
|
||||
|
||||
for otherName, otherPath := range conf.Paths {
|
||||
if otherPath != pconf && otherPath != nil && otherPath.Source == "rpiCamera" {
|
||||
return fmt.Errorf("'rpiCamera' is used as source in two paths ('%s' and '%s')", name, otherName)
|
||||
if otherPath != pconf && otherPath != nil &&
|
||||
otherPath.Source == "rpiCamera" && otherPath.RPICameraCamID == pconf.RPICameraCamID {
|
||||
return fmt.Errorf("'rpiCamera' with same camera ID %d is used as source in two paths, '%s' and '%s'",
|
||||
pconf.RPICameraCamID, name, otherName)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,7 @@ import (
|
||||
"github.com/aler9/rtsp-simple-server/internal/externalcmd"
|
||||
"github.com/aler9/rtsp-simple-server/internal/logger"
|
||||
"github.com/aler9/rtsp-simple-server/internal/rlimit"
|
||||
"github.com/aler9/rtsp-simple-server/internal/rpicamera"
|
||||
)
|
||||
|
||||
var version = "v0.0.0"
|
||||
@ -84,6 +85,8 @@ func New(args []string) (*Core, bool) {
|
||||
// do not check for errors
|
||||
rlimit.Raise()
|
||||
|
||||
rpicamera.LibcameraSetup()
|
||||
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
|
||||
ctx, ctxCancel := context.WithCancel(context.Background())
|
||||
@ -186,6 +189,8 @@ outer:
|
||||
p.ctxCancel()
|
||||
|
||||
p.closeResources(nil, false)
|
||||
|
||||
rpicamera.LibcameraCleanup()
|
||||
}
|
||||
|
||||
func (p *Core) createResources(initial bool) error {
|
||||
|
47
internal/rpicamera/libcamera.go
Normal file
47
internal/rpicamera/libcamera.go
Normal file
@ -0,0 +1,47 @@
|
||||
//go:build rpicamera
|
||||
// +build rpicamera
|
||||
|
||||
package rpicamera
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func findLibrary(name string) (string, error) {
|
||||
byts, err := exec.Command("ldconfig", "-p").Output()
|
||||
if err == nil {
|
||||
for _, line := range strings.Split(string(byts), "\n") {
|
||||
f := strings.Split(line, " => ")
|
||||
if len(f) == 2 && strings.Contains(f[1], name+".so") {
|
||||
return f[1], nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return "", fmt.Errorf("library '%s' not found", name)
|
||||
}
|
||||
|
||||
func setupSymlink(name string) error {
|
||||
lib, err := findLibrary(name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
os.Remove("/dev/shm/" + name + ".so.x.x.x")
|
||||
return os.Symlink(lib, "/dev/shm/"+name+".so.x.x.x")
|
||||
}
|
||||
|
||||
// LibcameraSetup creates libcamera simlinks that are version agnostic.
|
||||
func LibcameraSetup() {
|
||||
setupSymlink("libcamera")
|
||||
setupSymlink("libcamera-base")
|
||||
}
|
||||
|
||||
// LibcameraCleanup removes files created by LibcameraSetup.
|
||||
func LibcameraCleanup() {
|
||||
os.Remove("/dev/shm/libcamera-base.so.x.x.x")
|
||||
os.Remove("/dev/shm/libcamera.so.x.x.x")
|
||||
}
|
12
internal/rpicamera/libcamera_disabled.go
Normal file
12
internal/rpicamera/libcamera_disabled.go
Normal file
@ -0,0 +1,12 @@
|
||||
//go:build !rpicamera
|
||||
// +build !rpicamera
|
||||
|
||||
package rpicamera
|
||||
|
||||
// LibcameraSetup creates libcamera simlinks that are version agnostic.
|
||||
func LibcameraSetup() {
|
||||
}
|
||||
|
||||
// LibcameraCleanup removes files created by LibcameraSetup.
|
||||
func LibcameraCleanup() {
|
||||
}
|
@ -53,45 +53,6 @@ func checkArch() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func findLibrary(name string) (string, error) {
|
||||
byts, err := exec.Command("ldconfig", "-p").Output()
|
||||
if err == nil {
|
||||
for _, line := range strings.Split(string(byts), "\n") {
|
||||
f := strings.Split(line, " => ")
|
||||
if len(f) == 2 && strings.Contains(f[1], name+".so") {
|
||||
return f[1], nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return "", fmt.Errorf("library '%s' not found", name)
|
||||
}
|
||||
|
||||
func setupSymlink(name string) error {
|
||||
lib, err := findLibrary(name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
os.Remove("/dev/shm/" + name + ".so.x.x.x")
|
||||
return os.Symlink(lib, "/dev/shm/"+name+".so.x.x.x")
|
||||
}
|
||||
|
||||
// create libcamera simlinks that are version agnostic.
|
||||
func setupSymlinks() error {
|
||||
err := setupSymlink("libcamera")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return setupSymlink("libcamera-base")
|
||||
}
|
||||
|
||||
func removeSymlinks() {
|
||||
os.Remove("/dev/shm/libcamera-base.so.x.x.x")
|
||||
os.Remove("/dev/shm/libcamera.so.x.x.x")
|
||||
}
|
||||
|
||||
func startEmbeddedExe(content []byte, env []string) (*exec.Cmd, error) {
|
||||
tempPath := tempPathPrefix + strconv.FormatInt(time.Now().UnixNano(), 10)
|
||||
|
||||
@ -172,12 +133,6 @@ func New(
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = setupSymlinks()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer removeSymlinks()
|
||||
|
||||
c := &RPICamera{
|
||||
onData: onData,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user