-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
147 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package av1 | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestContainsKeyFrame(t *testing.T) { | ||
for _, ca := range []struct { | ||
name string | ||
byts []byte | ||
}{ | ||
{ | ||
"sequence header", | ||
[]byte{ | ||
0x0a, 0x0e, 0x00, 0x00, 0x00, 0x4a, 0xab, 0xbf, | ||
0xc3, 0x77, 0x6b, 0xe4, 0x40, 0x40, 0x40, 0x41, | ||
}, | ||
}, | ||
} { | ||
t.Run(ca.name, func(t *testing.T) { | ||
ok, err := ContainsKeyFrame([][]byte{ca.byts}) | ||
require.NoError(t, err) | ||
require.Equal(t, true, ok) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// Package opus contains utilities to work with the Opus codec. | ||
package opus |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package opus | ||
|
||
import ( | ||
"time" | ||
) | ||
|
||
var frameSizes = [32]int{ | ||
480, 960, 1920, 2880, // Silk NB | ||
480, 960, 1920, 2880, // Silk MB | ||
480, 960, 1920, 2880, // Silk WB | ||
480, 960, // Hybrid SWB | ||
480, 960, // Hybrid FB | ||
120, 240, 480, 960, // CELT NB | ||
120, 240, 480, 960, // CELT NB | ||
120, 240, 480, 960, // CELT NB | ||
120, 240, 480, 960, // CELT NB | ||
} | ||
|
||
// PacketDuration returns the duration of an Opus packet. | ||
// Specification: RFC6716, 3.1 | ||
func PacketDuration(pkt []byte) time.Duration { | ||
if len(pkt) == 0 { | ||
return 0 | ||
} | ||
|
||
frameDuration := frameSizes[pkt[0]>>3] | ||
|
||
frameCount := 0 | ||
switch pkt[0] & 3 { | ||
case 0: | ||
frameCount = 1 | ||
case 1: | ||
frameCount = 2 | ||
case 2: | ||
frameCount = 2 | ||
case 3: | ||
if len(pkt) < 2 { | ||
return 0 | ||
} | ||
frameCount = int(pkt[1] & 63) | ||
} | ||
|
||
return (time.Duration(frameDuration) * time.Duration(frameCount) * time.Millisecond) / 48 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package opus | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
var casesPacketDuration = []struct { | ||
name string | ||
byts []byte | ||
duration time.Duration | ||
}{ | ||
{ | ||
"aa", | ||
[]byte{1}, | ||
20 * time.Millisecond, | ||
}, | ||
} | ||
|
||
func TestPacketDuration(t *testing.T) { | ||
for _, ca := range casesPacketDuration { | ||
t.Run(ca.name, func(t *testing.T) { | ||
require.Equal(t, ca.duration, PacketDuration(ca.byts)) | ||
}) | ||
} | ||
} | ||
|
||
func FuzzPacketDuration(f *testing.F) { | ||
f.Fuzz(func(t *testing.T, b []byte) { | ||
PacketDuration(b) | ||
}) | ||
} |
2 changes: 2 additions & 0 deletions
2
pkg/codecs/opus/testdata/fuzz/FuzzPacketDuration/2fde656d41007dc7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
go test fuzz v1 | ||
[]byte("2") |
2 changes: 2 additions & 0 deletions
2
pkg/codecs/opus/testdata/fuzz/FuzzPacketDuration/50f595e1cd9aeb89
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
go test fuzz v1 | ||
[]byte("70") |
2 changes: 2 additions & 0 deletions
2
pkg/codecs/opus/testdata/fuzz/FuzzPacketDuration/582528ddfad69eb5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
go test fuzz v1 | ||
[]byte("0") |
2 changes: 2 additions & 0 deletions
2
pkg/codecs/opus/testdata/fuzz/FuzzPacketDuration/916d1b270bc67219
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
go test fuzz v1 | ||
[]byte("1") |
2 changes: 2 additions & 0 deletions
2
pkg/codecs/opus/testdata/fuzz/FuzzPacketDuration/caf81e9797b19c76
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
go test fuzz v1 | ||
[]byte("") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters