diff --git a/protocol/rtp/client.go b/protocol/rtp/client.go index f47f9baf..3ab856b9 100644 --- a/protocol/rtp/client.go +++ b/protocol/rtp/client.go @@ -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 : 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 }