Add RTSPS listen

pull/234/head
Jae-Sung Lee 2 years ago
parent c5eaa242c4
commit d84ceeb67e

@ -45,6 +45,10 @@
"rtsp": {
"enable": true,
"addr": ":5544",
"rtsps_enable": true,
"rtsps_addr": ":5322",
"rtsps_cert_file": "./conf/cert.pem",
"rtsps_key_file": "./conf/key.pem",
"out_wait_key_frame_flag": true,
"auth_enable": false,
"auth_method": 1,

@ -27,6 +27,7 @@ const (
DefaultHttpsPort = 443
DefaultRtspPort = 554
DefaultRtmpsPort = 443
DefaultRtspsPort = 322
)
type UrlPathContext struct {
@ -112,6 +113,8 @@ func ParseUrl(rawUrl string, defaultPort int) (ctx UrlContext, err error) {
defaultPort = DefaultRtspPort
case "rtmps":
defaultPort = DefaultRtmpsPort
case "rtsps":
defaultPort = DefaultRtspsPort
}
}
@ -203,7 +206,7 @@ func ParseRtspUrl(rawUrl string) (ctx UrlContext, err error) {
return
}
// 注意存在一种情况使用rtsp pull session直接拉取没有url path的流所以不检查ctx.Path
if ctx.Scheme != "rtsp" || ctx.Host == "" {
if (ctx.Scheme != "rtsp" && ctx.Scheme != "rtsps") || ctx.Host == "" {
return ctx, fmt.Errorf("%w. url=%s", ErrInvalidUrl, rawUrl)
}

@ -89,6 +89,10 @@ type HlsConfig struct {
type RtspConfig struct {
Enable bool `json:"enable"`
Addr string `json:"addr"`
RtspsEnable bool `json:"rtsps_enable"`
RtspsAddr string `json:"rtsps_addr"`
RtspsCertFile string `json:"rtsps_cert_file"`
RtspsKeyFile string `json:"rtsps_key_file"`
OutWaitKeyFrameFlag bool `json:"out_wait_key_frame_flag"`
rtsp.ServerAuthConfig
}

@ -10,10 +10,11 @@ package logic
import (
"encoding/json"
"github.com/q191201771/lal/pkg/gb28181"
"strings"
"sync"
"github.com/q191201771/lal/pkg/gb28181"
"github.com/q191201771/lal/pkg/base"
"github.com/q191201771/lal/pkg/hls"
"github.com/q191201771/lal/pkg/httpflv"
@ -574,7 +575,7 @@ func (group *Group) inSessionUniqueKey() string {
}
func (group *Group) shouldStartRtspRemuxer() bool {
return group.config.RtspConfig.Enable
return group.config.RtspConfig.Enable || group.config.RtspConfig.RtspsEnable
}
func (group *Group) shouldStartMpegtsRemuxer() bool {

@ -48,6 +48,7 @@ type ServerManager struct {
rtmpServer *rtmp.Server
rtmpsServer *rtmp.Server
rtspServer *rtsp.Server
rtspsServer *rtsp.Server
httpApiServer *HttpApiServer
pprofServer *http.Server
exitChan chan struct{}
@ -130,6 +131,9 @@ Doc: %s
if sm.config.RtspConfig.Enable {
sm.rtspServer = rtsp.NewServer(sm.config.RtspConfig.Addr, sm, sm.config.RtspConfig.ServerAuthConfig)
}
if sm.config.RtspConfig.RtspsEnable {
sm.rtspsServer = rtsp.NewServer(sm.config.RtspConfig.RtspsAddr, sm, sm.config.RtspConfig.ServerAuthConfig)
}
if sm.config.HttpApiConfig.Enable {
sm.httpApiServer = NewHttpApiServer(sm.config.HttpApiConfig.Addr, sm)
}
@ -246,6 +250,17 @@ func (sm *ServerManager) RunLoop() error {
}()
}
if sm.rtspsServer != nil {
if err := sm.rtspsServer.ListenWithTLS(sm.config.RtspConfig.RtspsCertFile, sm.config.RtspConfig.RtspsKeyFile); err != nil {
return err
}
go func() {
if err := sm.rtspsServer.RunLoop(); err != nil {
Log.Error(err)
}
}()
}
if sm.httpApiServer != nil {
if err := sm.httpApiServer.Listen(); err != nil {
return err
@ -323,10 +338,18 @@ func (sm *ServerManager) Dispose() {
sm.rtmpServer.Dispose()
}
if sm.rtmpsServer != nil {
sm.rtmpsServer.Dispose()
}
if sm.rtspServer != nil {
sm.rtspServer.Dispose()
}
if sm.rtspsServer != nil {
sm.rtspsServer.Dispose()
}
if sm.httpServerManager != nil {
sm.httpServerManager.Dispose()
}

@ -9,6 +9,7 @@
package rtsp
import (
"crypto/tls"
"net"
)
@ -81,6 +82,19 @@ func (s *Server) Listen() (err error) {
return
}
func (s *Server) ListenWithTLS(certFile, keyFile string) (err error) {
cert, err := tls.LoadX509KeyPair(certFile, keyFile)
if err != nil {
return
}
tlsConfig := &tls.Config{Certificates: []tls.Certificate{cert}}
if s.ln, err = tls.Listen("tcp", s.addr, tlsConfig); err != nil {
return
}
Log.Infof("start rtsps server listen. addr=%s", s.addr)
return
}
func (s *Server) RunLoop() error {
for {
conn, err := s.ln.Accept()

Loading…
Cancel
Save