正在显示
2 个修改的文件
包含
26 行增加
和
19 行删除
@@ -120,13 +120,13 @@ void SrsKbps::set_io(ISrsProtocolStatistic* in, ISrsProtocolStatistic* out) | @@ -120,13 +120,13 @@ void SrsKbps::set_io(ISrsProtocolStatistic* in, ISrsProtocolStatistic* out) | ||
120 | } | 120 | } |
121 | // save the old in bytes. | 121 | // save the old in bytes. |
122 | if (is.io.in) { | 122 | if (is.io.in) { |
123 | - is.bytes += is.last_bytes - is.io_bytes_base; | 123 | + is.bytes += is.io.in->get_recv_bytes() - is.io_bytes_base; |
124 | } | 124 | } |
125 | // use new io. | 125 | // use new io. |
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.bytes += is.io.in->get_recv_bytes() - is.io_bytes_base; | 129 | + is.last_bytes = is.io_bytes_base = in->get_recv_bytes(); |
130 | } | 130 | } |
131 | // resample | 131 | // resample |
132 | is.sample(); | 132 | is.sample(); |
@@ -199,11 +199,16 @@ int64_t SrsKbps::get_send_bytes() | @@ -199,11 +199,16 @@ int64_t SrsKbps::get_send_bytes() | ||
199 | // session start bytes. | 199 | // session start bytes. |
200 | int64_t bytes = os.bytes; | 200 | int64_t bytes = os.bytes; |
201 | 201 | ||
202 | - // session delta. | 202 | + // When exists active session, use it to get the last bytes. |
203 | if (os.io.out) { | 203 | if (os.io.out) { |
204 | bytes += os.io.out->get_send_bytes() - os.io_bytes_base; | 204 | bytes += os.io.out->get_send_bytes() - os.io_bytes_base; |
205 | + return bytes; | ||
205 | } | 206 | } |
206 | 207 | ||
208 | + // When no active session, the last_bytes record the last valid bytes. | ||
209 | + // TODO: Maybe the bellow bytes is zero, because the ios.io.out is NULL. | ||
210 | + bytes += os.last_bytes - os.io_bytes_base; | ||
211 | + | ||
207 | return bytes; | 212 | return bytes; |
208 | } | 213 | } |
209 | 214 | ||
@@ -216,11 +221,16 @@ int64_t SrsKbps::get_recv_bytes() | @@ -216,11 +221,16 @@ int64_t SrsKbps::get_recv_bytes() | ||
216 | // session start bytes. | 221 | // session start bytes. |
217 | int64_t bytes = is.bytes; | 222 | int64_t bytes = is.bytes; |
218 | 223 | ||
219 | - // session delta. | 224 | + // When exists active session, use it to get the last bytes. |
220 | if (is.io.in) { | 225 | if (is.io.in) { |
221 | bytes += is.io.in->get_recv_bytes() - is.io_bytes_base; | 226 | bytes += is.io.in->get_recv_bytes() - is.io_bytes_base; |
227 | + return bytes; | ||
222 | } | 228 | } |
223 | 229 | ||
230 | + // When no active session, the last_bytes record the last valid bytes. | ||
231 | + // TODO: Maybe the bellow bytes is zero, because the ios.io.out is NULL. | ||
232 | + bytes += is.last_bytes - is.io_bytes_base; | ||
233 | + | ||
224 | return bytes; | 234 | return bytes; |
225 | } | 235 | } |
226 | 236 | ||
@@ -274,3 +284,8 @@ void SrsKbps::sample() | @@ -274,3 +284,8 @@ void SrsKbps::sample() | ||
274 | os.sample(); | 284 | os.sample(); |
275 | } | 285 | } |
276 | 286 | ||
287 | +int SrsKbps::size_memory() | ||
288 | +{ | ||
289 | + return sizeof(SrsKbps); | ||
290 | +} | ||
291 | + |
@@ -157,14 +157,14 @@ public: | @@ -157,14 +157,14 @@ public: | ||
157 | * delta->resample(); | 157 | * delta->resample(); |
158 | * 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()); |
159 | * delta->cleanup(); | 159 | * delta->cleanup(); |
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: | 160 | * 4. kbps used as ISrsProtocolStatistic, to provides raw bytes: |
162 | * SrsKbps* kbps = ...; | 161 | * SrsKbps* kbps = ...; |
163 | * kbps->set_io(in, out); | 162 | * kbps->set_io(in, out); |
164 | * // both kbps->get_recv_bytes() and kbps->get_send_bytes() are available. | 163 | * // 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: | 164 | +* // we can use the kbps as the data source of another kbps: |
166 | * SrsKbps* user = ...; | 165 | * SrsKbps* user = ...; |
167 | * user->set_io(kbps, kbps); | 166 | * user->set_io(kbps, kbps); |
167 | + * the server never know how many bytes already send/recv, for the connection maybe closed. | ||
168 | */ | 168 | */ |
169 | class SrsKbps : public virtual ISrsProtocolStatistic, public virtual IKbpsDelta | 169 | class SrsKbps : public virtual ISrsProtocolStatistic, public virtual IKbpsDelta |
170 | { | 170 | { |
@@ -198,26 +198,15 @@ public: | @@ -198,26 +198,15 @@ public: | ||
198 | // 5m | 198 | // 5m |
199 | virtual int get_send_kbps_5m(); | 199 | virtual int get_send_kbps_5m(); |
200 | virtual int get_recv_kbps_5m(); | 200 | virtual int get_recv_kbps_5m(); |
201 | +// interface ISrsProtocolStatistic | ||
201 | public: | 202 | public: |
202 | - /** | ||
203 | - * get the total send/recv bytes, from the startup of the oldest io. | ||
204 | - * @remark, use sample() to update data. | ||
205 | - */ | ||
206 | virtual int64_t get_send_bytes(); | 203 | virtual int64_t get_send_bytes(); |
207 | virtual int64_t get_recv_bytes(); | 204 | virtual int64_t get_recv_bytes(); |
205 | +// interface IKbpsDelta | ||
208 | public: | 206 | public: |
209 | - /** | ||
210 | - * resample to get the delta. | ||
211 | - */ | ||
212 | virtual void resample(); | 207 | virtual void resample(); |
213 | - /** | ||
214 | - * get the delta of send/recv bytes. | ||
215 | - */ | ||
216 | virtual int64_t get_send_bytes_delta(); | 208 | virtual int64_t get_send_bytes_delta(); |
217 | virtual int64_t get_recv_bytes_delta(); | 209 | virtual int64_t get_recv_bytes_delta(); |
218 | - /** | ||
219 | - * cleanup the delta. | ||
220 | - */ | ||
221 | virtual void cleanup(); | 210 | virtual void cleanup(); |
222 | public: | 211 | public: |
223 | /** | 212 | /** |
@@ -235,6 +224,9 @@ public: | @@ -235,6 +224,9 @@ public: | ||
235 | * use the add_delta() is better solutions. | 224 | * use the add_delta() is better solutions. |
236 | */ | 225 | */ |
237 | virtual void sample(); | 226 | virtual void sample(); |
227 | +// interface ISrsMemorySizer | ||
228 | +public: | ||
229 | + virtual int size_memory(); | ||
238 | }; | 230 | }; |
239 | 231 | ||
240 | #endif | 232 | #endif |
-
请 注册 或 登录 后发表评论