RTSPServerThread: Convert to std::thread
parent
8f0431d85b
commit
c78e174e78
|
@ -157,9 +157,9 @@ int main(int argc, char *argv[]) {
|
|||
sigaddset(&block_set, SIGUSR1);
|
||||
sigaddset(&block_set, SIGUSR2);
|
||||
|
||||
RTSPServerThread * rtsp_server_thread = nullptr;
|
||||
std::unique_ptr<RTSPServerThread> rtsp_server_thread;
|
||||
if (config.min_rtsp_port) {
|
||||
rtsp_server_thread = new RTSPServerThread(config.min_rtsp_port);
|
||||
rtsp_server_thread = ZM::make_unique<RTSPServerThread>(config.min_rtsp_port);
|
||||
Debug(1, "Starting RTSP server because min_rtsp_port is set");
|
||||
} else {
|
||||
Debug(1, "Not starting RTSP server because min_rtsp_port not set");
|
||||
|
@ -168,8 +168,6 @@ int main(int argc, char *argv[]) {
|
|||
ServerMediaSession **sessions = new ServerMediaSession *[monitors.size()];
|
||||
for (size_t i = 0; i < monitors.size(); i++) sessions[i] = nullptr;
|
||||
|
||||
rtsp_server_thread->start();
|
||||
|
||||
while (!zm_terminate) {
|
||||
|
||||
for (size_t i = 0; i < monitors.size(); i++) {
|
||||
|
@ -226,11 +224,6 @@ int main(int argc, char *argv[]) {
|
|||
} // end if zm_reload
|
||||
} // end while ! zm_terminate
|
||||
|
||||
rtsp_server_thread->stop();
|
||||
rtsp_server_thread->join();
|
||||
delete rtsp_server_thread;
|
||||
rtsp_server_thread = nullptr;
|
||||
|
||||
delete[] sessions;
|
||||
sessions = nullptr;
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
#include <StreamReplicator.hh>
|
||||
|
||||
RTSPServerThread::RTSPServerThread(int port) :
|
||||
terminate(0)
|
||||
terminate_(false), scheduler_watch_var_(0)
|
||||
{
|
||||
//unsigned short rtsp_over_http_port = 0;
|
||||
//const char *realm = "ZoneMinder";
|
||||
|
@ -34,9 +34,15 @@ RTSPServerThread::RTSPServerThread(int port) :
|
|||
}
|
||||
const char *prefix = rtspServer->rtspURLPrefix();
|
||||
delete[] prefix;
|
||||
} // end RTSPServerThread::RTSPServerThread
|
||||
|
||||
thread_ = std::thread(&RTSPServerThread::Run, this);
|
||||
}
|
||||
|
||||
RTSPServerThread::~RTSPServerThread() {
|
||||
Stop();
|
||||
if (thread_.joinable())
|
||||
thread_.join();
|
||||
|
||||
if (rtspServer) {
|
||||
Medium::close(rtspServer);
|
||||
} // end if rtsp_server
|
||||
|
@ -49,25 +55,26 @@ RTSPServerThread::~RTSPServerThread() {
|
|||
delete scheduler;
|
||||
}
|
||||
|
||||
int RTSPServerThread::run() {
|
||||
Debug(1, "RTSPServerThread::run()");
|
||||
if ( rtspServer )
|
||||
env->taskScheduler().doEventLoop(&terminate); // does not return
|
||||
void RTSPServerThread::Run() {
|
||||
Debug(1, "RTSPServerThread::Run()");
|
||||
if (rtspServer)
|
||||
env->taskScheduler().doEventLoop(&scheduler_watch_var_); // does not return
|
||||
Debug(1, "RTSPServerThread::done()");
|
||||
return 0;
|
||||
} // end in RTSPServerThread::run()
|
||||
}
|
||||
|
||||
void RTSPServerThread::stop() {
|
||||
void RTSPServerThread::Stop() {
|
||||
Debug(1, "RTSPServerThread::stop()");
|
||||
terminate = 1;
|
||||
terminate_ = true;
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lck(scheduler_watch_var_mutex_);
|
||||
scheduler_watch_var_ = 1;
|
||||
}
|
||||
|
||||
for ( std::list<FramedSource *>::iterator it = sources.begin(); it != sources.end(); ++it ) {
|
||||
(*it)->stopGettingFrames();
|
||||
}
|
||||
} // end RTSPServerThread::stop()
|
||||
|
||||
bool RTSPServerThread::stopped() const {
|
||||
return terminate ? true : false;
|
||||
} // end RTSPServerThread::stopped()
|
||||
}
|
||||
|
||||
ServerMediaSession *RTSPServerThread::addSession(std::string &streamname) {
|
||||
ServerMediaSession *sms = ServerMediaSession::createNew(*env, streamname.c_str());
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include "zm_thread.h"
|
||||
#include "zm_rtsp_server_server_media_subsession.h"
|
||||
#include "zm_rtsp_server_fifo_source.h"
|
||||
#include <atomic>
|
||||
#include <list>
|
||||
#include <memory>
|
||||
|
||||
|
@ -15,10 +16,14 @@
|
|||
|
||||
class Monitor;
|
||||
|
||||
class RTSPServerThread : public Thread {
|
||||
class RTSPServerThread {
|
||||
private:
|
||||
std::shared_ptr<Monitor> monitor_;
|
||||
char terminate;
|
||||
|
||||
std::thread thread_;
|
||||
std::atomic<bool> terminate_;
|
||||
std::mutex scheduler_watch_var_mutex_;
|
||||
char scheduler_watch_var_;
|
||||
|
||||
TaskScheduler* scheduler;
|
||||
UsageEnvironment* env;
|
||||
|
@ -34,9 +39,9 @@ class RTSPServerThread : public Thread {
|
|||
void removeSession(ServerMediaSession *sms);
|
||||
void addStream(std::string &streamname, AVStream *, AVStream *);
|
||||
FramedSource *addFifo(ServerMediaSession *sms, std::string fifo);
|
||||
int run();
|
||||
void stop();
|
||||
bool stopped() const;
|
||||
void Run();
|
||||
void Stop();
|
||||
bool IsStopped() const { return terminate_; };
|
||||
private:
|
||||
const std::string getRtpFormat(AVCodecID codec, bool muxTS);
|
||||
int addSession(
|
||||
|
|
Loading…
Reference in New Issue