Merge pull request #41 from allenporter/rtsp-tls

Add support for rtsps streams
This commit is contained in:
Andrey Semochkin 2021-11-13 13:42:08 +03:00 committed by GitHub
commit 022deeb641
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,6 +4,7 @@ import (
"bufio"
"bytes"
"crypto/md5"
"crypto/tls"
"encoding/base64"
"encoding/binary"
"errors"
@ -125,6 +126,14 @@ func Dial(options RTSPClientOptions) (*RTSPClient, error) {
if err != nil {
return nil, err
}
if client.pURL.Scheme == "rtsps" {
tlsConn := tls.Client(conn, &tls.Config{ServerName: client.pURL.Hostname()})
err = tlsConn.Handshake()
if err != nil {
return nil, err
}
conn = tlsConn
}
client.conn = conn
client.connRW = bufio.NewReadWriter(bufio.NewReader(conn), bufio.NewWriter(conn))
err = client.request(OPTIONS, nil, client.pURL.String(), false, false)
@ -485,7 +494,7 @@ func (client *RTSPClient) parseURL(rawURL string) error {
if l.Port() == "" {
l.Host = fmt.Sprintf("%s:%s", l.Host, "554")
}
if l.Scheme != "rtsp" {
if l.Scheme != "rtsp" && l.Scheme != "rtsps" {
l.Scheme = "rtsp"
}
client.pURL = l