正在显示
3 个修改的文件
包含
134 行增加
和
139 行删除
| @@ -64,8 +64,6 @@ SrsFFMPEG::SrsFFMPEG(std::string ffmpeg_bin) | @@ -64,8 +64,6 @@ SrsFFMPEG::SrsFFMPEG(std::string ffmpeg_bin) | ||
| 64 | abitrate = 0; | 64 | abitrate = 0; |
| 65 | asample_rate = 0; | 65 | asample_rate = 0; |
| 66 | achannels = 0; | 66 | achannels = 0; |
| 67 | - | ||
| 68 | - log_fd = -1; | ||
| 69 | } | 67 | } |
| 70 | 68 | ||
| 71 | SrsFFMPEG::~SrsFFMPEG() | 69 | SrsFFMPEG::~SrsFFMPEG() |
| @@ -375,6 +373,7 @@ int SrsFFMPEG::start() | @@ -375,6 +373,7 @@ int SrsFFMPEG::start() | ||
| 375 | // child process: ffmpeg encoder engine. | 373 | // child process: ffmpeg encoder engine. |
| 376 | if (pid == 0) { | 374 | if (pid == 0) { |
| 377 | // redirect logs to file. | 375 | // redirect logs to file. |
| 376 | + int log_fd = -1; | ||
| 378 | int flags = O_CREAT|O_WRONLY|O_APPEND; | 377 | int flags = O_CREAT|O_WRONLY|O_APPEND; |
| 379 | mode_t mode = S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH; | 378 | mode_t mode = S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH; |
| 380 | if ((log_fd = ::open(log_file.c_str(), flags, mode)) < 0) { | 379 | if ((log_fd = ::open(log_file.c_str(), flags, mode)) < 0) { |
| @@ -392,6 +391,8 @@ int SrsFFMPEG::start() | @@ -392,6 +391,8 @@ int SrsFFMPEG::start() | ||
| 392 | srs_error("dup2 encoder file failed. ret=%d", ret); | 391 | srs_error("dup2 encoder file failed. ret=%d", ret); |
| 393 | return ret; | 392 | return ret; |
| 394 | } | 393 | } |
| 394 | + // close log fd | ||
| 395 | + ::close(log_fd); | ||
| 395 | // close other fds | 396 | // close other fds |
| 396 | // TODO: do in right way. | 397 | // TODO: do in right way. |
| 397 | for (int i = 3; i < 1024; i++) { | 398 | for (int i = 3; i < 1024; i++) { |
| @@ -456,11 +457,6 @@ int SrsFFMPEG::cycle() | @@ -456,11 +457,6 @@ int SrsFFMPEG::cycle() | ||
| 456 | 457 | ||
| 457 | void SrsFFMPEG::stop() | 458 | void SrsFFMPEG::stop() |
| 458 | { | 459 | { |
| 459 | - if (log_fd > 0) { | ||
| 460 | - ::close(log_fd); | ||
| 461 | - log_fd = -1; | ||
| 462 | - } | ||
| 463 | - | ||
| 464 | if (!started) { | 460 | if (!started) { |
| 465 | return; | 461 | return; |
| 466 | } | 462 | } |
trunk/src/core/srs_core.hpp
100644 → 100755
| 1 | -/* | ||
| 2 | -The MIT License (MIT) | ||
| 3 | - | ||
| 4 | -Copyright (c) 2013-2014 winlin | ||
| 5 | - | ||
| 6 | -Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
| 7 | -this software and associated documentation files (the "Software"), to deal in | ||
| 8 | -the Software without restriction, including without limitation the rights to | ||
| 9 | -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
| 10 | -the Software, and to permit persons to whom the Software is furnished to do so, | ||
| 11 | -subject to the following conditions: | ||
| 12 | - | ||
| 13 | -The above copyright notice and this permission notice shall be included in all | ||
| 14 | -copies or substantial portions of the Software. | ||
| 15 | - | ||
| 16 | -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| 17 | -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
| 18 | -FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
| 19 | -COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
| 20 | -IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
| 21 | -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 22 | -*/ | ||
| 23 | - | ||
| 24 | -#ifndef SRS_CORE_HPP | ||
| 25 | -#define SRS_CORE_HPP | ||
| 26 | - | ||
| 27 | -/* | ||
| 28 | -#include <srs_core.hpp> | ||
| 29 | -*/ | ||
| 30 | - | ||
| 31 | -// current release version | ||
| 32 | -#define VERSION_MAJOR "0" | ||
| 33 | -#define VERSION_MINOR "9" | ||
| 34 | -#define VERSION_REVISION "93" | ||
| 35 | -#define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION | ||
| 36 | -// server info. | ||
| 37 | -#define RTMP_SIG_SRS_KEY "srs" | ||
| 38 | -#define RTMP_SIG_SRS_ROLE "origin/edge server" | ||
| 39 | -#define RTMP_SIG_SRS_NAME RTMP_SIG_SRS_KEY"(simple rtmp server)" | ||
| 40 | -#define RTMP_SIG_SRS_URL_SHORT "github.com/winlinvip/simple-rtmp-server" | ||
| 41 | -#define RTMP_SIG_SRS_URL "https://"RTMP_SIG_SRS_URL_SHORT | ||
| 42 | -#define RTMP_SIG_SRS_WEB "http://blog.csdn.net/win_lin" | ||
| 43 | -#define RTMP_SIG_SRS_EMAIL "winlin@vip.126.com" | ||
| 44 | -#define RTMP_SIG_SRS_LICENSE "The MIT License (MIT)" | ||
| 45 | -#define RTMP_SIG_SRS_COPYRIGHT "Copyright (c) 2013-2014 winlin" | ||
| 46 | -#define RTMP_SIG_SRS_PRIMARY_AUTHROS "winlin,wenjie.zhao" | ||
| 47 | -#define RTMP_SIG_SRS_CONTRIBUTORS_URL RTMP_SIG_SRS_URL"/blob/master/AUTHORS.txt" | ||
| 48 | - | ||
| 49 | -/** | ||
| 50 | -* the core provides the common defined macros, utilities, | ||
| 51 | -* user must include the srs_core.hpp before any header, or maybe | ||
| 52 | -* build failed. | ||
| 53 | -*/ | ||
| 54 | - | ||
| 55 | -// for 32bit os, 2G big file limit for unistd io, | ||
| 56 | -// ie. read/write/lseek to use 64bits size for huge file. | ||
| 57 | -#ifndef _FILE_OFFSET_BITS | ||
| 58 | - #define _FILE_OFFSET_BITS 64 | ||
| 59 | -#endif | ||
| 60 | - | ||
| 61 | -// for int64_t print using PRId64 format. | ||
| 62 | -#ifndef __STDC_FORMAT_MACROS | ||
| 63 | - #define __STDC_FORMAT_MACROS | ||
| 64 | -#endif | ||
| 65 | -#include <inttypes.h> | ||
| 66 | - | ||
| 67 | -#include <assert.h> | ||
| 68 | -#define srs_assert(expression) assert(expression) | ||
| 69 | - | ||
| 70 | -#include <stddef.h> | ||
| 71 | -#include <sys/types.h> | ||
| 72 | - | ||
| 73 | -// generated by configure. | ||
| 74 | -#include <srs_auto_headers.hpp> | ||
| 75 | - | ||
| 76 | -// free the p and set to NULL. | ||
| 77 | -// p must be a T*. | ||
| 78 | -#define srs_freep(p) \ | ||
| 79 | - if (p) { \ | ||
| 80 | - delete p; \ | ||
| 81 | - p = NULL; \ | ||
| 82 | - } \ | ||
| 83 | - (void)0 | ||
| 84 | -// free the p which represents a array | ||
| 85 | -#define srs_freepa(p) \ | ||
| 86 | - if (p) { \ | ||
| 87 | - delete[] p; \ | ||
| 88 | - p = NULL; \ | ||
| 89 | - } \ | ||
| 90 | - (void)0 | ||
| 91 | - | ||
| 92 | -// compare | ||
| 93 | -#define srs_min(a, b) (((a) < (b))? (a) : (b)) | ||
| 94 | -#define srs_max(a, b) (((a) < (b))? (b) : (a)) | ||
| 95 | - | ||
| 96 | -// signal defines. | ||
| 97 | -#define SIGNAL_RELOAD SIGHUP | ||
| 98 | - | ||
| 99 | -#include <string> | ||
| 100 | -// replace old_str to new_str of str | ||
| 101 | -extern std::string srs_string_replace(std::string str, std::string old_str, std::string new_str); | ||
| 102 | -// trim char in trim_chars of str | ||
| 103 | -extern std::string srs_string_trim_end(std::string str, std::string trim_chars); | ||
| 104 | -// trim char in trim_chars of str | ||
| 105 | -extern std::string srs_string_trim_start(std::string str, std::string trim_chars); | ||
| 106 | -// remove char in remove_chars of str | ||
| 107 | -extern std::string srs_string_remove(std::string str, std::string remove_chars); | ||
| 108 | -// whether string end with | ||
| 109 | -extern bool srs_string_ends_with(std::string str, std::string flag); | ||
| 110 | - | ||
| 111 | -// dns resolve utility, return the resolved ip address. | ||
| 112 | -extern std::string srs_dns_resolve(std::string host); | ||
| 113 | -// whether system is little endian | ||
| 114 | -extern bool srs_is_little_endian(); | ||
| 115 | - | ||
| 116 | -/** | ||
| 117 | -* disable copy constructor of class | ||
| 118 | -*/ | ||
| 119 | -#define disable_default_copy(className)\ | ||
| 120 | - private:\ | ||
| 121 | - /** \ | ||
| 122 | - * disable the copy constructor and operator=, donot allow directly copy. \ | ||
| 123 | - */ \ | ||
| 124 | - className(const className&); \ | ||
| 125 | - className& operator= (const className&) | ||
| 126 | - | ||
| 127 | -// const time for st to convert to us | ||
| 128 | -#define SRS_TIME_MILLISECONDS 1000 | ||
| 129 | -#define SRS_TIME_SECONDS 1000000 | ||
| 130 | - | ||
| 131 | -#endif | 1 | +/* |
| 2 | +The MIT License (MIT) | ||
| 3 | + | ||
| 4 | +Copyright (c) 2013-2014 winlin | ||
| 5 | + | ||
| 6 | +Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
| 7 | +this software and associated documentation files (the "Software"), to deal in | ||
| 8 | +the Software without restriction, including without limitation the rights to | ||
| 9 | +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
| 10 | +the Software, and to permit persons to whom the Software is furnished to do so, | ||
| 11 | +subject to the following conditions: | ||
| 12 | + | ||
| 13 | +The above copyright notice and this permission notice shall be included in all | ||
| 14 | +copies or substantial portions of the Software. | ||
| 15 | + | ||
| 16 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| 17 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
| 18 | +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
| 19 | +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
| 20 | +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
| 21 | +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 22 | +*/ | ||
| 23 | + | ||
| 24 | +#ifndef SRS_CORE_HPP | ||
| 25 | +#define SRS_CORE_HPP | ||
| 26 | + | ||
| 27 | +/* | ||
| 28 | +#include <srs_core.hpp> | ||
| 29 | +*/ | ||
| 30 | + | ||
| 31 | +// current release version | ||
| 32 | +#define VERSION_MAJOR "0" | ||
| 33 | +#define VERSION_MINOR "9" | ||
| 34 | +#define VERSION_REVISION "94" | ||
| 35 | +#define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION | ||
| 36 | +// server info. | ||
| 37 | +#define RTMP_SIG_SRS_KEY "srs" | ||
| 38 | +#define RTMP_SIG_SRS_ROLE "origin/edge server" | ||
| 39 | +#define RTMP_SIG_SRS_NAME RTMP_SIG_SRS_KEY"(simple rtmp server)" | ||
| 40 | +#define RTMP_SIG_SRS_URL_SHORT "github.com/winlinvip/simple-rtmp-server" | ||
| 41 | +#define RTMP_SIG_SRS_URL "https://"RTMP_SIG_SRS_URL_SHORT | ||
| 42 | +#define RTMP_SIG_SRS_WEB "http://blog.csdn.net/win_lin" | ||
| 43 | +#define RTMP_SIG_SRS_EMAIL "winlin@vip.126.com" | ||
| 44 | +#define RTMP_SIG_SRS_LICENSE "The MIT License (MIT)" | ||
| 45 | +#define RTMP_SIG_SRS_COPYRIGHT "Copyright (c) 2013-2014 winlin" | ||
| 46 | +#define RTMP_SIG_SRS_PRIMARY_AUTHROS "winlin,wenjie.zhao" | ||
| 47 | +#define RTMP_SIG_SRS_CONTRIBUTORS_URL RTMP_SIG_SRS_URL"/blob/master/AUTHORS.txt" | ||
| 48 | + | ||
| 49 | +/** | ||
| 50 | +* the core provides the common defined macros, utilities, | ||
| 51 | +* user must include the srs_core.hpp before any header, or maybe | ||
| 52 | +* build failed. | ||
| 53 | +*/ | ||
| 54 | + | ||
| 55 | +// for 32bit os, 2G big file limit for unistd io, | ||
| 56 | +// ie. read/write/lseek to use 64bits size for huge file. | ||
| 57 | +#ifndef _FILE_OFFSET_BITS | ||
| 58 | + #define _FILE_OFFSET_BITS 64 | ||
| 59 | +#endif | ||
| 60 | + | ||
| 61 | +// for int64_t print using PRId64 format. | ||
| 62 | +#ifndef __STDC_FORMAT_MACROS | ||
| 63 | + #define __STDC_FORMAT_MACROS | ||
| 64 | +#endif | ||
| 65 | +#include <inttypes.h> | ||
| 66 | + | ||
| 67 | +#include <assert.h> | ||
| 68 | +#define srs_assert(expression) assert(expression) | ||
| 69 | + | ||
| 70 | +#include <stddef.h> | ||
| 71 | +#include <sys/types.h> | ||
| 72 | + | ||
| 73 | +// generated by configure. | ||
| 74 | +#include <srs_auto_headers.hpp> | ||
| 75 | + | ||
| 76 | +// free the p and set to NULL. | ||
| 77 | +// p must be a T*. | ||
| 78 | +#define srs_freep(p) \ | ||
| 79 | + if (p) { \ | ||
| 80 | + delete p; \ | ||
| 81 | + p = NULL; \ | ||
| 82 | + } \ | ||
| 83 | + (void)0 | ||
| 84 | +// free the p which represents a array | ||
| 85 | +#define srs_freepa(p) \ | ||
| 86 | + if (p) { \ | ||
| 87 | + delete[] p; \ | ||
| 88 | + p = NULL; \ | ||
| 89 | + } \ | ||
| 90 | + (void)0 | ||
| 91 | + | ||
| 92 | +// compare | ||
| 93 | +#define srs_min(a, b) (((a) < (b))? (a) : (b)) | ||
| 94 | +#define srs_max(a, b) (((a) < (b))? (b) : (a)) | ||
| 95 | + | ||
| 96 | +// signal defines. | ||
| 97 | +#define SIGNAL_RELOAD SIGHUP | ||
| 98 | + | ||
| 99 | +#include <string> | ||
| 100 | +// replace old_str to new_str of str | ||
| 101 | +extern std::string srs_string_replace(std::string str, std::string old_str, std::string new_str); | ||
| 102 | +// trim char in trim_chars of str | ||
| 103 | +extern std::string srs_string_trim_end(std::string str, std::string trim_chars); | ||
| 104 | +// trim char in trim_chars of str | ||
| 105 | +extern std::string srs_string_trim_start(std::string str, std::string trim_chars); | ||
| 106 | +// remove char in remove_chars of str | ||
| 107 | +extern std::string srs_string_remove(std::string str, std::string remove_chars); | ||
| 108 | +// whether string end with | ||
| 109 | +extern bool srs_string_ends_with(std::string str, std::string flag); | ||
| 110 | + | ||
| 111 | +// dns resolve utility, return the resolved ip address. | ||
| 112 | +extern std::string srs_dns_resolve(std::string host); | ||
| 113 | +// whether system is little endian | ||
| 114 | +extern bool srs_is_little_endian(); | ||
| 115 | + | ||
| 116 | +/** | ||
| 117 | +* disable copy constructor of class | ||
| 118 | +*/ | ||
| 119 | +#define disable_default_copy(className)\ | ||
| 120 | + private:\ | ||
| 121 | + /** \ | ||
| 122 | + * disable the copy constructor and operator=, donot allow directly copy. \ | ||
| 123 | + */ \ | ||
| 124 | + className(const className&); \ | ||
| 125 | + className& operator= (const className&) | ||
| 126 | + | ||
| 127 | +// const time for st to convert to us | ||
| 128 | +#define SRS_TIME_MILLISECONDS 1000 | ||
| 129 | +#define SRS_TIME_SECONDS 1000000 | ||
| 130 | + | ||
| 131 | +#endif |
-
请 注册 或 登录 后发表评论