forked from asticode/go-astiav
-
Notifications
You must be signed in to change notification settings - Fork 0
/
audio_fifo.go
60 lines (50 loc) · 1.94 KB
/
audio_fifo.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
57
58
59
60
package astiav
//#include <libavutil/audio_fifo.h>
import "C"
import "unsafe"
// https://ffmpeg.org/doxygen/7.0/structAVAudioFifo.html
type AudioFifo struct {
c *C.AVAudioFifo
}
func newAudioFifoFromC(c *C.AVAudioFifo) *AudioFifo {
if c == nil {
return nil
}
return &AudioFifo{c: c}
}
// https://ffmpeg.org/doxygen/7.0/group__lavu__audiofifo.html#ga9d792394f0615a329aec47847f8f8784
func AllocAudioFifo(sampleFmt SampleFormat, channels int, nbSamples int) *AudioFifo {
return newAudioFifoFromC(C.av_audio_fifo_alloc(C.enum_AVSampleFormat(sampleFmt), C.int(channels), C.int(nbSamples)))
}
// https://ffmpeg.org/doxygen/7.0/group__lavu__audiofifo.html#ga27c1e16e5f09940d6016b1971c0b5742
func (a *AudioFifo) Realloc(nbSamples int) error {
return newError(C.av_audio_fifo_realloc(a.c, C.int(nbSamples)))
}
// https://ffmpeg.org/doxygen/7.0/group__lavu__audiofifo.html#gaa0a4742ecac52a999e8b4478d27f3b9b
func (a *AudioFifo) Size() int {
return int(C.av_audio_fifo_size(a.c))
}
// https://ffmpeg.org/doxygen/7.0/group__lavu__audiofifo.html#ga2bed2f01fe34228ee8a73617b3177d00
func (a *AudioFifo) Space() int {
return int(C.av_audio_fifo_space(a.c))
}
// https://ffmpeg.org/doxygen/7.0/group__lavu__audiofifo.html#ga51d81a165872919bbfdee3f00f6d6530
func (a *AudioFifo) Write(f *Frame) (int, error) {
ret := C.av_audio_fifo_write(a.c, (*unsafe.Pointer)(unsafe.Pointer(&f.c.data[0])), C.int(f.NbSamples()))
if err := newError(ret); err != nil {
return 0, err
}
return int(ret), nil
}
// https://ffmpeg.org/doxygen/7.0/group__lavu__audiofifo.html#ga5e2c87bbeefba0d229b4109b4b755529
func (a *AudioFifo) Read(f *Frame) (int, error) {
ret := C.av_audio_fifo_read(a.c, (*unsafe.Pointer)(unsafe.Pointer(&f.c.data[0])), C.int(f.NbSamples()))
if err := newError(ret); err != nil {
return 0, err
}
return int(ret), nil
}
// https://ffmpeg.org/doxygen/7.0/group__lavu__audiofifo.html#ga74e029e47f7aa99217ad1f315c434875
func (a *AudioFifo) Free() {
C.av_audio_fifo_free(a.c)
}