forked from 3d0c/gmf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stream_test.go
62 lines (44 loc) · 1.4 KB
/
stream_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 gmf
import (
"log"
"testing"
)
func TestStream(t *testing.T) {
ctx := NewCtx()
vc, err := FindEncoder("mpeg4")
if err != nil {
t.Fatal(err)
}
cc := NewCodecCtx(vc)
if cc == nil {
t.Fatal("Unable to allocate codec context")
}
defer Release(cc)
if ctx.NewStream(vc) == nil {
t.Fatal("Unable to create new stream")
}
td := CodecCtxTestData
cc.SetWidth(td.width).SetHeight(td.height).SetTimeBase(td.timebase).SetPixFmt(td.pixfmt).SetBitRate(td.bitrate)
if err := cc.Open(nil); err != nil {
t.Fatal(err)
}
st := assert(ctx.GetStream(0)).(*Stream)
st.SetCodecCtx(cc)
if st.CodecCtx().Height() != td.height || st.CodecCtx().Width() != td.width {
t.Fatalf("Expected dimension = %dx%d, %dx%d got\n", td.width, td.height, st.CodecCtx().Width(), st.CodecCtx().Height())
}
ctx.Free()
log.Println("Stream is OK")
}
func TestStreamInputCtx(t *testing.T) {
inputCtx, err := NewInputCtx(inputSampleFilename)
if err != nil {
t.Fatal(err)
}
ist := assert(inputCtx.GetStream(0)).(*Stream)
if ist.CodecCtx().Width() != inputSampleWidth || ist.CodecCtx().Height() != inputSampleHeight {
t.Fatalf("Expected dimension = %dx%d, %dx%d got\n", inputSampleWidth, inputSampleHeight, ist.CodecCtx().Width(), ist.CodecCtx().Height())
}
log.Printf("Input stream is OK, cnt: %d, %dx%d\n", inputCtx.StreamsCnt(), ist.CodecCtx().Width(), ist.CodecCtx().Height())
inputCtx.CloseInputAndRelease()
}