mirror of
https://github.com/aler9/rtsp-simple-server
synced 2025-10-21 22:59:37 +08:00
rtmp: cleanup tests
This commit is contained in:
@@ -238,9 +238,19 @@ func (m chunk3) write(w io.Writer) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestReadTracks(t *testing.T) {
|
func TestReadTracks(t *testing.T) {
|
||||||
|
sps := []byte{
|
||||||
|
0x67, 0x64, 0x00, 0x0c, 0xac, 0x3b, 0x50, 0xb0,
|
||||||
|
0x4b, 0x42, 0x00, 0x00, 0x03, 0x00, 0x02, 0x00,
|
||||||
|
0x00, 0x03, 0x00, 0x3d, 0x08,
|
||||||
|
}
|
||||||
|
|
||||||
|
pps := []byte{
|
||||||
|
0x68, 0xee, 0x3c, 0x80,
|
||||||
|
}
|
||||||
|
|
||||||
for _, ca := range []string{
|
for _, ca := range []string{
|
||||||
"standard",
|
"standard",
|
||||||
"empty metadata",
|
"metadata without codec id",
|
||||||
"no metadata",
|
"no metadata",
|
||||||
} {
|
} {
|
||||||
t.Run(ca, func(t *testing.T) {
|
t.Run(ca, func(t *testing.T) {
|
||||||
@@ -264,16 +274,7 @@ func TestReadTracks(t *testing.T) {
|
|||||||
|
|
||||||
switch ca {
|
switch ca {
|
||||||
case "standard":
|
case "standard":
|
||||||
videoTrack2, err := gortsplib.NewTrackH264(96,
|
videoTrack2, err := gortsplib.NewTrackH264(96, sps, pps, nil)
|
||||||
[]byte{
|
|
||||||
0x67, 0x64, 0x00, 0x0c, 0xac, 0x3b, 0x50, 0xb0,
|
|
||||||
0x4b, 0x42, 0x00, 0x00, 0x03, 0x00, 0x02, 0x00,
|
|
||||||
0x00, 0x03, 0x00, 0x3d, 0x08,
|
|
||||||
},
|
|
||||||
[]byte{
|
|
||||||
0x68, 0xee, 0x3c, 0x80,
|
|
||||||
},
|
|
||||||
nil)
|
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, videoTrack2, videoTrack)
|
require.Equal(t, videoTrack2, videoTrack)
|
||||||
|
|
||||||
@@ -281,34 +282,15 @@ func TestReadTracks(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, audioTrack2, audioTrack)
|
require.Equal(t, audioTrack2, audioTrack)
|
||||||
|
|
||||||
case "empty metadata":
|
case "metadata without codec id":
|
||||||
videoTrack2, err := gortsplib.NewTrackH264(96,
|
videoTrack2, err := gortsplib.NewTrackH264(96, sps, pps, nil)
|
||||||
[]byte{
|
|
||||||
0x67, 0x64, 0x00, 0x32, 0xac, 0x2c, 0x6a, 0x80,
|
|
||||||
0xa8, 0x02, 0xfe, 0x9b, 0x82, 0x80, 0x82, 0xa0,
|
|
||||||
0x00, 0x00, 0x03, 0x00, 0x20, 0x00, 0x00, 0x06,
|
|
||||||
0x50, 0x80,
|
|
||||||
},
|
|
||||||
[]byte{
|
|
||||||
0x68, 0xee, 0x31, 0xb2, 0x1b,
|
|
||||||
},
|
|
||||||
nil)
|
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, videoTrack2, videoTrack)
|
require.Equal(t, videoTrack2, videoTrack)
|
||||||
|
|
||||||
require.Equal(t, (*gortsplib.TrackAAC)(nil), audioTrack)
|
require.Equal(t, (*gortsplib.TrackAAC)(nil), audioTrack)
|
||||||
|
|
||||||
case "no metadata":
|
case "no metadata":
|
||||||
videoTrack2, err := gortsplib.NewTrackH264(96,
|
videoTrack2, err := gortsplib.NewTrackH264(96, sps, pps, nil)
|
||||||
[]byte{
|
|
||||||
0x27, 0x42, 0xe0, 0x1f, 0x8d, 0x68, 0x05, 0x00,
|
|
||||||
0x5b, 0xa1, 0x00, 0x00, 0x03, 0x00, 0x01, 0x00,
|
|
||||||
0x00, 0x03, 0x00, 0x1e, 0x0f, 0x10, 0x7a, 0x80,
|
|
||||||
},
|
|
||||||
[]byte{
|
|
||||||
0x28, 0xce, 0x32, 0x48,
|
|
||||||
},
|
|
||||||
nil)
|
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, videoTrack2, videoTrack)
|
require.Equal(t, videoTrack2, videoTrack)
|
||||||
|
|
||||||
@@ -548,28 +530,22 @@ func TestReadTracks(t *testing.T) {
|
|||||||
// C->S H264 decoder config
|
// C->S H264 decoder config
|
||||||
codec := nh264.Codec{
|
codec := nh264.Codec{
|
||||||
SPS: map[int][]byte{
|
SPS: map[int][]byte{
|
||||||
0: {
|
0: sps,
|
||||||
0x67, 0x64, 0x00, 0x0c, 0xac, 0x3b, 0x50, 0xb0,
|
|
||||||
0x4b, 0x42, 0x00, 0x00, 0x03, 0x00, 0x02, 0x00,
|
|
||||||
0x00, 0x03, 0x00, 0x3d, 0x08,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
PPS: map[int][]byte{
|
PPS: map[int][]byte{
|
||||||
0: {
|
0: pps,
|
||||||
0x68, 0xee, 0x3c, 0x80,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
b := make([]byte, 128)
|
b := make([]byte, 128)
|
||||||
var n int
|
var n int
|
||||||
codec.ToConfig(b, &n)
|
codec.ToConfig(b, &n)
|
||||||
decConfig := b[:n]
|
body := append([]byte{flvio.FRAME_KEY<<4 | flvio.VIDEO_H264, 0, 0, 0, 0}, b[:n]...)
|
||||||
err = chunk0{
|
err = chunk0{
|
||||||
chunkStreamID: 6,
|
chunkStreamID: 6,
|
||||||
typ: flvio.TAG_VIDEO,
|
typ: flvio.TAG_VIDEO,
|
||||||
streamID: 1,
|
streamID: 1,
|
||||||
bodyLen: uint32(len(decConfig) + 5),
|
bodyLen: uint32(len(body)),
|
||||||
body: append([]byte{flvio.FRAME_KEY<<4 | flvio.VIDEO_H264, 0, 0, 0, 0}, decConfig...),
|
body: body,
|
||||||
}.write(conn)
|
}.write(conn)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
@@ -592,7 +568,7 @@ func TestReadTracks(t *testing.T) {
|
|||||||
}.write(conn)
|
}.write(conn)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
case "empty metadata":
|
case "metadata without codec id":
|
||||||
// C->S metadata
|
// C->S metadata
|
||||||
byts = flvio.FillAMF0ValsMalloc([]interface{}{
|
byts = flvio.FillAMF0ValsMalloc([]interface{}{
|
||||||
"@setDataFrame",
|
"@setDataFrame",
|
||||||
@@ -622,39 +598,47 @@ func TestReadTracks(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// C->S H264 decoder config
|
// C->S H264 decoder config
|
||||||
byts := []byte{
|
codec := nh264.Codec{
|
||||||
0x17, 0x00, 0x00, 0x00, 0x00, 0x01, 0x64, 0x00,
|
SPS: map[int][]byte{
|
||||||
0x32, 0xff, 0xe1, 0x00, 0x1a, 0x67, 0x64, 0x00,
|
0: sps,
|
||||||
0x32, 0xac, 0x2c, 0x6a, 0x80, 0xa8, 0x02, 0xfe,
|
},
|
||||||
0x9b, 0x82, 0x80, 0x82, 0xa0, 0x00, 0x00, 0x03,
|
PPS: map[int][]byte{
|
||||||
0x00, 0x20, 0x00, 0x00, 0x06, 0x50, 0x80, 0x01,
|
0: pps,
|
||||||
0x00, 0x05, 0x68, 0xee, 0x31, 0xb2, 0x1b,
|
},
|
||||||
}
|
}
|
||||||
|
b := make([]byte, 128)
|
||||||
|
var n int
|
||||||
|
codec.ToConfig(b, &n)
|
||||||
|
body := append([]byte{flvio.FRAME_KEY<<4 | flvio.VIDEO_H264, 0, 0, 0, 0}, b[:n]...)
|
||||||
err = chunk0{
|
err = chunk0{
|
||||||
chunkStreamID: 21,
|
chunkStreamID: 6,
|
||||||
typ: 0x09,
|
typ: flvio.TAG_VIDEO,
|
||||||
streamID: 1,
|
streamID: 1,
|
||||||
bodyLen: uint32(len(byts)),
|
bodyLen: uint32(len(body)),
|
||||||
body: byts,
|
body: body,
|
||||||
}.write(conn)
|
}.write(conn)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
case "no metadata":
|
case "no metadata":
|
||||||
// C->S H264 decoder config
|
// C->S H264 decoder config
|
||||||
byts := []byte{
|
codec := nh264.Codec{
|
||||||
0x17, 0x00, 0x00, 0x00, 0x00, 0x01, 0x42, 0xe0,
|
SPS: map[int][]byte{
|
||||||
0x1f, 0xff, 0xe1, 0x00, 0x18, 0x27, 0x42, 0xe0,
|
0: sps,
|
||||||
0x1f, 0x8d, 0x68, 0x05, 0x00, 0x5b, 0xa1, 0x00,
|
},
|
||||||
0x00, 0x03, 0x00, 0x01, 0x00, 0x00, 0x03, 0x00,
|
PPS: map[int][]byte{
|
||||||
0x1e, 0x0f, 0x10, 0x7a, 0x80, 0x01, 0x00, 0x04,
|
0: pps,
|
||||||
0x28, 0xce, 0x32, 0x48,
|
},
|
||||||
}
|
}
|
||||||
|
b := make([]byte, 128)
|
||||||
|
var n int
|
||||||
|
codec.ToConfig(b, &n)
|
||||||
|
body := append([]byte{flvio.FRAME_KEY<<4 | flvio.VIDEO_H264, 0, 0, 0, 0}, b[:n]...)
|
||||||
err = chunk0{
|
err = chunk0{
|
||||||
chunkStreamID: 4,
|
chunkStreamID: 6,
|
||||||
typ: 0x09,
|
typ: flvio.TAG_VIDEO,
|
||||||
streamID: 1,
|
streamID: 1,
|
||||||
bodyLen: uint32(len(byts)),
|
bodyLen: uint32(len(body)),
|
||||||
body: byts,
|
body: body,
|
||||||
}.write(conn)
|
}.write(conn)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user