Skip to content

Commit

Permalink
Add a 20s timeout for handling network errors
Browse files Browse the repository at this point in the history
  • Loading branch information
clsid2 committed Apr 9, 2021
1 parent feb07eb commit ccaaa70
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
9 changes: 9 additions & 0 deletions demuxer/Demuxers/LAVFDemuxer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,11 @@ int CLAVFDemuxer::avio_interrupt_cb(void *opaque)
if (demux->m_timeOpening && now > (demux->m_timeOpening + AVFORMAT_OPEN_TIMEOUT))
return 1;

if (demux->m_timePacketRead && now > (demux->m_timePacketRead + AVFORMAT_OPEN_TIMEOUT)) {
DbgLog((LOG_ERROR, 0, TEXT("Timeout while reading packet")));
return 1;
}

if (demux->m_Abort && now > demux->m_timeAbort)
return 1;

Expand Down Expand Up @@ -1451,6 +1456,7 @@ STDMETHODIMP CLAVFDemuxer::GetNextPacket(Packet **ppPacket)
m_avFormat->pb->eof_reached = 0;
}

m_timePacketRead = time(nullptr);
int result = 0;
try
{
Expand All @@ -1460,10 +1466,12 @@ STDMETHODIMP CLAVFDemuxer::GetNextPacket(Packet **ppPacket)
{
// ignore..
}
m_timePacketRead = 0;

if (result == AVERROR(EINTR) || result == AVERROR(EAGAIN))
{
// timeout, probably no real error, return empty packet
DbgLog((LOG_TRACE, 10, L"::GetNextPacket(): Timeout"));
bReturnEmpty = true;
}
else if (result == AVERROR_EOF)
Expand All @@ -1472,6 +1480,7 @@ STDMETHODIMP CLAVFDemuxer::GetNextPacket(Packet **ppPacket)
}
else if (result < 0)
{
DbgLog((LOG_TRACE, 10, L"::GetNextPacket(): Fail, result = %d"), result);
// meh, fail
}
else if (pkt.size <= 0 || pkt.stream_index < 0 || (unsigned)pkt.stream_index >= m_avFormat->nb_streams)
Expand Down
2 changes: 2 additions & 0 deletions demuxer/Demuxers/LAVFDemuxer.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,4 +237,6 @@ class CLAVFDemuxer
int m_Abort = 0;
time_t m_timeAbort = 0;
time_t m_timeOpening = 0;
time_t m_timePacketRead = 0;

};

0 comments on commit ccaaa70

Please sign in to comment.