Changeset View
Changeset View
Standalone View
Standalone View
src/context.cpp
Show All 27 Lines | |||||
28 | 28 | | |||
29 | #include "card.h" | 29 | #include "card.h" | ||
30 | #include "client.h" | 30 | #include "client.h" | ||
31 | #include "sink.h" | 31 | #include "sink.h" | ||
32 | #include "sinkinput.h" | 32 | #include "sinkinput.h" | ||
33 | #include "source.h" | 33 | #include "source.h" | ||
34 | #include "sourceoutput.h" | 34 | #include "sourceoutput.h" | ||
35 | #include "streamrestore.h" | 35 | #include "streamrestore.h" | ||
36 | #include "module.h" | ||||
36 | 37 | | |||
37 | namespace QPulseAudio | 38 | namespace QPulseAudio | ||
38 | { | 39 | { | ||
39 | 40 | | |||
40 | Context* Context::s_context = nullptr; | 41 | Context* Context::s_context = nullptr; | ||
41 | 42 | | |||
42 | static bool isGoodState(int eol) | 43 | static bool isGoodState(int eol) | ||
43 | { | 44 | { | ||
▲ Show 20 Lines • Show All 81 Lines • ▼ Show 20 Line(s) | |||||
125 | { | 126 | { | ||
126 | if (!isGoodState(eol)) | 127 | if (!isGoodState(eol)) | ||
127 | return; | 128 | return; | ||
128 | Q_ASSERT(context); | 129 | Q_ASSERT(context); | ||
129 | Q_ASSERT(data); | 130 | Q_ASSERT(data); | ||
130 | ((Context *)data)->cardCallback(info); | 131 | ((Context *)data)->cardCallback(info); | ||
131 | } | 132 | } | ||
132 | 133 | | |||
134 | static void module_info_list_cb(pa_context *context, const pa_module_info *info, int eol, void *data) | ||||
135 | { | ||||
136 | if (!isGoodState(eol)) | ||||
137 | return; | ||||
138 | Q_ASSERT(context); | ||||
139 | Q_ASSERT(data); | ||||
140 | ((Context *)data)->moduleCallback(info); | ||||
141 | } | ||||
142 | | ||||
133 | static void server_cb(pa_context *context, const pa_server_info *info, void *data) | 143 | static void server_cb(pa_context *context, const pa_server_info *info, void *data) | ||
134 | { | 144 | { | ||
135 | Q_ASSERT(context); | 145 | Q_ASSERT(context); | ||
136 | Q_ASSERT(data); | 146 | Q_ASSERT(data); | ||
137 | ((Context *)data)->serverCallback(info); | 147 | ((Context *)data)->serverCallback(info); | ||
138 | } | 148 | } | ||
139 | 149 | | |||
140 | static void context_state_callback(pa_context *context, void *data) | 150 | static void context_state_callback(pa_context *context, void *data) | ||
▲ Show 20 Lines • Show All 141 Lines • ▼ Show 20 Line(s) | 289 | case PA_SUBSCRIPTION_EVENT_CARD: | |||
282 | } else { | 292 | } else { | ||
283 | if (!PAOperation(pa_context_get_card_info_by_index(context, index, card_cb, this))) { | 293 | if (!PAOperation(pa_context_get_card_info_by_index(context, index, card_cb, this))) { | ||
284 | qCWarning(PLASMAPA) << "pa_context_get_card_info_by_index() failed"; | 294 | qCWarning(PLASMAPA) << "pa_context_get_card_info_by_index() failed"; | ||
285 | return; | 295 | return; | ||
286 | } | 296 | } | ||
287 | } | 297 | } | ||
288 | break; | 298 | break; | ||
289 | 299 | | |||
300 | case PA_SUBSCRIPTION_EVENT_MODULE: | ||||
301 | if ((type & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_REMOVE) { | ||||
302 | m_modules.removeEntry(index); | ||||
303 | } else { | ||||
304 | if (!PAOperation(pa_context_get_module_info_list(context, module_info_list_cb, this))) { | ||||
305 | qCWarning(PLASMAPA) << "pa_context_get_module_info_list() failed"; | ||||
306 | return; | ||||
307 | } | ||||
308 | } | ||||
309 | break; | ||||
310 | | ||||
311 | | ||||
290 | case PA_SUBSCRIPTION_EVENT_SERVER: | 312 | case PA_SUBSCRIPTION_EVENT_SERVER: | ||
291 | if (!PAOperation(pa_context_get_server_info(context, server_cb, this))) { | 313 | if (!PAOperation(pa_context_get_server_info(context, server_cb, this))) { | ||
292 | qCWarning(PLASMAPA) << "pa_context_get_server_info() failed"; | 314 | qCWarning(PLASMAPA) << "pa_context_get_server_info() failed"; | ||
293 | return; | 315 | return; | ||
294 | } | 316 | } | ||
295 | break; | 317 | break; | ||
296 | 318 | | |||
297 | } | 319 | } | ||
Show All 12 Lines | 330 | if (m_context == c) { | |||
310 | 332 | | |||
311 | if (!PAOperation(pa_context_subscribe(c, (pa_subscription_mask_t) | 333 | if (!PAOperation(pa_context_subscribe(c, (pa_subscription_mask_t) | ||
312 | (PA_SUBSCRIPTION_MASK_SINK| | 334 | (PA_SUBSCRIPTION_MASK_SINK| | ||
313 | PA_SUBSCRIPTION_MASK_SOURCE| | 335 | PA_SUBSCRIPTION_MASK_SOURCE| | ||
314 | PA_SUBSCRIPTION_MASK_CLIENT| | 336 | PA_SUBSCRIPTION_MASK_CLIENT| | ||
315 | PA_SUBSCRIPTION_MASK_SINK_INPUT| | 337 | PA_SUBSCRIPTION_MASK_SINK_INPUT| | ||
316 | PA_SUBSCRIPTION_MASK_SOURCE_OUTPUT| | 338 | PA_SUBSCRIPTION_MASK_SOURCE_OUTPUT| | ||
317 | PA_SUBSCRIPTION_MASK_CARD| | 339 | PA_SUBSCRIPTION_MASK_CARD| | ||
340 | PA_SUBSCRIPTION_MASK_MODULE| | ||||
318 | PA_SUBSCRIPTION_MASK_SERVER), nullptr, nullptr))) { | 341 | PA_SUBSCRIPTION_MASK_SERVER), nullptr, nullptr))) { | ||
319 | qCWarning(PLASMAPA) << "pa_context_subscribe() failed"; | 342 | qCWarning(PLASMAPA) << "pa_context_subscribe() failed"; | ||
320 | return; | 343 | return; | ||
321 | } | 344 | } | ||
322 | } | 345 | } | ||
323 | 346 | | |||
324 | if (!PAOperation(pa_context_get_sink_info_list(c, sink_cb, this))) { | 347 | if (!PAOperation(pa_context_get_sink_info_list(c, sink_cb, this))) { | ||
325 | qCWarning(PLASMAPA) << "pa_context_get_sink_info_list() failed"; | 348 | qCWarning(PLASMAPA) << "pa_context_get_sink_info_list() failed"; | ||
Show All 20 Lines | 367 | if (!PAOperation(pa_context_get_sink_input_info_list(c, sink_input_callback, this))) { | |||
346 | return; | 369 | return; | ||
347 | } | 370 | } | ||
348 | 371 | | |||
349 | if (!PAOperation(pa_context_get_source_output_info_list(c, source_output_cb, this))) { | 372 | if (!PAOperation(pa_context_get_source_output_info_list(c, source_output_cb, this))) { | ||
350 | qCWarning(PLASMAPA) << "pa_context_get_source_output_info_list() failed"; | 373 | qCWarning(PLASMAPA) << "pa_context_get_source_output_info_list() failed"; | ||
351 | return; | 374 | return; | ||
352 | } | 375 | } | ||
353 | 376 | | |||
377 | if (!PAOperation(pa_context_get_module_info_list(c, module_info_list_cb, this))) { | ||||
378 | qCWarning(PLASMAPA) << "pa_context_get_module_info_list() failed"; | ||||
379 | return; | ||||
380 | } | ||||
381 | | ||||
354 | if (!PAOperation(pa_context_get_server_info(c, server_cb, this))) { | 382 | if (!PAOperation(pa_context_get_server_info(c, server_cb, this))) { | ||
355 | qCWarning(PLASMAPA) << "pa_context_get_server_info() failed"; | 383 | qCWarning(PLASMAPA) << "pa_context_get_server_info() failed"; | ||
356 | return; | 384 | return; | ||
357 | } | 385 | } | ||
358 | 386 | | |||
359 | if (PAOperation(pa_ext_stream_restore_read(c, ext_stream_restore_read_cb, this))) { | 387 | if (PAOperation(pa_ext_stream_restore_read(c, ext_stream_restore_read_cb, this))) { | ||
360 | pa_ext_stream_restore_set_subscribe_cb(c, ext_stream_restore_subscribe_cb, this); | 388 | pa_ext_stream_restore_set_subscribe_cb(c, ext_stream_restore_subscribe_cb, this); | ||
361 | PAOperation(pa_ext_stream_restore_subscribe(c, 1, nullptr, this)); | 389 | PAOperation(pa_ext_stream_restore_subscribe(c, 1, nullptr, this)); | ||
Show All 37 Lines | 426 | { | |||
399 | m_clients.updateEntry(info, this); | 427 | m_clients.updateEntry(info, this); | ||
400 | } | 428 | } | ||
401 | 429 | | |||
402 | void Context::cardCallback(const pa_card_info *info) | 430 | void Context::cardCallback(const pa_card_info *info) | ||
403 | { | 431 | { | ||
404 | m_cards.updateEntry(info, this); | 432 | m_cards.updateEntry(info, this); | ||
405 | } | 433 | } | ||
406 | 434 | | |||
435 | void Context::moduleCallback(const pa_module_info *info) | ||||
436 | { | ||||
437 | m_modules.updateEntry(info, this); | ||||
438 | } | ||||
439 | | ||||
407 | void Context::streamRestoreCallback(const pa_ext_stream_restore_info *info) | 440 | void Context::streamRestoreCallback(const pa_ext_stream_restore_info *info) | ||
408 | { | 441 | { | ||
409 | if (qstrcmp(info->name, "sink-input-by-media-role:event") != 0) { | 442 | if (qstrcmp(info->name, "sink-input-by-media-role:event") != 0) { | ||
410 | return; | 443 | return; | ||
411 | } | 444 | } | ||
412 | 445 | | |||
413 | const int eventRoleIndex = 1; | 446 | const int eventRoleIndex = 1; | ||
414 | StreamRestore *obj = qobject_cast<StreamRestore *>(m_streamRestores.data().value(eventRoleIndex)); | 447 | StreamRestore *obj = qobject_cast<StreamRestore *>(m_streamRestores.data().value(eventRoleIndex)); | ||
▲ Show 20 Lines • Show All 106 Lines • ▼ Show 20 Line(s) | |||||
521 | 554 | | |||
522 | void Context::reset() | 555 | void Context::reset() | ||
523 | { | 556 | { | ||
524 | m_sinks.reset(); | 557 | m_sinks.reset(); | ||
525 | m_sinkInputs.reset(); | 558 | m_sinkInputs.reset(); | ||
526 | m_sources.reset(); | 559 | m_sources.reset(); | ||
527 | m_sourceOutputs.reset(); | 560 | m_sourceOutputs.reset(); | ||
528 | m_clients.reset(); | 561 | m_clients.reset(); | ||
562 | m_cards.reset(); | ||||
563 | m_modules.reset(); | ||||
564 | m_streamRestores.reset(); | ||||
529 | m_server->reset(); | 565 | m_server->reset(); | ||
530 | } | 566 | } | ||
531 | 567 | | |||
532 | } // QPulseAudio | 568 | } // QPulseAudio |