diff options
author | Tim Blechmann <[email protected]> | 2025-06-26 09:36:34 +0800 |
---|---|---|
committer | Tim Blechmann <[email protected]> | 2025-06-30 01:43:07 +0000 |
commit | a153ec3e013d62db11a15a6281e64cc7f642bd71 (patch) | |
tree | 4cc64d9c73201aac9c00a706f44df92bd9f851c1 /src | |
parent | e6d969fc3889387f0bcc136521f932fd4913927f (diff) |
It is sometimes helpful to assert which thread a function is supposed to
be called on. Adding a thread() getter taken from one of the QObject
members helps with this.
Pick-to: 6.8 6.9 6.10
Change-Id: I53e214ac9670abd432ef0acfa4879da0d27e4d8a
Reviewed-by: Artem Dyomin <[email protected]>
Reviewed-by: Mikko Hallamaa <[email protected]>
Diffstat (limited to 'src')
-rw-r--r-- | src/multimedia/audio/qaudiosystem_platform_stream_support.cpp | 17 | ||||
-rw-r--r-- | src/multimedia/audio/qaudiosystem_platform_stream_support_p.h | 8 |
2 files changed, 23 insertions, 2 deletions
diff --git a/src/multimedia/audio/qaudiosystem_platform_stream_support.cpp b/src/multimedia/audio/qaudiosystem_platform_stream_support.cpp index 3b59289af..07bc6bb06 100644 --- a/src/multimedia/audio/qaudiosystem_platform_stream_support.cpp +++ b/src/multimedia/audio/qaudiosystem_platform_stream_support.cpp @@ -224,6 +224,7 @@ std::chrono::microseconds QPlatformAudioSinkStream::processedDuration() const void QPlatformAudioSinkStream::pullFromQIODevice() { + Q_ASSERT(thread()->isCurrentThread()); Q_ASSERT(m_device); visitRingbuffer([&](auto &ringbuffer) { @@ -281,6 +282,13 @@ void QPlatformAudioSinkStream::stopIdleDetection() QObject::disconnect(m_streamIdleDetectionConnection); } +QThread *QPlatformAudioSinkStream::thread() const +{ + // QPlatformAudioSinkStream is not a QObject, but still has a notion of an application thread + // where it lives on. + return m_streamIdleDetectionNotifier.thread(); +} + // we limit alloca calls to 0.5MB. it's good enough for virtually all use cases (i.e. buffers // of 4092 frames / 32 channels) and well in the reasonable range of available stack memory on linux // (8MB) @@ -360,6 +368,8 @@ uint64_t QPlatformAudioSourceStream::process( void QPlatformAudioSourceStream::pushToIODevice() { + Q_ASSERT(thread()->isCurrentThread()); + qsizetype bytesPushed = visitRingbuffer([&](auto &ringbuffer) { return QtPrivate::pushToQIODeviceFromRingbuffer(*m_device, ringbuffer); }); @@ -396,6 +406,13 @@ void QPlatformAudioSourceStream::emptyRingbuffer() }); } +QThread *QPlatformAudioSourceStream::thread() const +{ + // QPlatformAudioSourceStream is not a QObject, but still has a notion of an application thread + // where it lives on. + return m_ringbufferHasData.thread(); +} + qsizetype QPlatformAudioSourceStream::bytesReady() const { return visitRingbuffer([](const auto &ringbuffer) { diff --git a/src/multimedia/audio/qaudiosystem_platform_stream_support_p.h b/src/multimedia/audio/qaudiosystem_platform_stream_support_p.h index 090d52097..17537ae8a 100644 --- a/src/multimedia/audio/qaudiosystem_platform_stream_support_p.h +++ b/src/multimedia/audio/qaudiosystem_platform_stream_support_p.h @@ -166,7 +166,7 @@ protected: void handleIOError(ParentType *parent) { if (parent) { - Q_ASSERT(parent->thread()->isCurrentThread()); + Q_ASSERT(thread()->isCurrentThread()); parent->setError(QAudio::IOError); parent->updateStreamState(QtAudio::State::StoppedState); @@ -174,6 +174,8 @@ protected: } } + QThread *thread() const; + private: // qiodevice QIODevice *m_device = nullptr; @@ -237,7 +239,7 @@ protected: void handleIOError(ParentType *parent) { if (parent) { - Q_ASSERT(parent->thread()->isCurrentThread()); + Q_ASSERT(thread()->isCurrentThread()); parent->setError(QAudio::IOError); parent->updateStreamState(QtAudio::State::StoppedState); @@ -250,6 +252,8 @@ protected: } } + QThread *thread() const; + private: // qiodevice QIODevice *m_device = nullptr; |