-
Notifications
You must be signed in to change notification settings - Fork 0
/
opus_stream_test.go
73 lines (59 loc) · 1.93 KB
/
opus_stream_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package avmuxer
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestNewDecodingOpusStream(t *testing.T) {
stream, err := NewDecodingOpusStream("stream1", 48000, 20, 2)
assert.NoError(t, err)
assert.NotNil(t, stream)
assert.Equal(t, 48000, stream.SampleRate())
assert.Equal(t, 2, stream.ChannelCount())
assert.Equal(t, 20, stream.SampleDurationMs())
assert.Equal(t, 960, stream.SampleCount()) // sampleDuration * sampleRate / 1000
}
func TestNewEncodingOpusStream(t *testing.T) {
stream, err := NewEncodingOpusStream("stream1", 48000, 20, 2)
assert.NoError(t, err)
assert.NotNil(t, stream)
assert.Equal(t, 48000, stream.SampleRate())
assert.Equal(t, 2, stream.ChannelCount())
assert.Equal(t, 20, stream.SampleDurationMs())
assert.Equal(t, 960, stream.SampleCount()) // sampleDuration * sampleRate / 1000
}
func TestDecodingStream_Write(t *testing.T) {
stream, err := NewDecodingOpusStream("stream1", 48000, 20, 2)
assert.NoError(t, err)
assert.NotNil(t, stream)
encodedData := make([]byte, 960)
n, err := stream.Write(encodedData)
assert.NoError(t, err)
assert.Equal(t, len(encodedData), n)
}
func TestEncodingStream_WritePCM(t *testing.T) {
stream, err := NewEncodingOpusStream("stream1", 48000, 20, 2)
assert.NoError(t, err)
assert.NotNil(t, stream)
pcmData := make([]int16, 960) // Example PCM data
n, err := stream.WritePCM(pcmData)
assert.NoError(t, err)
assert.Equal(t, 960, n)
}
func TestDecodingStream_ReadPCM(t *testing.T) {
stream, err := NewDecodingOpusStream("stream1", 48000, 20, 2)
assert.NoError(t, err)
assert.NotNil(t, stream)
dst := make([]int16, 960)
n, err := stream.ReadPCM(dst)
assert.NoError(t, err)
assert.Equal(t, 960, n)
}
func TestEncodingStream_Read(t *testing.T) {
stream, err := NewEncodingOpusStream("stream1", 48000, 20, 2)
assert.NoError(t, err)
assert.NotNil(t, stream)
dst := make([]byte, 4096)
n, err := stream.Read(dst)
assert.NoError(t, err)
assert.True(t, n > 0)
}