正在显示
4 个修改的文件
包含
27 行增加
和
0 行删除
| @@ -85,3 +85,22 @@ std::string srs_dns_resolve(std::string host) | @@ -85,3 +85,22 @@ std::string srs_dns_resolve(std::string host) | ||
| 85 | return ipv4; | 85 | return ipv4; |
| 86 | } | 86 | } |
| 87 | 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 | + |
| @@ -99,6 +99,8 @@ extern void srs_update_system_time_ms(); | @@ -99,6 +99,8 @@ extern void srs_update_system_time_ms(); | ||
| 99 | extern std::string srs_replace(std::string str, std::string old_str, std::string new_str); | 99 | extern std::string srs_replace(std::string str, std::string old_str, std::string new_str); |
| 100 | // dns resolve utility, return the resolved ip address. | 100 | // dns resolve utility, return the resolved ip address. |
| 101 | extern std::string srs_dns_resolve(std::string host); | 101 | extern std::string srs_dns_resolve(std::string host); |
| 102 | +// whether system is little endian | ||
| 103 | +extern bool srs_is_little_endian(); | ||
| 102 | 104 | ||
| 103 | /** | 105 | /** |
| 104 | * disable copy constructor of class | 106 | * disable copy constructor of class |
| @@ -30,6 +30,9 @@ SrsStream::SrsStream() | @@ -30,6 +30,9 @@ SrsStream::SrsStream() | ||
| 30 | { | 30 | { |
| 31 | p = bytes = NULL; | 31 | p = bytes = NULL; |
| 32 | size = 0; | 32 | size = 0; |
| 33 | + | ||
| 34 | + // TODO: support both little and big endian. | ||
| 35 | + srs_assert(srs_is_little_endian()); | ||
| 33 | } | 36 | } |
| 34 | 37 | ||
| 35 | SrsStream::~SrsStream() | 38 | SrsStream::~SrsStream() |
| @@ -53,6 +53,9 @@ void handler(int signo) | @@ -53,6 +53,9 @@ void handler(int signo) | ||
| 53 | int main(int argc, char** argv) | 53 | int main(int argc, char** argv) |
| 54 | { | 54 | { |
| 55 | int ret = ERROR_SUCCESS; | 55 | int ret = ERROR_SUCCESS; |
| 56 | + | ||
| 57 | + // TODO: support both little and big endian. | ||
| 58 | + srs_assert(srs_is_little_endian()); | ||
| 56 | 59 | ||
| 57 | #ifdef SRS_GPERF_MP | 60 | #ifdef SRS_GPERF_MP |
| 58 | HeapProfilerStart("gperf.srs.gmp"); | 61 | HeapProfilerStart("gperf.srs.gmp"); |
-
请 注册 或 登录 后发表评论