From efb5b75f1a8386150fff8211037edb7d7f6a67e4 Mon Sep 17 00:00:00 2001 From: saxon Date: Sat, 18 Aug 2018 13:51:07 +0930 Subject: [PATCH] Started using my structs - tested and working --- rtmp/rtmp.go | 690 +++++++++++++++++++++++++-------------------------- 1 file changed, 345 insertions(+), 345 deletions(-) diff --git a/rtmp/rtmp.go b/rtmp/rtmp.go index 5dba64db..c1f0cdaa 100644 --- a/rtmp/rtmp.go +++ b/rtmp/rtmp.go @@ -188,12 +188,6 @@ const ( debugMode = false ) -// TODO(kortschak): Remove these. -const ( - TRUE = 1 - FALSE = 0 -) - // av_setDataFrame is a static const global in rtmp.c var ( AV_empty = AVC("") @@ -248,8 +242,8 @@ var ( ) var ( - AMFObj_Invalid C.AMFObject - AMFProp_Invalid = C.AMFObjectProperty{p_type: AMF_INVALID} + AMFObj_Invalid C_AMFObject + AMFProp_Invalid = C_AMFObjectProperty{p_type: AMF_INVALID} packetSize = [...]int{12, 8, 4, 1} RTMPProtocolStringsLower = [...]string{ "rtmp", @@ -272,7 +266,7 @@ type Session interface { // session provides parameters required for an rtmp communication session. type session struct { - rtmp *C.RTMP + rtmp *C_RTMP url string timeout uint } @@ -291,9 +285,9 @@ type C_RTMP struct { m_mediaStamp uint32 m_pauseStamp uint32 m_pausing int32 - m_nServerBw int32 - m_nClientBw int32 - m_nClientBw2 uint8 + m_nServerBW int32 + m_nClientBW int32 + m_nClientBW2 uint8 m_bPlaying uint8 m_bSendEncoding uint8 m_bSendCounter uint8 @@ -342,7 +336,7 @@ type C_RTMP_METHOD struct { num int32 } -// typedef struct C.AVal +// typedef struct C_AVal // amf.h +57 type C_AVal struct { av_val *byte @@ -439,7 +433,7 @@ type C_AMFObjectProperty struct { // typedef struct P_vu // amf.h +73 type P_vu struct { - p_number float32 + p_number float64 p_aval C_AVal p_object C_AMFObject } @@ -491,7 +485,7 @@ func (s *session) Write(data []byte) (int, error) { } if C_RTMP_Write(s.rtmp, data) == 0 { - //if C.RTMP_Write(s.rtmp, (*C.char)(unsafe.Pointer(&data[0])), C.int(len(data))) == 0 { + //if C.RTMP_Write(s.rtmp, (*byte)(unsafe.Pointer(&data[0])), int32(len(data))) == 0 { return 0, Err(2) } return len(data), nil @@ -499,15 +493,15 @@ func (s *session) Write(data []byte) (int, error) { // int RTMP_IsConnected(RTMP *r); // rtmp.c +363 -func C_RTMP_IsConnected(r *C.RTMP) int32 { +func C_RTMP_IsConnected(r *C_RTMP) int32 { if r.m_sb.sb_socket != -1 { return 1 } return 0 } -func startSession(rtmp *C.RTMP, u string, timeout uint32) (*C.RTMP, error) { - connect_timeout := C.int(timeout) +func startSession(rtmp *C_RTMP, u string, timeout uint32) (*C_RTMP, error) { + connect_timeout := int32(timeout) rtmp = C_RTMP_Alloc() //rtmp = C.RTMP_Alloc() C_RTMP_Init(rtmp) @@ -544,15 +538,15 @@ func startSession(rtmp *C.RTMP, u string, timeout uint32) (*C.RTMP, error) { // RTMP* RTMP_IsConnected(); // 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))) +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))) } // void RTMP_Init(RTMP *r); // rtmp.c +329 -func C_RTMP_Init(r *C.RTMP) { +func C_RTMP_Init(r *C_RTMP) { r.m_sb.sb_socket = -1 r.m_inChunkSize = RTMP_DEFAULT_CHUNKSIZE r.m_outChunkSize = RTMP_DEFAULT_CHUNKSIZE @@ -569,7 +563,7 @@ func C_RTMP_Init(r *C.RTMP) { // int RTMP_SetupURL(RTMP *r, char* url); // rtmp.c +757 // NOTE: code dealing with rtmp over http has been disregarded -func C_RTMP_SetupURL(r *C.RTMP, u string) int32 { +func C_RTMP_SetupURL(r *C_RTMP, u string) int32 { url := goStrToCStr(u) var ret, length int32 @@ -578,7 +572,7 @@ func C_RTMP_SetupURL(r *C.RTMP, u string) int32 { length = strlen(url) // TODO: port this - //ret = int32(C.RTMP_ParseURL((*C.char)(unsafe.Pointer(url)), &r.Link.protocol, + //ret = int32(C.RTMP_ParseURL((*byte)(unsafe.Pointer(url)), &r.Link.protocol, // &r.Link.hostname, (*C.uint)(&port), &r.Link.playpath0, &r.Link.app)) ret = int32(C_RTMP_ParseURL((*byte)(unsafe.Pointer(url)), (*int32)( unsafe.Pointer(&r.Link.protocol)), &r.Link.hostname, (*uint32)( @@ -587,23 +581,23 @@ func C_RTMP_SetupURL(r *C.RTMP, u string) int32 { return ret } - r.Link.port = C.ushort(port) + r.Link.port = uint16(port) r.Link.playpath = r.Link.playpath0 if r.Link.tcUrl.av_len == 0 { - r.Link.tcUrl.av_val = (*C.char)(unsafe.Pointer(url)) + r.Link.tcUrl.av_val = (*byte)(unsafe.Pointer(url)) if r.Link.app.av_len != 0 { if int(uintptr(unsafe.Pointer(r.Link.app.av_val))) < int(uintptr(incBytePtr(unsafe.Pointer(url), int(length)))) { - r.Link.tcUrl.av_len = C.int(int(r.Link.app.av_len) + + r.Link.tcUrl.av_len = int32(int(r.Link.app.av_len) + int(uintptr(decBytePtr(unsafe.Pointer(r.Link.app.av_val), int(uintptr(unsafe.Pointer(url))))))) } else { 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)(C.malloc(C.size_t(uintptr(length)))) + r.Link.tcUrl.av_val = (*byte)(C.malloc(C.size_t(uintptr(length)))) hostname := string(ptrToSlice(unsafe.Pointer(r.Link.hostname.av_val), int(r.Link.hostname.av_len))) @@ -613,15 +607,15 @@ func C_RTMP_SetupURL(r *C.RTMP, u string) int32 { fString := fmt.Sprintf("%v://%v:%v/%v", RTMPProtocolStringsLower[r.Link.protocol], hostname, r.Link.port, app) - r.Link.tcUrl.av_val = (*C.char)(bToUP(goStrToCStr(fString))) - r.Link.tcUrl.av_len = C.int(strLen(RTMPProtocolStringsLower[r.Link.protocol]) + + r.Link.tcUrl.av_val = (*byte)(bToUP(goStrToCStr(fString))) + r.Link.tcUrl.av_len = int32(strLen(RTMPProtocolStringsLower[r.Link.protocol]) + strLen(string("://")) + strLen(hostname) + strLen(string(":")) + strLen(strconv.Itoa(int(r.Link.port))) + strLen(string("/")) + strLen(app)) r.Link.lFlags |= RTMP_LF_FTCU } } else { - r.Link.tcUrl.av_len = C.int(strlen(url)) + r.Link.tcUrl.av_len = int32(strlen(url)) } } @@ -643,8 +637,8 @@ func C_RTMP_SetupURL(r *C.RTMP, u string) int32 { // int RTMP_ParseURL(const char *url, int *protocol, AVal *host, unsigned int *port, // AVal *playpath, AVal *app); // parseurl.c +33 -func C_RTMP_ParseURL(url *byte, protocol *int32, host *C.AVal, port *uint32, - playpath *C.AVal, app *C.AVal) int { +func C_RTMP_ParseURL(url *byte, protocol *int32, host *C_AVal, port *uint32, + playpath *C_AVal, app *C_AVal) int { var p, end, col, ques, slash *byte // TODO: use our logger here @@ -720,8 +714,8 @@ func C_RTMP_ParseURL(url *byte, protocol *int32, host *C.AVal, port *uint32, } if hostlen < 256 { - host.av_val = (*C.char)(unsafe.Pointer(p)) - host.av_len = C.int(hostlen) + host.av_val = (*byte)(unsafe.Pointer(p)) + host.av_len = int32(hostlen) // TODO: use new logger with this //RTMP_Log(RTMP_LOGDEBUG, "Parsed host : %.*s", hostlen, host.av_val); } else { @@ -804,8 +798,8 @@ func C_RTMP_ParseURL(url *byte, protocol *int32, host *C.AVal, port *uint32, applen = appnamelen } - app.av_val = (*C.char)(unsafe.Pointer(p)) - app.av_len = C.int(applen) + app.av_val = (*byte)(unsafe.Pointer(p)) + app.av_len = int32(applen) // TODO: use new logging here // RTMP_Log(RTMP_LOGDEBUG, "Parsed app : %.*s", applen, p); @@ -818,9 +812,9 @@ func C_RTMP_ParseURL(url *byte, protocol *int32, host *C.AVal, port *uint32, // NOTE: don't think we currently need this section - see 787 for this func if int(uintptr(unsafe.Pointer(end))-uintptr(unsafe.Pointer(p))) != 0 { - var av C.AVal - av.av_val = (*C.char)(unsafe.Pointer(p)) - av.av_len = C.int(uintptr(unsafe.Pointer(end)) - uintptr(unsafe.Pointer(p))) + var av C_AVal + av.av_val = (*byte)(unsafe.Pointer(p)) + av.av_len = int32(uintptr(unsafe.Pointer(end)) - uintptr(unsafe.Pointer(p))) // TODO: port THis //C.RTMP_ParsePlaypath(&av, playpath) C_RTMP_ParsePlaypath(&av, playpath) @@ -831,7 +825,7 @@ func C_RTMP_ParseURL(url *byte, protocol *int32, host *C.AVal, port *uint32, // void RTMP_ParsePlaypath(AVal *in, AVal *out); // parseurl.c +201 -func C_RTMP_ParsePlaypath(in, out *C.AVal) { +func C_RTMP_ParsePlaypath(in, out *C_AVal) { var addMP4 int32 = 0 var addMP3 int32 = 0 var subExt int32 = 0 @@ -930,14 +924,14 @@ func C_RTMP_ParsePlaypath(in, out *C.AVal) { } *destptr = '\x00' - out.av_val = (*C.char)(unsafe.Pointer(streamname)) - out.av_len = C.int(uintptr(unsafe.Pointer(destptr)) - uintptr(unsafe.Pointer( + out.av_val = (*byte)(unsafe.Pointer(streamname)) + out.av_len = int32(uintptr(unsafe.Pointer(destptr)) - uintptr(unsafe.Pointer( streamname))) } -// void SocksSetup(RTMP *r, C.AVal* sockshost); +// void SocksSetup(RTMP *r, C_AVal* sockshost); // rtmp.c +410 -func C_SocksSetup(r *C.RTMP, sockshost *C.AVal) { +func C_SocksSetup(r *C_RTMP, sockshost *C_AVal) { if sockshost.av_len != 0 { socksport := strchr((*byte)(unsafe.Pointer(sockshost.av_val)), ':') hostname := strdup((*byte)(unsafe.Pointer(sockshost.av_val))) @@ -946,8 +940,8 @@ func C_SocksSetup(r *C.RTMP, sockshost *C.AVal) { *indxBytePtr(unsafe.Pointer(hostname), int(uintptr(decBytePtr(unsafe.Pointer(socksport), int(uintptr(unsafe.Pointer(sockshost.av_val))))))) = '\000' - r.Link.sockshost.av_val = (*C.char)(unsafe.Pointer(hostname)) - r.Link.sockshost.av_len = C.int(strlen(hostname)) + r.Link.sockshost.av_val = (*byte)(unsafe.Pointer(hostname)) + r.Link.sockshost.av_len = int32(strlen(hostname)) value, err := strconv.Atoi(string(ptrToSlice(unsafe.Pointer(uintptr( unsafe.Pointer(socksport))+uintptr(1)), int(strlen((*byte)(unsafe.Pointer( @@ -958,7 +952,7 @@ func C_SocksSetup(r *C.RTMP, sockshost *C.AVal) { if uintptr(unsafe.Pointer(socksport)) == 0 { value = 1080 } - r.Link.socksport = C.ushort(value) + r.Link.socksport = uint16(value) } } else { r.Link.sockshost.av_val = nil @@ -968,11 +962,11 @@ func C_SocksSetup(r *C.RTMP, sockshost *C.AVal) { } /* -func rtmpClose(r *C.RTMP) { +func rtmpClose(r *C_RTMP) { closeInternal(r, 0) } -func closeInternal(r *C.RTMP, reconnect int32) { +func closeInternal(r *C_RTMP, reconnect int32) { var i int32 if C_RTMP_IsConnected(r) != 0 { @@ -981,7 +975,7 @@ func closeInternal(r *C.RTMP, reconnect int32) { if r.Link.protocol&RTMP_FEATURE_WRITE != 0 { C.SendFCUnpublish(r) } - C.SendDeleteStream(r, C.double(i)) + C.SendDeleteStream(r, float64(i)) } C.RTMPSockBuf_Close(&r.m_sb) } @@ -1008,16 +1002,16 @@ func closeInternal(r *C.RTMP, reconnect int32) { C.RTMPPacket_Free(&r.m_write) for i := 0; i < int(r.m_channelsAllocatedIn); i++ { - if *(**C.RTMPPacket)(incPtr(unsafe.Pointer(r.m_vecChannelsIn), i, + if *(**C_RTMPPacket)(incPtr(unsafe.Pointer(r.m_vecChannelsIn), i, int(unsafe.Sizeof(&r.m_write)))) != nil { - C.RTMPPacket_Free(*(**C.RTMPPacket)(incPtr(unsafe.Pointer(r.m_vecChannelsIn), i, + C.RTMPPacket_Free(*(**C_RTMPPacket)(incPtr(unsafe.Pointer(r.m_vecChannelsIn), i, int(unsafe.Sizeof(&r.m_write))))) - C.free(unsafe.Pointer(*(**C.RTMPPacket)(incPtr(unsafe.Pointer(r.m_vecChannelsIn), + C.free(unsafe.Pointer(*(**C_RTMPPacket)(incPtr(unsafe.Pointer(r.m_vecChannelsIn), i, int(unsafe.Sizeof(&r.m_write)))))) - *(**C.RTMPPacket)(incPtr(unsafe.Pointer(r.m_vecChannelsIn), + *(**C_RTMPPacket)(incPtr(unsafe.Pointer(r.m_vecChannelsIn), i, int(unsafe.Sizeof(&r.m_write)))) = nil } } @@ -1053,19 +1047,19 @@ func closeInternal(r *C.RTMP, reconnect int32) { // void RTMP_EnableWrite(RTMP *r); // rtmp.c +351 -func C_RTMP_EnableWrite(r *C.RTMP) { +func C_RTMP_EnableWrite(r *C_RTMP) { r.Link.protocol |= RTMP_FEATURE_WRITE } // void RTMP_SetBufferMS(RTMP *r, int size); // rtmp.c +381 -func C_RTMP_SetBufferMS(r *C.RTMP, size int32) { - r.m_nBufferMS = C.int(size) +func C_RTMP_SetBufferMS(r *C_RTMP, size int32) { + r.m_nBufferMS = int32(size) } // int RTMP_Connect(RTMP *r, RTMPPacket* cp); // rtmp.c +1032 -func C_RTMP_Connect(r *C.RTMP, cp *C.RTMPPacket) int { +func C_RTMP_Connect(r *C_RTMP, cp *C_RTMPPacket) int { // TODO: port this var service C.sockaddr_in @@ -1079,7 +1073,7 @@ func C_RTMP_Connect(r *C.RTMP, cp *C.RTMPPacket) int { if r.Link.socksport != 0 { // TODO: port this - if C.add_addr_info(&service, &r.Link.sockshost, C.int(r.Link.socksport)) == 0 { + if C.add_addr_info(&service, (*C.AVal)(unsafe.Pointer(&r.Link.sockshost)), C.int(r.Link.socksport)) == 0 { return 0 } } else { @@ -1102,16 +1096,16 @@ func C_RTMP_Connect(r *C.RTMP, cp *C.RTMPPacket) int { // int RTMP_Connect0(RTMP *r, struct sockaddr* service); // rtmp.c +906 -func C_RTMP_Connect0(r *C.RTMP, service *C.sockaddr) int { +func C_RTMP_Connect0(r *C_RTMP, service *C.sockaddr) int { on := 1 r.m_sb.sb_timedout = 0 r.m_pausing = 0 r.m_fDuration = 0 - r.m_sb.sb_socket = C.socket(C.AF_INET, C.SOCK_STREAM, C.IPPROTO_TCP) + r.m_sb.sb_socket = int32(C.socket(C.AF_INET, C.SOCK_STREAM, C.IPPROTO_TCP)) if r.m_sb.sb_socket != -1 { - if C.connect(r.m_sb.sb_socket, service, C.socklen_t(unsafe.Sizeof(*service))) < 0 { + if C.connect(C.int(r.m_sb.sb_socket), service, C.socklen_t(unsafe.Sizeof(*service))) < 0 { log.Println("C_RTMP_Connect0, failed to connect socket.") } @@ -1134,15 +1128,15 @@ func C_RTMP_Connect0(r *C.RTMP, service *C.sockaddr) int { { var tv int32 SET_RCVTIMEO(&tv, int32(r.Link.timeout)) - // tv := C.int(r.Link.timeout * 1000) + // tv := int32(r.Link.timeout * 1000) - if C.setsockopt(r.m_sb.sb_socket, C.SOL_SOCKET, C.SO_RCVTIMEO, + 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 { log.Println("C_RTMP_Connect0: Setting socket timeout failed") } } - C.setsockopt(r.m_sb.sb_socket, C.IPPROTO_TCP, C.TCP_NODELAY, + C.setsockopt(C.int(r.m_sb.sb_socket), C.IPPROTO_TCP, C.TCP_NODELAY, unsafe.Pointer(&on), C.socklen_t(unsafe.Sizeof(on))) return 1 @@ -1150,13 +1144,13 @@ func C_RTMP_Connect0(r *C.RTMP, service *C.sockaddr) int { // int SocksNegotiate(RTMP* r); // rtmp.c +1062 -func C_SocksNegotiate(r *C.RTMP) int { +func C_SocksNegotiate(r *C_RTMP) int { var addr int32 var service C.sockaddr_in memset((*byte)(unsafe.Pointer(&service)), 0, int(unsafe.Sizeof(service))) - C.add_addr_info(&service, &r.Link.hostname, C.int(r.Link.port)) + C.add_addr_info(&service, (*C.AVal)(unsafe.Pointer(&r.Link.hostname)), C.int(r.Link.port)) addr = int32(inet.Htonl(uint32(service.sin_addr.s_addr))) { @@ -1192,7 +1186,7 @@ func SET_RCVTIMEO(tv *int32, s int32) { // int RTMP_Connect1(RTMP* r, RTMPPacket* cp); // rtmp.c +978 -func C_RTMP_Connect1(r *C.RTMP, cp *C.RTMPPacket) int { +func C_RTMP_Connect1(r *C_RTMP, cp *C_RTMPPacket) int { if debugMode { log.Println("... connected, handshaking...") } @@ -1214,7 +1208,7 @@ func C_RTMP_Connect1(r *C.RTMP, cp *C.RTMPPacket) int { // int HandShake(RTMP* r, int FP9HandShake); // rtmp.c +3744 -func C_HandShake(r *C.RTMP, FP9HandShake int32) int { +func C_HandShake(r *C_RTMP, FP9HandShake int32) int { var bMatch int //uptime := uint32(0) //suptime := uint32(0) @@ -1244,7 +1238,7 @@ func C_HandShake(r *C.RTMP, FP9HandShake int32) int { return 0 } - //if C.ReadN(r, (*C.char)(unsafe.Pointer(&typ)), 1) != 1 { + //if C.ReadN(r, (*byte)(unsafe.Pointer(&typ)), 1) != 1 { if C_ReadN(r, (*byte)(unsafe.Pointer(&typ)), 1) != 1 { return 0 } @@ -1257,7 +1251,7 @@ func C_HandShake(r *C.RTMP, FP9HandShake int32) int { clientbuf[0], typ) } if C_ReadN(r, (*byte)(unsafe.Pointer(&serversig[0])), RTMP_SIG_SIZE) != RTMP_SIG_SIZE { - //if C.ReadN(r, (*C.char)(unsafe.Pointer(&serversig[0])), RTMP_SIG_SIZE) != RTMP_SIG_SIZE { + //if C.ReadN(r, (*byte)(unsafe.Pointer(&serversig[0])), RTMP_SIG_SIZE) != RTMP_SIG_SIZE { return 0 } @@ -1271,7 +1265,7 @@ func C_HandShake(r *C.RTMP, FP9HandShake int32) int { } if C_ReadN(r, (*byte)(unsafe.Pointer(&serversig[0])), RTMP_SIG_SIZE) != RTMP_SIG_SIZE { - //if C.ReadN(r, (*C.char)(unsafe.Pointer(&serversig[0])), RTMP_SIG_SIZE) != RTMP_SIG_SIZE { + //if C.ReadN(r, (*byte)(unsafe.Pointer(&serversig[0])), RTMP_SIG_SIZE) != RTMP_SIG_SIZE { return 0 } @@ -1296,7 +1290,7 @@ func C_RTMP_GetTime() int32 { // int ReadN(RTMP* r, char* buffer, int n); // rtmp.c +1390 -func C_ReadN(r *C.RTMP, buffer *byte, n int) int { +func C_ReadN(r *C_RTMP, buffer *byte, n int) int { nOriginalSize := n var avail int var ptr *byte @@ -1328,11 +1322,11 @@ func C_ReadN(r *C.RTMP, buffer *byte, n int) int { if nRead > 0 { memmove(unsafe.Pointer(ptr), unsafe.Pointer(r.m_sb.sb_start), uintptr(nRead)) - r.m_sb.sb_start = (*C.char)(incBytePtr(unsafe.Pointer(r.m_sb.sb_start), + r.m_sb.sb_start = (*byte)(incBytePtr(unsafe.Pointer(r.m_sb.sb_start), nRead)) - r.m_sb.sb_size -= C.int(nRead) + r.m_sb.sb_size -= int32(nRead) nBytes = nRead - r.m_nBytesIn += C.int(nRead) + r.m_nBytesIn += int32(nRead) if r.m_bSendCounter != 0 && r.m_nBytesIn > (r.m_nBytesInSent+ r.m_nClientBW/10) { //if C.SendBytesReceived(r) == 0 { @@ -1357,7 +1351,7 @@ func C_ReadN(r *C.RTMP, buffer *byte, n int) int { // int RTMPSockBuf_Fill(RTMPSockBuf* sb); // rtmp.c +4253 -func C_RTMPSockBuf_Fill(sb *C.RTMPSockBuf) int { +func C_RTMPSockBuf_Fill(sb *C_RTMPSockBuf) int { var nBytes int if sb.sb_size == 0 { @@ -1370,11 +1364,11 @@ func C_RTMPSockBuf_Fill(sb *C.RTMPSockBuf) int { &sb.sb_buf[0]))) // TODO: figure out what to do with recv - nBytes = int(C.recv(sb.sb_socket, unsafe.Pointer(uintptr(unsafe.Pointer( + nBytes = int(C.recv(C.int(sb.sb_socket), unsafe.Pointer(uintptr(unsafe.Pointer( sb.sb_start))+uintptr(int(sb.sb_size))), C.size_t(nBytes), 0)) if nBytes != -1 { - sb.sb_size += C.int(nBytes) + sb.sb_size += int32(nBytes) } else { log.Println("C_RTMPSockBuf_Fill: recv error!") } @@ -1385,8 +1379,8 @@ func C_RTMPSockBuf_Fill(sb *C.RTMPSockBuf) int { // int SendBytesReceived(RTMP* r); // rtmp.c +2080 -func C_SendBytesReceived(r *C.RTMP) int { - var packet C.RTMPPacket +func C_SendBytesReceived(r *C_RTMP) int { + var packet C_RTMPPacket var pbuf [256]byte pend := (*byte)(incBytePtr(unsafe.Pointer(&pbuf[0]), 256)) @@ -1396,13 +1390,13 @@ func C_SendBytesReceived(r *C.RTMP) int { packet.m_nTimeStamp = 0 packet.m_nInfoField2 = 0 packet.m_hasAbsTimestamp = 0 - packet.m_body = (*C.char)(incBytePtr(unsafe.Pointer(&pbuf[0]), + packet.m_body = (*byte)(incBytePtr(unsafe.Pointer(&pbuf[0]), RTMP_MAX_HEADER_SIZE)) packet.m_nBodySize = 4 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) + // C.AMF_EncodeInt32(packet.m_body, (*byte)(unsafe.Pointer(pend)), r.m_nBytesIn) r.m_nBytesInSent = r.m_nBytesIn @@ -1412,8 +1406,8 @@ func C_SendBytesReceived(r *C.RTMP) int { // int SendConnectPacket(RTMP* r, RTMPPacket* cp); // rtmp.c +1579 -func C_SendConnectPacket(r *C.RTMP, cp *C.RTMPPacket) int { - var packet C.RTMPPacket +func C_SendConnectPacket(r *C_RTMP, cp *C_RTMPPacket) int { + var packet C_RTMPPacket var pbuf [4096]byte pend := (*byte)(unsafe.Pointer(incBytePtr(unsafe.Pointer(&pbuf[0]), int(unsafe.Sizeof(pbuf))))) @@ -1430,32 +1424,32 @@ func C_SendConnectPacket(r *C.RTMP, cp *C.RTMPPacket) int { packet.m_nTimeStamp = 0 packet.m_nInfoField2 = 0 packet.m_hasAbsTimestamp = 0 - packet.m_body = (*C.char)(incBytePtr(unsafe.Pointer(&pbuf[0]), + packet.m_body = (*byte)(incBytePtr(unsafe.Pointer(&pbuf[0]), RTMP_MAX_HEADER_SIZE)) enc = (*byte)(unsafe.Pointer(packet.m_body)) - //enc = (*byte)(unsafe.Pointer(C.AMF_EncodeString((*C.char)(unsafe.Pointer(enc)), - //(*C.char)(unsafe.Pointer(pend)), &av_connect))) + //enc = (*byte)(unsafe.Pointer(C.AMF_EncodeString((*byte)(unsafe.Pointer(enc)), + //(*byte)(unsafe.Pointer(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 = (*byte)(unsafe.Pointer(C.AMF_EncodeNumber((*byte)(unsafe.Pointer(enc)), + //(*byte)(unsafe.Pointer(pend)), float64(r.m_numInvokes)))) enc = C_AMF_EncodeNumber(enc, pend, float64(r.m_numInvokes)) *indxBytePtr(unsafe.Pointer(enc), 0) = AMF_OBJECT enc = (*byte)(unsafe.Pointer(incBytePtr(unsafe.Pointer(enc), 1))) - //enc = (*byte)(unsafe.Pointer(C.AMF_EncodeNamedString((*C.char)( - //unsafe.Pointer(enc)), (*C.char)(unsafe.Pointer(pend)), &av_app, &r.Link.app))) + //enc = (*byte)(unsafe.Pointer(C.AMF_EncodeNamedString((*byte)( + //unsafe.Pointer(enc)), (*byte)(unsafe.Pointer(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 = (*byte)(unsafe.Pointer(C.AMF_EncodeNamedString((*byte)( + //unsafe.Pointer(enc)), (*byte)(unsafe.Pointer(pend)), &av_type, &av_nonprivate))) enc = C_AMF_EncodeNamedString(enc, pend, &av_type, &av_nonprivate) if enc == nil { @@ -1464,16 +1458,16 @@ 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 = (*byte)(unsafe.Pointer(C.AMF_EncodeNamedString((*byte)( + //unsafe.Pointer(enc)), (*byte)(unsafe.Pointer(pend)), &av_flashVer, &r.Link.flashVer))) enc = C_AMF_EncodeNamedString(enc, pend, &av_flashVer, &r.Link.flashVer) if enc == nil { return 0 } } 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 = (*byte)(unsafe.Pointer(C.AMF_EncodeNamedString((*byte)( + // unsafe.Pointer(enc)), (*byte)(unsafe.Pointer(pend)), &av_swfUrl, &r.Link.swfUrl))) enc = C_AMF_EncodeNamedString(enc, pend, &av_swfUrl, &r.Link.swfUrl) if enc == nil { return 0 @@ -1481,8 +1475,8 @@ 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 = (*byte)(unsafe.Pointer(C.AMF_EncodeNamedString((*byte)( + //unsafe.Pointer(enc)), (*byte)(unsafe.Pointer(pend)), &av_tcUrl, &r.Link.tcUrl))) enc = C_AMF_EncodeNamedString(enc, pend, &av_tcUrl, &r.Link.tcUrl) if enc == nil { return 0 @@ -1490,39 +1484,39 @@ 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 = (*byte)(unsafe.Pointer(C.AMF_EncodeNamedBoolean((*byte)( + //unsafe.Pointer(enc)), (*byte)(unsafe.Pointer(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 = (*byte)(unsafe.Pointer(C.AMF_EncodeNamedNumber((*byte)( + //unsafe.Pointer(enc)), (*byte)(unsafe.Pointer(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 = (*byte)(unsafe.Pointer(C.AMF_EncodeNamedNumber((*byte)( + // unsafe.Pointer(enc)), (*byte)(unsafe.Pointer(pend)), &av_audioCodecs, 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 = (*byte)(unsafe.Pointer(C.AMF_EncodeNamedNumber((*byte)( + //unsafe.Pointer(enc)), (*byte)(unsafe.Pointer(pend)), &av_videoCodecs, 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 = (*byte)(unsafe.Pointer(C.AMF_EncodeNamedNumber((*byte)( + // unsafe.Pointer(enc)), (*byte)(unsafe.Pointer(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 = (*byte)(unsafe.Pointer(C.AMF_EncodeNamedString((*byte)( + //unsafe.Pointer(enc)), (*byte)(unsafe.Pointer(pend)), &av_pageUrl, &r.Link.pageUrl))) enc = C_AMF_EncodeNamedString(enc, pend, &av_pageUrl, &r.Link.pageUrl) if enc == nil { return 0 @@ -1531,8 +1525,8 @@ 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 = (*byte)(unsafe.Pointer(C.AMF_EncodeNamedNumber((*byte)( + //unsafe.Pointer(enc)), (*byte)(unsafe.Pointer(pend)), &av_objectEncoding, r.m_fEncoding))) enc = C_AMF_EncodeNamedNumber(enc, pend, &av_objectEncoding, float64(r.m_fEncoding)) if enc == nil { return 0 @@ -1553,14 +1547,14 @@ func C_SendConnectPacket(r *C.RTMP, cp *C.RTMPPacket) int { /* add auth string */ 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 = (*byte)(unsafe.Pointer(C.AMF_EncodeBoolean((*byte)( + // unsafe.Pointer(enc)), (*byte)(unsafe.Pointer(pend)), 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 = (*byte)(unsafe.Pointer(C.AMF_EncodeString((*byte)(unsafe.Pointer(enc)), + //(*byte)(unsafe.Pointer(pend)), &r.Link.auth))) enc = C_AMF_EncodeString(enc, (*byte)(pend), &r.Link.auth) if enc == nil { return 0 @@ -1569,11 +1563,11 @@ func C_SendConnectPacket(r *C.RTMP, cp *C.RTMPPacket) int { if r.Link.extras.o_num != 0 { for i := 0; i < int(r.Link.extras.o_num); i++ { - //enc = (*byte)(unsafe.Pointer(C.AMFProp_Encode((*C.AMFObjectProperty)( + //enc = (*byte)(unsafe.Pointer(C.AMFProp_Encode((*C_AMFObjectProperty)( //incPtr(unsafe.Pointer(&r.Link.extras.o_props), int(unsafe.Sizeof( - //r.Link.extras.o_props)), i)), (*C.char)(unsafe.Pointer(enc)), (*C.char)( + //r.Link.extras.o_props)), i)), (*byte)(unsafe.Pointer(enc)), (*byte)( //unsafe.Pointer(pend))))) - enc = C_AMF_PropEncode((*C.AMFObjectProperty)(incPtr(unsafe.Pointer( + enc = C_AMF_PropEncode((*C_AMFObjectProperty)(incPtr(unsafe.Pointer( &r.Link.extras.o_props), int(unsafe.Sizeof(r.Link.extras.o_props)), i)), enc, pend) @@ -1583,8 +1577,8 @@ func C_SendConnectPacket(r *C.RTMP, cp *C.RTMPPacket) int { } } - packet.m_nBodySize = C.uint32_t(int(uintptr(decBytePtr(unsafe.Pointer(enc), - int(uintptr(unsafe.Pointer(packet.m_body))))))) + packet.m_nBodySize = uint32(uintptr(decBytePtr(unsafe.Pointer(enc), + int(uintptr(unsafe.Pointer(packet.m_body)))))) //return int(C.RTMP_SendPacket(r, &packet, 1)) return C_RTMP_SendPacket(r, &packet, 1) @@ -1592,7 +1586,7 @@ func C_SendConnectPacket(r *C.RTMP, cp *C.RTMPPacket) int { // char* AMFPropEncode(AMFOBjectProperty* prop, char* pBufer, char* pBufEnd); // amf.c +366 -func C_AMF_PropEncode(p *C.AMFObjectProperty, pBuffer *byte, pBufEnd *byte) *byte { +func C_AMF_PropEncode(p *C_AMFObjectProperty, pBuffer *byte, pBufEnd *byte) *byte { if p.p_type == AMF_INVALID { return nil } @@ -1633,13 +1627,13 @@ func C_AMF_PropEncode(p *C.AMFObjectProperty, pBuffer *byte, pBufEnd *byte) *byt pBuffer = (*byte)(incBytePtr(unsafe.Pointer(pBuffer), 1)) case AMF_OBJECT: pBuffer = C_AMF_Encode(&p.p_vu.p_object, pBuffer, pBufEnd) - //pBuffer = (*byte)(unsafe.Pointer(C.AMF_Encode(&p.p_vu.p_object, (*C.char)( - //unsafe.Pointer(pBuffer)), (*C.char)(unsafe.Pointer(pBufEnd))))) + //pBuffer = (*byte)(unsafe.Pointer(C.AMF_Encode(&p.p_vu.p_object, (*byte)( + //unsafe.Pointer(pBuffer)), (*byte)(unsafe.Pointer(pBufEnd))))) case AMF_ECMA_ARRAY: pBuffer = C_AMF_EncodeEcmaArray(&p.p_vu.p_object, pBuffer, pBufEnd) - //pBuffer = (*byte)(unsafe.Pointer(C.AMF_EncodeEcmaArray(&p.p_vu.p_object, (*C.char)(unsafe.Pointer(pBuffer)), (*C.char)(unsafe.Pointer(pBufEnd))))) + //pBuffer = (*byte)(unsafe.Pointer(C.AMF_EncodeEcmaArray(&p.p_vu.p_object, (*byte)(unsafe.Pointer(pBuffer)), (*byte)(unsafe.Pointer(pBufEnd))))) case AMF_STRICT_ARRAY: - //pBuffer = (*byte)(unsafe.Pointer(C.AMF_EncodeArray(&p.p_vu.p_object, (*C.char)(unsafe.Pointer(pBuffer)), (*C.char)(unsafe.Pointer(pBufEnd))))) + //pBuffer = (*byte)(unsafe.Pointer(C.AMF_EncodeArray(&p.p_vu.p_object, (*byte)(unsafe.Pointer(pBuffer)), (*byte)(unsafe.Pointer(pBufEnd))))) pBuffer = C_AMF_EncodeArray(&p.p_vu.p_object, pBuffer, pBufEnd) default: log.Println("C_AMF_PropEncode: invalid type!") @@ -1650,7 +1644,7 @@ func C_AMF_PropEncode(p *C.AMFObjectProperty, pBuffer *byte, pBufEnd *byte) *byt // char* AMF_Encode(AMFObject* obj, char* pBuffer, char* pBufEnd); // amf.c +891 -func C_AMF_Encode(obj *C.AMFObject, pBuffer *byte, pBufEnd *byte) *byte { +func C_AMF_Encode(obj *C_AMFObject, pBuffer *byte, pBufEnd *byte) *byte { if uintptr(unsafe.Pointer(pBuffer))+uintptr(4) >= uintptr(unsafe.Pointer(pBufEnd)) { return nil } @@ -1659,7 +1653,7 @@ func C_AMF_Encode(obj *C.AMFObject, pBuffer *byte, pBufEnd *byte) *byte { pBuffer = (*byte)(incBytePtr(unsafe.Pointer(pBuffer), 1)) for i := 0; i < int(obj.o_num); i++ { - res := C_AMF_PropEncode((*C.AMFObjectProperty)(incPtr(unsafe.Pointer( + res := C_AMF_PropEncode((*C_AMFObjectProperty)(incPtr(unsafe.Pointer( obj.o_props), i, int(unsafe.Sizeof(*obj.o_props)))), pBuffer, pBufEnd) if res == nil { log.Println("C_AMF_Encode: failed to encode property in index") @@ -1680,7 +1674,7 @@ func C_AMF_Encode(obj *C.AMFObject, pBuffer *byte, pBufEnd *byte) *byte { // char* AMF_EncodeEcmaArray(AMFObject* obj, char* pBuffer, char* pBufEnd); // amf.c +924 -func C_AMF_EncodeEcmaArray(obj *C.AMFObject, pBuffer *byte, pBufEnd *byte) *byte { +func C_AMF_EncodeEcmaArray(obj *C_AMFObject, pBuffer *byte, pBufEnd *byte) *byte { if int(uintptr(unsafe.Pointer(pBuffer)))+4 >= int(uintptr(unsafe.Pointer(pBufEnd))) { return nil } @@ -1691,7 +1685,7 @@ func C_AMF_EncodeEcmaArray(obj *C.AMFObject, pBuffer *byte, pBufEnd *byte) *byte pBuffer = C_AMF_EncodeInt32(pBuffer, pBufEnd, int32(obj.o_num)) for i := 0; i < int(obj.o_num); i++ { - res := C_AMF_PropEncode((*C.AMFObjectProperty)(incPtr(unsafe.Pointer( + res := C_AMF_PropEncode((*C_AMFObjectProperty)(incPtr(unsafe.Pointer( obj.o_props), i, int(unsafe.Sizeof(*obj.o_props)))), pBuffer, pBufEnd) if res == nil { log.Println("C_AMF_EncodeEcmaArray: failed to encode property!") @@ -1712,7 +1706,7 @@ func C_AMF_EncodeEcmaArray(obj *C.AMFObject, pBuffer *byte, pBufEnd *byte) *byte // char* AMF_EncodeArray(AMFObject* obj, char* pBuffer, char* pBufEnd); // amf.c +959 -func C_AMF_EncodeArray(obj *C.AMFObject, pBuffer *byte, pBufEnd *byte) *byte { +func C_AMF_EncodeArray(obj *C_AMFObject, pBuffer *byte, pBufEnd *byte) *byte { if int(uintptr(unsafe.Pointer(pBuffer)))+4 >= int(uintptr(unsafe.Pointer(pBufEnd))) { return nil } @@ -1723,7 +1717,7 @@ func C_AMF_EncodeArray(obj *C.AMFObject, pBuffer *byte, pBufEnd *byte) *byte { pBuffer = C_AMF_EncodeInt32(pBuffer, pBufEnd, int32(obj.o_num)) for i := 0; i < int(obj.o_num); i++ { - res := C_AMF_PropEncode((*C.AMFObjectProperty)(incPtr(unsafe.Pointer( + res := C_AMF_PropEncode((*C_AMFObjectProperty)(incPtr(unsafe.Pointer( obj.o_props), i, int(unsafe.Sizeof(*obj.o_props)))), pBuffer, pBufEnd) if res == nil { log.Println("C_AMF_EncodeEcmaArray: failed to encode property!") @@ -1737,24 +1731,24 @@ func C_AMF_EncodeArray(obj *C.AMFObject, pBuffer *byte, pBufEnd *byte) *byte { } // int AMF_DecodeArray(AMFObject *obj, const char *pBuffer, int nSize, int nArrayLen, int bDecodeName); -func C_AMF_DecodeArray(obj *C.AMFObject, pBuffer *byte, nSize, nArrayLen, bDecodeName int32) int32 { +func C_AMF_DecodeArray(obj *C_AMFObject, pBuffer *byte, nSize, nArrayLen, bDecodeName int32) int32 { nOriginalSize := nSize - var bError int32 = FALSE + var bError int32 = 0 obj.o_num = 0 obj.o_props = nil for nArrayLen > 0 { - var prop C.AMFObjectProperty + var prop C_AMFObjectProperty var nRes int32 nArrayLen-- if nSize <= 0 { - bError = TRUE + bError = 1 break } nRes = C_AMFProp_Decode(&prop, pBuffer, nSize, bDecodeName) if nRes == -1 { - bError = TRUE + bError = 1 break } else { nSize -= nRes @@ -1771,12 +1765,12 @@ func C_AMF_DecodeArray(obj *C.AMFObject, pBuffer *byte, nSize, nArrayLen, bDecod // int RTMP_ConnectStream(RTMP* r, int seekTime); // rtmp.c +1099 -func C_RTMP_ConnectStream(r *C.RTMP, seekTime int32) int { - var packet C.RTMPPacket +func C_RTMP_ConnectStream(r *C_RTMP, seekTime int32) int { + var packet C_RTMPPacket memset((*byte)(unsafe.Pointer(&packet)), 0, int(unsafe.Sizeof(packet))) if seekTime > 0 { - r.Link.seekTime = C.int(seekTime) + r.Link.seekTime = int32(seekTime) } r.m_mediaChannel = 0 @@ -1811,7 +1805,7 @@ func C_RTMP_ConnectStream(r *C.RTMP, seekTime int32) int { // int RTMP_ClientPacket() // rtmp.c +1226 // NOTE cases have been commented out that are not currently used by AusOcean -func C_RTMP_ClientPacket(r *C.RTMP, packet *C.RTMPPacket) int32 { +func C_RTMP_ClientPacket(r *C_RTMP, packet *C_RTMPPacket) int32 { var bHasMediaPacket int32 = 0 switch packet.m_packetType { @@ -1874,7 +1868,7 @@ func C_RTMP_ClientPacket(r *C.RTMP, packet *C.RTMPPacket) int32 { // TODO use new logger here // RTMP_Log(RTMP_LOGDEBUG,"%s, flex message, size %u bytes, not fully supported", __FUNCTION__, packet.m_nBodySize); - if C.HandleInvoke(r, (*C.char)(incBytePtr(unsafe.Pointer(packet.m_body), 1)), + if C.HandleInvoke(r, (*byte)(incBytePtr(unsafe.Pointer(packet.m_body), 1)), C.uint(packet.m_nBodySize-1)) == 1 { bHasMediaPacket = 2 } @@ -1917,7 +1911,7 @@ func C_RTMP_ClientPacket(r *C.RTMP, packet *C.RTMPPacket) int32 { switch { case *indxBytePtr(unsafe.Pointer(packet.m_body), int(pos)) == 0x12: - C.HandleMetadata(r, (*C.char)(incBytePtr(unsafe.Pointer(packet.m_body), + C.HandleMetadata(r, (*byte)(incBytePtr(unsafe.Pointer(packet.m_body), int(pos+11))), C.uint(dataSize)) case *indxBytePtr(unsafe.Pointer(packet.m_body), int(pos)) == 8 || *indxBytePtr(unsafe.Pointer(packet.m_body), int(pos)) == 9: @@ -1929,7 +1923,7 @@ func C_RTMP_ClientPacket(r *C.RTMP, packet *C.RTMPPacket) int32 { pos += (11 + dataSize + 4) } if r.m_pausing == 0 { - r.m_mediaStamp = C.uint32_t(nTimeStamp) + r.m_mediaStamp = uint32(nTimeStamp) } bHasMediaPacket = 1 @@ -1946,10 +1940,10 @@ func C_RTMP_ClientPacket(r *C.RTMP, packet *C.RTMPPacket) int32 { // void HandleChangeChunkSize(RTMP* r, const RTMPPacket* packet); // rtmp.c +3345 -func C_HandleChangeChunkSize(r *C.RTMP, packet *C.RTMPPacket) { +func C_HandleChangeChunkSize(r *C_RTMP, packet *C_RTMPPacket) { if packet.m_nBodySize >= 4 { - //r.m_inChunkSize = C.int(C.AMF_DecodeInt32((*C.char)(unsafe.Pointer(packet.m_body)))) - r.m_inChunkSize = C.int(C_AMF_DecodeInt32((*byte)(unsafe.Pointer(packet.m_body)))) + //r.m_inChunkSize = int32(C.AMF_DecodeInt32((*byte)(unsafe.Pointer(packet.m_body)))) + r.m_inChunkSize = int32(C_AMF_DecodeInt32((*byte)(unsafe.Pointer(packet.m_body)))) // TODO use new logger here // RTMP_Log(RTMP_LOGDEBUG, "%s, received: chunk size change to %d", __FUNCTION__, r.m_inChunkSize); } @@ -1957,21 +1951,21 @@ func C_HandleChangeChunkSize(r *C.RTMP, packet *C.RTMPPacket) { // void HandleServerBW(RTMP* r, const RTMPPacket* packet); // rtmp.c +3508 -func C_HandlServerBW(r *C.RTMP, packet *C.RTMPPacket) { - r.m_nServerBW = C.int(C_AMF_DecodeInt32((*byte)(unsafe.Pointer(packet.m_body)))) - //r.m_nServerBW = C.int(C.AMF_DecodeInt32((*C.char)(unsafe.Pointer(packet.m_body)))) +func C_HandlServerBW(r *C_RTMP, packet *C_RTMPPacket) { + r.m_nServerBW = int32(C_AMF_DecodeInt32((*byte)(unsafe.Pointer(packet.m_body)))) + //r.m_nServerBW = int32(C.AMF_DecodeInt32((*byte)(unsafe.Pointer(packet.m_body)))) // TODO use new logger here // RTMP_Log(RTMP_LOGDEBUG, "%s: server BW = %d", __FUNCTION__, r.m_nServerBW); } // void HandleClientBW(RTMP* r, const RTMPPacket* packet); // rtmp.c +3515 -func C_HandleClientBW(r *C.RTMP, packet *C.RTMPPacket) { - r.m_nClientBW = C.int(C_AMF_DecodeInt32((*byte)(unsafe.Pointer(packet.m_body)))) - //r.m_nClientBW = C.int(C.AMF_DecodeInt32((*C.char)(unsafe.Pointer(packet.m_body)))) +func C_HandleClientBW(r *C_RTMP, packet *C_RTMPPacket) { + r.m_nClientBW = int32(C_AMF_DecodeInt32((*byte)(unsafe.Pointer(packet.m_body)))) + //r.m_nClientBW = int32(C.AMF_DecodeInt32((*byte)(unsafe.Pointer(packet.m_body)))) if packet.m_nBodySize > 4 { - r.m_nClientBW2 = (C.uint8_t)(*indxBytePtr(unsafe.Pointer(packet.m_body), 4)) + r.m_nClientBW2 = (uint8)(*indxBytePtr(unsafe.Pointer(packet.m_body), 4)) } else { //r.m_nClientBW2 = -1 r.m_nClientBW2 = 0 @@ -1983,9 +1977,9 @@ func C_HandleClientBW(r *C.RTMP, packet *C.RTMPPacket) { // int HandleInvoke(RTMP* r, const char* body, unsigned int nBodySize); // rtmp.c +2912 -func C_HandleInvoke(r *C.RTMP, body *byte, nBodySize uint32) int32 { - var obj C.AMFObject - var method C.AVal +func C_HandleInvoke(r *C_RTMP, body *byte, nBodySize uint32) int32 { + var obj C_AMFObject + var method C_AVal var txn float64 var ret int32 = 0 var nRes int32 @@ -1997,7 +1991,7 @@ func C_HandleInvoke(r *C.RTMP, body *byte, nBodySize uint32) int32 { return 0 } nRes = C_AMF_Decode(&obj, body, int32(nBodySize), 0) - //nRes = int32(C.AMF_Decode(&obj, (*C.char)(unsafe.Pointer(body)), C.int(nBodySize), 0)) + //nRes = int32(C.AMF_Decode(&obj, (*byte)(unsafe.Pointer(body)), int32(nBodySize), 0)) if nRes < 0 { // TODO use new logger here //RTMP_Log(RTMP_LOGERROR, "%s, error decoding invoke packet", __FUNCTION__); @@ -2015,14 +2009,14 @@ func C_HandleInvoke(r *C.RTMP, body *byte, nBodySize uint32) int32 { switch { case C_AVMATCH(&method, &av__result) != 0: { - var methodInvoked C.AVal + var methodInvoked C_AVal var i int32 for i = 0; i < int32(r.m_numCalls); i++ { - if float64((*(*C.RTMP_METHOD)(incPtr(unsafe.Pointer(r.m_methodCalls), int(i), + if float64((*(*C_RTMP_METHOD)(incPtr(unsafe.Pointer(r.m_methodCalls), int(i), int(unsafe.Sizeof(*r.m_methodCalls))))).num) == txn { - methodInvoked = (*(*C.RTMP_METHOD)(incPtr(unsafe.Pointer(r.m_methodCalls), + methodInvoked = (*(*C_RTMP_METHOD)(incPtr(unsafe.Pointer(r.m_methodCalls), int(i), int(unsafe.Sizeof(*r.m_methodCalls))))).name - //C.AV_erase(r.m_methodCalls, &r.m_numCalls, C.int(i), 0) + //C.AV_erase(r.m_methodCalls, &r.m_numCalls, int32(i), 0) C_AV_erase(r.m_methodCalls, (*int32)(&r.m_numCalls), int32(i), 0) break } @@ -2043,7 +2037,7 @@ func C_HandleInvoke(r *C.RTMP, body *byte, nBodySize uint32) int32 { TODO port this eventually if r.Link.token.av_len != 0 { log.Println("2.1") - var p C.AMFObjectProperty + var p C_AMFObjectProperty if C.RTMP_FindFirstMatchingProperty(&obj, &av_secureToken, &p) != 0 { log.Println("2.2") C.DecodeTEA(&r.Link.token, &p.p_vu.p_aval) @@ -2088,7 +2082,7 @@ func C_HandleInvoke(r *C.RTMP, body *byte, nBodySize uint32) int32 { } case C_AVMATCH(&methodInvoked, &av_createStream) != 0: { - r.m_stream_id = C.int(C_AMFProp_GetNumber(C_AMF_GetProp(&obj, nil, 3))) + r.m_stream_id = int32(C_AMFProp_GetNumber(C_AMF_GetProp(&obj, nil, 3))) if (r.Link.protocol & RTMP_FEATURE_WRITE) != 0 { C_SendPublish(r) @@ -2132,21 +2126,21 @@ func C_HandleInvoke(r *C.RTMP, body *byte, nBodySize uint32) int32 { case C_AVMATCH(&method, &av_ping) != 0: { log.Println("9") - C.SendPong(r, C.double(txn)) + C.SendPong(r, float64(txn)) } case C_AVMATCH(&method, &av__onbwcheck) != 0: { log.Println("10") - C.SendCheckBWResult(r, C.double(txn)) + C.SendCheckBWResult(r, float64(txn)) } case C_AVMATCH(&method, &av__onbwdone) != 0: { log.Println("11") var i int32 for i = 0; i < int32(r.m_numCalls); i++ { - if C_AVMATCH(&(*(*C.RTMP_METHOD)(incPtr(unsafe.Pointer(r.m_methodCalls), int(i), + if C_AVMATCH(&(*(*C_RTMP_METHOD)(incPtr(unsafe.Pointer(r.m_methodCalls), int(i), int(unsafe.Sizeof(*r.m_methodCalls))))).name, &av__checkbw) != 0 { - C.AV_erase(r.m_methodCalls, &r.m_numCalls, C.int(i), 1) + C.AV_erase(r.m_methodCalls, &r.m_numCalls, int32(i), 1) break } } @@ -2161,8 +2155,8 @@ func C_HandleInvoke(r *C.RTMP, body *byte, nBodySize uint32) int32 { */ case C_AVMATCH(&method, &av_onStatus) != 0: { - var obj2 C.AMFObject - var code, level C.AVal + var obj2 C_AMFObject + var code, level C_AVal C_AMFProp_GetObject(C_AMF_GetProp(&obj, nil, 3), &obj2) C_AMFProp_GetString(C_AMF_GetProp(&obj2, &av_code, -1), &code) C_AMFProp_GetString(C_AMF_GetProp(&obj2, &av_level, -1), &level) @@ -2189,10 +2183,10 @@ func C_HandleInvoke(r *C.RTMP, body *byte, nBodySize uint32) int32 { var i int32 r.m_bPlaying = 1 for i = 0; i < int32(r.m_numCalls); i++ { - if C_AVMATCH(&(*(*C.RTMP_METHOD)(incPtr(unsafe.Pointer(r.m_methodCalls), int(i), + if C_AVMATCH(&(*(*C_RTMP_METHOD)(incPtr(unsafe.Pointer(r.m_methodCalls), int(i), int(unsafe.Sizeof(*r.m_methodCalls))))).name, &av_play) != 0 { log.Println("15.1") - C.AV_erase(r.m_methodCalls, &r.m_numCalls, C.int(i), 1) + C.AV_erase(r.m_methodCalls, &r.m_numCalls, int32(i), 1) break } } @@ -2203,9 +2197,9 @@ func C_HandleInvoke(r *C.RTMP, body *byte, nBodySize uint32) int32 { var i int32 r.m_bPlaying = 1 for i = 0; i < int32(r.m_numCalls); i++ { - if C_AVMATCH(&(*(*C.RTMP_METHOD)(incPtr(unsafe.Pointer(r.m_methodCalls), int(i), + if C_AVMATCH(&(*(*C_RTMP_METHOD)(incPtr(unsafe.Pointer(r.m_methodCalls), int(i), int(unsafe.Sizeof(*r.m_methodCalls))))).name, &av_publish) != 0 { - //C.AV_erase(r.m_methodCalls, &r.m_numCalls, C.int(i), 1) + //C.AV_erase(r.m_methodCalls, &r.m_numCalls, int32(i), 1) C_AV_erase(r.m_methodCalls, (*int32)(&r.m_numCalls), int32(i), 1) break } @@ -2224,13 +2218,13 @@ func C_HandleInvoke(r *C.RTMP, body *byte, nBodySize uint32) int32 { { log.Println("18") // NOTE ~ has been replace by ^ - is this correct ? - r.m_read.flags = C.uint8_t(int8(r.m_read.flags) & ^RTMP_READ_SEEKING) + r.m_read.flags = uint8(int8(r.m_read.flags) & ^RTMP_READ_SEEKING) } case C_AVMATCH(&code, &av_NetStream_Pause_Notify) != 0: { log.Println("19") if r.m_pausing == 1 || r.m_pausing == 2 { - C.RTMP_SendPause(r, 0, C.int(r.m_pauseStamp)) + C.RTMP_SendPause(r, 0, int32(r.m_pauseStamp)) r.m_pausing = 3 } } @@ -2243,9 +2237,9 @@ func C_HandleInvoke(r *C.RTMP, body *byte, nBodySize uint32) int32 { log.Println("19") var i int32 for i = 0; i < int32(r.m_numCalls); i++ { - if C_AVMATCH(&(*(*C.RTMP_METHOD)(incPtr(unsafe.Pointer(r.m_methodCalls), int(i), + if C_AVMATCH(&(*(*C_RTMP_METHOD)(incPtr(unsafe.Pointer(r.m_methodCalls), int(i), int(unsafe.Sizeof(*r.m_methodCalls))))).name, &av_set_playlist) != 0 { - C.AV_erase(r.m_methodCalls, &r.m_numCalls, C.int(i), 1) + C.AV_erase(r.m_methodCalls, &r.m_numCalls, int32(i), 1) break } } @@ -2261,10 +2255,10 @@ leave: // void AMF_Reset(AMFObject* obj); // amf.c +1282 -func C_AMF_Reset(obj *C.AMFObject) { +func C_AMF_Reset(obj *C_AMFObject) { var n int32 for n = 0; n < int32(obj.o_num); n++ { - C_AMFProp_Reset(&(*(*C.AMFObjectProperty)(incPtr(unsafe.Pointer(obj.o_props), + C_AMFProp_Reset(&(*(*C_AMFObjectProperty)(incPtr(unsafe.Pointer(obj.o_props), int(n), int(unsafe.Sizeof(*obj.o_props)))))) } C.free(unsafe.Pointer(obj.o_props)) @@ -2274,7 +2268,7 @@ func C_AMF_Reset(obj *C.AMFObject) { // void AMFProp_Reset(AMFObjectProperty* prop); // amf.c +875 -func C_AMFProp_Reset(prop *C.AMFObjectProperty) { +func C_AMFProp_Reset(prop *C_AMFObjectProperty) { if prop.p_type == AMF_OBJECT || prop.p_type == AMF_ECMA_ARRAY || prop.p_type == AMF_STRICT_ARRAY { C_AMF_Reset(&prop.p_vu.p_object) @@ -2287,8 +2281,8 @@ func C_AMFProp_Reset(prop *C.AMFObjectProperty) { // int SendReleaseStream(RTMP* r); // rtmp.c +1816 -func C_SendReleaseStream(r *C.RTMP) int32 { - var packet C.RTMPPacket +func C_SendReleaseStream(r *C_RTMP) int32 { + var packet C_RTMPPacket var pbuf [1024]byte var pend *byte = (*byte)(unsafe.Pointer(uintptr(unsafe.Pointer(&pbuf[0])) + unsafe.Sizeof(pbuf))) @@ -2300,7 +2294,7 @@ func C_SendReleaseStream(r *C.RTMP) int32 { packet.m_nTimeStamp = 0 packet.m_nInfoField2 = 0 packet.m_hasAbsTimestamp = 0 - packet.m_body = (*C.char)(incBytePtr(unsafe.Pointer(&pbuf[0]), + packet.m_body = (*byte)(incBytePtr(unsafe.Pointer(&pbuf[0]), int(RTMP_MAX_HEADER_SIZE))) enc = (*byte)(unsafe.Pointer(packet.m_body)) @@ -2313,7 +2307,7 @@ func C_SendReleaseStream(r *C.RTMP) int32 { if enc == nil { return 0 } - packet.m_nBodySize = C.uint32_t(uintptr(unsafe.Pointer(enc)) - uintptr( + packet.m_nBodySize = uint32(uintptr(unsafe.Pointer(enc)) - uintptr( unsafe.Pointer(packet.m_body))) return int32(C_RTMP_SendPacket(r, &packet, 0)) @@ -2321,8 +2315,8 @@ func C_SendReleaseStream(r *C.RTMP) int32 { // int SendFCPublish(RTMP* r); // rtmp.c +1846 -func C_SendFCPublish(r *C.RTMP) int32 { - var packet C.RTMPPacket +func C_SendFCPublish(r *C_RTMP) int32 { + var packet C_RTMPPacket var pbuf [1024]byte var pend *byte = (*byte)(unsafe.Pointer(uintptr(unsafe.Pointer(&pbuf[0])) + unsafe.Sizeof(pbuf))) @@ -2334,7 +2328,7 @@ func C_SendFCPublish(r *C.RTMP) int32 { packet.m_nTimeStamp = 0 packet.m_nInfoField2 = 0 packet.m_hasAbsTimestamp = 0 - packet.m_body = (*C.char)(incBytePtr(unsafe.Pointer(&pbuf[0]), + packet.m_body = (*byte)(incBytePtr(unsafe.Pointer(&pbuf[0]), int(RTMP_MAX_HEADER_SIZE))) enc = (*byte)(unsafe.Pointer(packet.m_body)) @@ -2347,7 +2341,7 @@ func C_SendFCPublish(r *C.RTMP) int32 { if enc == nil { return 0 } - packet.m_nBodySize = C.uint32_t(uintptr(unsafe.Pointer(enc)) - uintptr( + packet.m_nBodySize = uint32(uintptr(unsafe.Pointer(enc)) - uintptr( unsafe.Pointer(packet.m_body))) return int32(C_RTMP_SendPacket(r, &packet, 0)) @@ -2355,8 +2349,8 @@ func C_SendFCPublish(r *C.RTMP) int32 { // int RTMP_SendCreateStream(RTMP* r); // rtmp.c +1725 -func C_RTMP_SendCreateStream(r *C.RTMP) int32 { - var packet C.RTMPPacket +func C_RTMP_SendCreateStream(r *C_RTMP) int32 { + var packet C_RTMPPacket var pbuf [256]byte var pend *byte = (*byte)(unsafe.Pointer(uintptr(unsafe.Pointer(&pbuf[0])) + unsafe.Sizeof(pbuf))) @@ -2368,7 +2362,7 @@ func C_RTMP_SendCreateStream(r *C.RTMP) int32 { packet.m_nTimeStamp = 0 packet.m_nInfoField2 = 0 packet.m_hasAbsTimestamp = 0 - packet.m_body = (*C.char)(incBytePtr(unsafe.Pointer(&pbuf[0]), + packet.m_body = (*byte)(incBytePtr(unsafe.Pointer(&pbuf[0]), int(RTMP_MAX_HEADER_SIZE))) enc = (*byte)(unsafe.Pointer(packet.m_body)) @@ -2378,7 +2372,7 @@ func C_RTMP_SendCreateStream(r *C.RTMP) int32 { *enc = AMF_NULL enc = (*byte)(incBytePtr(unsafe.Pointer(enc), 1)) - packet.m_nBodySize = C.uint32_t(uintptr(unsafe.Pointer(enc)) - uintptr( + packet.m_nBodySize = uint32(uintptr(unsafe.Pointer(enc)) - uintptr( unsafe.Pointer(packet.m_body))) return int32(C_RTMP_SendPacket(r, &packet, 1)) @@ -2386,8 +2380,8 @@ func C_RTMP_SendCreateStream(r *C.RTMP) int32 { // int SendPublish(RTMP* r); // rtmp.c +1908 -func C_SendPublish(r *C.RTMP) int32 { - var packet C.RTMPPacket +func C_SendPublish(r *C_RTMP) int32 { + var packet C_RTMPPacket var pbuf [1024]byte var pend *byte = (*byte)(unsafe.Pointer(uintptr(unsafe.Pointer(&pbuf[0])) + unsafe.Sizeof(pbuf))) @@ -2397,9 +2391,9 @@ func C_SendPublish(r *C.RTMP) int32 { packet.m_headerType = RTMP_PACKET_SIZE_LARGE packet.m_packetType = RTMP_PACKET_TYPE_INVOKE packet.m_nTimeStamp = 0 - packet.m_nInfoField2 = C.int32_t(r.m_stream_id) + packet.m_nInfoField2 = int32(r.m_stream_id) packet.m_hasAbsTimestamp = 0 - packet.m_body = (*C.char)(incBytePtr(unsafe.Pointer(&pbuf[0]), + packet.m_body = (*byte)(incBytePtr(unsafe.Pointer(&pbuf[0]), int(RTMP_MAX_HEADER_SIZE))) enc = (*byte)(unsafe.Pointer(packet.m_body)) @@ -2419,7 +2413,7 @@ func C_SendPublish(r *C.RTMP) int32 { return 0 } - packet.m_nBodySize = C.uint32_t(uintptr(unsafe.Pointer(enc)) - uintptr( + packet.m_nBodySize = uint32(uintptr(unsafe.Pointer(enc)) - uintptr( unsafe.Pointer(packet.m_body))) return int32(C_RTMP_SendPacket(r, &packet, 1)) @@ -2427,8 +2421,8 @@ func C_SendPublish(r *C.RTMP) int32 { // int SendCheckBW(RTMP* r); // rtmp.c +2105 -func C_SendCheckBW(r *C.RTMP) int32 { - var packet C.RTMPPacket +func C_SendCheckBW(r *C_RTMP) int32 { + var packet C_RTMPPacket var pbuf [256]byte var pend *byte = (*byte)(unsafe.Pointer(uintptr(unsafe.Pointer(&pbuf[0])) + unsafe.Sizeof(pbuf))) @@ -2440,7 +2434,7 @@ func C_SendCheckBW(r *C.RTMP) int32 { packet.m_nTimeStamp = 0 packet.m_nInfoField2 = 0 packet.m_hasAbsTimestamp = 0 - packet.m_body = (*C.char)(incBytePtr(unsafe.Pointer(&pbuf[0]), + packet.m_body = (*byte)(incBytePtr(unsafe.Pointer(&pbuf[0]), int(RTMP_MAX_HEADER_SIZE))) enc = (*byte)(unsafe.Pointer(packet.m_body)) @@ -2450,7 +2444,7 @@ func C_SendCheckBW(r *C.RTMP) int32 { *enc = AMF_NULL enc = (*byte)(incBytePtr(unsafe.Pointer(enc), 1)) - packet.m_nBodySize = C.uint32_t(uintptr(unsafe.Pointer(enc)) - uintptr( + packet.m_nBodySize = uint32(uintptr(unsafe.Pointer(enc)) - uintptr( unsafe.Pointer(packet.m_body))) return int32(C_RTMP_SendPacket(r, &packet, 0)) @@ -2458,7 +2452,7 @@ func C_SendCheckBW(r *C.RTMP) int32 { // #define AVMATCH(a1,a2) // amf.h +63 -func C_AVMATCH(a1, a2 *C.AVal) int32 { +func C_AVMATCH(a1, a2 *C_AVal) int32 { if a1.av_len == a2.av_len && memcmp(unsafe.Pointer(a1.av_val), unsafe.Pointer(a2.av_val), int(a1.av_len)) == 0 { return 1 @@ -2469,7 +2463,7 @@ func C_AVMATCH(a1, a2 *C.AVal) int32 { // void AMFProp_GetString(AMFObjectProperty* prop, AVal* str); // amf.c -func C_AMFProp_GetString(prop *C.AMFObjectProperty, str *C.AVal) { +func C_AMFProp_GetString(prop *C_AMFObjectProperty, str *C_AVal) { if prop.p_type == AMF_STRING { *str = prop.p_vu.p_aval } else { @@ -2479,7 +2473,7 @@ func C_AMFProp_GetString(prop *C.AMFObjectProperty, str *C.AVal) { // void AMFProp_GetObject(AMFObjectProperty *prop, AMFObject *obj); // amf.c +351 -func C_AMFProp_GetObject(prop *C.AMFObjectProperty, obj *C.AMFObject) { +func C_AMFProp_GetObject(prop *C_AMFObjectProperty, obj *C_AMFObject) { if prop.p_type == AMF_OBJECT { *obj = prop.p_vu.p_object } else { @@ -2489,56 +2483,56 @@ func C_AMFProp_GetObject(prop *C.AMFObjectProperty, obj *C.AMFObject) { // AMFObjectProperty* AMF_GetProp(AMFObject *obj, const AVal* name, int nIndex); // amf.c + 1249 -func C_AMF_GetProp(obj *C.AMFObject, name *C.AVal, nIndex int32) *C.AMFObjectProperty { +func C_AMF_GetProp(obj *C_AMFObject, name *C_AVal, nIndex int32) *C_AMFObjectProperty { if nIndex >= 0 { if nIndex < int32(obj.o_num) { - return &(*(*C.AMFObjectProperty)(incPtr(unsafe.Pointer(obj.o_props), + return &(*(*C_AMFObjectProperty)(incPtr(unsafe.Pointer(obj.o_props), int(nIndex), int(unsafe.Sizeof(*obj.o_props))))) //return &obj.o_props[nIndex] } } else { var n int32 for n = 0; n < int32(obj.o_num); n++ { - if C_AVMATCH(&(*(*C.AMFObjectProperty)(incPtr(unsafe.Pointer(obj.o_props), + if C_AVMATCH(&(*(*C_AMFObjectProperty)(incPtr(unsafe.Pointer(obj.o_props), int(n), int(unsafe.Sizeof(*obj.o_props))))).p_name, name) != 0 { - return &(*(*C.AMFObjectProperty)(incPtr(unsafe.Pointer(obj.o_props), + return &(*(*C_AMFObjectProperty)(incPtr(unsafe.Pointer(obj.o_props), int(n), int(unsafe.Sizeof(*obj.o_props))))) } } } - return (*C.AMFObjectProperty)(&AMFProp_Invalid) + return (*C_AMFObjectProperty)(&AMFProp_Invalid) } // double AMFProp_GetNumber(AMFObjectProperty* prop); // amf.c +330 -func C_AMFProp_GetNumber(prop *C.AMFObjectProperty) float64 { +func C_AMFProp_GetNumber(prop *C_AMFObjectProperty) float64 { return float64(prop.p_vu.p_number) } -// void AV_erase(C.RTMP_METHOD* vals, int* num, int i, int freeit); +// void AV_erase(C_RTMP_METHOD* vals, int* num, int i, int freeit); // rtmp.c +2393 -func C_AV_erase(vals *C.RTMP_METHOD, num *int32, i, freeit int32) { +func C_AV_erase(vals *C_RTMP_METHOD, num *int32, i, freeit int32) { if freeit != 0 { - C.free(unsafe.Pointer((*(*C.RTMP_METHOD)(incPtr(unsafe.Pointer(vals), int(i), + C.free(unsafe.Pointer((*(*C_RTMP_METHOD)(incPtr(unsafe.Pointer(vals), int(i), int(unsafe.Sizeof(*vals))))).name.av_val)) } (*num)-- for ; i < *num; i++ { - *(*C.RTMP_METHOD)(incPtr(unsafe.Pointer(vals), int(i), - int(unsafe.Sizeof(*vals)))) = *(*C.RTMP_METHOD)(incPtr( + *(*C_RTMP_METHOD)(incPtr(unsafe.Pointer(vals), int(i), + int(unsafe.Sizeof(*vals)))) = *(*C_RTMP_METHOD)(incPtr( unsafe.Pointer(vals), int(i+1), int(unsafe.Sizeof(*vals)))) } - (*(*C.RTMP_METHOD)(incPtr(unsafe.Pointer(vals), int(i), + (*(*C_RTMP_METHOD)(incPtr(unsafe.Pointer(vals), int(i), int(unsafe.Sizeof(*vals))))).name.av_val = nil - (*(*C.RTMP_METHOD)(incPtr(unsafe.Pointer(vals), int(i), + (*(*C_RTMP_METHOD)(incPtr(unsafe.Pointer(vals), int(i), int(unsafe.Sizeof(*vals))))).name.av_len = 0 - (*(*C.RTMP_METHOD)(incPtr(unsafe.Pointer(vals), int(i), + (*(*C_RTMP_METHOD)(incPtr(unsafe.Pointer(vals), int(i), int(unsafe.Sizeof(*vals))))).num = 0 } // void RTMPPacket_Free(RTMPPacket* p); // rtmp.c +203 -func C_RTMPPacket_Free(p *C.RTMPPacket) { +func C_RTMPPacket_Free(p *C_RTMPPacket) { if p.m_body != nil { C.free(decBytePtr(unsafe.Pointer(p.m_body), RTMP_MAX_HEADER_SIZE)) p.m_body = nil @@ -2547,7 +2541,7 @@ func C_RTMPPacket_Free(p *C.RTMPPacket) { // int RTMP_ReadPacket(RTMP* r, RTMPPacket* packet); // rtmp.c +3550 -func C_RTMP_ReadPacket(r *C.RTMP, packet *C.RTMPPacket) int32 { +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) var header *byte @@ -2560,8 +2554,8 @@ func C_RTMP_ReadPacket(r *C.RTMP, packet *C.RTMPPacket) int32 { return 0 } - packet.m_headerType = C.uint8_t((hbuf[0] & 0xc0) >> 6) - packet.m_nChannel = C.int(hbuf[0] & 0x3f) + packet.m_headerType = uint8((hbuf[0] & 0xc0) >> 6) + packet.m_nChannel = int32(hbuf[0] & 0x3f) header = (*byte)(incBytePtr(unsafe.Pointer(header), 1)) switch { @@ -2571,7 +2565,7 @@ func C_RTMP_ReadPacket(r *C.RTMP, packet *C.RTMPPacket) int32 { return 0 } - packet.m_nChannel = C.int(hbuf[1]) + packet.m_nChannel = int32(hbuf[1]) packet.m_nChannel += 64 header = (*byte)(incBytePtr(unsafe.Pointer(header), 1)) case packet.m_nChannel == 1: @@ -2583,7 +2577,7 @@ func C_RTMP_ReadPacket(r *C.RTMP, packet *C.RTMPPacket) int32 { } tmp = int32((hbuf[2] << 8) + hbuf[1]) - packet.m_nChannel = C.int(tmp + 64) + packet.m_nChannel = int32(tmp + 64) header = (*byte)(incBytePtr(unsafe.Pointer(header), 2)) } @@ -2594,8 +2588,8 @@ func C_RTMP_ReadPacket(r *C.RTMP, packet *C.RTMPPacket) int32 { 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), + var packetPtr *C_RTMPPacket + packets := (**C_RTMPPacket)(C.realloc(unsafe.Pointer(r.m_vecChannelsIn), C.size_t(int32(unsafe.Sizeof(packetPtr))*n))) if timestamp == nil { C.free(unsafe.Pointer(r.m_channelTimestamp)) @@ -2605,7 +2599,7 @@ func C_RTMP_ReadPacket(r *C.RTMP, packet *C.RTMPPacket) int32 { C.free(unsafe.Pointer(r.m_vecChannelsIn)) } - r.m_channelTimestamp = (*C.int)(timestamp) + r.m_channelTimestamp = (*int32)(timestamp) r.m_vecChannelsIn = packets if timestamp == nil || packets == nil { @@ -2619,19 +2613,19 @@ func C_RTMP_ReadPacket(r *C.RTMP, packet *C.RTMPPacket) int32 { 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 = C.int(n) + r.m_channelsAllocatedIn = int32(n) } switch { case nSize == RTMP_LARGE_HEADER_SIZE: packet.m_hasAbsTimestamp = 1 case nSize < RTMP_LARGE_HEADER_SIZE: - var tmpPacketPtr *C.RTMPPacket - if *(**C.RTMPPacket)(incPtr(unsafe.Pointer(r.m_vecChannelsIn), + var tmpPacketPtr *C_RTMPPacket + if *(**C_RTMPPacket)(incPtr(unsafe.Pointer(r.m_vecChannelsIn), int(packet.m_nChannel), int(unsafe.Sizeof(tmpPacketPtr)))) != nil { - var tmpPacket C.RTMPPacket + var tmpPacket C_RTMPPacket memmove(unsafe.Pointer(packet), unsafe.Pointer( - *(**C.RTMPPacket)(incPtr(unsafe.Pointer(r.m_vecChannelsIn), + *(**C_RTMPPacket)(incPtr(unsafe.Pointer(r.m_vecChannelsIn), int(packet.m_nChannel), int(unsafe.Sizeof(tmpPacketPtr))))), unsafe.Sizeof(tmpPacket)) } @@ -2648,21 +2642,21 @@ 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_AMF_DecodeInt24(header)) + packet.m_nTimeStamp = uint32(C_AMF_DecodeInt24(header)) if nSize >= 6 { - packet.m_nBodySize = C.uint32_t(C_AMF_DecodeInt24((*byte)(incBytePtr( + packet.m_nBodySize = uint32(C_AMF_DecodeInt24((*byte)(incBytePtr( unsafe.Pointer(header), 3)))) packet.m_nBytesRead = 0 if nSize > 6 { - packet.m_packetType = C.uint8_t(*indxBytePtr(unsafe.Pointer(header), 6)) + packet.m_packetType = uint8(*indxBytePtr(unsafe.Pointer(header), 6)) if nSize == 11 { // TODO: port this - packet.m_nInfoField2 = C.int32_t(C_DecodeInt32LE((*byte)(incBytePtr( + packet.m_nInfoField2 = int32(C_DecodeInt32LE((*byte)(incBytePtr( unsafe.Pointer(header), 7)))) - //packet.m_nInfoField2 = C.int32_t(C.DecodeInt32LE((*C.char)(incBytePtr( + //packet.m_nInfoField2 = int32(C.DecodeInt32LE((*byte)(incBytePtr( //unsafe.Pointer(header), 7)))) } } @@ -2679,9 +2673,9 @@ func C_RTMP_ReadPacket(r *C.RTMP, packet *C.RTMPPacket) int32 { return 0 } // TODO: port this - packet.m_nTimeStamp = C.uint32_t(C_AMF_DecodeInt32((*byte)(incBytePtr( + packet.m_nTimeStamp = uint32(C_AMF_DecodeInt32((*byte)(incBytePtr( unsafe.Pointer(header), int(nSize))))) - //packet.m_nTimeStamp = C.uint32_t(C.AMF_DecodeInt32((*C.char)(incBytePtr( + //packet.m_nTimeStamp = uint32(C.AMF_DecodeInt32((*byte)(incBytePtr( //unsafe.Pointer(header), int(nSize))))) hSize += 4 } @@ -2692,7 +2686,7 @@ func C_RTMP_ReadPacket(r *C.RTMP, packet *C.RTMPPacket) int32 { log.Println("RTMPRead_Packet: failed to allocate packet") return 0 } - packet.m_headerType = C.uint8_t((hbuf[0] & 0xc0) >> 6) + packet.m_headerType = uint8((hbuf[0] & 0xc0) >> 6) } nToRead = int32(packet.m_nBodySize - packet.m_nBytesRead) @@ -2703,12 +2697,12 @@ func C_RTMP_ReadPacket(r *C.RTMP, packet *C.RTMPPacket) int32 { } if packet.m_chunk != nil { - packet.m_chunk.c_headerSize = C.int(hSize) + packet.m_chunk.c_headerSize = int32(hSize) memmove(unsafe.Pointer(&packet.m_chunk.c_header[0]), unsafe.Pointer(&hbuf[0]), uintptr(hSize)) - packet.m_chunk.c_chunk = (*C.char)(incBytePtr(unsafe.Pointer(packet.m_body), + packet.m_chunk.c_chunk = (*byte)(incBytePtr(unsafe.Pointer(packet.m_body), int(packet.m_nBytesRead))) - packet.m_chunk.c_chunkSize = C.int(nChunk) + packet.m_chunk.c_chunkSize = int32(nChunk) } if C_ReadN(r, (*byte)(incBytePtr(unsafe.Pointer(packet.m_body), int(packet.m_nBytesRead))), @@ -2717,24 +2711,24 @@ func C_RTMP_ReadPacket(r *C.RTMP, packet *C.RTMPPacket) int32 { return 0 } - packet.m_nBytesRead += C.uint32_t(nChunk) + packet.m_nBytesRead += uint32(nChunk) - var tmpPktPtr *C.RTMPPacket + var tmpPktPtr *C_RTMPPacket // keep the packet as ref for other packets on this channel - if *(**C.RTMPPacket)(incPtr(unsafe.Pointer(r.m_vecChannelsIn), + 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( + 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)))) } - memmove(unsafe.Pointer(*(**C.RTMPPacket)(incPtr(unsafe.Pointer( + memmove(unsafe.Pointer(*(**C_RTMPPacket)(incPtr(unsafe.Pointer( r.m_vecChannelsIn), int(packet.m_nChannel), int(unsafe.Sizeof(tmpPktPtr))))), unsafe.Pointer(packet), unsafe.Sizeof(tmpPktPtr)) if extendedTimestamp != 0 { - (*(**C.RTMPPacket)(incPtr(unsafe.Pointer( + (*(**C_RTMPPacket)(incPtr(unsafe.Pointer( r.m_vecChannelsIn), int(packet.m_nChannel), int(unsafe.Sizeof(tmpPktPtr))))).m_nTimeStamp = 0xffffff } @@ -2743,17 +2737,17 @@ func C_RTMP_ReadPacket(r *C.RTMP, packet *C.RTMPPacket) int32 { if C_RTMPPacket_IsReady(packet) != 0 { if packet.m_hasAbsTimestamp == 0 { // timestamps seem to always be relative - packet.m_nTimeStamp += *(*C.uint32_t)(incPtr(unsafe.Pointer(r.m_channelTimestamp), + packet.m_nTimeStamp += *(*uint32)(incPtr(unsafe.Pointer(r.m_channelTimestamp), int(packet.m_nChannel), 4)) } - *(*C.uint32_t)(incPtr(unsafe.Pointer(r.m_channelTimestamp), int(packet.m_nChannel), + *(*uint32)(incPtr(unsafe.Pointer(r.m_channelTimestamp), int(packet.m_nChannel), 4)) = packet.m_nTimeStamp - (*(**C.RTMPPacket)(incPtr(unsafe.Pointer(r.m_vecChannelsIn), int(packet.m_nChannel), + (*(**C_RTMPPacket)(incPtr(unsafe.Pointer(r.m_vecChannelsIn), int(packet.m_nChannel), int(unsafe.Sizeof(*r.m_vecChannelsIn))))).m_body = nil - (*(**C.RTMPPacket)(incPtr(unsafe.Pointer(r.m_vecChannelsIn), int(packet.m_nChannel), + (*(**C_RTMPPacket)(incPtr(unsafe.Pointer(r.m_vecChannelsIn), int(packet.m_nChannel), int(unsafe.Sizeof(*r.m_vecChannelsIn))))).m_nBytesRead = 0 - (*(**C.RTMPPacket)(incPtr(unsafe.Pointer(r.m_vecChannelsIn), int(packet.m_nChannel), + (*(**C_RTMPPacket)(incPtr(unsafe.Pointer(r.m_vecChannelsIn), int(packet.m_nChannel), int(unsafe.Sizeof(*r.m_vecChannelsIn))))).m_hasAbsTimestamp = 0 } else { packet.m_body = nil /* so it won't be erased on free */ @@ -2763,7 +2757,7 @@ func C_RTMP_ReadPacket(r *C.RTMP, packet *C.RTMPPacket) int32 { // 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 { +func C_AMF_Decode(obj *C_AMFObject, pBuffer *byte, nSize int32, bDecodeName int32) int32 { var nOriginalSize int32 = nSize var bError int32 = 0 @@ -2771,7 +2765,7 @@ func C_AMF_Decode(obj *C.AMFObject, pBuffer *byte, nSize int32, bDecodeName int3 obj.o_props = nil for nSize > 0 { - var prop C.AMFObjectProperty + var prop C_AMFObjectProperty var nRes int32 if nSize >= 3 && C_AMF_DecodeInt24(pBuffer) == C.AMF_OBJECT_END { @@ -2790,8 +2784,8 @@ func C_AMF_Decode(obj *C.AMFObject, pBuffer *byte, nSize int32, bDecodeName int3 // TODO port AMFProp_Decode nRes = int32(C_AMFProp_Decode(&prop, (*byte)(unsafe.Pointer(pBuffer)), int32(nSize), int32(bDecodeName))) - // nRes = int32(C.AMFProp_Decode(&prop, (*C.char)(unsafe.Pointer(pBuffer)), - // C.int(nSize), C.int(bDecodeName))) + // nRes = int32(C.AMFProp_Decode(&prop, (*byte)(unsafe.Pointer(pBuffer)), + // int32(nSize), int32(bDecodeName))) if nRes == -1 { bError = 1 break @@ -2813,9 +2807,9 @@ func C_AMF_Decode(obj *C.AMFObject, pBuffer *byte, nSize int32, bDecodeName int3 return nOriginalSize - nSize } -// int AMFProp_Decode(C.AMFOBjectProperty* prop, const char* pBuffer, int nSize, int bDecodeName); +// int AMFProp_Decode(C_AMFObjectProperty* prop, const char* pBuffer, int nSize, int bDecodeName); // amf.c +619 -func C_AMFProp_Decode(prop *C.AMFObjectProperty, pBuffer *byte, nSize, bDecodeName int32) int32 { +func C_AMFProp_Decode(prop *C_AMFObjectProperty, pBuffer *byte, nSize, bDecodeName int32) int32 { var nOriginalSize int32 = nSize var nRes int32 @@ -2855,7 +2849,7 @@ func C_AMFProp_Decode(prop *C.AMFObjectProperty, pBuffer *byte, nSize, bDecodeNa nSize-- - prop.p_type = (C.AMFDataType)(int32(*pBuffer)) + prop.p_type = (C_AMFDataType)(int32(*pBuffer)) pBuffer = (*byte)(incBytePtr(unsafe.Pointer(pBuffer), 1)) switch prop.p_type { @@ -2864,7 +2858,7 @@ func C_AMFProp_Decode(prop *C.AMFObjectProperty, pBuffer *byte, nSize, bDecodeNa if nSize < 8 { return -1 } - prop.p_vu.p_number = C.double(C_AMF_DecodeNumber(pBuffer)) + prop.p_vu.p_number = float64(C_AMF_DecodeNumber(pBuffer)) nSize -= 8 /* @@ -2873,7 +2867,7 @@ func C_AMFProp_Decode(prop *C.AMFObjectProperty, pBuffer *byte, nSize, bDecodeNa if nSize < 1 { return -1 } - prop.p_vu.p_number = C.double(C_AMF_DecodeBoolean((*byte)(unsafe.Pointer(pBuffer)))) + prop.p_vu.p_number = float64(C_AMF_DecodeBoolean((*byte)(unsafe.Pointer(pBuffer)))) nSize-- */ case AMF_STRING: @@ -2932,7 +2926,7 @@ func C_AMFProp_Decode(prop *C.AMFObjectProperty, pBuffer *byte, nSize, bDecodeNa // next comes the rest, mixed array has a final 0x000009 mark and names, so its an object nRes = C_AMF_Decode(&prop.p_vu.p_object, (*byte)(incBytePtr( - unsafe.Pointer(pBuffer), 4)), nSize, TRUE) + unsafe.Pointer(pBuffer), 4)), nSize, 1) if nRes == -1 { return -1 } @@ -2969,7 +2963,7 @@ func C_AMFProp_Decode(prop *C.AMFObjectProperty, pBuffer *byte, nSize, bDecodeNa return -1 } - prop.p_vu.p_number = C.double(C_AMF_DecodeNumber(pBuffer)) + prop.p_vu.p_number = float64(C_AMF_DecodeNumber(pBuffer)) prop.p_UTCoffset = C.int16_t(C_AMF_DecodeInt16((*byte)(incBytePtr(unsafe.Pointer(pBuffer), 8)))) nSize -= 10 @@ -3014,7 +3008,7 @@ func C_AMFProp_Decode(prop *C.AMFObjectProperty, pBuffer *byte, nSize, bDecodeNa case AMF_AVMPLUS: { log.Println("18") - nRes := int32(C.AMF3_Decode(&prop.p_vu.p_object, (*C.char)(unsafe.Pointer(pBuffer)), C.int(nSize), 1)) + nRes := int32(C.AMF3_Decode(&prop.p_vu.p_object, (*byte)(unsafe.Pointer(pBuffer)), int32(nSize), 1)) if nRes == -1 { return -1 } @@ -3035,12 +3029,12 @@ func C_AMFProp_Decode(prop *C.AMFObjectProperty, pBuffer *byte, nSize, bDecodeNa // void AMF_AddProp(AMFObject* obj, const AMFObjectProperty* prop); // amf.c + 1234 -func C_AMF_AddProp(obj *C.AMFObject, prop *C.AMFObjectProperty) { +func C_AMF_AddProp(obj *C_AMFObject, prop *C_AMFObjectProperty) { if (obj.o_num & 0x0f) == 0 { - obj.o_props = (*C.AMFObjectProperty)(C.realloc(unsafe.Pointer(obj.o_props), + obj.o_props = (*C_AMFObjectProperty)(C.realloc(unsafe.Pointer(obj.o_props), C.size_t(int(obj.o_num+16)*int(unsafe.Sizeof(*obj.o_props))))) } - memmove(unsafe.Pointer(&(*(*C.AMFObjectProperty)(incPtr( + memmove(unsafe.Pointer(&(*(*C_AMFObjectProperty)(incPtr( unsafe.Pointer(obj.o_props), int(obj.o_num), int(unsafe.Sizeof(*obj.o_props)))))), unsafe.Pointer(prop), unsafe.Sizeof(*obj.o_props)) obj.o_num++ @@ -3083,14 +3077,14 @@ func C_EncodeInt32LE(output *byte, nVal int32) int32 { // #define RTMPPacket_IsReady(a) // rtmp.h +142 -func C_RTMPPacket_IsReady(p *C.RTMPPacket) int { +func C_RTMPPacket_IsReady(p *C_RTMPPacket) int { if p.m_nBytesRead == p.m_nBodySize { return 1 } return 0 } -func endSession(rtmp *C.RTMP) uint32 { +func endSession(rtmp *C_RTMP) uint32 { if rtmp == nil { return 3 } @@ -3102,7 +3096,7 @@ func endSession(rtmp *C.RTMP) uint32 { // int RTMP_Write(RTMP* r, const char* buf, int size); // rtmp.c +5095 -func C_RTMP_Write(r *C.RTMP, data []byte) int { +func C_RTMP_Write(r *C_RTMP, data []byte) int { buf := sliceToPtr(data) // TODO: port RTMPPacket var pkt = &r.m_write @@ -3112,7 +3106,7 @@ func C_RTMP_Write(r *C.RTMP, data []byte) int { var ret, num int pkt.m_nChannel = 0x04 - pkt.m_nInfoField2 = C.int32_t(r.m_stream_id) + pkt.m_nInfoField2 = int32(r.m_stream_id) for s2 != 0 { if pkt.m_nBytesRead == 0 { if size < minDataSize { @@ -3126,13 +3120,13 @@ func C_RTMP_Write(r *C.RTMP, data []byte) int { s2 -= 13 } - pkt.m_packetType = C.uint8_t(*indxBytePtr(buf, 0)) + pkt.m_packetType = uint8(*indxBytePtr(buf, 0)) buf = incBytePtr(buf, 1) - pkt.m_nBodySize = C.uint32_t(C_AMF_DecodeInt24((*byte)(buf))) + pkt.m_nBodySize = uint32(C_AMF_DecodeInt24((*byte)(buf))) buf = incBytePtr(buf, 3) - pkt.m_nTimeStamp = C.uint32_t(C_AMF_DecodeInt24((*byte)(buf))) + pkt.m_nTimeStamp = uint32(C_AMF_DecodeInt24((*byte)(buf))) buf = incBytePtr(buf, 3) - pkt.m_nTimeStamp |= C.uint32_t(*indxBytePtr(buf, 0)) << 24 + pkt.m_nTimeStamp |= uint32(*indxBytePtr(buf, 0)) << 24 buf = incBytePtr(buf, 4) s2 -= 11 @@ -3159,7 +3153,7 @@ func C_RTMP_Write(r *C.RTMP, data []byte) int { if pkt.m_packetType == RTMP_PACKET_TYPE_INFO { enc = unsafe.Pointer(C_AMF_EncodeString((*byte)(enc), (*byte)(pend), &setDataFrame)) - pkt.m_nBytesRead = C.uint32_t(math.Abs(float64(uintptr(enc) - + pkt.m_nBytesRead = uint32(math.Abs(float64(uintptr(enc) - uintptr(unsafe.Pointer(pkt.m_body))))) } @@ -3172,7 +3166,7 @@ func C_RTMP_Write(r *C.RTMP, data []byte) int { } memmove(enc, buf, uintptr(num)) - pkt.m_nBytesRead += C.uint32_t(num) + pkt.m_nBytesRead += uint32(num) s2 -= num buf = incBytePtr(buf, num) if pkt.m_nBytesRead == pkt.m_nBodySize { @@ -3197,7 +3191,7 @@ func C_RTMP_Write(r *C.RTMP, data []byte) int { // int RTMPPacket_Alloc(RTMPPacket* p, uint32_t nSize); // rtmp.c +189 -func C_RTMPPacket_Alloc(p *C.RTMPPacket, nSize uint32) int { +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 @@ -3211,15 +3205,15 @@ func C_RTMPPacket_Alloc(p *C.RTMPPacket, nSize uint32) int { if ptr == nil { return 0 } - p.m_body = (*C.char)(incBytePtr(unsafe.Pointer(ptr), RTMP_MAX_HEADER_SIZE)) + p.m_body = (*byte)(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 { - var prevPacket *C.RTMPPacket +func C_RTMP_SendPacket(r *C_RTMP, packet *C_RTMPPacket, queue int) int { + var prevPacket *C_RTMPPacket last := 0 var nSize, hSize, cSize, nChunkSize int var header, hptr, hend, buffer, tbuf, toff unsafe.Pointer @@ -3242,7 +3236,7 @@ func C_RTMP_SendPacket(r *C.RTMP, packet *C.RTMPPacket, queue int) int { r.m_channelsAllocatedOut = 0 return 0 } - r.m_vecChannelsOut = (**C.RTMPPacket)(packets) + r.m_vecChannelsOut = (**C_RTMPPacket)(packets) C.memset(incPtr(unsafe.Pointer(r.m_vecChannelsOut), int(r.m_channelsAllocatedOut), int(unsafe.Sizeof(packet))), 0, C.size_t(unsafe.Sizeof(packet)* @@ -3251,9 +3245,9 @@ func C_RTMP_SendPacket(r *C.RTMP, packet *C.RTMPPacket, queue int) int { //memset((*byte)(incPtr(unsafe.Pointer(r.m_vecChannelsOut), int( // r.m_channelsAllocatedOut), int(unsafe.Sizeof(packet)))), 0, int( // unsafe.Sizeof(packet)*uintptr(n-int(r.m_channelsAllocatedOut)))) - r.m_channelsAllocatedOut = C.int(n) + r.m_channelsAllocatedOut = int32(n) } - 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)))) if prevPacket != nil && packet.m_headerType != RTMP_PACKET_SIZE_LARGE { @@ -3354,8 +3348,8 @@ func C_RTMP_SendPacket(r *C.RTMP, packet *C.RTMPPacket, queue int) int { // TODO: port this hptr = incBytePtr(hptr, int(C_EncodeInt32LE((*byte)(hptr), int32(packet.m_nInfoField2)))) - //hptr = incBytePtr(hptr, int(C.EncodeInt32LE((*C.char)(hptr), - //C.int(packet.m_nInfoField2)))) + //hptr = incBytePtr(hptr, int(C.EncodeInt32LE((*byte)(hptr), + //int32(packet.m_nInfoField2)))) } if t >= 0xffffff { @@ -3441,11 +3435,11 @@ func C_RTMP_SendPacket(r *C.RTMP, packet *C.RTMPPacket, queue int) int { // We invoked a remote method // TODO: port the const if packet.m_packetType == RTMP_PACKET_TYPE_INVOKE { - // TODO: port C.AVal - var method C.AVal + // TODO: port C_AVal + var method C_AVal var ptr unsafe.Pointer ptr = incBytePtr(unsafe.Pointer(packet.m_body), 1) - //C.AMF_DecodeString((*C.char)(ptr), &method) + //C.AMF_DecodeString((*byte)(ptr), &method) C_AMF_DecodeString((*byte)(ptr), &method) if debugMode { @@ -3455,24 +3449,24 @@ func C_RTMP_SendPacket(r *C.RTMP, packet *C.RTMPPacket, queue int) int { if queue != 0 { var txn int ptr = incBytePtr(ptr, 3+int(method.av_len)) - //txn = int(C.AMF_DecodeNumber((*C.char)(ptr))) + //txn = int(C.AMF_DecodeNumber((*byte)(ptr))) 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)) + //C.AV_queue(&r.m_methodCalls, (*int32)(unsafe.Pointer(&r.m_numCalls)), &method, + //int32(txn)) } } - if *(**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 { - *(**C.RTMPPacket)(incPtr(unsafe.Pointer(r.m_vecChannelsOut), + *(**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)))) + (*C_RTMPPacket)(C.malloc(C.size_t(unsafe.Sizeof(*packet)))) } - memmove(unsafe.Pointer(*(**C.RTMPPacket)(incPtr(unsafe.Pointer(r.m_vecChannelsOut), + 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))) return 1 @@ -3480,7 +3474,7 @@ func C_RTMP_SendPacket(r *C.RTMP, packet *C.RTMPPacket, queue int) int { // int WriteN(RTMP* r, const char* buffer, int n); // rtmp.c +1502 -func C_WriteN(r *C.RTMP, buffer unsafe.Pointer, n int) int { +func C_WriteN(r *C_RTMP, buffer unsafe.Pointer, n int) int { ptr := buffer for n > 0 { var nBytes int @@ -3524,18 +3518,18 @@ var RTMPT_cmds = []string{ // int RTMPSockBuf_Send(RTMPSockBuf* sb, const char* buf, int len); // rtmp.c +4297 // TODO replace send with golang net connection send -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_RTMPSockBuf_Send(sb *C_RTMPSockBuf, buf *byte, l int32) int32 { + return int32(C.send(C.int(sb.sb_socket), unsafe.Pointer(buf), C.size_t(l), 0)) } -// void AV_queue(RTMP_METHOD** vals, int* num, C.AVal* av, int txn); +// void AV_queue(RTMP_METHOD** vals, int* num, C_AVal* av, int txn); // rtmp.c +2414 -func C_AV_queue(vals **C.RTMP_METHOD, num *int32, av *C.AVal, txn int32) { +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)* + //*vals = (*C_RTMP_METHOD)(realloc(unsafe.Pointer(*vals), int((*num+16)* //int(unsafe.Sizeof(*(*vals)))))) - *vals = (*C.RTMP_METHOD)(C.realloc(unsafe.Pointer(*vals), C.size_t((*num+16)* + *vals = (*C_RTMP_METHOD)(C.realloc(unsafe.Pointer(*vals), C.size_t((*num+16)* int32(unsafe.Sizeof(*(*vals)))))) } tmp := C.malloc(C.size_t(av.av_len + 1)) @@ -3543,18 +3537,18 @@ func C_AV_queue(vals **C.RTMP_METHOD, num *int32, av *C.AVal, txn int32) { memmove(tmp, unsafe.Pointer(av.av_val), uintptr(av.av_len)) *indxBytePtr(tmp, int(av.av_len)) = '\000' - (*(*C.RTMP_METHOD)(incPtr(unsafe.Pointer(*vals), int(*num), - int(unsafe.Sizeof(*(*vals)))))).num = C.int(txn) - (*(*C.RTMP_METHOD)(incPtr(unsafe.Pointer(*vals), int(*num), + (*(*C_RTMP_METHOD)(incPtr(unsafe.Pointer(*vals), int(*num), + int(unsafe.Sizeof(*(*vals)))))).num = int32(txn) + (*(*C_RTMP_METHOD)(incPtr(unsafe.Pointer(*vals), int(*num), int(unsafe.Sizeof(*(*vals)))))).name.av_len = av.av_len - (*(*C.RTMP_METHOD)(incPtr(unsafe.Pointer(*vals), int(*num), - int(unsafe.Sizeof(*(*vals)))))).name.av_val = (*C.char)(tmp) + (*(*C_RTMP_METHOD)(incPtr(unsafe.Pointer(*vals), int(*num), + int(unsafe.Sizeof(*(*vals)))))).name.av_val = (*byte)(tmp) (*num)++ } -// char* AMF_EncodeNamedNumber(char* output, char* outend, const C.AVal* strName, double dVal); +// char* AMF_EncodeNamedNumber(char* output, char* outend, const C_AVal* strName, double dVal); // amf.c +286 -func C_AMF_EncodeNamedNumber(output *byte, outend *byte, strName *C.AVal, dVal float64) *byte { +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 } @@ -3564,9 +3558,9 @@ func C_AMF_EncodeNamedNumber(output *byte, outend *byte, strName *C.AVal, dVal f return C_AMF_EncodeNumber(output, outend, dVal) } -// char* AMF_EncodeNamedBoolean(char* output, char* outend, const C.AVal* strname, int bVal); +// char* AMF_EncodeNamedBoolean(char* output, char* outend, const C_AVal* strname, int bVal); // amf.c +299 -func C_AMF_EncodeNamedBoolean(output *byte, outend *byte, strName *C.AVal, bVal int) *byte { +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 } @@ -3578,7 +3572,7 @@ func C_AMF_EncodeNamedBoolean(output *byte, outend *byte, strName *C.AVal, bVal // void AMFProp_SetName(AMFObjectProperty *prop, AVal *name); // amf.c +318 -func C_AMFProp_SetName(prop *C.AMFObjectProperty, name *C.AVal) { +func C_AMFProp_SetName(prop *C_AMFObjectProperty, name *C_AVal) { prop.p_name = *name } @@ -3631,7 +3625,7 @@ func C_AMF3ReadInteger(data *byte, valp *int32) int32 { // int AMF3ReadString(const char *data, AVal *str); // amf.c +466 -func C_AMF3ReadString(data *byte, str *C.AVal) int32 { +func C_AMF3ReadString(data *byte, str *C_AVal) int32 { var ref int32 // assert elided - we will get a panic if it's nil. @@ -3650,8 +3644,8 @@ func C_AMF3ReadString(data *byte, str *C.AVal) int32 { return len } else { nSize := (ref >> 1) - str.av_val = (*C.char)(unsafe.Pointer(data)) - str.av_len = C.int(nSize) + str.av_val = (*byte)(unsafe.Pointer(data)) + str.av_len = int32(nSize) return len + nSize } return len @@ -3696,10 +3690,10 @@ func C_AMF_EncodeNumber(output *byte, outend *byte, dVal float64) *byte { // void AMF_DecodeLongString(const char *data, AVal *bv); // amf.c +75 -func C_AMF_DecodeLongString(data *byte, bv *C.AVal) { - bv.av_len = C.int(C_AMF_DecodeInt32(data)) +func C_AMF_DecodeLongString(data *byte, bv *C_AVal) { + bv.av_len = int32(C_AMF_DecodeInt32(data)) if bv.av_len > 0 { - bv.av_val = (*C.char)(incBytePtr(unsafe.Pointer(data), 4)) + bv.av_val = (*byte)(incBytePtr(unsafe.Pointer(data), 4)) } else { bv.av_val = nil } @@ -3727,9 +3721,9 @@ func C_AMF_DecodeBoolean(data *byte) int32 { return 0 } -// char* AMF_EncodeNamedString(char* output, char* outend, const C.AVal* strName, const C.AVal* strValue); +// char* AMF_EncodeNamedString(char* output, char* outend, const C_AVal* strName, const C_AVal* strValue); // amf.c +273 -func C_AMF_EncodeNamedString(output *byte, outend *byte, strName *C.AVal, strValue *C.AVal) *byte { +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 } @@ -3739,14 +3733,14 @@ func C_AMF_EncodeNamedString(output *byte, outend *byte, strName *C.AVal, strVal return C_AMF_EncodeString(output, outend, strValue) } -// void AMF_DecodeString(const char* data, C.AVal* bv); +// void AMF_DecodeString(const char* data, C_AVal* bv); // amf.c +68 -func C_AMF_DecodeString(data *byte, bv *C.AVal) { +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_AMF_DecodeInt16((*byte)(dataPtr))) + //bv.av_len = int32(C.AMF_DecodeInt16((*byte)(dataPtr))) + bv.av_len = int32(C_AMF_DecodeInt16((*byte)(dataPtr))) if bv.av_len > 0 { - bv.av_val = (*C.char)(incBytePtr(dataPtr, 2)) + bv.av_val = (*byte)(incBytePtr(dataPtr, 2)) } else { bv.av_val = nil } @@ -3792,9 +3786,9 @@ func C_AMF_DecodeInt24(data *byte) uint32 { return dst } -// char* AMF_EncodeString(char* output, char* outend, const C.AVal* bv); +// char* AMF_EncodeString(char* output, char* outend, const C_AVal* bv); // amf.c +174 -func C_AMF_EncodeString(output *byte, outend *byte, bv *C.AVal) *byte { +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))) > @@ -3867,13 +3861,15 @@ func C_AMF_EncodeInt32(output *byte, outend *byte, nVal int32) *byte { // void AMF3CD_AddProp(AMF3ClassDef *cd, AVal *prop); // amf.c +1298 // TODO test -func AMF3CD_AddProp(cd *C.AMF3ClassDef, prop *C.AVal) { +/* +func AMF3CD_AddProp(cd *C.AMF3ClassDef, prop *C_AVal) { if cd.cd_num&0x0f == 0 { - cd.cd_props = (*C.AVal)(realloc(unsafe.Pointer(cd.cd_props), int(uintptr(cd.cd_num+16)*unsafe.Sizeof(C.AVal{})))) + cd.cd_props = (*C_AVal)(realloc(unsafe.Pointer(cd.cd_props), int(uintptr(cd.cd_num+16)*unsafe.Sizeof(C_AVal{})))) } - *(*C.AVal)(incPtr(unsafe.Pointer(cd.cd_props), int(cd.cd_num), int(unsafe.Sizeof(C.AVal{})))) = *prop + *(*C_AVal)(incPtr(unsafe.Pointer(cd.cd_props), int(cd.cd_num), int(unsafe.Sizeof(C_AVal{})))) = *prop cd.cd_num++ } +*/ func realloc(ptr unsafe.Pointer, size int) unsafe.Pointer { dest := allocate(uintptr(size)) @@ -4104,12 +4100,16 @@ func ptrToSlice(data unsafe.Pointer, size int) []byte { return ret } -// C.AVal is in amf.h +// C_AVal is in amf.h // See AVC(str) {str, sizeof(str)-1} in amf.h -func AVC(str string) C.AVal { - var aval C.AVal - aval.av_val = C.CString(str) - aval.av_len = C.int(len(str)) +func AVC(str string) C_AVal { + var aval C_AVal + if len(str) != 0 { + aval.av_val = &([]byte(str)[0]) + } else { + aval.av_val = nil + } + aval.av_len = int32(len(str)) return aval }