diff options
-rw-r--r-- | orkaudio/BatchProcessing.cpp | 81 | ||||
-rw-r--r-- | orkbasecxx/AudioCapture.h | 2 |
2 files changed, 67 insertions, 16 deletions
diff --git a/orkaudio/BatchProcessing.cpp b/orkaudio/BatchProcessing.cpp index 14b5d11..fe10581 100644 --- a/orkaudio/BatchProcessing.cpp +++ b/orkaudio/BatchProcessing.cpp @@ -14,6 +14,9 @@ #define _WINSOCKAPI_ // prevents the inclusion of winsock.h +#include <vector> +#include <bitset> + #include "ConfigManager.h" #include "BatchProcessing.h" #include "ace/OS_NS_unistd.h" @@ -150,6 +153,18 @@ void BatchProcessing::ThreadHandler(void *args) FilterRef filter; FilterRef decoder1; FilterRef decoder2; + FilterRef decoder; + + std::bitset<RTP_PAYLOAD_TYPE_MAX> seenRtpPayloadTypes; + std::vector<FilterRef> decoders1; + std::vector<FilterRef> decoders2; + for(int pt=0; pt<RTP_PAYLOAD_TYPE_MAX; pt++) + { + decoder1 = FilterRegistry::instance()->GetNewFilter(pt); + decoders1.push_back(decoder1); + decoder2 = FilterRegistry::instance()->GetNewFilter(pt); + decoders2.push_back(decoder2); + } bool firstChunk = true; bool voIpSession = false; @@ -167,32 +182,66 @@ void BatchProcessing::ThreadHandler(void *args) // ############ HACK AudioChunkDetails details = *chunkRef->GetDetails(); - if(firstChunk && details.m_rtpPayloadType != -1) + decoder.reset(); + + if(details.m_rtpPayloadType < -1 || details.m_rtpPayloadType > RTP_PAYLOAD_TYPE_MAX) + { + logMsg.Format("RTP payload type out of bound:%d", details.m_rtpPayloadType); + throw(logMsg); + } + + // Instanciate any decoder we might need during a VoIP session + if(details.m_rtpPayloadType != -1) { - CStdString rtpPayloadType = IntToString(details.m_rtpPayloadType); - LOG4CXX_INFO(LOG.batchProcessingLog, "[" + trackingId + "] Th" + threadIdString + " RTP payload type:" + rtpPayloadType); + voIpSession = true; - CStdString filterName("RtpMixer"); - filter = FilterRegistry::instance()->GetNewFilter(filterName); - if(filter.get() == NULL) + if(details.m_channel == 2) { - debug = "Could not instanciate RTP mixer"; - throw(debug); + decoder2 = decoders2.at(details.m_rtpPayloadType); + decoder = decoder2; } - decoder1 = FilterRegistry::instance()->GetNewFilter(details.m_rtpPayloadType); - decoder2 = FilterRegistry::instance()->GetNewFilter(details.m_rtpPayloadType); - if(decoder1.get() == NULL || decoder2.get() == NULL) + else { - debug.Format("Could not find decoder for RTP payload type:%u", chunkRef->GetDetails()->m_rtpPayloadType); - throw(debug); + decoder1 = decoders1.at(details.m_rtpPayloadType); + decoder = decoder1; + } + + bool ptAlreadySeen = seenRtpPayloadTypes.test(details.m_rtpPayloadType); + seenRtpPayloadTypes.set(details.m_rtpPayloadType); + + if(decoder.get() == NULL) + { + if(ptAlreadySeen == false) + { + // First time we see a particular unsupported payload type in this session, log it + CStdString rtpPayloadType = IntToString(details.m_rtpPayloadType); + LOG4CXX_ERROR(LOG.batchProcessingLog, "[" + trackingId + "] Th" + threadIdString + " unsupported RTP payload type:" + rtpPayloadType); + } + // We cannot decode this chunk due to unknown codec, go to next chunk + continue; + } + else if(ptAlreadySeen == false) + { + // First time we see a particular supported payload type in this session, log it + CStdString rtpPayloadType = IntToString(details.m_rtpPayloadType); + LOG4CXX_INFO(LOG.batchProcessingLog, "[" + trackingId + "] Th" + threadIdString + " RTP payload type:" + rtpPayloadType); } - voIpSession = true; } - if(firstChunk) + if(!voIpSession || (firstChunk && decoder.get())) { firstChunk = false; - // At this point, we know we have the right codec, open the output file + // At this point, we know we have a working codec, create an RTP mixer and open the output file + if(voIpSession) + { + CStdString filterName("RtpMixer"); + filter = FilterRegistry::instance()->GetNewFilter(filterName); + if(filter.get() == NULL) + { + debug = "Could not instanciate RTP mixer"; + throw(debug); + } + } CStdString file = CONFIG.m_audioOutputPath + "/" + audioTapeRef->GetPath() + audioTapeRef->GetIdentifier(); outFileRef->Open(file, AudioFile::WRITE, false, fileRef->GetSampleRate()); } diff --git a/orkbasecxx/AudioCapture.h b/orkbasecxx/AudioCapture.h index 89277b9..52485c7 100644 --- a/orkbasecxx/AudioCapture.h +++ b/orkbasecxx/AudioCapture.h @@ -38,6 +38,8 @@ typedef enum #define MEDIA_CHUNK_MARKER 0x2A2A2A2A // corresponds to "****" #define MEDIA_CHUNK_EOS_MARKER 0x454F534D /// corresponds to "EOSM" +#define RTP_PAYLOAD_TYPE_MAX 127 + class DLL_IMPORT_EXPORT_ORKBASE AudioChunkDetails { public: |