split ffctx to single file
This commit is contained in:
parent
54c98210dd
commit
3c6c076e44
50
audio.go
50
audio.go
@ -1,20 +1,17 @@
|
|||||||
package ffmpeg
|
package ffmpeg
|
||||||
|
|
||||||
|
/*
|
||||||
|
#include "ffmpeg.h"
|
||||||
|
int wrap_avcodec_decode_audio4(AVCodecContext *ctx, AVFrame *frame, void *data, int size, int *got) {
|
||||||
|
struct AVPacket pkt = {.data = data, .size = size};
|
||||||
|
return avcodec_decode_audio4(ctx, frame, got, &pkt);
|
||||||
|
}
|
||||||
|
int wrap_avresample_convert(AVAudioResampleContext *avr, int *out, int outsize, int outcount, int *in, int insize, int incount) {
|
||||||
|
return avresample_convert(avr, (void *)out, outsize, outcount, (void *)in, insize, incount);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
import "C"
|
||||||
import (
|
import (
|
||||||
/*
|
|
||||||
#include "ffmpeg.h"
|
|
||||||
|
|
||||||
int wrap_avcodec_decode_audio4(AVCodecContext *ctx, AVFrame *frame, void *data, int size, int *got) {
|
|
||||||
struct AVPacket pkt = {.data = data, .size = size};
|
|
||||||
return avcodec_decode_audio4(ctx, frame, got, &pkt);
|
|
||||||
}
|
|
||||||
|
|
||||||
int wrap_avresample_convert(AVAudioResampleContext *avr, int *out, int outsize, int outcount, int *in, int insize, int incount) {
|
|
||||||
return avresample_convert(avr, (void *)out, outsize, outcount, (void *)in, insize, incount);
|
|
||||||
}
|
|
||||||
|
|
||||||
*/
|
|
||||||
"C"
|
|
||||||
"unsafe"
|
"unsafe"
|
||||||
"runtime"
|
"runtime"
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -24,10 +21,6 @@ import (
|
|||||||
|
|
||||||
const debug = false
|
const debug = false
|
||||||
|
|
||||||
type ffctx struct {
|
|
||||||
ff C.FFCtx
|
|
||||||
}
|
|
||||||
|
|
||||||
type Resampler struct {
|
type Resampler struct {
|
||||||
inSampleFormat, OutSampleFormat av.SampleFormat
|
inSampleFormat, OutSampleFormat av.SampleFormat
|
||||||
inChannelLayout, OutChannelLayout av.ChannelLayout
|
inChannelLayout, OutChannelLayout av.ChannelLayout
|
||||||
@ -546,27 +539,6 @@ func HasDecoder(name string) bool {
|
|||||||
//func EncodersList() []string
|
//func EncodersList() []string
|
||||||
//func DecodersList() []string
|
//func DecodersList() []string
|
||||||
|
|
||||||
func newFFCtxByCodec(codec *C.AVCodec) (ff *ffctx, err error) {
|
|
||||||
ff = &ffctx{}
|
|
||||||
ff.ff.codec = codec
|
|
||||||
ff.ff.codecCtx = C.avcodec_alloc_context3(codec)
|
|
||||||
runtime.SetFinalizer(ff, freeFFCtx)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func freeFFCtx(self *ffctx) {
|
|
||||||
ff := &self.ff
|
|
||||||
if ff.frame != nil {
|
|
||||||
C.av_frame_free(&ff.frame)
|
|
||||||
ff.frame = nil
|
|
||||||
}
|
|
||||||
if ff.codecCtx != nil {
|
|
||||||
C.avcodec_close(ff.codecCtx)
|
|
||||||
C.av_free(unsafe.Pointer(ff.codecCtx))
|
|
||||||
ff.codecCtx = nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewAudioEncoderByCodecType(typ int) (enc *AudioEncoder, err error) {
|
func NewAudioEncoderByCodecType(typ int) (enc *AudioEncoder, err error) {
|
||||||
var id uint32
|
var id uint32
|
||||||
|
|
||||||
|
29
ffmpeg.go
29
ffmpeg.go
@ -8,6 +8,10 @@ void ffinit() {
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
|
import (
|
||||||
|
"runtime"
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
QUIET = int(C.AV_LOG_QUIET)
|
QUIET = int(C.AV_LOG_QUIET)
|
||||||
@ -29,3 +33,28 @@ func init() {
|
|||||||
C.ffinit()
|
C.ffinit()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ffctx struct {
|
||||||
|
ff C.FFCtx
|
||||||
|
}
|
||||||
|
|
||||||
|
func newFFCtxByCodec(codec *C.AVCodec) (ff *ffctx, err error) {
|
||||||
|
ff = &ffctx{}
|
||||||
|
ff.ff.codec = codec
|
||||||
|
ff.ff.codecCtx = C.avcodec_alloc_context3(codec)
|
||||||
|
runtime.SetFinalizer(ff, freeFFCtx)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func freeFFCtx(self *ffctx) {
|
||||||
|
ff := &self.ff
|
||||||
|
if ff.frame != nil {
|
||||||
|
C.av_frame_free(&ff.frame)
|
||||||
|
ff.frame = nil
|
||||||
|
}
|
||||||
|
if ff.codecCtx != nil {
|
||||||
|
C.avcodec_close(ff.codecCtx)
|
||||||
|
C.av_free(unsafe.Pointer(ff.codecCtx))
|
||||||
|
ff.codecCtx = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user