Skip to content

Commit

Permalink
sp 3d0c#1, not working
Browse files Browse the repository at this point in the history
  • Loading branch information
3d0c committed May 15, 2014
1 parent ad9913e commit 7ade702
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
38 changes: 25 additions & 13 deletions avio.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,26 @@ package gmf
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <string.h>
#include "libavformat/avio.h"
extern int readCallBack(void*, uint8_t*, int);
static int wrap(void *o, uint8_t *buf, int buf_size) {
fprintf(stderr, "buf_size:%d\n", buf_size);
buf = av_malloc(buf_size);
int ret = readCallBack(o, buf, buf_size);
fprintf(stderr, "ret: %d\ndata:\n%s\n", ret, buf);
fprintf(stderr, "len:%d\n", ret);
return ret;
}
static AVIOContext *gmf_avio_alloc_context(unsigned char *buffer, int buf_size, void *opaque) {
return avio_alloc_context(buffer, buf_size, 0, opaque, wrap, NULL, NULL);
return avio_alloc_context(buffer, buf_size, 0, opaque, readCallBack, NULL, NULL);
}
*/
Expand All @@ -34,7 +40,7 @@ import (
)

var (
IO_BUFFER_SIZE int = 32768
IO_BUFFER_SIZE int = 1024
)

var ReaderHandler func()
Expand Down Expand Up @@ -67,28 +73,34 @@ var section *io.SectionReader
func readCallBack(opaque unsafe.Pointer, buf *C.uint8_t, buf_size C.int) C.int {
// b, n := reader()
// fmt.Println((*_Ctype_AVIOContext)(opaque).buffer)
// return C.int(n)
file, err := os.Open("tmp/ref.mp4")
if err != nil {
panic(err)
}
var file *os.File
var err error

if section == nil {
file, err = os.Open("tmp/ref.mp4")
// file, err := os.Open("./avio.go")
if err != nil {
panic(err)
}

section = io.NewSectionReader(file, 0, int64(buf_size))
}

p := make([]byte, int(buf_size))
b := make([]byte, int(buf_size))

n, err := section.Read(p)
n, err := section.Read(b)
if err != nil {
panic(err)
fmt.Println(err)
file.Close()
}

fmt.Println(n, "bytes read")
fmt.Println(n, "bytes, [0-10]:", b[0:10])

buf = (*C.uint8_t)(unsafe.Pointer(&p[0]))
buf = (*C.uint8_t)(unsafe.Pointer(C.av_malloc(C.size_t(n))))
C.memcpy(unsafe.Pointer(buf), unsafe.Pointer(&b[0]), C.size_t(n))

return C.int(n)

}

func reader() {
Expand Down
1 change: 1 addition & 0 deletions format_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,5 +153,6 @@ func TestCtxPb(t *testing.T) {

for p := range ctx.Packets() {
p.Dump()
os.Exit(0)
}
}

0 comments on commit 7ade702

Please sign in to comment.