Merge pull request #222 from narspt/patch-20

fix ambed openstream timeout issue
This commit is contained in:
LX3JL 2023-03-01 18:24:16 +01:00 committed by GitHub
commit 8428d1ef40
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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