mirror of
https://github.com/aler9/rtsp-simple-server
synced 2025-10-06 16:17:59 +08:00
restore compatibility with non-raspberry arm systems (#1587)
This commit is contained in:
@@ -181,8 +181,6 @@ outer:
|
|||||||
p.ctxCancel()
|
p.ctxCancel()
|
||||||
|
|
||||||
p.closeResources(nil, false)
|
p.closeResources(nil, false)
|
||||||
|
|
||||||
rpicamera.LibcameraCleanup()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Core) createResources(initial bool) error {
|
func (p *Core) createResources(initial bool) error {
|
||||||
@@ -210,11 +208,6 @@ func (p *Core) createResources(initial bool) error {
|
|||||||
// do not check for errors
|
// do not check for errors
|
||||||
rlimit.Raise()
|
rlimit.Raise()
|
||||||
|
|
||||||
err := rpicamera.LibcameraSetup()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
gin.SetMode(gin.ReleaseMode)
|
gin.SetMode(gin.ReleaseMode)
|
||||||
|
|
||||||
p.externalCmdPool = externalcmd.NewPool()
|
p.externalCmdPool = externalcmd.NewPool()
|
||||||
@@ -679,6 +672,10 @@ func (p *Core) closeResources(newConf *conf.Conf, calledByAPI bool) {
|
|||||||
p.externalCmdPool.Close()
|
p.externalCmdPool.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if newConf == nil {
|
||||||
|
rpicamera.Cleanup()
|
||||||
|
}
|
||||||
|
|
||||||
if closeLogger {
|
if closeLogger {
|
||||||
p.logger.Close()
|
p.logger.Close()
|
||||||
p.logger = nil
|
p.logger = nil
|
||||||
|
@@ -1,51 +0,0 @@
|
|||||||
//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() error {
|
|
||||||
err := setupSymlink("libcamera")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return 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")
|
|
||||||
}
|
|
@@ -1,13 +0,0 @@
|
|||||||
//go:build !rpicamera
|
|
||||||
// +build !rpicamera
|
|
||||||
|
|
||||||
package rpicamera
|
|
||||||
|
|
||||||
// LibcameraSetup creates libcamera simlinks that are version agnostic.
|
|
||||||
func LibcameraSetup() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// LibcameraCleanup removes files created by LibcameraSetup.
|
|
||||||
func LibcameraCleanup() {
|
|
||||||
}
|
|
@@ -12,6 +12,7 @@ import (
|
|||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/aler9/gortsplib/v2/pkg/codecs/h264"
|
"github.com/aler9/gortsplib/v2/pkg/codecs/h264"
|
||||||
@@ -35,24 +36,6 @@ func getKernelArch() (string, error) {
|
|||||||
return string(byts[:len(byts)-1]), nil
|
return string(byts[:len(byts)-1]), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 32-bit embedded executables can't run on 64-bit.
|
|
||||||
func checkArch() error {
|
|
||||||
if runtime.GOARCH != "arm" {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
arch, err := getKernelArch()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if arch == "aarch64" {
|
|
||||||
return fmt.Errorf("OS is 64-bit, you need the arm64 server version")
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func startEmbeddedExe(content []byte, env []string) (*exec.Cmd, error) {
|
func startEmbeddedExe(content []byte, env []string) (*exec.Cmd, error) {
|
||||||
tempPath := tempPathPrefix + strconv.FormatInt(time.Now().UnixNano(), 10)
|
tempPath := tempPathPrefix + strconv.FormatInt(time.Now().UnixNano(), 10)
|
||||||
|
|
||||||
@@ -113,6 +96,87 @@ func serializeParams(p Params) []byte {
|
|||||||
return []byte(strings.Join(ret, " "))
|
return []byte(strings.Join(ret, " "))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 32-bit embedded executables can't run on 64-bit.
|
||||||
|
func checkArch() error {
|
||||||
|
if runtime.GOARCH != "arm" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
arch, err := getKernelArch()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if arch == "aarch64" {
|
||||||
|
return fmt.Errorf("OS is 64-bit, you need the arm64 server version")
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
mutex sync.Mutex
|
||||||
|
setupped bool
|
||||||
|
)
|
||||||
|
|
||||||
|
func setupLibcameraOnce() error {
|
||||||
|
mutex.Lock()
|
||||||
|
defer mutex.Unlock()
|
||||||
|
|
||||||
|
if !setupped {
|
||||||
|
err := checkArch()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = setupSymlink("libcamera")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = setupSymlink("libcamera-base")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
setupped = true
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cleanup cleanups files created by the camera implementation.
|
||||||
|
func Cleanup() {
|
||||||
|
if setupped {
|
||||||
|
os.Remove("/dev/shm/libcamera-base.so.x.x.x")
|
||||||
|
os.Remove("/dev/shm/libcamera.so.x.x.x")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type RPICamera struct {
|
type RPICamera struct {
|
||||||
onData func(time.Duration, [][]byte)
|
onData func(time.Duration, [][]byte)
|
||||||
|
|
||||||
@@ -128,7 +192,7 @@ func New(
|
|||||||
params Params,
|
params Params,
|
||||||
onData func(time.Duration, [][]byte),
|
onData func(time.Duration, [][]byte),
|
||||||
) (*RPICamera, error) {
|
) (*RPICamera, error) {
|
||||||
err := checkArch()
|
err := setupLibcameraOnce()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@@ -9,6 +9,10 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Cleanup cleanups files created by the camera implementation.
|
||||||
|
func Cleanup() {
|
||||||
|
}
|
||||||
|
|
||||||
// RPICamera is a RPI Camera reader.
|
// RPICamera is a RPI Camera reader.
|
||||||
type RPICamera struct{}
|
type RPICamera struct{}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user