|
|
|
@ -2,11 +2,6 @@ package core
@@ -2,11 +2,6 @@ package core
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
|
"context" |
|
|
|
|
"crypto/sha256" |
|
|
|
|
"crypto/tls" |
|
|
|
|
"encoding/hex" |
|
|
|
|
"fmt" |
|
|
|
|
"strings" |
|
|
|
|
"time" |
|
|
|
|
|
|
|
|
|
"github.com/bluenviron/gortsplib/v3" |
|
|
|
@ -19,37 +14,6 @@ import (
@@ -19,37 +14,6 @@ import (
|
|
|
|
|
"github.com/bluenviron/mediamtx/internal/logger" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
type rtspSourceParent interface { |
|
|
|
|
logger.Writer |
|
|
|
|
sourceStaticImplSetReady(req pathSourceStaticSetReadyReq) pathSourceStaticSetReadyRes |
|
|
|
|
sourceStaticImplSetNotReady(req pathSourceStaticSetNotReadyReq) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
type rtspSource struct { |
|
|
|
|
readTimeout conf.StringDuration |
|
|
|
|
writeTimeout conf.StringDuration |
|
|
|
|
readBufferCount int |
|
|
|
|
parent rtspSourceParent |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func newRTSPSource( |
|
|
|
|
readTimeout conf.StringDuration, |
|
|
|
|
writeTimeout conf.StringDuration, |
|
|
|
|
readBufferCount int, |
|
|
|
|
parent rtspSourceParent, |
|
|
|
|
) *rtspSource { |
|
|
|
|
return &rtspSource{ |
|
|
|
|
readTimeout: readTimeout, |
|
|
|
|
writeTimeout: writeTimeout, |
|
|
|
|
readBufferCount: readBufferCount, |
|
|
|
|
parent: parent, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (s *rtspSource) Log(level logger.Level, format string, args ...interface{}) { |
|
|
|
|
s.parent.Log(level, "[rtsp source] "+format, args...) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func createRangeHeader(cnf *conf.PathConf) (*headers.Range, error) { |
|
|
|
|
switch cnf.RtspRangeType { |
|
|
|
|
case conf.RtspRangeTypeClock: |
|
|
|
@ -95,33 +59,44 @@ func createRangeHeader(cnf *conf.PathConf) (*headers.Range, error) {
@@ -95,33 +59,44 @@ func createRangeHeader(cnf *conf.PathConf) (*headers.Range, error) {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// run implements sourceStaticImpl.
|
|
|
|
|
func (s *rtspSource) run(ctx context.Context, cnf *conf.PathConf, reloadConf chan *conf.PathConf) error { |
|
|
|
|
s.Log(logger.Debug, "connecting") |
|
|
|
|
type rtspSourceParent interface { |
|
|
|
|
logger.Writer |
|
|
|
|
sourceStaticImplSetReady(req pathSourceStaticSetReadyReq) pathSourceStaticSetReadyRes |
|
|
|
|
sourceStaticImplSetNotReady(req pathSourceStaticSetNotReadyReq) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var tlsConfig *tls.Config |
|
|
|
|
if cnf.SourceFingerprint != "" { |
|
|
|
|
tlsConfig = &tls.Config{ |
|
|
|
|
InsecureSkipVerify: true, |
|
|
|
|
VerifyConnection: func(cs tls.ConnectionState) error { |
|
|
|
|
h := sha256.New() |
|
|
|
|
h.Write(cs.PeerCertificates[0].Raw) |
|
|
|
|
hstr := hex.EncodeToString(h.Sum(nil)) |
|
|
|
|
fingerprintLower := strings.ToLower(cnf.SourceFingerprint) |
|
|
|
|
|
|
|
|
|
if hstr != fingerprintLower { |
|
|
|
|
return fmt.Errorf("server fingerprint do not match: expected %s, got %s", |
|
|
|
|
fingerprintLower, hstr) |
|
|
|
|
} |
|
|
|
|
type rtspSource struct { |
|
|
|
|
readTimeout conf.StringDuration |
|
|
|
|
writeTimeout conf.StringDuration |
|
|
|
|
readBufferCount int |
|
|
|
|
parent rtspSourceParent |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return nil |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
func newRTSPSource( |
|
|
|
|
readTimeout conf.StringDuration, |
|
|
|
|
writeTimeout conf.StringDuration, |
|
|
|
|
readBufferCount int, |
|
|
|
|
parent rtspSourceParent, |
|
|
|
|
) *rtspSource { |
|
|
|
|
return &rtspSource{ |
|
|
|
|
readTimeout: readTimeout, |
|
|
|
|
writeTimeout: writeTimeout, |
|
|
|
|
readBufferCount: readBufferCount, |
|
|
|
|
parent: parent, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (s *rtspSource) Log(level logger.Level, format string, args ...interface{}) { |
|
|
|
|
s.parent.Log(level, "[rtsp source] "+format, args...) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// run implements sourceStaticImpl.
|
|
|
|
|
func (s *rtspSource) run(ctx context.Context, cnf *conf.PathConf, reloadConf chan *conf.PathConf) error { |
|
|
|
|
s.Log(logger.Debug, "connecting") |
|
|
|
|
|
|
|
|
|
c := &gortsplib.Client{ |
|
|
|
|
Transport: cnf.SourceProtocol.Transport, |
|
|
|
|
TLSConfig: tlsConfig, |
|
|
|
|
TLSConfig: tlsConfigForFingerprint(cnf.SourceFingerprint), |
|
|
|
|
ReadTimeout: time.Duration(s.readTimeout), |
|
|
|
|
WriteTimeout: time.Duration(s.writeTimeout), |
|
|
|
|
ReadBufferCount: s.readBufferCount, |
|
|
|
|