2015-01-25 22:10:49 +01:00
|
|
|
/** @file
|
|
|
|
* @author Edouard DUPIN
|
|
|
|
* @copyright 2011, Edouard DUPIN, all right reserved
|
|
|
|
* @license APACHE v2.0 (see license file)
|
|
|
|
*/
|
|
|
|
|
2015-04-10 23:00:13 +02:00
|
|
|
#include <audio/drain/EndPointCallback.h>
|
|
|
|
#include <audio/drain/debug.h>
|
2015-01-25 22:10:49 +01:00
|
|
|
|
2015-01-27 21:26:03 +01:00
|
|
|
#undef __class__
|
|
|
|
#define __class__ "EndPointCallback"
|
|
|
|
|
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-25 22:10:49 +01:00
|
|
|
|
|
|
|
}
|
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-01-25 22:10:49 +01:00
|
|
|
}
|
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
|
|
|
}
|
2015-01-25 22:10:49 +01:00
|
|
|
|
2015-04-10 23:00:13 +02:00
|
|
|
std11::shared_ptr<audio::drain::EndPointCallback> audio::drain::EndPointCallback::create(playbackFunction _callback) {
|
|
|
|
std11::shared_ptr<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
|
|
|
std11::shared_ptr<audio::drain::EndPointCallback> audio::drain::EndPointCallback::create(recordFunction _callback) {
|
|
|
|
std11::shared_ptr<audio::drain::EndPointCallback> tmp(new audio::drain::EndPointCallback());
|
2015-01-29 21:46:01 +01:00
|
|
|
tmp->init(_callback);
|
|
|
|
return tmp;
|
|
|
|
}
|
2015-01-25 22:10:49 +01:00
|
|
|
|
2015-04-10 23:00:13 +02:00
|
|
|
void audio::drain::EndPointCallback::configurationChange() {
|
|
|
|
audio::drain::EndPoint::configurationChange();
|
2015-02-05 21:33:12 +01:00
|
|
|
DRAIN_INFO("update : format=" << m_output.getFormat() << " map=" << m_input.getMap() << " freq=" << m_input.getFrequency() << " size=" << int32_t(m_formatSize));
|
2015-01-25 22:10:49 +01:00
|
|
|
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");
|
2015-02-17 21:08:15 +01:00
|
|
|
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-01-25 22:10:49 +01:00
|
|
|
// call user
|
2015-02-05 21:33:12 +01:00
|
|
|
DRAIN_VERBOSE("call user get " << _inputNbChunk << "*" << m_output.getMap().size() << " map=" << m_output.getMap() << " datasize=" << int32_t(m_formatSize));
|
2015-02-17 21:08:15 +01:00
|
|
|
m_outputFunction(&m_outputData[0],
|
|
|
|
_time,
|
2015-01-27 21:26:03 +01:00
|
|
|
_inputNbChunk,
|
2015-02-17 21:08:15 +01:00
|
|
|
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) {
|
2015-02-05 21:33:12 +01:00
|
|
|
DRAIN_ERROR(" can not get enough data from user ... " << m_outputData.size() << " != " << _inputNbChunk*m_output.getMap().size());
|
2015-01-25 22:10:49 +01:00
|
|
|
return false;
|
|
|
|
}
|
2015-01-27 21:26:03 +01:00
|
|
|
_output = &m_outputData[0];
|
2015-01-25 22:10:49 +01:00
|
|
|
_outputNbChunk = _inputNbChunk;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|