client: support publishing with opus

This commit is contained in:
aler9
2021-10-30 15:45:13 +02:00
parent e9044bc6a5
commit cab3fe270e
14 changed files with 1208 additions and 855 deletions

157
track_opus_test.go Normal file
View File

@@ -0,0 +1,157 @@
package gortsplib
import (
"testing"
psdp "github.com/pion/sdp/v3"
"github.com/stretchr/testify/require"
)
func TestTrackOpusNew(t *testing.T) {
track, err := NewTrackOpus(96, &TrackConfigOpus{
SampleRate: 48000,
ChannelCount: 2,
})
require.NoError(t, err)
require.Equal(t, &Track{
Media: &psdp.MediaDescription{
MediaName: psdp.MediaName{
Media: "audio",
Protos: []string{"RTP", "AVP"},
Formats: []string{"96"},
},
Attributes: []psdp.Attribute{
{
Key: "rtpmap",
Value: "96 opus/48000/2",
},
{
Key: "fmtp",
Value: "96 sprop-stereo=1",
},
},
},
}, track)
}
func TestTrackIsOpus(t *testing.T) {
for _, ca := range []struct {
name string
track *Track
}{
{
"standard",
&Track{
Media: &psdp.MediaDescription{
MediaName: psdp.MediaName{
Media: "audio",
Protos: []string{"RTP", "AVP"},
Formats: []string{"96"},
},
Attributes: []psdp.Attribute{
{
Key: "rtpmap",
Value: "96 opus/48000/2",
},
{
Key: "fmtp",
Value: "96 sprop-stereo=1",
},
},
},
},
},
} {
t.Run(ca.name, func(t *testing.T) {
require.Equal(t, true, ca.track.IsOpus())
})
}
}
func TestTrackExtractConfigOpus(t *testing.T) {
for _, ca := range []struct {
name string
track *Track
conf *TrackConfigOpus
}{
{
"generic",
&Track{
Media: &psdp.MediaDescription{
MediaName: psdp.MediaName{
Media: "audio",
Protos: []string{"RTP", "AVP"},
Formats: []string{"96"},
},
Attributes: []psdp.Attribute{
{
Key: "rtpmap",
Value: "96 opus/48000/2",
},
{
Key: "fmtp",
Value: "96 sprop-stereo=1",
},
},
},
},
&TrackConfigOpus{
SampleRate: 48000,
ChannelCount: 2,
},
},
} {
t.Run(ca.name, func(t *testing.T) {
conf, err := ca.track.ExtractConfigOpus()
require.NoError(t, err)
require.Equal(t, ca.conf, conf)
})
}
}
func TestTrackConfigOpusErrors(t *testing.T) {
for _, ca := range []struct {
name string
track *Track
err string
}{
{
"missing rtpmap",
&Track{
Media: &psdp.MediaDescription{
MediaName: psdp.MediaName{
Media: "audio",
Protos: []string{"RTP", "AVP"},
Formats: []string{"96"},
},
Attributes: []psdp.Attribute{},
},
},
"rtpmap attribute is missing",
},
{
"invalid rtpmap",
&Track{
Media: &psdp.MediaDescription{
MediaName: psdp.MediaName{
Media: "audio",
Protos: []string{"RTP", "AVP"},
Formats: []string{"96"},
},
Attributes: []psdp.Attribute{
{
Key: "rtpmap",
Value: "96",
},
},
},
},
"invalid rtpmap (96)",
},
} {
t.Run(ca.name, func(t *testing.T) {
_, err := ca.track.ExtractConfigOpus()
require.Equal(t, ca.err, err.Error())
})
}
}