protocol/rtp: consts for chan and ringbuffer sizes

This commit is contained in:
Saxon 2019-04-20 21:05:28 +09:30
parent 190d546c58
commit 00db293b44
1 changed files with 13 additions and 4 deletions

View File

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