diff --git a/pkg/formats/format.go b/pkg/formats/format.go index 84e790b5..e9f9f594 100644 --- a/pkg/formats/format.go +++ b/pkg/formats/format.go @@ -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{} diff --git a/pkg/formats/format_test.go b/pkg/formats/format_test.go index 2c89c7c9..9299af52 100644 --- a/pkg/formats/format_test.go +++ b/pkg/formats/format_test.go @@ -343,6 +343,16 @@ var casesFormat = []struct { "", nil, }, + { + "video mpeg-ts", + "video", + 33, + "", + nil, + &MPEGTS{}, + "MP2T/90000", + nil, + }, { "video mpeg4 video", "video", diff --git a/pkg/formats/mpegts.go b/pkg/formats/mpegts.go new file mode 100644 index 00000000..84856db0 --- /dev/null +++ b/pkg/formats/mpegts.go @@ -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 +} diff --git a/pkg/formats/mpegts_test.go b/pkg/formats/mpegts_test.go new file mode 100644 index 00000000..eb5198f3 --- /dev/null +++ b/pkg/formats/mpegts_test.go @@ -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{})) +}