mirror of
https://github.com/LX3JL/xlxd.git
synced 2025-12-06 07:42:01 +01:00
fix openstream timeout issue
This commit is contained in:
parent
adec5c8d14
commit
99530863d5
|
|
@ -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++;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue