Browse Source

add missing tests

pull/1128/head
aler9 3 years ago
parent
commit
afcb874657
  1. 63
      internal/core/api_test.go
  2. 5
      internal/core/rtmp_conn.go
  3. 1
      internal/core/rtmp_server.go

63
internal/core/api_test.go

@ -6,7 +6,9 @@ import ( @@ -6,7 +6,9 @@ import (
"encoding/json"
"fmt"
"io"
"net"
"net/http"
"net/url"
"os"
"testing"
"time"
@ -14,6 +16,8 @@ import ( @@ -14,6 +16,8 @@ import (
"github.com/aler9/gortsplib"
"github.com/aler9/gortsplib/pkg/mpeg4audio"
"github.com/stretchr/testify/require"
"github.com/aler9/rtsp-simple-server/internal/rtmp"
)
func httpRequest(method string, ur string, in interface{}, out interface{}) error {
@ -365,16 +369,23 @@ func TestAPIProtocolSpecificList(t *testing.T) { @@ -365,16 +369,23 @@ func TestAPIProtocolSpecificList(t *testing.T) {
"rtsp",
"rtsps",
"rtmp",
"rtmps",
"hls",
} {
t.Run(ca, func(t *testing.T) {
conf := "api: yes\n"
if ca == "rtsps" {
switch ca {
case "rtsps":
conf += "protocols: [tcp]\n" +
"encryption: strict\n" +
"serverCert: " + serverCertFpath + "\n" +
"serverKey: " + serverKeyFpath + "\n"
case "rtmps":
conf += "rtmpEncryption: strict\n" +
"rtmpServerCert: " + serverCertFpath + "\n" +
"rtmpServerKey: " + serverKeyFpath + "\n"
}
conf += "paths:\n" +
@ -409,17 +420,42 @@ func TestAPIProtocolSpecificList(t *testing.T) { @@ -409,17 +420,42 @@ func TestAPIProtocolSpecificList(t *testing.T) {
require.NoError(t, err)
defer source.Close()
case "rtmp":
cnt1, err := newContainer("ffmpeg", "source", []string{
"-re",
"-stream_loop", "-1",
"-i", "emptyvideo.mkv",
"-c", "copy",
"-f", "flv",
"rtmp://localhost:1935/test1/test2",
})
case "rtmp", "rtmps":
var port string
if ca == "rtmp" {
port = "1935"
} else {
port = "1936"
}
u, err := url.Parse("rtmp://127.0.0.1:" + port + "/mypath")
require.NoError(t, err)
nconn, err := func() (net.Conn, error) {
if ca == "rtmp" {
return net.Dial("tcp", u.Host)
}
return tls.Dial("tcp", u.Host, &tls.Config{InsecureSkipVerify: true})
}()
require.NoError(t, err)
defer nconn.Close()
conn := rtmp.NewConn(nconn)
err = conn.InitializeClient(u, true)
require.NoError(t, err)
videoTrack := &gortsplib.TrackH264{
PayloadType: 96,
SPS: []byte{ // 1920x1080 baseline
0x67, 0x42, 0xc0, 0x28, 0xd9, 0x00, 0x78, 0x02,
0x27, 0xe5, 0x84, 0x00, 0x00, 0x03, 0x00, 0x04,
0x00, 0x00, 0x03, 0x00, 0xf0, 0x3c, 0x60, 0xc9, 0x20,
},
PPS: []byte{0x08, 0x06, 0x07, 0x08},
}
err = conn.WriteTracks(videoTrack, nil)
require.NoError(t, err)
defer cnt1.close()
case "hls":
source := gortsplib.Client{}
@ -438,7 +474,7 @@ func TestAPIProtocolSpecificList(t *testing.T) { @@ -438,7 +474,7 @@ func TestAPIProtocolSpecificList(t *testing.T) {
}
switch ca {
case "rtsp", "rtsps", "rtmp":
case "rtsp", "rtsps", "rtmp", "rtmps":
var pa string
switch ca {
case "rtsp":
@ -449,6 +485,9 @@ func TestAPIProtocolSpecificList(t *testing.T) { @@ -449,6 +485,9 @@ func TestAPIProtocolSpecificList(t *testing.T) {
case "rtmp":
pa = "rtmpconns"
case "rtmps":
pa = "rtmpsconns"
}
var out struct {

5
internal/core/rtmp_conn.go

@ -56,6 +56,7 @@ type rtmpConnParent interface { @@ -56,6 +56,7 @@ type rtmpConnParent interface {
}
type rtmpConn struct {
isTLS bool
id string
externalAuthenticationURL string
rtspAddress string
@ -82,6 +83,7 @@ type rtmpConn struct { @@ -82,6 +83,7 @@ type rtmpConn struct {
func newRTMPConn(
parentCtx context.Context,
isTLS bool,
id string,
externalAuthenticationURL string,
rtspAddress string,
@ -99,6 +101,7 @@ func newRTMPConn( @@ -99,6 +101,7 @@ func newRTMPConn(
ctx, ctxCancel := context.WithCancel(parentCtx)
c := &rtmpConn{
isTLS: isTLS,
id: id,
externalAuthenticationURL: externalAuthenticationURL,
rtspAddress: rtspAddress,
@ -672,7 +675,7 @@ func (c *rtmpConn) apiReaderDescribe() interface{} { @@ -672,7 +675,7 @@ func (c *rtmpConn) apiReaderDescribe() interface{} {
// apiSourceDescribe implements source.
func (c *rtmpConn) apiSourceDescribe() interface{} {
var typ string
if s.isTLS {
if c.isTLS {
typ = "rtmpsConn"
} else {
typ = "rtmpConn"

1
internal/core/rtmp_server.go

@ -200,6 +200,7 @@ outer: @@ -200,6 +200,7 @@ outer:
c := newRTMPConn(
s.ctx,
s.isTLS,
id,
s.externalAuthenticationURL,
s.rtspAddress,

Loading…
Cancel
Save