diff --git a/pkg/formats/av1.go b/pkg/formats/av1.go index b3697c87..463c0a5c 100644 --- a/pkg/formats/av1.go +++ b/pkg/formats/av1.go @@ -55,9 +55,16 @@ func (f *AV1) unmarshal(payloadType uint8, _ string, _ string, _ string, fmtp ma return nil } +// Codec implements Format. +func (f *AV1) Codec() string { + return "AV1" +} + // String implements Format. +// +// Deprecated: replaced by Codec(). func (f *AV1) String() string { - return "AV1" + return f.Codec() } // ClockRate implements Format. diff --git a/pkg/formats/format.go b/pkg/formats/format.go index de079ec5..d85af70b 100644 --- a/pkg/formats/format.go +++ b/pkg/formats/format.go @@ -17,11 +17,14 @@ func getCodecAndClock(rtpMap string) (string, string) { } // Format is a RTP format of a media. -// It defines a codec and a payload type used to transmit the media. +// It defines a codec and a payload type to transmit the media. type Format interface { unmarshal(payloadType uint8, clock string, codec string, rtpmap string, fmtp map[string]string) error - // String returns a description of the format. + // Codec returns the codec name. + Codec() string + + // Deprecated: replaced by Codec(). String() string // ClockRate returns the clock rate. diff --git a/pkg/formats/g711.go b/pkg/formats/g711.go index b1ef815b..73565f5f 100644 --- a/pkg/formats/g711.go +++ b/pkg/formats/g711.go @@ -18,9 +18,16 @@ func (f *G711) unmarshal(payloadType uint8, _ string, _ string, _ string, _ map[ return nil } +// Codec implements Format. +func (f *G711) Codec() string { + return "G711" +} + // String implements Format. +// +// Deprecated: replaced by Codec(). func (f *G711) String() string { - return "G711" + return f.Codec() } // ClockRate implements Format. diff --git a/pkg/formats/g711_test.go b/pkg/formats/g711_test.go index d7d72d91..cb89e9d4 100644 --- a/pkg/formats/g711_test.go +++ b/pkg/formats/g711_test.go @@ -9,14 +9,14 @@ import ( func TestG711Attributes(t *testing.T) { format := &G711{} - require.Equal(t, "G711", format.String()) + require.Equal(t, "G711", format.Codec()) require.Equal(t, 8000, format.ClockRate()) require.Equal(t, true, format.PTSEqualsDTS(&rtp.Packet{})) format = &G711{ MULaw: true, } - require.Equal(t, "G711", format.String()) + require.Equal(t, "G711", format.Codec()) require.Equal(t, 8000, format.ClockRate()) } diff --git a/pkg/formats/g722.go b/pkg/formats/g722.go index 75fcb000..718c4999 100644 --- a/pkg/formats/g722.go +++ b/pkg/formats/g722.go @@ -14,9 +14,16 @@ func (f *G722) unmarshal(_ uint8, _ string, _ string, _ string, _ map[string]str return nil } +// Codec implements Format. +func (f *G722) Codec() string { + return "G722" +} + // String implements Format. +// +// Deprecated: replaced by Codec(). func (f *G722) String() string { - return "G722" + return f.Codec() } // ClockRate implements Format. diff --git a/pkg/formats/g722_test.go b/pkg/formats/g722_test.go index 8e81729b..d4500007 100644 --- a/pkg/formats/g722_test.go +++ b/pkg/formats/g722_test.go @@ -9,7 +9,7 @@ import ( func TestG722Attributes(t *testing.T) { format := &G722{} - require.Equal(t, "G722", format.String()) + require.Equal(t, "G722", format.Codec()) require.Equal(t, 8000, format.ClockRate()) require.Equal(t, true, format.PTSEqualsDTS(&rtp.Packet{})) } diff --git a/pkg/formats/generic.go b/pkg/formats/generic.go index 820832c7..2f8bb48a 100644 --- a/pkg/formats/generic.go +++ b/pkg/formats/generic.go @@ -75,11 +75,18 @@ func (f *Generic) unmarshal(payloadType uint8, _ string, _ string, rtpmap string return f.Init() } -// String returns a description of the format. -func (f *Generic) String() string { +// Codec implements Format. +func (f *Generic) Codec() string { return "Generic" } +// String implements Format. +// +// Deprecated: replaced by Codec(). +func (f *Generic) String() string { + return f.Codec() +} + // ClockRate implements Format. func (f *Generic) ClockRate() int { return f.ClockRat diff --git a/pkg/formats/generic_test.go b/pkg/formats/generic_test.go index ba316f14..1c727637 100644 --- a/pkg/formats/generic_test.go +++ b/pkg/formats/generic_test.go @@ -21,7 +21,7 @@ func TestGenericAttributes(t *testing.T) { err := format.Init() require.NoError(t, err) - require.Equal(t, "Generic", format.String()) + require.Equal(t, "Generic", format.Codec()) require.Equal(t, 90000, format.ClockRate()) require.Equal(t, true, format.PTSEqualsDTS(&rtp.Packet{})) } diff --git a/pkg/formats/h264.go b/pkg/formats/h264.go index 68ca9324..be697a85 100644 --- a/pkg/formats/h264.go +++ b/pkg/formats/h264.go @@ -116,9 +116,16 @@ func (f *H264) unmarshal(payloadType uint8, _ string, _ string, _ string, fmtp m return nil } +// Codec implements Format. +func (f *H264) Codec() string { + return "H264" +} + // String implements Format. +// +// Deprecated: replaced by Codec(). func (f *H264) String() string { - return "H264" + return f.Codec() } // ClockRate implements Format. diff --git a/pkg/formats/h264_test.go b/pkg/formats/h264_test.go index 5f5c8335..c9a9ced8 100644 --- a/pkg/formats/h264_test.go +++ b/pkg/formats/h264_test.go @@ -14,7 +14,7 @@ func TestH264Attributes(t *testing.T) { PPS: []byte{0x03, 0x04}, PacketizationMode: 1, } - require.Equal(t, "H264", format.String()) + require.Equal(t, "H264", format.Codec()) require.Equal(t, 90000, format.ClockRate()) sps, pps := format.SafeParams() diff --git a/pkg/formats/h265.go b/pkg/formats/h265.go index 667b603c..a8fae8fd 100644 --- a/pkg/formats/h265.go +++ b/pkg/formats/h265.go @@ -61,9 +61,16 @@ func (f *H265) unmarshal(payloadType uint8, _ string, _ string, _ string, fmtp m return nil } +// Codec implements Format. +func (f *H265) Codec() string { + return "H265" +} + // String implements Format. +// +// Deprecated: replaced by Codec(). func (f *H265) String() string { - return "H265" + return f.Codec() } // ClockRate implements Format. diff --git a/pkg/formats/h265_test.go b/pkg/formats/h265_test.go index 9ef1d9c6..ea7ced42 100644 --- a/pkg/formats/h265_test.go +++ b/pkg/formats/h265_test.go @@ -14,7 +14,7 @@ func TestH265Attributes(t *testing.T) { SPS: []byte{0x03, 0x04}, PPS: []byte{0x05, 0x06}, } - require.Equal(t, "H265", format.String()) + require.Equal(t, "H265", format.Codec()) require.Equal(t, 90000, format.ClockRate()) require.Equal(t, true, format.PTSEqualsDTS(&rtp.Packet{})) diff --git a/pkg/formats/lpcm.go b/pkg/formats/lpcm.go index aaab3ab7..2b2f9a6e 100644 --- a/pkg/formats/lpcm.go +++ b/pkg/formats/lpcm.go @@ -53,9 +53,16 @@ func (f *LPCM) unmarshal(payloadType uint8, clock string, codec string, _ string return nil } +// Codec implements Format. +func (f *LPCM) Codec() string { + return "LPCM" +} + // String implements Format. +// +// Deprecated: replaced by Codec(). func (f *LPCM) String() string { - return "LPCM" + return f.Codec() } // ClockRate implements Format. diff --git a/pkg/formats/lpcm_test.go b/pkg/formats/lpcm_test.go index b32e1f0d..0a70be98 100644 --- a/pkg/formats/lpcm_test.go +++ b/pkg/formats/lpcm_test.go @@ -14,7 +14,7 @@ func TestLPCMAttributes(t *testing.T) { SampleRate: 44100, ChannelCount: 2, } - require.Equal(t, "LPCM", format.String()) + require.Equal(t, "LPCM", format.Codec()) require.Equal(t, 44100, format.ClockRate()) require.Equal(t, true, format.PTSEqualsDTS(&rtp.Packet{})) } diff --git a/pkg/formats/mjpeg.go b/pkg/formats/mjpeg.go index 1f7a374d..c6468bb4 100644 --- a/pkg/formats/mjpeg.go +++ b/pkg/formats/mjpeg.go @@ -14,9 +14,16 @@ func (f *MJPEG) unmarshal(_ uint8, _ string, _ string, _ string, _ map[string]st return nil } +// Codec implements Format. +func (f *MJPEG) Codec() string { + return "M-JPEG" +} + // String implements Format. +// +// Deprecated: replaced by Codec(). func (f *MJPEG) String() string { - return "M-JPEG" + return f.Codec() } // ClockRate implements Format. diff --git a/pkg/formats/mjpeg_test.go b/pkg/formats/mjpeg_test.go index a78a06a7..5f44b9a6 100644 --- a/pkg/formats/mjpeg_test.go +++ b/pkg/formats/mjpeg_test.go @@ -9,7 +9,7 @@ import ( func TestMJPEGAttributes(t *testing.T) { format := &MJPEG{} - require.Equal(t, "M-JPEG", format.String()) + require.Equal(t, "M-JPEG", format.Codec()) require.Equal(t, 90000, format.ClockRate()) require.Equal(t, true, format.PTSEqualsDTS(&rtp.Packet{})) } diff --git a/pkg/formats/mpeg2_audio.go b/pkg/formats/mpeg2_audio.go index 3a8e7c87..f5a9da40 100644 --- a/pkg/formats/mpeg2_audio.go +++ b/pkg/formats/mpeg2_audio.go @@ -14,9 +14,16 @@ func (f *MPEG2Audio) unmarshal(_ uint8, _ string, _ string, _ string, _ map[stri return nil } +// Codec implements Format. +func (f *MPEG2Audio) Codec() string { + return "MPEG-1/2 Audio" +} + // String implements Format. +// +// Deprecated: replaced by Codec(). func (f *MPEG2Audio) String() string { - return "MPEG2-audio" + return f.Codec() } // ClockRate implements Format. diff --git a/pkg/formats/mpeg2_audio_test.go b/pkg/formats/mpeg2_audio_test.go index ed45e862..a65710b6 100644 --- a/pkg/formats/mpeg2_audio_test.go +++ b/pkg/formats/mpeg2_audio_test.go @@ -9,7 +9,7 @@ import ( func TestMPEG2AudioAttributes(t *testing.T) { format := &MPEG2Audio{} - require.Equal(t, "MPEG2-audio", format.String()) + require.Equal(t, "MPEG-1/2 Audio", 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 index 0851972c..a589897b 100644 --- a/pkg/formats/mpeg2_video.go +++ b/pkg/formats/mpeg2_video.go @@ -1,4 +1,4 @@ -package formats +package formats //nolint:dupl import ( "github.com/pion/rtp" @@ -12,9 +12,16 @@ func (f *MPEG2Video) unmarshal(_ uint8, _ string, _ string, _ string, _ map[stri 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 "MPEG2-video" + return f.Codec() } // ClockRate implements Format. diff --git a/pkg/formats/mpeg2_video_test.go b/pkg/formats/mpeg2_video_test.go index d9ef1598..2db8a752 100644 --- a/pkg/formats/mpeg2_video_test.go +++ b/pkg/formats/mpeg2_video_test.go @@ -9,7 +9,7 @@ import ( func TestMPEG2VideoAttributes(t *testing.T) { format := &MPEG2Video{} - require.Equal(t, "MPEG2-video", format.String()) + 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/mpeg4_audio_generic.go b/pkg/formats/mpeg4_audio_generic.go index 41c0e48d..95e4f570 100644 --- a/pkg/formats/mpeg4_audio_generic.go +++ b/pkg/formats/mpeg4_audio_generic.go @@ -98,10 +98,16 @@ func (f *MPEG4AudioGeneric) unmarshal( return nil } +// Codec implements Format. +func (f *MPEG4AudioGeneric) Codec() string { + return "MPEG-4 Audio" +} + // String implements Format. +// +// Deprecated: replaced by Codec(). func (f *MPEG4AudioGeneric) String() string { - // currently, String() returns the codec name, hence hide the format name. - return "MPEG4-audio" + return f.Codec() } // ClockRate implements Format. diff --git a/pkg/formats/mpeg4_audio_generic_test.go b/pkg/formats/mpeg4_audio_generic_test.go index f3685668..08de53ad 100644 --- a/pkg/formats/mpeg4_audio_generic_test.go +++ b/pkg/formats/mpeg4_audio_generic_test.go @@ -21,7 +21,7 @@ func TestMPEG4AudioGenericAttributes(t *testing.T) { IndexLength: 3, IndexDeltaLength: 3, } - require.Equal(t, "MPEG4-audio", format.String()) + require.Equal(t, "MPEG-4 Audio", format.Codec()) require.Equal(t, 48000, format.ClockRate()) require.Equal(t, true, format.PTSEqualsDTS(&rtp.Packet{})) } diff --git a/pkg/formats/mpeg4_audio_latm.go b/pkg/formats/mpeg4_audio_latm.go index 742f11a8..aaf04a14 100644 --- a/pkg/formats/mpeg4_audio_latm.go +++ b/pkg/formats/mpeg4_audio_latm.go @@ -85,10 +85,16 @@ func (f *MPEG4AudioLATM) unmarshal( return nil } +// Codec implements Format. +func (f *MPEG4AudioLATM) Codec() string { + return "MPEG-4 Audio" +} + // String implements Format. +// +// Deprecated: replaced by Codec(). func (f *MPEG4AudioLATM) String() string { - // currently, String() returns the codec name, hence hide the format name. - return "MPEG4-audio" + return f.Codec() } // ClockRate implements Format. diff --git a/pkg/formats/mpeg4_audio_latm_test.go b/pkg/formats/mpeg4_audio_latm_test.go index 879cda95..40772a52 100644 --- a/pkg/formats/mpeg4_audio_latm_test.go +++ b/pkg/formats/mpeg4_audio_latm_test.go @@ -25,7 +25,7 @@ func TestMPEG4AudioLATMAttributes(t *testing.T) { }}, }, } - require.Equal(t, "MPEG4-audio", format.String()) + require.Equal(t, "MPEG-4 Audio", format.Codec()) require.Equal(t, 44100, format.ClockRate()) require.Equal(t, true, format.PTSEqualsDTS(&rtp.Packet{})) } diff --git a/pkg/formats/mpeg4_video_es.go b/pkg/formats/mpeg4_video_es.go index ed1faeca..fb69931b 100644 --- a/pkg/formats/mpeg4_video_es.go +++ b/pkg/formats/mpeg4_video_es.go @@ -51,9 +51,16 @@ func (f *MPEG4VideoES) unmarshal( return nil } +// Codec implements Format. +func (f *MPEG4VideoES) Codec() string { + return "MPEG-4 Video" +} + // String implements Format. +// +// Deprecated: replaced by Codec(). func (f *MPEG4VideoES) String() string { - return "MPEG4-video-es" + return f.Codec() } // ClockRate implements Format. diff --git a/pkg/formats/mpeg4_video_es_test.go b/pkg/formats/mpeg4_video_es_test.go index c2cdce2b..8fd0b7ff 100644 --- a/pkg/formats/mpeg4_video_es_test.go +++ b/pkg/formats/mpeg4_video_es_test.go @@ -13,7 +13,7 @@ func TestMPEG4VideoESAttributes(t *testing.T) { ProfileLevelID: 1, Config: []byte{0x01, 0x02, 0x03}, } - require.Equal(t, "MPEG4-video-es", format.String()) + require.Equal(t, "MPEG-4 Video", format.Codec()) require.Equal(t, 90000, format.ClockRate()) require.Equal(t, true, format.PTSEqualsDTS(&rtp.Packet{})) } diff --git a/pkg/formats/mpegts.go b/pkg/formats/mpegts.go index f65d81a7..213df58d 100644 --- a/pkg/formats/mpegts.go +++ b/pkg/formats/mpegts.go @@ -1,4 +1,4 @@ -package formats +package formats //nolint:dupl import ( "github.com/pion/rtp" @@ -12,9 +12,16 @@ func (f *MPEGTS) unmarshal(_ uint8, _ string, _ string, _ string, _ map[string]s return nil } +// Codec implements Format. +func (f *MPEGTS) Codec() string { + return "MPEG-TS" +} + // String implements Format. +// +// Deprecated: replaced by Codec(). func (f *MPEGTS) String() string { - return "MPEG-TS" + return f.Codec() } // ClockRate implements Format. diff --git a/pkg/formats/mpegts_test.go b/pkg/formats/mpegts_test.go index cc39329a..e257cb7f 100644 --- a/pkg/formats/mpegts_test.go +++ b/pkg/formats/mpegts_test.go @@ -9,7 +9,7 @@ import ( func TestMPEGTSAttributes(t *testing.T) { format := &MPEGTS{} - require.Equal(t, "MPEG-TS", format.String()) + require.Equal(t, "MPEG-TS", format.Codec()) require.Equal(t, 90000, format.ClockRate()) require.Equal(t, true, format.PTSEqualsDTS(&rtp.Packet{})) } diff --git a/pkg/formats/opus.go b/pkg/formats/opus.go index 601b2ae0..af4608ce 100644 --- a/pkg/formats/opus.go +++ b/pkg/formats/opus.go @@ -44,9 +44,16 @@ func (f *Opus) unmarshal(payloadType uint8, clock string, _ string, _ string, fm return nil } +// Codec implements Format. +func (f *Opus) Codec() string { + return "Opus" +} + // String implements Format. +// +// Deprecated: replaced by Codec(). func (f *Opus) String() string { - return "Opus" + return f.Codec() } // ClockRate implements Format. diff --git a/pkg/formats/opus_test.go b/pkg/formats/opus_test.go index 4dae72ff..87e52791 100644 --- a/pkg/formats/opus_test.go +++ b/pkg/formats/opus_test.go @@ -12,7 +12,7 @@ func TestOpusAttributes(t *testing.T) { PayloadTyp: 96, IsStereo: true, } - require.Equal(t, "Opus", format.String()) + require.Equal(t, "Opus", format.Codec()) require.Equal(t, 48000, format.ClockRate()) require.Equal(t, true, format.PTSEqualsDTS(&rtp.Packet{})) } diff --git a/pkg/formats/vorbis.go b/pkg/formats/vorbis.go index 4ce35b52..cd69ce5b 100644 --- a/pkg/formats/vorbis.go +++ b/pkg/formats/vorbis.go @@ -56,9 +56,16 @@ func (f *Vorbis) unmarshal(payloadType uint8, clock string, _ string, _ string, return nil } +// Codec implements Format. +func (f *Vorbis) Codec() string { + return "Vorbis" +} + // String implements Format. +// +// Deprecated: replaced by Codec(). func (f *Vorbis) String() string { - return "Vorbis" + return f.Codec() } // ClockRate implements Format. diff --git a/pkg/formats/vorbis_test.go b/pkg/formats/vorbis_test.go index d2f18a2a..3a18cd98 100644 --- a/pkg/formats/vorbis_test.go +++ b/pkg/formats/vorbis_test.go @@ -14,7 +14,7 @@ func TestVorbisAttributes(t *testing.T) { ChannelCount: 2, Configuration: []byte{0x01, 0x02, 0x03, 0x04}, } - require.Equal(t, "Vorbis", format.String()) + require.Equal(t, "Vorbis", format.Codec()) require.Equal(t, 48000, format.ClockRate()) require.Equal(t, true, format.PTSEqualsDTS(&rtp.Packet{})) } diff --git a/pkg/formats/vp8.go b/pkg/formats/vp8.go index 7f05d84f..a2073523 100644 --- a/pkg/formats/vp8.go +++ b/pkg/formats/vp8.go @@ -45,9 +45,16 @@ func (f *VP8) unmarshal(payloadType uint8, _ string, _ string, _ string, fmtp ma return nil } +// Codec implements Format. +func (f *VP8) Codec() string { + return "VP8" +} + // String implements Format. +// +// Deprecated: replaced by Codec(). func (f *VP8) String() string { - return "VP8" + return f.Codec() } // ClockRate implements Format. diff --git a/pkg/formats/vp8_test.go b/pkg/formats/vp8_test.go index 0ad8d45a..e7e4e993 100644 --- a/pkg/formats/vp8_test.go +++ b/pkg/formats/vp8_test.go @@ -11,7 +11,7 @@ func TestVP8ttributes(t *testing.T) { format := &VP8{ PayloadTyp: 99, } - require.Equal(t, "VP8", format.String()) + require.Equal(t, "VP8", format.Codec()) require.Equal(t, 90000, format.ClockRate()) require.Equal(t, true, format.PTSEqualsDTS(&rtp.Packet{})) } diff --git a/pkg/formats/vp9.go b/pkg/formats/vp9.go index 832fd9cc..508117b5 100644 --- a/pkg/formats/vp9.go +++ b/pkg/formats/vp9.go @@ -55,9 +55,16 @@ func (f *VP9) unmarshal(payloadType uint8, _ string, _ string, _ string, fmtp ma return nil } +// Codec implements Format. +func (f *VP9) Codec() string { + return "VP9" +} + // String implements Format. +// +// Deprecated: replaced by Codec(). func (f *VP9) String() string { - return "VP9" + return f.Codec() } // ClockRate implements Format. diff --git a/pkg/formats/vp9_test.go b/pkg/formats/vp9_test.go index 480a9e3a..445ade00 100644 --- a/pkg/formats/vp9_test.go +++ b/pkg/formats/vp9_test.go @@ -11,7 +11,7 @@ func TestVP9Attributes(t *testing.T) { format := &VP9{ PayloadTyp: 100, } - require.Equal(t, "VP9", format.String()) + require.Equal(t, "VP9", format.Codec()) require.Equal(t, 90000, format.ClockRate()) require.Equal(t, true, format.PTSEqualsDTS(&rtp.Packet{})) }