-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecoder_constructor_options_test.go
More file actions
89 lines (81 loc) · 3.09 KB
/
Copy pathdecoder_constructor_options_test.go
File metadata and controls
89 lines (81 loc) · 3.09 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
//go:build amd64 || arm64
package ffmpeg
import (
"testing"
"time"
)
func TestMergeProtocolDecoderOptionsPreservesGenericOptions(t *testing.T) {
generic := &DecoderOptions{
Format: "mpegts",
AVOptions: map[string]string{"shared": "generic", "generic": "kept"},
ProbeSizeBytes: 4096,
FormatWhitelist: []string{"mpegts"},
Streams: []MediaType{MediaTypeVideo},
ProgramID: 7,
Hardware: &HWDecoderConfig{Mode: HardwareAccelerationAuto},
}
protocol := &ProtocolOptions{
Timeout: 3 * time.Second,
AVOptions: map[string]string{"shared": "protocol", "protocol": "kept"},
}
got := mergeProtocolDecoderOptions(generic, protocol)
if got == generic {
t.Fatal("merge returned the caller-owned DecoderOptions")
}
if got.Format != generic.Format || got.ProbeSizeBytes != generic.ProbeSizeBytes || got.ProgramID != generic.ProgramID {
t.Fatalf("generic options were not preserved: %#v", got)
}
if len(got.Streams) != 1 || got.Streams[0] != MediaTypeVideo {
t.Fatalf("streams = %v, want video", got.Streams)
}
if got.Hardware == nil || got.Hardware == generic.Hardware {
t.Fatal("hardware decoder config was not preserved as an independent copy")
}
if got.AVOptions["generic"] != "kept" || got.AVOptions["protocol"] != "kept" {
t.Fatalf("merged AVOptions = %#v", got.AVOptions)
}
if got.AVOptions["shared"] != "protocol" {
t.Fatalf("shared option = %q, want protocol", got.AVOptions["shared"])
}
if got.AVOptions["timeout"] != "3000000" || got.AVOptions["stimeout"] != "3000000" {
t.Fatalf("typed timeout options = %#v", got.AVOptions)
}
got.AVOptions["generic"] = "changed"
got.Streams[0] = MediaTypeAudio
if generic.AVOptions["generic"] != "kept" || generic.Streams[0] != MediaTypeVideo {
t.Fatal("merge mutated caller-owned decoder options")
}
}
func TestImageSequenceDecoderOptionsPreservesGenericOptions(t *testing.T) {
generic := &DecoderOptions{
AVOptions: map[string]string{"probesize": "8192", "framerate": "1/1"},
Streams: []MediaType{MediaTypeVideo},
CodecWhitelist: []string{"png"},
Hardware: &HWDecoderConfig{DeviceType: HWDeviceTypeVAAPI},
}
config := ImageSequenceConfig{
Pattern: "frame-%03d.png",
StartNumber: 4,
FrameRate: NewRational(60, 1),
}
got := imageSequenceDecoderOptions(config, generic)
if got.Format != "image2" {
t.Fatalf("format = %q, want image2", got.Format)
}
if got.AVOptions["probesize"] != "8192" {
t.Fatalf("generic AVOptions = %#v", got.AVOptions)
}
if got.AVOptions["pattern_type"] != "sequence" || got.AVOptions["start_number"] != "4" || got.AVOptions["framerate"] != "60/1" {
t.Fatalf("sequence AVOptions = %#v", got.AVOptions)
}
if len(got.CodecWhitelist) != 1 || got.CodecWhitelist[0] != "png" {
t.Fatalf("codec whitelist = %v", got.CodecWhitelist)
}
if got.Hardware == nil || got.Hardware.DeviceType != HWDeviceTypeVAAPI || got.Hardware == generic.Hardware {
t.Fatalf("hardware config = %#v", got.Hardware)
}
got.AVOptions["probesize"] = "changed"
if generic.AVOptions["probesize"] != "8192" {
t.Fatal("sequence options mutated caller-owned decoder options")
}
}