正在显示
8 个修改的文件
包含
84 行增加
和
8 行删除
| @@ -42,6 +42,13 @@ int main(int argc, char** argv) | @@ -42,6 +42,13 @@ int main(int argc, char** argv) | ||
| 42 | printf("publish rtmp stream to server like FMLE/FFMPEG/Encoder\n"); | 42 | printf("publish rtmp stream to server like FMLE/FFMPEG/Encoder\n"); |
| 43 | printf("srs(simple-rtmp-server) client librtmp library.\n"); | 43 | printf("srs(simple-rtmp-server) client librtmp library.\n"); |
| 44 | printf("version: %d.%d.%d\n", srs_version_major(), srs_version_minor(), srs_version_revision()); | 44 | printf("version: %d.%d.%d\n", srs_version_major(), srs_version_minor(), srs_version_revision()); |
| 45 | + // warn it . | ||
| 46 | + // @see: https://github.com/winlinvip/simple-rtmp-server/issues/126 | ||
| 47 | + printf("\033[33m%s\033[0m", | ||
| 48 | + "[warning] it's only a sample to use librtmp. " | ||
| 49 | + "please never use it to publish and test forward/transcode/edge/HLS whatever. " | ||
| 50 | + "you should refer to this tool to use the srs-librtmp to publish the real media stream."); | ||
| 51 | + printf("\n"); | ||
| 45 | 52 | ||
| 46 | rtmp = srs_rtmp_create("rtmp://127.0.0.1:1935/live/livestream"); | 53 | rtmp = srs_rtmp_create("rtmp://127.0.0.1:1935/live/livestream"); |
| 47 | 54 |
| @@ -80,17 +80,21 @@ SrsFastLog::~SrsFastLog() | @@ -80,17 +80,21 @@ SrsFastLog::~SrsFastLog() | ||
| 80 | fd = -1; | 80 | fd = -1; |
| 81 | } | 81 | } |
| 82 | 82 | ||
| 83 | - _srs_config->unsubscribe(this); | 83 | + if (_srs_config) { |
| 84 | + _srs_config->unsubscribe(this); | ||
| 85 | + } | ||
| 84 | } | 86 | } |
| 85 | 87 | ||
| 86 | int SrsFastLog::initialize() | 88 | int SrsFastLog::initialize() |
| 87 | { | 89 | { |
| 88 | int ret = ERROR_SUCCESS; | 90 | int ret = ERROR_SUCCESS; |
| 89 | 91 | ||
| 90 | - _srs_config->subscribe(this); | ||
| 91 | - | ||
| 92 | - log_to_file_tank = _srs_config->get_log_tank_file(); | ||
| 93 | - _level = srs_get_log_level(_srs_config->get_log_level()); | 92 | + if (_srs_config) { |
| 93 | + _srs_config->subscribe(this); | ||
| 94 | + | ||
| 95 | + log_to_file_tank = _srs_config->get_log_tank_file(); | ||
| 96 | + _level = srs_get_log_level(_srs_config->get_log_level()); | ||
| 97 | + } | ||
| 94 | 98 | ||
| 95 | return ret; | 99 | return ret; |
| 96 | } | 100 | } |
| @@ -60,7 +60,8 @@ public: | @@ -60,7 +60,8 @@ public: | ||
| 60 | */ | 60 | */ |
| 61 | class SrsFastLog : public ISrsLog, public ISrsReloadHandler | 61 | class SrsFastLog : public ISrsLog, public ISrsReloadHandler |
| 62 | { | 62 | { |
| 63 | -private: | 63 | +// for utest to override |
| 64 | +protected: | ||
| 64 | // defined in SrsLogLevel. | 65 | // defined in SrsLogLevel. |
| 65 | int _level; | 66 | int _level; |
| 66 | char* log_data; | 67 | char* log_data; |
| @@ -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 "171" | 34 | +#define VERSION_REVISION "172" |
| 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" |
| @@ -52,6 +52,8 @@ public: | @@ -52,6 +52,8 @@ public: | ||
| 52 | static const int Trace = 0x03; | 52 | static const int Trace = 0x03; |
| 53 | static const int Warn = 0x04; | 53 | static const int Warn = 0x04; |
| 54 | static const int Error = 0x05; | 54 | static const int Error = 0x05; |
| 55 | + // specified the disabled level, no log, for utest. | ||
| 56 | + static const int Disabled = 0x06; | ||
| 55 | }; | 57 | }; |
| 56 | 58 | ||
| 57 | /** | 59 | /** |
| @@ -30,12 +30,36 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -30,12 +30,36 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 30 | #include <srs_app_log.hpp> | 30 | #include <srs_app_log.hpp> |
| 31 | 31 | ||
| 32 | // kernel module. | 32 | // kernel module. |
| 33 | -ISrsLog* _srs_log = new ISrsLog(); | 33 | +ISrsLog* _srs_log = new MockEmptyLog(SrsLogLevel::Disabled); |
| 34 | ISrsThreadContext* _srs_context = new ISrsThreadContext(); | 34 | ISrsThreadContext* _srs_context = new ISrsThreadContext(); |
| 35 | // app module. | 35 | // app module. |
| 36 | SrsConfig* _srs_config = NULL; | 36 | SrsConfig* _srs_config = NULL; |
| 37 | SrsServer* _srs_server = NULL; | 37 | SrsServer* _srs_server = NULL; |
| 38 | 38 | ||
| 39 | +MockEmptyLog::MockEmptyLog(int level) | ||
| 40 | +{ | ||
| 41 | + _level = level; | ||
| 42 | +} | ||
| 43 | + | ||
| 44 | +MockEmptyLog::~MockEmptyLog() | ||
| 45 | +{ | ||
| 46 | +} | ||
| 47 | + | ||
| 48 | +int MockEmptyLog::on_reload_log_tank() | ||
| 49 | +{ | ||
| 50 | + return ERROR_SUCCESS; | ||
| 51 | +} | ||
| 52 | + | ||
| 53 | +int MockEmptyLog::on_reload_log_level() | ||
| 54 | +{ | ||
| 55 | + return ERROR_SUCCESS; | ||
| 56 | +} | ||
| 57 | + | ||
| 58 | +int MockEmptyLog::on_reload_log_file() | ||
| 59 | +{ | ||
| 60 | + return ERROR_SUCCESS; | ||
| 61 | +} | ||
| 62 | + | ||
| 39 | void __srs_bytes_print(char* pa, int size) | 63 | void __srs_bytes_print(char* pa, int size) |
| 40 | { | 64 | { |
| 41 | for(int i = 0; i < size; i++) { | 65 | for(int i = 0; i < size; i++) { |
| @@ -31,6 +31,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -31,6 +31,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 31 | 31 | ||
| 32 | #include "gtest/gtest.h" | 32 | #include "gtest/gtest.h" |
| 33 | 33 | ||
| 34 | +#include <srs_app_log.hpp> | ||
| 35 | + | ||
| 34 | // we add an empty macro for upp to show the smart tips. | 36 | // we add an empty macro for upp to show the smart tips. |
| 35 | #define VOID | 37 | #define VOID |
| 36 | 38 | ||
| @@ -52,4 +54,17 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -52,4 +54,17 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 52 | // print the bytes. | 54 | // print the bytes. |
| 53 | void __srs_bytes_print(char* pa, int size); | 55 | void __srs_bytes_print(char* pa, int size); |
| 54 | 56 | ||
| 57 | +class MockEmptyLog : public SrsFastLog | ||
| 58 | +{ | ||
| 59 | +private: | ||
| 60 | + int _level; | ||
| 61 | +public: | ||
| 62 | + MockEmptyLog(int level); | ||
| 63 | + virtual ~MockEmptyLog(); | ||
| 64 | +public: | ||
| 65 | + virtual int on_reload_log_tank(); | ||
| 66 | + virtual int on_reload_log_level(); | ||
| 67 | + virtual int on_reload_log_file(); | ||
| 68 | +}; | ||
| 69 | + | ||
| 55 | #endif | 70 | #endif |
| @@ -4341,3 +4341,26 @@ VOID TEST(ConfigMainTest, ParseFullConf_removed) | @@ -4341,3 +4341,26 @@ VOID TEST(ConfigMainTest, ParseFullConf_removed) | ||
| 4341 | EXPECT_STREQ("/", conf.get_vhost_http_mount(vhost).c_str()); | 4341 | EXPECT_STREQ("/", conf.get_vhost_http_mount(vhost).c_str()); |
| 4342 | EXPECT_STREQ("./objs/nginx/html", conf.get_vhost_http_dir(vhost).c_str()); | 4342 | EXPECT_STREQ("./objs/nginx/html", conf.get_vhost_http_dir(vhost).c_str()); |
| 4343 | } | 4343 | } |
| 4344 | + | ||
| 4345 | +VOID TEST(ConfigMainTest, CheckConf_listen) | ||
| 4346 | +{ | ||
| 4347 | + if (true) { | ||
| 4348 | + MockSrsConfig conf; | ||
| 4349 | + EXPECT_TRUE(ERROR_SUCCESS != conf.parse("listens 1935;")); | ||
| 4350 | + } | ||
| 4351 | + | ||
| 4352 | + if (true) { | ||
| 4353 | + MockSrsConfig conf; | ||
| 4354 | + EXPECT_TRUE(ERROR_SUCCESS != conf.parse("listen 0;")); | ||
| 4355 | + } | ||
| 4356 | + | ||
| 4357 | + if (true) { | ||
| 4358 | + MockSrsConfig conf; | ||
| 4359 | + EXPECT_TRUE(ERROR_SUCCESS != conf.parse("listen -1;")); | ||
| 4360 | + } | ||
| 4361 | + | ||
| 4362 | + if (true) { | ||
| 4363 | + MockSrsConfig conf; | ||
| 4364 | + EXPECT_TRUE(ERROR_SUCCESS != conf.parse("listen -1935;")); | ||
| 4365 | + } | ||
| 4366 | +} |
-
请 注册 或 登录 后发表评论