Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make it compatible with ffmpeg tag n3.X #81

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions avcodec/avcodec.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,16 @@ func AvsubtitleFree(s *AvSubtitle) {
C.avsubtitle_free((*C.struct_AVSubtitle)(s))
}

//Alloc a packet
func AvPacketAlloc() *Packet {
return (*Packet)(C.av_packet_alloc())
}

//Free a packet
func AvPacketFree(packet *Packet) {
C.av_packet_free((**C.struct_AVPacket)(unsafe.Pointer(&packet)))
}

//Pack a dictionary for use in side_data.
func AvPacketPackDictionary(d *Dictionary, s *int) *uint8 {
return (*uint8)(C.av_packet_pack_dictionary((*C.struct_AVDictionary)(d), (*C.int)(unsafe.Pointer(s))))
Expand All @@ -180,10 +186,6 @@ func AvcodecFindDecoder(id CodecId) *Codec {
return (*Codec)(C.avcodec_find_decoder((C.enum_AVCodecID)(id)))
}

func AvCodecIterate(p *unsafe.Pointer) *Codec {
return (*Codec)(C.av_codec_iterate(p))
}

//Find a registered decoder with the specified name.
func AvcodecFindDecoderByName(n string) *Codec {
return (*Codec)(C.avcodec_find_decoder_by_name(C.CString(n)))
Expand Down
20 changes: 20 additions & 0 deletions avcodec/avcodec_n4.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// +build !n3,!n2,!n1,!n0
// require ffmpeg tag n4.x

package avcodec

//#cgo pkg-config: libavformat libavcodec libavutil libswresample
//#include <stdio.h>
//#include <stdlib.h>
//#include <inttypes.h>
//#include <stdint.h>
//#include <string.h>
//#include <libavformat/avformat.h>
//#include <libavcodec/avcodec.h>
//#include <libavutil/avutil.h>
import "C"
import "unsafe"

func AvCodecIterate(p *unsafe.Pointer) *Codec {
return (*Codec)(C.av_codec_iterate(p))
}
10 changes: 10 additions & 0 deletions avcodec/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@ func (ctxt *Context) AvcodecCopyContext(ctxt2 *Context) int {
return int(C.avcodec_copy_context((*C.struct_AVCodecContext)(ctxt), (*C.struct_AVCodecContext)(ctxt2)))
}

//Convert settings from AvCodecParameters into the destination Context.
func (ctxt *Context) AvcodecFromParameters(parameters *AvCodecParameters) int {
return int(C.avcodec_parameters_to_context((*C.struct_AVCodecContext)(ctxt), (*C.struct_AVCodecParameters)(parameters)))
}

//Convert settings from the destination Context into AvCodecParameters.
func (ctxt *Context) AvcodecToParameters(parameters *AvCodecParameters) int {
return int(C.avcodec_parameters_from_context((*C.struct_AVCodecParameters)(parameters), (*C.struct_AVCodecContext)(ctxt)))
}

//Initialize the Context to use the given Codec
func (ctxt *Context) AvcodecOpen2(c *Codec, d **Dictionary) int {
return int(C.avcodec_open2((*C.struct_AVCodecContext)(ctxt), (*C.struct_AVCodec)(c), (**C.struct_AVDictionary)(unsafe.Pointer(d))))
Expand Down
2 changes: 1 addition & 1 deletion avcodec/packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (p *Packet) AvCopyPacketSideData(r *Packet) int {

}

//Free a packet.
//Free inner data of a packet.
func (p *Packet) AvFreePacket() {
C.av_free_packet((*C.struct_AVPacket)(p))

Expand Down
2 changes: 1 addition & 1 deletion avutil/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import "errors"

const (
AvErrorEOF = -('E' | ('O' << 8) | ('F' << 16) | (' ' << 24))
AvErrorEAGAIN = -35
AvErrorEAGAIN = -11
)

func ErrorFromCode(code int) error {
Expand Down
8 changes: 0 additions & 8 deletions avutil/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ func AvMalloc(s uintptr) unsafe.Pointer {
return unsafe.Pointer(C.av_malloc(C.size_t(s)))
}

func AvMallocArray(n, s uintptr) unsafe.Pointer {
return C.av_malloc_array(C.size_t(n), C.size_t(s))
}

//Allocate or reallocate a block of memory.
func AvRealloc(p *int, s uintptr) unsafe.Pointer {
return C.av_realloc(unsafe.Pointer(&p), C.size_t(s))
Expand Down Expand Up @@ -61,10 +57,6 @@ func AvCalloc(n, s uintptr) unsafe.Pointer {
return C.av_calloc(C.size_t(n), C.size_t(s))
}

func AvMalloczArray(n, s uintptr) unsafe.Pointer {
return C.av_mallocz_array(C.size_t(n), C.size_t(s))
}

//Duplicate the string s.
func AvStrdup(s string) string {
return C.GoString(C.av_strdup(C.CString(s)))
Expand Down
21 changes: 21 additions & 0 deletions avutil/memory_n4.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// +build !n3,!n2,!n1,!n0
// require ffmpeg tag n4.x

package avutil

/*
#cgo pkg-config: libavutil
#include <libavutil/avutil.h>
#include <libavutil/frame.h>
#include <stdlib.h>
*/
import "C"
import "unsafe"

func AvMallocArray(n, s uintptr) unsafe.Pointer {
return C.av_malloc_array(C.size_t(n), C.size_t(s))
}

func AvMalloczArray(n, s uintptr) unsafe.Pointer {
return C.av_mallocz_array(C.size_t(n), C.size_t(s))
}