winlin

refine main object(server, config, log, context), handler reload in intialize(), change to 0.9.59

@@ -350,7 +350,7 @@ class RESTServers(object): @@ -350,7 +350,7 @@ class RESTServers(object):
350 if rtmp_url is None: 350 if rtmp_url is None:
351 return "meeting stream not found" 351 return "meeting stream not found"
352 urls = rtmp_url.replace("...vhost...", "?vhost=").replace("rtmp://", "").split("/") 352 urls = rtmp_url.replace("...vhost...", "?vhost=").replace("rtmp://", "").split("/")
353 - hls_url = "http://%s:8080/%s/%s.m3u8"%(urls[0].replace(":1935",""), urls[1].split("?")[0], urls[2]) 353 + hls_url = "http://%s:8080/%s/%s.m3u8"%(urls[0].strip(":19350").strip(":1935"), urls[1].split("?")[0], urls[2])
354 return """ 354 return """
355 <video width="640" height="360" 355 <video width="640" height="360"
356 autoplay controls autobuffer 356 autoplay controls autobuffer
@@ -31,6 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -31,6 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 #include <fcntl.h> 31 #include <fcntl.h>
32 32
33 #include <srs_app_config.hpp> 33 #include <srs_app_config.hpp>
  34 +#include <srs_kernel_error.hpp>
34 35
35 SrsThreadContext::SrsThreadContext() 36 SrsThreadContext::SrsThreadContext()
36 { 37 {
@@ -65,8 +66,6 @@ SrsFastLog::SrsFastLog() @@ -65,8 +66,6 @@ SrsFastLog::SrsFastLog()
65 log_data = new char[LOG_MAX_SIZE]; 66 log_data = new char[LOG_MAX_SIZE];
66 67
67 fd = -1; 68 fd = -1;
68 -  
69 - // TODO: support reload.  
70 } 69 }
71 70
72 SrsFastLog::~SrsFastLog() 71 SrsFastLog::~SrsFastLog()
@@ -79,6 +78,12 @@ SrsFastLog::~SrsFastLog() @@ -79,6 +78,12 @@ SrsFastLog::~SrsFastLog()
79 } 78 }
80 } 79 }
81 80
  81 +int SrsFastLog::initialize()
  82 +{
  83 + // TODO: support reload.
  84 + return ERROR_SUCCESS;
  85 +}
  86 +
82 int SrsFastLog::level() 87 int SrsFastLog::level()
83 { 88 {
84 return _level; 89 return _level;
@@ -69,6 +69,7 @@ public: @@ -69,6 +69,7 @@ public:
69 SrsFastLog(); 69 SrsFastLog();
70 virtual ~SrsFastLog(); 70 virtual ~SrsFastLog();
71 public: 71 public:
  72 + virtual int initialize();
72 virtual int level(); 73 virtual int level();
73 virtual void set_level(int level); 74 virtual void set_level(int level);
74 virtual void verbose(const char* tag, int context_id, const char* fmt, ...); 75 virtual void verbose(const char* tag, int context_id, const char* fmt, ...);
@@ -160,9 +160,6 @@ SrsServer::SrsServer() @@ -160,9 +160,6 @@ SrsServer::SrsServer()
160 signal_reload = false; 160 signal_reload = false;
161 signal_gmc_stop = false; 161 signal_gmc_stop = false;
162 162
163 - srs_assert(_srs_config);  
164 - _srs_config->subscribe(this);  
165 -  
166 // donot new object in constructor, 163 // donot new object in constructor,
167 // for some global instance is not ready now, 164 // for some global instance is not ready now,
168 // new these objects in initialize instead. 165 // new these objects in initialize instead.
@@ -208,6 +205,12 @@ int SrsServer::initialize() @@ -208,6 +205,12 @@ int SrsServer::initialize()
208 { 205 {
209 int ret = ERROR_SUCCESS; 206 int ret = ERROR_SUCCESS;
210 207
  208 + // for the main objects(server, config, log),
  209 + // never subscribe handler in constructor,
  210 + // instead, subscribe handler in initialize method.
  211 + srs_assert(_srs_config);
  212 + _srs_config->subscribe(this);
  213 +
211 #ifdef SRS_HTTP_API 214 #ifdef SRS_HTTP_API
212 srs_assert(!http_api_handler); 215 srs_assert(!http_api_handler);
213 http_api_handler = SrsHttpHandler::create_http_api(); 216 http_api_handler = SrsHttpHandler::create_http_api();
@@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 // current release version 31 // current release version
32 #define VERSION_MAJOR "0" 32 #define VERSION_MAJOR "0"
33 #define VERSION_MINOR "9" 33 #define VERSION_MINOR "9"
34 -#define VERSION_REVISION "58" 34 +#define VERSION_REVISION "59"
35 #define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION 35 #define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION
36 // server info. 36 // server info.
37 #define RTMP_SIG_SRS_KEY "srs" 37 #define RTMP_SIG_SRS_KEY "srs"
@@ -23,6 +23,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -23,6 +23,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 23
24 #include <srs_kernel_log.hpp> 24 #include <srs_kernel_log.hpp>
25 25
  26 +#include <srs_kernel_error.hpp>
  27 +
26 ISrsLog::ISrsLog() 28 ISrsLog::ISrsLog()
27 { 29 {
28 } 30 }
@@ -31,6 +33,11 @@ ISrsLog::~ISrsLog() @@ -31,6 +33,11 @@ ISrsLog::~ISrsLog()
31 { 33 {
32 } 34 }
33 35
  36 +int ISrsLog::initialize()
  37 +{
  38 + return ERROR_SUCCESS;
  39 +}
  40 +
34 int ISrsLog::level() 41 int ISrsLog::level()
35 { 42 {
36 return SrsLogLevel::Trace; 43 return SrsLogLevel::Trace;
@@ -64,6 +64,11 @@ public: @@ -64,6 +64,11 @@ public:
64 virtual ~ISrsLog(); 64 virtual ~ISrsLog();
65 public: 65 public:
66 /** 66 /**
  67 + * initialize log utilities.
  68 + */
  69 + virtual int initialize();
  70 +public:
  71 + /**
67 * defined in SrsLogLevel. 72 * defined in SrsLogLevel.
68 */ 73 */
69 virtual int level(); 74 virtual int level();
@@ -55,38 +55,61 @@ void handler(int signo) @@ -55,38 +55,61 @@ void handler(int signo)
55 _srs_server->on_signal(signo); 55 _srs_server->on_signal(signo);
56 } 56 }
57 57
58 -int run_master() 58 +int run();
  59 +int run_master();
  60 +
  61 +int main(int argc, char** argv)
59 { 62 {
60 int ret = ERROR_SUCCESS; 63 int ret = ERROR_SUCCESS;
61 64
62 - signal(SIGNAL_RELOAD, handler);  
63 - signal(SIGTERM, handler);  
64 - signal(SIGINT, handler);  
65 -  
66 - if ((ret = _srs_server->acquire_pid_file()) != ERROR_SUCCESS) {  
67 - return ret;  
68 - } 65 + // TODO: support both little and big endian.
  66 + srs_assert(srs_is_little_endian());
  67 +
  68 +#ifdef SRS_GPERF_MP
  69 + HeapProfilerStart("gperf.srs.gmp");
  70 +#endif
  71 +#ifdef SRS_GPERF_CP
  72 + ProfilerStart("gperf.srs.gcp");
  73 +#endif
  74 +
  75 +#ifdef SRS_GPERF_MC
  76 + #ifdef SRS_GPERF_MP
  77 + srs_error("option --with-gmc confict with --with-gmp, "
  78 + "@see: http://google-perftools.googlecode.com/svn/trunk/doc/heap_checker.html\n"
  79 + "Note that since the heap-checker uses the heap-profiling framework internally, "
  80 + "it is not possible to run both the heap-checker and heap profiler at the same time");
  81 + return -1;
  82 + #endif
  83 +#endif
69 84
70 - if ((ret = _srs_server->initialize_st()) != ERROR_SUCCESS) { 85 + // never use srs log(srs_trace, srs_error, etc) before config parse the option,
  86 + // which will load the log config and apply it.
  87 + if ((ret = _srs_config->parse_options(argc, argv)) != ERROR_SUCCESS) {
71 return ret; 88 return ret;
72 } 89 }
73 90
74 - if ((ret = _srs_server->listen()) != ERROR_SUCCESS) { 91 + // config parsed, initialize log.
  92 + if ((ret = _srs_log->initialize()) != ERROR_SUCCESS) {
75 return ret; 93 return ret;
76 } 94 }
  95 + _srs_log->set_level(srs_get_log_level(_srs_config->get_srs_log_level()));
77 96
78 - if ((ret = _srs_server->ingest()) != ERROR_SUCCESS) {  
79 - return ret;  
80 - } 97 + srs_trace("srs(simple-rtmp-server) "RTMP_SIG_SRS_VERSION);
  98 + srs_trace("uname: "SRS_UNAME);
  99 + srs_trace("build: %s, %s", SRS_BUILD_DATE, srs_is_little_endian()? "little-endian":"big-endian");
  100 + srs_trace("configure: "SRS_CONFIGURE);
  101 +#ifdef SRS_ARM_UBUNTU12
  102 + srs_trace("arm tool chain: "SRS_ARM_TOOL_CHAIN);
  103 +#endif
81 104
82 - if ((ret = _srs_server->cycle()) != ERROR_SUCCESS) { 105 + if ((ret = _srs_server->initialize()) != ERROR_SUCCESS) {
83 return ret; 106 return ret;
84 } 107 }
85 108
86 - return 0; 109 + return run();
87 } 110 }
88 111
89 -int run() 112 +int run()
90 { 113 {
91 // if not deamon, directly run master. 114 // if not deamon, directly run master.
92 if (!_srs_config->get_deamon()) { 115 if (!_srs_config->get_deamon()) {
@@ -133,50 +156,33 @@ int run() @@ -133,50 +156,33 @@ int run()
133 return run_master(); 156 return run_master();
134 } 157 }
135 158
136 -int main(int argc, char** argv) 159 +int run_master()
137 { 160 {
138 int ret = ERROR_SUCCESS; 161 int ret = ERROR_SUCCESS;
139 162
140 - // TODO: support both little and big endian.  
141 - srs_assert(srs_is_little_endian());  
142 -  
143 -#ifdef SRS_GPERF_MP  
144 - HeapProfilerStart("gperf.srs.gmp");  
145 -#endif  
146 -#ifdef SRS_GPERF_CP  
147 - ProfilerStart("gperf.srs.gcp");  
148 -#endif  
149 -  
150 -#ifdef SRS_GPERF_MC  
151 - #ifdef SRS_GPERF_MP  
152 - srs_error("option --with-gmc confict with --with-gmp, "  
153 - "@see: http://google-perftools.googlecode.com/svn/trunk/doc/heap_checker.html\n"  
154 - "Note that since the heap-checker uses the heap-profiling framework internally, "  
155 - "it is not possible to run both the heap-checker and heap profiler at the same time");  
156 - return -1;  
157 - #endif  
158 -#endif 163 + signal(SIGNAL_RELOAD, handler);
  164 + signal(SIGTERM, handler);
  165 + signal(SIGINT, handler);
159 166
160 - // never use srs log(srs_trace, srs_error, etc) before config parse the option,  
161 - // which will load the log config and apply it.  
162 - if ((ret = _srs_config->parse_options(argc, argv)) != ERROR_SUCCESS) { 167 + if ((ret = _srs_server->acquire_pid_file()) != ERROR_SUCCESS) {
163 return ret; 168 return ret;
164 } 169 }
165 170
166 - // config parsed, initialize log.  
167 - _srs_log->set_level(srs_get_log_level(_srs_config->get_srs_log_level())); 171 + if ((ret = _srs_server->initialize_st()) != ERROR_SUCCESS) {
  172 + return ret;
  173 + }
168 174
169 - srs_trace("srs(simple-rtmp-server) "RTMP_SIG_SRS_VERSION);  
170 - srs_trace("uname: "SRS_UNAME);  
171 - srs_trace("build: %s, %s", SRS_BUILD_DATE, srs_is_little_endian()? "little-endian":"big-endian");  
172 - srs_trace("configure: "SRS_CONFIGURE);  
173 -#ifdef SRS_ARM_UBUNTU12  
174 - srs_trace("arm tool chain: "SRS_ARM_TOOL_CHAIN);  
175 -#endif 175 + if ((ret = _srs_server->listen()) != ERROR_SUCCESS) {
  176 + return ret;
  177 + }
176 178
177 - if ((ret = _srs_server->initialize()) != ERROR_SUCCESS) { 179 + if ((ret = _srs_server->ingest()) != ERROR_SUCCESS) {
178 return ret; 180 return ret;
179 } 181 }
180 182
181 - return run(); 183 + if ((ret = _srs_server->cycle()) != ERROR_SUCCESS) {
  184 + return ret;
  185 + }
  186 +
  187 + return 0;
182 } 188 }