File indexing completed on 2025-04-13 08:09:52
0001 /* 0002 SPDX-FileCopyrightText: 2014-2015 Harald Sitter <sitter@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 0007 #include "sink.h" 0008 0009 #include "context.h" 0010 #include "server.h" 0011 #include "sinkinput.h" 0012 0013 namespace QPulseAudio 0014 { 0015 Sink::Sink(QObject *parent) 0016 : Device(parent) 0017 { 0018 connect(context()->server(), &Server::defaultSinkChanged, this, &Sink::defaultChanged); 0019 } 0020 0021 Sink::~Sink() = default; 0022 0023 void Sink::update(const pa_sink_info *info) 0024 { 0025 updateDevice(info); 0026 if (m_monitorIndex != info->monitor_source) { 0027 m_monitorIndex = info->monitor_source; 0028 Q_EMIT monitorIndexChanged(); 0029 } 0030 } 0031 0032 void Sink::setVolume(qint64 volume) 0033 { 0034 context()->setGenericVolume(index(), -1, volume, cvolume(), &pa_context_set_sink_volume_by_index); 0035 } 0036 0037 void Sink::setMuted(bool muted) 0038 { 0039 context()->setGenericMute(m_index, muted, &pa_context_set_sink_mute_by_index); 0040 } 0041 0042 void Sink::setActivePortIndex(quint32 port_index) 0043 { 0044 Port *port = qobject_cast<Port *>(ports().at(port_index)); 0045 if (!port) { 0046 qCWarning(PLASMAPA) << "invalid port set request" << port_index; 0047 return; 0048 } 0049 context()->setGenericPort(index(), port->name(), &pa_context_set_sink_port_by_index); 0050 } 0051 0052 void Sink::setChannelVolume(int channel, qint64 volume) 0053 { 0054 context()->setGenericVolume(index(), channel, volume, cvolume(), &pa_context_set_sink_volume_by_index); 0055 } 0056 0057 void Sink::setChannelVolumes(const QList<qint64> &channelVolumes) 0058 { 0059 context()->setGenericVolumes(index(), channelVolumes, cvolume(), &pa_context_set_sink_volume_by_index); 0060 } 0061 0062 bool Sink::isDefault() const 0063 { 0064 return context()->server()->defaultSink() == this; 0065 } 0066 0067 void Sink::setDefault(bool enable) 0068 { 0069 if (!isDefault() && enable) { 0070 context()->server()->setDefaultSink(this); 0071 } 0072 } 0073 0074 void Sink::switchStreams() 0075 { 0076 const auto data = context()->sinkInputs().data(); 0077 std::for_each(data.begin(), data.end(), [this](SinkInput *paObj) { 0078 paObj->setDeviceIndex(m_index); 0079 }); 0080 } 0081 0082 quint32 Sink::monitorIndex() const 0083 { 0084 return m_monitorIndex; 0085 } 0086 0087 } // QPulseAudio