diff --git a/rtmp/packet.go b/rtmp/packet.go index bf16b3cf..3c2c5d09 100644 --- a/rtmp/packet.go +++ b/rtmp/packet.go @@ -220,7 +220,7 @@ func (pkt *packet) readFrom(s *Session) error { pkt.bytesRead += uint32(chunkSize) - // keep the packet as a reference for other packets on this channel + // Keep the packet as a reference for other packets on this channel. if s.channelsIn[pkt.channel] == nil { s.channelsIn[pkt.channel] = &packet{} } @@ -231,7 +231,7 @@ func (pkt *packet) readFrom(s *Session) error { } if !pkt.hasAbsTimestamp { - // timestamps seem to always be relative + // Timestamps seem to always be relative. pkt.timestamp += uint32(s.channelTimestamp[pkt.channel]) } s.channelTimestamp[pkt.channel] = int32(pkt.timestamp) @@ -269,7 +269,7 @@ func (pkt *packet) resize(size uint32, ht uint8) { // writeTo writes a packet to the RTMP connection. // Packets are written in chunks which are Session.chunkSize in length (128 bytes in length). -// We defers sending small audio packets and combine consecutive small audio packets where possible to reduce I/O. +// We defer sending small audio packets and combine consecutive small audio packets where possible to reduce I/O. // When queue is true, we expect a response to this request and cache the method on s.methodCalls. func (pkt *packet) writeTo(s *Session, queue bool) error { if pkt.body == nil { @@ -298,7 +298,7 @@ func (pkt *packet) writeTo(s *Session, queue bool) error { prevPkt := s.channelsOut[pkt.channel] var last int if prevPkt != nil && pkt.headerType != headerSizeLarge { - // compress a bit by using the prev packet's attributes + // Compress header by using the previous packet's attributes. if prevPkt.bodySize == pkt.bodySize && prevPkt.packetType == pkt.packetType && pkt.headerType == headerSizeMedium { pkt.headerType = headerSizeSmall } @@ -321,7 +321,7 @@ func (pkt *packet) writeTo(s *Session, queue bool) error { hSize := headerSizes[pkt.headerType] origIdx := fullHeaderSize - hSize - // adjust 1 or 2 bytes for the channel + // Adjust 1 or 2 bytes depending on the channel. cSize := 0 switch { case pkt.channel > 319: @@ -335,7 +335,7 @@ func (pkt *packet) writeTo(s *Session, queue bool) error { hSize += cSize } - // adjust 4 bytes for the timestamp + // Adjust 4 bytes for the timestamp. var ts uint32 if prevPkt != nil { ts = uint32(int(pkt.timestamp) - last) @@ -372,11 +372,11 @@ func (pkt *packet) writeTo(s *Session, queue bool) error { } if headerSizes[pkt.headerType] > 1 { - res := ts + tmp := ts if ts > 0xffffff { - res = 0xffffff + tmp = 0xffffff } - amf.EncodeInt24(headBytes[headerIdx:], int32(res)) + amf.EncodeInt24(headBytes[headerIdx:], int32(tmp)) headerIdx += 3 // 24bits } @@ -468,17 +468,14 @@ func (pkt *packet) writeTo(s *Session, queue bool) error { } } - // We invoked a remote method, - if pkt.packetType == packetTypeInvoke { + // If we invoked a remote method and queue is true, we queue the method until the result arrives. + if pkt.packetType == packetTypeInvoke && queue { buf := pkt.body[1:] meth := amf.DecodeString(buf) - s.log(DebugLevel, pkg+"invoking method "+meth) - // keep it in call queue till result arrives - if queue { - buf = buf[3+len(meth):] - txn := int32(amf.DecodeNumber(buf[:8])) - s.methodCalls = append(s.methodCalls, method{name: meth, num: txn}) - } + s.log(DebugLevel, pkg+"queuing method "+meth) + buf = buf[3+len(meth):] + txn := int32(amf.DecodeNumber(buf[:8])) + s.methodCalls = append(s.methodCalls, method{name: meth, num: txn}) } if s.channelsOut[pkt.channel] == nil {