+ /* Attempt to inject the devices into the list in priority order */
+ total_devices = PA_MAX(pa_idxset_size(m->core->sinks), pa_idxset_size(m->core->sources));
+ if (total_devices > 0 && total_devices < 128) {
+ uint32_t i;
+ struct prioritised_indexes p_i[128];
+
+ /* We cycle over all the available sinks so that they are added to our database if they are not in it yet */
+ i = 0;
+ PA_IDXSET_FOREACH(sink, m->core->sinks, idx) {
+ pa_log_debug("Found sink index %u", sink->index);
+ p_i[i ].index = sink->index;
+ p_i[i++].priority = sink->priority;
+ }
+ /* Bubble sort it (only really useful for first time creation) */
+ if (i > 1)
+ for (uint32_t j = 0; j < i; ++j)
+ for (uint32_t k = 0; k < i; ++k)
+ if (p_i[j].priority > p_i[k].priority) {
+ struct prioritised_indexes tmp_pi = p_i[k];
+ p_i[k] = p_i[j];
+ p_i[j] = tmp_pi;
+ }
+ /* Register it */
+ for (uint32_t j = 0; j < i; ++j)
+ subscribe_callback(m->core, PA_SUBSCRIPTION_EVENT_SINK|PA_SUBSCRIPTION_EVENT_NEW, p_i[j].index, u);
+
+ /* We cycle over all the available sources so that they are added to our database if they are not in it yet */
+ i = 0;
+ PA_IDXSET_FOREACH(source, m->core->sources, idx) {
+ p_i[i ].index = source->index;
+ p_i[i++].priority = source->priority;
+ }
+ /* Bubble sort it (only really useful for first time creation) */
+ if (i > 1)
+ for (uint32_t j = 0; j < i; ++j)
+ for (uint32_t k = 0; k < i; ++k)
+ if (p_i[j].priority > p_i[k].priority) {
+ struct prioritised_indexes tmp_pi = p_i[k];
+ p_i[k] = p_i[j];
+ p_i[j] = tmp_pi;
+ }
+ /* Register it */
+ for (uint32_t j = 0; j < i; ++j)
+ subscribe_callback(m->core, PA_SUBSCRIPTION_EVENT_SOURCE|PA_SUBSCRIPTION_EVENT_NEW, p_i[j].index, u);
+ }
+ else if (total_devices > 0) {
+ /* This user has a *lot* of devices... */
+ PA_IDXSET_FOREACH(sink, m->core->sinks, idx)
+ subscribe_callback(m->core, PA_SUBSCRIPTION_EVENT_SINK|PA_SUBSCRIPTION_EVENT_NEW, sink->index, u);