-
Notifications
You must be signed in to change notification settings - Fork 46
/
class_test.go
75 lines (68 loc) · 1.96 KB
/
class_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
63
64
65
66
67
68
69
70
71
72
73
74
75
package astiav
import (
"fmt"
"os"
"path/filepath"
"testing"
"unsafe"
"github.com/stretchr/testify/require"
)
func TestClass(t *testing.T) {
c := FindDecoder(CodecIDMjpeg)
require.NotNil(t, c)
cc := AllocCodecContext(c)
require.NotNil(t, cc)
defer cc.Free()
cl := cc.Class()
require.NotNil(t, cl)
require.Equal(t, ClassCategoryDecoder, cl.Category())
require.Equal(t, "mjpeg", cl.ItemName())
require.Equal(t, "AVCodecContext", cl.Name())
require.Equal(t, fmt.Sprintf("mjpeg [AVCodecContext] @ %p", cc.c), cl.String())
// TODO Test parent
}
func TestClassers(t *testing.T) {
cl := len(classers.p)
f1 := AllocFilterGraph()
f2 := AllocFilterGraph()
c := FindDecoder(CodecIDMjpeg)
require.NotNil(t, c)
bf := FindBitStreamFilterByName("null")
require.NotNil(t, bf)
bfc, err := AllocBitStreamFilterContext(bf)
require.NoError(t, err)
cc := AllocCodecContext(c)
require.NotNil(t, cc)
bufferSink := FindFilterByName("buffersink")
require.NotNil(t, bufferSink)
fc1, err := f1.NewFilterContext(bufferSink, "filter_out", nil)
require.NoError(t, err)
_, err = f2.NewFilterContext(bufferSink, "filter_out", nil)
require.NoError(t, err)
fmc1 := AllocFormatContext()
fmc2 := AllocFormatContext()
require.NoError(t, fmc2.OpenInput("testdata/video.mp4", nil, nil))
path := filepath.Join(t.TempDir(), "iocontext.txt")
ic1, err := OpenIOContext(path, NewIOContextFlags(IOContextFlagWrite))
require.NoError(t, err)
defer os.RemoveAll(path)
ic2, err := AllocIOContext(1, true, nil, nil, nil)
require.NoError(t, err)
ssc, err := CreateSoftwareScaleContext(1, 1, PixelFormatRgba, 2, 2, PixelFormatRgba, NewSoftwareScaleContextFlags())
require.NoError(t, err)
require.Equal(t, cl+12, len(classers.p))
v, ok := classers.get(unsafe.Pointer(f1.c))
require.True(t, ok)
require.Equal(t, f1, v)
bfc.Free()
cc.Free()
fc1.Free()
f1.Free()
f2.Free()
fmc1.Free()
fmc2.CloseInput()
require.NoError(t, ic1.Close())
ic2.Free()
ssc.Free()
require.Equal(t, cl, len(classers.p))
}