fix openstream timeout issue

This commit is contained in:
narspt 2022-08-19 21:22:10 +01:00
parent adec5c8d14
commit 99530863d5
3 changed files with 19 additions and 1 deletions

View file

@ -32,6 +32,7 @@ CSemaphore::CSemaphore()
{
// Initialized as locked.
m_Count = 0;
m_WaitingCount = 0;
}
////////////////////////////////////////////////////////////////////////////////////////
@ -66,7 +67,21 @@ bool CSemaphore::WaitFor(uint ms)
{
m_Count--;
}
if ( m_WaitingCount > 0 )
{
m_WaitingCount--;
}
return ok;
}
void CSemaphore::PreWaitFor(void)
{
std::unique_lock<decltype(m_Mutex)> lock(m_Mutex);
// discard timedout notify(s) count
if ( m_Count > m_WaitingCount )
{
m_Count = m_WaitingCount;
}
// pre flag waiting notify
m_WaitingCount++;
}

View file

@ -43,12 +43,14 @@ public:
void Notify(void);
void Wait(void);
bool WaitFor(uint);
void PreWaitFor(void);
protected:
// data
std::mutex m_Mutex;
std::condition_variable m_Condition;
size_t m_Count;
size_t m_WaitingCount;
};

View file

@ -216,6 +216,7 @@ CCodecStream *CTranscoder::GetStream(CPacketStream *PacketStream, uint8 uiCodecI
{
// yes, post openstream request
EncodeOpenstreamPacket(&Buffer, uiCodecIn, (uiCodecIn == CODEC_AMBEPLUS) ? CODEC_AMBE2PLUS : CODEC_AMBEPLUS);
m_SemaphoreOpenStream.PreWaitFor(); // pre flag waiting notify and discard timedout notify(s) count
m_Socket.Send(Buffer, m_Ip, TRANSCODER_PORT);
// wait relpy here