Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qqnxsndaudiosource_p.h
Go to the documentation of this file.
1// Copyright (C) 2025 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4//
5// W A R N I N G
6// -------------
7//
8// This file is not part of the Qt API. It exists for the convenience
9// of other Qt classes. This header file may change from version to
10// version without notice, or even be removed.
11//
12// We mean it.
13//
14
15#ifndef QQNXSNDAUDIOSOURCE_P_H
16#define QQNXSNDAUDIOSOURCE_P_H
17
18#include <alsa/asoundlib.h>
19
20#include <QtCore/qiodevice.h>
21#include <QtCore/qthread.h>
22#include <QtCore/qtclasshelpermacros.h>
23#include <QtMultimedia/qaudio.h>
24#include <QtMultimedia/qaudiodevice.h>
25#include <QtMultimedia/private/qaudiosystem_p.h>
26#include <QtMultimedia/private/qaudiosystem_platform_stream_support_p.h>
27#include <QtMultimedia/private/qaudio_platform_implementation_support_p.h>
28
30
31#include <atomic>
32#include <memory>
33#include <optional>
34
35QT_BEGIN_NAMESPACE
36
37class QQnxSndAudioSource;
38
42{
43 using SourceType = QQnxSndAudioSource;
47
48 QQnxSndAudioSourceStream(QAudioDevice, const QAudioFormat &,
49 std::optional<qsizetype> ringbufferSize, QQnxSndAudioSource *parent,
50 float volume, std::optional<NativePeriodFrames> nativePeriodFrames);
53
59
60 bool open();
61 bool start(QIODevice *);
63 bool start(AudioCallback);
64
65 void suspend();
66 void resume();
67 void stop(ShutdownPolicy);
68
69 void updateStreamIdle(bool) override;
70
71private:
72 bool openPcmDevice();
73 int recoverFromXrun(int err);
74 void startWorker();
75 void joinWorkerThread();
76 void runProcessLoop();
77 bool processOnePeriod();
78 void handleSndPcmError(int err = 0);
79 void closePcmDevice();
80
81 snd_pcm_t *m_handle = nullptr;
82 snd_pcm_uframes_t m_periodFrames = 0;
83 // Device-native sample format chosen at open (best-native + convert); the
84 // host buffer read from io-snd is in this format, converted to the
85 // application format by the base-class process()/runAudioCallback helpers.
86 QAudioHelperInternal::NativeSampleFormat m_nativeFormat =
88
89 std::atomic_bool m_suspended = false;
90
91 std::unique_ptr<QThread> m_workerThread;
92 // Wakes the worker out of poll() for stop/suspend/resume (see runProcessLoop).
93 QnxSndHelpers::WakePipe m_wakePipe;
94 std::optional<AudioCallback> m_audioCallback = std::nullopt;
95
96 // See QQnxSndAudioSinkStream::m_parent: atomic to bridge worker reads
97 // and app-thread writes safely.
98 std::atomic<QQnxSndAudioSource *> m_parent{ nullptr };
99};
100
101class QQnxSndAudioSource final
102 : public QtMultimediaPrivate::QPlatformAudioSourceImplementationWithCallback<
103 QQnxSndAudioSourceStream, QQnxSndAudioSource>
104{
105 using BaseClass = QtMultimediaPrivate::QPlatformAudioSourceImplementationWithCallback<
106 QQnxSndAudioSourceStream, QQnxSndAudioSource>;
107
108public:
109 QQnxSndAudioSource(QAudioDevice, const QAudioFormat &, QObject *parent);
111};
112
113QT_END_NAMESPACE
114
115#endif // QQNXSNDAUDIOSOURCE_P_H
QQnxSndAudioSource(QAudioDevice, const QAudioFormat &, QObject *parent)
void setWorkerRealtimePriority(const QLoggingCategory &category)
int startPcm(snd_pcm_t *handle)
int recoverFromXrun(snd_pcm_t *handle, int err)
PollOutcome pollPcm(snd_pcm_t *handle, const WakePipe &wake)
PcmOpenResult openConfiguredPcm(const PcmOpenConfig &config)
QT_BEGIN_NAMESPACE Q_STATIC_LOGGING_CATEGORY(lcSynthesizedIterableAccess, "qt.iterable.synthesized", QtWarningMsg)
void updateStreamIdle(bool) override
QtMultimediaPrivate::QPlatformAudioSourceStream::AudioCallback AudioCallback
QQnxSndAudioSourceStream(QAudioDevice, const QAudioFormat &, std::optional< qsizetype > ringbufferSize, QQnxSndAudioSource *parent, float volume, std::optional< NativePeriodFrames > nativePeriodFrames)