| | |
| | | } |
| | | return nil, 0, 0 |
| | | } |
| | | |
| | | ///////////////for encoder |
| | | |
| | | // GoEncoder encoder |
| | | type GoEncoder struct { |
| | | enc C.cencoder |
| | | } |
| | | |
| | | // NewEncoder encoder |
| | | func NewEncoder(w, h, fps, br, sFlag, gi int) *GoEncoder { |
| | | if w <= 0 || h <= 0 { |
| | | return nil |
| | | } |
| | | |
| | | return &GoEncoder{ |
| | | enc: C.wrap_fn_create_encoder(C.int(w), C.int(h), C.int(fps), C.int(br), C.int(sFlag), C.int(gi)), |
| | | } |
| | | } |
| | | |
| | | // Free free |
| | | func (e *GoEncoder) Free() { |
| | | C.wrap_fn_destroy_encoder(e.enc) |
| | | } |
| | | |
| | | // Encode pic |
| | | func (e *GoEncoder) Encode(in []byte, w, h int) ([]byte, int, bool) { |
| | | |
| | | var size C.int |
| | | var key C.int |
| | | cin := C.CBytes(in) |
| | | defer C.free(cin) |
| | | |
| | | p := C.wrap_fn_encode(e.enc, cin, C.int(w), C.int(h), &size, &key) |
| | | defer C.free(p) |
| | | if p != nil && size > 0 { |
| | | b := C.GoBytes(p, size) |
| | | |
| | | isKey := false |
| | | if key > 0 { |
| | | isKey = true |
| | | } |
| | | return b, int(size), isKey |
| | | } |
| | | return nil, 0, false |
| | | } |