golanggohlsrtmpwebrtcmedia-serverobs-studiortcprtmp-proxyrtmp-serverrtprtsprtsp-proxyrtsp-relayrtsp-serversrtstreamingwebrtc-proxy
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
227 lines
4.6 KiB
227 lines
4.6 KiB
package message |
|
|
|
import ( |
|
"bytes" |
|
"testing" |
|
"time" |
|
|
|
"github.com/notedit/rtmp/format/flv/flvio" |
|
"github.com/stretchr/testify/require" |
|
|
|
"github.com/aler9/rtsp-simple-server/internal/rtmp/bytecounter" |
|
) |
|
|
|
var readWriterCases = []struct { |
|
name string |
|
dec Message |
|
enc []byte |
|
}{ |
|
{ |
|
"acknowledge", |
|
&MsgAcknowledge{ |
|
Value: 45953968, |
|
}, |
|
[]byte{ |
|
0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x4, 0x3, |
|
0x0, 0x0, 0x0, 0x0, 0x2, 0xbd, 0x33, 0xb0, |
|
}, |
|
}, |
|
{ |
|
"audio", |
|
&MsgAudio{ |
|
ChunkStreamID: 7, |
|
DTS: 6013806 * time.Millisecond, |
|
MessageStreamID: 4534543, |
|
Rate: flvio.SOUND_44Khz, |
|
Depth: flvio.SOUND_16BIT, |
|
Channels: flvio.SOUND_STEREO, |
|
AACType: flvio.AAC_RAW, |
|
Payload: []byte{0x5A, 0xC0, 0x77, 0x40}, |
|
}, |
|
[]byte{ |
|
0x7, 0x5b, 0xc3, 0x6e, 0x0, 0x0, 0x6, 0x8, |
|
0x0, 0x45, 0x31, 0xf, 0xaf, 0x1, 0x5a, 0xc0, |
|
0x77, 0x40, |
|
}, |
|
}, |
|
{ |
|
"command amf0", |
|
&MsgCommandAMF0{ |
|
ChunkStreamID: 3, |
|
MessageStreamID: 345243, |
|
Name: "i8yythrergre", |
|
CommandID: 56456, |
|
Arguments: []interface{}{ |
|
flvio.AMFMap{ |
|
{K: "k1", V: "v1"}, |
|
{K: "k2", V: "v2"}, |
|
}, |
|
nil, |
|
}, |
|
}, |
|
[]byte{ |
|
0x3, 0x0, 0x0, 0x0, 0x0, 0x0, 0x2f, 0x14, |
|
0x0, 0x5, 0x44, 0x9b, 0x2, 0x0, 0xc, 0x69, |
|
0x38, 0x79, 0x79, 0x74, 0x68, 0x72, 0x65, 0x72, |
|
0x67, 0x72, 0x65, 0x0, 0x40, 0xeb, 0x91, 0x0, |
|
0x0, 0x0, 0x0, 0x0, 0x3, 0x0, 0x2, 0x6b, |
|
0x31, 0x2, 0x0, 0x2, 0x76, 0x31, 0x0, 0x2, |
|
0x6b, 0x32, 0x2, 0x0, 0x2, 0x76, 0x32, 0x0, |
|
0x0, 0x9, 0x5, |
|
}, |
|
}, |
|
{ |
|
"data amf0", |
|
&MsgDataAMF0{ |
|
ChunkStreamID: 3, |
|
MessageStreamID: 345243, |
|
Payload: []interface{}{ |
|
float64(234), |
|
"string", |
|
nil, |
|
}, |
|
}, |
|
[]byte{ |
|
0x3, 0x0, 0x0, 0x0, 0x0, 0x0, 0x13, 0x12, |
|
0x0, 0x5, 0x44, 0x9b, 0x0, 0x40, 0x6d, 0x40, |
|
0x0, 0x0, 0x0, 0x0, 0x0, 0x2, 0x0, 0x6, |
|
0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x05, |
|
}, |
|
}, |
|
{ |
|
"set chunk size", |
|
&MsgSetChunkSize{ |
|
Value: 10000, |
|
}, |
|
[]byte{ |
|
0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x4, 0x1, |
|
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x27, 0x10, |
|
}, |
|
}, |
|
{ |
|
"set peer bandwidth", |
|
&MsgSetChunkSize{ |
|
Value: 10000, |
|
}, |
|
[]byte{ |
|
0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x4, 0x1, |
|
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x27, 0x10, |
|
}, |
|
}, |
|
{ |
|
"set window ack size", |
|
&MsgSetChunkSize{ |
|
Value: 10000, |
|
}, |
|
[]byte{ |
|
0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x4, 0x1, |
|
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x27, 0x10, |
|
}, |
|
}, |
|
{ |
|
"user control ping request", |
|
&MsgUserControlPingRequest{ |
|
ServerTime: 569834435, |
|
}, |
|
[]byte{ |
|
0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x6, 0x4, |
|
0x0, 0x0, 0x0, 0x0, 0x0, 0x6, 0x21, 0xf6, |
|
0xfb, 0xc3, |
|
}, |
|
}, |
|
{ |
|
"user control ping response", |
|
&MsgUserControlPingResponse{ |
|
ServerTime: 569834435, |
|
}, |
|
[]byte{ |
|
0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x6, 0x4, |
|
0x0, 0x0, 0x0, 0x0, 0x0, 0x7, 0x21, 0xf6, |
|
0xfb, 0xc3, |
|
}, |
|
}, |
|
{ |
|
"user control set buffer length", |
|
&MsgUserControlSetBufferLength{ |
|
StreamID: 35534, |
|
BufferLength: 235345, |
|
}, |
|
[]byte{ |
|
0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0xa, 0x4, |
|
0x0, 0x0, 0x0, 0x0, 0x0, 0x3, 0x0, 0x0, |
|
0x8a, 0xce, 0x0, 0x3, 0x97, 0x51, |
|
}, |
|
}, |
|
{ |
|
"user control stream begin", |
|
&MsgUserControlStreamBegin{ |
|
StreamID: 35534, |
|
}, |
|
[]byte{ |
|
0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x6, 0x4, |
|
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, |
|
0x8a, 0xce, |
|
}, |
|
}, |
|
{ |
|
"user control stream dry", |
|
&MsgUserControlStreamDry{ |
|
StreamID: 35534, |
|
}, |
|
[]byte{ |
|
0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x6, 0x4, |
|
0x0, 0x0, 0x0, 0x0, 0x0, 0x2, 0x0, 0x0, |
|
0x8a, 0xce, |
|
}, |
|
}, |
|
{ |
|
"user control stream eof", |
|
&MsgUserControlStreamEOF{ |
|
StreamID: 35534, |
|
}, |
|
[]byte{ |
|
0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x6, 0x4, |
|
0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, |
|
0x8a, 0xce, |
|
}, |
|
}, |
|
{ |
|
"user control stream is recorded", |
|
&MsgUserControlStreamIsRecorded{ |
|
StreamID: 35534, |
|
}, |
|
[]byte{ |
|
0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x6, 0x4, |
|
0x0, 0x0, 0x0, 0x0, 0x0, 0x4, 0x0, 0x0, |
|
0x8a, 0xce, |
|
}, |
|
}, |
|
{ |
|
"video", |
|
&MsgVideo{ |
|
ChunkStreamID: 6, |
|
DTS: 2543534 * time.Millisecond, |
|
MessageStreamID: 0x1000000, |
|
IsKeyFrame: true, |
|
H264Type: flvio.AVC_SEQHDR, |
|
PTSDelta: 10 * time.Millisecond, |
|
Payload: []byte{0x01, 0x02, 0x03}, |
|
}, |
|
[]byte{ |
|
0x6, 0x26, 0xcf, 0xae, 0x0, 0x0, 0x8, 0x9, |
|
0x1, 0x0, 0x0, 0x0, 0x17, 0x0, 0x0, 0x0, |
|
0xa, 0x1, 0x2, 0x3, |
|
}, |
|
}, |
|
} |
|
|
|
func TestReader(t *testing.T) { |
|
for _, ca := range readWriterCases { |
|
t.Run(ca.name, func(t *testing.T) { |
|
r := NewReader(bytecounter.NewReader(bytes.NewReader(ca.enc)), nil) |
|
dec, err := r.Read() |
|
require.NoError(t, err) |
|
require.Equal(t, ca.dec, dec) |
|
}) |
|
} |
|
}
|
|
|