Commit 707ade13 authored by Thomas Eschenbacher's avatar Thomas Eschenbacher
Browse files

playback handling: improved responsiveness in pre-listen mode

parent 7d8a93d3
......@@ -159,8 +159,10 @@ void Kwave::FilterPlugin::run(QStringList params)
// transport the samples
while (!shouldStop() && (!source.done() || m_listen)) {
// process one step
if (m_listen) QThread::yieldCurrentThread();
source.goOn();
filter->goOn();
if (m_listen) QThread::yieldCurrentThread();
// watch out for changed parameters when in
// pre-listen mode
......
......@@ -21,6 +21,7 @@
#include <QMutexLocker>
#include <QtGlobal>
#include <QThread>
#include "libkwave/MultiPlaybackSink.h"
#include "libkwave/PlayBackDevice.h"
......@@ -99,8 +100,17 @@ void Kwave::MultiPlaybackSink::input(unsigned int track,
}
// play the output buffer
int res = m_device->write(m_out_buffer);
if (res < 0) break;
unsigned int retry = 5;
while (retry--) {
// shortcut for more responsiveness when pressing cancel
if (QThread::currentThread()->isInterruptionRequested())
break;
int res = m_device->write(m_out_buffer);
if (res != 0) {
QThread::yieldCurrentThread();
} else break;
}
}
m_in_buffer_filled.fill(false);
......
......@@ -507,9 +507,14 @@ void Kwave::PlaybackController::run_wrapper(const QVariant &params)
// write samples to the playback device
int result = -1;
{
QMutexLocker lock(&m_lock_device);
if (m_device)
result = m_device->write(out_samples);
unsigned int retry = 10;
while (retry-- && !m_thread.isInterruptionRequested()) {
QMutexLocker lock(&m_lock_device);
if (m_device)
result = m_device->write(out_samples);
if (result == 0)
break;
}
}
if (result) {
m_thread.requestInterruption();
......
......@@ -330,6 +330,7 @@ void Kwave::Plugin::closeProgressDialog(Kwave::Plugin *)
void Kwave::Plugin::cancel()
{
m_stop = true;
if (m_thread) m_thread->requestInterruption();
}
//***************************************************************************
......@@ -358,6 +359,12 @@ bool Kwave::Plugin::canClose() const
return !isRunning();
}
//***************************************************************************
bool Kwave::Plugin::shouldStop() const
{
return (m_stop || (m_thread && m_thread->isInterruptionRequested()));
}
//***************************************************************************
bool Kwave::Plugin::isRunning() const
{
......
......@@ -118,7 +118,7 @@ namespace Kwave
* Returns true if the plugin should stop, e.g. when the
* user has pressed "cancel"
*/
bool shouldStop() const { return m_stop; }
bool shouldStop() const;
/**
* Called after the plugin has been loaded into memory. This is
......
......@@ -236,30 +236,8 @@ int Kwave::PlayBackQt::write(const Kwave::SampleArray &samples)
m_encoder->encode(samples, samples.size(), frame);
}
int retry = 10;
qint64 written = 0;
qint64 remaining = frame.size();
const char *p = frame.constData();
while (retry-- && remaining)
{
if (QThread::currentThread()->isInterruptionRequested()) {
remaining = 0;
break;
}
qint64 len = m_buffer.writeData(p, remaining);
if (len < 1) continue;
written += len;
remaining -= len;
p += len;
}
if (remaining) {
qDebug("WARNING: Kwave::PlayBackQt::write: written=%lld/%d",
written, frame.size());
return -EIO;
}
return 0;
qint64 written = m_buffer.writeData(frame.constData(), frame.size());
return (written == frame.size()) ? 0 : -EAGAIN;
}
//***************************************************************************
......@@ -579,7 +557,7 @@ qint64 Kwave::PlayBackQt::Buffer::writeData(const char *data, qint64 len)
qint64 written_bytes = 0;
int count = qMin<int>(qMax(m_sem_free.available(), 1), Kwave::toInt(len));
int count = Kwave::toInt(len);
if (Q_LIKELY(m_sem_free.tryAcquire(count, m_timeout))) {
QMutexLocker _lock(&m_lock); // context: kwave worker thread
m_sem_filled.release(count);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment