forked from asticode/go-astiav
-
Notifications
You must be signed in to change notification settings - Fork 0
/
codec_context_test.go
115 lines (107 loc) · 4.53 KB
/
codec_context_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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package astiav_test
import (
"testing"
"github.com/asticode/go-astiav"
"github.com/stretchr/testify/require"
)
func TestCodecContext(t *testing.T) {
_, s1, s2, err := videoInputStreams()
require.NoError(t, err)
c1 := astiav.FindDecoder(s1.CodecParameters().CodecID())
require.NotNil(t, c1)
cc1 := astiav.AllocCodecContext(c1)
require.NotNil(t, cc1)
defer cc1.Free()
err = s1.CodecParameters().ToCodecContext(cc1)
require.NoError(t, err)
require.Equal(t, "Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 320x180 [SAR 1:1 DAR 16:9], 441 kb/s", cc1.String())
require.Equal(t, int64(441324), cc1.BitRate())
require.Equal(t, astiav.ChromaLocationLeft, cc1.ChromaLocation())
require.Equal(t, astiav.CodecIDH264, cc1.CodecID())
require.Equal(t, astiav.ColorPrimariesUnspecified, cc1.ColorPrimaries())
require.Equal(t, astiav.ColorRangeUnspecified, cc1.ColorRange())
require.Equal(t, astiav.ColorSpaceUnspecified, cc1.ColorSpace())
require.Equal(t, astiav.ColorTransferCharacteristicUnspecified, cc1.ColorTransferCharacteristic())
require.Equal(t, 12, cc1.GopSize())
require.Equal(t, 180, cc1.Height())
require.Equal(t, astiav.Level(13), cc1.Level())
require.Equal(t, astiav.MediaTypeVideo, cc1.MediaType())
require.Equal(t, astiav.PixelFormatYuv420P, cc1.PixelFormat())
require.Equal(t, astiav.ProfileH264ConstrainedBaseline, cc1.Profile())
require.Equal(t, astiav.NewRational(1, 1), cc1.SampleAspectRatio())
require.Equal(t, astiav.StrictStdComplianceNormal, cc1.StrictStdCompliance())
require.Equal(t, 1, cc1.ThreadCount())
require.Equal(t, astiav.ThreadType(3), cc1.ThreadType())
require.Equal(t, 320, cc1.Width())
c2 := astiav.FindDecoder(s2.CodecParameters().CodecID())
require.NotNil(t, c2)
cc2 := astiav.AllocCodecContext(c2)
require.NotNil(t, cc2)
defer cc2.Free()
err = s2.CodecParameters().ToCodecContext(cc2)
require.NoError(t, err)
require.Equal(t, "Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 161 kb/s", cc2.String())
require.Equal(t, int64(161052), cc2.BitRate())
require.Equal(t, 2, cc2.Channels())
require.Equal(t, astiav.ChannelLayoutStereo, cc2.ChannelLayout())
require.Equal(t, astiav.CodecIDAac, cc2.CodecID())
require.Equal(t, 1024, cc2.FrameSize())
require.Equal(t, astiav.MediaTypeAudio, cc2.MediaType())
require.Equal(t, astiav.SampleFormatFltp, cc2.SampleFormat())
require.Equal(t, 48000, cc2.SampleRate())
require.Equal(t, astiav.StrictStdComplianceNormal, cc2.StrictStdCompliance())
require.Equal(t, 1, cc2.ThreadCount())
require.Equal(t, astiav.ThreadType(3), cc2.ThreadType())
c3 := astiav.FindEncoder(astiav.CodecIDMjpeg)
require.NotNil(t, c3)
cc3 := astiav.AllocCodecContext(c3)
require.NotNil(t, cc3)
defer cc3.Free()
cc3.SetHeight(2)
cc3.SetPixelFormat(astiav.PixelFormatYuvj420P)
cc3.SetTimeBase(astiav.NewRational(1, 1))
cc3.SetWidth(3)
err = cc3.Open(c3, nil)
require.NoError(t, err)
cc4 := astiav.AllocCodecContext(nil)
require.NotNil(t, cc4)
defer cc4.Free()
cc4.SetBitRate(1)
cc4.SetChannelLayout(astiav.ChannelLayout21)
cc4.SetChannels(3)
cc4.SetFlags(astiav.NewCodecContextFlags(4))
cc4.SetFlags2(astiav.NewCodecContextFlags2(5))
cc4.SetFramerate(astiav.NewRational(6, 1))
cc4.SetGopSize(7)
cc4.SetHeight(8)
cc4.SetPixelFormat(astiav.PixelFormat0Bgr)
cc4.SetSampleAspectRatio(astiav.NewRational(10, 1))
cc4.SetSampleFormat(astiav.SampleFormatDbl)
cc4.SetSampleRate(12)
cc4.SetStrictStdCompliance(astiav.StrictStdComplianceExperimental)
cc4.SetThreadCount(13)
cc4.SetThreadType(astiav.ThreadTypeSlice)
cc4.SetTimeBase(astiav.NewRational(15, 1))
cc4.SetWidth(16)
require.Equal(t, int64(1), cc4.BitRate())
require.Equal(t, astiav.ChannelLayout21, cc4.ChannelLayout())
require.Equal(t, 3, cc4.Channels())
require.Equal(t, astiav.NewCodecContextFlags(4), cc4.Flags())
require.Equal(t, astiav.NewCodecContextFlags2(5), cc4.Flags2())
require.Equal(t, astiav.NewRational(6, 1), cc4.Framerate())
require.Equal(t, 7, cc4.GopSize())
require.Equal(t, 8, cc4.Height())
require.Equal(t, astiav.PixelFormat0Bgr, cc4.PixelFormat())
require.Equal(t, astiav.NewRational(10, 1), cc4.SampleAspectRatio())
require.Equal(t, astiav.SampleFormatDbl, cc4.SampleFormat())
require.Equal(t, 12, cc4.SampleRate())
require.Equal(t, astiav.StrictStdComplianceExperimental, cc4.StrictStdCompliance())
require.Equal(t, 13, cc4.ThreadCount())
require.Equal(t, astiav.ThreadTypeSlice, cc4.ThreadType())
require.Equal(t, astiav.NewRational(15, 1), cc4.TimeBase())
require.Equal(t, 16, cc4.Width())
// TODO Test ReceivePacket
// TODO Test SendPacket
// TODO Test ReceiveFrame
// TODO Test SendFrame
}