1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-02-14 20:31:56 +00:00

merge from 2.0release

This commit is contained in:
winlin 2015-07-01 14:51:27 +08:00
commit c8fef99cb6
4 changed files with 96 additions and 11 deletions

View file

@ -348,6 +348,7 @@ Remark:
### SRS 2.0 history
* v2.0, 2015-07-01, fix [#433](https://github.com/simple-rtmp-server/srs/issues/433) fix the sps parse bug. 2.0.176
* 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
* v2.0, 2015-06-10, fix [#424](https://github.com/simple-rtmp-server/srs/issues/424) fix aggregate timestamp bug. 2.0.174
* v2.0, 2015-06-06, fix [#421](https://github.com/simple-rtmp-server/srs/issues/421) drop video for unkown RTMP header.

View file

@ -35,6 +35,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#endif
#include <stdlib.h>
#include <sys/time.h>
#include <map>
using namespace std;
#include <srs_kernel_log.hpp>
@ -999,12 +1000,14 @@ void srs_update_network_devices()
// @see: read_net_dev() from https://github.com/sysstat/sysstat/blob/master/rd_stats.c#L786
// @remark, we use our algorithm, not sysstat.
char fname[7];
sscanf(buf, "%6[^:]:%llu %lu %lu %lu %lu %lu %lu %lu %llu %lu %lu %lu %lu %lu %lu %lu\n",
r.name, &r.rbytes, &r.rpackets, &r.rerrs, &r.rdrop, &r.rfifo, &r.rframe, &r.rcompressed, &r.rmulticast,
fname, &r.rbytes, &r.rpackets, &r.rerrs, &r.rdrop, &r.rfifo, &r.rframe, &r.rcompressed, &r.rmulticast,
&r.sbytes, &r.spackets, &r.serrs, &r.sdrop, &r.sfifo, &r.scolls, &r.scarrier, &r.scompressed);
r.name[sizeof(r.name) - 1] = 0;
sscanf(fname, "%s", r.name);
_nb_srs_system_network_devices = i + 1;
srs_info("scan network device ifname=%s, total=%d", r.name, _nb_srs_system_network_devices);
r.sample_time = srs_get_system_time_ms();
r.ok = true;
@ -1018,6 +1021,48 @@ void srs_update_network_devices()
#endif
}
// we detect all network device as internet or intranet device, by its ip address.
// key is device name, for instance, eth0
// value is whether internet, for instance, true.
static std::map<std::string, bool> _srs_device_ifs;
bool srs_net_device_is_internet(string ifname)
{
srs_info("check ifname=%s", ifname.c_str());
if (_srs_device_ifs.find(ifname) == _srs_device_ifs.end()) {
return false;
}
return _srs_device_ifs[ifname];
}
bool srs_net_device_is_internet(in_addr_t addr)
{
u_int32_t addr_h = ntohl(addr);
// lo, 127.0.0.0-127.0.0.1
if (addr_h >= 0x7f000000 && addr_h <= 0x7f000001) {
return false;
}
// Class A 10.0.0.0-10.255.255.255
if (addr_h >= 0x0a000000 && addr_h <= 0x0affffff) {
return false;
}
// Class B 172.16.0.0-172.31.255.255
if (addr_h >= 0xac100000 && addr_h <= 0xac1fffff) {
return false;
}
// Class C 192.168.0.0-192.168.255.255
if (addr_h >= 0xc0a80000 && addr_h <= 0xc0a8ffff) {
return false;
}
return true;
}
SrsNetworkRtmpServer::SrsNetworkRtmpServer()
{
ok = false;
@ -1186,7 +1231,9 @@ void retrieve_local_ipv4_ips()
ifaddrs* p = ifap;
while (p != NULL) {
sockaddr* addr = p->ifa_addr;
ifaddrs* cur = p;
sockaddr* addr = cur->ifa_addr;
p = p->ifa_next;
// retrieve ipv4 addr
// ignore the tun0 network device,
@ -1208,9 +1255,16 @@ void retrieve_local_ipv4_ips()
srs_trace("retrieve local ipv4 ip=%s, index=%d", ip.c_str(), (int)ips.size());
ips.push_back(ip);
}
// set the device internet status.
if (!srs_net_device_is_internet(inaddr->s_addr)) {
srs_trace("detect intranet address: %s, ifname=%s", ip.c_str(), cur->ifa_name);
_srs_device_ifs[cur->ifa_name] = false;
} else {
srs_trace("detect internet address: %s, ifname=%s", ip.c_str(), cur->ifa_name);
_srs_device_ifs[cur->ifa_name] = true;
}
}
p = p->ifa_next;
}
freeifaddrs(ifap);
@ -1320,19 +1374,30 @@ void srs_api_dump_summaries(std::stringstream& ss)
int64_t n_sample_time = 0;
int64_t nr_bytes = 0;
int64_t ns_bytes = 0;
int64_t nri_bytes = 0;
int64_t nsi_bytes = 0;
int nb_n = srs_get_network_devices_count();
for (int i = 0; i < nb_n; i++) {
SrsNetworkDevices& o = n[i];
// ignore the lo interface.
std::string inter = o.name;
if (!o.ok || inter == "lo") {
if (!o.ok) {
continue;
}
// update the sample time.
n_sample_time = o.sample_time;
// stat the intranet bytes.
if (inter == "lo" || !srs_net_device_is_internet(inter)) {
nri_bytes += o.rbytes;
nsi_bytes += o.sbytes;
continue;
}
nr_bytes += o.rbytes;
ns_bytes += o.sbytes;
n_sample_time = o.sample_time;
}
// all data is ok?
@ -1371,9 +1436,15 @@ void srs_api_dump_summaries(std::stringstream& ss)
<< SRS_JFIELD_ORG("load_1m", p->load_one_minutes) << SRS_JFIELD_CONT
<< SRS_JFIELD_ORG("load_5m", p->load_five_minutes) << SRS_JFIELD_CONT
<< SRS_JFIELD_ORG("load_15m", p->load_fifteen_minutes) << SRS_JFIELD_CONT
// system network bytes stat.
<< SRS_JFIELD_ORG("net_sample_time", n_sample_time) << SRS_JFIELD_CONT
// internet public address network device bytes.
<< SRS_JFIELD_ORG("net_recv_bytes", nr_bytes) << SRS_JFIELD_CONT
<< SRS_JFIELD_ORG("net_send_bytes", ns_bytes) << SRS_JFIELD_CONT
// intranet private address network device bytes.
<< SRS_JFIELD_ORG("net_recvi_bytes", nri_bytes) << SRS_JFIELD_CONT
<< SRS_JFIELD_ORG("net_sendi_bytes", nsi_bytes) << SRS_JFIELD_CONT
// srs network bytes stat.
<< SRS_JFIELD_ORG("srs_sample_time", nrs->sample_time) << SRS_JFIELD_CONT
<< SRS_JFIELD_ORG("srs_recv_bytes", nrs->rbytes) << SRS_JFIELD_CONT
<< SRS_JFIELD_ORG("srs_send_bytes", nrs->sbytes) << SRS_JFIELD_CONT

View file

@ -34,6 +34,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <string>
#include <sstream>
#include <arpa/inet.h>
#include <sys/resource.h>
#include <srs_app_st.hpp>
@ -609,6 +610,9 @@ extern SrsNetworkDevices* srs_get_network_devices();
extern int srs_get_network_devices_count();
// the deamon st-thread will update it.
extern void srs_update_network_devices();
// detect whether specified device is internet public address.
extern bool srs_net_device_is_internet(std::string ifname);
extern bool srs_net_device_is_internet(in_addr_t addr);
// system connections, and srs rtmp network summary
class SrsNetworkRtmpServer

View file

@ -981,11 +981,11 @@ int SrsAvcAacCodec::avc_demux_sps_rbsp(char* rbsp, int nb_rbsp)
}
srs_info("sps parse profile=%d, level=%d, sps_id=%d", profile_idc, level_idc, seq_parameter_set_id);
int32_t chroma_format_idc = -1;
if (profile_idc == 100 || profile_idc == 110 || profile_idc == 122 || profile_idc == 244
|| profile_idc == 44 || profile_idc == 83 || profile_idc == 86 || profile_idc == 118
|| profile_idc == 128
) {
int32_t chroma_format_idc = -1;
if ((ret = srs_avc_nalu_read_uev(&bs, chroma_format_idc)) != ERROR_SUCCESS) {
return ret;
}
@ -1016,9 +1016,18 @@ int SrsAvcAacCodec::avc_demux_sps_rbsp(char* rbsp, int nb_rbsp)
return ret;
}
if (seq_scaling_matrix_present_flag) {
ret = ERROR_HLS_DECODE_ERROR;
srs_error("sps the seq_scaling_matrix_present_flag invalid. ret=%d", ret);
return ret;
int nb_scmpfs = ((chroma_format_idc != 3)? 8:12);
for (int i = 0; i < nb_scmpfs; i++) {
int8_t seq_scaling_matrix_present_flag_i = -1;
if ((ret = srs_avc_nalu_read_bit(&bs, seq_scaling_matrix_present_flag_i)) != ERROR_SUCCESS) {
return ret;
}
if (seq_scaling_matrix_present_flag_i) {
ret = ERROR_HLS_DECODE_ERROR;
srs_error("sps the seq_scaling_matrix_present_flag invalid, i=%d, nb_scmpfs=%d. ret=%d", i, nb_scmpfs, ret);
return ret;
}
}
}
}