Skip to content

Commit

Permalink
Merge pull request #503 from valbok/crash-on-switch
Browse files Browse the repository at this point in the history
Don't accept packets if the abort is called
  • Loading branch information
valbok authored Dec 7, 2024
2 parents 746db80 + ed380f3 commit 79105ca
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/QtAVPlayer/qavpacketqueue_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,12 @@ class QAVPacketQueue
void enqueue(const QAVPacket &packet)
{
QMutexLocker locker(&m_mutex);
if (m_abort)
return;
m_packets.append(packet);
m_bytes += packet.packet()->size + sizeof(packet);
m_duration += packet.duration();
m_consumerWaiter.wakeAll();
m_abort = false;
m_waitingForPackets = false;
}

Expand Down Expand Up @@ -180,10 +181,10 @@ class QAVPacketQueue
m_producerWaiter.wait(&m_mutex);
}

void abort()
void abort(bool aborted = true)
{
QMutexLocker locker(&m_mutex);
m_abort = true;
m_abort = aborted;
m_waitingForPackets = true;
m_consumerWaiter.wakeAll();
m_producerWaiter.wakeAll();
Expand Down
3 changes: 3 additions & 0 deletions src/QtAVPlayer/qavplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,9 @@ void QAVPlayerPrivate::terminate()
loaderFuture.waitForFinished();
videoPlayFuture.waitForFinished();
audioPlayFuture.waitForFinished();
videoQueue.abort(false);
audioQueue.abort(false);
subtitleQueue.abort(false);
demuxer.abort(false);

pendingPosition = 0;
Expand Down
16 changes: 16 additions & 0 deletions tests/auto/integration/qavplayer/tst_qavplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ private slots:
void multiFilterInputs_data();
void multiFilterInputs();
void streamMetadataRotate();
void switchingSource();
};

void tst_QAVPlayer::initTestCase()
Expand Down Expand Up @@ -3426,5 +3427,20 @@ void tst_QAVPlayer::streamMetadataRotate()
QCOMPARE(p.currentVideoStreams()[0].metadata()["rotate"], "90");
}

void tst_QAVPlayer::switchingSource()
{
QAVPlayer p;
QList<QString> files = {"av_sample.mkv", "test.mkv", "small.mp4"};
p.setSynced(false);
for (const auto &f : files) {
QFileInfo file(testData(f));
p.setSource(file.absoluteFilePath());
p.play();
QTRY_VERIFY(p.mediaStatus() == QAVPlayer::LoadedMedia || p.mediaStatus() == QAVPlayer::EndOfMedia);
}

QTRY_COMPARE(p.mediaStatus(), QAVPlayer::EndOfMedia);
}

QTEST_MAIN(tst_QAVPlayer)
#include "tst_qavplayer.moc"

0 comments on commit 79105ca

Please sign in to comment.