-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathstreams_buffer.go
More file actions
49 lines (39 loc) · 1.27 KB
/
streams_buffer.go
File metadata and controls
49 lines (39 loc) · 1.27 KB
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
package avformat
import (
"github.com/lkmio/avformat/collections"
"github.com/lkmio/avformat/utils"
)
type StreamsBuffer struct {
buffers []*collections.RBBlockBuffer
}
func (s *StreamsBuffer) findOrCreateStreamBuffer(index int, mediaType utils.AVMediaType) *collections.RBBlockBuffer {
exist := index < len(s.buffers)
if !exist {
if utils.AVMediaTypeVideo == mediaType {
s.buffers = append(s.buffers, collections.NewRBBlockBuffer(1024*1024*2))
} else {
s.buffers = append(s.buffers, collections.NewRBBlockBuffer(48000*12))
}
}
return s.buffers[index]
}
func (s *StreamsBuffer) Write(data []byte, index int, mediaType utils.AVMediaType) (int, error) {
s.findOrCreateStreamBuffer(index, mediaType).Write(data)
return len(data), nil
}
func (s *StreamsBuffer) Fetch(index int) ([]byte, error) {
data := s.findOrCreateStreamBuffer(index, utils.AVMediaTypeUnknown).Fetch()
return data, nil
}
func (s *StreamsBuffer) Discard(index int) {
s.buffers[index].Pop()
}
func (s *StreamsBuffer) DiscardBackPacket(index int) {
s.buffers[index].PopBack()
}
func (s *StreamsBuffer) DiscardHeadPacket(index int) {
s.buffers[index].Pop()
}
func (s *StreamsBuffer) PendingBlockSize(index int) int {
return s.findOrCreateStreamBuffer(index, utils.AVMediaTypeUnknown).PendingBlockSize()
}