[pulseaudio-commits] r1630 - in /branches/lennart/src/daemon: daemon-conf.c daemon-conf.h daemon.conf.in main.c
svnmailer-noreply at 0pointer.de
svnmailer-noreply at 0pointer.de
Sat Aug 11 08:56:57 PDT 2007
Author: lennart
Date: Sat Aug 11 17:56:57 2007
New Revision: 1630
URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=3D1630&root=3Dpulseaudio&vi=
ew=3Drev
Log:
allow setting the default sample and fragment settings from the config file
Modified:
branches/lennart/src/daemon/daemon-conf.c
branches/lennart/src/daemon/daemon-conf.h
branches/lennart/src/daemon/daemon.conf.in
branches/lennart/src/daemon/main.c
Modified: branches/lennart/src/daemon/daemon-conf.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/daemon/dae=
mon-conf.c?rev=3D1630&root=3Dpulseaudio&r1=3D1629&r2=3D1630&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/lennart/src/daemon/daemon-conf.c (original)
+++ branches/lennart/src/daemon/daemon-conf.c Sat Aug 11 17:56:57 2007
@@ -29,7 +29,6 @@
#include <errno.h>
#include <stdio.h>
#include <string.h>
-#include <assert.h>
#include <unistd.h>
=
#include <pulse/xmalloc.h>
@@ -39,6 +38,7 @@
#include <pulsecore/strbuf.h>
#include <pulsecore/conf-parser.h>
#include <pulsecore/resampler.h>
+#include <pulsecore/macro.h>
=
#include "daemon-conf.h"
=
@@ -77,7 +77,10 @@
.use_pid_file =3D 1,
.system_instance =3D 0,
.no_cpu_limit =3D 0,
- .disable_shm =3D 0
+ .disable_shm =3D 0,
+ .default_n_fragments =3D 4,
+ .default_fragment_size_msec =3D 25,
+ .default_sample_spec =3D { .format =3D PA_SAMPLE_S16NE, .rate =3D 4410=
0, .channels =3D 2 }
#ifdef HAVE_SYS_RESOURCE_H
, .rlimit_as =3D { .value =3D 0, .is_set =3D 0 },
.rlimit_core =3D { .value =3D 0, .is_set =3D 0 },
@@ -96,7 +99,7 @@
=
pa_daemon_conf* pa_daemon_conf_new(void) {
FILE *f;
- pa_daemon_conf *c =3D pa_xmemdup(&default_conf, sizeof(default_conf));
+ pa_daemon_conf *c =3D pa_xnewdup(pa_daemon_conf, &default_conf, 1);
=
if ((f =3D pa_open_config_file(DEFAULT_SCRIPT_FILE, DEFAULT_SCRIPT_FIL=
E_USER, ENV_SCRIPT_FILE, &c->default_script_file, "r")))
fclose(f);
@@ -106,7 +109,7 @@
}
=
void pa_daemon_conf_free(pa_daemon_conf *c) {
- assert(c);
+ pa_assert(c);
pa_xfree(c->script_commands);
pa_xfree(c->dl_search_path);
pa_xfree(c->default_script_file);
@@ -115,7 +118,8 @@
}
=
int pa_daemon_conf_set_log_target(pa_daemon_conf *c, const char *string) {
- assert(c && string);
+ pa_assert(c);
+ pa_assert(string);
=
if (!strcmp(string, "auto"))
c->auto_log_target =3D 1;
@@ -133,7 +137,8 @@
=
int pa_daemon_conf_set_log_level(pa_daemon_conf *c, const char *string) {
uint32_t u;
- assert(c && string);
+ pa_assert(c);
+ pa_assert(string);
=
if (pa_atou(string, &u) >=3D 0) {
if (u >=3D PA_LOG_LEVEL_MAX)
@@ -158,7 +163,8 @@
=
int pa_daemon_conf_set_resample_method(pa_daemon_conf *c, const char *stri=
ng) {
int m;
- assert(c && string);
+ pa_assert(c);
+ pa_assert(string);
=
if ((m =3D pa_parse_resample_method(string)) < 0)
return -1;
@@ -169,7 +175,11 @@
=
static int parse_log_target(const char *filename, unsigned line, const cha=
r *lvalue, const char *rvalue, void *data, PA_GCC_UNUSED void *userdata) {
pa_daemon_conf *c =3D data;
- assert(filename && lvalue && rvalue && data);
+
+ pa_assert(filename);
+ pa_assert(lvalue);
+ pa_assert(rvalue);
+ pa_assert(data);
=
if (pa_daemon_conf_set_log_target(c, rvalue) < 0) {
pa_log("[%s:%u] Invalid log target '%s'.", filename, line, rvalue);
@@ -181,7 +191,11 @@
=
static int parse_log_level(const char *filename, unsigned line, const char=
*lvalue, const char *rvalue, void *data, PA_GCC_UNUSED void *userdata) {
pa_daemon_conf *c =3D data;
- assert(filename && lvalue && rvalue && data);
+ =
+ pa_assert(filename);
+ pa_assert(lvalue);
+ pa_assert(rvalue);
+ pa_assert(data);
=
if (pa_daemon_conf_set_log_level(c, rvalue) < 0) {
pa_log("[%s:%u] Invalid log level '%s'.", filename, line, rvalue);
@@ -193,10 +207,14 @@
=
static int parse_resample_method(const char *filename, unsigned line, cons=
t char *lvalue, const char *rvalue, void *data, PA_GCC_UNUSED void *userdat=
a) {
pa_daemon_conf *c =3D data;
- assert(filename && lvalue && rvalue && data);
+
+ pa_assert(filename);
+ pa_assert(lvalue);
+ pa_assert(rvalue);
+ pa_assert(data);
=
if (pa_daemon_conf_set_resample_method(c, rvalue) < 0) {
- pa_log("[%s:%u] Inavalid resample method '%s'.", filename, line, r=
value);
+ pa_log("[%s:%u] Invalid resample method '%s'.", filename, line, rv=
alue);
return -1;
}
=
@@ -206,10 +224,11 @@
static int parse_rlimit(const char *filename, unsigned line, const char *l=
value, const char *rvalue, void *data, PA_GCC_UNUSED void *userdata) {
#ifdef HAVE_SYS_RESOURCE_H
struct pa_rlimit *r =3D data;
- assert(filename);
- assert(lvalue);
- assert(rvalue);
- assert(r);
+
+ pa_assert(filename);
+ pa_assert(lvalue);
+ pa_assert(rvalue);
+ pa_assert(r);
=
if (rvalue[strspn(rvalue, "\t ")] =3D=3D 0) {
/* Empty string */
@@ -218,7 +237,7 @@
} else {
int32_t k;
if (pa_atoi(rvalue, &k) < 0) {
- pa_log("[%s:%u] Inavalid rlimit '%s'.", filename, line, rvalue=
);
+ pa_log("[%s:%u] Invalid rlimit '%s'.", filename, line, rvalue);
return -1;
}
r->is_set =3D k >=3D 0;
@@ -231,43 +250,138 @@
return 0;
}
=
+static int parse_sample_format(const char *filename, unsigned line, const =
char *lvalue, const char *rvalue, void *data, PA_GCC_UNUSED void *userdata)=
{
+ pa_daemon_conf *c =3D data;
+ pa_sample_format_t f;
+
+ pa_assert(filename);
+ pa_assert(lvalue);
+ pa_assert(rvalue);
+ pa_assert(data);
+
+ if ((f =3D pa_parse_sample_format(rvalue)) < 0) {
+ pa_log("[%s:%u] Invalid sample format '%s'.", filename, line, rval=
ue);
+ return -1;
+ }
+
+ c->default_sample_spec.format =3D f;
+ return 0;
+}
+
+static int parse_sample_rate(const char *filename, unsigned line, const ch=
ar *lvalue, const char *rvalue, void *data, PA_GCC_UNUSED void *userdata) {
+ pa_daemon_conf *c =3D data;
+ int32_t r;
+
+ pa_assert(filename);
+ pa_assert(lvalue);
+ pa_assert(rvalue);
+ pa_assert(data);
+
+ if (pa_atoi(rvalue, &r) < 0 || r > PA_RATE_MAX || r <=3D 0) {
+ pa_log("[%s:%u] Invalid sample rate '%s'.", filename, line, rvalue=
);
+ return -1;
+ }
+
+ c->default_sample_spec.rate =3D r;
+ return 0;
+}
+
+static int parse_sample_channels(const char *filename, unsigned line, cons=
t char *lvalue, const char *rvalue, void *data, PA_GCC_UNUSED void *userdat=
a) {
+ pa_daemon_conf *c =3D data;
+ int32_t n;
+
+ pa_assert(filename);
+ pa_assert(lvalue);
+ pa_assert(rvalue);
+ pa_assert(data);
+
+ if (pa_atoi(rvalue, &n) < 0 || n > PA_CHANNELS_MAX || n <=3D 0) {
+ pa_log("[%s:%u] Invalid sample channels '%s'.", filename, line, rv=
alue);
+ return -1;
+ }
+ =
+ c->default_sample_spec.channels =3D (uint8_t) n;
+ return 0;
+}
+
+static int parse_fragments(const char *filename, unsigned line, const char=
*lvalue, const char *rvalue, void *data, PA_GCC_UNUSED void *userdata) {
+ pa_daemon_conf *c =3D data;
+ int32_t n;
+
+ pa_assert(filename);
+ pa_assert(lvalue);
+ pa_assert(rvalue);
+ pa_assert(data);
+
+ if (pa_atoi(rvalue, &n) < 0 || n < 2) {
+ pa_log("[%s:%u] Invalid number of fragments '%s'.", filename, line=
, rvalue);
+ return -1;
+ }
+
+ c->default_n_fragments =3D (unsigned) n;
+ return 0;
+}
+
+static int parse_fragment_size_msec(const char *filename, unsigned line, c=
onst char *lvalue, const char *rvalue, void *data, PA_GCC_UNUSED void *user=
data) {
+ pa_daemon_conf *c =3D data;
+ int32_t n;
+
+ pa_assert(filename);
+ pa_assert(lvalue);
+ pa_assert(rvalue);
+ pa_assert(data);
+
+ if (pa_atoi(rvalue, &n) < 0 || n < 1) {
+ pa_log("[%s:%u] Invalid fragment size '%s'.", filename, line, rval=
ue);
+ return -1;
+ }
+
+ c->default_fragment_size_msec =3D (unsigned) n;
+ return 0;
+}
+
int pa_daemon_conf_load(pa_daemon_conf *c, const char *filename) {
int r =3D -1;
FILE *f =3D NULL;
=
pa_config_item table[] =3D {
- { "daemonize", pa_config_parse_bool, NULL },
- { "fail", pa_config_parse_bool, NULL },
- { "high-priority", pa_config_parse_bool, NULL },
- { "disallow-module-loading", pa_config_parse_bool, NULL },
- { "exit-idle-time", pa_config_parse_int, NULL },
- { "module-idle-time", pa_config_parse_int, NULL },
- { "scache-idle-time", pa_config_parse_int, NULL },
- { "dl-search-path", pa_config_parse_string, NULL },
- { "default-script-file", pa_config_parse_string, NULL },
- { "log-target", parse_log_target, NULL },
- { "log-level", parse_log_level, NULL },
- { "verbose", parse_log_level, NULL },
- { "resample-method", parse_resample_method, NULL },
- { "use-pid-file", pa_config_parse_bool, NULL },
- { "system-instance", pa_config_parse_bool, NULL },
- { "no-cpu-limit", pa_config_parse_bool, NULL },
- { "disable-shm", pa_config_parse_bool, NULL },
+ { "daemonize", pa_config_parse_bool, NULL },
+ { "fail", pa_config_parse_bool, NULL },
+ { "high-priority", pa_config_parse_bool, NULL },
+ { "disallow-module-loading", pa_config_parse_bool, NULL },
+ { "exit-idle-time", pa_config_parse_int, NULL },
+ { "module-idle-time", pa_config_parse_int, NULL },
+ { "scache-idle-time", pa_config_parse_int, NULL },
+ { "dl-search-path", pa_config_parse_string, NULL },
+ { "default-script-file", pa_config_parse_string, NULL },
+ { "log-target", parse_log_target, NULL },
+ { "log-level", parse_log_level, NULL },
+ { "verbose", parse_log_level, NULL },
+ { "resample-method", parse_resample_method, NULL },
+ { "use-pid-file", pa_config_parse_bool, NULL },
+ { "system-instance", pa_config_parse_bool, NULL },
+ { "no-cpu-limit", pa_config_parse_bool, NULL },
+ { "disable-shm", pa_config_parse_bool, NULL },
+ { "default-sample-format", parse_sample_format, NULL },
+ { "default-sample-rate", parse_sample_rate, NULL },
+ { "default-sample-channels", parse_sample_channels, NULL },
+ { "default-fragments", parse_fragments, NULL },
+ { "default-fragment-size-msec", parse_fragment_size_msec, NULL }, =
#ifdef HAVE_SYS_RESOURCE_H
- { "rlimit-as", parse_rlimit, NULL },
- { "rlimit-core", parse_rlimit, NULL },
- { "rlimit-data", parse_rlimit, NULL },
- { "rlimit-fsize", parse_rlimit, NULL },
- { "rlimit-nofile", parse_rlimit, NULL },
- { "rlimit-stack", parse_rlimit, NULL },
+ { "rlimit-as", parse_rlimit, NULL },
+ { "rlimit-core", parse_rlimit, NULL },
+ { "rlimit-data", parse_rlimit, NULL },
+ { "rlimit-fsize", parse_rlimit, NULL },
+ { "rlimit-nofile", parse_rlimit, NULL },
+ { "rlimit-stack", parse_rlimit, NULL },
#ifdef RLIMIT_NPROC
- { "rlimit-nproc", parse_rlimit, NULL },
+ { "rlimit-nproc", parse_rlimit, NULL },
#endif
#ifdef RLIMIT_MEMLOCK
- { "rlimit-memlock", parse_rlimit, NULL },
-#endif
-#endif
- { NULL, NULL, NULL },
+ { "rlimit-memlock", parse_rlimit, NULL },
+#endif
+#endif
+ { NULL, NULL, NULL },
};
=
table[0].data =3D &c->daemonize;
@@ -287,24 +401,28 @@
table[14].data =3D &c->system_instance;
table[15].data =3D &c->no_cpu_limit;
table[16].data =3D &c->disable_shm;
+ table[17].data =3D c;
+ table[18].data =3D c;
+ table[19].data =3D c;
+ table[20].data =3D c;
+ table[21].data =3D c;
#ifdef HAVE_SYS_RESOURCE_H
- table[17].data =3D &c->rlimit_as;
- table[18].data =3D &c->rlimit_core;
- table[19].data =3D &c->rlimit_data;
- table[20].data =3D &c->rlimit_fsize;
- table[21].data =3D &c->rlimit_nofile;
- table[22].data =3D &c->rlimit_stack;
+ table[22].data =3D &c->rlimit_as;
+ table[23].data =3D &c->rlimit_core;
+ table[24].data =3D &c->rlimit_data;
+ table[25].data =3D &c->rlimit_fsize;
+ table[26].data =3D &c->rlimit_nofile;
+ table[27].data =3D &c->rlimit_stack;
#ifdef RLIMIT_NPROC
- table[23].data =3D &c->rlimit_nproc;
+ table[28].data =3D &c->rlimit_nproc;
#endif
#ifdef RLIMIT_MEMLOCK
#ifndef RLIMIT_NPROC
#error "Houston, we have a numbering problem!"
#endif
- table[24].data =3D &c->rlimit_memlock;
-#endif
-#endif
-
+ table[29].data =3D &c->rlimit_memlock;
+#endif
+#endif
=
pa_xfree(c->config_file);
c->config_file =3D NULL;
@@ -351,12 +469,16 @@
};
=
char *pa_daemon_conf_dump(pa_daemon_conf *c) {
- pa_strbuf *s =3D pa_strbuf_new();
+ pa_strbuf *s;
+
+ pa_assert(c);
+
+ s =3D pa_strbuf_new();
=
if (c->config_file)
pa_strbuf_printf(s, "### Read from configuration file: %s ###\n", =
c->config_file);
=
- assert(c->log_level <=3D PA_LOG_LEVEL_MAX);
+ pa_assert(c->log_level <=3D PA_LOG_LEVEL_MAX);
=
pa_strbuf_printf(s, "daemonize =3D %i\n", !!c->daemonize);
pa_strbuf_printf(s, "fail =3D %i\n", !!c->fail);
@@ -373,7 +495,12 @@
pa_strbuf_printf(s, "use-pid-file =3D %i\n", c->use_pid_file);
pa_strbuf_printf(s, "system-instance =3D %i\n", !!c->system_instance);
pa_strbuf_printf(s, "no-cpu-limit =3D %i\n", !!c->no_cpu_limit);
- pa_strbuf_printf(s, "disable_shm =3D %i\n", !!c->disable_shm);
+ pa_strbuf_printf(s, "disable-shm =3D %i\n", !!c->disable_shm);
+ pa_strbuf_printf(s, "default-sample-format =3D %s\n", pa_sample_format=
_to_string(c->default_sample_spec.format));
+ pa_strbuf_printf(s, "default-sample-rate =3D %u\n", c->default_sample_=
spec.rate);
+ pa_strbuf_printf(s, "default-sample-channels =3D %u\n", c->default_sam=
ple_spec.channels);
+ pa_strbuf_printf(s, "default-fragments =3D %u\n", c->default_n_fragmen=
ts);
+ pa_strbuf_printf(s, "default-fragment-size-msec =3D %u\n", c->default_=
fragment_size_msec);
#ifdef HAVE_SYS_RESOURCE_H
pa_strbuf_printf(s, "rlimit-as =3D %li\n", c->rlimit_as.is_set ? (long=
int) c->rlimit_as.value : -1);
pa_strbuf_printf(s, "rlimit-core =3D %li\n", c->rlimit_core.is_set ? (=
long int) c->rlimit_core.value : -1);
Modified: branches/lennart/src/daemon/daemon-conf.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/daemon/dae=
mon-conf.h?rev=3D1630&root=3Dpulseaudio&r1=3D1629&r2=3D1630&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/lennart/src/daemon/daemon-conf.h (original)
+++ branches/lennart/src/daemon/daemon-conf.h Sat Aug 11 17:56:57 2007
@@ -26,6 +26,7 @@
***/
=
#include <pulsecore/log.h>
+#include <pulse/sample.h>
=
#ifdef HAVE_SYS_RESOURCE_H
#include <sys/resource.h>
@@ -80,6 +81,8 @@
#endif
#endif
=
+ unsigned default_n_fragments, default_fragment_size_msec;
+ pa_sample_spec default_sample_spec;
} pa_daemon_conf;
=
/* Allocate a new structure and fill it with sane defaults */
Modified: branches/lennart/src/daemon/daemon.conf.in
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/daemon/dae=
mon.conf.in?rev=3D1630&root=3Dpulseaudio&r1=3D1629&r2=3D1630&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/lennart/src/daemon/daemon.conf.in (original)
+++ branches/lennart/src/daemon/daemon.conf.in Sat Aug 11 17:56:57 2007
@@ -99,3 +99,12 @@
=
## Disable shared memory data transfer =
; disable-shm =3D 0
+
+## Default sample format
+; default-sample-format =3D s16le
+; default-sample-rate =3D 44100
+; default-sample-channels =3D 2
+
+## Default fragment settings, for device drivers that need this
+; default-fragments =3D 4
+; default-fragment-size-msec =3D 25
Modified: branches/lennart/src/daemon/main.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/daemon/mai=
n.c?rev=3D1630&root=3Dpulseaudio&r1=3D1629&r2=3D1630&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/lennart/src/daemon/main.c (original)
+++ branches/lennart/src/daemon/main.c Sat Aug 11 17:56:57 2007
@@ -573,6 +573,9 @@
}
=
c->is_system_instance =3D !!conf->system_instance;
+ c->default_sample_spec =3D conf->default_sample_spec;
+ c->default_n_fragments =3D conf->default_n_fragments;
+ c->default_fragment_size_msec =3D conf->default_fragment_size_msec;
=
r =3D pa_signal_init(pa_mainloop_get_api(mainloop));
assert(r =3D=3D 0);
More information about the pulseaudio-commits
mailing list