Add RecorderMutex
This commit is contained in:
@@ -8,7 +8,8 @@
|
||||
namespace CameraRecorder {
|
||||
namespace Recorder {
|
||||
|
||||
RTSPRecorder::RTSPRecorder(Http::HttpClient* pHttpClient, const Settings& settings) :
|
||||
RTSPRecorder::RTSPRecorder(Http::HttpClient* pHttpClient, const Settings& settings, Util::RecorderMutexPointer pRecorderMutex) :
|
||||
Recorder(pRecorderMutex),
|
||||
m_pHttpClient(pHttpClient),
|
||||
m_settings(settings)
|
||||
{
|
||||
@@ -43,12 +44,20 @@ std::string RTSPRecorder::Snapshot(ctpl::thread_pool* pThreadPool, const std::st
|
||||
}
|
||||
}
|
||||
|
||||
//if (m_pRecorderMutex->IsRecording(m_settings.IpAddress))
|
||||
// return std::string();
|
||||
|
||||
std::string dateTimeString = Util::GetDateTimeString();
|
||||
std::string fileName = GetFileName(m_settings, "jpg", dateTimeString, 0);
|
||||
|
||||
Http::HttpClient* pHttpClient = m_pHttpClient;
|
||||
Settings settings = m_settings;
|
||||
RTSPRecorder::Snapshots(ffmpeg, settings, dateTimeString, 1);
|
||||
//Util::RecorderMutexPointer pRecorderMutex = m_pRecorderMutex;
|
||||
//pThreadPool->push( [ffmpeg, settings, dateTimeString, pRecorderMutex](int) {
|
||||
// pRecorderMutex->RegisterRecording(settings.IpAddress);
|
||||
RTSPRecorder::Snapshots(ffmpeg, settings, dateTimeString, 1);
|
||||
// pRecorderMutex->UnregisterRecording(settings.IpAddress);
|
||||
//} );
|
||||
|
||||
return fileName;
|
||||
}
|
||||
@@ -78,12 +87,23 @@ std::string RTSPRecorder::MultiSnapshot(ctpl::thread_pool* pThreadPool, const st
|
||||
}
|
||||
}
|
||||
|
||||
if (m_pRecorderMutex->IsRecording(m_settings.IpAddress))
|
||||
{
|
||||
Logging::Log(Logging::Severity::Debug, "RTSPRecorder MultiSnapshot Cancelled, Recording in progress");
|
||||
return std::string();
|
||||
}
|
||||
|
||||
std::string dateTimeString = Util::GetDateTimeString();
|
||||
std::string fileName = GetFileName(m_settings, "jpg", dateTimeString, 0);
|
||||
|
||||
Http::HttpClient* pHttpClient = m_pHttpClient;
|
||||
Settings settings = m_settings;
|
||||
pThreadPool->push( [ffmpeg, settings, dateTimeString, numberOfImages](int) { RTSPRecorder::Snapshots(ffmpeg, settings, dateTimeString, numberOfImages); } );
|
||||
Util::RecorderMutexPointer pRecorderMutex = m_pRecorderMutex;
|
||||
pThreadPool->push( [ffmpeg, settings, dateTimeString, numberOfImages, pRecorderMutex](int) {
|
||||
pRecorderMutex->RegisterRecording(settings.IpAddress);
|
||||
RTSPRecorder::Snapshots(ffmpeg, settings, dateTimeString, numberOfImages);
|
||||
pRecorderMutex->UnregisterRecording(settings.IpAddress);
|
||||
} );
|
||||
|
||||
return fileName;
|
||||
}
|
||||
@@ -116,6 +136,12 @@ std::string RTSPRecorder::Video(ctpl::thread_pool* pThreadPool, const std::strin
|
||||
}
|
||||
}
|
||||
|
||||
if (m_pRecorderMutex->IsRecording(m_settings.IpAddress))
|
||||
{
|
||||
Logging::Log(Logging::Severity::Debug, "RTSPRecorder Video Cancelled, Recording in progress");
|
||||
return std::string();
|
||||
}
|
||||
|
||||
std::string dateTimeString = Util::GetDateTimeString();
|
||||
std::string fileName = GetFileName(m_settings, "mp4", dateTimeString, 0);
|
||||
|
||||
@@ -124,7 +150,13 @@ std::string RTSPRecorder::Video(ctpl::thread_pool* pThreadPool, const std::strin
|
||||
|
||||
std::string cmd(command.str());
|
||||
Logging::Log(Logging::Severity::Debug, cmd);
|
||||
pThreadPool->push( [cmd](int) { int retval = std::system(cmd.c_str()); } );
|
||||
Settings settings = m_settings;
|
||||
Util::RecorderMutexPointer pRecorderMutex = m_pRecorderMutex;
|
||||
pThreadPool->push( [cmd, settings, pRecorderMutex](int) {
|
||||
pRecorderMutex->RegisterRecording(settings.IpAddress);
|
||||
int retval = std::system(cmd.c_str());
|
||||
pRecorderMutex->UnregisterRecording(settings.IpAddress);
|
||||
} );
|
||||
|
||||
return fileName;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user