[AFV] Ref T730, made OPUS decoder not copyable/assignable (avoid resource conflicts)

This commit is contained in:
Klaus Basan
2019-10-11 17:08:40 +02:00
committed by Mat Sutcliffe
parent 11ee2413b5
commit 7e22318a6e
2 changed files with 16 additions and 13 deletions

View File

@@ -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

View File

@@ -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