mirror of
https://github.com/aler9/gortsplib
synced 2025-10-05 15:16:51 +08:00
add TrackPCMA
This commit is contained in:
3
track.go
3
track.go
@@ -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
67
track_pcma.go
Normal 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,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
@@ -1,4 +1,4 @@
|
|||||||
package gortsplib
|
package gortsplib //nolint:dupl
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@@ -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",
|
||||||
|
Reference in New Issue
Block a user