• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

asticode / go-astiav / 5681893079

27 Jul 2023 02:32PM UTC coverage: 80.997% (-10.4%) from 91.374%
5681893079

push

github

asticode
Added github actions

1202 of 1484 relevant lines covered (81.0%)

11.12 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

91.49
/codec_context.go
1
package astiav
2

3
//#cgo pkg-config: libavcodec libavutil
4
//#include <libavcodec/avcodec.h>
5
//#include <libavutil/frame.h>
6
import "C"
7

8
// https://github.com/FFmpeg/FFmpeg/blob/n5.0/libavcodec/avcodec.h#L383
9
type CodecContext struct {
10
        c *C.struct_AVCodecContext
11
}
12

13
func AllocCodecContext(c *Codec) *CodecContext {
6✔
14
        var cc *C.struct_AVCodec
6✔
15
        if c != nil {
10✔
16
                cc = c.c
4✔
17
        }
4✔
18
        return newCodecContextFromC(C.avcodec_alloc_context3(cc))
6✔
19
}
20

21
func newCodecContextFromC(c *C.struct_AVCodecContext) *CodecContext {
6✔
22
        if c == nil {
6✔
23
                return nil
×
24
        }
×
25
        return &CodecContext{c: c}
6✔
26
}
27

28
func (cc *CodecContext) Free() {
5✔
29
        C.avcodec_free_context(&cc.c)
5✔
30
}
5✔
31

32
func (cc *CodecContext) String() string {
2✔
33
        s, _ := stringFromC(255, func(buf *C.char, size C.size_t) error {
4✔
34
                C.avcodec_string(buf, C.int(size), cc.c, C.int(0))
2✔
35
                return nil
2✔
36
        })
2✔
37
        return s
2✔
38
}
39

40
func (cc *CodecContext) BitRate() int64 {
3✔
41
        return int64(cc.c.bit_rate)
3✔
42
}
3✔
43

44
func (cc *CodecContext) SetBitRate(bitRate int64) {
1✔
45
        cc.c.bit_rate = C.int64_t(bitRate)
1✔
46
}
1✔
47

48
func (cc *CodecContext) Channels() int {
3✔
49
        return int(cc.c.channels)
3✔
50
}
3✔
51

52
func (cc *CodecContext) SetChannels(channels int) {
1✔
53
        cc.c.channels = C.int(channels)
1✔
54
}
1✔
55

56
func (cc *CodecContext) ChannelLayout() *ChannelLayout {
2✔
57
        return newChannelLayoutFromC(&cc.c.ch_layout)
2✔
58
}
2✔
59

60
func (cc *CodecContext) SetChannelLayout(l *ChannelLayout) {
1✔
61
        l.copy(&cc.c.ch_layout) //nolint: errcheck
1✔
62
}
1✔
63

64
func (cc *CodecContext) ChromaLocation() ChromaLocation {
1✔
65
        return ChromaLocation(cc.c.chroma_sample_location)
1✔
66
}
1✔
67

68
func (cc *CodecContext) CodecID() CodecID {
2✔
69
        return CodecID(cc.c.codec_id)
2✔
70
}
2✔
71

72
func (cc *CodecContext) ColorPrimaries() ColorPrimaries {
1✔
73
        return ColorPrimaries(cc.c.color_primaries)
1✔
74
}
1✔
75

76
func (cc *CodecContext) ColorRange() ColorRange {
1✔
77
        return ColorRange(cc.c.color_range)
1✔
78
}
1✔
79

80
func (cc *CodecContext) ColorSpace() ColorSpace {
1✔
81
        return ColorSpace(cc.c.colorspace)
1✔
82
}
1✔
83

84
func (cc *CodecContext) ColorTransferCharacteristic() ColorTransferCharacteristic {
1✔
85
        return ColorTransferCharacteristic(cc.c.color_trc)
1✔
86
}
1✔
87

88
func (cc *CodecContext) Flags() CodecContextFlags {
1✔
89
        return CodecContextFlags(cc.c.flags)
1✔
90
}
1✔
91

92
func (cc *CodecContext) SetFlags(fs CodecContextFlags) {
1✔
93
        cc.c.flags = C.int(fs)
1✔
94
}
1✔
95

96
func (cc *CodecContext) Flags2() CodecContextFlags2 {
1✔
97
        return CodecContextFlags2(cc.c.flags2)
1✔
98
}
1✔
99

100
func (cc *CodecContext) SetFlags2(fs CodecContextFlags2) {
1✔
101
        cc.c.flags2 = C.int(fs)
1✔
102
}
1✔
103

104
func (cc *CodecContext) Framerate() Rational {
1✔
105
        return newRationalFromC(cc.c.framerate)
1✔
106
}
1✔
107

108
func (cc *CodecContext) SetFramerate(f Rational) {
1✔
109
        cc.c.framerate = f.c
1✔
110
}
1✔
111

112
func (cc *CodecContext) FrameSize() int {
1✔
113
        return int(cc.c.frame_size)
1✔
114
}
1✔
115

116
func (cc *CodecContext) GopSize() int {
2✔
117
        return int(cc.c.gop_size)
2✔
118
}
2✔
119

120
func (cc *CodecContext) SetGopSize(gopSize int) {
1✔
121
        cc.c.gop_size = C.int(gopSize)
1✔
122
}
1✔
123

124
func (cc *CodecContext) Height() int {
2✔
125
        return int(cc.c.height)
2✔
126
}
2✔
127

128
func (cc *CodecContext) SetHeight(height int) {
2✔
129
        cc.c.height = C.int(height)
2✔
130
}
2✔
131

132
func (cc *CodecContext) Level() Level {
1✔
133
        return Level(cc.c.level)
1✔
134
}
1✔
135

136
func (cc *CodecContext) MediaType() MediaType {
2✔
137
        return MediaType(cc.c.codec_type)
2✔
138
}
2✔
139

140
func (cc *CodecContext) PixelFormat() PixelFormat {
2✔
141
        return PixelFormat(cc.c.pix_fmt)
2✔
142
}
2✔
143

144
func (cc *CodecContext) SetPixelFormat(pixFmt PixelFormat) {
2✔
145
        cc.c.pix_fmt = C.enum_AVPixelFormat(pixFmt)
2✔
146
}
2✔
147

148
func (cc *CodecContext) Profile() Profile {
1✔
149
        return Profile(cc.c.profile)
1✔
150
}
1✔
151

152
func (cc *CodecContext) Qmin() int {
1✔
153
        return int(cc.c.qmin)
1✔
154
}
1✔
155

156
func (cc *CodecContext) SetQmin(qmin int) {
1✔
157
        cc.c.qmin = C.int(qmin)
1✔
158
}
1✔
159

160
func (cc *CodecContext) SampleAspectRatio() Rational {
2✔
161
        return newRationalFromC(cc.c.sample_aspect_ratio)
2✔
162
}
2✔
163

164
func (cc *CodecContext) SetSampleAspectRatio(r Rational) {
1✔
165
        cc.c.sample_aspect_ratio = r.c
1✔
166
}
1✔
167

168
func (cc *CodecContext) SampleFormat() SampleFormat {
2✔
169
        return SampleFormat(cc.c.sample_fmt)
2✔
170
}
2✔
171

172
func (cc *CodecContext) SetSampleFormat(f SampleFormat) {
1✔
173
        cc.c.sample_fmt = C.enum_AVSampleFormat(f)
1✔
174
}
1✔
175

176
func (cc *CodecContext) SampleRate() int {
2✔
177
        return int(cc.c.sample_rate)
2✔
178
}
2✔
179

180
func (cc *CodecContext) SetSampleRate(sampleRate int) {
1✔
181
        cc.c.sample_rate = C.int(sampleRate)
1✔
182
}
1✔
183

184
func (cc *CodecContext) StrictStdCompliance() StrictStdCompliance {
3✔
185
        return StrictStdCompliance(cc.c.strict_std_compliance)
3✔
186
}
3✔
187

188
func (cc *CodecContext) SetStrictStdCompliance(c StrictStdCompliance) {
1✔
189
        cc.c.strict_std_compliance = C.int(c)
1✔
190
}
1✔
191

192
func (cc *CodecContext) TimeBase() Rational {
1✔
193
        return newRationalFromC(cc.c.time_base)
1✔
194
}
1✔
195

196
func (cc *CodecContext) SetTimeBase(r Rational) {
2✔
197
        cc.c.time_base = r.c
2✔
198
}
2✔
199

200
func (cc *CodecContext) ThreadCount() int {
3✔
201
        return int(cc.c.thread_count)
3✔
202
}
3✔
203

204
func (cc *CodecContext) SetThreadCount(threadCount int) {
1✔
205
        cc.c.thread_count = C.int(threadCount)
1✔
206
}
1✔
207

208
func (cc *CodecContext) ThreadType() ThreadType {
3✔
209
        return ThreadType(cc.c.thread_type)
3✔
210
}
3✔
211

212
func (cc *CodecContext) SetThreadType(t ThreadType) {
1✔
213
        cc.c.thread_type = C.int(t)
1✔
214
}
1✔
215

216
func (cc *CodecContext) Width() int {
2✔
217
        return int(cc.c.width)
2✔
218
}
2✔
219

220
func (cc *CodecContext) SetWidth(width int) {
2✔
221
        cc.c.width = C.int(width)
2✔
222
}
2✔
223

224
func (cc *CodecContext) Open(c *Codec, d *Dictionary) error {
2✔
225
        var dc **C.struct_AVDictionary
2✔
226
        if d != nil {
2✔
227
                dc = &d.c
×
228
        }
×
229
        return newError(C.avcodec_open2(cc.c, c.c, dc))
2✔
230
}
231

232
func (cc *CodecContext) ReceivePacket(p *Packet) error {
×
233
        var pc *C.struct_AVPacket
×
234
        if p != nil {
×
235
                pc = p.c
×
236
        }
×
237
        return newError(C.avcodec_receive_packet(cc.c, pc))
×
238
}
239

240
func (cc *CodecContext) SendPacket(p *Packet) error {
120✔
241
        var pc *C.struct_AVPacket
120✔
242
        if p != nil {
240✔
243
                pc = p.c
120✔
244
        }
120✔
245
        return newError(C.avcodec_send_packet(cc.c, pc))
120✔
246
}
247

248
func (cc *CodecContext) ReceiveFrame(f *Frame) error {
240✔
249
        var fc *C.struct_AVFrame
240✔
250
        if f != nil {
480✔
251
                fc = f.c
240✔
252
        }
240✔
253
        return newError(C.avcodec_receive_frame(cc.c, fc))
240✔
254
}
255

256
func (cc *CodecContext) SendFrame(f *Frame) error {
×
257
        var fc *C.struct_AVFrame
×
258
        if f != nil {
×
259
                fc = f.c
×
260
        }
×
261
        return newError(C.avcodec_send_frame(cc.c, fc))
×
262
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc