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 package codec
import ( import (
@ -18,7 +17,7 @@ import (
static int aacdec_new(aacdec_t *m, uint8_t *buf, int len) { static int aacdec_new(aacdec_t *m, uint8_t *buf, int len) {
m->c = avcodec_find_decoder(CODEC_ID_AAC); m->c = avcodec_find_decoder(CODEC_ID_AAC);
m->ctx = avcodec_alloc_context3(m->c); m->ctx = avcodec_alloc_context3(m->c);
m->f = avcodec_alloc_frame(); m->f = av_frame_alloc();
m->ctx->extradata = buf; m->ctx->extradata = buf;
m->ctx->extradata_size = len; m->ctx->extradata_size = len;
m->ctx->debug = 0x3; m->ctx->debug = 0x3;
@ -36,8 +35,8 @@ import (
} }
*/ */
"C" "C"
"unsafe"
"errors" "errors"
"unsafe"
) )
type AACDecoder struct { type AACDecoder struct {
@ -81,4 +80,3 @@ func (m *AACDecoder) Decode(data []byte) (sample []byte, err error) {
} }
return return
} }

View File

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

View File

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

View File

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

View File

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