diff --git a/bit_stream_filter.go b/bit_stream_filter.go index dccdd0c..9930b98 100644 --- a/bit_stream_filter.go +++ b/bit_stream_filter.go @@ -9,10 +9,10 @@ import ( // https://github.com/FFmpeg/FFmpeg/blob/release/5.1/libavcodec/bsf.h#L111 type BitStreamFilter struct { - c *C.struct_AVBitStreamFilter + c *C.AVBitStreamFilter } -func newBitStreamFilterFromC(c *C.struct_AVBitStreamFilter) *BitStreamFilter { +func newBitStreamFilterFromC(c *C.AVBitStreamFilter) *BitStreamFilter { if c == nil { return nil } diff --git a/bit_stream_filter_context.go b/bit_stream_filter_context.go index 65aeda1..39f1d4e 100644 --- a/bit_stream_filter_context.go +++ b/bit_stream_filter_context.go @@ -9,10 +9,10 @@ import ( // https://github.com/FFmpeg/FFmpeg/blob/release/5.1/libavcodec/bsf.h#L68 type BitStreamFilterContext struct { - c *C.struct_AVBSFContext + c *C.AVBSFContext } -func newBSFContextFromC(c *C.struct_AVBSFContext) *BitStreamFilterContext { +func newBSFContextFromC(c *C.AVBSFContext) *BitStreamFilterContext { if c == nil { return nil } @@ -28,7 +28,7 @@ func AllocBitStreamFilterContext(f *BitStreamFilter) (*BitStreamFilterContext, e return nil, errors.New("astiav: bit stream filter must not be nil") } - var bsfc *C.struct_AVBSFContext + var bsfc *C.AVBSFContext if err := newError(C.av_bsf_alloc(f.c, &bsfc)); err != nil { return nil, err } @@ -45,7 +45,7 @@ func (bsfc *BitStreamFilterContext) Initialize() error { } func (bsfc *BitStreamFilterContext) SendPacket(p *Packet) error { - var pc *C.struct_AVPacket + var pc *C.AVPacket if p != nil { pc = p.c } diff --git a/channel_layout.go b/channel_layout.go index 13181f3..9e626bc 100644 --- a/channel_layout.go +++ b/channel_layout.go @@ -1,96 +1,54 @@ package astiav -//#include -/* - -// Calling C.AV_CHANNEL_LAYOUT_* in Go gives a "could not determine kind of name for X" error -// therefore we need to bridge the channel layout values -AVChannelLayout *c2goChannelLayoutMono = &(AVChannelLayout)AV_CHANNEL_LAYOUT_MONO; -AVChannelLayout *c2goChannelLayoutStereo = &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO; -AVChannelLayout *c2goChannelLayout2Point1 = &(AVChannelLayout)AV_CHANNEL_LAYOUT_2POINT1; -AVChannelLayout *c2goChannelLayout21 = &(AVChannelLayout)AV_CHANNEL_LAYOUT_2_1; -AVChannelLayout *c2goChannelLayoutSurround = &(AVChannelLayout)AV_CHANNEL_LAYOUT_SURROUND; -AVChannelLayout *c2goChannelLayout3Point1 = &(AVChannelLayout)AV_CHANNEL_LAYOUT_3POINT1; -AVChannelLayout *c2goChannelLayout4Point0 = &(AVChannelLayout)AV_CHANNEL_LAYOUT_4POINT0; -AVChannelLayout *c2goChannelLayout4Point1 = &(AVChannelLayout)AV_CHANNEL_LAYOUT_4POINT1; -AVChannelLayout *c2goChannelLayout22 = &(AVChannelLayout)AV_CHANNEL_LAYOUT_2_2; -AVChannelLayout *c2goChannelLayoutQuad = &(AVChannelLayout)AV_CHANNEL_LAYOUT_QUAD; -AVChannelLayout *c2goChannelLayout5Point0 = &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT0; -AVChannelLayout *c2goChannelLayout5Point1 = &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT1; -AVChannelLayout *c2goChannelLayout5Point0Back = &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT0_BACK; -AVChannelLayout *c2goChannelLayout5Point1Back = &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT1_BACK; -AVChannelLayout *c2goChannelLayout6Point0 = &(AVChannelLayout)AV_CHANNEL_LAYOUT_6POINT0; -AVChannelLayout *c2goChannelLayout6Point0Front = &(AVChannelLayout)AV_CHANNEL_LAYOUT_6POINT0_FRONT; -AVChannelLayout *c2goChannelLayoutHexagonal = &(AVChannelLayout)AV_CHANNEL_LAYOUT_HEXAGONAL; -AVChannelLayout *c2goChannelLayout3Point1Point2 = &(AVChannelLayout)AV_CHANNEL_LAYOUT_3POINT1POINT2; -AVChannelLayout *c2goChannelLayout6Point1 = &(AVChannelLayout)AV_CHANNEL_LAYOUT_6POINT1; -AVChannelLayout *c2goChannelLayout6Point1Back = &(AVChannelLayout)AV_CHANNEL_LAYOUT_6POINT1_BACK; -AVChannelLayout *c2goChannelLayout6Point1Front = &(AVChannelLayout)AV_CHANNEL_LAYOUT_6POINT1_FRONT; -AVChannelLayout *c2goChannelLayout7Point0 = &(AVChannelLayout)AV_CHANNEL_LAYOUT_7POINT0; -AVChannelLayout *c2goChannelLayout7Point0Front = &(AVChannelLayout)AV_CHANNEL_LAYOUT_7POINT0_FRONT; -AVChannelLayout *c2goChannelLayout7Point1 = &(AVChannelLayout)AV_CHANNEL_LAYOUT_7POINT1; -AVChannelLayout *c2goChannelLayout7Point1Wide = &(AVChannelLayout)AV_CHANNEL_LAYOUT_7POINT1_WIDE; -AVChannelLayout *c2goChannelLayout7Point1WideBack = &(AVChannelLayout)AV_CHANNEL_LAYOUT_7POINT1_WIDE_BACK; -AVChannelLayout *c2goChannelLayout5Point1Point2Back = &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT1POINT2_BACK; -AVChannelLayout *c2goChannelLayoutOctagonal = &(AVChannelLayout)AV_CHANNEL_LAYOUT_OCTAGONAL; -AVChannelLayout *c2goChannelLayoutCube = &(AVChannelLayout)AV_CHANNEL_LAYOUT_CUBE; -AVChannelLayout *c2goChannelLayout5Point1Point4Back = &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT1POINT4_BACK; -AVChannelLayout *c2goChannelLayout7Point1Point2 = &(AVChannelLayout)AV_CHANNEL_LAYOUT_7POINT1POINT2; -AVChannelLayout *c2goChannelLayout7Point1Point4Back = &(AVChannelLayout)AV_CHANNEL_LAYOUT_7POINT1POINT4_BACK; -AVChannelLayout *c2goChannelLayoutHexadecagonal = &(AVChannelLayout)AV_CHANNEL_LAYOUT_HEXADECAGONAL; -AVChannelLayout *c2goChannelLayoutStereoDownmix = &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO_DOWNMIX; -AVChannelLayout *c2goChannelLayout22Point2 = &(AVChannelLayout)AV_CHANNEL_LAYOUT_22POINT2; -AVChannelLayout *c2goChannelLayout7Point1TopBack = &(AVChannelLayout)AV_CHANNEL_LAYOUT_7POINT1_TOP_BACK; - -*/ +//#include "channel_layout.h" import "C" import "unsafe" // https://github.com/FFmpeg/FFmpeg/blob/n5.0/libavutil/channel_layout.h#L90 var ( - ChannelLayoutMono = newChannelLayoutFromC(C.c2goChannelLayoutMono) - ChannelLayoutStereo = newChannelLayoutFromC(C.c2goChannelLayoutStereo) - ChannelLayout2Point1 = newChannelLayoutFromC(C.c2goChannelLayout2Point1) - ChannelLayout21 = newChannelLayoutFromC(C.c2goChannelLayout21) - ChannelLayoutSurround = newChannelLayoutFromC(C.c2goChannelLayoutSurround) - ChannelLayout3Point1 = newChannelLayoutFromC(C.c2goChannelLayout3Point1) - ChannelLayout4Point0 = newChannelLayoutFromC(C.c2goChannelLayout4Point0) - ChannelLayout4Point1 = newChannelLayoutFromC(C.c2goChannelLayout4Point1) - ChannelLayout22 = newChannelLayoutFromC(C.c2goChannelLayout22) - ChannelLayoutQuad = newChannelLayoutFromC(C.c2goChannelLayoutQuad) - ChannelLayout5Point0 = newChannelLayoutFromC(C.c2goChannelLayout5Point0) - ChannelLayout5Point1 = newChannelLayoutFromC(C.c2goChannelLayout5Point1) - ChannelLayout5Point0Back = newChannelLayoutFromC(C.c2goChannelLayout5Point0Back) - ChannelLayout5Point1Back = newChannelLayoutFromC(C.c2goChannelLayout5Point1Back) - ChannelLayout6Point0 = newChannelLayoutFromC(C.c2goChannelLayout6Point0) - ChannelLayout6Point0Front = newChannelLayoutFromC(C.c2goChannelLayout6Point0Front) - ChannelLayoutHexagonal = newChannelLayoutFromC(C.c2goChannelLayoutHexagonal) - ChannelLayout3Point1Point2 = newChannelLayoutFromC(C.c2goChannelLayout3Point1Point2) - ChannelLayout6Point1 = newChannelLayoutFromC(C.c2goChannelLayout6Point1) - ChannelLayout6Point1Back = newChannelLayoutFromC(C.c2goChannelLayout6Point1Back) - ChannelLayout6Point1Front = newChannelLayoutFromC(C.c2goChannelLayout6Point1Front) - ChannelLayout7Point0 = newChannelLayoutFromC(C.c2goChannelLayout7Point0) - ChannelLayout7Point0Front = newChannelLayoutFromC(C.c2goChannelLayout7Point0Front) - ChannelLayout7Point1 = newChannelLayoutFromC(C.c2goChannelLayout7Point1) - ChannelLayout7Point1Wide = newChannelLayoutFromC(C.c2goChannelLayout7Point1Wide) - ChannelLayout7Point1WideBack = newChannelLayoutFromC(C.c2goChannelLayout7Point1WideBack) - ChannelLayout5Point1Point2Back = newChannelLayoutFromC(C.c2goChannelLayout5Point1Point2Back) - ChannelLayoutOctagonal = newChannelLayoutFromC(C.c2goChannelLayoutOctagonal) - ChannelLayoutCube = newChannelLayoutFromC(C.c2goChannelLayoutCube) - ChannelLayout5Point1Point4Back = newChannelLayoutFromC(C.c2goChannelLayout5Point1Point4Back) - ChannelLayout7Point1Point2 = newChannelLayoutFromC(C.c2goChannelLayout7Point1Point2) - ChannelLayout7Point1Point4Back = newChannelLayoutFromC(C.c2goChannelLayout7Point1Point4Back) - ChannelLayoutHexadecagonal = newChannelLayoutFromC(C.c2goChannelLayoutHexadecagonal) - ChannelLayoutStereoDownmix = newChannelLayoutFromC(C.c2goChannelLayoutStereoDownmix) - ChannelLayout22Point2 = newChannelLayoutFromC(C.c2goChannelLayout22Point2) - ChannelLayout7Point1TopBack = newChannelLayoutFromC(C.c2goChannelLayout7Point1TopBack) + ChannelLayoutMono = newChannelLayoutFromC(C.astiavChannelLayoutMono) + ChannelLayoutStereo = newChannelLayoutFromC(C.astiavChannelLayoutStereo) + ChannelLayout2Point1 = newChannelLayoutFromC(C.astiavChannelLayout2Point1) + ChannelLayout21 = newChannelLayoutFromC(C.astiavChannelLayout21) + ChannelLayoutSurround = newChannelLayoutFromC(C.astiavChannelLayoutSurround) + ChannelLayout3Point1 = newChannelLayoutFromC(C.astiavChannelLayout3Point1) + ChannelLayout4Point0 = newChannelLayoutFromC(C.astiavChannelLayout4Point0) + ChannelLayout4Point1 = newChannelLayoutFromC(C.astiavChannelLayout4Point1) + ChannelLayout22 = newChannelLayoutFromC(C.astiavChannelLayout22) + ChannelLayoutQuad = newChannelLayoutFromC(C.astiavChannelLayoutQuad) + ChannelLayout5Point0 = newChannelLayoutFromC(C.astiavChannelLayout5Point0) + ChannelLayout5Point1 = newChannelLayoutFromC(C.astiavChannelLayout5Point1) + ChannelLayout5Point0Back = newChannelLayoutFromC(C.astiavChannelLayout5Point0Back) + ChannelLayout5Point1Back = newChannelLayoutFromC(C.astiavChannelLayout5Point1Back) + ChannelLayout6Point0 = newChannelLayoutFromC(C.astiavChannelLayout6Point0) + ChannelLayout6Point0Front = newChannelLayoutFromC(C.astiavChannelLayout6Point0Front) + ChannelLayoutHexagonal = newChannelLayoutFromC(C.astiavChannelLayoutHexagonal) + ChannelLayout3Point1Point2 = newChannelLayoutFromC(C.astiavChannelLayout3Point1Point2) + ChannelLayout6Point1 = newChannelLayoutFromC(C.astiavChannelLayout6Point1) + ChannelLayout6Point1Back = newChannelLayoutFromC(C.astiavChannelLayout6Point1Back) + ChannelLayout6Point1Front = newChannelLayoutFromC(C.astiavChannelLayout6Point1Front) + ChannelLayout7Point0 = newChannelLayoutFromC(C.astiavChannelLayout7Point0) + ChannelLayout7Point0Front = newChannelLayoutFromC(C.astiavChannelLayout7Point0Front) + ChannelLayout7Point1 = newChannelLayoutFromC(C.astiavChannelLayout7Point1) + ChannelLayout7Point1Wide = newChannelLayoutFromC(C.astiavChannelLayout7Point1Wide) + ChannelLayout7Point1WideBack = newChannelLayoutFromC(C.astiavChannelLayout7Point1WideBack) + ChannelLayout5Point1Point2Back = newChannelLayoutFromC(C.astiavChannelLayout5Point1Point2Back) + ChannelLayoutOctagonal = newChannelLayoutFromC(C.astiavChannelLayoutOctagonal) + ChannelLayoutCube = newChannelLayoutFromC(C.astiavChannelLayoutCube) + ChannelLayout5Point1Point4Back = newChannelLayoutFromC(C.astiavChannelLayout5Point1Point4Back) + ChannelLayout7Point1Point2 = newChannelLayoutFromC(C.astiavChannelLayout7Point1Point2) + ChannelLayout7Point1Point4Back = newChannelLayoutFromC(C.astiavChannelLayout7Point1Point4Back) + ChannelLayoutHexadecagonal = newChannelLayoutFromC(C.astiavChannelLayoutHexadecagonal) + ChannelLayoutStereoDownmix = newChannelLayoutFromC(C.astiavChannelLayoutStereoDownmix) + ChannelLayout22Point2 = newChannelLayoutFromC(C.astiavChannelLayout22Point2) + ChannelLayout7Point1TopBack = newChannelLayoutFromC(C.astiavChannelLayout7Point1TopBack) ) type ChannelLayout struct { - c *C.struct_AVChannelLayout + c *C.AVChannelLayout } -func newChannelLayoutFromC(c *C.struct_AVChannelLayout) ChannelLayout { +func newChannelLayoutFromC(c *C.AVChannelLayout) ChannelLayout { return ChannelLayout{c: c} } @@ -135,12 +93,12 @@ func (l ChannelLayout) Equal(l2 ChannelLayout) bool { return v } -func (l ChannelLayout) copy(dst *C.struct_AVChannelLayout) error { +func (l ChannelLayout) copy(dst *C.AVChannelLayout) error { return newError(C.av_channel_layout_copy(dst, l.c)) } func (l ChannelLayout) clone() (ChannelLayout, error) { - var cl C.struct_AVChannelLayout + var cl C.AVChannelLayout err := l.copy(&cl) dst := newChannelLayoutFromC(&cl) return dst, err diff --git a/channel_layout.h b/channel_layout.h new file mode 100644 index 0000000..7726055 --- /dev/null +++ b/channel_layout.h @@ -0,0 +1,40 @@ +#include + +// Calling C.AV_CHANNEL_LAYOUT_* in Go gives a "could not determine kind of name for X" error +// therefore we need to bridge the channel layout values +AVChannelLayout *astiavChannelLayoutMono = &(AVChannelLayout)AV_CHANNEL_LAYOUT_MONO; +AVChannelLayout *astiavChannelLayoutStereo = &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO; +AVChannelLayout *astiavChannelLayout2Point1 = &(AVChannelLayout)AV_CHANNEL_LAYOUT_2POINT1; +AVChannelLayout *astiavChannelLayout21 = &(AVChannelLayout)AV_CHANNEL_LAYOUT_2_1; +AVChannelLayout *astiavChannelLayoutSurround = &(AVChannelLayout)AV_CHANNEL_LAYOUT_SURROUND; +AVChannelLayout *astiavChannelLayout3Point1 = &(AVChannelLayout)AV_CHANNEL_LAYOUT_3POINT1; +AVChannelLayout *astiavChannelLayout4Point0 = &(AVChannelLayout)AV_CHANNEL_LAYOUT_4POINT0; +AVChannelLayout *astiavChannelLayout4Point1 = &(AVChannelLayout)AV_CHANNEL_LAYOUT_4POINT1; +AVChannelLayout *astiavChannelLayout22 = &(AVChannelLayout)AV_CHANNEL_LAYOUT_2_2; +AVChannelLayout *astiavChannelLayoutQuad = &(AVChannelLayout)AV_CHANNEL_LAYOUT_QUAD; +AVChannelLayout *astiavChannelLayout5Point0 = &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT0; +AVChannelLayout *astiavChannelLayout5Point1 = &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT1; +AVChannelLayout *astiavChannelLayout5Point0Back = &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT0_BACK; +AVChannelLayout *astiavChannelLayout5Point1Back = &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT1_BACK; +AVChannelLayout *astiavChannelLayout6Point0 = &(AVChannelLayout)AV_CHANNEL_LAYOUT_6POINT0; +AVChannelLayout *astiavChannelLayout6Point0Front = &(AVChannelLayout)AV_CHANNEL_LAYOUT_6POINT0_FRONT; +AVChannelLayout *astiavChannelLayoutHexagonal = &(AVChannelLayout)AV_CHANNEL_LAYOUT_HEXAGONAL; +AVChannelLayout *astiavChannelLayout3Point1Point2 = &(AVChannelLayout)AV_CHANNEL_LAYOUT_3POINT1POINT2; +AVChannelLayout *astiavChannelLayout6Point1 = &(AVChannelLayout)AV_CHANNEL_LAYOUT_6POINT1; +AVChannelLayout *astiavChannelLayout6Point1Back = &(AVChannelLayout)AV_CHANNEL_LAYOUT_6POINT1_BACK; +AVChannelLayout *astiavChannelLayout6Point1Front = &(AVChannelLayout)AV_CHANNEL_LAYOUT_6POINT1_FRONT; +AVChannelLayout *astiavChannelLayout7Point0 = &(AVChannelLayout)AV_CHANNEL_LAYOUT_7POINT0; +AVChannelLayout *astiavChannelLayout7Point0Front = &(AVChannelLayout)AV_CHANNEL_LAYOUT_7POINT0_FRONT; +AVChannelLayout *astiavChannelLayout7Point1 = &(AVChannelLayout)AV_CHANNEL_LAYOUT_7POINT1; +AVChannelLayout *astiavChannelLayout7Point1Wide = &(AVChannelLayout)AV_CHANNEL_LAYOUT_7POINT1_WIDE; +AVChannelLayout *astiavChannelLayout7Point1WideBack = &(AVChannelLayout)AV_CHANNEL_LAYOUT_7POINT1_WIDE_BACK; +AVChannelLayout *astiavChannelLayout5Point1Point2Back = &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT1POINT2_BACK; +AVChannelLayout *astiavChannelLayoutOctagonal = &(AVChannelLayout)AV_CHANNEL_LAYOUT_OCTAGONAL; +AVChannelLayout *astiavChannelLayoutCube = &(AVChannelLayout)AV_CHANNEL_LAYOUT_CUBE; +AVChannelLayout *astiavChannelLayout5Point1Point4Back = &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT1POINT4_BACK; +AVChannelLayout *astiavChannelLayout7Point1Point2 = &(AVChannelLayout)AV_CHANNEL_LAYOUT_7POINT1POINT2; +AVChannelLayout *astiavChannelLayout7Point1Point4Back = &(AVChannelLayout)AV_CHANNEL_LAYOUT_7POINT1POINT4_BACK; +AVChannelLayout *astiavChannelLayoutHexadecagonal = &(AVChannelLayout)AV_CHANNEL_LAYOUT_HEXADECAGONAL; +AVChannelLayout *astiavChannelLayoutStereoDownmix = &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO_DOWNMIX; +AVChannelLayout *astiavChannelLayout22Point2 = &(AVChannelLayout)AV_CHANNEL_LAYOUT_22POINT2; +AVChannelLayout *astiavChannelLayout7Point1TopBack = &(AVChannelLayout)AV_CHANNEL_LAYOUT_7POINT1_TOP_BACK; \ No newline at end of file diff --git a/class.c b/class.c new file mode 100644 index 0000000..549334f --- /dev/null +++ b/class.c @@ -0,0 +1,22 @@ +#include +#include +#include + +char* astiavClassItemName(AVClass* c, void* ptr) { + return (char*)c->item_name(ptr); +} + +AVClassCategory astiavClassCategory(AVClass* c, void* ptr) { + if (c->get_category) return c->get_category(ptr); + return c->category; +} + +AVClass** astiavClassParent(AVClass* c, void* ptr) { + if (c->parent_log_context_offset) { + AVClass** parent = *(AVClass ***) (((uint8_t *) ptr) + c->parent_log_context_offset); + if (parent && *parent) { + return parent; + } + } + return NULL; +} \ No newline at end of file diff --git a/class.go b/class.go index 6c2a984..48d81a2 100644 --- a/class.go +++ b/class.go @@ -1,29 +1,6 @@ package astiav -//#include -//#include -/* - -static inline char* astiavClassItemName(AVClass* c, void* ptr) { - return (char*)c->item_name(ptr); -} - -static inline AVClassCategory astiavClassCategory(AVClass* c, void* ptr) { - if (c->get_category) return c->get_category(ptr); - return c->category; -} - -static inline AVClass** astiavClassParent(AVClass* c, void* ptr) { - if (c->parent_log_context_offset) { - AVClass** parent = *(AVClass ***) (((uint8_t *) ptr) + c->parent_log_context_offset); - if (parent && *parent) { - return parent; - } - } - return NULL; -} - -*/ +//#include "class.h" import "C" import ( "fmt" @@ -33,7 +10,7 @@ import ( // https://github.com/FFmpeg/FFmpeg/blob/n5.0/libavutil/log.h#L66 type Class struct { - c *C.struct_AVClass + c *C.AVClass ptr unsafe.Pointer } @@ -41,7 +18,7 @@ func newClassFromC(ptr unsafe.Pointer) *Class { if ptr == nil { return nil } - c := (**C.struct_AVClass)(ptr) + c := (**C.AVClass)(ptr) if c == nil { return nil } diff --git a/class.h b/class.h new file mode 100644 index 0000000..7efe031 --- /dev/null +++ b/class.h @@ -0,0 +1,5 @@ +#include + +char* astiavClassItemName(AVClass* c, void* ptr); +AVClassCategory astiavClassCategory(AVClass* c, void* ptr); +AVClass** astiavClassParent(AVClass* c, void* ptr); \ No newline at end of file diff --git a/class_category.go b/class_category.go index faf9b05..41d35d2 100644 --- a/class_category.go +++ b/class_category.go @@ -4,8 +4,7 @@ package astiav import "C" // https://github.com/FFmpeg/FFmpeg/blob/n5.0/libavutil/log.h#L28 -// TODO Find a way to use C.enum_AVClassCategory instead of uint -type ClassCategory uint +type ClassCategory C.AVClassCategory const ( ClassCategoryBitstreamFilter = ClassCategory(C.AV_CLASS_CATEGORY_BITSTREAM_FILTER) diff --git a/codec.go b/codec.go index 13cb3ff..b2df45c 100644 --- a/codec.go +++ b/codec.go @@ -9,10 +9,10 @@ import ( // https://github.com/FFmpeg/FFmpeg/blob/n5.0/libavcodec/codec.h#L202 type Codec struct { - c *C.struct_AVCodec + c *C.AVCodec } -func newCodecFromC(c *C.struct_AVCodec) *Codec { +func newCodecFromC(c *C.AVCodec) *Codec { if c == nil { return nil } @@ -37,7 +37,7 @@ func (c *Codec) ChannelLayouts() (o []ChannelLayout) { } size := unsafe.Sizeof(*c.c.ch_layouts) for i := 0; ; i++ { - v, _ := newChannelLayoutFromC((*C.struct_AVChannelLayout)(unsafe.Pointer(uintptr(unsafe.Pointer(c.c.ch_layouts)) + uintptr(i)*size))).clone() + v, _ := newChannelLayoutFromC((*C.AVChannelLayout)(unsafe.Pointer(uintptr(unsafe.Pointer(c.c.ch_layouts)) + uintptr(i)*size))).clone() if !v.Valid() { break } diff --git a/codec_context.c b/codec_context.c new file mode 100644 index 0000000..c0dc590 --- /dev/null +++ b/codec_context.c @@ -0,0 +1,22 @@ +#include "codec_context.h" +#include +#include + +enum AVPixelFormat astiavCodecContextGetFormat(AVCodecContext *ctx, const enum AVPixelFormat *pix_fmts) +{ + int pix_fmts_size = 0; + while (*pix_fmts != AV_PIX_FMT_NONE) { + pix_fmts_size++; + pix_fmts++; + } + pix_fmts -= pix_fmts_size; + return goAstiavCodecContextGetFormat(ctx, (enum AVPixelFormat*)(pix_fmts), pix_fmts_size); +} +void astiavSetCodecContextGetFormat(AVCodecContext *ctx) +{ + ctx->get_format = astiavCodecContextGetFormat; +} +void astiavResetCodecContextGetFormat(AVCodecContext *ctx) +{ + ctx->get_format = NULL; +} \ No newline at end of file diff --git a/codec_context.go b/codec_context.go index b5c330a..ac79400 100644 --- a/codec_context.go +++ b/codec_context.go @@ -1,30 +1,6 @@ package astiav -//#include -//#include -/* -extern enum AVPixelFormat goAstiavCodecContextGetFormat(AVCodecContext *ctx, enum AVPixelFormat *pix_fmts, int pix_fmts_size); - -static inline enum AVPixelFormat astiavCodecContextGetFormat(AVCodecContext *ctx, const enum AVPixelFormat *pix_fmts) -{ - int pix_fmts_size = 0; - while (*pix_fmts != AV_PIX_FMT_NONE) { - pix_fmts_size++; - pix_fmts++; - } - pix_fmts -= pix_fmts_size; - return goAstiavCodecContextGetFormat(ctx, (enum AVPixelFormat*)(pix_fmts), pix_fmts_size); -} -static inline void astiavSetCodecContextGetFormat(AVCodecContext *ctx) -{ - ctx->get_format = astiavCodecContextGetFormat; -} -static inline void astiavResetCodecContextGetFormat(AVCodecContext *ctx) -{ - ctx->get_format = NULL; -} - -*/ +//#include "codec_context.h" import "C" import ( "sync" @@ -33,12 +9,12 @@ import ( // https://github.com/FFmpeg/FFmpeg/blob/n5.0/libavcodec/avcodec.h#L383 type CodecContext struct { - c *C.struct_AVCodecContext + c *C.AVCodecContext // We need to store this to unref it properly hdc *HardwareDeviceContext } -func newCodecContextFromC(c *C.struct_AVCodecContext) *CodecContext { +func newCodecContextFromC(c *C.AVCodecContext) *CodecContext { if c == nil { return nil } @@ -50,7 +26,7 @@ func newCodecContextFromC(c *C.struct_AVCodecContext) *CodecContext { var _ Classer = (*CodecContext)(nil) func AllocCodecContext(c *Codec) *CodecContext { - var cc *C.struct_AVCodec + var cc *C.AVCodec if c != nil { cc = c.c } @@ -275,7 +251,7 @@ func (cc *CodecContext) SetWidth(width int) { } func (cc *CodecContext) Open(c *Codec, d *Dictionary) error { - var dc **C.struct_AVDictionary + var dc **C.AVDictionary if d != nil { dc = &d.c } @@ -283,7 +259,7 @@ func (cc *CodecContext) Open(c *Codec, d *Dictionary) error { } func (cc *CodecContext) ReceivePacket(p *Packet) error { - var pc *C.struct_AVPacket + var pc *C.AVPacket if p != nil { pc = p.c } @@ -291,7 +267,7 @@ func (cc *CodecContext) ReceivePacket(p *Packet) error { } func (cc *CodecContext) SendPacket(p *Packet) error { - var pc *C.struct_AVPacket + var pc *C.AVPacket if p != nil { pc = p.c } @@ -299,7 +275,7 @@ func (cc *CodecContext) SendPacket(p *Packet) error { } func (cc *CodecContext) ReceiveFrame(f *Frame) error { - var fc *C.struct_AVFrame + var fc *C.AVFrame if f != nil { fc = f.c } @@ -307,7 +283,7 @@ func (cc *CodecContext) ReceiveFrame(f *Frame) error { } func (cc *CodecContext) SendFrame(f *Frame) error { - var fc *C.struct_AVFrame + var fc *C.AVFrame if f != nil { fc = f.c } @@ -343,7 +319,7 @@ func (cc *CodecContext) SetExtraHardwareFrames(n int) { type CodecContextPixelFormatCallback func(pfs []PixelFormat) PixelFormat var ( - codecContextPixelFormatCallbacks = make(map[*C.struct_AVCodecContext]CodecContextPixelFormatCallback) + codecContextPixelFormatCallbacks = make(map[*C.AVCodecContext]CodecContextPixelFormatCallback) codecContextPixelFormatCallbacksMutex = &sync.Mutex{} ) @@ -363,7 +339,7 @@ func (cc *CodecContext) SetPixelFormatCallback(c CodecContextPixelFormatCallback } //export goAstiavCodecContextGetFormat -func goAstiavCodecContextGetFormat(cc *C.struct_AVCodecContext, pfsCPtr *C.enum_AVPixelFormat, pfsCSize C.int) C.enum_AVPixelFormat { +func goAstiavCodecContextGetFormat(cc *C.AVCodecContext, pfsCPtr *C.enum_AVPixelFormat, pfsCSize C.int) C.enum_AVPixelFormat { // Lock codecContextPixelFormatCallbacksMutex.Lock() defer codecContextPixelFormatCallbacksMutex.Unlock() diff --git a/codec_context.h b/codec_context.h new file mode 100644 index 0000000..d8f4ab7 --- /dev/null +++ b/codec_context.h @@ -0,0 +1,6 @@ +#include + +extern enum AVPixelFormat goAstiavCodecContextGetFormat(AVCodecContext *ctx, enum AVPixelFormat *pix_fmts, int pix_fmts_size); +enum AVPixelFormat astiavCodecContextGetFormat(AVCodecContext *ctx, const enum AVPixelFormat *pix_fmts); +void astiavSetCodecContextGetFormat(AVCodecContext *ctx); +void astiavResetCodecContextGetFormat(AVCodecContext *ctx); \ No newline at end of file diff --git a/codec_hardware_config.go b/codec_hardware_config.go index e6349be..f415bc2 100644 --- a/codec_hardware_config.go +++ b/codec_hardware_config.go @@ -5,10 +5,10 @@ import "C" // https://github.com/FFmpeg/FFmpeg/blob/n5.0/libavcodec/codec.h#L460 type CodecHardwareConfig struct { - c *C.struct_AVCodecHWConfig + c *C.AVCodecHWConfig } -func newCodecHardwareConfigFromC(c *C.struct_AVCodecHWConfig) CodecHardwareConfig { +func newCodecHardwareConfigFromC(c *C.AVCodecHWConfig) CodecHardwareConfig { return CodecHardwareConfig{c: c} } diff --git a/codec_parameters.go b/codec_parameters.go index d6f6316..70ea3fb 100644 --- a/codec_parameters.go +++ b/codec_parameters.go @@ -5,14 +5,14 @@ import "C" // https://github.com/FFmpeg/FFmpeg/blob/n5.0/libavcodec/codec_par.h#L52 type CodecParameters struct { - c *C.struct_AVCodecParameters + c *C.AVCodecParameters } func AllocCodecParameters() *CodecParameters { return newCodecParametersFromC(C.avcodec_parameters_alloc()) } -func newCodecParametersFromC(c *C.struct_AVCodecParameters) *CodecParameters { +func newCodecParametersFromC(c *C.AVCodecParameters) *CodecParameters { if c == nil { return nil } diff --git a/dictionary.go b/dictionary.go index d7d2dea..1301aa6 100644 --- a/dictionary.go +++ b/dictionary.go @@ -10,14 +10,14 @@ import ( // https://github.com/FFmpeg/FFmpeg/blob/n5.0/libavutil/dict.h#L84 type Dictionary struct { - c *C.struct_AVDictionary + c *C.AVDictionary } func NewDictionary() *Dictionary { return &Dictionary{} } -func newDictionaryFromC(c *C.struct_AVDictionary) *Dictionary { +func newDictionaryFromC(c *C.AVDictionary) *Dictionary { if c == nil { return nil } @@ -45,7 +45,7 @@ func (d *Dictionary) ParseString(i, keyValSep, pairsSep string, flags Dictionary func (d *Dictionary) Get(key string, prev *DictionaryEntry, flags DictionaryFlags) *DictionaryEntry { ck := C.CString(key) defer C.free(unsafe.Pointer(ck)) - var cp *C.struct_AVDictionaryEntry + var cp *C.AVDictionaryEntry if prev != nil { cp = prev.c } diff --git a/dictionary_entry.go b/dictionary_entry.go index 361964c..ac40de6 100644 --- a/dictionary_entry.go +++ b/dictionary_entry.go @@ -5,10 +5,10 @@ import "C" // https://github.com/FFmpeg/FFmpeg/blob/n5.0/libavutil/dict.h#L79 type DictionaryEntry struct { - c *C.struct_AVDictionaryEntry + c *C.AVDictionaryEntry } -func newDictionaryEntryFromC(c *C.struct_AVDictionaryEntry) *DictionaryEntry { +func newDictionaryEntryFromC(c *C.AVDictionaryEntry) *DictionaryEntry { return &DictionaryEntry{c: c} } diff --git a/filter.go b/filter.go index 736594e..8e8b133 100644 --- a/filter.go +++ b/filter.go @@ -6,10 +6,10 @@ import "unsafe" // https://github.com/FFmpeg/FFmpeg/blob/n5.0/libavfilter/avfilter.h#L165 type Filter struct { - c *C.struct_AVFilter + c *C.AVFilter } -func newFilterFromC(c *C.struct_AVFilter) *Filter { +func newFilterFromC(c *C.AVFilter) *Filter { if c == nil { return nil } diff --git a/filter_context.go b/filter_context.go index 25e02ac..ed8cb8d 100644 --- a/filter_context.go +++ b/filter_context.go @@ -12,10 +12,10 @@ import ( // https://github.com/FFmpeg/FFmpeg/blob/n5.0/libavfilter/avfilter.h#L67 type FilterContext struct { - c *C.struct_AVFilterContext + c *C.AVFilterContext } -func newFilterContext(c *C.struct_AVFilterContext) *FilterContext { +func newFilterContext(c *C.AVFilterContext) *FilterContext { if c == nil { return nil } @@ -32,7 +32,7 @@ func (fc *FilterContext) Free() { } func (fc *FilterContext) BuffersrcAddFrame(f *Frame, fs BuffersrcFlags) error { - var cf *C.struct_AVFrame + var cf *C.AVFrame if f != nil { cf = f.c } @@ -40,7 +40,7 @@ func (fc *FilterContext) BuffersrcAddFrame(f *Frame, fs BuffersrcFlags) error { } func (fc *FilterContext) BuffersinkGetFrame(f *Frame, fs BuffersinkFlags) error { - var cf *C.struct_AVFrame + var cf *C.AVFrame if f != nil { cf = f.c } @@ -60,7 +60,7 @@ func (fc *FilterContext) NbOutputs() int { } func (fc *FilterContext) Inputs() (ls []*FilterLink) { - lcs := (*[(math.MaxInt32 - 1) / unsafe.Sizeof((*C.struct_AVFilterLink)(nil))](*C.struct_AVFilterLink))(unsafe.Pointer(fc.c.inputs)) + lcs := (*[(math.MaxInt32 - 1) / unsafe.Sizeof((*C.AVFilterLink)(nil))](*C.AVFilterLink))(unsafe.Pointer(fc.c.inputs)) for i := 0; i < fc.NbInputs(); i++ { ls = append(ls, newFilterLinkFromC(lcs[i])) } @@ -68,7 +68,7 @@ func (fc *FilterContext) Inputs() (ls []*FilterLink) { } func (fc *FilterContext) Outputs() (ls []*FilterLink) { - lcs := (*[(math.MaxInt32 - 1) / unsafe.Sizeof((*C.struct_AVFilterLink)(nil))](*C.struct_AVFilterLink))(unsafe.Pointer(fc.c.outputs)) + lcs := (*[(math.MaxInt32 - 1) / unsafe.Sizeof((*C.AVFilterLink)(nil))](*C.AVFilterLink))(unsafe.Pointer(fc.c.outputs)) for i := 0; i < fc.NbOutputs(); i++ { ls = append(ls, newFilterLinkFromC(lcs[i])) } diff --git a/filter_graph.go b/filter_graph.go index 267b456..7865589 100644 --- a/filter_graph.go +++ b/filter_graph.go @@ -9,10 +9,10 @@ import ( // https://github.com/FFmpeg/FFmpeg/blob/n5.0/libavfilter/avfilter.h#L861 type FilterGraph struct { - c *C.struct_AVFilterGraph + c *C.AVFilterGraph } -func newFilterGraphFromC(c *C.struct_AVFilterGraph) *FilterGraph { +func newFilterGraphFromC(c *C.AVFilterGraph) *FilterGraph { if c == nil { return nil } @@ -76,7 +76,7 @@ func (g *FilterGraph) NewFilterContext(f *Filter, name string, args FilterArgs) } cn := C.CString(name) defer C.free(unsafe.Pointer(cn)) - var c *C.struct_AVFilterContext + var c *C.AVFilterContext if err := newError(C.avfilter_graph_create_filter(&c, f.c, cn, ca, nil, g.c)); err != nil { return nil, err } @@ -86,11 +86,11 @@ func (g *FilterGraph) NewFilterContext(f *Filter, name string, args FilterArgs) func (g *FilterGraph) Parse(content string, inputs, outputs *FilterInOut) error { cc := C.CString(content) defer C.free(unsafe.Pointer(cc)) - var ic **C.struct_AVFilterInOut + var ic **C.AVFilterInOut if inputs != nil { ic = &inputs.c } - var oc **C.struct_AVFilterInOut + var oc **C.AVFilterInOut if outputs != nil { oc = &outputs.c } diff --git a/filter_in_out.go b/filter_in_out.go index ae4077b..ec3ea01 100644 --- a/filter_in_out.go +++ b/filter_in_out.go @@ -5,10 +5,10 @@ import "C" // https://github.com/FFmpeg/FFmpeg/blob/n5.0/libavfilter/avfilter.h#L1021 type FilterInOut struct { - c *C.struct_AVFilterInOut + c *C.AVFilterInOut } -func newFilterInOutFromC(c *C.struct_AVFilterInOut) *FilterInOut { +func newFilterInOutFromC(c *C.AVFilterInOut) *FilterInOut { if c == nil { return nil } @@ -28,7 +28,7 @@ func (i *FilterInOut) SetName(n string) { } func (i *FilterInOut) SetFilterContext(c *FilterContext) { - i.c.filter_ctx = (*C.struct_AVFilterContext)(c.c) + i.c.filter_ctx = (*C.AVFilterContext)(c.c) } func (i *FilterInOut) SetPadIdx(idx int) { @@ -36,7 +36,7 @@ func (i *FilterInOut) SetPadIdx(idx int) { } func (i *FilterInOut) SetNext(n *FilterInOut) { - var nc *C.struct_AVFilterInOut + var nc *C.AVFilterInOut if n != nil { nc = n.c } diff --git a/filter_link.go b/filter_link.go index 1f5a37b..e5eef06 100644 --- a/filter_link.go +++ b/filter_link.go @@ -5,10 +5,10 @@ import "C" // https://github.com/FFmpeg/FFmpeg/blob/n5.0/libavfilter/avfilter.h#L471 type FilterLink struct { - c *C.struct_AVFilterLink + c *C.AVFilterLink } -func newFilterLinkFromC(c *C.struct_AVFilterLink) *FilterLink { +func newFilterLinkFromC(c *C.AVFilterLink) *FilterLink { if c == nil { return nil } diff --git a/format_context.go b/format_context.go index 2978947..f8dacfd 100644 --- a/format_context.go +++ b/format_context.go @@ -10,10 +10,10 @@ import ( // https://github.com/FFmpeg/FFmpeg/blob/n5.0/libavformat/avformat.h#L1202 type FormatContext struct { - c *C.struct_AVFormatContext + c *C.AVFormatContext } -func newFormatContextFromC(c *C.struct_AVFormatContext) *FormatContext { +func newFormatContextFromC(c *C.AVFormatContext) *FormatContext { if c == nil { return nil } @@ -39,11 +39,11 @@ func AllocOutputFormatContext(of *OutputFormat, formatName, filename string) (*F finc = C.CString(filename) defer C.free(unsafe.Pointer(finc)) } - var ofc *C.struct_AVOutputFormat + var ofc *C.AVOutputFormat if of != nil { ofc = of.c } - var fcc *C.struct_AVFormatContext + var fcc *C.AVFormatContext if err := newError(C.avformat_alloc_output_context2(&fcc, ofc, fonc, finc)); err != nil { return nil, err } @@ -137,7 +137,7 @@ func (fc *FormatContext) Pb() *IOContext { } func (fc *FormatContext) Programs() (ps []*Program) { - pcs := (*[(math.MaxInt32 - 1) / unsafe.Sizeof((*C.struct_AVProgram)(nil))](*C.struct_AVProgram))(unsafe.Pointer(fc.c.programs)) + pcs := (*[(math.MaxInt32 - 1) / unsafe.Sizeof((*C.AVProgram)(nil))](*C.AVProgram))(unsafe.Pointer(fc.c.programs)) for i := 0; i < fc.NbPrograms(); i++ { ps = append(ps, newProgramFromC(pcs[i], fc)) } @@ -153,7 +153,7 @@ func (fc *FormatContext) StartTime() int64 { } func (fc *FormatContext) Streams() (ss []*Stream) { - scs := (*[(math.MaxInt32 - 1) / unsafe.Sizeof((*C.struct_AVStream)(nil))](*C.struct_AVStream))(unsafe.Pointer(fc.c.streams)) + scs := (*[(math.MaxInt32 - 1) / unsafe.Sizeof((*C.AVStream)(nil))](*C.AVStream))(unsafe.Pointer(fc.c.streams)) for i := 0; i < fc.NbStreams(); i++ { ss = append(ss, newStreamFromC(scs[i])) } @@ -174,11 +174,11 @@ func (fc *FormatContext) OpenInput(url string, fmt *InputFormat, d *Dictionary) urlc = C.CString(url) defer C.free(unsafe.Pointer(urlc)) } - var dc **C.struct_AVDictionary + var dc **C.AVDictionary if d != nil { dc = &d.c } - var fmtc *C.struct_AVInputFormat + var fmtc *C.AVInputFormat if fmt != nil { fmtc = fmt.c } @@ -206,7 +206,7 @@ func (fc *FormatContext) NewProgram(id int) *Program { } func (fc *FormatContext) NewStream(c *Codec) *Stream { - var cc *C.struct_AVCodec + var cc *C.AVCodec if c != nil { cc = c.c } @@ -214,7 +214,7 @@ func (fc *FormatContext) NewStream(c *Codec) *Stream { } func (fc *FormatContext) FindStreamInfo(d *Dictionary) error { - var dc **C.struct_AVDictionary + var dc **C.AVDictionary if d != nil { dc = &d.c } @@ -222,7 +222,7 @@ func (fc *FormatContext) FindStreamInfo(d *Dictionary) error { } func (fc *FormatContext) ReadFrame(p *Packet) error { - var pc *C.struct_AVPacket + var pc *C.AVPacket if p != nil { pc = p.c } @@ -238,7 +238,7 @@ func (fc *FormatContext) Flush() error { } func (fc *FormatContext) WriteHeader(d *Dictionary) error { - var dc **C.struct_AVDictionary + var dc **C.AVDictionary if d != nil { dc = &d.c } @@ -246,7 +246,7 @@ func (fc *FormatContext) WriteHeader(d *Dictionary) error { } func (fc *FormatContext) WriteFrame(p *Packet) error { - var pc *C.struct_AVPacket + var pc *C.AVPacket if p != nil { pc = p.c } @@ -254,7 +254,7 @@ func (fc *FormatContext) WriteFrame(p *Packet) error { } func (fc *FormatContext) WriteInterleavedFrame(p *Packet) error { - var pc *C.struct_AVPacket + var pc *C.AVPacket if p != nil { pc = p.c } @@ -266,7 +266,7 @@ func (fc *FormatContext) WriteTrailer() error { } func (fc *FormatContext) GuessSampleAspectRatio(s *Stream, f *Frame) Rational { - var cf *C.struct_AVFrame + var cf *C.AVFrame if f != nil { cf = f.c } @@ -274,7 +274,7 @@ func (fc *FormatContext) GuessSampleAspectRatio(s *Stream, f *Frame) Rational { } func (fc *FormatContext) GuessFrameRate(s *Stream, f *Frame) Rational { - var cf *C.struct_AVFrame + var cf *C.AVFrame if f != nil { cf = f.c } @@ -287,7 +287,7 @@ func (fc *FormatContext) SDPCreate() (string, error) { func sdpCreate(fcs []*FormatContext) (string, error) { return stringFromC(1024, func(buf *C.char, size C.size_t) error { - fccs := []*C.struct_AVFormatContext{} + fccs := []*C.AVFormatContext{} for _, fc := range fcs { fccs = append(fccs, fc.c) } diff --git a/frame.go b/frame.go index 7414406..797571d 100644 --- a/frame.go +++ b/frame.go @@ -14,10 +14,10 @@ const NumDataPointers = uint(C.AV_NUM_DATA_POINTERS) // https://github.com/FFmpeg/FFmpeg/blob/n5.0/libavutil/frame.h#L317 type Frame struct { - c *C.struct_AVFrame + c *C.AVFrame } -func newFrameFromC(c *C.struct_AVFrame) *Frame { +func newFrameFromC(c *C.AVFrame) *Frame { if c == nil { return nil } diff --git a/frame_data.go b/frame_data.go index 5f86cb5..2571b05 100644 --- a/frame_data.go +++ b/frame_data.go @@ -1,13 +1,7 @@ package astiav //#include -//#include -/* -ptrdiff_t astiavFFAlign(int i, int align) -{ - return FFALIGN(i, align); -} -*/ +//#include "macros.h" import "C" import ( "errors" diff --git a/frame_side_data.go b/frame_side_data.go index 6316a45..588fe7f 100644 --- a/frame_side_data.go +++ b/frame_side_data.go @@ -9,10 +9,10 @@ import ( // https://github.com/FFmpeg/FFmpeg/blob/n5.0/libavutil/frame.h#L223 type FrameSideData struct { - c *C.struct_AVFrameSideData + c *C.AVFrameSideData } -func newFrameSideDataFromC(c *C.struct_AVFrameSideData) *FrameSideData { +func newFrameSideDataFromC(c *C.AVFrameSideData) *FrameSideData { if c == nil { return nil } diff --git a/hardware_device_context.go b/hardware_device_context.go index 6f3999f..595f19d 100644 --- a/hardware_device_context.go +++ b/hardware_device_context.go @@ -9,7 +9,7 @@ import ( // https://github.com/FFmpeg/FFmpeg/blob/n5.0/libavutil/hwcontext.h#L61 type HardwareDeviceContext struct { - c *C.struct_AVBufferRef + c *C.AVBufferRef } func CreateHardwareDeviceContext(t HardwareDeviceType, device string, options *Dictionary) (*HardwareDeviceContext, error) { @@ -19,7 +19,7 @@ func CreateHardwareDeviceContext(t HardwareDeviceType, device string, options *D deviceC = C.CString(device) defer C.free(unsafe.Pointer(deviceC)) } - optionsC := (*C.struct_AVDictionary)(nil) + optionsC := (*C.AVDictionary)(nil) if options != nil { optionsC = options.c } diff --git a/input_format.go b/input_format.go index 6959df2..fcbcd0c 100644 --- a/input_format.go +++ b/input_format.go @@ -6,10 +6,10 @@ import "unsafe" // https://github.com/FFmpeg/FFmpeg/blob/n5.0/libavformat/avformat.h#L650 type InputFormat struct { - c *C.struct_AVInputFormat + c *C.AVInputFormat } -func newInputFormatFromC(c *C.struct_AVInputFormat) *InputFormat { +func newInputFormatFromC(c *C.AVInputFormat) *InputFormat { if c == nil { return nil } diff --git a/int_read_write.c b/int_read_write.c new file mode 100644 index 0000000..4369228 --- /dev/null +++ b/int_read_write.c @@ -0,0 +1,8 @@ +#include + +uint32_t astiavRL32(uint8_t *i) { + return AV_RL32(i); +} +uint32_t astiavRL32WithOffset(uint8_t *i, int o) { + return AV_RL32(i+o); +} \ No newline at end of file diff --git a/int_read_write.go b/int_read_write.go index 5ca03c5..b9c6456 100644 --- a/int_read_write.go +++ b/int_read_write.go @@ -1,14 +1,6 @@ package astiav -//#include -/* -uint32_t astiavRL32(uint8_t *i) { - return AV_RL32(i); -} -uint32_t astiavRL32WithOffset(uint8_t *i, int o) { - return AV_RL32(i+o); -} -*/ +//#include "int_read_write.h" import "C" import "unsafe" diff --git a/int_read_write.h b/int_read_write.h new file mode 100644 index 0000000..6752389 --- /dev/null +++ b/int_read_write.h @@ -0,0 +1,4 @@ +#include + +uint32_t astiavRL32(uint8_t *i); +uint32_t astiavRL32WithOffset(uint8_t *i, int o); \ No newline at end of file diff --git a/io_context.go b/io_context.go index c0dd134..b1b26b3 100644 --- a/io_context.go +++ b/io_context.go @@ -12,11 +12,11 @@ import ( // https://github.com/FFmpeg/FFmpeg/blob/n5.0/libavformat/avio.h#L161 type IOContext struct { - c *C.struct_AVIOContext + c *C.AVIOContext handlerID unsafe.Pointer } -func newIOContextFromC(c *C.struct_AVIOContext) *IOContext { +func newIOContextFromC(c *C.AVIOContext) *IOContext { if c == nil { return nil } @@ -109,7 +109,7 @@ func AllocIOContext(bufferSize int, writable bool, readFunc IOContextReadFunc, s func OpenIOContext(filename string, flags IOContextFlags) (*IOContext, error) { cfi := C.CString(filename) defer C.free(unsafe.Pointer(cfi)) - var c *C.struct_AVIOContext + var c *C.AVIOContext if err := newError(C.avio_open(&c, cfi, C.int(flags))); err != nil { return nil, err } diff --git a/io_interrupter.c b/io_interrupter.c new file mode 100644 index 0000000..6df0852 --- /dev/null +++ b/io_interrupter.c @@ -0,0 +1,12 @@ +#include + +int astiavInterruptCallback(void *ret) +{ + return *((int*)ret); +} + +AVIOInterruptCB astiavNewInterruptCallback(int *ret) +{ + AVIOInterruptCB c = { astiavInterruptCallback, ret }; + return c; +} \ No newline at end of file diff --git a/io_interrupter.go b/io_interrupter.go index a6c7432..9ede1fe 100644 --- a/io_interrupter.go +++ b/io_interrupter.go @@ -1,17 +1,6 @@ package astiav -//#include -/* -int astiavInterruptCallback(void *ret) -{ - return *((int*)ret); -} -AVIOInterruptCB astiavNewInterruptCallback(int *ret) -{ - AVIOInterruptCB c = { astiavInterruptCallback, ret }; - return c; -} -*/ +//#include "io_interrupter.h" import "C" type IOInterrupter interface { @@ -20,7 +9,7 @@ type IOInterrupter interface { } type defaultIOInterrupter struct { - c C.struct_AVIOInterruptCB + c C.AVIOInterruptCB i C.int } diff --git a/io_interrupter.h b/io_interrupter.h new file mode 100644 index 0000000..eca2172 --- /dev/null +++ b/io_interrupter.h @@ -0,0 +1,4 @@ +#include + +int astiavInterruptCallback(void *ret); +AVIOInterruptCB astiavNewInterruptCallback(int *ret); \ No newline at end of file diff --git a/log.c b/log.c new file mode 100644 index 0000000..ede5041 --- /dev/null +++ b/log.c @@ -0,0 +1,26 @@ +#include "log.h" +#include +#include + +void astiavLogCallback(void *ptr, int level, const char *fmt, va_list vl) +{ + if (level > av_log_get_level()) return; + char msg[1024]; + vsprintf(msg, fmt, vl); + goAstiavLogCallback(ptr, level, (char*)(fmt), msg); +} + +void astiavSetLogCallback() +{ + av_log_set_callback(astiavLogCallback); +} + +void astiavResetLogCallback() +{ + av_log_set_callback(av_log_default_callback); +} + +void astiavLog(void* ptr, int level, const char *fmt, char* arg) +{ + av_log(ptr, level, fmt, arg); +} \ No newline at end of file diff --git a/log.go b/log.go index 4fccf04..15e118a 100644 --- a/log.go +++ b/log.go @@ -1,31 +1,8 @@ package astiav +//#include "log.h" //#include -//#include //#include -/* -extern void goAstiavLogCallback(void* ptr, int level, char* fmt, char* msg); - -static inline void astiavLogCallback(void *ptr, int level, const char *fmt, va_list vl) -{ - if (level > av_log_get_level()) return; - char msg[1024]; - vsprintf(msg, fmt, vl); - goAstiavLogCallback(ptr, level, (char*)(fmt), msg); -} -static inline void astiavSetLogCallback() -{ - av_log_set_callback(astiavLogCallback); -} -static inline void astiavResetLogCallback() -{ - av_log_set_callback(av_log_default_callback); -} -static inline void astiavLog(void* ptr, int level, const char *fmt, char* arg) -{ - av_log(ptr, level, fmt, arg); -} -*/ import "C" import ( "unsafe" diff --git a/log.h b/log.h new file mode 100644 index 0000000..22ee1b8 --- /dev/null +++ b/log.h @@ -0,0 +1,7 @@ +#include + +extern void goAstiavLogCallback(void* ptr, int level, char* fmt, char* msg); +void astiavLogCallback(void *ptr, int level, const char *fmt, va_list vl); +void astiavSetLogCallback(); +void astiavResetLogCallback(); +void astiavLog(void* ptr, int level, const char *fmt, char* arg); \ No newline at end of file diff --git a/macros.c b/macros.c new file mode 100644 index 0000000..345c5d6 --- /dev/null +++ b/macros.c @@ -0,0 +1,7 @@ +#include +#include + +ptrdiff_t astiavFFAlign(int i, int align) +{ + return FFALIGN(i, align); +} \ No newline at end of file diff --git a/macros.h b/macros.h new file mode 100644 index 0000000..60829da --- /dev/null +++ b/macros.h @@ -0,0 +1,3 @@ +#include + +ptrdiff_t astiavFFAlign(int i, int align); \ No newline at end of file diff --git a/output_format.go b/output_format.go index a947bdc..725cb20 100644 --- a/output_format.go +++ b/output_format.go @@ -6,10 +6,10 @@ import "unsafe" // https://github.com/FFmpeg/FFmpeg/blob/n5.0/libavformat/avformat.h#L503 type OutputFormat struct { - c *C.struct_AVOutputFormat + c *C.AVOutputFormat } -func newOutputFormatFromC(c *C.struct_AVOutputFormat) *OutputFormat { +func newOutputFormatFromC(c *C.AVOutputFormat) *OutputFormat { if c == nil { return nil } diff --git a/packet.go b/packet.go index c58586d..8fbc434 100644 --- a/packet.go +++ b/packet.go @@ -9,10 +9,10 @@ import ( // https://github.com/FFmpeg/FFmpeg/blob/n5.0/libavcodec/packet.h#L350 type Packet struct { - c *C.struct_AVPacket + c *C.AVPacket } -func newPacketFromC(c *C.struct_AVPacket) *Packet { +func newPacketFromC(c *C.AVPacket) *Packet { if c == nil { return nil } diff --git a/packet_side_data.go b/packet_side_data.go index df43bd0..48ad9eb 100644 --- a/packet_side_data.go +++ b/packet_side_data.go @@ -9,11 +9,11 @@ import ( // https://github.com/FFmpeg/FFmpeg/blob/n6.1.1/libavcodec/packet.h#L342 type PacketSideData struct { - sd **C.struct_AVPacketSideData + sd **C.AVPacketSideData size *C.int } -func newPacketSideDataFromC(sd **C.struct_AVPacketSideData, size *C.int) *PacketSideData { +func newPacketSideDataFromC(sd **C.AVPacketSideData, size *C.int) *PacketSideData { return &PacketSideData{ sd: sd, size: size, diff --git a/program.go b/program.go index 0d8c6c2..c63efc9 100644 --- a/program.go +++ b/program.go @@ -8,11 +8,11 @@ import ( // https://github.com/FFmpeg/FFmpeg/blob/n7.0/libavformat/avformat.h#L1181 type Program struct { - c *C.struct_AVProgram + c *C.AVProgram fc *FormatContext } -func newProgramFromC(c *C.struct_AVProgram, fc *FormatContext) *Program { +func newProgramFromC(c *C.AVProgram, fc *FormatContext) *Program { if c == nil { return nil } diff --git a/rational.go b/rational.go index d4fe70a..c35c42e 100644 --- a/rational.go +++ b/rational.go @@ -6,10 +6,10 @@ import "strconv" // https://github.com/FFmpeg/FFmpeg/blob/n5.0/libavutil/rational.h#L58 type Rational struct { - c C.struct_AVRational + c C.AVRational } -func newRationalFromC(c C.struct_AVRational) Rational { +func newRationalFromC(c C.AVRational) Rational { return Rational{c: c} } diff --git a/stream.go b/stream.go index 61b1f00..7d1fef3 100644 --- a/stream.go +++ b/stream.go @@ -5,10 +5,10 @@ import "C" // https://github.com/FFmpeg/FFmpeg/blob/n5.0/libavformat/avformat.h#L937 type Stream struct { - c *C.struct_AVStream + c *C.AVStream } -func newStreamFromC(c *C.struct_AVStream) *Stream { +func newStreamFromC(c *C.AVStream) *Stream { if c == nil { return nil }