mirror of https://bitbucket.org/ausocean/av.git
rtmp: simplify C_RTMP_SendPacket
This commit is contained in:
parent
6e5e597b11
commit
dc040ccf9c
46
rtmp/rtmp.go
46
rtmp/rtmp.go
|
@ -1298,12 +1298,7 @@ func C_HandShake(r *C_RTMP, FP9HandShake int32) (ok bool) {
|
|||
// rtmp.c +3896
|
||||
func C_RTMP_SendPacket(r *C_RTMP, packet *C_RTMPPacket, queue int) (ok bool) {
|
||||
var prevPacket *C_RTMPPacket
|
||||
last := 0
|
||||
var header, hptr, hend, buffer, tbuf, toff unsafe.Pointer
|
||||
var goHbuf [RTMP_MAX_HEADER_SIZE]byte
|
||||
var hbuf = unsafe.Pointer(&goHbuf[0])
|
||||
var c byte
|
||||
var t uint32
|
||||
var last int
|
||||
|
||||
if packet.m_nChannel >= r.m_channelsAllocatedOut {
|
||||
n := int(packet.m_nChannel + 10)
|
||||
|
@ -1326,15 +1321,11 @@ func C_RTMP_SendPacket(r *C_RTMP, packet *C_RTMPPacket, queue int) (ok bool) {
|
|||
|
||||
if prevPacket != nil && packet.m_headerType != RTMP_PACKET_SIZE_LARGE {
|
||||
// compress a bit by using the prev packet's attributes
|
||||
if prevPacket.m_nBodySize == packet.m_nBodySize &&
|
||||
prevPacket.m_packetType == packet.m_packetType &&
|
||||
packet.m_headerType == RTMP_PACKET_SIZE_MEDIUM {
|
||||
|
||||
if prevPacket.m_nBodySize == packet.m_nBodySize && prevPacket.m_packetType == packet.m_packetType && packet.m_headerType == RTMP_PACKET_SIZE_MEDIUM {
|
||||
packet.m_headerType = RTMP_PACKET_SIZE_SMALL
|
||||
}
|
||||
|
||||
if prevPacket.m_nTimeStamp == packet.m_nTimeStamp &&
|
||||
packet.m_headerType == RTMP_PACKET_SIZE_SMALL {
|
||||
if prevPacket.m_nTimeStamp == packet.m_nTimeStamp && packet.m_headerType == RTMP_PACKET_SIZE_SMALL {
|
||||
packet.m_headerType = RTMP_PACKET_SIZE_MINIMUM
|
||||
}
|
||||
|
||||
|
@ -1350,16 +1341,16 @@ func C_RTMP_SendPacket(r *C_RTMP, packet *C_RTMPPacket, queue int) (ok bool) {
|
|||
nSize := packetSize[int(packet.m_headerType)]
|
||||
hSize := nSize
|
||||
cSize := 0
|
||||
t = uint32(int(packet.m_nTimeStamp) - last)
|
||||
t := uint32(int(packet.m_nTimeStamp) - last)
|
||||
|
||||
var header, hend unsafe.Pointer
|
||||
if packet.m_body != nil {
|
||||
header = decBytePtr(unsafe.Pointer(&packet.m_body[0]), nSize)
|
||||
hend = unsafe.Pointer(&packet.m_body[0])
|
||||
} else {
|
||||
header = incBytePtr(hbuf, 6)
|
||||
// TODO: be cautious about this sizeof - make sure it works how you think it
|
||||
// does. C code used sizeof(hbuf) where hbuf is a *char
|
||||
hend = incBytePtr(hbuf, RTMP_MAX_HEADER_SIZE)
|
||||
var hbuf [RTMP_MAX_HEADER_SIZE]byte
|
||||
header = incBytePtr(unsafe.Pointer(&hbuf[0]), 6)
|
||||
hend = incBytePtr(unsafe.Pointer(&hbuf[0]), RTMP_MAX_HEADER_SIZE)
|
||||
}
|
||||
|
||||
switch {
|
||||
|
@ -1380,8 +1371,8 @@ func C_RTMP_SendPacket(r *C_RTMP, packet *C_RTMPPacket, queue int) (ok bool) {
|
|||
log.Printf("Larger timestamp than 24-bit: 0x%v", t)
|
||||
}
|
||||
|
||||
hptr = header
|
||||
c = packet.m_headerType << 6
|
||||
hptr := header
|
||||
c := packet.m_headerType << 6
|
||||
|
||||
switch cSize {
|
||||
case 0:
|
||||
|
@ -1427,13 +1418,14 @@ func C_RTMP_SendPacket(r *C_RTMP, packet *C_RTMPPacket, queue int) (ok bool) {
|
|||
}
|
||||
|
||||
nSize = int(packet.m_nBodySize)
|
||||
buffer = unsafe.Pointer(&packet.m_body[0])
|
||||
buffer := unsafe.Pointer(&packet.m_body[0])
|
||||
nChunkSize := int(r.m_outChunkSize)
|
||||
|
||||
if debugMode {
|
||||
log.Printf("C_RTMP_SendPacket: fd=%v, size=%v", r.m_sb.sb_socket, nSize)
|
||||
}
|
||||
|
||||
var tbuf, toff unsafe.Pointer
|
||||
for (nSize + hSize) != 0 {
|
||||
if nSize < nChunkSize {
|
||||
nChunkSize = nSize
|
||||
|
@ -1669,23 +1661,13 @@ func C_RTMP_Write(r *C_RTMP, buf []byte) int {
|
|||
// incBytePtr returns an unsafe.Pointer to a byte that is inc positive positions
|
||||
// from the passed ptr
|
||||
func incBytePtr(ptr unsafe.Pointer, inc int) unsafe.Pointer {
|
||||
return incPtr(ptr, inc, 1)
|
||||
}
|
||||
|
||||
// incPtr attempts to replicate C like pointer arithmatic functionality
|
||||
func incPtr(ptr unsafe.Pointer, inc, typeSize int) unsafe.Pointer {
|
||||
return unsafe.Pointer(uintptr(ptr) + uintptr(inc*typeSize))
|
||||
}
|
||||
|
||||
// incPtr attempts to replicate C like pointer arithmatic functionality
|
||||
func decPtr(ptr unsafe.Pointer, dec, typeSize int) unsafe.Pointer {
|
||||
return unsafe.Pointer(uintptr(ptr) - uintptr(dec*typeSize))
|
||||
return unsafe.Pointer(uintptr(ptr) + uintptr(inc))
|
||||
}
|
||||
|
||||
// decBytePtr returns an unsafe.Pointer to a byte that is dec negative positions
|
||||
// from ptr
|
||||
func decBytePtr(ptr unsafe.Pointer, dec int) unsafe.Pointer {
|
||||
return decPtr(ptr, dec, 1)
|
||||
return unsafe.Pointer(uintptr(ptr) - uintptr(dec))
|
||||
}
|
||||
|
||||
var rtmpErrs = [...]string{
|
||||
|
|
Loading…
Reference in New Issue