Skip to content

Commit

Permalink
rename Format.String() into Format.Codec() (#307)
Browse files Browse the repository at this point in the history
  • Loading branch information
aler9 committed Jun 9, 2023
1 parent ccf42f4 commit 9b4cdbe
Show file tree
Hide file tree
Showing 36 changed files with 170 additions and 43 deletions.
9 changes: 8 additions & 1 deletion pkg/formats/av1.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 5 additions & 2 deletions pkg/formats/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 8 additions & 1 deletion pkg/formats/g711.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions pkg/formats/g711_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}

Expand Down
9 changes: 8 additions & 1 deletion pkg/formats/g722.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion pkg/formats/g722_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}))
}
Expand Down
11 changes: 9 additions & 2 deletions pkg/formats/generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/formats/generic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}))
}
9 changes: 8 additions & 1 deletion pkg/formats/h264.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion pkg/formats/h264_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
9 changes: 8 additions & 1 deletion pkg/formats/h265.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion pkg/formats/h265_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}))

Expand Down
9 changes: 8 additions & 1 deletion pkg/formats/lpcm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion pkg/formats/lpcm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}))
}
Expand Down
9 changes: 8 additions & 1 deletion pkg/formats/mjpeg.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion pkg/formats/mjpeg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}))
}
Expand Down
9 changes: 8 additions & 1 deletion pkg/formats/mpeg2_audio.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion pkg/formats/mpeg2_audio_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}))
}
Expand Down
11 changes: 9 additions & 2 deletions pkg/formats/mpeg2_video.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package formats
package formats //nolint:dupl

import (
"github.com/pion/rtp"
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion pkg/formats/mpeg2_video_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}))
}
10 changes: 8 additions & 2 deletions pkg/formats/mpeg4_audio_generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion pkg/formats/mpeg4_audio_generic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}))
}
Expand Down
10 changes: 8 additions & 2 deletions pkg/formats/mpeg4_audio_latm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion pkg/formats/mpeg4_audio_latm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}))
}
Expand Down
9 changes: 8 additions & 1 deletion pkg/formats/mpeg4_video_es.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion pkg/formats/mpeg4_video_es_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}))
}
Expand Down
Loading

0 comments on commit 9b4cdbe

Please sign in to comment.