4#include <common/qgstreameraudioinput_p.h>
6#include <QtCore/qloggingcategory.h>
7#include <QtMultimedia/qaudiodevice.h>
8#include <QtMultimedia/qaudioinput.h>
10#include <audio/qgstreameraudiodevice_p.h>
11#include <common/qgstpipeline_p.h>
18Q_STATIC_LOGGING_CATEGORY(qLcMediaAudioInput,
"qt.multimedia.audioinput")
21 using namespace Qt::Literals;
23 if constexpr (QT_CONFIG(pulseaudio))
25 else if constexpr (QT_CONFIG(alsa))
28 return "autoaudiosrc"_L1;
33 using namespace Qt::Literals;
34 QLatin1String elementType = element.typeName();
36 if constexpr (QT_CONFIG(pulseaudio))
37 return elementType ==
"GstPulseSrc"_L1;
39 if constexpr (0 && QT_CONFIG(alsa))
41 return elementType ==
"GstAlsaSrc"_L1;
50 static const auto error = qGstErrorMessageIfElementsNotAvailable(
"autoaudiosrc",
"volume");
59 QPlatformAudioInput(parent),
60 m_audioInputBin(QGstBin::create(
"audioInput")),
62 QGstElement::createFromFactory(defaultSrcName.constData(),
"autoaudiosrc"),
65 QGstElement::createFromFactory(
"volume",
"volume"),
68 m_audioInputBin.add(m_audioSrc, m_audioVolume);
69 qLinkGstElements(m_audioSrc, m_audioVolume);
71 m_audioInputBin.addGhostPad(m_audioVolume,
"src");
76 const auto *customDeviceInfo =
77 dynamic_cast<
const QGStreamerCustomAudioDeviceInfo *>(m_audioDevice.handle());
79 if (customDeviceInfo) {
80 qCDebug(qLcMediaAudioInput)
81 <<
"requesting custom audio src element: " << customDeviceInfo->id;
89 qCWarning(qLcMediaAudioInput)
90 <<
"Cannot create audio source element:" << customDeviceInfo->id;
93 const QByteArray &id = m_audioDevice.id();
94 if constexpr (QT_CONFIG(pulseaudio) || QT_CONFIG(alsa)) {
97 newSrc.set(
"device", id.constData());
101 qWarning() <<
"Cannot create" << defaultSrcName;
104 auto *deviceInfo =
dynamic_cast<
const QGStreamerAudioDeviceInfo *>(m_audioDevice.handle());
105 if (deviceInfo && deviceInfo->gstDevice) {
106 QGstElement element = QGstElement::createFromDevice(deviceInfo->gstDevice,
"audiosrc");
111 qCWarning(qLcMediaAudioInput) <<
"Invalid audio device";
112 qCWarning(qLcMediaAudioInput)
113 <<
"Failed to create a gst element for the audio device, using a default audio source";
119 m_audioInputBin.setStateSync(GST_STATE_NULL);
124 m_audioVolume.set(
"volume", volume);
129 m_audioVolume.set(
"mute", muted);
134 if (device == m_audioDevice)
136 qCDebug(qLcMediaAudioInput) <<
"setAudioDevice" << device.description() << device.isNull();
137 m_audioDevice = device;
139 if (srcHasDeviceProperty(m_audioSrc) && !isCustomAudioDevice(m_audioDevice)) {
140 m_audioSrc.set(
"device", m_audioDevice.id().constData());
146 m_audioVolume.sink().modifyPipelineInIdleProbe([&] {
147 qUnlinkGstElements(m_audioSrc, m_audioVolume);
148 m_audioInputBin.stopAndRemoveElements(m_audioSrc);
149 m_audioSrc = std::move(newSrc);
150 m_audioInputBin.add(m_audioSrc);
151 qLinkGstElements(m_audioSrc, m_audioVolume);
152 m_audioSrc.syncStateWithParent();
static QGstBin createFromPipelineDescription(const char *pipelineDescription, const char *name=nullptr, bool ghostUnlinkedPads=false)
static QGstElement createFromFactory(const char *factory, const char *name=nullptr)
Combined button and popup list for selecting options.
constexpr QLatin1String defaultSrcName
bool srcHasDeviceProperty(const QGstElement &element)