Skip to content

Commit

Permalink
fix ClockRate() of G711 16khz tracks (#511)
Browse files Browse the repository at this point in the history
  • Loading branch information
aler9 authored Jan 26, 2024
1 parent 2f13007 commit 0b6dda6
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 23 deletions.
2 changes: 1 addition & 1 deletion pkg/format/g711.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (f *G711) Codec() string {

// ClockRate implements Format.
func (f *G711) ClockRate() int {
return 8000
return f.SampleRate
}

// PayloadType implements Format.
Expand Down
64 changes: 42 additions & 22 deletions pkg/format/g711_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,48 @@ import (
)

func TestG711Attributes(t *testing.T) {
t.Run("pcma", func(t *testing.T) {
format := &G711{
PayloadTyp: 8,
MULaw: false,
SampleRate: 8000,
ChannelCount: 1,
}
require.Equal(t, "G711", format.Codec())
require.Equal(t, 8000, format.ClockRate())
require.Equal(t, true, format.PTSEqualsDTS(&rtp.Packet{}))
})

t.Run("pcmu", func(t *testing.T) {
format := &G711{
PayloadTyp: 0,
MULaw: true,
SampleRate: 8000,
ChannelCount: 1,
}
require.Equal(t, "G711", format.Codec())
require.Equal(t, 8000, format.ClockRate())
})
for _, ca := range []struct {
name string
format *G711
clockRate int
}{
{
"pcma 8khz",
&G711{
PayloadTyp: 8,
MULaw: false,
SampleRate: 8000,
ChannelCount: 1,
},
8000,
},
{
"pcmu 8khz",
&G711{
PayloadTyp: 0,
MULaw: true,
SampleRate: 8000,
ChannelCount: 1,
},
8000,
},
{
"pcma 16khz",
&G711{
PayloadTyp: 96,
MULaw: true,
SampleRate: 16000,
ChannelCount: 1,
},
16000,
},
} {
t.Run(ca.name, func(t *testing.T) {
require.Equal(t, "G711", ca.format.Codec())
require.Equal(t, ca.clockRate, ca.format.ClockRate())
require.Equal(t, true, ca.format.PTSEqualsDTS(&rtp.Packet{}))
})
}
}

func TestG711DecEncoder(t *testing.T) {
Expand Down

0 comments on commit 0b6dda6

Please sign in to comment.