rpicamera: support changing parameters without interrupting the stream (#1463)

This commit is contained in:
Alessandro Ros
2023-02-13 12:12:04 +01:00
committed by GitHub
parent 69c9e57983
commit b461f15a4c
33 changed files with 837 additions and 630 deletions

View File

@@ -30,23 +30,17 @@ type rtmpSourceParent interface {
}
type rtmpSource struct {
ur string
fingerprint string
readTimeout conf.StringDuration
writeTimeout conf.StringDuration
parent rtmpSourceParent
}
func newRTMPSource(
ur string,
fingerprint string,
readTimeout conf.StringDuration,
writeTimeout conf.StringDuration,
parent rtmpSourceParent,
) *rtmpSource {
return &rtmpSource{
ur: ur,
fingerprint: fingerprint,
readTimeout: readTimeout,
writeTimeout: writeTimeout,
parent: parent,
@@ -58,10 +52,10 @@ func (s *rtmpSource) Log(level logger.Level, format string, args ...interface{})
}
// run implements sourceStaticImpl.
func (s *rtmpSource) run(ctx context.Context) error {
func (s *rtmpSource) run(ctx context.Context, cnf *conf.PathConf, reloadConf chan *conf.PathConf) error {
s.Log(logger.Debug, "connecting")
u, err := url.Parse(s.ur)
u, err := url.Parse(cnf.Source)
if err != nil {
return err
}
@@ -86,7 +80,7 @@ func (s *rtmpSource) run(ctx context.Context) error {
h := sha256.New()
h.Write(cs.PeerCertificates[0].Raw)
hstr := hex.EncodeToString(h.Sum(nil))
fingerprintLower := strings.ToLower(s.fingerprint)
fingerprintLower := strings.ToLower(cnf.SourceFingerprint)
if hstr != fingerprintLower {
return fmt.Errorf("server fingerprint do not match: expected %s, got %s",
@@ -213,15 +207,19 @@ func (s *rtmpSource) run(ctx context.Context) error {
}()
}()
select {
case err := <-readDone:
nconn.Close()
return err
for {
select {
case err := <-readDone:
nconn.Close()
return err
case <-ctx.Done():
nconn.Close()
<-readDone
return nil
case <-reloadConf:
case <-ctx.Done():
nconn.Close()
<-readDone
return nil
}
}
}