rtmp: remove unnecessary type conversions

This commit is contained in:
Dan Kortschak 2018-09-12 12:07:43 +09:30
parent 6978c44de6
commit f387b827ae
2 changed files with 67 additions and 79 deletions

View File

@ -81,13 +81,13 @@ func C_AMF_DecodeInt24(data *byte) uint32 {
// unsigned int AMF_DeocdeInt32(const char* data);
// amf.c +59
func C_AMF_DecodeInt32(data *byte) uint32 {
c := (*uint8)(data)
c := data
val := uint32(
int32(*c)<<24 |
int32(*(*uint8)(incBytePtr(unsafe.Pointer(c), 1)))<<16 |
int32(*(*uint8)(incBytePtr(unsafe.Pointer(c), 2)))<<8 |
int32(*(*uint8)(incBytePtr(unsafe.Pointer(c), 3))))
return uint32(val)
return val
}
// void AMF_DecodeString(const char* data, C_AVal* bv);
@ -303,7 +303,7 @@ func C_AMFProp_SetName(prop *C_AMFObjectProperty, name string) {
// double AMFProp_GetNumber(AMFObjectProperty* prop);
// amf.c +330
func C_AMFProp_GetNumber(prop *C_AMFObjectProperty) float64 {
return float64(prop.p_vu.p_number)
return prop.p_vu.p_number
}
// void AMFProp_GetString(AMFObjectProperty* prop, AVal* str);
@ -348,7 +348,7 @@ func C_AMF_PropEncode(p *C_AMFObjectProperty, pBuffer *byte, pBufEnd *byte) *byt
switch p.p_type {
case AMF_NUMBER:
pBuffer = C_AMF_EncodeNumber(pBuffer, pBufEnd, float64(p.p_vu.p_number))
pBuffer = C_AMF_EncodeNumber(pBuffer, pBufEnd, p.p_vu.p_number)
case AMF_BOOLEAN:
pBuffer = C_AMF_EncodeBoolean(pBuffer, pBufEnd, p.p_vu.p_number != 0)
case AMF_STRING:
@ -494,7 +494,7 @@ func C_AMFProp_Decode(prop *C_AMFObjectProperty, pBuffer *byte, nSize, bDecodeNa
if nSize < 8 {
return -1
}
prop.p_vu.p_number = float64(C_AMF_DecodeNumber(pBuffer))
prop.p_vu.p_number = C_AMF_DecodeNumber(pBuffer)
nSize -= 8
case AMF_BOOLEAN:
@ -510,7 +510,7 @@ func C_AMFProp_Decode(prop *C_AMFObjectProperty, pBuffer *byte, nSize, bDecodeNa
nSize -= int32(2 + nStringSize)
case AMF_OBJECT:
var nRes int32 = int32(C_AMF_Decode(&prop.p_vu.p_object, pBuffer, nSize, 1))
var nRes int32 = C_AMF_Decode(&prop.p_vu.p_object, pBuffer, nSize, 1)
if nRes == -1 {
return -1
}
@ -634,7 +634,7 @@ func C_AMF_EncodeEcmaArray(obj *C_AMFObject, pBuffer *byte, pBufEnd *byte) *byte
*pBuffer = AMF_ECMA_ARRAY
pBuffer = (*byte)(incBytePtr(unsafe.Pointer(pBuffer), 1))
pBuffer = C_AMF_EncodeInt32(pBuffer, pBufEnd, int32(obj.o_num))
pBuffer = C_AMF_EncodeInt32(pBuffer, pBufEnd, obj.o_num)
for i := 0; i < int(obj.o_num); i++ {
res := C_AMF_PropEncode((*C_AMFObjectProperty)(incPtr(unsafe.Pointer(
@ -666,7 +666,7 @@ func C_AMF_EncodeArray(obj *C_AMFObject, pBuffer *byte, pBufEnd *byte) *byte {
*pBuffer = AMF_STRICT_ARRAY
pBuffer = (*byte)(incBytePtr(unsafe.Pointer(pBuffer), 1))
pBuffer = C_AMF_EncodeInt32(pBuffer, pBufEnd, int32(obj.o_num))
pBuffer = C_AMF_EncodeInt32(pBuffer, pBufEnd, obj.o_num)
for i := 0; i < int(obj.o_num); i++ {
res := C_AMF_PropEncode((*C_AMFObjectProperty)(incPtr(unsafe.Pointer(
@ -718,9 +718,9 @@ func C_AMF_DecodeArray(obj *C_AMFObject, pBuffer *byte, nSize, nArrayLen, bDecod
// int AMF_Decode(AMFObject *obj, const char* pBuffer, int nSize, int bDecodeName);
// amf.c +1180
func C_AMF_Decode(obj *C_AMFObject, pBuffer *byte, nSize int32, bDecodeName int32) int32 {
var nOriginalSize int32 = nSize
var bError int32 = 0
func C_AMF_Decode(obj *C_AMFObject, pBuffer *byte, nSize, bDecodeName int32) int32 {
nOriginalSize := nSize
var bError int32
obj.o_num = 0
obj.o_props = nil
@ -743,8 +743,7 @@ func C_AMF_Decode(obj *C_AMFObject, pBuffer *byte, nSize int32, bDecodeName int3
continue
}
// TODO port AMFProp_Decode
nRes = int32(C_AMFProp_Decode(&prop, (*byte)(unsafe.Pointer(pBuffer)),
int32(nSize), int32(bDecodeName)))
nRes = C_AMFProp_Decode(&prop, pBuffer, nSize, bDecodeName)
// nRes = int32(C.AMFProp_Decode(&prop, (*byte)(unsafe.Pointer(pBuffer)),
// int32(nSize), int32(bDecodeName)))
if nRes == -1 {
@ -787,7 +786,7 @@ func C_AMF_AddProp(obj *C_AMFObject, prop *C_AMFObjectProperty) {
// amf.c + 1249
func C_AMF_GetProp(obj *C_AMFObject, name string, nIndex int32) *C_AMFObjectProperty {
if nIndex >= 0 {
if nIndex < int32(obj.o_num) {
if nIndex < obj.o_num {
return &(*(*C_AMFObjectProperty)(incPtr(unsafe.Pointer(obj.o_props),
int(nIndex), int(unsafe.Sizeof(*obj.o_props)))))
}
@ -801,14 +800,14 @@ func C_AMF_GetProp(obj *C_AMFObject, name string, nIndex int32) *C_AMFObjectProp
}
}
}
return (*C_AMFObjectProperty)(&AMFProp_Invalid)
return &AMFProp_Invalid
}
// void AMF_Reset(AMFObject* obj);
// amf.c +1282
func C_AMF_Reset(obj *C_AMFObject) {
var n int32
for n = 0; n < int32(obj.o_num); n++ {
for n = 0; n < obj.o_num; n++ {
C_AMFProp_Reset(&(*(*C_AMFObjectProperty)(incPtr(unsafe.Pointer(obj.o_props),
int(n), int(unsafe.Sizeof(*obj.o_props))))))
}

View File

@ -259,7 +259,7 @@ func C_RTMP_IsConnected(r *C_RTMP) int32 {
// void RTMP_SetBufferMS(RTMP *r, int size);
// rtmp.c +381
func C_RTMP_SetBufferMS(r *C_RTMP, size int32) {
r.m_nBufferMS = int32(size)
r.m_nBufferMS = size
}
// void SocksSetup(RTMP *r, C_AVal* sockshost);
@ -368,7 +368,7 @@ func C_RTMP_Connect0(r *C_RTMP, service *C.sockaddr) (ok bool) {
{
var tv int32
SET_RCVTIMEO(&tv, int32(r.Link.timeout))
SET_RCVTIMEO(&tv, r.Link.timeout)
if C.setsockopt(C.int(r.m_sb.sb_socket), C.SOL_SOCKET, C.SO_RCVTIMEO,
unsafe.Pointer(&tv), C.socklen_t(unsafe.Sizeof(tv))) != 0 {
@ -479,7 +479,7 @@ func C_RTMP_ConnectStream(r *C_RTMP, seekTime int32) (playing bool) {
memset((*byte)(unsafe.Pointer(&packet)), 0, int(unsafe.Sizeof(packet)))
if seekTime > 0 {
r.Link.seekTime = int32(seekTime)
r.Link.seekTime = seekTime
}
r.m_mediaChannel = 0
@ -554,7 +554,7 @@ func C_RTMP_ClientPacket(r *C_RTMP, packet *C_RTMPPacket) int32 {
// TODO use new logger here
//RTMP_Log(RTMP_LOGDEBUG, "%s, received: invoke %u bytes", __FUNCTION__,packet.m_nBodySize);
if C_HandleInvoke(r, (*byte)(unsafe.Pointer(packet.m_body)), uint32(packet.m_nBodySize)) {
if C_HandleInvoke(r, packet.m_body, packet.m_nBodySize) {
// This will never happen with the methods we implement.
log.Println("HasMediaPacket")
bHasMediaPacket = 2
@ -666,8 +666,7 @@ func C_WriteN(r *C_RTMP, buffer unsafe.Pointer, n int) (ok bool) {
func C_SendConnectPacket(r *C_RTMP, cp *C_RTMPPacket) (ok bool) {
var packet C_RTMPPacket
var pbuf [4096]byte
pend := (*byte)(unsafe.Pointer(incBytePtr(unsafe.Pointer(&pbuf[0]),
int(unsafe.Sizeof(pbuf)))))
pend := (*byte)(incBytePtr(unsafe.Pointer(&pbuf[0]), int(unsafe.Sizeof(pbuf))))
var enc *byte
if cp != nil {
@ -691,7 +690,7 @@ func C_SendConnectPacket(r *C_RTMP, cp *C_RTMPPacket) (ok bool) {
(*[_Gi]byte)(unsafe.Pointer(enc))[0] = AMF_OBJECT
enc = (*byte)(unsafe.Pointer(incBytePtr(unsafe.Pointer(enc), 1)))
enc = (*byte)(incBytePtr(unsafe.Pointer(enc), 1))
enc = C_AMF_EncodeNamedString(enc, pend, av_app, r.Link.app)
if enc == nil {
@ -733,11 +732,11 @@ func C_SendConnectPacket(r *C_RTMP, cp *C_RTMPPacket) (ok bool) {
if enc == nil {
return false
}
enc = C_AMF_EncodeNamedNumber(enc, pend, av_audioCodecs, float64(r.m_fAudioCodecs))
enc = C_AMF_EncodeNamedNumber(enc, pend, av_audioCodecs, r.m_fAudioCodecs)
if enc == nil {
return false
}
enc = C_AMF_EncodeNamedNumber(enc, pend, av_videoCodecs, float64(r.m_fVideoCodecs))
enc = C_AMF_EncodeNamedNumber(enc, pend, av_videoCodecs, r.m_fVideoCodecs)
if enc == nil {
return false
}
@ -754,7 +753,7 @@ func C_SendConnectPacket(r *C_RTMP, cp *C_RTMPPacket) (ok bool) {
}
if r.m_fEncoding != 0.0 || r.m_bSendEncoding != 0 {
enc = C_AMF_EncodeNamedNumber(enc, pend, av_objectEncoding, float64(r.m_fEncoding))
enc = C_AMF_EncodeNamedNumber(enc, pend, av_objectEncoding, r.m_fEncoding)
if enc == nil {
return false
}
@ -778,7 +777,7 @@ func C_SendConnectPacket(r *C_RTMP, cp *C_RTMPPacket) (ok bool) {
if enc == nil {
return false
}
enc = C_AMF_EncodeString(enc, (*byte)(pend), r.Link.auth)
enc = C_AMF_EncodeString(enc, pend, r.Link.auth)
if enc == nil {
return false
}
@ -946,7 +945,7 @@ func C_SendPublish(r *C_RTMP) (ok bool) {
packet.m_headerType = RTMP_PACKET_SIZE_LARGE
packet.m_packetType = RTMP_PACKET_TYPE_INVOKE
packet.m_nTimeStamp = 0
packet.m_nInfoField2 = int32(r.m_stream_id)
packet.m_nInfoField2 = r.m_stream_id
packet.m_hasAbsTimestamp = 0
packet.m_body = &pbuf[RTMP_MAX_HEADER_SIZE]
@ -1022,7 +1021,7 @@ func C_SendBytesReceived(r *C_RTMP) (ok bool) {
packet.m_nBodySize = 4
C_AMF_EncodeInt32((*byte)(unsafe.Pointer(packet.m_body)), pend, int32(r.m_nBytesIn))
C_AMF_EncodeInt32(packet.m_body, pend, r.m_nBytesIn)
r.m_nBytesInSent = r.m_nBytesIn
@ -1070,9 +1069,6 @@ func C_AV_erase(m []C_RTMP_METHOD, i int) []C_RTMP_METHOD {
// int HandleInvoke(RTMP* r, const char* body, unsigned int nBodySize);
// rtmp.c +2912
func C_HandleInvoke(r *C_RTMP, body *byte, nBodySize uint32) (ok bool) {
var obj C_AMFObject
var txn float64
var nRes int32
if *body != 0x02 {
// TODO use new logger here
@ -1080,7 +1076,8 @@ func C_HandleInvoke(r *C_RTMP, body *byte, nBodySize uint32) (ok bool) {
//__FUNCTION__);
return false
}
nRes = C_AMF_Decode(&obj, body, int32(nBodySize), 0)
var obj C_AMFObject
nRes := C_AMF_Decode(&obj, body, int32(nBodySize), 0)
if nRes < 0 {
// TODO use new logger here
//RTMP_Log(RTMP_LOGERROR, "%s, error decoding invoke packet", __FUNCTION__);
@ -1091,7 +1088,7 @@ func C_HandleInvoke(r *C_RTMP, body *byte, nBodySize uint32) (ok bool) {
//C.AMF_Dump(&obj)
//C.AMFProp_GetString(C_AMF_GetProp(&obj, nil, 0), &method)
method := C_AMFProp_GetString(C_AMF_GetProp(&obj, "", 0))
txn = float64(C_AMFProp_GetNumber(C_AMF_GetProp(&obj, "", 1)))
txn := C_AMFProp_GetNumber(C_AMF_GetProp(&obj, "", 1))
// TODO use new logger here
// RTMP_Log(RTMP_LOGDEBUG, "%s, server invoking <%s>", __FUNCTION__, method.av_val);
@ -1242,9 +1239,9 @@ func C_HandleClientBW(r *C_RTMP, packet *C_RTMPPacket) {
//r.m_nClientBW = int32(C.AMF_DecodeInt32((*byte)(unsafe.Pointer(packet.m_body))))
if packet.m_nBodySize > 4 {
r.m_nClientBW2 = (uint8)((*[_Gi]byte)(unsafe.Pointer(packet.m_body))[4])
r.m_nClientBW2 = (*[_Gi]byte)(unsafe.Pointer(packet.m_body))[4]
} else {
r.m_nClientBW2 = 255
r.m_nClientBW2 = 0xff
}
// TODO use new logger here
// RTMP_Log(RTMP_LOGDEBUG, "%s: client BW = %d %d", __FUNCTION__, r.m_nClientBW,
@ -1254,7 +1251,7 @@ func C_HandleClientBW(r *C_RTMP, packet *C_RTMPPacket) {
// static int DecodeInt32LE(const char* data);
// rtmp.c +3527
func C_DecodeInt32LE(data *byte) int32 {
var c *uint8 = (*uint8)(data)
var c *uint8 = data
return int32(((*[_Gi]byte)(unsafe.Pointer(c))[3] << 24) |
((*[_Gi]byte)(unsafe.Pointer(c))[2] << 16) |
((*[_Gi]byte)(unsafe.Pointer(c))[1] << 8) |
@ -1278,24 +1275,23 @@ func C_EncodeInt32LE(output *byte, nVal int32) int32 {
// rtmp.c +3550
func C_RTMP_ReadPacket(r *C_RTMP, packet *C_RTMPPacket) (ok bool) {
var hbuf [RTMP_MAX_HEADER_SIZE]uint8
memset((*byte)(&hbuf[0]), 0, RTMP_MAX_HEADER_SIZE)
var header *byte
header = (*byte)(unsafe.Pointer(&hbuf[0]))
var nSize, hSize, nToRead, nChunk int32
var extendedTimestamp int32
if C_ReadN(r, (*byte)(&hbuf[0]), 1) == 0 {
if C_ReadN(r, &hbuf[0], 1) == 0 {
log.Println("C_RTMP_ReadPacket: failed to read RTMP packet header!")
return false
}
packet.m_headerType = uint8((hbuf[0] & 0xc0) >> 6)
packet.m_headerType = (hbuf[0] & 0xc0) >> 6
packet.m_nChannel = int32(hbuf[0] & 0x3f)
header = (*byte)(incBytePtr(unsafe.Pointer(header), 1))
switch {
case packet.m_nChannel == 0:
if C_ReadN(r, (*byte)(&hbuf[1]), 1) != 1 {
if C_ReadN(r, &hbuf[1], 1) != 1 {
log.Println("C_RTMP_ReadPacket: failed to read rtmp packet header 2nd byte.")
return false
}
@ -1306,20 +1302,20 @@ func C_RTMP_ReadPacket(r *C_RTMP, packet *C_RTMPPacket) (ok bool) {
case packet.m_nChannel == 1:
var tmp int32
if C_ReadN(r, (*byte)(&hbuf[1]), 2) != 2 {
if C_ReadN(r, &hbuf[1], 2) != 2 {
log.Println("C_RTMP_ReadPacket: failed to read RTMP packet 3rd byte")
return false
}
tmp = int32((hbuf[2] << 8) + hbuf[1])
packet.m_nChannel = int32(tmp + 64)
packet.m_nChannel = tmp + 64
header = (*byte)(incBytePtr(unsafe.Pointer(header), 2))
}
nSize = int32(packetSize[packet.m_headerType])
if packet.m_nChannel >= r.m_channelsAllocatedIn {
var n int32 = int32(packet.m_nChannel + 10)
n := packet.m_nChannel + 10
timestamp := (*int32)(C.realloc(unsafe.Pointer(r.m_channelTimestamp),
C.size_t(int32(unsafe.Sizeof(n))*n)))
@ -1334,7 +1330,7 @@ func C_RTMP_ReadPacket(r *C_RTMP, packet *C_RTMPPacket) (ok bool) {
//C.free(unsafe.Pointer(r.m_vecChannelsIn))
}
r.m_channelTimestamp = (*int32)(timestamp)
r.m_channelTimestamp = timestamp
r.m_vecChannelsIn = packets
if timestamp == nil || packets == nil {
@ -1344,11 +1340,11 @@ func C_RTMP_ReadPacket(r *C_RTMP, packet *C_RTMPPacket) (ok bool) {
memset((*byte)(incPtr(unsafe.Pointer(r.m_channelTimestamp),
int(r.m_channelsAllocatedIn), int(unsafe.Sizeof(*r.m_channelTimestamp)))),
0, int(4*int32((n-int32(r.m_channelsAllocatedIn)))))
0, int(4*(n-r.m_channelsAllocatedIn)))
memset((*byte)(incPtr(unsafe.Pointer(r.m_vecChannelsIn), int(
r.m_channelsAllocatedIn), int(unsafe.Sizeof(*r.m_vecChannelsIn)))), 0,
int(int32(unsafe.Sizeof(*packets))*(n-int32(r.m_channelsAllocatedIn))))
r.m_channelsAllocatedIn = int32(n)
int(int32(unsafe.Sizeof(*packets))*(n-r.m_channelsAllocatedIn)))
r.m_channelsAllocatedIn = n
}
switch {
@ -1377,20 +1373,18 @@ func C_RTMP_ReadPacket(r *C_RTMP, packet *C_RTMPPacket) (ok bool) {
unsafe.Pointer(&hbuf[0])))), int(nSize))))
if nSize >= 3 {
packet.m_nTimeStamp = uint32(C_AMF_DecodeInt24(header))
packet.m_nTimeStamp = C_AMF_DecodeInt24(header)
if nSize >= 6 {
packet.m_nBodySize = uint32(C_AMF_DecodeInt24((*byte)(incBytePtr(
unsafe.Pointer(header), 3))))
packet.m_nBodySize = C_AMF_DecodeInt24((*byte)(incBytePtr(unsafe.Pointer(header), 3)))
packet.m_nBytesRead = 0
if nSize > 6 {
packet.m_packetType = uint8((*[_Gi]byte)(unsafe.Pointer(header))[6])
packet.m_packetType = (*[_Gi]byte)(unsafe.Pointer(header))[6]
if nSize == 11 {
// TODO: port this
packet.m_nInfoField2 = int32(C_DecodeInt32LE((*byte)(incBytePtr(
unsafe.Pointer(header), 7))))
packet.m_nInfoField2 = C_DecodeInt32LE((*byte)(incBytePtr(unsafe.Pointer(header), 7)))
}
}
}
@ -1406,34 +1400,33 @@ func C_RTMP_ReadPacket(r *C_RTMP, packet *C_RTMPPacket) (ok bool) {
return false
}
// TODO: port this
packet.m_nTimeStamp = uint32(C_AMF_DecodeInt32((*byte)(incBytePtr(
unsafe.Pointer(header), int(nSize)))))
packet.m_nTimeStamp = C_AMF_DecodeInt32((*byte)(incBytePtr(unsafe.Pointer(header), int(nSize))))
hSize += 4
}
if packet.m_nBodySize > 0 && packet.m_body == nil {
// TODO: port this
if !C_RTMPPacket_Alloc(packet, uint32(packet.m_nBodySize)) {
if !C_RTMPPacket_Alloc(packet, packet.m_nBodySize) {
log.Println("RTMPRead_Packet: failed to allocate packet")
return false
}
packet.m_headerType = uint8((hbuf[0] & 0xc0) >> 6)
packet.m_headerType = (hbuf[0] & 0xc0) >> 6
}
nToRead = int32(packet.m_nBodySize - packet.m_nBytesRead)
nChunk = int32(r.m_inChunkSize)
nChunk = r.m_inChunkSize
if nToRead < nChunk {
nChunk = nToRead
}
if packet.m_chunk != nil {
packet.m_chunk.c_headerSize = int32(hSize)
packet.m_chunk.c_headerSize = hSize
memmove(unsafe.Pointer(&packet.m_chunk.c_header[0]), unsafe.Pointer(&hbuf[0]),
uintptr(hSize))
packet.m_chunk.c_chunk = (*byte)(incBytePtr(unsafe.Pointer(packet.m_body),
int(packet.m_nBytesRead)))
packet.m_chunk.c_chunkSize = int32(nChunk)
packet.m_chunk.c_chunkSize = nChunk
}
if C_ReadN(r, (*byte)(incBytePtr(unsafe.Pointer(packet.m_body), int(packet.m_nBytesRead))),
@ -1451,8 +1444,7 @@ func C_RTMP_ReadPacket(r *C_RTMP, packet *C_RTMPPacket) (ok bool) {
var tmpPkt C_RTMPPacket
*(**C_RTMPPacket)(incPtr(unsafe.Pointer(r.m_vecChannelsIn), int(packet.m_nChannel),
int(unsafe.Sizeof(tmpPktPtr)))) = (*C_RTMPPacket)(malloc(uintptr(
unsafe.Sizeof(tmpPkt))))
int(unsafe.Sizeof(tmpPktPtr)))) = (*C_RTMPPacket)(malloc(unsafe.Sizeof(tmpPkt)))
}
memmove(unsafe.Pointer(*(**C_RTMPPacket)(incPtr(unsafe.Pointer(
r.m_vecChannelsIn), int(packet.m_nChannel), int(unsafe.Sizeof(tmpPktPtr))))),
@ -1640,7 +1632,7 @@ func C_RTMP_SendPacket(r *C_RTMP, packet *C_RTMPPacket, queue int) (ok bool) {
}
hptr = header
c = byte(packet.m_headerType) << 6
c = packet.m_headerType << 6
switch cSize {
case 0:
@ -1673,14 +1665,13 @@ func C_RTMP_SendPacket(r *C_RTMP, packet *C_RTMPPacket, queue int) (ok bool) {
if nSize > 4 {
hptr = unsafe.Pointer(C_AMF_EncodeInt24((*byte)(hptr), (*byte)(hend), (int32(packet.m_nBodySize))))
*(*byte)(hptr) = byte(packet.m_packetType)
*(*byte)(hptr) = packet.m_packetType
hptr = incBytePtr(hptr, 1)
}
if nSize > 8 {
// TODO: port this
hptr = incBytePtr(hptr, int(C_EncodeInt32LE((*byte)(hptr),
int32(packet.m_nInfoField2))))
hptr = incBytePtr(hptr, int(C_EncodeInt32LE((*byte)(hptr), packet.m_nInfoField2)))
}
if t >= 0xffffff {
@ -1728,7 +1719,7 @@ func C_RTMP_SendPacket(r *C_RTMP, packet *C_RTMPPacket, queue int) (ok bool) {
hSize += 4
}
*(*byte)(header) = byte(0xc0 | c)
*(*byte)(header) = 0xc0 | c
if cSize != 0 {
tmp := int(packet.m_nChannel) - 64
@ -1747,7 +1738,7 @@ func C_RTMP_SendPacket(r *C_RTMP, packet *C_RTMPPacket, queue int) (ok bool) {
}
if tbuf != nil {
ok := C_WriteN(r, tbuf, int(uintptr(decBytePtr(toff, int(uintptr(unsafe.Pointer(tbuf)))))))
ok := C_WriteN(r, tbuf, int(uintptr(decBytePtr(toff, int(uintptr(tbuf))))))
////C.free(tbuf)
tbuf = nil
@ -1779,13 +1770,11 @@ func C_RTMP_SendPacket(r *C_RTMP, packet *C_RTMPPacket, queue int) (ok bool) {
int(packet.m_nChannel), int(unsafe.Sizeof(packet)))) == nil {
*(**C_RTMPPacket)(incPtr(unsafe.Pointer(r.m_vecChannelsOut),
int(packet.m_nChannel), int(unsafe.Sizeof(packet)))) =
(*C_RTMPPacket)(malloc(uintptr(unsafe.Sizeof(*packet))))
int(packet.m_nChannel), int(unsafe.Sizeof(packet)))) = (*C_RTMPPacket)(malloc(unsafe.Sizeof(*packet)))
}
memmove(unsafe.Pointer(*(**C_RTMPPacket)(incPtr(unsafe.Pointer(r.m_vecChannelsOut),
int(packet.m_nChannel), int(unsafe.Sizeof(packet))))), unsafe.Pointer(packet),
uintptr(unsafe.Sizeof(*packet)))
int(packet.m_nChannel), int(unsafe.Sizeof(packet))))), unsafe.Pointer(packet), unsafe.Sizeof(*packet))
return true
}
@ -1802,7 +1791,7 @@ func C_CloseInternal(r *C_RTMP, reconnect int32) {
if C_RTMP_IsConnected(r) != 0 {
if r.m_stream_id > 0 {
i = int32(r.m_stream_id)
i = r.m_stream_id
if r.Link.protocol&RTMP_FEATURE_WRITE != 0 {
C_SendFCUnpublish(r)
}
@ -1916,7 +1905,7 @@ func C_RTMP_Write(r *C_RTMP, buf []byte) int {
var num int
pkt.m_nChannel = 0x04
pkt.m_nInfoField2 = int32(r.m_stream_id)
pkt.m_nInfoField2 = r.m_stream_id
for len(buf) != 0 {
if pkt.m_nBytesRead == 0 {
if size < minDataSize {
@ -1929,11 +1918,11 @@ func C_RTMP_Write(r *C_RTMP, buf []byte) int {
buf = buf[13:]
}
pkt.m_packetType = uint8(buf[0])
pkt.m_packetType = buf[0]
buf = buf[1:]
pkt.m_nBodySize = uint32(C_AMF_DecodeInt24(&buf[0]))
pkt.m_nBodySize = C_AMF_DecodeInt24(&buf[0])
buf = buf[3:]
pkt.m_nTimeStamp = uint32(C_AMF_DecodeInt24(&buf[0]))
pkt.m_nTimeStamp = C_AMF_DecodeInt24(&buf[0])
buf = buf[3:]
pkt.m_nTimeStamp |= uint32(buf[0]) << 24
buf = buf[4:]
@ -1951,7 +1940,7 @@ func C_RTMP_Write(r *C_RTMP, buf []byte) int {
pkt.m_headerType = RTMP_PACKET_SIZE_MEDIUM
}
// TODO: Port this
if !C_RTMPPacket_Alloc(pkt, uint32(pkt.m_nBodySize)) {
if !C_RTMPPacket_Alloc(pkt, pkt.m_nBodySize) {
log.Println("Failed to allocate packet")
return 0
}