summaryrefslogtreecommitdiff
path: root/orkaudio/BatchProcessing.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'orkaudio/BatchProcessing.cpp')
-rw-r--r--orkaudio/BatchProcessing.cpp219
1 files changed, 151 insertions, 68 deletions
diff --git a/orkaudio/BatchProcessing.cpp b/orkaudio/BatchProcessing.cpp
index 5be8b74..1435bb4 100644
--- a/orkaudio/BatchProcessing.cpp
+++ b/orkaudio/BatchProcessing.cpp
@@ -24,6 +24,11 @@ BatchProcessing BatchProcessing::m_batchProcessingSingleton;
BatchProcessing::BatchProcessing()
{
m_threadCount = 0;
+
+ struct tm date = {0};
+ time_t now = time(NULL);
+ ACE_OS::localtime_r(&now, &date);
+ m_currentDay = date.tm_mday;
}
@@ -41,6 +46,65 @@ void BatchProcessing::AddAudioTape(AudioTapeRef audioTapeRef)
}
}
+void BatchProcessing::TapeDropRegistration(CStdString& filename)
+{
+ MutexSentinel sentinel(m_tapeDropMutex);
+
+ CStdString absoluteFilename = CONFIG.m_audioOutputPath + "/" + filename;
+ if (ACE_OS::unlink((PCSTR)absoluteFilename) != 0)
+ {
+ LOG4CXX_DEBUG(LOG.batchProcessingLog, "Could not deleted tape: " + filename);
+ m_tapesToDrop.insert(std::make_pair(filename, time(NULL)));
+ }
+ else
+ {
+ LOG4CXX_INFO(LOG.batchProcessingLog, "Deleted tape: " + filename);
+ }
+}
+
+bool BatchProcessing::DropTapeIfNeeded(CStdString& filename)
+{
+ bool shouldDrop = false;
+
+ MutexSentinel sentinel(m_tapeDropMutex);
+
+ std::map<CStdString, time_t>::iterator pair;
+ pair = m_tapesToDrop.find(filename);
+ if(pair != m_tapesToDrop.end())
+ {
+ shouldDrop = true;
+ CStdString absoluteFilename = CONFIG.m_audioOutputPath + "/" + filename;
+ if (ACE_OS::unlink((PCSTR)absoluteFilename) == 0)
+ {
+ LOG4CXX_INFO(LOG.batchProcessingLog, "Deleted tape: " + filename);
+ m_tapesToDrop.erase(filename);
+ }
+ else
+ {
+ LOG4CXX_DEBUG(LOG.batchProcessingLog, "Could not deleted tape: " + filename);
+ }
+ }
+
+ TapeDropHousekeeping();
+
+ return shouldDrop;
+}
+
+void BatchProcessing::TapeDropHousekeeping()
+{
+ struct tm date = {0};
+ time_t now = time(NULL);
+ ACE_OS::localtime_r(&now, &date);
+ if(m_currentDay != date.tm_mday)
+ {
+ // another day has passed away ... clear possible leftovers
+ m_currentDay = date.tm_mday;
+ m_tapesToDrop.clear();
+ }
+}
+
+
+
void BatchProcessing::ThreadHandler(void *args)
{
CStdString debug;
@@ -73,89 +137,108 @@ void BatchProcessing::ThreadHandler(void *args)
}
else
{
- CStdString threadIdString = IntToString(threadId);
- LOG4CXX_INFO(LOG.batchProcessingLog, CStdString("Th") + threadIdString + " processing: " + audioTapeRef->GetIdentifier());
-
fileRef = audioTapeRef->GetAudioFileRef();
- fileRef->MoveOrig();
- fileRef->Open(AudioFile::READ);
- AudioChunkRef chunkRef;
- AudioChunkRef tmpChunkRef;
-
- switch(CONFIG.m_storageAudioFormat)
+ if(pBatchProcessing->DropTapeIfNeeded(audioTapeRef->GetFilename()) == true)
{
- case AudioTape::FfUlaw:
- outFileRef.reset(new LibSndFileFile(SF_FORMAT_ULAW | SF_FORMAT_WAV));
- break;
- case AudioTape::FfAlaw:
- outFileRef.reset(new LibSndFileFile(SF_FORMAT_ALAW | SF_FORMAT_WAV));
- break;
- case AudioTape::FfGsm:
- outFileRef.reset(new LibSndFileFile(SF_FORMAT_GSM610 | SF_FORMAT_WAV));
- break;
- case AudioTape::FfPcmWav:
- default:
- outFileRef.reset(new LibSndFileFile(SF_FORMAT_PCM_16 | SF_FORMAT_WAV));
+ // The tape we have pulled has been dropped in the meantime. just delete the capture file
+ if(CONFIG.m_deleteNativeFile)
+ {
+ fileRef->Delete();
+ }
}
- CStdString file = CONFIG.m_audioOutputPath + "/" + audioTapeRef->GetPath() + audioTapeRef->GetIdentifier();
- outFileRef->Open(file, AudioFile::WRITE, false, fileRef->GetSampleRate());
+ else
+ {
+ // Let's work on the tape we have pulled
+ CStdString threadIdString = IntToString(threadId);
+ LOG4CXX_INFO(LOG.batchProcessingLog, CStdString("Th") + threadIdString + " processing: " + audioTapeRef->GetIdentifier());
- FilterRef filter;
- FilterRef decoder1;
- FilterRef decoder2;
+ fileRef->MoveOrig();
+ fileRef->Open(AudioFile::READ);
- bool firstChunk = true;
- bool voIpSession = false;
+ AudioChunkRef chunkRef;
+ AudioChunkRef tmpChunkRef;
- while(fileRef->ReadChunkMono(chunkRef))
- {
- AudioChunkDetails details = *chunkRef->GetDetails();
- if(firstChunk && details.m_rtpPayloadType != -1)
+ switch(CONFIG.m_storageAudioFormat)
{
- firstChunk = false;
- CStdString filterName("RtpMixer");
- filter = FilterRegistry::instance()->GetNewFilter(filterName);
- if(filter.get() == NULL)
- {
- debug = "BatchProcessing - Could not instanciate RTP mixer";
- throw(debug);
- }
- decoder1 = FilterRegistry::instance()->GetNewFilter(details.m_rtpPayloadType);
- decoder2 = FilterRegistry::instance()->GetNewFilter(details.m_rtpPayloadType);
- if(decoder1.get() == NULL || decoder2.get() == NULL)
- {
- debug.Format("BatchProcessing - Could not find decoder for RTP payload type:%u", chunkRef->GetDetails()->m_rtpPayloadType);
- throw(debug);
- }
- voIpSession = true;
+ case AudioTape::FfUlaw:
+ outFileRef.reset(new LibSndFileFile(SF_FORMAT_ULAW | SF_FORMAT_WAV));
+ break;
+ case AudioTape::FfAlaw:
+ outFileRef.reset(new LibSndFileFile(SF_FORMAT_ALAW | SF_FORMAT_WAV));
+ break;
+ case AudioTape::FfGsm:
+ outFileRef.reset(new LibSndFileFile(SF_FORMAT_GSM610 | SF_FORMAT_WAV));
+ break;
+ case AudioTape::FfPcmWav:
+ default:
+ outFileRef.reset(new LibSndFileFile(SF_FORMAT_PCM_16 | SF_FORMAT_WAV));
}
- if(voIpSession)
- {
- if(details.m_channel == 2)
+ CStdString file = CONFIG.m_audioOutputPath + "/" + audioTapeRef->GetPath() + audioTapeRef->GetIdentifier();
+ outFileRef->Open(file, AudioFile::WRITE, false, fileRef->GetSampleRate());
+
+ FilterRef filter;
+ FilterRef decoder1;
+ FilterRef decoder2;
+
+ bool firstChunk = true;
+ bool voIpSession = false;
+
+ while(fileRef->ReadChunkMono(chunkRef))
+ {
+ AudioChunkDetails details = *chunkRef->GetDetails();
+ if(firstChunk && details.m_rtpPayloadType != -1)
{
- decoder2->AudioChunkIn(chunkRef);
- decoder2->AudioChunkOut(tmpChunkRef);
+ firstChunk = false;
+ CStdString filterName("RtpMixer");
+ filter = FilterRegistry::instance()->GetNewFilter(filterName);
+ if(filter.get() == NULL)
+ {
+ debug = "BatchProcessing - Could not instanciate RTP mixer";
+ throw(debug);
+ }
+ decoder1 = FilterRegistry::instance()->GetNewFilter(details.m_rtpPayloadType);
+ decoder2 = FilterRegistry::instance()->GetNewFilter(details.m_rtpPayloadType);
+ if(decoder1.get() == NULL || decoder2.get() == NULL)
+ {
+ debug.Format("BatchProcessing - Could not find decoder for RTP payload type:%u", chunkRef->GetDetails()->m_rtpPayloadType);
+ throw(debug);
+ }
+ voIpSession = true;
}
- else
- {
- decoder1->AudioChunkIn(chunkRef);
- decoder1->AudioChunkOut(tmpChunkRef);
+ if(voIpSession)
+ {
+ if(details.m_channel == 2)
+ {
+ decoder2->AudioChunkIn(chunkRef);
+ decoder2->AudioChunkOut(tmpChunkRef);
+ }
+ else
+ {
+ decoder1->AudioChunkIn(chunkRef);
+ decoder1->AudioChunkOut(tmpChunkRef);
+ }
+ filter->AudioChunkIn(tmpChunkRef);
+ filter->AudioChunkOut(tmpChunkRef);
}
- filter->AudioChunkIn(tmpChunkRef);
- filter->AudioChunkOut(tmpChunkRef);
+ outFileRef->WriteChunk(tmpChunkRef);
+
+ // Give up CPU to make sure the actual recording always has priority
+ ACE_Time_Value yield;
+ yield.set(0,1); // 1 us
+ ACE_OS::sleep(yield);
}
- outFileRef->WriteChunk(tmpChunkRef);
- }
- fileRef->Close();
- outFileRef->Close();
+ fileRef->Close();
+ outFileRef->Close();
- if(CONFIG.m_deleteNativeFile)
- {
- fileRef->Delete();
- CStdString threadIdString = IntToString(threadId);
- LOG4CXX_INFO(LOG.batchProcessingLog, CStdString("Th") + threadIdString + " deleting native: " + audioTapeRef->GetIdentifier());
+ if(CONFIG.m_deleteNativeFile)
+ {
+ fileRef->Delete();
+ CStdString threadIdString = IntToString(threadId);
+ LOG4CXX_INFO(LOG.batchProcessingLog, CStdString("Th") + threadIdString + " deleting native: " + audioTapeRef->GetIdentifier());
+ }
+ pBatchProcessing->DropTapeIfNeeded(audioTapeRef->GetFilename()); // maybe the tape was dropped while we were processing it
}
}
}