mirror of
https://github.com/aler9/rtsp-simple-server
synced 2025-09-26 19:51:26 +08:00
rtsp: support reading streams tunneled with HTTP or WebSocket (#4986)
This commit is contained in:
@@ -4,7 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net"
|
||||
gourl "net/url"
|
||||
"net/url"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"sort"
|
||||
@@ -372,8 +372,12 @@ func (pconf *Path) validate(
|
||||
}
|
||||
|
||||
case strings.HasPrefix(pconf.Source, "rtsp://") ||
|
||||
strings.HasPrefix(pconf.Source, "rtsps://"):
|
||||
_, err := base.ParseURL(pconf.Source)
|
||||
strings.HasPrefix(pconf.Source, "rtsps://") ||
|
||||
strings.HasPrefix(pconf.Source, "rtsp+http://") ||
|
||||
strings.HasPrefix(pconf.Source, "rtsps+http://") ||
|
||||
strings.HasPrefix(pconf.Source, "rtsp+ws://") ||
|
||||
strings.HasPrefix(pconf.Source, "rtsps+ws://"):
|
||||
_, err := url.Parse(pconf.Source)
|
||||
if err != nil {
|
||||
return fmt.Errorf("'%s' is not a valid URL", pconf.Source)
|
||||
}
|
||||
@@ -390,7 +394,7 @@ func (pconf *Path) validate(
|
||||
|
||||
case strings.HasPrefix(pconf.Source, "rtmp://") ||
|
||||
strings.HasPrefix(pconf.Source, "rtmps://"):
|
||||
u, err := gourl.Parse(pconf.Source)
|
||||
u, err := url.Parse(pconf.Source)
|
||||
if err != nil {
|
||||
return fmt.Errorf("'%s' is not a valid URL", pconf.Source)
|
||||
}
|
||||
@@ -406,15 +410,11 @@ func (pconf *Path) validate(
|
||||
|
||||
case strings.HasPrefix(pconf.Source, "http://") ||
|
||||
strings.HasPrefix(pconf.Source, "https://"):
|
||||
u, err := gourl.Parse(pconf.Source)
|
||||
u, err := url.Parse(pconf.Source)
|
||||
if err != nil {
|
||||
return fmt.Errorf("'%s' is not a valid URL", pconf.Source)
|
||||
}
|
||||
|
||||
if u.Scheme != "http" && u.Scheme != "https" {
|
||||
return fmt.Errorf("'%s' is not a valid URL", pconf.Source)
|
||||
}
|
||||
|
||||
if u.User != nil {
|
||||
pass, _ := u.User.Password()
|
||||
user := u.User.Username()
|
||||
@@ -454,14 +454,14 @@ func (pconf *Path) validate(
|
||||
}
|
||||
|
||||
case strings.HasPrefix(pconf.Source, "srt://"):
|
||||
_, err := gourl.Parse(pconf.Source)
|
||||
_, err := url.Parse(pconf.Source)
|
||||
if err != nil {
|
||||
return fmt.Errorf("'%s' is not a valid URL", pconf.Source)
|
||||
}
|
||||
|
||||
case strings.HasPrefix(pconf.Source, "whep://") ||
|
||||
strings.HasPrefix(pconf.Source, "wheps://"):
|
||||
_, err := gourl.Parse(pconf.Source)
|
||||
_, err := url.Parse(pconf.Source)
|
||||
if err != nil {
|
||||
return fmt.Errorf("'%s' is not a valid URL", pconf.Source)
|
||||
}
|
||||
|
@@ -95,7 +95,11 @@ func (s *Handler) Initialize() {
|
||||
|
||||
switch {
|
||||
case strings.HasPrefix(s.Conf.Source, "rtsp://") ||
|
||||
strings.HasPrefix(s.Conf.Source, "rtsps://"):
|
||||
strings.HasPrefix(s.Conf.Source, "rtsps://") ||
|
||||
strings.HasPrefix(s.Conf.Source, "rtsp+http://") ||
|
||||
strings.HasPrefix(s.Conf.Source, "rtsps+http://") ||
|
||||
strings.HasPrefix(s.Conf.Source, "rtsp+ws://") ||
|
||||
strings.HasPrefix(s.Conf.Source, "rtsps+ws://"):
|
||||
s.instance = &ssrtsp.Source{
|
||||
ReadTimeout: s.ReadTimeout,
|
||||
WriteTimeout: s.WriteTimeout,
|
||||
|
@@ -2,6 +2,8 @@
|
||||
package rtsp
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"regexp"
|
||||
"time"
|
||||
|
||||
"github.com/bluenviron/gortsplib/v5"
|
||||
@@ -116,14 +118,37 @@ func (s *Source) Run(params defs.StaticSourceRunParams) error {
|
||||
decodeErrors.Start()
|
||||
defer decodeErrors.Stop()
|
||||
|
||||
u, err := base.ParseURL(params.ResolvedSource)
|
||||
u0, err := url.Parse(params.ResolvedSource)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var scheme string
|
||||
if u0.Scheme == "rtsp" || u0.Scheme == "rtsp+http" || u0.Scheme == "rtsp+ws" {
|
||||
scheme = "rtsp"
|
||||
} else {
|
||||
scheme = "rtsps"
|
||||
}
|
||||
|
||||
var tunnel gortsplib.Tunnel
|
||||
switch u0.Scheme {
|
||||
case "rtsp+http", "rtsps+http":
|
||||
tunnel = gortsplib.TunnelHTTP
|
||||
case "rtsp+ws", "rtsps+ws":
|
||||
tunnel = gortsplib.TunnelWebSocket
|
||||
default:
|
||||
tunnel = gortsplib.TunnelNone
|
||||
}
|
||||
|
||||
u, err := base.ParseURL(regexp.MustCompile("^.*?://").ReplaceAllString(params.ResolvedSource, "rtsp://"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
c := &gortsplib.Client{
|
||||
Scheme: u.Scheme,
|
||||
Scheme: scheme,
|
||||
Host: u.Host,
|
||||
Tunnel: tunnel,
|
||||
Protocol: params.Conf.RTSPTransport.Protocol,
|
||||
TLSConfig: tls.MakeConfig(u.Hostname(), params.Conf.SourceFingerprint),
|
||||
ReadTimeout: time.Duration(s.ReadTimeout),
|
||||
|
Reference in New Issue
Block a user