整理代码
This commit is contained in:
commit
c7b4e178ec
364 changed files with 59691 additions and 0 deletions
125
video/hisi/mpp5/AudioInput.cpp
Normal file
125
video/hisi/mpp5/AudioInput.cpp
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
/*
|
||||
*******************************************************************************
|
||||
* INCLUDE
|
||||
*******************************************************************************
|
||||
*/
|
||||
#include "AudioInput.h"
|
||||
#include "Util.h"
|
||||
|
||||
namespace Video
|
||||
{
|
||||
namespace MPP5
|
||||
{
|
||||
/*
|
||||
*******************************************************************************
|
||||
* LOCAL FUNCTIONS
|
||||
*******************************************************************************
|
||||
*/
|
||||
/*
|
||||
*******************************************************************************
|
||||
* CLASS DECLARE
|
||||
*******************************************************************************
|
||||
*/
|
||||
AudioInput::AudioInput(uint32_t deviceID)
|
||||
: Core::AbstractAudioInput(Poco::format("MPP5::AI#%u", deviceID)), MPPChannel((uint32_t)HI_ID_AI, deviceID, 0)
|
||||
{
|
||||
setSampleRate(48000);
|
||||
setFrameSize(1024);
|
||||
setSampleFormat(Core::SampleFormat::S16P);
|
||||
}
|
||||
|
||||
AudioInput::~AudioInput()
|
||||
{
|
||||
}
|
||||
|
||||
void AudioInput::start()
|
||||
{
|
||||
hi_aio_attr attr;
|
||||
attr.sample_rate = (hi_audio_sample_rate)getSampleRate();
|
||||
attr.bit_width = Util::getBitWidth(getSampleFormat());
|
||||
attr.work_mode = HI_AIO_MODE_I2S_SLAVE;
|
||||
attr.i2s_type = HI_AIO_I2STYPE_EXTERN;
|
||||
attr.snd_mode = HI_AUDIO_SOUND_MODE_STEREO;
|
||||
attr.expand_flag = 0;
|
||||
attr.frame_num = 8;
|
||||
attr.point_num_per_frame = getFrameSize();
|
||||
attr.chn_cnt = 2;
|
||||
|
||||
attr.clk_share = 0;
|
||||
int32_t rc = hi_mpi_ai_set_pub_attr(deviceID(), &attr);
|
||||
if (rc != HI_SUCCESS)
|
||||
throw Poco::InvalidAccessException(Poco::format("%s: set PUB-ATTR FAIL: %d(%#x)", name(), rc, (uint32_t)rc),
|
||||
rc);
|
||||
|
||||
rc = hi_mpi_ai_enable(deviceID());
|
||||
if (rc != HI_SUCCESS)
|
||||
throw Poco::InvalidAccessException(Poco::format("%s: enable FAIL: %d(%#x)", name(), rc, (uint32_t)rc), rc);
|
||||
|
||||
rc = hi_mpi_ai_enable_chn(deviceID(), channelID());
|
||||
if (rc != HI_SUCCESS)
|
||||
throw Poco::InvalidAccessException(Poco::format("%s: enable channel FAIL: %d(%#x)", name(), rc, (uint32_t)rc),
|
||||
rc);
|
||||
|
||||
hi_ai_chn_param param;
|
||||
param.usr_frame_depth = 8;
|
||||
hi_mpi_ai_set_chn_param(deviceID(), channelID(), ¶m);
|
||||
|
||||
run();
|
||||
}
|
||||
|
||||
void AudioInput::stop()
|
||||
{
|
||||
cancel();
|
||||
|
||||
hi_mpi_ai_disable_chn(deviceID(), channelID());
|
||||
hi_mpi_ai_disable(deviceID());
|
||||
}
|
||||
|
||||
void AudioInput::onConfigChanged(ParameterNames& names)
|
||||
{
|
||||
if (!started())
|
||||
return;
|
||||
|
||||
auto code = serialCodeManager().code();
|
||||
if (names.exists(_SampleRate))
|
||||
serialCodeManager().put(_SampleRate, getSampleRate());
|
||||
|
||||
if (names.exists(_FrameSize))
|
||||
serialCodeManager().put(_FrameSize, getFrameSize());
|
||||
|
||||
if (code != serialCodeManager().code())
|
||||
{
|
||||
stop();
|
||||
start();
|
||||
}
|
||||
|
||||
AbstractAudioInput::onConfigChanged(names);
|
||||
}
|
||||
|
||||
Core::Frame::Ptr AudioInput::readFrame()
|
||||
{
|
||||
hi_audio_frame frame;
|
||||
hi_aec_frame aecFrame;
|
||||
|
||||
int rc = hi_mpi_ai_get_frame(deviceID(), 0, &frame, &aecFrame, 1000);
|
||||
if (rc != HI_SUCCESS)
|
||||
throw Poco::TimeoutException(Poco::format("%s: Get frame error: %u(%#x)!", name(), (uint32_t)rc, (uint32_t)rc));
|
||||
|
||||
Core::Frame::Ptr pFrame = nullptr;
|
||||
if (frame.len > 0)
|
||||
{
|
||||
pFrame = new Core::Frame;
|
||||
pFrame->data[0] = new uint8_t[frame.len];
|
||||
memcpy(pFrame->data[0], frame.virt_addr[0], frame.len);
|
||||
pFrame->data[1] = new uint8_t[frame.len];
|
||||
memcpy(pFrame->data[1], frame.virt_addr[1], frame.len);
|
||||
pFrame->length = frame.len;
|
||||
pFrame->timestamp = frame.time_stamp;
|
||||
}
|
||||
|
||||
hi_mpi_ai_release_frame(deviceID(), 0, &frame, &aecFrame);
|
||||
_traffic++;
|
||||
return pFrame;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue