Changeset View
Changeset View
Standalone View
Standalone View
src/context.cpp
Show First 20 Lines • Show All 172 Lines • ▼ Show 20 Line(s) | |||||
173 | { | 173 | { | ||
174 | Q_ASSERT(context); | 174 | Q_ASSERT(context); | ||
175 | Q_ASSERT(data); | 175 | Q_ASSERT(data); | ||
176 | if (!PAOperation(pa_ext_stream_restore_read(context, ext_stream_restore_read_cb, data))) { | 176 | if (!PAOperation(pa_ext_stream_restore_read(context, ext_stream_restore_read_cb, data))) { | ||
177 | qCWarning(PLASMAPA) << "pa_ext_stream_restore_read() failed"; | 177 | qCWarning(PLASMAPA) << "pa_ext_stream_restore_read() failed"; | ||
178 | } | 178 | } | ||
179 | } | 179 | } | ||
180 | 180 | | |||
181 | static void ext_stream_restore_change_sink_cb(pa_context *context, const pa_ext_stream_restore_info *info, int eol, void *data) | ||||
182 | { | ||||
183 | if (!isGoodState(eol)) { | ||||
184 | return; | ||||
185 | } | ||||
186 | Q_ASSERT(context); | ||||
187 | Q_ASSERT(data); | ||||
188 | if (qstrncmp(info->name, "sink-input-by", 13) == 0) { | ||||
189 | Context *context = static_cast<Context *>(data); | ||||
190 | const QByteArray deviceData = context->newDefaultSink().toUtf8(); | ||||
191 | pa_ext_stream_restore_info newinfo; | ||||
192 | newinfo.name = info->name; | ||||
193 | newinfo.channel_map = info->channel_map; | ||||
194 | newinfo.volume = info->volume; | ||||
195 | newinfo.mute = info->mute; | ||||
196 | newinfo.device = deviceData.constData(); | ||||
197 | context->streamRestoreWrite(&newinfo); | ||||
198 | } | ||||
199 | } | ||||
200 | | ||||
201 | static void ext_stream_restore_change_source_cb(pa_context *context, const pa_ext_stream_restore_info *info, int eol, void *data) | ||||
202 | { | ||||
203 | if (!isGoodState(eol)) { | ||||
204 | return; | ||||
205 | } | ||||
206 | Q_ASSERT(context); | ||||
207 | Q_ASSERT(data); | ||||
208 | if (qstrncmp(info->name, "source-output-by", 16) == 0) { | ||||
209 | Context *context = static_cast<Context *>(data); | ||||
210 | const QByteArray deviceData = context->newDefaultSource().toUtf8(); | ||||
211 | pa_ext_stream_restore_info newinfo; | ||||
212 | newinfo.name = info->name; | ||||
213 | newinfo.channel_map = info->channel_map; | ||||
214 | newinfo.volume = info->volume; | ||||
215 | newinfo.mute = info->mute; | ||||
216 | newinfo.device = deviceData.constData(); | ||||
217 | context->streamRestoreWrite(&newinfo); | ||||
218 | } | ||||
219 | } | ||||
220 | | ||||
181 | // -------------------------- | 221 | // -------------------------- | ||
182 | 222 | | |||
183 | Context::Context(QObject *parent) | 223 | Context::Context(QObject *parent) | ||
184 | : QObject(parent) | 224 | : QObject(parent) | ||
185 | , m_server(new Server(this)) | 225 | , m_server(new Server(this)) | ||
186 | , m_context(nullptr) | 226 | , m_context(nullptr) | ||
187 | , m_mainloop(nullptr) | 227 | , m_mainloop(nullptr) | ||
188 | , m_references(0) | 228 | , m_references(0) | ||
▲ Show 20 Lines • Show All 295 Lines • ▼ Show 20 Line(s) | 521 | { | |||
484 | } | 524 | } | ||
485 | const QByteArray nameData = name.toUtf8(); | 525 | const QByteArray nameData = name.toUtf8(); | ||
486 | if (!PAOperation(pa_context_set_default_sink(m_context, | 526 | if (!PAOperation(pa_context_set_default_sink(m_context, | ||
487 | nameData.constData(), | 527 | nameData.constData(), | ||
488 | nullptr, | 528 | nullptr, | ||
489 | nullptr))) { | 529 | nullptr))) { | ||
490 | qCWarning(PLASMAPA) << "pa_context_set_default_sink failed"; | 530 | qCWarning(PLASMAPA) << "pa_context_set_default_sink failed"; | ||
491 | } | 531 | } | ||
532 | | ||||
533 | // Change device for all entries in stream-restore database | ||||
534 | m_newDefaultSink = name; | ||||
535 | if (!PAOperation(pa_ext_stream_restore_read(m_context, | ||||
536 | ext_stream_restore_change_sink_cb, | ||||
537 | this))) { | ||||
538 | qCWarning(PLASMAPA) << "pa_ext_stream_restore_read failed"; | ||||
539 | } | ||||
492 | } | 540 | } | ||
493 | 541 | | |||
494 | void Context::setDefaultSource(const QString &name) | 542 | void Context::setDefaultSource(const QString &name) | ||
495 | { | 543 | { | ||
496 | if (!m_context) { | 544 | if (!m_context) { | ||
497 | return; | 545 | return; | ||
498 | } | 546 | } | ||
499 | const QByteArray nameData = name.toUtf8(); | 547 | const QByteArray nameData = name.toUtf8(); | ||
500 | if (!PAOperation(pa_context_set_default_source(m_context, | 548 | if (!PAOperation(pa_context_set_default_source(m_context, | ||
501 | nameData.constData(), | 549 | nameData.constData(), | ||
502 | nullptr, | 550 | nullptr, | ||
503 | nullptr))) { | 551 | nullptr))) { | ||
504 | qCWarning(PLASMAPA) << "pa_context_set_default_source failed"; | 552 | qCWarning(PLASMAPA) << "pa_context_set_default_source failed"; | ||
505 | } | 553 | } | ||
554 | | ||||
555 | // Change device for all entries in stream-restore database | ||||
556 | m_newDefaultSource = name; | ||||
557 | if (!PAOperation(pa_ext_stream_restore_read(m_context, | ||||
558 | ext_stream_restore_change_source_cb, | ||||
559 | this))) { | ||||
560 | qCWarning(PLASMAPA) << "pa_ext_stream_restore_read failed"; | ||||
561 | } | ||||
506 | } | 562 | } | ||
507 | 563 | | |||
508 | void Context::streamRestoreWrite(const pa_ext_stream_restore_info *info) | 564 | void Context::streamRestoreWrite(const pa_ext_stream_restore_info *info) | ||
509 | { | 565 | { | ||
510 | if (!m_context) { | 566 | if (!m_context) { | ||
511 | return; | 567 | return; | ||
512 | } | 568 | } | ||
513 | if (!PAOperation(pa_ext_stream_restore_write(m_context, | 569 | if (!PAOperation(pa_ext_stream_restore_write(m_context, | ||
▲ Show 20 Lines • Show All 55 Lines • Show Last 20 Lines |