正在显示
4 个修改的文件
包含
55 行增加
和
82 行删除
| @@ -3,7 +3,7 @@ simple-rtmp-server | @@ -3,7 +3,7 @@ simple-rtmp-server | ||
| 3 | 3 | ||
| 4 | srs(simple rtmp origin live server) over state-threads.<br/> | 4 | srs(simple rtmp origin live server) over state-threads.<br/> |
| 5 | srs is a simple, high-performance, running in single process, origin live server.<br/> | 5 | srs is a simple, high-performance, running in single process, origin live server.<br/> |
| 6 | -srs supports rtmp, HLS, transcoding, forward, http hooks. <br/> | 6 | +srs supports vhost, rtmp, HLS, transcoding, forward, http hooks. <br/> |
| 7 | blog: [http://blog.csdn.net/win_lin](http://blog.csdn.net/win_lin) <br/> | 7 | blog: [http://blog.csdn.net/win_lin](http://blog.csdn.net/win_lin) <br/> |
| 8 | see also: [https://github.com/winlinvip/simple-rtmp-server](https://github.com/winlinvip/simple-rtmp-server) <br/> | 8 | see also: [https://github.com/winlinvip/simple-rtmp-server](https://github.com/winlinvip/simple-rtmp-server) <br/> |
| 9 | see also: [http://winlinvip.github.io/simple-rtmp-server](http://winlinvip.github.io/simple-rtmp-server) | 9 | 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 | @@ -198,6 +198,7 @@ usr sys idl wai hiq siq| read writ| recv send| in out | int csw | ||
| 198 | * nginx v1.5.0: 139524 lines <br/> | 198 | * nginx v1.5.0: 139524 lines <br/> |
| 199 | 199 | ||
| 200 | ### History | 200 | ### History |
| 201 | +* v0.9, 2013-12-14, support reload the hls/forwarder/transcoder. | ||
| 201 | * v0.9, 2013-12-14, refine the thread model for the retry threads. | 202 | * v0.9, 2013-12-14, refine the thread model for the retry threads. |
| 202 | * v0.9, 2013-12-10, auto install depends tools/libs on centos/ubuntu. | 203 | * v0.9, 2013-12-10, auto install depends tools/libs on centos/ubuntu. |
| 203 | * v0.8, 2013-12-08, v0.8 released. 19186 lines. | 204 | * v0.8, 2013-12-08, v0.8 released. 19186 lines. |
| @@ -58,15 +58,35 @@ bool is_common_space(char ch) | @@ -58,15 +58,35 @@ bool is_common_space(char ch) | ||
| 58 | return (ch == ' ' || ch == '\t' || ch == CR || ch == LF); | 58 | return (ch == ' ' || ch == '\t' || ch == CR || ch == LF); |
| 59 | } | 59 | } |
| 60 | 60 | ||
| 61 | -#define CONF_BUFFER_SIZE 1024 * 1024 | 61 | +class SrsFileBuffer |
| 62 | +{ | ||
| 63 | +private: | ||
| 64 | + int fd; | ||
| 65 | + // last available position. | ||
| 66 | + char* last; | ||
| 67 | + // end of buffer. | ||
| 68 | + char* end; | ||
| 69 | +public: | ||
| 70 | + // start of buffer. | ||
| 71 | + char* start; | ||
| 72 | + // current consumed position. | ||
| 73 | + char* pos; | ||
| 74 | + // current parsed line. | ||
| 75 | + int line; | ||
| 76 | + | ||
| 77 | + SrsFileBuffer(); | ||
| 78 | + virtual ~SrsFileBuffer(); | ||
| 79 | + virtual int fullfill(const char* filename); | ||
| 80 | + virtual bool empty(); | ||
| 81 | +}; | ||
| 62 | 82 | ||
| 63 | SrsFileBuffer::SrsFileBuffer() | 83 | SrsFileBuffer::SrsFileBuffer() |
| 64 | { | 84 | { |
| 65 | fd = -1; | 85 | fd = -1; |
| 66 | line = 0; | 86 | line = 0; |
| 67 | 87 | ||
| 68 | - pos = last = start = new char[CONF_BUFFER_SIZE]; | ||
| 69 | - end = start + CONF_BUFFER_SIZE; | 88 | + pos = last = start = NULL; |
| 89 | + end = start; | ||
| 70 | } | 90 | } |
| 71 | 91 | ||
| 72 | SrsFileBuffer::~SrsFileBuffer() | 92 | SrsFileBuffer::~SrsFileBuffer() |
| @@ -77,7 +97,7 @@ SrsFileBuffer::~SrsFileBuffer() | @@ -77,7 +97,7 @@ SrsFileBuffer::~SrsFileBuffer() | ||
| 77 | srs_freepa(start); | 97 | srs_freepa(start); |
| 78 | } | 98 | } |
| 79 | 99 | ||
| 80 | -int SrsFileBuffer::open(const char* filename) | 100 | +int SrsFileBuffer::fullfill(const char* filename) |
| 81 | { | 101 | { |
| 82 | assert(fd == -1); | 102 | assert(fd == -1); |
| 83 | 103 | ||
| @@ -88,9 +108,29 @@ int SrsFileBuffer::open(const char* filename) | @@ -88,9 +108,29 @@ int SrsFileBuffer::open(const char* filename) | ||
| 88 | 108 | ||
| 89 | line = 1; | 109 | line = 1; |
| 90 | 110 | ||
| 111 | + int size = FILE_SIZE(fd) - FILE_OFFSET(fd); | ||
| 112 | + if (size <= 0) { | ||
| 113 | + return ERROR_SYSTEM_CONFIG_EOF; | ||
| 114 | + } | ||
| 115 | + | ||
| 116 | + srs_freepa(start); | ||
| 117 | + pos = last = start = new char[size]; | ||
| 118 | + end = start + size; | ||
| 119 | + | ||
| 120 | + int n = read(fd, start, size); | ||
| 121 | + if (n != size) { | ||
| 122 | + srs_error("read file read error. expect %d, actual %d bytes.", size, n); | ||
| 123 | + return ERROR_SYSTEM_CONFIG_INVALID; | ||
| 124 | + } | ||
| 125 | + | ||
| 91 | return ERROR_SUCCESS; | 126 | return ERROR_SUCCESS; |
| 92 | } | 127 | } |
| 93 | 128 | ||
| 129 | +bool SrsFileBuffer::empty() | ||
| 130 | +{ | ||
| 131 | + return pos >= end; | ||
| 132 | +} | ||
| 133 | + | ||
| 94 | SrsConfDirective::SrsConfDirective() | 134 | SrsConfDirective::SrsConfDirective() |
| 95 | { | 135 | { |
| 96 | } | 136 | } |
| @@ -156,7 +196,7 @@ int SrsConfDirective::parse(const char* filename) | @@ -156,7 +196,7 @@ int SrsConfDirective::parse(const char* filename) | ||
| 156 | 196 | ||
| 157 | SrsFileBuffer buffer; | 197 | SrsFileBuffer buffer; |
| 158 | 198 | ||
| 159 | - if ((ret = buffer.open(filename)) != ERROR_SUCCESS) { | 199 | + if ((ret = buffer.fullfill(filename)) != ERROR_SUCCESS) { |
| 160 | return ret; | 200 | return ret; |
| 161 | } | 201 | } |
| 162 | 202 | ||
| @@ -240,11 +280,15 @@ int SrsConfDirective::read_token(SrsFileBuffer* buffer, std::vector<std::string> | @@ -240,11 +280,15 @@ int SrsConfDirective::read_token(SrsFileBuffer* buffer, std::vector<std::string> | ||
| 240 | bool last_space = true; | 280 | bool last_space = true; |
| 241 | 281 | ||
| 242 | while (true) { | 282 | while (true) { |
| 243 | - if ((ret = refill_buffer(buffer, d_quoted, s_quoted, startline, pstart)) != ERROR_SUCCESS) { | 283 | + if (buffer->empty()) { |
| 284 | + ret = ERROR_SYSTEM_CONFIG_EOF; | ||
| 285 | + | ||
| 244 | if (!args.empty() || !last_space) { | 286 | if (!args.empty() || !last_space) { |
| 245 | srs_error("line %d: unexpected end of file, expecting ; or \"}\"", buffer->line); | 287 | srs_error("line %d: unexpected end of file, expecting ; or \"}\"", buffer->line); |
| 246 | return ERROR_SYSTEM_CONFIG_INVALID; | 288 | return ERROR_SYSTEM_CONFIG_INVALID; |
| 247 | } | 289 | } |
| 290 | + srs_error("end of file. ret=%d", ret); | ||
| 291 | + | ||
| 248 | return ret; | 292 | return ret; |
| 249 | } | 293 | } |
| 250 | 294 | ||
| @@ -363,59 +407,6 @@ int SrsConfDirective::read_token(SrsFileBuffer* buffer, std::vector<std::string> | @@ -363,59 +407,6 @@ int SrsConfDirective::read_token(SrsFileBuffer* buffer, std::vector<std::string> | ||
| 363 | return ret; | 407 | return ret; |
| 364 | } | 408 | } |
| 365 | 409 | ||
| 366 | -int SrsConfDirective::refill_buffer(SrsFileBuffer* buffer, bool d_quoted, bool s_quoted, int startline, char*& pstart) | ||
| 367 | -{ | ||
| 368 | - int ret = ERROR_SUCCESS; | ||
| 369 | - | ||
| 370 | - if (buffer->pos < buffer->last) { | ||
| 371 | - return ret; | ||
| 372 | - } | ||
| 373 | - | ||
| 374 | - int size = FILE_SIZE(buffer->fd) - FILE_OFFSET(buffer->fd); | ||
| 375 | - if (size > CONF_BUFFER_SIZE) { | ||
| 376 | - ret = ERROR_SYSTEM_CONFIG_TOO_LARGE; | ||
| 377 | - srs_error("config file too large, max=%d, actual=%d, ret=%d", | ||
| 378 | - CONF_BUFFER_SIZE, size, ret); | ||
| 379 | - return ret; | ||
| 380 | - } | ||
| 381 | - | ||
| 382 | - if (size <= 0) { | ||
| 383 | - return ERROR_SYSTEM_CONFIG_EOF; | ||
| 384 | - } | ||
| 385 | - | ||
| 386 | - int len = buffer->pos - buffer->start; | ||
| 387 | - if (len >= CONF_BUFFER_SIZE) { | ||
| 388 | - buffer->line = startline; | ||
| 389 | - | ||
| 390 | - if (!d_quoted && !s_quoted) { | ||
| 391 | - srs_error("line %d: too long parameter \"%*s...\" started", | ||
| 392 | - buffer->line, 10, buffer->start); | ||
| 393 | - | ||
| 394 | - } else { | ||
| 395 | - srs_error("line %d: too long parameter, " | ||
| 396 | - "probably missing terminating '%c' character", buffer->line, d_quoted? '"':'\''); | ||
| 397 | - } | ||
| 398 | - return ERROR_SYSTEM_CONFIG_INVALID; | ||
| 399 | - } | ||
| 400 | - | ||
| 401 | - if (len) { | ||
| 402 | - memmove(buffer->start, pstart, len); | ||
| 403 | - } | ||
| 404 | - | ||
| 405 | - size = srs_min(size, buffer->end - (buffer->start + len)); | ||
| 406 | - int n = read(buffer->fd, buffer->start + len, size); | ||
| 407 | - if (n != size) { | ||
| 408 | - srs_error("read file read error. expect %d, actual %d bytes.", size, n); | ||
| 409 | - return ERROR_SYSTEM_CONFIG_INVALID; | ||
| 410 | - } | ||
| 411 | - | ||
| 412 | - buffer->pos = buffer->start + len; | ||
| 413 | - buffer->last = buffer->pos + n; | ||
| 414 | - pstart = buffer->start; | ||
| 415 | - | ||
| 416 | - return ret; | ||
| 417 | -} | ||
| 418 | - | ||
| 419 | SrsConfig* config = new SrsConfig(); | 410 | SrsConfig* config = new SrsConfig(); |
| 420 | 411 | ||
| 421 | SrsConfig::SrsConfig() | 412 | SrsConfig::SrsConfig() |
| @@ -49,24 +49,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -49,24 +49,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 49 | // in ms, for HLS aac flush the audio | 49 | // in ms, for HLS aac flush the audio |
| 50 | #define SRS_CONF_DEFAULT_AAC_DELAY 300 | 50 | #define SRS_CONF_DEFAULT_AAC_DELAY 300 |
| 51 | 51 | ||
| 52 | -class SrsFileBuffer | ||
| 53 | -{ | ||
| 54 | -public: | ||
| 55 | - int fd; | ||
| 56 | - int line; | ||
| 57 | - // start of buffer. | ||
| 58 | - char* start; | ||
| 59 | - // end of buffer. | ||
| 60 | - char* end; | ||
| 61 | - // current consumed position. | ||
| 62 | - char* pos; | ||
| 63 | - // last available position. | ||
| 64 | - char* last; | ||
| 65 | - | ||
| 66 | - SrsFileBuffer(); | ||
| 67 | - virtual ~SrsFileBuffer(); | ||
| 68 | - virtual int open(const char* filename); | ||
| 69 | -}; | 52 | +class SrsFileBuffer; |
| 70 | 53 | ||
| 71 | class SrsConfDirective | 54 | class SrsConfDirective |
| 72 | { | 55 | { |
| @@ -89,7 +72,6 @@ public: | @@ -89,7 +72,6 @@ public: | ||
| 89 | enum SrsDirectiveType{parse_file, parse_block}; | 72 | enum SrsDirectiveType{parse_file, parse_block}; |
| 90 | virtual int parse_conf(SrsFileBuffer* buffer, SrsDirectiveType type); | 73 | virtual int parse_conf(SrsFileBuffer* buffer, SrsDirectiveType type); |
| 91 | virtual int read_token(SrsFileBuffer* buffer, std::vector<std::string>& args); | 74 | virtual int read_token(SrsFileBuffer* buffer, std::vector<std::string>& args); |
| 92 | - virtual int refill_buffer(SrsFileBuffer* buffer, bool d_quoted, bool s_quoted, int startline, char*& pstart); | ||
| 93 | }; | 75 | }; |
| 94 | 76 | ||
| 95 | /** | 77 | /** |
| @@ -83,9 +83,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -83,9 +83,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 83 | #define ERROR_SYSTEM_CONFIG_EOF 409 | 83 | #define ERROR_SYSTEM_CONFIG_EOF 409 |
| 84 | #define ERROR_SYSTEM_STREAM_BUSY 410 | 84 | #define ERROR_SYSTEM_STREAM_BUSY 410 |
| 85 | #define ERROR_SYSTEM_IP_INVALID 411 | 85 | #define ERROR_SYSTEM_IP_INVALID 411 |
| 86 | -#define ERROR_SYSTEM_CONFIG_TOO_LARGE 412 | ||
| 87 | -#define ERROR_SYSTEM_FORWARD_LOOP 413 | ||
| 88 | -#define ERROR_SYSTEM_WAITPID 414 | 86 | +#define ERROR_SYSTEM_FORWARD_LOOP 412 |
| 87 | +#define ERROR_SYSTEM_WAITPID 413 | ||
| 89 | 88 | ||
| 90 | // see librtmp. | 89 | // see librtmp. |
| 91 | // failed when open ssl create the dh | 90 | // failed when open ssl create the dh |
-
请 注册 或 登录 后发表评论