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

asticode / go-astiav / 6339542342

28 Sep 2023 01:24PM UTC coverage: 88.974% (+0.07%) from 88.903%
6339542342

push

github

asticode
Fixed h264 test

1388 of 1560 relevant lines covered (88.97%)

33.4 hits per line

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

91.53
/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 {
21✔
14
        var cc *C.struct_AVCodec
21✔
15
        if c != nil {
36✔
16
                cc = c.c
15✔
17
        }
15✔
18
        return newCodecContextFromC(C.avcodec_alloc_context3(cc))
21✔
19
}
20

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

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

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

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

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

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

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

56
func (cc *CodecContext) ChannelLayout() ChannelLayout {
6✔
57
        l, _ := newChannelLayoutFromC(&cc.c.ch_layout).clone()
6✔
58
        return l
6✔
59
}
6✔
60

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

257
func (cc *CodecContext) SendFrame(f *Frame) error {
×
258
        var fc *C.struct_AVFrame
×
259
        if f != nil {
×
260
                fc = f.c
×
261
        }
×
262
        return newError(C.avcodec_send_frame(cc.c, fc))
×
263
}
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