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

refine code by winlin, for merged from allspace.

This commit is contained in:
winlin 2014-11-27 15:22:39 +08:00
parent 1855c9429c
commit 18c308248e
11 changed files with 416 additions and 539 deletions

7
trunk/configure vendored
View file

@ -299,10 +299,9 @@ END
GDBDebug=" -g -O0"
# the warning level.
WarnLevel=" -Wall"
# the compile standard.
if [ "$MSYSTEM" != "MINGW32" -a "$MSYSTEM" != "MINGW64" ]; then
CppStd="-ansi"
fi
# the compile in c++ standard.
# @remark, donot specifies it for mingw.
CppStd="-ansi" && echo $MSYSTEM|grep "MINGW">/dev/null && CppStd=""
# for library compile
LibraryCompile=" -fPIC"
# performance of gprof

View file

@ -85,7 +85,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// generated by configure.
#include <srs_auto_headers.hpp>
#include <srs_platform.hpp>
// free the p and set to NULL.
// p must be a T*.
#define srs_freep(p) \
@ -110,5 +110,9 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
className(const className&); \
className& operator= (const className&)
// for windows to compile srs-librtmp
// @see: https://github.com/winlinvip/simple-rtmp-server/issues/213
#include <srs_platform.hpp>
#endif

View file

@ -1,11 +1,33 @@
/*
The MIT License (MIT)
Copyright (c) 2014 allspace
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <srs_platform.hpp>
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include "srs_platform.hpp"
#if defined(_WIN32) && !defined(__CYGWIN__)
int socket_setup()
{
WORD wVersionRequested;
@ -347,61 +369,5 @@ int socket_cleanup()
/* from public\sdk\inc\crt\errno.h */
#define ENOSPC 28
/*
*
*/
/*
#ifndef INET_ADDRSTRLEN
#define INET_ADDRSTRLEN 16
#endif
static const char *
inet_ntop_v4 (const void *src, char *dst, size_t size)
{
const char digits[] = "0123456789";
int i;
struct in_addr *addr = (struct in_addr *)src;
u_long a = ntohl(addr->s_addr);
const char *orig_dst = dst;
if (size < INET_ADDRSTRLEN) {
Set_errno(ENOSPC);
return NULL;
}
for (i = 0; i < 4; ++i) {
int n = (a >> (24 - i * 8)) & 0xFF;
int non_zerop = 0;
if (non_zerop || n / 100 > 0) {
*dst++ = digits[n / 100];
n %= 100;
non_zerop = 1;
}
if (non_zerop || n / 10 > 0) {
*dst++ = digits[n / 10];
n %= 10;
non_zerop = 1;
}
*dst++ = digits[n];
if (i != 3)
*dst++ = '.';
}
*dst++ = '\0';
return orig_dst;
}
const char *
inet_ntop(int af, const void *src, char *dst, size_t size)
{
switch (af) {
case AF_INET :
return inet_ntop_v4 (src, dst, size);
default :
Set_errno(EAFNOSUPPORT);
return NULL;
}
}
*/
#endif

View file

@ -1,21 +1,33 @@
#ifndef SRS_WIN_PORTING_H
#define SRS_WIN_PORTING_H
#if !defined(_WIN32) || defined(__CYGWIN__) /*not on windows or it's cygwin. _WIN32 includes both 32-bit and 64-bit*/
// for srs-librtmp, @see https://github.com/winlinvip/simple-rtmp-server/issues/213
#if defined(_WIN32)
#include <windows.h>
#endif
/**
* for linux like,
* for example, not on windows or it's cygwin.
* while the _WIN32 includes both 32-bit and 64-bit
*/
#if !defined(_WIN32) || defined(__CYGWIN__)
#define SOCKET_ETIME ETIME
#define SOCKET_ECONNRESET ECONNRESET
#define SOCKET int
#define SOCKET_ERRNO() errno
#define SOCKET_RESET(x) x=-1
#define SOCKET_CLOSE(x) if(x>=0){::close(x);x=-1;}
#define SOCKET_VALID(x) (x>=0)
#define SOCKET_SETUP() {}
#define SOCKET_CLEANUP() {}
#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 /*on windows, but not on cygwin*/
#include <sys/stat.h>
#include <time.h>
#include <winsock2.h>

View file

@ -30,11 +30,9 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <srs_core.hpp>
// success, ok
#if !defined(_WIN32) || defined(__CYGWIN__) //avoid redefine error on Windows
// for srs-librtmp, @see https://github.com/winlinvip/simple-rtmp-server/issues/213
#ifndef _WIN32
#define ERROR_SUCCESS 0
#else
#include <windows.h>
#endif
///////////////////////////////////////////////////////

View file

@ -45,7 +45,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
SimpleSocketStream::SimpleSocketStream()
{
//fd = -1;
SOCKET_RESET(fd);
send_timeout = recv_timeout = ST_UTIME_NO_TIMEOUT;
recv_bytes = send_bytes = 0;
@ -54,17 +53,12 @@ SimpleSocketStream::SimpleSocketStream()
SimpleSocketStream::~SimpleSocketStream()
{
//if (fd != -1) {
// ::close(fd);
// fd = -1;
//}
SOCKET_CLOSE(fd);
SOCKET_CLEANUP();
}
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;

View file

@ -22,7 +22,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <srs_librtmp.hpp>
#include <srs_platform.hpp>
#include <stdlib.h>
// for srs-librtmp, @see https://github.com/winlinvip/simple-rtmp-server/issues/213
@ -34,6 +34,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <sstream>
using namespace std;
#include <srs_platform.hpp>
#include <srs_kernel_error.hpp>
#include <srs_protocol_rtmp.hpp>
#include <srs_lib_simple_socket.hpp>
@ -107,56 +108,6 @@ struct Context
}
};
// for srs-librtmp, @see https://github.com/winlinvip/simple-rtmp-server/issues/213
#ifdef _WIN32
/*
int open(const char *pathname, int flags)
{
return open(pathname, flags, 0);
}
int open(const char *pathname, int flags, mode_t mode)
{
FILE* file = NULL;
if ((flags & O_RDONLY) == O_RDONLY) {
file = fopen(pathname, "r");
} else {
file = fopen(pathname, "w+");
}
if (file == NULL) {
return -1;
}
return (int)file;
}
int close(int fd)
{
FILE* file = (FILE*)fd;
return fclose(file);
}
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);
}
*/
#endif
int srs_librtmp_context_parse_uri(Context* context)
{
int ret = ERROR_SUCCESS;

View file

@ -31,53 +31,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <sys/types.h>
// for srs-librtmp, @see https://github.com/winlinvip/simple-rtmp-server/issues/213
#if 0
#define _CRT_SECURE_NO_WARNINGS
typedef unsigned long long u_int64_t;
typedef long long int64_t;
typedef unsigned int u_int32_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 */
size_t iov_len; /* Number of bytes to transfer */
};
#include <time.h>
#include <windows.h>
int gettimeofday(struct timeval* tv, struct timezone* tz);
#define PRId64 "lld"
typedef int socklen_t;
const char *inet_ntop(int af, const void *src, char *dst, socklen_t size);
typedef int mode_t;
#define S_IRUSR 0
#define S_IWUSR 0
#define S_IRGRP 0
#define S_IWGRP 0
#define S_IROTH 0
int open(const char *pathname, int flags);
int open(const char *pathname, int flags, mode_t mode);
int close(int fd);
off_t lseek(int fd, off_t offset, int whence);
ssize_t write(int fd, const void *buf, size_t count);
ssize_t read(int fd, void *buf, size_t count);
typedef int pid_t;
pid_t getpid(void);
#define snprintf _snprintf
ssize_t writev(int fd, const struct iovec *iov, int iovcnt);
typedef int64_t useconds_t;
int usleep(useconds_t usec);
#endif
#if defined(_WIN32) && !defined(__CYGWIN__)
#include <stdint.h>
typedef uint32_t u_int32_t;
#endif
/**
* srs-librtmp is a librtmp like library,
* used to play/publish rtmp stream from/to rtmp server.

View file

@ -19,7 +19,7 @@
#undef SRS_AUTO_HTTP_CALLBACK
#undef SRS_AUTO_SSL
#undef SRS_AUTO_FFMPEG_TOOL
#define SRS_AUTO_FFMPEG_STUB
#undef SRS_AUTO_FFMPEG_STUB
#undef SRS_AUTO_TRANSCODE
#undef SRS_AUTO_INGEST
#undef SRS_AUTO_STAT

View file

@ -77,7 +77,7 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\research\librtmp\srs_play.c" />
<ClCompile Include="srs_play.c" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">

View file

@ -15,7 +15,7 @@
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\research\librtmp\srs_play.c">
<ClCompile Include="srs_play.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>