diff --git a/rtmp/rtmp.go b/rtmp/rtmp.go index 07bbd3c3..1903eea1 100644 --- a/rtmp/rtmp.go +++ b/rtmp/rtmp.go @@ -974,7 +974,7 @@ func C_SendBytesReceived(r *C.RTMP) int { packet.m_nBodySize = 4 - C_AMFEncodeInt32((*byte)(unsafe.Pointer(packet.m_body)), pend, int32(r.m_nBytesIn)) + C_AMF_EncodeInt32((*byte)(unsafe.Pointer(packet.m_body)), pend, int32(r.m_nBytesIn)) // C.AMF_EncodeInt32(packet.m_body, (*C.char)(unsafe.Pointer(pend)), r.m_nBytesIn) r.m_nBytesInSent = r.m_nBytesIn @@ -983,6 +983,8 @@ func C_SendBytesReceived(r *C.RTMP) int { return C_RTMP_SendPacket(r, &packet, 0) } +// int SendConnectPacket(RTMP* r, RTMPPacket* cp); +// rtmp.c +1579 func C_SendConnectPacket(r *C.RTMP, cp *C.RTMPPacket) int { var packet C.RTMPPacket var pbuf [4096]byte @@ -1008,11 +1010,11 @@ func C_SendConnectPacket(r *C.RTMP, cp *C.RTMPPacket) int { //enc = (*byte)(unsafe.Pointer(C.AMF_EncodeString((*C.char)(unsafe.Pointer(enc)), //(*C.char)(unsafe.Pointer(pend)), &av_connect))) - enc = C_AMFEncodeString(enc, pend, &av_connect) + enc = C_AMF_EncodeString(enc, pend, &av_connect) r.m_numInvokes += 1 //enc = (*byte)(unsafe.Pointer(C.AMF_EncodeNumber((*C.char)(unsafe.Pointer(enc)), //(*C.char)(unsafe.Pointer(pend)), C.double(r.m_numInvokes)))) - enc = C_AMFEncodeNumber(enc, pend, float64(r.m_numInvokes)) + enc = C_AMF_EncodeNumber(enc, pend, float64(r.m_numInvokes)) *indxBytePtr(unsafe.Pointer(enc), 0) = AMF_OBJECT @@ -1020,14 +1022,14 @@ func C_SendConnectPacket(r *C.RTMP, cp *C.RTMPPacket) int { //enc = (*byte)(unsafe.Pointer(C.AMF_EncodeNamedString((*C.char)( //unsafe.Pointer(enc)), (*C.char)(unsafe.Pointer(pend)), &av_app, &r.Link.app))) - enc = C_AMFEncodeNamedString(enc, pend, &av_app, &r.Link.app) + enc = C_AMF_EncodeNamedString(enc, pend, &av_app, &r.Link.app) if enc == nil { return 0 } if r.Link.protocol&RTMP_FEATURE_WRITE != 0 { //enc = (*byte)(unsafe.Pointer(C.AMF_EncodeNamedString((*C.char)( //unsafe.Pointer(enc)), (*C.char)(unsafe.Pointer(pend)), &av_type, &av_nonprivate))) - enc = C_AMFEncodeNamedString(enc, pend, &av_type, &av_nonprivate) + enc = C_AMF_EncodeNamedString(enc, pend, &av_type, &av_nonprivate) if enc == nil { return 0 @@ -1037,7 +1039,7 @@ func C_SendConnectPacket(r *C.RTMP, cp *C.RTMPPacket) int { if r.Link.flashVer.av_len != 0 { //enc = (*byte)(unsafe.Pointer(C.AMF_EncodeNamedString((*C.char)( //unsafe.Pointer(enc)), (*C.char)(unsafe.Pointer(pend)), &av_flashVer, &r.Link.flashVer))) - enc = C_AMFEncodeNamedString(enc, pend, &av_flashVer, &r.Link.flashVer) + enc = C_AMF_EncodeNamedString(enc, pend, &av_flashVer, &r.Link.flashVer) if enc == nil { return 0 } @@ -1045,7 +1047,7 @@ func C_SendConnectPacket(r *C.RTMP, cp *C.RTMPPacket) int { if r.Link.swfUrl.av_len != 0 { //enc = (*byte)(unsafe.Pointer(C.AMF_EncodeNamedString((*C.char)( // unsafe.Pointer(enc)), (*C.char)(unsafe.Pointer(pend)), &av_swfUrl, &r.Link.swfUrl))) - enc = C_AMFEncodeNamedString(enc, pend, &av_swfUrl, &r.Link.swfUrl) + enc = C_AMF_EncodeNamedString(enc, pend, &av_swfUrl, &r.Link.swfUrl) if enc == nil { return 0 } @@ -1054,7 +1056,7 @@ func C_SendConnectPacket(r *C.RTMP, cp *C.RTMPPacket) int { if r.Link.tcUrl.av_len != 0 { //enc = (*byte)(unsafe.Pointer(C.AMF_EncodeNamedString((*C.char)( //unsafe.Pointer(enc)), (*C.char)(unsafe.Pointer(pend)), &av_tcUrl, &r.Link.tcUrl))) - enc = C_AMFEncodeNamedString(enc, pend, &av_tcUrl, &r.Link.tcUrl) + enc = C_AMF_EncodeNamedString(enc, pend, &av_tcUrl, &r.Link.tcUrl) if enc == nil { return 0 } @@ -1063,38 +1065,38 @@ func C_SendConnectPacket(r *C.RTMP, cp *C.RTMPPacket) int { if r.Link.protocol&RTMP_FEATURE_WRITE == 0 { //enc = (*byte)(unsafe.Pointer(C.AMF_EncodeNamedBoolean((*C.char)( //unsafe.Pointer(enc)), (*C.char)(unsafe.Pointer(pend)), &av_fpad, 0))) - enc = C_AMFEncodeNamedBoolean(enc, pend, &av_fpad, 0) + enc = C_AMF_EncodeNamedBoolean(enc, pend, &av_fpad, 0) if enc == nil { return 0 } //enc = (*byte)(unsafe.Pointer(C.AMF_EncodeNamedNumber((*C.char)( //unsafe.Pointer(enc)), (*C.char)(unsafe.Pointer(pend)), &av_capabilities, 15.0))) - enc = C_AMFEncodeNamedNumber(enc, pend, &av_capabilities, 15.0) + enc = C_AMF_EncodeNamedNumber(enc, pend, &av_capabilities, 15.0) if enc == nil { return 0 } //enc = (*byte)(unsafe.Pointer(C.AMF_EncodeNamedNumber((*C.char)( // unsafe.Pointer(enc)), (*C.char)(unsafe.Pointer(pend)), &av_audioCodecs, r.m_fAudioCodecs))) - enc = C_AMFEncodeNamedNumber(enc, pend, &av_audioCodecs, float64(r.m_fAudioCodecs)) + enc = C_AMF_EncodeNamedNumber(enc, pend, &av_audioCodecs, float64(r.m_fAudioCodecs)) if enc == nil { return 0 } //enc = (*byte)(unsafe.Pointer(C.AMF_EncodeNamedNumber((*C.char)( //unsafe.Pointer(enc)), (*C.char)(unsafe.Pointer(pend)), &av_videoCodecs, r.m_fVideoCodecs))) - enc = C_AMFEncodeNamedNumber(enc, pend, &av_videoCodecs, float64(r.m_fVideoCodecs)) + enc = C_AMF_EncodeNamedNumber(enc, pend, &av_videoCodecs, float64(r.m_fVideoCodecs)) if enc == nil { return 0 } //enc = (*byte)(unsafe.Pointer(C.AMF_EncodeNamedNumber((*C.char)( // unsafe.Pointer(enc)), (*C.char)(unsafe.Pointer(pend)), &av_videoFunction, 1.0))) - enc = C_AMFEncodeNamedNumber(enc, pend, &av_videoFunction, 1.0) + enc = C_AMF_EncodeNamedNumber(enc, pend, &av_videoFunction, 1.0) if enc == nil { return 0 } if r.Link.pageUrl.av_len != 0 { //enc = (*byte)(unsafe.Pointer(C.AMF_EncodeNamedString((*C.char)( //unsafe.Pointer(enc)), (*C.char)(unsafe.Pointer(pend)), &av_pageUrl, &r.Link.pageUrl))) - enc = C_AMFEncodeNamedString(enc, pend, &av_pageUrl, &r.Link.pageUrl) + enc = C_AMF_EncodeNamedString(enc, pend, &av_pageUrl, &r.Link.pageUrl) if enc == nil { return 0 } @@ -1104,7 +1106,7 @@ func C_SendConnectPacket(r *C.RTMP, cp *C.RTMPPacket) int { if r.m_fEncoding != 0.0 || r.m_bSendEncoding != 0 { //enc = (*byte)(unsafe.Pointer(C.AMF_EncodeNamedNumber((*C.char)( //unsafe.Pointer(enc)), (*C.char)(unsafe.Pointer(pend)), &av_objectEncoding, r.m_fEncoding))) - enc = C_AMFEncodeNamedNumber(enc, pend, &av_objectEncoding, float64(r.m_fEncoding)) + enc = C_AMF_EncodeNamedNumber(enc, pend, &av_objectEncoding, float64(r.m_fEncoding)) if enc == nil { return 0 } @@ -1126,13 +1128,13 @@ func C_SendConnectPacket(r *C.RTMP, cp *C.RTMPPacket) int { if r.Link.auth.av_len != 0 { //enc = (*byte)(unsafe.Pointer(C.AMF_EncodeBoolean((*C.char)( // unsafe.Pointer(enc)), (*C.char)(unsafe.Pointer(pend)), r.Link.lFlags&RTMP_LF_AUTH))) - enc = C_AMFEncodeBoolean(enc, pend, int(r.Link.lFlags&RTMP_LF_AUTH)) + enc = C_AMF_EncodeBoolean(enc, pend, int(r.Link.lFlags&RTMP_LF_AUTH)) if enc == nil { return 0 } //enc = (*byte)(unsafe.Pointer(C.AMF_EncodeString((*C.char)(unsafe.Pointer(enc)), //(*C.char)(unsafe.Pointer(pend)), &r.Link.auth))) - enc = C_AMFEncodeString(enc, (*byte)(pend), &r.Link.auth) + enc = C_AMF_EncodeString(enc, (*byte)(pend), &r.Link.auth) if enc == nil { return 0 } @@ -1161,6 +1163,8 @@ func C_SendConnectPacket(r *C.RTMP, cp *C.RTMPPacket) int { return C_RTMP_SendPacket(r, &packet, 1) } +// char* AMFPropEncode(AMFOBjectProperty* prop, char* pBufer, char* pBufEnd); +// amf.c +366 func C_AMFPropEncode(p *C.AMFObjectProperty, pBuffer *byte, pBufEnd *byte) *byte { if p.p_type == AMF_INVALID { return nil @@ -1184,15 +1188,15 @@ func C_AMFPropEncode(p *C.AMFObjectProperty, pBuffer *byte, pBufEnd *byte) *byte switch p.p_type { case AMF_NUMBER: - pBuffer = C_AMFEncodeNumber(pBuffer, pBufEnd, float64(p.p_vu.p_number)) + pBuffer = C_AMF_EncodeNumber(pBuffer, pBufEnd, float64(p.p_vu.p_number)) case AMF_BOOLEAN: val := 0 if p.p_vu.p_number != 0 { val = 1 } - pBuffer = C_AMFEncodeBoolean(pBuffer, pBufEnd, val) + pBuffer = C_AMF_EncodeBoolean(pBuffer, pBufEnd, val) case AMF_STRING: - pBuffer = C_AMFEncodeString(pBuffer, pBufEnd, &p.p_vu.p_aval) + pBuffer = C_AMF_EncodeString(pBuffer, pBufEnd, &p.p_vu.p_aval) case AMF_NULL: if uintptr(incBytePtr(unsafe.Pointer(pBuffer), 1)) >= uintptr(unsafe.Pointer( pBufEnd)) { @@ -1217,6 +1221,8 @@ func C_AMFPropEncode(p *C.AMFObjectProperty, pBuffer *byte, pBufEnd *byte) *byte return pBuffer } +// char* AMF_ENCODE(AMFObject* obj, char* pBuffer, char* pBufEnd); +// amf.c +891 func C_AMFEncode(obj *C.AMFObject, pBuffer *byte, pBufEnd *byte) *byte { if uintptr(unsafe.Pointer(pBuffer))+uintptr(4) >= uintptr(unsafe.Pointer(pBufEnd)) { return nil @@ -1245,6 +1251,8 @@ func C_AMFEncode(obj *C.AMFObject, pBuffer *byte, pBufEnd *byte) *byte { return pBuffer } +// char* AMF_EncodeEcmaArray(AMFObject* obj, char* pBuffer, char* pBufEnd); +// amf.c +924 func C_AMFEncodeEcmaArray(obj *C.AMFObject, pBuffer *byte, pBufEnd *byte) *byte { if int(uintptr(unsafe.Pointer(pBuffer)))+4 >= int(uintptr(unsafe.Pointer(pBufEnd))) { return nil @@ -1253,7 +1261,7 @@ func C_AMFEncodeEcmaArray(obj *C.AMFObject, pBuffer *byte, pBufEnd *byte) *byte *pBuffer = AMF_ECMA_ARRAY pBuffer = (*byte)(incBytePtr(unsafe.Pointer(pBuffer), 1)) - pBuffer = C_AMFEncodeInt32(pBuffer, pBufEnd, int32(obj.o_num)) + pBuffer = C_AMF_EncodeInt32(pBuffer, pBufEnd, int32(obj.o_num)) for i := 0; i < int(obj.o_num); i++ { res := C_AMFPropEncode((*C.AMFObjectProperty)(incPtr(unsafe.Pointer( @@ -1275,6 +1283,8 @@ func C_AMFEncodeEcmaArray(obj *C.AMFObject, pBuffer *byte, pBufEnd *byte) *byte return pBuffer } +// char* AMF_EncodeArray(AMFObject* obj, char* pBuffer, char* pBufEnd); +// amf.c +959 func C_AMFEncodeArray(obj *C.AMFObject, pBuffer *byte, pBufEnd *byte) *byte { if int(uintptr(unsafe.Pointer(pBuffer)))+4 >= int(uintptr(unsafe.Pointer(pBufEnd))) { return nil @@ -1283,7 +1293,7 @@ func C_AMFEncodeArray(obj *C.AMFObject, pBuffer *byte, pBufEnd *byte) *byte { *pBuffer = AMF_STRICT_ARRAY pBuffer = (*byte)(incBytePtr(unsafe.Pointer(pBuffer), 1)) - pBuffer = C_AMFEncodeInt32(pBuffer, pBufEnd, int32(obj.o_num)) + pBuffer = C_AMF_EncodeInt32(pBuffer, pBufEnd, int32(obj.o_num)) for i := 0; i < int(obj.o_num); i++ { res := C_AMFPropEncode((*C.AMFObjectProperty)(incPtr(unsafe.Pointer( @@ -1299,6 +1309,8 @@ func C_AMFEncodeArray(obj *C.AMFObject, pBuffer *byte, pBufEnd *byte) *byte { return pBuffer } +// int RTMP_ConnectStream(RTMP* r, int seekTime); +// rtmp.c +1099 func C_RTMP_ConnectStream(r *C.RTMP, seekTime int32) int { var packet C.RTMPPacket memset((*byte)(unsafe.Pointer(&packet)), 0, int(unsafe.Sizeof(packet))) @@ -1314,7 +1326,7 @@ func C_RTMP_ConnectStream(r *C.RTMP, seekTime int32) int { C.RTMP_ReadPacket(r, &packet) != 0 { // TODO: port is ready - if C_RTMP_PacketIsReady(&packet) != 0 { + if C_RTMPPacketIsReady(&packet) != 0 { if packet.m_nBodySize == 0 { continue } @@ -1335,6 +1347,8 @@ func C_RTMP_ConnectStream(r *C.RTMP, seekTime int32) int { return int(r.m_bPlaying) } +// int RTMP_ReadPacket(RTMP* r, RTMPPacket* packet); +// rtmp.c +3550 func C_RTMP_ReadPacket(r *C.RTMP, packet *C.RTMPPacket) int32 { var hbuf [RTMP_MAX_HEADER_SIZE]uint8 memset((*byte)(&hbuf[0]), 0, RTMP_MAX_HEADER_SIZE) @@ -1436,10 +1450,10 @@ func C_RTMP_ReadPacket(r *C.RTMP, packet *C.RTMPPacket) int32 { unsafe.Pointer(&hbuf[0])))), int(nSize)))) if nSize >= 3 { - packet.m_nTimeStamp = C.uint32_t(C_AMFDecodeInt24(header)) + packet.m_nTimeStamp = C.uint32_t(C_AMF_DecodeInt24(header)) if nSize >= 6 { - packet.m_nBodySize = C.uint32_t(C_AMFDecodeInt24((*byte)(incBytePtr( + packet.m_nBodySize = C.uint32_t(C_AMF_DecodeInt24((*byte)(incBytePtr( unsafe.Pointer(header), 3)))) packet.m_nBytesRead = 0 @@ -1544,7 +1558,9 @@ func C_RTMP_ReadPacket(r *C.RTMP, packet *C.RTMPPacket) int32 { return TRUE } -func C_RTMP_PacketIsReady(p *C.RTMPPacket) int { +// #define RTMPPacket_IsReady(a) +// rtmp.h +142 +func C_RTMPPacketIsReady(p *C.RTMPPacket) int { if p.m_nBytesRead == p.m_nBodySize { return 1 } @@ -1561,7 +1577,8 @@ func endSession(rtmp *C.RTMP) uint32 { return 0 } -// C_RTMP_Write writes data to the current rtmp connection encapsulated by r +// int RTMP_Write(RTMP* r, const char* buf, int size); +// rtmp.c +5095 func C_RTMP_Write(r *C.RTMP, data []byte) int { buf := sliceToPtr(data) // TODO: port RTMPPacket @@ -1588,9 +1605,9 @@ func C_RTMP_Write(r *C.RTMP, data []byte) int { pkt.m_packetType = C.uint8_t(*indxBytePtr(buf, 0)) buf = incBytePtr(buf, 1) - pkt.m_nBodySize = C.uint32_t(C_AMFDecodeInt24((*byte)(buf))) + pkt.m_nBodySize = C.uint32_t(C_AMF_DecodeInt24((*byte)(buf))) buf = incBytePtr(buf, 3) - pkt.m_nTimeStamp = C.uint32_t(C_AMFDecodeInt24((*byte)(buf))) + pkt.m_nTimeStamp = C.uint32_t(C_AMF_DecodeInt24((*byte)(buf))) buf = incBytePtr(buf, 3) pkt.m_nTimeStamp |= C.uint32_t(*indxBytePtr(buf, 0)) << 24 buf = incBytePtr(buf, 4) @@ -1618,7 +1635,7 @@ func C_RTMP_Write(r *C.RTMP, data []byte) int { pend = incBytePtr(enc, int(pkt.m_nBodySize)) if pkt.m_packetType == RTMP_PACKET_TYPE_INFO { - enc = unsafe.Pointer(C_AMFEncodeString((*byte)(enc), (*byte)(pend), &setDataFrame)) + enc = unsafe.Pointer(C_AMF_EncodeString((*byte)(enc), (*byte)(pend), &setDataFrame)) pkt.m_nBytesRead = C.uint32_t(math.Abs(float64(uintptr(enc) - uintptr(unsafe.Pointer(pkt.m_body))))) } @@ -1654,7 +1671,8 @@ func C_RTMP_Write(r *C.RTMP, data []byte) int { return size + s2 } -// send packet version 1 - less C stuff +// 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 { var prevPacket *C.RTMPPacket last := 0 @@ -1794,7 +1812,7 @@ func C_RTMP_SendPacket(r *C.RTMP, packet *C.RTMPPacket, queue int) int { } if t >= 0xffffff { - hptr = unsafe.Pointer(C_AMFEncodeInt32((*byte)(hptr), (*byte)(hend), (int32)(t))) + hptr = unsafe.Pointer(C_AMF_EncodeInt32((*byte)(hptr), (*byte)(hend), (int32)(t))) } nSize = int(packet.m_nBodySize) @@ -1856,7 +1874,7 @@ func C_RTMP_SendPacket(r *C.RTMP, packet *C.RTMPPacket, queue int) int { } if t >= 0xffffff { extendedTimestamp := incBytePtr(header, 1+cSize) - C_AMFEncodeInt32((*byte)(extendedTimestamp), + C_AMF_EncodeInt32((*byte)(extendedTimestamp), (*byte)(incBytePtr(extendedTimestamp, 4)), (int32)(t)) } } @@ -1881,7 +1899,7 @@ func C_RTMP_SendPacket(r *C.RTMP, packet *C.RTMPPacket, queue int) int { var ptr unsafe.Pointer ptr = incBytePtr(unsafe.Pointer(packet.m_body), 1) //C.AMF_DecodeString((*C.char)(ptr), &method) - C_AMFDecodeString((*byte)(ptr), &method) + C_AMF_DecodeString((*byte)(ptr), &method) if debugMode { log.Printf("Invoking %v", method.av_val) @@ -1891,8 +1909,8 @@ func C_RTMP_SendPacket(r *C.RTMP, packet *C.RTMPPacket, queue int) int { var txn int ptr = incBytePtr(ptr, 3+int(method.av_len)) //txn = int(C.AMF_DecodeNumber((*C.char)(ptr))) - txn = int(C_AMFDecodeNumber((*byte)(ptr))) - C_AvQueue(&r.m_methodCalls, (*int32)(unsafe.Pointer(&r.m_numCalls)), + txn = int(C_AMF_DecodeNumber((*byte)(ptr))) + C_AV_queue(&r.m_methodCalls, (*int32)(unsafe.Pointer(&r.m_numCalls)), &method, int32(txn)) //C.AV_queue(&r.m_methodCalls, (*C.int)(unsafe.Pointer(&r.m_numCalls)), &method, //C.int(txn)) @@ -1913,13 +1931,15 @@ func C_RTMP_SendPacket(r *C.RTMP, packet *C.RTMPPacket, queue int) int { return 1 } +// int WriteN(RTMP* r, const char* buffer, int n); +// rtmp.c +1502 func C_WriteN(r *C.RTMP, buffer unsafe.Pointer, n int) int { ptr := buffer for n > 0 { var nBytes int // TODO: port this if necessary - nBytes = int(C_SockBufSend(&r.m_sb, (*byte)(ptr), int32(n))) + nBytes = int(C_RTMPSockBuf_Send(&r.m_sb, (*byte)(ptr), int32(n))) if nBytes < 0 { if debugMode { @@ -1955,11 +1975,15 @@ var RTMPT_cmds = []string{ "close", } -func C_SockBufSend(sb *C.RTMPSockBuf, buf *byte, l int32) int32 { +// int RTMPSockBuf_Send(RTMPSockBuf* sb, const char* buf, int len); +// rtmp.c +4297 +func C_RTMPSockBuf_Send(sb *C.RTMPSockBuf, buf *byte, l int32) int32 { return int32(C.send(sb.sb_socket, unsafe.Pointer(buf), C.size_t(l), 0)) } -func C_AvQueue(vals **C.RTMP_METHOD, num *int32, av *C.AVal, txn int32) { +// void AV_queue(RTMP_METHOD** vals, int* num, AVal* av, int txn); +// rtmp.c +2414 +func C_AV_queue(vals **C.RTMP_METHOD, num *int32, av *C.AVal, txn int32) { if (*num & 0x0f) == 0 { // TODO: work out what to do with the realloc //*vals = (*C.RTMP_METHOD)(realloc(unsafe.Pointer(*vals), int((*num+16)* @@ -1981,27 +2005,33 @@ func C_AvQueue(vals **C.RTMP_METHOD, num *int32, av *C.AVal, txn int32) { (*num)++ } -func C_AMFEncodeNamedNumber(output *byte, outend *byte, strName *C.AVal, dVal float64) *byte { +// char* AMF_EncodeNamedNumber(char* output, char* outend, const AVal* strName, double dVal); +// amf.c +286 +func C_AMF_EncodeNamedNumber(output *byte, outend *byte, strName *C.AVal, dVal float64) *byte { if int(uintptr(unsafe.Pointer(output)))+2+int(strName.av_len) > int(uintptr(unsafe.Pointer(outend))) { return nil } - output = C_AMFEncodeInt16(output, outend, int16(strName.av_len)) + output = C_AMF_EncodeInt16(output, outend, int16(strName.av_len)) memmove(unsafe.Pointer(output), unsafe.Pointer(strName.av_val), uintptr(strName.av_len)) output = (*byte)(incBytePtr(unsafe.Pointer(output), int(strName.av_len))) - return C_AMFEncodeNumber(output, outend, dVal) + return C_AMF_EncodeNumber(output, outend, dVal) } -func C_AMFEncodeNamedBoolean(output *byte, outend *byte, strName *C.AVal, bVal int) *byte { +// char* AMF_EncodeNamedBoolean(char* output, char* outend, const AVal* strname, int bVal); +// amf.c +299 +func C_AMF_EncodeNamedBoolean(output *byte, outend *byte, strName *C.AVal, bVal int) *byte { if int(uintptr(unsafe.Pointer(output)))+2+int(strName.av_len) > int(uintptr(unsafe.Pointer(outend))) { return nil } - output = C_AMFEncodeInt16(output, outend, int16(strName.av_len)) + output = C_AMF_EncodeInt16(output, outend, int16(strName.av_len)) memmove(unsafe.Pointer(output), unsafe.Pointer(strName.av_val), uintptr(strName.av_len)) output = (*byte)(incBytePtr(unsafe.Pointer(output), int(strName.av_len))) - return C_AMFEncodeBoolean(output, outend, bVal) + return C_AMF_EncodeBoolean(output, outend, bVal) } -func C_AMFEncodeBoolean(output *byte, outend *byte, bVal int) *byte { +// char* AMF_EncodeBoolean(char* output, char* outend, int bVal); +// amf.c +260 +func C_AMF_EncodeBoolean(output *byte, outend *byte, bVal int) *byte { if int(uintptr(unsafe.Pointer(output)))+2 > int(uintptr(unsafe.Pointer(outend))) { return nil } @@ -2016,7 +2046,9 @@ func C_AMFEncodeBoolean(output *byte, outend *byte, bVal int) *byte { return output } -func C_AMFEncodeNumber(output *byte, outend *byte, dVal float64) *byte { +// char* AMF_EncodeNumber(char* output, char* outend, double dVal); +// amf.c +199 +func C_AMF_EncodeNumber(output *byte, outend *byte, dVal float64) *byte { if int(uintptr(unsafe.Pointer(output)))+1+8 > int(uintptr(unsafe.Pointer(outend))) { return nil } @@ -2034,7 +2066,9 @@ func C_AMFEncodeNumber(output *byte, outend *byte, dVal float64) *byte { return (*byte)(incBytePtr(unsafe.Pointer(output), 8)) } -func C_AMFDecodeNumber(data *byte) float64 { +// double AMF_DecodeNumber(const char* data); +// amf.c +82 +func C_AMF_DecodeNumber(data *byte) float64 { var dVal float64 var ci, co *uint8 ci = (*uint8)(unsafe.Pointer(data)) @@ -2045,21 +2079,24 @@ func C_AMFDecodeNumber(data *byte) float64 { return dVal } -func C_AMFEncodeNamedString(output *byte, outend *byte, strName *C.AVal, strValue *C.AVal) *byte { +// char* AMF_EncodeNamedString(char* output, char* outend, const AVal* strName, const AVal* strValue); +// amf.c +273 +func C_AMF_EncodeNamedString(output *byte, outend *byte, strName *C.AVal, strValue *C.AVal) *byte { if int(uintptr(unsafe.Pointer(output)))+2+int(strName.av_len) > int(uintptr(unsafe.Pointer(outend))) { return nil } - output = C_AMFEncodeInt16(output, outend, int16(strName.av_len)) + output = C_AMF_EncodeInt16(output, outend, int16(strName.av_len)) memmove(unsafe.Pointer(output), unsafe.Pointer(strName.av_val), uintptr(strName.av_len)) output = (*byte)(incBytePtr(unsafe.Pointer(output), int(strName.av_len))) - return C_AMFEncodeString(output, outend, strValue) + return C_AMF_EncodeString(output, outend, strValue) } -// C_AMFDecodeString decodes data into a string inside a AVal -func C_AMFDecodeString(data *byte, bv *C.AVal) { +// void AMF_DecodeString(const char* data, AVal* bv); +// amf.c +68 +func C_AMF_DecodeString(data *byte, bv *C.AVal) { dataPtr := unsafe.Pointer(data) //bv.av_len = C.int(C.AMF_DecodeInt16((*C.char)(dataPtr))) - bv.av_len = C.int(C_AMFDecodeInt16((*byte)(dataPtr))) + bv.av_len = C.int(C_AMF_DecodeInt16((*byte)(dataPtr))) if bv.av_len > 0 { bv.av_val = (*C.char)(incBytePtr(dataPtr, 2)) } else { @@ -2067,13 +2104,15 @@ func C_AMFDecodeString(data *byte, bv *C.AVal) { } } -// C_AMFDecodeInt16 decodes data into a 16 bit number -func C_AMFDecodeInt16(data *byte) uint16 { +// unsigned short AMF_DecodeInt16(const char* data); +// amf.c +41 +func C_AMF_DecodeInt16(data *byte) uint16 { c := unsafe.Pointer(data) return uint16(*(*uint8)(c)<<8 | *(*byte)(incBytePtr(c, 1))) } -// C_AMFEncodeInt24 encodes a int24 into data +// char* AMF_EncodeInt24(char* output, char* outend, int nVal); +// amf.c +149 func C_AMFEncodeInt24(output *byte, outend *byte, nVal int32) *byte { outputPtr := unsafe.Pointer(output) outendPtr := unsafe.Pointer(outend) @@ -2092,8 +2131,9 @@ func C_AMFEncodeInt24(output *byte, outend *byte, nVal int32) *byte { return (*byte)(incBytePtr(outputPtr, 3)) } -// C_AMFDecodeInt24 decodes data into an unsigned int -func C_AMFDecodeInt24(data *byte) uint32 { +// unsigned int AMF_DecodeInt24(const char* data); +// amf.c +50 +func C_AMF_DecodeInt24(data *byte) uint32 { // TODO Understand logic and simplify c := (*uint8)(unsafe.Pointer(data)) dst := uint32(int32(*c) << 16) @@ -2104,7 +2144,9 @@ func C_AMFDecodeInt24(data *byte) uint32 { return dst } -func C_AMFEncodeString(output *byte, outend *byte, bv *C.AVal) *byte { +// char* AMF_EncodeString(char* output, char* outend, const AVal* bv); +// amf.c +174 +func C_AMF_EncodeString(output *byte, outend *byte, bv *C.AVal) *byte { outputPtr := unsafe.Pointer(output) outendPtr := unsafe.Pointer(outend) if (bv.av_len < 65536 && uintptr(incBytePtr(outputPtr, 1+2+int(bv.av_len))) > @@ -2117,14 +2159,14 @@ func C_AMFEncodeString(output *byte, outend *byte, bv *C.AVal) *byte { outputPtr = incBytePtr(outputPtr, 1) outputPtr = unsafe.Pointer(C.AMF_EncodeInt16((*C.char)(outputPtr), (*C.char)( outendPtr), C.short(bv.av_len))) - //outputPtr = unsafe.Pointer(C_AMFEncodeInt16((*byte)(outputPtr), + //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_AMFEncodeInt32((*byte)(outputPtr), + //outputPtr = unsafe.Pointer(C_AMF_EncodeInt32((*byte)(outputPtr), //(*byte)(outendPtr), (int32)(bv.av_len))) } memmove(unsafe.Pointer(outputPtr), unsafe.Pointer(bv.av_val), uintptr(bv.av_len)) @@ -2133,8 +2175,9 @@ func C_AMFEncodeString(output *byte, outend *byte, bv *C.AVal) *byte { return (*byte)(outputPtr) } -// C_AMFEncodeInt16 encodes a int16 into data -func C_AMFEncodeInt16(output *byte, outend *byte, nVal int16) *byte { +// char* AMF_EncodeInt16(char* output, char* outend, short nVal); +// amf.c +138 +func C_AMF_EncodeInt16(output *byte, outend *byte, nVal int16) *byte { outputPtr := unsafe.Pointer(output) outendPtr := unsafe.Pointer(outend) if uintptr(outputPtr)+2 > uintptr(outendPtr) { @@ -2149,8 +2192,9 @@ func C_AMFEncodeInt16(output *byte, outend *byte, nVal int16) *byte { return (*byte)(incBytePtr(outputPtr, 2)) } -// C_AMFEncodeInt32 encodes a int32 into data -func C_AMFEncodeInt32(output *byte, outend *byte, nVal int32) *byte { +// char* AMF_EncodeInt32(char* output, char* outend, int nVal); +// amf.c +161 +func C_AMF_EncodeInt32(output *byte, outend *byte, nVal int32) *byte { outputPtr := unsafe.Pointer(output) outendPtr := unsafe.Pointer(outend) if uintptr(outputPtr)+4 > uintptr(outendPtr) {