Working again but not sure whyyy

This commit is contained in:
saxon 2018-08-11 13:48:21 +09:30
parent a20beaf75e
commit 7111456991
1 changed files with 42 additions and 15 deletions

View File

@ -503,8 +503,8 @@ func startSession(rtmp *C.RTMP, u string, timeout uint32) (*C.RTMP, error) {
// rtmp.c +317
func C_RTMP_Alloc() *C.RTMP {
var r C.RTMP
//return (*C.RTMP)(C.malloc(C.size_t(unsafe.Sizeof(r))))
return (*C.RTMP)(allocate(unsafe.Sizeof(r)))
return (*C.RTMP)(C.malloc(C.size_t(unsafe.Sizeof(r))))
//return (*C.RTMP)(allocate(unsafe.Sizeof(r)))
}
// void RTMP_Init(RTMP *r);
@ -560,7 +560,7 @@ func C_RTMP_SetupURL(r *C.RTMP, u string) int32 {
length = int32(r.Link.hostname.av_len) + int32(r.Link.app.av_len) +
int32(len("rtmpte://:65535/\x00"))
r.Link.tcUrl.av_val = (*C.char)(allocate(uintptr(length)))
r.Link.tcUrl.av_val = (*C.char)(C.malloc(C.size_t(uintptr(length))))
hostname := string(ptrToSlice(unsafe.Pointer(r.Link.hostname.av_val),
int(r.Link.hostname.av_len)))
@ -1707,7 +1707,7 @@ func C_RTMP_ConnectStream(r *C.RTMP, seekTime int32) int {
// TODO: read packet
for r.m_bPlaying == 0 && C_RTMP_IsConnected(r) != 0 &&
// C.RTMP_ReadPacket(r, &packet) != 0 {
//C.RTMP_ReadPacket(r, &packet) != 0 {
C_RTMP_ReadPacket(r, &packet) != 0 {
// TODO: port is ready
@ -1780,6 +1780,7 @@ func C_RTMP_ReadPacket(r *C.RTMP, packet *C.RTMPPacket) int32 {
var n int32 = int32(packet.m_nChannel + 10)
timestamp := (*int32)(C.realloc(unsafe.Pointer(r.m_channelTimestamp),
C.size_t(int32(unsafe.Sizeof(n))*n)))
var packetPtr *C.RTMPPacket
packets := (**C.RTMPPacket)(C.realloc(unsafe.Pointer(r.m_vecChannelsIn),
C.size_t(int32(unsafe.Sizeof(packetPtr))*n)))
@ -1870,7 +1871,7 @@ func C_RTMP_ReadPacket(r *C.RTMP, packet *C.RTMPPacket) int32 {
if packet.m_nBodySize > 0 && packet.m_body == nil {
// TODO: port this
if C.RTMPPacket_Alloc(packet, packet.m_nBodySize) == 0 {
if C_RTMPPacket_Alloc(packet, uint32(packet.m_nBodySize)) == 0 {
log.Println("RTMPRead_Packet: failed to allocate packet")
return 0
}
@ -1905,9 +1906,11 @@ func C_RTMP_ReadPacket(r *C.RTMP, packet *C.RTMPPacket) int32 {
// keep the packet as ref for other packets on this channel
if *(**C.RTMPPacket)(incPtr(unsafe.Pointer(r.m_vecChannelsIn),
int(packet.m_nChannel), int(unsafe.Sizeof(tmpPktPtr)))) == nil {
var tmpPkt C.RTMPPacket
*(**C.RTMPPacket)(incPtr(unsafe.Pointer(r.m_vecChannelsIn), int(packet.m_nChannel),
int(unsafe.Sizeof(tmpPktPtr)))) = (*C.RTMPPacket)(C.malloc(C.size_t(unsafe.Sizeof(tmpPkt))))
int(unsafe.Sizeof(tmpPktPtr)))) = (*C.RTMPPacket)(C.malloc(C.size_t(
unsafe.Sizeof(tmpPkt))))
}
memmove(unsafe.Pointer(*(**C.RTMPPacket)(incPtr(unsafe.Pointer(
r.m_vecChannelsIn), int(packet.m_nChannel), int(unsafe.Sizeof(tmpPktPtr))))),
@ -1938,10 +1941,12 @@ func C_RTMP_ReadPacket(r *C.RTMP, packet *C.RTMPPacket) int32 {
} else {
packet.m_body = nil /* so it won't be erased on free */
}
return 1
}
// static int DecodeInt32LE(const char* data);
// rtmp.c
// #define RTMPPacket_IsReady(a)
// rtmp.h +142
func C_RTMPPacket_IsReady(p *C.RTMPPacket) int {
@ -2010,7 +2015,7 @@ func C_RTMP_Write(r *C.RTMP, data []byte) int {
pkt.m_headerType = RTMP_PACKET_SIZE_MEDIUM
}
// TODO: Port this
if int(C.RTMPPacket_Alloc(pkt, pkt.m_nBodySize)) == 0 {
if int(C_RTMPPacket_Alloc(pkt, uint32(pkt.m_nBodySize))) == 0 {
log.Println("Failed to allocate packet")
return 0
}
@ -2055,6 +2060,27 @@ func C_RTMP_Write(r *C.RTMP, data []byte) int {
return size + s2
}
// int RTMPPacket_Alloc(RTMPPacket* p, uint32_t nSize);
// rtmp.c +189
func C_RTMPPacket_Alloc(p *C.RTMPPacket, nSize uint32) int {
var ptr *byte
// TODO: port C.SIZE_MAX
// also work out how to deal with the overfloat
/*
if int64(nSize) > (C.SIZE_MAX - RTMP_MAX_HEADER_SIZE) {
return 0
}
*/
ptr = (*byte)(C.calloc(1, C.size_t(nSize+RTMP_MAX_HEADER_SIZE)))
if ptr == nil {
return 0
}
p.m_body = (*C.char)(incBytePtr(unsafe.Pointer(ptr), RTMP_MAX_HEADER_SIZE))
p.m_nBytesRead = 0
return 1
}
// int RTMP_SendPacket(RTMP* r, RTMPPacket* packet, int queue);
// rtmp.c +3896
func C_RTMP_SendPacket(r *C.RTMP, packet *C.RTMPPacket, queue int) int {
@ -2306,7 +2332,7 @@ func C_RTMP_SendPacket(r *C.RTMP, packet *C.RTMPPacket, queue int) int {
*(**C.RTMPPacket)(incPtr(unsafe.Pointer(r.m_vecChannelsOut),
int(packet.m_nChannel), int(unsafe.Sizeof(packet)))) =
(*C.RTMPPacket)(allocate(unsafe.Sizeof(*packet)))
(*C.RTMPPacket)(C.malloc(C.size_t(unsafe.Sizeof(*packet))))
}
memmove(unsafe.Pointer(*(**C.RTMPPacket)(incPtr(unsafe.Pointer(r.m_vecChannelsOut),
@ -2331,7 +2357,7 @@ func C_WriteN(r *C.RTMP, buffer unsafe.Pointer, n int) int {
}
// TODO: port this
C.RTMP_Close(r)
//C.RTMP_Close(r)
n = 1
break
}
@ -2437,7 +2463,7 @@ func C_AMF_EncodeNumber(output *byte, outend *byte, dVal float64) *byte {
return nil
}
// TODO: port this
*(*byte)(unsafe.Pointer(output)) = C.AMF_NUMBER
*(*byte)(unsafe.Pointer(output)) = AMF_NUMBER
output = (*byte)(incBytePtr(unsafe.Pointer(output), 1))
// NOTE: here we are assuming little endian for both byte order and float
// word order
@ -2541,15 +2567,16 @@ func C_AMF_EncodeString(output *byte, outend *byte, bv *C.AVal) *byte {
if bv.av_len < 65536 {
*(*byte)(outputPtr) = AMF_STRING
outputPtr = incBytePtr(outputPtr, 1)
outputPtr = unsafe.Pointer(C.AMF_EncodeInt16((*C.char)(outputPtr), (*C.char)(
outendPtr), C.short(bv.av_len)))
// TODO: port AMF_EncodeInt16
outputPtr = unsafe.Pointer(C_AMF_EncodeInt16((*byte)(outputPtr), (*byte)(
outendPtr), int16(bv.av_len)))
//outputPtr = unsafe.Pointer(C_AMF_EncodeInt16((*byte)(outputPtr),
//(*byte)(outendPtr), (int16)(bv.av_len)))
} else {
*(*byte)(outputPtr) = AMF_LONG_STRING
outputPtr = incBytePtr(outputPtr, 1)
outputPtr = unsafe.Pointer(C.AMF_EncodeInt32((*C.char)(outputPtr), (*C.char)(
outendPtr), C.int(bv.av_len)))
outputPtr = unsafe.Pointer(C_AMF_EncodeInt32((*byte)(outputPtr), (*byte)(
outendPtr), int32(bv.av_len)))
//outputPtr = unsafe.Pointer(C_AMF_EncodeInt32((*byte)(outputPtr),
//(*byte)(outendPtr), (int32)(bv.av_len)))
}