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

asticode / go-astiav / 20960391307

13 Jan 2026 02:10PM UTC coverage: 86.203% (-0.2%) from 86.374%
20960391307

push

github

web-flow
Now compatible with n8.0 (#178)

* n7.1: Migrate deprecated methods, fields, and definitions

* n7.1: Add new definitions

* n7.1: Add new field

* n7.1: Update doxygen url

* n8.0: Clean up remaining n7.x deprecations

* n8.0: Add new CodecIDs and fields

* n8.0: Migration to n8.0

* n8.0: Refactor swscale with Publicly expose struct SwsContext, enum SwsDither, and enum SwsAlphaBlend

n8.0: Stash commit

* n8.0: Update doxygen url

* n8.0: Fix windows.patch to apply new library.mak in n8.0

* n8.0: Clean up and organize the APIs, remove redundant implementations, and reorder the enum fields

* n8.0: Refactor SoftwareScaleContext to simplify and optimize update logic and remove redundant code

* Add tests for supported sample rates and frame rates in codec encoders

* Revert changes in `Free` and `Class`, other minor improvements

* Adapt the examples to the current library

* Update breaking changes

109 of 112 new or added lines in 5 files covered. (97.32%)

1 existing line in 1 file now uncovered.

3049 of 3537 relevant lines covered (86.2%)

53.83 hits per line

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

92.92
/software_scale_context.go
1
package astiav
2

3
//#include <libswscale/swscale.h>
4
import "C"
5
import (
6
        "errors"
7
        "unsafe"
8
)
9

10
// https://ffmpeg.org/doxygen/8.0/structSwsContext.html
11
type SoftwareScaleContext struct {
12
        c *C.struct_SwsContext
13
}
14

15
type softwareScaleContextUpdate struct {
16
        dstFormat PixelFormat
17
        dstH      int
18
        dstW      int
19
        flags     SoftwareScaleContextFlags
20
        srcFormat PixelFormat
21
        srcH      int
22
        srcW      int
23
}
24

25
func newSoftwareScaleContextFromC(c *C.struct_SwsContext) *SoftwareScaleContext {
9✔
26
        if c == nil {
9✔
NEW
27
                return nil
×
UNCOV
28
        }
×
29
        return &SoftwareScaleContext{c: c}
9✔
30
}
31

32
// https://ffmpeg.org/doxygen/8.0/group__libsws.html#ga59cc19eff0434e7ec11676dc5e222ff3
33
func CreateSoftwareScaleContext(srcW, srcH int, srcFormat PixelFormat, dstW, dstH int, dstFormat PixelFormat, flags SoftwareScaleContextFlags) (*SoftwareScaleContext, error) {
9✔
34
        ssc := newSoftwareScaleContextFromC(C.sws_getContext(C.int(srcW), C.int(srcH), C.enum_AVPixelFormat(srcFormat), C.int(dstW), C.int(dstH), C.enum_AVPixelFormat(dstFormat), C.int(flags), nil, nil, nil))
9✔
35
        if ssc == nil {
9✔
36
                return nil, errors.New("astiav: empty new context")
×
37
        }
×
38

39
        classers.set(ssc)
9✔
40
        return ssc, nil
9✔
41
}
42

43
// https://ffmpeg.org/doxygen/8.0/group__libsws.html#gad90b463ceeafdfd526994742f9954dbb
44
func (ssc *SoftwareScaleContext) Free() {
6✔
45
        if ssc.c != nil {
12✔
46
                // Make sure to clone the classer before freeing the object since
6✔
47
                // the C free method may reset the pointer
6✔
48
                c := newClonedClasser(ssc)
6✔
49
                C.sws_freeContext(ssc.c)
6✔
50
                ssc.c = nil
6✔
51
                // Make sure to remove from classers after freeing the object since
6✔
52
                // the C free method may use methods needing the classer
6✔
53
                if c != nil {
12✔
54
                        classers.del(c)
6✔
55
                }
6✔
56
        }
57
}
58

59
var _ Classer = (*SoftwareScaleContext)(nil)
60

61
// https://ffmpeg.org/doxygen/8.0/structSwsContext.html#a6866f52574bc730833d2580abc806261
62
func (ssc *SoftwareScaleContext) Class() *Class {
18✔
63
        if ssc.c == nil {
18✔
64
                return nil
×
65
        }
×
66
        return newClassFromC(unsafe.Pointer(ssc.c))
18✔
67
}
68

69
// https://ffmpeg.org/doxygen/8.0/swscale-v2_8txt.html#a20ffff3ac1378332422b93ed70264f4c
70
func (ssc *SoftwareScaleContext) ScaleFrame(src, dst *Frame) error {
6✔
71
        return newError(C.sws_scale_frame(ssc.c, dst.c, src.c))
6✔
72
}
6✔
73

74
// https://ffmpeg.org/doxygen/8.0/group__libsws.html#ga9fd74ceaf0f126f762b81e3677f70c75
75
func (ssc *SoftwareScaleContext) update(fn func(update *softwareScaleContextUpdate)) error {
27✔
76
        u := &softwareScaleContextUpdate{
27✔
77
                dstFormat: ssc.DestinationPixelFormat(),
27✔
78
                dstH:      ssc.DestinationHeight(),
27✔
79
                dstW:      ssc.DestinationWidth(),
27✔
80
                flags:     ssc.Flags(),
27✔
81
                srcFormat: ssc.SourcePixelFormat(),
27✔
82
                srcH:      ssc.SourceHeight(),
27✔
83
                srcW:      ssc.SourceWidth(),
27✔
84
        }
27✔
85

27✔
86
        fn(u)
27✔
87

27✔
88
        c := C.sws_getCachedContext(
27✔
89
                ssc.c,
27✔
90
                C.int(u.srcW),
27✔
91
                C.int(u.srcH),
27✔
92
                C.enum_AVPixelFormat(u.srcFormat),
27✔
93
                C.int(u.dstW),
27✔
94
                C.int(u.dstH),
27✔
95
                C.enum_AVPixelFormat(u.dstFormat),
27✔
96
                C.int(u.flags),
27✔
97
                nil, nil, nil,
27✔
98
        )
27✔
99
        if c == nil {
27✔
100
                return errors.New("astiav: empty new context")
×
101
        }
×
102

103
        ssc.c = c
27✔
104

27✔
105
        return nil
27✔
106
}
107

108
// https://ffmpeg.org/doxygen/8.0/structSwsContext.html#aef45de443b59978fd38ad1531c618574
109
func (ssc *SoftwareScaleContext) Flags() SoftwareScaleContextFlags {
33✔
110
        return SoftwareScaleContextFlags(ssc.c.flags)
33✔
111
}
33✔
112

113
// https://ffmpeg.org/doxygen/8.0/structSwsContext.html#aef45de443b59978fd38ad1531c618574
114
func (ssc *SoftwareScaleContext) SetFlags(swscf SoftwareScaleContextFlags) error {
3✔
115
        return ssc.update(func(u *softwareScaleContextUpdate) { u.flags = swscf })
6✔
116
}
117

118
// https://ffmpeg.org/doxygen/8.0/structSwsContext.html#a883a891c8a2d4ea7a15a3a7055f64386
119
func (ssc *SoftwareScaleContext) DestinationWidth() int {
33✔
120
        return int(ssc.c.dst_w)
33✔
121
}
33✔
122

123
// https://ffmpeg.org/doxygen/8.0/structSwsContext.html#a883a891c8a2d4ea7a15a3a7055f64386
124
func (ssc *SoftwareScaleContext) SetDestinationWidth(i int) error {
3✔
125
        return ssc.update(func(u *softwareScaleContextUpdate) { u.dstW = i })
6✔
126
}
127

128
// https://ffmpeg.org/doxygen/8.0/structSwsContext.html#a7facd34608c9258dae8c2942e3dce78f
129
func (ssc *SoftwareScaleContext) DestinationHeight() int {
33✔
130
        return int(ssc.c.dst_h)
33✔
131
}
33✔
132

133
// https://ffmpeg.org/doxygen/8.0/structSwsContext.html#a7facd34608c9258dae8c2942e3dce78f
134
func (ssc *SoftwareScaleContext) SetDestinationHeight(i int) error {
3✔
135
        return ssc.update(func(u *softwareScaleContextUpdate) { u.dstH = i })
6✔
136
}
137

138
// https://ffmpeg.org/doxygen/8.0/structSwsContext.html#a0ff71c9ef5ab6dabf90378fa7bf836ec
139
func (ssc *SoftwareScaleContext) DestinationPixelFormat() PixelFormat {
33✔
140
        return PixelFormat(ssc.c.dst_format)
33✔
141
}
33✔
142

143
// https://ffmpeg.org/doxygen/8.0/structSwsContext.html#a0ff71c9ef5ab6dabf90378fa7bf836ec
144
func (ssc *SoftwareScaleContext) SetDestinationPixelFormat(p PixelFormat) error {
3✔
145
        return ssc.update(func(u *softwareScaleContextUpdate) { u.dstFormat = p })
6✔
146
}
147

148
func (ssc *SoftwareScaleContext) DestinationResolution() (width int, height int) {
6✔
149
        return int(ssc.c.dst_w), int(ssc.c.dst_h)
6✔
150
}
6✔
151

152
func (ssc *SoftwareScaleContext) SetDestinationResolution(w int, h int) error {
3✔
153
        return ssc.update(func(u *softwareScaleContextUpdate) {
6✔
154
                u.dstW = w
3✔
155
                u.dstH = h
3✔
156
        })
3✔
157
}
158

159
// https://ffmpeg.org/doxygen/8.0/structSwsContext.html#aa7dc7a4f9ec57a7c37957259a51cd920
160
func (ssc *SoftwareScaleContext) SourceWidth() int {
33✔
161
        return int(ssc.c.src_w)
33✔
162
}
33✔
163

164
// https://ffmpeg.org/doxygen/8.0/structSwsContext.html#a0ff71c9ef5ab6dabf90378fa7bf836ec
165
func (ssc *SoftwareScaleContext) SetSourceWidth(i int) error {
3✔
166
        return ssc.update(func(u *softwareScaleContextUpdate) { u.srcW = i })
6✔
167
}
168

169
// https://ffmpeg.org/doxygen/8.0/structSwsContext.html#a0dbc8c02bd3b4cd472e07008009751ff
170
func (ssc *SoftwareScaleContext) SourceHeight() int {
33✔
171
        return int(ssc.c.src_h)
33✔
172
}
33✔
173

174
// https://ffmpeg.org/doxygen/8.0/structSwsContext.html#a0ff71c9ef5ab6dabf90378fa7bf836ec
175
func (ssc *SoftwareScaleContext) SetSourceHeight(i int) error {
3✔
176
        return ssc.update(func(u *softwareScaleContextUpdate) { u.srcH = i })
6✔
177
}
178

179
// https://ffmpeg.org/doxygen/8.0/structSwsContext.html#aab113373f157ee3b255ad97481af0cd9
180
func (ssc *SoftwareScaleContext) SourcePixelFormat() PixelFormat {
33✔
181
        return PixelFormat(ssc.c.src_format)
33✔
182
}
33✔
183

184
// https://ffmpeg.org/doxygen/8.0/structSwsContext.html#aab113373f157ee3b255ad97481af0cd9
185
func (ssc *SoftwareScaleContext) SetSourcePixelFormat(p PixelFormat) error {
3✔
186
        return ssc.update(func(u *softwareScaleContextUpdate) { u.srcFormat = p })
6✔
187
}
188

189
func (ssc *SoftwareScaleContext) SourceResolution() (int, int) {
6✔
190
        return int(ssc.c.src_w), int(ssc.c.src_h)
6✔
191
}
6✔
192

193
func (ssc *SoftwareScaleContext) SetSourceResolution(w int, h int) error {
3✔
194
        return ssc.update(func(u *softwareScaleContextUpdate) {
6✔
195
                u.srcW = w
3✔
196
                u.srcH = h
3✔
197
        })
3✔
198
}
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