1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00
qTox/audiooutputproxy.cpp

46 lines
1.0 KiB
C++
Raw Normal View History

#include "audiooutputproxy.h"
#include <QDebug>
#define RING_SIZE 11025
AudioOutputProxy::AudioOutputProxy(QObject *parent) :
QIODevice(parent),
2014-07-14 21:16:44 +08:00
ring_buffer(new MemRing<int16_t>(RING_SIZE))
{
open(QIODevice::ReadOnly | QIODevice::Unbuffered);
2014-07-14 21:16:44 +08:00
qDebug() << "AudioOutputProxy::AudioOutputProxy";
}
AudioOutputProxy::~AudioOutputProxy()
{
if (ring_buffer) {
delete ring_buffer;
ring_buffer = 0;
}
close();
2014-07-14 21:16:44 +08:00
qDebug() << "AudioOutputProxy::~AudioOutputProxy";
}
qint64 AudioOutputProxy::readData(char *data, qint64 len)
{
2014-07-14 21:16:44 +08:00
qDebug() << "AudioOutputProxy::read" << len;
return ring_buffer->pull((int16_t*)data, len/2)*2;
}
qint64 AudioOutputProxy::writeData(const char* data, qint64 len)
{
2014-07-14 21:16:44 +08:00
// qDebug() << "AudioOutputProxy::write" << len;
return ring_buffer->push((int16_t*)data, len/2)*2;
}
qint64 AudioOutputProxy::bytesAvailable() const
{
return ring_buffer->readSpace() + QIODevice::bytesAvailable();
}
2014-07-14 21:16:44 +08:00
bool AudioOutputProxy::isSequential() const
{
return true;
}