rename Format.String() into Format.Codec() (#307)

This commit is contained in:
Alessandro Ros
2023-06-09 12:42:32 +02:00
committed by GitHub
parent ccf42f49c7
commit 9b4cdbe7ab
36 changed files with 182 additions and 55 deletions

View File

@@ -55,11 +55,18 @@ func (f *AV1) unmarshal(payloadType uint8, _ string, _ string, _ string, fmtp ma
return nil return nil
} }
// String implements Format. // Codec implements Format.
func (f *AV1) String() string { func (f *AV1) Codec() string {
return "AV1" return "AV1"
} }
// String implements Format.
//
// Deprecated: replaced by Codec().
func (f *AV1) String() string {
return f.Codec()
}
// ClockRate implements Format. // ClockRate implements Format.
func (f *AV1) ClockRate() int { func (f *AV1) ClockRate() int {
return 90000 return 90000

View File

@@ -17,11 +17,14 @@ func getCodecAndClock(rtpMap string) (string, string) {
} }
// Format is a RTP format of a media. // 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 { type Format interface {
unmarshal(payloadType uint8, clock string, codec string, rtpmap string, fmtp map[string]string) error 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 String() string
// ClockRate returns the clock rate. // ClockRate returns the clock rate.

View File

@@ -18,11 +18,18 @@ func (f *G711) unmarshal(payloadType uint8, _ string, _ string, _ string, _ map[
return nil return nil
} }
// String implements Format. // Codec implements Format.
func (f *G711) String() string { func (f *G711) Codec() string {
return "G711" return "G711"
} }
// String implements Format.
//
// Deprecated: replaced by Codec().
func (f *G711) String() string {
return f.Codec()
}
// ClockRate implements Format. // ClockRate implements Format.
func (f *G711) ClockRate() int { func (f *G711) ClockRate() int {
return 8000 return 8000

View File

@@ -9,14 +9,14 @@ import (
func TestG711Attributes(t *testing.T) { func TestG711Attributes(t *testing.T) {
format := &G711{} format := &G711{}
require.Equal(t, "G711", format.String()) require.Equal(t, "G711", format.Codec())
require.Equal(t, 8000, format.ClockRate()) require.Equal(t, 8000, format.ClockRate())
require.Equal(t, true, format.PTSEqualsDTS(&rtp.Packet{})) require.Equal(t, true, format.PTSEqualsDTS(&rtp.Packet{}))
format = &G711{ format = &G711{
MULaw: true, MULaw: true,
} }
require.Equal(t, "G711", format.String()) require.Equal(t, "G711", format.Codec())
require.Equal(t, 8000, format.ClockRate()) require.Equal(t, 8000, format.ClockRate())
} }

View File

@@ -14,11 +14,18 @@ func (f *G722) unmarshal(_ uint8, _ string, _ string, _ string, _ map[string]str
return nil return nil
} }
// String implements Format. // Codec implements Format.
func (f *G722) String() string { func (f *G722) Codec() string {
return "G722" return "G722"
} }
// String implements Format.
//
// Deprecated: replaced by Codec().
func (f *G722) String() string {
return f.Codec()
}
// ClockRate implements Format. // ClockRate implements Format.
func (f *G722) ClockRate() int { func (f *G722) ClockRate() int {
return 8000 return 8000

View File

@@ -9,7 +9,7 @@ import (
func TestG722Attributes(t *testing.T) { func TestG722Attributes(t *testing.T) {
format := &G722{} format := &G722{}
require.Equal(t, "G722", format.String()) require.Equal(t, "G722", format.Codec())
require.Equal(t, 8000, format.ClockRate()) require.Equal(t, 8000, format.ClockRate())
require.Equal(t, true, format.PTSEqualsDTS(&rtp.Packet{})) require.Equal(t, true, format.PTSEqualsDTS(&rtp.Packet{}))
} }

View File

@@ -75,11 +75,18 @@ func (f *Generic) unmarshal(payloadType uint8, _ string, _ string, rtpmap string
return f.Init() return f.Init()
} }
// String returns a description of the format. // Codec implements Format.
func (f *Generic) String() string { func (f *Generic) Codec() string {
return "Generic" return "Generic"
} }
// String implements Format.
//
// Deprecated: replaced by Codec().
func (f *Generic) String() string {
return f.Codec()
}
// ClockRate implements Format. // ClockRate implements Format.
func (f *Generic) ClockRate() int { func (f *Generic) ClockRate() int {
return f.ClockRat return f.ClockRat

View File

@@ -21,7 +21,7 @@ func TestGenericAttributes(t *testing.T) {
err := format.Init() err := format.Init()
require.NoError(t, err) 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, 90000, format.ClockRate())
require.Equal(t, true, format.PTSEqualsDTS(&rtp.Packet{})) require.Equal(t, true, format.PTSEqualsDTS(&rtp.Packet{}))
} }

View File

@@ -116,11 +116,18 @@ func (f *H264) unmarshal(payloadType uint8, _ string, _ string, _ string, fmtp m
return nil return nil
} }
// String implements Format. // Codec implements Format.
func (f *H264) String() string { func (f *H264) Codec() string {
return "H264" return "H264"
} }
// String implements Format.
//
// Deprecated: replaced by Codec().
func (f *H264) String() string {
return f.Codec()
}
// ClockRate implements Format. // ClockRate implements Format.
func (f *H264) ClockRate() int { func (f *H264) ClockRate() int {
return 90000 return 90000

View File

@@ -14,7 +14,7 @@ func TestH264Attributes(t *testing.T) {
PPS: []byte{0x03, 0x04}, PPS: []byte{0x03, 0x04},
PacketizationMode: 1, PacketizationMode: 1,
} }
require.Equal(t, "H264", format.String()) require.Equal(t, "H264", format.Codec())
require.Equal(t, 90000, format.ClockRate()) require.Equal(t, 90000, format.ClockRate())
sps, pps := format.SafeParams() sps, pps := format.SafeParams()

View File

@@ -61,11 +61,18 @@ func (f *H265) unmarshal(payloadType uint8, _ string, _ string, _ string, fmtp m
return nil return nil
} }
// String implements Format. // Codec implements Format.
func (f *H265) String() string { func (f *H265) Codec() string {
return "H265" return "H265"
} }
// String implements Format.
//
// Deprecated: replaced by Codec().
func (f *H265) String() string {
return f.Codec()
}
// ClockRate implements Format. // ClockRate implements Format.
func (f *H265) ClockRate() int { func (f *H265) ClockRate() int {
return 90000 return 90000

View File

@@ -14,7 +14,7 @@ func TestH265Attributes(t *testing.T) {
SPS: []byte{0x03, 0x04}, SPS: []byte{0x03, 0x04},
PPS: []byte{0x05, 0x06}, 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, 90000, format.ClockRate())
require.Equal(t, true, format.PTSEqualsDTS(&rtp.Packet{})) require.Equal(t, true, format.PTSEqualsDTS(&rtp.Packet{}))

View File

@@ -53,11 +53,18 @@ func (f *LPCM) unmarshal(payloadType uint8, clock string, codec string, _ string
return nil return nil
} }
// String implements Format. // Codec implements Format.
func (f *LPCM) String() string { func (f *LPCM) Codec() string {
return "LPCM" return "LPCM"
} }
// String implements Format.
//
// Deprecated: replaced by Codec().
func (f *LPCM) String() string {
return f.Codec()
}
// ClockRate implements Format. // ClockRate implements Format.
func (f *LPCM) ClockRate() int { func (f *LPCM) ClockRate() int {
return f.SampleRate return f.SampleRate

View File

@@ -14,7 +14,7 @@ func TestLPCMAttributes(t *testing.T) {
SampleRate: 44100, SampleRate: 44100,
ChannelCount: 2, ChannelCount: 2,
} }
require.Equal(t, "LPCM", format.String()) require.Equal(t, "LPCM", format.Codec())
require.Equal(t, 44100, format.ClockRate()) require.Equal(t, 44100, format.ClockRate())
require.Equal(t, true, format.PTSEqualsDTS(&rtp.Packet{})) require.Equal(t, true, format.PTSEqualsDTS(&rtp.Packet{}))
} }

View File

@@ -14,11 +14,18 @@ func (f *MJPEG) unmarshal(_ uint8, _ string, _ string, _ string, _ map[string]st
return nil return nil
} }
// String implements Format. // Codec implements Format.
func (f *MJPEG) String() string { func (f *MJPEG) Codec() string {
return "M-JPEG" return "M-JPEG"
} }
// String implements Format.
//
// Deprecated: replaced by Codec().
func (f *MJPEG) String() string {
return f.Codec()
}
// ClockRate implements Format. // ClockRate implements Format.
func (f *MJPEG) ClockRate() int { func (f *MJPEG) ClockRate() int {
return 90000 return 90000

View File

@@ -9,7 +9,7 @@ import (
func TestMJPEGAttributes(t *testing.T) { func TestMJPEGAttributes(t *testing.T) {
format := &MJPEG{} 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, 90000, format.ClockRate())
require.Equal(t, true, format.PTSEqualsDTS(&rtp.Packet{})) require.Equal(t, true, format.PTSEqualsDTS(&rtp.Packet{}))
} }

View File

@@ -14,9 +14,16 @@ func (f *MPEG2Audio) unmarshal(_ uint8, _ string, _ string, _ string, _ map[stri
return nil return nil
} }
// Codec implements Format.
func (f *MPEG2Audio) Codec() string {
return "MPEG-1/2 Audio"
}
// String implements Format. // String implements Format.
//
// Deprecated: replaced by Codec().
func (f *MPEG2Audio) String() string { func (f *MPEG2Audio) String() string {
return "MPEG2-audio" return f.Codec()
} }
// ClockRate implements Format. // ClockRate implements Format.

View File

@@ -9,7 +9,7 @@ import (
func TestMPEG2AudioAttributes(t *testing.T) { func TestMPEG2AudioAttributes(t *testing.T) {
format := &MPEG2Audio{} 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, 90000, format.ClockRate())
require.Equal(t, true, format.PTSEqualsDTS(&rtp.Packet{})) require.Equal(t, true, format.PTSEqualsDTS(&rtp.Packet{}))
} }

View File

@@ -1,4 +1,4 @@
package formats package formats //nolint:dupl
import ( import (
"github.com/pion/rtp" "github.com/pion/rtp"
@@ -12,9 +12,16 @@ func (f *MPEG2Video) unmarshal(_ uint8, _ string, _ string, _ string, _ map[stri
return nil return nil
} }
// Codec implements Format.
func (f *MPEG2Video) Codec() string {
return "MPEG-1/2 Video"
}
// String implements Format. // String implements Format.
//
// Deprecated: replaced by Codec().
func (f *MPEG2Video) String() string { func (f *MPEG2Video) String() string {
return "MPEG2-video" return f.Codec()
} }
// ClockRate implements Format. // ClockRate implements Format.

View File

@@ -9,7 +9,7 @@ import (
func TestMPEG2VideoAttributes(t *testing.T) { func TestMPEG2VideoAttributes(t *testing.T) {
format := &MPEG2Video{} 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, 90000, format.ClockRate())
require.Equal(t, true, format.PTSEqualsDTS(&rtp.Packet{})) require.Equal(t, true, format.PTSEqualsDTS(&rtp.Packet{}))
} }

View File

@@ -98,10 +98,16 @@ func (f *MPEG4AudioGeneric) unmarshal(
return nil return nil
} }
// Codec implements Format.
func (f *MPEG4AudioGeneric) Codec() string {
return "MPEG-4 Audio"
}
// String implements Format. // String implements Format.
//
// Deprecated: replaced by Codec().
func (f *MPEG4AudioGeneric) String() string { func (f *MPEG4AudioGeneric) String() string {
// currently, String() returns the codec name, hence hide the format name. return f.Codec()
return "MPEG4-audio"
} }
// ClockRate implements Format. // ClockRate implements Format.

View File

@@ -21,7 +21,7 @@ func TestMPEG4AudioGenericAttributes(t *testing.T) {
IndexLength: 3, IndexLength: 3,
IndexDeltaLength: 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, 48000, format.ClockRate())
require.Equal(t, true, format.PTSEqualsDTS(&rtp.Packet{})) require.Equal(t, true, format.PTSEqualsDTS(&rtp.Packet{}))
} }

View File

@@ -85,10 +85,16 @@ func (f *MPEG4AudioLATM) unmarshal(
return nil return nil
} }
// Codec implements Format.
func (f *MPEG4AudioLATM) Codec() string {
return "MPEG-4 Audio"
}
// String implements Format. // String implements Format.
//
// Deprecated: replaced by Codec().
func (f *MPEG4AudioLATM) String() string { func (f *MPEG4AudioLATM) String() string {
// currently, String() returns the codec name, hence hide the format name. return f.Codec()
return "MPEG4-audio"
} }
// ClockRate implements Format. // ClockRate implements Format.

View File

@@ -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, 44100, format.ClockRate())
require.Equal(t, true, format.PTSEqualsDTS(&rtp.Packet{})) require.Equal(t, true, format.PTSEqualsDTS(&rtp.Packet{}))
} }

View File

@@ -51,9 +51,16 @@ func (f *MPEG4VideoES) unmarshal(
return nil return nil
} }
// Codec implements Format.
func (f *MPEG4VideoES) Codec() string {
return "MPEG-4 Video"
}
// String implements Format. // String implements Format.
//
// Deprecated: replaced by Codec().
func (f *MPEG4VideoES) String() string { func (f *MPEG4VideoES) String() string {
return "MPEG4-video-es" return f.Codec()
} }
// ClockRate implements Format. // ClockRate implements Format.

View File

@@ -13,7 +13,7 @@ func TestMPEG4VideoESAttributes(t *testing.T) {
ProfileLevelID: 1, ProfileLevelID: 1,
Config: []byte{0x01, 0x02, 0x03}, 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, 90000, format.ClockRate())
require.Equal(t, true, format.PTSEqualsDTS(&rtp.Packet{})) require.Equal(t, true, format.PTSEqualsDTS(&rtp.Packet{}))
} }

View File

@@ -1,4 +1,4 @@
package formats package formats //nolint:dupl
import ( import (
"github.com/pion/rtp" "github.com/pion/rtp"
@@ -12,11 +12,18 @@ func (f *MPEGTS) unmarshal(_ uint8, _ string, _ string, _ string, _ map[string]s
return nil return nil
} }
// String implements Format. // Codec implements Format.
func (f *MPEGTS) String() string { func (f *MPEGTS) Codec() string {
return "MPEG-TS" return "MPEG-TS"
} }
// String implements Format.
//
// Deprecated: replaced by Codec().
func (f *MPEGTS) String() string {
return f.Codec()
}
// ClockRate implements Format. // ClockRate implements Format.
func (f *MPEGTS) ClockRate() int { func (f *MPEGTS) ClockRate() int {
return 90000 return 90000

View File

@@ -9,7 +9,7 @@ import (
func TestMPEGTSAttributes(t *testing.T) { func TestMPEGTSAttributes(t *testing.T) {
format := &MPEGTS{} 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, 90000, format.ClockRate())
require.Equal(t, true, format.PTSEqualsDTS(&rtp.Packet{})) require.Equal(t, true, format.PTSEqualsDTS(&rtp.Packet{}))
} }

View File

@@ -44,11 +44,18 @@ func (f *Opus) unmarshal(payloadType uint8, clock string, _ string, _ string, fm
return nil return nil
} }
// String implements Format. // Codec implements Format.
func (f *Opus) String() string { func (f *Opus) Codec() string {
return "Opus" return "Opus"
} }
// String implements Format.
//
// Deprecated: replaced by Codec().
func (f *Opus) String() string {
return f.Codec()
}
// ClockRate implements Format. // ClockRate implements Format.
func (f *Opus) ClockRate() int { func (f *Opus) ClockRate() int {
// RFC7587: the RTP timestamp is incremented with a 48000 Hz // RFC7587: the RTP timestamp is incremented with a 48000 Hz

View File

@@ -12,7 +12,7 @@ func TestOpusAttributes(t *testing.T) {
PayloadTyp: 96, PayloadTyp: 96,
IsStereo: true, IsStereo: true,
} }
require.Equal(t, "Opus", format.String()) require.Equal(t, "Opus", format.Codec())
require.Equal(t, 48000, format.ClockRate()) require.Equal(t, 48000, format.ClockRate())
require.Equal(t, true, format.PTSEqualsDTS(&rtp.Packet{})) require.Equal(t, true, format.PTSEqualsDTS(&rtp.Packet{}))
} }

View File

@@ -56,11 +56,18 @@ func (f *Vorbis) unmarshal(payloadType uint8, clock string, _ string, _ string,
return nil return nil
} }
// String implements Format. // Codec implements Format.
func (f *Vorbis) String() string { func (f *Vorbis) Codec() string {
return "Vorbis" return "Vorbis"
} }
// String implements Format.
//
// Deprecated: replaced by Codec().
func (f *Vorbis) String() string {
return f.Codec()
}
// ClockRate implements Format. // ClockRate implements Format.
func (f *Vorbis) ClockRate() int { func (f *Vorbis) ClockRate() int {
return f.SampleRate return f.SampleRate

View File

@@ -14,7 +14,7 @@ func TestVorbisAttributes(t *testing.T) {
ChannelCount: 2, ChannelCount: 2,
Configuration: []byte{0x01, 0x02, 0x03, 0x04}, 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, 48000, format.ClockRate())
require.Equal(t, true, format.PTSEqualsDTS(&rtp.Packet{})) require.Equal(t, true, format.PTSEqualsDTS(&rtp.Packet{}))
} }

View File

@@ -45,11 +45,18 @@ func (f *VP8) unmarshal(payloadType uint8, _ string, _ string, _ string, fmtp ma
return nil return nil
} }
// String implements Format. // Codec implements Format.
func (f *VP8) String() string { func (f *VP8) Codec() string {
return "VP8" return "VP8"
} }
// String implements Format.
//
// Deprecated: replaced by Codec().
func (f *VP8) String() string {
return f.Codec()
}
// ClockRate implements Format. // ClockRate implements Format.
func (f *VP8) ClockRate() int { func (f *VP8) ClockRate() int {
return 90000 return 90000

View File

@@ -11,7 +11,7 @@ func TestVP8ttributes(t *testing.T) {
format := &VP8{ format := &VP8{
PayloadTyp: 99, PayloadTyp: 99,
} }
require.Equal(t, "VP8", format.String()) require.Equal(t, "VP8", format.Codec())
require.Equal(t, 90000, format.ClockRate()) require.Equal(t, 90000, format.ClockRate())
require.Equal(t, true, format.PTSEqualsDTS(&rtp.Packet{})) require.Equal(t, true, format.PTSEqualsDTS(&rtp.Packet{}))
} }

View File

@@ -55,11 +55,18 @@ func (f *VP9) unmarshal(payloadType uint8, _ string, _ string, _ string, fmtp ma
return nil return nil
} }
// String implements Format. // Codec implements Format.
func (f *VP9) String() string { func (f *VP9) Codec() string {
return "VP9" return "VP9"
} }
// String implements Format.
//
// Deprecated: replaced by Codec().
func (f *VP9) String() string {
return f.Codec()
}
// ClockRate implements Format. // ClockRate implements Format.
func (f *VP9) ClockRate() int { func (f *VP9) ClockRate() int {
return 90000 return 90000

View File

@@ -11,7 +11,7 @@ func TestVP9Attributes(t *testing.T) {
format := &VP9{ format := &VP9{
PayloadTyp: 100, PayloadTyp: 100,
} }
require.Equal(t, "VP9", format.String()) require.Equal(t, "VP9", format.Codec())
require.Equal(t, 90000, format.ClockRate()) require.Equal(t, 90000, format.ClockRate())
require.Equal(t, true, format.PTSEqualsDTS(&rtp.Packet{})) require.Equal(t, true, format.PTSEqualsDTS(&rtp.Packet{}))
} }