mirror of https://bitbucket.org/ausocean/av.git
Merged in rtp-packet-reader (pull request #198)
protocol/rtp/client.go: Client now uses PacketReader Approved-by: Alan Noble <anoble@gmail.com>
This commit is contained in:
commit
5485399e6d
|
@ -34,7 +34,7 @@ import (
|
|||
// Client describes an RTP client that can receive an RTP stream and implements
|
||||
// io.Reader.
|
||||
type Client struct {
|
||||
conn *net.UDPConn
|
||||
r *PacketReader
|
||||
}
|
||||
|
||||
// NewClient returns a pointer to a new Client.
|
||||
|
@ -42,14 +42,14 @@ type Client struct {
|
|||
// addr is the address of form <ip>:<port> that we expect to receive
|
||||
// RTP at.
|
||||
func NewClient(addr string) (*Client, error) {
|
||||
c := &Client{}
|
||||
c := &Client{r: &PacketReader{}}
|
||||
|
||||
a, err := net.ResolveUDPAddr("udp", addr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
c.conn, err = net.ListenUDP("udp", a)
|
||||
c.r.PacketConn, err = net.ListenUDP("udp", a)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -57,7 +57,18 @@ func NewClient(addr string) (*Client, error) {
|
|||
return c, nil
|
||||
}
|
||||
|
||||
// Read implements io.Reader. This wraps the Read for the connection.
|
||||
// Read implements io.Reader.
|
||||
func (c *Client) Read(p []byte) (int, error) {
|
||||
return c.conn.Read(p)
|
||||
return c.r.Read(p)
|
||||
}
|
||||
|
||||
// PacketReader provides an io.Reader interface to an underlying UDP PacketConn.
|
||||
type PacketReader struct {
|
||||
net.PacketConn
|
||||
}
|
||||
|
||||
// Read implements io.Reader.
|
||||
func (r PacketReader) Read(b []byte) (int, error) {
|
||||
n, _, err := r.PacketConn.ReadFrom(b)
|
||||
return n, err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue