-
Notifications
You must be signed in to change notification settings - Fork 47
/
dictionary.go
78 lines (68 loc) · 2.24 KB
/
dictionary.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package astiav
//#include <libavcodec/avcodec.h>
//#include <libavutil/dict.h>
//#include <stdlib.h>
import "C"
import (
"unsafe"
)
// https://ffmpeg.org/doxygen/7.0/structAVDictionary.html
type Dictionary struct {
c *C.AVDictionary
}
func NewDictionary() *Dictionary {
return &Dictionary{}
}
func newDictionaryFromC(c *C.AVDictionary) *Dictionary {
if c == nil {
return nil
}
return &Dictionary{c: c}
}
// https://ffmpeg.org/doxygen/7.0/group__lavu__dict.html#ga8d9c2de72b310cef8e6a28c9cd3acbbe
func (d *Dictionary) Set(key, value string, flags DictionaryFlags) error {
ck := C.CString(key)
defer C.free(unsafe.Pointer(ck))
cv := C.CString(value)
defer C.free(unsafe.Pointer(cv))
return newError(C.av_dict_set(&d.c, ck, cv, C.int(flags)))
}
// https://ffmpeg.org/doxygen/7.0/group__lavu__dict.html#gaca5ff7c251e60bd13164d13c82f21b79
func (d *Dictionary) ParseString(i, keyValSep, pairsSep string, flags DictionaryFlags) error {
ci := C.CString(i)
defer C.free(unsafe.Pointer(ci))
ck := C.CString(keyValSep)
defer C.free(unsafe.Pointer(ck))
cp := C.CString(pairsSep)
defer C.free(unsafe.Pointer(cp))
return newError(C.av_dict_parse_string(&d.c, ci, ck, cp, C.int(flags)))
}
// https://ffmpeg.org/doxygen/7.0/group__lavu__dict.html#gae67f143237b2cb2936c9b147aa6dfde3
func (d *Dictionary) Get(key string, prev *DictionaryEntry, flags DictionaryFlags) *DictionaryEntry {
ck := C.CString(key)
defer C.free(unsafe.Pointer(ck))
var cp *C.AVDictionaryEntry
if prev != nil {
cp = prev.c
}
if e := C.av_dict_get(d.c, ck, cp, C.int(flags)); e != nil {
return newDictionaryEntryFromC(e)
}
return nil
}
// https://ffmpeg.org/doxygen/7.0/group__lavu__dict.html#ga1bafd682b1fbb90e48a4cc3814b820f7
func (d *Dictionary) Free() {
C.av_dict_free(&d.c)
}
// https://ffmpeg.org/doxygen/7.0/group__lavc__packet.html#ga2d2c8e143a2c98cf0aa31b072c286186
func (d *Dictionary) Pack() []byte {
return bytesFromC(func(size *C.size_t) *C.uint8_t {
return C.av_packet_pack_dictionary(d.c, size)
})
}
// https://ffmpeg.org/doxygen/7.0/group__lavc__packet.html#gaae45c29cb3a29dc80b0b8f4ee9724492
func (d *Dictionary) Unpack(b []byte) error {
return bytesToC(b, func(b *C.uint8_t, size C.size_t) error {
return newError(C.av_packet_unpack_dictionary(b, size, &d.c))
})
}