- add BufferQueue class to HL_Sync.*
- minor cleanup in CoreAudio support
This commit is contained in:
parent
b9acc5a622
commit
b6400b6f81
|
|
@ -13,9 +13,9 @@
|
||||||
#include "Audio_Helper.h"
|
#include "Audio_Helper.h"
|
||||||
#include "Audio_Resampler.h"
|
#include "Audio_Resampler.h"
|
||||||
#include "Audio_DataWindow.h"
|
#include "Audio_DataWindow.h"
|
||||||
#include "../Helper/HL_Pointer.h"
|
#include "../helper/HL_Pointer.h"
|
||||||
#include "../Helper/HL_ByteBuffer.h"
|
#include "../helper/HL_ByteBuffer.h"
|
||||||
#include "../Helper/HL_Exception.h"
|
#include "../helper/HL_Exception.h"
|
||||||
#include <AudioToolbox/AudioQueue.h>
|
#include <AudioToolbox/AudioQueue.h>
|
||||||
|
|
||||||
// Define CoreAudio buffer time length in milliseconds
|
// Define CoreAudio buffer time length in milliseconds
|
||||||
|
|
|
||||||
|
|
@ -84,3 +84,39 @@ uint32_t TimeHelper::getDelta(uint32_t later, uint32_t earlier)
|
||||||
|
|
||||||
return 0;
|
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;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@
|
||||||
#include <condition_variable>
|
#include <condition_variable>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
typedef std::recursive_mutex Mutex;
|
typedef std::recursive_mutex Mutex;
|
||||||
typedef std::unique_lock<std::recursive_mutex> Lock;
|
typedef std::unique_lock<std::recursive_mutex> Lock;
|
||||||
|
|
@ -77,4 +78,21 @@ public:
|
||||||
static uint32_t getDelta(uint32_t later, uint32_t earlier);
|
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
|
#endif
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue