-
Notifications
You must be signed in to change notification settings - Fork 171
Expand file tree
/
Copy pathdict.go
More file actions
43 lines (31 loc) · 652 Bytes
/
dict.go
File metadata and controls
43 lines (31 loc) · 652 Bytes
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
package gmf
/*
#cgo pkg-config: libavutil
#include "stdlib.h"
#include "libavutil/dict.h"
*/
import "C"
import (
"log"
"unsafe"
)
type Pair struct {
Key string
Val string
}
type Dict struct {
avDict *C.struct_AVDictionary
}
func NewDict(pairs []Pair) *Dict {
this := &Dict{avDict: nil}
for _, pair := range pairs {
ckey := C.CString(pair.Key)
cval := C.CString(pair.Val)
if ret := C.av_dict_set(&this.avDict, ckey, cval, 0); int(ret) < 0 {
log.Printf("unable to set key '%v' value '%v', error: %s\n", pair.Key, pair.Val, AvError(int(ret)))
}
C.free(unsafe.Pointer(ckey))
C.free(unsafe.Pointer(cval))
}
return this
}