mirror of https://bitbucket.org/ausocean/av.git
rtmp: make C_RTMP.m_vecChannelsOut a []*C_RTMPPacket
This commit is contained in:
parent
0c124eb761
commit
b45f70bdf8
43
rtmp/rtmp.go
43
rtmp/rtmp.go
|
@ -1500,35 +1500,30 @@ func C_HandShake(r *C_RTMP, FP9HandShake int32) (ok bool) {
|
||||||
func C_RTMP_SendPacket(r *C_RTMP, packet *C_RTMPPacket, queue int) (ok bool) {
|
func C_RTMP_SendPacket(r *C_RTMP, packet *C_RTMPPacket, queue int) (ok bool) {
|
||||||
var prevPacket *C_RTMPPacket
|
var prevPacket *C_RTMPPacket
|
||||||
last := 0
|
last := 0
|
||||||
var nSize, hSize, cSize, nChunkSize int
|
|
||||||
var header, hptr, hend, buffer, tbuf, toff unsafe.Pointer
|
var header, hptr, hend, buffer, tbuf, toff unsafe.Pointer
|
||||||
var goHbuf [RTMP_MAX_HEADER_SIZE]byte
|
var goHbuf [RTMP_MAX_HEADER_SIZE]byte
|
||||||
var hbuf = unsafe.Pointer(&goHbuf[0])
|
var hbuf = unsafe.Pointer(&goHbuf[0])
|
||||||
var c byte
|
var c byte
|
||||||
var t uint32
|
var t uint32
|
||||||
var packets unsafe.Pointer
|
|
||||||
|
|
||||||
if packet.m_nChannel >= r.m_channelsAllocatedOut {
|
if packet.m_nChannel >= r.m_channelsAllocatedOut {
|
||||||
n := int(packet.m_nChannel + 10)
|
n := int(packet.m_nChannel + 10)
|
||||||
packets = C.realloc(unsafe.Pointer(r.m_vecChannelsOut), C.size_t(
|
|
||||||
unsafe.Sizeof(packet)*uintptr(n)))
|
|
||||||
|
|
||||||
if uintptr(packets) == uintptr(0) {
|
var packets []*C_RTMPPacket
|
||||||
//C.free(unsafe.Pointer(r.m_vecChannelsOut))
|
if r.m_vecChannelsOut == nil {
|
||||||
r.m_vecChannelsOut = nil
|
packets = make([]*C_RTMPPacket, n)
|
||||||
r.m_channelsAllocatedOut = 0
|
} else {
|
||||||
return false
|
packets = append(r.m_vecChannelsOut[:packet.m_nChannel:packet.m_nChannel], make([]*C_RTMPPacket, 10)...)
|
||||||
}
|
}
|
||||||
r.m_vecChannelsOut = (**C_RTMPPacket)(packets)
|
r.m_vecChannelsOut = packets
|
||||||
|
|
||||||
memset((*byte)(incPtr(unsafe.Pointer(r.m_vecChannelsOut), int(r.m_channelsAllocatedOut),
|
for i := int(r.m_channelsAllocatedOut); i < n; i++ {
|
||||||
int(unsafe.Sizeof(packet)))), 0, int(unsafe.Sizeof(packet)*
|
r.m_vecChannelsOut[i] = nil
|
||||||
uintptr(n-int(r.m_channelsAllocatedOut))))
|
}
|
||||||
|
|
||||||
r.m_channelsAllocatedOut = int32(n)
|
r.m_channelsAllocatedOut = int32(n)
|
||||||
}
|
}
|
||||||
prevPacket = *(**C_RTMPPacket)(incPtr(unsafe.Pointer(r.m_vecChannelsOut),
|
prevPacket = r.m_vecChannelsOut[packet.m_nChannel]
|
||||||
int(packet.m_nChannel), int(unsafe.Sizeof(packet))))
|
|
||||||
|
|
||||||
if prevPacket != nil && packet.m_headerType != RTMP_PACKET_SIZE_LARGE {
|
if prevPacket != nil && packet.m_headerType != RTMP_PACKET_SIZE_LARGE {
|
||||||
// compress a bit by using the prev packet's attributes
|
// compress a bit by using the prev packet's attributes
|
||||||
|
@ -1553,9 +1548,9 @@ func C_RTMP_SendPacket(r *C_RTMP, packet *C_RTMPPacket, queue int) (ok bool) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
nSize = packetSize[int(packet.m_headerType)]
|
nSize := packetSize[int(packet.m_headerType)]
|
||||||
hSize = nSize
|
hSize := nSize
|
||||||
cSize = 0
|
cSize := 0
|
||||||
t = uint32(int(packet.m_nTimeStamp) - last)
|
t = uint32(int(packet.m_nTimeStamp) - last)
|
||||||
|
|
||||||
if packet.m_body != nil {
|
if packet.m_body != nil {
|
||||||
|
@ -1635,7 +1630,7 @@ func C_RTMP_SendPacket(r *C_RTMP, packet *C_RTMPPacket, queue int) (ok bool) {
|
||||||
|
|
||||||
nSize = int(packet.m_nBodySize)
|
nSize = int(packet.m_nBodySize)
|
||||||
buffer = unsafe.Pointer(packet.m_body)
|
buffer = unsafe.Pointer(packet.m_body)
|
||||||
nChunkSize = int(r.m_outChunkSize)
|
nChunkSize := int(r.m_outChunkSize)
|
||||||
|
|
||||||
if debugMode {
|
if debugMode {
|
||||||
log.Printf("C_RTMP_SendPacket: fd=%v, size=%v", r.m_sb.sb_socket, nSize)
|
log.Printf("C_RTMP_SendPacket: fd=%v, size=%v", r.m_sb.sb_socket, nSize)
|
||||||
|
@ -1721,15 +1716,11 @@ func C_RTMP_SendPacket(r *C_RTMP, packet *C_RTMPPacket, queue int) (ok bool) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if *(**C_RTMPPacket)(incPtr(unsafe.Pointer(r.m_vecChannelsOut),
|
if r.m_vecChannelsOut[packet.m_nChannel] == nil {
|
||||||
int(packet.m_nChannel), int(unsafe.Sizeof(packet)))) == nil {
|
r.m_vecChannelsOut[packet.m_nChannel] = &C_RTMPPacket{}
|
||||||
|
|
||||||
*(**C_RTMPPacket)(incPtr(unsafe.Pointer(r.m_vecChannelsOut),
|
|
||||||
int(packet.m_nChannel), int(unsafe.Sizeof(packet)))) = (*C_RTMPPacket)(malloc(unsafe.Sizeof(*packet)))
|
|
||||||
}
|
}
|
||||||
|
*(r.m_vecChannelsOut[packet.m_nChannel]) = *packet
|
||||||
|
|
||||||
memmove(unsafe.Pointer(*(**C_RTMPPacket)(incPtr(unsafe.Pointer(r.m_vecChannelsOut),
|
|
||||||
int(packet.m_nChannel), int(unsafe.Sizeof(packet))))), unsafe.Pointer(packet), unsafe.Sizeof(*packet))
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -203,7 +203,7 @@ type C_RTMP struct {
|
||||||
m_channelsAllocatedIn int32
|
m_channelsAllocatedIn int32
|
||||||
m_channelsAllocatedOut int32
|
m_channelsAllocatedOut int32
|
||||||
m_vecChannelsIn []*C_RTMPPacket
|
m_vecChannelsIn []*C_RTMPPacket
|
||||||
m_vecChannelsOut **C_RTMPPacket
|
m_vecChannelsOut []*C_RTMPPacket
|
||||||
m_channelTimestamp []int32
|
m_channelTimestamp []int32
|
||||||
m_fAudioCodecs float64
|
m_fAudioCodecs float64
|
||||||
m_fVideoCodecs float64
|
m_fVideoCodecs float64
|
||||||
|
|
Loading…
Reference in New Issue