[pulseaudio-commits] [SCM] PulseAudio Sound Server branch, master, updated. v0.9.15-108-g0cb3837

Lennart Poettering gitmailer-noreply at 0pointer.de
Wed May 13 16:25:03 PDT 2009


This is an automated email from the git hooks/post-receive script. It was
generated because of a push to the "PulseAudio Sound Server" repository.

The master branch has been updated
      from  905c8004a0b77ad4303f64b1dc8b1b29e3795a63 (commit)

- Log -----------------------------------------------------------------
0cb3837 alsa: be a bit more verbose when a hwparam call fails
b7e2223 database: port restore modules to new database API
003e03d macro: include string.h because we need it for memset
6df14e0 database: add tdb backend
46bceed database: add gdbm backend
c69ed91 database: add abstracted database API
-----------------------------------------------------------------------

Summary of changes:
 configure.ac                        |   74 ++++++++++-
 src/Makefile.am                     |   23 +++-
 src/modules/alsa/alsa-util.c        |   45 +++++-
 src/modules/module-card-restore.c   |   65 ++++------
 src/modules/module-device-restore.c |   65 ++++------
 src/modules/module-stream-restore.c |  138 ++++++++------------
 src/pulsecore/database-gdbm.c       |  246 +++++++++++++++++++++++++++++++++++
 src/pulsecore/database-tdb.c        |  224 +++++++++++++++++++++++++++++++
 src/pulsecore/database.h            |   61 +++++++++
 src/pulsecore/macro.h               |    1 +
 10 files changed, 766 insertions(+), 176 deletions(-)
 create mode 100644 src/pulsecore/database-gdbm.c
 create mode 100644 src/pulsecore/database-tdb.c
 create mode 100644 src/pulsecore/database.h

-----------------------------------------------------------------------

commit c69ed91239d64ffd22798aa9a485f62e9ec5ee93
Author: Lennart Poettering <lennart at poettering.net>
Date:   Thu May 14 01:21:56 2009 +0200

    database: add abstracted database API

diff --git a/src/pulsecore/database.h b/src/pulsecore/database.h
new file mode 100644
index 0000000..17455d4
--- /dev/null
+++ b/src/pulsecore/database.h
@@ -0,0 +1,61 @@
+#ifndef foopulsecoredatabasehfoo
+#define foopulsecoredatabasehfoo
+
+/***
+  This file is part of PulseAudio.
+
+  Copyright 2009 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 by the Free Software Foundation; either version 2.1 of the
+  License, 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
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with PulseAudio; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+  USA.
+***/
+
+#include <sys/types.h>
+
+#include <pulsecore/macro.h>
+
+/* A little abstraction over simple databases, such as gdbm, tdb, and
+ * so on. We only make minimal assumptions about the supported
+ * backend: it does not need to support locking, it does not have to
+ * be arch independant. */
+
+typedef struct pa_database pa_database;
+
+typedef struct pa_datum {
+    void *data;
+    size_t size;
+} pa_datum;
+
+void pa_datum_free(pa_datum *d);
+
+/* This will append a suffix to the filename */
+pa_database* pa_database_open(const char *fn, pa_bool_t for_write);
+void pa_database_close(pa_database *db);
+
+pa_datum* pa_database_get(pa_database *db, const pa_datum *key, pa_datum* data);
+
+int pa_database_set(pa_database *db, const pa_datum *key, const pa_datum* data, pa_bool_t overwrite);
+int pa_database_unset(pa_database *db, const pa_datum *key);
+
+int pa_database_clear(pa_database *db);
+
+signed pa_database_size(pa_database *db);
+
+pa_datum* pa_database_first(pa_database *db, pa_datum *key, pa_datum *data /* may be NULL */);
+pa_datum* pa_database_next(pa_database *db, const pa_datum *key, pa_datum *next, pa_datum *data /* may be NULL */);
+
+int pa_database_sync(pa_database *db);
+
+#endif

commit 46bceedc9813cfa51738adb5abef43edc06252a3
Author: Lennart Poettering <lennart at poettering.net>
Date:   Thu May 14 01:22:36 2009 +0200

    database: add gdbm backend

diff --git a/src/pulsecore/database-gdbm.c b/src/pulsecore/database-gdbm.c
new file mode 100644
index 0000000..aeaac64
--- /dev/null
+++ b/src/pulsecore/database-gdbm.c
@@ -0,0 +1,246 @@
+/***
+  This file is part of PulseAudio.
+
+  Copyright 2009 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 by the Free Software Foundation; either version 2.1 of the
+  License, 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
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with PulseAudio; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+  USA.
+***/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <errno.h>
+#include <gdbm.h>
+
+#include <pulse/xmalloc.h>
+#include <pulsecore/core-util.h>
+#include <pulsecore/log.h>
+
+#include "database.h"
+
+#define MAKE_GDBM_FILE(x) ((GDBM_FILE) (x))
+
+static inline datum* datum_to_gdbm(datum *to, const pa_datum *from) {
+    pa_assert(from);
+    pa_assert(to);
+
+    to->dptr = from->data;
+    to->dsize = from->size;
+
+    return to;
+}
+
+static inline pa_datum* datum_from_gdbm(pa_datum *to, const datum *from) {
+    pa_assert(from);
+    pa_assert(to);
+
+    to->data = from->dptr;
+    to->size = from->dsize;
+
+    return to;
+}
+
+void pa_datum_free(pa_datum *d) {
+    pa_assert(d);
+
+    free(d->data); /* gdbm uses raw malloc/free hence we should do that here, too */
+    pa_zero(d);
+}
+
+pa_database* pa_database_open(const char *fn, pa_bool_t for_write) {
+    GDBM_FILE f;
+    int gdbm_cache_size;
+    char *path;
+
+    pa_assert(fn);
+
+    /* We include the host identifier in the file name because gdbm
+     * files are CPU dependant, and we don't want things to go wrong
+     * if we are on a multiarch system. */
+
+    path = pa_sprintf_malloc("%s."CANONICAL_HOST".gdbm", fn);
+    errno = 0;
+    f = gdbm_open((char*) path, 0, GDBM_NOLOCK | (for_write ? GDBM_WRCREAT : GDBM_READER), 0644, NULL);
+
+    if (f)
+        pa_log_debug("Opened GDBM database '%s'", path);
+
+    pa_xfree(path);
+
+    if (!f) {
+        if (errno == 0)
+            errno = EIO;
+        return NULL;
+    }
+
+    /* By default the cache of gdbm is rather large, let's reduce it a bit to save memory */
+    gdbm_cache_size = 10;
+    gdbm_setopt(f, GDBM_CACHESIZE, &gdbm_cache_size, sizeof(gdbm_cache_size));
+
+    return (pa_database*) f;
+}
+
+void pa_database_close(pa_database *db) {
+    pa_assert(db);
+
+    gdbm_close(MAKE_GDBM_FILE(db));
+}
+
+pa_datum* pa_database_get(pa_database *db, const pa_datum *key, pa_datum* data) {
+    datum gdbm_key, gdbm_data;
+
+    pa_assert(db);
+    pa_assert(key);
+    pa_assert(data);
+
+    gdbm_data = gdbm_fetch(MAKE_GDBM_FILE(db), *datum_to_gdbm(&gdbm_key, key));
+
+    return gdbm_data.dptr ?
+        datum_from_gdbm(data, &gdbm_data) :
+        NULL;
+}
+
+int pa_database_set(pa_database *db, const pa_datum *key, const pa_datum* data, pa_bool_t overwrite) {
+    datum gdbm_key, gdbm_data;
+
+    pa_assert(db);
+    pa_assert(key);
+    pa_assert(data);
+
+    return gdbm_store(MAKE_GDBM_FILE(db),
+                      *datum_to_gdbm(&gdbm_key, key),
+                      *datum_to_gdbm(&gdbm_data, data),
+                      overwrite ? GDBM_REPLACE : GDBM_INSERT) != 0 ? -1 : 0;
+}
+
+int pa_database_unset(pa_database *db, const pa_datum *key) {
+    datum gdbm_key;
+
+    pa_assert(db);
+    pa_assert(key);
+
+    return gdbm_delete(MAKE_GDBM_FILE(db), *datum_to_gdbm(&gdbm_key, key)) != 0 ? -1 : 0;
+}
+
+int pa_database_clear(pa_database *db) {
+    datum gdbm_key;
+
+    pa_assert(db);
+
+    gdbm_key = gdbm_firstkey(MAKE_GDBM_FILE(db));
+
+    while (gdbm_key.dptr) {
+        datum next;
+
+        next = gdbm_nextkey(MAKE_GDBM_FILE(db), gdbm_key);
+
+        gdbm_delete(MAKE_GDBM_FILE(db), gdbm_key);
+
+        free(gdbm_key.dptr);
+        gdbm_key = next;
+    }
+
+    return gdbm_reorganize(MAKE_GDBM_FILE(db)) == 0 ? 0 : -1;
+}
+
+signed pa_database_size(pa_database *db) {
+    datum gdbm_key;
+    unsigned n = 0;
+
+    pa_assert(db);
+
+    /* This sucks */
+
+    gdbm_key = gdbm_firstkey(MAKE_GDBM_FILE(db));
+
+    while (gdbm_key.dptr) {
+        datum next;
+
+        n++;
+
+        next = gdbm_nextkey(MAKE_GDBM_FILE(db), gdbm_key);
+        free(gdbm_key.dptr);
+        gdbm_key = next;
+    }
+
+    return (signed) n;
+}
+
+pa_datum* pa_database_first(pa_database *db, pa_datum *key, pa_datum *data) {
+    datum gdbm_key, gdbm_data;
+
+    pa_assert(db);
+    pa_assert(key);
+
+    gdbm_key = gdbm_firstkey(MAKE_GDBM_FILE(db));
+
+    if (!gdbm_key.dptr)
+        return NULL;
+
+    if (data) {
+        gdbm_data = gdbm_fetch(MAKE_GDBM_FILE(db), gdbm_key);
+
+        if (!gdbm_data.dptr) {
+            free(gdbm_key.dptr);
+            return NULL;
+        }
+
+        datum_from_gdbm(data, &gdbm_data);
+    }
+
+    datum_from_gdbm(key, &gdbm_key);
+
+    return key;
+}
+
+pa_datum* pa_database_next(pa_database *db, const pa_datum *key, pa_datum *next, pa_datum *data) {
+    datum gdbm_key, gdbm_data;
+
+    pa_assert(db);
+    pa_assert(key);
+    pa_assert(next);
+
+    if (!key)
+        return pa_database_first(db, next, data);
+
+    gdbm_key = gdbm_nextkey(MAKE_GDBM_FILE(db), *datum_to_gdbm(&gdbm_key, key));
+
+    if (!gdbm_key.dptr)
+        return NULL;
+
+    if (data) {
+        gdbm_data = gdbm_fetch(MAKE_GDBM_FILE(db), gdbm_key);
+
+        if (!gdbm_data.dptr) {
+            free(gdbm_key.dptr);
+            return NULL;
+        }
+
+        datum_from_gdbm(data, &gdbm_data);
+    }
+
+    datum_from_gdbm(next, &gdbm_key);
+
+    return next;
+}
+
+int pa_database_sync(pa_database *db) {
+    pa_assert(db);
+
+    gdbm_sync(MAKE_GDBM_FILE(db));
+    return 0;
+}

commit 6df14e016148cc50e92911fda8c641cc35482198
Author: Lennart Poettering <lennart at poettering.net>
Date:   Thu May 14 01:22:49 2009 +0200

    database: add tdb backend

diff --git a/src/pulsecore/database-tdb.c b/src/pulsecore/database-tdb.c
new file mode 100644
index 0000000..c35fd81
--- /dev/null
+++ b/src/pulsecore/database-tdb.c
@@ -0,0 +1,224 @@
+/***
+  This file is part of PulseAudio.
+
+  Copyright 2009 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 by the Free Software Foundation; either version 2.1 of the
+  License, 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
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with PulseAudio; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+  USA.
+***/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <fcntl.h>
+#include <unistd.h>
+#include <errno.h>
+#include <tdb.h>
+
+#include <pulse/xmalloc.h>
+#include <pulsecore/core-util.h>
+#include <pulsecore/log.h>
+
+#include "database.h"
+
+#define MAKE_TDB_CONTEXT(x) ((struct tdb_context*) (x))
+
+static inline TDB_DATA* datum_to_tdb(TDB_DATA *to, const pa_datum *from) {
+    pa_assert(from);
+    pa_assert(to);
+
+    to->dptr = from->data;
+    to->dsize = from->size;
+
+    return to;
+}
+
+static inline pa_datum* datum_from_tdb(pa_datum *to, const TDB_DATA *from) {
+    pa_assert(from);
+    pa_assert(to);
+
+    to->data = from->dptr;
+    to->size = from->dsize;
+
+    return to;
+}
+
+void pa_datum_free(pa_datum *d) {
+    pa_assert(d);
+
+    free(d->data); /* tdb uses raw malloc/free hence we should do that here, too */
+    pa_zero(d);
+}
+
+pa_database* pa_database_open(const char *fn, pa_bool_t for_write) {
+    struct tdb_context *c;
+    char *path;
+
+    pa_assert(fn);
+
+    path = pa_sprintf_malloc("%s.tdb", fn);
+    errno = 0;
+    c = tdb_open(path, 0, TDB_NOSYNC|TDB_NOLOCK,
+                 (for_write ? O_RDWR|O_CREAT : O_RDONLY)|O_NOCTTY
+#ifdef O_CLOEXEC
+                 |O_CLOEXEC
+#endif
+                 , 0644);
+
+    if (c)
+        pa_log_debug("Opened TDB database '%s'", path);
+
+    pa_xfree(path);
+
+    if (!c) {
+        if (errno == 0)
+            errno = EIO;
+        return NULL;
+    }
+
+    return (pa_database*) c;
+}
+
+void pa_database_close(pa_database *db) {
+    pa_assert(db);
+
+    tdb_close(MAKE_TDB_CONTEXT(db));
+}
+
+pa_datum* pa_database_get(pa_database *db, const pa_datum *key, pa_datum* data) {
+    TDB_DATA tdb_key, tdb_data;
+
+    pa_assert(db);
+    pa_assert(key);
+    pa_assert(data);
+
+    tdb_data = tdb_fetch(MAKE_TDB_CONTEXT(db), *datum_to_tdb(&tdb_key, key));
+
+    return tdb_data.dptr ?
+        datum_from_tdb(data, &tdb_data) :
+        NULL;
+}
+
+int pa_database_set(pa_database *db, const pa_datum *key, const pa_datum* data, pa_bool_t overwrite) {
+    TDB_DATA tdb_key, tdb_data;
+
+    pa_assert(db);
+    pa_assert(key);
+    pa_assert(data);
+
+    return tdb_store(MAKE_TDB_CONTEXT(db),
+                      *datum_to_tdb(&tdb_key, key),
+                      *datum_to_tdb(&tdb_data, data),
+                     overwrite ? TDB_REPLACE : TDB_INSERT) != 0 ? -1 : 0;
+}
+
+int pa_database_unset(pa_database *db, const pa_datum *key) {
+    TDB_DATA tdb_key;
+
+    pa_assert(db);
+    pa_assert(key);
+
+    return tdb_delete(MAKE_TDB_CONTEXT(db), *datum_to_tdb(&tdb_key, key)) != 0 ? -1 : 0;
+}
+
+int pa_database_clear(pa_database *db) {
+    pa_assert(db);
+
+    return tdb_wipe_all(MAKE_TDB_CONTEXT(db)) != 0 ? -1 : 0;
+}
+
+signed pa_database_size(pa_database *db) {
+    TDB_DATA tdb_key;
+    unsigned n = 0;
+
+    pa_assert(db);
+
+    /* This sucks */
+
+    tdb_key = tdb_firstkey(MAKE_TDB_CONTEXT(db));
+
+    while (tdb_key.dptr) {
+        TDB_DATA next;
+
+        n++;
+
+        next = tdb_nextkey(MAKE_TDB_CONTEXT(db), tdb_key);
+        free(tdb_key.dptr);
+        tdb_key = next;
+    }
+
+    return (signed) n;
+}
+
+pa_datum* pa_database_first(pa_database *db, pa_datum *key, pa_datum *data) {
+    TDB_DATA tdb_key, tdb_data;
+
+    pa_assert(db);
+    pa_assert(key);
+
+    tdb_key = tdb_firstkey(MAKE_TDB_CONTEXT(db));
+
+    if (!tdb_key.dptr)
+        return NULL;
+
+    if (data) {
+        tdb_data = tdb_fetch(MAKE_TDB_CONTEXT(db), tdb_key);
+
+        if (!tdb_data.dptr) {
+            free(tdb_key.dptr);
+            return NULL;
+        }
+
+        datum_from_tdb(data, &tdb_data);
+    }
+
+    datum_from_tdb(key, &tdb_key);
+
+    return key;
+}
+
+pa_datum* pa_database_next(pa_database *db, const pa_datum *key, pa_datum *next, pa_datum *data) {
+    TDB_DATA tdb_key, tdb_data;
+
+    pa_assert(db);
+    pa_assert(key);
+
+    tdb_key = tdb_nextkey(MAKE_TDB_CONTEXT(db), *datum_to_tdb(&tdb_key, key));
+
+    if (!tdb_key.dptr)
+        return NULL;
+
+    if (data) {
+        tdb_data = tdb_fetch(MAKE_TDB_CONTEXT(db), tdb_key);
+
+        if (!tdb_data.dptr) {
+            free(tdb_key.dptr);
+            return NULL;
+        }
+
+        datum_from_tdb(data, &tdb_data);
+    }
+
+    datum_from_tdb(next, &tdb_key);
+
+    return next;
+}
+
+int pa_database_sync(pa_database *db) {
+    pa_assert(db);
+
+    return 0;
+}

commit 003e03d233b7eef7ca1d69ac2978280adb0520c0
Author: Lennart Poettering <lennart at poettering.net>
Date:   Thu May 14 01:23:12 2009 +0200

    macro: include string.h because we need it for memset

diff --git a/src/pulsecore/macro.h b/src/pulsecore/macro.h
index e9888c3..cf66251 100644
--- a/src/pulsecore/macro.h
+++ b/src/pulsecore/macro.h
@@ -29,6 +29,7 @@
 #include <unistd.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 
 #include <pulse/gccmacro.h>
 

commit b7e222318652b660391de9f96ea47f3ba164630b
Author: Lennart Poettering <lennart at poettering.net>
Date:   Thu May 14 01:24:26 2009 +0200

    database: port restore modules to new database API

diff --git a/configure.ac b/configure.ac
index 6031ebd..16e6648 100644
--- a/configure.ac
+++ b/configure.ac
@@ -392,9 +392,6 @@ AC_SEARCH_LIBS([connect], [socket])
 # build, disabling its ability to make dlls.
 AC_CHECK_FUNCS([getopt_long], [], [AC_CHECK_LIB([iberty], [getopt_long])])
 
-AC_CHECK_LIB(gdbm, gdbm_open)
-AC_CHECK_HEADERS(gdbm.h, [], [AC_MSG_ERROR([gdbm.h not found])])
-
 #### Check for functions ####
 
 # ISO
@@ -602,6 +599,65 @@ AC_SUBST(LIBSAMPLERATE_LIBS)
 AC_SUBST(HAVE_LIBSAMPLERATE)
 AM_CONDITIONAL([HAVE_LIBSAMPLERATE], [test "x$HAVE_LIBSAMPLERATE" = x1])
 
+#### Database support ####
+
+HAVE_TDB=0
+HAVE_GDBM=0
+
+AC_ARG_WITH(
+        [database],
+        AS_HELP_STRING([--with-database=auto|tdb|gdbm],[Choose database backend.]),[],[with_database=auto])
+
+if test "x${with_database}" == "xauto" -o "x${with_database}" == "xtdb" ; then
+    PKG_CHECK_MODULES(TDB, [ tdb ],
+        [
+            HAVE_TDB=1
+            with_database=tdb
+        ], [
+            if test "x${with_database}" == "xtdb" ; then
+                AC_MSG_ERROR([*** tdb not found])
+            fi
+        ])
+fi
+
+if test "x${with_database}" == "xauto" -o "x${with_database}" == "xgdbm" ; then
+   have_gdbm=yes
+
+   AC_CHECK_LIB(gdbm, gdbm_open, [], [have_gdbm=no])
+   AC_CHECK_HEADERS(gdbm.h, [], [have_gdbm=no])
+
+   if test "x${have_gdbm}" == "xyes" ; then
+       HAVE_GDBM=1
+       GDBM_CFLAGS=
+       GDBM_LIBS=-lgdbm
+       with_database=gdbm
+   elif test "x${with_database}" == "xgdbm"; then
+       AC_MSG_ERROR([*** gdbm not found])
+   fi
+fi
+
+if test "x${HAVE_TDB}" != x1 -a "x${HAVE_GDBM}" != x1; then
+   AC_MSG_ERROR([*** missing database backend])
+fi
+
+if test "x${HAVE_TDB}" = x1 ; then
+   AC_DEFINE([HAVE_TDB], 1, [Have tdb?])
+fi
+
+if test "x${HAVE_GDBM}" = x1 ; then
+   AC_DEFINE([HAVE_GDBM], 1, [Have gdbm?])
+fi
+
+AC_SUBST(TDB_CFLAGS)
+AC_SUBST(TDB_LIBS)
+AC_SUBST(HAVE_TDB)
+AM_CONDITIONAL([HAVE_TDB], [test "x$HAVE_TDB" = x1])
+
+AC_SUBST(GDBM_CFLAGS)
+AC_SUBST(GDBM_LIBS)
+AC_SUBST(HAVE_GDBM)
+AM_CONDITIONAL([HAVE_GDBM], [test "x$HAVE_GDBM" = x1])
+
 #### OSS support (optional) ####
 
 AC_ARG_ENABLE([oss],
@@ -1410,6 +1466,16 @@ if test "x${HAVE_POLKIT}" = "x1" ; then
    ENABLE_POLKIT=yes
 fi
 
+ENABLE_GDBM=no
+if test "x${HAVE_GDBM}" = "x1" ; then
+   ENABLE_GDBM=yes
+fi
+
+ENABLE_TDB=no
+if test "x${HAVE_TDB}" = "x1" ; then
+   ENABLE_TDB=yes
+fi
+
 ENABLE_OPENSSL=no
 if test "x${HAVE_OPENSSL}" = "x1" ; then
    ENABLE_OPENSSL=yes
@@ -1456,6 +1522,8 @@ echo "
     Enable PolicyKit:              ${ENABLE_POLKIT}
     Enable IPv6:                   ${ENABLE_IPV6}
     Enable OpenSSL (for Airtunes): ${ENABLE_OPENSSL}
+    Enable tdb:                    ${ENABLE_TDB}
+    Enable gdbm:                   ${ENABLE_GDBM}
 
     System User:                   ${PA_SYSTEM_USER}
     System Group:                  ${PA_SYSTEM_GROUP}
diff --git a/src/Makefile.am b/src/Makefile.am
index b41ae39..49a0c69 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -816,7 +816,8 @@ libpulsecore_ at PA_MAJORMINORMICRO@_la_SOURCES = \
 		pulsecore/source.c pulsecore/source.h \
 		pulsecore/start-child.c pulsecore/start-child.h \
 		pulsecore/thread-mq.c pulsecore/thread-mq.h \
-		pulsecore/time-smoother.c pulsecore/time-smoother.h
+		pulsecore/time-smoother.c pulsecore/time-smoother.h \
+		pulsecore/database.h
 
 libpulsecore_ at PA_MAJORMINORMICRO@_la_CFLAGS = $(AM_CFLAGS) $(LIBOIL_CFLAGS)
 libpulsecore_ at PA_MAJORMINORMICRO@_la_LDFLAGS = -avoid-version
@@ -828,13 +829,25 @@ libpulsecore_ at PA_MAJORMINORMICRO@_la_CFLAGS += $(X11_CFLAGS)
 libpulsecore_ at PA_MAJORMINORMICRO@_la_LDFLAGS += $(X11_LIBS)
 endif
 
-
 if HAVE_DBUS
 libpulsecore_ at PA_MAJORMINORMICRO@_la_SOURCES += pulsecore/dbus-shared.c pulsecore/dbus-shared.h
 libpulsecore_ at PA_MAJORMINORMICRO@_la_CFLAGS += $(DBUS_CFLAGS)
 libpulsecore_ at PA_MAJORMINORMICRO@_la_LIBADD += $(DBUS_LIBS)
 endif
 
+if HAVE_GDBM
+libpulsecore_ at PA_MAJORMINORMICRO@_la_SOURCES += pulsecore/database-gdbm.c
+libpulsecore_ at PA_MAJORMINORMICRO@_la_CFLAGS += $(GDBM_CFLAGS)
+libpulsecore_ at PA_MAJORMINORMICRO@_la_LIBADD += $(GDBM_LIBS)
+endif
+
+if HAVE_TDB
+libpulsecore_ at PA_MAJORMINORMICRO@_la_SOURCES += pulsecore/database-tdb.c
+libpulsecore_ at PA_MAJORMINORMICRO@_la_CFLAGS += $(TDB_CFLAGS)
+libpulsecore_ at PA_MAJORMINORMICRO@_la_LIBADD += $(TDB_LIBS)
+endif
+
+
 # We split the foreign code off to not be annoyed by warnings we don't care about
 noinst_LTLIBRARIES = libpulsecore-foreign.la
 
@@ -1441,19 +1454,19 @@ module_cork_music_on_phone_la_CFLAGS = $(AM_CFLAGS)
 # Device volume/muted restore module
 module_device_restore_la_SOURCES = modules/module-device-restore.c
 module_device_restore_la_LDFLAGS = $(MODULE_LDFLAGS)
-module_device_restore_la_LIBADD = $(AM_LIBADD) libpulsecore- at PA_MAJORMINORMICRO@.la -lgdbm libpulsecommon- at PA_MAJORMINORMICRO@.la libpulse.la
+module_device_restore_la_LIBADD = $(AM_LIBADD) libpulsecore- at PA_MAJORMINORMICRO@.la libpulsecommon- at PA_MAJORMINORMICRO@.la libpulse.la
 module_device_restore_la_CFLAGS = $(AM_CFLAGS)
 
 # Stream volume/muted/device restore module
 module_stream_restore_la_SOURCES = modules/module-stream-restore.c
 module_stream_restore_la_LDFLAGS = $(MODULE_LDFLAGS)
-module_stream_restore_la_LIBADD = $(AM_LIBADD) libprotocol-native.la libpulsecore- at PA_MAJORMINORMICRO@.la -lgdbm libpulsecommon- at PA_MAJORMINORMICRO@.la libpulse.la
+module_stream_restore_la_LIBADD = $(AM_LIBADD) libprotocol-native.la libpulsecore- at PA_MAJORMINORMICRO@.la libpulsecommon- at PA_MAJORMINORMICRO@.la libpulse.la
 module_stream_restore_la_CFLAGS = $(AM_CFLAGS)
 
 # Card profile restore module
 module_card_restore_la_SOURCES = modules/module-card-restore.c
 module_card_restore_la_LDFLAGS = $(MODULE_LDFLAGS)
-module_card_restore_la_LIBADD = $(AM_LIBADD) libpulsecore- at PA_MAJORMINORMICRO@.la -lgdbm libpulsecommon- at PA_MAJORMINORMICRO@.la libpulse.la
+module_card_restore_la_LIBADD = $(AM_LIBADD) libpulsecore- at PA_MAJORMINORMICRO@.la libpulsecommon- at PA_MAJORMINORMICRO@.la libpulse.la
 module_card_restore_la_CFLAGS = $(AM_CFLAGS)
 
 # Default sink/source restore module
diff --git a/src/modules/module-card-restore.c b/src/modules/module-card-restore.c
index 17f1f8c..85478d1 100644
--- a/src/modules/module-card-restore.c
+++ b/src/modules/module-card-restore.c
@@ -30,7 +30,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <ctype.h>
-#include <gdbm.h>
 
 #include <pulse/xmalloc.h>
 #include <pulse/volume.h>
@@ -45,6 +44,7 @@
 #include <pulsecore/core-subscribe.h>
 #include <pulsecore/card.h>
 #include <pulsecore/namereg.h>
+#include <pulsecore/database.h>
 
 #include "module-card-restore-symdef.h"
 
@@ -65,7 +65,7 @@ struct userdata {
     pa_subscription *subscription;
     pa_hook_slot *card_new_hook_slot;
     pa_time_event *save_time_event;
-    GDBM_FILE gdbm_file;
+    pa_database *database;
 };
 
 #define ENTRY_VERSION 1
@@ -87,31 +87,31 @@ static void save_time_callback(pa_mainloop_api*a, pa_time_event* e, const struct
     u->core->mainloop->time_free(u->save_time_event);
     u->save_time_event = NULL;
 
-    gdbm_sync(u->gdbm_file);
+    pa_database_sync(u->database);
     pa_log_info("Synced.");
 }
 
 static struct entry* read_entry(struct userdata *u, const char *name) {
-    datum key, data;
+    pa_datum key, data;
     struct entry *e;
 
     pa_assert(u);
     pa_assert(name);
 
-    key.dptr = (char*) name;
-    key.dsize = (int) strlen(name);
+    key.data = (char*) name;
+    key.size = strlen(name);
 
-    data = gdbm_fetch(u->gdbm_file, key);
+    pa_zero(data);
 
-    if (!data.dptr)
+    if (!pa_database_get(u->database, &key, &data))
         goto fail;
 
-    if (data.dsize != sizeof(struct entry)) {
-        pa_log_debug("Database contains entry for card %s of wrong size %lu != %lu. Probably due to upgrade, ignoring.", name, (unsigned long) data.dsize, (unsigned long) sizeof(struct entry));
+    if (data.size != sizeof(struct entry)) {
+        pa_log_debug("Database contains entry for card %s of wrong size %lu != %lu. Probably due to upgrade, ignoring.", name, (unsigned long) data.size, (unsigned long) sizeof(struct entry));
         goto fail;
     }
 
-    e = (struct entry*) data.dptr;
+    e = (struct entry*) data.data;
 
     if (e->version != ENTRY_VERSION) {
         pa_log_debug("Version of database entry for card %s doesn't match our version. Probably due to upgrade, ignoring.", name);
@@ -127,7 +127,7 @@ static struct entry* read_entry(struct userdata *u, const char *name) {
 
 fail:
 
-    pa_xfree(data.dptr);
+    pa_datum_free(&data);
     return NULL;
 }
 
@@ -145,7 +145,7 @@ static void trigger_save(struct userdata *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;
-    datum key, data;
+    pa_datum key, data;
     pa_card *card;
 
     pa_assert(c);
@@ -155,7 +155,7 @@ static void subscribe_callback(pa_core *c, pa_subscription_event_type_t t, uint3
         t != (PA_SUBSCRIPTION_EVENT_CARD|PA_SUBSCRIPTION_EVENT_CHANGE))
         return;
 
-    memset(&entry, 0, sizeof(entry));
+    pa_zero(entry);
     entry.version = ENTRY_VERSION;
 
     if (!(card = pa_idxset_get_by_index(c->cards, idx)))
@@ -176,15 +176,15 @@ static void subscribe_callback(pa_core *c, pa_subscription_event_type_t t, uint3
         pa_xfree(old);
     }
 
-    key.dptr = card->name;
-    key.dsize = (int) strlen(card->name);
+    key.data = card->name;
+    key.size = strlen(card->name);
 
-    data.dptr = (void*) &entry;
-    data.dsize = sizeof(entry);
+    data.data = &entry;
+    data.size = sizeof(entry);
 
     pa_log_info("Storing profile for card %s.", card->name);
 
-    gdbm_store(u->gdbm_file, key, data, GDBM_REPLACE);
+    pa_database_set(u->database, &key, &data, TRUE);
 
     trigger_save(u);
 }
@@ -211,10 +211,9 @@ static pa_hook_result_t card_new_hook_callback(pa_core *c, pa_card_new_data *new
 int pa__init(pa_module*m) {
     pa_modargs *ma = NULL;
     struct userdata *u;
-    char *fname, *fn;
+    char *fname;
     pa_card *card;
     uint32_t idx;
-    int gdbm_cache_size;
 
     pa_assert(m);
 
@@ -227,33 +226,21 @@ int pa__init(pa_module*m) {
     u->core = m->core;
     u->module = m;
     u->save_time_event = NULL;
-    u->gdbm_file = NULL;
+    u->database = NULL;
 
     u->subscription = pa_subscription_new(m->core, PA_SUBSCRIPTION_MASK_CARD, subscribe_callback, u);
 
     u->card_new_hook_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_CARD_NEW], PA_HOOK_EARLY, (pa_hook_cb_t) card_new_hook_callback, u);
 
-    /* We include the host identifier in the file name because gdbm
-     * files are CPU dependant, and we don't want things to go wrong
-     * if we are on a multiarch system. */
-
-    fn = pa_sprintf_malloc("card-database."CANONICAL_HOST".gdbm");
-    fname = pa_state_path(fn, TRUE);
-    pa_xfree(fn);
-
-    if (!fname)
+    if (!(fname = pa_state_path("card-database", TRUE)))
         goto fail;
 
-    if (!(u->gdbm_file = gdbm_open(fname, 0, GDBM_WRCREAT|GDBM_NOLOCK, 0600, NULL))) {
-        pa_log("Failed to open volume database '%s': %s", fname, gdbm_strerror(gdbm_errno));
+    if (!(u->database = pa_database_open(fname, TRUE))) {
+        pa_log("Failed to open volume database '%s': %s", fname, pa_cstrerror(errno));
         pa_xfree(fname);
         goto fail;
     }
 
-    /* By default the cache of gdbm is rather large, let's reduce it a bit to save memory */
-    gdbm_cache_size = 10;
-    gdbm_setopt(u->gdbm_file, GDBM_CACHESIZE, &gdbm_cache_size, sizeof(gdbm_cache_size));
-
     pa_log_info("Sucessfully opened database file '%s'.", fname);
     pa_xfree(fname);
 
@@ -289,8 +276,8 @@ void pa__done(pa_module*m) {
     if (u->save_time_event)
         u->core->mainloop->time_free(u->save_time_event);
 
-    if (u->gdbm_file)
-        gdbm_close(u->gdbm_file);
+    if (u->database)
+        pa_database_close(u->database);
 
     pa_xfree(u);
 }
diff --git a/src/modules/module-device-restore.c b/src/modules/module-device-restore.c
index 7d87ca0..ae21acd 100644
--- a/src/modules/module-device-restore.c
+++ b/src/modules/module-device-restore.c
@@ -30,7 +30,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <ctype.h>
-#include <gdbm.h>
 
 #include <pulse/xmalloc.h>
 #include <pulse/volume.h>
@@ -46,6 +45,7 @@
 #include <pulsecore/sink-input.h>
 #include <pulsecore/source-output.h>
 #include <pulsecore/namereg.h>
+#include <pulsecore/database.h>
 
 #include "module-device-restore-symdef.h"
 
@@ -73,7 +73,7 @@ struct userdata {
         *sink_fixate_hook_slot,
         *source_fixate_hook_slot;
     pa_time_event *save_time_event;
-    GDBM_FILE gdbm_file;
+    pa_database *database;
 
     pa_bool_t restore_volume:1;
     pa_bool_t restore_muted:1;
@@ -100,31 +100,31 @@ static void save_time_callback(pa_mainloop_api*a, pa_time_event* e, const struct
     u->core->mainloop->time_free(u->save_time_event);
     u->save_time_event = NULL;
 
-    gdbm_sync(u->gdbm_file);
+    pa_database_sync(u->database);
     pa_log_info("Synced.");
 }
 
 static struct entry* read_entry(struct userdata *u, const char *name) {
-    datum key, data;
+    pa_datum key, data;
     struct entry *e;
 
     pa_assert(u);
     pa_assert(name);
 
-    key.dptr = (char*) name;
-    key.dsize = (int) strlen(name);
+    key.data = (char*) name;
+    key.size = strlen(name);
 
-    data = gdbm_fetch(u->gdbm_file, key);
+    pa_zero(data);
 
-    if (!data.dptr)
+    if (!pa_database_get(u->database, &key, &data))
         goto fail;
 
-    if (data.dsize != sizeof(struct entry)) {
-        pa_log_debug("Database contains entry for device %s of wrong size %lu != %lu. Probably due to upgrade, ignoring.", name, (unsigned long) data.dsize, (unsigned long) sizeof(struct entry));
+    if (data.size != sizeof(struct entry)) {
+        pa_log_debug("Database contains entry for device %s of wrong size %lu != %lu. Probably due to upgrade, ignoring.", name, (unsigned long) data.size, (unsigned long) sizeof(struct entry));
         goto fail;
     }
 
-    e = (struct entry*) data.dptr;
+    e = (struct entry*) data.data;
 
     if (e->version != ENTRY_VERSION) {
         pa_log_debug("Version of database entry for device %s doesn't match our version. Probably due to upgrade, ignoring.", name);
@@ -150,7 +150,7 @@ static struct entry* read_entry(struct userdata *u, const char *name) {
 
 fail:
 
-    pa_xfree(data.dptr);
+    pa_datum_free(&data);
     return NULL;
 }
 
@@ -169,7 +169,7 @@ static void subscribe_callback(pa_core *c, pa_subscription_event_type_t t, uint3
     struct userdata *u = userdata;
     struct entry entry, *old;
     char *name;
-    datum key, data;
+    pa_datum key, data;
 
     pa_assert(c);
     pa_assert(u);
@@ -180,7 +180,7 @@ static void subscribe_callback(pa_core *c, pa_subscription_event_type_t t, uint3
         t != (PA_SUBSCRIPTION_EVENT_SOURCE|PA_SUBSCRIPTION_EVENT_CHANGE))
         return;
 
-    memset(&entry, 0, sizeof(entry));
+    pa_zero(entry);
     entry.version = ENTRY_VERSION;
 
     if ((t & PA_SUBSCRIPTION_EVENT_FACILITY_MASK) == PA_SUBSCRIPTION_EVENT_SINK) {
@@ -221,15 +221,15 @@ static void subscribe_callback(pa_core *c, pa_subscription_event_type_t t, uint3
         pa_xfree(old);
     }
 
-    key.dptr = name;
-    key.dsize = (int) strlen(name);
+    key.data = name;
+    key.size = strlen(name);
 
-    data.dptr = (void*) &entry;
-    data.dsize = sizeof(entry);
+    data.data = &entry;
+    data.size = sizeof(entry);
 
     pa_log_info("Storing volume/mute for device %s.", name);
 
-    gdbm_store(u->gdbm_file, key, data, GDBM_REPLACE);
+    pa_database_set(u->database, &key, &data, TRUE);
 
     pa_xfree(name);
 
@@ -312,12 +312,11 @@ static pa_hook_result_t source_fixate_hook_callback(pa_core *c, pa_source_new_da
 int pa__init(pa_module*m) {
     pa_modargs *ma = NULL;
     struct userdata *u;
-    char *fname, *fn;
+    char *fname;
     pa_sink *sink;
     pa_source *source;
     uint32_t idx;
     pa_bool_t restore_volume = TRUE, restore_muted = TRUE;
-    int gdbm_cache_size;
 
     pa_assert(m);
 
@@ -341,7 +340,7 @@ int pa__init(pa_module*m) {
     u->save_time_event = NULL;
     u->restore_volume = restore_volume;
     u->restore_muted = restore_muted;
-    u->gdbm_file = NULL;
+    u->database = NULL;
 
     u->subscription = pa_subscription_new(m->core, PA_SUBSCRIPTION_MASK_SINK|PA_SUBSCRIPTION_MASK_SOURCE, subscribe_callback, u);
 
@@ -350,27 +349,15 @@ int pa__init(pa_module*m) {
         u->source_fixate_hook_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_FIXATE], PA_HOOK_EARLY, (pa_hook_cb_t) source_fixate_hook_callback, u);
     }
 
-    /* We include the host identifier in the file name because gdbm
-     * files are CPU dependant, and we don't want things to go wrong
-     * if we are on a multiarch system. */
-
-    fn = pa_sprintf_malloc("device-volumes."CANONICAL_HOST".gdbm");
-    fname = pa_state_path(fn, TRUE);
-    pa_xfree(fn);
-
-    if (!fname)
+    if (!(fname = pa_state_path("device-volumes", TRUE)))
         goto fail;
 
-    if (!(u->gdbm_file = gdbm_open(fname, 0, GDBM_WRCREAT|GDBM_NOLOCK, 0600, NULL))) {
-        pa_log("Failed to open volume database '%s': %s", fname, gdbm_strerror(gdbm_errno));
+    if (!(u->database = pa_database_open(fname, TRUE))) {
+        pa_log("Failed to open volume database '%s': %s", fname, pa_cstrerror(errno));
         pa_xfree(fname);
         goto fail;
     }
 
-    /* By default the cache of gdbm is rather large, let's reduce it a bit to save memory */
-    gdbm_cache_size = 10;
-    gdbm_setopt(u->gdbm_file, GDBM_CACHESIZE, &gdbm_cache_size, sizeof(gdbm_cache_size));
-
     pa_log_info("Sucessfully opened database file '%s'.", fname);
     pa_xfree(fname);
 
@@ -411,8 +398,8 @@ void pa__done(pa_module*m) {
     if (u->save_time_event)
         u->core->mainloop->time_free(u->save_time_event);
 
-    if (u->gdbm_file)
-        gdbm_close(u->gdbm_file);
+    if (u->database)
+        pa_database_close(u->database);
 
     pa_xfree(u);
 }
diff --git a/src/modules/module-stream-restore.c b/src/modules/module-stream-restore.c
index 70cd89a..2de98f4 100644
--- a/src/modules/module-stream-restore.c
+++ b/src/modules/module-stream-restore.c
@@ -30,7 +30,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <ctype.h>
-#include <gdbm.h>
 
 #include <pulse/xmalloc.h>
 #include <pulse/volume.h>
@@ -49,6 +48,7 @@
 #include <pulsecore/protocol-native.h>
 #include <pulsecore/pstream.h>
 #include <pulsecore/pstream-util.h>
+#include <pulsecore/database.h>
 
 #include "module-stream-restore-symdef.h"
 
@@ -81,7 +81,7 @@ struct userdata {
         *source_output_new_hook_slot,
         *connection_unlink_hook_slot;
     pa_time_event *save_time_event;
-    GDBM_FILE gdbm_file;
+    pa_database* database;
 
     pa_bool_t restore_device:1;
     pa_bool_t restore_volume:1;
@@ -123,7 +123,7 @@ static void save_time_callback(pa_mainloop_api*a, pa_time_event* e, const struct
     u->core->mainloop->time_free(u->save_time_event);
     u->save_time_event = NULL;
 
-    gdbm_sync(u->gdbm_file);
+    pa_database_sync(u->database);
     pa_log_info("Synced.");
 }
 
@@ -153,28 +153,28 @@ static char *get_name(pa_proplist *p, const char *prefix) {
 }
 
 static struct entry* read_entry(struct userdata *u, const char *name) {
-    datum key, data;
+    pa_datum key, data;
     struct entry *e;
 
     pa_assert(u);
     pa_assert(name);
 
-    key.dptr = (char*) name;
-    key.dsize = (int) strlen(name);
+    key.data = (char*) name;
+    key.size = strlen(name);
 
-    data = gdbm_fetch(u->gdbm_file, key);
+    pa_zero(data);
 
-    if (!data.dptr)
+    if (!pa_database_get(u->database, &key, &data))
         goto fail;
 
-    if (data.dsize != sizeof(struct entry)) {
+    if (data.size != sizeof(struct entry)) {
         /* This is probably just a database upgrade, hence let's not
          * consider this more than a debug message */
-        pa_log_debug("Database contains entry for stream %s of wrong size %lu != %lu. Probably due to uprade, ignoring.", name, (unsigned long) data.dsize, (unsigned long) sizeof(struct entry));
+        pa_log_debug("Database contains entry for stream %s of wrong size %lu != %lu. Probably due to uprade, ignoring.", name, (unsigned long) data.size, (unsigned long) sizeof(struct entry));
         goto fail;
     }
 
-    e = (struct entry*) data.dptr;
+    e = (struct entry*) data.data;
 
     if (e->version != ENTRY_VERSION) {
         pa_log_debug("Version of database entry for stream %s doesn't match our version. Probably due to upgrade, ignoring.", name);
@@ -205,7 +205,7 @@ static struct entry* read_entry(struct userdata *u, const char *name) {
 
 fail:
 
-    pa_xfree(data.dptr);
+    pa_datum_free(&data);
     return NULL;
 }
 
@@ -261,7 +261,7 @@ static void subscribe_callback(pa_core *c, pa_subscription_event_type_t t, uint3
     struct userdata *u = userdata;
     struct entry entry, *old;
     char *name;
-    datum key, data;
+    pa_datum key, data;
 
     pa_assert(c);
     pa_assert(u);
@@ -272,7 +272,7 @@ static void subscribe_callback(pa_core *c, pa_subscription_event_type_t t, uint3
         t != (PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT|PA_SUBSCRIPTION_EVENT_CHANGE))
         return;
 
-    memset(&entry, 0, sizeof(entry));
+    pa_zero(entry);
     entry.version = ENTRY_VERSION;
 
     if ((t & PA_SUBSCRIPTION_EVENT_FACILITY_MASK) == PA_SUBSCRIPTION_EVENT_SINK_INPUT) {
@@ -334,15 +334,15 @@ static void subscribe_callback(pa_core *c, pa_subscription_event_type_t t, uint3
         pa_xfree(old);
     }
 
-    key.dptr = name;
-    key.dsize = (int) strlen(name);
+    key.data = name;
+    key.size = strlen(name);
 
-    data.dptr = (void*) &entry;
-    data.dsize = sizeof(entry);
+    data.data = &entry;
+    data.size = sizeof(entry);
 
     pa_log_info("Storing volume/mute/device for stream %s.", name);
 
-    gdbm_store(u->gdbm_file, key, data, GDBM_REPLACE);
+    pa_database_set(u->database, &key, &data, TRUE);
 
     pa_xfree(name);
 
@@ -471,25 +471,6 @@ static pa_hook_result_t source_output_new_hook_callback(pa_core *c, pa_source_ou
 
 #define EXT_VERSION 1
 
-static void clear_db(struct userdata *u) {
-    datum key;
-
-    pa_assert(u);
-
-    key = gdbm_firstkey(u->gdbm_file);
-    while (key.dptr) {
-        datum next_key;
-        next_key = gdbm_nextkey(u->gdbm_file, key);
-
-        gdbm_delete(u->gdbm_file, key);
-        pa_xfree(key.dptr);
-
-        key = next_key;
-    }
-
-    gdbm_reorganize(u->gdbm_file);
-}
-
 static void apply_entry(struct userdata *u, const char *name, struct entry *e) {
     pa_sink_input *si;
     pa_source_output *so;
@@ -559,18 +540,20 @@ static void apply_entry(struct userdata *u, const char *name, struct entry *e) {
 
 #if 0
 static void dump_database(struct userdata *u) {
-    datum key;
+    pa_datum key;
+    pa_bool_t done;
 
-    key = gdbm_firstkey(u->gdbm_file);
-    while (key.dptr) {
-        datum next_key;
+    done = !pa_database_first(u->database, &key, NULL);
+
+    while (!done) {
+        pa_datum next_key;
         struct entry *e;
         char *name;
 
-        next_key = gdbm_nextkey(u->gdbm_file, key);
+        done = !pa_database_next(u->database, &key, &next_key, NULL);
 
-        name = pa_xstrndup(key.dptr, key.dsize);
-        pa_xfree(key.dptr);
+        name = pa_xstrndup(key.data, key.size);
+        pa_datum_free(&key);
 
         if ((e = read_entry(u, name))) {
             char t[256];
@@ -618,21 +601,23 @@ static int extension_cb(pa_native_protocol *p, pa_module *m, pa_native_connectio
         }
 
         case SUBCOMMAND_READ: {
-            datum key;
+            pa_datum key;
+            pa_bool_t done;
 
             if (!pa_tagstruct_eof(t))
                 goto fail;
 
-            key = gdbm_firstkey(u->gdbm_file);
-            while (key.dptr) {
-                datum next_key;
+            done = !pa_database_first(u->database, &key, NULL);
+
+            while (!done) {
+                pa_datum next_key;
                 struct entry *e;
                 char *name;
 
-                next_key = gdbm_nextkey(u->gdbm_file, key);
+                done = !pa_database_next(u->database, &key, &next_key, NULL);
 
-                name = pa_xstrndup(key.dptr, (size_t) key.dsize);
-                pa_xfree(key.dptr);
+                name = pa_xstrndup(key.data, key.size);
+                pa_datum_free(&key);
 
                 if ((e = read_entry(u, name))) {
                     pa_cvolume r;
@@ -669,16 +654,15 @@ static int extension_cb(pa_native_protocol *p, pa_module *m, pa_native_connectio
                 goto fail;
 
             if (mode == PA_UPDATE_SET)
-                clear_db(u);
+                pa_database_clear(u->database);
 
             while (!pa_tagstruct_eof(t)) {
                 const char *name, *device;
                 pa_bool_t muted;
                 struct entry entry;
-                datum key, data;
-                int k;
+                pa_datum key, data;
 
-                memset(&entry, 0, sizeof(entry));
+                pa_zero(entry);
                 entry.version = ENTRY_VERSION;
 
                 if (pa_tagstruct_gets(t, &name) < 0 ||
@@ -708,13 +692,13 @@ static int extension_cb(pa_native_protocol *p, pa_module *m, pa_native_connectio
                     !pa_namereg_is_valid_name(entry.device))
                     goto fail;
 
-                key.dptr = (void*) name;
-                key.dsize = (int) strlen(name);
+                key.data = (char*) name;
+                key.size = strlen(name);
 
-                data.dptr = (void*) &entry;
-                data.dsize = sizeof(entry);
+                data.data = &entry;
+                data.size = sizeof(entry);
 
-                if ((k = gdbm_store(u->gdbm_file, key, data, mode == PA_UPDATE_REPLACE ? GDBM_REPLACE : GDBM_INSERT)) == 0)
+                if (pa_database_set(u->database, &key, &data, mode == PA_UPDATE_REPLACE) == 0)
                     if (apply_immediately)
                         apply_entry(u, name, &entry);
             }
@@ -728,15 +712,15 @@ static int extension_cb(pa_native_protocol *p, pa_module *m, pa_native_connectio
 
             while (!pa_tagstruct_eof(t)) {
                 const char *name;
-                datum key;
+                pa_datum key;
 
                 if (pa_tagstruct_gets(t, &name) < 0)
                     goto fail;
 
-                key.dptr = (void*) name;
-                key.dsize = (int) strlen(name);
+                key.data = (char*) name;
+                key.size = strlen(name);
 
-                gdbm_delete(u->gdbm_file, key);
+                pa_database_unset(u->database, &key);
             }
 
             trigger_save(u);
@@ -786,12 +770,11 @@ static pa_hook_result_t connection_unlink_hook_cb(pa_native_protocol *p, pa_nati
 int pa__init(pa_module*m) {
     pa_modargs *ma = NULL;
     struct userdata *u;
-    char *fname, *fn;
+    char *fname;
     pa_sink_input *si;
     pa_source_output *so;
     uint32_t idx;
     pa_bool_t restore_device = TRUE, restore_volume = TRUE, restore_muted = TRUE;
-    int gdbm_cache_size;
 
     pa_assert(m);
 
@@ -817,7 +800,7 @@ int pa__init(pa_module*m) {
     u->restore_device = restore_device;
     u->restore_volume = restore_volume;
     u->restore_muted = restore_muted;
-    u->gdbm_file = NULL;
+    u->database = NULL;
     u->subscribed = pa_idxset_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func);
 
     u->protocol = pa_native_protocol_get(m->core);
@@ -835,27 +818,18 @@ int pa__init(pa_module*m) {
     if (restore_volume || restore_muted)
         u->sink_input_fixate_hook_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_INPUT_FIXATE], PA_HOOK_EARLY, (pa_hook_cb_t) sink_input_fixate_hook_callback, u);
 
-    /* We include the host identifier in the file name because gdbm
-     * files are CPU dependant, and we don't want things to go wrong
-     * if we are on a multiarch system. */
 
-    fn = pa_sprintf_malloc("stream-volumes."CANONICAL_HOST".gdbm");
-    fname = pa_state_path(fn, TRUE);
-    pa_xfree(fn);
+    fname = pa_state_path("stream-volumes", TRUE);
 
     if (!fname)
         goto fail;
 
-    if (!(u->gdbm_file = gdbm_open(fname, 0, GDBM_WRCREAT|GDBM_NOLOCK, 0600, NULL))) {
-        pa_log("Failed to open volume database '%s': %s", fname, gdbm_strerror(gdbm_errno));
+    if (!(u->database = pa_database_open(fname, TRUE))) {
+        pa_log("Failed to open volume database '%s': %s", fname, pa_cstrerror(errno));
         pa_xfree(fname);
         goto fail;
     }
 
-    /* By default the cache of gdbm is rather large, let's reduce it a bit to save memory */
-    gdbm_cache_size = 10;
-    gdbm_setopt(u->gdbm_file, GDBM_CACHESIZE, &gdbm_cache_size, sizeof(gdbm_cache_size));
-
     pa_log_info("Sucessfully opened database file '%s'.", fname);
     pa_xfree(fname);
 
@@ -901,8 +875,8 @@ void pa__done(pa_module*m) {
     if (u->save_time_event)
         u->core->mainloop->time_free(u->save_time_event);
 
-    if (u->gdbm_file)
-        gdbm_close(u->gdbm_file);
+    if (u->database)
+        pa_database_close(u->database);
 
     if (u->protocol) {
         pa_native_protocol_remove_ext(u->protocol, m);

commit 0cb383717e1e65847f3ede7f3c904caff9129c93
Author: Lennart Poettering <lennart at poettering.net>
Date:   Thu May 14 01:25:07 2009 +0200

    alsa: be a bit more verbose when a hwparam call fails

diff --git a/src/modules/alsa/alsa-util.c b/src/modules/alsa/alsa-util.c
index 17c7c80..c03866c 100644
--- a/src/modules/alsa/alsa-util.c
+++ b/src/modules/alsa/alsa-util.c
@@ -272,6 +272,11 @@ static int set_format(snd_pcm_t *pcm_handle, snd_pcm_hw_params_t *hwparams, pa_s
     if ((ret = snd_pcm_hw_params_set_format(pcm_handle, hwparams, format_trans[*f])) >= 0)
         return ret;
 
+    pa_log_debug("snd_pcm_hw_params_set_format(%s) failed: %s",
+                 snd_pcm_format_description(format_trans[*f]),
+                 pa_alsa_strerror(ret));
+
+
     if (*f == PA_SAMPLE_FLOAT32BE)
         *f = PA_SAMPLE_FLOAT32LE;
     else if (*f == PA_SAMPLE_FLOAT32LE)
@@ -298,6 +303,10 @@ static int set_format(snd_pcm_t *pcm_handle, snd_pcm_hw_params_t *hwparams, pa_s
     if ((ret = snd_pcm_hw_params_set_format(pcm_handle, hwparams, format_trans[*f])) >= 0)
         return ret;
 
+    pa_log_debug("snd_pcm_hw_params_set_format(%s) failed: %s",
+                 snd_pcm_format_description(format_trans[*f]),
+                 pa_alsa_strerror(ret));
+
 try_auto:
 
     for (i = 0; try_order[i] != PA_SAMPLE_INVALID; i++) {
@@ -305,6 +314,10 @@ try_auto:
 
         if ((ret = snd_pcm_hw_params_set_format(pcm_handle, hwparams, format_trans[*f])) >= 0)
             return ret;
+
+        pa_log_debug("snd_pcm_hw_params_set_format(%s) failed: %s",
+                     snd_pcm_format_description(format_trans[*f]),
+                     pa_alsa_strerror(ret));
     }
 
     return -1;
@@ -338,11 +351,15 @@ int pa_alsa_set_hw_params(
 
     snd_pcm_hw_params_alloca(&hwparams);
 
-    if ((ret = snd_pcm_hw_params_any(pcm_handle, hwparams)) < 0)
+    if ((ret = snd_pcm_hw_params_any(pcm_handle, hwparams)) < 0) {
+        pa_log_debug("snd_pcm_hw_params_any() failed: %s", pa_alsa_strerror(ret));
         goto finish;
+    }
 
-    if ((ret = snd_pcm_hw_params_set_rate_resample(pcm_handle, hwparams, 0)) < 0)
+    if ((ret = snd_pcm_hw_params_set_rate_resample(pcm_handle, hwparams, 0)) < 0) {
+        pa_log_debug("snd_pcm_hw_params_set_rate_resample() failed: %s", pa_alsa_strerror(ret));
         goto finish;
+    }
 
     if (_use_mmap) {
 
@@ -350,14 +367,18 @@ int pa_alsa_set_hw_params(
 
             /* mmap() didn't work, fall back to interleaved */
 
-            if ((ret = snd_pcm_hw_params_set_access(pcm_handle, hwparams, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0)
+            if ((ret = snd_pcm_hw_params_set_access(pcm_handle, hwparams, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0) {
+                pa_log_debug("snd_pcm_hw_params_set_access() failed: %s", pa_alsa_strerror(ret));
                 goto finish;
+            }
 
             _use_mmap = FALSE;
         }
 
-    } else if ((ret = snd_pcm_hw_params_set_access(pcm_handle, hwparams, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0)
+    } else if ((ret = snd_pcm_hw_params_set_access(pcm_handle, hwparams, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0) {
+        pa_log_debug("snd_pcm_hw_params_set_access() failed: %s", pa_alsa_strerror(ret));
         goto finish;
+    }
 
     if (!_use_mmap)
         _use_tsched = FALSE;
@@ -365,19 +386,27 @@ int pa_alsa_set_hw_params(
     if ((ret = set_format(pcm_handle, hwparams, &f)) < 0)
         goto finish;
 
-    if ((ret = snd_pcm_hw_params_set_rate_near(pcm_handle, hwparams, &r, NULL)) < 0)
+    if ((ret = snd_pcm_hw_params_set_rate_near(pcm_handle, hwparams, &r, NULL)) < 0) {
+        pa_log_debug("snd_pcm_hw_params_set_rate_near() failed: %s", pa_alsa_strerror(ret));
         goto finish;
+    }
 
     if (require_exact_channel_number) {
-        if ((ret = snd_pcm_hw_params_set_channels(pcm_handle, hwparams, c)) < 0)
+        if ((ret = snd_pcm_hw_params_set_channels(pcm_handle, hwparams, c)) < 0) {
+            pa_log_debug("snd_pcm_hw_params_set_channels() failed: %s", pa_alsa_strerror(ret));
             goto finish;
+        }
     } else {
-        if ((ret = snd_pcm_hw_params_set_channels_near(pcm_handle, hwparams, &c)) < 0)
+        if ((ret = snd_pcm_hw_params_set_channels_near(pcm_handle, hwparams, &c)) < 0) {
+            pa_log_debug("snd_pcm_hw_params_set_channels_near() failed: %s", pa_alsa_strerror(ret));
             goto finish;
+        }
     }
 
-    if ((ret = snd_pcm_hw_params_set_periods_integer(pcm_handle, hwparams)) < 0)
+    if ((ret = snd_pcm_hw_params_set_periods_integer(pcm_handle, hwparams)) < 0) {
+        pa_log_debug("snd_pcm_hw_params_set_periods_integer() failed: %s", pa_alsa_strerror(ret));
         goto finish;
+    }
 
     if (_period_size && tsched_size && _periods) {
 

-- 
hooks/post-receive
PulseAudio Sound Server



More information about the pulseaudio-commits mailing list