forked from External/mediamtx
parent
22414bb38c
commit
0c131a2e92
11 changed files with 71 additions and 33 deletions
|
|
@ -310,6 +310,7 @@ func (p *Core) createResources(initial bool) error {
|
|||
|
||||
if p.pathManager == nil {
|
||||
p.pathManager = newPathManager(
|
||||
p.conf.LogLevel,
|
||||
p.conf.ExternalAuthenticationURL,
|
||||
p.conf.RTSPAddress,
|
||||
p.conf.AuthMethods,
|
||||
|
|
@ -614,6 +615,7 @@ func (p *Core) closeResources(newConf *conf.Conf, calledByAPI bool) {
|
|||
closeLogger
|
||||
|
||||
closePathManager := newConf == nil ||
|
||||
newConf.LogLevel != p.conf.LogLevel ||
|
||||
newConf.ExternalAuthenticationURL != p.conf.ExternalAuthenticationURL ||
|
||||
newConf.RTSPAddress != p.conf.RTSPAddress ||
|
||||
!reflect.DeepEqual(newConf.AuthMethods, p.conf.AuthMethods) ||
|
||||
|
|
|
|||
|
|
@ -64,6 +64,7 @@ type pathAPIPathsGetReq struct {
|
|||
}
|
||||
|
||||
type path struct {
|
||||
logLevel conf.LogLevel
|
||||
rtspAddress string
|
||||
readTimeout conf.StringDuration
|
||||
writeTimeout conf.StringDuration
|
||||
|
|
@ -116,6 +117,7 @@ type path struct {
|
|||
|
||||
func newPath(
|
||||
parentCtx context.Context,
|
||||
logLevel conf.LogLevel,
|
||||
rtspAddress string,
|
||||
readTimeout conf.StringDuration,
|
||||
writeTimeout conf.StringDuration,
|
||||
|
|
@ -132,6 +134,7 @@ func newPath(
|
|||
ctx, ctxCancel := context.WithCancel(parentCtx)
|
||||
|
||||
pa := &path{
|
||||
logLevel: logLevel,
|
||||
rtspAddress: rtspAddress,
|
||||
readTimeout: readTimeout,
|
||||
writeTimeout: writeTimeout,
|
||||
|
|
@ -206,6 +209,7 @@ func (pa *path) run() {
|
|||
|
||||
pa.source = &staticSourceHandler{
|
||||
conf: pa.conf,
|
||||
logLevel: pa.logLevel,
|
||||
readTimeout: pa.readTimeout,
|
||||
writeTimeout: pa.writeTimeout,
|
||||
writeQueueSize: pa.writeQueueSize,
|
||||
|
|
|
|||
|
|
@ -79,6 +79,7 @@ type pathManagerParent interface {
|
|||
}
|
||||
|
||||
type pathManager struct {
|
||||
logLevel conf.LogLevel
|
||||
externalAuthenticationURL string
|
||||
rtspAddress string
|
||||
authMethods conf.AuthMethods
|
||||
|
|
@ -112,6 +113,7 @@ type pathManager struct {
|
|||
}
|
||||
|
||||
func newPathManager(
|
||||
logLevel conf.LogLevel,
|
||||
externalAuthenticationURL string,
|
||||
rtspAddress string,
|
||||
authMethods conf.AuthMethods,
|
||||
|
|
@ -126,6 +128,7 @@ func newPathManager(
|
|||
ctx, ctxCancel := context.WithCancel(context.Background())
|
||||
|
||||
pm := &pathManager{
|
||||
logLevel: logLevel,
|
||||
externalAuthenticationURL: externalAuthenticationURL,
|
||||
rtspAddress: rtspAddress,
|
||||
authMethods: authMethods,
|
||||
|
|
@ -400,6 +403,7 @@ func (pm *pathManager) createPath(
|
|||
) {
|
||||
pa := newPath(
|
||||
pm.ctx,
|
||||
pm.logLevel,
|
||||
pm.rtspAddress,
|
||||
pm.readTimeout,
|
||||
pm.writeTimeout,
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ type staticSourceHandlerParent interface {
|
|||
// staticSourceHandler is a static source handler.
|
||||
type staticSourceHandler struct {
|
||||
conf *conf.Path
|
||||
logLevel conf.LogLevel
|
||||
readTimeout conf.StringDuration
|
||||
writeTimeout conf.StringDuration
|
||||
writeQueueSize int
|
||||
|
|
@ -108,7 +109,8 @@ func (s *staticSourceHandler) initialize() {
|
|||
|
||||
case s.resolvedSource == "rpiCamera":
|
||||
s.instance = &rpicamerasource.Source{
|
||||
Parent: s,
|
||||
LogLevel: s.logLevel,
|
||||
Parent: s,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -126,13 +126,23 @@ static void set_hdr(bool hdr) {
|
|||
}
|
||||
|
||||
bool camera_create(const parameters_t *params, camera_frame_cb frame_cb, camera_t **cam) {
|
||||
std::unique_ptr<CameraPriv> camp = std::make_unique<CameraPriv>();
|
||||
|
||||
set_hdr(params->hdr);
|
||||
|
||||
if (strcmp(params->log_level, "debug") == 0) {
|
||||
setenv("LIBCAMERA_LOG_LEVELS", "*:DEBUG", 1);
|
||||
} else if (strcmp(params->log_level, "info") == 0) {
|
||||
setenv("LIBCAMERA_LOG_LEVELS", "*:INFO", 1);
|
||||
} else if (strcmp(params->log_level, "warn") == 0) {
|
||||
setenv("LIBCAMERA_LOG_LEVELS", "*:WARN", 1);
|
||||
} else { // error
|
||||
setenv("LIBCAMERA_LOG_LEVELS", "*:ERROR", 1);
|
||||
}
|
||||
|
||||
// We make sure to set the environment variable before libcamera init
|
||||
setenv("LIBCAMERA_RPI_TUNING_FILE", params->tuning_file, 1);
|
||||
|
||||
std::unique_ptr<CameraPriv> camp = std::make_unique<CameraPriv>();
|
||||
|
||||
camp->camera_manager = std::make_unique<CameraManager>();
|
||||
int ret = camp->camera_manager->start();
|
||||
if (ret != 0) {
|
||||
|
|
|
|||
|
|
@ -37,7 +37,9 @@ bool parameters_unserialize(parameters_t *params, const uint8_t *buf, size_t buf
|
|||
char *key = strsep(&entry, ":");
|
||||
char *val = strsep(&entry, ":");
|
||||
|
||||
if (strcmp(key, "CameraID") == 0) {
|
||||
if (strcmp(key, "LogLevel") == 0) {
|
||||
params->log_level = base64_decode(val);
|
||||
} else if (strcmp(key, "CameraID") == 0) {
|
||||
params->camera_id = atoi(val);
|
||||
} else if (strcmp(key, "Width") == 0) {
|
||||
params->width = atoi(val);
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
#include "sensor_mode.h"
|
||||
|
||||
typedef struct {
|
||||
char *log_level;
|
||||
unsigned int camera_id;
|
||||
unsigned int width;
|
||||
unsigned int height;
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import (
|
|||
|
||||
// Params is a set of camera parameters.
|
||||
type Params struct {
|
||||
LogLevel string
|
||||
CameraID int
|
||||
Width int
|
||||
Height int
|
||||
|
|
|
|||
|
|
@ -111,8 +111,10 @@ func checkLibraries64Bit() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// RPICamera is a RPI Camera reader.
|
||||
type RPICamera struct {
|
||||
onData func(time.Duration, [][]byte)
|
||||
Params Params
|
||||
OnData func(time.Duration, [][]byte)
|
||||
|
||||
cmd *exec.Cmd
|
||||
pipeConf *pipe
|
||||
|
|
@ -122,31 +124,25 @@ type RPICamera struct {
|
|||
readerDone chan error
|
||||
}
|
||||
|
||||
func New(
|
||||
params Params,
|
||||
onData func(time.Duration, [][]byte),
|
||||
) (*RPICamera, error) {
|
||||
// Initialize initializes a RPICamera.
|
||||
func (c *RPICamera) Initialize() error {
|
||||
if runtime.GOARCH == "arm" {
|
||||
err := checkLibraries64Bit()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
c := &RPICamera{
|
||||
onData: onData,
|
||||
}
|
||||
|
||||
var err error
|
||||
c.pipeConf, err = newPipe()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
|
||||
c.pipeVideo, err = newPipe()
|
||||
if err != nil {
|
||||
c.pipeConf.close()
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
|
||||
env := []string{
|
||||
|
|
@ -158,10 +154,10 @@ func New(
|
|||
if err != nil {
|
||||
c.pipeConf.close()
|
||||
c.pipeVideo.close()
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
|
||||
c.pipeConf.write(append([]byte{'c'}, params.serialize()...))
|
||||
c.pipeConf.write(append([]byte{'c'}, c.Params.serialize()...))
|
||||
|
||||
c.waitDone = make(chan error)
|
||||
go func() {
|
||||
|
|
@ -178,7 +174,7 @@ func New(
|
|||
c.pipeConf.close()
|
||||
c.pipeVideo.close()
|
||||
<-c.readerDone
|
||||
return nil, fmt.Errorf("process exited unexpectedly")
|
||||
return fmt.Errorf("process exited unexpectedly")
|
||||
|
||||
case err := <-c.readerDone:
|
||||
if err != nil {
|
||||
|
|
@ -186,7 +182,7 @@ func New(
|
|||
<-c.waitDone
|
||||
c.pipeConf.close()
|
||||
c.pipeVideo.close()
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -195,7 +191,7 @@ func New(
|
|||
c.readerDone <- c.readData()
|
||||
}()
|
||||
|
||||
return c, nil
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *RPICamera) Close() {
|
||||
|
|
@ -248,6 +244,6 @@ func (c *RPICamera) readData() error {
|
|||
return err
|
||||
}
|
||||
|
||||
c.onData(dts, nalus)
|
||||
c.OnData(dts, nalus)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,14 +14,14 @@ func Cleanup() {
|
|||
}
|
||||
|
||||
// RPICamera is a RPI Camera reader.
|
||||
type RPICamera struct{}
|
||||
type RPICamera struct {
|
||||
Params Params
|
||||
OnData func(time.Duration, [][]byte)
|
||||
}
|
||||
|
||||
// New allocates a RPICamera.
|
||||
func New(
|
||||
_ Params,
|
||||
_ func(time.Duration, [][]byte),
|
||||
) (*RPICamera, error) {
|
||||
return nil, fmt.Errorf("server was compiled without support for the Raspberry Pi Camera")
|
||||
// Initialize initializes a RPICamera.
|
||||
func (c *RPICamera) Initialize() error {
|
||||
return fmt.Errorf("server was compiled without support for the Raspberry Pi Camera")
|
||||
}
|
||||
|
||||
// Close closes a RPICamera.
|
||||
|
|
|
|||
|
|
@ -15,8 +15,19 @@ import (
|
|||
"github.com/bluenviron/mediamtx/internal/unit"
|
||||
)
|
||||
|
||||
func paramsFromConf(cnf *conf.Path) rpicamera.Params {
|
||||
func paramsFromConf(logLevel conf.LogLevel, cnf *conf.Path) rpicamera.Params {
|
||||
return rpicamera.Params{
|
||||
LogLevel: func() string {
|
||||
switch logLevel {
|
||||
case conf.LogLevel(logger.Debug):
|
||||
return "debug"
|
||||
case conf.LogLevel(logger.Info):
|
||||
return "info"
|
||||
case conf.LogLevel(logger.Warn):
|
||||
return "warn"
|
||||
}
|
||||
return "error"
|
||||
}(),
|
||||
CameraID: cnf.RPICameraCamID,
|
||||
Width: cnf.RPICameraWidth,
|
||||
Height: cnf.RPICameraHeight,
|
||||
|
|
@ -54,7 +65,8 @@ func paramsFromConf(cnf *conf.Path) rpicamera.Params {
|
|||
|
||||
// Source is a Raspberry Pi Camera static source.
|
||||
type Source struct {
|
||||
Parent defs.StaticSourceParent
|
||||
LogLevel conf.LogLevel
|
||||
Parent defs.StaticSourceParent
|
||||
}
|
||||
|
||||
// Log implements logger.Writer.
|
||||
|
|
@ -96,7 +108,11 @@ func (s *Source) Run(params defs.StaticSourceRunParams) error {
|
|||
})
|
||||
}
|
||||
|
||||
cam, err := rpicamera.New(paramsFromConf(params.Conf), onData)
|
||||
cam := &rpicamera.RPICamera{
|
||||
Params: paramsFromConf(s.LogLevel, params.Conf),
|
||||
OnData: onData,
|
||||
}
|
||||
err := cam.Initialize()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -111,7 +127,7 @@ func (s *Source) Run(params defs.StaticSourceRunParams) error {
|
|||
for {
|
||||
select {
|
||||
case cnf := <-params.ReloadConf:
|
||||
cam.ReloadParams(paramsFromConf(cnf))
|
||||
cam.ReloadParams(paramsFromConf(s.LogLevel, cnf))
|
||||
|
||||
case <-params.Context.Done():
|
||||
return nil
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue