winlin

fix hls bug, refine config and log, according to clion of jetbrains. 0.9.216.

@@ -208,6 +208,7 @@ Supported operating systems and hardware: @@ -208,6 +208,7 @@ Supported operating systems and hardware:
208 * 2013-10-17, Created.<br/> 208 * 2013-10-17, Created.<br/>
209 209
210 ## History 210 ## History
  211 +* v1.0, 2014-09-26, fix hls bug, refine config and log, according to clion of jetbrains. 0.9.216.
211 * v1.0, 2014-09-25, fix [#177](https://github.com/winlinvip/simple-rtmp-server/issues/177), dvr segment add config dvr_wait_keyframe. 0.9.213. 212 * v1.0, 2014-09-25, fix [#177](https://github.com/winlinvip/simple-rtmp-server/issues/177), dvr segment add config dvr_wait_keyframe. 0.9.213.
212 * v1.0, 2014-08-28, fix [#167](https://github.com/winlinvip/simple-rtmp-server/issues/167), add openssl includes to utest. 0.9.209. 213 * v1.0, 2014-08-28, fix [#167](https://github.com/winlinvip/simple-rtmp-server/issues/167), add openssl includes to utest. 0.9.209.
213 * v1.0, 2014-08-27, max connections is 32756, for st use mmap default. 0.9.209 214 * v1.0, 2014-08-27, max connections is 32756, for st use mmap default. 0.9.209
@@ -50,16 +50,6 @@ using namespace _srs_internal; @@ -50,16 +50,6 @@ using namespace _srs_internal;
50 50
51 #define SRS_WIKI_URL_LOG "https://github.com/winlinvip/simple-rtmp-server/wiki/SrsLog" 51 #define SRS_WIKI_URL_LOG "https://github.com/winlinvip/simple-rtmp-server/wiki/SrsLog"
52 52
53 -#define FILE_OFFSET(fd) lseek(fd, 0, SEEK_CUR)  
54 -  
55 -int64_t FILE_SIZE(int fd)  
56 -{  
57 - int64_t pre = FILE_OFFSET(fd);  
58 - int64_t pos = lseek(fd, 0, SEEK_END);  
59 - lseek(fd, pre, SEEK_SET);  
60 - return pos;  
61 -}  
62 -  
63 // '\n' 53 // '\n'
64 #define __LF (char)0x0a 54 #define __LF (char)0x0a
65 55
@@ -407,6 +397,7 @@ int SrsConfig::reload() @@ -407,6 +397,7 @@ int SrsConfig::reload()
407 int ret = ERROR_SUCCESS; 397 int ret = ERROR_SUCCESS;
408 398
409 SrsConfig conf; 399 SrsConfig conf;
  400 +
410 if ((ret = conf.parse_file(config_file.c_str())) != ERROR_SUCCESS) { 401 if ((ret = conf.parse_file(config_file.c_str())) != ERROR_SUCCESS) {
411 srs_error("ignore config reloader parse file failed. ret=%d", ret); 402 srs_error("ignore config reloader parse file failed. ret=%d", ret);
412 ret = ERROR_SUCCESS; 403 ret = ERROR_SUCCESS;
@@ -414,6 +405,12 @@ int SrsConfig::reload() @@ -414,6 +405,12 @@ int SrsConfig::reload()
414 } 405 }
415 srs_info("config reloader parse file success."); 406 srs_info("config reloader parse file success.");
416 407
  408 + if ((ret = conf.check_config()) != ERROR_SUCCESS) {
  409 + srs_error("ignore config reloader check config failed. ret=%d", ret);
  410 + ret = ERROR_SUCCESS;
  411 + return ret;
  412 + }
  413 +
417 return reload_conf(&conf); 414 return reload_conf(&conf);
418 } 415 }
419 416
@@ -1074,6 +1071,12 @@ int SrsConfig::parse_options(int argc, char** argv) @@ -1074,6 +1071,12 @@ int SrsConfig::parse_options(int argc, char** argv)
1074 ret = parse_file(config_file.c_str()); 1071 ret = parse_file(config_file.c_str());
1075 1072
1076 if (test_conf) { 1073 if (test_conf) {
  1074 + // the parse_file never check the config,
  1075 + // we check it when user requires check config file.
  1076 + if (ret == ERROR_SUCCESS) {
  1077 + ret = check_config();
  1078 + }
  1079 +
1077 if (ret == ERROR_SUCCESS) { 1080 if (ret == ERROR_SUCCESS) {
1078 srs_trace("config file is ok"); 1081 srs_trace("config file is ok");
1079 exit(0); 1082 exit(0);
@@ -1083,6 +1086,25 @@ int SrsConfig::parse_options(int argc, char** argv) @@ -1083,6 +1086,25 @@ int SrsConfig::parse_options(int argc, char** argv)
1083 } 1086 }
1084 } 1087 }
1085 1088
  1089 + ////////////////////////////////////////////////////////////////////////
  1090 + // check log name and level
  1091 + ////////////////////////////////////////////////////////////////////////
  1092 + if (true) {
  1093 + std::string log_filename = this->get_log_file();
  1094 + if (get_log_tank_file() && log_filename.empty()) {
  1095 + ret = ERROR_SYSTEM_CONFIG_INVALID;
  1096 + srs_error("must specifies the file to write log to. ret=%d", ret);
  1097 + return ret;
  1098 + }
  1099 + if (get_log_tank_file()) {
  1100 + srs_trace("write log to file %s", log_filename.c_str());
  1101 + srs_trace("you can: tailf %s", log_filename.c_str());
  1102 + srs_trace("@see: %s", SRS_WIKI_URL_LOG);
  1103 + } else {
  1104 + srs_trace("write log to console");
  1105 + }
  1106 + }
  1107 +
1086 return ret; 1108 return ret;
1087 } 1109 }
1088 1110
@@ -1190,6 +1212,8 @@ int SrsConfig::check_config() @@ -1190,6 +1212,8 @@ int SrsConfig::check_config()
1190 { 1212 {
1191 int ret = ERROR_SUCCESS; 1213 int ret = ERROR_SUCCESS;
1192 1214
  1215 + srs_trace("srs checking config...");
  1216 +
1193 vector<SrsConfDirective*> vhosts = get_vhosts(); 1217 vector<SrsConfDirective*> vhosts = get_vhosts();
1194 1218
1195 //////////////////////////////////////////////////////////////////////// 1219 ////////////////////////////////////////////////////////////////////////
@@ -1629,7 +1653,7 @@ int SrsConfig::parse_buffer(SrsConfigBuffer* buffer) @@ -1629,7 +1653,7 @@ int SrsConfig::parse_buffer(SrsConfigBuffer* buffer)
1629 return ret; 1653 return ret;
1630 } 1654 }
1631 1655
1632 - return check_config(); 1656 + return ret;
1633 } 1657 }
1634 1658
1635 string SrsConfig::cwd() 1659 string SrsConfig::cwd()
@@ -340,6 +340,11 @@ private: @@ -340,6 +340,11 @@ private:
340 * parse the config file, which is specified by cli. 340 * parse the config file, which is specified by cli.
341 */ 341 */
342 virtual int parse_file(const char* filename); 342 virtual int parse_file(const char* filename);
  343 +public:
  344 + /**
  345 + * check the parsed config.
  346 + */
  347 + virtual int check_config();
343 protected: 348 protected:
344 /** 349 /**
345 * parse config from the buffer. 350 * parse config from the buffer.
@@ -347,11 +352,6 @@ protected: @@ -347,11 +352,6 @@ protected:
347 * @remark, use protected for the utest to override with mock. 352 * @remark, use protected for the utest to override with mock.
348 */ 353 */
349 virtual int parse_buffer(_srs_internal::SrsConfigBuffer* buffer); 354 virtual int parse_buffer(_srs_internal::SrsConfigBuffer* buffer);
350 -private:  
351 - /**  
352 - * check the parsed config.  
353 - */  
354 - virtual int check_config();  
355 // global env 355 // global env
356 public: 356 public:
357 /** 357 /**
@@ -38,7 +38,7 @@ SrsStageInfo::SrsStageInfo(int _stage_id) @@ -38,7 +38,7 @@ SrsStageInfo::SrsStageInfo(int _stage_id)
38 { 38 {
39 stage_id = _stage_id; 39 stage_id = _stage_id;
40 nb_clients = 0; 40 nb_clients = 0;
41 - age = printed_age = 0; 41 + age = 0;
42 42
43 update_print_time(); 43 update_print_time();
44 44
@@ -40,7 +40,6 @@ public: @@ -40,7 +40,6 @@ public:
40 int nb_clients; 40 int nb_clients;
41 public: 41 public:
42 int64_t age; 42 int64_t age;
43 - int64_t printed_age;  
44 public: 43 public:
45 SrsStageInfo(int _stage_id); 44 SrsStageInfo(int _stage_id);
46 virtual ~SrsStageInfo(); 45 virtual ~SrsStageInfo();
@@ -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 "215" 34 +#define VERSION_REVISION "216"
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"
@@ -170,6 +170,11 @@ int main(int argc, char** argv) @@ -170,6 +170,11 @@ int main(int argc, char** argv)
170 return ret; 170 return ret;
171 } 171 }
172 172
  173 + // we check the config when the log initialized.
  174 + if ((ret = _srs_config->check_config()) != ERROR_SUCCESS) {
  175 + return ret;
  176 + }
  177 +
173 srs_trace("srs(simple-rtmp-server) "RTMP_SIG_SRS_VERSION); 178 srs_trace("srs(simple-rtmp-server) "RTMP_SIG_SRS_VERSION);
174 srs_trace("license: "RTMP_SIG_SRS_LICENSE); 179 srs_trace("license: "RTMP_SIG_SRS_LICENSE);
175 srs_trace("authors: "RTMP_SIG_SRS_PRIMARY_AUTHROS); 180 srs_trace("authors: "RTMP_SIG_SRS_PRIMARY_AUTHROS);