From fac1f70107cfb9c3d43bbc8d4485f146949f3806 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Thu, 29 Jan 2015 21:46:01 +0100 Subject: [PATCH] [DEBUG] correct the segfault error --- airtalgo/Algo.cpp | 6 +++--- airtalgo/Algo.h | 8 +++++--- airtalgo/ChannelReorder.cpp | 13 ++++++++++--- airtalgo/ChannelReorder.h | 7 +++++-- airtalgo/EndPoint.h | 6 +++++- airtalgo/EndPointCallback.cpp | 30 +++++++++++++++++++++--------- airtalgo/EndPointCallback.h | 12 ++++++++---- airtalgo/EndPointRead.cpp | 12 +++++++++--- airtalgo/EndPointRead.h | 7 +++++-- airtalgo/EndPointWrite.cpp | 12 ++++++++---- airtalgo/EndPointWrite.h | 7 +++++-- airtalgo/FormatUpdate.cpp | 15 +++++++++++---- airtalgo/FormatUpdate.h | 7 +++++-- airtalgo/Process.cpp | 2 +- airtalgo/Resampler.cpp | 16 +++++++++++++--- airtalgo/Resampler.h | 5 ++++- 16 files changed, 118 insertions(+), 47 deletions(-) diff --git a/airtalgo/Algo.cpp b/airtalgo/Algo.cpp index 59b1b99..1349e0f 100644 --- a/airtalgo/Algo.cpp +++ b/airtalgo/Algo.cpp @@ -15,15 +15,15 @@ airtalgo::Algo::Algo() : m_formatSize(0), m_needProcess(false) { AIRTALGO_VERBOSE("CREATE ALGO"); +} + +void airtalgo::Algo::init() { // set notification callback : m_input.setCallback(std::bind(&airtalgo::Algo::configurationChange, this)); m_output.setCallback(std::bind(&airtalgo::Algo::configurationChange, this)); // first configure ==> update the internal parameters configurationChange(); } -airtalgo::Algo::~Algo() { - AIRTALGO_VERBOSE("Remove ALGO"); -} void airtalgo::Algo::configurationChange() { m_needProcess = false; diff --git a/airtalgo/Algo.h b/airtalgo/Algo.h index 741b4f1..7703345 100644 --- a/airtalgo/Algo.h +++ b/airtalgo/Algo.h @@ -15,6 +15,7 @@ #include #include #include +#include #include "debug.h" namespace airtalgo{ @@ -128,19 +129,20 @@ namespace airtalgo{ }; - class Algo { + class Algo : public std::enable_shared_from_this { protected: std::vector m_outputData; int8_t m_formatSize; //!< sample size - public: /** * @brief Constructor */ Algo(); + void init(); + public: /** * @brief Destructor */ - virtual ~Algo(); + virtual ~Algo() {}; protected: bool m_needProcess; //!< if no change, then no need to process, just forward buffer... IOFormatInterface m_input; //!< Input audio property diff --git a/airtalgo/ChannelReorder.cpp b/airtalgo/ChannelReorder.cpp index 890cc3a..e53f83b 100644 --- a/airtalgo/ChannelReorder.cpp +++ b/airtalgo/ChannelReorder.cpp @@ -16,10 +16,17 @@ airtalgo::ChannelReorder::ChannelReorder() { } -airtalgo::ChannelReorder::~ChannelReorder() { - AIRTALGO_INFO("Remove ChannelReorder"); + + +void airtalgo::ChannelReorder::init() { + airtalgo::Algo::init(); } +std::shared_ptr airtalgo::ChannelReorder::create() { + std::shared_ptr tmp(new airtalgo::ChannelReorder()); + tmp->init(); + return tmp; +} void airtalgo::ChannelReorder::configurationChange() { airtalgo::autoLogInOut("ChannelReorder (config)"); @@ -46,7 +53,7 @@ bool airtalgo::ChannelReorder::process(std::chrono::system_clock::time_point& _t size_t _inputNbChunk, void*& _output, size_t& _outputNbChunk) { - airtalgo::autoLogInOut("ChannelReorder"); + airtalgo::autoLogInOut tmpLog("ChannelReorder"); _outputNbChunk = _inputNbChunk; // check if we need to process: if (m_needProcess == false) { diff --git a/airtalgo/ChannelReorder.h b/airtalgo/ChannelReorder.h index 3f2fe00..afefa33 100644 --- a/airtalgo/ChannelReorder.h +++ b/airtalgo/ChannelReorder.h @@ -11,15 +11,18 @@ namespace airtalgo{ class ChannelReorder : public Algo { - public: + protected: /** * @brief Constructor */ ChannelReorder(); + void init(); + public: + static std::shared_ptr create(); /** * @brief Destructor */ - virtual ~ChannelReorder(); + virtual ~ChannelReorder() {}; protected: virtual void configurationChange(); public: diff --git a/airtalgo/EndPoint.h b/airtalgo/EndPoint.h index b1c9d3b..102034b 100644 --- a/airtalgo/EndPoint.h +++ b/airtalgo/EndPoint.h @@ -11,11 +11,15 @@ namespace airtalgo{ class EndPoint : public Algo { - public: + protected: /** * @brief Constructor */ EndPoint() {}; + void init() { + airtalgo::Algo::init(); + }; + public: /** * @brief Destructor */ diff --git a/airtalgo/EndPointCallback.cpp b/airtalgo/EndPointCallback.cpp index 3b3c514..adf2abd 100644 --- a/airtalgo/EndPointCallback.cpp +++ b/airtalgo/EndPointCallback.cpp @@ -10,20 +10,32 @@ #undef __class__ #define __class__ "EndPointCallback" -airtalgo::EndPointCallback::EndPointCallback(needDataFunction _callback) : - m_outputFunction(_callback), +airtalgo::EndPointCallback::EndPointCallback() : + m_outputFunction(nullptr), m_inputFunction(nullptr) { } -airtalgo::EndPointCallback::EndPointCallback(haveNewDataFunction _callback) : - m_outputFunction(nullptr), - m_inputFunction(_callback) { - + +void airtalgo::EndPointCallback::init(needDataFunction _callback) { + m_outputFunction = _callback; + airtalgo::EndPoint::init(); } -airtalgo::EndPointCallback::~EndPointCallback() { - AIRTALGO_INFO("Remove EndPointCallback"); +void airtalgo::EndPointCallback::init(haveNewDataFunction _callback) { + m_inputFunction = _callback; + airtalgo::EndPoint::init(); } +std::shared_ptr airtalgo::EndPointCallback::create(needDataFunction _callback) { + std::shared_ptr tmp(new airtalgo::EndPointCallback()); + tmp->init(_callback); + return tmp; +} + +std::shared_ptr airtalgo::EndPointCallback::create(haveNewDataFunction _callback) { + std::shared_ptr tmp(new airtalgo::EndPointCallback()); + tmp->init(_callback); + return tmp; +} void airtalgo::EndPointCallback::configurationChange() { airtalgo::EndPoint::configurationChange(); @@ -37,7 +49,7 @@ bool airtalgo::EndPointCallback::process(std::chrono::system_clock::time_point& size_t _inputNbChunk, // requested number of sample ... void*& _output, size_t& _outputNbChunk){ - airtalgo::autoLogInOut("EndPointCallback"); + airtalgo::autoLogInOut tmpLog("EndPointCallback"); if (m_outputFunction != nullptr) { // update buffer size ... m_outputData.resize(_inputNbChunk*m_output.getMap().size()*m_formatSize); diff --git a/airtalgo/EndPointCallback.h b/airtalgo/EndPointCallback.h index 8d4457a..5638e92 100644 --- a/airtalgo/EndPointCallback.h +++ b/airtalgo/EndPointCallback.h @@ -26,16 +26,20 @@ namespace airtalgo { private: needDataFunction m_outputFunction; haveNewDataFunction m_inputFunction; - public: + protected: /** * @brief Constructor */ - EndPointCallback(needDataFunction _callback); - EndPointCallback(haveNewDataFunction _callback); + EndPointCallback(); + void init(needDataFunction _callback); + void init(haveNewDataFunction _callback); + public: + static std::shared_ptr create(needDataFunction _callback); + static std::shared_ptr create(haveNewDataFunction _callback); /** * @brief Destructor */ - virtual ~EndPointCallback(); + virtual ~EndPointCallback() {}; virtual void configurationChange(); virtual bool process(std::chrono::system_clock::time_point& _time, void* _input, diff --git a/airtalgo/EndPointRead.cpp b/airtalgo/EndPointRead.cpp index ee11510..a71af41 100644 --- a/airtalgo/EndPointRead.cpp +++ b/airtalgo/EndPointRead.cpp @@ -14,10 +14,16 @@ airtalgo::EndPointRead::EndPointRead() { } -airtalgo::EndPointRead::~EndPointRead() { - AIRTALGO_INFO("Remove EndPointRead"); + +void airtalgo::EndPointRead::init() { + airtalgo::EndPoint::init(); } +std::shared_ptr airtalgo::EndPointRead::create() { + std::shared_ptr tmp(new airtalgo::EndPointRead()); + tmp->init(); + return tmp; +} void airtalgo::EndPointRead::configurationChange() { airtalgo::EndPoint::configurationChange(); @@ -30,7 +36,7 @@ bool airtalgo::EndPointRead::process(std::chrono::system_clock::time_point& _tim size_t _inputNbChunk, void*& _output, size_t& _outputNbChunk){ - airtalgo::autoLogInOut("EndPointRead"); + airtalgo::autoLogInOut tmpLog("EndPointRead"); return false; } diff --git a/airtalgo/EndPointRead.h b/airtalgo/EndPointRead.h index d698273..142117e 100644 --- a/airtalgo/EndPointRead.h +++ b/airtalgo/EndPointRead.h @@ -11,15 +11,18 @@ namespace airtalgo{ class EndPointRead : public EndPoint { - public: + protected: /** * @brief Constructor */ EndPointRead(); + void init(); + public: + static std::shared_ptr create(); /** * @brief Destructor */ - virtual ~EndPointRead(); + virtual ~EndPointRead() {}; virtual void configurationChange(); virtual bool process(std::chrono::system_clock::time_point& _time, void* _input, diff --git a/airtalgo/EndPointWrite.cpp b/airtalgo/EndPointWrite.cpp index 911c876..a290a1e 100644 --- a/airtalgo/EndPointWrite.cpp +++ b/airtalgo/EndPointWrite.cpp @@ -15,10 +15,14 @@ airtalgo::EndPointWrite::EndPointWrite() : } +void airtalgo::EndPointWrite::init() { + airtalgo::EndPoint::init(); +} -airtalgo::EndPointWrite::~EndPointWrite() { - AIRTALGO_INFO("Remove EndPointWrite"); - +std::shared_ptr airtalgo::EndPointWrite::create() { + std::shared_ptr tmp(new airtalgo::EndPointWrite()); + tmp->init(); + return tmp; } void airtalgo::EndPointWrite::configurationChange() { @@ -32,7 +36,7 @@ bool airtalgo::EndPointWrite::process(std::chrono::system_clock::time_point& _ti size_t _inputNbChunk, void*& _output, size_t& _outputNbChunk){ - airtalgo::autoLogInOut("EndPointWrite"); + airtalgo::autoLogInOut tmpLog("EndPointWrite"); //AIRTALGO_INFO(" nb Sample in buffer : " << m_tmpData.size()); if (m_function != nullptr) { if (m_tmpData.size() <= 20000) { diff --git a/airtalgo/EndPointWrite.h b/airtalgo/EndPointWrite.h index dcb2a38..197394e 100644 --- a/airtalgo/EndPointWrite.h +++ b/airtalgo/EndPointWrite.h @@ -21,15 +21,18 @@ namespace airtalgo{ std::vector m_tmpData; needDataFunctionWrite m_function; std::mutex m_mutex; - public: + protected: /** * @brief Constructor */ EndPointWrite(); + void init(); + public: + static std::shared_ptr create(); /** * @brief Destructor */ - virtual ~EndPointWrite(); + virtual ~EndPointWrite() {}; virtual void configurationChange(); virtual bool process(std::chrono::system_clock::time_point& _time, void* _input, diff --git a/airtalgo/FormatUpdate.cpp b/airtalgo/FormatUpdate.cpp index 189554d..19f6c6b 100644 --- a/airtalgo/FormatUpdate.cpp +++ b/airtalgo/FormatUpdate.cpp @@ -127,11 +127,18 @@ static void convert__float__to__int32(void* _input, void* _output, size_t _nbSam airtalgo::FormatUpdate::FormatUpdate() : - m_functionConvert(NULL) { + m_functionConvert(nullptr) { } -airtalgo::FormatUpdate::~FormatUpdate() { - AIRTALGO_INFO("Remove FormatUpdate"); + +void airtalgo::FormatUpdate::init() { + airtalgo::Algo::init(); +} + +std::shared_ptr airtalgo::FormatUpdate::create() { + std::shared_ptr tmp(new airtalgo::FormatUpdate()); + tmp->init(); + return tmp; } void airtalgo::FormatUpdate::configurationChange() { @@ -240,7 +247,7 @@ bool airtalgo::FormatUpdate::process(std::chrono::system_clock::time_point& _tim size_t _inputNbChunk, void*& _output, size_t& _outputNbChunk) { - airtalgo::autoLogInOut("FormatUpdate"); + airtalgo::autoLogInOut tmpLog("FormatUpdate"); // chack if we need to process: if (m_needProcess == false) { _output = _input; diff --git a/airtalgo/FormatUpdate.h b/airtalgo/FormatUpdate.h index 0786996..2da6a46 100644 --- a/airtalgo/FormatUpdate.h +++ b/airtalgo/FormatUpdate.h @@ -10,15 +10,18 @@ namespace airtalgo { class FormatUpdate : public Algo { - public: + protected: /** * @brief Constructor */ FormatUpdate(); + void init(); + public: + static std::shared_ptr create(); /** * @brief Destructor */ - virtual ~FormatUpdate(); + virtual ~FormatUpdate() {}; protected: virtual void configurationChange(); public: diff --git a/airtalgo/Process.cpp b/airtalgo/Process.cpp index 268829a..3517b8e 100644 --- a/airtalgo/Process.cpp +++ b/airtalgo/Process.cpp @@ -31,7 +31,7 @@ bool airtalgo::Process::push(std::chrono::system_clock::time_point& _time, size_t _nbChunk) { void* out = nullptr; size_t nbChunkOut; - AIRTALGO_VERBOSE(" Interface DIRECT "); + AIRTALGO_VERBOSE(" Process push"); process(_time, _data, _nbChunk, out, nbChunkOut); return true; } diff --git a/airtalgo/Resampler.cpp b/airtalgo/Resampler.cpp index 3a1c8ff..a4e3e79 100644 --- a/airtalgo/Resampler.cpp +++ b/airtalgo/Resampler.cpp @@ -19,8 +19,18 @@ airtalgo::Resampler::Resampler() : m_positionWrite(0) { } + +void airtalgo::Resampler::init() { + airtalgo::Algo::init(); +} + +std::shared_ptr airtalgo::Resampler::create() { + std::shared_ptr tmp(new airtalgo::Resampler()); + tmp->init(); + return tmp; +} + airtalgo::Resampler::~Resampler() { - AIRTALGO_INFO("Remove Resampler"); #ifdef HAVE_SPEEX_DSP_RESAMPLE if (m_speexResampler != nullptr) { speex_resampler_destroy(m_speexResampler); @@ -71,7 +81,7 @@ bool airtalgo::Resampler::process(std::chrono::system_clock::time_point& _time, size_t _inputNbChunk, void*& _output, size_t& _outputNbChunk) { - airtalgo::autoLogInOut("Resampler"); + airtalgo::autoLogInOut tmpLog("Resampler"); _outputNbChunk = 2048; // chack if we need to process: if (m_needProcess == false) { @@ -95,7 +105,7 @@ bool airtalgo::Resampler::process(std::chrono::system_clock::time_point& _time, AIRTALGO_VERBOSE(" Frame duration=" << nbInputTime); AIRTALGO_VERBOSE(" nbInput chunk=" << _inputNbChunk << " nbOutputChunk=" << nbOutputSample); - m_outputData.resize(_outputNbChunk*m_output.getMap().size()*m_formatSize); + m_outputData.resize(_outputNbChunk*m_output.getMap().size()*m_formatSize*16); _output = &(m_outputData[0]); if (m_speexResampler == nullptr) { AIRTALGO_ERROR(" No speex resampler"); diff --git a/airtalgo/Resampler.h b/airtalgo/Resampler.h index 9be6902..f6549fe 100644 --- a/airtalgo/Resampler.h +++ b/airtalgo/Resampler.h @@ -21,11 +21,14 @@ namespace airtalgo { #endif size_t m_positionRead; //!< For residual data in the buffer last read number of chunk size_t m_positionWrite; //!< Current pointer of writing new output data of resampler - public: + protected: /** * @brief Constructor */ Resampler(); + void init(); + public: + static std::shared_ptr create(); /** * @brief Destructor */