mirror of https://bitbucket.org/ausocean/av.git
protocol/rtp/client.go: wrote PacketReader type
Client now possesses a PacketReader which has it's Read func wrapped by the Client's Read func
This commit is contained in:
parent
11ad16dbe1
commit
6acc2d7376
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue