- work to merge latest changes into master branch

This commit is contained in:
Dmytro Bogovych 2023-05-10 11:03:48 +03:00
parent 76aa7861f5
commit 55445f6630
8 changed files with 36 additions and 146 deletions

View File

@ -132,7 +132,9 @@ std::string AgentImpl::command(const std::string& command)
{
answer["status"] = e.what();
}
return answer.toStyledString();
std::string result = answer.toStyledString();
return result;
}
bool AgentImpl::waitForData(int /*milliseconds*/)
@ -238,7 +240,7 @@ void AgentImpl::processCreateAccount(JsonCpp::Value &d, JsonCpp::Value& answer)
(*c)[CONFIG_DOMAIN] = d["domain"].asString();
(*c)[CONFIG_EXTERNALIP] = d["use_external_ip"].asBool();
auto nameAndPort = StringHelper::parseHost(d["stun_server"].asString(), 3478);
auto nameAndPort = strx::parseHost(d["stun_server"].asString(), 3478);
(*c)[CONFIG_STUNSERVER_NAME] = nameAndPort.first;
(*c)[CONFIG_STUNSERVER_PORT] = nameAndPort.second;
@ -320,7 +322,7 @@ void AgentImpl::processStartSession(JsonCpp::Value& request, JsonCpp::Value& ans
PDataProvider audioProvider = std::make_shared<AudioProvider>(*this, *mTerminal);
audioProvider->setState(audioProvider->state() | static_cast<int>(StreamState::Grabbing) | static_cast<int>(StreamState::Playing));
#if defined(USE_AQUA_LIBRARY)
/*#if defined(USE_AQUA_LIBRARY)
std::string path_faults = request["path_faults"].asString();
sevana::aqua::config config = {
@ -344,8 +346,8 @@ void AgentImpl::processStartSession(JsonCpp::Value& request, JsonCpp::Value& ans
};
// std::string config = "-avlp on -smtnrm on -decor off -mprio off -npnt auto -voip off -enorm off -g711 on -spfrcor off -grad off -tmc on -miter 1 -trim a 10 -output json";
/*if (temp_path.size())
config += " -fau " + temp_path; */
// if (temp_path.size())
// config += " -fau " + temp_path;
auto qc = std::make_shared<sevana::aqua>();
if (!qc->is_open())
@ -358,6 +360,7 @@ void AgentImpl::processStartSession(JsonCpp::Value& request, JsonCpp::Value& ans
mAquaMap[sessionIter->first] = qc;
dynamic_cast<AudioProvider*>(audioProvider.get())->configureMediaObserver(this, (void*)qc.get());
#endif
*/
// TODO: support SRTP via StreamState::Srtp option in audio provider state
@ -432,9 +435,9 @@ void AgentImpl::processDestroySession(JsonCpp::Value& request, JsonCpp::Value& a
auto sessionIter = mSessionMap.find(sessionId);
if (sessionIter != mSessionMap.end())
mSessionMap.erase(sessionIter);
#if defined(USE_AQUA_LIBRARY)
closeAqua(sessionId);
#endif
//#if defined(USE_AQUA_LIBRARY)
// closeAqua(sessionId);
//#endif
answer["status"] = Status_Ok;
}
@ -469,7 +472,7 @@ static JsonCpp::Value CsvReportToJson(const std::string& report)
{
JsonCpp::Value detectorNames;
for (size_t nameIndex = 0; nameIndex < cells.size(); nameIndex++)
detectorNames[static_cast<int>(nameIndex)] = StringHelper::trim(cells[nameIndex]);
detectorNames[static_cast<int>(nameIndex)] = strx::trim(cells[nameIndex]);
// Put first line name of columns
detectorValues[0] = detectorNames;
@ -481,7 +484,7 @@ static JsonCpp::Value CsvReportToJson(const std::string& report)
for (size_t valueIndex = 0; valueIndex < cells.size(); valueIndex++)
{
bool isFloat = true;
float v = StringHelper::toFloat(cells[valueIndex], 0.0, &isFloat);
float v = strx::toFloat(cells[valueIndex], 0.0, &isFloat);
if (isFloat)
row[static_cast<int>(valueIndex)] = static_cast<double>(v);
else
@ -544,7 +547,7 @@ void AgentImpl::processGetMediaStats(JsonCpp::Value& request, JsonCpp::Value& an
answer["rtp_remotepeer"] = result[SessionInfo_RemotePeer].asStdString();
#if defined(USE_AQUA_LIBRARY)
if (includeAqua)
/* if (includeAqua)
{
answer["incoming_audio"] = mAquaIncoming.hexstring();
answer["incoming_audio_samplerate"] = AUDIO_SAMPLERATE;
@ -561,7 +564,7 @@ void AgentImpl::processGetMediaStats(JsonCpp::Value& request, JsonCpp::Value& an
auto sa = mAquaMap[sessionIter->first];
if (sa) {
Audio::WavFileReader reader;
reader.open(StringHelper::makeTstring(aquaReference));
reader.open(strx::makeTstring(aquaReference));
if (reader.isOpened()) {
char buffer[1024];
@ -593,11 +596,6 @@ void AgentImpl::processGetMediaStats(JsonCpp::Value& request, JsonCpp::Value& an
}
answer["aqua_mos"] = r.mMos;
answer["aqua_report"] = r.mFaultsText;
/*std::string aqua_audio_text;
if (Base64::Encode(std::string(reinterpret_cast<const char*>(mAquaIncoming.data()), mAquaIncoming.size()), &aqua_audio_text))
{
answer["aqua_audio"] = aqua_audio_text;
}*/
if (r.mErrorCode) {
answer["aqua_error_code"] = r.mErrorCode;
@ -608,7 +606,7 @@ void AgentImpl::processGetMediaStats(JsonCpp::Value& request, JsonCpp::Value& an
}
// Remove test audio
mAquaIncoming.clear(); mAquaOutgoing.clear();
}
}*/
#endif
answer["status"] = Status_Ok;
@ -730,7 +728,7 @@ void AgentImpl::processUseStreamForSession(JsonCpp::Value& request, JsonCpp::Val
else
{
Audio::PWavFileReader reader = std::make_shared<Audio::WavFileReader>();
if (!reader->open(StringHelper::makeTstring(path)))
if (!reader->open(strx::makeTstring(path)))
answer["status"] = Status_FailedToOpenFile;
else
{
@ -751,7 +749,7 @@ void AgentImpl::processUseStreamForSession(JsonCpp::Value& request, JsonCpp::Val
else
{
Audio::PWavFileWriter writer = std::make_shared<Audio::WavFileWriter>();
if (!writer->open(StringHelper::makeTstring(path), AUDIO_SAMPLERATE, AUDIO_CHANNELS))
if (!writer->open(strx::makeTstring(path), AUDIO_SAMPLERATE, AUDIO_CHANNELS))
answer["status"] = Status_FailedToOpenFile;
else
{
@ -774,25 +772,14 @@ void AgentImpl::processUseStreamForSession(JsonCpp::Value& request, JsonCpp::Val
}
}
#if defined(USE_AQUA_LIBRARY)
void AgentImpl::onMedia(const void* data, int length, MT::Stream::MediaDirection direction, void* context, void* userTag)
{
/* if (mIncomingAudioDump && direction == MT::Stream::MediaDirection::Incoming)
mIncomingAudioDump->write(data, length);
if (mOutgoingAudioDump && direction == MT::Stream::MediaDirection::Outgoing)
mOutgoingAudioDump->write(data, length);*/
// User tag points to accumulator object which includes
// auto* sa = reinterpret_cast<sevana::aqua*>(userTag);
switch (direction)
/*switch (direction)
{
case MT::Stream::MediaDirection::Incoming: mAquaIncoming.appendBuffer(data, length); break;
case MT::Stream::MediaDirection::Outgoing: mAquaOutgoing.appendBuffer(data, length); break;
}
}*/
}
#endif
// Called on new incoming session; providers shoukld
@ -949,12 +936,12 @@ void AgentImpl::addEvent(const JsonCpp::Value& v)
}
#if defined(USE_AQUA_LIBRARY)
void AgentImpl::closeAqua(int sessionId)
/*void AgentImpl::closeAqua(int sessionId)
{
auto aquaIter = mAquaMap.find(sessionId);
if (aquaIter != mAquaMap.end()) {
aquaIter->second->close();
mAquaMap.erase(aquaIter);
}
}
}*/
#endif

View File

@ -14,7 +14,7 @@
#include <mutex>
#include <condition_variable>
class AgentImpl: public UserAgent
class AgentImpl: public UserAgent, public MT::Stream::MediaObserver
{
protected:
std::recursive_mutex mAgentMutex;
@ -29,13 +29,6 @@ protected:
typedef std::map<int, PSession> SessionMap;
SessionMap mSessionMap;
#if defined(USE_AQUA_LIBRARY)
// Keys are the same as used in mSessionMap
typedef std::map<int, std::shared_ptr<sevana::aqua>> AquaMap;
AquaMap mAquaMap;
ByteBuffer mAquaIncoming, mAquaOutgoing;
void closeAqua(int sessionId);
#endif
std::shared_ptr<std::thread> mThread;
volatile bool mShutdown;
@ -121,10 +114,8 @@ public:
// Called when problem with SIP connection(s) detected
void onSipConnectionFailed() override;
#if defined(USE_AQUA_LIBRARY)
// Called on incoming & outgoing audio for voice sessions
void onMedia(const void* data, int length, MT::Stream::MediaDirection direction, void* context, void* userTag) override;
#endif
};
#endif

View File

@ -136,7 +136,7 @@ int AndroidInputDevice::readBuffer(void* buffer)
// ------------ AndroidOutputDevice -----------------
AndroidOutputDevice::AndroidOutputDevice(int devId)
{
ICELogDebug(<< "Creating AndroidOutputDevice. This is: " << StringHelper::toHex(this));
ICELogDebug(<< "Creating AndroidOutputDevice. This is: " << strx::toHex(this));
}
AndroidOutputDevice::~AndroidOutputDevice()
{

View File

@ -105,7 +105,7 @@ void UserAgent::start()
while (std::getline(ss, line))
{
line = StringHelper::trim(line);
line = strx::trim(line);
ice::NetworkAddress addr(line.c_str(), 0); addr.setPort(80); // Fake port to make ICEAddress initialized
switch (addr.family())
{
@ -661,7 +661,7 @@ bool UserAgent::operator()(resip::Log::Level level, const resip::Subsystem& subs
std::string filename = file;
std::stringstream ss;
ss << "File " << StringHelper::extractFilename(filename).c_str() << ", line " << line << ": " << message.c_str();
ss << "File " << strx::extractFilename(filename).c_str() << ", line " << line << ": " << message.c_str();
if (level <= resip::Log::Crit)
ICELogCritical(<< ss.str())
else
@ -948,7 +948,7 @@ void UserAgent::onAnswer(resip::InviteSessionHandle h, const resip::SipMessage&
// See if remote stream has "rtcp" or "rtcp-mux" attributes
if (remoteStream.exists("rtcp"))
addr2.setPort( StringHelper::toInt(remoteStream.getValues("rtcp").front().c_str(), remoteDefaultPort+1) );
addr2.setPort( strx::toInt(remoteStream.getValues("rtcp").front().c_str(), remoteDefaultPort+1) );
else
if (remoteStream.exists("rtcp-mux"))
addr2.setPort( remoteDefaultPort );
@ -1568,11 +1568,11 @@ void UserAgent::onSipMessage(int flow, const char* msg, unsigned int length, con
{
case resip::InternalTransport::TransportLogger::Flow_Received:
ICELogDebug(<< "Received from " << addressText << ":" << "\n"
<< StringHelper::prefixLines(d, "--->"));
<< strx::prefixLines(d, "--->"));
break;
case resip::InternalTransport::TransportLogger::Flow_Sent:
ICELogDebug(<< "Sent to " << addressText << "\n" << StringHelper::prefixLines(d, "<---"));
ICELogDebug(<< "Sent to " << addressText << "\n" << strx::prefixLines(d, "<---"));
break;
}
}

View File

@ -959,7 +959,7 @@ int Session::processSdp(UInt64 version, bool iceAvailable, std::string icePwd, s
targetAddr.mRtcp.setPort( remoteStream.port() );
else
if (stream.rtcpAttr())
targetAddr.mRtcp.setPort( StringHelper::toInt(remoteStream.getValues("rtcp").front().c_str(), remoteStream.port() + 1 ) );
targetAddr.mRtcp.setPort( strx::toInt(remoteStream.getValues("rtcp").front().c_str(), remoteStream.port() + 1 ) );
else
targetAddr.mRtcp.setPort( remoteStream.port() + 1);

View File

@ -341,12 +341,6 @@ AudioReceiver::AudioReceiver(const CodecList::Settings& settings, MT::Statistics
AudioReceiver::~AudioReceiver()
{
#if defined(USE_PVQA_LIBRARY) && defined(PVQA_IN_RECEIVER)
if (mPVQA && mPvqaBuffer)
{
mStat.mPvqaMos = calculatePvqaMos(AUDIO_SAMPLERATE, mStat.mPvqaReport);
}
#endif
mResampler8.stop();
mResampler16.stop();
mResampler32.stop();
@ -487,11 +481,6 @@ void AudioReceiver::processDecoded(Audio::DataWindow& output, int options)
makeMonoAndResample(resample ? mCodec->samplerate() : 0,
mCodec->channels());
// Update PVQA with stats
#if defined(USE_PVQA_LIBRARY) && defined(PVQA_IN_RECEIVER)
updatePvqa(mResampledFrame, mResampledLength);
#endif
// Send to output
output.add(mResampledFrame, mResampledLength);
}
@ -537,10 +526,6 @@ AudioReceiver::DecodeResult AudioReceiver::getAudio(Audio::DataWindow& output, i
case RtpBuffer::FetchResult::NoPacket:
ICELogDebug(<< "No packet available in jitter buffer");
mFailedCount++;
#if defined(USE_PVQA_LIBRARY) && defined(PVQA_IN_RECEIVER)
if (mResampledLength > 0)
updatePvqa(nullptr, mResampledLength);
#endif
break;
case RtpBuffer::FetchResult::RegularPacket:
@ -734,70 +719,6 @@ Codec* AudioReceiver::findCodec(int payloadType)
return codecIter->second.get();
}
#if defined(USE_PVQA_LIBRARY) && defined(PVQA_IN_RECEIVER)
void AudioReceiver::initPvqa()
{
// Allocate space for 20 seconds audio
if (!mPvqaBuffer)
{
mPvqaBuffer = std::make_shared<Audio::DataWindow>();
mPvqaBuffer->setCapacity(Audio::Format().sizeFromTime(30000));
}
// Instantiate & open PVQA analyzer
if (!mPVQA)
{
mPVQA = std::make_shared<sevana::pvqa>();
bool is_opened = mPVQA->open(AUDIO_SAMPLERATE, 1, PVQA_INTERVAL);
if (!is_opened)
{
//
}
}
}
void AudioReceiver::updatePvqa(const void *data, int size)
{
if (!mPVQA)
initPvqa();
if (mPVQA)
{
if (data)
mPvqaBuffer->add(data, size);
else
mPvqaBuffer->addZero(size);
Audio::Format fmt;
int frames = static_cast<int>(fmt.timeFromSize(mPvqaBuffer->filled())) / (PVQA_INTERVAL * 1000);
if (frames > 0)
{
int time4pvqa = (int)(frames * PVQA_INTERVAL * 1000);
int size4pvqa = (int)fmt.sizeFromTime(time4pvqa);
ICELogDebug(<< "PVQA buffer has " << time4pvqa << " milliseconds of audio.");
bool update_result = mPVQA->update(mPvqaBuffer->data(), size4pvqa);
if (!update_result)
{
//
}
mPvqaBuffer->erase(size4pvqa);
}
}
}
float AudioReceiver::calculatePvqaMos(int rate, std::string& report)
{
if (mPVQA && mPvqaBuffer)
{
sevana::pvqa::result result;
if (mPVQA->get_result(result)) {
report = result.mReport;
return result.mMos;
}
}
return 0.0f;
}
#endif
void AudioReceiver::processStatisticsWithAmrCodec(Codec* c)
{

View File

@ -10,6 +10,7 @@
#include "MT_CodecList.h"
#include "MT_AudioCodec.h"
#include "MT_CngHelper.h"
#include "../helper/HL_Pointer.h"
#include "../helper/HL_Sync.h"
#include "../helper/HL_Optional.hpp"
@ -20,10 +21,6 @@
#include "../audio/Audio_DataWindow.h"
#include "../audio/Audio_Resampler.h"
/*#if defined(USE_PVQA_LIBRARY)
# include "pvqa++.h"
#endif*/
#include <map>
// #define DUMP_DECODED
@ -209,16 +206,6 @@ namespace MT
// Resamples, sends to analysis, writes to dump and queues to output decoded frames from mDecodedFrame
void processDecoded(Audio::DataWindow& output, int options);
/*
#if defined(USE_PVQA_LIBRARY) && defined(PVQA_IN_RECEIVER)
std::shared_ptr<sevana::pvqa> mPVQA;
void initPvqa();
void updatePvqa(const void* data, int size);
float calculatePvqaMos(int rate, std::string& report);
std::shared_ptr<Audio::DataWindow> mPvqaBuffer;
#endif
*/
void processStatisticsWithAmrCodec(Codec* c);
};

View File

@ -1,8 +1,9 @@
/* Copyright(C) 2007-2022 VoIPobjects (voipobjects.com)
/* Copyright(C) 2007-2023 VoIPobjects (voipobjects.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include <algorithm>
#include <list>
#include "../config.h"
#include "MT_CodecList.h"
@ -125,6 +126,7 @@ CodecList::Settings::OpusSpec CodecList::Settings::OpusSpec::parse(const std::st
return result;
}
#if defined(USE_RESIP_INTEGRATION)
CodecList::Settings CodecList::Settings::parseSdp(const std::list<resip::Codec>& codeclist)
{
CodecList::Settings r{DefaultSettings};
@ -147,6 +149,8 @@ CodecList::Settings CodecList::Settings::parseSdp(const std::list<resip::Codec>&
}
return r;
}
#endif
bool CodecList::Settings::operator == (const Settings& rhs) const
{