diff --git a/protocol/rtcp/client.go b/protocol/rtcp/client.go index 6d293648..da2fddde 100644 --- a/protocol/rtcp/client.go +++ b/protocol/rtcp/client.go @@ -45,6 +45,7 @@ const ( defaultClientName = "client" delayUnit = 1.0 / 65536.0 pkg = "rtcp: " + rtcpVer = 2 ) type log func(lvl int8, msg string, args ...interface{}) @@ -52,7 +53,8 @@ type log func(lvl int8, msg string, args ...interface{}) // client is an RTCP client that will hadle receiving SenderReports from a server // and sending out ReceiverReports. type client struct { - ErrChan chan error + ErrChan chan error + cAddr *net.UDPAddr sAddr *net.UDPAddr name string @@ -125,7 +127,7 @@ func (c *client) Stop() { c.wg.Wait() } -// listen reads from the UDP connection and parses SenderReports. +// recv reads from the UDP connection and parses SenderReports. func (c *client) recv() { defer c.wg.Done() c.log(logger.Debug, pkg+"client is receiving") @@ -159,7 +161,7 @@ func (c *client) send() { report := ReceiverReport{ Header: Header{ - Version: 2, + Version: rtcpVer, Padding: false, ReportCount: 1, Type: typeReceiverReport, @@ -181,7 +183,7 @@ func (c *client) send() { description := SourceDescription{ Header: Header{ - Version: 2, + Version: rtcpVer, Padding: false, ReportCount: 1, Type: typeSourceDescription, diff --git a/protocol/rtcp/client_test.go b/protocol/rtcp/client_test.go index b7d61572..a05822fe 100644 --- a/protocol/rtcp/client_test.go +++ b/protocol/rtcp/client_test.go @@ -202,12 +202,12 @@ func TestReceiveAndSend(t *testing.T) { now := time.Now().Second() var time [8]byte binary.BigEndian.PutUint64(time[:], uint64(now)) - msw := binary.BigEndian.Uint32(time[:]) + msw := binary.BigEndian.Uint32(time[:4]) lsw := binary.BigEndian.Uint32(time[4:]) report := SenderReport{ Header: Header{ - Version: 2, + Version: rtcpVer, Padding: false, ReportCount: 0, Type: typeSenderReport, diff --git a/protocol/rtcp/parse.go b/protocol/rtcp/parse.go index b033cb74..d56af390 100644 --- a/protocol/rtcp/parse.go +++ b/protocol/rtcp/parse.go @@ -39,7 +39,7 @@ func Timestamp(buf []byte) (msw, lsw uint32, err error) { if len(buf) < 4 { return 0, 0, errors.New("bad RTCP packet, not of sufficient length") } - if (buf[0] & 0xc0 >> 6) != 2 { + if (buf[0]&0xc0)>>6 != 2 { return 0, 0, errors.New("incompatible RTCP version") } diff --git a/protocol/rtcp/rtcp.go b/protocol/rtcp/rtcp.go index 098438ea..1fd3cf3f 100644 --- a/protocol/rtcp/rtcp.go +++ b/protocol/rtcp/rtcp.go @@ -72,18 +72,13 @@ func (r *ReceiverReport) Bytes(buf []byte) []byte { idx := 8 for _, b := range r.Blocks { binary.BigEndian.PutUint32(buf[idx:], b.SSRC) - idx += 4 - binary.BigEndian.PutUint32(buf[idx:], b.PacketsLost) - buf[idx] = b.FractionLost - idx += 4 - binary.BigEndian.PutUint32(buf[idx:], b.HighestSequence) - idx += 4 - binary.BigEndian.PutUint32(buf[idx:], b.Jitter) - idx += 4 - binary.BigEndian.PutUint32(buf[idx:], b.LSR) - idx += 4 - binary.BigEndian.PutUint32(buf[idx:], b.DLSR) - idx += 4 + binary.BigEndian.PutUint32(buf[idx+4:], b.PacketsLost) + buf[idx+4] = b.FractionLost + binary.BigEndian.PutUint32(buf[idx+8:], b.HighestSequence) + binary.BigEndian.PutUint32(buf[idx+12:], b.Jitter) + binary.BigEndian.PutUint32(buf[idx+16:], b.LSR) + binary.BigEndian.PutUint32(buf[idx+20:], b.DLSR) + idx += 24 } for _, e := range r.Extensions { @@ -132,9 +127,8 @@ func (d *SourceDescription) Bytes(buf []byte) []byte { idx += 4 for _, i := range c.Items { buf[idx] = i.Type - idx++ - buf[idx] = byte(len(i.Text)) - idx++ + buf[idx+1] = byte(len(i.Text)) + idx += 2 copy(buf[idx:], i.Text) idx += len(i.Text) }