mirror of
https://github.com/aler9/rtsp-simple-server
synced 2025-10-05 15:46:58 +08:00
104 lines
2.1 KiB
Go
104 lines
2.1 KiB
Go
package webrtc
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/bluenviron/gortsplib/v4/pkg/description"
|
|
"github.com/bluenviron/gortsplib/v4/pkg/format"
|
|
"github.com/bluenviron/mediamtx/internal/logger"
|
|
"github.com/bluenviron/mediamtx/internal/stream"
|
|
"github.com/bluenviron/mediamtx/internal/test"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestFromStreamNoSupportedCodecs(t *testing.T) {
|
|
stream, err := stream.New(
|
|
512,
|
|
1460,
|
|
&description.Session{Medias: []*description.Media{{
|
|
Type: description.MediaTypeVideo,
|
|
Formats: []format.Format{&format.H265{}},
|
|
}}},
|
|
true,
|
|
test.NilLogger,
|
|
)
|
|
require.NoError(t, err)
|
|
|
|
l := test.Logger(func(logger.Level, string, ...interface{}) {
|
|
t.Error("should not happen")
|
|
})
|
|
|
|
err = FromStream(stream, l, nil)
|
|
require.Equal(t, errNoSupportedCodecsFrom, err)
|
|
}
|
|
|
|
func TestFromStreamSkipUnsupportedTracks(t *testing.T) {
|
|
stream, err := stream.New(
|
|
512,
|
|
1460,
|
|
&description.Session{Medias: []*description.Media{
|
|
{
|
|
Type: description.MediaTypeVideo,
|
|
Formats: []format.Format{&format.H264{}},
|
|
},
|
|
{
|
|
Type: description.MediaTypeVideo,
|
|
Formats: []format.Format{&format.H265{}},
|
|
},
|
|
}},
|
|
true,
|
|
test.NilLogger,
|
|
)
|
|
require.NoError(t, err)
|
|
|
|
n := 0
|
|
|
|
l := test.Logger(func(l logger.Level, format string, args ...interface{}) {
|
|
require.Equal(t, logger.Warn, l)
|
|
if n == 0 {
|
|
require.Equal(t, "skipping track 2 (H265)", fmt.Sprintf(format, args...))
|
|
}
|
|
n++
|
|
})
|
|
|
|
pc := &PeerConnection{}
|
|
|
|
err = FromStream(stream, l, pc)
|
|
require.NoError(t, err)
|
|
defer stream.RemoveReader(l)
|
|
|
|
require.Equal(t, 1, n)
|
|
}
|
|
|
|
func TestFromStream(t *testing.T) {
|
|
for _, ca := range toFromStreamCases {
|
|
if ca.in == nil {
|
|
continue
|
|
}
|
|
t.Run(ca.name, func(t *testing.T) {
|
|
stream, err := stream.New(
|
|
512,
|
|
1460,
|
|
&description.Session{
|
|
Medias: []*description.Media{{
|
|
Formats: []format.Format{ca.in},
|
|
}},
|
|
},
|
|
false,
|
|
test.NilLogger,
|
|
)
|
|
require.NoError(t, err)
|
|
defer stream.Close()
|
|
|
|
pc := &PeerConnection{}
|
|
|
|
err = FromStream(stream, nil, pc)
|
|
require.NoError(t, err)
|
|
defer stream.RemoveReader(nil)
|
|
|
|
require.Equal(t, ca.webrtcCaps, pc.OutgoingTracks[0].Caps)
|
|
})
|
|
}
|
|
}
|