winlin

merge from 2.0release

@@ -348,6 +348,7 @@ Remark: @@ -348,6 +348,7 @@ Remark:
348 348
349 ### SRS 2.0 history 349 ### SRS 2.0 history
350 350
  351 +* v2.0, 2015-07-01, fix [#433](https://github.com/simple-rtmp-server/srs/issues/433) fix the sps parse bug. 2.0.176
351 * v2.0, 2015-06-10, fix [#425](https://github.com/simple-rtmp-server/srs/issues/425) refine the time jitter, correct (-inf,-250)+(250,+inf) to 10ms. 2.0.175 352 * v2.0, 2015-06-10, fix [#425](https://github.com/simple-rtmp-server/srs/issues/425) refine the time jitter, correct (-inf,-250)+(250,+inf) to 10ms. 2.0.175
352 * v2.0, 2015-06-10, fix [#424](https://github.com/simple-rtmp-server/srs/issues/424) fix aggregate timestamp bug. 2.0.174 353 * v2.0, 2015-06-10, fix [#424](https://github.com/simple-rtmp-server/srs/issues/424) fix aggregate timestamp bug. 2.0.174
353 * v2.0, 2015-06-06, fix [#421](https://github.com/simple-rtmp-server/srs/issues/421) drop video for unkown RTMP header. 354 * v2.0, 2015-06-06, fix [#421](https://github.com/simple-rtmp-server/srs/issues/421) drop video for unkown RTMP header.
@@ -35,6 +35,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -35,6 +35,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 #endif 35 #endif
36 #include <stdlib.h> 36 #include <stdlib.h>
37 #include <sys/time.h> 37 #include <sys/time.h>
  38 +#include <map>
38 using namespace std; 39 using namespace std;
39 40
40 #include <srs_kernel_log.hpp> 41 #include <srs_kernel_log.hpp>
@@ -999,12 +1000,14 @@ void srs_update_network_devices() @@ -999,12 +1000,14 @@ void srs_update_network_devices()
999 1000
1000 // @see: read_net_dev() from https://github.com/sysstat/sysstat/blob/master/rd_stats.c#L786 1001 // @see: read_net_dev() from https://github.com/sysstat/sysstat/blob/master/rd_stats.c#L786
1001 // @remark, we use our algorithm, not sysstat. 1002 // @remark, we use our algorithm, not sysstat.
  1003 + char fname[7];
1002 sscanf(buf, "%6[^:]:%llu %lu %lu %lu %lu %lu %lu %lu %llu %lu %lu %lu %lu %lu %lu %lu\n", 1004 sscanf(buf, "%6[^:]:%llu %lu %lu %lu %lu %lu %lu %lu %llu %lu %lu %lu %lu %lu %lu %lu\n",
1003 - r.name, &r.rbytes, &r.rpackets, &r.rerrs, &r.rdrop, &r.rfifo, &r.rframe, &r.rcompressed, &r.rmulticast, 1005 + fname, &r.rbytes, &r.rpackets, &r.rerrs, &r.rdrop, &r.rfifo, &r.rframe, &r.rcompressed, &r.rmulticast,
1004 &r.sbytes, &r.spackets, &r.serrs, &r.sdrop, &r.sfifo, &r.scolls, &r.scarrier, &r.scompressed); 1006 &r.sbytes, &r.spackets, &r.serrs, &r.sdrop, &r.sfifo, &r.scolls, &r.scarrier, &r.scompressed);
1005 1007
1006 - r.name[sizeof(r.name) - 1] = 0; 1008 + sscanf(fname, "%s", r.name);
1007 _nb_srs_system_network_devices = i + 1; 1009 _nb_srs_system_network_devices = i + 1;
  1010 + srs_info("scan network device ifname=%s, total=%d", r.name, _nb_srs_system_network_devices);
1008 1011
1009 r.sample_time = srs_get_system_time_ms(); 1012 r.sample_time = srs_get_system_time_ms();
1010 r.ok = true; 1013 r.ok = true;
@@ -1018,6 +1021,48 @@ void srs_update_network_devices() @@ -1018,6 +1021,48 @@ void srs_update_network_devices()
1018 #endif 1021 #endif
1019 } 1022 }
1020 1023
  1024 +// we detect all network device as internet or intranet device, by its ip address.
  1025 +// key is device name, for instance, eth0
  1026 +// value is whether internet, for instance, true.
  1027 +static std::map<std::string, bool> _srs_device_ifs;
  1028 +
  1029 +bool srs_net_device_is_internet(string ifname)
  1030 +{
  1031 + srs_info("check ifname=%s", ifname.c_str());
  1032 +
  1033 + if (_srs_device_ifs.find(ifname) == _srs_device_ifs.end()) {
  1034 + return false;
  1035 + }
  1036 + return _srs_device_ifs[ifname];
  1037 +}
  1038 +
  1039 +bool srs_net_device_is_internet(in_addr_t addr)
  1040 +{
  1041 + u_int32_t addr_h = ntohl(addr);
  1042 +
  1043 + // lo, 127.0.0.0-127.0.0.1
  1044 + if (addr_h >= 0x7f000000 && addr_h <= 0x7f000001) {
  1045 + return false;
  1046 + }
  1047 +
  1048 + // Class A 10.0.0.0-10.255.255.255
  1049 + if (addr_h >= 0x0a000000 && addr_h <= 0x0affffff) {
  1050 + return false;
  1051 + }
  1052 +
  1053 + // Class B 172.16.0.0-172.31.255.255
  1054 + if (addr_h >= 0xac100000 && addr_h <= 0xac1fffff) {
  1055 + return false;
  1056 + }
  1057 +
  1058 + // Class C 192.168.0.0-192.168.255.255
  1059 + if (addr_h >= 0xc0a80000 && addr_h <= 0xc0a8ffff) {
  1060 + return false;
  1061 + }
  1062 +
  1063 + return true;
  1064 +}
  1065 +
1021 SrsNetworkRtmpServer::SrsNetworkRtmpServer() 1066 SrsNetworkRtmpServer::SrsNetworkRtmpServer()
1022 { 1067 {
1023 ok = false; 1068 ok = false;
@@ -1186,7 +1231,9 @@ void retrieve_local_ipv4_ips() @@ -1186,7 +1231,9 @@ void retrieve_local_ipv4_ips()
1186 1231
1187 ifaddrs* p = ifap; 1232 ifaddrs* p = ifap;
1188 while (p != NULL) { 1233 while (p != NULL) {
1189 - sockaddr* addr = p->ifa_addr; 1234 + ifaddrs* cur = p;
  1235 + sockaddr* addr = cur->ifa_addr;
  1236 + p = p->ifa_next;
1190 1237
1191 // retrieve ipv4 addr 1238 // retrieve ipv4 addr
1192 // ignore the tun0 network device, 1239 // ignore the tun0 network device,
@@ -1208,9 +1255,16 @@ void retrieve_local_ipv4_ips() @@ -1208,9 +1255,16 @@ void retrieve_local_ipv4_ips()
1208 srs_trace("retrieve local ipv4 ip=%s, index=%d", ip.c_str(), (int)ips.size()); 1255 srs_trace("retrieve local ipv4 ip=%s, index=%d", ip.c_str(), (int)ips.size());
1209 ips.push_back(ip); 1256 ips.push_back(ip);
1210 } 1257 }
1211 - }  
1212 1258
1213 - p = p->ifa_next; 1259 + // set the device internet status.
  1260 + if (!srs_net_device_is_internet(inaddr->s_addr)) {
  1261 + srs_trace("detect intranet address: %s, ifname=%s", ip.c_str(), cur->ifa_name);
  1262 + _srs_device_ifs[cur->ifa_name] = false;
  1263 + } else {
  1264 + srs_trace("detect internet address: %s, ifname=%s", ip.c_str(), cur->ifa_name);
  1265 + _srs_device_ifs[cur->ifa_name] = true;
  1266 + }
  1267 + }
1214 } 1268 }
1215 1269
1216 freeifaddrs(ifap); 1270 freeifaddrs(ifap);
@@ -1320,19 +1374,30 @@ void srs_api_dump_summaries(std::stringstream& ss) @@ -1320,19 +1374,30 @@ void srs_api_dump_summaries(std::stringstream& ss)
1320 int64_t n_sample_time = 0; 1374 int64_t n_sample_time = 0;
1321 int64_t nr_bytes = 0; 1375 int64_t nr_bytes = 0;
1322 int64_t ns_bytes = 0; 1376 int64_t ns_bytes = 0;
  1377 + int64_t nri_bytes = 0;
  1378 + int64_t nsi_bytes = 0;
1323 int nb_n = srs_get_network_devices_count(); 1379 int nb_n = srs_get_network_devices_count();
1324 for (int i = 0; i < nb_n; i++) { 1380 for (int i = 0; i < nb_n; i++) {
1325 SrsNetworkDevices& o = n[i]; 1381 SrsNetworkDevices& o = n[i];
1326 1382
1327 // ignore the lo interface. 1383 // ignore the lo interface.
1328 std::string inter = o.name; 1384 std::string inter = o.name;
1329 - if (!o.ok || inter == "lo") { 1385 + if (!o.ok) {
  1386 + continue;
  1387 + }
  1388 +
  1389 + // update the sample time.
  1390 + n_sample_time = o.sample_time;
  1391 +
  1392 + // stat the intranet bytes.
  1393 + if (inter == "lo" || !srs_net_device_is_internet(inter)) {
  1394 + nri_bytes += o.rbytes;
  1395 + nsi_bytes += o.sbytes;
1330 continue; 1396 continue;
1331 } 1397 }
1332 1398
1333 nr_bytes += o.rbytes; 1399 nr_bytes += o.rbytes;
1334 ns_bytes += o.sbytes; 1400 ns_bytes += o.sbytes;
1335 - n_sample_time = o.sample_time;  
1336 } 1401 }
1337 1402
1338 // all data is ok? 1403 // all data is ok?
@@ -1371,9 +1436,15 @@ void srs_api_dump_summaries(std::stringstream& ss) @@ -1371,9 +1436,15 @@ void srs_api_dump_summaries(std::stringstream& ss)
1371 << SRS_JFIELD_ORG("load_1m", p->load_one_minutes) << SRS_JFIELD_CONT 1436 << SRS_JFIELD_ORG("load_1m", p->load_one_minutes) << SRS_JFIELD_CONT
1372 << SRS_JFIELD_ORG("load_5m", p->load_five_minutes) << SRS_JFIELD_CONT 1437 << SRS_JFIELD_ORG("load_5m", p->load_five_minutes) << SRS_JFIELD_CONT
1373 << SRS_JFIELD_ORG("load_15m", p->load_fifteen_minutes) << SRS_JFIELD_CONT 1438 << SRS_JFIELD_ORG("load_15m", p->load_fifteen_minutes) << SRS_JFIELD_CONT
  1439 + // system network bytes stat.
1374 << SRS_JFIELD_ORG("net_sample_time", n_sample_time) << SRS_JFIELD_CONT 1440 << SRS_JFIELD_ORG("net_sample_time", n_sample_time) << SRS_JFIELD_CONT
  1441 + // internet public address network device bytes.
1375 << SRS_JFIELD_ORG("net_recv_bytes", nr_bytes) << SRS_JFIELD_CONT 1442 << SRS_JFIELD_ORG("net_recv_bytes", nr_bytes) << SRS_JFIELD_CONT
1376 << SRS_JFIELD_ORG("net_send_bytes", ns_bytes) << SRS_JFIELD_CONT 1443 << SRS_JFIELD_ORG("net_send_bytes", ns_bytes) << SRS_JFIELD_CONT
  1444 + // intranet private address network device bytes.
  1445 + << SRS_JFIELD_ORG("net_recvi_bytes", nri_bytes) << SRS_JFIELD_CONT
  1446 + << SRS_JFIELD_ORG("net_sendi_bytes", nsi_bytes) << SRS_JFIELD_CONT
  1447 + // srs network bytes stat.
1377 << SRS_JFIELD_ORG("srs_sample_time", nrs->sample_time) << SRS_JFIELD_CONT 1448 << SRS_JFIELD_ORG("srs_sample_time", nrs->sample_time) << SRS_JFIELD_CONT
1378 << SRS_JFIELD_ORG("srs_recv_bytes", nrs->rbytes) << SRS_JFIELD_CONT 1449 << SRS_JFIELD_ORG("srs_recv_bytes", nrs->rbytes) << SRS_JFIELD_CONT
1379 << SRS_JFIELD_ORG("srs_send_bytes", nrs->sbytes) << SRS_JFIELD_CONT 1450 << SRS_JFIELD_ORG("srs_send_bytes", nrs->sbytes) << SRS_JFIELD_CONT
@@ -34,6 +34,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -34,6 +34,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 #include <string> 34 #include <string>
35 #include <sstream> 35 #include <sstream>
36 36
  37 +#include <arpa/inet.h>
37 #include <sys/resource.h> 38 #include <sys/resource.h>
38 39
39 #include <srs_app_st.hpp> 40 #include <srs_app_st.hpp>
@@ -609,6 +610,9 @@ extern SrsNetworkDevices* srs_get_network_devices(); @@ -609,6 +610,9 @@ extern SrsNetworkDevices* srs_get_network_devices();
609 extern int srs_get_network_devices_count(); 610 extern int srs_get_network_devices_count();
610 // the deamon st-thread will update it. 611 // the deamon st-thread will update it.
611 extern void srs_update_network_devices(); 612 extern void srs_update_network_devices();
  613 +// detect whether specified device is internet public address.
  614 +extern bool srs_net_device_is_internet(std::string ifname);
  615 +extern bool srs_net_device_is_internet(in_addr_t addr);
612 616
613 // system connections, and srs rtmp network summary 617 // system connections, and srs rtmp network summary
614 class SrsNetworkRtmpServer 618 class SrsNetworkRtmpServer
@@ -981,11 +981,11 @@ int SrsAvcAacCodec::avc_demux_sps_rbsp(char* rbsp, int nb_rbsp) @@ -981,11 +981,11 @@ int SrsAvcAacCodec::avc_demux_sps_rbsp(char* rbsp, int nb_rbsp)
981 } 981 }
982 srs_info("sps parse profile=%d, level=%d, sps_id=%d", profile_idc, level_idc, seq_parameter_set_id); 982 srs_info("sps parse profile=%d, level=%d, sps_id=%d", profile_idc, level_idc, seq_parameter_set_id);
983 983
  984 + int32_t chroma_format_idc = -1;
984 if (profile_idc == 100 || profile_idc == 110 || profile_idc == 122 || profile_idc == 244 985 if (profile_idc == 100 || profile_idc == 110 || profile_idc == 122 || profile_idc == 244
985 || profile_idc == 44 || profile_idc == 83 || profile_idc == 86 || profile_idc == 118 986 || profile_idc == 44 || profile_idc == 83 || profile_idc == 86 || profile_idc == 118
986 || profile_idc == 128 987 || profile_idc == 128
987 ) { 988 ) {
988 - int32_t chroma_format_idc = -1;  
989 if ((ret = srs_avc_nalu_read_uev(&bs, chroma_format_idc)) != ERROR_SUCCESS) { 989 if ((ret = srs_avc_nalu_read_uev(&bs, chroma_format_idc)) != ERROR_SUCCESS) {
990 return ret; 990 return ret;
991 } 991 }
@@ -1016,11 +1016,20 @@ int SrsAvcAacCodec::avc_demux_sps_rbsp(char* rbsp, int nb_rbsp) @@ -1016,11 +1016,20 @@ int SrsAvcAacCodec::avc_demux_sps_rbsp(char* rbsp, int nb_rbsp)
1016 return ret; 1016 return ret;
1017 } 1017 }
1018 if (seq_scaling_matrix_present_flag) { 1018 if (seq_scaling_matrix_present_flag) {
  1019 + int nb_scmpfs = ((chroma_format_idc != 3)? 8:12);
  1020 + for (int i = 0; i < nb_scmpfs; i++) {
  1021 + int8_t seq_scaling_matrix_present_flag_i = -1;
  1022 + if ((ret = srs_avc_nalu_read_bit(&bs, seq_scaling_matrix_present_flag_i)) != ERROR_SUCCESS) {
  1023 + return ret;
  1024 + }
  1025 + if (seq_scaling_matrix_present_flag_i) {
1019 ret = ERROR_HLS_DECODE_ERROR; 1026 ret = ERROR_HLS_DECODE_ERROR;
1020 - srs_error("sps the seq_scaling_matrix_present_flag invalid. ret=%d", ret); 1027 + srs_error("sps the seq_scaling_matrix_present_flag invalid, i=%d, nb_scmpfs=%d. ret=%d", i, nb_scmpfs, ret);
1021 return ret; 1028 return ret;
1022 } 1029 }
1023 } 1030 }
  1031 + }
  1032 + }
1024 1033
1025 int32_t log2_max_frame_num_minus4 = -1; 1034 int32_t log2_max_frame_num_minus4 = -1;
1026 if ((ret = srs_avc_nalu_read_uev(&bs, log2_max_frame_num_minus4)) != ERROR_SUCCESS) { 1035 if ((ret = srs_avc_nalu_read_uev(&bs, log2_max_frame_num_minus4)) != ERROR_SUCCESS) {