winlin

refine core, move specified functions to kernel utility.

@@ -346,7 +346,7 @@ function write_nginx_html5() @@ -346,7 +346,7 @@ function write_nginx_html5()
346 END 346 END
347 } 347 }
348 # create the nginx dir, for http-server if not build nginx 348 # create the nginx dir, for http-server if not build nginx
349 -rm -rf ${SRS_OBJS}/nginx && mkdir -p ${SRS_OBJS}/nginx 349 +mkdir -p ${SRS_OBJS}/nginx
350 # make nginx 350 # make nginx
351 __SRS_BUILD_NGINX=NO; if [ $SRS_EMBEDED_CPU = NO ]; then if [ $SRS_NGINX = YES ]; then __SRS_BUILD_NGINX=YES; fi fi 351 __SRS_BUILD_NGINX=NO; if [ $SRS_EMBEDED_CPU = NO ]; then if [ $SRS_NGINX = YES ]; then __SRS_BUILD_NGINX=YES; fi fi
352 if [ $__SRS_BUILD_NGINX = YES ]; then 352 if [ $__SRS_BUILD_NGINX = YES ]; then
@@ -70,6 +70,8 @@ SRS_PURE_RTMP=NO @@ -70,6 +70,8 @@ SRS_PURE_RTMP=NO
70 SRS_RTMP_HLS=NO 70 SRS_RTMP_HLS=NO
71 # the most fast compile, nothing, only support vp6 RTMP. 71 # the most fast compile, nothing, only support vp6 RTMP.
72 SRS_DISABLE_ALL=NO 72 SRS_DISABLE_ALL=NO
  73 +# all features is on
  74 +SRS_ENABLE_ALL=NO
73 # 75 #
74 # calc 76 # calc
75 # whether embed cpu, arm/mips 77 # whether embed cpu, arm/mips
@@ -146,6 +148,7 @@ Presets: @@ -146,6 +148,7 @@ Presets:
146 --pure-rtmp only support RTMP with ssl. 148 --pure-rtmp only support RTMP with ssl.
147 --rtmp-hls only support RTMP+HLS with ssl. 149 --rtmp-hls only support RTMP+HLS with ssl.
148 --disable-all disable all features, only support vp6 RTMP. 150 --disable-all disable all features, only support vp6 RTMP.
  151 + --full enable all features.
149 152
150 Conflicts: 153 Conflicts:
151 1. --with-gmc vs --with-gmp: 154 1. --with-gmc vs --with-gmp:
@@ -229,6 +232,7 @@ function parse_user_option() { @@ -229,6 +232,7 @@ function parse_user_option() {
229 --disable-all) SRS_DISABLE_ALL=YES ;; 232 --disable-all) SRS_DISABLE_ALL=YES ;;
230 --pure-rtmp) SRS_PURE_RTMP=YES ;; 233 --pure-rtmp) SRS_PURE_RTMP=YES ;;
231 --rtmp-hls) SRS_RTMP_HLS=YES ;; 234 --rtmp-hls) SRS_RTMP_HLS=YES ;;
  235 + --full) SRS_ENABLE_ALL=YES ;;
232 236
233 --use-sys-ssl) SRS_USE_SYS_SSL=YES ;; 237 --use-sys-ssl) SRS_USE_SYS_SSL=YES ;;
234 238
@@ -272,12 +276,14 @@ function apply_user_presets() { @@ -272,12 +276,14 @@ function apply_user_presets() {
272 if [ $SRS_PURE_RTMP = NO ]; then 276 if [ $SRS_PURE_RTMP = NO ]; then
273 if [ $SRS_FAST = NO ]; then 277 if [ $SRS_FAST = NO ]; then
274 if [ $SRS_DISABLE_ALL = NO ]; then 278 if [ $SRS_DISABLE_ALL = NO ]; then
275 - if [ $SRS_DEV = NO ]; then  
276 - if [ $SRS_ARM_UBUNTU12 = NO ]; then  
277 - if [ $SRS_MIPS_UBUNTU12 = NO ]; then  
278 - if [ $SRS_PI = NO ]; then  
279 - if [ $SRS_X86_X64 = NO ]; then  
280 - SRS_X86_X64=YES; opt="--x86-x64 $opt"; 279 + if [ $SRS_ENABLE_ALL = NO ]; then
  280 + if [ $SRS_DEV = NO ]; then
  281 + if [ $SRS_ARM_UBUNTU12 = NO ]; then
  282 + if [ $SRS_MIPS_UBUNTU12 = NO ]; then
  283 + if [ $SRS_PI = NO ]; then
  284 + if [ $SRS_X86_X64 = NO ]; then
  285 + SRS_X86_X64=YES; opt="--x86-x64 $opt";
  286 + fi
281 fi 287 fi
282 fi 288 fi
283 fi 289 fi
@@ -321,6 +327,31 @@ function apply_user_presets() { @@ -321,6 +327,31 @@ function apply_user_presets() {
321 SRS_STATIC=NO 327 SRS_STATIC=NO
322 fi 328 fi
323 329
  330 + # all enabled.
  331 + if [ $SRS_ENABLE_ALL = YES ]; then
  332 + SRS_HLS=YES
  333 + SRS_DVR=YES
  334 + SRS_NGINX=YES
  335 + SRS_SSL=YES
  336 + SRS_FFMPEG_TOOL=YES
  337 + SRS_TRANSCODE=YES
  338 + SRS_INGEST=YES
  339 + SRS_HTTP_PARSER=YES
  340 + SRS_HTTP_CALLBACK=YES
  341 + SRS_HTTP_SERVER=YES
  342 + SRS_HTTP_API=YES
  343 + SRS_LIBRTMP=YES
  344 + SRS_BWTC=YES
  345 + SRS_RESEARCH=YES
  346 + SRS_UTEST=YES
  347 + SRS_GPERF=NO
  348 + SRS_GPERF_MC=NO
  349 + SRS_GPERF_MP=NO
  350 + SRS_GPERF_CP=NO
  351 + SRS_GPROF=NO
  352 + SRS_STATIC=NO
  353 + fi
  354 +
324 # only rtmp vp6 355 # only rtmp vp6
325 if [ $SRS_FAST = YES ]; then 356 if [ $SRS_FAST = YES ]; then
326 SRS_HLS=NO 357 SRS_HLS=NO
@@ -29,6 +29,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -29,6 +29,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 */ 29 */
30 #include <srs_core.hpp> 30 #include <srs_core.hpp>
31 31
  32 +#include <string>
  33 +
32 #ifdef SRS_AUTO_DVR 34 #ifdef SRS_AUTO_DVR
33 35
34 class SrsSource; 36 class SrsSource;
@@ -238,4 +240,4 @@ public: @@ -238,4 +240,4 @@ public:
238 240
239 #endif 241 #endif
240 242
241 -#endif  
  243 +#endif
@@ -43,6 +43,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -43,6 +43,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
43 #include <srs_core_autofree.hpp> 43 #include <srs_core_autofree.hpp>
44 #include <srs_app_socket.hpp> 44 #include <srs_app_socket.hpp>
45 #include <srs_app_kbps.hpp> 45 #include <srs_app_kbps.hpp>
  46 +#include <srs_kernel_utility.hpp>
46 47
47 // when error, edge ingester sleep for a while and retry. 48 // when error, edge ingester sleep for a while and retry.
48 #define SRS_EDGE_INGESTER_SLEEP_US (int64_t)(1*1000*1000LL) 49 #define SRS_EDGE_INGESTER_SLEEP_US (int64_t)(1*1000*1000LL)
@@ -33,6 +33,7 @@ using namespace std; @@ -33,6 +33,7 @@ using namespace std;
33 #include <srs_app_pithy_print.hpp> 33 #include <srs_app_pithy_print.hpp>
34 #include <srs_protocol_rtmp_stack.hpp> 34 #include <srs_protocol_rtmp_stack.hpp>
35 #include <srs_app_ffmpeg.hpp> 35 #include <srs_app_ffmpeg.hpp>
  36 +#include <srs_kernel_utility.hpp>
36 37
37 #ifdef SRS_AUTO_TRANSCODE 38 #ifdef SRS_AUTO_TRANSCODE
38 39
@@ -40,6 +40,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -40,6 +40,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
40 #include <srs_protocol_utility.hpp> 40 #include <srs_protocol_utility.hpp>
41 #include <srs_protocol_rtmp.hpp> 41 #include <srs_protocol_rtmp.hpp>
42 #include <srs_app_kbps.hpp> 42 #include <srs_app_kbps.hpp>
  43 +#include <srs_kernel_utility.hpp>
43 44
44 // when error, forwarder sleep for a while and retry. 45 // when error, forwarder sleep for a while and retry.
45 #define SRS_FORWARDER_SLEEP_US (int64_t)(3*1000*1000LL) 46 #define SRS_FORWARDER_SLEEP_US (int64_t)(3*1000*1000LL)
@@ -43,6 +43,7 @@ using namespace std; @@ -43,6 +43,7 @@ using namespace std;
43 #include <srs_core_autofree.hpp> 43 #include <srs_core_autofree.hpp>
44 #include <srs_protocol_rtmp.hpp> 44 #include <srs_protocol_rtmp.hpp>
45 #include <srs_app_pithy_print.hpp> 45 #include <srs_app_pithy_print.hpp>
  46 +#include <srs_kernel_utility.hpp>
46 47
47 // max PES packets size to flush the video. 48 // max PES packets size to flush the video.
48 #define SRS_AUTO_HLS_AUDIO_CACHE_SIZE 1024 * 1024 49 #define SRS_AUTO_HLS_AUDIO_CACHE_SIZE 1024 * 1024
@@ -35,6 +35,7 @@ using namespace std; @@ -35,6 +35,7 @@ using namespace std;
35 #include <srs_app_http_api.hpp> 35 #include <srs_app_http_api.hpp>
36 #include <srs_app_http_conn.hpp> 36 #include <srs_app_http_conn.hpp>
37 #include <srs_app_json.hpp> 37 #include <srs_app_json.hpp>
  38 +#include <srs_kernel_utility.hpp>
38 39
39 #define SRS_DEFAULT_HTTP_PORT 80 40 #define SRS_DEFAULT_HTTP_PORT 80
40 41
@@ -33,6 +33,7 @@ using namespace std; @@ -33,6 +33,7 @@ using namespace std;
33 #include <srs_kernel_error.hpp> 33 #include <srs_kernel_error.hpp>
34 #include <srs_kernel_log.hpp> 34 #include <srs_kernel_log.hpp>
35 #include <srs_app_socket.hpp> 35 #include <srs_app_socket.hpp>
  36 +#include <srs_kernel_utility.hpp>
36 37
37 SrsHttpClient::SrsHttpClient() 38 SrsHttpClient::SrsHttpClient()
38 { 39 {
@@ -29,6 +29,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -29,6 +29,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 */ 29 */
30 #include <srs_core.hpp> 30 #include <srs_core.hpp>
31 31
  32 +#include <string>
  33 +
32 #ifdef SRS_AUTO_HTTP_PARSER 34 #ifdef SRS_AUTO_HTTP_PARSER
33 35
34 #include <srs_app_st.hpp> 36 #include <srs_app_st.hpp>
@@ -41,6 +41,7 @@ using namespace std; @@ -41,6 +41,7 @@ using namespace std;
41 #include <srs_app_json.hpp> 41 #include <srs_app_json.hpp>
42 #include <srs_app_config.hpp> 42 #include <srs_app_config.hpp>
43 #include <srs_kernel_flv.hpp> 43 #include <srs_kernel_flv.hpp>
  44 +#include <srs_kernel_utility.hpp>
44 45
45 #define SRS_HTTP_DEFAULT_PAGE "index.html" 46 #define SRS_HTTP_DEFAULT_PAGE "index.html"
46 47
@@ -29,6 +29,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -29,6 +29,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 */ 29 */
30 #include <srs_core.hpp> 30 #include <srs_core.hpp>
31 31
  32 +#include <string>
  33 +
32 #ifdef SRS_AUTO_HTTP_CALLBACK 34 #ifdef SRS_AUTO_HTTP_CALLBACK
33 35
34 #include <http_parser.h> 36 #include <http_parser.h>
@@ -117,4 +119,4 @@ public: @@ -117,4 +119,4 @@ public:
117 119
118 #endif 120 #endif
119 121
120 -#endif  
  122 +#endif
@@ -32,6 +32,7 @@ using namespace std; @@ -32,6 +32,7 @@ using namespace std;
32 #include <srs_kernel_log.hpp> 32 #include <srs_kernel_log.hpp>
33 #include <srs_app_ffmpeg.hpp> 33 #include <srs_app_ffmpeg.hpp>
34 #include <srs_app_pithy_print.hpp> 34 #include <srs_app_pithy_print.hpp>
  35 +#include <srs_kernel_utility.hpp>
35 36
36 // when error, ingester sleep for a while and retry. 37 // when error, ingester sleep for a while and retry.
37 // ingest never sleep a long time, for we must start the stream ASAP. 38 // ingest never sleep a long time, for we must start the stream ASAP.
@@ -33,6 +33,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -33,6 +33,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 #include <srs_app_config.hpp> 33 #include <srs_app_config.hpp>
34 #include <srs_kernel_error.hpp> 34 #include <srs_kernel_error.hpp>
35 #include <srs_app_utility.hpp> 35 #include <srs_app_utility.hpp>
  36 +#include <srs_kernel_utility.hpp>
36 37
37 SrsThreadContext::SrsThreadContext() 38 SrsThreadContext::SrsThreadContext()
38 { 39 {
@@ -46,6 +46,9 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -46,6 +46,9 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
46 #include <srs_app_utility.hpp> 46 #include <srs_app_utility.hpp>
47 #include <srs_app_heartbeat.hpp> 47 #include <srs_app_heartbeat.hpp>
48 48
  49 +// signal defines.
  50 +#define SIGNAL_RELOAD SIGHUP
  51 +
49 #define SERVER_LISTEN_BACKLOG 512 52 #define SERVER_LISTEN_BACKLOG 512
50 53
51 // system interval 54 // system interval
@@ -40,6 +40,7 @@ using namespace std; @@ -40,6 +40,7 @@ using namespace std;
40 #include <srs_app_dvr.hpp> 40 #include <srs_app_dvr.hpp>
41 #include <srs_kernel_stream.hpp> 41 #include <srs_kernel_stream.hpp>
42 #include <srs_app_edge.hpp> 42 #include <srs_app_edge.hpp>
  43 +#include <srs_kernel_utility.hpp>
43 44
44 #define CONST_MAX_JITTER_MS 500 45 #define CONST_MAX_JITTER_MS 500
45 #define DEFAULT_FRAME_TIME_MS 40 46 #define DEFAULT_FRAME_TIME_MS 40
@@ -26,6 +26,10 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -26,6 +26,10 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 #include <srs_kernel_error.hpp> 26 #include <srs_kernel_error.hpp>
27 #include <srs_kernel_log.hpp> 27 #include <srs_kernel_log.hpp>
28 28
  29 +// const time for st to convert to us
  30 +#define SRS_TIME_MILLISECONDS 1000
  31 +#define SRS_TIME_SECONDS 1000000
  32 +
29 ISrsThreadHandler::ISrsThreadHandler() 33 ISrsThreadHandler::ISrsThreadHandler()
30 { 34 {
31 } 35 }
@@ -180,4 +184,4 @@ void* SrsThread::thread_fun(void* arg) @@ -180,4 +184,4 @@ void* SrsThread::thread_fun(void* arg)
180 st_thread_exit(NULL); 184 st_thread_exit(NULL);
181 185
182 return NULL; 186 return NULL;
183 -}  
  187 +}
@@ -23,128 +23,3 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -23,128 +23,3 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 23
24 #include <srs_core.hpp> 24 #include <srs_core.hpp>
25 25
26 -#include <string.h>  
27 -#include <netdb.h>  
28 -#include <arpa/inet.h>  
29 -  
30 -using namespace std;  
31 -  
32 -string srs_string_replace(string str, string old_str, string new_str)  
33 -{  
34 - std::string ret = str;  
35 -  
36 - if (old_str == new_str) {  
37 - return ret;  
38 - }  
39 -  
40 - size_t pos = 0;  
41 - while ((pos = ret.find(old_str, pos)) != std::string::npos) {  
42 - ret = ret.replace(pos, old_str.length(), new_str);  
43 - }  
44 -  
45 - return ret;  
46 -}  
47 -  
48 -string srs_string_trim_end(string str, string trim_chars)  
49 -{  
50 - std::string ret = str;  
51 -  
52 - for (int i = 0; i < (int)trim_chars.length(); i++) {  
53 - char ch = trim_chars.at(i);  
54 -  
55 - while (!ret.empty() && ret.at(ret.length() - 1) == ch) {  
56 - ret.erase(ret.end() - 1);  
57 -  
58 - // ok, matched, should reset the search  
59 - i = 0;  
60 - }  
61 - }  
62 -  
63 - return ret;  
64 -}  
65 -  
66 -string srs_string_trim_start(string str, string trim_chars)  
67 -{  
68 - std::string ret = str;  
69 -  
70 - for (int i = 0; i < (int)trim_chars.length(); i++) {  
71 - char ch = trim_chars.at(i);  
72 -  
73 - while (!ret.empty() && ret.at(0) == ch) {  
74 - ret.erase(ret.begin());  
75 -  
76 - // ok, matched, should reset the search  
77 - i = 0;  
78 - }  
79 - }  
80 -  
81 - return ret;  
82 -}  
83 -  
84 -string srs_string_remove(string str, string remove_chars)  
85 -{  
86 - std::string ret = str;  
87 -  
88 - for (int i = 0; i < (int)remove_chars.length(); i++) {  
89 - char ch = remove_chars.at(i);  
90 -  
91 - for (std::string::iterator it = ret.begin(); it != ret.end();) {  
92 - if (ch == *it) {  
93 - it = ret.erase(it);  
94 -  
95 - // ok, matched, should reset the search  
96 - i = 0;  
97 - } else {  
98 - ++it;  
99 - }  
100 - }  
101 - }  
102 -  
103 - return ret;  
104 -}  
105 -  
106 -bool srs_string_ends_with(string str, string flag)  
107 -{  
108 - return str.rfind(flag) == str.length() - flag.length();  
109 -}  
110 -  
111 -string srs_dns_resolve(string host)  
112 -{  
113 - if (inet_addr(host.c_str()) != INADDR_NONE) {  
114 - return host;  
115 - }  
116 -  
117 - hostent* answer = gethostbyname(host.c_str());  
118 - if (answer == NULL) {  
119 - return "";  
120 - }  
121 -  
122 - char ipv4[16];  
123 - memset(ipv4, 0, sizeof(ipv4));  
124 - for (int i = 0; i < answer->h_length; i++) {  
125 - inet_ntop(AF_INET, answer->h_addr_list[i], ipv4, sizeof(ipv4));  
126 - break;  
127 - }  
128 -  
129 - return ipv4;  
130 -}  
131 -  
132 -bool srs_is_little_endian()  
133 -{  
134 - // convert to network(big-endian) order, if not equals,  
135 - // the system is little-endian, so need to convert the int64  
136 - static int little_endian_check = -1;  
137 -  
138 - if(little_endian_check == -1) {  
139 - union {  
140 - int32_t i;  
141 - int8_t c;  
142 - } little_check_union;  
143 -  
144 - little_check_union.i = 0x01;  
145 - little_endian_check = little_check_union.c;  
146 - }  
147 -  
148 - return (little_endian_check == 1);  
149 -}  
150 -  
@@ -85,30 +85,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -85,30 +85,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
85 // it's recomments to free each elem explicit. 85 // it's recomments to free each elem explicit.
86 // so we remove the srs_freepa utility. 86 // so we remove the srs_freepa utility.
87 87
88 -// compare  
89 -#define srs_min(a, b) (((a) < (b))? (a) : (b))  
90 -#define srs_max(a, b) (((a) < (b))? (b) : (a))  
91 -  
92 -// signal defines.  
93 -#define SIGNAL_RELOAD SIGHUP  
94 -  
95 -#include <string>  
96 -// replace old_str to new_str of str  
97 -extern std::string srs_string_replace(std::string str, std::string old_str, std::string new_str);  
98 -// trim char in trim_chars of str  
99 -extern std::string srs_string_trim_end(std::string str, std::string trim_chars);  
100 -// trim char in trim_chars of str  
101 -extern std::string srs_string_trim_start(std::string str, std::string trim_chars);  
102 -// remove char in remove_chars of str  
103 -extern std::string srs_string_remove(std::string str, std::string remove_chars);  
104 -// whether string end with  
105 -extern bool srs_string_ends_with(std::string str, std::string flag);  
106 -  
107 -// dns resolve utility, return the resolved ip address.  
108 -extern std::string srs_dns_resolve(std::string host);  
109 -// whether system is little endian  
110 -extern bool srs_is_little_endian();  
111 -  
112 /** 88 /**
113 * disable copy constructor of class 89 * disable copy constructor of class
114 */ 90 */
@@ -120,8 +96,4 @@ extern bool srs_is_little_endian(); @@ -120,8 +96,4 @@ extern bool srs_is_little_endian();
120 className(const className&); \ 96 className(const className&); \
121 className& operator= (const className&) 97 className& operator= (const className&)
122 98
123 -// const time for st to convert to us  
124 -#define SRS_TIME_MILLISECONDS 1000  
125 -#define SRS_TIME_SECONDS 1000000  
126 -  
127 #endif 99 #endif
@@ -29,6 +29,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -29,6 +29,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 */ 29 */
30 #include <srs_core.hpp> 30 #include <srs_core.hpp>
31 31
  32 +#include <string>
  33 +
32 class SrsStream; 34 class SrsStream;
33 35
34 /** 36 /**
@@ -173,4 +175,4 @@ public: @@ -173,4 +175,4 @@ public:
173 virtual int read_previous_tag_size(char ts[4]); 175 virtual int read_previous_tag_size(char ts[4]);
174 }; 176 };
175 177
176 -#endif  
  178 +#endif
@@ -27,6 +27,7 @@ using namespace std; @@ -27,6 +27,7 @@ using namespace std;
27 27
28 #include <srs_kernel_log.hpp> 28 #include <srs_kernel_log.hpp>
29 #include <srs_kernel_error.hpp> 29 #include <srs_kernel_error.hpp>
  30 +#include <srs_kernel_utility.hpp>
30 31
31 SrsStream::SrsStream() 32 SrsStream::SrsStream()
32 { 33 {
@@ -23,8 +23,13 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -23,8 +23,13 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 23
24 #include <srs_kernel_utility.hpp> 24 #include <srs_kernel_utility.hpp>
25 25
26 -#include <sys/time.h>  
27 #include <unistd.h> 26 #include <unistd.h>
  27 +#include <string.h>
  28 +#include <netdb.h>
  29 +#include <arpa/inet.h>
  30 +#include <sys/time.h>
  31 +
  32 +using namespace std;
28 33
29 #include <srs_kernel_log.hpp> 34 #include <srs_kernel_log.hpp>
30 35
@@ -58,3 +63,122 @@ void srs_update_system_time_ms() @@ -58,3 +63,122 @@ void srs_update_system_time_ms()
58 63
59 _srs_system_time_us_cache = now_us; 64 _srs_system_time_us_cache = now_us;
60 } 65 }
  66 +
  67 +string srs_dns_resolve(string host)
  68 +{
  69 + if (inet_addr(host.c_str()) != INADDR_NONE) {
  70 + return host;
  71 + }
  72 +
  73 + hostent* answer = gethostbyname(host.c_str());
  74 + if (answer == NULL) {
  75 + return "";
  76 + }
  77 +
  78 + char ipv4[16];
  79 + memset(ipv4, 0, sizeof(ipv4));
  80 + for (int i = 0; i < answer->h_length; i++) {
  81 + inet_ntop(AF_INET, answer->h_addr_list[i], ipv4, sizeof(ipv4));
  82 + break;
  83 + }
  84 +
  85 + return ipv4;
  86 +}
  87 +
  88 +bool srs_is_little_endian()
  89 +{
  90 + // convert to network(big-endian) order, if not equals,
  91 + // the system is little-endian, so need to convert the int64
  92 + static int little_endian_check = -1;
  93 +
  94 + if(little_endian_check == -1) {
  95 + union {
  96 + int32_t i;
  97 + int8_t c;
  98 + } little_check_union;
  99 +
  100 + little_check_union.i = 0x01;
  101 + little_endian_check = little_check_union.c;
  102 + }
  103 +
  104 + return (little_endian_check == 1);
  105 +}
  106 +
  107 +string srs_string_replace(string str, string old_str, string new_str)
  108 +{
  109 + std::string ret = str;
  110 +
  111 + if (old_str == new_str) {
  112 + return ret;
  113 + }
  114 +
  115 + size_t pos = 0;
  116 + while ((pos = ret.find(old_str, pos)) != std::string::npos) {
  117 + ret = ret.replace(pos, old_str.length(), new_str);
  118 + }
  119 +
  120 + return ret;
  121 +}
  122 +
  123 +string srs_string_trim_end(string str, string trim_chars)
  124 +{
  125 + std::string ret = str;
  126 +
  127 + for (int i = 0; i < (int)trim_chars.length(); i++) {
  128 + char ch = trim_chars.at(i);
  129 +
  130 + while (!ret.empty() && ret.at(ret.length() - 1) == ch) {
  131 + ret.erase(ret.end() - 1);
  132 +
  133 + // ok, matched, should reset the search
  134 + i = 0;
  135 + }
  136 + }
  137 +
  138 + return ret;
  139 +}
  140 +
  141 +string srs_string_trim_start(string str, string trim_chars)
  142 +{
  143 + std::string ret = str;
  144 +
  145 + for (int i = 0; i < (int)trim_chars.length(); i++) {
  146 + char ch = trim_chars.at(i);
  147 +
  148 + while (!ret.empty() && ret.at(0) == ch) {
  149 + ret.erase(ret.begin());
  150 +
  151 + // ok, matched, should reset the search
  152 + i = 0;
  153 + }
  154 + }
  155 +
  156 + return ret;
  157 +}
  158 +
  159 +string srs_string_remove(string str, string remove_chars)
  160 +{
  161 + std::string ret = str;
  162 +
  163 + for (int i = 0; i < (int)remove_chars.length(); i++) {
  164 + char ch = remove_chars.at(i);
  165 +
  166 + for (std::string::iterator it = ret.begin(); it != ret.end();) {
  167 + if (ch == *it) {
  168 + it = ret.erase(it);
  169 +
  170 + // ok, matched, should reset the search
  171 + i = 0;
  172 + } else {
  173 + ++it;
  174 + }
  175 + }
  176 + }
  177 +
  178 + return ret;
  179 +}
  180 +
  181 +bool srs_string_ends_with(string str, string flag)
  182 +{
  183 + return str.rfind(flag) == str.length() - flag.length();
  184 +}
@@ -30,9 +30,32 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -30,9 +30,32 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 30
31 #include <srs_core.hpp> 31 #include <srs_core.hpp>
32 32
  33 +#include <string>
  34 +
  35 +// compare
  36 +#define srs_min(a, b) (((a) < (b))? (a) : (b))
  37 +#define srs_max(a, b) (((a) < (b))? (b) : (a))
  38 +
33 // get current system time in ms, use cache to avoid performance problem 39 // get current system time in ms, use cache to avoid performance problem
34 extern int64_t srs_get_system_time_ms(); 40 extern int64_t srs_get_system_time_ms();
35 // the deamon st-thread will update it. 41 // the deamon st-thread will update it.
36 extern void srs_update_system_time_ms(); 42 extern void srs_update_system_time_ms();
37 43
  44 +// dns resolve utility, return the resolved ip address.
  45 +extern std::string srs_dns_resolve(std::string host);
  46 +
  47 +// whether system is little endian
  48 +extern bool srs_is_little_endian();
  49 +
  50 +// replace old_str to new_str of str
  51 +extern std::string srs_string_replace(std::string str, std::string old_str, std::string new_str);
  52 +// trim char in trim_chars of str
  53 +extern std::string srs_string_trim_end(std::string str, std::string trim_chars);
  54 +// trim char in trim_chars of str
  55 +extern std::string srs_string_trim_start(std::string str, std::string trim_chars);
  56 +// remove char in remove_chars of str
  57 +extern std::string srs_string_remove(std::string str, std::string remove_chars);
  58 +// whether string end with
  59 +extern bool srs_string_ends_with(std::string str, std::string flag);
  60 +
38 #endif 61 #endif
@@ -38,6 +38,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -38,6 +38,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38 #include <srs_app_config.hpp> 38 #include <srs_app_config.hpp>
39 #include <srs_app_log.hpp> 39 #include <srs_app_log.hpp>
40 #include <srs_app_server.hpp> 40 #include <srs_app_server.hpp>
  41 +#include <srs_kernel_utility.hpp>
41 42
42 // kernel module. 43 // kernel module.
43 ISrsLog* _srs_log = new SrsFastLog(); 44 ISrsLog* _srs_log = new SrsFastLog();
@@ -39,6 +39,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -39,6 +39,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
39 #include <srs_app_config.hpp> 39 #include <srs_app_config.hpp>
40 #include <srs_app_log.hpp> 40 #include <srs_app_log.hpp>
41 #include <srs_app_utility.hpp> 41 #include <srs_app_utility.hpp>
  42 +#include <srs_kernel_utility.hpp>
42 43
43 // pre-declare 44 // pre-declare
44 int run(); 45 int run();
@@ -32,6 +32,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -32,6 +32,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 #include <srs_protocol_rtmp_stack.hpp> 32 #include <srs_protocol_rtmp_stack.hpp>
33 #include <srs_protocol_utility.hpp> 33 #include <srs_protocol_utility.hpp>
34 #include <srs_kernel_stream.hpp> 34 #include <srs_kernel_stream.hpp>
  35 +#include <srs_kernel_utility.hpp>
35 36
36 using namespace std; 37 using namespace std;
37 38
@@ -30,6 +30,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -30,6 +30,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 #include <srs_kernel_buffer.hpp> 30 #include <srs_kernel_buffer.hpp>
31 #include <srs_kernel_stream.hpp> 31 #include <srs_kernel_stream.hpp>
32 #include <srs_core_autofree.hpp> 32 #include <srs_core_autofree.hpp>
  33 +#include <srs_kernel_utility.hpp>
33 34
34 using namespace std; 35 using namespace std;
35 36
@@ -26,6 +26,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -26,6 +26,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 #include <stdlib.h> 26 #include <stdlib.h>
27 27
28 #include <srs_kernel_log.hpp> 28 #include <srs_kernel_log.hpp>
  29 +#include <srs_kernel_utility.hpp>
29 30
30 void srs_vhost_resolve(std::string& vhost, std::string& app) 31 void srs_vhost_resolve(std::string& vhost, std::string& app)
31 { 32 {
@@ -29,6 +29,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -29,6 +29,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 */ 29 */
30 #include <srs_core.hpp> 30 #include <srs_core.hpp>
31 31
  32 +#include <string>
  33 +
32 #define RTMP_DEFAULT_PORT "1935" 34 #define RTMP_DEFAULT_PORT "1935"
33 35
34 // the default chunk size for system. 36 // the default chunk size for system.
@@ -23,6 +23,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -23,6 +23,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 #include <srs_utest_buffer.hpp> 23 #include <srs_utest_buffer.hpp>
24 24
25 #include <srs_kernel_error.hpp> 25 #include <srs_kernel_error.hpp>
  26 +#include <srs_kernel_utility.hpp>
26 27
27 MockBufferReader::MockBufferReader(const char* data) 28 MockBufferReader::MockBufferReader(const char* data)
28 { 29 {