add TrackPCMA

This commit is contained in:
aler9
2022-04-22 15:14:41 +02:00
parent c759021124
commit 79ebb7d336
4 changed files with 72 additions and 6 deletions

View File

@@ -66,6 +66,9 @@ func newTrackFromMediaDescription(md *psdp.MediaDescription) (Track, error) {
case len(md.MediaName.Formats) == 1 && md.MediaName.Formats[0] == "0": case len(md.MediaName.Formats) == 1 && md.MediaName.Formats[0] == "0":
return newTrackPCMUFromMediaDescription(control, rtpmapPart1, md) return newTrackPCMUFromMediaDescription(control, rtpmapPart1, md)
case len(md.MediaName.Formats) == 1 && md.MediaName.Formats[0] == "8":
return newTrackPCMAFromMediaDescription(control, rtpmapPart1, md)
case strings.HasPrefix(strings.ToLower(rtpmapPart1), "mpeg4-generic/"): case strings.HasPrefix(strings.ToLower(rtpmapPart1), "mpeg4-generic/"):
return newTrackAACFromMediaDescription(control, payloadType, md) return newTrackAACFromMediaDescription(control, payloadType, md)

67
track_pcma.go Normal file
View File

@@ -0,0 +1,67 @@
package gortsplib //nolint:dupl
import (
"fmt"
"strings"
psdp "github.com/pion/sdp/v3"
)
// TrackPCMA is a PCMA track.
type TrackPCMA struct {
trackBase
}
// NewTrackPCMA allocates a TrackPCMA.
func NewTrackPCMA() *TrackPCMA {
return &TrackPCMA{}
}
func newTrackPCMAFromMediaDescription(
control string,
rtpmapPart1 string,
md *psdp.MediaDescription) (*TrackPCMA, error,
) {
tmp := strings.Split(rtpmapPart1, "/")
if len(tmp) >= 3 && tmp[2] != "1" {
return nil, fmt.Errorf("PCMA tracks must have only one channel")
}
return &TrackPCMA{
trackBase: trackBase{
control: control,
},
}, nil
}
// ClockRate returns the track clock rate.
func (t *TrackPCMA) ClockRate() int {
return 8000
}
func (t *TrackPCMA) clone() Track {
return &TrackPCMA{
trackBase: t.trackBase,
}
}
// MediaDescription returns the track media description in SDP format.
func (t *TrackPCMA) MediaDescription() *psdp.MediaDescription {
return &psdp.MediaDescription{
MediaName: psdp.MediaName{
Media: "audio",
Protos: []string{"RTP", "AVP"},
Formats: []string{"8"},
},
Attributes: []psdp.Attribute{
{
Key: "rtpmap",
Value: "8 PCMA/8000",
},
{
Key: "control",
Value: t.control,
},
},
}
}

View File

@@ -1,4 +1,4 @@
package gortsplib package gortsplib //nolint:dupl
import ( import (
"fmt" "fmt"

View File

@@ -24,11 +24,7 @@ func TestTrackNewFromMediaDescription(t *testing.T) {
Formats: []string{"8"}, Formats: []string{"8"},
}, },
}, },
&TrackGeneric{ &TrackPCMA{},
clockRate: 8000,
media: "audio",
formats: []string{"8"},
},
}, },
{ {
"pcmu", "pcmu",