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()
32StreamRestorePrivate::StreamRestorePrivate(StreamRestore *q)
37StreamRestorePrivate::~StreamRestorePrivate()
41void StreamRestorePrivate::update(
const pa_ext_stream_restore_info *info)
43 q->PulseObject::d->updatePulseObject(info);
44 m_cache.valid =
false;
47 if (m_device != infoDevice) {
48 m_device = infoDevice;
49 Q_EMIT q->deviceChanged();
51 if (m_muted != info->mute) {
53 Q_EMIT q->mutedChanged();
55 if (!pa_cvolume_equal(&m_volume, &info->volume)) {
56 m_volume = info->volume;
57 Q_EMIT q->volumeChanged();
58 Q_EMIT q->channelVolumesChanged();
60 if (!pa_channel_map_equal(&m_channelMap, &info->channel_map)) {
62 m_channels.reserve(info->channel_map.channels);
63 for (
int i = 0; i < info->channel_map.channels; ++i) {
64 m_channels <<
QString::fromUtf8(pa_channel_position_to_pretty_string(info->channel_map.map[i]));
66 m_channelMap = info->channel_map;
67 Q_EMIT q->channelsChanged();
71QString StreamRestore::device()
const
76void StreamRestore::setDevice(
const QString &device)
78 if (d->m_cache.valid) {
79 if (d->m_cache.device != device) {
80 d->writeChanges(d->m_cache.volume, d->m_cache.muted, device);
83 if (d->m_device != device) {
84 d->writeChanges(d->m_volume, d->m_muted, device);
89qint64 StreamRestore::volume()
const
94 if (d->m_cache.valid) {
95 return d->m_cache.volume.values[0];
97 return d->m_volume.values[0];
101void StreamRestore::setVolume(qint64 volume)
103 pa_cvolume vol = d->m_cache.valid ? d->m_cache.volume : d->m_volume;
107 if (vol.channels == 0) {
111 for (
int i = 0; i < vol.channels; ++i) {
115 if (d->m_cache.valid) {
116 qCDebug(PULSEAUDIOQT) <<
"Changing cached volume of StreamRestore" <<
name() <<
" to " <<
volume;
117 d->writeChanges(vol, d->m_cache.muted, d->m_cache.device);
119 qCDebug(PULSEAUDIOQT) <<
"Changing uncached volume of StreamRestore" <<
name() <<
" to " <<
volume;
120 d->writeChanges(vol, d->m_muted, d->m_device);
124bool StreamRestore::isMuted()
const
129 if (d->m_cache.valid) {
130 return d->m_cache.muted;
136void StreamRestore::setMuted(
bool muted)
138 if (d->m_cache.valid) {
139 if (d->m_cache.muted != muted) {
140 d->writeChanges(d->m_cache.volume, muted, d->m_cache.device);
143 if (d->m_muted != muted) {
144 d->writeChanges(d->m_volume, muted, d->m_device);
149bool StreamRestore::hasVolume()
const
154bool StreamRestore::isVolumeWritable()
const
161 return d->m_channels;
167 ret.
reserve(d->m_volume.channels);
168 for (
int i = 0; i < d->m_volume.channels; ++i) {
169 ret << d->m_volume.values[i];
174void StreamRestore::setChannelVolume(
int channel, qint64 volume)
176 Q_ASSERT(channel >= 0 && channel < d->m_volume.channels);
177 pa_cvolume vol = d->m_cache.valid ? d->m_cache.volume : d->m_volume;
178 vol.values[channel] =
volume;
180 if (d->m_cache.valid) {
181 d->writeChanges(vol, d->m_cache.muted, d->m_cache.device);
183 d->writeChanges(vol, d->m_muted, d->m_device);
187quint32 StreamRestore::deviceIndex()
const
189 return PA_INVALID_INDEX;
192void StreamRestore::setDeviceIndex(quint32 deviceIndex)
194 Q_UNUSED(deviceIndex);
195 qCWarning(PULSEAUDIOQT) <<
"Not implemented";
198void StreamRestorePrivate::writeChanges(
const pa_cvolume &volume,
bool muted,
const QString &device)
200 const QByteArray nameData = q->name().toUtf8();
203 pa_ext_stream_restore_info info;
205 info.channel_map = m_channelMap;
212 if (info.channel_map.channels == 0) {
213 info.channel_map.channels = 1;
214 info.channel_map.map[0] = PA_CHANNEL_POSITION_MONO;
217 m_cache.valid =
true;
219 m_cache.muted = muted;
220 m_cache.device = device;
222 Context::instance()->d->streamRestoreWrite(&info);
225quint32 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