mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-17 10:55:32 +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
|
namespace Codecs
|
||||||
{
|
{
|
||||||
COpusDecoder::COpusDecoder(int sampleRate, int channels) :
|
COpusDecoder::COpusDecoder(int sampleRate, int channels) : m_channels(channels)
|
||||||
m_sampleRate(sampleRate),
|
|
||||||
m_channels(channels)
|
|
||||||
{
|
{
|
||||||
int error;
|
int error;
|
||||||
opusDecoder = opus_decoder_create(sampleRate, channels, &error);
|
m_opusDecoder = opus_decoder_create(sampleRate, channels, &error);
|
||||||
}
|
}
|
||||||
|
|
||||||
COpusDecoder::~COpusDecoder()
|
COpusDecoder::~COpusDecoder()
|
||||||
{
|
{
|
||||||
opus_decoder_destroy(opusDecoder);
|
opus_decoder_destroy(m_opusDecoder);
|
||||||
}
|
}
|
||||||
|
|
||||||
int COpusDecoder::frameCount(int bufferSize)
|
int COpusDecoder::frameCount(int bufferSize)
|
||||||
@@ -35,12 +33,12 @@ namespace BlackSound
|
|||||||
|
|
||||||
QVector<qint16> COpusDecoder::decode(const QByteArray opusData, int dataLength, int *decodedLength)
|
QVector<qint16> COpusDecoder::decode(const QByteArray opusData, int dataLength, int *decodedLength)
|
||||||
{
|
{
|
||||||
QVector<qint16> decoded(maxDataBytes, 0);
|
QVector<qint16> decoded(MaxDataBytes, 0);
|
||||||
int count = frameCount(maxDataBytes);
|
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);
|
decoded.resize(*decodedLength);
|
||||||
return decoded;
|
return decoded;
|
||||||
@@ -48,7 +46,8 @@ namespace BlackSound
|
|||||||
|
|
||||||
void COpusDecoder::resetState()
|
void COpusDecoder::resetState()
|
||||||
{
|
{
|
||||||
opus_decoder_ctl(opusDecoder, OPUS_RESET_STATE);
|
if (!m_opusDecoder) { return; }
|
||||||
|
opus_decoder_ctl(m_opusDecoder, OPUS_RESET_STATE);
|
||||||
}
|
}
|
||||||
} // ns
|
} // ns
|
||||||
} // ns
|
} // ns
|
||||||
|
|||||||
@@ -30,6 +30,11 @@ namespace BlackSound
|
|||||||
//! Dtor
|
//! Dtor
|
||||||
~COpusDecoder();
|
~COpusDecoder();
|
||||||
|
|
||||||
|
//! Not copyable and assignable @{
|
||||||
|
COpusDecoder(const COpusDecoder &decoder) = delete;
|
||||||
|
COpusDecoder& operator=(COpusDecoder const&) = delete;
|
||||||
|
//! @}
|
||||||
|
|
||||||
//! Frame count
|
//! Frame count
|
||||||
int frameCount(int bufferSize);
|
int frameCount(int bufferSize);
|
||||||
|
|
||||||
@@ -40,11 +45,10 @@ namespace BlackSound
|
|||||||
void resetState();
|
void resetState();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
OpusDecoder *opusDecoder = nullptr;
|
OpusDecoder *m_opusDecoder = nullptr;
|
||||||
int m_sampleRate;
|
|
||||||
int m_channels;
|
int m_channels;
|
||||||
|
|
||||||
static constexpr int maxDataBytes = 4000;
|
static constexpr int MaxDataBytes = 4000;
|
||||||
};
|
};
|
||||||
} // ns
|
} // ns
|
||||||
} // ns
|
} // ns
|
||||||
|
|||||||
Reference in New Issue
Block a user