Index: librtmp/amf.c =================================================================== --- librtmp/amf.c (revision 426) +++ librtmp/amf.c (working copy) @@ -22,6 +22,10 @@ * http://www.gnu.org/copyleft/lgpl.html */ +#ifdef _MSC_VER +#include +#endif + #include #include #include @@ -30,6 +34,7 @@ #include "log.h" #include "bytes.h" + static const AMFObjectProperty AMFProp_Invalid = { {0, 0}, AMF_INVALID }; static const AVal AV_empty = { 0, 0 }; @@ -448,10 +453,11 @@ int AMF3ReadString(const char *data, AVal *str) { + int32_t ref = 0; + int len; assert(str != 0); - int32_t ref = 0; - int len = AMF3ReadInteger(data, &ref); + len = AMF3ReadInteger(data, &ref); data += len; if ((ref & 0x1) == 0) @@ -596,6 +602,7 @@ bool bDecodeName) { int nOriginalSize = nSize; + int nRes; prop->p_name.av_len = 0; prop->p_name.av_val = NULL; @@ -692,7 +699,7 @@ nSize -= 4; /* next comes the rest, mixed array has a final 0x000009 mark and names, so its an object */ - int nRes = AMF_Decode(&prop->p_vu.p_object, pBuffer + 4, nSize, true); + nRes = AMF_Decode(&prop->p_vu.p_object, pBuffer + 4, nSize, true); if (nRes == -1) return -1; nSize -= nRes; @@ -709,7 +716,7 @@ unsigned int nArrayLen = AMF_DecodeInt32(pBuffer); nSize -= 4; - int nRes = AMF_DecodeArray(&prop->p_vu.p_object, pBuffer + 4, nSize, + nRes = AMF_DecodeArray(&prop->p_vu.p_object, pBuffer + 4, nSize, nArrayLen, false); if (nRes == -1) return -1; @@ -899,10 +906,11 @@ obj->o_props = NULL; while (nArrayLen > 0) { + AMFObjectProperty prop; + int nRes; nArrayLen--; - AMFObjectProperty prop; - int nRes = AMFProp_Decode(&prop, pBuffer, nSize, bDecodeName); + nRes = AMFProp_Decode(&prop, pBuffer, nSize, bDecodeName); if (nRes == -1) bError = true; else Index: librtmp/amf.h =================================================================== --- librtmp/amf.h (revision 426) +++ librtmp/amf.h (working copy) @@ -25,9 +25,7 @@ */ #include -#ifndef _MSC_VER #include -#endif #ifdef __cplusplus extern "C" Index: librtmp/dh.h =================================================================== --- librtmp/dh.h (revision 426) +++ librtmp/dh.h (working copy) @@ -126,9 +126,10 @@ isValidPublicKey(MP_t y, MP_t p, MP_t q) { int ret = true; + MP_t bn; assert(y); - MP_t bn = MP_new(); + bn = MP_new(); assert(bn); // y must lie in [2,p-1] @@ -210,16 +211,17 @@ static int DHGenerateKey(MDH *dh) { + size_t res = 0; if (!dh) return 0; - size_t res = 0; while (!res) { + MP_t q1 = NULL; + if (!MDH_generate_key(dh)) return 0; - MP_t q1 = NULL; MP_gethex(&q1, Q1024, res); assert(res); @@ -242,10 +244,11 @@ static int DHGetPublicKey(MDH *dh, uint8_t *pubkey, size_t nPubkeyLen) { + int len; if (!dh || !dh->pub_key) return 0; - int len = MP_bytes(dh->pub_key); + len = MP_bytes(dh->pub_key); if (len <= 0 || len > (int) nPubkeyLen) return 0; Index: librtmp/handshake.h =================================================================== --- librtmp/handshake.h (revision 426) +++ librtmp/handshake.h (working copy) @@ -121,6 +121,7 @@ { unsigned int offset = 0; unsigned char *ptr = (unsigned char *) handshake + 768; + unsigned int res; assert(RTMP_SIG_SIZE <= len); @@ -132,7 +133,7 @@ ptr++; offset += (*ptr); - unsigned int res = (offset % 632) + 8; + res = (offset % 632) + 8; if (res + 128 > 767) { @@ -149,6 +150,7 @@ { unsigned int offset = 0; unsigned char *ptr = (unsigned char *) handshake + 772; + unsigned int res; offset += (*ptr); ptr++; @@ -158,7 +160,7 @@ ptr++; offset += (*ptr); - unsigned int res = (offset % 728) + 776; + res = (offset % 728) + 776; if (res + 32 > 1535) { @@ -175,6 +177,7 @@ { unsigned int offset = 0; unsigned char *ptr = (unsigned char *) handshake + 1532; + unsigned int res; assert(RTMP_SIG_SIZE <= len); @@ -186,7 +189,7 @@ ptr++; offset += (*ptr); - unsigned int res = (offset % 632) + 772; + res = (offset % 632) + 772; if (res + 128 > 1531) { @@ -203,6 +206,7 @@ { unsigned int offset = 0; unsigned char *ptr = (unsigned char *) handshake + 8; + unsigned int res; assert(12 <= len); @@ -214,7 +218,7 @@ ptr++; offset += (*ptr); - unsigned int res = (offset % 728) + 12; + res = (offset % 728) + 12; if (res + 32 > 771) { @@ -246,7 +250,7 @@ const char *key, size_t keyLen, char *digest) { const int messageLen = RTMP_SIG_SIZE - SHA256_DIGEST_LENGTH; - char message[messageLen]; + char message[RTMP_SIG_SIZE - SHA256_DIGEST_LENGTH]; memcpy(message, handshakeMessage, digestPos); memcpy(message + digestPos, @@ -477,8 +481,10 @@ #endif if (FP9HandShake) - { - int dhposServer; + { + int dhposServer; + char digestResp[SHA256_DIGEST_LENGTH]; + char *signatureResp = NULL; /* we have to use this signature now to find the correct algorithms for getting the digest and DH positions */ int digestPosServer = GetDigestOffset2(serversig, RTMP_SIG_SIZE); @@ -552,8 +558,7 @@ *ip++ = rand(); #endif /* calculate response now */ - char digestResp[SHA256_DIGEST_LENGTH]; - char *signatureResp = reply+RTMP_SIG_SIZE-SHA256_DIGEST_LENGTH; + signatureResp = reply+RTMP_SIG_SIZE-SHA256_DIGEST_LENGTH; HMACsha256(&serversig[digestPosServer], SHA256_DIGEST_LENGTH, GenuineFPKey, sizeof(GenuineFPKey), digestResp); @@ -675,11 +680,11 @@ if (encrypted) { + char buff[RTMP_SIG_SIZE]; /* set keys for encryption from now on */ r->Link.rc4keyIn = keyIn; r->Link.rc4keyOut = keyOut; - char buff[RTMP_SIG_SIZE]; /* update the keystreams */ if (r->Link.rc4keyIn) @@ -842,6 +847,9 @@ if (FP9HandShake) { + char digestResp[SHA256_DIGEST_LENGTH]; + char *signatureResp = NULL; + /* we have to use this signature now to find the correct algorithms for getting the digest and DH positions */ int digestPosClient = GetDigestOffset1(clientsig, RTMP_SIG_SIZE); @@ -906,8 +914,7 @@ /* calculate response now */ - char digestResp[SHA256_DIGEST_LENGTH]; - char *signatureResp = clientsig+RTMP_SIG_SIZE-SHA256_DIGEST_LENGTH; + signatureResp = clientsig+RTMP_SIG_SIZE-SHA256_DIGEST_LENGTH; HMACsha256(&clientsig[digestPosClient], SHA256_DIGEST_LENGTH, GenuineFMSKey, sizeof(GenuineFMSKey), digestResp); @@ -1018,12 +1025,11 @@ if (encrypted) { + char buff[RTMP_SIG_SIZE]; /* set keys for encryption from now on */ r->Link.rc4keyIn = keyIn; r->Link.rc4keyOut = keyOut; - char buff[RTMP_SIG_SIZE]; - /* update the keystreams */ if (r->Link.rc4keyIn) { Index: librtmp/hashswf.c =================================================================== --- librtmp/hashswf.c (revision 426) +++ librtmp/hashswf.c (working copy) @@ -77,6 +77,7 @@ HTTPResult ret = HTTPRES_OK; struct sockaddr_in sa; RTMPSockBuf sb = {0}; + DECL_RCVTIMEO(tv); http->status = -1; Index: librtmp/parseurl.c =================================================================== --- librtmp/parseurl.c (revision 426) +++ librtmp/parseurl.c (working copy) @@ -111,8 +111,9 @@ // get the port number if available if(*p == ':') { + unsigned int p2; p++; - unsigned int p2 = atoi(p); + p2 = atoi(p); if(p2 > 65535) { RTMP_Log(RTMP_LOGWARNING, "Invalid port number!"); } else { @@ -196,6 +197,9 @@ const char *playpath = in->av_val; const char *temp, *q, *ext = NULL; const char *ppstart = playpath; + char *streamname = NULL; + char *destptr = NULL; + char *p = NULL; int pplen = in->av_len; @@ -233,11 +237,11 @@ } } - char *streamname = (char *)malloc((pplen+4+1)*sizeof(char)); + streamname = (char *)malloc((pplen+4+1)*sizeof(char)); if (!streamname) return; - char *destptr = streamname, *p; + destptr = streamname; if (addMP4 && (strncmp(ppstart, "mp4:", 4) != 0)) { strcpy(destptr, "mp4:"); destptr += 4; Index: librtmp/rtmp.c =================================================================== --- librtmp/rtmp.c (revision 426) +++ librtmp/rtmp.c (working copy) @@ -734,6 +734,8 @@ bool RTMP_Connect0(RTMP *r, struct sockaddr * service) { + int on = 1; + DECL_RCVTIMEO(tv); r->m_sb.sb_timedout = false; r->m_pausing = 0; r->m_fDuration = 0.0; @@ -777,7 +779,6 @@ __FUNCTION__, r->Link.timeout); } - int on = 1; setsockopt(r->m_sb.sb_socket, IPPROTO_TCP, TCP_NODELAY, &on, sizeof(on)); return true; @@ -865,35 +866,38 @@ static bool SocksNegotiate(RTMP *r) { + unsigned long addr; struct sockaddr_in service; memset(&service, 0, sizeof(struct sockaddr_in)); add_addr_info(&service, &r->Link.hostname, r->Link.port); - unsigned long addr = htonl(service.sin_addr.s_addr); + addr = htonl(service.sin_addr.s_addr); - char packet[] = { - 4, 1, // SOCKS 4, connect - (r->Link.port >> 8) & 0xFF, - (r->Link.port) & 0xFF, - (char)(addr >> 24) & 0xFF, (char)(addr >> 16) & 0xFF, - (char)(addr >> 8) & 0xFF, (char)addr & 0xFF, - 0 - }; // NULL terminate + { + char packet[] = { + 4, 1, // SOCKS 4, connect + (r->Link.port >> 8) & 0xFF, + (r->Link.port) & 0xFF, + (char)(addr >> 24) & 0xFF, (char)(addr >> 16) & 0xFF, + (char)(addr >> 8) & 0xFF, (char)addr & 0xFF, + 0 + }; // NULL terminate - WriteN(r, packet, sizeof packet); + WriteN(r, packet, sizeof packet); - if (ReadN(r, packet, 8) != 8) - return false; + if (ReadN(r, packet, 8) != 8) + return false; - if (packet[0] == 0 && packet[1] == 90) - { - return true; - } - else - { - RTMP_Log(RTMP_LOGERROR, "%s, SOCKS returned error code %d", packet[1]); - return false; - } + if (packet[0] == 0 && packet[1] == 90) + { + return true; + } + else + { + RTMP_Log(RTMP_LOGERROR, "%s, SOCKS returned error code %d", packet[1]); + return false; + } + } } bool @@ -1355,6 +1359,7 @@ { RTMPPacket packet; char pbuf[4096], *pend = pbuf + sizeof(pbuf); + char *enc = NULL; if (cp) return RTMP_SendPacket(r, cp, true); @@ -1367,7 +1372,7 @@ packet.m_hasAbsTimestamp = 0; packet.m_body = pbuf + RTMP_MAX_HEADER_SIZE; - char *enc = packet.m_body; + enc = packet.m_body; enc = AMF_EncodeString(enc, pend, &av_connect); enc = AMF_EncodeNumber(enc, pend, ++r->m_numInvokes); *enc++ = AMF_OBJECT; @@ -1468,6 +1473,7 @@ { RTMPPacket packet; char pbuf[1024], *pend = pbuf + sizeof(pbuf); + char *enc = NULL; packet.m_nChannel = 0x03; // control channel (invoke) packet.m_headerType = RTMP_PACKET_SIZE_MEDIUM; @@ -1477,7 +1483,7 @@ packet.m_hasAbsTimestamp = 0; packet.m_body = pbuf + RTMP_MAX_HEADER_SIZE; - char *enc = packet.m_body; + enc = packet.m_body; enc = AMF_EncodeString(enc, pend, &av_bgHasStream); enc = AMF_EncodeNumber(enc, pend, dId); *enc++ = AMF_NULL; @@ -1499,6 +1505,7 @@ { RTMPPacket packet; char pbuf[256], *pend = pbuf + sizeof(pbuf); + char *enc = NULL; packet.m_nChannel = 0x03; // control channel (invoke) packet.m_headerType = RTMP_PACKET_SIZE_MEDIUM; @@ -1508,7 +1515,7 @@ packet.m_hasAbsTimestamp = 0; packet.m_body = pbuf + RTMP_MAX_HEADER_SIZE; - char *enc = packet.m_body; + enc = packet.m_body; enc = AMF_EncodeString(enc, pend, &av_createStream); enc = AMF_EncodeNumber(enc, pend, ++r->m_numInvokes); *enc++ = AMF_NULL; // NULL @@ -1525,6 +1532,7 @@ { RTMPPacket packet; char pbuf[512], *pend = pbuf + sizeof(pbuf); + char *enc = NULL; packet.m_nChannel = 0x03; // control channel (invoke) packet.m_headerType = RTMP_PACKET_SIZE_MEDIUM; packet.m_packetType = 0x14; // INVOKE @@ -1534,7 +1542,7 @@ packet.m_body = pbuf + RTMP_MAX_HEADER_SIZE; RTMP_Log(RTMP_LOGDEBUG, "FCSubscribe: %s", subscribepath->av_val); - char *enc = packet.m_body; + enc = packet.m_body; enc = AMF_EncodeString(enc, pend, &av_FCSubscribe); enc = AMF_EncodeNumber(enc, pend, ++r->m_numInvokes); *enc++ = AMF_NULL; @@ -1555,6 +1563,7 @@ { RTMPPacket packet; char pbuf[1024], *pend = pbuf + sizeof(pbuf); + char *enc = NULL; packet.m_nChannel = 0x03; // control channel (invoke) packet.m_headerType = RTMP_PACKET_SIZE_MEDIUM; @@ -1564,7 +1573,7 @@ packet.m_hasAbsTimestamp = 0; packet.m_body = pbuf + RTMP_MAX_HEADER_SIZE; - char *enc = packet.m_body; + enc = packet.m_body; enc = AMF_EncodeString(enc, pend, &av_releaseStream); enc = AMF_EncodeNumber(enc, pend, ++r->m_numInvokes); *enc++ = AMF_NULL; @@ -1584,6 +1593,7 @@ { RTMPPacket packet; char pbuf[1024], *pend = pbuf + sizeof(pbuf); + char *enc = NULL; packet.m_nChannel = 0x03; // control channel (invoke) packet.m_headerType = RTMP_PACKET_SIZE_MEDIUM; @@ -1593,7 +1603,7 @@ packet.m_hasAbsTimestamp = 0; packet.m_body = pbuf + RTMP_MAX_HEADER_SIZE; - char *enc = packet.m_body; + enc = packet.m_body; enc = AMF_EncodeString(enc, pend, &av_FCPublish); enc = AMF_EncodeNumber(enc, pend, ++r->m_numInvokes); *enc++ = AMF_NULL; @@ -1613,6 +1623,7 @@ { RTMPPacket packet; char pbuf[1024], *pend = pbuf + sizeof(pbuf); + char *enc = NULL; packet.m_nChannel = 0x03; // control channel (invoke) packet.m_headerType = RTMP_PACKET_SIZE_MEDIUM; @@ -1622,7 +1633,7 @@ packet.m_hasAbsTimestamp = 0; packet.m_body = pbuf + RTMP_MAX_HEADER_SIZE; - char *enc = packet.m_body; + enc = packet.m_body; enc = AMF_EncodeString(enc, pend, &av_FCUnpublish); enc = AMF_EncodeNumber(enc, pend, ++r->m_numInvokes); *enc++ = AMF_NULL; @@ -1644,6 +1655,7 @@ { RTMPPacket packet; char pbuf[1024], *pend = pbuf + sizeof(pbuf); + char *enc = NULL; packet.m_nChannel = 0x04; // source channel (invoke) packet.m_headerType = RTMP_PACKET_SIZE_LARGE; @@ -1653,7 +1665,7 @@ packet.m_hasAbsTimestamp = 0; packet.m_body = pbuf + RTMP_MAX_HEADER_SIZE; - char *enc = packet.m_body; + enc = packet.m_body; enc = AMF_EncodeString(enc, pend, &av_publish); enc = AMF_EncodeNumber(enc, pend, ++r->m_numInvokes); *enc++ = AMF_NULL; @@ -1678,6 +1690,7 @@ { RTMPPacket packet; char pbuf[256], *pend = pbuf + sizeof(pbuf); + char *enc = NULL; packet.m_nChannel = 0x03; // control channel (invoke) packet.m_headerType = RTMP_PACKET_SIZE_MEDIUM; @@ -1687,7 +1700,7 @@ packet.m_hasAbsTimestamp = 0; packet.m_body = pbuf + RTMP_MAX_HEADER_SIZE; - char *enc = packet.m_body; + enc = packet.m_body; enc = AMF_EncodeString(enc, pend, &av_deleteStream); enc = AMF_EncodeNumber(enc, pend, ++r->m_numInvokes); *enc++ = AMF_NULL; @@ -1706,6 +1719,7 @@ { RTMPPacket packet; char pbuf[256], *pend = pbuf + sizeof(pbuf); + char *enc = NULL; packet.m_nChannel = 0x08; // video channel packet.m_headerType = RTMP_PACKET_SIZE_MEDIUM; @@ -1715,7 +1729,7 @@ packet.m_hasAbsTimestamp = 0; packet.m_body = pbuf + RTMP_MAX_HEADER_SIZE; - char *enc = packet.m_body; + enc = packet.m_body; enc = AMF_EncodeString(enc, pend, &av_pause); enc = AMF_EncodeNumber(enc, pend, ++r->m_numInvokes); *enc++ = AMF_NULL; @@ -1735,6 +1749,7 @@ { RTMPPacket packet; char pbuf[256], *pend = pbuf + sizeof(pbuf); + char *enc = NULL; packet.m_nChannel = 0x08; // video channel packet.m_headerType = RTMP_PACKET_SIZE_MEDIUM; @@ -1744,7 +1759,7 @@ packet.m_hasAbsTimestamp = 0; packet.m_body = pbuf + RTMP_MAX_HEADER_SIZE; - char *enc = packet.m_body; + enc = packet.m_body; enc = AMF_EncodeString(enc, pend, &av_seek); enc = AMF_EncodeNumber(enc, pend, ++r->m_numInvokes); *enc++ = AMF_NULL; @@ -1829,6 +1844,7 @@ { RTMPPacket packet; char pbuf[256], *pend = pbuf + sizeof(pbuf); + char *enc = NULL; packet.m_nChannel = 0x03; // control channel (invoke) packet.m_headerType = RTMP_PACKET_SIZE_LARGE; @@ -1838,7 +1854,7 @@ packet.m_hasAbsTimestamp = 0; packet.m_body = pbuf + RTMP_MAX_HEADER_SIZE; - char *enc = packet.m_body; + enc = packet.m_body; enc = AMF_EncodeString(enc, pend, &av__checkbw); enc = AMF_EncodeNumber(enc, pend, ++r->m_numInvokes); *enc++ = AMF_NULL; @@ -1856,6 +1872,7 @@ { RTMPPacket packet; char pbuf[256], *pend = pbuf + sizeof(pbuf); + char *enc = NULL; packet.m_nChannel = 0x03; // control channel (invoke) packet.m_headerType = RTMP_PACKET_SIZE_MEDIUM; @@ -1865,7 +1882,7 @@ packet.m_hasAbsTimestamp = 0; packet.m_body = pbuf + RTMP_MAX_HEADER_SIZE; - char *enc = packet.m_body; + enc = packet.m_body; enc = AMF_EncodeString(enc, pend, &av__result); enc = AMF_EncodeNumber(enc, pend, txn); *enc++ = AMF_NULL; @@ -1883,6 +1900,7 @@ { RTMPPacket packet; char pbuf[1024], *pend = pbuf + sizeof(pbuf); + char *enc = NULL; packet.m_nChannel = 0x08; // we make 8 our stream channel packet.m_headerType = RTMP_PACKET_SIZE_LARGE; @@ -1892,7 +1910,7 @@ packet.m_hasAbsTimestamp = 0; packet.m_body = pbuf + RTMP_MAX_HEADER_SIZE; - char *enc = packet.m_body; + enc = packet.m_body; enc = AMF_EncodeString(enc, pend, &av_play); enc = AMF_EncodeNumber(enc, pend, ++r->m_numInvokes); *enc++ = AMF_NULL; @@ -1944,6 +1962,7 @@ { RTMPPacket packet; char pbuf[1024], *pend = pbuf + sizeof(pbuf); + char *enc = NULL; packet.m_nChannel = 0x03; /* control channel (invoke) */ packet.m_headerType = RTMP_PACKET_SIZE_MEDIUM; @@ -1953,7 +1972,7 @@ packet.m_hasAbsTimestamp = 0; packet.m_body = pbuf + RTMP_MAX_HEADER_SIZE; - char *enc = packet.m_body; + enc = packet.m_body; enc = AMF_EncodeString(enc, pend, &av_secureTokenResponse); enc = AMF_EncodeNumber(enc, pend, 0.0); *enc++ = AMF_NULL; @@ -1985,12 +2004,13 @@ bool RTMP_SendCtrl(RTMP *r, short nType, unsigned int nObject, unsigned int nTime) { - RTMP_Log(RTMP_LOGDEBUG, "sending ctrl. type: 0x%04x", (unsigned short)nType); - RTMPPacket packet; char pbuf[256], *pend = pbuf + sizeof(pbuf); int nSize; + char *buf = NULL; + RTMP_Log(RTMP_LOGDEBUG, "sending ctrl. type: 0x%04x", (unsigned short)nType); + packet.m_nChannel = 0x02; // control channel (ping) packet.m_headerType = RTMP_PACKET_SIZE_MEDIUM; packet.m_packetType = 0x04; // ctrl @@ -2008,7 +2028,7 @@ packet.m_nBodySize = nSize; - char *buf = packet.m_body; + buf = packet.m_body; buf = AMF_EncodeInt16(buf, pend, nType); if (nType == 0x1B) @@ -2106,6 +2126,9 @@ static int HandleInvoke(RTMP *r, const char *body, unsigned int nBodySize) { + AMFObject obj; + AVal method; + double txn; int ret = 0, nRes; if (body[0] != 0x02) // make sure it is a string method name we start with { @@ -2114,7 +2137,6 @@ return 0; } - AMFObject obj; nRes = AMF_Decode(&obj, body, nBodySize, false); if (nRes < 0) { @@ -2123,9 +2145,8 @@ } AMF_Dump(&obj); - AVal method; AMFProp_GetString(AMF_GetProp(&obj, NULL, 0), &method); - double txn = AMFProp_GetNumber(AMF_GetProp(&obj, NULL, 1)); + txn = AMFProp_GetNumber(AMF_GetProp(&obj, NULL, 1)); RTMP_Log(RTMP_LOGDEBUG, "%s, server invoking <%s>", __FUNCTION__, method.av_val); if (AVMATCH(&method, &av__result)) @@ -2584,6 +2605,8 @@ RTMP_ReadPacket(RTMP *r, RTMPPacket *packet) { char hbuf[RTMP_MAX_HEADER_SIZE] = { 0 }, *header = hbuf; + int nSize, hSize, nToRead, nChunk; + bool didAlloc = false; RTMP_Log(RTMP_LOGDEBUG2, "%s: fd=%d", __FUNCTION__, r->m_sb.sb_socket); @@ -2623,7 +2646,7 @@ header += 2; } - int nSize = packetSize[packet->m_headerType], hSize; + nSize = packetSize[packet->m_headerType]; if (nSize == RTMP_LARGE_HEADER_SIZE) // if we get a full header the timestamp is absolute packet->m_hasAbsTimestamp = true; @@ -2681,7 +2704,6 @@ RTMP_LogHexString(RTMP_LOGDEBUG2, hbuf, hSize); - bool didAlloc = false; if (packet->m_nBodySize > 0 && packet->m_body == NULL) { if (!RTMPPacket_Alloc(packet, packet->m_nBodySize)) @@ -2693,8 +2715,8 @@ packet->m_headerType = (hbuf[0] & 0xc0) >> 6; } - int nToRead = packet->m_nBodySize - packet->m_nBytesRead; - int nChunk = r->m_inChunkSize; + nToRead = packet->m_nBodySize - packet->m_nBytesRead; + nChunk = r->m_inChunkSize; if (nToRead < nChunk) nChunk = nToRead; @@ -2752,10 +2774,14 @@ int i; char clientbuf[RTMP_SIG_SIZE + 1], *clientsig = clientbuf + 1; char serversig[RTMP_SIG_SIZE]; + uint32_t uptime; + char type; + uint32_t suptime; + bool bMatch; clientbuf[0] = 0x03; // not encrypted - uint32_t uptime = htonl(RTMP_GetTime()); + uptime = htonl(RTMP_GetTime()); memcpy(clientsig, &uptime, 4); memset(&clientsig[4], 0, 4); @@ -2771,7 +2797,6 @@ if (!WriteN(r, clientbuf, RTMP_SIG_SIZE + 1)) return false; - char type; if (ReadN(r, &type, 1) != 1) // 0x03 or 0x06 return false; @@ -2785,7 +2810,6 @@ return false; // decode server response - uint32_t suptime; memcpy(&suptime, serversig, 4); suptime = ntohl(suptime); @@ -2801,7 +2825,7 @@ if (ReadN(r, serversig, RTMP_SIG_SIZE) != RTMP_SIG_SIZE) return false; - bool bMatch = (memcmp(serversig, clientsig, RTMP_SIG_SIZE) == 0); + bMatch = (memcmp(serversig, clientsig, RTMP_SIG_SIZE) == 0); if (!bMatch) { RTMP_Log(RTMP_LOGWARNING, "%s, client signature does not match!", __FUNCTION__); @@ -2816,6 +2840,7 @@ char serverbuf[RTMP_SIG_SIZE + 1], *serversig = serverbuf + 1; char clientsig[RTMP_SIG_SIZE]; uint32_t uptime; + bool bMatch; if (ReadN(r, serverbuf, 1) != 1) // 0x03 or 0x06 return false; @@ -2863,7 +2888,7 @@ if (ReadN(r, clientsig, RTMP_SIG_SIZE) != RTMP_SIG_SIZE) return false; - bool bMatch = (memcmp(serversig, clientsig, RTMP_SIG_SIZE) == 0); + bMatch = (memcmp(serversig, clientsig, RTMP_SIG_SIZE) == 0); if (!bMatch) { RTMP_Log(RTMP_LOGWARNING, "%s, client signature does not match!", __FUNCTION__); @@ -2901,6 +2926,14 @@ { const RTMPPacket *prevPacket = r->m_vecChannelsOut[packet->m_nChannel]; uint32_t last = 0; + int nSize; + int hSize, cSize; + char *header, *hptr, *hend, hbuf[RTMP_MAX_HEADER_SIZE], c; + uint32_t t; + char *buffer, *tbuf = NULL, *toff = NULL; + int nChunkSize; + int tlen; + if (prevPacket && packet->m_headerType != RTMP_PACKET_SIZE_LARGE) { // compress a bit by using the prev packet's attributes @@ -2922,10 +2955,9 @@ return false; } - int nSize = packetSize[packet->m_headerType]; - int hSize = nSize, cSize = 0; - char *header, *hptr, *hend, hbuf[RTMP_MAX_HEADER_SIZE], c; - uint32_t t = packet->m_nTimeStamp - last; + nSize = packetSize[packet->m_headerType]; + hSize = nSize; cSize = 0; + t = packet->m_nTimeStamp - last; if (packet->m_body) { @@ -2994,9 +3026,8 @@ hptr = AMF_EncodeInt32(hptr, hend, t); nSize = packet->m_nBodySize; - char *buffer = packet->m_body, *tbuf = NULL, *toff = NULL; - int nChunkSize = r->m_outChunkSize; - int tlen; + buffer = packet->m_body; + nChunkSize = r->m_outChunkSize; RTMP_Log(RTMP_LOGDEBUG2, "%s: fd=%d, size=%d", __FUNCTION__, r->m_sb.sb_socket, nSize); @@ -3411,6 +3442,10 @@ int rtnGetNextMediaPacket = 0, ret = RTMP_READ_EOF; RTMPPacket packet = { 0 }; bool recopy = false; + unsigned int size; + char *ptr, *pend; + uint32_t nTimeStamp = 0; + unsigned int len; rtnGetNextMediaPacket = RTMP_GetNextMediaPacket(r, &packet); while (rtnGetNextMediaPacket) @@ -3689,12 +3724,11 @@ } /* calculate packet size and allocate slop buffer if necessary */ - unsigned int size = nPacketLen + + size = nPacketLen + ((packet.m_packetType == 0x08 || packet.m_packetType == 0x09 || packet.m_packetType == 0x12) ? 11 : 0) + (packet.m_packetType != 0x16 ? 4 : 0); - char *ptr, *pend; if (size + 4 > buflen) { /* the extra 4 is for the case of an FLV stream without a last @@ -3716,7 +3750,6 @@ pend = ptr + size + 4; /* use to return timestamp of last processed packet */ - uint32_t nTimeStamp = 0; /* audio (0x08), video (0x09) or metadata (0x12) packets : * construct 11 byte header then add rtmp packet's data */ @@ -3756,7 +3789,7 @@ } memcpy(ptr, packetBody, nPacketLen); - unsigned int len = nPacketLen; + len = nPacketLen; /* correct tagSize and obtain timestamp if we have an FLV stream */ if (packet.m_packetType == 0x16) Index: librtmp/rtmp_sys.h =================================================================== --- librtmp/rtmp_sys.h (revision 426) +++ librtmp/rtmp_sys.h (working copy) @@ -21,6 +21,10 @@ * http://www.gnu.org/copyleft/lgpl.html */ +#ifdef _MSC_VER +#include +#endif + #ifdef WIN32 #include #define GetSockError() WSAGetLastError() @@ -29,7 +33,8 @@ #define sleep(n) Sleep(n*1000) #define msleep(n) Sleep(n) #define socklen_t int -#define SET_RCVTIMEO(tv,s) int tv = s*1000 +#define DECL_RCVTIMEO(tv) int tv +#define SET_RCVTIMEO(tv,s) tv = s*1000 #else #include #include @@ -43,7 +48,8 @@ #undef closesocket #define closesocket(s) close(s) #define msleep(n) usleep(n*1000) -#define SET_RCVTIMEO(tv,s) struct timeval tv = {s,0} +#define DECL_RCVTIMEO(tv) struct timeval tv +#define SET_RCVTIMEO(tv,s) tv = {s,0} #endif #include "rtmp.h" Index: msvc_compat/include/msvc_compat.h =================================================================== --- msvc_compat/include/msvc_compat.h (revision 0) +++ msvc_compat/include/msvc_compat.h (revision 0) @@ -0,0 +1,5 @@ + +#define strncasecmp _strnicmp +#define strcasecmp _stricmp +#define snprintf _snprintf +#define strdup _strdup Index: msvc_compat/include/stdbool.h =================================================================== --- msvc_compat/include/stdbool.h (revision 0) +++ msvc_compat/include/stdbool.h (revision 0) @@ -0,0 +1,28 @@ +#ifndef _STDBOOL_H +#define _STDBOOL_H + +#include "stdint.h" + +/* C99 Boolean types for compilers without C99 support */ +/* http://www.opengroup.org/onlinepubs/009695399/basedefs/stdbool.h.html */ +#if !defined(__cplusplus) + +#if !defined(__GNUC__) +/* _Bool builtin type is included in GCC */ +/* ISO C Standard: 5.2.5 An object declared as +type _Bool is large enough to store +the values 0 and 1. */ +/* We choose 8 bit to match C++ */ +/* It must also promote to integer */ +typedef int8_t _Bool; +#endif + +/* ISO C Standard: 7.16 Boolean type */ +#define bool _Bool +#define true 1 +#define false 0 +#define __bool_true_false_are_defined 1 + +#endif + +#endif \ No newline at end of file Index: msvc_compat/include/stdint.h =================================================================== --- msvc_compat/include/stdint.h (revision 0) +++ msvc_compat/include/stdint.h (revision 0) @@ -0,0 +1,247 @@ +// ISO C9x compliant stdint.h for Microsoft Visual Studio +// Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124 +// +// Copyright (c) 2006-2008 Alexander Chemeris +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// 3. The name of the author may be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED +// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO +// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +/////////////////////////////////////////////////////////////////////////////// + +#ifndef _MSC_VER // [ +#error "Use this header only with Microsoft Visual C++ compilers!" +#endif // _MSC_VER ] + +#ifndef _MSC_STDINT_H_ // [ +#define _MSC_STDINT_H_ + +#if _MSC_VER > 1000 +#pragma once +#endif + +#include + +// For Visual Studio 6 in C++ mode and for many Visual Studio versions when +// compiling for ARM we should wrap include with 'extern "C++" {}' +// or compiler give many errors like this: +// error C2733: second C linkage of overloaded function 'wmemchr' not allowed +#ifdef __cplusplus +extern "C" { +#endif +# include +#ifdef __cplusplus +} +#endif + +// Define _W64 macros to mark types changing their size, like intptr_t. +#ifndef _W64 +# if !defined(__midl) && (defined(_X86_) || defined(_M_IX86)) && _MSC_VER >= 1300 +# define _W64 __w64 +# else +# define _W64 +# endif +#endif + + +// 7.18.1 Integer types + +// 7.18.1.1 Exact-width integer types + +// Visual Studio 6 and Embedded Visual C++ 4 doesn't +// realize that, e.g. char has the same size as __int8 +// so we give up on __intX for them. +#if (_MSC_VER < 1300) + typedef char int8_t; + typedef short int16_t; + typedef int int32_t; + typedef unsigned char uint8_t; + typedef unsigned short uint16_t; + typedef unsigned int uint32_t; +#else + typedef __int8 int8_t; + typedef __int16 int16_t; + typedef __int32 int32_t; + typedef unsigned __int8 uint8_t; + typedef unsigned __int16 uint16_t; + typedef unsigned __int32 uint32_t; +#endif +typedef __int64 int64_t; +typedef unsigned __int64 uint64_t; + + +// 7.18.1.2 Minimum-width integer types +typedef int8_t int_least8_t; +typedef int16_t int_least16_t; +typedef int32_t int_least32_t; +typedef int64_t int_least64_t; +typedef uint8_t uint_least8_t; +typedef uint16_t uint_least16_t; +typedef uint32_t uint_least32_t; +typedef uint64_t uint_least64_t; + +// 7.18.1.3 Fastest minimum-width integer types +typedef int8_t int_fast8_t; +typedef int16_t int_fast16_t; +typedef int32_t int_fast32_t; +typedef int64_t int_fast64_t; +typedef uint8_t uint_fast8_t; +typedef uint16_t uint_fast16_t; +typedef uint32_t uint_fast32_t; +typedef uint64_t uint_fast64_t; + +// 7.18.1.4 Integer types capable of holding object pointers +#ifdef _WIN64 // [ + typedef __int64 intptr_t; + typedef unsigned __int64 uintptr_t; +#else // _WIN64 ][ + typedef _W64 int intptr_t; + typedef _W64 unsigned int uintptr_t; +#endif // _WIN64 ] + +// 7.18.1.5 Greatest-width integer types +typedef int64_t intmax_t; +typedef uint64_t uintmax_t; + + +// 7.18.2 Limits of specified-width integer types + +#if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) // [ See footnote 220 at page 257 and footnote 221 at page 259 + +// 7.18.2.1 Limits of exact-width integer types +#define INT8_MIN ((int8_t)_I8_MIN) +#define INT8_MAX _I8_MAX +#define INT16_MIN ((int16_t)_I16_MIN) +#define INT16_MAX _I16_MAX +#define INT32_MIN ((int32_t)_I32_MIN) +#define INT32_MAX _I32_MAX +#define INT64_MIN ((int64_t)_I64_MIN) +#define INT64_MAX _I64_MAX +#define UINT8_MAX _UI8_MAX +#define UINT16_MAX _UI16_MAX +#define UINT32_MAX _UI32_MAX +#define UINT64_MAX _UI64_MAX + +// 7.18.2.2 Limits of minimum-width integer types +#define INT_LEAST8_MIN INT8_MIN +#define INT_LEAST8_MAX INT8_MAX +#define INT_LEAST16_MIN INT16_MIN +#define INT_LEAST16_MAX INT16_MAX +#define INT_LEAST32_MIN INT32_MIN +#define INT_LEAST32_MAX INT32_MAX +#define INT_LEAST64_MIN INT64_MIN +#define INT_LEAST64_MAX INT64_MAX +#define UINT_LEAST8_MAX UINT8_MAX +#define UINT_LEAST16_MAX UINT16_MAX +#define UINT_LEAST32_MAX UINT32_MAX +#define UINT_LEAST64_MAX UINT64_MAX + +// 7.18.2.3 Limits of fastest minimum-width integer types +#define INT_FAST8_MIN INT8_MIN +#define INT_FAST8_MAX INT8_MAX +#define INT_FAST16_MIN INT16_MIN +#define INT_FAST16_MAX INT16_MAX +#define INT_FAST32_MIN INT32_MIN +#define INT_FAST32_MAX INT32_MAX +#define INT_FAST64_MIN INT64_MIN +#define INT_FAST64_MAX INT64_MAX +#define UINT_FAST8_MAX UINT8_MAX +#define UINT_FAST16_MAX UINT16_MAX +#define UINT_FAST32_MAX UINT32_MAX +#define UINT_FAST64_MAX UINT64_MAX + +// 7.18.2.4 Limits of integer types capable of holding object pointers +#ifdef _WIN64 // [ +# define INTPTR_MIN INT64_MIN +# define INTPTR_MAX INT64_MAX +# define UINTPTR_MAX UINT64_MAX +#else // _WIN64 ][ +# define INTPTR_MIN INT32_MIN +# define INTPTR_MAX INT32_MAX +# define UINTPTR_MAX UINT32_MAX +#endif // _WIN64 ] + +// 7.18.2.5 Limits of greatest-width integer types +#define INTMAX_MIN INT64_MIN +#define INTMAX_MAX INT64_MAX +#define UINTMAX_MAX UINT64_MAX + +// 7.18.3 Limits of other integer types + +#ifdef _WIN64 // [ +# define PTRDIFF_MIN _I64_MIN +# define PTRDIFF_MAX _I64_MAX +#else // _WIN64 ][ +# define PTRDIFF_MIN _I32_MIN +# define PTRDIFF_MAX _I32_MAX +#endif // _WIN64 ] + +#define SIG_ATOMIC_MIN INT_MIN +#define SIG_ATOMIC_MAX INT_MAX + +#ifndef SIZE_MAX // [ +# ifdef _WIN64 // [ +# define SIZE_MAX _UI64_MAX +# else // _WIN64 ][ +# define SIZE_MAX _UI32_MAX +# endif // _WIN64 ] +#endif // SIZE_MAX ] + +// WCHAR_MIN and WCHAR_MAX are also defined in +#ifndef WCHAR_MIN // [ +# define WCHAR_MIN 0 +#endif // WCHAR_MIN ] +#ifndef WCHAR_MAX // [ +# define WCHAR_MAX _UI16_MAX +#endif // WCHAR_MAX ] + +#define WINT_MIN 0 +#define WINT_MAX _UI16_MAX + +#endif // __STDC_LIMIT_MACROS ] + + +// 7.18.4 Limits of other integer types + +#if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) // [ See footnote 224 at page 260 + +// 7.18.4.1 Macros for minimum-width integer constants + +#define INT8_C(val) val##i8 +#define INT16_C(val) val##i16 +#define INT32_C(val) val##i32 +#define INT64_C(val) val##i64 + +#define UINT8_C(val) val##ui8 +#define UINT16_C(val) val##ui16 +#define UINT32_C(val) val##ui32 +#define UINT64_C(val) val##ui64 + +// 7.18.4.2 Macros for greatest-width integer constants +#define INTMAX_C INT64_C +#define UINTMAX_C UINT64_C + +#endif // __STDC_CONSTANT_MACROS ] + + +#endif // _MSC_STDINT_H_ ] Index: project/VS2008/librtmp/librtmp.vcproj =================================================================== --- project/VS2008/librtmp/librtmp.vcproj (revision 0) +++ project/VS2008/librtmp/librtmp.vcproj (revision 0) @@ -0,0 +1,237 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Index: project/VS2008/rtmpdump.sln =================================================================== --- project/VS2008/rtmpdump.sln (revision 0) +++ project/VS2008/rtmpdump.sln (revision 0) @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 10.00 +# Visual Studio 2008 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "librtmp", "librtmp\librtmp.vcproj", "{6F40418D-B92E-41B7-AB78-99C9F67402E7}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {6F40418D-B92E-41B7-AB78-99C9F67402E7}.Debug|Win32.ActiveCfg = Debug|Win32 + {6F40418D-B92E-41B7-AB78-99C9F67402E7}.Debug|Win32.Build.0 = Debug|Win32 + {6F40418D-B92E-41B7-AB78-99C9F67402E7}.Release|Win32.ActiveCfg = Release|Win32 + {6F40418D-B92E-41B7-AB78-99C9F67402E7}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal