Merge pull request #9 from prohulaelk/cgo_compile_errors

fix for issues 2, 3, and 8
This commit is contained in:
nareix 2016-04-19 11:56:31 +08:00
commit 7e8474e9f2
5 changed files with 151 additions and 162 deletions

View File

@ -1,4 +1,3 @@
package codec
import (
@ -18,7 +17,7 @@ import (
static int aacdec_new(aacdec_t *m, uint8_t *buf, int len) {
m->c = avcodec_find_decoder(CODEC_ID_AAC);
m->ctx = avcodec_alloc_context3(m->c);
m->f = avcodec_alloc_frame();
m->f = av_frame_alloc();
m->ctx->extradata = buf;
m->ctx->extradata_size = len;
m->ctx->debug = 0x3;
@ -36,8 +35,8 @@ import (
}
*/
"C"
"unsafe"
"errors"
"unsafe"
)
type AACDecoder struct {
@ -70,7 +69,7 @@ func (m *AACDecoder) Decode(data []byte) (sample []byte, err error) {
err = errors.New("no data")
return
}
size := int(m.m.f.linesize[0])*2
size := int(m.m.f.linesize[0]) * 2
sample = make([]byte, size*2)
for i := 0; i < 2; i++ {
C.memcpy(
@ -81,4 +80,3 @@ func (m *AACDecoder) Decode(data []byte) (sample []byte, err error) {
}
return
}

View File

@ -1,4 +1,3 @@
package codec
import (
@ -25,7 +24,7 @@ import (
m->ctx->bit_rate = m->bitrate;
m->ctx->channels = m->channels;
m->ctx->strict_std_compliance = FF_COMPLIANCE_EXPERIMENTAL;
m->f = avcodec_alloc_frame();
m->f = av_frame_alloc();
int r = avcodec_open2(m->ctx, m->c, 0);
av_log(m->ctx, AV_LOG_DEBUG, "extra %d\n", m->ctx->extradata_size);
return r;
@ -45,8 +44,8 @@ import (
}
*/
"C"
"unsafe"
"errors"
"unsafe"
)
type AACEncoder struct {
@ -90,4 +89,3 @@ func (m *AACEncoder) Encode(sample []byte) (ret []byte, err error) {
)
return
}

View File

@ -1,4 +1,3 @@
package codec
import (
@ -17,7 +16,7 @@ import (
static int h264dec_new(h264dec_t *h, uint8_t *data, int len) {
h->c = avcodec_find_decoder(CODEC_ID_H264);
h->ctx = avcodec_alloc_context3(h->c);
h->f = avcodec_alloc_frame();
h->f = av_frame_alloc();
h->ctx->extradata = data;
h->ctx->extradata_size = len;
h->ctx->debug = 0x3;
@ -33,9 +32,9 @@ import (
}
*/
"C"
"unsafe"
"errors"
"image"
"unsafe"
)
type H264Decoder struct {
@ -87,4 +86,3 @@ func (m *H264Decoder) Decode(nal []byte) (f *image.YCbCr, err error) {
return
}

View File

@ -1,4 +1,3 @@
package codec
import (
@ -33,16 +32,16 @@ import (
m->ctx->bit_rate = m->bitrate;
m->ctx->pix_fmt = m->pixfmt;
m->ctx->flags |= CODEC_FLAG_GLOBAL_HEADER;
m->f = avcodec_alloc_frame();
m->f = av_frame_alloc();
return avcodec_open2(m->ctx, m->c, NULL);
}
*/
"C"
"unsafe"
"image"
"errors"
"image"
"strings"
"unsafe"
//"log"
)
@ -111,12 +110,12 @@ func (m *H264Encoder) Encode(img *image.YCbCr) (out h264Out, err error) {
return
}
f = m.m.f
f.data[0] = (*C.uint8_t)(unsafe.Pointer(&img.Y[0]));
f.data[1] = (*C.uint8_t)(unsafe.Pointer(&img.Cb[0]));
f.data[2] = (*C.uint8_t)(unsafe.Pointer(&img.Cr[0]));
f.linesize[0] = (C.int)(img.YStride);
f.linesize[1] = (C.int)(img.CStride);
f.linesize[2] = (C.int)(img.CStride);
f.data[0] = (*C.uint8_t)(unsafe.Pointer(&img.Y[0]))
f.data[1] = (*C.uint8_t)(unsafe.Pointer(&img.Cb[0]))
f.data[2] = (*C.uint8_t)(unsafe.Pointer(&img.Cr[0]))
f.linesize[0] = (C.int)(img.YStride)
f.linesize[1] = (C.int)(img.CStride)
f.linesize[2] = (C.int)(img.CStride)
}
C.av_init_packet(&m.m.pkt)
@ -130,7 +129,7 @@ func (m *H264Encoder) Encode(img *image.YCbCr) (out h264Out, err error) {
err = errors.New("no picture")
return
}
if (m.m.pkt.size == 0) {
if m.m.pkt.size == 0 {
err = errors.New("packet size == 0")
return
}
@ -145,4 +144,3 @@ func (m *H264Encoder) Encode(img *image.YCbCr) (out h264Out, err error) {
return
}

View File

@ -1,4 +1,3 @@
/*
Golang h264,aac decoder/encoder libav wrapper
@ -19,11 +18,11 @@ Golang h264,aac decoder/encoder libav wrapper
package codec
import (
"unsafe"
"reflect"
"unsafe"
/*
#cgo darwin LDFLAGS: -lavformat -lavutil -lavcodec
#cgo LDFLAGS: -lavformat -lavutil -lavcodec
#include <libavutil/avutil.h>
#include <libavformat/avformat.h>
@ -47,5 +46,3 @@ func fromCPtr(buf unsafe.Pointer, size int) (ret []uint8) {
hdr.Data = uintptr(buf)
return
}