|
|
|
|
@ -1,3 +1,4 @@
@@ -1,3 +1,4 @@
|
|
|
|
|
//nolint:dupl,lll
|
|
|
|
|
package core |
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
|
@ -6,7 +7,6 @@ import (
@@ -6,7 +7,6 @@ import (
|
|
|
|
|
"context" |
|
|
|
|
"crypto/tls" |
|
|
|
|
"encoding/json" |
|
|
|
|
"fmt" |
|
|
|
|
"io" |
|
|
|
|
"net" |
|
|
|
|
"net/http" |
|
|
|
|
@ -339,7 +339,7 @@ func TestAPIPathsGet(t *testing.T) {
@@ -339,7 +339,7 @@ func TestAPIPathsGet(t *testing.T) {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestAPIProtocolList(t *testing.T) { |
|
|
|
|
func TestAPIProtocolListGet(t *testing.T) { |
|
|
|
|
serverCertFpath, err := writeTempFile(serverCert) |
|
|
|
|
require.NoError(t, err) |
|
|
|
|
defer os.Remove(serverCertFpath) |
|
|
|
|
@ -552,388 +552,262 @@ func TestAPIProtocolList(t *testing.T) {
@@ -552,388 +552,262 @@ func TestAPIProtocolList(t *testing.T) {
|
|
|
|
|
time.Sleep(500 * time.Millisecond) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var pa string |
|
|
|
|
switch ca { |
|
|
|
|
case "rtsp conns", "rtsp sessions", "rtsps conns", "rtsps sessions", "rtmp", "rtmps", "srt": |
|
|
|
|
var pa string |
|
|
|
|
switch ca { |
|
|
|
|
case "rtsp conns": |
|
|
|
|
pa = "rtspconns" |
|
|
|
|
|
|
|
|
|
case "rtsp sessions": |
|
|
|
|
pa = "rtspsessions" |
|
|
|
|
|
|
|
|
|
case "rtsps conns": |
|
|
|
|
pa = "rtspsconns" |
|
|
|
|
|
|
|
|
|
case "rtsps sessions": |
|
|
|
|
pa = "rtspssessions" |
|
|
|
|
case "rtsp conns": |
|
|
|
|
pa = "rtspconns" |
|
|
|
|
|
|
|
|
|
case "rtmp": |
|
|
|
|
pa = "rtmpconns" |
|
|
|
|
case "rtsp sessions": |
|
|
|
|
pa = "rtspsessions" |
|
|
|
|
|
|
|
|
|
case "rtmps": |
|
|
|
|
pa = "rtmpsconns" |
|
|
|
|
case "rtsps conns": |
|
|
|
|
pa = "rtspsconns" |
|
|
|
|
|
|
|
|
|
case "srt": |
|
|
|
|
pa = "srtconns" |
|
|
|
|
} |
|
|
|
|
case "rtsps sessions": |
|
|
|
|
pa = "rtspssessions" |
|
|
|
|
|
|
|
|
|
type item struct { |
|
|
|
|
State string `json:"state"` |
|
|
|
|
Path string `json:"path"` |
|
|
|
|
Query string `json:"query"` |
|
|
|
|
} |
|
|
|
|
case "rtmp": |
|
|
|
|
pa = "rtmpconns" |
|
|
|
|
|
|
|
|
|
var out struct { |
|
|
|
|
ItemCount int `json:"itemCount"` |
|
|
|
|
Items []item `json:"items"` |
|
|
|
|
} |
|
|
|
|
httpRequest(t, hc, http.MethodGet, "http://localhost:9997/v3/"+pa+"/list", nil, &out) |
|
|
|
|
|
|
|
|
|
if ca != "rtsp conns" && ca != "rtsps conns" { |
|
|
|
|
require.Equal(t, item{ |
|
|
|
|
State: "publish", |
|
|
|
|
Path: "mypath", |
|
|
|
|
Query: "key=val", |
|
|
|
|
}, out.Items[0]) |
|
|
|
|
} |
|
|
|
|
case "rtmps": |
|
|
|
|
pa = "rtmpsconns" |
|
|
|
|
|
|
|
|
|
case "hls": |
|
|
|
|
type item struct { |
|
|
|
|
Created string `json:"created"` |
|
|
|
|
LastRequest string `json:"lastRequest"` |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var out struct { |
|
|
|
|
ItemCount int `json:"itemCount"` |
|
|
|
|
Items []item `json:"items"` |
|
|
|
|
} |
|
|
|
|
httpRequest(t, hc, http.MethodGet, "http://localhost:9997/v3/hlsmuxers/list", nil, &out) |
|
|
|
|
|
|
|
|
|
s := fmt.Sprintf("^%d-", time.Now().Year()) |
|
|
|
|
require.Regexp(t, s, out.Items[0].Created) |
|
|
|
|
require.Regexp(t, s, out.Items[0].LastRequest) |
|
|
|
|
pa = "hlsmuxers" |
|
|
|
|
|
|
|
|
|
case "webrtc": |
|
|
|
|
type item struct { |
|
|
|
|
PeerConnectionEstablished bool `json:"peerConnectionEstablished"` |
|
|
|
|
State string `json:"state"` |
|
|
|
|
Path string `json:"path"` |
|
|
|
|
Query string `json:"query"` |
|
|
|
|
} |
|
|
|
|
pa = "webrtcsessions" |
|
|
|
|
|
|
|
|
|
var out struct { |
|
|
|
|
ItemCount int `json:"itemCount"` |
|
|
|
|
Items []item `json:"items"` |
|
|
|
|
} |
|
|
|
|
httpRequest(t, hc, http.MethodGet, "http://localhost:9997/v3/webrtcsessions/list", nil, &out) |
|
|
|
|
|
|
|
|
|
require.Equal(t, item{ |
|
|
|
|
PeerConnectionEstablished: true, |
|
|
|
|
State: "read", |
|
|
|
|
Path: "mypath", |
|
|
|
|
Query: "key=val", |
|
|
|
|
}, out.Items[0]) |
|
|
|
|
case "srt": |
|
|
|
|
pa = "srtconns" |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestAPIProtocolGet(t *testing.T) { |
|
|
|
|
serverCertFpath, err := writeTempFile(serverCert) |
|
|
|
|
require.NoError(t, err) |
|
|
|
|
defer os.Remove(serverCertFpath) |
|
|
|
|
|
|
|
|
|
serverKeyFpath, err := writeTempFile(serverKey) |
|
|
|
|
require.NoError(t, err) |
|
|
|
|
defer os.Remove(serverKeyFpath) |
|
|
|
|
|
|
|
|
|
for _, ca := range []string{ |
|
|
|
|
"rtsp conns", |
|
|
|
|
"rtsp sessions", |
|
|
|
|
"rtsps conns", |
|
|
|
|
"rtsps sessions", |
|
|
|
|
"rtmp", |
|
|
|
|
"rtmps", |
|
|
|
|
"hls", |
|
|
|
|
"webrtc", |
|
|
|
|
"srt", |
|
|
|
|
} { |
|
|
|
|
t.Run(ca, func(t *testing.T) { |
|
|
|
|
conf := "api: yes\n" |
|
|
|
|
var out1 interface{} |
|
|
|
|
httpRequest(t, hc, http.MethodGet, "http://localhost:9997/v3/"+pa+"/list", nil, &out1) |
|
|
|
|
|
|
|
|
|
switch ca { |
|
|
|
|
case "rtsps conns", "rtsps sessions": |
|
|
|
|
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" + |
|
|
|
|
" all_others:\n" |
|
|
|
|
|
|
|
|
|
p, ok := newInstance(conf) |
|
|
|
|
require.Equal(t, true, ok) |
|
|
|
|
defer p.Close() |
|
|
|
|
|
|
|
|
|
hc := &http.Client{Transport: &http.Transport{}} |
|
|
|
|
|
|
|
|
|
medi := testMediaH264 |
|
|
|
|
|
|
|
|
|
switch ca { //nolint:dupl
|
|
|
|
|
case "rtsp conns", "rtsp sessions": |
|
|
|
|
source := gortsplib.Client{} |
|
|
|
|
|
|
|
|
|
err := source.StartRecording("rtsp://localhost:8554/mypath", |
|
|
|
|
&description.Session{Medias: []*description.Media{medi}}) |
|
|
|
|
require.NoError(t, err) |
|
|
|
|
defer source.Close() |
|
|
|
|
|
|
|
|
|
case "rtsps conns", "rtsps sessions": |
|
|
|
|
source := gortsplib.Client{ |
|
|
|
|
TLSConfig: &tls.Config{InsecureSkipVerify: true}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
err := source.StartRecording("rtsps://localhost:8322/mypath", |
|
|
|
|
&description.Session{Medias: []*description.Media{medi}}) |
|
|
|
|
require.NoError(t, err) |
|
|
|
|
defer source.Close() |
|
|
|
|
|
|
|
|
|
case "rtmp", "rtmps": |
|
|
|
|
var port string |
|
|
|
|
if ca == "rtmp" { |
|
|
|
|
port = "1935" |
|
|
|
|
} else { |
|
|
|
|
port = "1936" |
|
|
|
|
} |
|
|
|
|
case "rtsp conns": |
|
|
|
|
require.Equal(t, map[string]interface{}{ |
|
|
|
|
"pageCount": float64(1), |
|
|
|
|
"itemCount": float64(1), |
|
|
|
|
"items": []interface{}{ |
|
|
|
|
map[string]interface{}{ |
|
|
|
|
"bytesReceived": out1.(map[string]interface{})["items"].([]interface{})[0].(map[string]interface{})["bytesReceived"], |
|
|
|
|
"bytesSent": out1.(map[string]interface{})["items"].([]interface{})[0].(map[string]interface{})["bytesSent"], |
|
|
|
|
"created": out1.(map[string]interface{})["items"].([]interface{})[0].(map[string]interface{})["created"], |
|
|
|
|
"id": out1.(map[string]interface{})["items"].([]interface{})[0].(map[string]interface{})["id"], |
|
|
|
|
"remoteAddr": out1.(map[string]interface{})["items"].([]interface{})[0].(map[string]interface{})["remoteAddr"], |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
}, out1) |
|
|
|
|
|
|
|
|
|
u, err := url.Parse("rtmp://127.0.0.1:" + port + "/mypath") |
|
|
|
|
require.NoError(t, err) |
|
|
|
|
case "rtsp sessions": |
|
|
|
|
require.Equal(t, map[string]interface{}{ |
|
|
|
|
"pageCount": float64(1), |
|
|
|
|
"itemCount": float64(1), |
|
|
|
|
"items": []interface{}{ |
|
|
|
|
map[string]interface{}{ |
|
|
|
|
"bytesReceived": float64(0), |
|
|
|
|
"bytesSent": out1.(map[string]interface{})["items"].([]interface{})[0].(map[string]interface{})["bytesSent"], |
|
|
|
|
"created": out1.(map[string]interface{})["items"].([]interface{})[0].(map[string]interface{})["created"], |
|
|
|
|
"id": out1.(map[string]interface{})["items"].([]interface{})[0].(map[string]interface{})["id"], |
|
|
|
|
"path": "mypath", |
|
|
|
|
"query": "key=val", |
|
|
|
|
"remoteAddr": out1.(map[string]interface{})["items"].([]interface{})[0].(map[string]interface{})["remoteAddr"], |
|
|
|
|
"state": "publish", |
|
|
|
|
"transport": "UDP", |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
}, out1) |
|
|
|
|
|
|
|
|
|
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() |
|
|
|
|
case "rtsps conns": |
|
|
|
|
require.Equal(t, map[string]interface{}{ |
|
|
|
|
"pageCount": float64(1), |
|
|
|
|
"itemCount": float64(1), |
|
|
|
|
"items": []interface{}{ |
|
|
|
|
map[string]interface{}{ |
|
|
|
|
"bytesReceived": out1.(map[string]interface{})["items"].([]interface{})[0].(map[string]interface{})["bytesReceived"], |
|
|
|
|
"bytesSent": out1.(map[string]interface{})["items"].([]interface{})[0].(map[string]interface{})["bytesSent"], |
|
|
|
|
"created": out1.(map[string]interface{})["items"].([]interface{})[0].(map[string]interface{})["created"], |
|
|
|
|
"id": out1.(map[string]interface{})["items"].([]interface{})[0].(map[string]interface{})["id"], |
|
|
|
|
"remoteAddr": out1.(map[string]interface{})["items"].([]interface{})[0].(map[string]interface{})["remoteAddr"], |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
}, out1) |
|
|
|
|
|
|
|
|
|
conn, err := rtmp.NewClientConn(nconn, u, true) |
|
|
|
|
require.NoError(t, err) |
|
|
|
|
case "rtsps sessions": |
|
|
|
|
require.Equal(t, map[string]interface{}{ |
|
|
|
|
"pageCount": float64(1), |
|
|
|
|
"itemCount": float64(1), |
|
|
|
|
"items": []interface{}{ |
|
|
|
|
map[string]interface{}{ |
|
|
|
|
"bytesReceived": float64(0), |
|
|
|
|
"bytesSent": out1.(map[string]interface{})["items"].([]interface{})[0].(map[string]interface{})["bytesSent"], |
|
|
|
|
"created": out1.(map[string]interface{})["items"].([]interface{})[0].(map[string]interface{})["created"], |
|
|
|
|
"id": out1.(map[string]interface{})["items"].([]interface{})[0].(map[string]interface{})["id"], |
|
|
|
|
"path": "mypath", |
|
|
|
|
"query": "key=val", |
|
|
|
|
"remoteAddr": out1.(map[string]interface{})["items"].([]interface{})[0].(map[string]interface{})["remoteAddr"], |
|
|
|
|
"state": "publish", |
|
|
|
|
"transport": "TCP", |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
}, out1) |
|
|
|
|
|
|
|
|
|
_, err = rtmp.NewWriter(conn, test.FormatH264, nil) |
|
|
|
|
require.NoError(t, err) |
|
|
|
|
case "rtmp": |
|
|
|
|
require.Equal(t, map[string]interface{}{ |
|
|
|
|
"pageCount": float64(1), |
|
|
|
|
"itemCount": float64(1), |
|
|
|
|
"items": []interface{}{ |
|
|
|
|
map[string]interface{}{ |
|
|
|
|
"bytesReceived": out1.(map[string]interface{})["items"].([]interface{})[0].(map[string]interface{})["bytesReceived"], |
|
|
|
|
"bytesSent": out1.(map[string]interface{})["items"].([]interface{})[0].(map[string]interface{})["bytesSent"], |
|
|
|
|
"created": out1.(map[string]interface{})["items"].([]interface{})[0].(map[string]interface{})["created"], |
|
|
|
|
"id": out1.(map[string]interface{})["items"].([]interface{})[0].(map[string]interface{})["id"], |
|
|
|
|
"path": "mypath", |
|
|
|
|
"query": "key=val", |
|
|
|
|
"remoteAddr": out1.(map[string]interface{})["items"].([]interface{})[0].(map[string]interface{})["remoteAddr"], |
|
|
|
|
"state": "publish", |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
}, out1) |
|
|
|
|
|
|
|
|
|
time.Sleep(500 * time.Millisecond) |
|
|
|
|
case "rtmps": |
|
|
|
|
require.Equal(t, map[string]interface{}{ |
|
|
|
|
"pageCount": float64(1), |
|
|
|
|
"itemCount": float64(1), |
|
|
|
|
"items": []interface{}{ |
|
|
|
|
map[string]interface{}{ |
|
|
|
|
"bytesReceived": out1.(map[string]interface{})["items"].([]interface{})[0].(map[string]interface{})["bytesReceived"], |
|
|
|
|
"bytesSent": out1.(map[string]interface{})["items"].([]interface{})[0].(map[string]interface{})["bytesSent"], |
|
|
|
|
"created": out1.(map[string]interface{})["items"].([]interface{})[0].(map[string]interface{})["created"], |
|
|
|
|
"id": out1.(map[string]interface{})["items"].([]interface{})[0].(map[string]interface{})["id"], |
|
|
|
|
"path": "mypath", |
|
|
|
|
"query": "key=val", |
|
|
|
|
"remoteAddr": out1.(map[string]interface{})["items"].([]interface{})[0].(map[string]interface{})["remoteAddr"], |
|
|
|
|
"state": "publish", |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
}, out1) |
|
|
|
|
|
|
|
|
|
case "hls": |
|
|
|
|
source := gortsplib.Client{} |
|
|
|
|
err := source.StartRecording("rtsp://localhost:8554/mypath", |
|
|
|
|
&description.Session{Medias: []*description.Media{medi}}) |
|
|
|
|
require.NoError(t, err) |
|
|
|
|
defer source.Close() |
|
|
|
|
|
|
|
|
|
go func() { |
|
|
|
|
time.Sleep(500 * time.Millisecond) |
|
|
|
|
|
|
|
|
|
for i := 0; i < 3; i++ { |
|
|
|
|
/*source.WritePacketRTP(medi, &rtp.Packet{ |
|
|
|
|
Header: rtp.Header{ |
|
|
|
|
Version: 2, |
|
|
|
|
Marker: true, |
|
|
|
|
PayloadType: 96, |
|
|
|
|
SequenceNumber: 123 + uint16(i), |
|
|
|
|
Timestamp: 45343 + uint32(i)*90000, |
|
|
|
|
SSRC: 563423, |
|
|
|
|
}, |
|
|
|
|
Payload: []byte{ |
|
|
|
|
testSPS, |
|
|
|
|
0x05, |
|
|
|
|
}, |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
[]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, |
|
|
|
|
},*/ |
|
|
|
|
|
|
|
|
|
err := source.WritePacketRTP(medi, &rtp.Packet{ |
|
|
|
|
Header: rtp.Header{ |
|
|
|
|
Version: 2, |
|
|
|
|
Marker: true, |
|
|
|
|
PayloadType: 96, |
|
|
|
|
SequenceNumber: 123 + uint16(i), |
|
|
|
|
Timestamp: 45343 + uint32(i)*90000, |
|
|
|
|
SSRC: 563423, |
|
|
|
|
}, |
|
|
|
|
Payload: []byte{ |
|
|
|
|
// testSPS,
|
|
|
|
|
0x05, |
|
|
|
|
}, |
|
|
|
|
}) |
|
|
|
|
require.NoError(t, err) |
|
|
|
|
} |
|
|
|
|
}() |
|
|
|
|
|
|
|
|
|
func() { |
|
|
|
|
res, err := hc.Get("http://localhost:8888/mypath/index.m3u8") |
|
|
|
|
require.NoError(t, err) |
|
|
|
|
defer res.Body.Close() |
|
|
|
|
require.Equal(t, 200, res.StatusCode) |
|
|
|
|
}() |
|
|
|
|
require.Equal(t, map[string]interface{}{ |
|
|
|
|
"itemCount": float64(1), |
|
|
|
|
"pageCount": float64(1), |
|
|
|
|
"items": []interface{}{ |
|
|
|
|
map[string]interface{}{ |
|
|
|
|
"bytesSent": out1.(map[string]interface{})["items"].([]interface{})[0].(map[string]interface{})["bytesSent"], |
|
|
|
|
"created": out1.(map[string]interface{})["items"].([]interface{})[0].(map[string]interface{})["created"], |
|
|
|
|
"lastRequest": out1.(map[string]interface{})["items"].([]interface{})[0].(map[string]interface{})["lastRequest"], |
|
|
|
|
"path": "mypath", |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
}, out1) |
|
|
|
|
|
|
|
|
|
case "webrtc": |
|
|
|
|
source := gortsplib.Client{} |
|
|
|
|
err := source.StartRecording("rtsp://localhost:8554/mypath", |
|
|
|
|
&description.Session{Medias: []*description.Media{medi}}) |
|
|
|
|
require.NoError(t, err) |
|
|
|
|
defer source.Close() |
|
|
|
|
|
|
|
|
|
u, err := url.Parse("http://localhost:8889/mypath/whep") |
|
|
|
|
require.NoError(t, err) |
|
|
|
|
|
|
|
|
|
go func() { |
|
|
|
|
time.Sleep(500 * time.Millisecond) |
|
|
|
|
|
|
|
|
|
err := source.WritePacketRTP(medi, &rtp.Packet{ |
|
|
|
|
Header: rtp.Header{ |
|
|
|
|
Version: 2, |
|
|
|
|
Marker: true, |
|
|
|
|
PayloadType: 96, |
|
|
|
|
SequenceNumber: 123, |
|
|
|
|
Timestamp: 45343, |
|
|
|
|
SSRC: 563423, |
|
|
|
|
require.Equal(t, map[string]interface{}{ |
|
|
|
|
"itemCount": float64(1), |
|
|
|
|
"pageCount": float64(1), |
|
|
|
|
"items": []interface{}{ |
|
|
|
|
map[string]interface{}{ |
|
|
|
|
"bytesReceived": out1.(map[string]interface{})["items"].([]interface{})[0].(map[string]interface{})["bytesReceived"], |
|
|
|
|
"bytesSent": out1.(map[string]interface{})["items"].([]interface{})[0].(map[string]interface{})["bytesSent"], |
|
|
|
|
"created": out1.(map[string]interface{})["items"].([]interface{})[0].(map[string]interface{})["created"], |
|
|
|
|
"id": out1.(map[string]interface{})["items"].([]interface{})[0].(map[string]interface{})["id"], |
|
|
|
|
"localCandidate": out1.(map[string]interface{})["items"].([]interface{})[0].(map[string]interface{})["localCandidate"], |
|
|
|
|
"path": "mypath", |
|
|
|
|
"peerConnectionEstablished": true, |
|
|
|
|
"query": "key=val", |
|
|
|
|
"remoteAddr": out1.(map[string]interface{})["items"].([]interface{})[0].(map[string]interface{})["remoteAddr"], |
|
|
|
|
"remoteCandidate": out1.(map[string]interface{})["items"].([]interface{})[0].(map[string]interface{})["remoteCandidate"], |
|
|
|
|
"state": "read", |
|
|
|
|
}, |
|
|
|
|
Payload: []byte{5, 1, 2, 3, 4}, |
|
|
|
|
}) |
|
|
|
|
require.NoError(t, err) |
|
|
|
|
}() |
|
|
|
|
|
|
|
|
|
c := &webrtc.WHIPClient{ |
|
|
|
|
HTTPClient: hc, |
|
|
|
|
URL: u, |
|
|
|
|
Log: test.NilLogger{}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
_, err = c.Read(context.Background()) |
|
|
|
|
require.NoError(t, err) |
|
|
|
|
defer checkClose(t, c.Close) |
|
|
|
|
}, |
|
|
|
|
}, out1) |
|
|
|
|
|
|
|
|
|
case "srt": |
|
|
|
|
conf := srt.DefaultConfig() |
|
|
|
|
conf.StreamId = "publish:mypath" |
|
|
|
|
|
|
|
|
|
conn, err := srt.Dial("srt", "localhost:8890", conf) |
|
|
|
|
require.NoError(t, err) |
|
|
|
|
defer conn.Close() |
|
|
|
|
|
|
|
|
|
track := &mpegts.Track{ |
|
|
|
|
Codec: &mpegts.CodecH264{}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bw := bufio.NewWriter(conn) |
|
|
|
|
w := mpegts.NewWriter(bw, []*mpegts.Track{track}) |
|
|
|
|
require.NoError(t, err) |
|
|
|
|
|
|
|
|
|
err = w.WriteH26x(track, 0, 0, true, [][]byte{{1}}) |
|
|
|
|
require.NoError(t, err) |
|
|
|
|
|
|
|
|
|
err = bw.Flush() |
|
|
|
|
require.NoError(t, err) |
|
|
|
|
|
|
|
|
|
time.Sleep(500 * time.Millisecond) |
|
|
|
|
require.Equal(t, map[string]interface{}{ |
|
|
|
|
"itemCount": float64(1), |
|
|
|
|
"pageCount": float64(1), |
|
|
|
|
"items": []interface{}{ |
|
|
|
|
map[string]interface{}{ |
|
|
|
|
"byteMSS": float64(1500), |
|
|
|
|
"bytesAvailReceiveBuf": float64(0), |
|
|
|
|
"bytesAvailSendBuf": float64(0), |
|
|
|
|
"bytesReceiveBuf": float64(0), |
|
|
|
|
"bytesReceived": float64(628), |
|
|
|
|
"bytesReceivedBelated": float64(0), |
|
|
|
|
"bytesReceivedDrop": float64(0), |
|
|
|
|
"bytesReceivedLoss": float64(0), |
|
|
|
|
"bytesReceivedRetrans": float64(0), |
|
|
|
|
"bytesReceivedUndecrypt": float64(0), |
|
|
|
|
"bytesReceivedUnique": float64(628), |
|
|
|
|
"bytesRetrans": float64(0), |
|
|
|
|
"bytesSendBuf": float64(0), |
|
|
|
|
"bytesSendDrop": float64(0), |
|
|
|
|
"bytesSent": float64(0), |
|
|
|
|
"bytesSentUnique": float64(0), |
|
|
|
|
"created": out1.(map[string]interface{})["items"].([]interface{})[0].(map[string]interface{})["created"], |
|
|
|
|
"id": out1.(map[string]interface{})["items"].([]interface{})[0].(map[string]interface{})["id"], |
|
|
|
|
"mbpsLinkCapacity": float64(0), |
|
|
|
|
"mbpsMaxBW": float64(-1), |
|
|
|
|
"mbpsReceiveRate": float64(0), |
|
|
|
|
"mbpsSendRate": float64(0), |
|
|
|
|
"msRTT": out1.(map[string]interface{})["items"].([]interface{})[0].(map[string]interface{})["msRTT"], |
|
|
|
|
"msReceiveBuf": float64(0), |
|
|
|
|
"msReceiveTsbPdDelay": float64(120), |
|
|
|
|
"msSendBuf": float64(0), |
|
|
|
|
"msSendTsbPdDelay": float64(120), |
|
|
|
|
"packetsFlightSize": float64(0), |
|
|
|
|
"packetsFlowWindow": float64(25600), |
|
|
|
|
"packetsReceiveBuf": float64(0), |
|
|
|
|
"packetsReceived": float64(1), |
|
|
|
|
"packetsReceivedACK": float64(0), |
|
|
|
|
"packetsReceivedAvgBelatedTime": float64(0), |
|
|
|
|
"packetsReceivedBelated": float64(0), |
|
|
|
|
"packetsReceivedDrop": float64(0), |
|
|
|
|
"packetsReceivedKM": float64(0), |
|
|
|
|
"packetsReceivedLoss": float64(0), |
|
|
|
|
"packetsReceivedLossRate": float64(0), |
|
|
|
|
"packetsReceivedNAK": float64(0), |
|
|
|
|
"packetsReceivedRetrans": float64(0), |
|
|
|
|
"packetsReceivedUndecrypt": float64(0), |
|
|
|
|
"packetsReceivedUnique": float64(1), |
|
|
|
|
"packetsReorderTolerance": float64(0), |
|
|
|
|
"packetsRetrans": float64(0), |
|
|
|
|
"packetsSendBuf": float64(0), |
|
|
|
|
"packetsSendDrop": float64(0), |
|
|
|
|
"packetsSendLoss": float64(0), |
|
|
|
|
"packetsSendLossRate": float64(0), |
|
|
|
|
"packetsSent": float64(0), |
|
|
|
|
"packetsSentACK": out1.(map[string]interface{})["items"].([]interface{})[0].(map[string]interface{})["packetsSentACK"], |
|
|
|
|
"packetsSentKM": float64(0), |
|
|
|
|
"packetsSentNAK": float64(0), |
|
|
|
|
"packetsSentUnique": float64(0), |
|
|
|
|
"path": "mypath", |
|
|
|
|
"query": "key=val", |
|
|
|
|
"remoteAddr": out1.(map[string]interface{})["items"].([]interface{})[0].(map[string]interface{})["remoteAddr"], |
|
|
|
|
"state": "publish", |
|
|
|
|
"usPacketsSendPeriod": float64(10.967254638671875), |
|
|
|
|
"usSndDuration": float64(0), |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
}, out1) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
switch ca { |
|
|
|
|
case "rtsp conns", "rtsp sessions", "rtsps conns", "rtsps sessions", "rtmp", "rtmps", "srt": |
|
|
|
|
var pa string |
|
|
|
|
switch ca { |
|
|
|
|
case "rtsp conns": |
|
|
|
|
pa = "rtspconns" |
|
|
|
|
|
|
|
|
|
case "rtsp sessions": |
|
|
|
|
pa = "rtspsessions" |
|
|
|
|
|
|
|
|
|
case "rtsps conns": |
|
|
|
|
pa = "rtspsconns" |
|
|
|
|
|
|
|
|
|
case "rtsps sessions": |
|
|
|
|
pa = "rtspssessions" |
|
|
|
|
var out2 interface{} |
|
|
|
|
|
|
|
|
|
case "rtmp": |
|
|
|
|
pa = "rtmpconns" |
|
|
|
|
|
|
|
|
|
case "rtmps": |
|
|
|
|
pa = "rtmpsconns" |
|
|
|
|
|
|
|
|
|
case "srt": |
|
|
|
|
pa = "srtconns" |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
type item struct { |
|
|
|
|
ID string `json:"id"` |
|
|
|
|
State string `json:"state"` |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var out1 struct { |
|
|
|
|
Items []item `json:"items"` |
|
|
|
|
} |
|
|
|
|
httpRequest(t, hc, http.MethodGet, "http://localhost:9997/v3/"+pa+"/list", nil, &out1) |
|
|
|
|
|
|
|
|
|
if ca != "rtsp conns" && ca != "rtsps conns" { |
|
|
|
|
require.Equal(t, "publish", out1.Items[0].State) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var out2 item |
|
|
|
|
httpRequest(t, hc, http.MethodGet, "http://localhost:9997/v3/"+pa+"/get/"+out1.Items[0].ID, nil, &out2) |
|
|
|
|
|
|
|
|
|
if ca != "rtsp conns" && ca != "rtsps conns" { |
|
|
|
|
require.Equal(t, "publish", out2.State) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
case "hls": |
|
|
|
|
type item struct { |
|
|
|
|
Created string `json:"created"` |
|
|
|
|
LastRequest string `json:"lastRequest"` |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var out item |
|
|
|
|
httpRequest(t, hc, http.MethodGet, "http://localhost:9997/v3/hlsmuxers/get/mypath", nil, &out) |
|
|
|
|
|
|
|
|
|
s := fmt.Sprintf("^%d-", time.Now().Year()) |
|
|
|
|
require.Regexp(t, s, out.Created) |
|
|
|
|
require.Regexp(t, s, out.LastRequest) |
|
|
|
|
|
|
|
|
|
case "webrtc": |
|
|
|
|
type item struct { |
|
|
|
|
ID string `json:"id"` |
|
|
|
|
Created time.Time `json:"created"` |
|
|
|
|
RemoteAddr string `json:"remoteAddr"` |
|
|
|
|
PeerConnectionEstablished bool `json:"peerConnectionEstablished"` |
|
|
|
|
LocalCandidate string `json:"localCandidate"` |
|
|
|
|
RemoteCandidate string `json:"remoteCandidate"` |
|
|
|
|
BytesReceived uint64 `json:"bytesReceived"` |
|
|
|
|
BytesSent uint64 `json:"bytesSent"` |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var out1 struct { |
|
|
|
|
Items []item `json:"items"` |
|
|
|
|
} |
|
|
|
|
httpRequest(t, hc, http.MethodGet, "http://localhost:9997/v3/webrtcsessions/list", nil, &out1) |
|
|
|
|
|
|
|
|
|
var out2 item |
|
|
|
|
httpRequest(t, hc, http.MethodGet, "http://localhost:9997/v3/webrtcsessions/get/"+out1.Items[0].ID, nil, &out2) |
|
|
|
|
|
|
|
|
|
require.Equal(t, true, out2.PeerConnectionEstablished) |
|
|
|
|
if ca == "hls" { |
|
|
|
|
httpRequest(t, hc, http.MethodGet, "http://localhost:9997/v3/"+pa+"/get/"+ |
|
|
|
|
out1.(map[string]interface{})["items"].([]interface{})[0].(map[string]interface{})["path"].(string), |
|
|
|
|
nil, &out2) |
|
|
|
|
} else { |
|
|
|
|
httpRequest(t, hc, http.MethodGet, "http://localhost:9997/v3/"+pa+"/get/"+ |
|
|
|
|
out1.(map[string]interface{})["items"].([]interface{})[0].(map[string]interface{})["id"].(string), |
|
|
|
|
nil, &out2) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
require.Equal(t, out1.(map[string]interface{})["items"].([]interface{})[0], out2) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|