rtmp: attempt to find some clarity of flow

This commit is contained in:
Dan Kortschak 2018-09-26 15:06:50 +09:30
parent b054ab103f
commit d101946cfe
1 changed files with 11 additions and 12 deletions

View File

@ -1338,15 +1338,10 @@ func C_RTMP_SendPacket(r *C_RTMP, packet *C_RTMPPacket, queue int) (ok bool) {
return false
}
nSize := packetSize[int(packet.m_headerType)]
hSize := nSize
cSize := 0
t := uint32(int(packet.m_nTimeStamp) - last)
var header, hend *byte
if packet.m_body != nil {
// Span from -nSize to the start of the body.
header = decBytePtr(&packet.m_body[0], nSize)
// Span from -packetsize for the type to the start of the body.
header = decBytePtr(&packet.m_body[0], packetSize[packet.m_headerType])
hend = &packet.m_body[0]
} else {
// Allocate a new header and allow 6 bytes of movement backward.
@ -1355,6 +1350,7 @@ func C_RTMP_SendPacket(r *C_RTMP, packet *C_RTMPPacket, queue int) (ok bool) {
hend = incBytePtr(&hbuf[0], RTMP_MAX_HEADER_SIZE)
}
var cSize int
switch {
case packet.m_nChannel > 319:
cSize = 2
@ -1362,11 +1358,13 @@ func C_RTMP_SendPacket(r *C_RTMP, packet *C_RTMPPacket, queue int) (ok bool) {
cSize = 1
}
hSize := packetSize[packet.m_headerType]
if cSize != 0 {
header = decBytePtr(header, cSize)
hSize += cSize
}
t := uint32(int(packet.m_nTimeStamp) - last)
if t >= 0xffffff {
header = decBytePtr(header, 4)
hSize += 4
@ -1380,8 +1378,9 @@ func C_RTMP_SendPacket(r *C_RTMP, packet *C_RTMPPacket, queue int) (ok bool) {
case 0:
c |= byte(packet.m_nChannel)
case 1:
// Do nothing.
case 2:
c |= byte(1)
c |= 1
}
*hptr = c
hptr = incBytePtr(hptr, 1)
@ -1397,7 +1396,7 @@ func C_RTMP_SendPacket(r *C_RTMP, packet *C_RTMPPacket, queue int) (ok bool) {
}
}
if nSize > 1 {
if packetSize[packet.m_headerType] > 1 {
res := t
if t > 0xffffff {
res = 0xffffff
@ -1405,13 +1404,13 @@ func C_RTMP_SendPacket(r *C_RTMP, packet *C_RTMPPacket, queue int) (ok bool) {
hptr = bAddr(C_AMF_EncodeInt24(pp2b(hptr, hend), int32(res)))
}
if nSize > 4 {
if packetSize[packet.m_headerType] > 4 {
hptr = bAddr(C_AMF_EncodeInt24(pp2b(hptr, hend), int32(packet.m_nBodySize)))
*hptr = packet.m_packetType
hptr = incBytePtr(hptr, 1)
}
if nSize > 8 {
if packetSize[packet.m_headerType] > 8 {
hptr = incBytePtr(hptr, int(C_EncodeInt32LE(pl2b(hptr, 4), packet.m_nInfoField2)))
}
@ -1419,7 +1418,7 @@ func C_RTMP_SendPacket(r *C_RTMP, packet *C_RTMPPacket, queue int) (ok bool) {
hptr = bAddr(C_AMF_EncodeInt32(pp2b(hptr, hend), int32(t)))
}
nSize = int(packet.m_nBodySize)
nSize := int(packet.m_nBodySize)
buffer := &packet.m_body[0]
nChunkSize := int(r.m_outChunkSize)