diff --git a/README.md b/README.md index cd2b189c0..102eae950 100755 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ simple-rtmp-server srs(simple rtmp origin live server) over state-threads.
srs is a simple, high-performance, running in single process, origin live server.
-srs supports rtmp, HLS, transcoding, forward, http hooks.
+srs supports vhost, rtmp, HLS, transcoding, forward, http hooks.
blog: [http://blog.csdn.net/win_lin](http://blog.csdn.net/win_lin)
see also: [https://github.com/winlinvip/simple-rtmp-server](https://github.com/winlinvip/simple-rtmp-server)
see also: [http://winlinvip.github.io/simple-rtmp-server](http://winlinvip.github.io/simple-rtmp-server) @@ -198,6 +198,7 @@ usr sys idl wai hiq siq| read writ| recv send| in out | int csw * nginx v1.5.0: 139524 lines
### History +* v0.9, 2013-12-14, support reload the hls/forwarder/transcoder. * v0.9, 2013-12-14, refine the thread model for the retry threads. * v0.9, 2013-12-10, auto install depends tools/libs on centos/ubuntu. * v0.8, 2013-12-08, v0.8 released. 19186 lines. diff --git a/trunk/src/core/srs_core_config.cpp b/trunk/src/core/srs_core_config.cpp index 96bdad2fe..fd917a689 100644 --- a/trunk/src/core/srs_core_config.cpp +++ b/trunk/src/core/srs_core_config.cpp @@ -58,15 +58,35 @@ bool is_common_space(char ch) return (ch == ' ' || ch == '\t' || ch == CR || ch == LF); } -#define CONF_BUFFER_SIZE 1024 * 1024 +class SrsFileBuffer +{ +private: + int fd; + // last available position. + char* last; + // end of buffer. + char* end; +public: + // start of buffer. + char* start; + // current consumed position. + char* pos; + // current parsed line. + int line; + + SrsFileBuffer(); + virtual ~SrsFileBuffer(); + virtual int fullfill(const char* filename); + virtual bool empty(); +}; SrsFileBuffer::SrsFileBuffer() { fd = -1; line = 0; - pos = last = start = new char[CONF_BUFFER_SIZE]; - end = start + CONF_BUFFER_SIZE; + pos = last = start = NULL; + end = start; } SrsFileBuffer::~SrsFileBuffer() @@ -77,7 +97,7 @@ SrsFileBuffer::~SrsFileBuffer() srs_freepa(start); } -int SrsFileBuffer::open(const char* filename) +int SrsFileBuffer::fullfill(const char* filename) { assert(fd == -1); @@ -88,9 +108,29 @@ int SrsFileBuffer::open(const char* filename) line = 1; + int size = FILE_SIZE(fd) - FILE_OFFSET(fd); + if (size <= 0) { + return ERROR_SYSTEM_CONFIG_EOF; + } + + srs_freepa(start); + pos = last = start = new char[size]; + end = start + size; + + int n = read(fd, start, size); + if (n != size) { + srs_error("read file read error. expect %d, actual %d bytes.", size, n); + return ERROR_SYSTEM_CONFIG_INVALID; + } + return ERROR_SUCCESS; } +bool SrsFileBuffer::empty() +{ + return pos >= end; +} + SrsConfDirective::SrsConfDirective() { } @@ -156,7 +196,7 @@ int SrsConfDirective::parse(const char* filename) SrsFileBuffer buffer; - if ((ret = buffer.open(filename)) != ERROR_SUCCESS) { + if ((ret = buffer.fullfill(filename)) != ERROR_SUCCESS) { return ret; } @@ -240,11 +280,15 @@ int SrsConfDirective::read_token(SrsFileBuffer* buffer, std::vector bool last_space = true; while (true) { - if ((ret = refill_buffer(buffer, d_quoted, s_quoted, startline, pstart)) != ERROR_SUCCESS) { + if (buffer->empty()) { + ret = ERROR_SYSTEM_CONFIG_EOF; + if (!args.empty() || !last_space) { srs_error("line %d: unexpected end of file, expecting ; or \"}\"", buffer->line); return ERROR_SYSTEM_CONFIG_INVALID; } + srs_error("end of file. ret=%d", ret); + return ret; } @@ -363,59 +407,6 @@ int SrsConfDirective::read_token(SrsFileBuffer* buffer, std::vector return ret; } -int SrsConfDirective::refill_buffer(SrsFileBuffer* buffer, bool d_quoted, bool s_quoted, int startline, char*& pstart) -{ - int ret = ERROR_SUCCESS; - - if (buffer->pos < buffer->last) { - return ret; - } - - int size = FILE_SIZE(buffer->fd) - FILE_OFFSET(buffer->fd); - if (size > CONF_BUFFER_SIZE) { - ret = ERROR_SYSTEM_CONFIG_TOO_LARGE; - srs_error("config file too large, max=%d, actual=%d, ret=%d", - CONF_BUFFER_SIZE, size, ret); - return ret; - } - - if (size <= 0) { - return ERROR_SYSTEM_CONFIG_EOF; - } - - int len = buffer->pos - buffer->start; - if (len >= CONF_BUFFER_SIZE) { - buffer->line = startline; - - if (!d_quoted && !s_quoted) { - srs_error("line %d: too long parameter \"%*s...\" started", - buffer->line, 10, buffer->start); - - } else { - srs_error("line %d: too long parameter, " - "probably missing terminating '%c' character", buffer->line, d_quoted? '"':'\''); - } - return ERROR_SYSTEM_CONFIG_INVALID; - } - - if (len) { - memmove(buffer->start, pstart, len); - } - - size = srs_min(size, buffer->end - (buffer->start + len)); - int n = read(buffer->fd, buffer->start + len, size); - if (n != size) { - srs_error("read file read error. expect %d, actual %d bytes.", size, n); - return ERROR_SYSTEM_CONFIG_INVALID; - } - - buffer->pos = buffer->start + len; - buffer->last = buffer->pos + n; - pstart = buffer->start; - - return ret; -} - SrsConfig* config = new SrsConfig(); SrsConfig::SrsConfig() diff --git a/trunk/src/core/srs_core_config.hpp b/trunk/src/core/srs_core_config.hpp index 50538cb53..50d7c1766 100644 --- a/trunk/src/core/srs_core_config.hpp +++ b/trunk/src/core/srs_core_config.hpp @@ -49,24 +49,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // in ms, for HLS aac flush the audio #define SRS_CONF_DEFAULT_AAC_DELAY 300 -class SrsFileBuffer -{ -public: - int fd; - int line; - // start of buffer. - char* start; - // end of buffer. - char* end; - // current consumed position. - char* pos; - // last available position. - char* last; - - SrsFileBuffer(); - virtual ~SrsFileBuffer(); - virtual int open(const char* filename); -}; +class SrsFileBuffer; class SrsConfDirective { @@ -89,7 +72,6 @@ public: enum SrsDirectiveType{parse_file, parse_block}; virtual int parse_conf(SrsFileBuffer* buffer, SrsDirectiveType type); virtual int read_token(SrsFileBuffer* buffer, std::vector& args); - virtual int refill_buffer(SrsFileBuffer* buffer, bool d_quoted, bool s_quoted, int startline, char*& pstart); }; /** diff --git a/trunk/src/core/srs_core_error.hpp b/trunk/src/core/srs_core_error.hpp index 47004397e..55372e6d1 100644 --- a/trunk/src/core/srs_core_error.hpp +++ b/trunk/src/core/srs_core_error.hpp @@ -83,9 +83,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #define ERROR_SYSTEM_CONFIG_EOF 409 #define ERROR_SYSTEM_STREAM_BUSY 410 #define ERROR_SYSTEM_IP_INVALID 411 -#define ERROR_SYSTEM_CONFIG_TOO_LARGE 412 -#define ERROR_SYSTEM_FORWARD_LOOP 413 -#define ERROR_SYSTEM_WAITPID 414 +#define ERROR_SYSTEM_FORWARD_LOOP 412 +#define ERROR_SYSTEM_WAITPID 413 // see librtmp. // failed when open ssl create the dh