1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

for bug #194, add fds poll, just sleep to send without recv.

This commit is contained in:
winlin 2014-11-11 18:35:46 +08:00
parent 133cc62b51
commit 164f632b62
4 changed files with 146 additions and 14 deletions

View file

@ -517,26 +517,31 @@ int SrsRtmpConn::playing(SrsSource* source)
SrsAutoFree(SrsConsumer, consumer);
srs_verbose("consumer created success.");
rtmp->set_recv_timeout(SRS_CONSTS_RTMP_PULSE_TIMEOUT_US);
SrsPithyPrint pithy_print(SRS_CONSTS_STAGE_PLAY_USER);
SrsSharedPtrMessageArray msgs(SYS_MAX_PLAY_SEND_MSGS);
bool user_specified_duration_to_stop = (req->duration > 0);
int64_t starttime = -1;
SrsPollFD poll;
if ((ret = poll.initialize(stfd)) != ERROR_SUCCESS) {
// use poll fd to manage the connection, read when active.
SrsPollFD poll_fd;
if ((ret = poll_fd.initialize(stfd)) != ERROR_SUCCESS) {
return ret;
}
// TODO: FIXME: remove following.
//rtmp->set_recv_timeout(SRS_CONSTS_RTMP_PULSE_TIMEOUT_US);
rtmp->set_recv_timeout(ST_UTIME_NO_TIMEOUT);
rtmp->set_send_timeout(ST_UTIME_NO_TIMEOUT);
// initialize other components
SrsPithyPrint pithy_print(SRS_CONSTS_STAGE_PLAY_USER);
SrsSharedPtrMessageArray msgs(SYS_MAX_PLAY_SEND_MSGS);
bool user_specified_duration_to_stop = (req->duration > 0);
int64_t starttime = -1;
while (true) {
// collect elapse for pithy print.
pithy_print.elapse();
// read from client.
if (true) {
if (poll_fd.active()) {
poll_fd.set_active(false);
SrsMessage* msg = NULL;
ret = rtmp->recv_message(&msg);
srs_verbose("play loop recv message. ret=%d", ret);
@ -565,6 +570,13 @@ int SrsRtmpConn::playing(SrsSource* source)
srs_error("get messages from consumer failed. ret=%d", ret);
return ret;
}
// no data, sleep a while.
// for the poll_fd maybe not active, and no message.
// @see: https://github.com/winlinvip/simple-rtmp-server/issues/194
if (count <= 0) {
st_usleep(SRS_CONSTS_RTMP_PULSE_TIMEOUT_US);
}
// reportable
if (pithy_print.can_print()) {