summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/pavucontrol.cc49
1 files changed, 41 insertions, 8 deletions
diff --git a/src/pavucontrol.cc b/src/pavucontrol.cc
index 4e62f33..92bcc48 100644
--- a/src/pavucontrol.cc
+++ b/src/pavucontrol.cc
@@ -62,6 +62,7 @@ static int default_tab = 0;
static bool retry = false;
static int reconnect_timeout = 1;
static QRegularExpression select_output;
+static uint32_t select_output_card = UINT32_MAX;
void show_error(const char *txt) {
char buf[256];
@@ -101,9 +102,30 @@ static void card_cb(pa_context *, const pa_card_info *i, int eol, void *userdata
w->updateCard(*i);
}
-static void card_cb_setdef(pa_context * ctx, const pa_card_info *i, int eol, void *) {
+static void sink_cb_setdef(pa_context *ctx, const pa_sink_info *sink_info, int eol, void *) {
if (eol < 0) {
- if (pa_context_errno(context) == PA_ERR_NOENTITY)
+ if (pa_context_errno(ctx) == PA_ERR_NOENTITY)
+ return;
+ show_error(QObject::tr("Card callback failure").toUtf8().constData());
+ return;
+ }
+ if (eol > 0)
+ return;
+ if (sink_info->card != select_output_card)
+ return;
+
+ printf("Setting default sink of card %d which is sink '%s' (%s)\n", (int)sink_info->card, sink_info->name, sink_info->description);
+ pa_operation *o;
+ if (!(o = pa_context_set_default_sink(ctx, sink_info->name, nullptr, nullptr))) {
+ printf("pa_context_set_default_sink() failed\n");
+ return;
+ }
+ pa_operation_unref(o);
+}
+
+static void card_cb_setdef(pa_context * ctx, const pa_card_info *card_info, int eol, void *) {
+ if (eol < 0) {
+ if (pa_context_errno(ctx) == PA_ERR_NOENTITY)
return;
show_error(QObject::tr("Card callback failure").toUtf8().constData());
@@ -111,6 +133,15 @@ static void card_cb_setdef(pa_context * ctx, const pa_card_info *i, int eol, voi
}
if (eol > 0) {
+ pa_operation *o;
+ printf("Trying to set default sink to card %d\n", (int)select_output_card);
+ if (select_output_card != UINT32_MAX) {
+ if (!(o = pa_context_get_sink_info_list(ctx, sink_cb_setdef, nullptr))) {
+ show_error(QObject::tr("pa_context_get_sink_info_list() failed").toUtf8().constData());
+ return;
+ }
+ pa_operation_unref(o);
+ }
return;
}
@@ -121,11 +152,11 @@ static void card_cb_setdef(pa_context * ctx, const pa_card_info *i, int eol, voi
QMap<QString, ProfileGroup> profiles;
profile_priorities.clear();
- for (pa_card_profile_info2 ** p_profile = i->profiles2; p_profile && *p_profile != nullptr; ++p_profile) {
+ for (pa_card_profile_info2 ** p_profile = card_info->profiles2; p_profile && *p_profile != nullptr; ++p_profile) {
profile_priorities.insert(*p_profile);
}
- populatePorts(*i, ports);
+ populatePorts(*card_info, ports);
groupProfiles(profile_priorities, ports, profiles);
ProfileGroup *best = nullptr;
@@ -134,6 +165,8 @@ static void card_cb_setdef(pa_context * ctx, const pa_card_info *i, int eol, voi
// Maybe we should track per-profile availability too and scan the list...
if (best == nullptr || p.available) {
best = &p;
+ if (select_output_card == UINT32_MAX || p.available)
+ select_output_card = card_info->index;
if (p.available)
break;
}
@@ -144,8 +177,8 @@ static void card_cb_setdef(pa_context * ctx, const pa_card_info *i, int eol, voi
// Can we do this inside the callback?
pa_operation* o;
const auto *entry = best->entries.first().id.constData();
- printf("Selecting profile %s\n", entry);
- if (!(o = pa_context_set_card_profile_by_index(ctx, i->index, entry, nullptr, nullptr))) {
+ printf("Selecting profile %s of card %s\n", entry, card_info->name);
+ if (!(o = pa_context_set_card_profile_by_index(ctx, card_info->index, entry, nullptr, nullptr))) {
printf("pa_context_set_card_profile_by_index() failed\n");
return;
}
@@ -789,14 +822,14 @@ int main(int argc, char *argv[]) {
exit_code = 1;
} else {
int evs;
- int tries = 10;
+ int tries = 50;
exit_code = 100;
// WTF
while ((evs = pa_mainloop_iterate(m, 0, &exit_code)) >= 0) {
if (evs == 0) {
if (--tries == 0)
break;
- usleep(100000);
+ usleep(20000);
}
}
printf("Exit: %d\n", exit_code);