From cccc483ab32899c0fe11fb2ec49cff715d739cfc Mon Sep 17 00:00:00 2001 From: winlin Date: Tue, 10 Jun 2014 17:39:12 +0800 Subject: [PATCH] add bytes statistic for librtmp --- trunk/research/librtmp/srs_detect_rtmp.c | 14 +++++++++++++- trunk/src/libs/srs_librtmp.cpp | 14 ++++++++++++++ trunk/src/libs/srs_librtmp.hpp | 2 ++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/trunk/research/librtmp/srs_detect_rtmp.c b/trunk/research/librtmp/srs_detect_rtmp.c index 6323b5e19..a9446db0e 100644 --- a/trunk/research/librtmp/srs_detect_rtmp.c +++ b/trunk/research/librtmp/srs_detect_rtmp.c @@ -43,6 +43,10 @@ int main(int argc, char** argv) int64_t time_cleanup = 0; // delay = actual - expect time when quit. int delay = 0; + // bytes + int64_t bytes_nsend = 0; + int time_duration = 0; + int64_t bytes_nrecv = 0; // packet data int type, size; @@ -145,8 +149,12 @@ int main(int argc, char** argv) } rtmp_destroy: + bytes_nsend = srs_get_nsend_bytes(rtmp); + bytes_nrecv = srs_get_nrecv_bytes(rtmp); + srs_rtmp_destroy(rtmp); time_cleanup = srs_get_time_ms(); + time_duration = (int)(time_cleanup - time_startup); // print result to stderr. fprintf(stderr, "{" @@ -159,10 +167,12 @@ rtmp_destroy: "\"%s\":%d, " // #6 "\"%s\":%d, " // #7 "\"%s\":%d, " // #8 + "\"%s\":%d, " // #9 + "\"%s\":%d, " // #10 "%s,%s,%s,%s}", "code", ret, //#0 // total = dns + tcp_connect + start_play + first_packet + last_packet - "total", (int)(time_cleanup - time_startup), //#1 + "total", time_duration, //#1 "dns", (int)(time_dns_resolve - time_startup), //#2 "tcp_connect", (int)(time_socket_connect - time_dns_resolve), //#3 "start_play", (int)(time_play_stream - time_socket_connect), //#4 @@ -173,6 +183,8 @@ rtmp_destroy: // actual = stream // delay = actual - expect "delay", (int)(timestamp - (time_cleanup - time_first_packet)), //#8 + "publish_kbps", (int)((time_duration <= 0)? 0:(bytes_nsend * 8 / time_duration)), //#9 + "play_kbps", (int)((time_duration <= 0)? 0:(bytes_nrecv * 8 / time_duration)), //#10 // unit in ms. "\"unit\": \"ms\"", "\"remark0\": \"total = dns + tcp_connect + start_play + first_packet + last_packet\"", diff --git a/trunk/src/libs/srs_librtmp.cpp b/trunk/src/libs/srs_librtmp.cpp index d362b54c0..6dedcfb4d 100644 --- a/trunk/src/libs/srs_librtmp.cpp +++ b/trunk/src/libs/srs_librtmp.cpp @@ -451,6 +451,20 @@ int64_t srs_get_time_ms() return srs_get_system_time_ms(); } +int64_t srs_get_nsend_bytes(srs_rtmp_t rtmp) +{ + srs_assert(rtmp != NULL); + Context* context = (Context*)rtmp; + return context->rtmp->get_send_bytes(); +} + +int64_t srs_get_nrecv_bytes(srs_rtmp_t rtmp) +{ + srs_assert(rtmp != NULL); + Context* context = (Context*)rtmp; + return context->rtmp->get_recv_bytes(); +} + struct FlvContext { SrsFileStream fs; diff --git a/trunk/src/libs/srs_librtmp.hpp b/trunk/src/libs/srs_librtmp.hpp index c104852eb..d5bf52f98 100644 --- a/trunk/src/libs/srs_librtmp.hpp +++ b/trunk/src/libs/srs_librtmp.hpp @@ -157,6 +157,8 @@ int srs_version_revision(); * utilities */ int64_t srs_get_time_ms(); +int64_t srs_get_nsend_bytes(srs_rtmp_t rtmp); +int64_t srs_get_nrecv_bytes(srs_rtmp_t rtmp); /** * flv codec