1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

merge from allspace srs-librtmp for win vs2010. 2.0.36

This commit is contained in:
winlin 2014-11-28 10:33:36 +08:00
parent 14fca601f9
commit 7f121efd7a
6 changed files with 68 additions and 53 deletions

View file

@ -112,7 +112,7 @@ int main(int argc, char** argv)
printf("version: %d.%d.%d\n", srs_version_major(), srs_version_minor(), srs_version_revision()); printf("version: %d.%d.%d\n", srs_version_major(), srs_version_minor(), srs_version_revision());
rtmp = srs_rtmp_create("rtmp://ossrs.net/live/livestream"); rtmp = srs_rtmp_create("rtmp://ossrs.net/live/livestream");
srs_lib_trace("create rtmp success"); srs_human_trace("create rtmp success");
srs_rtmp_destroy(rtmp); srs_rtmp_destroy(rtmp);
return 0; return 0;

View file

@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// current release version // current release version
#define VERSION_MAJOR 2 #define VERSION_MAJOR 2
#define VERSION_MINOR 0 #define VERSION_MINOR 0
#define VERSION_REVISION 35 #define VERSION_REVISION 36
// server info. // server info.
#define RTMP_SIG_SRS_KEY "SRS" #define RTMP_SIG_SRS_KEY "SRS"
#define RTMP_SIG_SRS_ROLE "origin/edge server" #define RTMP_SIG_SRS_ROLE "origin/edge server"

View file

@ -45,22 +45,22 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
SimpleSocketStream::SimpleSocketStream() SimpleSocketStream::SimpleSocketStream()
{ {
fd = -1; SOCKET_RESET(fd);
send_timeout = recv_timeout = ST_UTIME_NO_TIMEOUT; send_timeout = recv_timeout = ST_UTIME_NO_TIMEOUT;
recv_bytes = send_bytes = 0; recv_bytes = send_bytes = 0;
SOCKET_SETUP();
} }
SimpleSocketStream::~SimpleSocketStream() SimpleSocketStream::~SimpleSocketStream()
{ {
if (fd != -1) { SOCKET_CLOSE(fd);
::close(fd); SOCKET_CLEANUP();
fd = -1;
}
} }
int SimpleSocketStream::create_socket() int SimpleSocketStream::create_socket()
{ {
if((fd = ::socket(AF_INET, SOCK_STREAM, 0)) < 0){ fd = ::socket(AF_INET, SOCK_STREAM, 0);
if (!SOCKET_VALID(fd)) {
return ERROR_SOCKET_CREATE; return ERROR_SOCKET_CREATE;
} }
@ -95,12 +95,12 @@ int SimpleSocketStream::read(void* buf, size_t size, ssize_t* nread)
// On success a non-negative integer indicating the number of bytes actually read is returned // On success a non-negative integer indicating the number of bytes actually read is returned
// (a value of 0 means the network connection is closed or end of file is reached). // (a value of 0 means the network connection is closed or end of file is reached).
if (nb_read <= 0) { if (nb_read <= 0) {
if (nb_read < 0 && errno == ETIME) { if (nb_read < 0 && SOCKET_ERRNO() == SOCKET_ETIME) {
return ERROR_SOCKET_TIMEOUT; return ERROR_SOCKET_TIMEOUT;
} }
if (nb_read == 0) { if (nb_read == 0) {
errno = ECONNRESET; errno = SOCKET_ECONNRESET;
} }
return ERROR_SOCKET_READ; return ERROR_SOCKET_READ;
@ -158,7 +158,7 @@ int SimpleSocketStream::writev(const iovec *iov, int iov_size, ssize_t* nwrite)
// returned, and errno is set appropriately. // returned, and errno is set appropriately.
if (nb_write <= 0) { if (nb_write <= 0) {
// @see https://github.com/winlinvip/simple-rtmp-server/issues/200 // @see https://github.com/winlinvip/simple-rtmp-server/issues/200
if (nb_write < 0 && errno == ETIME) { if (nb_write < 0 && SOCKET_ERRNO() == SOCKET_ETIME) {
return ERROR_SOCKET_TIMEOUT; return ERROR_SOCKET_TIMEOUT;
} }
@ -215,7 +215,7 @@ int SimpleSocketStream::write(void* buf, size_t size, ssize_t* nwrite)
if (nb_write <= 0) { if (nb_write <= 0) {
// @see https://github.com/winlinvip/simple-rtmp-server/issues/200 // @see https://github.com/winlinvip/simple-rtmp-server/issues/200
if (nb_write < 0 && errno == ETIME) { if (nb_write < 0 && SOCKET_ERRNO() == SOCKET_ETIME) {
return ERROR_SOCKET_TIMEOUT; return ERROR_SOCKET_TIMEOUT;
} }

View file

@ -31,6 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <srs_core.hpp> #include <srs_core.hpp>
#include <srs_protocol_io.hpp> #include <srs_protocol_io.hpp>
#include <srs_librtmp.hpp>
/** /**
* simple socket stream, * simple socket stream,
@ -43,7 +44,7 @@ private:
int64_t send_timeout; int64_t send_timeout;
int64_t recv_bytes; int64_t recv_bytes;
int64_t send_bytes; int64_t send_bytes;
int fd; SOCKET fd;
public: public:
SimpleSocketStream(); SimpleSocketStream();
virtual ~SimpleSocketStream(); virtual ~SimpleSocketStream();

View file

@ -133,47 +133,29 @@ struct Context
return 0; return 0;
} }
int open(const char *pathname, int flags) int socket_setup()
{ {
return open(pathname, flags, 0); WORD wVersionRequested;
} WSADATA wsaData;
int err;
int open(const char *pathname, int flags, mode_t mode) /* Use the MAKEWORD(lowbyte, highbyte) macro declared in Windef.h */
{ wVersionRequested = MAKEWORD(2, 2);
FILE* file = NULL;
if ((flags & O_RDONLY) == O_RDONLY) { err = WSAStartup(wVersionRequested, &wsaData);
file = fopen(pathname, "r"); if (err != 0) {
} else { /* Tell the user that we could not find a usable */
file = fopen(pathname, "w+"); /* Winsock DLL. */
} //printf("WSAStartup failed with error: %d\n", err);
if (file == NULL) {
return -1; return -1;
} }
return 0;
return (int)file;
} }
int close(int fd) int socket_cleanup()
{ {
FILE* file = (FILE*)fd; WSACleanup();
return fclose(file); return 0;
}
off_t lseek(int fd, off_t offset, int whence)
{
return (off_t)fseek((FILE*)fd, offset, whence);
}
ssize_t write(int fd, const void *buf, size_t count)
{
return (ssize_t)fwrite(buf, count, 1, (FILE*)fd);
}
ssize_t read(int fd, void *buf, size_t count)
{
return (ssize_t)fread(buf, count, 1, (FILE*)fd);
} }
pid_t getpid(void) pid_t getpid(void)

View file

@ -31,7 +31,23 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <sys/types.h> #include <sys/types.h>
// for srs-librtmp, @see https://github.com/winlinvip/simple-rtmp-server/issues/213 // for srs-librtmp, @see https://github.com/winlinvip/simple-rtmp-server/issues/213
#ifdef _WIN32 #ifndef _WIN32
#define SOCKET_ETIME ETIME
#define SOCKET_ECONNRESET ECONNRESET
#define SOCKET int
#define SOCKET_ERRNO() errno
#define SOCKET_RESET(fd) fd = -1; (void)0
#define SOCKET_CLOSE(fd) \
if (fd > 0) {\
::close(fd); \
fd = -1; \
} \
(void)0
#define SOCKET_VALID(x) (x > 0)
#define SOCKET_SETUP() (void)0
#define SOCKET_CLEANUP() (void)0
#else
#define _CRT_SECURE_NO_WARNINGS #define _CRT_SECURE_NO_WARNINGS
typedef unsigned long long u_int64_t; typedef unsigned long long u_int64_t;
typedef long long int64_t; typedef long long int64_t;
@ -50,6 +66,17 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <windows.h> #include <windows.h>
int gettimeofday(struct timeval* tv, struct timezone* tz); int gettimeofday(struct timeval* tv, struct timezone* tz);
#define PRId64 "lld" #define PRId64 "lld"
#define SOCKET_ETIME WSAETIMEDOUT
#define SOCKET_ECONNRESET WSAECONNRESET
#define SOCKET_ERRNO() WSAGetLastError()
#define SOCKET_RESET(x) x=INVALID_SOCKET
#define SOCKET_CLOSE(x) if(x!=INVALID_SOCKET){::closesocket(x);x=INVALID_SOCKET;}
#define SOCKET_VALID(x) (x!=INVALID_SOCKET)
#define SOCKET_BUFF(x) ((char*)x)
#define SOCKET_SETUP() socket_setup()
#define SOCKET_CLEANUP() socket_cleanup()
typedef int socklen_t; typedef int socklen_t;
const char *inet_ntop(int af, const void *src, char *dst, socklen_t size); const char *inet_ntop(int af, const void *src, char *dst, socklen_t size);
typedef int mode_t; typedef int mode_t;
@ -58,18 +85,23 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#define S_IRGRP 0 #define S_IRGRP 0
#define S_IWGRP 0 #define S_IWGRP 0
#define S_IROTH 0 #define S_IROTH 0
int open(const char *pathname, int flags);
int open(const char *pathname, int flags, mode_t mode); #include <io.h>
int close(int fd); #include <fcntl.h>
off_t lseek(int fd, off_t offset, int whence); #define open _open
ssize_t write(int fd, const void *buf, size_t count); #define close _close
ssize_t read(int fd, void *buf, size_t count); #define lseek _lseek
#define write _write
#define read _read
typedef int pid_t; typedef int pid_t;
pid_t getpid(void); pid_t getpid(void);
#define snprintf _snprintf #define snprintf _snprintf
ssize_t writev(int fd, const struct iovec *iov, int iovcnt); ssize_t writev(int fd, const struct iovec *iov, int iovcnt);
typedef int64_t useconds_t; typedef int64_t useconds_t;
int usleep(useconds_t usec); int usleep(useconds_t usec);
int socket_setup();
int socket_cleanup();
#endif #endif
/** /**