2009-01-21 02:49:42 +01:00
|
|
|
/***
|
|
|
|
|
This file is part of PulseAudio.
|
|
|
|
|
|
|
|
|
|
Copyright 2006-2008 Lennart Poettering
|
|
|
|
|
|
|
|
|
|
PulseAudio is free software; you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as published
|
2009-03-03 20:23:02 +00:00
|
|
|
by the Free Software Foundation; either version 2.1 of the License,
|
2009-01-21 02:49:42 +01:00
|
|
|
or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
PulseAudio is distributed in the hope that it will be useful, but
|
|
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
2014-11-26 14:14:51 +01:00
|
|
|
along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
|
2009-01-21 02:49:42 +01:00
|
|
|
***/
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
#include <config.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
2011-06-13 15:04:33 +02:00
|
|
|
#include <pulse/gccmacro.h>
|
2009-01-21 02:49:42 +01:00
|
|
|
#include <pulse/xmalloc.h>
|
|
|
|
|
#include <pulse/timeval.h>
|
2009-04-05 02:13:43 +03:00
|
|
|
#include <pulse/rtclock.h>
|
2009-01-21 02:49:42 +01:00
|
|
|
|
|
|
|
|
#include <pulsecore/core-error.h>
|
|
|
|
|
#include <pulsecore/module.h>
|
|
|
|
|
#include <pulsecore/core-util.h>
|
|
|
|
|
#include <pulsecore/modargs.h>
|
|
|
|
|
#include <pulsecore/log.h>
|
|
|
|
|
#include <pulsecore/core-subscribe.h>
|
|
|
|
|
#include <pulsecore/card.h>
|
|
|
|
|
#include <pulsecore/namereg.h>
|
2009-05-14 01:24:26 +02:00
|
|
|
#include <pulsecore/database.h>
|
2011-06-07 23:21:04 +01:00
|
|
|
#include <pulsecore/tagstruct.h>
|
2009-01-21 02:49:42 +01:00
|
|
|
|
|
|
|
|
PA_MODULE_AUTHOR("Lennart Poettering");
|
|
|
|
|
PA_MODULE_DESCRIPTION("Automatically restore profile of cards");
|
|
|
|
|
PA_MODULE_VERSION(PACKAGE_VERSION);
|
2013-06-27 19:28:09 +02:00
|
|
|
PA_MODULE_LOAD_ONCE(true);
|
2018-07-20 12:39:22 -07:00
|
|
|
PA_MODULE_USAGE(
|
|
|
|
|
"restore_bluetooth_profile=<boolean>"
|
|
|
|
|
);
|
2009-01-21 02:49:42 +01:00
|
|
|
|
2009-04-05 02:13:43 +03:00
|
|
|
#define SAVE_INTERVAL (10 * PA_USEC_PER_SEC)
|
2009-01-21 02:49:42 +01:00
|
|
|
|
|
|
|
|
static const char* const valid_modargs[] = {
|
2019-12-07 19:06:28 -03:00
|
|
|
"restore_bluetooth_profile",
|
|
|
|
|
NULL
|
2009-01-21 02:49:42 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct userdata {
|
|
|
|
|
pa_core *core;
|
|
|
|
|
pa_module *module;
|
|
|
|
|
pa_time_event *save_time_event;
|
2009-05-14 01:24:26 +02:00
|
|
|
pa_database *database;
|
2018-07-20 12:39:22 -07:00
|
|
|
bool restore_bluetooth_profile;
|
2009-01-21 02:49:42 +01:00
|
|
|
};
|
|
|
|
|
|
2020-12-16 00:35:05 +03:00
|
|
|
#define ENTRY_VERSION 5
|
2012-06-27 22:55:35 +02:00
|
|
|
|
|
|
|
|
struct port_info {
|
|
|
|
|
char *name;
|
|
|
|
|
int64_t offset;
|
2015-11-17 15:10:33 +01:00
|
|
|
char *profile;
|
2012-06-27 22:55:35 +02:00
|
|
|
};
|
2009-02-04 18:31:24 +01:00
|
|
|
|
2009-02-13 18:02:47 +01:00
|
|
|
struct entry {
|
2011-06-07 23:21:04 +01:00
|
|
|
char *profile;
|
2012-06-27 22:55:35 +02:00
|
|
|
pa_hashmap *ports; /* Port name -> struct port_info */
|
2016-03-04 15:23:31 +02:00
|
|
|
char *preferred_input_port;
|
|
|
|
|
char *preferred_output_port;
|
2020-12-16 00:35:05 +03:00
|
|
|
bool profile_is_sticky; /* since version 5; must be restored together with profile name */
|
2011-06-07 23:21:04 +01:00
|
|
|
};
|
2009-01-21 02:49:42 +01:00
|
|
|
|
2009-04-05 02:13:43 +03:00
|
|
|
static void save_time_callback(pa_mainloop_api*a, pa_time_event* e, const struct timeval *t, void *userdata) {
|
2009-01-21 02:49:42 +01:00
|
|
|
struct userdata *u = userdata;
|
|
|
|
|
|
|
|
|
|
pa_assert(a);
|
|
|
|
|
pa_assert(e);
|
|
|
|
|
pa_assert(u);
|
|
|
|
|
|
|
|
|
|
pa_assert(e == u->save_time_event);
|
|
|
|
|
u->core->mainloop->time_free(u->save_time_event);
|
|
|
|
|
u->save_time_event = NULL;
|
|
|
|
|
|
2009-05-14 01:24:26 +02:00
|
|
|
pa_database_sync(u->database);
|
2009-01-21 02:49:42 +01:00
|
|
|
pa_log_info("Synced.");
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-08 00:47:19 +01:00
|
|
|
static void trigger_save(struct userdata *u) {
|
|
|
|
|
if (u->save_time_event)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
u->save_time_event = pa_core_rttime_new(u->core, pa_rtclock_now() + SAVE_INTERVAL, save_time_callback, u);
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-14 11:50:10 +05:30
|
|
|
static void port_info_free(struct port_info *p_info) {
|
|
|
|
|
pa_assert(p_info);
|
|
|
|
|
|
2015-11-17 15:10:33 +01:00
|
|
|
pa_xfree(p_info->profile);
|
2013-09-14 11:50:10 +05:30
|
|
|
pa_xfree(p_info->name);
|
|
|
|
|
pa_xfree(p_info);
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-07 23:21:04 +01:00
|
|
|
static struct entry* entry_new(void) {
|
|
|
|
|
struct entry *r = pa_xnew0(struct entry, 1);
|
2013-09-14 11:50:10 +05:30
|
|
|
r->ports = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func, NULL, (pa_free_cb_t) port_info_free);
|
2011-06-07 23:21:04 +01:00
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-15 23:51:30 +01:00
|
|
|
static struct port_info *port_info_new(pa_device_port *port) {
|
|
|
|
|
struct port_info *p_info;
|
|
|
|
|
|
|
|
|
|
if (port) {
|
2015-11-17 15:10:33 +01:00
|
|
|
p_info = pa_xnew0(struct port_info, 1);
|
2013-01-15 23:51:30 +01:00
|
|
|
p_info->name = pa_xstrdup(port->name);
|
|
|
|
|
p_info->offset = port->latency_offset;
|
2015-11-17 15:10:33 +01:00
|
|
|
if (port->preferred_profile)
|
|
|
|
|
p_info->profile = pa_xstrdup(port->preferred_profile);
|
2013-01-15 23:51:30 +01:00
|
|
|
} else
|
|
|
|
|
p_info = pa_xnew0(struct port_info, 1);
|
|
|
|
|
|
|
|
|
|
return p_info;
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-07 23:21:04 +01:00
|
|
|
static void entry_free(struct entry* e) {
|
|
|
|
|
pa_assert(e);
|
|
|
|
|
|
2016-03-04 15:23:31 +02:00
|
|
|
pa_xfree(e->preferred_output_port);
|
|
|
|
|
pa_xfree(e->preferred_input_port);
|
2011-06-07 23:21:04 +01:00
|
|
|
pa_xfree(e->profile);
|
2013-09-14 11:50:10 +05:30
|
|
|
pa_hashmap_free(e->ports);
|
2012-06-27 22:55:35 +02:00
|
|
|
|
2011-06-07 23:21:04 +01:00
|
|
|
pa_xfree(e);
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-15 23:51:30 +01:00
|
|
|
static struct entry *entry_from_card(pa_card *card) {
|
|
|
|
|
struct port_info *p_info;
|
|
|
|
|
struct entry *entry;
|
|
|
|
|
pa_device_port *port;
|
|
|
|
|
void *state;
|
|
|
|
|
|
|
|
|
|
pa_assert(card);
|
|
|
|
|
|
|
|
|
|
entry = entry_new();
|
2020-12-16 00:35:05 +03:00
|
|
|
entry->profile_is_sticky = card->profile_is_sticky;
|
|
|
|
|
if (card->save_profile || entry->profile_is_sticky)
|
2013-01-15 23:51:30 +01:00
|
|
|
entry->profile = pa_xstrdup(card->active_profile->name);
|
|
|
|
|
|
|
|
|
|
PA_HASHMAP_FOREACH(port, card->ports, state) {
|
|
|
|
|
p_info = port_info_new(port);
|
|
|
|
|
pa_assert_se(pa_hashmap_put(entry->ports, p_info->name, p_info) >= 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return entry;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool entrys_equal(struct entry *a, struct entry *b) {
|
|
|
|
|
struct port_info *Ap_info, *Bp_info;
|
|
|
|
|
void *state;
|
|
|
|
|
|
|
|
|
|
pa_assert(a);
|
|
|
|
|
pa_assert(b);
|
|
|
|
|
|
|
|
|
|
if (!pa_streq(a->profile, b->profile) ||
|
|
|
|
|
pa_hashmap_size(a->ports) != pa_hashmap_size(b->ports))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
PA_HASHMAP_FOREACH(Ap_info, a->ports, state) {
|
|
|
|
|
if ((Bp_info = pa_hashmap_get(b->ports, Ap_info->name))) {
|
|
|
|
|
if (Ap_info->offset != Bp_info->offset)
|
|
|
|
|
return false;
|
|
|
|
|
} else
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-04 15:23:31 +02:00
|
|
|
if (!pa_safe_streq(a->preferred_input_port, b->preferred_input_port))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (!pa_safe_streq(a->preferred_output_port, b->preferred_output_port))
|
|
|
|
|
return false;
|
|
|
|
|
|
2020-12-16 00:35:05 +03:00
|
|
|
if (a->profile_is_sticky != b->profile_is_sticky)
|
|
|
|
|
return false;
|
|
|
|
|
|
2013-01-15 23:51:30 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-27 19:28:09 +02:00
|
|
|
static bool entry_write(struct userdata *u, const char *name, const struct entry *e) {
|
2011-06-08 00:47:19 +01:00
|
|
|
pa_tagstruct *t;
|
|
|
|
|
pa_datum key, data;
|
2013-06-27 19:28:09 +02:00
|
|
|
bool r;
|
2012-06-27 22:55:35 +02:00
|
|
|
void *state;
|
|
|
|
|
struct port_info *p_info;
|
2011-06-08 00:47:19 +01:00
|
|
|
|
|
|
|
|
pa_assert(u);
|
|
|
|
|
pa_assert(name);
|
|
|
|
|
pa_assert(e);
|
|
|
|
|
|
2014-10-23 16:09:45 +02:00
|
|
|
t = pa_tagstruct_new();
|
2015-11-17 15:10:36 +01:00
|
|
|
pa_tagstruct_putu8(t, ENTRY_VERSION);
|
2011-06-08 00:47:19 +01:00
|
|
|
pa_tagstruct_puts(t, e->profile);
|
2012-06-27 22:55:35 +02:00
|
|
|
pa_tagstruct_putu32(t, pa_hashmap_size(e->ports));
|
|
|
|
|
|
|
|
|
|
PA_HASHMAP_FOREACH(p_info, e->ports, state) {
|
|
|
|
|
pa_tagstruct_puts(t, p_info->name);
|
|
|
|
|
pa_tagstruct_puts64(t, p_info->offset);
|
2015-11-17 15:10:36 +01:00
|
|
|
pa_tagstruct_puts(t, p_info->profile);
|
2012-06-27 22:55:35 +02:00
|
|
|
}
|
2011-06-08 00:47:19 +01:00
|
|
|
|
2016-03-04 15:23:31 +02:00
|
|
|
pa_tagstruct_puts(t, e->preferred_input_port);
|
|
|
|
|
pa_tagstruct_puts(t, e->preferred_output_port);
|
|
|
|
|
|
2020-12-16 00:35:05 +03:00
|
|
|
pa_tagstruct_put_boolean(t, e->profile_is_sticky);
|
|
|
|
|
|
2011-06-08 00:47:19 +01:00
|
|
|
key.data = (char *) name;
|
|
|
|
|
key.size = strlen(name);
|
|
|
|
|
|
|
|
|
|
data.data = (void*)pa_tagstruct_data(t, &data.size);
|
|
|
|
|
|
2013-06-27 19:28:09 +02:00
|
|
|
r = (pa_database_set(u->database, &key, &data, true) == 0);
|
2011-06-08 00:47:19 +01:00
|
|
|
|
|
|
|
|
pa_tagstruct_free(t);
|
|
|
|
|
|
|
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef ENABLE_LEGACY_DATABASE_ENTRY_FORMAT
|
|
|
|
|
|
|
|
|
|
#define LEGACY_ENTRY_VERSION 1
|
|
|
|
|
static struct entry* legacy_entry_read(struct userdata *u, pa_datum *data) {
|
|
|
|
|
struct legacy_entry {
|
|
|
|
|
uint8_t version;
|
|
|
|
|
char profile[PA_NAME_MAX];
|
|
|
|
|
} PA_GCC_PACKED ;
|
|
|
|
|
struct legacy_entry *le;
|
|
|
|
|
struct entry *e;
|
|
|
|
|
|
|
|
|
|
pa_assert(u);
|
|
|
|
|
pa_assert(data);
|
|
|
|
|
|
|
|
|
|
if (data->size != sizeof(struct legacy_entry)) {
|
|
|
|
|
pa_log_debug("Size does not match.");
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
le = (struct legacy_entry*)data->data;
|
|
|
|
|
|
|
|
|
|
if (le->version != LEGACY_ENTRY_VERSION) {
|
|
|
|
|
pa_log_debug("Version mismatch.");
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!memchr(le->profile, 0, sizeof(le->profile))) {
|
|
|
|
|
pa_log_warn("Profile has missing NUL byte.");
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
e = entry_new();
|
|
|
|
|
e->profile = pa_xstrdup(le->profile);
|
|
|
|
|
return e;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2011-06-07 23:21:04 +01:00
|
|
|
static struct entry* entry_read(struct userdata *u, const char *name) {
|
2009-05-14 01:24:26 +02:00
|
|
|
pa_datum key, data;
|
2011-06-07 23:21:04 +01:00
|
|
|
struct entry *e = NULL;
|
|
|
|
|
pa_tagstruct *t = NULL;
|
|
|
|
|
const char* profile;
|
2015-11-17 15:10:36 +01:00
|
|
|
uint8_t version;
|
2009-01-21 02:49:42 +01:00
|
|
|
|
|
|
|
|
pa_assert(u);
|
|
|
|
|
pa_assert(name);
|
|
|
|
|
|
2009-05-14 01:24:26 +02:00
|
|
|
key.data = (char*) name;
|
|
|
|
|
key.size = strlen(name);
|
2009-01-21 02:49:42 +01:00
|
|
|
|
2009-05-14 01:24:26 +02:00
|
|
|
pa_zero(data);
|
2009-01-21 02:49:42 +01:00
|
|
|
|
2014-10-20 16:19:36 +02:00
|
|
|
if (!pa_database_get(u->database, &key, &data)) {
|
|
|
|
|
pa_log_debug("Database contains no data for key: %s", name);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2009-01-21 02:49:42 +01:00
|
|
|
|
2014-10-23 16:09:45 +02:00
|
|
|
t = pa_tagstruct_new_fixed(data.data, data.size);
|
2011-06-07 23:21:04 +01:00
|
|
|
e = entry_new();
|
2009-01-21 02:49:42 +01:00
|
|
|
|
2015-11-17 15:10:36 +01:00
|
|
|
if (pa_tagstruct_getu8(t, &version) < 0 ||
|
|
|
|
|
version > ENTRY_VERSION ||
|
2011-06-07 23:21:04 +01:00
|
|
|
pa_tagstruct_gets(t, &profile) < 0) {
|
2009-01-21 02:49:42 +01:00
|
|
|
|
2009-02-04 18:31:24 +01:00
|
|
|
goto fail;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-30 13:00:25 +03:00
|
|
|
if (!profile)
|
|
|
|
|
profile = "";
|
|
|
|
|
|
2011-06-07 23:21:04 +01:00
|
|
|
e->profile = pa_xstrdup(profile);
|
|
|
|
|
|
2015-11-17 15:10:36 +01:00
|
|
|
if (version >= 2) {
|
2012-06-27 22:55:35 +02:00
|
|
|
uint32_t port_count = 0;
|
2015-11-17 15:10:33 +01:00
|
|
|
const char *port_name = NULL, *profile_name = NULL;
|
2012-06-27 22:55:35 +02:00
|
|
|
int64_t port_offset = 0;
|
|
|
|
|
struct port_info *p_info;
|
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
|
|
if (pa_tagstruct_getu32(t, &port_count) < 0)
|
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < port_count; i++) {
|
|
|
|
|
if (pa_tagstruct_gets(t, &port_name) < 0 ||
|
|
|
|
|
!port_name ||
|
|
|
|
|
pa_hashmap_get(e->ports, port_name) ||
|
|
|
|
|
pa_tagstruct_gets64(t, &port_offset) < 0)
|
|
|
|
|
goto fail;
|
2015-11-17 15:10:36 +01:00
|
|
|
if (version >= 3 && pa_tagstruct_gets(t, &profile_name) < 0)
|
2015-11-17 15:10:33 +01:00
|
|
|
goto fail;
|
2012-06-27 22:55:35 +02:00
|
|
|
|
2013-01-15 23:51:30 +01:00
|
|
|
p_info = port_info_new(NULL);
|
2012-06-27 22:55:35 +02:00
|
|
|
p_info->name = pa_xstrdup(port_name);
|
|
|
|
|
p_info->offset = port_offset;
|
2015-11-17 15:10:33 +01:00
|
|
|
if (profile_name)
|
|
|
|
|
p_info->profile = pa_xstrdup(profile_name);
|
2012-06-27 22:55:35 +02:00
|
|
|
|
|
|
|
|
pa_assert_se(pa_hashmap_put(e->ports, p_info->name, p_info) >= 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-04 15:23:31 +02:00
|
|
|
if (version >= 4) {
|
|
|
|
|
const char *preferred_input_port;
|
|
|
|
|
const char *preferred_output_port;
|
|
|
|
|
|
|
|
|
|
if (pa_tagstruct_gets(t, &preferred_input_port) < 0
|
|
|
|
|
|| pa_tagstruct_gets(t, &preferred_output_port) < 0)
|
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
|
|
e->preferred_input_port = pa_xstrdup(preferred_input_port);
|
|
|
|
|
e->preferred_output_port = pa_xstrdup(preferred_output_port);
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-16 00:35:05 +03:00
|
|
|
if (version >= 5) {
|
|
|
|
|
bool profile_is_sticky;
|
|
|
|
|
if (pa_tagstruct_get_boolean(t, &profile_is_sticky) < 0)
|
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
|
|
e->profile_is_sticky = profile_is_sticky;
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-07 23:21:04 +01:00
|
|
|
if (!pa_tagstruct_eof(t))
|
2009-01-21 02:49:42 +01:00
|
|
|
goto fail;
|
2011-06-07 23:21:04 +01:00
|
|
|
|
|
|
|
|
pa_tagstruct_free(t);
|
|
|
|
|
pa_datum_free(&data);
|
2009-01-21 02:49:42 +01:00
|
|
|
|
|
|
|
|
return e;
|
|
|
|
|
|
|
|
|
|
fail:
|
|
|
|
|
|
2011-06-07 23:21:04 +01:00
|
|
|
pa_log_debug("Database contains invalid data for key: %s (probably pre-v1.0 data)", name);
|
|
|
|
|
|
|
|
|
|
if (e)
|
|
|
|
|
entry_free(e);
|
|
|
|
|
if (t)
|
|
|
|
|
pa_tagstruct_free(t);
|
2009-01-21 02:49:42 +01:00
|
|
|
|
2011-06-08 00:47:19 +01:00
|
|
|
#ifdef ENABLE_LEGACY_DATABASE_ENTRY_FORMAT
|
|
|
|
|
pa_log_debug("Attempting to load legacy (pre-v1.0) data for key: %s", name);
|
|
|
|
|
if ((e = legacy_entry_read(u, &data))) {
|
|
|
|
|
pa_log_debug("Success. Saving new format for key: %s", name);
|
|
|
|
|
if (entry_write(u, name, e))
|
|
|
|
|
trigger_save(u);
|
|
|
|
|
pa_datum_free(&data);
|
|
|
|
|
return e;
|
|
|
|
|
} else
|
|
|
|
|
pa_log_debug("Unable to load legacy (pre-v1.0) data for key: %s. Ignoring.", name);
|
|
|
|
|
#endif
|
2009-01-21 02:49:42 +01:00
|
|
|
|
2011-06-08 00:47:19 +01:00
|
|
|
pa_datum_free(&data);
|
|
|
|
|
return NULL;
|
2009-01-21 02:49:42 +01:00
|
|
|
}
|
|
|
|
|
|
2013-01-15 23:51:30 +01:00
|
|
|
static void show_full_info(pa_card *card) {
|
|
|
|
|
pa_assert(card);
|
|
|
|
|
|
|
|
|
|
if (card->save_profile)
|
|
|
|
|
pa_log_info("Storing profile and port latency offsets for card %s.", card->name);
|
|
|
|
|
else
|
|
|
|
|
pa_log_info("Storing port latency offsets for card %s.", card->name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static pa_hook_result_t card_put_hook_callback(pa_core *c, pa_card *card, struct userdata *u) {
|
2011-06-07 23:21:04 +01:00
|
|
|
struct entry *entry, *old;
|
2009-01-21 02:49:42 +01:00
|
|
|
|
2013-01-15 23:51:30 +01:00
|
|
|
pa_assert(card);
|
2009-01-21 02:49:42 +01:00
|
|
|
|
2013-01-15 23:51:30 +01:00
|
|
|
entry = entry_from_card(card);
|
2009-01-21 02:49:42 +01:00
|
|
|
|
2013-01-15 23:51:30 +01:00
|
|
|
if ((old = entry_read(u, card->name))) {
|
|
|
|
|
if (!card->save_profile)
|
|
|
|
|
entry->profile = pa_xstrdup(old->profile);
|
|
|
|
|
if (entrys_equal(entry, old))
|
|
|
|
|
goto finish;
|
|
|
|
|
}
|
2009-01-21 02:49:42 +01:00
|
|
|
|
2013-01-15 23:51:30 +01:00
|
|
|
show_full_info(card);
|
2012-06-27 22:55:35 +02:00
|
|
|
|
2013-01-15 23:51:30 +01:00
|
|
|
if (entry_write(u, card->name, entry))
|
|
|
|
|
trigger_save(u);
|
2012-06-27 22:55:35 +02:00
|
|
|
|
2013-01-15 23:51:30 +01:00
|
|
|
finish:
|
|
|
|
|
entry_free(entry);
|
|
|
|
|
if (old)
|
|
|
|
|
entry_free(old);
|
2012-06-27 22:55:35 +02:00
|
|
|
|
2013-01-15 23:51:30 +01:00
|
|
|
return PA_HOOK_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-17 15:10:33 +01:00
|
|
|
static void update_profile_for_port(struct entry *entry, pa_card *card, pa_device_port *p) {
|
|
|
|
|
struct port_info *p_info;
|
|
|
|
|
|
|
|
|
|
if (p == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (!(p_info = pa_hashmap_get(entry->ports, p->name))) {
|
|
|
|
|
p_info = port_info_new(p);
|
|
|
|
|
pa_assert_se(pa_hashmap_put(entry->ports, p_info->name, p_info) >= 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!pa_safe_streq(p_info->profile, p->preferred_profile)) {
|
|
|
|
|
pa_xfree(p_info->profile);
|
|
|
|
|
p_info->profile = pa_xstrdup(p->preferred_profile);
|
|
|
|
|
pa_log_info("Storing profile %s for port %s on card %s.", p_info->profile, p->name, card->name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-25 16:39:01 +02:00
|
|
|
static pa_hook_result_t card_profile_changed_callback(pa_core *c, pa_card *card, struct userdata *u) {
|
2013-01-15 23:51:30 +01:00
|
|
|
struct entry *entry;
|
2015-11-17 15:10:33 +01:00
|
|
|
pa_sink *sink;
|
|
|
|
|
pa_source *source;
|
|
|
|
|
uint32_t state;
|
2013-01-15 23:51:30 +01:00
|
|
|
|
|
|
|
|
pa_assert(card);
|
|
|
|
|
|
2020-12-16 00:35:05 +03:00
|
|
|
if (!card->save_profile && !card->profile_is_sticky)
|
2013-01-15 23:51:30 +01:00
|
|
|
return PA_HOOK_OK;
|
|
|
|
|
|
|
|
|
|
if ((entry = entry_read(u, card->name))) {
|
2014-01-29 20:54:39 +02:00
|
|
|
pa_xfree(entry->profile);
|
2020-12-16 00:35:05 +03:00
|
|
|
entry->profile_is_sticky = card->profile_is_sticky;
|
2013-01-15 23:51:30 +01:00
|
|
|
entry->profile = pa_xstrdup(card->active_profile->name);
|
|
|
|
|
pa_log_info("Storing card profile for card %s.", card->name);
|
|
|
|
|
} else {
|
|
|
|
|
entry = entry_from_card(card);
|
|
|
|
|
show_full_info(card);
|
2012-06-27 22:55:35 +02:00
|
|
|
}
|
2009-01-21 02:49:42 +01:00
|
|
|
|
2015-11-17 15:10:33 +01:00
|
|
|
PA_IDXSET_FOREACH(sink, card->sinks, state)
|
|
|
|
|
update_profile_for_port(entry, card, sink->active_port);
|
|
|
|
|
PA_IDXSET_FOREACH(source, card->sources, state)
|
|
|
|
|
update_profile_for_port(entry, card, source->active_port);
|
|
|
|
|
|
2013-01-15 23:51:30 +01:00
|
|
|
if (entry_write(u, card->name, entry))
|
|
|
|
|
trigger_save(u);
|
2012-06-27 22:55:35 +02:00
|
|
|
|
2013-01-15 23:51:30 +01:00
|
|
|
entry_free(entry);
|
|
|
|
|
return PA_HOOK_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-25 16:39:01 +02:00
|
|
|
static pa_hook_result_t card_profile_added_callback(pa_core *c, pa_card_profile *profile, struct userdata *u) {
|
|
|
|
|
struct entry *entry;
|
|
|
|
|
|
|
|
|
|
pa_assert(profile);
|
|
|
|
|
|
card-restore: Fix profile restoring with bluetooth
The bluetooth card is created when the first profile becomes
available, which means that the card may have profiles that are not
available when the card is initialized. If module-card-restore tries
to restore such profile, that will fail, and the card will be
initialized with the "off" profile active.
This patch modifies module-card-restore so that if follows the profile
availability status, and when the saved profile becomes available, it
is activated. Additionally, module-card-restore is modified so that it
doesn't even try to restore unavailable profiles, when the necessary
information is available. In practice there are two existing places
where the profile is restored, and only one of those contexts has the
necessary information available. Unfortunately, it's the more
important context (card creation) where the information is not
available. This means that module-card-restore will set the initial
profile of a new card even if the profile is unavailable, and this
will cause an ugly warning in the log, even though there's nothing
abnormal happening.
BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=87081
2014-12-16 13:14:41 +02:00
|
|
|
if (profile->available == PA_AVAILABLE_NO)
|
|
|
|
|
return PA_HOOK_OK;
|
|
|
|
|
|
2013-07-25 16:39:01 +02:00
|
|
|
if (!(entry = entry_read(u, profile->card->name)))
|
|
|
|
|
return PA_HOOK_OK;
|
|
|
|
|
|
|
|
|
|
if (pa_safe_streq(entry->profile, profile->name)) {
|
2013-11-20 15:42:26 +02:00
|
|
|
if (pa_card_set_profile(profile->card, profile, true) >= 0)
|
2013-07-25 16:39:01 +02:00
|
|
|
pa_log_info("Restored profile '%s' for card %s.", profile->name, profile->card->name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
entry_free(entry);
|
|
|
|
|
|
|
|
|
|
return PA_HOOK_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-15 23:51:30 +01:00
|
|
|
static pa_hook_result_t port_offset_change_callback(pa_core *c, pa_device_port *port, struct userdata *u) {
|
|
|
|
|
struct entry *entry;
|
|
|
|
|
pa_card *card;
|
|
|
|
|
|
|
|
|
|
pa_assert(port);
|
|
|
|
|
card = port->card;
|
|
|
|
|
|
|
|
|
|
if ((entry = entry_read(u, card->name))) {
|
|
|
|
|
struct port_info *p_info;
|
|
|
|
|
|
|
|
|
|
if ((p_info = pa_hashmap_get(entry->ports, port->name)))
|
|
|
|
|
p_info->offset = port->latency_offset;
|
|
|
|
|
else {
|
|
|
|
|
p_info = port_info_new(port);
|
|
|
|
|
pa_assert_se(pa_hashmap_put(entry->ports, p_info->name, p_info) >= 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pa_log_info("Storing latency offset for port %s on card %s.", port->name, card->name);
|
|
|
|
|
|
|
|
|
|
} else {
|
2013-12-16 17:00:24 +01:00
|
|
|
entry = entry_from_card(card);
|
2013-01-15 23:51:30 +01:00
|
|
|
show_full_info(card);
|
|
|
|
|
}
|
2009-01-21 02:49:42 +01:00
|
|
|
|
2011-06-07 23:21:04 +01:00
|
|
|
if (entry_write(u, card->name, entry))
|
|
|
|
|
trigger_save(u);
|
2009-01-21 02:49:42 +01:00
|
|
|
|
2011-06-07 23:21:04 +01:00
|
|
|
entry_free(entry);
|
2013-01-15 23:51:30 +01:00
|
|
|
return PA_HOOK_OK;
|
2009-01-21 02:49:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static pa_hook_result_t card_new_hook_callback(pa_core *c, pa_card_new_data *new_data, struct userdata *u) {
|
|
|
|
|
struct entry *e;
|
2012-06-27 22:55:35 +02:00
|
|
|
void *state;
|
|
|
|
|
pa_device_port *p;
|
|
|
|
|
struct port_info *p_info;
|
2009-01-21 02:49:42 +01:00
|
|
|
|
|
|
|
|
pa_assert(new_data);
|
|
|
|
|
|
2012-06-27 22:55:35 +02:00
|
|
|
if (!(e = entry_read(u, new_data->name)))
|
|
|
|
|
return PA_HOOK_OK;
|
2009-01-21 02:49:42 +01:00
|
|
|
|
2012-06-27 22:55:35 +02:00
|
|
|
/* Always restore the latency offsets because their
|
|
|
|
|
* initial value is always 0 */
|
|
|
|
|
|
|
|
|
|
pa_log_info("Restoring port latency offsets for card %s.", new_data->name);
|
|
|
|
|
|
|
|
|
|
PA_HASHMAP_FOREACH(p_info, e->ports, state)
|
2015-11-17 15:10:33 +01:00
|
|
|
if ((p = pa_hashmap_get(new_data->ports, p_info->name))) {
|
2012-06-27 22:55:35 +02:00
|
|
|
p->latency_offset = p_info->offset;
|
2015-11-17 15:10:33 +01:00
|
|
|
if (!p->preferred_profile && p_info->profile)
|
|
|
|
|
pa_device_port_set_preferred_profile(p, p_info->profile);
|
|
|
|
|
}
|
2016-03-04 15:23:31 +02:00
|
|
|
|
|
|
|
|
if (e->preferred_input_port) {
|
|
|
|
|
p = pa_hashmap_get(new_data->ports, e->preferred_input_port);
|
|
|
|
|
if (p)
|
|
|
|
|
pa_card_new_data_set_preferred_port(new_data, PA_DIRECTION_INPUT, p);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (e->preferred_output_port) {
|
|
|
|
|
p = pa_hashmap_get(new_data->ports, e->preferred_output_port);
|
|
|
|
|
if (p)
|
|
|
|
|
pa_card_new_data_set_preferred_port(new_data, PA_DIRECTION_OUTPUT, p);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
entry_free(e);
|
|
|
|
|
|
|
|
|
|
return PA_HOOK_OK;
|
|
|
|
|
}
|
|
|
|
|
|
card: move profile selection after pa_card_new()
I want module-alsa-card to set the availability of unavailable
profiles before the initial card profile gets selected, so that the
selection logic can use correct availability information.
module-alsa-card initializes the jack state after calling
pa_card_new(), however, and the profile selection happens in
pa_card_new(). This patch solves that by moving parts of pa_card_new()
to pa_card_choose_initial_profile() and pa_card_put().
pa_card_choose_initial_profile() applies the profile selection policy,
so module-alsa-card can first call pa_card_new(), then initialize the
jack state, and then call pa_card_choose_initial_profile(). After that
module-alsa-card can still override the profile selection policy, in
case module-alsa-card was loaded with the "profile" argument. Finally,
pa_card_put() finalizes the card creation.
An alternative solution would have been to move the jack
initialization to happen before pa_card_new() and use pa_card_new_data
instead of pa_card in the jack initialization code, but I disliked
that idea (I want to get rid of the "new data" pattern eventually).
The order in which the initial profile policy is applied is reversed
in this patch. Previously the first one to set it won, now the last
one to set it wins. I think this is better, because if you have N
parties that want to set the profile, we avoid checking N times
whether someone else has already set the profile.
2015-10-23 12:59:53 +03:00
|
|
|
static pa_hook_result_t card_choose_initial_profile_callback(pa_core *core, pa_card *card, struct userdata *u) {
|
|
|
|
|
struct entry *e;
|
|
|
|
|
|
|
|
|
|
if (!(e = entry_read(u, card->name)))
|
|
|
|
|
return PA_HOOK_OK;
|
|
|
|
|
|
2018-07-20 12:39:22 -07:00
|
|
|
if (!u->restore_bluetooth_profile) {
|
|
|
|
|
const char *s = pa_proplist_gets(card->proplist, PA_PROP_DEVICE_BUS);
|
|
|
|
|
if (pa_safe_streq(s, "bluetooth"))
|
2020-06-16 12:40:39 +02:00
|
|
|
goto finish;
|
2018-07-20 12:39:22 -07:00
|
|
|
}
|
|
|
|
|
|
2020-12-16 00:35:05 +03:00
|
|
|
card->profile_is_sticky = e->profile_is_sticky;
|
|
|
|
|
pa_log_info("Profile '%s' was previously %s for card %s.",
|
|
|
|
|
e->profile,
|
|
|
|
|
card->profile_is_sticky ? "sticky" : "automatically selected",
|
|
|
|
|
card->name);
|
|
|
|
|
|
card: move profile selection after pa_card_new()
I want module-alsa-card to set the availability of unavailable
profiles before the initial card profile gets selected, so that the
selection logic can use correct availability information.
module-alsa-card initializes the jack state after calling
pa_card_new(), however, and the profile selection happens in
pa_card_new(). This patch solves that by moving parts of pa_card_new()
to pa_card_choose_initial_profile() and pa_card_put().
pa_card_choose_initial_profile() applies the profile selection policy,
so module-alsa-card can first call pa_card_new(), then initialize the
jack state, and then call pa_card_choose_initial_profile(). After that
module-alsa-card can still override the profile selection policy, in
case module-alsa-card was loaded with the "profile" argument. Finally,
pa_card_put() finalizes the card creation.
An alternative solution would have been to move the jack
initialization to happen before pa_card_new() and use pa_card_new_data
instead of pa_card in the jack initialization code, but I disliked
that idea (I want to get rid of the "new data" pattern eventually).
The order in which the initial profile policy is applied is reversed
in this patch. Previously the first one to set it won, now the last
one to set it wins. I think this is better, because if you have N
parties that want to set the profile, we avoid checking N times
whether someone else has already set the profile.
2015-10-23 12:59:53 +03:00
|
|
|
if (e->profile[0]) {
|
|
|
|
|
pa_card_profile *profile;
|
|
|
|
|
|
|
|
|
|
profile = pa_hashmap_get(card->profiles, e->profile);
|
|
|
|
|
if (profile) {
|
2020-12-16 00:35:05 +03:00
|
|
|
if (profile->available != PA_AVAILABLE_NO || card->profile_is_sticky) {
|
2017-11-08 14:20:23 +02:00
|
|
|
pa_log_info("Restoring profile '%s' for card %s.", profile->name, card->name);
|
|
|
|
|
pa_card_set_profile(card, profile, true);
|
|
|
|
|
} else
|
|
|
|
|
pa_log_debug("Not restoring profile %s for card %s, because the profile is currently unavailable.",
|
|
|
|
|
profile->name, card->name);
|
card: move profile selection after pa_card_new()
I want module-alsa-card to set the availability of unavailable
profiles before the initial card profile gets selected, so that the
selection logic can use correct availability information.
module-alsa-card initializes the jack state after calling
pa_card_new(), however, and the profile selection happens in
pa_card_new(). This patch solves that by moving parts of pa_card_new()
to pa_card_choose_initial_profile() and pa_card_put().
pa_card_choose_initial_profile() applies the profile selection policy,
so module-alsa-card can first call pa_card_new(), then initialize the
jack state, and then call pa_card_choose_initial_profile(). After that
module-alsa-card can still override the profile selection policy, in
case module-alsa-card was loaded with the "profile" argument. Finally,
pa_card_put() finalizes the card creation.
An alternative solution would have been to move the jack
initialization to happen before pa_card_new() and use pa_card_new_data
instead of pa_card in the jack initialization code, but I disliked
that idea (I want to get rid of the "new data" pattern eventually).
The order in which the initial profile policy is applied is reversed
in this patch. Previously the first one to set it won, now the last
one to set it wins. I think this is better, because if you have N
parties that want to set the profile, we avoid checking N times
whether someone else has already set the profile.
2015-10-23 12:59:53 +03:00
|
|
|
} else {
|
|
|
|
|
pa_log_debug("Tried to restore profile %s for card %s, but the card doesn't have such profile.",
|
|
|
|
|
e->profile, card->name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-16 12:40:39 +02:00
|
|
|
finish:
|
card: move profile selection after pa_card_new()
I want module-alsa-card to set the availability of unavailable
profiles before the initial card profile gets selected, so that the
selection logic can use correct availability information.
module-alsa-card initializes the jack state after calling
pa_card_new(), however, and the profile selection happens in
pa_card_new(). This patch solves that by moving parts of pa_card_new()
to pa_card_choose_initial_profile() and pa_card_put().
pa_card_choose_initial_profile() applies the profile selection policy,
so module-alsa-card can first call pa_card_new(), then initialize the
jack state, and then call pa_card_choose_initial_profile(). After that
module-alsa-card can still override the profile selection policy, in
case module-alsa-card was loaded with the "profile" argument. Finally,
pa_card_put() finalizes the card creation.
An alternative solution would have been to move the jack
initialization to happen before pa_card_new() and use pa_card_new_data
instead of pa_card in the jack initialization code, but I disliked
that idea (I want to get rid of the "new data" pattern eventually).
The order in which the initial profile policy is applied is reversed
in this patch. Previously the first one to set it won, now the last
one to set it wins. I think this is better, because if you have N
parties that want to set the profile, we avoid checking N times
whether someone else has already set the profile.
2015-10-23 12:59:53 +03:00
|
|
|
entry_free(e);
|
|
|
|
|
|
|
|
|
|
return PA_HOOK_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-04 15:23:31 +02:00
|
|
|
static pa_hook_result_t card_preferred_port_changed_callback(pa_core *core, pa_card_preferred_port_changed_hook_data *data,
|
|
|
|
|
struct userdata *u) {
|
|
|
|
|
struct entry *e;
|
|
|
|
|
pa_card *card;
|
|
|
|
|
|
|
|
|
|
card = data->card;
|
|
|
|
|
|
|
|
|
|
e = entry_read(u, card->name);
|
|
|
|
|
if (!e)
|
|
|
|
|
e = entry_from_card(card);
|
|
|
|
|
|
|
|
|
|
if (data->direction == PA_DIRECTION_INPUT) {
|
|
|
|
|
pa_xfree(e->preferred_input_port);
|
|
|
|
|
e->preferred_input_port = pa_xstrdup(card->preferred_input_port ? card->preferred_input_port->name : NULL);
|
|
|
|
|
} else {
|
|
|
|
|
pa_xfree(e->preferred_output_port);
|
|
|
|
|
e->preferred_output_port = pa_xstrdup(card->preferred_output_port ? card->preferred_output_port->name : NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (entry_write(u, card->name, e))
|
|
|
|
|
trigger_save(u);
|
|
|
|
|
|
2012-06-27 22:55:35 +02:00
|
|
|
entry_free(e);
|
|
|
|
|
|
2009-01-21 02:49:42 +01:00
|
|
|
return PA_HOOK_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int pa__init(pa_module*m) {
|
|
|
|
|
pa_modargs *ma = NULL;
|
|
|
|
|
struct userdata *u;
|
2020-11-29 11:21:29 +03:00
|
|
|
char *state_path;
|
2018-07-20 12:39:22 -07:00
|
|
|
bool restore_bluetooth_profile;
|
2009-01-21 02:49:42 +01:00
|
|
|
|
|
|
|
|
pa_assert(m);
|
|
|
|
|
|
|
|
|
|
if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
|
|
|
|
|
pa_log("Failed to parse module arguments");
|
|
|
|
|
goto fail;
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-20 12:39:22 -07:00
|
|
|
restore_bluetooth_profile = false;
|
|
|
|
|
if (pa_modargs_get_value_boolean(ma, "restore_bluetooth_profile", &restore_bluetooth_profile) < 0) {
|
|
|
|
|
pa_log("Invalid boolean value for restore_bluetooth_profile parameter");
|
|
|
|
|
goto fail;
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-18 00:59:33 +02:00
|
|
|
m->userdata = u = pa_xnew0(struct userdata, 1);
|
2009-01-21 02:49:42 +01:00
|
|
|
u->core = m->core;
|
|
|
|
|
u->module = m;
|
2018-07-20 12:39:22 -07:00
|
|
|
u->restore_bluetooth_profile = restore_bluetooth_profile;
|
2009-01-21 02:49:42 +01:00
|
|
|
|
2015-03-27 11:20:12 +01:00
|
|
|
pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_CARD_NEW], PA_HOOK_EARLY, (pa_hook_cb_t) card_new_hook_callback, u);
|
card: move profile selection after pa_card_new()
I want module-alsa-card to set the availability of unavailable
profiles before the initial card profile gets selected, so that the
selection logic can use correct availability information.
module-alsa-card initializes the jack state after calling
pa_card_new(), however, and the profile selection happens in
pa_card_new(). This patch solves that by moving parts of pa_card_new()
to pa_card_choose_initial_profile() and pa_card_put().
pa_card_choose_initial_profile() applies the profile selection policy,
so module-alsa-card can first call pa_card_new(), then initialize the
jack state, and then call pa_card_choose_initial_profile(). After that
module-alsa-card can still override the profile selection policy, in
case module-alsa-card was loaded with the "profile" argument. Finally,
pa_card_put() finalizes the card creation.
An alternative solution would have been to move the jack
initialization to happen before pa_card_new() and use pa_card_new_data
instead of pa_card in the jack initialization code, but I disliked
that idea (I want to get rid of the "new data" pattern eventually).
The order in which the initial profile policy is applied is reversed
in this patch. Previously the first one to set it won, now the last
one to set it wins. I think this is better, because if you have N
parties that want to set the profile, we avoid checking N times
whether someone else has already set the profile.
2015-10-23 12:59:53 +03:00
|
|
|
pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_CARD_CHOOSE_INITIAL_PROFILE], PA_HOOK_NORMAL,
|
|
|
|
|
(pa_hook_cb_t) card_choose_initial_profile_callback, u);
|
2015-03-27 11:20:12 +01:00
|
|
|
pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_CARD_PUT], PA_HOOK_NORMAL, (pa_hook_cb_t) card_put_hook_callback, u);
|
2016-03-04 15:23:31 +02:00
|
|
|
pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_CARD_PREFERRED_PORT_CHANGED], PA_HOOK_NORMAL, (pa_hook_cb_t) card_preferred_port_changed_callback, u);
|
2015-03-27 11:20:12 +01:00
|
|
|
pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_CARD_PROFILE_CHANGED], PA_HOOK_NORMAL, (pa_hook_cb_t) card_profile_changed_callback, u);
|
|
|
|
|
pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_CARD_PROFILE_ADDED], PA_HOOK_NORMAL, (pa_hook_cb_t) card_profile_added_callback, u);
|
|
|
|
|
pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_PORT_LATENCY_OFFSET_CHANGED], PA_HOOK_NORMAL, (pa_hook_cb_t) port_offset_change_callback, u);
|
2009-01-21 02:49:42 +01:00
|
|
|
|
2020-11-29 11:21:29 +03:00
|
|
|
if (!(state_path = pa_state_path(NULL, true)))
|
2009-01-21 02:49:42 +01:00
|
|
|
goto fail;
|
|
|
|
|
|
2020-11-29 11:21:29 +03:00
|
|
|
if (!(u->database = pa_database_open(state_path, "card-database", true, true))) {
|
|
|
|
|
pa_xfree(state_path);
|
2009-01-21 02:49:42 +01:00
|
|
|
goto fail;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-29 11:21:29 +03:00
|
|
|
pa_xfree(state_path);
|
2009-01-21 02:49:42 +01:00
|
|
|
|
|
|
|
|
pa_modargs_free(ma);
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
fail:
|
|
|
|
|
pa__done(m);
|
|
|
|
|
|
|
|
|
|
if (ma)
|
|
|
|
|
pa_modargs_free(ma);
|
|
|
|
|
|
2011-03-12 19:45:02 +01:00
|
|
|
return -1;
|
2009-01-21 02:49:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void pa__done(pa_module*m) {
|
|
|
|
|
struct userdata* u;
|
|
|
|
|
|
|
|
|
|
pa_assert(m);
|
|
|
|
|
|
|
|
|
|
if (!(u = m->userdata))
|
|
|
|
|
return;
|
|
|
|
|
|
2016-03-04 15:16:54 +02:00
|
|
|
if (u->save_time_event) {
|
2009-01-21 02:49:42 +01:00
|
|
|
u->core->mainloop->time_free(u->save_time_event);
|
2016-03-04 15:16:54 +02:00
|
|
|
pa_database_sync(u->database);
|
|
|
|
|
}
|
2009-01-21 02:49:42 +01:00
|
|
|
|
2009-05-14 01:24:26 +02:00
|
|
|
if (u->database)
|
|
|
|
|
pa_database_close(u->database);
|
2009-01-21 02:49:42 +01:00
|
|
|
|
|
|
|
|
pa_xfree(u);
|
|
|
|
|
}
|