- add BufferQueue class to HL_Sync.*

- minor cleanup in CoreAudio support
This commit is contained in:
Dmytro Bogovych 2018-07-12 16:20:26 +03:00
parent b9acc5a622
commit b6400b6f81
3 changed files with 57 additions and 3 deletions

View File

@ -13,9 +13,9 @@
#include "Audio_Helper.h"
#include "Audio_Resampler.h"
#include "Audio_DataWindow.h"
#include "../Helper/HL_Pointer.h"
#include "../Helper/HL_ByteBuffer.h"
#include "../Helper/HL_Exception.h"
#include "../helper/HL_Pointer.h"
#include "../helper/HL_ByteBuffer.h"
#include "../helper/HL_Exception.h"
#include <AudioToolbox/AudioQueue.h>
// Define CoreAudio buffer time length in milliseconds

View File

@ -84,3 +84,39 @@ uint32_t TimeHelper::getDelta(uint32_t later, uint32_t earlier)
return 0;
}
// --------------- BufferQueue -----------------
BufferQueue::BufferQueue()
{
}
BufferQueue::~BufferQueue()
{
}
void BufferQueue::push(const void* data, int bytes)
{
std::unique_lock<std::mutex> l(mMutex);
Block b = std::make_shared<std::vector<unsigned char>>();
b->resize(bytes);
memcpy(b->data(), data, bytes);
mBlockList.push_back(b);
}
BufferQueue::Block BufferQueue::pull(std::chrono::milliseconds timeout)
{
std::unique_lock<std::mutex> l(mMutex);
std::cv_status status = std::cv_status::no_timeout;
while (mBlockList.empty() && status == std::cv_status::no_timeout)
status = mSignal.wait_for(l, timeout);
Block r;
if (status == std::cv_status::no_timeout)
r = mBlockList.front(); mBlockList.erase(mBlockList.begin());
return r;
}

View File

@ -10,6 +10,7 @@
#include <condition_variable>
#include <chrono>
#include <thread>
#include <vector>
typedef std::recursive_mutex Mutex;
typedef std::unique_lock<std::recursive_mutex> Lock;
@ -77,4 +78,21 @@ public:
static uint32_t getDelta(uint32_t later, uint32_t earlier);
};
class BufferQueue
{
public:
BufferQueue();
~BufferQueue();
typedef std::shared_ptr<std::vector<unsigned char>> Block;
void push(const void* data, int bytes);
Block pull(std::chrono::milliseconds timeout);
protected:
std::mutex mMutex;
std::condition_variable mSignal;
std::vector<Block> mBlockList;
};
#endif