forked from asticode/go-astiav
-
Notifications
You must be signed in to change notification settings - Fork 0
/
codec_context.go
254 lines (199 loc) · 5.47 KB
/
codec_context.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
package astiav
//#cgo pkg-config: libavcodec libavutil
//#include <libavcodec/avcodec.h>
//#include <libavutil/frame.h>
import "C"
// https://github.com/FFmpeg/FFmpeg/blob/n5.0/libavcodec/avcodec.h#L383
type CodecContext struct {
c *C.struct_AVCodecContext
}
func AllocCodecContext(c *Codec) *CodecContext {
var cc *C.struct_AVCodec
if c != nil {
cc = c.c
}
return newCodecContextFromC(C.avcodec_alloc_context3(cc))
}
func newCodecContextFromC(c *C.struct_AVCodecContext) *CodecContext {
if c == nil {
return nil
}
return &CodecContext{c: c}
}
func (cc *CodecContext) Free() {
C.avcodec_free_context(&cc.c)
}
func (cc *CodecContext) String() string {
s, _ := stringFromC(255, func(buf *C.char, size C.size_t) error {
C.avcodec_string(buf, C.int(size), cc.c, C.int(0))
return nil
})
return s
}
func (cc *CodecContext) BitRate() int64 {
return int64(cc.c.bit_rate)
}
func (cc *CodecContext) SetBitRate(bitRate int64) {
cc.c.bit_rate = C.int64_t(bitRate)
}
func (cc *CodecContext) Channels() int {
return int(cc.c.channels)
}
func (cc *CodecContext) SetChannels(channels int) {
cc.c.channels = C.int(channels)
}
func (cc *CodecContext) ChannelLayout() ChannelLayout {
return ChannelLayout(cc.c.channel_layout)
}
func (cc *CodecContext) SetChannelLayout(l ChannelLayout) {
cc.c.channel_layout = C.uint64_t(l)
}
func (cc *CodecContext) ChromaLocation() ChromaLocation {
return ChromaLocation(cc.c.chroma_sample_location)
}
func (cc *CodecContext) CodecID() CodecID {
return CodecID(cc.c.codec_id)
}
func (cc *CodecContext) ColorPrimaries() ColorPrimaries {
return ColorPrimaries(cc.c.color_primaries)
}
func (cc *CodecContext) ColorRange() ColorRange {
return ColorRange(cc.c.color_range)
}
func (cc *CodecContext) ColorSpace() ColorSpace {
return ColorSpace(cc.c.colorspace)
}
func (cc *CodecContext) ColorTransferCharacteristic() ColorTransferCharacteristic {
return ColorTransferCharacteristic(cc.c.color_trc)
}
func (cc *CodecContext) Flags() CodecContextFlags {
return CodecContextFlags(cc.c.flags)
}
func (cc *CodecContext) SetFlags(fs CodecContextFlags) {
cc.c.flags = C.int(fs)
}
func (cc *CodecContext) Flags2() CodecContextFlags2 {
return CodecContextFlags2(cc.c.flags2)
}
func (cc *CodecContext) SetFlags2(fs CodecContextFlags2) {
cc.c.flags2 = C.int(fs)
}
func (cc *CodecContext) Framerate() Rational {
return newRationalFromC(cc.c.framerate)
}
func (cc *CodecContext) SetFramerate(f Rational) {
cc.c.framerate = f.c
}
func (cc *CodecContext) FrameSize() int {
return int(cc.c.frame_size)
}
func (cc *CodecContext) GopSize() int {
return int(cc.c.gop_size)
}
func (cc *CodecContext) SetGopSize(gopSize int) {
cc.c.gop_size = C.int(gopSize)
}
func (cc *CodecContext) Height() int {
return int(cc.c.height)
}
func (cc *CodecContext) SetHeight(height int) {
cc.c.height = C.int(height)
}
func (cc *CodecContext) Level() Level {
return Level(cc.c.level)
}
func (cc *CodecContext) MediaType() MediaType {
return MediaType(cc.c.codec_type)
}
func (cc *CodecContext) PixelFormat() PixelFormat {
return PixelFormat(cc.c.pix_fmt)
}
func (cc *CodecContext) SetPixelFormat(pixFmt PixelFormat) {
cc.c.pix_fmt = C.enum_AVPixelFormat(pixFmt)
}
func (cc *CodecContext) Profile() Profile {
return Profile(cc.c.profile)
}
func (cc *CodecContext) SampleAspectRatio() Rational {
return newRationalFromC(cc.c.sample_aspect_ratio)
}
func (cc *CodecContext) SetSampleAspectRatio(r Rational) {
cc.c.sample_aspect_ratio = r.c
}
func (cc *CodecContext) SampleFormat() SampleFormat {
return SampleFormat(cc.c.sample_fmt)
}
func (cc *CodecContext) SetSampleFormat(f SampleFormat) {
cc.c.sample_fmt = C.enum_AVSampleFormat(f)
}
func (cc *CodecContext) SampleRate() int {
return int(cc.c.sample_rate)
}
func (cc *CodecContext) SetSampleRate(sampleRate int) {
cc.c.sample_rate = C.int(sampleRate)
}
func (cc *CodecContext) StrictStdCompliance() StrictStdCompliance {
return StrictStdCompliance(cc.c.strict_std_compliance)
}
func (cc *CodecContext) SetStrictStdCompliance(c StrictStdCompliance) {
cc.c.strict_std_compliance = C.int(c)
}
func (cc *CodecContext) TimeBase() Rational {
return newRationalFromC(cc.c.time_base)
}
func (cc *CodecContext) SetTimeBase(r Rational) {
cc.c.time_base = r.c
}
func (cc *CodecContext) ThreadCount() int {
return int(cc.c.thread_count)
}
func (cc *CodecContext) SetThreadCount(threadCount int) {
cc.c.thread_count = C.int(threadCount)
}
func (cc *CodecContext) ThreadType() ThreadType {
return ThreadType(cc.c.thread_type)
}
func (cc *CodecContext) SetThreadType(t ThreadType) {
cc.c.thread_type = C.int(t)
}
func (cc *CodecContext) Width() int {
return int(cc.c.width)
}
func (cc *CodecContext) SetWidth(width int) {
cc.c.width = C.int(width)
}
func (cc *CodecContext) Open(c *Codec, d *Dictionary) error {
var dc **C.struct_AVDictionary
if d != nil {
dc = &d.c
}
return newError(C.avcodec_open2(cc.c, c.c, dc))
}
func (cc *CodecContext) ReceivePacket(p *Packet) error {
var pc *C.struct_AVPacket
if p != nil {
pc = p.c
}
return newError(C.avcodec_receive_packet(cc.c, pc))
}
func (cc *CodecContext) SendPacket(p *Packet) error {
var pc *C.struct_AVPacket
if p != nil {
pc = p.c
}
return newError(C.avcodec_send_packet(cc.c, pc))
}
func (cc *CodecContext) ReceiveFrame(f *Frame) error {
var fc *C.struct_AVFrame
if f != nil {
fc = f.c
}
return newError(C.avcodec_receive_frame(cc.c, fc))
}
func (cc *CodecContext) SendFrame(f *Frame) error {
var fc *C.struct_AVFrame
if f != nil {
fc = f.c
}
return newError(C.avcodec_send_frame(cc.c, fc))
}