-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathvideo2ascii_stream_test.go
More file actions
58 lines (54 loc) 路 1.43 KB
/
Copy pathvideo2ascii_stream_test.go
File metadata and controls
58 lines (54 loc) 路 1.43 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
package convert2ascii
import (
"context"
"errors"
"testing"
"time"
)
// streamTestVideo is the repo asset at the repo-root test/assets directory.
const streamTestVideo = "test/assets/fireworks.mp4"
// TestGeneratePlayStreamsWithoutTempFile verifies the live play path wires up a
// real-time audio stream (no temp WAV, no full-track wait), produces frames,
// and shuts both pipelines down cleanly on cancel.
func TestGeneratePlayStreamsWithoutTempFile(t *testing.T) {
v := NewVideo2Ascii(VideoOptions{URI: streamTestVideo, Width: 40})
if err := v.Generate(); err != nil {
t.Fatal(err)
}
defer func() {
if v.cancel != nil {
v.cancel()
<-v.playerErrCh // video pipeline stops
if v.audioErrCh != nil {
select {
case err := <-v.audioErrCh:
if err != nil && !errors.Is(err, context.Canceled) {
t.Errorf("audio stream ended: %v", err)
}
default:
// audio decode observes cancel and exits
}
}
}
}()
if v.audioStream == nil {
t.Fatal("play mode should have a live audio stream")
}
if v.audioPath != "" {
t.Fatalf("play mode must not create a temp wav, got %q", v.audioPath)
}
if v.framesCh == nil {
t.Fatal("frames channel missing")
}
// the pipeline is actually producing frames
for i := 0; i < 3; i++ {
select {
case f, ok := <-v.framesCh:
if !ok || f == "" {
t.Fatal("bad frame from stream")
}
case <-time.After(5 * time.Second):
t.Fatal("no frame within 5s")
}
}
}