[DEV] basics ideas of buffer bloks and processing

This commit is contained in:
Edouard DUPIN 2014-03-06 21:53:51 +01:00
parent c5970f769f
commit fa2639a2a8
22 changed files with 347 additions and 197 deletions

View File

@ -6,6 +6,88 @@
* @license BSD v3 (see license file)
*/
#include <eaudiofx/debug.h>
#include <eaudiofx/core/Block.h>
#include <eaudiofx/core/Buffer.h>
#include <eaudiofx/core/BlockMeta.h>
eaudiofx::Block::Block(void) :
m_uid(0),
m_type(),
m_parent(NULL) {
static size_t id=0;
m_uid = id;
id++;
}
eaudiofx::Block::~Block(void) {
for (auto &it : m_io) {
if (it.second.m_buffer == NULL) {
continue;
}
if (it.second.m_internal != true) {
continue;
}
// just remove pointer from reference system.
eaudiofx::Buffer* tmp = it.second.m_buffer;
it.second.m_buffer = NULL;
// Notify all element that a buffer is removed.
subRemoveBuffer(tmp);
delete(tmp);
}
}
void eaudiofx::Block::subRemoveBuffer(const eaudiofx::Buffer* _buffer) {
if (_buffer == NULL) {
return;
}
if (m_parent == NULL) {
onRemoveBuffer(_buffer);
} else {
m_parent->subRemoveBuffer(_buffer);
}
}
void eaudiofx::Block::onRemoveBuffer(const eaudiofx::Buffer* _buffer) {
// For every buffer, remove internal reference...
for (auto &it : m_io) {
if (it.second.m_buffer == _buffer) {
it.second.m_buffer = NULL;
}
}
}
int32_t eaudiofx::Block::linkBuffer(eaudiofx::Buffer* _buffer, const std::string& _name) {
for (auto &it : m_io) {
if (it.first == _name) {
if (it.second.m_type == ioOutput) {
EAUDIOFX_ERROR("[" << getUID() << "Can not overwrite output buffer...");
return eaudiofx::ERR_FORBIDEN;
}
it.second.m_buffer = _buffer;
return eaudiofx::ERR_NONE;
}
}
return eaudiofx::ERR_NO_IO;
}
int32_t eaudiofx::Block::getBuffer(eaudiofx::Buffer*& _buffer, const std::string& _name) {
for (auto &it : m_io) {
if (it.first == _name) {
if (it.second.m_type == ioInput) {
EAUDIOFX_ERROR("[" << getUID() << "Can not Request Input buffer...");
return eaudiofx::ERR_FORBIDEN;
}
if (it.second.m_type == ioParameter) {
EAUDIOFX_ERROR("[" << getUID() << "Can not Request Parameter buffer...");
return eaudiofx::ERR_FORBIDEN;
}
_buffer = it.second.m_buffer;
return eaudiofx::ERR_NONE;
}
}
return eaudiofx::ERR_NO_IO;
}

View File

@ -10,29 +10,87 @@
#define __EAUDIOFX_BLOCK_H__
#include <eaudiofx/core/audio.h>
#include <eaudiofx/core/Buffer.h>
#include <string>
#include <mutex>
#include <map>
namespace eaudiofx {
class Buffer;
class BlockMeta;
enum blockType {
blockTypeUnknow,
blockTypeFilter,
blockTypeGenerator,
blockTypeReceiver,
blockTypeDecoder,
blockTypeEncoder,
};
class Block {
public:
Block(void) {};
~Block(void) {};
Block(void);
~Block(void);
protected:
std::mutex m_mutex; //!< Block mutex access
private:
size_t m_uid; //!< Unique block ID
public:
/**
* @brief Get the Block Unique ID
* @return the UID
*/
size_t getUID(void) {
return m_uid;
}
private:
std::string m_name; //!< name of the block
public:
/**
* @brief Set the block name
* @param[in] _name New name of the Block
*/
void setName(const std::string& _name) {
virtual void setName(const std::string& _name) {
m_name = _name;
}
/**
* @brief Set the block name
* @brief Set the block name.
* @return The block name.
*/
const std::string& setName(void) {
virtual const std::string& setName(void) {
return m_name;
}
private:
enum blockType m_type; // Type of the current block
public:
/**
* @brief Get block type
*/
virtual enum blockType getType(void) {
return m_type;
};
protected:
/**
* @brief Set type of the block ==> detect generator and receiver
*/
virtual void setType(enum blockType _type) {
m_type = _type;
};
protected:
eaudiofx::BlockMeta* m_parent;
public:
/**
* @brief Get parrent ob this block
* @return Pointer on the parrent if one is set.
*/
virtual eaudiofx::BlockMeta* getParrent(void) {
return m_parent;
};
/**
* @brief Set the parrent pointer.
* @param[in] _meta Pointer on the parrent.
*/
virtual void setParrent(eaudiofx::BlockMeta* _meta) {
m_parent = _meta;
};
protected:
// TODO : set properties ...
public:
@ -48,13 +106,100 @@ namespace eaudiofx {
};
public:
/**
*
* @brief Call by downstream to request some data
* @param[in] _currentTime Current stream time (in second)
* @param[in] _requestTime Data requested (can be chunk number 256 samples, or data byte for stream) (-1 for automatic)
* @param[in] _timeout system time to be obsolet (for realTime streaming) (-1 for no realTime streaming)
* @return generic error
*/
virtual int32_t push(int32_t _interface, eaudiofx::Buffer& _buffer, float _timeout) { };
virtual int32_t pull(double _currentTime, int32_t _request, float _timeout) {
return eaudiofx::ERR_NONE;
};
/**
*
* @brief Get The total stream size (in byte for streaming byte element, in second for time streaming)
* @param[out] _value Get total streaming time (-1 for unknown)
* @return generic error
*/
virtual int32_t pull(int32_t _interface, eaudiofx::Buffer& _buffer, float _timeout) { };
virtual int32_t getTotal(double& _value) {
_value = -1;
return eaudiofx::ERR_NONE;
};
/**
* @brief Seek to a specific position in the stream (in byte for streaming byte element, in second for time streaming)
* @param[out] _pos position to seek (0 for starting)
* @return generic error
*/
virtual int32_t seekTo(double _pos) {
return eaudiofx::ERR_NONE;
};
/**
* @brief Request a flush of the current buffer
* @param[in] _currentTime Current stream time (in second)
* @param[in] _timeout system time to be obsolet (for realTime streaming) (-1 for no realTime streaming)
* @return generic error
*/
virtual int32_t flush(double _currentTime, float _timeout) {
return eaudiofx::ERR_NONE;
};
/**
* @brief Reset the block
* @return generic error
*/
virtual int32_t reset(void) {
return eaudiofx::ERR_NONE;
};
public:
/**
* @brief Call when a block is removed from the system (current)
* @param[in] _block Pointer on the removed block
*/
virtual void onRemoveBlock(const eaudiofx::Block* _block) {};
/**
* @brief Call when a buffer is removed from the system (current).
* @param[in] _buffer Pointer on the removed buffer.
*/
virtual void onRemoveBuffer(const eaudiofx::Buffer* _buffer);
/**
* @brief A child call his parrent that it is removing a buffer.
* @param[in] _buffer Pointer on the removed buffer.
*/
virtual void subRemoveBuffer(const eaudiofx::Buffer* _buffer);
protected:
enum typeIO {
ioUnknow,
ioInput,
ioOutput,
ioParameter,
};
class IOProperty {
public:
enum typeIO m_type;
std::string m_description;
bool m_internal;
eaudiofx::Buffer* m_buffer;
IOProperty(void) :
m_type(ioUnknow),
m_internal(false),
m_buffer(NULL) {
}
};
std::map<std::string, eaudiofx::Block::IOProperty> m_io; //!< All IO in the Block
/**
* @brief Link the provided buffer to the IO name.
* @param[in] _buffer Pointer on the buffer to link.
* @param[in] _name Name of the IO;
* @return A generic error.
*/
virtual int32_t linkBuffer(eaudiofx::Buffer* _buffer, const std::string& _name);
/**
* @brief Request a buffer pointer on the IO named.
* @param[out] _buffer Pointer on the buffer to link.
* @param[in] _name Name of the IO;
* @return A generic error.
*/
virtual int32_t getBuffer(eaudiofx::Buffer*& _buffer, const std::string& _name);
};
};

View File

@ -1,11 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2014, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#include <eaudiofx/core/BlockDecoder.h>

View File

@ -1,24 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2014, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#ifndef __EAUDIOFX_BLOCK_DECODER_H__
#define __EAUDIOFX_BLOCK_DECODER_H__
#include <eaudiofx/core/Block.h>
namespace eaudiofx {
class BlockDecoder : public eaudiofx::Block {
public:
BlockDecoder(void) {};
~BlockDecoder(void) {};
};
};
#endif

View File

@ -1,11 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2014, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#include <eaudiofx/core/BlockEncoder.h>

View File

@ -1,25 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2014, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#ifndef __EAUDIOFX_BLOCK_ENCODER_H__
#define __EAUDIOFX_BLOCK_ENCODER_H__
#include <eaudiofx/core/Block.h>
namespace eaudiofx {
class BlockEncoder : public eaudiofx::Block {
public:
BlockEncoder(void) {};
~BlockEncoder(void) {};
};
};
#endif

View File

@ -0,0 +1,27 @@
/**
* @author Edouard DUPIN
*
* @copyright 2014, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#include <eaudiofx/core/BlockMeta.h>
eaudiofx::BlockMeta::BlockMeta(void) {
}
eaudiofx::BlockMeta::~BlockMeta(void) {
for (auto &it : m_list) {
if (it == NULL) {
continue;
}
eaudiofx::Block* tmp = it;
it = NULL;
delete(tmp);
}
}

28
eaudiofx/core/BlockMeta.h Normal file
View File

@ -0,0 +1,28 @@
/**
* @author Edouard DUPIN
*
* @copyright 2014, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#ifndef __EAUDIOFX_BLOCK_META_H__
#define __EAUDIOFX_BLOCK_META_H__
#include <eaudiofx/core/Block.h>
#include <vector>
namespace eaudiofx {
class BlockMeta : public eaudiofx::Block {
public:
BlockMeta(void);
~BlockMeta(void);
private:
std::vector<eaudiofx::Block*> m_list; //!< list of all block to process.
};
};
#endif

View File

@ -10,12 +10,19 @@
#define __EAUDIOFX_BUFFER_H__
#include <eaudiofx/core/audio.h>
#include <eaudiofx/core/Block.h>
namespace eaudiofx {
class Block;
class Buffer {
public:
Buffer(void) {};
Buffer(eaudiofx::Block& _parent) :
m_parent(_parent) {
};
~Buffer(void) {};
protected:
eaudiofx::Block& m_parent; //!< parrent Block of this Buffer
protected:
double m_timestamp; //!< current buffer time;
double m_time; //!< current buffer data time size;

View File

@ -9,7 +9,8 @@
#include <eaudiofx/core/BufferAudio.h>
#include <eaudiofx/debug.h>
eaudiofx::BufferAudio::BufferAudio(void) :
eaudiofx::BufferAudio::BufferAudio(eaudiofx::Block& _parent) :
eaudiofx::Buffer(_parent),
m_frequency(0),
m_nbChannel(0),
m_data(0),
@ -24,12 +25,12 @@ eaudiofx::BufferAudio::~BufferAudio(void) {
}
}
void eaudiofx::BufferAudio::resize(size_t _newSizeByte) {
void eaudiofx::BufferAudio::resize(size_t _newSize) {
if (m_data != NULL) {
delete[] m_data;
m_data = NULL;
}
m_data = new uint8_t[_newSizeByte];
m_data = new float[_newSize];
if (m_data == NULL) {
EAUDIOFX_ERROR("Can not allocate Buffer Audio");
}

View File

@ -14,20 +14,28 @@
namespace eaudiofx {
class BufferAudio : public eaudiofx::Buffer {
public:
BufferAudio(void);
BufferAudio(eaudiofx::Block& _parent);
~BufferAudio(void);
protected:
int32_t m_frequency;
int32_t m_nbChannel;
enum channelPosition m_channelType[MAX_NUMBER_OF_SIMULTANEOUS_CHANNEL];
protected:
uint8_t* m_data; //!< pointer on the data.
size_t m_allocated; //!< number of byte allocated
float* m_data; //!< pointer on the data.
size_t m_allocated; //!< number of sample allocated
protected:
/**
* @brief Reallocate the Buffer data.
*/
virtual void resize(size_t _newSizeByte);
virtual void resize(size_t _newSize);
public:
/**
* @brief Get the buffer casted in float*
* @return Pointer on the buffer with correct cast.
*/
float* getData(void) {
return m_data;
}
};
};

View File

@ -9,3 +9,8 @@
#include <eaudiofx/core/BufferAudioFreq.h>
eaudiofx::BufferAudioFreq::BufferAudioFreq(eaudiofx::Block& _parent) :
eaudiofx::BufferAudio(_parent) {
}

View File

@ -14,7 +14,7 @@
namespace eaudiofx {
class BufferAudioFreq : public eaudiofx::BufferAudio {
public:
BufferAudioFreq(void) {};
BufferAudioFreq(eaudiofx::Block& _parent);
~BufferAudioFreq(void) {};
};
};

View File

@ -9,3 +9,8 @@
#include <eaudiofx/core/BufferAudioRaw.h>
eaudiofx::BufferAudioRaw::BufferAudioRaw(eaudiofx::Block& _parent) :
eaudiofx::BufferAudio(_parent) {
}

View File

@ -14,7 +14,7 @@
namespace eaudiofx {
class BufferAudioRaw : public eaudiofx::BufferAudio {
public:
BufferAudioRaw(void) {};
BufferAudioRaw(eaudiofx::Block& _parent);
~BufferAudioRaw(void) {};
protected:
size_t m_allocatedSample; //!< generate with m_allocatedBytes/sizeof(**m_audioFormat**) / m_nbChannel;
@ -22,87 +22,6 @@ namespace eaudiofx {
size_t m_size; //!< number of sample for each channels provided in this buffer ... (write by the upstream (can be 0))
protected:
size_t m_sizeRequested; //!< in pull mode, number of sample for each channels requested by the next Filter
protected:
enum audioRawFormat m_audioFormat;
public:
/**
* @brief Get the buffer casted in void*
* @return Pointer on the buffer with correct cast.
*/
void* getDataVoid(void) {
return (void*)m_data;
}
/**
* @brief Get the buffer casted in int8_t*
* @return Pointer on the buffer with correct cast.
*/
int8_t* getDataI8(void) {
return (int8_t*)m_data;
}
/**
* @brief Get the buffer casted in int16_t*
* @return Pointer on the buffer with correct cast.
*/
int16_t* getDataI16(void) {
return (int16_t*)m_data;
}
/**
* @brief Get the buffer casted in int32_t*
* @return Pointer on the buffer with correct cast.
*/
int32_t* getDataI32(void) {
return (int32_t*)m_data;
}
/**
* @brief Get the buffer casted in int64_t*
* @return Pointer on the buffer with correct cast.
*/
int64_t* getDataI64(void) {
return (int64_t*)m_data;
}
/**
* @brief Get the buffer casted in uint8_t*
* @return Pointer on the buffer with correct cast.
*/
uint8_t* getDataU8(void) {
return (uint8_t*)m_data;
}
/**
* @brief Get the buffer casted in uint16_t*
* @return Pointer on the buffer with correct cast.
*/
uint16_t* getDataU16(void) {
return (uint16_t*)m_data;
}
/**
* @brief Get the buffer casted in uint32_t*
* @return Pointer on the buffer with correct cast.
*/
uint32_t* getDataU32(void) {
return (uint32_t*)m_data;
}
/**
* @brief Get the buffer casted in uint64_t*
* @return Pointer on the buffer with correct cast.
*/
uint64_t* getDataU64(void) {
return (uint64_t*)m_data;
}
/**
* @brief Get the buffer casted in float*
* @return Pointer on the buffer with correct cast.
*/
float* getDataF(void) {
return (float*)m_data;
}
/**
* @brief Get the buffer casted in double*
* @return Pointer on the buffer with correct cast.
*/
double* getDataD(void) {
return (double*)m_data;
}
};
};

View File

@ -9,3 +9,9 @@
#include <eaudiofx/core/BufferMessage.h>
eaudiofx::BufferMessage::BufferMessage(eaudiofx::Block& _parent, int32_t _message) :
eaudiofx::Buffer(_parent),
m_messageId(_message) {
}

View File

@ -21,7 +21,7 @@ namespace eaudiofx {
};
class BufferMessage : public eaudiofx::Buffer {
public:
BufferMessage(int32_t _message = bufferMessageEndOfStream) {};
BufferMessage(eaudiofx::Block& _parent, int32_t _message = eaudiofx::bufferMessageEndOfStream);
~BufferMessage(void) {};
protected:
int32_t m_messageId; //!< message ID
@ -37,7 +37,7 @@ namespace eaudiofx {
* @brief Set the message.
* @param[in] _message The ID of the message (if value is < 0 : custom message ...)
*/
int32_t getMessage(int32_t _messageId) {
void getMessage(int32_t _messageId) {
m_messageId = _messageId;
}
private:

View File

@ -8,7 +8,8 @@
#include <eaudiofx/core/BufferStream.h>
eaudiofx::BufferStream::BufferStream(void) {
eaudiofx::BufferStream::BufferStream(eaudiofx::Block& _parent) :
eaudiofx::Buffer(_parent) {
}
eaudiofx::BufferStream::~BufferStream(void) {

View File

@ -14,7 +14,7 @@
namespace eaudiofx {
class BufferStream : public eaudiofx::Buffer {
public:
BufferStream(void);
BufferStream(eaudiofx::Block& _parent);
~BufferStream(void);
protected:
void* m_data; //!< buffer data

View File

@ -11,12 +11,15 @@
#include <eaudiofx/core/audio.h>
#include <eaudiofx/core/Buffer.h>
#include <eaudiofx/core/Block.h>
#include <vector>
namespace eaudiofx {
class Processing {
public:
Processing(void) {};
~Processing(void) {};
private:
};
};

View File

@ -74,26 +74,11 @@ namespace eaudiofx {
#define CHANNEL_HEIGHT_TOP 0x04
#define CHANNEL_HEIGHT_BOTTOM 0x08
enum audioRawFormat {
// fix-point mode
audioRawFormatS8,
audioRawFormatS16,
audioRawFormatS32,
audioRawFormatS64,
audioRawFormatU8,
audioRawFormatU16,
audioRawFormatU32,
audioRawFormatU64,
// float mode
audioRawFormatFloat,
audioRawFormatDouble
enum {
ERR_NONE = 0,
ERR_FORBIDEN,
ERR_NO_IO,
};
};
#endif

View File

@ -14,11 +14,10 @@ def create(target):
'eaudiofx/debug.cpp',
'eaudiofx/core/Processing.cpp',
'eaudiofx/core/Block.cpp',
'eaudiofx/core/BlockMeta.cpp',
'eaudiofx/core/BlockGenerator.cpp',
'eaudiofx/core/BlockReceiver.cpp',
'eaudiofx/core/BlockFilter.cpp',
'eaudiofx/core/BlockEncoder.cpp',
'eaudiofx/core/BlockDecoder.cpp',
'eaudiofx/core/Buffer.cpp',
'eaudiofx/core/BufferMessage.cpp',
'eaudiofx/core/BufferStream.cpp',