From c58dbe4d146fdfa46879d41fcb8953c2e74a50fb Mon Sep 17 00:00:00 2001 From: winlin Date: Wed, 11 Jan 2017 11:22:16 +0800 Subject: [PATCH 1/3] fix #588, kbps interface error. 2.0.228 --- README.md | 2 ++ trunk/src/core/srs_core.hpp | 2 +- trunk/src/protocol/srs_protocol_kbps.cpp | 32 +++++++++++++++++++++--- trunk/src/protocol/srs_protocol_kbps.hpp | 15 ++++++----- 4 files changed, 40 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 08d2b4668..48dfe8269 100755 --- a/README.md +++ b/README.md @@ -345,6 +345,7 @@ Remark: ## History +* 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-10, refine hls html5 video template. * v2.0, 2017-01-10, fix [#635][bug #635], hls support NonIDR(open gop). 2.0.226 @@ -1272,6 +1273,7 @@ Winlin [bug #513]: https://github.com/ossrs/srs/issues/513 [bug #730]: https://github.com/ossrs/srs/issues/730 [bug #635]: https://github.com/ossrs/srs/issues/635 +[bug #588]: https://github.com/ossrs/srs/issues/588 [bug #xxxxxxxxxx]: https://github.com/ossrs/srs/issues/xxxxxxxxxx [exo #828]: https://github.com/google/ExoPlayer/pull/828 diff --git a/trunk/src/core/srs_core.hpp b/trunk/src/core/srs_core.hpp index 893f94c7a..72561527a 100644 --- a/trunk/src/core/srs_core.hpp +++ b/trunk/src/core/srs_core.hpp @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // current release version #define VERSION_MAJOR 2 #define VERSION_MINOR 0 -#define VERSION_REVISION 227 +#define VERSION_REVISION 228 // generated by configure, only macros. #include diff --git a/trunk/src/protocol/srs_protocol_kbps.cpp b/trunk/src/protocol/srs_protocol_kbps.cpp index 2722685f6..554d6615e 100644 --- a/trunk/src/protocol/srs_protocol_kbps.cpp +++ b/trunk/src/protocol/srs_protocol_kbps.cpp @@ -126,7 +126,7 @@ void SrsKbps::set_io(ISrsProtocolStatistic* in, ISrsProtocolStatistic* out) is.io.in = in; is.last_bytes = is.io_bytes_base = 0; if (in) { - is.last_bytes = is.io_bytes_base = in->get_recv_bytes(); + is.bytes += is.io.in->get_recv_bytes() - is.io_bytes_base; } // resample is.sample(); @@ -138,7 +138,7 @@ void SrsKbps::set_io(ISrsProtocolStatistic* in, ISrsProtocolStatistic* out) } // save the old in bytes. 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. os.io.out = out; @@ -192,12 +192,36 @@ int SrsKbps::get_recv_kbps_5m() 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; + + // session delta. + if (os.io.out) { + bytes += os.io.out->get_send_bytes() - os.io_bytes_base; + } + + return 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; + + // session delta. + if (is.io.in) { + bytes += is.io.in->get_recv_bytes() - is.io_bytes_base; + } + + return bytes; } void SrsKbps::resample() diff --git a/trunk/src/protocol/srs_protocol_kbps.hpp b/trunk/src/protocol/srs_protocol_kbps.hpp index 75a928526..5c5452015 100644 --- a/trunk/src/protocol/srs_protocol_kbps.hpp +++ b/trunk/src/protocol/srs_protocol_kbps.hpp @@ -95,13 +95,9 @@ public: SrsKbpsSlice(); virtual ~SrsKbpsSlice(); public: - /** - * get current total bytes. - */ + // Get current total bytes, not depend on sample(). virtual int64_t get_total_bytes(); - /** - * resample all samples. - */ + // Resample the slice to calculate the kbps. virtual void sample(); }; @@ -162,6 +158,13 @@ public: * printf("delta is %d/%d", delta->get_send_bytes_delta(), delta->get_recv_bytes_delta()); * delta->cleanup(); * the server never know how many bytes already send/recv, for the connection maybe closed. + * 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); */ class SrsKbps : public virtual ISrsProtocolStatistic, public virtual IKbpsDelta { From 6a8c232c5b838be0e8f1f503aa21db06f6f235eb Mon Sep 17 00:00:00 2001 From: winlin Date: Wed, 11 Jan 2017 11:37:26 +0800 Subject: [PATCH 2/3] fix #588, kbps interface error. 2.0.228 --- trunk/src/protocol/srs_protocol_kbps.cpp | 23 +++++++++++++++++++---- trunk/src/protocol/srs_protocol_kbps.hpp | 22 +++++++--------------- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/trunk/src/protocol/srs_protocol_kbps.cpp b/trunk/src/protocol/srs_protocol_kbps.cpp index 554d6615e..0c6234e6d 100644 --- a/trunk/src/protocol/srs_protocol_kbps.cpp +++ b/trunk/src/protocol/srs_protocol_kbps.cpp @@ -120,13 +120,13 @@ void SrsKbps::set_io(ISrsProtocolStatistic* in, ISrsProtocolStatistic* out) } // save the old in bytes. 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. is.io.in = in; is.last_bytes = is.io_bytes_base = 0; if (in) { - is.bytes += is.io.in->get_recv_bytes() - is.io_bytes_base; + is.last_bytes = is.io_bytes_base = in->get_recv_bytes(); } // resample is.sample(); @@ -199,11 +199,16 @@ int64_t SrsKbps::get_send_bytes() // session start bytes. int64_t bytes = os.bytes; - // session delta. + // 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; } @@ -216,11 +221,16 @@ int64_t SrsKbps::get_recv_bytes() // session start bytes. int64_t bytes = is.bytes; - // session delta. + // 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; } @@ -274,3 +284,8 @@ void SrsKbps::sample() os.sample(); } +int SrsKbps::size_memory() +{ + return sizeof(SrsKbps); +} + diff --git a/trunk/src/protocol/srs_protocol_kbps.hpp b/trunk/src/protocol/srs_protocol_kbps.hpp index 5c5452015..dd5a8ada0 100644 --- a/trunk/src/protocol/srs_protocol_kbps.hpp +++ b/trunk/src/protocol/srs_protocol_kbps.hpp @@ -157,14 +157,14 @@ public: * delta->resample(); * printf("delta is %d/%d", delta->get_send_bytes_delta(), delta->get_recv_bytes_delta()); * delta->cleanup(); - * the server never know how many bytes already send/recv, for the connection maybe closed. * 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: +* // 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. */ class SrsKbps : public virtual ISrsProtocolStatistic, public virtual IKbpsDelta { @@ -198,26 +198,15 @@ public: // 5m virtual int get_send_kbps_5m(); virtual int get_recv_kbps_5m(); +// interface ISrsProtocolStatistic 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_recv_bytes(); +// interface IKbpsDelta public: - /** - * resample to get the delta. - */ virtual void resample(); - /** - * get the delta of send/recv bytes. - */ virtual int64_t get_send_bytes_delta(); virtual int64_t get_recv_bytes_delta(); - /** - * cleanup the delta. - */ virtual void cleanup(); public: /** @@ -235,6 +224,9 @@ public: * use the add_delta() is better solutions. */ virtual void sample(); +// interface ISrsMemorySizer +public: + virtual int size_memory(); }; #endif From fec6f96a8f02b356ec9c341060212d9a702b0103 Mon Sep 17 00:00:00 2001 From: winlin Date: Wed, 11 Jan 2017 11:44:51 +0800 Subject: [PATCH 3/3] fix link for readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 48dfe8269..f9339818e 100755 --- a/README.md +++ b/README.md @@ -1273,6 +1273,7 @@ Winlin [bug #513]: https://github.com/ossrs/srs/issues/513 [bug #730]: https://github.com/ossrs/srs/issues/730 [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