2016-10-04 21:42:09 +02:00
|
|
|
/** @file
|
|
|
|
* @author Edouard DUPIN
|
|
|
|
* @copyright 2014, Edouard DUPIN, all right reserved
|
|
|
|
* @license APACHE v2.0 (see license file)
|
|
|
|
*/
|
|
|
|
#include <audio/blockEngine/debug.hpp>
|
|
|
|
#include <audio/blockEngine/base/ReceiverFile.hpp>
|
|
|
|
|
|
|
|
|
|
|
|
audio::blockEngine::ReceiverFile::ReceiverFile() :
|
2018-06-19 22:31:29 +02:00
|
|
|
m_file(null),
|
2016-10-04 21:42:09 +02:00
|
|
|
m_channels(4),
|
|
|
|
m_frequency(16000),
|
|
|
|
m_requestSize(256),
|
|
|
|
m_processStarted(false) {
|
|
|
|
// set input :
|
|
|
|
m_io.insert(
|
2017-10-09 10:25:41 +02:00
|
|
|
etk::Pair<etk::String, audio::blockEngine::Block::IOProperty>(
|
2016-10-04 21:42:09 +02:00
|
|
|
"in",
|
|
|
|
audio::blockEngine::Block::IOProperty(
|
|
|
|
audio::blockEngine::Block::ioInput,
|
|
|
|
"{ type:'audio', compression:'raw', frequency:16000, channel:4, format:'int16_t' }",
|
2018-06-19 22:31:29 +02:00
|
|
|
null
|
2016-10-04 21:42:09 +02:00
|
|
|
) ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int32_t audio::blockEngine::ReceiverFile::init() {
|
|
|
|
m_file = new etk::FSNode("ouput.raw");
|
2018-06-19 22:31:29 +02:00
|
|
|
if (m_file == null) {
|
2016-10-04 21:42:09 +02:00
|
|
|
ABE_ERROR("Can not allocate the output file ...");
|
|
|
|
return audio::blockEngine::ERR_FAIL;
|
|
|
|
}
|
|
|
|
if (m_file->fileOpenWrite() == false) {
|
|
|
|
ABE_ERROR("Can not open the output file ...");
|
|
|
|
return audio::blockEngine::ERR_FAIL;
|
|
|
|
}
|
|
|
|
return audio::blockEngine::ERR_NONE;
|
|
|
|
};
|
|
|
|
|
|
|
|
int32_t audio::blockEngine::ReceiverFile::unInit() {
|
|
|
|
ABE_DEBUG("un-init Stream ...");
|
2018-06-19 22:31:29 +02:00
|
|
|
if (m_file == null) {
|
2016-10-04 21:42:09 +02:00
|
|
|
return audio::blockEngine::ERR_NONE;
|
|
|
|
}
|
|
|
|
if (m_file->fileClose() == false) {
|
|
|
|
ABE_ERROR("Can not close the input file ...");
|
|
|
|
delete(m_file);
|
2018-06-19 22:31:29 +02:00
|
|
|
m_file = null;
|
2016-10-04 21:42:09 +02:00
|
|
|
return audio::blockEngine::ERR_FAIL;
|
|
|
|
}
|
|
|
|
delete(m_file);
|
2018-06-19 22:31:29 +02:00
|
|
|
m_file = null;
|
2016-10-04 21:42:09 +02:00
|
|
|
return audio::blockEngine::ERR_NONE;
|
|
|
|
};
|
|
|
|
|
|
|
|
int32_t audio::blockEngine::ReceiverFile::start() {
|
|
|
|
ABE_DEBUG("Start stream ...");
|
|
|
|
m_processStarted = true;
|
|
|
|
return audio::blockEngine::ERR_NONE;
|
|
|
|
};
|
|
|
|
|
|
|
|
int32_t audio::blockEngine::ReceiverFile::stop() {
|
|
|
|
ABE_DEBUG("Stop Stream ...");
|
|
|
|
m_processStarted = false;
|
|
|
|
return audio::blockEngine::ERR_NONE;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
int32_t audio::blockEngine::ReceiverFile::pull(double _currentTime, int32_t _request, float _timeout) {
|
|
|
|
auto it = m_io.find("out");
|
|
|
|
if (it == m_io.end()) {
|
|
|
|
ABE_WARNING("request to pull data with no output !!!");
|
|
|
|
return audio::blockEngine::ERR_FAIL;
|
|
|
|
}
|
|
|
|
audio::blockEngine::BufferStream* buffer = dynamic_cast<audio::blockEngine::BufferStream*>(it->second.m_buffer);
|
|
|
|
//ABE_ERROR("Generate data, request : " << _request << " at time : " << _currentTime);
|
2018-06-19 22:31:29 +02:00
|
|
|
if (buffer == null) {
|
2016-10-04 21:42:09 +02:00
|
|
|
// !! impossible case => a buffer can not be removed ...
|
|
|
|
ABE_ERROR("Buffer has been removed... OR change type ...");
|
|
|
|
return audio::blockEngine::ERR_FAIL;
|
|
|
|
}
|
|
|
|
//request outpuffer needed size :
|
|
|
|
buffer->setProperty(_request);
|
|
|
|
uint8_t* data = buffer->getData();
|
2018-06-19 22:31:29 +02:00
|
|
|
if (m_file == null) {
|
2016-10-04 21:42:09 +02:00
|
|
|
ABE_ERROR("Buffer output error ==> !!ERROR!!");
|
|
|
|
return audio::blockEngine::ERR_FAIL;
|
|
|
|
}
|
|
|
|
int64_t nbRead = m_file->fileRead(data, sizeof(uint8_t), _request);
|
|
|
|
buffer->setAvaillableSize(nbRead);
|
|
|
|
return audio::blockEngine::ERR_NONE;
|
|
|
|
}
|
|
|
|
*/
|