83 lines
2.7 KiB
C++
83 lines
2.7 KiB
C++
/*
|
|
*******************************************************************************
|
|
* INCLUDE
|
|
*******************************************************************************
|
|
*/
|
|
#include "AudioAdaptablePipe.h"
|
|
|
|
namespace Video
|
|
{
|
|
namespace Core
|
|
{
|
|
/*
|
|
*******************************************************************************
|
|
* CLASS DEFINE
|
|
*******************************************************************************
|
|
*/
|
|
void AudioAdaptablePipe::onLink(Core::Component::Ptr pPrevious)
|
|
{
|
|
if (!frameQueues().empty() && frameQueues().firstComponent() != pPrevious)
|
|
throw Poco::LogicException(name() + ": Support only one previous component, conflict with: " +
|
|
pPrevious->name() + ", Current: " + frameQueues().firstComponent()->name());
|
|
|
|
frameQueues().add(pPrevious, name(), MediaType::AUDIO);
|
|
}
|
|
|
|
void AudioAdaptablePipe::onUnlink(Core::Component::Ptr pPrevious)
|
|
{
|
|
frameQueues().remove(pPrevious);
|
|
}
|
|
|
|
Frame::Ptr AudioAdaptablePipe::readFrame(uint32_t timeout)
|
|
{
|
|
if (previousComponents().size() == 0)
|
|
throw Poco::NotFoundException(name() + ": No previous components");
|
|
|
|
auto pFrameQueue = frameQueues().first();
|
|
while (true)
|
|
{
|
|
Frame::Ptr pFrame = nullptr;
|
|
if (!_pFrameAdapter.isNull())
|
|
{
|
|
pFrame = _pFrameAdapter->get();
|
|
if (!pFrame.isNull())
|
|
return pFrame;
|
|
}
|
|
|
|
pFrame = pFrameQueue->dequeue(timeout);
|
|
if (serialCodeWatcher().isChanged(pFrame->code, true))
|
|
{
|
|
auto pPrevious = previousComponents().first().cast<AudioComponent>();
|
|
|
|
auto inLayout = pPrevious->getChannelLayout();
|
|
auto inFormat = pPrevious->getSampleFormat();
|
|
auto inRate = pPrevious->getSampleRate();
|
|
auto outLayout = getChannelLayout();
|
|
auto outFormat = getSampleFormat();
|
|
auto outRate = getSampleRate();
|
|
|
|
if (inLayout != outLayout || inFormat != outFormat || inRate != outRate)
|
|
_pResample = AudioResample::create(inLayout, inFormat, inRate, outLayout, outFormat, outRate);
|
|
else
|
|
_pResample.reset();
|
|
|
|
if (inRate != outRate || pPrevious->getFrameSize() != getFrameSize())
|
|
_pFrameAdapter = new AudioFrameAdapter(outLayout, outFormat, getFrameSize(), outRate);
|
|
else
|
|
_pFrameAdapter.reset();
|
|
}
|
|
|
|
if (_pFrameAdapter.isNull() && _pResample.isNull())
|
|
return pFrame;
|
|
|
|
if (!_pResample.isNull())
|
|
pFrame = _pResample->process(pFrame);
|
|
|
|
if (!_pFrameAdapter.isNull())
|
|
_pFrameAdapter->put(pFrame);
|
|
else
|
|
return pFrame;
|
|
}
|
|
}
|
|
}
|
|
}
|