mirror of https://bitbucket.org/ausocean/av.git
packetSize -> headerSizes.
This commit is contained in:
parent
9796465018
commit
2333d1953e
|
@ -68,8 +68,12 @@ const (
|
||||||
RTMP_CHANNEL_SOURCE = 0x04
|
RTMP_CHANNEL_SOURCE = 0x04
|
||||||
)
|
)
|
||||||
|
|
||||||
// packetSize defines valid packet sizes.
|
// headerSizes defines header sizes for header types 0, 1, 2 and 3 respectively:
|
||||||
var packetSize = [...]int{12, 8, 4, 1}
|
// 0: full header (12 bytes)
|
||||||
|
// 1: header without message ID (8 bytes)
|
||||||
|
// 2: basic header + timestamp (4 byes)
|
||||||
|
// 3: basic header (chunk type and stream ID) (1 byte)
|
||||||
|
var headerSizes = [...]int{12, 8, 4, 1}
|
||||||
|
|
||||||
// packet defines an RTMP packet.
|
// packet defines an RTMP packet.
|
||||||
type packet struct {
|
type packet struct {
|
||||||
|
@ -154,7 +158,7 @@ func readPacket(s *Session, pkt *packet) error {
|
||||||
s.channelsAllocatedIn = n
|
s.channelsAllocatedIn = n
|
||||||
}
|
}
|
||||||
|
|
||||||
size := packetSize[pkt.headerType]
|
size := headerSizes[pkt.headerType]
|
||||||
switch {
|
switch {
|
||||||
case size == RTMP_LARGE_HEADER_SIZE:
|
case size == RTMP_LARGE_HEADER_SIZE:
|
||||||
pkt.hasAbsTimestamp = true
|
pkt.hasAbsTimestamp = true
|
||||||
|
@ -308,7 +312,7 @@ func sendPacket(s *Session, pkt *packet, queue bool) error {
|
||||||
if pkt.body != nil {
|
if pkt.body != nil {
|
||||||
// Span from -packetsize for the type to the start of the body.
|
// Span from -packetsize for the type to the start of the body.
|
||||||
headBytes = pkt.header
|
headBytes = pkt.header
|
||||||
origIdx = RTMP_MAX_HEADER_SIZE - packetSize[pkt.headerType]
|
origIdx = RTMP_MAX_HEADER_SIZE - headerSizes[pkt.headerType]
|
||||||
} else {
|
} else {
|
||||||
// Allocate a new header and allow 6 bytes of movement backward.
|
// Allocate a new header and allow 6 bytes of movement backward.
|
||||||
var hbuf [RTMP_MAX_HEADER_SIZE]byte
|
var hbuf [RTMP_MAX_HEADER_SIZE]byte
|
||||||
|
@ -324,7 +328,7 @@ func sendPacket(s *Session, pkt *packet, queue bool) error {
|
||||||
cSize = 1
|
cSize = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
hSize := packetSize[pkt.headerType]
|
hSize := headerSizes[pkt.headerType]
|
||||||
if cSize != 0 {
|
if cSize != 0 {
|
||||||
origIdx -= cSize
|
origIdx -= cSize
|
||||||
hSize += cSize
|
hSize += cSize
|
||||||
|
@ -365,7 +369,7 @@ func sendPacket(s *Session, pkt *packet, queue bool) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if packetSize[pkt.headerType] > 1 {
|
if headerSizes[pkt.headerType] > 1 {
|
||||||
res := ts
|
res := ts
|
||||||
if ts > 0xffffff {
|
if ts > 0xffffff {
|
||||||
res = 0xffffff
|
res = 0xffffff
|
||||||
|
@ -374,14 +378,14 @@ func sendPacket(s *Session, pkt *packet, queue bool) error {
|
||||||
headerIdx += 3 // 24bits
|
headerIdx += 3 // 24bits
|
||||||
}
|
}
|
||||||
|
|
||||||
if packetSize[pkt.headerType] > 4 {
|
if headerSizes[pkt.headerType] > 4 {
|
||||||
C_AMF_EncodeInt24(headBytes[headerIdx:], int32(pkt.bodySize))
|
C_AMF_EncodeInt24(headBytes[headerIdx:], int32(pkt.bodySize))
|
||||||
headerIdx += 3 // 24bits
|
headerIdx += 3 // 24bits
|
||||||
headBytes[headerIdx] = pkt.packetType
|
headBytes[headerIdx] = pkt.packetType
|
||||||
headerIdx++
|
headerIdx++
|
||||||
}
|
}
|
||||||
|
|
||||||
if packetSize[pkt.headerType] > 8 {
|
if headerSizes[pkt.headerType] > 8 {
|
||||||
n := int(encodeInt32LE(headBytes[headerIdx:headerIdx+4], pkt.info))
|
n := int(encodeInt32LE(headBytes[headerIdx:headerIdx+4], pkt.info))
|
||||||
headerIdx += n
|
headerIdx += n
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue