diff --git a/protocol/rtp/client.go b/protocol/rtp/client.go index f47f9baf..ea6951cf 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. @@ -49,7 +49,7 @@ func NewClient(addr string) (*Client, error) { 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,17 @@ 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) +} + +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 }