add MPEG-TS format (#244)

This commit is contained in:
Alessandro Ros
2023-04-12 21:47:17 +02:00
committed by GitHub
parent 39ce0bc3af
commit 7bf71a18b3
4 changed files with 67 additions and 0 deletions

View File

@@ -51,6 +51,9 @@ func Unmarshal(mediaType string, payloadType uint8, rtpMap string, fmtp map[stri
case payloadType == 32:
return &MPEG2Video{}
case payloadType == 33:
return &MPEGTS{}
case codec == "mp4v-es" && clock == "90000":
return &MPEG4Video{}

View File

@@ -343,6 +343,16 @@ var casesFormat = []struct {
"",
nil,
},
{
"video mpeg-ts",
"video",
33,
"",
nil,
&MPEGTS{},
"MP2T/90000",
nil,
},
{
"video mpeg4 video",
"video",

38
pkg/formats/mpegts.go Normal file
View File

@@ -0,0 +1,38 @@
package formats
import (
"github.com/pion/rtp"
)
// MPEGTS is a RTP format that uses MPEG-TS to wrap underlying tracks.
// Specification: https://datatracker.ietf.org/doc/html/rfc2250
type MPEGTS struct{}
// String implements Format.
func (f *MPEGTS) String() string {
return "MPEG-TS"
}
// ClockRate implements Format.
func (f *MPEGTS) ClockRate() int {
return 90000
}
// PayloadType implements Format.
func (f *MPEGTS) PayloadType() uint8 {
return 33
}
func (f *MPEGTS) unmarshal(payloadType uint8, clock string, codec string, rtpmap string, fmtp map[string]string) error {
return nil
}
// Marshal implements Format.
func (f *MPEGTS) Marshal() (string, map[string]string) {
return "MP2T/90000", nil
}
// PTSEqualsDTS implements Format.
func (f *MPEGTS) PTSEqualsDTS(*rtp.Packet) bool {
return true
}

View File

@@ -0,0 +1,16 @@
package formats
import (
"testing"
"github.com/pion/rtp"
"github.com/stretchr/testify/require"
)
func TestMPEGTSAttributes(t *testing.T) {
format := &MPEGTS{}
require.Equal(t, "MPEG-TS", format.String())
require.Equal(t, 90000, format.ClockRate())
require.Equal(t, uint8(33), format.PayloadType())
require.Equal(t, true, format.PTSEqualsDTS(&rtp.Packet{}))
}