Live video on the AT Protocol
1package media
2
3import (
4 "bytes"
5 "context"
6 "fmt"
7 "io"
8 "os"
9 "testing"
10
11 "github.com/stretchr/testify/require"
12 "golang.org/x/sync/errgroup"
13 "stream.place/streamplace/test/remote"
14)
15
16func TestThumbnail(t *testing.T) {
17 withNoGSTLeaks(t, func() {
18 // Open input file
19 inputFile, err := os.Open(getFixture("sample-segment.mp4"))
20 require.NoError(t, err)
21 defer inputFile.Close()
22 bs, err := io.ReadAll(inputFile)
23 require.NoError(t, err)
24
25 ctx := context.Background()
26 g, ctx := errgroup.WithContext(ctx)
27
28 for i := 0; i < streamplaceTestCount; i++ {
29 g.Go(func() error {
30 thumbnail := bytes.Buffer{}
31 // thumbnailCtx = log.WithDebugValue(ctx, map[string]map[string]int{"function": {"Thumbnail": 9}})
32 err := Thumbnail(ctx, bytes.NewReader(bs), &thumbnail, "png")
33 if err != nil {
34 return err
35 }
36 if thumbnail.Len() == 0 {
37 return fmt.Errorf("thumbnail buffer is empty")
38 }
39 require.Equal(t, thumbnail.Len(), 1418910)
40 return nil
41 })
42 g.Go(func() error {
43 thumbnail := bytes.Buffer{}
44 // thumbnailCtx = log.WithDebugValue(ctx, map[string]map[string]int{"function": {"Thumbnail": 9}})
45 err := Thumbnail(ctx, bytes.NewReader(bs), &thumbnail, "jpeg")
46 if err != nil {
47 return err
48 }
49 if thumbnail.Len() == 0 {
50 return fmt.Errorf("thumbnail buffer is empty")
51 }
52 require.Equal(t, thumbnail.Len(), 140969)
53 return nil
54 })
55 }
56
57 err = g.Wait()
58 require.NoError(t, err)
59 })
60}
61
62// This segment once caused a segfault in gst-libav.
63// It doesn't gotta work but it does gotta not crash.
64func TestKryptoniteThumbnail(t *testing.T) {
65 withNoGSTLeaks(t, func() {
66 inputFile, err := os.Open(remote.RemoteFixture("46c876d5e6c4124275b8856431833adaad31cb5246caca8ded9dc4d37de400a4/kryptonite-screenshot.mp4"))
67 require.NoError(t, err)
68 defer inputFile.Close()
69 bs, err := io.ReadAll(inputFile)
70 require.NoError(t, err)
71
72 thumbnail := bytes.Buffer{}
73 err = Thumbnail(context.Background(), bytes.NewReader(bs), &thumbnail, "png")
74 require.NoError(t, err)
75 require.Equal(t, 561486, thumbnail.Len())
76 })
77}