mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
merge srs2 for kbps
This commit is contained in:
commit
f92db0f87e
3 changed files with 61 additions and 23 deletions
|
@ -205,6 +205,7 @@ Please select your language:
|
||||||
|
|
||||||
### V2 changes
|
### V2 changes
|
||||||
|
|
||||||
|
* v2.0, 2017-01-11, fix [#588][bug #588], kbps interface error. 2.0.228
|
||||||
* v2.0, 2017-01-11, fix [#736][bug #736], recovery the hls dispose. 2.0.227
|
* v2.0, 2017-01-11, fix [#736][bug #736], recovery the hls dispose. 2.0.227
|
||||||
* v2.0, 2017-01-10, refine hls html5 video template.
|
* v2.0, 2017-01-10, refine hls html5 video template.
|
||||||
* v2.0, 2017-01-10, fix [#635][bug #635], hls support NonIDR(open gop). 2.0.226
|
* v2.0, 2017-01-10, fix [#635][bug #635], hls support NonIDR(open gop). 2.0.226
|
||||||
|
@ -1368,6 +1369,9 @@ Winlin
|
||||||
[bug #513]: https://github.com/ossrs/srs/issues/513
|
[bug #513]: https://github.com/ossrs/srs/issues/513
|
||||||
[bug #730]: https://github.com/ossrs/srs/issues/730
|
[bug #730]: https://github.com/ossrs/srs/issues/730
|
||||||
[bug #635]: https://github.com/ossrs/srs/issues/635
|
[bug #635]: https://github.com/ossrs/srs/issues/635
|
||||||
|
[bug #736]: https://github.com/ossrs/srs/issues/736
|
||||||
|
[bug #588]: https://github.com/ossrs/srs/issues/588
|
||||||
|
[bug #xxxxxxxxxx]: https://github.com/ossrs/srs/issues/xxxxxxxxxx
|
||||||
[bug #735]: https://github.com/ossrs/srs/issues/735
|
[bug #735]: https://github.com/ossrs/srs/issues/735
|
||||||
[bug #xxxxxxxxxx]: https://github.com/ossrs/srs/issues/xxxxxxxxxx
|
[bug #xxxxxxxxxx]: https://github.com/ossrs/srs/issues/xxxxxxxxxx
|
||||||
|
|
||||||
|
|
|
@ -120,7 +120,7 @@ void SrsKbps::set_io(ISrsProtocolStatistic* in, ISrsProtocolStatistic* out)
|
||||||
}
|
}
|
||||||
// save the old in bytes.
|
// save the old in bytes.
|
||||||
if (is.io.in) {
|
if (is.io.in) {
|
||||||
is.bytes += is.last_bytes - is.io_bytes_base;
|
is.bytes += is.io.in->get_recv_bytes() - is.io_bytes_base;
|
||||||
}
|
}
|
||||||
// use new io.
|
// use new io.
|
||||||
is.io.in = in;
|
is.io.in = in;
|
||||||
|
@ -138,7 +138,7 @@ void SrsKbps::set_io(ISrsProtocolStatistic* in, ISrsProtocolStatistic* out)
|
||||||
}
|
}
|
||||||
// save the old in bytes.
|
// save the old in bytes.
|
||||||
if (os.io.out) {
|
if (os.io.out) {
|
||||||
os.bytes += os.last_bytes - os.io_bytes_base;
|
os.bytes += os.io.out->get_send_bytes() - os.io_bytes_base;
|
||||||
}
|
}
|
||||||
// use new io.
|
// use new io.
|
||||||
os.io.out = out;
|
os.io.out = out;
|
||||||
|
@ -192,12 +192,46 @@ int SrsKbps::get_recv_kbps_5m()
|
||||||
|
|
||||||
int64_t SrsKbps::get_send_bytes()
|
int64_t SrsKbps::get_send_bytes()
|
||||||
{
|
{
|
||||||
return os.get_total_bytes();
|
// we must calc the send bytes dynamically,
|
||||||
|
// to not depends on the sample(which used to calc the kbps).
|
||||||
|
// @read https://github.com/ossrs/srs/issues/588
|
||||||
|
|
||||||
|
// session start bytes.
|
||||||
|
int64_t bytes = os.bytes;
|
||||||
|
|
||||||
|
// When exists active session, use it to get the last bytes.
|
||||||
|
if (os.io.out) {
|
||||||
|
bytes += os.io.out->get_send_bytes() - os.io_bytes_base;
|
||||||
|
return bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
// When no active session, the last_bytes record the last valid bytes.
|
||||||
|
// TODO: Maybe the bellow bytes is zero, because the ios.io.out is NULL.
|
||||||
|
bytes += os.last_bytes - os.io_bytes_base;
|
||||||
|
|
||||||
|
return bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t SrsKbps::get_recv_bytes()
|
int64_t SrsKbps::get_recv_bytes()
|
||||||
{
|
{
|
||||||
return is.get_total_bytes();
|
// we must calc the send bytes dynamically,
|
||||||
|
// to not depends on the sample(which used to calc the kbps).
|
||||||
|
// @read https://github.com/ossrs/srs/issues/588
|
||||||
|
|
||||||
|
// session start bytes.
|
||||||
|
int64_t bytes = is.bytes;
|
||||||
|
|
||||||
|
// When exists active session, use it to get the last bytes.
|
||||||
|
if (is.io.in) {
|
||||||
|
bytes += is.io.in->get_recv_bytes() - is.io_bytes_base;
|
||||||
|
return bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
// When no active session, the last_bytes record the last valid bytes.
|
||||||
|
// TODO: Maybe the bellow bytes is zero, because the ios.io.out is NULL.
|
||||||
|
bytes += is.last_bytes - is.io_bytes_base;
|
||||||
|
|
||||||
|
return bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SrsKbps::resample()
|
void SrsKbps::resample()
|
||||||
|
@ -250,3 +284,8 @@ void SrsKbps::sample()
|
||||||
os.sample();
|
os.sample();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int SrsKbps::size_memory()
|
||||||
|
{
|
||||||
|
return sizeof(SrsKbps);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -95,13 +95,9 @@ public:
|
||||||
SrsKbpsSlice();
|
SrsKbpsSlice();
|
||||||
virtual ~SrsKbpsSlice();
|
virtual ~SrsKbpsSlice();
|
||||||
public:
|
public:
|
||||||
/**
|
// Get current total bytes, not depend on sample().
|
||||||
* get current total bytes.
|
|
||||||
*/
|
|
||||||
virtual int64_t get_total_bytes();
|
virtual int64_t get_total_bytes();
|
||||||
/**
|
// Resample the slice to calculate the kbps.
|
||||||
* resample all samples.
|
|
||||||
*/
|
|
||||||
virtual void sample();
|
virtual void sample();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -161,6 +157,13 @@ public:
|
||||||
* delta->resample();
|
* delta->resample();
|
||||||
* printf("delta is %d/%d", delta->get_send_bytes_delta(), delta->get_recv_bytes_delta());
|
* printf("delta is %d/%d", delta->get_send_bytes_delta(), delta->get_recv_bytes_delta());
|
||||||
* delta->cleanup();
|
* delta->cleanup();
|
||||||
|
* 4. kbps used as ISrsProtocolStatistic, to provides raw bytes:
|
||||||
|
* SrsKbps* kbps = ...;
|
||||||
|
* kbps->set_io(in, out);
|
||||||
|
* // both kbps->get_recv_bytes() and kbps->get_send_bytes() are available.
|
||||||
|
* // we can use the kbps as the data source of another kbps:
|
||||||
|
* SrsKbps* user = ...;
|
||||||
|
* user->set_io(kbps, kbps);
|
||||||
* the server never know how many bytes already send/recv, for the connection maybe closed.
|
* the server never know how many bytes already send/recv, for the connection maybe closed.
|
||||||
*/
|
*/
|
||||||
class SrsKbps : public virtual ISrsProtocolStatistic, public virtual IKbpsDelta
|
class SrsKbps : public virtual ISrsProtocolStatistic, public virtual IKbpsDelta
|
||||||
|
@ -195,26 +198,15 @@ public:
|
||||||
// 5m
|
// 5m
|
||||||
virtual int get_send_kbps_5m();
|
virtual int get_send_kbps_5m();
|
||||||
virtual int get_recv_kbps_5m();
|
virtual int get_recv_kbps_5m();
|
||||||
|
// interface ISrsProtocolStatistic
|
||||||
public:
|
public:
|
||||||
/**
|
|
||||||
* get the total send/recv bytes, from the startup of the oldest io.
|
|
||||||
* @remark, use sample() to update data.
|
|
||||||
*/
|
|
||||||
virtual int64_t get_send_bytes();
|
virtual int64_t get_send_bytes();
|
||||||
virtual int64_t get_recv_bytes();
|
virtual int64_t get_recv_bytes();
|
||||||
|
// interface IKbpsDelta
|
||||||
public:
|
public:
|
||||||
/**
|
|
||||||
* resample to get the delta.
|
|
||||||
*/
|
|
||||||
virtual void resample();
|
virtual void resample();
|
||||||
/**
|
|
||||||
* get the delta of send/recv bytes.
|
|
||||||
*/
|
|
||||||
virtual int64_t get_send_bytes_delta();
|
virtual int64_t get_send_bytes_delta();
|
||||||
virtual int64_t get_recv_bytes_delta();
|
virtual int64_t get_recv_bytes_delta();
|
||||||
/**
|
|
||||||
* cleanup the delta.
|
|
||||||
*/
|
|
||||||
virtual void cleanup();
|
virtual void cleanup();
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
|
@ -232,6 +224,9 @@ public:
|
||||||
* use the add_delta() is better solutions.
|
* use the add_delta() is better solutions.
|
||||||
*/
|
*/
|
||||||
virtual void sample();
|
virtual void sample();
|
||||||
|
// interface ISrsMemorySizer
|
||||||
|
public:
|
||||||
|
virtual int size_memory();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue