mirror of https://bitbucket.org/ausocean/av.git
protocol/rtp: removed op from Client i.e. what is read from Client are RTP packets.
This commit is contained in:
parent
d358f70585
commit
80a7d41d8a
|
@ -47,7 +47,7 @@ const (
|
|||
|
||||
// RingBuffer consts.
|
||||
const (
|
||||
ringBufferSize = 10
|
||||
ringBufferSize = 100
|
||||
ringBufferElementSize = 4096
|
||||
)
|
||||
|
||||
|
@ -60,7 +60,6 @@ type Client struct {
|
|||
wg sync.WaitGroup // Used to wait for recv routine to finish.
|
||||
done chan struct{} // Used to terminate the recv routine.
|
||||
ring *ring.Buffer // Processed data from RTP packets will be stored here.
|
||||
op func([]byte) ([]byte, error) // The operation to perform on received RTP packets before storing.
|
||||
err chan error // Errors encountered during recv will be sent to this chan.
|
||||
rt time.Duration // Read timeout used when reading from the ringbuffer.
|
||||
log
|
||||
|
@ -75,11 +74,10 @@ type Client struct {
|
|||
// in the ringBuffer for reading. l is a logging function defined by the
|
||||
// signuture of the log type defined above. rt is the read timeout used when
|
||||
// reading from the client ringbuffer.
|
||||
func NewClient(addr string, op func([]byte) ([]byte, error), l log, rt time.Duration) (*Client, error) {
|
||||
func NewClient(addr string, l log, rt time.Duration) (*Client, error) {
|
||||
c := &Client{
|
||||
done: make(chan struct{}, chanSize),
|
||||
ring: ring.NewBuffer(ringBufferSize, ringBufferElementSize, 0),
|
||||
op: op,
|
||||
log: l,
|
||||
err: make(chan error),
|
||||
rt: rt,
|
||||
|
@ -139,19 +137,7 @@ func (c *Client) recv() {
|
|||
}
|
||||
c.log(logger.Debug, pkg+"packet received", "packet", buf[:n])
|
||||
|
||||
var _buf []byte
|
||||
switch c.op {
|
||||
case nil:
|
||||
_buf = buf[:n]
|
||||
default:
|
||||
_buf, err = c.op(buf[:n])
|
||||
if err != nil {
|
||||
c.err <- err
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
_, err = c.ring.Write(_buf)
|
||||
_, err = c.ring.Write(buf[:n])
|
||||
c.ring.Flush()
|
||||
if err != nil {
|
||||
c.err <- err
|
||||
|
|
|
@ -75,7 +75,6 @@ func TestReceive(t *testing.T) {
|
|||
packetsToSend = 20
|
||||
)
|
||||
|
||||
for _, op := range []func([]byte) ([]byte, error){nil, Payload} {
|
||||
testErr := make(chan error)
|
||||
serverErr := make(chan error)
|
||||
done := make(chan struct{})
|
||||
|
@ -86,7 +85,7 @@ func TestReceive(t *testing.T) {
|
|||
go func() {
|
||||
// Create and start the client.
|
||||
var err error
|
||||
c, err = NewClient(clientAddr, op, (*dummyLogger)(t).log, 1*time.Millisecond)
|
||||
c, err = NewClient(clientAddr, (*dummyLogger)(t).log, 1*time.Millisecond)
|
||||
if err != nil {
|
||||
testErr <- fmt.Errorf("could not create client, failed with error: %v\n", err)
|
||||
}
|
||||
|
@ -108,12 +107,6 @@ func TestReceive(t *testing.T) {
|
|||
|
||||
// Create expected data and apply operation if there is one.
|
||||
expect := (&Pkt{V: rtpVer, Payload: []byte{byte(packetsReceived)}}).Bytes(nil)
|
||||
if op != nil {
|
||||
expect, err = op(expect)
|
||||
if err != nil {
|
||||
testErr <- fmt.Errorf("unexpected error when applying op: %v\n", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Compare.
|
||||
got := buf[:n]
|
||||
|
@ -165,4 +158,3 @@ func TestReceive(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue