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
}
// String implements Format.
func (f *AV1) String() string {
// Codec implements Format.
func (f *AV1) Codec() string {
return "AV1"
}
// String implements Format.
//
// Deprecated: replaced by Codec().
func (f *AV1) String() string {
return f.Codec()
}
// ClockRate implements Format.
func (f *AV1) ClockRate() int {
return 90000

View File

@@ -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.

View File

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

View File

@@ -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())
}

View File

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

View File

@@ -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{}))
}

View File

@@ -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

View File

@@ -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{}))
}

View File

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

View File

@@ -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()

View File

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

View File

@@ -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{}))

View File

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

View File

@@ -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{}))
}

View File

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

View File

@@ -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{}))
}

View File

@@ -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.

View File

@@ -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{}))
}

View File

@@ -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.

View File

@@ -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{}))
}

View File

@@ -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.

View File

@@ -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{}))
}

View File

@@ -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.

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, true, format.PTSEqualsDTS(&rtp.Packet{}))
}

View File

@@ -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.

View File

@@ -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{}))
}

View File

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

View File

@@ -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{}))
}

View File

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

View File

@@ -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{}))
}

View File

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

View File

@@ -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{}))
}

View File

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

View File

@@ -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{}))
}

View File

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

View File

@@ -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{}))
}