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 d->writeChanges(vol, d->m_cache.muted, d->m_cache.device);
119 d->writeChanges(vol, d->m_muted, d->m_device);
123bool StreamRestore::isMuted()
const
128 if (d->m_cache.valid) {
129 return d->m_cache.muted;
135void StreamRestore::setMuted(
bool muted)
137 if (d->m_cache.valid) {
138 if (d->m_cache.muted != muted) {
139 d->writeChanges(d->m_cache.volume, muted, d->m_cache.device);
142 if (d->m_muted != muted) {
143 d->writeChanges(d->m_volume, muted, d->m_device);
148bool StreamRestore::hasVolume()
const
153bool StreamRestore::isVolumeWritable()
const
160 return d->m_channels;
166 ret.
reserve(d->m_volume.channels);
167 for (
int i = 0; i < d->m_volume.channels; ++i) {
168 ret << d->m_volume.values[i];
173void StreamRestore::setChannelVolume(
int channel, qint64 volume)
175 Q_ASSERT(channel >= 0 && channel < d->m_volume.channels);
176 pa_cvolume vol = d->m_cache.valid ? d->m_cache.volume : d->m_volume;
177 vol.values[channel] =
volume;
179 if (d->m_cache.valid) {
180 d->writeChanges(vol, d->m_cache.muted, d->m_cache.device);
182 d->writeChanges(vol, d->m_muted, d->m_device);
186quint32 StreamRestore::deviceIndex()
const
188 return PA_INVALID_INDEX;
191void StreamRestore::setDeviceIndex(quint32 deviceIndex)
193 Q_UNUSED(deviceIndex);
194 qCWarning(PULSEAUDIOQT) <<
"Not implemented";
197void StreamRestorePrivate::writeChanges(
const pa_cvolume &volume,
bool muted,
const QString &device)
199 const QByteArray nameData = q->name().toUtf8();
202 pa_ext_stream_restore_info info;
204 info.channel_map = m_channelMap;
211 if (info.channel_map.channels == 0) {
212 info.channel_map.channels = 1;
213 info.channel_map.map[0] = PA_CHANNEL_POSITION_MONO;
216 m_cache.valid =
true;
218 m_cache.muted = muted;
219 m_cache.device = device;
221 Context::instance()->d->streamRestoreWrite(&info);
224quint32 StreamRestore::index()
const
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