mirror of
https://github.com/giorgisio/goav.git
synced 2026-10-19 16:14:41 +00:00
Add bindings for avutil AVDictionary and AVDictionaryEntry.
This commit is contained in:
+2
-2
@@ -89,7 +89,7 @@ func (s *Context) AvNewProgram(id int) *AvProgram {
|
||||
}
|
||||
|
||||
//Read packets of a media file to get stream information.
|
||||
func (s *Context) AvformatFindStreamInfo(d **Dictionary) int {
|
||||
func (s *Context) AvformatFindStreamInfo(d **avutil.Dictionary) int {
|
||||
return int(C.avformat_find_stream_info((*C.struct_AVFormatContext)(s), (**C.struct_AVDictionary)(unsafe.Pointer(d))))
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ func (s *Context) AvformatCloseInput() {
|
||||
}
|
||||
|
||||
//Allocate the stream private data and write the stream header to an output media file.
|
||||
func (s *Context) AvformatWriteHeader(o **Dictionary) int {
|
||||
func (s *Context) AvformatWriteHeader(o **avutil.Dictionary) int {
|
||||
return int(C.avformat_write_header((*C.struct_AVFormatContext)(s), (**C.struct_AVDictionary)(unsafe.Pointer(o))))
|
||||
}
|
||||
|
||||
|
||||
@@ -27,8 +27,8 @@ func (ctxt *Context) VideoCodec() *AvCodec {
|
||||
return (*AvCodec)(unsafe.Pointer(ctxt.video_codec))
|
||||
}
|
||||
|
||||
func (ctxt *Context) Metadata() *Dictionary {
|
||||
return (*Dictionary)(unsafe.Pointer(ctxt.metadata))
|
||||
func (ctxt *Context) Metadata() *avutil.Dictionary {
|
||||
return (*avutil.Dictionary)(unsafe.Pointer(ctxt.metadata))
|
||||
}
|
||||
|
||||
func (ctxt *Context) Internal() *AvFormatInternal {
|
||||
|
||||
@@ -20,8 +20,8 @@ func (avs *Stream) Codec() *CodecContext {
|
||||
return (*CodecContext)(unsafe.Pointer(avs.codec))
|
||||
}
|
||||
|
||||
func (avs *Stream) Metadata() *Dictionary {
|
||||
return (*Dictionary)(unsafe.Pointer(avs.metadata))
|
||||
func (avs *Stream) Metadata() *avutil.Dictionary {
|
||||
return (*avutil.Dictionary)(unsafe.Pointer(avs.metadata))
|
||||
}
|
||||
|
||||
func (avs *Stream) IndexEntries() *AvIndexEntry {
|
||||
|
||||
@@ -17,7 +17,6 @@ import (
|
||||
|
||||
type (
|
||||
Options C.struct_AVOptions
|
||||
Dictionary C.struct_AVDictionary
|
||||
AvTree C.struct_AVTree
|
||||
Rational C.struct_AVRational
|
||||
MediaType C.enum_AVMediaType
|
||||
|
||||
+133
@@ -0,0 +1,133 @@
|
||||
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
|
||||
// Giorgis (habtom@giorgis.io)
|
||||
|
||||
// Package avutil is a utility library to aid portable multimedia programming.
|
||||
// It contains safe portable string functions, random number generators, data structures,
|
||||
// additional mathematics functions, cryptography and multimedia related functionality.
|
||||
// Some generic features and utilities provided by the libavutil library
|
||||
package avutil
|
||||
|
||||
//#cgo pkg-config: libavutil
|
||||
//#include <libavutil/avutil.h>
|
||||
//#include <libavutil/dict.h>
|
||||
//#include <stdlib.h>
|
||||
import "C"
|
||||
import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
type (
|
||||
Dictionary C.struct_AVDictionary
|
||||
DictionaryEntry C.struct_AVDictionaryEntry
|
||||
)
|
||||
|
||||
const (
|
||||
AV_DICT_MATCH_CASE = int(C.AV_DICT_MATCH_CASE)
|
||||
AV_DICT_IGNORE_SUFFIX = int(C.AV_DICT_IGNORE_SUFFIX)
|
||||
AV_DICT_DONT_STRDUP_KEY = int(C.AV_DICT_DONT_STRDUP_KEY)
|
||||
AV_DICT_DONT_STRDUP_VAL = int(C.AV_DICT_DONT_STRDUP_VAL)
|
||||
AV_DICT_DONT_OVERWRITE = int(C.AV_DICT_DONT_OVERWRITE)
|
||||
AV_DICT_APPEND = int(C.AV_DICT_APPEND)
|
||||
AV_DICT_MULTIKEY = int(C.AV_DICT_MULTIKEY)
|
||||
)
|
||||
|
||||
func (d *Dictionary) AvDictGet(key string, prev *DictionaryEntry, flags int) *DictionaryEntry {
|
||||
Ckey := C.CString(key)
|
||||
defer C.free(unsafe.Pointer(Ckey))
|
||||
|
||||
return (*DictionaryEntry)(C.av_dict_get(
|
||||
(*C.struct_AVDictionary)(d),
|
||||
Ckey,
|
||||
(*C.struct_AVDictionaryEntry)(prev),
|
||||
C.int(flags),
|
||||
))
|
||||
}
|
||||
|
||||
func (d *Dictionary) AvDictCount() int {
|
||||
return int(C.av_dict_count((*C.struct_AVDictionary)(d)))
|
||||
}
|
||||
|
||||
func (d *Dictionary) AvDictSet(key, value string, flags int) int {
|
||||
Ckey := C.CString(key)
|
||||
defer C.free(unsafe.Pointer(Ckey))
|
||||
|
||||
Cvalue := C.CString(value)
|
||||
defer C.free(unsafe.Pointer(Cvalue))
|
||||
|
||||
return int(C.av_dict_set(
|
||||
(**C.struct_AVDictionary)(unsafe.Pointer(&d)),
|
||||
Ckey,
|
||||
Cvalue,
|
||||
C.int(flags),
|
||||
))
|
||||
}
|
||||
|
||||
func (d *Dictionary) AvDictSetInt(key string, value int64, flags int) int {
|
||||
Ckey := C.CString(key)
|
||||
defer C.free(unsafe.Pointer(Ckey))
|
||||
|
||||
return int(C.av_dict_set_int(
|
||||
(**C.struct_AVDictionary)(unsafe.Pointer(&d)),
|
||||
Ckey,
|
||||
C.int64_t(value),
|
||||
C.int(flags),
|
||||
))
|
||||
}
|
||||
|
||||
func (d *Dictionary) AvDictParseString(str, key_val_sep, pairs_sep string, flags int) int {
|
||||
Cstr := C.CString(str)
|
||||
defer C.free(unsafe.Pointer(Cstr))
|
||||
|
||||
Ckey_val_sep := C.CString(key_val_sep)
|
||||
defer C.free(unsafe.Pointer(Ckey_val_sep))
|
||||
|
||||
Cpairs_sep := C.CString(pairs_sep)
|
||||
defer C.free(unsafe.Pointer(Cpairs_sep))
|
||||
|
||||
return int(C.av_dict_parse_string(
|
||||
(**C.struct_AVDictionary)(unsafe.Pointer(&d)),
|
||||
Cstr,
|
||||
Ckey_val_sep,
|
||||
Cpairs_sep,
|
||||
C.int(flags),
|
||||
))
|
||||
}
|
||||
|
||||
func (d *Dictionary) AvDictCopy(src *Dictionary, flags int) int {
|
||||
return int(C.av_dict_copy(
|
||||
(**C.struct_AVDictionary)(unsafe.Pointer(&d)),
|
||||
(*C.struct_AVDictionary)(unsafe.Pointer(src)),
|
||||
C.int(flags),
|
||||
))
|
||||
}
|
||||
|
||||
func (d *Dictionary) AvDictFree() {
|
||||
C.av_dict_free((**C.struct_AVDictionary)(unsafe.Pointer(&d)))
|
||||
}
|
||||
|
||||
func (d *Dictionary) AvDictGetString(key_val_sep, pairs_sep byte) (int, string) {
|
||||
var Cbuf *C.char
|
||||
|
||||
ret := int(C.av_dict_get_string(
|
||||
(*C.struct_AVDictionary)(d),
|
||||
(**C.char)(&Cbuf),
|
||||
C.char(key_val_sep),
|
||||
C.char(pairs_sep),
|
||||
))
|
||||
|
||||
var buf string
|
||||
if ret == 0 {
|
||||
buf = C.GoString(Cbuf)
|
||||
C.free(unsafe.Pointer(Cbuf))
|
||||
}
|
||||
|
||||
return ret, buf
|
||||
}
|
||||
|
||||
func (d *DictionaryEntry) Key() string {
|
||||
return C.GoString(d.key)
|
||||
}
|
||||
|
||||
func (d *DictionaryEntry) Value() string {
|
||||
return C.GoString(d.value)
|
||||
}
|
||||
Reference in New Issue
Block a user