mirror of
https://github.com/aler9/gortsplib
synced 2025-10-05 15:16:51 +08:00
add TrackMpegAudio
This commit is contained in:
5
track.go
5
track.go
@@ -67,7 +67,7 @@ func newTrackFromMediaDescription(md *psdp.MediaDescription) (Track, error) {
|
|||||||
return newTrackJPEGFromMediaDescription(control)
|
return newTrackJPEGFromMediaDescription(control)
|
||||||
|
|
||||||
case md.MediaName.Formats[0] == "32":
|
case md.MediaName.Formats[0] == "32":
|
||||||
return newTrackMPVFromMediaDescription(control)
|
return newTrackMpegVideoFromMediaDescription(control)
|
||||||
|
|
||||||
case rtpmapPart1 == "H264/90000":
|
case rtpmapPart1 == "H264/90000":
|
||||||
return newTrackH264FromMediaDescription(control, payloadType, md)
|
return newTrackH264FromMediaDescription(control, payloadType, md)
|
||||||
@@ -84,6 +84,9 @@ func newTrackFromMediaDescription(md *psdp.MediaDescription) (Track, error) {
|
|||||||
case md.MediaName.Formats[0] == "8":
|
case md.MediaName.Formats[0] == "8":
|
||||||
return newTrackPCMAFromMediaDescription(control, rtpmapPart1)
|
return newTrackPCMAFromMediaDescription(control, rtpmapPart1)
|
||||||
|
|
||||||
|
case md.MediaName.Formats[0] == "14":
|
||||||
|
return newTrackMpegAudioFromMediaDescription(control)
|
||||||
|
|
||||||
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)
|
||||||
|
|
||||||
|
53
track_mpegaudio.go
Normal file
53
track_mpegaudio.go
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
package gortsplib //nolint:dupl
|
||||||
|
|
||||||
|
import (
|
||||||
|
psdp "github.com/pion/sdp/v3"
|
||||||
|
)
|
||||||
|
|
||||||
|
// TrackMpegAudio is a MPEG-1 or MPEG-2 audio track.
|
||||||
|
type TrackMpegAudio struct {
|
||||||
|
trackBase
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewTrackMpegAudio allocates a TrackMpegAudio.
|
||||||
|
func NewTrackMpegAudio() *TrackMpegAudio {
|
||||||
|
return &TrackMpegAudio{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func newTrackMpegAudioFromMediaDescription(
|
||||||
|
control string) (*TrackMpegAudio, error,
|
||||||
|
) {
|
||||||
|
return &TrackMpegAudio{
|
||||||
|
trackBase: trackBase{
|
||||||
|
control: control,
|
||||||
|
},
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClockRate returns the track clock rate.
|
||||||
|
func (t *TrackMpegAudio) ClockRate() int {
|
||||||
|
return 90000
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *TrackMpegAudio) clone() Track {
|
||||||
|
return &TrackMpegAudio{
|
||||||
|
trackBase: t.trackBase,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MediaDescription returns the track media description in SDP format.
|
||||||
|
func (t *TrackMpegAudio) MediaDescription() *psdp.MediaDescription {
|
||||||
|
return &psdp.MediaDescription{
|
||||||
|
MediaName: psdp.MediaName{
|
||||||
|
Media: "audio",
|
||||||
|
Protos: []string{"RTP", "AVP"},
|
||||||
|
Formats: []string{"14"},
|
||||||
|
},
|
||||||
|
Attributes: []psdp.Attribute{
|
||||||
|
{
|
||||||
|
Key: "control",
|
||||||
|
Value: t.control,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
39
track_mpegaudio_test.go
Normal file
39
track_mpegaudio_test.go
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
package gortsplib
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
psdp "github.com/pion/sdp/v3"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestTrackMpegAudioNew(t *testing.T) {
|
||||||
|
track := NewTrackMpegAudio()
|
||||||
|
require.Equal(t, "", track.GetControl())
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestTrackMpegAudioClone(t *testing.T) {
|
||||||
|
track := NewTrackMpegAudio()
|
||||||
|
|
||||||
|
clone := track.clone()
|
||||||
|
require.NotSame(t, track, clone)
|
||||||
|
require.Equal(t, track, clone)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestTrackMpegAudioMediaDescription(t *testing.T) {
|
||||||
|
track := NewTrackMpegAudio()
|
||||||
|
|
||||||
|
require.Equal(t, &psdp.MediaDescription{
|
||||||
|
MediaName: psdp.MediaName{
|
||||||
|
Media: "audio",
|
||||||
|
Protos: []string{"RTP", "AVP"},
|
||||||
|
Formats: []string{"14"},
|
||||||
|
},
|
||||||
|
Attributes: []psdp.Attribute{
|
||||||
|
{
|
||||||
|
Key: "control",
|
||||||
|
Value: "",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}, track.MediaDescription())
|
||||||
|
}
|
@@ -4,20 +4,20 @@ import (
|
|||||||
psdp "github.com/pion/sdp/v3"
|
psdp "github.com/pion/sdp/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TrackMPV is a MPEG-1 or MPEG-2 video track.
|
// TrackMpegVideo is a MPEG-1 or MPEG-2 video track.
|
||||||
type TrackMPV struct {
|
type TrackMpegVideo struct {
|
||||||
trackBase
|
trackBase
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewTrackMPV allocates a TrackMPV.
|
// NewTrackMpegVideo allocates a TrackMpegVideo.
|
||||||
func NewTrackMPV() *TrackMPV {
|
func NewTrackMpegVideo() *TrackMpegVideo {
|
||||||
return &TrackMPV{}
|
return &TrackMpegVideo{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func newTrackMPVFromMediaDescription(
|
func newTrackMpegVideoFromMediaDescription(
|
||||||
control string) (*TrackMPV, error,
|
control string) (*TrackMpegVideo, error,
|
||||||
) {
|
) {
|
||||||
return &TrackMPV{
|
return &TrackMpegVideo{
|
||||||
trackBase: trackBase{
|
trackBase: trackBase{
|
||||||
control: control,
|
control: control,
|
||||||
},
|
},
|
||||||
@@ -25,18 +25,18 @@ func newTrackMPVFromMediaDescription(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ClockRate returns the track clock rate.
|
// ClockRate returns the track clock rate.
|
||||||
func (t *TrackMPV) ClockRate() int {
|
func (t *TrackMpegVideo) ClockRate() int {
|
||||||
return 90000
|
return 90000
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TrackMPV) clone() Track {
|
func (t *TrackMpegVideo) clone() Track {
|
||||||
return &TrackMPV{
|
return &TrackMpegVideo{
|
||||||
trackBase: t.trackBase,
|
trackBase: t.trackBase,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MediaDescription returns the track media description in SDP format.
|
// MediaDescription returns the track media description in SDP format.
|
||||||
func (t *TrackMPV) MediaDescription() *psdp.MediaDescription {
|
func (t *TrackMpegVideo) MediaDescription() *psdp.MediaDescription {
|
||||||
return &psdp.MediaDescription{
|
return &psdp.MediaDescription{
|
||||||
MediaName: psdp.MediaName{
|
MediaName: psdp.MediaName{
|
||||||
Media: "video",
|
Media: "video",
|
@@ -7,21 +7,21 @@ import (
|
|||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestTrackMPVNew(t *testing.T) {
|
func TestTrackMpegVideoNew(t *testing.T) {
|
||||||
track := NewTrackMPV()
|
track := NewTrackMpegVideo()
|
||||||
require.Equal(t, "", track.GetControl())
|
require.Equal(t, "", track.GetControl())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTrackMPVClone(t *testing.T) {
|
func TestTrackMpegVideoClone(t *testing.T) {
|
||||||
track := NewTrackMPV()
|
track := NewTrackMpegVideo()
|
||||||
|
|
||||||
clone := track.clone()
|
clone := track.clone()
|
||||||
require.NotSame(t, track, clone)
|
require.NotSame(t, track, clone)
|
||||||
require.Equal(t, track, clone)
|
require.Equal(t, track, clone)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTrackMPVMediaDescription(t *testing.T) {
|
func TestTrackMpegVideoMediaDescription(t *testing.T) {
|
||||||
track := NewTrackMPV()
|
track := NewTrackMpegVideo()
|
||||||
|
|
||||||
require.Equal(t, &psdp.MediaDescription{
|
require.Equal(t, &psdp.MediaDescription{
|
||||||
MediaName: psdp.MediaName{
|
MediaName: psdp.MediaName{
|
@@ -37,6 +37,17 @@ func TestTrackNewFromMediaDescription(t *testing.T) {
|
|||||||
},
|
},
|
||||||
&TrackPCMU{},
|
&TrackPCMU{},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"mpeg audio",
|
||||||
|
&psdp.MediaDescription{
|
||||||
|
MediaName: psdp.MediaName{
|
||||||
|
Media: "audio",
|
||||||
|
Protos: []string{"RTP", "AVP"},
|
||||||
|
Formats: []string{"14"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
&TrackMpegAudio{},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"aac",
|
"aac",
|
||||||
&psdp.MediaDescription{
|
&psdp.MediaDescription{
|
||||||
@@ -203,7 +214,7 @@ func TestTrackNewFromMediaDescription(t *testing.T) {
|
|||||||
&TrackJPEG{},
|
&TrackJPEG{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"mpv",
|
"mpeg video",
|
||||||
&psdp.MediaDescription{
|
&psdp.MediaDescription{
|
||||||
MediaName: psdp.MediaName{
|
MediaName: psdp.MediaName{
|
||||||
Media: "video",
|
Media: "video",
|
||||||
@@ -211,7 +222,7 @@ func TestTrackNewFromMediaDescription(t *testing.T) {
|
|||||||
Formats: []string{"32"},
|
Formats: []string{"32"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
&TrackMPV{},
|
&TrackMpegVideo{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"h264",
|
"h264",
|
||||||
|
Reference in New Issue
Block a user