-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rpi: embed libcamera and libfreetype into the server (#2581)
- Loading branch information
Showing
9 changed files
with
195 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,107 @@ | ||
//go:build (linux && arm) || (linux && arm64) | ||
// +build linux,arm linux,arm64 | ||
|
||
package rpicamera | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"strconv" | ||
"sync" | ||
"time" | ||
) | ||
|
||
//go:generate go run ./mtxrpicamdownloader | ||
|
||
const ( | ||
dumpPrefix = "/dev/shm/mediamtx-rpicamera-" | ||
) | ||
|
||
var ( | ||
dumpMutex sync.Mutex | ||
dumpCount = 0 | ||
dumpPath = "" | ||
) | ||
|
||
func dumpEmbedFSRecursive(src string, dest string) error { | ||
files, err := component.ReadDir(src) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
for _, f := range files { | ||
if f.IsDir() { | ||
err = os.Mkdir(filepath.Join(dest, f.Name()), 0o755) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = dumpEmbedFSRecursive(filepath.Join(src, f.Name()), filepath.Join(dest, f.Name())) | ||
if err != nil { | ||
return err | ||
} | ||
} else { | ||
buf, err := component.ReadFile(filepath.Join(src, f.Name())) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = os.WriteFile(filepath.Join(dest, f.Name()), buf, 0o644) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func dumpComponent() error { | ||
dumpMutex.Lock() | ||
defer dumpMutex.Unlock() | ||
|
||
if dumpCount > 0 { | ||
dumpCount++ | ||
return nil | ||
} | ||
|
||
dumpPath = dumpPrefix + strconv.FormatInt(time.Now().UnixNano(), 10) | ||
|
||
err := os.Mkdir(dumpPath, 0o755) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
files, err := component.ReadDir(".") | ||
if err != nil { | ||
os.RemoveAll(dumpPath) | ||
return err | ||
} | ||
|
||
err = dumpEmbedFSRecursive(files[0].Name(), dumpPath) | ||
if err != nil { | ||
os.RemoveAll(dumpPath) | ||
return err | ||
} | ||
|
||
err = os.Chmod(filepath.Join(dumpPath, "exe"), 0o755) | ||
if err != nil { | ||
os.RemoveAll(dumpPath) | ||
return err | ||
} | ||
|
||
dumpCount++ | ||
|
||
return nil | ||
} | ||
|
||
func freeComponent() { | ||
dumpMutex.Lock() | ||
defer dumpMutex.Unlock() | ||
|
||
dumpCount-- | ||
|
||
if dumpCount == 0 { | ||
os.RemoveAll(dumpPath) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package rpicamera | ||
|
||
//go:generate go run ./mtxrpicamdownloader |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
v1.0.0 | ||
v2.0.0 |
Oops, something went wrong.