diff --git a/src/engine/helper/HL_CrashRpt.cpp b/src/engine/helper/HL_CrashRpt.cpp index fbd8a003..2729fb5f 100644 --- a/src/engine/helper/HL_CrashRpt.cpp +++ b/src/engine/helper/HL_CrashRpt.cpp @@ -1,6 +1,7 @@ +#include "HL_CrashRpt.h" + #if defined(USE_CRASHRPT) -#include "HL_CrashRpt.h" #include "HL_String.h" @@ -171,4 +172,22 @@ CrashReporterGuard::~CrashReporterGuard() CrashReporter::free(); } +#else + +CrashReporterThreadPoint::CrashReporterThreadPoint() +{ +} + +CrashReporterThreadPoint::~CrashReporterThreadPoint() +{ +} + +CrashReporterGuard::CrashReporterGuard() +{ +} + +CrashReporterGuard::~CrashReporterGuard() +{ +} + #endif diff --git a/src/engine/helper/HL_CsvReader.cpp b/src/engine/helper/HL_CsvReader.cpp index 30866500..f305013e 100644 --- a/src/engine/helper/HL_CsvReader.cpp +++ b/src/engine/helper/HL_CsvReader.cpp @@ -20,6 +20,9 @@ bool CsvReader::readLine(std::vector& cells) std::string line; if (!std::getline(mInputStream, line)) return false; + StringHelper::trim(line); + if (line.empty()) + return false; StringHelper::split(line, cells, ",;"); return true; diff --git a/src/engine/helper/HL_Process.cpp b/src/engine/helper/HL_Process.cpp index e1b9b5be..7d1d96e5 100644 --- a/src/engine/helper/HL_Process.cpp +++ b/src/engine/helper/HL_Process.cpp @@ -202,7 +202,6 @@ std::shared_ptr OsProcess::asyncExecCommand(const std::string& cmdl std::string OsProcess::execCommand(const std::string& cmd) { std::string cp = cmd; - std::shared_ptr pipe(popen(cp.c_str(), "r"), pclose); if (!pipe) throw std::runtime_error("Failed to run."); diff --git a/src/engine/helper/HL_String.cpp b/src/engine/helper/HL_String.cpp index d18b3294..edfbaa58 100644 --- a/src/engine/helper/HL_String.cpp +++ b/src/engine/helper/HL_String.cpp @@ -276,8 +276,8 @@ float StringHelper::toFloat(const std::string &s, float v, bool* isOk) std::string StringHelper::trim(const std::string &s) { - auto wsfront = std::find_if_not(s.begin(), s.end(), [](int c) { return std::isspace(c); }); - auto wsback = std::find_if_not(s.rbegin(), s.rend(), [](int c) { return std::isspace(c); }).base(); + auto wsfront = std::find_if_not(s.begin(), s.end(), [](int c) { return std::isspace(c) || c == '\r' || c == '\n'; }); + auto wsback = std::find_if_not(s.rbegin(), s.rend(), [](int c) { return std::isspace(c) || c == '\r' || c == '\n'; }).base(); return (wsback <= wsfront ? std::string() : std::string(wsfront,wsback)); } diff --git a/src/engine/media/MT_AudioCodec.h b/src/engine/media/MT_AudioCodec.h index 9e256851..65906a66 100644 --- a/src/engine/media/MT_AudioCodec.h +++ b/src/engine/media/MT_AudioCodec.h @@ -17,8 +17,8 @@ extern "C" { - #include "libgsm/gsm.h" - #include "g722/g722.h" +#include "libgsm/gsm.h" +#include "g722/g722.h" } #include "libg729/g729_typedef.h" @@ -28,27 +28,27 @@ extern "C" namespace MT { - class G729Codec: public Codec - { - protected: +class G729Codec: public Codec +{ +protected: CodState* mEncoder = nullptr; DecState* mDecoder = nullptr; void decodeFrame(const uint8_t* rtp, int16_t* pcm); - public: +public: class G729Factory: public Factory { public: - const char* name() override; - int channels() override; - int samplerate() override; - int payloadType() override; + const char* name() override; + int channels() override; + int samplerate() override; + int payloadType() override; #if defined(USE_RESIP_INTEGRATION) - void updateSdp(resip::SdpContents::Session::Medium::CodecContainer& codecs, SdpDirection direction) override; - int processSdp(const resip::SdpContents::Session::Medium::CodecContainer& codecs, SdpDirection direction) override; + void updateSdp(resip::SdpContents::Session::Medium::CodecContainer& codecs, SdpDirection direction) override; + int processSdp(const resip::SdpContents::Session::Medium::CodecContainer& codecs, SdpDirection direction) override; #endif - PCodec create() override; + PCodec create() override; }; G729Codec(); ~G729Codec() override; @@ -62,48 +62,48 @@ namespace MT int encode(const void* input, int inputBytes, void* output, int outputCapacity) override; int decode(const void* input, int inputBytes, void* output, int outputCapacity) override; int plc(int lostFrames, void* output, int outputCapacity) override; - }; +}; - class OpusCodec: public Codec - { - protected: +class OpusCodec: public Codec +{ +protected: OpusEncoder *mEncoderCtx; OpusDecoder *mDecoderCtx; int mPTime, mSamplerate, mChannels; Audio::SpeexResampler mDecodeResampler; - public: +public: struct Params { - bool mUseDtx, mUseInbandFec, mStereo; - int mPtime, mTargetBitrate, mExpectedPacketLoss; + bool mUseDtx, mUseInbandFec, mStereo; + int mPtime, mTargetBitrate, mExpectedPacketLoss; - Params(); + Params(); #if defined(USE_RESIP_INTEGRATION) - resip::Data toString() const; - void parse(const resip::Data& params); + resip::Data toString() const; + void parse(const resip::Data& params); #endif }; class OpusFactory: public Factory { protected: - int mSamplerate, mChannels, mPType; - OpusCodec::Params mParams; - typedef std::vector CodecList; - CodecList mCodecList; + int mSamplerate, mChannels, mPType; + OpusCodec::Params mParams; + typedef std::vector CodecList; + CodecList mCodecList; public: - OpusFactory(int samplerate, int channels, int ptype); + OpusFactory(int samplerate, int channels, int ptype); - const char* name() override; - int channels() override; - int samplerate() override; - int payloadType() override; + const char* name() override; + int channels() override; + int samplerate() override; + int payloadType() override; #if defined(USE_RESIP_INTEGRATION) - void updateSdp(resip::SdpContents::Session::Medium::CodecContainer& codecs, SdpDirection direction) override; - int processSdp(const resip::SdpContents::Session::Medium::CodecContainer& codecs, SdpDirection direction) override; + void updateSdp(resip::SdpContents::Session::Medium::CodecContainer& codecs, SdpDirection direction) override; + int processSdp(const resip::SdpContents::Session::Medium::CodecContainer& codecs, SdpDirection direction) override; #endif - PCodec create() override; + PCodec create() override; }; OpusCodec(int samplerate, int channels, int ptime); @@ -119,34 +119,34 @@ namespace MT int encode(const void* input, int inputBytes, void* output, int outputCapacity); int decode(const void* input, int inputBytes, void* output, int outputCapacity); int plc(int lostFrames, void* output, int outputCapacity); - }; +}; - class IlbcCodec: public Codec - { - protected: +class IlbcCodec: public Codec +{ +protected: int mPacketTime; /// Single frame time (20 or 30 ms) iLBC_encinst_t* mEncoderCtx; iLBC_decinst_t* mDecoderCtx; - public: +public: class IlbcFactory: public Factory { protected: - int mPtime; - int mPType20ms, mPType30ms; + int mPtime; + int mPType20ms, mPType30ms; public: - IlbcFactory(int ptype20ms, int ptype30ms); - const char* name(); - int samplerate(); - int payloadType(); + IlbcFactory(int ptype20ms, int ptype30ms); + const char* name(); + int samplerate(); + int payloadType(); #if defined(USE_RESIP_INTEGRATION) - void updateSdp(resip::SdpContents::Session::Medium::CodecContainer& codecs, SdpDirection direction); - int processSdp(const resip::SdpContents::Session::Medium::CodecContainer& codecs, SdpDirection direction); - void create(CodecMap& codecs); + void updateSdp(resip::SdpContents::Session::Medium::CodecContainer& codecs, SdpDirection direction); + int processSdp(const resip::SdpContents::Session::Medium::CodecContainer& codecs, SdpDirection direction); + void create(CodecMap& codecs); #endif - PCodec create(); + PCodec create(); }; IlbcCodec(int packetTime); @@ -159,33 +159,33 @@ namespace MT int encode(const void* input, int inputBytes, void* output, int outputCapacity); int decode(const void* input, int inputBytes, void* output, int outputCapacity); int plc(int lostFrames, void* output, int outputCapacity); - }; +}; - class G711Codec: public Codec - { - public: +class G711Codec: public Codec +{ +public: class AlawFactory: public Factory { public: - const char* name(); - int samplerate(); - int payloadType(); - PCodec create(); + const char* name(); + int samplerate(); + int payloadType(); + PCodec create(); }; class UlawFactory: public Factory { public: - const char* name(); - int samplerate(); - int payloadType(); - PCodec create(); + const char* name(); + int samplerate(); + int payloadType(); + PCodec create(); }; enum { - ALaw = 0, /// a-law codec type - ULaw = 1 /// u-law codec type + ALaw = 0, /// a-law codec type + ULaw = 1 /// u-law codec type }; G711Codec(int type); @@ -201,42 +201,42 @@ namespace MT int decode(const void* input, int inputBytes, void* output, int outputCapacity); int plc(int lostSamples, void* output, int outputCapacity); - protected: +protected: int mType; /// Determines if it is u-law or a-law codec. Its value is ALaw or ULaw. - }; +}; - class IsacCodec: public Codec - { - protected: - int mSamplerate; +class IsacCodec: public Codec +{ +protected: + int mSamplerate; ISACFIX_MainStruct* mEncoderCtx; ISACFIX_MainStruct* mDecoderCtx; - public: +public: class IsacFactory16K: public Factory { public: - IsacFactory16K(int ptype); - const char* name(); - int samplerate(); - int payloadType(); - PCodec create(); + IsacFactory16K(int ptype); + const char* name(); + int samplerate(); + int payloadType(); + PCodec create(); protected: - int mPType; + int mPType; }; class IsacFactory32K: public Factory { public: - IsacFactory32K(int ptype); + IsacFactory32K(int ptype); - const char* name(); - int samplerate(); - int payloadType(); - PCodec create(); + const char* name(); + int samplerate(); + int payloadType(); + PCodec create(); protected: - int mPType; + int mPType; }; IsacCodec(int sampleRate); @@ -251,63 +251,63 @@ namespace MT int encode(const void* input, int inputBytes, void* output, int outputCapacity); int decode(const void* input, int inputBytes, void* output, int outputCapacity); int plc(int lostFrames, void* output, int outputCapacity); - }; - +}; - /// GSM MIME name - #define GSM_MIME_NAME "gsm" - /// Optional GSM SIP attributes - #define GSM_SIP_ATTR "" +/// GSM MIME name +#define GSM_MIME_NAME "gsm" - /// GSM codec single frame time in milliseconds - #define GSM_AUDIOFRAME_TIME 20 +/// Optional GSM SIP attributes +#define GSM_SIP_ATTR "" - /// GSM codec single RTP frame size in bytes - #define GSM_RTPFRAME_SIZE_33 33 - #define GSM_RTPFRAME_SIZE_32 32 - #define GSM_RTPFRAME_SIZE_31 31 +/// GSM codec single frame time in milliseconds +#define GSM_AUDIOFRAME_TIME 20 - /// GSM payload type - #define GSM_PAYLOAD_TYPE 3 +/// GSM codec single RTP frame size in bytes +#define GSM_RTPFRAME_SIZE_33 33 +#define GSM_RTPFRAME_SIZE_32 32 +#define GSM_RTPFRAME_SIZE_31 31 - /// GSM bitrate (bits/sec) - #define GSM_BITRATE 13000 +/// GSM payload type +#define GSM_PAYLOAD_TYPE 3 + +/// GSM bitrate (bits/sec) +#define GSM_BITRATE 13000 - /*! +/*! * GSM codec wrapper. Based on implementation located in libgsm directory. * @see IMediaCodec */ - class GsmCodec: public Codec - { - public: +class GsmCodec: public Codec +{ +public: enum class Type { - Bytes_33, - Bytes_32, - Bytes_31, - Bytes_65 + Bytes_33, + Bytes_32, + Bytes_31, + Bytes_65 }; - protected: +protected: struct gsm_state * mGSM; /// Pointer to codec context Type mCodecType; - public: +public: class GsmFactory: public Factory { protected: - int mPayloadType; - Type mCodecType; + int mPayloadType; + Type mCodecType; public: - GsmFactory(Type codecType = Type::Bytes_33, int pt = GSM_PAYLOAD_TYPE); + GsmFactory(Type codecType = Type::Bytes_33, int pt = GSM_PAYLOAD_TYPE); - const char* name(); - int samplerate(); - int payloadType(); - PCodec create(); + const char* name(); + int samplerate(); + int payloadType(); + PCodec create(); }; /*! Default constructor. Initializes codec context's pointer to NULL. */ @@ -325,42 +325,42 @@ namespace MT int encode(const void* input, int inputBytes, void* output, int outputCapacity); int decode(const void* input, int inputBytes, void* output, int outputCapacity); int plc(int lostFrames, void* output, int outputCapacity); - }; +}; - /// GSM MIME name - #define G722_MIME_NAME "g722" +/// GSM MIME name +#define G722_MIME_NAME "g722" - /// Optional GSM SIP attributes - #define G722_SIP_ATTR "" +/// Optional GSM SIP attributes +#define G722_SIP_ATTR "" - /// GSM codec single frame time in milliseconds - #define G722_AUDIOFRAME_TIME 20 +/// GSM codec single frame time in milliseconds +#define G722_AUDIOFRAME_TIME 20 - /// GSM codec single RTP frame size in bytes - #define G722_RTPFRAME_SIZE 80 +/// GSM codec single RTP frame size in bytes +#define G722_RTPFRAME_SIZE 80 - /// GSM payload type - #define G722_PAYLOAD_TYPE 9 +/// GSM payload type +#define G722_PAYLOAD_TYPE 9 - /// GSM bitrate (bits/sec) - #define G722_BITRATE 64000 +/// GSM bitrate (bits/sec) +#define G722_BITRATE 64000 - class G722Codec: public Codec - { - protected: +class G722Codec: public Codec +{ +protected: void* mEncoder; void* mDecoder; - public: +public: class G722Factory: public Factory { public: - G722Factory(); + G722Factory(); - const char* name(); - int samplerate(); - int payloadType(); - PCodec create(); + const char* name(); + int samplerate(); + int payloadType(); + PCodec create(); }; G722Codec(); virtual ~G722Codec(); @@ -376,26 +376,26 @@ namespace MT int plc(int lostFrames, void* output, int outputCapacity); //unsigned GetSamplerate() { return 16000; } - }; +}; - class GsmHrCodec: public Codec - { - protected: +class GsmHrCodec: public Codec +{ +protected: void* mDecoder; - public: +public: class GsmHrFactory: public Factory { protected: - int mPtype; + int mPtype; public: - GsmHrFactory(int ptype); + GsmHrFactory(int ptype); - const char* name() override; - int samplerate() override; - int payloadType() override; - PCodec create() override; + const char* name() override; + int samplerate() override; + int payloadType() override; + PCodec create() override; }; GsmHrCodec(); @@ -410,7 +410,7 @@ namespace MT int encode(const void* input, int inputBytes, void* output, int outputCapacity) override; int decode(const void* input, int inputBytes, void* output, int outputCapacity) override; int plc(int lostFrames, void* output, int outputCapacity) override; - }; +}; } #endif diff --git a/src/engine/media/MT_Codec.h b/src/engine/media/MT_Codec.h index dd608ae6..b6b1b8ad 100644 --- a/src/engine/media/MT_Codec.h +++ b/src/engine/media/MT_Codec.h @@ -16,33 +16,33 @@ namespace MT { - class Codec; - typedef std::shared_ptr PCodec; +class Codec; +typedef std::shared_ptr PCodec; - class CodecMap: public std::map - { - }; +class CodecMap: public std::map +{ +}; - class Codec - { - public: +class Codec +{ +public: class Factory { public: - virtual ~Factory() {} - virtual const char* name() = 0; - virtual int samplerate() = 0; - virtual int payloadType() = 0; - virtual PCodec create() = 0; + virtual ~Factory() {} + virtual const char* name() = 0; + virtual int samplerate() = 0; + virtual int payloadType() = 0; + virtual PCodec create() = 0; - virtual int channels(); + virtual int channels(); #if defined(USE_RESIP_INTEGRATION) - typedef std::map CodecMap; - virtual void create(CodecMap& codecs); - virtual void updateSdp(resip::SdpContents::Session::Medium::CodecContainer& codecs, SdpDirection direction); - // Returns payload type from chosen codec if success. -1 is returned for negative result. - virtual int processSdp(const resip::SdpContents::Session::Medium::CodecContainer& codecs, SdpDirection direction); - resip::Codec resipCodec(); + typedef std::map CodecMap; + virtual void create(CodecMap& codecs); + virtual void updateSdp(resip::SdpContents::Session::Medium::CodecContainer& codecs, SdpDirection direction); + // Returns payload type from chosen codec if success. -1 is returned for negative result. + virtual int processSdp(const resip::SdpContents::Session::Medium::CodecContainer& codecs, SdpDirection direction); + resip::Codec resipCodec(); #endif }; virtual ~Codec() {} @@ -59,6 +59,6 @@ namespace MT // Returns size of codec in memory virtual int getSize() const { return 0; }; - }; +}; } #endif diff --git a/src/engine/media/MT_CodecList.h b/src/engine/media/MT_CodecList.h index 5a81b439..58f602b3 100644 --- a/src/engine/media/MT_CodecList.h +++ b/src/engine/media/MT_CodecList.h @@ -19,41 +19,41 @@ namespace MT { - class CodecList - { - public: +class CodecList +{ +public: struct Settings { - bool mWrapIuUP = false; - bool mSkipDecode = false; + bool mWrapIuUP = false; + bool mSkipDecode = false; - // AMR payload types - std::set mAmrWbPayloadType = { MT_AMRWB_PAYLOADTYPE }; - std::set mAmrNbPayloadType = { MT_AMRNB_PAYLOADTYPE }; - std::set mAmrWbOctetPayloadType = { MT_AMRWB_OCTET_PAYLOADTYPE }; - std::set mAmrNbOctetPayloadType = { MT_AMRNB_OCTET_PAYLOADTYPE }; + // AMR payload types + std::set mAmrWbPayloadType = { MT_AMRWB_PAYLOADTYPE }; + std::set mAmrNbPayloadType = { MT_AMRNB_PAYLOADTYPE }; + std::set mAmrWbOctetPayloadType = { MT_AMRWB_OCTET_PAYLOADTYPE }; + std::set mAmrNbOctetPayloadType = { MT_AMRNB_OCTET_PAYLOADTYPE }; - bool isAmrWb(int ptype) const { return mAmrWbOctetPayloadType.count(ptype) > 0 || mAmrWbPayloadType.count(ptype) > 0; } - bool isAmrNb(int ptype) const { return mAmrNbOctetPayloadType.count(ptype) > 0 || mAmrNbPayloadType.count(ptype) > 0; } + bool isAmrWb(int ptype) const { return mAmrWbOctetPayloadType.count(ptype) > 0 || mAmrWbPayloadType.count(ptype) > 0; } + bool isAmrNb(int ptype) const { return mAmrNbOctetPayloadType.count(ptype) > 0 || mAmrNbPayloadType.count(ptype) > 0; } - int mIsac16KPayloadType = MT_ISAC16K_PAYLOADTYPE; - int mIsac32KPayloadType = MT_ISAC32K_PAYLOADTYPE; - int mIlbc20PayloadType = MT_ILBC20_PAYLOADTYPE; - int mIlbc30PayloadType = MT_ILBC30_PAYLOADTYPE; - int mGsmFrPayloadType = 3; // GSM is codec with fixed payload type. But sometimes it has to be overwritten. - int mGsmFrPayloadLength = 33; // Expected GSM payload length - int mGsmHrPayloadType = MT_GSMHR_PAYLOADTYPE; - int mGsmEfrPayloadType = MT_GSMEFR_PAYLOADTYPE; + int mIsac16KPayloadType = MT_ISAC16K_PAYLOADTYPE; + int mIsac32KPayloadType = MT_ISAC32K_PAYLOADTYPE; + int mIlbc20PayloadType = MT_ILBC20_PAYLOADTYPE; + int mIlbc30PayloadType = MT_ILBC30_PAYLOADTYPE; + int mGsmFrPayloadType = 3; // GSM is codec with fixed payload type. But sometimes it has to be overwritten. + int mGsmFrPayloadLength = 33; // Expected GSM payload length + int mGsmHrPayloadType = MT_GSMHR_PAYLOADTYPE; + int mGsmEfrPayloadType = MT_GSMEFR_PAYLOADTYPE; - struct OpusSpec - { - int mPayloadType = 0; - int mRate = 0; - int mChannels = 0; - }; - std::vector mOpusSpec; + struct OpusSpec + { + int mPayloadType = 0; + int mRate = 0; + int mChannels = 0; + }; + std::vector mOpusSpec; - static Settings DefaultSettings; + static Settings DefaultSettings; }; CodecList(const Settings& settings); @@ -64,15 +64,15 @@ namespace MT int findCodec(const std::string& name) const; void fillCodecMap(CodecMap& cm); - protected: +protected: typedef std::vector FactoryList; FactoryList mFactoryList; Settings mSettings; - }; +}; - class CodecListPriority - { - public: +class CodecListPriority +{ +public: CodecListPriority(); ~CodecListPriority(); @@ -80,16 +80,16 @@ namespace MT int count(const CodecList& cl) const; Codec::Factory& codecAt(const CodecList& cl, int index) const; - protected: +protected: struct Item { - int mCodecIndex; - int mPriority; + int mCodecIndex; + int mPriority; }; std::vector mPriorityList; static bool isNegativePriority(const CodecListPriority::Item& item); static bool compare(const Item& item1, const Item& item2); - }; +}; } #endif