Now on pause fill the buffer with silent instead stopping.
Abandono esta rama de desarrollo: 1. Al cambiar el volumen se escucha ruido 2. QAudioOutput::reset() no funciona correctamente 3. Hay muchos pops en la reproducción
This commit is contained in:
parent
fe4d118cfb
commit
37835e7571
3 changed files with 60 additions and 31 deletions
|
@ -5,6 +5,8 @@
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QTime>
|
#include <QTime>
|
||||||
|
|
||||||
|
#include <time.h> // nanosleep y la chapuza de liberar el buffer
|
||||||
|
|
||||||
AudioLayerWidget::AudioLayerWidget(QWidget *parent, QString name):
|
AudioLayerWidget::AudioLayerWidget(QWidget *parent, QString name):
|
||||||
QGroupBox(parent)
|
QGroupBox(parent)
|
||||||
, m_suspendResumeButton(0)
|
, m_suspendResumeButton(0)
|
||||||
|
@ -19,7 +21,8 @@ AudioLayerWidget::AudioLayerWidget(QWidget *parent, QString name):
|
||||||
, m_progressCounter(new QTime(0,0,0,1))
|
, m_progressCounter(new QTime(0,0,0,1))
|
||||||
, m_progressMs(0)
|
, m_progressMs(0)
|
||||||
, m_currentMedia(" ")
|
, m_currentMedia(" ")
|
||||||
|
, m_running(false)
|
||||||
|
, m_emptyBuffer()
|
||||||
{
|
{
|
||||||
this->setTitle(name);
|
this->setTitle(name);
|
||||||
|
|
||||||
|
@ -122,6 +125,11 @@ AudioLayerWidget::AudioLayerWidget(QWidget *parent, QString name):
|
||||||
m_format.setByteOrder(QAudioFormat::LittleEndian);
|
m_format.setByteOrder(QAudioFormat::LittleEndian);
|
||||||
m_format.setSampleType(QAudioFormat::SignedInt);
|
m_format.setSampleType(QAudioFormat::SignedInt);
|
||||||
|
|
||||||
|
// Init the silent buffer
|
||||||
|
QAudioBuffer *abuf = new QAudioBuffer(44100, m_format, -1);
|
||||||
|
QByteArray ba((const char*)abuf->data(), abuf->byteCount());
|
||||||
|
m_emptyBuffer.append(ba);
|
||||||
|
|
||||||
QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice());
|
QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice());
|
||||||
if (!info.isFormatSupported(m_format)) {
|
if (!info.isFormatSupported(m_format)) {
|
||||||
qWarning("Default format not supported - trying to use nearest");
|
qWarning("Default format not supported - trying to use nearest");
|
||||||
|
@ -139,7 +147,6 @@ AudioLayerWidget::AudioLayerWidget(QWidget *parent, QString name):
|
||||||
m_watchDMX->start(1000);
|
m_watchDMX->start(1000);
|
||||||
|
|
||||||
createAudioOutput();
|
createAudioOutput();
|
||||||
pause();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AudioLayerWidget::~AudioLayerWidget()
|
AudioLayerWidget::~AudioLayerWidget()
|
||||||
|
@ -152,10 +159,13 @@ void AudioLayerWidget::createAudioOutput()
|
||||||
m_audioOutput = new QAudioOutput(m_device, m_format, this);
|
m_audioOutput = new QAudioOutput(m_device, m_format, this);
|
||||||
Q_CHECK_PTR(m_audioOutput);
|
Q_CHECK_PTR(m_audioOutput);
|
||||||
m_audioOutput->setNotifyInterval(NOTIFY_INTERVAL);
|
m_audioOutput->setNotifyInterval(NOTIFY_INTERVAL);
|
||||||
|
m_audioOutput->setCategory("LibreMediaServer");
|
||||||
connect(m_audioOutput, SIGNAL(notify()), SLOT(notified()));
|
connect(m_audioOutput, SIGNAL(notify()), SLOT(notified()));
|
||||||
reset();
|
m_output = m_audioOutput->start();
|
||||||
|
Q_CHECK_PTR(m_output);
|
||||||
m_statusValue->setText(PAUSE_LABEL);
|
m_statusValue->setText(PAUSE_LABEL);
|
||||||
connect(m_audioOutput, SIGNAL(stateChanged(QAudio::State)), SLOT(handleStateChanged(QAudio::State)));
|
connect(m_audioOutput, SIGNAL(stateChanged(QAudio::State)), SLOT(handleStateChanged(QAudio::State)));
|
||||||
|
m_pullTimer->start(PULL_TIMER_INTERVAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioLayerWidget::deviceChanged(int index)
|
void AudioLayerWidget::deviceChanged(int index)
|
||||||
|
@ -220,6 +230,7 @@ void AudioLayerWidget::pullTimerExpired()
|
||||||
if (m_audioOutput && m_audioOutput->state() != QAudio::StoppedState) {
|
if (m_audioOutput && m_audioOutput->state() != QAudio::StoppedState) {
|
||||||
int chunks = m_audioOutput->bytesFree() / m_audioOutput->periodSize();
|
int chunks = m_audioOutput->bytesFree() / m_audioOutput->periodSize();
|
||||||
while (chunks) {
|
while (chunks) {
|
||||||
|
if (m_running) {
|
||||||
const qint64 len = m_decoder->read(m_buffer.data(), m_audioOutput->periodSize());
|
const qint64 len = m_decoder->read(m_buffer.data(), m_audioOutput->periodSize());
|
||||||
if ( len == -1) {
|
if ( len == -1) {
|
||||||
stop();
|
stop();
|
||||||
|
@ -231,11 +242,13 @@ void AudioLayerWidget::pullTimerExpired()
|
||||||
}
|
}
|
||||||
if (len != m_audioOutput->periodSize())
|
if (len != m_audioOutput->periodSize())
|
||||||
break;
|
break;
|
||||||
|
} else {
|
||||||
|
m_output->write(m_emptyBuffer.data(), m_audioOutput->periodSize());
|
||||||
|
}
|
||||||
--chunks;
|
--chunks;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioLayerWidget::toggleSuspendResume()
|
void AudioLayerWidget::toggleSuspendResume()
|
||||||
{
|
{
|
||||||
if (m_audioOutput->state() == QAudio::SuspendedState) {
|
if (m_audioOutput->state() == QAudio::SuspendedState) {
|
||||||
|
@ -246,7 +259,8 @@ void AudioLayerWidget::toggleSuspendResume()
|
||||||
play();
|
play();
|
||||||
} else if (m_audioOutput->state() == QAudio::IdleState) {
|
} else if (m_audioOutput->state() == QAudio::IdleState) {
|
||||||
qWarning("%s: IdleState", this->title().toLatin1().constData());
|
qWarning("%s: IdleState", this->title().toLatin1().constData());
|
||||||
play();
|
reset();
|
||||||
|
resume();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -254,12 +268,16 @@ void AudioLayerWidget::handleStateChanged(QAudio::State state)
|
||||||
{
|
{
|
||||||
if (state == QAudio::SuspendedState) {
|
if (state == QAudio::SuspendedState) {
|
||||||
m_statusValue->setText(PAUSE_LABEL);
|
m_statusValue->setText(PAUSE_LABEL);
|
||||||
|
qDebug("Pause");
|
||||||
} else if (state == QAudio::ActiveState) {
|
} else if (state == QAudio::ActiveState) {
|
||||||
m_statusValue->setText(PLAY_LABEL);
|
m_statusValue->setText(PLAY_LABEL);
|
||||||
|
qDebug("Play");
|
||||||
} else if (m_audioOutput->state() == QAudio::StoppedState) {
|
} else if (m_audioOutput->state() == QAudio::StoppedState) {
|
||||||
m_statusValue->setText(STOP_LABEL);
|
m_statusValue->setText(STOP_LABEL);
|
||||||
|
qDebug("Stop");
|
||||||
} else if (state == QAudio::IdleState) {
|
} else if (state == QAudio::IdleState) {
|
||||||
m_statusValue->setText(IDDLE_LABEL);
|
m_statusValue->setText(IDDLE_LABEL);
|
||||||
|
qDebug("Iddle");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -273,10 +291,10 @@ void AudioLayerWidget::durationChanged(qint64 dur)
|
||||||
|
|
||||||
void AudioLayerWidget::play()
|
void AudioLayerWidget::play()
|
||||||
{
|
{
|
||||||
// reset();
|
|
||||||
setInitPosition();
|
setInitPosition();
|
||||||
m_pullTimer->start(PULL_TIMER_INTERVAL);
|
// m_pullTimer->start(PULL_TIMER_INTERVAL);
|
||||||
m_audioOutput->resume();
|
// m_audioOutput->resume();
|
||||||
|
m_running = true;
|
||||||
pullTimerExpired();
|
pullTimerExpired();
|
||||||
m_progressCounter->start();
|
m_progressCounter->start();
|
||||||
m_suspendResumeButton->setText(tr(SUSPEND_LABEL));
|
m_suspendResumeButton->setText(tr(SUSPEND_LABEL));
|
||||||
|
@ -284,15 +302,17 @@ void AudioLayerWidget::play()
|
||||||
|
|
||||||
void AudioLayerWidget::pause()
|
void AudioLayerWidget::pause()
|
||||||
{
|
{
|
||||||
m_audioOutput->suspend();
|
// m_pullTimer->stop();
|
||||||
m_pullTimer->stop();
|
// m_audioOutput->suspend();
|
||||||
|
m_running = false;
|
||||||
m_suspendResumeButton->setText(tr(RESUME_LABEL));
|
m_suspendResumeButton->setText(tr(RESUME_LABEL));
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioLayerWidget::resume()
|
void AudioLayerWidget::resume()
|
||||||
{
|
{
|
||||||
m_pullTimer->start(PULL_TIMER_INTERVAL);
|
// m_pullTimer->start(PULL_TIMER_INTERVAL);
|
||||||
m_audioOutput->resume();
|
// m_audioOutput->resume();
|
||||||
|
m_running = true;
|
||||||
pullTimerExpired();
|
pullTimerExpired();
|
||||||
m_progressCounter->start();
|
m_progressCounter->start();
|
||||||
m_suspendResumeButton->setText(tr(SUSPEND_LABEL));
|
m_suspendResumeButton->setText(tr(SUSPEND_LABEL));
|
||||||
|
@ -300,7 +320,7 @@ void AudioLayerWidget::resume()
|
||||||
|
|
||||||
void AudioLayerWidget::stop()
|
void AudioLayerWidget::stop()
|
||||||
{
|
{
|
||||||
// reset();
|
m_running = false;
|
||||||
setInitPosition();
|
setInitPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -310,12 +330,11 @@ void AudioLayerWidget::reset()
|
||||||
m_audioOutput->reset();
|
m_audioOutput->reset();
|
||||||
m_output = m_audioOutput->start();
|
m_output = m_audioOutput->start();
|
||||||
Q_CHECK_PTR(m_output);
|
Q_CHECK_PTR(m_output);
|
||||||
// pause();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioLayerWidget::setInitPosition()
|
void AudioLayerWidget::setInitPosition()
|
||||||
{
|
{
|
||||||
reset();
|
// reset();
|
||||||
m_decoder->setPos(0);
|
m_decoder->setPos(0);
|
||||||
m_progressMs = 0;
|
m_progressMs = 0;
|
||||||
m_progressTime->setTime(QTime::fromMSecsSinceStartOfDay(m_progressMs));
|
m_progressTime->setTime(QTime::fromMSecsSinceStartOfDay(m_progressMs));
|
||||||
|
@ -330,3 +349,8 @@ void AudioLayerWidget::updateWatchDMX(bool b)
|
||||||
{
|
{
|
||||||
m_receiveDMX->setChecked(b);
|
m_receiveDMX->setChecked(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AudioLayerWidget::flushBuffer()
|
||||||
|
{
|
||||||
|
// Esto es una chapuza para arreglar que reset() no limpia el buffer realmente
|
||||||
|
}
|
||||||
|
|
|
@ -79,11 +79,16 @@ private:
|
||||||
|
|
||||||
QString m_currentMedia;
|
QString m_currentMedia;
|
||||||
|
|
||||||
|
bool m_running;
|
||||||
|
|
||||||
|
QByteArray m_emptyBuffer;
|
||||||
|
|
||||||
void createAudioOutput();
|
void createAudioOutput();
|
||||||
|
|
||||||
void reset();
|
void reset();
|
||||||
void setInitPosition();
|
void setInitPosition();
|
||||||
|
|
||||||
|
void flushBuffer();
|
||||||
private slots:
|
private slots:
|
||||||
void notified();
|
void notified();
|
||||||
void pullTimerExpired();
|
void pullTimerExpired();
|
||||||
|
|
|
@ -7,8 +7,8 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>60</width>
|
<width>126</width>
|
||||||
<height>57</height>
|
<height>89</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
|
@ -20,7 +20,7 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>60</width>
|
<width>126</width>
|
||||||
<height>29</height>
|
<height>29</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
|
|
Loading…
Add table
Reference in a new issue