winlin

refine the macros for windows of srs-librtmp

@@ -27,6 +27,34 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -27,6 +27,34 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 27
28 // for srs-librtmp, @see https://github.com/winlinvip/simple-rtmp-server/issues/213 28 // for srs-librtmp, @see https://github.com/winlinvip/simple-rtmp-server/issues/213
29 #ifndef _WIN32 29 #ifndef _WIN32
  30 + #define SOCKET_ETIME ETIME
  31 + #define SOCKET_ECONNRESET ECONNRESET
  32 +
  33 + #define SOCKET_ERRNO() errno
  34 + #define SOCKET_RESET(fd) fd = -1; (void)0
  35 + #define SOCKET_CLOSE(fd) \
  36 + if (fd > 0) {\
  37 + ::close(fd); \
  38 + fd = -1; \
  39 + } \
  40 + (void)0
  41 + #define SOCKET_VALID(x) (x > 0)
  42 + #define SOCKET_SETUP() (void)0
  43 + #define SOCKET_CLEANUP() (void)0
  44 +#else
  45 + #define SOCKET_ETIME WSAETIMEDOUT
  46 + #define SOCKET_ECONNRESET WSAECONNRESET
  47 + #define SOCKET_ERRNO() WSAGetLastError()
  48 + #define SOCKET_RESET(x) x=INVALID_SOCKET
  49 + #define SOCKET_CLOSE(x) if(x!=INVALID_SOCKET){::closesocket(x);x=INVALID_SOCKET;}
  50 + #define SOCKET_VALID(x) (x!=INVALID_SOCKET)
  51 + #define SOCKET_BUFF(x) ((char*)x)
  52 + #define SOCKET_SETUP() socket_setup()
  53 + #define SOCKET_CLEANUP() socket_cleanup()
  54 +#endif
  55 +
  56 +// for srs-librtmp, @see https://github.com/winlinvip/simple-rtmp-server/issues/213
  57 +#ifndef _WIN32
30 #include <unistd.h> 58 #include <unistd.h>
31 #include <sys/socket.h> 59 #include <sys/socket.h>
32 #include <netinet/in.h> 60 #include <netinet/in.h>
@@ -33,6 +33,11 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -33,6 +33,11 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 #include <srs_protocol_io.hpp> 33 #include <srs_protocol_io.hpp>
34 #include <srs_librtmp.hpp> 34 #include <srs_librtmp.hpp>
35 35
  36 +// for srs-librtmp, @see https://github.com/winlinvip/simple-rtmp-server/issues/213
  37 +#ifndef _WIN32
  38 + #define SOCKET int
  39 +#endif
  40 +
36 /** 41 /**
37 * simple socket stream, 42 * simple socket stream,
38 * use tcp socket, sync block mode, for client like srs-librtmp. 43 * use tcp socket, sync block mode, for client like srs-librtmp.
@@ -28,27 +28,11 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -28,27 +28,11 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 #include <srs_librtmp.h> 28 #include <srs_librtmp.h>
29 */ 29 */
30 30
31 -#include <sys/types.h>  
32 -  
33 // for srs-librtmp, @see https://github.com/winlinvip/simple-rtmp-server/issues/213 31 // for srs-librtmp, @see https://github.com/winlinvip/simple-rtmp-server/issues/213
34 -#ifndef _WIN32  
35 - #define SOCKET_ETIME ETIME  
36 - #define SOCKET_ECONNRESET ECONNRESET  
37 -  
38 - #define SOCKET int  
39 - #define SOCKET_ERRNO() errno  
40 - #define SOCKET_RESET(fd) fd = -1; (void)0  
41 - #define SOCKET_CLOSE(fd) \  
42 - if (fd > 0) {\  
43 - ::close(fd); \  
44 - fd = -1; \  
45 - } \  
46 - (void)0  
47 - #define SOCKET_VALID(x) (x > 0)  
48 - #define SOCKET_SETUP() (void)0  
49 - #define SOCKET_CLEANUP() (void)0  
50 -#else  
51 - #define _CRT_SECURE_NO_WARNINGS 32 +#ifdef _WIN32
  33 + // include windows first.
  34 + #include <windows.h>
  35 + // the type used by this header for windows.
52 typedef unsigned long long u_int64_t; 36 typedef unsigned long long u_int64_t;
53 typedef long long int64_t; 37 typedef long long int64_t;
54 typedef unsigned int u_int32_t; 38 typedef unsigned int u_int32_t;
@@ -62,48 +46,10 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -62,48 +46,10 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
62 void *iov_base; /* Starting address */ 46 void *iov_base; /* Starting address */
63 size_t iov_len; /* Number of bytes to transfer */ 47 size_t iov_len; /* Number of bytes to transfer */
64 }; 48 };
65 - #include <time.h>  
66 - #include <windows.h>  
67 - int gettimeofday(struct timeval* tv, struct timezone* tz);  
68 - #define PRId64 "lld"  
69 -  
70 - #define SOCKET_ETIME WSAETIMEDOUT  
71 - #define SOCKET_ECONNRESET WSAECONNRESET  
72 - #define SOCKET_ERRNO() WSAGetLastError()  
73 - #define SOCKET_RESET(x) x=INVALID_SOCKET  
74 - #define SOCKET_CLOSE(x) if(x!=INVALID_SOCKET){::closesocket(x);x=INVALID_SOCKET;}  
75 - #define SOCKET_VALID(x) (x!=INVALID_SOCKET)  
76 - #define SOCKET_BUFF(x) ((char*)x)  
77 - #define SOCKET_SETUP() socket_setup()  
78 - #define SOCKET_CLEANUP() socket_cleanup()  
79 -  
80 - typedef int socklen_t;  
81 - const char *inet_ntop(int af, const void *src, char *dst, socklen_t size);  
82 - typedef int mode_t;  
83 - #define S_IRUSR 0  
84 - #define S_IWUSR 0  
85 - #define S_IRGRP 0  
86 - #define S_IWGRP 0  
87 - #define S_IROTH 0  
88 -  
89 - #include <io.h>  
90 - #include <fcntl.h>  
91 - #define open _open  
92 - #define close _close  
93 - #define lseek _lseek  
94 - #define write _write  
95 - #define read _read  
96 -  
97 - typedef int pid_t;  
98 - pid_t getpid(void);  
99 - #define snprintf _snprintf  
100 - ssize_t writev(int fd, const struct iovec *iov, int iovcnt);  
101 - typedef int64_t useconds_t;  
102 - int usleep(useconds_t usec);  
103 - int socket_setup();  
104 - int socket_cleanup();  
105 #endif 49 #endif
106 50
  51 +#include <sys/types.h>
  52 +
107 /** 53 /**
108 * srs-librtmp is a librtmp like library, 54 * srs-librtmp is a librtmp like library,
109 * used to play/publish rtmp stream from/to rtmp server. 55 * used to play/publish rtmp stream from/to rtmp server.
@@ -1028,6 +974,45 @@ typedef void* srs_hijack_io_t; @@ -1028,6 +974,45 @@ typedef void* srs_hijack_io_t;
1028 extern int srs_hijack_io_write(srs_hijack_io_t ctx, void* buf, size_t size, ssize_t* nwrite); 974 extern int srs_hijack_io_write(srs_hijack_io_t ctx, void* buf, size_t size, ssize_t* nwrite);
1029 #endif 975 #endif
1030 976
  977 +/*************************************************************
  978 +**************************************************************
  979 +* Windows SRS-LIBRTMP solution
  980 +**************************************************************
  981 +*************************************************************/
  982 +// for srs-librtmp, @see https://github.com/winlinvip/simple-rtmp-server/issues/213
  983 +#ifdef _WIN32
  984 + #define _CRT_SECURE_NO_WARNINGS
  985 + #include <time.h>
  986 + int gettimeofday(struct timeval* tv, struct timezone* tz);
  987 + #define PRId64 "lld"
  988 +
  989 + typedef int socklen_t;
  990 + const char *inet_ntop(int af, const void *src, char *dst, socklen_t size);
  991 + typedef int mode_t;
  992 + #define S_IRUSR 0
  993 + #define S_IWUSR 0
  994 + #define S_IRGRP 0
  995 + #define S_IWGRP 0
  996 + #define S_IROTH 0
  997 +
  998 + #include <io.h>
  999 + #include <fcntl.h>
  1000 + #define open _open
  1001 + #define close _close
  1002 + #define lseek _lseek
  1003 + #define write _write
  1004 + #define read _read
  1005 +
  1006 + typedef int pid_t;
  1007 + pid_t getpid(void);
  1008 + #define snprintf _snprintf
  1009 + ssize_t writev(int fd, const struct iovec *iov, int iovcnt);
  1010 + typedef int64_t useconds_t;
  1011 + int usleep(useconds_t usec);
  1012 + int socket_setup();
  1013 + int socket_cleanup();
  1014 +#endif
  1015 +
1031 #ifdef __cplusplus 1016 #ifdef __cplusplus
1032 } 1017 }
1033 #endif 1018 #endif