Fixed some other little things, but still doesn't fix the seg fault

This commit is contained in:
saxon 2018-07-17 18:00:24 +09:30
parent a24003af44
commit dd41aeb966
1 changed files with 47 additions and 9 deletions

View File

@ -92,7 +92,7 @@ func AVC(str string) C.AVal {
// av_setDataFrame is a static const global in rtmp.c // av_setDataFrame is a static const global in rtmp.c
var setDataFrame = AVC("@setDataFrame") var setDataFrame = AVC("@setDataFrame")
var packetSize = [...]int32{ 12, 8, 4, 1} var packetSize = [...]int{ 12, 8, 4, 1}
// Session provides an interface for sending flv tags over rtmp. // Session provides an interface for sending flv tags over rtmp.
type Session interface { type Session interface {
@ -258,6 +258,7 @@ func rtmpWrite(r *C.RTMP, data []byte) int {
} }
// send packet version 1 - less C stuff
func sendPacket(r *C.RTMP, packet *C.RTMPPacket, queue int) int { func sendPacket(r *C.RTMP, packet *C.RTMPPacket, queue int) int {
var prevPacket *C.RTMPPacket var prevPacket *C.RTMPPacket
last := 0 last := 0
@ -289,6 +290,8 @@ func sendPacket(r *C.RTMP, packet *C.RTMPPacket, queue int) int {
prevPacket = *(**C.RTMPPacket)(incPtr(unsafe.Pointer(r.m_vecChannelsOut), prevPacket = *(**C.RTMPPacket)(incPtr(unsafe.Pointer(r.m_vecChannelsOut),
int(packet.m_nChannel), int(unsafe.Sizeof(packet)))) 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
if prevPacket.m_nBodySize == packet.m_nBodySize && if prevPacket.m_nBodySize == packet.m_nBodySize &&
@ -313,7 +316,7 @@ func sendPacket(r *C.RTMP, packet *C.RTMPPacket, queue int) int {
return 0 return 0
} }
nSize = int(*(*int)(incInt32Ptr(unsafe.Pointer(&packetSize[0]),int(packet.m_headerType)))) nSize = packetSize[int(packet.m_headerType)]
hSize = nSize hSize = nSize
cSize = 0 cSize = 0
t = int32(int(packet.m_nTimeStamp) - last) t = int32(int(packet.m_nTimeStamp) - last)
@ -356,7 +359,6 @@ func sendPacket(r *C.RTMP, packet *C.RTMPPacket, queue int) int {
case 2: case 2:
c |= byte(1) c |= byte(1)
} }
*(*byte)(hptr) = c *(*byte)(hptr) = c
hptr = incBytePtr(hptr,1) hptr = incBytePtr(hptr,1)
@ -452,7 +454,7 @@ func sendPacket(r *C.RTMP, packet *C.RTMPPacket, queue int) int {
hSize = 1 hSize = 1
if cSize != 0 { if cSize != 0 {
header = decBytePtr(header,1) header = decBytePtr(header,cSize)
hSize += cSize hSize += cSize
} }
@ -516,21 +518,57 @@ func sendPacket(r *C.RTMP, packet *C.RTMPPacket, queue int) int {
} }
} }
if unsafe.Pointer((*C.RTMPPacket)(incPtr(unsafe.Pointer(r.m_vecChannelsOut), if *(**C.RTMPPacket)(incPtr(unsafe.Pointer(r.m_vecChannelsOut),
int(packet.m_nChannel), int(unsafe.Sizeof(packet))))) == nil { int(packet.m_nChannel), int(unsafe.Sizeof(packet)))) == nil {
r.m_vecChannelsOut = (**C.RTMPPacket)(C.malloc(C.size_t(unsafe.Sizeof(packet)))) *(**C.RTMPPacket)(incPtr(unsafe.Pointer(r.m_vecChannelsOut),
int(packet.m_nChannel), int(unsafe.Sizeof(packet)))) =
(*C.RTMPPacket)(C.malloc(C.size_t(unsafe.Sizeof(*packet))))
} }
//memmove(incPtr(unsafe.Pointer(r.m_vecChannelsOut),int(packet.m_nChannel), //memmove(incPtr(unsafe.Pointer(r.m_vecChannelsOut),int(packet.m_nChannel),
//int(unsafe.Sizeof(packet))),unsafe.Pointer(packet), unsafe.Sizeof(packet)) //int(unsafe.Sizeof(packet))),unsafe.Pointer(packet), unsafe.Sizeof(packet))
dest := ptrToSlice(incPtr(unsafe.Pointer(r.m_vecChannelsOut),int(packet.m_nChannel), dest := ptrToSlice(incPtr(unsafe.Pointer(r.m_vecChannelsOut),int(packet.m_nChannel),
int(unsafe.Sizeof(packet))),int(unsafe.Sizeof(packet))) int(unsafe.Sizeof(packet))),int(unsafe.Sizeof(*packet)))
src := ptrToSlice(unsafe.Pointer(packet),int(unsafe.Sizeof(packet))) src := ptrToSlice(unsafe.Pointer(packet),int(unsafe.Sizeof(*packet)))
copy(dest,src) copy(dest,src)
return 1 return 1
} }
/*
func sendPacket(r *C.RTMP, packet *C.RTMPPacket, queue C.int ) C.int {
prevPacket *C.RTMPPacket
var last = 0 C.uint32_t
var nSize C.int
var hSize, cSize C.int
var header, hptr, hend *C.char
var hArr [C.RTMP_MAX_HEADER_SIZE]byte
hbuf := (*C.char)(unsafe.Pointer(&hArr[0]))
var c C.char
var t C.uint32_t
var buffer, tbuf, toff *C.char
var nChunkSize C.int
var tlen C.int
if packet.m_nChannel >= r.m_channelsAllocatedOut {
n := packet.m_nChannel + 10
packets := (**C.RTMPPacket)(C.realloc(r.m_vecChannelsOut, unsafe.Sizeof(packet) * n))
if packets != nil {
C.free(r.m_vecChannelsOut)
r.m_vecChannelsOut = nil
r.m_channelsAllocatedOut = 0
return 0
}
r.m_vecChannelsOut = packets
C.memset(r.m_vecChannelsOut + r.m_channelsAllocatedOut, 0, unsafe.Sizeof(packet) * (n - r.m_channelsAllocatedOut))
r.m_channelsAllocatedOut = n
}
prePacket = r.m_vecChannelsOut[packet.m_nChannel]
}
*/
/* /*
func writeN(r *C.RTMP, buffer unsafe.Pointer, n int) int { func writeN(r *C.RTMP, buffer unsafe.Pointer, n int) int {
ptr := buffer ptr := buffer