Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move private impl of QAVAudioOutput to audio thread #467

Merged
merged 1 commit into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/QtAVPlayer/qavaudiooutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ static QAudioFormat format(const QAVAudioFormat &from)
return out;
}

class QAVAudioOutputPrivate
class QAVAudioOutputPrivate : public QObject
{
public:
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
Expand Down Expand Up @@ -156,7 +156,7 @@ QAVAudioOutput::QAVAudioOutput(QObject *parent)
Q_D(QAVAudioOutput);
// The audio is rendered by this thread
d->audioThread.reset(new QThread);
moveToThread(d->audioThread.get());
d->moveToThread(d->audioThread.get());
// QAVAudioOutputDevice::readData() should be called on audioThread
d->device.reset(new QAVAudioOutputDevice);
d->device->open(QIODevice::ReadOnly);
Expand Down Expand Up @@ -236,7 +236,7 @@ bool QAVAudioOutput::play(const QAVAudioFrame &frame)
quint64 bufferSize = d->bufferSize ? qMin(d->bufferSize, 96000) : 96000;
if (d->device->bytesInQueue() >= bufferSize) {
// Reset the output on QAVAudioOutput's thread
QMetaObject::invokeMethod(this, [fmt, d] {
QMetaObject::invokeMethod(d, [fmt, d] {
d->resetIfNeeded(fmt, d->bufferSize, d->volume);
});
}
Expand Down
5 changes: 5 additions & 0 deletions tests/auto/integration/qavplayer/tst_qavplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1868,6 +1868,11 @@ void tst_QAVPlayer::audioOutput()
frame = f;
}, Qt::DirectConnection);

auto outWithParent = new QAVAudioOutput(&p);
QObject::connect(&p, &QAVPlayer::audioFrame, &p, [&outWithParent](const QAVAudioFrame &f) {
outWithParent->play(f);
}, Qt::DirectConnection);

p.setSource(file1.absoluteFilePath());
p.play();
QTest::qWait(100);
Expand Down
Loading