diff --git a/README.md b/README.md index 63999865..4ba3f9e2 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ Features: * Parse RTSP elements * Encode/decode format-specific frames into/from RTP packets. The following formats are supported: * Video: H264, H265, M-JPEG, VP8, VP9 - * Audio: G711 (PCMA, PCMU), G722, LPCM, MPEG4 Audio (AAC), Opus + * Audio: G711 (PCMA, PCMU), G722, LPCM, MPEG-2 Audio (MP3), MPEG-4 Audio (AAC), Opus ## Table of contents diff --git a/go.mod b/go.mod index 61659e18..4b007552 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.18 require ( github.com/asticode/go-astits v1.11.0 - github.com/bluenviron/mediacommon v0.3.1 + github.com/bluenviron/mediacommon v0.4.1 github.com/google/uuid v1.3.0 github.com/pion/rtcp v1.2.10 github.com/pion/rtp v0.0.0-20230107162714-c3ea6851e25b diff --git a/go.sum b/go.sum index 9384f10c..a97594f0 100644 --- a/go.sum +++ b/go.sum @@ -2,8 +2,8 @@ github.com/asticode/go-astikit v0.30.0 h1:DkBkRQRIxYcknlaU7W7ksNfn4gMFsB0tqMJflx github.com/asticode/go-astikit v0.30.0/go.mod h1:h4ly7idim1tNhaVkdVBeXQZEE3L0xblP7fCWbgwipF0= github.com/asticode/go-astits v1.11.0 h1:GTHUXht0ZXAJXsVbsLIcyfHr1Bchi4QQwMARw2ZWAng= github.com/asticode/go-astits v1.11.0/go.mod h1:QSHmknZ51pf6KJdHKZHJTLlMegIrhega3LPWz3ND/iI= -github.com/bluenviron/mediacommon v0.3.1 h1:C4okNqyN1Mg5CVGcGKk2tEk9Uj2hHZusHV7nqdjn1Lk= -github.com/bluenviron/mediacommon v0.3.1/go.mod h1:t0dqPsWUTchyvib0MhixIwXEgvDX4V9G+I0GzWLQRb8= +github.com/bluenviron/mediacommon v0.4.1 h1:oiqvqwnZ0NbB+mCZjuyBtgY7cF88rZdhb/PTSNG9M+Q= +github.com/bluenviron/mediacommon v0.4.1/go.mod h1:t0dqPsWUTchyvib0MhixIwXEgvDX4V9G+I0GzWLQRb8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/pkg/formats/mjpeg.go b/pkg/formats/mjpeg.go index 8da5b5f3..0370a537 100644 --- a/pkg/formats/mjpeg.go +++ b/pkg/formats/mjpeg.go @@ -1,4 +1,4 @@ -package formats +package formats //nolint:dupl import ( "github.com/pion/rtp" diff --git a/pkg/formats/mpeg2_audio.go b/pkg/formats/mpeg2_audio.go index 51cab41b..024fc3ae 100644 --- a/pkg/formats/mpeg2_audio.go +++ b/pkg/formats/mpeg2_audio.go @@ -1,7 +1,9 @@ -package formats +package formats //nolint:dupl import ( "github.com/pion/rtp" + + "github.com/bluenviron/gortsplib/v3/pkg/formats/rtpmpeg2audio" ) // MPEG2Audio is a RTP format that uses a MPEG-1 or MPEG-2 audio codec. @@ -44,3 +46,17 @@ func (f *MPEG2Audio) FMTP() map[string]string { func (f *MPEG2Audio) PTSEqualsDTS(*rtp.Packet) bool { return true } + +// CreateDecoder creates a decoder able to decode the content of the format. +func (f *MPEG2Audio) CreateDecoder() *rtpmpeg2audio.Decoder { + d := &rtpmpeg2audio.Decoder{} + d.Init() + return d +} + +// CreateEncoder creates an encoder able to encode the content of the format. +func (f *MPEG2Audio) CreateEncoder() *rtpmpeg2audio.Encoder { + e := &rtpmpeg2audio.Encoder{} + e.Init() + return e +} diff --git a/pkg/formats/mpeg2_audio_test.go b/pkg/formats/mpeg2_audio_test.go index afcc38bc..782588eb 100644 --- a/pkg/formats/mpeg2_audio_test.go +++ b/pkg/formats/mpeg2_audio_test.go @@ -13,3 +13,43 @@ func TestMPEG2AudioAttributes(t *testing.T) { require.Equal(t, 90000, format.ClockRate()) require.Equal(t, true, format.PTSEqualsDTS(&rtp.Packet{})) } + +func TestMPEG2AudioDecEncoder(t *testing.T) { + format := &MPEG2Audio{} + + enc := format.CreateEncoder() + pkts, err := enc.Encode([][]byte{{ + 0xff, 0xfb, 0x14, 0x64, 0x00, 0x0f, 0xf0, 0x00, + 0x00, 0x69, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, + 0x0d, 0x20, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, + 0xa4, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x34, + 0x80, 0x00, 0x00, 0x04, 0x4c, 0x41, 0x4d, 0x45, + 0x33, 0x2e, 0x31, 0x30, 0x30, 0x55, 0x55, 0x55, + 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, + 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, + 0x55, 0xc0, 0x65, 0xf4, 0xa0, 0x31, 0x8f, 0xce, + 0x8d, 0x46, 0xfc, 0x8c, 0x73, 0xb9, 0x34, 0x3e, + 0xb5, 0x03, 0x39, 0xc0, 0x04, 0x01, 0x98, 0x44, + 0x38, 0xe0, 0x98, 0x10, 0x9b, 0xa8, 0x0f, 0xa8, + }}, 0) + require.NoError(t, err) + require.Equal(t, format.PayloadType(), pkts[0].PayloadType) + + dec := format.CreateDecoder() + byts, _, err := dec.Decode(pkts[0]) + require.NoError(t, err) + require.Equal(t, [][]byte{{ + 0xff, 0xfb, 0x14, 0x64, 0x00, 0x0f, 0xf0, 0x00, + 0x00, 0x69, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, + 0x0d, 0x20, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, + 0xa4, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x34, + 0x80, 0x00, 0x00, 0x04, 0x4c, 0x41, 0x4d, 0x45, + 0x33, 0x2e, 0x31, 0x30, 0x30, 0x55, 0x55, 0x55, + 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, + 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, + 0x55, 0xc0, 0x65, 0xf4, 0xa0, 0x31, 0x8f, 0xce, + 0x8d, 0x46, 0xfc, 0x8c, 0x73, 0xb9, 0x34, 0x3e, + 0xb5, 0x03, 0x39, 0xc0, 0x04, 0x01, 0x98, 0x44, + 0x38, 0xe0, 0x98, 0x10, 0x9b, 0xa8, 0x0f, 0xa8, + }}, byts) +} diff --git a/pkg/formats/rtph264/decoder.go b/pkg/formats/rtph264/decoder.go index 52f039dd..e1e80d56 100644 --- a/pkg/formats/rtph264/decoder.go +++ b/pkg/formats/rtph264/decoder.go @@ -23,6 +23,7 @@ var ErrNonStartingPacketAndNoPrevious = errors.New( "received a non-starting fragment without any previous starting fragment") // Decoder is a RTP/H264 decoder. +// Specification: https://datatracker.ietf.org/doc/html/rfc6184 type Decoder struct { // indicates the packetization mode. PacketizationMode int diff --git a/pkg/formats/rtph264/decoder_test.go b/pkg/formats/rtph264/decoder_test.go index eba28359..d5f3b58b 100644 --- a/pkg/formats/rtph264/decoder_test.go +++ b/pkg/formats/rtph264/decoder_test.go @@ -204,7 +204,7 @@ func TestDecodeUntilMarker(t *testing.T) { require.Equal(t, [][]byte{{0x01, 0x02}, {0x01, 0x02}}, nalus) } -func FuzzDecoderUnmarshal(f *testing.F) { +func FuzzDecoder(f *testing.F) { d := &Decoder{} d.Init() diff --git a/pkg/formats/rtph264/encoder.go b/pkg/formats/rtph264/encoder.go index acba1bf5..3604103d 100644 --- a/pkg/formats/rtph264/encoder.go +++ b/pkg/formats/rtph264/encoder.go @@ -22,6 +22,7 @@ func randUint32() uint32 { } // Encoder is a RTP/H264 encoder. +// Specification: https://datatracker.ietf.org/doc/html/rfc6184 type Encoder struct { // payload type of packets. PayloadType uint8 diff --git a/pkg/formats/rtph264/testdata/fuzz/FuzzDecoderUnmarshal/048b606517c23baffac96520675af386f92f471f22f098caec184d581dd6292e b/pkg/formats/rtph264/testdata/fuzz/FuzzDecoder/048b606517c23baffac96520675af386f92f471f22f098caec184d581dd6292e similarity index 100% rename from pkg/formats/rtph264/testdata/fuzz/FuzzDecoderUnmarshal/048b606517c23baffac96520675af386f92f471f22f098caec184d581dd6292e rename to pkg/formats/rtph264/testdata/fuzz/FuzzDecoder/048b606517c23baffac96520675af386f92f471f22f098caec184d581dd6292e diff --git a/pkg/formats/rtph264/testdata/fuzz/FuzzDecoderUnmarshal/17ec193e17dd91d1b2a621884383564489d9f873db1b015a693c79fb7c1c1a46 b/pkg/formats/rtph264/testdata/fuzz/FuzzDecoder/17ec193e17dd91d1b2a621884383564489d9f873db1b015a693c79fb7c1c1a46 similarity index 100% rename from pkg/formats/rtph264/testdata/fuzz/FuzzDecoderUnmarshal/17ec193e17dd91d1b2a621884383564489d9f873db1b015a693c79fb7c1c1a46 rename to pkg/formats/rtph264/testdata/fuzz/FuzzDecoder/17ec193e17dd91d1b2a621884383564489d9f873db1b015a693c79fb7c1c1a46 diff --git a/pkg/formats/rtph264/testdata/fuzz/FuzzDecoderUnmarshal/55cc57e8de6f7821309a6444040480f3aa0128b6b6cd96325b7997ff47d5d29d b/pkg/formats/rtph264/testdata/fuzz/FuzzDecoder/55cc57e8de6f7821309a6444040480f3aa0128b6b6cd96325b7997ff47d5d29d similarity index 100% rename from pkg/formats/rtph264/testdata/fuzz/FuzzDecoderUnmarshal/55cc57e8de6f7821309a6444040480f3aa0128b6b6cd96325b7997ff47d5d29d rename to pkg/formats/rtph264/testdata/fuzz/FuzzDecoder/55cc57e8de6f7821309a6444040480f3aa0128b6b6cd96325b7997ff47d5d29d diff --git a/pkg/formats/rtph264/testdata/fuzz/FuzzDecoderUnmarshal/c30437d5edf1393c2957896ca6c4e4d0467a50451fd1feb1cae249fdcbf25a5a b/pkg/formats/rtph264/testdata/fuzz/FuzzDecoder/c30437d5edf1393c2957896ca6c4e4d0467a50451fd1feb1cae249fdcbf25a5a similarity index 100% rename from pkg/formats/rtph264/testdata/fuzz/FuzzDecoderUnmarshal/c30437d5edf1393c2957896ca6c4e4d0467a50451fd1feb1cae249fdcbf25a5a rename to pkg/formats/rtph264/testdata/fuzz/FuzzDecoder/c30437d5edf1393c2957896ca6c4e4d0467a50451fd1feb1cae249fdcbf25a5a diff --git a/pkg/formats/rtph264/testdata/fuzz/FuzzDecoderUnmarshal/c89423ac94e1743f63fb142431eed08c3b74e51a4e7b8ed44a1ba826ca6129d9 b/pkg/formats/rtph264/testdata/fuzz/FuzzDecoder/c89423ac94e1743f63fb142431eed08c3b74e51a4e7b8ed44a1ba826ca6129d9 similarity index 100% rename from pkg/formats/rtph264/testdata/fuzz/FuzzDecoderUnmarshal/c89423ac94e1743f63fb142431eed08c3b74e51a4e7b8ed44a1ba826ca6129d9 rename to pkg/formats/rtph264/testdata/fuzz/FuzzDecoder/c89423ac94e1743f63fb142431eed08c3b74e51a4e7b8ed44a1ba826ca6129d9 diff --git a/pkg/formats/rtph264/testdata/fuzz/FuzzDecoderUnmarshal/caf81e9797b19c76c1fc4dbf537d4d81f389524539f402d13aa01f93a65ac7e9 b/pkg/formats/rtph264/testdata/fuzz/FuzzDecoder/caf81e9797b19c76c1fc4dbf537d4d81f389524539f402d13aa01f93a65ac7e9 similarity index 100% rename from pkg/formats/rtph264/testdata/fuzz/FuzzDecoderUnmarshal/caf81e9797b19c76c1fc4dbf537d4d81f389524539f402d13aa01f93a65ac7e9 rename to pkg/formats/rtph264/testdata/fuzz/FuzzDecoder/caf81e9797b19c76c1fc4dbf537d4d81f389524539f402d13aa01f93a65ac7e9 diff --git a/pkg/formats/rtph264/testdata/fuzz/FuzzDecoderUnmarshal/f428976a5b2917c009d1f28d7a96e81095be8631f062798130aa7e6835b67b01 b/pkg/formats/rtph264/testdata/fuzz/FuzzDecoder/f428976a5b2917c009d1f28d7a96e81095be8631f062798130aa7e6835b67b01 similarity index 100% rename from pkg/formats/rtph264/testdata/fuzz/FuzzDecoderUnmarshal/f428976a5b2917c009d1f28d7a96e81095be8631f062798130aa7e6835b67b01 rename to pkg/formats/rtph264/testdata/fuzz/FuzzDecoder/f428976a5b2917c009d1f28d7a96e81095be8631f062798130aa7e6835b67b01 diff --git a/pkg/formats/rtph264/testdata/fuzz/FuzzDecoderUnmarshal/fe107a097efccd5098d6b0147ef4b39f0e467f0257dbf8f8b2f256c235640a6e b/pkg/formats/rtph264/testdata/fuzz/FuzzDecoder/fe107a097efccd5098d6b0147ef4b39f0e467f0257dbf8f8b2f256c235640a6e similarity index 100% rename from pkg/formats/rtph264/testdata/fuzz/FuzzDecoderUnmarshal/fe107a097efccd5098d6b0147ef4b39f0e467f0257dbf8f8b2f256c235640a6e rename to pkg/formats/rtph264/testdata/fuzz/FuzzDecoder/fe107a097efccd5098d6b0147ef4b39f0e467f0257dbf8f8b2f256c235640a6e diff --git a/pkg/formats/rtph265/decoder.go b/pkg/formats/rtph265/decoder.go index 34580c88..f8e94931 100644 --- a/pkg/formats/rtph265/decoder.go +++ b/pkg/formats/rtph265/decoder.go @@ -22,6 +22,7 @@ var ErrNonStartingPacketAndNoPrevious = errors.New( "received a non-starting fragment without any previous starting fragment") // Decoder is a RTP/H265 decoder. +// Specification: https://datatracker.ietf.org/doc/html/rfc7798 type Decoder struct { // indicates that NALUs have an additional field that specifies the decoding order. MaxDONDiff int diff --git a/pkg/formats/rtph265/decoder_test.go b/pkg/formats/rtph265/decoder_test.go index 300bb0d7..9921ab73 100644 --- a/pkg/formats/rtph265/decoder_test.go +++ b/pkg/formats/rtph265/decoder_test.go @@ -56,7 +56,7 @@ func TestDecode(t *testing.T) { } } -func FuzzDecoderUnmarshal(f *testing.F) { +func FuzzDecoder(f *testing.F) { d := &Decoder{} d.Init() diff --git a/pkg/formats/rtph265/encoder.go b/pkg/formats/rtph265/encoder.go index 36f65de9..b8be0ce9 100644 --- a/pkg/formats/rtph265/encoder.go +++ b/pkg/formats/rtph265/encoder.go @@ -21,6 +21,7 @@ func randUint32() uint32 { } // Encoder is a RTP/H265 encoder. +// Specification: https://datatracker.ietf.org/doc/html/rfc7798 type Encoder struct { // payload type of packets. PayloadType uint8 diff --git a/pkg/formats/rtph265/testdata/fuzz/FuzzDecoderUnmarshal/353ba911ad2dc1916f0bb9eb5e553575e27c9a6662e86d265f55bd57d1746962 b/pkg/formats/rtph265/testdata/fuzz/FuzzDecoder/353ba911ad2dc1916f0bb9eb5e553575e27c9a6662e86d265f55bd57d1746962 similarity index 100% rename from pkg/formats/rtph265/testdata/fuzz/FuzzDecoderUnmarshal/353ba911ad2dc1916f0bb9eb5e553575e27c9a6662e86d265f55bd57d1746962 rename to pkg/formats/rtph265/testdata/fuzz/FuzzDecoder/353ba911ad2dc1916f0bb9eb5e553575e27c9a6662e86d265f55bd57d1746962 diff --git a/pkg/formats/rtph265/testdata/fuzz/FuzzDecoderUnmarshal/6e0463cbdc2d559f2823538d2efee4a8b811c3ea02d2bd8e0f306d81382d5698 b/pkg/formats/rtph265/testdata/fuzz/FuzzDecoder/6e0463cbdc2d559f2823538d2efee4a8b811c3ea02d2bd8e0f306d81382d5698 similarity index 100% rename from pkg/formats/rtph265/testdata/fuzz/FuzzDecoderUnmarshal/6e0463cbdc2d559f2823538d2efee4a8b811c3ea02d2bd8e0f306d81382d5698 rename to pkg/formats/rtph265/testdata/fuzz/FuzzDecoder/6e0463cbdc2d559f2823538d2efee4a8b811c3ea02d2bd8e0f306d81382d5698 diff --git a/pkg/formats/rtph265/testdata/fuzz/FuzzDecoderUnmarshal/95aa14d7ab02ec8b5c470dcc780587540caba1589c6a7ce702ff84edca9b3133 b/pkg/formats/rtph265/testdata/fuzz/FuzzDecoder/95aa14d7ab02ec8b5c470dcc780587540caba1589c6a7ce702ff84edca9b3133 similarity index 100% rename from pkg/formats/rtph265/testdata/fuzz/FuzzDecoderUnmarshal/95aa14d7ab02ec8b5c470dcc780587540caba1589c6a7ce702ff84edca9b3133 rename to pkg/formats/rtph265/testdata/fuzz/FuzzDecoder/95aa14d7ab02ec8b5c470dcc780587540caba1589c6a7ce702ff84edca9b3133 diff --git a/pkg/formats/rtph265/testdata/fuzz/FuzzDecoderUnmarshal/c4389a565e8280502fc611cde347896b5d167806b2e49e22db23bed73deef75b b/pkg/formats/rtph265/testdata/fuzz/FuzzDecoder/c4389a565e8280502fc611cde347896b5d167806b2e49e22db23bed73deef75b similarity index 100% rename from pkg/formats/rtph265/testdata/fuzz/FuzzDecoderUnmarshal/c4389a565e8280502fc611cde347896b5d167806b2e49e22db23bed73deef75b rename to pkg/formats/rtph265/testdata/fuzz/FuzzDecoder/c4389a565e8280502fc611cde347896b5d167806b2e49e22db23bed73deef75b diff --git a/pkg/formats/rtph265/testdata/fuzz/FuzzDecoderUnmarshal/caf81e9797b19c76c1fc4dbf537d4d81f389524539f402d13aa01f93a65ac7e9 b/pkg/formats/rtph265/testdata/fuzz/FuzzDecoder/caf81e9797b19c76c1fc4dbf537d4d81f389524539f402d13aa01f93a65ac7e9 similarity index 100% rename from pkg/formats/rtph265/testdata/fuzz/FuzzDecoderUnmarshal/caf81e9797b19c76c1fc4dbf537d4d81f389524539f402d13aa01f93a65ac7e9 rename to pkg/formats/rtph265/testdata/fuzz/FuzzDecoder/caf81e9797b19c76c1fc4dbf537d4d81f389524539f402d13aa01f93a65ac7e9 diff --git a/pkg/formats/rtph265/testdata/fuzz/FuzzDecoderUnmarshal/cb84a08ac93f5772ee3ba0f0bcfde81c9cd71a403c69f893cebc8378c60af625 b/pkg/formats/rtph265/testdata/fuzz/FuzzDecoder/cb84a08ac93f5772ee3ba0f0bcfde81c9cd71a403c69f893cebc8378c60af625 similarity index 100% rename from pkg/formats/rtph265/testdata/fuzz/FuzzDecoderUnmarshal/cb84a08ac93f5772ee3ba0f0bcfde81c9cd71a403c69f893cebc8378c60af625 rename to pkg/formats/rtph265/testdata/fuzz/FuzzDecoder/cb84a08ac93f5772ee3ba0f0bcfde81c9cd71a403c69f893cebc8378c60af625 diff --git a/pkg/formats/rtph265/testdata/fuzz/FuzzDecoderUnmarshal/e45ead12fae619dd0807aaf83341d58eca4d50fab6eefbe78953581a1a4df198 b/pkg/formats/rtph265/testdata/fuzz/FuzzDecoder/e45ead12fae619dd0807aaf83341d58eca4d50fab6eefbe78953581a1a4df198 similarity index 100% rename from pkg/formats/rtph265/testdata/fuzz/FuzzDecoderUnmarshal/e45ead12fae619dd0807aaf83341d58eca4d50fab6eefbe78953581a1a4df198 rename to pkg/formats/rtph265/testdata/fuzz/FuzzDecoder/e45ead12fae619dd0807aaf83341d58eca4d50fab6eefbe78953581a1a4df198 diff --git a/pkg/formats/rtph265/testdata/fuzz/FuzzDecoderUnmarshal/eb4593a9592045ab0cf0b17a3f9f2754d6898ee465ec32d9e08392bcbab0a81a b/pkg/formats/rtph265/testdata/fuzz/FuzzDecoder/eb4593a9592045ab0cf0b17a3f9f2754d6898ee465ec32d9e08392bcbab0a81a similarity index 100% rename from pkg/formats/rtph265/testdata/fuzz/FuzzDecoderUnmarshal/eb4593a9592045ab0cf0b17a3f9f2754d6898ee465ec32d9e08392bcbab0a81a rename to pkg/formats/rtph265/testdata/fuzz/FuzzDecoder/eb4593a9592045ab0cf0b17a3f9f2754d6898ee465ec32d9e08392bcbab0a81a diff --git a/pkg/formats/rtplpcm/decoder.go b/pkg/formats/rtplpcm/decoder.go index 3bb43175..8fde00ff 100644 --- a/pkg/formats/rtplpcm/decoder.go +++ b/pkg/formats/rtplpcm/decoder.go @@ -10,6 +10,7 @@ import ( ) // Decoder is a RTP/LPCM decoder. +// Specification: https://datatracker.ietf.org/doc/html/rfc3190 type Decoder struct { BitDepth int SampleRate int diff --git a/pkg/formats/rtplpcm/decoder_test.go b/pkg/formats/rtplpcm/decoder_test.go index e9de58f5..cdb8764c 100644 --- a/pkg/formats/rtplpcm/decoder_test.go +++ b/pkg/formats/rtplpcm/decoder_test.go @@ -54,7 +54,7 @@ func TestDecode(t *testing.T) { } } -func FuzzDecoderUnmarshal(f *testing.F) { +func FuzzDecoder(f *testing.F) { d := &Decoder{ BitDepth: 24, SampleRate: 48000, diff --git a/pkg/formats/rtplpcm/encoder.go b/pkg/formats/rtplpcm/encoder.go index 0a25216d..cc2a6ec4 100644 --- a/pkg/formats/rtplpcm/encoder.go +++ b/pkg/formats/rtplpcm/encoder.go @@ -21,6 +21,7 @@ func randUint32() uint32 { } // Encoder is a RTP/LPCM encoder. +// Specification: https://datatracker.ietf.org/doc/html/rfc3190 type Encoder struct { // payload type of packets. PayloadType uint8 diff --git a/pkg/formats/rtplpcm/testdata/fuzz/FuzzDecoderUnmarshal/582528ddfad69eb57775199a43e0f9fd5c94bba343ce7bb6724d4ebafe311ed4 b/pkg/formats/rtplpcm/testdata/fuzz/FuzzDecoder/582528ddfad69eb57775199a43e0f9fd5c94bba343ce7bb6724d4ebafe311ed4 similarity index 100% rename from pkg/formats/rtplpcm/testdata/fuzz/FuzzDecoderUnmarshal/582528ddfad69eb57775199a43e0f9fd5c94bba343ce7bb6724d4ebafe311ed4 rename to pkg/formats/rtplpcm/testdata/fuzz/FuzzDecoder/582528ddfad69eb57775199a43e0f9fd5c94bba343ce7bb6724d4ebafe311ed4 diff --git a/pkg/formats/rtpmjpeg/decoder.go b/pkg/formats/rtpmjpeg/decoder.go index ee88f94a..4752bf92 100644 --- a/pkg/formats/rtpmjpeg/decoder.go +++ b/pkg/formats/rtpmjpeg/decoder.go @@ -95,6 +95,7 @@ var chmAcSymbols = []byte{ //nolint:dupl } // Decoder is a RTP/M-JPEG decoder. +// Specification: https://datatracker.ietf.org/doc/html/rfc2435 type Decoder struct { timeDecoder *rtptime.Decoder firstPacketReceived bool diff --git a/pkg/formats/rtpmjpeg/decoder_test.go b/pkg/formats/rtpmjpeg/decoder_test.go index 5c50e617..1f4858b1 100644 --- a/pkg/formats/rtpmjpeg/decoder_test.go +++ b/pkg/formats/rtpmjpeg/decoder_test.go @@ -30,7 +30,7 @@ func TestDecode(t *testing.T) { } } -func FuzzDecoderUnmarshal(f *testing.F) { +func FuzzDecoder(f *testing.F) { d := &Decoder{} d.Init() diff --git a/pkg/formats/rtpmjpeg/encoder.go b/pkg/formats/rtpmjpeg/encoder.go index 98f490b0..30153d0e 100644 --- a/pkg/formats/rtpmjpeg/encoder.go +++ b/pkg/formats/rtpmjpeg/encoder.go @@ -24,6 +24,7 @@ func randUint32() uint32 { } // Encoder is a RTP/M-JPEG encoder. +// Specification: https://datatracker.ietf.org/doc/html/rfc2435 type Encoder struct { // SSRC of packets (optional). // It defaults to a random value. diff --git a/pkg/formats/rtpmjpeg/testdata/fuzz/FuzzDecoderUnmarshal/52b2e47791e6e8c660670149d685c83d5fecefd94c322f710147669ef887e099 b/pkg/formats/rtpmjpeg/testdata/fuzz/FuzzDecoder/52b2e47791e6e8c660670149d685c83d5fecefd94c322f710147669ef887e099 similarity index 100% rename from pkg/formats/rtpmjpeg/testdata/fuzz/FuzzDecoderUnmarshal/52b2e47791e6e8c660670149d685c83d5fecefd94c322f710147669ef887e099 rename to pkg/formats/rtpmjpeg/testdata/fuzz/FuzzDecoder/52b2e47791e6e8c660670149d685c83d5fecefd94c322f710147669ef887e099 diff --git a/pkg/formats/rtpmjpeg/testdata/fuzz/FuzzDecoderUnmarshal/76a6865e7bb36d841a943abed143b3403b2d0ffaecdf3298988189c118ee10c1 b/pkg/formats/rtpmjpeg/testdata/fuzz/FuzzDecoder/76a6865e7bb36d841a943abed143b3403b2d0ffaecdf3298988189c118ee10c1 similarity index 100% rename from pkg/formats/rtpmjpeg/testdata/fuzz/FuzzDecoderUnmarshal/76a6865e7bb36d841a943abed143b3403b2d0ffaecdf3298988189c118ee10c1 rename to pkg/formats/rtpmjpeg/testdata/fuzz/FuzzDecoder/76a6865e7bb36d841a943abed143b3403b2d0ffaecdf3298988189c118ee10c1 diff --git a/pkg/formats/rtpmjpeg/testdata/fuzz/FuzzDecoderUnmarshal/bbed53e53be4cad7bab7f568e12dda0590d7c11c0f890b3816ab6eff536ac9fc b/pkg/formats/rtpmjpeg/testdata/fuzz/FuzzDecoder/bbed53e53be4cad7bab7f568e12dda0590d7c11c0f890b3816ab6eff536ac9fc similarity index 100% rename from pkg/formats/rtpmjpeg/testdata/fuzz/FuzzDecoderUnmarshal/bbed53e53be4cad7bab7f568e12dda0590d7c11c0f890b3816ab6eff536ac9fc rename to pkg/formats/rtpmjpeg/testdata/fuzz/FuzzDecoder/bbed53e53be4cad7bab7f568e12dda0590d7c11c0f890b3816ab6eff536ac9fc diff --git a/pkg/formats/rtpmjpeg/testdata/fuzz/FuzzDecoderUnmarshal/be012bfe6e99e126df96e194dc125f8c57860dd62c4244dd7b4e7512cb22a205 b/pkg/formats/rtpmjpeg/testdata/fuzz/FuzzDecoder/be012bfe6e99e126df96e194dc125f8c57860dd62c4244dd7b4e7512cb22a205 similarity index 100% rename from pkg/formats/rtpmjpeg/testdata/fuzz/FuzzDecoderUnmarshal/be012bfe6e99e126df96e194dc125f8c57860dd62c4244dd7b4e7512cb22a205 rename to pkg/formats/rtpmjpeg/testdata/fuzz/FuzzDecoder/be012bfe6e99e126df96e194dc125f8c57860dd62c4244dd7b4e7512cb22a205 diff --git a/pkg/formats/rtpmjpeg/testdata/fuzz/FuzzDecoderUnmarshal/c2ffebd2c319dea9e791ab793c970d84bc212c35134cc2dfb85aa7d862858a49 b/pkg/formats/rtpmjpeg/testdata/fuzz/FuzzDecoder/c2ffebd2c319dea9e791ab793c970d84bc212c35134cc2dfb85aa7d862858a49 similarity index 100% rename from pkg/formats/rtpmjpeg/testdata/fuzz/FuzzDecoderUnmarshal/c2ffebd2c319dea9e791ab793c970d84bc212c35134cc2dfb85aa7d862858a49 rename to pkg/formats/rtpmjpeg/testdata/fuzz/FuzzDecoder/c2ffebd2c319dea9e791ab793c970d84bc212c35134cc2dfb85aa7d862858a49 diff --git a/pkg/formats/rtpmjpeg/testdata/fuzz/FuzzDecoderUnmarshal/fe09b7699690e38a634478835482b418adf4885a063409efe36d0d6120af5eb9 b/pkg/formats/rtpmjpeg/testdata/fuzz/FuzzDecoder/fe09b7699690e38a634478835482b418adf4885a063409efe36d0d6120af5eb9 similarity index 100% rename from pkg/formats/rtpmjpeg/testdata/fuzz/FuzzDecoderUnmarshal/fe09b7699690e38a634478835482b418adf4885a063409efe36d0d6120af5eb9 rename to pkg/formats/rtpmjpeg/testdata/fuzz/FuzzDecoder/fe09b7699690e38a634478835482b418adf4885a063409efe36d0d6120af5eb9 diff --git a/pkg/formats/rtpmpeg2audio/decoder.go b/pkg/formats/rtpmpeg2audio/decoder.go new file mode 100644 index 00000000..d3da4de6 --- /dev/null +++ b/pkg/formats/rtpmpeg2audio/decoder.go @@ -0,0 +1,46 @@ +package rtpmpeg2audio + +import ( + "fmt" + "time" + + "github.com/bluenviron/mediacommon/pkg/codecs/mpeg2audio" + "github.com/pion/rtp" + + "github.com/bluenviron/gortsplib/v3/pkg/rtptime" +) + +// Decoder is a RTP/MPEG2-audio decoder. +// Specification: https://datatracker.ietf.org/doc/html/rfc2250 +type Decoder struct { + timeDecoder *rtptime.Decoder +} + +// Init initializes the decoder. +func (d *Decoder) Init() { + d.timeDecoder = rtptime.NewDecoder(90000) +} + +// Decode decodes frames from a RTP/MPEG2-audio packet. +func (d *Decoder) Decode(pkt *rtp.Packet) ([][]byte, time.Duration, error) { + if len(pkt.Payload) < 5 { + return nil, 0, fmt.Errorf("payload is too short") + } + + mbz := uint16(pkt.Payload[0])<<8 | uint16(pkt.Payload[1]) + if mbz != 0 { + return nil, 0, fmt.Errorf("invalid MBZ: %v", mbz) + } + + offset := uint16(pkt.Payload[2])<<8 | uint16(pkt.Payload[3]) + if offset != 0 { + return nil, 0, fmt.Errorf("fragmented units are not supported") + } + + frames, err := mpeg2audio.SplitFrames(pkt.Payload[4:]) + if err != nil { + return nil, 0, err + } + + return frames, d.timeDecoder.Decode(pkt.Timestamp), nil +} diff --git a/pkg/formats/rtpmpeg2audio/decoder_test.go b/pkg/formats/rtpmpeg2audio/decoder_test.go new file mode 100644 index 00000000..7047da25 --- /dev/null +++ b/pkg/formats/rtpmpeg2audio/decoder_test.go @@ -0,0 +1,39 @@ +package rtpmpeg2audio + +import ( + "testing" + + "github.com/pion/rtp" + "github.com/stretchr/testify/require" +) + +func TestDecode(t *testing.T) { + for _, ca := range cases { + t.Run(ca.name, func(t *testing.T) { + d := &Decoder{} + d.Init() + + frames, _, err := d.Decode(ca.pkt) + require.NoError(t, err) + require.Equal(t, ca.frames, frames) + }) + } +} + +func FuzzDecoder(f *testing.F) { + d := &Decoder{} + d.Init() + + f.Fuzz(func(t *testing.T, b []byte) { + d.Decode(&rtp.Packet{ + Header: rtp.Header{ + Version: 2, + PayloadType: 96, + SequenceNumber: 17645, + Timestamp: 2289527317, + SSRC: 0x9dbb7812, + }, + Payload: b, + }) + }) +} diff --git a/pkg/formats/rtpmpeg2audio/encoder.go b/pkg/formats/rtpmpeg2audio/encoder.go new file mode 100644 index 00000000..9cdf3ca5 --- /dev/null +++ b/pkg/formats/rtpmpeg2audio/encoder.go @@ -0,0 +1,151 @@ +package rtpmpeg2audio + +import ( + "crypto/rand" + "fmt" + "time" + + "github.com/bluenviron/mediacommon/pkg/codecs/mpeg2audio" + "github.com/pion/rtp" + + "github.com/bluenviron/gortsplib/v3/pkg/rtptime" +) + +const ( + rtpVersion = 2 +) + +func randUint32() uint32 { + var b [4]byte + rand.Read(b[:]) + return uint32(b[0])<<24 | uint32(b[1])<<16 | uint32(b[2])<<8 | uint32(b[3]) +} + +func lenAggregated(frames [][]byte, frame []byte) int { + l := 4 + len(frame) + for _, fr := range frames { + l += len(fr) + } + return l +} + +// Encoder is a RTP/MPEG2-audio encoder. +// Specification: https://datatracker.ietf.org/doc/html/rfc2250 +type Encoder struct { + // SSRC of packets (optional). + // It defaults to a random value. + SSRC *uint32 + + // initial sequence number of packets (optional). + // It defaults to a random value. + InitialSequenceNumber *uint16 + + // initial timestamp of packets (optional). + // It defaults to a random value. + InitialTimestamp *uint32 + + // maximum size of packet payloads (optional). + // It defaults to 1460. + PayloadMaxSize int + + sequenceNumber uint16 + timeEncoder *rtptime.Encoder +} + +// Init initializes the encoder. +func (e *Encoder) Init() { + if e.SSRC == nil { + v := randUint32() + e.SSRC = &v + } + if e.InitialSequenceNumber == nil { + v := uint16(randUint32()) + e.InitialSequenceNumber = &v + } + if e.InitialTimestamp == nil { + v := randUint32() + e.InitialTimestamp = &v + } + if e.PayloadMaxSize == 0 { + e.PayloadMaxSize = 1460 // 1500 (UDP MTU) - 20 (IP header) - 8 (UDP header) - 12 (RTP header) + } + + e.sequenceNumber = *e.InitialSequenceNumber + e.timeEncoder = rtptime.NewEncoder(90000, *e.InitialTimestamp) +} + +// Encode encodes frames into RTP/MPEG2-audio packets. +func (e *Encoder) Encode(frames [][]byte, pts time.Duration) ([]*rtp.Packet, error) { + var rets []*rtp.Packet + var batch [][]byte + + for _, frame := range frames { + if len(frame) > e.PayloadMaxSize { + return nil, fmt.Errorf("frame is too big") + } + + if lenAggregated(batch, frame) <= e.PayloadMaxSize { + batch = append(batch, frame) + } else { + // write last batch + if batch != nil { + pkt, err := e.writeBatch(batch, pts) + if err != nil { + return nil, err + } + rets = append(rets, pkt) + + for _, frame := range batch { + var h mpeg2audio.FrameHeader + err := h.Unmarshal(frame) + if err != nil { + return nil, err + } + + pts += time.Duration(h.SampleCount()) * time.Second / time.Duration(h.SampleRate) + } + } + + // initialize new batch + batch = [][]byte{frame} + } + } + + // write last batch + pkt, err := e.writeBatch(batch, pts) + if err != nil { + return nil, err + } + rets = append(rets, pkt) + + return rets, nil +} + +func (e *Encoder) writeBatch(frames [][]byte, pts time.Duration) (*rtp.Packet, error) { + l := 4 + for _, frame := range frames { + l += len(frame) + } + + payload := make([]byte, l) + n := 4 + for _, frame := range frames { + n += copy(payload[n:], frame) + } + + pkt := &rtp.Packet{ + Header: rtp.Header{ + Version: rtpVersion, + PayloadType: 14, + SequenceNumber: e.sequenceNumber, + Timestamp: e.timeEncoder.Encode(pts), + SSRC: *e.SSRC, + Marker: true, + }, + Payload: payload, + } + + e.sequenceNumber++ + + return pkt, nil +} diff --git a/pkg/formats/rtpmpeg2audio/encoder_test.go b/pkg/formats/rtpmpeg2audio/encoder_test.go new file mode 100644 index 00000000..8476d1cf --- /dev/null +++ b/pkg/formats/rtpmpeg2audio/encoder_test.go @@ -0,0 +1,163 @@ +package rtpmpeg2audio + +import ( + "testing" + + "github.com/pion/rtp" + "github.com/stretchr/testify/require" +) + +var cases = []struct { + name string + frames [][]byte + pkt *rtp.Packet +}{ + { + "single", + [][]byte{ + { + 0xff, 0xfb, 0x14, 0x64, 0x00, 0x0f, 0xf0, 0x00, + 0x00, 0x69, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, + 0x0d, 0x20, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, + 0xa4, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x34, + 0x80, 0x00, 0x00, 0x04, 0x4c, 0x41, 0x4d, 0x45, + 0x33, 0x2e, 0x31, 0x30, 0x30, 0x55, 0x55, 0x55, + 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, + 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, + 0x55, 0xc0, 0x65, 0xf4, 0xa0, 0x31, 0x8f, 0xce, + 0x8d, 0x46, 0xfc, 0x8c, 0x73, 0xb9, 0x34, 0x3e, + 0xb5, 0x03, 0x39, 0xc0, 0x04, 0x01, 0x98, 0x44, + 0x38, 0xe0, 0x98, 0x10, 0x9b, 0xa8, 0x0f, 0xa8, + }, + }, + &rtp.Packet{ + Header: rtp.Header{ + Version: 2, + Marker: true, + PayloadType: 14, + SequenceNumber: 17645, + Timestamp: 2289526357, + SSRC: 0x9dbb7812, + }, + Payload: []byte{ + 0x00, 0x00, 0x00, 0x00, + 0xff, 0xfb, 0x14, 0x64, 0x00, 0x0f, 0xf0, 0x00, + 0x00, 0x69, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, + 0x0d, 0x20, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, + 0xa4, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x34, + 0x80, 0x00, 0x00, 0x04, 0x4c, 0x41, 0x4d, 0x45, + 0x33, 0x2e, 0x31, 0x30, 0x30, 0x55, 0x55, 0x55, + 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, + 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, + 0x55, 0xc0, 0x65, 0xf4, 0xa0, 0x31, 0x8f, 0xce, + 0x8d, 0x46, 0xfc, 0x8c, 0x73, 0xb9, 0x34, 0x3e, + 0xb5, 0x03, 0x39, 0xc0, 0x04, 0x01, 0x98, 0x44, + 0x38, 0xe0, 0x98, 0x10, 0x9b, 0xa8, 0x0f, 0xa8, + }, + }, + }, + { + "aggregated", + [][]byte{ + { + 0xff, 0xfb, 0x14, 0x64, 0x00, 0x0f, 0xf0, 0x00, + 0x00, 0x69, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, + 0x0d, 0x20, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, + 0xa4, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x34, + 0x80, 0x00, 0x00, 0x04, 0x4c, 0x41, 0x4d, 0x45, + 0x33, 0x2e, 0x31, 0x30, 0x30, 0x55, 0x55, 0x55, + 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, + 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, + 0x55, 0xc0, 0x65, 0xf4, 0xa0, 0x31, 0x8f, 0xce, + 0x8d, 0x46, 0xfc, 0x8c, 0x73, 0xb9, 0x34, 0x3e, + 0xb5, 0x03, 0x39, 0xc0, 0x04, 0x01, 0x98, 0x44, + 0x38, 0xe0, 0x98, 0x10, 0x9b, 0xa8, 0x0f, 0xa8, + }, + { + 0xff, 0xfb, 0x14, 0x64, 0x1e, 0x0f, 0xf0, 0x00, + 0x00, 0x69, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, + 0x0d, 0x20, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, + 0xa4, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x34, + 0x80, 0x00, 0x00, 0x04, 0xe6, 0x50, 0x10, 0x01, + 0xca, 0x13, 0x94, 0x27, 0x4a, 0x4a, 0x64, 0xce, + 0x07, 0xc2, 0x2f, 0x59, 0xc0, 0x19, 0x04, 0x05, + 0xdf, 0xe7, 0xce, 0x65, 0x24, 0xed, 0xa4, 0xe3, + 0xff, 0xc9, 0x00, 0x00, 0x05, 0x5f, 0x4a, 0x04, + 0x0e, 0xc4, 0x24, 0xfd, 0x5e, 0x4a, 0x35, 0x72, + 0x21, 0x27, 0x31, 0x08, 0x47, 0x18, 0x00, 0x06, + 0xc4, 0x02, 0x72, 0x81, 0x89, 0xc3, 0xe4, 0x0a, + }, + }, + &rtp.Packet{ + Header: rtp.Header{ + Version: 2, + Marker: true, + PayloadType: 14, + SequenceNumber: 17645, + Timestamp: 2289526357, + SSRC: 0x9dbb7812, + }, + Payload: []byte{ + 0x00, 0x00, 0x00, 0x00, + 0xff, 0xfb, 0x14, 0x64, 0x00, 0x0f, 0xf0, 0x00, + 0x00, 0x69, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, + 0x0d, 0x20, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, + 0xa4, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x34, + 0x80, 0x00, 0x00, 0x04, 0x4c, 0x41, 0x4d, 0x45, + 0x33, 0x2e, 0x31, 0x30, 0x30, 0x55, 0x55, 0x55, + 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, + 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, + 0x55, 0xc0, 0x65, 0xf4, 0xa0, 0x31, 0x8f, 0xce, + 0x8d, 0x46, 0xfc, 0x8c, 0x73, 0xb9, 0x34, 0x3e, + 0xb5, 0x03, 0x39, 0xc0, 0x04, 0x01, 0x98, 0x44, + 0x38, 0xe0, 0x98, 0x10, 0x9b, 0xa8, 0x0f, 0xa8, + 0xff, 0xfb, 0x14, 0x64, 0x1e, 0x0f, 0xf0, 0x00, + 0x00, 0x69, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, + 0x0d, 0x20, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, + 0xa4, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x34, + 0x80, 0x00, 0x00, 0x04, 0xe6, 0x50, 0x10, 0x01, + 0xca, 0x13, 0x94, 0x27, 0x4a, 0x4a, 0x64, 0xce, + 0x07, 0xc2, 0x2f, 0x59, 0xc0, 0x19, 0x04, 0x05, + 0xdf, 0xe7, 0xce, 0x65, 0x24, 0xed, 0xa4, 0xe3, + 0xff, 0xc9, 0x00, 0x00, 0x05, 0x5f, 0x4a, 0x04, + 0x0e, 0xc4, 0x24, 0xfd, 0x5e, 0x4a, 0x35, 0x72, + 0x21, 0x27, 0x31, 0x08, 0x47, 0x18, 0x00, 0x06, + 0xc4, 0x02, 0x72, 0x81, 0x89, 0xc3, 0xe4, 0x0a, + }, + }, + }, +} + +func TestEncode(t *testing.T) { + for _, ca := range cases { + t.Run(ca.name, func(t *testing.T) { + e := &Encoder{ + SSRC: func() *uint32 { + v := uint32(0x9dbb7812) + return &v + }(), + InitialSequenceNumber: func() *uint16 { + v := uint16(0x44ed) + return &v + }(), + InitialTimestamp: func() *uint32 { + v := uint32(0x88776655) + return &v + }(), + } + e.Init() + + pkts, err := e.Encode(ca.frames, 0) + require.NoError(t, err) + require.Equal(t, ca.pkt, pkts[0]) + }) + } +} + +func TestEncodeRandomInitialState(t *testing.T) { + e := &Encoder{} + e.Init() + require.NotEqual(t, nil, e.SSRC) + require.NotEqual(t, nil, e.InitialSequenceNumber) + require.NotEqual(t, nil, e.InitialTimestamp) +} diff --git a/pkg/formats/rtpmpeg2audio/rtpmpeg2audio.go b/pkg/formats/rtpmpeg2audio/rtpmpeg2audio.go new file mode 100644 index 00000000..a2082c09 --- /dev/null +++ b/pkg/formats/rtpmpeg2audio/rtpmpeg2audio.go @@ -0,0 +1,2 @@ +// Package rtpmpeg2audio contains a RTP/MPEG2-audio decoder and encoder. +package rtpmpeg2audio diff --git a/pkg/formats/rtpmpeg2audio/testdata/fuzz/FuzzDecoder/582528ddfad69eb5 b/pkg/formats/rtpmpeg2audio/testdata/fuzz/FuzzDecoder/582528ddfad69eb5 new file mode 100644 index 00000000..a96f5599 --- /dev/null +++ b/pkg/formats/rtpmpeg2audio/testdata/fuzz/FuzzDecoder/582528ddfad69eb5 @@ -0,0 +1,2 @@ +go test fuzz v1 +[]byte("0") diff --git a/pkg/formats/rtpmpeg2audio/testdata/fuzz/FuzzDecoder/b456f27416f443a7 b/pkg/formats/rtpmpeg2audio/testdata/fuzz/FuzzDecoder/b456f27416f443a7 new file mode 100644 index 00000000..831db5dd --- /dev/null +++ b/pkg/formats/rtpmpeg2audio/testdata/fuzz/FuzzDecoder/b456f27416f443a7 @@ -0,0 +1,2 @@ +go test fuzz v1 +[]byte("\x00\x00\x00\x000") diff --git a/pkg/formats/rtpmpeg2audio/testdata/fuzz/FuzzDecoder/d92bed38676468bc b/pkg/formats/rtpmpeg2audio/testdata/fuzz/FuzzDecoder/d92bed38676468bc new file mode 100644 index 00000000..bb74629d --- /dev/null +++ b/pkg/formats/rtpmpeg2audio/testdata/fuzz/FuzzDecoder/d92bed38676468bc @@ -0,0 +1,2 @@ +go test fuzz v1 +[]byte("\x00\x00000") diff --git a/pkg/formats/rtpmpeg2audio/testdata/fuzz/FuzzDecoder/f34630c44c11bb13 b/pkg/formats/rtpmpeg2audio/testdata/fuzz/FuzzDecoder/f34630c44c11bb13 new file mode 100644 index 00000000..a389d3c6 --- /dev/null +++ b/pkg/formats/rtpmpeg2audio/testdata/fuzz/FuzzDecoder/f34630c44c11bb13 @@ -0,0 +1,2 @@ +go test fuzz v1 +[]byte("00000") diff --git a/pkg/formats/rtpmpeg4audio/decoder.go b/pkg/formats/rtpmpeg4audio/decoder.go index 61c4422c..427c11a6 100644 --- a/pkg/formats/rtpmpeg4audio/decoder.go +++ b/pkg/formats/rtpmpeg4audio/decoder.go @@ -16,6 +16,7 @@ import ( var ErrMorePacketsNeeded = errors.New("need more packets") // Decoder is a RTP/MPEG4-audio decoder. +// Specification: https://datatracker.ietf.org/doc/html/rfc3640 type Decoder struct { // sample rate of input packets. SampleRate int @@ -73,7 +74,7 @@ func (d *Decoder) Decode(pkt *rtp.Packet) ([][]byte, time.Duration, error) { var aus [][]byte if len(d.fragments) == 0 { - if pkt.Header.Marker { + if pkt.Marker { // AUs aus = make([][]byte, len(dataLens)) for i, dataLen := range dataLens { @@ -117,7 +118,7 @@ func (d *Decoder) Decode(pkt *rtp.Packet) ([][]byte, time.Duration, error) { d.fragments = append(d.fragments, payload[:dataLens[0]]) - if !pkt.Header.Marker { + if !pkt.Marker { return nil, 0, ErrMorePacketsNeeded } diff --git a/pkg/formats/rtpmpeg4audio/decoder_test.go b/pkg/formats/rtpmpeg4audio/decoder_test.go index 36ba3915..54a91271 100644 --- a/pkg/formats/rtpmpeg4audio/decoder_test.go +++ b/pkg/formats/rtpmpeg4audio/decoder_test.go @@ -109,7 +109,7 @@ func TestDecodeADTS(t *testing.T) { } } -func FuzzDecoderUnmarshal(f *testing.F) { +func FuzzDecoder(f *testing.F) { d := &Decoder{ SampleRate: 16000, SizeLength: 13, diff --git a/pkg/formats/rtpmpeg4audio/encoder.go b/pkg/formats/rtpmpeg4audio/encoder.go index a409aafe..a93748f4 100644 --- a/pkg/formats/rtpmpeg4audio/encoder.go +++ b/pkg/formats/rtpmpeg4audio/encoder.go @@ -22,6 +22,7 @@ func randUint32() uint32 { } // Encoder is a RTP/MPEG4-audio encoder. +// Specification: https://datatracker.ietf.org/doc/html/rfc3640 type Encoder struct { // payload type of packets. PayloadType uint8 diff --git a/pkg/formats/rtpmpeg4audio/testdata/fuzz/FuzzDecoderUnmarshal/17b3f3cab1067ee0ee8464bd3f7890cc1a42ed3f47f13ee83ffdc3ddec1879ef b/pkg/formats/rtpmpeg4audio/testdata/fuzz/FuzzDecoder/17b3f3cab1067ee0ee8464bd3f7890cc1a42ed3f47f13ee83ffdc3ddec1879ef similarity index 100% rename from pkg/formats/rtpmpeg4audio/testdata/fuzz/FuzzDecoderUnmarshal/17b3f3cab1067ee0ee8464bd3f7890cc1a42ed3f47f13ee83ffdc3ddec1879ef rename to pkg/formats/rtpmpeg4audio/testdata/fuzz/FuzzDecoder/17b3f3cab1067ee0ee8464bd3f7890cc1a42ed3f47f13ee83ffdc3ddec1879ef diff --git a/pkg/formats/rtpmpeg4audio/testdata/fuzz/FuzzDecoderUnmarshal/17f38ee4db10b1296a5bdbd03e35ab29e7e86c1008f89d4437529302df6ecb59 b/pkg/formats/rtpmpeg4audio/testdata/fuzz/FuzzDecoder/17f38ee4db10b1296a5bdbd03e35ab29e7e86c1008f89d4437529302df6ecb59 similarity index 100% rename from pkg/formats/rtpmpeg4audio/testdata/fuzz/FuzzDecoderUnmarshal/17f38ee4db10b1296a5bdbd03e35ab29e7e86c1008f89d4437529302df6ecb59 rename to pkg/formats/rtpmpeg4audio/testdata/fuzz/FuzzDecoder/17f38ee4db10b1296a5bdbd03e35ab29e7e86c1008f89d4437529302df6ecb59 diff --git a/pkg/formats/rtpmpeg4audio/testdata/fuzz/FuzzDecoderUnmarshal/38d1a2c06720135e2d5accd1afc1f312bc4b6991cd97c1444c86690b4ed6df70 b/pkg/formats/rtpmpeg4audio/testdata/fuzz/FuzzDecoder/38d1a2c06720135e2d5accd1afc1f312bc4b6991cd97c1444c86690b4ed6df70 similarity index 100% rename from pkg/formats/rtpmpeg4audio/testdata/fuzz/FuzzDecoderUnmarshal/38d1a2c06720135e2d5accd1afc1f312bc4b6991cd97c1444c86690b4ed6df70 rename to pkg/formats/rtpmpeg4audio/testdata/fuzz/FuzzDecoder/38d1a2c06720135e2d5accd1afc1f312bc4b6991cd97c1444c86690b4ed6df70 diff --git a/pkg/formats/rtpmpeg4audio/testdata/fuzz/FuzzDecoderUnmarshal/4c3e593e59c1f853f845a7e3c992d1837f63c5052d805c21db6734a64c3ee1e0 b/pkg/formats/rtpmpeg4audio/testdata/fuzz/FuzzDecoder/4c3e593e59c1f853f845a7e3c992d1837f63c5052d805c21db6734a64c3ee1e0 similarity index 100% rename from pkg/formats/rtpmpeg4audio/testdata/fuzz/FuzzDecoderUnmarshal/4c3e593e59c1f853f845a7e3c992d1837f63c5052d805c21db6734a64c3ee1e0 rename to pkg/formats/rtpmpeg4audio/testdata/fuzz/FuzzDecoder/4c3e593e59c1f853f845a7e3c992d1837f63c5052d805c21db6734a64c3ee1e0 diff --git a/pkg/formats/rtpmpeg4audio/testdata/fuzz/FuzzDecoderUnmarshal/52b2e47791e6e8c660670149d685c83d5fecefd94c322f710147669ef887e099 b/pkg/formats/rtpmpeg4audio/testdata/fuzz/FuzzDecoder/52b2e47791e6e8c660670149d685c83d5fecefd94c322f710147669ef887e099 similarity index 100% rename from pkg/formats/rtpmpeg4audio/testdata/fuzz/FuzzDecoderUnmarshal/52b2e47791e6e8c660670149d685c83d5fecefd94c322f710147669ef887e099 rename to pkg/formats/rtpmpeg4audio/testdata/fuzz/FuzzDecoder/52b2e47791e6e8c660670149d685c83d5fecefd94c322f710147669ef887e099 diff --git a/pkg/formats/rtpmpeg4audio/testdata/fuzz/FuzzDecoderUnmarshal/7b9886f07cd0d1b52d80762d475eda9b446e4861160e9a79b294eeb75345ebc5 b/pkg/formats/rtpmpeg4audio/testdata/fuzz/FuzzDecoder/7b9886f07cd0d1b52d80762d475eda9b446e4861160e9a79b294eeb75345ebc5 similarity index 100% rename from pkg/formats/rtpmpeg4audio/testdata/fuzz/FuzzDecoderUnmarshal/7b9886f07cd0d1b52d80762d475eda9b446e4861160e9a79b294eeb75345ebc5 rename to pkg/formats/rtpmpeg4audio/testdata/fuzz/FuzzDecoder/7b9886f07cd0d1b52d80762d475eda9b446e4861160e9a79b294eeb75345ebc5 diff --git a/pkg/formats/rtpmpeg4audio/testdata/fuzz/FuzzDecoderUnmarshal/82ab2d91fd10f5f409473e000b93d979dcea2547839dece510544e4f2243b80b b/pkg/formats/rtpmpeg4audio/testdata/fuzz/FuzzDecoder/82ab2d91fd10f5f409473e000b93d979dcea2547839dece510544e4f2243b80b similarity index 100% rename from pkg/formats/rtpmpeg4audio/testdata/fuzz/FuzzDecoderUnmarshal/82ab2d91fd10f5f409473e000b93d979dcea2547839dece510544e4f2243b80b rename to pkg/formats/rtpmpeg4audio/testdata/fuzz/FuzzDecoder/82ab2d91fd10f5f409473e000b93d979dcea2547839dece510544e4f2243b80b diff --git a/pkg/formats/rtpmpeg4audio/testdata/fuzz/FuzzDecoderUnmarshal/a253c894d4f7ea0c24ff61014f52a33011acd37d246b6e81527f5544c00140b6 b/pkg/formats/rtpmpeg4audio/testdata/fuzz/FuzzDecoder/a253c894d4f7ea0c24ff61014f52a33011acd37d246b6e81527f5544c00140b6 similarity index 100% rename from pkg/formats/rtpmpeg4audio/testdata/fuzz/FuzzDecoderUnmarshal/a253c894d4f7ea0c24ff61014f52a33011acd37d246b6e81527f5544c00140b6 rename to pkg/formats/rtpmpeg4audio/testdata/fuzz/FuzzDecoder/a253c894d4f7ea0c24ff61014f52a33011acd37d246b6e81527f5544c00140b6 diff --git a/pkg/formats/rtpmpeg4audio/testdata/fuzz/FuzzDecoderUnmarshal/a2d4352b624b7e9e5fefbc9881be89bcf82806ed6644dbb3c0914215e484c015 b/pkg/formats/rtpmpeg4audio/testdata/fuzz/FuzzDecoder/a2d4352b624b7e9e5fefbc9881be89bcf82806ed6644dbb3c0914215e484c015 similarity index 100% rename from pkg/formats/rtpmpeg4audio/testdata/fuzz/FuzzDecoderUnmarshal/a2d4352b624b7e9e5fefbc9881be89bcf82806ed6644dbb3c0914215e484c015 rename to pkg/formats/rtpmpeg4audio/testdata/fuzz/FuzzDecoder/a2d4352b624b7e9e5fefbc9881be89bcf82806ed6644dbb3c0914215e484c015 diff --git a/pkg/formats/rtpmpeg4audio/testdata/fuzz/FuzzDecoderUnmarshal/fc47c4c80ffd62dfd9c7adf40b38f9d9fe0bf9466af436b5c3487f2c4b9b90e4 b/pkg/formats/rtpmpeg4audio/testdata/fuzz/FuzzDecoder/fc47c4c80ffd62dfd9c7adf40b38f9d9fe0bf9466af436b5c3487f2c4b9b90e4 similarity index 100% rename from pkg/formats/rtpmpeg4audio/testdata/fuzz/FuzzDecoderUnmarshal/fc47c4c80ffd62dfd9c7adf40b38f9d9fe0bf9466af436b5c3487f2c4b9b90e4 rename to pkg/formats/rtpmpeg4audio/testdata/fuzz/FuzzDecoder/fc47c4c80ffd62dfd9c7adf40b38f9d9fe0bf9466af436b5c3487f2c4b9b90e4 diff --git a/pkg/formats/rtpvp8/decoder.go b/pkg/formats/rtpvp8/decoder.go index 921036ef..2cf69ba2 100644 --- a/pkg/formats/rtpvp8/decoder.go +++ b/pkg/formats/rtpvp8/decoder.go @@ -22,6 +22,7 @@ var ErrNonStartingPacketAndNoPrevious = errors.New( "received a non-starting fragment without any previous starting fragment") // Decoder is a RTP/VP8 decoder. +// Specification: https://datatracker.ietf.org/doc/html/rfc7741 type Decoder struct { timeDecoder *rtptime.Decoder firstPacketReceived bool diff --git a/pkg/formats/rtpvp8/decoder_test.go b/pkg/formats/rtpvp8/decoder_test.go index 0e3d9344..6f2f5c91 100644 --- a/pkg/formats/rtpvp8/decoder_test.go +++ b/pkg/formats/rtpvp8/decoder_test.go @@ -52,7 +52,7 @@ func TestDecode(t *testing.T) { } } -func FuzzDecoderUnmarshal(f *testing.F) { +func FuzzDecoder(f *testing.F) { d := &Decoder{} d.Init() diff --git a/pkg/formats/rtpvp8/encoder.go b/pkg/formats/rtpvp8/encoder.go index 4b7961d7..ba505733 100644 --- a/pkg/formats/rtpvp8/encoder.go +++ b/pkg/formats/rtpvp8/encoder.go @@ -22,6 +22,7 @@ func randUint32() uint32 { } // Encoder is a RTP/VP8 encoder. +// Specification: https://datatracker.ietf.org/doc/html/rfc7741 type Encoder struct { // payload type of packets. PayloadType uint8 diff --git a/pkg/formats/rtpvp8/testdata/fuzz/FuzzDecoderUnmarshal/52b2e47791e6e8c660670149d685c83d5fecefd94c322f710147669ef887e099 b/pkg/formats/rtpvp8/testdata/fuzz/FuzzDecoder/52b2e47791e6e8c660670149d685c83d5fecefd94c322f710147669ef887e099 similarity index 100% rename from pkg/formats/rtpvp8/testdata/fuzz/FuzzDecoderUnmarshal/52b2e47791e6e8c660670149d685c83d5fecefd94c322f710147669ef887e099 rename to pkg/formats/rtpvp8/testdata/fuzz/FuzzDecoder/52b2e47791e6e8c660670149d685c83d5fecefd94c322f710147669ef887e099 diff --git a/pkg/formats/rtpvp8/testdata/fuzz/FuzzDecoderUnmarshal/7a1c68afba07c13a12f3686c52a228b2ca8d9794363a61529fcad02658ea03e3 b/pkg/formats/rtpvp8/testdata/fuzz/FuzzDecoder/7a1c68afba07c13a12f3686c52a228b2ca8d9794363a61529fcad02658ea03e3 similarity index 100% rename from pkg/formats/rtpvp8/testdata/fuzz/FuzzDecoderUnmarshal/7a1c68afba07c13a12f3686c52a228b2ca8d9794363a61529fcad02658ea03e3 rename to pkg/formats/rtpvp8/testdata/fuzz/FuzzDecoder/7a1c68afba07c13a12f3686c52a228b2ca8d9794363a61529fcad02658ea03e3 diff --git a/pkg/formats/rtpvp8/testdata/fuzz/FuzzDecoderUnmarshal/c4c11fb7d7de62a02ee8e7d6962d074d82fa5fdd472096dc3ba35696d1649fa4 b/pkg/formats/rtpvp8/testdata/fuzz/FuzzDecoder/c4c11fb7d7de62a02ee8e7d6962d074d82fa5fdd472096dc3ba35696d1649fa4 similarity index 100% rename from pkg/formats/rtpvp8/testdata/fuzz/FuzzDecoderUnmarshal/c4c11fb7d7de62a02ee8e7d6962d074d82fa5fdd472096dc3ba35696d1649fa4 rename to pkg/formats/rtpvp8/testdata/fuzz/FuzzDecoder/c4c11fb7d7de62a02ee8e7d6962d074d82fa5fdd472096dc3ba35696d1649fa4 diff --git a/pkg/formats/rtpvp9/decoder.go b/pkg/formats/rtpvp9/decoder.go index 45f5dd50..cee7f911 100644 --- a/pkg/formats/rtpvp9/decoder.go +++ b/pkg/formats/rtpvp9/decoder.go @@ -22,6 +22,7 @@ var ErrNonStartingPacketAndNoPrevious = errors.New( "received a non-starting fragment without any previous starting fragment") // Decoder is a RTP/VP9 decoder. +// Specification: https://datatracker.ietf.org/doc/html/draft-ietf-payload-vp9-16 type Decoder struct { timeDecoder *rtptime.Decoder firstPacketReceived bool diff --git a/pkg/formats/rtpvp9/decoder_test.go b/pkg/formats/rtpvp9/decoder_test.go index 5df79345..387fd553 100644 --- a/pkg/formats/rtpvp9/decoder_test.go +++ b/pkg/formats/rtpvp9/decoder_test.go @@ -52,7 +52,7 @@ func TestDecode(t *testing.T) { } } -func FuzzDecoderUnmarshal(f *testing.F) { +func FuzzDecoder(f *testing.F) { d := &Decoder{} d.Init() diff --git a/pkg/formats/rtpvp9/encoder.go b/pkg/formats/rtpvp9/encoder.go index 2de3d7f9..89f143e1 100644 --- a/pkg/formats/rtpvp9/encoder.go +++ b/pkg/formats/rtpvp9/encoder.go @@ -22,6 +22,7 @@ func randUint32() uint32 { } // Encoder is a RTP/VP9 encoder. +// Specification: https://datatracker.ietf.org/doc/html/draft-ietf-payload-vp9-16 type Encoder struct { // payload type of packets. PayloadType uint8 diff --git a/pkg/formats/rtpvp9/testdata/fuzz/FuzzDecoderUnmarshal/a562b457d1a04bb296308020307f2e271491c804e84959ad2d5fdaa2e32b6a0f b/pkg/formats/rtpvp9/testdata/fuzz/FuzzDecoder/a562b457d1a04bb296308020307f2e271491c804e84959ad2d5fdaa2e32b6a0f similarity index 100% rename from pkg/formats/rtpvp9/testdata/fuzz/FuzzDecoderUnmarshal/a562b457d1a04bb296308020307f2e271491c804e84959ad2d5fdaa2e32b6a0f rename to pkg/formats/rtpvp9/testdata/fuzz/FuzzDecoder/a562b457d1a04bb296308020307f2e271491c804e84959ad2d5fdaa2e32b6a0f diff --git a/pkg/formats/rtpvp9/testdata/fuzz/FuzzDecoderUnmarshal/ef9d289981397c05db640a6c59c3451a32320b9343d5fefb3e03f72b36377a6c b/pkg/formats/rtpvp9/testdata/fuzz/FuzzDecoder/ef9d289981397c05db640a6c59c3451a32320b9343d5fefb3e03f72b36377a6c similarity index 100% rename from pkg/formats/rtpvp9/testdata/fuzz/FuzzDecoderUnmarshal/ef9d289981397c05db640a6c59c3451a32320b9343d5fefb3e03f72b36377a6c rename to pkg/formats/rtpvp9/testdata/fuzz/FuzzDecoder/ef9d289981397c05db640a6c59c3451a32320b9343d5fefb3e03f72b36377a6c