]> code.delx.au - pulseaudio/blobdiff - src/daemon/daemon-conf.c
Move compile-time checks around pa_run_from_build_tree to core-util
[pulseaudio] / src / daemon / daemon-conf.c
index bfd5c118de91384b3acd9f8dd52f92ea5bca103f..2872c74556a2266d2c10d4afa8842e1f48ac9ff3 100644 (file)
 #include <stdio.h>
 #include <string.h>
 #include <unistd.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+
+#ifdef HAVE_SCHED_H
 #include <sched.h>
+#endif
 
 #include <pulse/xmalloc.h>
 #include <pulse/timeval.h>
 #include <pulse/i18n.h>
+#include <pulse/version.h>
 
 #include <pulsecore/core-error.h>
 #include <pulsecore/core-util.h>
@@ -89,8 +95,11 @@ static const pa_daemon_conf default_conf = {
     .no_cpu_limit = TRUE,
     .disable_shm = FALSE,
     .lock_memory = FALSE,
+    .sync_volume = TRUE,
     .default_n_fragments = 4,
     .default_fragment_size_msec = 25,
+    .sync_volume_safety_margin_usec = 8000,
+    .sync_volume_extra_delay_usec = 0,
     .default_sample_spec = { .format = PA_SAMPLE_S16NE, .rate = 44100, .channels = 2 },
     .default_channel_map = { .channels = 2, .map = { PA_CHANNEL_POSITION_LEFT, PA_CHANNEL_POSITION_RIGHT } },
     .shm_size = 0
@@ -135,31 +144,30 @@ static const pa_daemon_conf default_conf = {
 #endif
 };
 
-pa_daemon_confpa_daemon_conf_new(void) {
+pa_daemon_conf *pa_daemon_conf_new(void) {
     pa_daemon_conf *c;
 
     c = pa_xnewdup(pa_daemon_conf, &default_conf, 1);
 
-#if defined(__linux__) && !defined(__OPTIMIZE__)
-
-    /* We abuse __OPTIMIZE__ as a check whether we are a debug build
-     * or not. If we are and are run from the build tree then we
-     * override the search path to point to our build tree */
-
+#ifdef OS_IS_WIN32
+    c->dl_search_path = pa_sprintf_malloc("%s" PA_PATH_SEP "lib" PA_PATH_SEP "pulse-%d.%d" PA_PATH_SEP "modules",
+                                          pa_win32_get_toplevel(NULL), PA_MAJOR, PA_MINOR);
+#else
     if (pa_run_from_build_tree()) {
         pa_log_notice("Detected that we are run from the build tree, fixing search path.");
         c->dl_search_path = pa_xstrdup(PA_BUILDDIR "/.libs/");
-
     } else
-
-#endif
         c->dl_search_path = pa_xstrdup(PA_DLSEARCHPATH);
+#endif
 
     return c;
 }
 
 void pa_daemon_conf_free(pa_daemon_conf *c) {
     pa_assert(c);
+
+    pa_log_set_fd(-1);
+
     pa_xfree(c->script_commands);
     pa_xfree(c->dl_search_path);
     pa_xfree(c->default_script_file);
@@ -205,6 +213,23 @@ int pa_daemon_conf_set_log_level(pa_daemon_conf *c, const char *string) {
         c->log_level = PA_LOG_WARN;
     else if (pa_startswith(string, "err"))
         c->log_level = PA_LOG_ERROR;
+    else if (pa_startswith(string, "file:")) {
+        char file_path[512];
+        int log_fd;
+
+        pa_strlcpy(file_path, string + 5, sizeof(file_path));
+
+        /* Open target file with user rights */
+        if ((log_fd = open(file_path, O_RDWR|O_TRUNC|O_CREAT, S_IRWXU)) >= 0) {
+             c->auto_log_target = 0;
+             c->log_target = PA_LOG_FD;
+             pa_log_set_fd(log_fd);
+        }
+        else {
+            printf("Failed to open target file %s, error : %s\n", file_path, pa_cstrerror(errno));
+            return -1;
+        }
+    }
     else
         return -1;
 
@@ -287,8 +312,8 @@ static int parse_resample_method(const char *filename, unsigned line, const char
     return 0;
 }
 
-static int parse_rlimit(const char *filename, unsigned line, const char *section, const char *lvalue, const char *rvalue, void *data, void *userdata) {
 #ifdef HAVE_SYS_RESOURCE_H
+static int parse_rlimit(const char *filename, unsigned line, const char *section, const char *lvalue, const char *rvalue, void *data, void *userdata) {
     struct pa_rlimit *r = data;
 
     pa_assert(filename);
@@ -309,12 +334,10 @@ static int parse_rlimit(const char *filename, unsigned line, const char *section
         r->is_set = k >= 0;
         r->value = k >= 0 ? (rlim_t) k : 0;
     }
-#else
-    pa_log_warn(_("[%s:%u] rlimit not supported on this platform."), filename, line);
-#endif
 
     return 0;
 }
+#endif
 
 static int parse_sample_format(const char *filename, unsigned line, const char *section, const char *lvalue, const char *rvalue, void *data, void *userdata) {
     pa_daemon_conf *c = data;
@@ -457,15 +480,18 @@ static int parse_rtprio(const char *filename, unsigned line, const char *section
     pa_assert(rvalue);
     pa_assert(data);
 
+#ifdef HAVE_SCHED_H
     if (pa_atoi(rvalue, &rtprio) < 0 || rtprio < sched_get_priority_min(SCHED_FIFO) || rtprio > sched_get_priority_max(SCHED_FIFO)) {
         pa_log("[%s:%u] Invalid realtime priority '%s'.", filename, line, rvalue);
         return -1;
     }
+#endif
 
     c->realtime_priority = (int) rtprio;
     return 0;
 }
 
+#ifdef HAVE_DBUS
 static int parse_server_type(const char *filename, unsigned line, const char *section, const char *lvalue, const char *rvalue, void *data, void *userdata) {
     pa_daemon_conf *c = data;
 
@@ -481,6 +507,7 @@ static int parse_server_type(const char *filename, unsigned line, const char *se
 
     return 0;
 }
+#endif
 
 int pa_daemon_conf_load(pa_daemon_conf *c, const char *filename) {
     int r = -1;
@@ -506,6 +533,7 @@ int pa_daemon_conf_load(pa_daemon_conf *c, const char *filename) {
         { "enable-shm",                 pa_config_parse_not_bool, &c->disable_shm, NULL },
         { "flat-volumes",               pa_config_parse_bool,     &c->flat_volumes, NULL },
         { "lock-memory",                pa_config_parse_bool,     &c->lock_memory, NULL },
+        { "enable-sync-volume",         pa_config_parse_bool,     &c->sync_volume, NULL },
         { "exit-idle-time",             pa_config_parse_int,      &c->exit_idle_time, NULL },
         { "scache-idle-time",           pa_config_parse_int,      &c->scache_idle_time, NULL },
         { "realtime-priority",          parse_rtprio,             c, NULL },
@@ -521,6 +549,8 @@ int pa_daemon_conf_load(pa_daemon_conf *c, const char *filename) {
         { "default-channel-map",        parse_channel_map,        &ci,  NULL },
         { "default-fragments",          parse_fragments,          c, NULL },
         { "default-fragment-size-msec", parse_fragment_size_msec, c, NULL },
+        { "sync-volume-safety-margin-usec", pa_config_parse_unsigned, &c->sync_volume_safety_margin_usec, NULL },
+        { "sync-volume-extra-delay-usec", pa_config_parse_int, &c->sync_volume_extra_delay_usec, NULL },
         { "nice-level",                 parse_nice_level,         c, NULL },
         { "disable-remixing",           pa_config_parse_bool,     &c->disable_remixing, NULL },
         { "enable-remixing",            pa_config_parse_not_bool, &c->disable_remixing, NULL },
@@ -666,12 +696,14 @@ char *pa_daemon_conf_dump(pa_daemon_conf *c) {
         [PA_LOG_ERROR] = "error"
     };
 
+#ifdef HAVE_DBUS
     static const char* const server_type_to_string[] = {
         [PA_SERVER_TYPE_UNSET] = "!!UNSET!!",
         [PA_SERVER_TYPE_USER] = "user",
         [PA_SERVER_TYPE_SYSTEM] = "system",
         [PA_SERVER_TYPE_NONE] = "none"
     };
+#endif
 
     pa_strbuf *s;
     char cm[PA_CHANNEL_MAP_SNPRINT_MAX];
@@ -702,6 +734,7 @@ char *pa_daemon_conf_dump(pa_daemon_conf *c) {
     pa_strbuf_printf(s, "enable-shm = %s\n", pa_yes_no(!c->disable_shm));
     pa_strbuf_printf(s, "flat-volumes = %s\n", pa_yes_no(c->flat_volumes));
     pa_strbuf_printf(s, "lock-memory = %s\n", pa_yes_no(c->lock_memory));
+    pa_strbuf_printf(s, "enable-sync-volume = %s\n", pa_yes_no(c->sync_volume));
     pa_strbuf_printf(s, "exit-idle-time = %i\n", c->exit_idle_time);
     pa_strbuf_printf(s, "scache-idle-time = %i\n", c->scache_idle_time);
     pa_strbuf_printf(s, "dl-search-path = %s\n", pa_strempty(c->dl_search_path));
@@ -718,6 +751,8 @@ char *pa_daemon_conf_dump(pa_daemon_conf *c) {
     pa_strbuf_printf(s, "default-channel-map = %s\n", pa_channel_map_snprint(cm, sizeof(cm), &c->default_channel_map));
     pa_strbuf_printf(s, "default-fragments = %u\n", c->default_n_fragments);
     pa_strbuf_printf(s, "default-fragment-size-msec = %u\n", c->default_fragment_size_msec);
+    pa_strbuf_printf(s, "sync-volume-safety-margin-usec = %u\n", c->sync_volume_safety_margin_usec);
+    pa_strbuf_printf(s, "sync-volume-extra-delay-usec = %d\n", c->sync_volume_extra_delay_usec);
     pa_strbuf_printf(s, "shm-size-bytes = %lu\n", (unsigned long) c->shm_size);
     pa_strbuf_printf(s, "log-meta = %s\n", pa_yes_no(c->log_meta));
     pa_strbuf_printf(s, "log-time = %s\n", pa_yes_no(c->log_time));