7#include "streamrestore.h"
10#include "streamrestore_p.h"
13#include "pulseobject_p.h"
17StreamRestore::StreamRestore(quint32 index,
const QVariantMap &properties,
QObject *parent)
19 , d(new StreamRestorePrivate(this))
21 memset(&d->m_volume, 0,
sizeof(d->m_volume));
22 memset(&d->m_channelMap, 0,
sizeof(d->m_channelMap));
28StreamRestore::~StreamRestore()
33StreamRestorePrivate::StreamRestorePrivate(StreamRestore *q)
38StreamRestorePrivate::~StreamRestorePrivate()
42void StreamRestorePrivate::update(
const pa_ext_stream_restore_info *info)
44 q->PulseObject::d->updatePulseObject(info);
45 m_cache.valid =
false;
48 if (m_device != infoDevice) {
49 m_device = infoDevice;
50 Q_EMIT q->deviceChanged();
52 if (m_muted != info->mute) {
54 Q_EMIT q->mutedChanged();
56 if (!pa_cvolume_equal(&m_volume, &info->volume)) {
57 m_volume = info->volume;
58 Q_EMIT q->volumeChanged();
59 Q_EMIT q->channelVolumesChanged();
61 if (!pa_channel_map_equal(&m_channelMap, &info->channel_map)) {
63 m_channels.reserve(info->channel_map.channels);
64 for (
int i = 0; i < info->channel_map.channels; ++i) {
65 m_channels <<
QString::fromUtf8(pa_channel_position_to_pretty_string(info->channel_map.map[i]));
67 m_channelMap = info->channel_map;
68 Q_EMIT q->channelsChanged();
72QString StreamRestore::device()
const
77void StreamRestore::setDevice(
const QString &device)
79 if (d->m_cache.valid) {
80 if (d->m_cache.device != device) {
81 d->writeChanges(d->m_cache.volume, d->m_cache.muted, device);
84 if (d->m_device != device) {
85 d->writeChanges(d->m_volume, d->m_muted, device);
90qint64 StreamRestore::volume()
const
95 if (d->m_cache.valid) {
96 return d->m_cache.volume.values[0];
98 return d->m_volume.values[0];
102void StreamRestore::setVolume(qint64 volume)
104 pa_cvolume vol = d->m_cache.valid ? d->m_cache.volume : d->m_volume;
108 if (vol.channels == 0) {
112 for (
int i = 0; i < vol.channels; ++i) {
116 if (d->m_cache.valid) {
117 qCDebug(PULSEAUDIOQT) <<
"Changing cached volume of StreamRestore" <<
name() <<
" to " <<
volume;
118 d->writeChanges(vol, d->m_cache.muted, d->m_cache.device);
120 qCDebug(PULSEAUDIOQT) <<
"Changing uncached volume of StreamRestore" <<
name() <<
" to " <<
volume;
121 d->writeChanges(vol, d->m_muted, d->m_device);
125bool StreamRestore::isMuted()
const
130 if (d->m_cache.valid) {
131 return d->m_cache.muted;
137void StreamRestore::setMuted(
bool muted)
139 if (d->m_cache.valid) {
140 if (d->m_cache.muted != muted) {
141 d->writeChanges(d->m_cache.volume, muted, d->m_cache.device);
144 if (d->m_muted != muted) {
145 d->writeChanges(d->m_volume, muted, d->m_device);
150bool StreamRestore::hasVolume()
const
155bool StreamRestore::isVolumeWritable()
const
162 return d->m_channels;
168 ret.
reserve(d->m_volume.channels);
169 for (
int i = 0; i < d->m_volume.channels; ++i) {
170 ret << d->m_volume.values[i];
175void StreamRestore::setChannelVolume(
int channel, qint64 volume)
177 Q_ASSERT(channel >= 0 && channel < d->m_volume.channels);
178 pa_cvolume vol = d->m_cache.valid ? d->m_cache.volume : d->m_volume;
179 vol.values[channel] =
volume;
181 if (d->m_cache.valid) {
182 d->writeChanges(vol, d->m_cache.muted, d->m_cache.device);
184 d->writeChanges(vol, d->m_muted, d->m_device);
188quint32 StreamRestore::deviceIndex()
const
190 return PA_INVALID_INDEX;
193void StreamRestore::setDeviceIndex(quint32 deviceIndex)
195 Q_UNUSED(deviceIndex);
196 qCWarning(PULSEAUDIOQT) <<
"Not implemented";
199void StreamRestorePrivate::writeChanges(
const pa_cvolume &volume,
bool muted,
const QString &device)
201 const QByteArray nameData = q->name().toUtf8();
204 pa_ext_stream_restore_info info;
206 info.channel_map = m_channelMap;
213 if (info.channel_map.channels == 0) {
214 info.channel_map.channels = 1;
215 info.channel_map.map[0] = PA_CHANNEL_POSITION_MONO;
218 m_cache.valid =
true;
220 m_cache.muted = muted;
221 m_cache.device = device;
223 Context::instance()->d->streamRestoreWrite(&info);
226quint32 StreamRestore::index()
const
QString name(StandardAction id)
The primary namespace of PulseAudioQt.
const char * constData() const const
bool isEmpty() const const
void reserve(qsizetype size)
QString fromUtf8(QByteArrayView str)
QByteArray toUtf8() const const