正在显示
2 个修改的文件
包含
115 行增加
和
114 行删除
| @@ -59,7 +59,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -59,7 +59,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 59 | #define RTMP_SIG_SRS_SERVER RTMP_SIG_SRS_KEY"/"RTMP_SIG_SRS_VERSION"("RTMP_SIG_SRS_CODE")" | 59 | #define RTMP_SIG_SRS_SERVER RTMP_SIG_SRS_KEY"/"RTMP_SIG_SRS_VERSION"("RTMP_SIG_SRS_CODE")" |
| 60 | 60 | ||
| 61 | // stable major version | 61 | // stable major version |
| 62 | -#define VERSION_STABLE 1 | 62 | +#define VERSION_STABLE 2 |
| 63 | #define VERSION_STABLE_BRANCH SRS_XSTR(VERSION_STABLE)".0release" | 63 | #define VERSION_STABLE_BRANCH SRS_XSTR(VERSION_STABLE)".0release" |
| 64 | 64 | ||
| 65 | // internal macros, covert macro values to str, | 65 | // internal macros, covert macro values to str, |
| @@ -51,6 +51,7 @@ using namespace std; | @@ -51,6 +51,7 @@ using namespace std; | ||
| 51 | // pre-declare | 51 | // pre-declare |
| 52 | int run(SrsServer* svr); | 52 | int run(SrsServer* svr); |
| 53 | int run_master(SrsServer* svr); | 53 | int run_master(SrsServer* svr); |
| 54 | +void show_macro_features(); | ||
| 54 | 55 | ||
| 55 | // @global log and context. | 56 | // @global log and context. |
| 56 | ISrsLog* _srs_log = new SrsFastLog(); | 57 | ISrsLog* _srs_log = new SrsFastLog(); |
| @@ -62,8 +63,113 @@ SrsConfig* _srs_config = new SrsConfig(); | @@ -62,8 +63,113 @@ SrsConfig* _srs_config = new SrsConfig(); | ||
| 62 | extern const char* _srs_version; | 63 | extern const char* _srs_version; |
| 63 | 64 | ||
| 64 | /** | 65 | /** |
| 65 | -* show the features by macro, the actual macro values. | 66 | +* main entrance. |
| 66 | */ | 67 | */ |
| 68 | +int main(int argc, char** argv) | ||
| 69 | +{ | ||
| 70 | + int ret = ERROR_SUCCESS; | ||
| 71 | + | ||
| 72 | + // TODO: support both little and big endian. | ||
| 73 | + srs_assert(srs_is_little_endian()); | ||
| 74 | + | ||
| 75 | + // for gperf gmp or gcp, | ||
| 76 | + // should never enable it when not enabled for performance issue. | ||
| 77 | +#ifdef SRS_AUTO_GPERF_MP | ||
| 78 | + HeapProfilerStart("gperf.srs.gmp"); | ||
| 79 | +#endif | ||
| 80 | +#ifdef SRS_AUTO_GPERF_CP | ||
| 81 | + ProfilerStart("gperf.srs.gcp"); | ||
| 82 | +#endif | ||
| 83 | + | ||
| 84 | + // directly compile error when these two macro defines. | ||
| 85 | +#if defined(SRS_AUTO_GPERF_MC) && defined(SRS_AUTO_GPERF_MP) | ||
| 86 | + #error ("option --with-gmc confict with --with-gmp, " | ||
| 87 | + "@see: http://google-perftools.googlecode.com/svn/trunk/doc/heap_checker.html\n" | ||
| 88 | + "Note that since the heap-checker uses the heap-profiling framework internally, " | ||
| 89 | + "it is not possible to run both the heap-checker and heap profiler at the same time"); | ||
| 90 | +#endif | ||
| 91 | + | ||
| 92 | + // never use gmp to check memory leak. | ||
| 93 | +#ifdef SRS_AUTO_GPERF_MP | ||
| 94 | + #warning "gmp is not used for memory leak, please use gmc instead." | ||
| 95 | +#endif | ||
| 96 | + | ||
| 97 | + // never use srs log(srs_trace, srs_error, etc) before config parse the option, | ||
| 98 | + // which will load the log config and apply it. | ||
| 99 | + if ((ret = _srs_config->parse_options(argc, argv)) != ERROR_SUCCESS) { | ||
| 100 | + return ret; | ||
| 101 | + } | ||
| 102 | + | ||
| 103 | + // change the work dir and set cwd. | ||
| 104 | + string cwd = _srs_config->get_work_dir(); | ||
| 105 | + if (!cwd.empty() && cwd != "./" && (ret = chdir(cwd.c_str())) != ERROR_SUCCESS) { | ||
| 106 | + srs_error("change cwd to %s failed. ret=%d", cwd.c_str(), ret); | ||
| 107 | + return ret; | ||
| 108 | + } | ||
| 109 | + if ((ret = _srs_config->initialize_cwd()) != ERROR_SUCCESS) { | ||
| 110 | + return ret; | ||
| 111 | + } | ||
| 112 | + | ||
| 113 | + // config parsed, initialize log. | ||
| 114 | + if ((ret = _srs_log->initialize()) != ERROR_SUCCESS) { | ||
| 115 | + return ret; | ||
| 116 | + } | ||
| 117 | + | ||
| 118 | + // config already applied to log. | ||
| 119 | + srs_trace(RTMP_SIG_SRS_SERVER", stable is "RTMP_SIG_SRS_PRIMARY); | ||
| 120 | + srs_trace("license: "RTMP_SIG_SRS_LICENSE", "RTMP_SIG_SRS_COPYRIGHT); | ||
| 121 | + srs_trace("authors: "RTMP_SIG_SRS_AUTHROS); | ||
| 122 | + srs_trace("contributors: "SRS_AUTO_CONSTRIBUTORS); | ||
| 123 | + srs_trace("build: %s, configure:%s, uname: %s", SRS_AUTO_BUILD_DATE, SRS_AUTO_USER_CONFIGURE, SRS_AUTO_UNAME); | ||
| 124 | + srs_trace("configure detail: "SRS_AUTO_CONFIGURE); | ||
| 125 | +#ifdef SRS_AUTO_EMBEDED_TOOL_CHAIN | ||
| 126 | + srs_trace("crossbuild tool chain: "SRS_AUTO_EMBEDED_TOOL_CHAIN); | ||
| 127 | +#endif | ||
| 128 | + srs_trace("cwd=%s, work_dir=%s", _srs_config->cwd().c_str(), cwd.c_str()); | ||
| 129 | + | ||
| 130 | +#ifdef SRS_PERF_GLIBC_MEMORY_CHECK | ||
| 131 | + // ensure glibc write error to stderr. | ||
| 132 | + setenv("LIBC_FATAL_STDERR_", "1", 1); | ||
| 133 | + // ensure glibc to do alloc check. | ||
| 134 | + setenv("MALLOC_CHECK_", "1", 1); | ||
| 135 | + srs_trace("env MALLOC_CHECK_=1 LIBC_FATAL_STDERR_=1"); | ||
| 136 | +#endif | ||
| 137 | + | ||
| 138 | +#ifdef SRS_AUTO_GPERF_MD | ||
| 139 | + char* TCMALLOC_PAGE_FENCE = getenv("TCMALLOC_PAGE_FENCE"); | ||
| 140 | + if (!TCMALLOC_PAGE_FENCE || strcmp(TCMALLOC_PAGE_FENCE, "1")) { | ||
| 141 | + srs_trace("gmd enabled without env TCMALLOC_PAGE_FENCE=1"); | ||
| 142 | + } else { | ||
| 143 | + srs_trace("env TCMALLOC_PAGE_FENCE=1"); | ||
| 144 | + } | ||
| 145 | +#endif | ||
| 146 | + | ||
| 147 | + // we check the config when the log initialized. | ||
| 148 | + if ((ret = _srs_config->check_config()) != ERROR_SUCCESS) { | ||
| 149 | + return ret; | ||
| 150 | + } | ||
| 151 | + | ||
| 152 | + // features | ||
| 153 | + show_macro_features(); | ||
| 154 | + | ||
| 155 | + SrsServer* svr = new SrsServer(); | ||
| 156 | + SrsAutoFree(SrsServer, svr); | ||
| 157 | + | ||
| 158 | + /** | ||
| 159 | + * we do nothing in the constructor of server, | ||
| 160 | + * and use initialize to create members, set hooks for instance the reload handler, | ||
| 161 | + * all initialize will done in this stage. | ||
| 162 | + */ | ||
| 163 | + if ((ret = svr->initialize(NULL)) != ERROR_SUCCESS) { | ||
| 164 | + return ret; | ||
| 165 | + } | ||
| 166 | + | ||
| 167 | + return run(svr); | ||
| 168 | +} | ||
| 169 | + | ||
| 170 | +/** | ||
| 171 | + * show the features by macro, the actual macro values. | ||
| 172 | + */ | ||
| 67 | void show_macro_features() | 173 | void show_macro_features() |
| 68 | { | 174 | { |
| 69 | if (true) { | 175 | if (true) { |
| @@ -135,8 +241,8 @@ void show_macro_features() | @@ -135,8 +241,8 @@ void show_macro_features() | ||
| 135 | #endif | 241 | #endif |
| 136 | 242 | ||
| 137 | ss << ", conf:" << _srs_config->config() << ", limit:" << _srs_config->get_max_connections() | 243 | ss << ", conf:" << _srs_config->config() << ", limit:" << _srs_config->get_max_connections() |
| 138 | - << ", writev:" << sysconf(_SC_IOV_MAX) << ", encoding:" << (srs_is_little_endian()? "little-endian":"big-endian") | ||
| 139 | - << ", HZ:" << (int)sysconf(_SC_CLK_TCK); | 244 | + << ", writev:" << sysconf(_SC_IOV_MAX) << ", encoding:" << (srs_is_little_endian()? "little-endian":"big-endian") |
| 245 | + << ", HZ:" << (int)sysconf(_SC_CLK_TCK); | ||
| 140 | 246 | ||
| 141 | srs_trace(ss.str().c_str()); | 247 | srs_trace(ss.str().c_str()); |
| 142 | } | 248 | } |
| @@ -184,7 +290,7 @@ void show_macro_features() | @@ -184,7 +290,7 @@ void show_macro_features() | ||
| 184 | #else | 290 | #else |
| 185 | ss << "off"; | 291 | ss << "off"; |
| 186 | #endif | 292 | #endif |
| 187 | - | 293 | + |
| 188 | // ss(SO_SENDBUF) | 294 | // ss(SO_SENDBUF) |
| 189 | ss << ", ss:"; | 295 | ss << ", ss:"; |
| 190 | #ifdef SRS_PERF_SO_SNDBUF_SIZE | 296 | #ifdef SRS_PERF_SO_SNDBUF_SIZE |
| @@ -205,130 +311,25 @@ void show_macro_features() | @@ -205,130 +311,25 @@ void show_macro_features() | ||
| 205 | SRS_PERF_MW_SLEEP, possible_mr_latency, SRS_PERF_PLAY_QUEUE*1000); | 311 | SRS_PERF_MW_SLEEP, possible_mr_latency, SRS_PERF_PLAY_QUEUE*1000); |
| 206 | 312 | ||
| 207 | #ifdef SRS_AUTO_MEM_WATCH | 313 | #ifdef SRS_AUTO_MEM_WATCH |
| 208 | - #warning "srs memory watcher will hurts performance. user should kill by SIGTERM or init.d script." | 314 | +#warning "srs memory watcher will hurts performance. user should kill by SIGTERM or init.d script." |
| 209 | srs_warn("srs memory watcher will hurts performance. user should kill by SIGTERM or init.d script."); | 315 | srs_warn("srs memory watcher will hurts performance. user should kill by SIGTERM or init.d script."); |
| 210 | #endif | 316 | #endif |
| 211 | 317 | ||
| 212 | #if defined(SRS_AUTO_STREAM_CASTER) | 318 | #if defined(SRS_AUTO_STREAM_CASTER) |
| 213 | - #warning "stream caster is experiment feature." | 319 | +#warning "stream caster is experiment feature." |
| 214 | srs_warn("stream caster is experiment feature."); | 320 | srs_warn("stream caster is experiment feature."); |
| 215 | #endif | 321 | #endif |
| 216 | 322 | ||
| 217 | #if VERSION_MAJOR > VERSION_STABLE | 323 | #if VERSION_MAJOR > VERSION_STABLE |
| 218 | - #warning "current branch is not stable, please use stable branch instead." | 324 | +#warning "current branch is not stable, please use stable branch instead." |
| 219 | srs_warn("SRS %s is not stable, please use stable branch %s instead", RTMP_SIG_SRS_VERSION, VERSION_STABLE_BRANCH); | 325 | srs_warn("SRS %s is not stable, please use stable branch %s instead", RTMP_SIG_SRS_VERSION, VERSION_STABLE_BRANCH); |
| 220 | #endif | 326 | #endif |
| 221 | 327 | ||
| 222 | #if defined(SRS_PERF_SO_SNDBUF_SIZE) && !defined(SRS_PERF_MW_SO_SNDBUF) | 328 | #if defined(SRS_PERF_SO_SNDBUF_SIZE) && !defined(SRS_PERF_MW_SO_SNDBUF) |
| 223 | - #error "SRS_PERF_SO_SNDBUF_SIZE depends on SRS_PERF_MW_SO_SNDBUF" | 329 | +#error "SRS_PERF_SO_SNDBUF_SIZE depends on SRS_PERF_MW_SO_SNDBUF" |
| 224 | #endif | 330 | #endif |
| 225 | } | 331 | } |
| 226 | 332 | ||
| 227 | -/** | ||
| 228 | -* main entrance. | ||
| 229 | -*/ | ||
| 230 | -int main(int argc, char** argv) | ||
| 231 | -{ | ||
| 232 | - int ret = ERROR_SUCCESS; | ||
| 233 | - | ||
| 234 | - // TODO: support both little and big endian. | ||
| 235 | - srs_assert(srs_is_little_endian()); | ||
| 236 | - | ||
| 237 | - // for gperf gmp or gcp, | ||
| 238 | - // should never enable it when not enabled for performance issue. | ||
| 239 | -#ifdef SRS_AUTO_GPERF_MP | ||
| 240 | - HeapProfilerStart("gperf.srs.gmp"); | ||
| 241 | -#endif | ||
| 242 | -#ifdef SRS_AUTO_GPERF_CP | ||
| 243 | - ProfilerStart("gperf.srs.gcp"); | ||
| 244 | -#endif | ||
| 245 | - | ||
| 246 | - // directly compile error when these two macro defines. | ||
| 247 | -#if defined(SRS_AUTO_GPERF_MC) && defined(SRS_AUTO_GPERF_MP) | ||
| 248 | - #error ("option --with-gmc confict with --with-gmp, " | ||
| 249 | - "@see: http://google-perftools.googlecode.com/svn/trunk/doc/heap_checker.html\n" | ||
| 250 | - "Note that since the heap-checker uses the heap-profiling framework internally, " | ||
| 251 | - "it is not possible to run both the heap-checker and heap profiler at the same time"); | ||
| 252 | -#endif | ||
| 253 | - | ||
| 254 | - // never use gmp to check memory leak. | ||
| 255 | -#ifdef SRS_AUTO_GPERF_MP | ||
| 256 | - #warning "gmp is not used for memory leak, please use gmc instead." | ||
| 257 | -#endif | ||
| 258 | - | ||
| 259 | - // never use srs log(srs_trace, srs_error, etc) before config parse the option, | ||
| 260 | - // which will load the log config and apply it. | ||
| 261 | - if ((ret = _srs_config->parse_options(argc, argv)) != ERROR_SUCCESS) { | ||
| 262 | - return ret; | ||
| 263 | - } | ||
| 264 | - | ||
| 265 | - // change the work dir and set cwd. | ||
| 266 | - string cwd = _srs_config->get_work_dir(); | ||
| 267 | - if (!cwd.empty() && cwd != "./" && (ret = chdir(cwd.c_str())) != ERROR_SUCCESS) { | ||
| 268 | - srs_error("change cwd to %s failed. ret=%d", cwd.c_str(), ret); | ||
| 269 | - return ret; | ||
| 270 | - } | ||
| 271 | - if ((ret = _srs_config->initialize_cwd()) != ERROR_SUCCESS) { | ||
| 272 | - return ret; | ||
| 273 | - } | ||
| 274 | - | ||
| 275 | - // config parsed, initialize log. | ||
| 276 | - if ((ret = _srs_log->initialize()) != ERROR_SUCCESS) { | ||
| 277 | - return ret; | ||
| 278 | - } | ||
| 279 | - | ||
| 280 | - // config already applied to log. | ||
| 281 | - srs_trace(RTMP_SIG_SRS_SERVER", stable is "RTMP_SIG_SRS_PRIMARY); | ||
| 282 | - srs_trace("license: "RTMP_SIG_SRS_LICENSE", "RTMP_SIG_SRS_COPYRIGHT); | ||
| 283 | - srs_trace("authors: "RTMP_SIG_SRS_AUTHROS); | ||
| 284 | - srs_trace("contributors: "SRS_AUTO_CONSTRIBUTORS); | ||
| 285 | - srs_trace("build: %s, configure:%s, uname: %s", SRS_AUTO_BUILD_DATE, SRS_AUTO_USER_CONFIGURE, SRS_AUTO_UNAME); | ||
| 286 | - srs_trace("configure detail: "SRS_AUTO_CONFIGURE); | ||
| 287 | -#ifdef SRS_AUTO_EMBEDED_TOOL_CHAIN | ||
| 288 | - srs_trace("crossbuild tool chain: "SRS_AUTO_EMBEDED_TOOL_CHAIN); | ||
| 289 | -#endif | ||
| 290 | - srs_trace("cwd=%s, work_dir=%s", _srs_config->cwd().c_str(), cwd.c_str()); | ||
| 291 | - | ||
| 292 | -#ifdef SRS_PERF_GLIBC_MEMORY_CHECK | ||
| 293 | - // ensure glibc write error to stderr. | ||
| 294 | - setenv("LIBC_FATAL_STDERR_", "1", 1); | ||
| 295 | - // ensure glibc to do alloc check. | ||
| 296 | - setenv("MALLOC_CHECK_", "1", 1); | ||
| 297 | - srs_trace("env MALLOC_CHECK_=1 LIBC_FATAL_STDERR_=1"); | ||
| 298 | -#endif | ||
| 299 | - | ||
| 300 | -#ifdef SRS_AUTO_GPERF_MD | ||
| 301 | - char* TCMALLOC_PAGE_FENCE = getenv("TCMALLOC_PAGE_FENCE"); | ||
| 302 | - if (!TCMALLOC_PAGE_FENCE || strcmp(TCMALLOC_PAGE_FENCE, "1")) { | ||
| 303 | - srs_trace("gmd enabled without env TCMALLOC_PAGE_FENCE=1"); | ||
| 304 | - } else { | ||
| 305 | - srs_trace("env TCMALLOC_PAGE_FENCE=1"); | ||
| 306 | - } | ||
| 307 | -#endif | ||
| 308 | - | ||
| 309 | - // we check the config when the log initialized. | ||
| 310 | - if ((ret = _srs_config->check_config()) != ERROR_SUCCESS) { | ||
| 311 | - return ret; | ||
| 312 | - } | ||
| 313 | - | ||
| 314 | - // features | ||
| 315 | - show_macro_features(); | ||
| 316 | - | ||
| 317 | - SrsServer* svr = new SrsServer(); | ||
| 318 | - SrsAutoFree(SrsServer, svr); | ||
| 319 | - | ||
| 320 | - /** | ||
| 321 | - * we do nothing in the constructor of server, | ||
| 322 | - * and use initialize to create members, set hooks for instance the reload handler, | ||
| 323 | - * all initialize will done in this stage. | ||
| 324 | - */ | ||
| 325 | - if ((ret = svr->initialize(NULL)) != ERROR_SUCCESS) { | ||
| 326 | - return ret; | ||
| 327 | - } | ||
| 328 | - | ||
| 329 | - return run(svr); | ||
| 330 | -} | ||
| 331 | - | ||
| 332 | int run(SrsServer* svr) | 333 | int run(SrsServer* svr) |
| 333 | { | 334 | { |
| 334 | // if not deamon, directly run master. | 335 | // if not deamon, directly run master. |
-
请 注册 或 登录 后发表评论