Removed superfluous packet.bytesRead.

This commit is contained in:
scruzin 2019-01-20 07:56:55 +10:30
parent 42be87d98a
commit 828cc3780a
1 changed files with 5 additions and 12 deletions

View File

@ -81,7 +81,7 @@ const (
// 3: basic header (chunk type and stream ID) (1 byte) // 3: basic header (chunk type and stream ID) (1 byte)
var headerSizes = [...]int{12, 8, 4, 1} var headerSizes = [...]int{12, 8, 4, 1}
// packet defines an RTMP packet. // packet represents an RTMP packet.
type packet struct { type packet struct {
headerType uint8 headerType uint8
packetType uint8 packetType uint8
@ -90,7 +90,6 @@ type packet struct {
timestamp uint32 timestamp uint32
streamID uint32 streamID uint32
bodySize uint32 bodySize uint32
bytesRead uint32
buf []byte buf []byte
body []byte body []byte
} }
@ -179,7 +178,6 @@ func (pkt *packet) readFrom(c *Conn) error {
pkt.timestamp = amf.DecodeInt24(header[:3]) pkt.timestamp = amf.DecodeInt24(header[:3])
if size >= 6 { if size >= 6 {
pkt.bodySize = amf.DecodeInt24(header[3:6]) pkt.bodySize = amf.DecodeInt24(header[3:6])
pkt.bytesRead = 0
if size > 6 { if size > 6 {
pkt.packetType = header[6] pkt.packetType = header[6]
@ -205,21 +203,17 @@ func (pkt *packet) readFrom(c *Conn) error {
pkt.resize(pkt.bodySize, (hbuf[0]&0xc0)>>6) pkt.resize(pkt.bodySize, (hbuf[0]&0xc0)>>6)
} }
toRead := pkt.bodySize - pkt.bytesRead sz := c.inChunkSize
chunkSize := c.inChunkSize if pkt.bodySize < sz {
sz = pkt.bodySize
if toRead < chunkSize {
chunkSize = toRead
} }
_, err = c.read(pkt.body[pkt.bytesRead:][:chunkSize]) _, err = c.read(pkt.body[:sz])
if err != nil { if err != nil {
c.log(DebugLevel, pkg+"failed to read packet body", "error", err.Error()) c.log(DebugLevel, pkg+"failed to read packet body", "error", err.Error())
return err return err
} }
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 c.channelsIn[pkt.channel] == nil { if c.channelsIn[pkt.channel] == nil {
c.channelsIn[pkt.channel] = &packet{} c.channelsIn[pkt.channel] = &packet{}
@ -237,7 +231,6 @@ func (pkt *packet) readFrom(c *Conn) error {
c.channelTimestamp[pkt.channel] = int32(pkt.timestamp) c.channelTimestamp[pkt.channel] = int32(pkt.timestamp)
c.channelsIn[pkt.channel].body = nil c.channelsIn[pkt.channel].body = nil
c.channelsIn[pkt.channel].bytesRead = 0
c.channelsIn[pkt.channel].hasAbsTimestamp = false c.channelsIn[pkt.channel].hasAbsTimestamp = false
return nil return nil
} }