diff --git a/README.md b/README.md index 9534a540..147dfdd6 100644 --- a/README.md +++ b/README.md @@ -108,7 +108,7 @@ In RTSP, media streams are routed between server and clients by using RTP packet |H265||[link](https://pkg.go.dev/github.com/bluenviron/gortsplib/v3/pkg/formats#H265)|:heavy_check_mark:| |H264||[link](https://pkg.go.dev/github.com/bluenviron/gortsplib/v3/pkg/formats#H264)|:heavy_check_mark:| |MPEG-4 Video (H263, Xvid)||[link](https://pkg.go.dev/github.com/bluenviron/gortsplib/v3/pkg/formats#MPEG4VideoES)|:heavy_check_mark:| -|MPEG-2 Video||[link](https://pkg.go.dev/github.com/bluenviron/gortsplib/v3/pkg/formats#MPEG2Video)|| +|MPEG-1/2 Video||[link](https://pkg.go.dev/github.com/bluenviron/gortsplib/v3/pkg/formats#MPEG1Video)|| |M-JPEG||[link](https://pkg.go.dev/github.com/bluenviron/gortsplib/v3/pkg/formats#MJPEG)|:heavy_check_mark:| ### Audio @@ -119,7 +119,7 @@ In RTSP, media streams are routed between server and clients by using RTP packet |Vorbis||[link](https://pkg.go.dev/github.com/bluenviron/gortsplib/v3/pkg/formats#Vorbis)|| |MPEG-4 Audio (AAC)|Generic (RFC3640)|[link](https://pkg.go.dev/github.com/bluenviron/gortsplib/v3/pkg/formats#MPEG4AudioGeneric)|:heavy_check_mark:| |MPEG-4 Audio (AAC)|LATM (RFC6416)|[link](https://pkg.go.dev/github.com/bluenviron/gortsplib/v3/pkg/formats#MPEG4AudioLATM)|:heavy_check_mark:| -|MPEG-1/2 Audio (MP3)||[link](https://pkg.go.dev/github.com/bluenviron/gortsplib/v3/pkg/formats#MPEG2Audio)|:heavy_check_mark:| +|MPEG-1/2 Audio (MP3)||[link](https://pkg.go.dev/github.com/bluenviron/gortsplib/v3/pkg/formats#MPEG1Audio)|:heavy_check_mark:| |G726||[link](https://pkg.go.dev/github.com/bluenviron/gortsplib/v3/pkg/formats#G726)|| |G722||[link](https://pkg.go.dev/github.com/bluenviron/gortsplib/v3/pkg/formats#G722)|:heavy_check_mark:| |G711 (PCMA, PCMU)||[link](https://pkg.go.dev/github.com/bluenviron/gortsplib/v3/pkg/formats#G711)|:heavy_check_mark:| diff --git a/pkg/formats/format.go b/pkg/formats/format.go index 5df22a70..62d430c3 100644 --- a/pkg/formats/format.go +++ b/pkg/formats/format.go @@ -55,7 +55,7 @@ func Unmarshal(mediaType string, payloadType uint8, rtpMap string, fmtp map[stri return &MJPEG{} case payloadType == 32: - return &MPEG2Video{} + return &MPEG1Video{} case payloadType == 33: return &MPEGTS{} @@ -98,7 +98,7 @@ func Unmarshal(mediaType string, payloadType uint8, rtpMap string, fmtp map[stri return &G726{} case payloadType == 14: - return &MPEG2Audio{} + return &MPEG1Audio{} case codec == "l8", codec == "l16", codec == "l24": return &LPCM{} diff --git a/pkg/formats/format_test.go b/pkg/formats/format_test.go index 602d1825..7c6ca23d 100644 --- a/pkg/formats/format_test.go +++ b/pkg/formats/format_test.go @@ -190,7 +190,7 @@ var casesFormat = []struct { 14, "", nil, - &MPEG2Audio{}, + &MPEG1Audio{}, "", nil, }, @@ -573,12 +573,12 @@ var casesFormat = []struct { nil, }, { - "video mpeg2 video", + "video mpeg1 video", "video", 32, "", nil, - &MPEG2Video{}, + &MPEG1Video{}, "", nil, }, diff --git a/pkg/formats/mpeg2_audio.go b/pkg/formats/mpeg1_audio.go similarity index 58% rename from pkg/formats/mpeg2_audio.go rename to pkg/formats/mpeg1_audio.go index 62b3577d..55a9fcb1 100644 --- a/pkg/formats/mpeg2_audio.go +++ b/pkg/formats/mpeg1_audio.go @@ -3,65 +3,65 @@ package formats //nolint:dupl import ( "github.com/pion/rtp" - "github.com/bluenviron/gortsplib/v3/pkg/formats/rtpmpeg2audio" + "github.com/bluenviron/gortsplib/v3/pkg/formats/rtpmpeg1audio" ) -// MPEG2Audio is a RTP format for a MPEG-1/2 Audio codec. +// MPEG1Audio is a RTP format for a MPEG-1/2 Audio codec. // Specification: https://datatracker.ietf.org/doc/html/rfc2250 -type MPEG2Audio struct{} +type MPEG1Audio struct{} -func (f *MPEG2Audio) unmarshal(_ uint8, _ string, _ string, _ string, _ map[string]string) error { +func (f *MPEG1Audio) unmarshal(_ uint8, _ string, _ string, _ string, _ map[string]string) error { return nil } // Codec implements Format. -func (f *MPEG2Audio) Codec() string { +func (f *MPEG1Audio) Codec() string { return "MPEG-1/2 Audio" } // String implements Format. // // Deprecated: replaced by Codec(). -func (f *MPEG2Audio) String() string { +func (f *MPEG1Audio) String() string { return f.Codec() } // ClockRate implements Format. -func (f *MPEG2Audio) ClockRate() int { +func (f *MPEG1Audio) ClockRate() int { return 90000 } // PayloadType implements Format. -func (f *MPEG2Audio) PayloadType() uint8 { +func (f *MPEG1Audio) PayloadType() uint8 { return 14 } // RTPMap implements Format. -func (f *MPEG2Audio) RTPMap() string { +func (f *MPEG1Audio) RTPMap() string { return "" } // FMTP implements Format. -func (f *MPEG2Audio) FMTP() map[string]string { +func (f *MPEG1Audio) FMTP() map[string]string { return nil } // PTSEqualsDTS implements Format. -func (f *MPEG2Audio) PTSEqualsDTS(*rtp.Packet) bool { +func (f *MPEG1Audio) PTSEqualsDTS(*rtp.Packet) bool { return true } // CreateDecoder creates a decoder able to decode the content of the format. // // Deprecated: this has been replaced by CreateDecoder2() that can also return an error. -func (f *MPEG2Audio) CreateDecoder() *rtpmpeg2audio.Decoder { +func (f *MPEG1Audio) CreateDecoder() *rtpmpeg1audio.Decoder { d, _ := f.CreateDecoder2() return d } // CreateDecoder2 creates a decoder able to decode the content of the format. -func (f *MPEG2Audio) CreateDecoder2() (*rtpmpeg2audio.Decoder, error) { - d := &rtpmpeg2audio.Decoder{} +func (f *MPEG1Audio) CreateDecoder2() (*rtpmpeg1audio.Decoder, error) { + d := &rtpmpeg1audio.Decoder{} err := d.Init() if err != nil { @@ -74,14 +74,14 @@ func (f *MPEG2Audio) CreateDecoder2() (*rtpmpeg2audio.Decoder, error) { // CreateEncoder creates an encoder able to encode the content of the format. // // Deprecated: this has been replaced by CreateEncoder2() that can also return an error. -func (f *MPEG2Audio) CreateEncoder() *rtpmpeg2audio.Encoder { +func (f *MPEG1Audio) CreateEncoder() *rtpmpeg1audio.Encoder { e, _ := f.CreateEncoder2() return e } // CreateEncoder2 creates an encoder able to encode the content of the format. -func (f *MPEG2Audio) CreateEncoder2() (*rtpmpeg2audio.Encoder, error) { - e := &rtpmpeg2audio.Encoder{} +func (f *MPEG1Audio) CreateEncoder2() (*rtpmpeg1audio.Encoder, error) { + e := &rtpmpeg1audio.Encoder{} err := e.Init() if err != nil { @@ -90,3 +90,8 @@ func (f *MPEG2Audio) CreateEncoder2() (*rtpmpeg2audio.Encoder, error) { return e, nil } + +// MPEG2Audio is an alias for MPEG1Audio. +// +// Deprecated: replaced by MPEG1Audio. +type MPEG2Audio = MPEG1Audio diff --git a/pkg/formats/mpeg2_audio_test.go b/pkg/formats/mpeg1_audio_test.go similarity index 92% rename from pkg/formats/mpeg2_audio_test.go rename to pkg/formats/mpeg1_audio_test.go index a65710b6..e165805c 100644 --- a/pkg/formats/mpeg2_audio_test.go +++ b/pkg/formats/mpeg1_audio_test.go @@ -7,15 +7,15 @@ import ( "github.com/stretchr/testify/require" ) -func TestMPEG2AudioAttributes(t *testing.T) { - format := &MPEG2Audio{} +func TestMPEG1AudioAttributes(t *testing.T) { + format := &MPEG1Audio{} require.Equal(t, "MPEG-1/2 Audio", format.Codec()) require.Equal(t, 90000, format.ClockRate()) require.Equal(t, true, format.PTSEqualsDTS(&rtp.Packet{})) } -func TestMPEG2AudioDecEncoder(t *testing.T) { - format := &MPEG2Audio{} +func TestMPEG1AudioDecEncoder(t *testing.T) { + format := &MPEG1Audio{} enc, err := format.CreateEncoder2() require.NoError(t, err) diff --git a/pkg/formats/mpeg1_video.go b/pkg/formats/mpeg1_video.go new file mode 100644 index 00000000..2c43c9cc --- /dev/null +++ b/pkg/formats/mpeg1_video.go @@ -0,0 +1,55 @@ +package formats //nolint:dupl + +import ( + "github.com/pion/rtp" +) + +// MPEG1Video is a RTP format for a MPEG-1/2 Video codec. +// Specification: https://datatracker.ietf.org/doc/html/rfc2250 +type MPEG1Video struct{} + +func (f *MPEG1Video) unmarshal(_ uint8, _ string, _ string, _ string, _ map[string]string) error { + return nil +} + +// Codec implements Format. +func (f *MPEG1Video) Codec() string { + return "MPEG-1/2 Video" +} + +// String implements Format. +// +// Deprecated: replaced by Codec(). +func (f *MPEG1Video) String() string { + return f.Codec() +} + +// ClockRate implements Format. +func (f *MPEG1Video) ClockRate() int { + return 90000 +} + +// PayloadType implements Format. +func (f *MPEG1Video) PayloadType() uint8 { + return 32 +} + +// RTPMap implements Format. +func (f *MPEG1Video) RTPMap() string { + return "" +} + +// FMTP implements Format. +func (f *MPEG1Video) FMTP() map[string]string { + return nil +} + +// PTSEqualsDTS implements Format. +func (f *MPEG1Video) PTSEqualsDTS(*rtp.Packet) bool { + return true +} + +// MPEG2Video is an alias for MPEG1Video. +// +// Deprecated: replaced by MPEG1Video. +type MPEG2Video = MPEG1Video diff --git a/pkg/formats/mpeg2_video_test.go b/pkg/formats/mpeg1_video_test.go similarity index 78% rename from pkg/formats/mpeg2_video_test.go rename to pkg/formats/mpeg1_video_test.go index 2db8a752..ee85fbbf 100644 --- a/pkg/formats/mpeg2_video_test.go +++ b/pkg/formats/mpeg1_video_test.go @@ -7,8 +7,8 @@ import ( "github.com/stretchr/testify/require" ) -func TestMPEG2VideoAttributes(t *testing.T) { - format := &MPEG2Video{} +func TestMPEG1VideoAttributes(t *testing.T) { + format := &MPEG1Video{} require.Equal(t, "MPEG-1/2 Video", format.Codec()) require.Equal(t, 90000, format.ClockRate()) require.Equal(t, true, format.PTSEqualsDTS(&rtp.Packet{})) diff --git a/pkg/formats/mpeg2_video.go b/pkg/formats/mpeg2_video.go deleted file mode 100644 index 0353d097..00000000 --- a/pkg/formats/mpeg2_video.go +++ /dev/null @@ -1,50 +0,0 @@ -package formats //nolint:dupl - -import ( - "github.com/pion/rtp" -) - -// MPEG2Video is a RTP format for a MPEG-1/2 Video codec. -// Specification: https://datatracker.ietf.org/doc/html/rfc2250 -type MPEG2Video struct{} - -func (f *MPEG2Video) unmarshal(_ uint8, _ string, _ string, _ string, _ map[string]string) error { - return nil -} - -// Codec implements Format. -func (f *MPEG2Video) Codec() string { - return "MPEG-1/2 Video" -} - -// String implements Format. -// -// Deprecated: replaced by Codec(). -func (f *MPEG2Video) String() string { - return f.Codec() -} - -// ClockRate implements Format. -func (f *MPEG2Video) ClockRate() int { - return 90000 -} - -// PayloadType implements Format. -func (f *MPEG2Video) PayloadType() uint8 { - return 32 -} - -// RTPMap implements Format. -func (f *MPEG2Video) RTPMap() string { - return "" -} - -// FMTP implements Format. -func (f *MPEG2Video) FMTP() map[string]string { - return nil -} - -// PTSEqualsDTS implements Format. -func (f *MPEG2Video) PTSEqualsDTS(*rtp.Packet) bool { - return true -} diff --git a/pkg/formats/rtpmpeg2audio/decoder.go b/pkg/formats/rtpmpeg1audio/decoder.go similarity index 99% rename from pkg/formats/rtpmpeg2audio/decoder.go rename to pkg/formats/rtpmpeg1audio/decoder.go index d76f2f66..359f750c 100644 --- a/pkg/formats/rtpmpeg2audio/decoder.go +++ b/pkg/formats/rtpmpeg1audio/decoder.go @@ -1,4 +1,4 @@ -package rtpmpeg2audio +package rtpmpeg1audio import ( "errors" diff --git a/pkg/formats/rtpmpeg2audio/decoder_test.go b/pkg/formats/rtpmpeg1audio/decoder_test.go similarity index 97% rename from pkg/formats/rtpmpeg2audio/decoder_test.go rename to pkg/formats/rtpmpeg1audio/decoder_test.go index 3c259cb3..68d86a04 100644 --- a/pkg/formats/rtpmpeg2audio/decoder_test.go +++ b/pkg/formats/rtpmpeg1audio/decoder_test.go @@ -1,4 +1,4 @@ -package rtpmpeg2audio +package rtpmpeg1audio import ( "testing" diff --git a/pkg/formats/rtpmpeg2audio/encoder.go b/pkg/formats/rtpmpeg1audio/encoder.go similarity index 99% rename from pkg/formats/rtpmpeg2audio/encoder.go rename to pkg/formats/rtpmpeg1audio/encoder.go index f136f3fc..b00fc3c1 100644 --- a/pkg/formats/rtpmpeg2audio/encoder.go +++ b/pkg/formats/rtpmpeg1audio/encoder.go @@ -1,4 +1,4 @@ -package rtpmpeg2audio +package rtpmpeg1audio import ( "crypto/rand" diff --git a/pkg/formats/rtpmpeg2audio/encoder_test.go b/pkg/formats/rtpmpeg1audio/encoder_test.go similarity index 99% rename from pkg/formats/rtpmpeg2audio/encoder_test.go rename to pkg/formats/rtpmpeg1audio/encoder_test.go index e8e1c6f5..eb5fe935 100644 --- a/pkg/formats/rtpmpeg2audio/encoder_test.go +++ b/pkg/formats/rtpmpeg1audio/encoder_test.go @@ -1,4 +1,4 @@ -package rtpmpeg2audio +package rtpmpeg1audio import ( "testing" diff --git a/pkg/formats/rtpmpeg1audio/rtpmpeg1audio.go b/pkg/formats/rtpmpeg1audio/rtpmpeg1audio.go new file mode 100644 index 00000000..dbc87fc3 --- /dev/null +++ b/pkg/formats/rtpmpeg1audio/rtpmpeg1audio.go @@ -0,0 +1,2 @@ +// Package rtpmpeg1audio contains a RTP/MPEG-1/2 Audio decoder and encoder. +package rtpmpeg1audio diff --git a/pkg/formats/rtpmpeg2audio/testdata/fuzz/FuzzDecoder/035c6218e0188ec4 b/pkg/formats/rtpmpeg1audio/testdata/fuzz/FuzzDecoder/035c6218e0188ec4 similarity index 100% rename from pkg/formats/rtpmpeg2audio/testdata/fuzz/FuzzDecoder/035c6218e0188ec4 rename to pkg/formats/rtpmpeg1audio/testdata/fuzz/FuzzDecoder/035c6218e0188ec4 diff --git a/pkg/formats/rtpmpeg2audio/testdata/fuzz/FuzzDecoder/0d51e18d32a6771a b/pkg/formats/rtpmpeg1audio/testdata/fuzz/FuzzDecoder/0d51e18d32a6771a similarity index 100% rename from pkg/formats/rtpmpeg2audio/testdata/fuzz/FuzzDecoder/0d51e18d32a6771a rename to pkg/formats/rtpmpeg1audio/testdata/fuzz/FuzzDecoder/0d51e18d32a6771a diff --git a/pkg/formats/rtpmpeg2audio/testdata/fuzz/FuzzDecoder/2dcc1140d95305bd b/pkg/formats/rtpmpeg1audio/testdata/fuzz/FuzzDecoder/2dcc1140d95305bd similarity index 100% rename from pkg/formats/rtpmpeg2audio/testdata/fuzz/FuzzDecoder/2dcc1140d95305bd rename to pkg/formats/rtpmpeg1audio/testdata/fuzz/FuzzDecoder/2dcc1140d95305bd diff --git a/pkg/formats/rtpmpeg2audio/testdata/fuzz/FuzzDecoder/30bd4b8733a5f13f b/pkg/formats/rtpmpeg1audio/testdata/fuzz/FuzzDecoder/30bd4b8733a5f13f similarity index 100% rename from pkg/formats/rtpmpeg2audio/testdata/fuzz/FuzzDecoder/30bd4b8733a5f13f rename to pkg/formats/rtpmpeg1audio/testdata/fuzz/FuzzDecoder/30bd4b8733a5f13f diff --git a/pkg/formats/rtpmpeg2audio/testdata/fuzz/FuzzDecoder/c1623732f13f642e b/pkg/formats/rtpmpeg1audio/testdata/fuzz/FuzzDecoder/c1623732f13f642e similarity index 100% rename from pkg/formats/rtpmpeg2audio/testdata/fuzz/FuzzDecoder/c1623732f13f642e rename to pkg/formats/rtpmpeg1audio/testdata/fuzz/FuzzDecoder/c1623732f13f642e diff --git a/pkg/formats/rtpmpeg2audio/testdata/fuzz/FuzzDecoder/cf7295b77ea49fed b/pkg/formats/rtpmpeg1audio/testdata/fuzz/FuzzDecoder/cf7295b77ea49fed similarity index 100% rename from pkg/formats/rtpmpeg2audio/testdata/fuzz/FuzzDecoder/cf7295b77ea49fed rename to pkg/formats/rtpmpeg1audio/testdata/fuzz/FuzzDecoder/cf7295b77ea49fed diff --git a/pkg/formats/rtpmpeg2audio/rtpmpeg2audio.go b/pkg/formats/rtpmpeg2audio/rtpmpeg2audio.go index 6984395b..551b833a 100644 --- a/pkg/formats/rtpmpeg2audio/rtpmpeg2audio.go +++ b/pkg/formats/rtpmpeg2audio/rtpmpeg2audio.go @@ -1,2 +1,26 @@ // Package rtpmpeg2audio contains a RTP/MPEG-1/2 Audio decoder and encoder. package rtpmpeg2audio + +import ( + "github.com/bluenviron/gortsplib/v3/pkg/formats/rtpmpeg1audio" +) + +// ErrMorePacketsNeeded is an alis for rtpmpeg1audio.ErrMorePacketsNeeded. +// +// Deprecated: replaced by rtpmpeg1audio.ErrMorePacketsNeeded. +var ErrMorePacketsNeeded = rtpmpeg1audio.ErrMorePacketsNeeded + +// ErrNonStartingPacketAndNoPrevious is an alis for rtpmpeg1audio.ErrNonStartingPacketAndNoPrevious. +// +// Deprecated: replaced by rtpmpeg1audio.ErrNonStartingPacketAndNoPrevious. +var ErrNonStartingPacketAndNoPrevious = rtpmpeg1audio.ErrNonStartingPacketAndNoPrevious + +// Decoder is an alis for rtpmpeg1audio.Decoder. +// +// Deprecated: replaced by rtpmpeg1audio.Decoder. +type Decoder = rtpmpeg1audio.Decoder + +// Encoder is an alis for rtpmpeg1audio.Encoder. +// +// Deprecated: replaced by rtpmpeg1audio.Encoder. +type Encoder = rtpmpeg1audio.Encoder