forked from asticode/go-astiav
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhardware_device_context.go
37 lines (33 loc) · 960 Bytes
/
hardware_device_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
package astiav
//#include <libavcodec/avcodec.h>
//#include <libavutil/hwcontext.h>
import "C"
import (
"unsafe"
)
// https://ffmpeg.org/doxygen/7.0/structAVHWDeviceContext.html
type HardwareDeviceContext struct {
c *C.AVBufferRef
}
// https://ffmpeg.org/doxygen/7.0/hwcontext_8c.html#a21fbd088225e4e25c4d9a01b3f5e8c51
func CreateHardwareDeviceContext(t HardwareDeviceType, device string, options *Dictionary, flags int) (*HardwareDeviceContext, error) {
hdc := HardwareDeviceContext{}
deviceC := (*C.char)(nil)
if device != "" {
deviceC = C.CString(device)
defer C.free(unsafe.Pointer(deviceC))
}
optionsC := (*C.AVDictionary)(nil)
if options != nil {
optionsC = options.c
}
if err := newError(C.av_hwdevice_ctx_create(&hdc.c, (C.enum_AVHWDeviceType)(t), deviceC, optionsC, C.int(flags))); err != nil {
return nil, err
}
return &hdc, nil
}
func (hdc *HardwareDeviceContext) Free() {
if hdc.c != nil {
C.av_buffer_unref(&hdc.c)
}
}