mirror of https://bitbucket.org/ausocean/av.git
protocol/rtp: consts for chan and ringbuffer sizes
This commit is contained in:
parent
190d546c58
commit
00db293b44
|
@ -37,10 +37,17 @@ import (
|
|||
"bitbucket.org/ausocean/utils/ring"
|
||||
)
|
||||
|
||||
// Misc consts.
|
||||
const (
|
||||
chanSize = 10
|
||||
)
|
||||
|
||||
// RingBuffer consts.
|
||||
const (
|
||||
ringBufferSize = 10
|
||||
ringBufferElementSize = 4096
|
||||
)
|
||||
|
||||
// Client describes an RTP client that can receive an RTP stream and implements
|
||||
// io.Reader.
|
||||
type Client struct {
|
||||
|
@ -61,8 +68,8 @@ type Client struct {
|
|||
// in the ringBuffer for reading.
|
||||
func NewClient(addr string, op func([]byte) ([]byte, error)) (*Client, error) {
|
||||
c := &Client{
|
||||
done: make(chan struct{}, 10),
|
||||
ring: ring.NewBuffer(10, 4096, 0),
|
||||
done: make(chan struct{}, chanSize),
|
||||
ring: ring.NewBuffer(ringBufferSize, ringBufferElementSize, 0),
|
||||
op: op,
|
||||
}
|
||||
|
||||
|
@ -90,7 +97,7 @@ func (c *Client) Start() {
|
|||
// ringBuffer for Reading.
|
||||
func (c *Client) recv() {
|
||||
defer c.wg.Done()
|
||||
buf := make([]byte, 4096)
|
||||
buf := make([]byte, ringBufferElementSize)
|
||||
for {
|
||||
select {
|
||||
case <-c.done:
|
||||
|
@ -101,6 +108,7 @@ func (c *Client) recv() {
|
|||
c.ErrChan <- err
|
||||
continue
|
||||
}
|
||||
|
||||
var _buf []byte
|
||||
switch c.op {
|
||||
case nil:
|
||||
|
@ -112,6 +120,7 @@ func (c *Client) recv() {
|
|||
continue
|
||||
}
|
||||
}
|
||||
|
||||
_, err = c.ring.Write(_buf)
|
||||
c.ring.Flush()
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue