fix bug #47: use stream time to stop for duration of rtmpdump
正在显示
3 个修改的文件
包含
25 行增加
和
12 行删除
| @@ -72,6 +72,7 @@ SrsRtmpConn::SrsRtmpConn(SrsServer* srs_server, st_netfd_t client_stfd) | @@ -72,6 +72,7 @@ SrsRtmpConn::SrsRtmpConn(SrsServer* srs_server, st_netfd_t client_stfd) | ||
| 72 | http_hooks = new SrsHttpHooks(); | 72 | http_hooks = new SrsHttpHooks(); |
| 73 | #endif | 73 | #endif |
| 74 | bandwidth = new SrsBandwidth(); | 74 | bandwidth = new SrsBandwidth(); |
| 75 | + duration = 0; | ||
| 75 | 76 | ||
| 76 | _srs_config->subscribe(this); | 77 | _srs_config->subscribe(this); |
| 77 | } | 78 | } |
| @@ -414,18 +415,10 @@ int SrsRtmpConn::playing(SrsSource* source) | @@ -414,18 +415,10 @@ int SrsRtmpConn::playing(SrsSource* source) | ||
| 414 | 415 | ||
| 415 | SrsPithyPrint pithy_print(SRS_STAGE_PLAY_USER); | 416 | SrsPithyPrint pithy_print(SRS_STAGE_PLAY_USER); |
| 416 | 417 | ||
| 418 | + int64_t starttime = -1; | ||
| 417 | while (true) { | 419 | while (true) { |
| 418 | pithy_print.elapse(SRS_PULSE_TIMEOUT_US / 1000); | 420 | pithy_print.elapse(SRS_PULSE_TIMEOUT_US / 1000); |
| 419 | 421 | ||
| 420 | - // if duration specified, and exceed it, stop play live. | ||
| 421 | - // @see: https://github.com/winlinvip/simple-rtmp-server/issues/45 | ||
| 422 | - // TODO: maybe the duration should use the stream duration. | ||
| 423 | - if (req->duration > 0 && pithy_print.get_age() >= (int64_t)req->duration) { | ||
| 424 | - ret = ERROR_RTMP_DURATION_EXCEED; | ||
| 425 | - srs_trace("stop live for duration exceed. ret=%d", ret); | ||
| 426 | - return ret; | ||
| 427 | - } | ||
| 428 | - | ||
| 429 | // switch to other st-threads. | 422 | // switch to other st-threads. |
| 430 | st_usleep(0); | 423 | st_usleep(0); |
| 431 | 424 | ||
| @@ -460,8 +453,8 @@ int SrsRtmpConn::playing(SrsSource* source) | @@ -460,8 +453,8 @@ int SrsRtmpConn::playing(SrsSource* source) | ||
| 460 | 453 | ||
| 461 | // reportable | 454 | // reportable |
| 462 | if (pithy_print.can_print()) { | 455 | if (pithy_print.can_print()) { |
| 463 | - srs_trace("-> time=%"PRId64", cmr=%d, msgs=%d, obytes=%"PRId64", ibytes=%"PRId64", okbps=%d, ikbps=%d", | ||
| 464 | - pithy_print.get_age(), ctl_msg_ret, count, rtmp->get_send_bytes(), rtmp->get_recv_bytes(), rtmp->get_send_kbps(), rtmp->get_recv_kbps()); | 456 | + srs_trace("-> time=%"PRId64", duration=%"PRId64", cmr=%d, msgs=%d, obytes=%"PRId64", ibytes=%"PRId64", okbps=%d, ikbps=%d", |
| 457 | + 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()); | ||
| 465 | } | 458 | } |
| 466 | 459 | ||
| 467 | if (count <= 0) { | 460 | if (count <= 0) { |
| @@ -482,6 +475,22 @@ int SrsRtmpConn::playing(SrsSource* source) | @@ -482,6 +475,22 @@ int SrsRtmpConn::playing(SrsSource* source) | ||
| 482 | srs_error("send message to client failed. ret=%d", ret); | 475 | srs_error("send message to client failed. ret=%d", ret); |
| 483 | return ret; | 476 | return ret; |
| 484 | } | 477 | } |
| 478 | + | ||
| 479 | + // foreach msg, collect the duration. | ||
| 480 | + if (starttime < 0 || starttime > msg->header.timestamp) { | ||
| 481 | + starttime = msg->header.timestamp; | ||
| 482 | + } | ||
| 483 | + duration += msg->header.timestamp - starttime; | ||
| 484 | + starttime = msg->header.timestamp; | ||
| 485 | + } | ||
| 486 | + | ||
| 487 | + // if duration specified, and exceed it, stop play live. | ||
| 488 | + // @see: https://github.com/winlinvip/simple-rtmp-server/issues/45 | ||
| 489 | + // TODO: maybe the duration should use the stream duration. | ||
| 490 | + if (req->duration > 0 && duration >= (int64_t)req->duration) { | ||
| 491 | + ret = ERROR_RTMP_DURATION_EXCEED; | ||
| 492 | + srs_trace("stop live for duration exceed. ret=%d", ret); | ||
| 493 | + return ret; | ||
| 485 | } | 494 | } |
| 486 | } | 495 | } |
| 487 | 496 |
| @@ -62,6 +62,10 @@ private: | @@ -62,6 +62,10 @@ private: | ||
| 62 | SrsHttpHooks* http_hooks; | 62 | SrsHttpHooks* http_hooks; |
| 63 | #endif | 63 | #endif |
| 64 | SrsBandwidth* bandwidth; | 64 | SrsBandwidth* bandwidth; |
| 65 | + // elapse duration in ms | ||
| 66 | + // for live play duration, for instance, rtmpdump to record. | ||
| 67 | + // @see https://github.com/winlinvip/simple-rtmp-server/issues/47 | ||
| 68 | + int64_t duration; | ||
| 65 | public: | 69 | public: |
| 66 | SrsRtmpConn(SrsServer* srs_server, st_netfd_t client_stfd); | 70 | SrsRtmpConn(SrsServer* srs_server, st_netfd_t client_stfd); |
| 67 | virtual ~SrsRtmpConn(); | 71 | virtual ~SrsRtmpConn(); |
| @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 31 | // current release version | 31 | // current release version |
| 32 | #define VERSION_MAJOR "0" | 32 | #define VERSION_MAJOR "0" |
| 33 | #define VERSION_MINOR "9" | 33 | #define VERSION_MINOR "9" |
| 34 | -#define VERSION_REVISION "63" | 34 | +#define VERSION_REVISION "64" |
| 35 | #define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION | 35 | #define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION |
| 36 | // server info. | 36 | // server info. |
| 37 | #define RTMP_SIG_SRS_KEY "srs" | 37 | #define RTMP_SIG_SRS_KEY "srs" |
-
请 注册 或 登录 后发表评论