diff --git a/README.md b/README.md
index 468c16d30..e869eca1f 100755
--- a/README.md
+++ b/README.md
@@ -46,6 +46,7 @@ url: rtmp://127.0.0.1:1935/live/livestream
* nginx v1.5.0: 139524 lines
### History
+* v0.3, 2013-10-29, support pithy print log message specified by stage.
* v0.3, 2013-10-28, support librtmp without extended-timestamp in 0xCX chunk packet.
* v0.3, 2013-10-27, support cache last gop for client fast startup.
* v0.2, 2013-10-25, v0.2 released. 10125 lines.
diff --git a/trunk/configure b/trunk/configure
index 19dcca9fa..85f5e9123 100755
--- a/trunk/configure
+++ b/trunk/configure
@@ -87,7 +87,7 @@ MODULE_FILES=("srs_core" "srs_core_log" "srs_core_server"
"srs_core_rtmp" "srs_core_socket" "srs_core_buffer"
"srs_core_auto_free" "srs_core_protocol" "srs_core_amf0"
"srs_core_stream" "srs_core_source" "srs_core_codec"
- "srs_core_complex_handshake")
+ "srs_core_complex_handshake" "srs_core_pithy_print")
MODULE_DIR="src/core" . auto/modules.sh
CORE_OBJS="${MODULE_OBJS[@]}"
diff --git a/trunk/src/core/srs_core.cpp b/trunk/src/core/srs_core.cpp
index 97b09bac2..e73c19b71 100755
--- a/trunk/src/core/srs_core.cpp
+++ b/trunk/src/core/srs_core.cpp
@@ -22,3 +22,24 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include
+
+#include
+
+static int64_t _srs_system_time_us_cache = 0;
+
+int64_t srs_get_system_time_ms()
+{
+ return _srs_system_time_us_cache / 1000;
+}
+
+void srs_update_system_time_ms()
+{
+ timeval now;
+
+ gettimeofday(&now, NULL);
+
+ // we must convert the tv_sec/tv_usec to int64_t.
+ _srs_system_time_us_cache = now.tv_sec * 1000 * 1000 + now.tv_usec;
+
+ _srs_system_time_us_cache = srs_max(0, _srs_system_time_us_cache);
+}
diff --git a/trunk/src/core/srs_core.hpp b/trunk/src/core/srs_core.hpp
index af05a23ff..d3ddd53a7 100755
--- a/trunk/src/core/srs_core.hpp
+++ b/trunk/src/core/srs_core.hpp
@@ -79,4 +79,9 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#define srs_min(a, b) ((a < b)? a : b)
#define srs_max(a, b) ((a < b)? b : a)
+// get current system time in ms, use cache to avoid performance problem
+extern int64_t srs_get_system_time_ms();
+// the deamon st-thread will update it.
+extern void srs_update_system_time_ms();
+
#endif
\ No newline at end of file
diff --git a/trunk/src/core/srs_core_client.cpp b/trunk/src/core/srs_core_client.cpp
index 1c64d04e9..3bdca698d 100755
--- a/trunk/src/core/srs_core_client.cpp
+++ b/trunk/src/core/srs_core_client.cpp
@@ -32,9 +32,11 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include
#include
#include
+#include
#define SRS_PULSE_TIMEOUT_MS 100
#define SRS_SEND_TIMEOUT_MS 5000
+#define SRS_RECV_TIMEOUT_MS SRS_SEND_TIMEOUT_MS
SrsClient::SrsClient(SrsServer* srs_server, st_netfd_t client_stfd)
: SrsConnection(srs_server, client_stfd)
@@ -61,9 +63,10 @@ int SrsClient::do_cycle()
srs_error("get peer ip failed. ret=%d", ret);
return ret;
}
- srs_verbose("get peer ip success. ip=%s", ip);
+ srs_trace("get peer ip success. ip=%s, send_to=%d, recv_to=%d",
+ ip, SRS_SEND_TIMEOUT_MS, SRS_RECV_TIMEOUT_MS);
- rtmp->set_recv_timeout(SRS_SEND_TIMEOUT_MS * 1000);
+ rtmp->set_recv_timeout(SRS_RECV_TIMEOUT_MS * 1000);
rtmp->set_send_timeout(SRS_SEND_TIMEOUT_MS * 1000);
if ((ret = rtmp->handshake()) != ERROR_SUCCESS) {
@@ -135,7 +138,7 @@ int SrsClient::do_cycle()
return ret;
}
srs_info("start to play stream %s success", req->stream.c_str());
- return streaming_play(source);
+ return playing(source);
}
case SrsClientFMLEPublish: {
srs_verbose("FMLE start to publish stream %s.", req->stream.c_str());
@@ -145,7 +148,7 @@ int SrsClient::do_cycle()
return ret;
}
srs_info("start to publish stream %s success", req->stream.c_str());
- ret = streaming_publish(source, true);
+ ret = publish(source, true);
source->on_unpublish();
return ret;
}
@@ -157,7 +160,7 @@ int SrsClient::do_cycle()
return ret;
}
srs_info("flash start to publish stream %s success", req->stream.c_str());
- ret = streaming_publish(source, false);
+ ret = publish(source, false);
source->on_unpublish();
return ret;
}
@@ -171,7 +174,7 @@ int SrsClient::do_cycle()
return ret;
}
-int SrsClient::streaming_play(SrsSource* source)
+int SrsClient::playing(SrsSource* source)
{
int ret = ERROR_SUCCESS;
@@ -187,11 +190,10 @@ int SrsClient::streaming_play(SrsSource* source)
rtmp->set_recv_timeout(SRS_PULSE_TIMEOUT_MS * 1000);
- int64_t report_time = 0;
- int64_t reported_time = 0;
+ SrsPithyPrint pithy_print(SRS_STAGE_PLAY_USER);
while (true) {
- report_time += SRS_PULSE_TIMEOUT_MS;
+ pithy_print.elapse(SRS_PULSE_TIMEOUT_MS);
// switch to other st-threads.
st_usleep(0);
@@ -223,8 +225,9 @@ int SrsClient::streaming_play(SrsSource* source)
}
// reportable
- if (server->can_report(reported_time, report_time)) {
- srs_trace("play report, time=%"PRId64", ctl_msg_ret=%d, msgs=%d", report_time, ctl_msg_ret, count);
+ if (pithy_print.can_print()) {
+ srs_trace("-> clock=%u, time=%"PRId64", cmr=%d, msgs=%d, obytes=%"PRId64", ibytes=%"PRId64", okbps=%d, ikbps=%d",
+ (int)srs_get_system_time_ms(), pithy_print.get_age(), ctl_msg_ret, count, rtmp->get_send_bytes(), rtmp->get_recv_bytes(), rtmp->get_send_kbps(), rtmp->get_recv_kbps());
}
if (count <= 0) {
@@ -251,10 +254,12 @@ int SrsClient::streaming_play(SrsSource* source)
return ret;
}
-int SrsClient::streaming_publish(SrsSource* source, bool is_fmle)
+int SrsClient::publish(SrsSource* source, bool is_fmle)
{
int ret = ERROR_SUCCESS;
+ SrsPithyPrint pithy_print(SRS_STAGE_PUBLISH_USER);
+
while (true) {
// switch to other st-threads.
st_usleep(0);
@@ -267,6 +272,14 @@ int SrsClient::streaming_publish(SrsSource* source, bool is_fmle)
SrsAutoFree(SrsCommonMessage, msg, false);
+ pithy_print.set_age(msg->header.timestamp);
+
+ // reportable
+ if (pithy_print.can_print()) {
+ srs_trace("<- clock=%u, time=%"PRId64", obytes=%"PRId64", ibytes=%"PRId64", okbps=%d, ikbps=%d",
+ (int)srs_get_system_time_ms(), pithy_print.get_age(), rtmp->get_send_bytes(), rtmp->get_recv_bytes(), rtmp->get_send_kbps(), rtmp->get_recv_kbps());
+ }
+
// process audio packet
if (msg->header.is_audio() && ((ret = source->on_audio(msg)) != ERROR_SUCCESS)) {
srs_error("process audio message failed. ret=%d", ret);
@@ -357,7 +370,7 @@ int SrsClient::get_peer_ip()
ip = new char[strlen(buf) + 1];
strcpy(ip, buf);
- srs_trace("get peer ip success. ip=%s, fd=%d", ip, fd);
+ srs_verbose("get peer ip success. ip=%s, fd=%d", ip, fd);
return ret;
}
diff --git a/trunk/src/core/srs_core_client.hpp b/trunk/src/core/srs_core_client.hpp
index cc2cad914..763d3ecec 100755
--- a/trunk/src/core/srs_core_client.hpp
+++ b/trunk/src/core/srs_core_client.hpp
@@ -53,8 +53,8 @@ public:
protected:
virtual int do_cycle();
private:
- virtual int streaming_play(SrsSource* source);
- virtual int streaming_publish(SrsSource* source, bool is_fmle);
+ virtual int playing(SrsSource* source);
+ virtual int publish(SrsSource* source, bool is_fmle);
virtual int get_peer_ip();
};
diff --git a/trunk/src/core/srs_core_pithy_print.cpp b/trunk/src/core/srs_core_pithy_print.cpp
new file mode 100755
index 000000000..e2917fb0a
--- /dev/null
+++ b/trunk/src/core/srs_core_pithy_print.cpp
@@ -0,0 +1,133 @@
+/*
+The MIT License (MIT)
+
+Copyright (c) 2013 winlin
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+the Software, and to permit persons to whom the Software is furnished to do so,
+subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+*/
+
+#include
+
+#include