mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-10-29 05:40:23 -04:00
database: Support legacy format database entries.
This adds code to specifically support legacy entries. I kept this code in a separate commit so that it can be (relatively) easily removed at some point in the future.
This commit is contained in:
parent
35f99c6e31
commit
9ffa9382dd
5 changed files with 453 additions and 181 deletions
12
configure.ac
12
configure.ac
|
|
@ -1138,6 +1138,13 @@ if test "x$enable_legacy_runtime_dir" != "xno" ; then
|
|||
AC_DEFINE(ENABLE_LEGACY_RUNTIME_DIR, [1], [Legacy runtime dir])
|
||||
fi
|
||||
|
||||
AC_ARG_ENABLE([legacy-database-entry-format],
|
||||
AS_HELP_STRING([--disable-legacy-database-entry-format], [Try to load legacy (< 1.0) database files (card, device and volume restore).]))
|
||||
if test "x$enable_legacy_database_entry_format" != "xno" ; then
|
||||
AC_DEFINE(ENABLE_LEGACY_DATABASE_ENTRY_FORMAT, [1], [Legacy database entry format])
|
||||
fi
|
||||
AC_DEFINE([WIBBLE], 1, [Just a test.])
|
||||
|
||||
AC_ARG_ENABLE([static-bins],
|
||||
AS_HELP_STRING([--enable-static-bins],[Statically link executables.]))
|
||||
|
||||
|
|
@ -1229,6 +1236,8 @@ AS_IF([test "x$HAVE_TDB" = "x1"], ENABLE_TDB=yes, ENABLE_TDB=no)
|
|||
AS_IF([test "x$HAVE_GDBM" = "x1"], ENABLE_GDBM=yes, ENABLE_GDBM=no)
|
||||
AS_IF([test "x$HAVE_SIMPLEDB" = "x1"], ENABLE_SIMPLEDB=yes, ENABLE_SIMPLEDB=no)
|
||||
AS_IF([test "x$USE_PER_USER_ESOUND_SOCKET" = "x1"], ENABLE_PER_USER_ESOUND_SOCKET=yes, ENABLE_PER_USER_ESOUND_SOCKET=no)
|
||||
AS_IF([test "x$enable_legacy_runtime_dir" != "xno"], ENABLE_LEGACY_RUNTIME_DIR=yes, ENABLE_LEGACY_RUNTIME_DIR=no)
|
||||
AS_IF([test "x$enable_legacy_database_entry_format" != "xno"], ENABLE_LEGACY_DATABASE_ENTRY_FORMAT=yes, ENABLE_LEGACY_DATABASE_ENTRY_FORMAT=no)
|
||||
|
||||
echo "
|
||||
---{ $PACKAGE_NAME $VERSION }---
|
||||
|
|
@ -1279,6 +1288,9 @@ echo "
|
|||
Enable per-user EsounD socket: ${ENABLE_PER_USER_ESOUND_SOCKET}
|
||||
Force preopen: ${FORCE_PREOPEN}
|
||||
Preopened modules: ${PREOPEN_MODS}
|
||||
|
||||
Legacy Runtime Dir Support: ${ENABLE_LEGACY_RUNTIME_DIR}
|
||||
Legacy Database Entry Support: ${ENABLE_LEGACY_DATABASE_ENTRY_FORMAT}
|
||||
"
|
||||
|
||||
if test "${ENABLE_DBUS}" = "no" && test "x$os_is_win32" != "x1" ; then
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ struct userdata {
|
|||
pa_database *database;
|
||||
};
|
||||
|
||||
#define ENTRY_VERSION 2
|
||||
#define ENTRY_VERSION 1
|
||||
|
||||
struct entry {
|
||||
uint8_t version;
|
||||
|
|
@ -92,6 +92,13 @@ static void save_time_callback(pa_mainloop_api*a, pa_time_event* e, const struct
|
|||
pa_log_info("Synced.");
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
static struct entry* entry_new(void) {
|
||||
struct entry *r = pa_xnew0(struct entry, 1);
|
||||
r->version = ENTRY_VERSION;
|
||||
|
|
@ -105,6 +112,68 @@ static void entry_free(struct entry* e) {
|
|||
pa_xfree(e);
|
||||
}
|
||||
|
||||
static pa_bool_t entry_write(struct userdata *u, const char *name, const struct entry *e) {
|
||||
pa_tagstruct *t;
|
||||
pa_datum key, data;
|
||||
pa_bool_t r;
|
||||
|
||||
pa_assert(u);
|
||||
pa_assert(name);
|
||||
pa_assert(e);
|
||||
|
||||
t = pa_tagstruct_new(NULL, 0);
|
||||
pa_tagstruct_putu8(t, e->version);
|
||||
pa_tagstruct_puts(t, e->profile);
|
||||
|
||||
key.data = (char *) name;
|
||||
key.size = strlen(name);
|
||||
|
||||
data.data = (void*)pa_tagstruct_data(t, &data.size);
|
||||
|
||||
r = (pa_database_set(u->database, &key, &data, TRUE) == 0);
|
||||
|
||||
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
|
||||
|
||||
static struct entry* entry_read(struct userdata *u, const char *name) {
|
||||
pa_datum key, data;
|
||||
struct entry *e = NULL;
|
||||
|
|
@ -150,42 +219,23 @@ fail:
|
|||
entry_free(e);
|
||||
if (t)
|
||||
pa_tagstruct_free(t);
|
||||
|
||||
#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
|
||||
|
||||
pa_datum_free(&data);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static pa_bool_t entry_write(struct userdata *u, const char *name, const struct entry *e) {
|
||||
pa_tagstruct *t;
|
||||
pa_datum key, data;
|
||||
pa_bool_t r;
|
||||
|
||||
pa_assert(u);
|
||||
pa_assert(name);
|
||||
pa_assert(e);
|
||||
|
||||
t = pa_tagstruct_new(NULL, 0);
|
||||
pa_tagstruct_putu8(t, e->version);
|
||||
pa_tagstruct_puts(t, e->profile);
|
||||
|
||||
key.data = (char *) name;
|
||||
key.size = strlen(name);
|
||||
|
||||
data.data = (void*)pa_tagstruct_data(t, &data.size);
|
||||
|
||||
r = (pa_database_set(u->database, &key, &data, TRUE) == 0);
|
||||
|
||||
pa_tagstruct_free(t);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
static void subscribe_callback(pa_core *c, pa_subscription_event_type_t t, uint32_t idx, void *userdata) {
|
||||
struct userdata *u = userdata;
|
||||
struct entry *entry, *old;
|
||||
|
|
|
|||
|
|
@ -130,7 +130,7 @@ struct userdata {
|
|||
role_indexes_t preferred_sources;
|
||||
};
|
||||
|
||||
#define ENTRY_VERSION 2
|
||||
#define ENTRY_VERSION 1
|
||||
|
||||
struct entry {
|
||||
uint8_t version;
|
||||
|
|
@ -152,6 +152,44 @@ enum {
|
|||
};
|
||||
|
||||
|
||||
/* Forward declarations */
|
||||
#ifdef DUMP_DATABASE
|
||||
static void dump_database(struct userdata *);
|
||||
#endif
|
||||
static void notify_subscribers(struct userdata *);
|
||||
|
||||
|
||||
static void save_time_callback(pa_mainloop_api*a, pa_time_event* e, const struct timeval *t, void *userdata) {
|
||||
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;
|
||||
|
||||
pa_database_sync(u->database);
|
||||
pa_log_info("Synced.");
|
||||
|
||||
#ifdef DUMP_DATABASE
|
||||
dump_database(u);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void trigger_save(struct userdata *u) {
|
||||
|
||||
pa_assert(u);
|
||||
|
||||
notify_subscribers(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);
|
||||
}
|
||||
|
||||
static struct entry* entry_new(void) {
|
||||
struct entry *r = pa_xnew0(struct entry, 1);
|
||||
r->version = ENTRY_VERSION;
|
||||
|
|
@ -165,6 +203,81 @@ static void entry_free(struct entry* e) {
|
|||
pa_xfree(e->icon);
|
||||
}
|
||||
|
||||
static pa_bool_t entry_write(struct userdata *u, const char *name, const struct entry *e) {
|
||||
pa_tagstruct *t;
|
||||
pa_datum key, data;
|
||||
pa_bool_t r;
|
||||
|
||||
pa_assert(u);
|
||||
pa_assert(name);
|
||||
pa_assert(e);
|
||||
|
||||
t = pa_tagstruct_new(NULL, 0);
|
||||
pa_tagstruct_putu8(t, e->version);
|
||||
pa_tagstruct_puts(t, e->description);
|
||||
pa_tagstruct_put_boolean(t, e->user_set_description);
|
||||
pa_tagstruct_puts(t, e->icon);
|
||||
for (uint8_t i=0; i<ROLE_MAX; ++i)
|
||||
pa_tagstruct_putu32(t, e->priority[i]);
|
||||
|
||||
key.data = (char *) name;
|
||||
key.size = strlen(name);
|
||||
|
||||
data.data = (void*)pa_tagstruct_data(t, &data.size);
|
||||
|
||||
r = (pa_database_set(u->database, &key, &data, TRUE) == 0);
|
||||
|
||||
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 description[PA_NAME_MAX];
|
||||
pa_bool_t user_set_description;
|
||||
char icon[PA_NAME_MAX];
|
||||
role_indexes_t priority;
|
||||
} 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->description, 0, sizeof(le->description))) {
|
||||
pa_log_warn("Description has missing NUL byte.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!memchr(le->icon, 0, sizeof(le->icon))) {
|
||||
pa_log_warn("Icon has missing NUL byte.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
e = entry_new();
|
||||
e->description = pa_xstrdup(le->description);
|
||||
e->icon = pa_xstrdup(le->icon);
|
||||
return e;
|
||||
}
|
||||
#endif
|
||||
|
||||
static struct entry* entry_read(struct userdata *u, const char *name) {
|
||||
pa_datum key, data;
|
||||
struct entry *e = NULL;
|
||||
|
|
@ -217,39 +330,23 @@ fail:
|
|||
entry_free(e);
|
||||
if (t)
|
||||
pa_tagstruct_free(t);
|
||||
|
||||
#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
|
||||
|
||||
pa_datum_free(&data);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static pa_bool_t entry_write(struct userdata *u, const char *name, const struct entry *e) {
|
||||
pa_tagstruct *t;
|
||||
pa_datum key, data;
|
||||
pa_bool_t r;
|
||||
|
||||
pa_assert(u);
|
||||
pa_assert(name);
|
||||
pa_assert(e);
|
||||
|
||||
t = pa_tagstruct_new(NULL, 0);
|
||||
pa_tagstruct_putu8(t, e->version);
|
||||
pa_tagstruct_puts(t, e->description);
|
||||
pa_tagstruct_put_boolean(t, e->user_set_description);
|
||||
pa_tagstruct_puts(t, e->icon);
|
||||
for (uint8_t i=0; i<ROLE_MAX; ++i)
|
||||
pa_tagstruct_putu32(t, e->priority[i]);
|
||||
|
||||
key.data = (char *) name;
|
||||
key.size = strlen(name);
|
||||
|
||||
data.data = (void*)pa_tagstruct_data(t, &data.size);
|
||||
|
||||
r = (pa_database_set(u->database, &key, &data, TRUE) == 0);
|
||||
|
||||
pa_tagstruct_free(t);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
#ifdef DUMP_DATABASE
|
||||
static void dump_database_helper(struct userdata *u, uint32_t role_index, const char* human, pa_bool_t sink_mode) {
|
||||
pa_assert(u);
|
||||
|
|
@ -332,25 +429,6 @@ static void dump_database(struct userdata *u) {
|
|||
}
|
||||
#endif
|
||||
|
||||
static void save_time_callback(pa_mainloop_api*a, pa_time_event* e, const struct timeval *t, void *userdata) {
|
||||
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;
|
||||
|
||||
pa_database_sync(u->database);
|
||||
pa_log_info("Synced.");
|
||||
|
||||
#ifdef DUMP_DATABASE
|
||||
dump_database(u);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void notify_subscribers(struct userdata *u) {
|
||||
|
||||
pa_native_connection *c;
|
||||
|
|
@ -372,18 +450,6 @@ static void notify_subscribers(struct userdata *u) {
|
|||
}
|
||||
}
|
||||
|
||||
static void trigger_save(struct userdata *u) {
|
||||
|
||||
pa_assert(u);
|
||||
|
||||
notify_subscribers(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);
|
||||
}
|
||||
|
||||
static pa_bool_t entries_equal(const struct entry *a, const struct entry *b) {
|
||||
|
||||
pa_assert(a);
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ enum {
|
|||
};
|
||||
|
||||
|
||||
#define ENTRY_VERSION 3
|
||||
#define ENTRY_VERSION 1
|
||||
|
||||
struct entry {
|
||||
uint8_t version;
|
||||
|
|
@ -134,10 +134,22 @@ static void save_time_callback(pa_mainloop_api*a, pa_time_event* e, const struct
|
|||
pa_log_info("Synced.");
|
||||
}
|
||||
|
||||
static struct entry* entry_new(void) {
|
||||
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);
|
||||
}
|
||||
|
||||
static struct entry* entry_new(pa_bool_t add_pcm_format) {
|
||||
struct entry *r = pa_xnew0(struct entry, 1);
|
||||
r->version = ENTRY_VERSION;
|
||||
r->formats = pa_idxset_new(NULL, NULL);
|
||||
if (add_pcm_format) {
|
||||
pa_format_info *f = pa_format_info_new();
|
||||
f->encoding = PA_ENCODING_PCM;
|
||||
pa_idxset_put(r->formats, f, NULL);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
|
|
@ -149,6 +161,105 @@ static void entry_free(struct entry* e) {
|
|||
pa_xfree(e);
|
||||
}
|
||||
|
||||
static pa_bool_t entry_write(struct userdata *u, const char *name, const struct entry *e) {
|
||||
pa_tagstruct *t;
|
||||
pa_datum key, data;
|
||||
pa_bool_t r;
|
||||
uint32_t i;
|
||||
pa_format_info *f;
|
||||
uint8_t n_formats;
|
||||
|
||||
pa_assert(u);
|
||||
pa_assert(name);
|
||||
pa_assert(e);
|
||||
|
||||
n_formats = pa_idxset_size(e->formats);
|
||||
pa_assert(n_formats > 0);
|
||||
|
||||
t = pa_tagstruct_new(NULL, 0);
|
||||
pa_tagstruct_putu8(t, e->version);
|
||||
pa_tagstruct_put_boolean(t, e->volume_valid);
|
||||
pa_tagstruct_put_channel_map(t, &e->channel_map);
|
||||
pa_tagstruct_put_cvolume(t, &e->volume);
|
||||
pa_tagstruct_put_boolean(t, e->muted_valid);
|
||||
pa_tagstruct_put_boolean(t, e->muted);
|
||||
pa_tagstruct_put_boolean(t, e->port_valid);
|
||||
pa_tagstruct_puts(t, e->port);
|
||||
pa_tagstruct_putu8(t, n_formats);
|
||||
|
||||
PA_IDXSET_FOREACH(f, e->formats, i) {
|
||||
pa_tagstruct_put_format_info(t, f);
|
||||
}
|
||||
|
||||
key.data = (char *) name;
|
||||
key.size = strlen(name);
|
||||
|
||||
data.data = (void*)pa_tagstruct_data(t, &data.size);
|
||||
|
||||
r = (pa_database_set(u->database, &key, &data, TRUE) == 0);
|
||||
|
||||
pa_tagstruct_free(t);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
#ifdef ENABLE_LEGACY_DATABASE_ENTRY_FORMAT
|
||||
|
||||
#define LEGACY_ENTRY_VERSION 2
|
||||
static struct entry* legacy_entry_read(struct userdata *u, pa_datum *data) {
|
||||
struct legacy_entry {
|
||||
uint8_t version;
|
||||
pa_bool_t muted_valid:1, volume_valid:1, port_valid:1;
|
||||
pa_bool_t muted:1;
|
||||
pa_channel_map channel_map;
|
||||
pa_cvolume volume;
|
||||
char port[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->port, 0, sizeof(le->port))) {
|
||||
pa_log_warn("Port has missing NUL byte.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (le->volume_valid && !pa_channel_map_valid(&le->channel_map)) {
|
||||
pa_log_warn("Invalid channel map.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (le->volume_valid && (!pa_cvolume_valid(&le->volume) || !pa_cvolume_compatible_with_channel_map(&le->volume, &le->channel_map))) {
|
||||
pa_log_warn("Volume and channel map don't match.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
e = entry_new(TRUE);
|
||||
e->muted_valid = le->muted_valid;
|
||||
e->volume_valid = le->volume_valid;
|
||||
e->port_valid = le->port_valid;
|
||||
e->muted = le->muted;
|
||||
e->channel_map = le->channel_map;
|
||||
e->volume = le->volume;
|
||||
e->port = pa_xstrdup(le->port);
|
||||
return e;
|
||||
}
|
||||
#endif
|
||||
|
||||
static struct entry* entry_read(struct userdata *u, const char *name) {
|
||||
pa_datum key, data;
|
||||
struct entry *e = NULL;
|
||||
|
|
@ -168,7 +279,7 @@ static struct entry* entry_read(struct userdata *u, const char *name) {
|
|||
goto fail;
|
||||
|
||||
t = pa_tagstruct_new(data.data, data.size);
|
||||
e = entry_new();
|
||||
e = entry_new(FALSE);
|
||||
|
||||
if (pa_tagstruct_getu8(t, &e->version) < 0 ||
|
||||
e->version > ENTRY_VERSION ||
|
||||
|
|
@ -179,7 +290,7 @@ static struct entry* entry_read(struct userdata *u, const char *name) {
|
|||
pa_tagstruct_get_boolean(t, &e->muted) < 0 ||
|
||||
pa_tagstruct_get_boolean(t, &e->port_valid) < 0 ||
|
||||
pa_tagstruct_gets(t, &port) < 0 ||
|
||||
pa_tagstruct_getu8(t, &n_formats) < 0) {
|
||||
pa_tagstruct_getu8(t, &n_formats) < 0 || n_formats < 1) {
|
||||
|
||||
goto fail;
|
||||
}
|
||||
|
|
@ -221,55 +332,30 @@ fail:
|
|||
entry_free(e);
|
||||
if (t)
|
||||
pa_tagstruct_free(t);
|
||||
|
||||
#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
|
||||
|
||||
pa_datum_free(&data);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static pa_bool_t entry_write(struct userdata *u, const char *name, const struct entry *e) {
|
||||
pa_tagstruct *t;
|
||||
pa_datum key, data;
|
||||
pa_bool_t r;
|
||||
uint32_t i;
|
||||
pa_format_info *f;
|
||||
|
||||
pa_assert(u);
|
||||
pa_assert(name);
|
||||
pa_assert(e);
|
||||
|
||||
t = pa_tagstruct_new(NULL, 0);
|
||||
pa_tagstruct_putu8(t, e->version);
|
||||
pa_tagstruct_put_boolean(t, e->volume_valid);
|
||||
pa_tagstruct_put_channel_map(t, &e->channel_map);
|
||||
pa_tagstruct_put_cvolume(t, &e->volume);
|
||||
pa_tagstruct_put_boolean(t, e->muted_valid);
|
||||
pa_tagstruct_put_boolean(t, e->muted);
|
||||
pa_tagstruct_put_boolean(t, e->port_valid);
|
||||
pa_tagstruct_puts(t, e->port);
|
||||
pa_tagstruct_putu8(t, pa_idxset_size(e->formats));
|
||||
|
||||
PA_IDXSET_FOREACH(f, e->formats, i) {
|
||||
pa_tagstruct_put_format_info(t, f);
|
||||
}
|
||||
|
||||
key.data = (char *) name;
|
||||
key.size = strlen(name);
|
||||
|
||||
data.data = (void*)pa_tagstruct_data(t, &data.size);
|
||||
|
||||
r = (pa_database_set(u->database, &key, &data, TRUE) == 0);
|
||||
|
||||
pa_tagstruct_free(t);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
static struct entry* entry_copy(const struct entry *e) {
|
||||
struct entry* r;
|
||||
uint32_t idx;
|
||||
pa_format_info *f;
|
||||
|
||||
pa_assert(e);
|
||||
r = entry_new();
|
||||
r = entry_new(FALSE);
|
||||
r->version = e->version;
|
||||
r->muted_valid = e->muted_valid;
|
||||
r->volume_valid = e->volume_valid;
|
||||
|
|
@ -285,13 +371,6 @@ static struct entry* entry_copy(const struct entry *e) {
|
|||
return r;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
static pa_bool_t entries_equal(const struct entry *a, const struct entry *b) {
|
||||
pa_cvolume t;
|
||||
|
||||
|
|
@ -308,6 +387,11 @@ static pa_bool_t entries_equal(const struct entry *a, const struct entry *b) {
|
|||
(a->volume_valid && !pa_cvolume_equal(pa_cvolume_remap(&t, &b->channel_map, &a->channel_map), &a->volume)))
|
||||
return FALSE;
|
||||
|
||||
if (pa_idxset_size(a->formats) != pa_idxset_size(b->formats))
|
||||
return FALSE;
|
||||
|
||||
/** TODO: Compare a bit better */
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
|
@ -336,7 +420,7 @@ static void subscribe_callback(pa_core *c, pa_subscription_event_type_t t, uint3
|
|||
if ((old = entry_read(u, name)))
|
||||
entry = entry_copy(old);
|
||||
else
|
||||
entry = entry_new();
|
||||
entry = entry_new(TRUE);
|
||||
|
||||
if (sink->save_volume) {
|
||||
entry->channel_map = sink->channel_map;
|
||||
|
|
@ -368,7 +452,7 @@ static void subscribe_callback(pa_core *c, pa_subscription_event_type_t t, uint3
|
|||
if ((old = entry_read(u, name)))
|
||||
entry = entry_copy(old);
|
||||
else
|
||||
entry = entry_new();
|
||||
entry = entry_new(TRUE);
|
||||
|
||||
if (source->save_volume) {
|
||||
entry->channel_map = source->channel_map;
|
||||
|
|
@ -702,7 +786,7 @@ static int extension_cb(pa_native_protocol *p, pa_module *m, pa_native_connectio
|
|||
/* Read or create an entry */
|
||||
name = pa_sprintf_malloc("sink:%s", sink->name);
|
||||
if (!(e = entry_read(u, name)))
|
||||
e = entry_new();
|
||||
e = entry_new(FALSE);
|
||||
|
||||
/* Read all the formats from our tagstruct */
|
||||
for (i = 0; i < n_formats; ++i) {
|
||||
|
|
|
|||
|
|
@ -115,7 +115,7 @@ struct userdata {
|
|||
#endif
|
||||
};
|
||||
|
||||
#define ENTRY_VERSION 4
|
||||
#define ENTRY_VERSION 1
|
||||
|
||||
struct entry {
|
||||
uint8_t version;
|
||||
|
|
@ -1002,6 +1002,86 @@ static void entry_free(struct entry* e) {
|
|||
pa_xfree(e);
|
||||
}
|
||||
|
||||
static pa_bool_t entry_write(struct userdata *u, const char *name, const struct entry *e, pa_bool_t replace) {
|
||||
pa_tagstruct *t;
|
||||
pa_datum key, data;
|
||||
pa_bool_t r;
|
||||
|
||||
pa_assert(u);
|
||||
pa_assert(name);
|
||||
pa_assert(e);
|
||||
|
||||
t = pa_tagstruct_new(NULL, 0);
|
||||
pa_tagstruct_putu8(t, e->version);
|
||||
pa_tagstruct_put_boolean(t, e->volume_valid);
|
||||
pa_tagstruct_put_channel_map(t, &e->channel_map);
|
||||
pa_tagstruct_put_cvolume(t, &e->volume);
|
||||
pa_tagstruct_put_boolean(t, e->muted_valid);
|
||||
pa_tagstruct_put_boolean(t, e->muted);
|
||||
pa_tagstruct_put_boolean(t, e->device_valid);
|
||||
pa_tagstruct_puts(t, e->device);
|
||||
pa_tagstruct_put_boolean(t, e->card_valid);
|
||||
pa_tagstruct_puts(t, e->card);
|
||||
|
||||
key.data = (char *) name;
|
||||
key.size = strlen(name);
|
||||
|
||||
data.data = (void*)pa_tagstruct_data(t, &data.size);
|
||||
|
||||
r = (pa_database_set(u->database, &key, &data, replace) == 0);
|
||||
|
||||
pa_tagstruct_free(t);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
#ifdef ENABLE_LEGACY_DATABASE_ENTRY_FORMAT
|
||||
|
||||
#define LEGACY_ENTRY_VERSION 3
|
||||
static struct entry* legacy_entry_read(struct userdata *u, pa_datum *data) {
|
||||
struct legacy_entry {
|
||||
uint8_t version;
|
||||
pa_bool_t muted_valid:1, volume_valid:1, device_valid:1, card_valid:1;
|
||||
pa_bool_t muted:1;
|
||||
pa_channel_map channel_map;
|
||||
pa_cvolume volume;
|
||||
char device[PA_NAME_MAX];
|
||||
char card[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->device, 0, sizeof(le->device))) {
|
||||
pa_log_warn("Device has missing NUL byte.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!memchr(le->card, 0, sizeof(le->card))) {
|
||||
pa_log_warn("Card has missing NUL byte.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
e = entry_new();
|
||||
e->card = pa_xstrdup(le->card);
|
||||
return e;
|
||||
}
|
||||
#endif
|
||||
|
||||
static struct entry *entry_read(struct userdata *u, const char *name) {
|
||||
pa_datum key, data;
|
||||
struct entry *e = NULL;
|
||||
|
|
@ -1076,43 +1156,23 @@ fail:
|
|||
entry_free(e);
|
||||
if (t)
|
||||
pa_tagstruct_free(t);
|
||||
|
||||
#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, TRUE))
|
||||
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
|
||||
|
||||
pa_datum_free(&data);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static pa_bool_t entry_write(struct userdata *u, const char *name, const struct entry *e, pa_bool_t replace) {
|
||||
pa_tagstruct *t;
|
||||
pa_datum key, data;
|
||||
pa_bool_t r;
|
||||
|
||||
pa_assert(u);
|
||||
pa_assert(name);
|
||||
pa_assert(e);
|
||||
|
||||
t = pa_tagstruct_new(NULL, 0);
|
||||
pa_tagstruct_putu8(t, e->version);
|
||||
pa_tagstruct_put_boolean(t, e->volume_valid);
|
||||
pa_tagstruct_put_channel_map(t, &e->channel_map);
|
||||
pa_tagstruct_put_cvolume(t, &e->volume);
|
||||
pa_tagstruct_put_boolean(t, e->muted_valid);
|
||||
pa_tagstruct_put_boolean(t, e->muted);
|
||||
pa_tagstruct_put_boolean(t, e->device_valid);
|
||||
pa_tagstruct_puts(t, e->device);
|
||||
pa_tagstruct_put_boolean(t, e->card_valid);
|
||||
pa_tagstruct_puts(t, e->card);
|
||||
|
||||
key.data = (char *) name;
|
||||
key.size = strlen(name);
|
||||
|
||||
data.data = (void*)pa_tagstruct_data(t, &data.size);
|
||||
|
||||
r = (pa_database_set(u->database, &key, &data, replace) == 0);
|
||||
|
||||
pa_tagstruct_free(t);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
static struct entry* entry_copy(const struct entry *e) {
|
||||
struct entry* r;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue