|
|
|
@ -9,6 +9,7 @@
|
|
|
|
|
package gb28181
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"encoding/hex"
|
|
|
|
|
"fmt"
|
|
|
|
|
"github.com/q191201771/lal/pkg/aac"
|
|
|
|
|
"github.com/q191201771/lal/pkg/base"
|
|
|
|
@ -20,20 +21,41 @@ import (
|
|
|
|
|
"time"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestPubSession(t *testing.T) {
|
|
|
|
|
// 测试:
|
|
|
|
|
// 1. 测试 TestPubSession
|
|
|
|
|
// 1.1 测试指定端口
|
|
|
|
|
// 1.2 测试随机端口
|
|
|
|
|
// 1.3 测试重复端口
|
|
|
|
|
// 2. 测试 TestReplayPubSession
|
|
|
|
|
|
|
|
|
|
func TestReplayPubSession(t *testing.T) {
|
|
|
|
|
// 重放业务方的流
|
|
|
|
|
// 步骤:
|
|
|
|
|
// 1. 业务方提供的lalserver录制下来的dump file
|
|
|
|
|
// 1. 业务方提供的lalserver录制下来的dump file,修改下面的文件名变量filename
|
|
|
|
|
// 2. 启动lalserver
|
|
|
|
|
// 3. 调用HTTP API
|
|
|
|
|
// curl -H "Content-Type:application/json" -X POST -d '{"stream_name": "test110", "port": 10002, "timeout_ms": 10000}' http://127.0.0.1:8083/api/ctrl/start_rtp_pub
|
|
|
|
|
// 4. 执行该测试
|
|
|
|
|
//testDumpFile("127.0.0.1:10002", "/tmp/test.psdata")
|
|
|
|
|
// go test -test.run TestReplayPubSession
|
|
|
|
|
//
|
|
|
|
|
filename := "/tmp/record.psdata"
|
|
|
|
|
|
|
|
|
|
b, err := ioutil.ReadFile(filename)
|
|
|
|
|
if len(b) == 0 || err != nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//testPushFile("127.0.0.1:10002", filename)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestPubSession(t *testing.T) {
|
|
|
|
|
// 读取一大堆.ps文件,并使用udp发送到`addr`地址(外部的,比如外部自己启动lalserver)
|
|
|
|
|
// 步骤:
|
|
|
|
|
// 1. 启动lalserver
|
|
|
|
|
// 2. 调用HTTP API
|
|
|
|
|
// curl -H "Content-Type:application/json" -X POST -d '{"stream_name": "test110", "port": 10002, "timeout_ms": 10000, "debug_dump_packet": "/tmp/test110.psdata"}' http://127.0.0.1:8083/api/ctrl/start_rtp_pub
|
|
|
|
|
// 3. 执行该测试
|
|
|
|
|
// go test -test.run TestPubSession
|
|
|
|
|
//helpUdpSend("127.0.0.1:10002")
|
|
|
|
|
|
|
|
|
|
// 读取一大堆.ps文件,并使用udp发送到`addr`地址(内部启动了PubSession做接收)
|
|
|
|
@ -77,7 +99,9 @@ func testPubSession() {
|
|
|
|
|
helpUdpSend(addr)
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
runErr := session.RunLoop(addr)
|
|
|
|
|
_, runErr := session.Listen(int(port))
|
|
|
|
|
nazalog.Assert(nil, runErr)
|
|
|
|
|
runErr = session.RunLoop()
|
|
|
|
|
nazalog.Assert(nil, runErr)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -91,13 +115,13 @@ func helpUdpSend(addr string) {
|
|
|
|
|
//filename := fmt.Sprintf("/tmp/rtp-ps-video/%d.ps", i)
|
|
|
|
|
b, err := ioutil.ReadFile(filename)
|
|
|
|
|
nazalog.Assert(nil, err)
|
|
|
|
|
//nazalog.Debugf("[test] %d: %s", i, hex.EncodeToString(b[12:]))
|
|
|
|
|
nazalog.Debugf("[test] %d: %s", i, hex.EncodeToString(b[12:]))
|
|
|
|
|
|
|
|
|
|
conn.Write(b)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func testDumpFile(addr string, filename string) {
|
|
|
|
|
func testPushFile(addr string, filename string) {
|
|
|
|
|
conn, err := nazanet.NewUdpConnection(func(option *nazanet.UdpConnectionOption) {
|
|
|
|
|
option.RAddr = addr
|
|
|
|
|
})
|
|
|
|
|