protocol/rtcp: addressing of PR feedback

This commit is contained in:
Saxon 2019-04-16 17:16:13 +09:30
parent f54dd13959
commit 51478ee064
4 changed files with 18 additions and 22 deletions

View File

@ -45,6 +45,7 @@ const (
defaultClientName = "client" defaultClientName = "client"
delayUnit = 1.0 / 65536.0 delayUnit = 1.0 / 65536.0
pkg = "rtcp: " pkg = "rtcp: "
rtcpVer = 2
) )
type log func(lvl int8, msg string, args ...interface{}) 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 // client is an RTCP client that will hadle receiving SenderReports from a server
// and sending out ReceiverReports. // and sending out ReceiverReports.
type client struct { type client struct {
ErrChan chan error ErrChan chan error
cAddr *net.UDPAddr cAddr *net.UDPAddr
sAddr *net.UDPAddr sAddr *net.UDPAddr
name string name string
@ -125,7 +127,7 @@ func (c *client) Stop() {
c.wg.Wait() 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() { func (c *client) recv() {
defer c.wg.Done() defer c.wg.Done()
c.log(logger.Debug, pkg+"client is receiving") c.log(logger.Debug, pkg+"client is receiving")
@ -159,7 +161,7 @@ func (c *client) send() {
report := ReceiverReport{ report := ReceiverReport{
Header: Header{ Header: Header{
Version: 2, Version: rtcpVer,
Padding: false, Padding: false,
ReportCount: 1, ReportCount: 1,
Type: typeReceiverReport, Type: typeReceiverReport,
@ -181,7 +183,7 @@ func (c *client) send() {
description := SourceDescription{ description := SourceDescription{
Header: Header{ Header: Header{
Version: 2, Version: rtcpVer,
Padding: false, Padding: false,
ReportCount: 1, ReportCount: 1,
Type: typeSourceDescription, Type: typeSourceDescription,

View File

@ -202,12 +202,12 @@ func TestReceiveAndSend(t *testing.T) {
now := time.Now().Second() now := time.Now().Second()
var time [8]byte var time [8]byte
binary.BigEndian.PutUint64(time[:], uint64(now)) binary.BigEndian.PutUint64(time[:], uint64(now))
msw := binary.BigEndian.Uint32(time[:]) msw := binary.BigEndian.Uint32(time[:4])
lsw := binary.BigEndian.Uint32(time[4:]) lsw := binary.BigEndian.Uint32(time[4:])
report := SenderReport{ report := SenderReport{
Header: Header{ Header: Header{
Version: 2, Version: rtcpVer,
Padding: false, Padding: false,
ReportCount: 0, ReportCount: 0,
Type: typeSenderReport, Type: typeSenderReport,

View File

@ -39,7 +39,7 @@ func Timestamp(buf []byte) (msw, lsw uint32, err error) {
if len(buf) < 4 { if len(buf) < 4 {
return 0, 0, errors.New("bad RTCP packet, not of sufficient length") 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") return 0, 0, errors.New("incompatible RTCP version")
} }

View File

@ -72,18 +72,13 @@ func (r *ReceiverReport) Bytes(buf []byte) []byte {
idx := 8 idx := 8
for _, b := range r.Blocks { for _, b := range r.Blocks {
binary.BigEndian.PutUint32(buf[idx:], b.SSRC) binary.BigEndian.PutUint32(buf[idx:], b.SSRC)
idx += 4 binary.BigEndian.PutUint32(buf[idx+4:], b.PacketsLost)
binary.BigEndian.PutUint32(buf[idx:], b.PacketsLost) buf[idx+4] = b.FractionLost
buf[idx] = b.FractionLost binary.BigEndian.PutUint32(buf[idx+8:], b.HighestSequence)
idx += 4 binary.BigEndian.PutUint32(buf[idx+12:], b.Jitter)
binary.BigEndian.PutUint32(buf[idx:], b.HighestSequence) binary.BigEndian.PutUint32(buf[idx+16:], b.LSR)
idx += 4 binary.BigEndian.PutUint32(buf[idx+20:], b.DLSR)
binary.BigEndian.PutUint32(buf[idx:], b.Jitter) idx += 24
idx += 4
binary.BigEndian.PutUint32(buf[idx:], b.LSR)
idx += 4
binary.BigEndian.PutUint32(buf[idx:], b.DLSR)
idx += 4
} }
for _, e := range r.Extensions { for _, e := range r.Extensions {
@ -132,9 +127,8 @@ func (d *SourceDescription) Bytes(buf []byte) []byte {
idx += 4 idx += 4
for _, i := range c.Items { for _, i := range c.Items {
buf[idx] = i.Type buf[idx] = i.Type
idx++ buf[idx+1] = byte(len(i.Text))
buf[idx] = byte(len(i.Text)) idx += 2
idx++
copy(buf[idx:], i.Text) copy(buf[idx:], i.Text)
idx += len(i.Text) idx += len(i.Text)
} }