audio-drain/drain/EndPointCallback.cpp

86 lines
2.9 KiB
C++
Raw Normal View History

/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license APACHE v2.0 (see license file)
*/
#include "debug.h"
2015-02-05 19:10:53 +01:00
#include <drain/EndPointCallback.h>
2015-01-27 21:26:03 +01:00
#undef __class__
#define __class__ "EndPointCallback"
2015-02-05 19:10:53 +01:00
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-02-05 19:10:53 +01:00
void drain::EndPointCallback::init(needDataFunction _callback) {
2015-01-29 21:46:01 +01:00
m_outputFunction = _callback;
2015-02-05 19:10:53 +01:00
drain::EndPoint::init();
2015-02-01 22:22:42 +01:00
m_type = "EndPointCallback";
}
2015-02-05 19:10:53 +01:00
void drain::EndPointCallback::init(haveNewDataFunction _callback) {
2015-01-29 21:46:01 +01:00
m_inputFunction = _callback;
2015-02-05 19:10:53 +01:00
drain::EndPoint::init();
2015-02-01 22:22:42 +01:00
m_type = "EndPointCallback";
2015-01-28 22:07:11 +01:00
}
2015-02-05 19:10:53 +01:00
std::shared_ptr<drain::EndPointCallback> drain::EndPointCallback::create(needDataFunction _callback) {
std::shared_ptr<drain::EndPointCallback> tmp(new drain::EndPointCallback());
2015-01-29 21:46:01 +01:00
tmp->init(_callback);
return tmp;
}
2015-02-05 19:10:53 +01:00
std::shared_ptr<drain::EndPointCallback> drain::EndPointCallback::create(haveNewDataFunction _callback) {
std::shared_ptr<drain::EndPointCallback> tmp(new drain::EndPointCallback());
2015-01-29 21:46:01 +01:00
tmp->init(_callback);
return tmp;
}
2015-02-05 19:10:53 +01:00
void drain::EndPointCallback::configurationChange() {
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-02-05 19:10:53 +01:00
bool drain::EndPointCallback::process(std::chrono::system_clock::time_point& _time,
void* _input, // uneeded
size_t _inputNbChunk, // requested number of sample ...
void*& _output,
size_t& _outputNbChunk){
2015-02-05 19:10:53 +01:00
drain::AutoLogInOut tmpLog("EndPointCallback");
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);
// call user
DRAIN_VERBOSE("call user get " << _inputNbChunk << "*" << m_output.getMap().size() << " map=" << m_output.getMap() << " datasize=" << int32_t(m_formatSize));
2015-01-27 21:26:03 +01:00
m_outputFunction(_time,
_inputNbChunk,
m_output.getMap(),
&m_outputData[0],
m_output.getFormat());
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;
}
2015-01-27 21:26:03 +01:00
if (m_inputFunction != nullptr) {
// Call user ...
DRAIN_VERBOSE("call user set " << _inputNbChunk << "*" << m_input.getMap().size());
2015-01-27 21:26:03 +01:00
m_inputFunction(_time,
_inputNbChunk,
m_input.getMap(),
_input,
m_input.getFormat());
return true;
}
return false;
}