正在显示
4 个修改的文件
包含
40 行增加
和
11 行删除
| @@ -345,6 +345,7 @@ Remark: | @@ -345,6 +345,7 @@ Remark: | ||
| 345 | 345 | ||
| 346 | ## History | 346 | ## History |
| 347 | 347 | ||
| 348 | +* v2.0, 2017-01-11, fix [#588][bug #588], kbps interface error. 2.0.228 | ||
| 348 | * v2.0, 2017-01-11, fix [#736][bug #736], recovery the hls dispose. 2.0.227 | 349 | * v2.0, 2017-01-11, fix [#736][bug #736], recovery the hls dispose. 2.0.227 |
| 349 | * v2.0, 2017-01-10, refine hls html5 video template. | 350 | * v2.0, 2017-01-10, refine hls html5 video template. |
| 350 | * v2.0, 2017-01-10, fix [#635][bug #635], hls support NonIDR(open gop). 2.0.226 | 351 | * v2.0, 2017-01-10, fix [#635][bug #635], hls support NonIDR(open gop). 2.0.226 |
| @@ -1272,6 +1273,7 @@ Winlin | @@ -1272,6 +1273,7 @@ Winlin | ||
| 1272 | [bug #513]: https://github.com/ossrs/srs/issues/513 | 1273 | [bug #513]: https://github.com/ossrs/srs/issues/513 |
| 1273 | [bug #730]: https://github.com/ossrs/srs/issues/730 | 1274 | [bug #730]: https://github.com/ossrs/srs/issues/730 |
| 1274 | [bug #635]: https://github.com/ossrs/srs/issues/635 | 1275 | [bug #635]: https://github.com/ossrs/srs/issues/635 |
| 1276 | +[bug #588]: https://github.com/ossrs/srs/issues/588 | ||
| 1275 | [bug #xxxxxxxxxx]: https://github.com/ossrs/srs/issues/xxxxxxxxxx | 1277 | [bug #xxxxxxxxxx]: https://github.com/ossrs/srs/issues/xxxxxxxxxx |
| 1276 | 1278 | ||
| 1277 | [exo #828]: https://github.com/google/ExoPlayer/pull/828 | 1279 | [exo #828]: https://github.com/google/ExoPlayer/pull/828 |
| @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 31 | // current release version | 31 | // current release version |
| 32 | #define VERSION_MAJOR 2 | 32 | #define VERSION_MAJOR 2 |
| 33 | #define VERSION_MINOR 0 | 33 | #define VERSION_MINOR 0 |
| 34 | -#define VERSION_REVISION 227 | 34 | +#define VERSION_REVISION 228 |
| 35 | 35 | ||
| 36 | // generated by configure, only macros. | 36 | // generated by configure, only macros. |
| 37 | #include <srs_auto_headers.hpp> | 37 | #include <srs_auto_headers.hpp> |
| @@ -126,7 +126,7 @@ void SrsKbps::set_io(ISrsProtocolStatistic* in, ISrsProtocolStatistic* out) | @@ -126,7 +126,7 @@ void SrsKbps::set_io(ISrsProtocolStatistic* in, ISrsProtocolStatistic* out) | ||
| 126 | is.io.in = in; | 126 | is.io.in = in; |
| 127 | is.last_bytes = is.io_bytes_base = 0; | 127 | is.last_bytes = is.io_bytes_base = 0; |
| 128 | if (in) { | 128 | if (in) { |
| 129 | - is.last_bytes = is.io_bytes_base = in->get_recv_bytes(); | 129 | + is.bytes += is.io.in->get_recv_bytes() - is.io_bytes_base; |
| 130 | } | 130 | } |
| 131 | // resample | 131 | // resample |
| 132 | is.sample(); | 132 | is.sample(); |
| @@ -138,7 +138,7 @@ void SrsKbps::set_io(ISrsProtocolStatistic* in, ISrsProtocolStatistic* out) | @@ -138,7 +138,7 @@ void SrsKbps::set_io(ISrsProtocolStatistic* in, ISrsProtocolStatistic* out) | ||
| 138 | } | 138 | } |
| 139 | // save the old in bytes. | 139 | // save the old in bytes. |
| 140 | if (os.io.out) { | 140 | if (os.io.out) { |
| 141 | - os.bytes += os.last_bytes - os.io_bytes_base; | 141 | + os.bytes += os.io.out->get_send_bytes() - os.io_bytes_base; |
| 142 | } | 142 | } |
| 143 | // use new io. | 143 | // use new io. |
| 144 | os.io.out = out; | 144 | os.io.out = out; |
| @@ -192,12 +192,36 @@ int SrsKbps::get_recv_kbps_5m() | @@ -192,12 +192,36 @@ int SrsKbps::get_recv_kbps_5m() | ||
| 192 | 192 | ||
| 193 | int64_t SrsKbps::get_send_bytes() | 193 | int64_t SrsKbps::get_send_bytes() |
| 194 | { | 194 | { |
| 195 | - return os.get_total_bytes(); | 195 | + // we must calc the send bytes dynamically, |
| 196 | + // to not depends on the sample(which used to calc the kbps). | ||
| 197 | + // @read https://github.com/ossrs/srs/issues/588 | ||
| 198 | + | ||
| 199 | + // session start bytes. | ||
| 200 | + int64_t bytes = os.bytes; | ||
| 201 | + | ||
| 202 | + // session delta. | ||
| 203 | + if (os.io.out) { | ||
| 204 | + bytes += os.io.out->get_send_bytes() - os.io_bytes_base; | ||
| 205 | + } | ||
| 206 | + | ||
| 207 | + return bytes; | ||
| 196 | } | 208 | } |
| 197 | 209 | ||
| 198 | int64_t SrsKbps::get_recv_bytes() | 210 | int64_t SrsKbps::get_recv_bytes() |
| 199 | { | 211 | { |
| 200 | - return is.get_total_bytes(); | 212 | + // we must calc the send bytes dynamically, |
| 213 | + // to not depends on the sample(which used to calc the kbps). | ||
| 214 | + // @read https://github.com/ossrs/srs/issues/588 | ||
| 215 | + | ||
| 216 | + // session start bytes. | ||
| 217 | + int64_t bytes = is.bytes; | ||
| 218 | + | ||
| 219 | + // session delta. | ||
| 220 | + if (is.io.in) { | ||
| 221 | + bytes += is.io.in->get_recv_bytes() - is.io_bytes_base; | ||
| 222 | + } | ||
| 223 | + | ||
| 224 | + return bytes; | ||
| 201 | } | 225 | } |
| 202 | 226 | ||
| 203 | void SrsKbps::resample() | 227 | void SrsKbps::resample() |
| @@ -95,13 +95,9 @@ public: | @@ -95,13 +95,9 @@ public: | ||
| 95 | SrsKbpsSlice(); | 95 | SrsKbpsSlice(); |
| 96 | virtual ~SrsKbpsSlice(); | 96 | virtual ~SrsKbpsSlice(); |
| 97 | public: | 97 | public: |
| 98 | - /** | ||
| 99 | - * get current total bytes. | ||
| 100 | - */ | 98 | + // Get current total bytes, not depend on sample(). |
| 101 | virtual int64_t get_total_bytes(); | 99 | virtual int64_t get_total_bytes(); |
| 102 | - /** | ||
| 103 | - * resample all samples. | ||
| 104 | - */ | 100 | + // Resample the slice to calculate the kbps. |
| 105 | virtual void sample(); | 101 | virtual void sample(); |
| 106 | }; | 102 | }; |
| 107 | 103 | ||
| @@ -162,6 +158,13 @@ public: | @@ -162,6 +158,13 @@ public: | ||
| 162 | * printf("delta is %d/%d", delta->get_send_bytes_delta(), delta->get_recv_bytes_delta()); | 158 | * printf("delta is %d/%d", delta->get_send_bytes_delta(), delta->get_recv_bytes_delta()); |
| 163 | * delta->cleanup(); | 159 | * delta->cleanup(); |
| 164 | * the server never know how many bytes already send/recv, for the connection maybe closed. | 160 | * the server never know how many bytes already send/recv, for the connection maybe closed. |
| 161 | + * 4. kbps used as ISrsProtocolStatistic, to provides raw bytes: | ||
| 162 | + * SrsKbps* kbps = ...; | ||
| 163 | + * kbps->set_io(in, out); | ||
| 164 | + * // both kbps->get_recv_bytes() and kbps->get_send_bytes() are available. | ||
| 165 | + * // we can use the kbps as the data source of another kbps: | ||
| 166 | + * SrsKbps* user = ...; | ||
| 167 | + * user->set_io(kbps, kbps); | ||
| 165 | */ | 168 | */ |
| 166 | class SrsKbps : public virtual ISrsProtocolStatistic, public virtual IKbpsDelta | 169 | class SrsKbps : public virtual ISrsProtocolStatistic, public virtual IKbpsDelta |
| 167 | { | 170 | { |
-
请 注册 或 登录 后发表评论