正在显示
3 个修改的文件
包含
29 行增加
和
1 行删除
| @@ -43,6 +43,10 @@ int main(int argc, char** argv) | @@ -43,6 +43,10 @@ int main(int argc, char** argv) | ||
| 43 | int64_t time_cleanup = 0; | 43 | int64_t time_cleanup = 0; |
| 44 | // delay = actual - expect time when quit. | 44 | // delay = actual - expect time when quit. |
| 45 | int delay = 0; | 45 | int delay = 0; |
| 46 | + // bytes | ||
| 47 | + int64_t bytes_nsend = 0; | ||
| 48 | + int time_duration = 0; | ||
| 49 | + int64_t bytes_nrecv = 0; | ||
| 46 | 50 | ||
| 47 | // packet data | 51 | // packet data |
| 48 | int type, size; | 52 | int type, size; |
| @@ -145,8 +149,12 @@ int main(int argc, char** argv) | @@ -145,8 +149,12 @@ int main(int argc, char** argv) | ||
| 145 | } | 149 | } |
| 146 | 150 | ||
| 147 | rtmp_destroy: | 151 | rtmp_destroy: |
| 152 | + bytes_nsend = srs_get_nsend_bytes(rtmp); | ||
| 153 | + bytes_nrecv = srs_get_nrecv_bytes(rtmp); | ||
| 154 | + | ||
| 148 | srs_rtmp_destroy(rtmp); | 155 | srs_rtmp_destroy(rtmp); |
| 149 | time_cleanup = srs_get_time_ms(); | 156 | time_cleanup = srs_get_time_ms(); |
| 157 | + time_duration = (int)(time_cleanup - time_startup); | ||
| 150 | 158 | ||
| 151 | // print result to stderr. | 159 | // print result to stderr. |
| 152 | fprintf(stderr, "{" | 160 | fprintf(stderr, "{" |
| @@ -159,10 +167,12 @@ rtmp_destroy: | @@ -159,10 +167,12 @@ rtmp_destroy: | ||
| 159 | "\"%s\":%d, " // #6 | 167 | "\"%s\":%d, " // #6 |
| 160 | "\"%s\":%d, " // #7 | 168 | "\"%s\":%d, " // #7 |
| 161 | "\"%s\":%d, " // #8 | 169 | "\"%s\":%d, " // #8 |
| 170 | + "\"%s\":%d, " // #9 | ||
| 171 | + "\"%s\":%d, " // #10 | ||
| 162 | "%s,%s,%s,%s}", | 172 | "%s,%s,%s,%s}", |
| 163 | "code", ret, //#0 | 173 | "code", ret, //#0 |
| 164 | // total = dns + tcp_connect + start_play + first_packet + last_packet | 174 | // total = dns + tcp_connect + start_play + first_packet + last_packet |
| 165 | - "total", (int)(time_cleanup - time_startup), //#1 | 175 | + "total", time_duration, //#1 |
| 166 | "dns", (int)(time_dns_resolve - time_startup), //#2 | 176 | "dns", (int)(time_dns_resolve - time_startup), //#2 |
| 167 | "tcp_connect", (int)(time_socket_connect - time_dns_resolve), //#3 | 177 | "tcp_connect", (int)(time_socket_connect - time_dns_resolve), //#3 |
| 168 | "start_play", (int)(time_play_stream - time_socket_connect), //#4 | 178 | "start_play", (int)(time_play_stream - time_socket_connect), //#4 |
| @@ -173,6 +183,8 @@ rtmp_destroy: | @@ -173,6 +183,8 @@ rtmp_destroy: | ||
| 173 | // actual = stream | 183 | // actual = stream |
| 174 | // delay = actual - expect | 184 | // delay = actual - expect |
| 175 | "delay", (int)(timestamp - (time_cleanup - time_first_packet)), //#8 | 185 | "delay", (int)(timestamp - (time_cleanup - time_first_packet)), //#8 |
| 186 | + "publish_kbps", (int)((time_duration <= 0)? 0:(bytes_nsend * 8 / time_duration)), //#9 | ||
| 187 | + "play_kbps", (int)((time_duration <= 0)? 0:(bytes_nrecv * 8 / time_duration)), //#10 | ||
| 176 | // unit in ms. | 188 | // unit in ms. |
| 177 | "\"unit\": \"ms\"", | 189 | "\"unit\": \"ms\"", |
| 178 | "\"remark0\": \"total = dns + tcp_connect + start_play + first_packet + last_packet\"", | 190 | "\"remark0\": \"total = dns + tcp_connect + start_play + first_packet + last_packet\"", |
| @@ -451,6 +451,20 @@ int64_t srs_get_time_ms() | @@ -451,6 +451,20 @@ int64_t srs_get_time_ms() | ||
| 451 | return srs_get_system_time_ms(); | 451 | return srs_get_system_time_ms(); |
| 452 | } | 452 | } |
| 453 | 453 | ||
| 454 | +int64_t srs_get_nsend_bytes(srs_rtmp_t rtmp) | ||
| 455 | +{ | ||
| 456 | + srs_assert(rtmp != NULL); | ||
| 457 | + Context* context = (Context*)rtmp; | ||
| 458 | + return context->rtmp->get_send_bytes(); | ||
| 459 | +} | ||
| 460 | + | ||
| 461 | +int64_t srs_get_nrecv_bytes(srs_rtmp_t rtmp) | ||
| 462 | +{ | ||
| 463 | + srs_assert(rtmp != NULL); | ||
| 464 | + Context* context = (Context*)rtmp; | ||
| 465 | + return context->rtmp->get_recv_bytes(); | ||
| 466 | +} | ||
| 467 | + | ||
| 454 | struct FlvContext | 468 | struct FlvContext |
| 455 | { | 469 | { |
| 456 | SrsFileStream fs; | 470 | SrsFileStream fs; |
| @@ -157,6 +157,8 @@ int srs_version_revision(); | @@ -157,6 +157,8 @@ int srs_version_revision(); | ||
| 157 | * utilities | 157 | * utilities |
| 158 | */ | 158 | */ |
| 159 | int64_t srs_get_time_ms(); | 159 | int64_t srs_get_time_ms(); |
| 160 | +int64_t srs_get_nsend_bytes(srs_rtmp_t rtmp); | ||
| 161 | +int64_t srs_get_nrecv_bytes(srs_rtmp_t rtmp); | ||
| 160 | 162 | ||
| 161 | /** | 163 | /** |
| 162 | * flv codec | 164 | * flv codec |
-
请 注册 或 登录 后发表评论