File indexing completed on 2024-04-21 04:43:26

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 #include "sink_p.h"
0009 
0010 #include "context.h"
0011 #include "context_p.h"
0012 #include "server.h"
0013 #include "sinkinput.h"
0014 
0015 #include "device_p.h"
0016 #include "volumeobject_p.h"
0017 
0018 namespace PulseAudioQt
0019 {
0020 Sink::Sink(QObject *parent)
0021     : Device(parent)
0022     , d(new SinkPrivate(this))
0023 {
0024     connect(Context::instance()->server(), &Server::defaultSinkChanged, this, &Sink::defaultChanged);
0025 }
0026 
0027 SinkPrivate::SinkPrivate(Sink *q)
0028     : q(q)
0029 {
0030 }
0031 
0032 Sink::~Sink()
0033 {
0034     delete d;
0035 }
0036 
0037 void SinkPrivate::update(const pa_sink_info *info)
0038 {
0039     q->Device::d->updateDevice(info);
0040 
0041     if (m_monitorIndex != info->monitor_source) {
0042         m_monitorIndex = info->monitor_source;
0043         Q_EMIT q->monitorIndexChanged();
0044     }
0045 }
0046 
0047 void Sink::setVolume(qint64 volume)
0048 {
0049     Context::instance()->d->setGenericVolume(index(), -1, volume, VolumeObject::d->cvolume(), &pa_context_set_sink_volume_by_index);
0050 }
0051 
0052 void Sink::setMuted(bool muted)
0053 {
0054     Context::instance()->d->setGenericMute(index(), muted, &pa_context_set_sink_mute_by_index);
0055 }
0056 
0057 void Sink::setActivePortIndex(quint32 port_index)
0058 {
0059     Port *port = qobject_cast<Port *>(ports().at(port_index));
0060     if (!port) {
0061         qCWarning(PULSEAUDIOQT) << "invalid port set request" << port_index;
0062         return;
0063     }
0064     Context::instance()->d->setGenericPort(index(), port->name(), &pa_context_set_sink_port_by_index);
0065 }
0066 
0067 void Sink::setChannelVolume(int channel, qint64 volume)
0068 {
0069     Context::instance()->d->setGenericVolume(index(), channel, volume, VolumeObject::d->cvolume(), &pa_context_set_sink_volume_by_index);
0070 }
0071 
0072 bool Sink::isDefault() const
0073 {
0074     return Context::instance()->server()->defaultSink() == this;
0075 }
0076 
0077 void Sink::setDefault(bool enable)
0078 {
0079     if (!isDefault() && enable) {
0080         Context::instance()->server()->setDefaultSink(this);
0081     }
0082 }
0083 
0084 quint32 Sink::monitorIndex() const
0085 {
0086     return d->m_monitorIndex;
0087 }
0088 
0089 void Sink::setChannelVolumes(const QVector<qint64> &channelVolumes)
0090 {
0091     Context::instance()->d->setGenericVolumes(index(), channelVolumes, VolumeObject::d->m_volume, &pa_context_set_sink_volume_by_index);
0092 }
0093 
0094 void Sink::switchStreams()
0095 {
0096     const auto sinkInputs = Context::instance()->sinkInputs();
0097     for (const auto &sinkInput : sinkInputs) {
0098         sinkInput->setDeviceIndex(index());
0099     }
0100 }
0101 
0102 } // PulseAudioQt