diff --git a/README.md b/README.md index 7ed8b1474..e72f55032 100755 --- a/README.md +++ b/README.md @@ -338,6 +338,7 @@ Remark: ## History +* v2.0, 2019-12-23, Fix [srs-librtmp #25](https://github.com/ossrs/srs-librtmp/issues/25), build srs-librtmp on windows. 2.0.267 * v2.0, 2019-12-13, Support openssl versions greater than 1.1.0. 2.0.266 * v2.0, 2019-11-29, [2.0 release7(2.0.265)][r2.0r7] released. 86994 lines. * v2.0, 2019-11-29, For [srs-docker](https://github.com/ossrs/srs-docker/tree/master/2.0), install Cherrypy without sudo. 2.0.265 diff --git a/trunk/src/core/srs_core.hpp b/trunk/src/core/srs_core.hpp index e2c7c7ccd..2ba1b4cb4 100644 --- a/trunk/src/core/srs_core.hpp +++ b/trunk/src/core/srs_core.hpp @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // current release version #define VERSION_MAJOR 2 #define VERSION_MINOR 0 -#define VERSION_REVISION 266 +#define VERSION_REVISION 267 // generated by configure, only macros. #include @@ -127,13 +127,16 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. className(const className&); \ className& operator= (const className&) -/** - * important check for st(state-threads), - * only support the following cpus: i386/amd64/x86_64/arm - * @reamrk to patch ST for arm, read https://github.com/ossrs/state-threads/issues/1 - */ -#if !defined(__amd64__) && !defined(__x86_64__) && !defined(__i386__) && !defined(__arm__) - #error "only support i386/amd64/x86_64/arm cpu" +// For librtmp, it is pure c++ and supports all OS. +#ifndef SRS_EXPORT_LIBRTMP + /** + * important check for st(state-threads), + * only support the following cpus: i386/amd64/x86_64/arm + * @reamrk to patch ST for arm, read https://github.com/ossrs/state-threads/issues/1 + */ + #if !defined(__amd64__) && !defined(__x86_64__) && !defined(__i386__) && !defined(__arm__) + #error "only support i386/amd64/x86_64/arm cpu" + #endif #endif #endif diff --git a/trunk/src/kernel/srs_kernel_flv.cpp b/trunk/src/kernel/srs_kernel_flv.cpp index 9d71747c9..a79cea810 100644 --- a/trunk/src/kernel/srs_kernel_flv.cpp +++ b/trunk/src/kernel/srs_kernel_flv.cpp @@ -303,12 +303,12 @@ int SrsSharedPtrMessage::chunk_header(char* cache, int nb_cache, bool c0) { if (c0) { return srs_chunk_header_c0( - ptr->header.perfer_cid, timestamp, ptr->header.payload_length, + ptr->header.perfer_cid, (u_int32_t)timestamp, ptr->header.payload_length, ptr->header.message_type, stream_id, cache, nb_cache); } else { return srs_chunk_header_c3( - ptr->header.perfer_cid, timestamp, + ptr->header.perfer_cid, (u_int32_t)timestamp, cache, nb_cache); } } diff --git a/trunk/src/kernel/srs_kernel_utility.cpp b/trunk/src/kernel/srs_kernel_utility.cpp index 4e75b06f2..8abb16e61 100644 --- a/trunk/src/kernel/srs_kernel_utility.cpp +++ b/trunk/src/kernel/srs_kernel_utility.cpp @@ -353,7 +353,7 @@ int srs_do_create_dir_recursively(string dir) mode_t mode = S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IWGRP|S_IXGRP|S_IROTH|S_IXOTH; if (::mkdir(dir.c_str(), mode) < 0) { #else - if (::mkdir(dir.c_str()) < 0) { + if (::_mkdir(dir.c_str()) < 0) { #endif if (errno == EEXIST) { return ERROR_SYSTEM_DIR_EXISTS; @@ -833,9 +833,9 @@ int srs_chunk_header_c0( *p++ = pp[1]; *p++ = pp[0]; } else { - *p++ = 0xFF; - *p++ = 0xFF; - *p++ = 0xFF; + *p++ = (char)0xFF; + *p++ = (char)0xFF; + *p++ = (char)0xFF; } // message_length, 3bytes, big-endian diff --git a/trunk/src/libs/srs_lib_simple_socket.cpp b/trunk/src/libs/srs_lib_simple_socket.cpp index 79d2bcf38..e025a1c7a 100644 --- a/trunk/src/libs/srs_lib_simple_socket.cpp +++ b/trunk/src/libs/srs_lib_simple_socket.cpp @@ -163,17 +163,27 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. int srs_hijack_io_set_recv_timeout(srs_hijack_io_t ctx, int64_t timeout_us) { SrsBlockSyncSocket* skt = (SrsBlockSyncSocket*)ctx; - + +#ifdef _WIN32 + DWORD tv = (DWORD)(timeout_us/1000); + + // To convert tv to const char* to make VS2015 happy. + if (setsockopt(skt->fd, SOL_SOCKET, SO_SNDTIMEO, (const char*)&tv, sizeof(tv)) == -1) { + return SOCKET_ERRNO(); + } +#else int sec = (int)(timeout_us / 1000000LL); int microsec = (int)(timeout_us % 1000000LL); - + sec = srs_max(0, sec); microsec = srs_max(0, microsec); - + struct timeval tv = { sec , microsec }; - if (setsockopt(skt->fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) == -1) { + if (setsockopt(skt->fd, SOL_SOCKET, SO_RCVTIMEO, tvv, sizeof(tv)) == -1) { return SOCKET_ERRNO(); } +#endif + skt->recv_timeout = timeout_us; return ERROR_SUCCESS; @@ -191,7 +201,15 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. int srs_hijack_io_set_send_timeout(srs_hijack_io_t ctx, int64_t timeout_us) { SrsBlockSyncSocket* skt = (SrsBlockSyncSocket*)ctx; - + +#ifdef _WIN32 + DWORD tv = (DWORD)(timeout_us/1000); + + // To convert tv to const char* to make VS2015 happy. + if (setsockopt(skt->fd, SOL_SOCKET, SO_SNDTIMEO, (const char*)&tv, sizeof(tv)) == -1) { + return SOCKET_ERRNO(); + } +#else int sec = (int)(timeout_us / 1000000LL); int microsec = (int)(timeout_us % 1000000LL); @@ -199,9 +217,10 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. microsec = srs_max(0, microsec); struct timeval tv = { sec , microsec }; - if (setsockopt(skt->fd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv)) == -1) { + if (setsockopt(skt->fd, SOL_SOCKET, SO_SNDTIMEO, tvv, sizeof(tv)) == -1) { return SOCKET_ERRNO(); } +#endif skt->send_timeout = timeout_us; diff --git a/trunk/src/libs/srs_librtmp.hpp b/trunk/src/libs/srs_librtmp.hpp index f70de7725..618b71e8c 100644 --- a/trunk/src/libs/srs_librtmp.hpp +++ b/trunk/src/libs/srs_librtmp.hpp @@ -43,18 +43,24 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *************************************************************/ // for srs-librtmp, @see https://github.com/ossrs/srs/issues/213 #ifdef _WIN32 + // To disable some security warnings. + #define _CRT_SECURE_NO_WARNINGS // include windows first. #include // the type used by this header for windows. + #if defined(_MSC_VER) + #include + #else + typedef char int8_t; + typedef short int16_t; + typedef int int32_t; + typedef long long int64_t; + #endif typedef unsigned long long u_int64_t; - typedef long long int64_t; typedef unsigned int u_int32_t; typedef u_int32_t uint32_t; - typedef int int32_t; typedef unsigned char u_int8_t; - typedef char int8_t; typedef unsigned short u_int16_t; - typedef short int16_t; typedef int64_t ssize_t; struct iovec { void *iov_base; /* Starting address */ @@ -1051,7 +1057,6 @@ typedef void* srs_hijack_io_t; // for srs-librtmp, @see https://github.com/ossrs/srs/issues/213 #ifdef _WIN32 // for time. - #define _CRT_SECURE_NO_WARNINGS #include int gettimeofday(struct timeval* tv, struct timezone* tz); #define PRId64 "lld" @@ -1094,8 +1099,10 @@ typedef void* srs_hijack_io_t; int socket_setup(); int socket_cleanup(); - // others. - #define snprintf _snprintf + // snprintf is defined in VS2015, so we only define this macro before that. + #if defined(_MSC_VER) && _MSC_VER < 1900 + #define snprintf _snprintf + #endif #endif #ifdef __cplusplus diff --git a/trunk/src/protocol/srs_protocol_buffer.cpp b/trunk/src/protocol/srs_protocol_buffer.cpp index 8b644fa62..4543ae823 100755 --- a/trunk/src/protocol/srs_protocol_buffer.cpp +++ b/trunk/src/protocol/srs_protocol_buffer.cpp @@ -201,7 +201,7 @@ int SrsFastBuffer::grow(ISrsBufferReader* reader, int required_size) // we just move the ptr to next. srs_assert((int)nread > 0); end += nread; - nb_free_space -= nread; + nb_free_space -= (int)nread; } return ret; diff --git a/trunk/src/protocol/srs_raw_avc.cpp b/trunk/src/protocol/srs_raw_avc.cpp index aaf1f8fb2..26dc8933b 100644 --- a/trunk/src/protocol/srs_raw_avc.cpp +++ b/trunk/src/protocol/srs_raw_avc.cpp @@ -200,7 +200,7 @@ int SrsRawH264Stream::mux_sequence_header(string sps, string pps, u_int32_t dts, // numOfSequenceParameterSets, always 1 stream.write_1bytes(0x01); // sequenceParameterSetLength - stream.write_2bytes(sps.length()); + stream.write_2bytes((int16_t)sps.length()); // sequenceParameterSetNALUnit stream.write_string(sps); } @@ -211,7 +211,7 @@ int SrsRawH264Stream::mux_sequence_header(string sps, string pps, u_int32_t dts, // numOfPictureParameterSets, always 1 stream.write_1bytes(0x01); // pictureParameterSetLength - stream.write_2bytes(pps.length()); + stream.write_2bytes((int16_t)pps.length()); // pictureParameterSetNALUnit stream.write_string(pps); } diff --git a/trunk/src/protocol/srs_rtmp_amf0.cpp b/trunk/src/protocol/srs_rtmp_amf0.cpp index e2a041bb0..a8da45bb4 100644 --- a/trunk/src/protocol/srs_rtmp_amf0.cpp +++ b/trunk/src/protocol/srs_rtmp_amf0.cpp @@ -1842,7 +1842,7 @@ namespace _srs_internal srs_error("amf0 write string length failed. ret=%d", ret); return ret; } - stream->write_2bytes(value.length()); + stream->write_2bytes((int16_t)value.length()); srs_verbose("amf0 write string length success. len=%d", (int)value.length()); // empty string diff --git a/trunk/src/protocol/srs_rtmp_stack.cpp b/trunk/src/protocol/srs_rtmp_stack.cpp index dac4cd2eb..ca5867f3d 100644 --- a/trunk/src/protocol/srs_rtmp_stack.cpp +++ b/trunk/src/protocol/srs_rtmp_stack.cpp @@ -244,6 +244,8 @@ SrsProtocol::SrsProtocol(ISrsProtocolReaderWriter* io) cs_cache[cid] = cs; } + + out_c0c3_caches = new char[SRS_CONSTS_C0C3_HEADERS_MAX]; } SrsProtocol::~SrsProtocol() @@ -282,6 +284,8 @@ SrsProtocol::~SrsProtocol() srs_freep(cs); } srs_freepa(cs_cache); + + srs_freepa(out_c0c3_caches); } void SrsProtocol::set_auto_response(bool v) @@ -656,12 +660,12 @@ int SrsProtocol::do_simple_send(SrsMessageHeader* mh, char* payload, int size) int nbh = 0; if (p == payload) { nbh = srs_chunk_header_c0( - mh->perfer_cid, mh->timestamp, mh->payload_length, + mh->perfer_cid, (uint32_t)mh->timestamp, mh->payload_length, mh->message_type, mh->stream_id, c0c3, sizeof(c0c3)); } else { nbh = srs_chunk_header_c3( - mh->perfer_cid, mh->timestamp, + mh->perfer_cid, (uint32_t)mh->timestamp, c0c3, sizeof(c0c3)); } srs_assert(nbh > 0);; @@ -2566,8 +2570,9 @@ int SrsRtmpServer::response_connect_app(SrsRequest *req, const char* server_ip) int ret = ERROR_SUCCESS; SrsConnectAppResPacket* pkt = new SrsConnectAppResPacket(); - - pkt->props->set("fmsVer", SrsAmf0Any::str("FMS/"RTMP_SIG_FMS_VER)); + + // @remark For windows, there must be a space between const string and macro. + pkt->props->set("fmsVer", SrsAmf0Any::str("FMS/" RTMP_SIG_FMS_VER)); pkt->props->set("capabilities", SrsAmf0Any::number(127)); pkt->props->set("mode", SrsAmf0Any::number(1)); diff --git a/trunk/src/protocol/srs_rtmp_stack.hpp b/trunk/src/protocol/srs_rtmp_stack.hpp index 9900000dc..bc21d1d6e 100644 --- a/trunk/src/protocol/srs_rtmp_stack.hpp +++ b/trunk/src/protocol/srs_rtmp_stack.hpp @@ -268,7 +268,8 @@ private: * * @remark, the c0c3 cache cannot be realloc. */ - char out_c0c3_caches[SRS_CONSTS_C0C3_HEADERS_MAX]; + // To allocate it in heap to make VS2015 happy. + char* out_c0c3_caches; // whether warned user to increase the c0c3 header cache. bool warned_c0c3_cache_dry; /** diff --git a/trunk/src/utest/srs_utest_config.cpp b/trunk/src/utest/srs_utest_config.cpp index 033aa3ec2..ce697623a 100644 --- a/trunk/src/utest/srs_utest_config.cpp +++ b/trunk/src/utest/srs_utest_config.cpp @@ -840,10 +840,10 @@ VOID TEST(ConfigMainTest, CheckConf_max_connections) MockSrsConfig conf; EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"max_connections 0;")); } - + if (true) { MockSrsConfig conf; - EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"max_connections 1000000;")); + EXPECT_TRUE(ERROR_SUCCESS != conf.parse(_MIN_OK_CONF"max_connections 100000000;")); } if (true) {