From 555492282098c2ed7d66df5c6817123e9b43cb28 Mon Sep 17 00:00:00 2001 From: winlin Date: Sat, 8 Nov 2014 14:06:40 +0800 Subject: [PATCH] refine librtmp tools, use srs_trace macro instead printf. --- trunk/research/librtmp/srs_bandwidth_check.c | 35 ++++++++++---------- trunk/research/librtmp/srs_detect_rtmp.c | 2 +- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/trunk/research/librtmp/srs_bandwidth_check.c b/trunk/research/librtmp/srs_bandwidth_check.c index 4c9cf5afe..7b863eb76 100644 --- a/trunk/research/librtmp/srs_bandwidth_check.c +++ b/trunk/research/librtmp/srs_bandwidth_check.c @@ -62,6 +62,10 @@ int main(int argc, char** argv) srs_primary_authors[0] = 0; srs_version[0] = 0; + printf("RTMP bandwidth check/test with server.\n"); + printf("srs(simple-rtmp-server) client librtmp library.\n"); + printf("version: %d.%d.%d\n", srs_version_major(), srs_version_minor(), srs_version_revision()); + if (argc <= 1) { printf("RTMP bandwidth check/test with server.\n" "Usage: %s \n" @@ -71,45 +75,40 @@ int main(int argc, char** argv) " %s rtmp://127.0.0.1:1935/app?key=35c9b402c12a7246868752e2878f7e0e,vhost=bandcheck.srs.com>/dev/null\n" "@remark, output text to stdout, while json to stderr.\n", argv[0], argv[0], argv[0]); - ret = 1; - exit(ret); - return ret; + exit(-1); } rtmp = srs_rtmp_create2(argv[1]); - printf("RTMP bandwidth check/test with server.\n"); - printf("srs(simple-rtmp-server) client librtmp library.\n"); - printf("version: %d.%d.%d\n", srs_version_major(), srs_version_minor(), srs_version_revision()); - printf("bandwidth check/test url: %s\n", argv[1]); + srs_trace("bandwidth check/test url: %s", argv[1]); if ((ret = srs_simple_handshake(rtmp)) != 0) { - printf("simple handshake failed.\n"); + srs_trace("simple handshake failed."); goto rtmp_destroy; } - printf("simple handshake success\n"); + srs_trace("simple handshake success"); if ((ret = srs_connect_app2(rtmp, srs_server_ip, srs_server, srs_primary_authors, srs_version, &srs_id, &srs_pid)) != 0) { - printf("connect vhost/app failed.\n"); + srs_trace("connect vhost/app failed."); goto rtmp_destroy; } - printf("connect vhost/app success\n"); + srs_trace("connect vhost/app success"); if ((ret = srs_bandwidth_check(rtmp, &start_time, &end_time, &play_kbps, &publish_kbps, &play_bytes, &publish_bytes, &play_duration, &publish_duration)) != 0 ) { - printf("bandwidth check/test failed.\n"); + srs_trace("bandwidth check/test failed."); goto rtmp_destroy; } - printf("bandwidth check/test success\n"); + srs_trace("bandwidth check/test success"); - printf("\n%s, %s\n" + srs_trace("\n%s, %s\n" "%s, %s, srs_pid=%d, srs_id=%d\n" "duration: %dms(%d+%d)\n" "play: %dkbps\n" - "publish: %dkbps\n\n", + "publish: %dkbps", (char*)srs_server, (char*)srs_primary_authors, (char*)srs_server_ip, (char*)srs_version, srs_pid, srs_id, (int)(end_time - start_time), play_duration, publish_duration, @@ -119,8 +118,6 @@ int main(int argc, char** argv) rtmp_destroy: srs_rtmp_destroy(rtmp); - printf("terminate with ret=%d\n\n", ret); - fprintf(stderr, "{\"code\":%d," "\"srs_server\":\"%s\", " "\"srs_primary_authors\":\"%s\", " @@ -138,5 +135,9 @@ rtmp_destroy: (char*)srs_server_ip, (char*)srs_version, srs_pid, srs_id, (int)(end_time - start_time), play_duration, publish_duration, play_kbps, publish_kbps); + + srs_trace(""); + srs_trace("completed"); + return ret; } diff --git a/trunk/research/librtmp/srs_detect_rtmp.c b/trunk/research/librtmp/srs_detect_rtmp.c index cfe235a31..13a2d6818 100644 --- a/trunk/research/librtmp/srs_detect_rtmp.c +++ b/trunk/research/librtmp/srs_detect_rtmp.c @@ -84,7 +84,7 @@ int main(int argc, char** argv) if (duration <= 0 || timeout <= 0) { srs_trace("duration and timeout must be positive."); - exit(-1); + exit(-2); } rtmp = srs_rtmp_create(rtmp_url);