-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathsource_test.go
62 lines (50 loc) · 1.15 KB
/
source_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
package unix
import (
"bufio"
"net"
"testing"
"time"
"github.com/bluenviron/mediacommon/v2/pkg/formats/mpegts"
"github.com/stretchr/testify/require"
"github.com/bluenviron/mediamtx/internal/conf"
"github.com/bluenviron/mediamtx/internal/defs"
"github.com/bluenviron/mediamtx/internal/test"
)
func TestSource(t *testing.T) {
te := test.NewSourceTester(
func(p defs.StaticSourceParent) defs.StaticSource {
return &Source{
ReadTimeout: conf.Duration(10 * time.Second),
Parent: p,
}
},
"unix:/tmp/mediamtx-test.sock",
&conf.Path{},
)
defer te.Close()
time.Sleep(50 * time.Millisecond)
conn, err := net.Dial("unix", "/tmp/mediamtx-test.sock")
require.NoError(t, err)
defer conn.Close()
track := &mpegts.Track{
Codec: &mpegts.CodecH264{},
}
bw := bufio.NewWriter(conn)
w := &mpegts.Writer{
W: bw,
Tracks: []*mpegts.Track{track},
}
err = w.Initialize()
require.NoError(t, err)
err = w.WriteH264(track, 0, 0, [][]byte{{ // IDR
5, 1,
}})
require.NoError(t, err)
err = w.WriteH264(track, 0, 0, [][]byte{{ // non-IDR
5, 2,
}})
require.NoError(t, err)
err = bw.Flush()
require.NoError(t, err)
<-te.Unit
}