mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-31 04:25:35 +08:00
[AFV] Ref T730, made OPUS decoder not copyable/assignable (avoid resource conflicts)
This commit is contained in:
committed by
Mat Sutcliffe
parent
11ee2413b5
commit
7e22318a6e
@@ -12,17 +12,15 @@ namespace BlackSound
|
||||
{
|
||||
namespace Codecs
|
||||
{
|
||||
COpusDecoder::COpusDecoder(int sampleRate, int channels) :
|
||||
m_sampleRate(sampleRate),
|
||||
m_channels(channels)
|
||||
COpusDecoder::COpusDecoder(int sampleRate, int channels) : m_channels(channels)
|
||||
{
|
||||
int error;
|
||||
opusDecoder = opus_decoder_create(sampleRate, channels, &error);
|
||||
m_opusDecoder = opus_decoder_create(sampleRate, channels, &error);
|
||||
}
|
||||
|
||||
COpusDecoder::~COpusDecoder()
|
||||
{
|
||||
opus_decoder_destroy(opusDecoder);
|
||||
opus_decoder_destroy(m_opusDecoder);
|
||||
}
|
||||
|
||||
int COpusDecoder::frameCount(int bufferSize)
|
||||
@@ -35,12 +33,12 @@ namespace BlackSound
|
||||
|
||||
QVector<qint16> COpusDecoder::decode(const QByteArray opusData, int dataLength, int *decodedLength)
|
||||
{
|
||||
QVector<qint16> decoded(maxDataBytes, 0);
|
||||
int count = frameCount(maxDataBytes);
|
||||
QVector<qint16> decoded(MaxDataBytes, 0);
|
||||
int count = frameCount(MaxDataBytes);
|
||||
|
||||
if (! opusData.isEmpty())
|
||||
if (!opusData.isEmpty())
|
||||
{
|
||||
*decodedLength = opus_decode(opusDecoder, reinterpret_cast<const unsigned char *>(opusData.data()), dataLength, decoded.data(), count, 0);
|
||||
*decodedLength = opus_decode(m_opusDecoder, reinterpret_cast<const unsigned char *>(opusData.data()), dataLength, decoded.data(), count, 0);
|
||||
}
|
||||
decoded.resize(*decodedLength);
|
||||
return decoded;
|
||||
@@ -48,7 +46,8 @@ namespace BlackSound
|
||||
|
||||
void COpusDecoder::resetState()
|
||||
{
|
||||
opus_decoder_ctl(opusDecoder, OPUS_RESET_STATE);
|
||||
if (!m_opusDecoder) { return; }
|
||||
opus_decoder_ctl(m_opusDecoder, OPUS_RESET_STATE);
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
@@ -30,6 +30,11 @@ namespace BlackSound
|
||||
//! Dtor
|
||||
~COpusDecoder();
|
||||
|
||||
//! Not copyable and assignable @{
|
||||
COpusDecoder(const COpusDecoder &decoder) = delete;
|
||||
COpusDecoder& operator=(COpusDecoder const&) = delete;
|
||||
//! @}
|
||||
|
||||
//! Frame count
|
||||
int frameCount(int bufferSize);
|
||||
|
||||
@@ -40,11 +45,10 @@ namespace BlackSound
|
||||
void resetState();
|
||||
|
||||
private:
|
||||
OpusDecoder *opusDecoder = nullptr;
|
||||
int m_sampleRate;
|
||||
OpusDecoder *m_opusDecoder = nullptr;
|
||||
int m_channels;
|
||||
|
||||
static constexpr int maxDataBytes = 4000;
|
||||
static constexpr int MaxDataBytes = 4000;
|
||||
};
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
Reference in New Issue
Block a user