RtpCtrlThread: Convert to std::thread
This commit is contained in:
parent
ff2bfb58da
commit
71edb9d830
|
@ -25,9 +25,16 @@
|
|||
|
||||
#if HAVE_LIBAVFORMAT
|
||||
|
||||
RtpCtrlThread::RtpCtrlThread( RtspThread &rtspThread, RtpSource &rtpSource )
|
||||
: mRtspThread( rtspThread ), mRtpSource( rtpSource ), mStop( false )
|
||||
RtpCtrlThread::RtpCtrlThread(RtspThread &rtspThread, RtpSource &rtpSource)
|
||||
: mRtspThread(rtspThread), mRtpSource(rtpSource), mTerminate(false)
|
||||
{
|
||||
mThread = std::thread(&RtpCtrlThread::Run, this);
|
||||
}
|
||||
|
||||
RtpCtrlThread::~RtpCtrlThread() {
|
||||
Stop();
|
||||
if (mThread.joinable())
|
||||
mThread.join();
|
||||
}
|
||||
|
||||
int RtpCtrlThread::recvPacket( const unsigned char *packet, ssize_t packetLen ) {
|
||||
|
@ -121,7 +128,7 @@ int RtpCtrlThread::recvPacket( const unsigned char *packet, ssize_t packetLen )
|
|||
}
|
||||
case RTCP_BYE :
|
||||
Debug(5, "RTCP Got BYE");
|
||||
mStop = true;
|
||||
Stop();
|
||||
break;
|
||||
case RTCP_APP :
|
||||
// Ignoring as per RFC 3550
|
||||
|
@ -241,7 +248,7 @@ int RtpCtrlThread::recvPackets( unsigned char *buffer, ssize_t nBytes ) {
|
|||
return nBytes;
|
||||
}
|
||||
|
||||
int RtpCtrlThread::run() {
|
||||
void RtpCtrlThread::Run() {
|
||||
Debug( 2, "Starting control thread %x on port %d", mRtpSource.getSsrc(), mRtpSource.getLocalCtrlPort() );
|
||||
ZM::SockAddrInet localAddr, remoteAddr;
|
||||
|
||||
|
@ -272,8 +279,7 @@ int RtpCtrlThread::run() {
|
|||
time_t last_receive = time(nullptr);
|
||||
bool timeout = false; // used as a flag that we had a timeout, and then sent an RR to see if we wake back up. Real timeout will happen when this is true.
|
||||
|
||||
while ( !mStop && select.wait() >= 0 ) {
|
||||
|
||||
while (!mTerminate && select.wait() >= 0) {
|
||||
time_t now = time(nullptr);
|
||||
ZM::Select::CommsList readable = select.getReadable();
|
||||
if ( readable.size() == 0 ) {
|
||||
|
@ -318,7 +324,7 @@ int RtpCtrlThread::run() {
|
|||
}
|
||||
} else {
|
||||
// Here is another case of not receiving some data causing us to terminate... why? Sometimes there are pauses in the interwebs.
|
||||
mStop = true;
|
||||
Stop();
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
|
@ -328,7 +334,6 @@ int RtpCtrlThread::run() {
|
|||
}
|
||||
rtpCtrlServer.close();
|
||||
mRtspThread.Stop();
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif // HAVE_LIBAVFORMAT
|
||||
|
|
|
@ -21,6 +21,8 @@
|
|||
#define ZM_RTP_CTRL_H
|
||||
|
||||
#include "zm_thread.h"
|
||||
#include <atomic>
|
||||
#include <thread>
|
||||
|
||||
// Defined in ffmpeg rtp.h
|
||||
//#define RTP_MAX_SDES 255 // maximum text length for SDES
|
||||
|
@ -32,7 +34,7 @@
|
|||
class RtspThread;
|
||||
class RtpSource;
|
||||
|
||||
class RtpCtrlThread : public Thread {
|
||||
class RtpCtrlThread {
|
||||
friend class RtspThread;
|
||||
|
||||
private:
|
||||
|
@ -121,7 +123,9 @@ private:
|
|||
RtspThread &mRtspThread;
|
||||
RtpSource &mRtpSource;
|
||||
int mPort;
|
||||
bool mStop;
|
||||
|
||||
std::atomic<bool> mTerminate;
|
||||
std::thread mThread;
|
||||
|
||||
private:
|
||||
int recvPacket( const unsigned char *packet, ssize_t packetLen );
|
||||
|
@ -129,14 +133,13 @@ private:
|
|||
int generateSdes( const unsigned char *packet, ssize_t packetLen );
|
||||
int generateBye( const unsigned char *packet, ssize_t packetLen );
|
||||
int recvPackets( unsigned char *buffer, ssize_t nBytes );
|
||||
int run();
|
||||
void Run();
|
||||
|
||||
public:
|
||||
RtpCtrlThread( RtspThread &rtspThread, RtpSource &rtpSource );
|
||||
~RtpCtrlThread();
|
||||
|
||||
void stop() {
|
||||
mStop = true;
|
||||
}
|
||||
void Stop() { mTerminate = true; }
|
||||
};
|
||||
|
||||
#endif // ZM_RTP_CTRL_H
|
||||
|
|
|
@ -587,7 +587,6 @@ void RtspThread::Run() {
|
|||
RtpCtrlThread rtpCtrlThread( *this, *source );
|
||||
|
||||
rtpDataThread.start();
|
||||
rtpCtrlThread.start();
|
||||
|
||||
while (!mTerminate) {
|
||||
now = time(nullptr);
|
||||
|
@ -616,7 +615,7 @@ void RtspThread::Run() {
|
|||
return;
|
||||
|
||||
rtpDataThread.stop();
|
||||
rtpCtrlThread.stop();
|
||||
rtpCtrlThread.Stop();
|
||||
|
||||
//rtpDataThread.kill( SIGTERM );
|
||||
//rtpCtrlThread.kill( SIGTERM );
|
||||
|
@ -749,7 +748,6 @@ Debug(5, "sendkeepalive %d, timeout %d, now: %d last: %d since: %d", sendKeepali
|
|||
RtpCtrlThread rtpCtrlThread( *this, *source );
|
||||
|
||||
rtpDataThread.start();
|
||||
rtpCtrlThread.start();
|
||||
|
||||
while (!mTerminate) {
|
||||
// Send a keepalive message if the server supports this feature and we are close to the timeout expiration
|
||||
|
@ -774,10 +772,9 @@ Debug(5, "sendkeepalive %d, timeout %d, now: %d last: %d since: %d", sendKeepali
|
|||
return;
|
||||
|
||||
rtpDataThread.stop();
|
||||
rtpCtrlThread.stop();
|
||||
rtpCtrlThread.Stop();
|
||||
|
||||
rtpDataThread.join();
|
||||
rtpCtrlThread.join();
|
||||
|
||||
delete mSources[ssrc];
|
||||
mSources.clear();
|
||||
|
|
Loading…
Reference in New Issue