audio-drain/audio/drain/EndPointCallback.cpp

88 lines
3.1 KiB
C++
Raw Normal View History

/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
2016-10-02 21:41:55 +02:00
#include <audio/drain/EndPointCallback.hpp>
#include <audio/drain/debug.hpp>
2015-01-27 21:26:03 +01:00
2015-04-10 23:00:13 +02:00
audio::drain::EndPointCallback::EndPointCallback() :
2015-01-29 21:46:01 +01:00
m_outputFunction(nullptr),
2015-01-27 21:26:03 +01:00
m_inputFunction(nullptr) {
}
2015-01-29 21:46:01 +01:00
2015-04-10 23:00:13 +02:00
void audio::drain::EndPointCallback::init(playbackFunction _callback) {
2015-01-29 21:46:01 +01:00
m_outputFunction = _callback;
2015-04-10 23:00:13 +02:00
audio::drain::EndPoint::init();
2015-02-01 22:22:42 +01:00
m_type = "EndPointCallback";
}
2015-04-10 23:00:13 +02:00
void audio::drain::EndPointCallback::init(recordFunction _callback) {
2015-01-29 21:46:01 +01:00
m_inputFunction = _callback;
2015-04-10 23:00:13 +02:00
audio::drain::EndPoint::init();
2015-02-01 22:22:42 +01:00
m_type = "EndPointCallback";
2015-01-28 22:07:11 +01:00
}
2016-07-19 21:43:58 +02:00
ememory::SharedPtr<audio::drain::EndPointCallback> audio::drain::EndPointCallback::create(playbackFunction _callback) {
ememory::SharedPtr<audio::drain::EndPointCallback> tmp(new audio::drain::EndPointCallback());
2015-01-29 21:46:01 +01:00
tmp->init(_callback);
return tmp;
}
2016-07-19 21:43:58 +02:00
ememory::SharedPtr<audio::drain::EndPointCallback> audio::drain::EndPointCallback::create(recordFunction _callback) {
ememory::SharedPtr<audio::drain::EndPointCallback> tmp(new audio::drain::EndPointCallback());
2015-01-29 21:46:01 +01:00
tmp->init(_callback);
return tmp;
}
2015-04-10 23:00:13 +02:00
void audio::drain::EndPointCallback::configurationChange() {
audio::drain::EndPoint::configurationChange();
DRAIN_INFO("update : format=" << m_output.getFormat() << " map=" << m_input.getMap() << " freq=" << m_input.getFrequency() << " size=" << int32_t(m_formatSize));
m_needProcess = true;
}
2015-04-13 21:49:48 +02:00
bool audio::drain::EndPointCallback::process(audio::Time& _time,
2015-04-10 23:00:13 +02:00
void* _input,
size_t _inputNbChunk,
void*& _output,
size_t& _outputNbChunk){
audio::drain::AutoLogInOut tmpLog("EndPointCallback");
if (m_inputFunction != nullptr) {
// Call user ...
DRAIN_VERBOSE("call user set " << _inputNbChunk << "*" << m_input.getMap().size());
m_inputFunction(_input,
_time,
_inputNbChunk,
m_output.getFormat(),
m_output.getFrequency(),
m_output.getMap());
return true;
}
2015-01-27 21:26:03 +01:00
if (m_outputFunction != nullptr) {
// update buffer size ...
m_outputData.resize(_inputNbChunk*m_output.getMap().size()*m_formatSize);
2015-06-26 22:21:58 +02:00
// clean output to prevent errors ...
memset(&m_outputData[0], 0, m_outputData.size());
// call user
DRAIN_VERBOSE("call user get " << _inputNbChunk << "*" << m_output.getMap().size() << " map=" << m_output.getMap() << " datasize=" << int32_t(m_formatSize));
m_outputFunction(&m_outputData[0],
_time,
2015-01-27 21:26:03 +01:00
_inputNbChunk,
m_output.getFormat(),
m_output.getFrequency(),
m_output.getMap());
2015-01-27 21:26:03 +01:00
if (m_outputData.size() != _inputNbChunk*m_output.getMap().size()*m_formatSize) {
DRAIN_ERROR(" can not get enough data from user ... " << m_outputData.size() << " != " << _inputNbChunk*m_output.getMap().size());
return false;
}
2015-01-27 21:26:03 +01:00
_output = &m_outputData[0];
_outputNbChunk = _inputNbChunk;
return true;
}
return false;
}