Skip to content

Commit

Permalink
Support build srs-librtmp by VS2015. 2.0.267
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Dec 23, 2019
1 parent fde1175 commit 3166286
Show file tree
Hide file tree
Showing 12 changed files with 74 additions and 38 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
* <strong>v2.0, 2019-11-29, [2.0 release7(2.0.265)][r2.0r7] released. 86994 lines.</strong>
* 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
Expand Down
19 changes: 11 additions & 8 deletions trunk/src/core/srs_core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <srs_auto_headers.hpp>
Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions trunk/src/kernel/srs_kernel_flv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
8 changes: 4 additions & 4 deletions trunk/src/kernel/srs_kernel_utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
31 changes: 25 additions & 6 deletions trunk/src/libs/srs_lib_simple_socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -191,17 +201,26 @@ 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);

sec = srs_max(0, sec);
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;

Expand Down
21 changes: 14 additions & 7 deletions trunk/src/libs/srs_librtmp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <windows.h>
// the type used by this header for windows.
#if defined(_MSC_VER)
#include <stdint.h>
#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 */
Expand Down Expand Up @@ -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 <time.h>
int gettimeofday(struct timeval* tv, struct timezone* tz);
#define PRId64 "lld"
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/protocol/srs_protocol_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions trunk/src/protocol/srs_raw_avc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/protocol/srs_rtmp_amf0.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 9 additions & 4 deletions trunk/src/protocol/srs_rtmp_stack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ SrsProtocol::SrsProtocol(ISrsProtocolReaderWriter* io)

cs_cache[cid] = cs;
}

out_c0c3_caches = new char[SRS_CONSTS_C0C3_HEADERS_MAX];
}

SrsProtocol::~SrsProtocol()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);;
Expand Down Expand Up @@ -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));

Expand Down
3 changes: 2 additions & 1 deletion trunk/src/protocol/srs_rtmp_stack.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,8 @@ class SrsProtocol
*
* @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;
/**
Expand Down
4 changes: 2 additions & 2 deletions trunk/src/utest/srs_utest_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 3166286

Please sign in to comment.