Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workaround for file://con use of stdin on Windows #651

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions apps/srt-live-transmit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,13 @@ int main(int argc, char** argv)
size_t lastReportedtLostBytes = 0;
std::time_t writeErrorLogTimer(std::time(nullptr));

UriParser::Type srcUriType = UriParser::Type::UNKNOWN;
bool srcReadMore = false;

#ifdef _WIN32
HANDLE hStdIn = INVALID_HANDLE_VALUE;
#endif

try {
// Now loop until broken
while (!int_state && !timer_state)
Expand All @@ -463,7 +470,8 @@ int main(int argc, char** argv)
return 1;
}
int events = SRT_EPOLL_IN | SRT_EPOLL_ERR;
switch (src->uri.type())
srcUriType = src->uri.type();
switch (srcUriType)
{
case UriParser::SRT:
if (srt_epoll_add_usock(pollid,
Expand All @@ -484,6 +492,9 @@ int main(int argc, char** argv)
}
break;
case UriParser::FILE:
#ifdef _WIN32
hStdIn = ::GetStdHandle(STD_INPUT_HANDLE);
#endif
if (srt_epoll_add_ssock(pollid,
src->GetSysSocket(), &events))
{
Expand Down Expand Up @@ -531,15 +542,28 @@ int main(int argc, char** argv)
lastReportedtLostBytes = 0;
}

#ifdef _WIN32
// Workaround Issue #646:
// On unix (POSIX), stdin is a valid FD with value 0. But not on Windows. This means that the first time epoll
// hits on Windows is when the connection is done for SRT target. After that you will not receive any other events
// from the poll. Furthermore, if you have connected and there is nothing in the stdin buffer waiting to be read, you
// will not read anything at all, because the polling event will never happen
srcReadMore = false;
if (srcUriType == UriParser::Type::FILE && tarConnected && ::WaitForSingleObject(hStdIn, 0) == WAIT_OBJECT_0)
{
srcReadMore = true;
}
#endif

int srtrfdslen = 2;
int srtwfdslen = 2;
SRTSOCKET srtrwfds[4] = {SRT_INVALID_SOCK, SRT_INVALID_SOCK , SRT_INVALID_SOCK , SRT_INVALID_SOCK };
int sysrfdslen = 2;
SYSSOCKET sysrfds[2];
if (srt_epoll_wait(pollid,
&srtrwfds[0], &srtrfdslen, &srtrwfds[2], &srtwfdslen,
100,
&sysrfds[0], &sysrfdslen, 0, 0) >= 0)
(srcReadMore ? 0 : 100),
&sysrfds[0], &sysrfdslen, 0, 0) >= 0 || srcReadMore)
{
bool doabort = false;
for (size_t i = 0; i < sizeof(srtrwfds) / sizeof(SRTSOCKET); i++)
Expand Down