This commit is contained in:
aler9
2020-09-20 13:27:46 +02:00
parent 0fb858afd7
commit 6f69d9dabd
5 changed files with 74 additions and 34 deletions

30
multibuffer.go Normal file
View File

@@ -0,0 +1,30 @@
package gortsplib
// MultiBuffer implements software multi buffering, that allows to reuse
// existing buffers without creating new ones, increasing performance.
type MultiBuffer struct {
buffers [][]byte
curBuf int
}
// NewMultiBuffer allocates a MultiBuffer.
func NewMultiBuffer(count int, size int) *MultiBuffer {
buffers := make([][]byte, count)
for i := 0; i < count; i++ {
buffers[i] = make([]byte, size)
}
return &MultiBuffer{
buffers: buffers,
}
}
// Next gets the current buffer and sets the next buffer as the current one.
func (mb *MultiBuffer) Next() []byte {
ret := mb.buffers[mb.curBuf]
mb.curBuf += 1
if mb.curBuf >= len(mb.buffers) {
mb.curBuf = 0
}
return ret
}