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

asticode / go-astiav / 7643887323

24 Jan 2024 05:23PM UTC coverage: 84.784% (-2.2%) from 86.991%
7643887323

push

github

web-flow
Implementation for HW Context (#32)

* Adding HW Context

* Check for hw pixel format and transfer data on ReciveFrame when its hw pixel format

* Remove hw_decoding example and update demuxing_dec example

* unref hw_device_ctx, and improve example

Unref correctly hw_device_ctx on free
decoding example has now a flag for hw decoding
Use error on hw context because its good to know the error that happen
Add a method to list supported hw codecs so user could check if system has a specif hwcodec before the create a hw context

* Fix test to use err, and update hw with device to also return error

* revert changes in demux example

* Add/Modify according to review

Seperate Hardware Device Context and Test
Renaming HW to Hardware
Create dedicated hardware_decoding Example
Update Readme
Add TransferHardwareData to frame.go
Add SetHardwareDeviceContext to codec_context.go

* Review changes

add HardwareConfigs to codec
create codec_hardware_config
create codec_hardware_config_method_flag
update example
update flags
better error handling in TransferHardwareData
update CreateHardwareDeviceContext, better null handling
remove hw ctx test because it fails when no nvidia is present
some reordering of conss in hardware_device_type

* Minor tweaks (review changes)

HardwareConfigs only returns a slice an no error anymore
remove if HardwareDeviceType checking in codec.go this should be done by user
order codec hw_config_method_flags constants alphabetically
some small changes in example
##  hardware_device_context.go
change link
update optionsC

21 of 67 new or added lines in 7 files covered. (31.34%)

1432 of 1689 relevant lines covered (84.78%)

20.54 hits per line

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

0.0
/hardware_device_context.go
1
package astiav
2

3
//#cgo pkg-config: libavutil libavcodec
4
//#include <libavcodec/avcodec.h>
5
//#include <libavutil/hwcontext.h>
6
import "C"
7
import (
8
        "unsafe"
9
)
10

11
// https://github.com/FFmpeg/FFmpeg/blob/n5.0/libavutil/hwcontext.h#L61
12
type HardwareDeviceContext struct {
13
        c *C.AVBufferRef
14
}
15

NEW
16
func CreateHardwareDeviceContext(t HardwareDeviceType, device string, options *Dictionary) (*HardwareDeviceContext, error) {
×
NEW
17
        hdc := HardwareDeviceContext{}
×
NEW
18
        deviceC := (*C.char)(nil)
×
NEW
19
        if device != "" {
×
NEW
20
                deviceC = C.CString(device)
×
NEW
21
                defer C.free(unsafe.Pointer(deviceC))
×
NEW
22
        }
×
NEW
23
        optionsC := (*C.struct_AVDictionary)(nil)
×
NEW
24
        if options != nil {
×
NEW
25
                optionsC = options.c
×
NEW
26
        }
×
NEW
27
        if err := newError(C.av_hwdevice_ctx_create(&hdc.c, (C.enum_AVHWDeviceType)(t), deviceC, optionsC, 0)); err != nil {
×
NEW
28
                return nil, err
×
NEW
29
        }
×
NEW
30
        return &hdc, nil
×
31
}
32

NEW
33
func (hdc *HardwareDeviceContext) Free() {
×
NEW
34
        if hdc.c != nil {
×
NEW
35
                C.av_buffer_unref(&hdc.c)
×
NEW
36
        }
×
37
}
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