Refactored parts of swscale, and filter packages

This commit is contained in:
H.G. Giorgis
2015-09-04 16:54:41 -04:00
parent 8733a06dd9
commit 725bc47296
6 changed files with 220 additions and 171 deletions
+1 -86
View File
@@ -91,21 +91,6 @@ func AvfilterRegisterAll() {
C.avfilter_register_all()
}
//Register a filter.
func AvfilterRegister(f *Filter) int {
return int(C.avfilter_register((*C.struct_AVFilter)(f)))
}
//Get a filter definition matching the given name.
func AvfilterGetByName(n string) *Filter {
return (*Filter)(C.avfilter_get_by_name(C.CString(n)))
}
//Iterate over all registered filters.
func AvfilterNext(f *Filter) *Filter {
return (*Filter)(C.avfilter_next((*C.struct_AVFilter)(f)))
}
//Initialize a filter with the supplied parameters.
func (ctx *Context) AvfilterInitStr(args string) int {
return int(C.avfilter_init_str((*C.struct_AVFilterContext)(ctx), C.CString(args)))
@@ -131,82 +116,12 @@ func AvfilterGetClass() *Class {
return (*Class)(C.avfilter_get_class())
}
//Allocate a filter graph.
func AvfilterGraphAlloc() *Graph {
return (*Graph)(C.avfilter_graph_alloc())
}
//Create a new filter instance in a filter graph.
func AvfilterGraphAllocFilter(g *Graph, f *Filter, n string) *Context {
return (*Context)(C.avfilter_graph_alloc_filter((*C.struct_AVFilterGraph)(g), (*C.struct_AVFilter)(f), C.CString(n)))
}
//Get a filter instance identified by instance name from graph.
func AvfilterGraphGetFilter(g *Graph, n string) *Context {
return (*Context)(C.avfilter_graph_get_filter((*C.struct_AVFilterGraph)(g), C.CString(n)))
}
//Create and add a filter instance into an existing graph.
func AvfilterGraphCreateFilter(cx **Context, f *Filter, n, a string, o int, g *Graph) int {
return int(C.avfilter_graph_create_filter((**C.struct_AVFilterContext)(unsafe.Pointer(cx)), (*C.struct_AVFilter)(f), C.CString(n), C.CString(a), unsafe.Pointer(&o), (*C.struct_AVFilterGraph)(g)))
}
//Enable or disable automatic format conversion inside the graph.
func AvfilterGraphSetAutoConvert(g *Graph, f uint) {
C.avfilter_graph_set_auto_convert((*C.struct_AVFilterGraph)(g), C.uint(f))
}
//Check validity and configure all the links and formats in the graph.
func AvfilterGraphConfig(g *Graph, l int) int {
return int(C.avfilter_graph_config((*C.struct_AVFilterGraph)(g), unsafe.Pointer(&l)))
}
//Free a graph, destroy its links, and set *graph to NULL.
func AvfilterGraphFree(g **Graph) {
C.avfilter_graph_free((**C.struct_AVFilterGraph)(unsafe.Pointer(g)))
}
//Allocate a single Input entry.
func AvfilterInoutAlloc() *Input {
return (*Input)(C.avfilter_inout_alloc())
}
//Free the supplied list of Input and set *inout to NULL.
func AvfilterInoutFree(i **Input) {
func AvfilterInoutFree(i *Input) {
C.avfilter_inout_free((**C.struct_AVFilterInOut)(unsafe.Pointer(i)))
}
//Add a graph described by a string to a graph.
func AvfilterGraphParse(g *Graph, f string, i, o *Input, l int) int {
return int(C.avfilter_graph_parse((*C.struct_AVFilterGraph)(g), C.CString(f), (*C.struct_AVFilterInOut)(i), (*C.struct_AVFilterInOut)(o), unsafe.Pointer(&l)))
}
//Add a graph described by a string to a graph.
func AvfilterGraphParsePtr(g *Graph, f string, i, o **Input, l int) int {
return int(C.avfilter_graph_parse_ptr((*C.struct_AVFilterGraph)(g), C.CString(f), (**C.struct_AVFilterInOut)(unsafe.Pointer(i)), (**C.struct_AVFilterInOut)(unsafe.Pointer(o)), unsafe.Pointer(&l)))
}
//Add a graph described by a string to a graph.
func AvfilterGraphParse2(g *Graph, f string, i, o **Input) int {
return int(C.avfilter_graph_parse2((*C.struct_AVFilterGraph)(g), C.CString(f), (**C.struct_AVFilterInOut)(unsafe.Pointer(i)), (**C.struct_AVFilterInOut)(unsafe.Pointer(o))))
}
//Send a command to one or more filter instances.
func AvfilterGraphSendCommand(g *Graph, t, cmd, arg, res string, resl, f int) int {
return int(C.avfilter_graph_send_command((*C.struct_AVFilterGraph)(g), C.CString(t), C.CString(cmd), C.CString(arg), C.CString(res), C.int(resl), C.int(f)))
}
//Queue a command for one or more filter instances.
func AvfilterGraphQueueCommand(g *Graph, t, cmd, arg string, f int, ts C.double) int {
return int(C.avfilter_graph_queue_command((*C.struct_AVFilterGraph)(g), C.CString(t), C.CString(cmd), C.CString(arg), C.int(f), ts))
}
//Dump a graph into a human-readable string representation.
func AvfilterGraphDump(g *Graph, o string) string {
return C.GoString(C.avfilter_graph_dump((*C.struct_AVFilterGraph)(g), C.CString(o)))
}
//Request a frame on the oldest sink
func AvfilterGraphRequestOldestlink(g *Graph) int {
return int(C.avfilter_graph_request_oldest((*C.struct_AVFilterGraph)(g)))
}
+26
View File
@@ -0,0 +1,26 @@
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
// Giorgis (habtom@giorgis.io)
// Filer Graphs
package avfilter
/*
#cgo pkg-config: libavfilter
#include <libavfilter/avfilter.h>
*/
import "C"
//Get a filter definition matching the given name.
func AvfilterGetByName(n string) *Filter {
return (*Filter)(C.avfilter_get_by_name(C.CString(n)))
}
//Register a filter.
func (f *Filter) AvfilterRegister() int {
return int(C.avfilter_register((*C.struct_AVFilter)(f)))
}
//Iterate over all registered filters.
func (f *Filter) AvfilterNext() *Filter {
return (*Filter)(C.avfilter_next((*C.struct_AVFilter)(f)))
}
+84
View File
@@ -0,0 +1,84 @@
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
// Giorgis (habtom@giorgis.io)
// Filer Graphs
package avfilter
/*
#cgo pkg-config: libavfilter
#include <libavfilter/avfilter.h>
*/
import "C"
import (
"unsafe"
)
//Allocate a filter graph.
func AvfilterGraphAlloc() *Graph {
return (*Graph)(C.avfilter_graph_alloc())
}
//Create a new filter instance in a filter graph.
func (g *Graph) AvfilterGraphAllocFilter(f *Filter, n string) *Context {
return (*Context)(C.avfilter_graph_alloc_filter((*C.struct_AVFilterGraph)(g), (*C.struct_AVFilter)(f), C.CString(n)))
}
//Get a filter instance identified by instance name from graph.
func (g *Graph) AvfilterGraphGetFilter(n string) *Context {
return (*Context)(C.avfilter_graph_get_filter((*C.struct_AVFilterGraph)(g), C.CString(n)))
}
//Enable or disable automatic format conversion inside the graph.
func (g *Graph) AvfilterGraphSetAutoConvert(f uint) {
C.avfilter_graph_set_auto_convert((*C.struct_AVFilterGraph)(g), C.uint(f))
}
//Check validity and configure all the links and formats in the graph.
func (g *Graph) AvfilterGraphConfig(l int) int {
return int(C.avfilter_graph_config((*C.struct_AVFilterGraph)(g), unsafe.Pointer(&l)))
}
//Free a graph, destroy its links, and set *graph to NULL.
func (g *Graph) AvfilterGraphFree() {
C.avfilter_graph_free((**C.struct_AVFilterGraph)(unsafe.Pointer(g)))
}
//Add a graph described by a string to a graph.
func (g *Graph) AvfilterGraphParse(f string, i, o *Input, l int) int {
return int(C.avfilter_graph_parse((*C.struct_AVFilterGraph)(g), C.CString(f), (*C.struct_AVFilterInOut)(i), (*C.struct_AVFilterInOut)(o), unsafe.Pointer(&l)))
}
//Add a graph described by a string to a graph.
func (g *Graph) AvfilterGraphParsePtr(f string, i, o **Input, l int) int {
return int(C.avfilter_graph_parse_ptr((*C.struct_AVFilterGraph)(g), C.CString(f), (**C.struct_AVFilterInOut)(unsafe.Pointer(i)), (**C.struct_AVFilterInOut)(unsafe.Pointer(o)), unsafe.Pointer(&l)))
}
//Add a graph described by a string to a graph.
func (g *Graph) AvfilterGraphParse2(f string, i, o **Input) int {
return int(C.avfilter_graph_parse2((*C.struct_AVFilterGraph)(g), C.CString(f), (**C.struct_AVFilterInOut)(unsafe.Pointer(i)), (**C.struct_AVFilterInOut)(unsafe.Pointer(o))))
}
//Send a command to one or more filter instances.
func (g *Graph) AvfilterGraphSendCommand(t, cmd, arg, res string, resl, f int) int {
return int(C.avfilter_graph_send_command((*C.struct_AVFilterGraph)(g), C.CString(t), C.CString(cmd), C.CString(arg), C.CString(res), C.int(resl), C.int(f)))
}
//Queue a command for one or more filter instances.
func (g *Graph) AvfilterGraphQueueCommand(t, cmd, arg string, f int, ts C.double) int {
return int(C.avfilter_graph_queue_command((*C.struct_AVFilterGraph)(g), C.CString(t), C.CString(cmd), C.CString(arg), C.int(f), ts))
}
//Dump a graph into a human-readable string representation.
func (g *Graph) AvfilterGraphDump(o string) string {
return C.GoString(C.avfilter_graph_dump((*C.struct_AVFilterGraph)(g), C.CString(o)))
}
//Request a frame on the oldest sink
func (g *Graph) AvfilterGraphRequestOldestlink() int {
return int(C.avfilter_graph_request_oldest((*C.struct_AVFilterGraph)(g)))
}
//Create and add a filter instance into an existing graph.
func AvfilterGraphCreateFilter(cx **Context, f *Filter, n, a string, o int, g *Graph) int {
return int(C.avfilter_graph_create_filter((**C.struct_AVFilterContext)(unsafe.Pointer(cx)), (*C.struct_AVFilter)(f), C.CString(n), C.CString(a), unsafe.Pointer(&o), (*C.struct_AVFilterGraph)(g)))
}
+37
View File
@@ -0,0 +1,37 @@
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
// Giorgis (habtom@giorgis.io)
//sws conttext
package swscale
//#cgo pkg-config: libswscale libavutil
//#include <libswscale/swscale.h>
import "C"
import (
"unsafe"
)
//Allocate an empty Context.
func SwsAllocContext() *Context {
return (*Context)(C.sws_alloc_context())
}
//Initialize the swscaler context sws_context.
func SwsInitContext(ctxt *Context, sf, df *Filter) int {
return int(C.sws_init_context((*C.struct_SwsContext)(ctxt), (*C.struct_SwsFilter)(sf), (*C.struct_SwsFilter)(df)))
}
//Free the swscaler context swsContext.
func SwsFreecontext(ctxt *Context) {
C.sws_freeContext((*C.struct_SwsContext)(ctxt))
}
//Allocate and return an Context.
func SwsGetcontext(sw, sh int, sf PixelFormat, dw, dh int, df PixelFormat, f int, sfl, dfl *Filter, p *int) *Context {
return (*Context)(C.sws_getContext(C.int(sw), C.int(sh), (C.enum_AVPixelFormat)(sf), C.int(dw), C.int(dh), (C.enum_AVPixelFormat)(df), C.int(f), (*C.struct_SwsFilter)(sfl), (*C.struct_SwsFilter)(dfl), (*C.double)(unsafe.Pointer(p))))
}
//Check if context can be reused, otherwise reallocate a new one.
func SwsGetcachedcontext(ctxt *Context, sw, sh int, sf PixelFormat, dw, dh int, df PixelFormat, f int, sfl, dfl *Filter, p *float64) *Context {
return (*Context)(C.sws_getCachedContext((*C.struct_SwsContext)(ctxt), C.int(sw), C.int(sh), (C.enum_AVPixelFormat)(sf), C.int(dw), C.int(dh), (C.enum_AVPixelFormat)(df), C.int(f), (*C.struct_SwsFilter)(sfl), (*C.struct_SwsFilter)(dfl), (*C.double)(p)))
}
-85
View File
@@ -60,26 +60,6 @@ func SwsIssupportedendiannessconversion(p PixelFormat) int {
return int(C.sws_isSupportedEndiannessConversion((C.enum_AVPixelFormat)(p)))
}
//Allocate an empty Context.
func SwsAllocContext() *Context {
return (*Context)(C.sws_alloc_context())
}
//Initialize the swscaler context sws_context.
func SwsInitContext(ctxt *Context, sf, df *Filter) int {
return int(C.sws_init_context((*C.struct_SwsContext)(ctxt), (*C.struct_SwsFilter)(sf), (*C.struct_SwsFilter)(df)))
}
//Free the swscaler context swsContext.
func SwsFreecontext(ctxt *Context) {
C.sws_freeContext((*C.struct_SwsContext)(ctxt))
}
//Allocate and return an Context.
func SwsGetcontext(sw, sh int, sf PixelFormat, dw, dh int, df PixelFormat, f int, sfl, dfl *Filter, p *int) *Context {
return (*Context)(C.sws_getContext(C.int(sw), C.int(sh), (C.enum_AVPixelFormat)(sf), C.int(dw), C.int(dh), (C.enum_AVPixelFormat)(df), C.int(f), (*C.struct_SwsFilter)(sfl), (*C.struct_SwsFilter)(dfl), (*C.double)(unsafe.Pointer(p))))
}
////Scale the image slice in srcSlice and put the resulting scaled slice in the image in dst.
func SwsScale(ctxt *Context, src *uint8, str int, y, h int, d *uint8, ds int) int {
cctxt := (*C.struct_SwsContext)(unsafe.Pointer(ctxt))
@@ -107,66 +87,6 @@ func SwsGetcolorspacedetails(ctxt *Context, it, sr, t, dr, b, c, s *int) int {
return int(C.sws_getColorspaceDetails((*C.struct_SwsContext)(ctxt), cit, csr, ct, cdr, cb, cc, cs))
}
//Allocate and return an uninitialized vector with length coefficients.
func SwsAllocvec(l int) *Vector {
return (*Vector)(C.sws_allocVec(C.int(l)))
}
//Return a normalized Gaussian curve used to filter stuff quality = 3 is high quality, lower is lower quality.
func SwsGetgaussianvec(v, q float64) *Vector {
return (*Vector)(unsafe.Pointer(C.sws_getGaussianVec(C.double(v), C.double(q))))
}
//Allocate and return a vector with length coefficients, all with the same value c.
func SwsGetconstvec(c float64, l int) *Vector {
return (*Vector)(unsafe.Pointer(C.sws_getConstVec(C.double(c), C.int(l))))
}
//Allocate and return a vector with just one coefficient, with value 1.0.
func SwsGetidentityvec() *Vector {
return (*Vector)(unsafe.Pointer(C.sws_getIdentityVec()))
}
//Scale all the coefficients of a by the scalar value.
func SwsScalevec(a *Vector, s float64) {
C.sws_scaleVec((*C.struct_SwsVector)(unsafe.Pointer(a)), C.double(s))
}
//Scale all the coefficients of a so that their sum equals height.
func SwsNormalizevec(a *Vector, h float64) {
C.sws_normalizeVec((*C.struct_SwsVector)(a), C.double(h))
}
func SwsConvvec(a, b *Vector) {
C.sws_convVec((*C.struct_SwsVector)(a), (*C.struct_SwsVector)(b))
}
func SwsAddvec(a, b *Vector) {
C.sws_addVec((*C.struct_SwsVector)(a), (*C.struct_SwsVector)(b))
}
func SwsSubvec(a, b *Vector) {
C.sws_subVec((*C.struct_SwsVector)(a), (*C.struct_SwsVector)(b))
}
func SwsShiftvec(a *Vector, s int) {
C.sws_shiftVec((*C.struct_SwsVector)(a), C.int(s))
}
//Allocate and return a clone of the vector a, that is a vector with the same coefficients as a.
func SwsClonevec(a *Vector) *Vector {
return (*Vector)(unsafe.Pointer(C.sws_cloneVec((*C.struct_SwsVector)(a))))
}
//Print with av_log() a textual representation of the vector a if log_level <= av_log_level.
func SwsPrintvec2(a *Vector, lctx *Class, l int) {
C.sws_printVec2((*C.struct_SwsVector)(a), (*C.struct_AVClass)(lctx), C.int(l))
}
func SwsFreevec(a *Vector) {
C.sws_freeVec((*C.struct_SwsVector)(a))
}
func SwsGetdefaultfilter(lb, cb, ls, cs, chs, cvs float32, v int) *Filter {
return (*Filter)(unsafe.Pointer(C.sws_getDefaultFilter(C.float(lb), C.float(cb), C.float(ls), C.float(cs), C.float(chs), C.float(cvs), C.int(v))))
}
@@ -175,11 +95,6 @@ func SwsFreefilter(f *Filter) {
C.sws_freeFilter((*C.struct_SwsFilter)(f))
}
//Check if context can be reused, otherwise reallocate a new one.
func SwsGetcachedcontext(ctxt *Context, sw, sh int, sf PixelFormat, dw, dh int, df PixelFormat, f int, sfl, dfl *Filter, p *float64) *Context {
return (*Context)(C.sws_getCachedContext((*C.struct_SwsContext)(ctxt), C.int(sw), C.int(sh), (C.enum_AVPixelFormat)(sf), C.int(dw), C.int(dh), (C.enum_AVPixelFormat)(df), C.int(f), (*C.struct_SwsFilter)(sfl), (*C.struct_SwsFilter)(dfl), (*C.double)(p)))
}
//Convert an 8-bit paletted frame into a frame with a color depth of 32 bits.
func SwsConvertpalette8topacked32(s, d *uint8, px int, p *uint8) {
C.sws_convertPalette8ToPacked32((*C.uint8_t)(s), (*C.uint8_t)(d), C.int(px), (*C.uint8_t)(p))
+72
View File
@@ -0,0 +1,72 @@
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
// Giorgis (habtom@giorgis.io)
//sws conttext
package swscale
//#cgo pkg-config: libswscale libavutil
//#include <libswscale/swscale.h>
import "C"
import (
"unsafe"
)
//Allocate and return an uninitialized vector with length coefficients.
func SwsAllocvec(l int) *Vector {
return (*Vector)(C.sws_allocVec(C.int(l)))
}
//Return a normalized Gaussian curve used to filter stuff quality = 3 is high quality, lower is lower quality.
func SwsGetgaussianvec(v, q float64) *Vector {
return (*Vector)(unsafe.Pointer(C.sws_getGaussianVec(C.double(v), C.double(q))))
}
//Allocate and return a vector with length coefficients, all with the same value c.
func SwsGetconstvec(c float64, l int) *Vector {
return (*Vector)(unsafe.Pointer(C.sws_getConstVec(C.double(c), C.int(l))))
}
//Allocate and return a vector with just one coefficient, with value 1.0.
func SwsGetidentityvec() *Vector {
return (*Vector)(unsafe.Pointer(C.sws_getIdentityVec()))
}
//Scale all the coefficients of a by the scalar value.
func (a *Vector) SwsScalevec(s float64) {
C.sws_scaleVec((*C.struct_SwsVector)(unsafe.Pointer(a)), C.double(s))
}
//Scale all the coefficients of a so that their sum equals height.
func (a *Vector) SwsNormalizevec(h float64) {
C.sws_normalizeVec((*C.struct_SwsVector)(a), C.double(h))
}
func (a *Vector) SwsConvvec(b *Vector) {
C.sws_convVec((*C.struct_SwsVector)(a), (*C.struct_SwsVector)(b))
}
func (a *Vector) SwsAddvec(b *Vector) {
C.sws_addVec((*C.struct_SwsVector)(a), (*C.struct_SwsVector)(b))
}
func (a *Vector) SwsSubvec(b *Vector) {
C.sws_subVec((*C.struct_SwsVector)(a), (*C.struct_SwsVector)(b))
}
func (a *Vector) SwsShiftvec(s int) {
C.sws_shiftVec((*C.struct_SwsVector)(a), C.int(s))
}
//Allocate and return a clone of the vector a, that is a vector with the same coefficients as a.
func (a *Vector) SwsClonevec() *Vector {
return (*Vector)(unsafe.Pointer(C.sws_cloneVec((*C.struct_SwsVector)(a))))
}
//Print with av_log() a textual representation of the vector a if log_level <= av_log_level.
func (a *Vector) SwsPrintvec2(lctx *Class, l int) {
C.sws_printVec2((*C.struct_SwsVector)(a), (*C.struct_AVClass)(lctx), C.int(l))
}
func (a *Vector) SwsFreevec() {
C.sws_freeVec((*C.struct_SwsVector)(a))
}