-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecode_select_contract_test.go
More file actions
100 lines (90 loc) · 2.64 KB
/
Copy pathdecode_select_contract_test.go
File metadata and controls
100 lines (90 loc) · 2.64 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package goav
import (
"context"
"reflect"
"testing"
"github.com/thesyncim/goav/av"
"github.com/thesyncim/goav/codec"
"github.com/thesyncim/goav/pipeline"
)
type closeDecodeStateRecorder struct {
closed bool
}
func (r *closeDecodeStateRecorder) Close() {
r.closed = true
}
func TestCloseDecodeStateContract(t *testing.T) {
closeDecodeState(nil)
closeDecodeState(struct{}{})
state := &closeDecodeStateRecorder{}
closeDecodeState(state)
if !state.closed {
t.Fatal("decode state was not closed")
}
}
func TestDecodeStreamWithSpecMergesExternalCodecMetadata(t *testing.T) {
stream := av.Stream{
ID: "incoming",
Codec: av.CodecParameters{
ID: av.CodecID("x-source"),
ClockRate: 44100,
SampleRate: 44100,
Channels: 1,
},
}
if got := decodeStreamWithSpec(stream, codec.Spec{}); !reflect.DeepEqual(got, stream) {
t.Fatalf("empty spec changed stream: got %+v want %+v", got, stream)
}
got := decodeStreamWithSpec(stream, codec.Spec{
ID: av.CodecID("x-external"),
Type: av.MediaAudio,
Parameters: av.CodecParameters{
ClockRate: 48000,
SampleRate: 48000,
Channels: 2,
ChannelLayout: "stereo",
Attributes: av.Metadata{"profile": "external"},
},
})
if got.Type != av.MediaAudio {
t.Fatalf("stream type = %q, want audio", got.Type)
}
if got.Codec.ID != av.CodecID("x-external") || got.Codec.Type != av.MediaAudio {
t.Fatalf("codec identity = %+v, want external audio", got.Codec)
}
if got.Codec.ClockRate != 48000 || got.Codec.SampleRate != 48000 || got.Codec.Channels != 2 || got.Codec.ChannelLayout != "stereo" {
t.Fatalf("codec parameters = %+v, want 48kHz stereo", got.Codec)
}
if got.Codec.Attributes["profile"] != "external" {
t.Fatalf("codec attributes = %+v, want external profile", got.Codec.Attributes)
}
if got.TimeBase != (av.TimeBase{Num: 1, Den: 48000}) {
t.Fatalf("time base = %+v, want 1/48000", got.TimeBase)
}
}
func TestSelectBranchesBuildsPlannedBranchFanout(t *testing.T) {
ctx := context.Background()
var got [][]int16
job := Select(
From(selectTestOneShotSource("a", 100)).Audio(),
From(selectTestOneShotSource("b", 200)).Audio(),
).Branches(
Branch("monitor").To(Sink(SinkFunc("monitor", func(_ context.Context, msg Message) error {
if msg.Kind == pipeline.MessageFrame && msg.Frame != nil && msg.Frame.Audio != nil {
got = append(got, mixTestReadS16(msg.Frame))
}
return nil
}))),
)
task, err := job.Build(ctx)
if err != nil {
t.Fatal(err)
}
defer task.Close()
if err := task.Run(ctx); err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(got, [][]int16{{100}}) {
t.Fatalf("monitor frames = %v, want selected default arm", got)
}
}