-
Notifications
You must be signed in to change notification settings - Fork 170
/
samplefmt_go112.go
56 lines (42 loc) · 1.03 KB
/
samplefmt_go112.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// +build go1.12
package gmf
/*
#cgo pkg-config: libavutil
#include "libavutil/samplefmt.h"
*/
import "C"
import (
"errors"
"fmt"
"unsafe"
)
//
// Unfinished.
//
type SampleFormat int
type Sample struct {
data **C.uint8_t
linesize *int
format SampleFormat
CgoMemoryManage
}
func NewSample(nbSamples, nbChannels int, format SampleFormat) error {
panic("This stuff is unfinished.")
sample := &Sample{format: format}
if ret := int(C.av_samples_alloc_array_and_samples(
&sample.data,
(*C.int)(unsafe.Pointer(&sample.linesize)),
C.int(nbChannels), C.int(nbSamples), int32(format), 0)); ret < 0 {
return errors.New(fmt.Sprintf("Unable to allocate array and samples: %v", AvError(ret)))
}
return nil
}
func (s *Sample) SampleRealloc(nbSamples, nbChannels int) error {
if ret := int(C.av_samples_alloc(
s.data,
(*C.int)(unsafe.Pointer(&s.linesize)),
C.int(nbChannels), C.int(nbSamples), int32(s.format), 0)); ret < 0 {
return errors.New(fmt.Sprintf("Unable to allocate samples: %v", AvError(ret)))
}
return nil
}