winlin

for bug#194, open pipe for each connection.

@@ -81,7 +81,7 @@ int SrsPipe::active() @@ -81,7 +81,7 @@ int SrsPipe::active()
81 int ret = ERROR_SUCCESS; 81 int ret = ERROR_SUCCESS;
82 82
83 int v = 0; 83 int v = 0;
84 - if (st_write(read_stfd, &v, sizeof(int), ST_UTIME_NO_TIMEOUT) != sizeof(int)) { 84 + if (st_write(write_stfd, &v, sizeof(int), ST_UTIME_NO_TIMEOUT) != sizeof(int)) {
85 ret = ERROR_SYSTEM_WRITE_PIPE; 85 ret = ERROR_SYSTEM_WRITE_PIPE;
86 srs_error("write pipe failed. ret=%d", ret); 86 srs_error("write pipe failed. ret=%d", ret);
87 return ret; 87 return ret;
@@ -516,7 +516,12 @@ int SrsRtmpConn::playing(SrsSource* source) @@ -516,7 +516,12 @@ int SrsRtmpConn::playing(SrsSource* source)
516 SrsAutoFree(SrsConsumer, consumer); 516 SrsAutoFree(SrsConsumer, consumer);
517 srs_verbose("consumer created success."); 517 srs_verbose("consumer created success.");
518 518
  519 + // TODO: FIXME: remove it.
519 rtmp->set_recv_timeout(SRS_CONSTS_RTMP_PULSE_TIMEOUT_US); 520 rtmp->set_recv_timeout(SRS_CONSTS_RTMP_PULSE_TIMEOUT_US);
  521 + // disable the timeout.
  522 + // TODO: FIXME: maybe can use larger timeout?
  523 + rtmp->set_recv_timeout(ST_UTIME_NO_TIMEOUT);
  524 + rtmp->set_send_timeout(ST_UTIME_NO_TIMEOUT);
520 525
521 SrsPithyPrint pithy_print(SRS_CONSTS_STAGE_PLAY_USER); 526 SrsPithyPrint pithy_print(SRS_CONSTS_STAGE_PLAY_USER);
522 527
@@ -525,12 +530,30 @@ int SrsRtmpConn::playing(SrsSource* source) @@ -525,12 +530,30 @@ int SrsRtmpConn::playing(SrsSource* source)
525 bool user_specified_duration_to_stop = (req->duration > 0); 530 bool user_specified_duration_to_stop = (req->duration > 0);
526 int64_t starttime = -1; 531 int64_t starttime = -1;
527 532
  533 + pollfd pds[2];
  534 + // poll the client incoming fd.
  535 + pds[0].fd = st_netfd_fileno(stfd);
  536 + pds[0].events = POLLIN;
  537 + // poll the consumer queue pipe.
  538 + pds[1].fd = st_netfd_fileno(consumer->pipe_fd());
  539 + pds[1].events = POLLIN;
  540 +
528 while (true) { 541 while (true) {
529 // collect elapse for pithy print. 542 // collect elapse for pithy print.
530 pithy_print.elapse(); 543 pithy_print.elapse();
531 544
  545 + pds[0].revents = 0;
  546 + pds[1].revents = 0;
  547 +
  548 + // wait for packet incoming or data outgoing.
  549 + if (st_poll(pds, 2, ST_UTIME_NO_TIMEOUT) <= 0) {
  550 + srs_error("st_poll failed.");
  551 + break;
  552 + }
  553 +
  554 + // packet incoming, read from RTMP.
532 // read from client. 555 // read from client.
533 - if (true) { 556 + if (pds[0].revents & POLLIN) {
534 SrsMessage* msg = NULL; 557 SrsMessage* msg = NULL;
535 ret = rtmp->recv_message(&msg); 558 ret = rtmp->recv_message(&msg);
536 srs_verbose("play loop recv message. ret=%d", ret); 559 srs_verbose("play loop recv message. ret=%d", ret);
@@ -553,6 +576,8 @@ int SrsRtmpConn::playing(SrsSource* source) @@ -553,6 +576,8 @@ int SrsRtmpConn::playing(SrsSource* source)
553 } 576 }
554 } 577 }
555 578
  579 + // data outgoing, sendout packets.
  580 + if (pds[1].revents & POLLIN) {
556 // get messages from consumer. 581 // get messages from consumer.
557 int count = 0; 582 int count = 0;
558 if ((ret = consumer->dump_packets(msgs.size, msgs.msgs, count)) != ERROR_SUCCESS) { 583 if ((ret = consumer->dump_packets(msgs.size, msgs.msgs, count)) != ERROR_SUCCESS) {
@@ -598,6 +623,7 @@ int SrsRtmpConn::playing(SrsSource* source) @@ -598,6 +623,7 @@ int SrsRtmpConn::playing(SrsSource* source)
598 return ret; 623 return ret;
599 } 624 }
600 } 625 }
  626 + }
601 627
602 // if duration specified, and exceed it, stop play live. 628 // if duration specified, and exceed it, stop play live.
603 // @see: https://github.com/winlinvip/simple-rtmp-server/issues/45 629 // @see: https://github.com/winlinvip/simple-rtmp-server/issues/45