From 2c6b6c6846243de9c2e9f73c518f4ff8b558d6c4 Mon Sep 17 00:00:00 2001 From: winlin Date: Mon, 14 Apr 2014 10:51:31 +0800 Subject: [PATCH] fix bug #47: use stream time to stop for duration of rtmpdump --- trunk/src/app/srs_app_rtmp_conn.cpp | 31 +++++++++++++++++++---------- trunk/src/app/srs_app_rtmp_conn.hpp | 4 ++++ trunk/src/core/srs_core.hpp | 2 +- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/trunk/src/app/srs_app_rtmp_conn.cpp b/trunk/src/app/srs_app_rtmp_conn.cpp index 40daa0b43..0b3674615 100644 --- a/trunk/src/app/srs_app_rtmp_conn.cpp +++ b/trunk/src/app/srs_app_rtmp_conn.cpp @@ -72,6 +72,7 @@ SrsRtmpConn::SrsRtmpConn(SrsServer* srs_server, st_netfd_t client_stfd) http_hooks = new SrsHttpHooks(); #endif bandwidth = new SrsBandwidth(); + duration = 0; _srs_config->subscribe(this); } @@ -414,18 +415,10 @@ int SrsRtmpConn::playing(SrsSource* source) SrsPithyPrint pithy_print(SRS_STAGE_PLAY_USER); + int64_t starttime = -1; while (true) { pithy_print.elapse(SRS_PULSE_TIMEOUT_US / 1000); - // if duration specified, and exceed it, stop play live. - // @see: https://github.com/winlinvip/simple-rtmp-server/issues/45 - // TODO: maybe the duration should use the stream duration. - if (req->duration > 0 && pithy_print.get_age() >= (int64_t)req->duration) { - ret = ERROR_RTMP_DURATION_EXCEED; - srs_trace("stop live for duration exceed. ret=%d", ret); - return ret; - } - // switch to other st-threads. st_usleep(0); @@ -460,8 +453,8 @@ int SrsRtmpConn::playing(SrsSource* source) // reportable if (pithy_print.can_print()) { - srs_trace("-> time=%"PRId64", cmr=%d, msgs=%d, obytes=%"PRId64", ibytes=%"PRId64", okbps=%d, ikbps=%d", - pithy_print.get_age(), ctl_msg_ret, count, rtmp->get_send_bytes(), rtmp->get_recv_bytes(), rtmp->get_send_kbps(), rtmp->get_recv_kbps()); + srs_trace("-> time=%"PRId64", duration=%"PRId64", cmr=%d, msgs=%d, obytes=%"PRId64", ibytes=%"PRId64", okbps=%d, ikbps=%d", + pithy_print.get_age(), duration, ctl_msg_ret, count, rtmp->get_send_bytes(), rtmp->get_recv_bytes(), rtmp->get_send_kbps(), rtmp->get_recv_kbps()); } if (count <= 0) { @@ -482,6 +475,22 @@ int SrsRtmpConn::playing(SrsSource* source) srs_error("send message to client failed. ret=%d", ret); return ret; } + + // foreach msg, collect the duration. + if (starttime < 0 || starttime > msg->header.timestamp) { + starttime = msg->header.timestamp; + } + duration += msg->header.timestamp - starttime; + starttime = msg->header.timestamp; + } + + // if duration specified, and exceed it, stop play live. + // @see: https://github.com/winlinvip/simple-rtmp-server/issues/45 + // TODO: maybe the duration should use the stream duration. + if (req->duration > 0 && duration >= (int64_t)req->duration) { + ret = ERROR_RTMP_DURATION_EXCEED; + srs_trace("stop live for duration exceed. ret=%d", ret); + return ret; } } diff --git a/trunk/src/app/srs_app_rtmp_conn.hpp b/trunk/src/app/srs_app_rtmp_conn.hpp index 9285dec78..8c4ba9293 100644 --- a/trunk/src/app/srs_app_rtmp_conn.hpp +++ b/trunk/src/app/srs_app_rtmp_conn.hpp @@ -62,6 +62,10 @@ private: SrsHttpHooks* http_hooks; #endif SrsBandwidth* bandwidth; + // elapse duration in ms + // for live play duration, for instance, rtmpdump to record. + // @see https://github.com/winlinvip/simple-rtmp-server/issues/47 + int64_t duration; public: SrsRtmpConn(SrsServer* srs_server, st_netfd_t client_stfd); virtual ~SrsRtmpConn(); diff --git a/trunk/src/core/srs_core.hpp b/trunk/src/core/srs_core.hpp index f4cf3e0d6..05fbe5777 100644 --- a/trunk/src/core/srs_core.hpp +++ b/trunk/src/core/srs_core.hpp @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // current release version #define VERSION_MAJOR "0" #define VERSION_MINOR "9" -#define VERSION_REVISION "63" +#define VERSION_REVISION "64" #define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION // server info. #define RTMP_SIG_SRS_KEY "srs"