summaryrefslogtreecommitdiffstats
path: root/src/pulse
diff options
context:
space:
mode:
authorTanu Kaskinen <tanuk@iki.fi>2009-08-24 14:43:11 +0300
committerTanu Kaskinen <tanuk@iki.fi>2009-08-24 14:43:11 +0300
commit2f3fc2f1d6ba418303a4bab6f8fd3caed7d291b4 (patch)
tree00bccb466ce49367f6fd54fe9f7f90557eea8738 /src/pulse
parent3025645b0b58f476f6404f2aed3b61a633794d10 (diff)
parentbe46eaa5b6324d84c5ecbed5dd72dec1c87e0cb1 (diff)
Merge branch 'master' of git://0pointer.de/pulseaudio into dbus-work
Conflicts: src/Makefile.am
Diffstat (limited to 'src/pulse')
-rw-r--r--src/pulse/glib-mainloop.h4
-rw-r--r--src/pulse/mainloop.h4
-rw-r--r--src/pulse/sample.c49
-rw-r--r--src/pulse/thread-mainloop.h4
-rw-r--r--src/pulse/util.c52
5 files changed, 58 insertions, 55 deletions
diff --git a/src/pulse/glib-mainloop.h b/src/pulse/glib-mainloop.h
index 189513a8..67aba27d 100644
--- a/src/pulse/glib-mainloop.h
+++ b/src/pulse/glib-mainloop.h
@@ -56,7 +56,9 @@ pa_glib_mainloop *pa_glib_mainloop_new(GMainContext *c);
/** Free the GLIB main loop object */
void pa_glib_mainloop_free(pa_glib_mainloop* g);
-/** Return the abstract main loop API vtable for the GLIB main loop object */
+/** Return the abstract main loop API vtable for the GLIB main loop
+ object. No need of freeing the API as it is owned by the loop and
+ it is destroyed when this dies */
pa_mainloop_api* pa_glib_mainloop_get_api(pa_glib_mainloop *g);
PA_C_DECL_END
diff --git a/src/pulse/mainloop.h b/src/pulse/mainloop.h
index 4a83ebe8..63abd588 100644
--- a/src/pulse/mainloop.h
+++ b/src/pulse/mainloop.h
@@ -108,7 +108,9 @@ int pa_mainloop_iterate(pa_mainloop *m, int block, int *retval);
/** Run unlimited iterations of the main loop object until the main loop's quit() routine is called. */
int pa_mainloop_run(pa_mainloop *m, int *retval);
-/** Return the abstract main loop abstraction layer vtable for this main loop. */
+/** Return the abstract main loop abstraction layer vtable for this
+ main loop. No need of freeing the API as it is owned by the loop
+ and it is destroyed when this dies */
pa_mainloop_api* pa_mainloop_get_api(pa_mainloop*m);
/** Shutdown the main loop */
diff --git a/src/pulse/sample.c b/src/pulse/sample.c
index d5d38eda..9698d8a5 100644
--- a/src/pulse/sample.c
+++ b/src/pulse/sample.c
@@ -36,28 +36,27 @@
#include "sample.h"
-size_t pa_sample_size_of_format(pa_sample_format_t f) {
-
- static const size_t table[] = {
- [PA_SAMPLE_U8] = 1,
- [PA_SAMPLE_ULAW] = 1,
- [PA_SAMPLE_ALAW] = 1,
- [PA_SAMPLE_S16LE] = 2,
- [PA_SAMPLE_S16BE] = 2,
- [PA_SAMPLE_FLOAT32LE] = 4,
- [PA_SAMPLE_FLOAT32BE] = 4,
- [PA_SAMPLE_S32LE] = 4,
- [PA_SAMPLE_S32BE] = 4,
- [PA_SAMPLE_S24LE] = 3,
- [PA_SAMPLE_S24BE] = 3,
- [PA_SAMPLE_S24_32LE] = 4,
- [PA_SAMPLE_S24_32BE] = 4
- };
+static const size_t size_table[] = {
+ [PA_SAMPLE_U8] = 1,
+ [PA_SAMPLE_ULAW] = 1,
+ [PA_SAMPLE_ALAW] = 1,
+ [PA_SAMPLE_S16LE] = 2,
+ [PA_SAMPLE_S16BE] = 2,
+ [PA_SAMPLE_FLOAT32LE] = 4,
+ [PA_SAMPLE_FLOAT32BE] = 4,
+ [PA_SAMPLE_S32LE] = 4,
+ [PA_SAMPLE_S32BE] = 4,
+ [PA_SAMPLE_S24LE] = 3,
+ [PA_SAMPLE_S24BE] = 3,
+ [PA_SAMPLE_S24_32LE] = 4,
+ [PA_SAMPLE_S24_32BE] = 4
+};
+size_t pa_sample_size_of_format(pa_sample_format_t f) {
pa_assert(f >= 0);
pa_assert(f < PA_SAMPLE_MAX);
- return table[f];
+ return size_table[f];
}
size_t pa_sample_size(const pa_sample_spec *spec) {
@@ -65,35 +64,35 @@ size_t pa_sample_size(const pa_sample_spec *spec) {
pa_assert(spec);
pa_return_val_if_fail(pa_sample_spec_valid(spec), 0);
- return pa_sample_size_of_format(spec->format);
+ return size_table[spec->format];
}
size_t pa_frame_size(const pa_sample_spec *spec) {
pa_assert(spec);
pa_return_val_if_fail(pa_sample_spec_valid(spec), 0);
- return pa_sample_size(spec) * spec->channels;
+ return size_table[spec->format] * spec->channels;
}
size_t pa_bytes_per_second(const pa_sample_spec *spec) {
pa_assert(spec);
pa_return_val_if_fail(pa_sample_spec_valid(spec), 0);
- return spec->rate*pa_frame_size(spec);
+ return spec->rate * size_table[spec->format] * spec->channels;
}
pa_usec_t pa_bytes_to_usec(uint64_t length, const pa_sample_spec *spec) {
pa_assert(spec);
pa_return_val_if_fail(pa_sample_spec_valid(spec), 0);
- return (((pa_usec_t) (length / pa_frame_size(spec)) * PA_USEC_PER_SEC) / spec->rate);
+ return (((pa_usec_t) (length / (size_table[spec->format] * spec->channels)) * PA_USEC_PER_SEC) / spec->rate);
}
size_t pa_usec_to_bytes(pa_usec_t t, const pa_sample_spec *spec) {
pa_assert(spec);
pa_return_val_if_fail(pa_sample_spec_valid(spec), 0);
- return (size_t) (((t * spec->rate) / PA_USEC_PER_SEC)) * pa_frame_size(spec);
+ return (size_t) (((t * spec->rate) / PA_USEC_PER_SEC)) * (size_table[spec->format] * spec->channels);
}
pa_sample_spec* pa_sample_spec_init(pa_sample_spec *spec) {
@@ -109,12 +108,12 @@ pa_sample_spec* pa_sample_spec_init(pa_sample_spec *spec) {
int pa_sample_spec_valid(const pa_sample_spec *spec) {
pa_assert(spec);
- if (spec->rate <= 0 ||
+ if (PA_UNLIKELY (spec->rate <= 0 ||
spec->rate > PA_RATE_MAX ||
spec->channels <= 0 ||
spec->channels > PA_CHANNELS_MAX ||
spec->format >= PA_SAMPLE_MAX ||
- spec->format < 0)
+ spec->format < 0))
return 0;
return 1;
diff --git a/src/pulse/thread-mainloop.h b/src/pulse/thread-mainloop.h
index e847070d..2cf496e1 100644
--- a/src/pulse/thread-mainloop.h
+++ b/src/pulse/thread-mainloop.h
@@ -299,7 +299,9 @@ void pa_threaded_mainloop_accept(pa_threaded_mainloop *m);
/** Return the return value as specified with the main loop's quit() routine. */
int pa_threaded_mainloop_get_retval(pa_threaded_mainloop *m);
-/** Return the abstract main loop abstraction layer vtable for this main loop. */
+/** Return the abstract main loop abstraction layer vtable for this
+ main loop. No need of freeing the API as it is owned by the loop
+ and it is destroyed when this dies */
pa_mainloop_api* pa_threaded_mainloop_get_api(pa_threaded_mainloop*m);
/** Returns non-zero when called from withing the event loop thread. \since 0.9.7 */
diff --git a/src/pulse/util.c b/src/pulse/util.c
index 6f1e40a9..9440f5de 100644
--- a/src/pulse/util.c
+++ b/src/pulse/util.c
@@ -61,38 +61,40 @@
#include <pulsecore/log.h>
#include <pulsecore/core-util.h>
#include <pulsecore/macro.h>
+#include <pulsecore/usergroup.h>
#include "util.h"
char *pa_get_user_name(char *s, size_t l) {
const char *p;
+ char *name = NULL;
+#ifdef OS_IS_WIN32
char buf[1024];
+#endif
#ifdef HAVE_PWD_H
- struct passwd pw, *r;
+ struct passwd *r;
#endif
pa_assert(s);
pa_assert(l > 0);
- if (!(p = (getuid() == 0 ? "root" : NULL)) &&
- !(p = getenv("USER")) &&
- !(p = getenv("LOGNAME")) &&
- !(p = getenv("USERNAME"))) {
+ if ((p = (getuid() == 0 ? "root" : NULL)) ||
+ (p = getenv("USER")) ||
+ (p = getenv("LOGNAME")) ||
+ (p = getenv("USERNAME")))
+ {
+ name = pa_strlcpy(s, p, l);
+ } else {
#ifdef HAVE_PWD_H
-#ifdef HAVE_GETPWUID_R
- if (getpwuid_r(getuid(), &pw, buf, sizeof(buf), &r) != 0 || !r) {
-#else
- /* XXX Not thread-safe, but needed on OSes (e.g. FreeBSD 4.X)
- * that do not support getpwuid_r. */
- if ((r = getpwuid(getuid())) == NULL) {
-#endif
+ if ((r = pa_getpwuid_malloc(getuid())) == NULL) {
pa_snprintf(s, l, "%lu", (unsigned long) getuid());
return s;
}
- p = r->pw_name;
+ name = pa_strlcpy(s, r->pw_name, l);
+ pa_getpwuid_free(r);
#elif defined(OS_IS_WIN32) /* HAVE_PWD_H */
DWORD size = sizeof(buf);
@@ -102,7 +104,7 @@ char *pa_get_user_name(char *s, size_t l) {
return NULL;
}
- p = buf;
+ name = pa_strlcpy(s, buf, l);
#else /* HAVE_PWD_H */
@@ -110,7 +112,7 @@ char *pa_get_user_name(char *s, size_t l) {
#endif /* HAVE_PWD_H */
}
- return pa_strlcpy(s, p, l);
+ return name;
}
char *pa_get_host_name(char *s, size_t l) {
@@ -126,11 +128,10 @@ char *pa_get_host_name(char *s, size_t l) {
}
char *pa_get_home_dir(char *s, size_t l) {
- char *e;
+ char *e, *dir;
#ifdef HAVE_PWD_H
- char buf[1024];
- struct passwd pw, *r;
+ struct passwd *r;
#endif
pa_assert(s);
@@ -143,22 +144,19 @@ char *pa_get_home_dir(char *s, size_t l) {
return pa_strlcpy(s, e, l);
#ifdef HAVE_PWD_H
-
errno = 0;
-#ifdef HAVE_GETPWUID_R
- if (getpwuid_r(getuid(), &pw, buf, sizeof(buf), &r) != 0 || !r) {
-#else
- /* XXX Not thread-safe, but needed on OSes (e.g. FreeBSD 4.X)
- * that do not support getpwuid_r. */
- if ((r = getpwuid(getuid())) == NULL) {
-#endif
+ if ((r = pa_getpwuid_malloc(getuid())) == NULL) {
if (!errno)
errno = ENOENT;
return NULL;
}
- return pa_strlcpy(s, r->pw_dir, l);
+ dir = pa_strlcpy(s, r->pw_dir, l);
+
+ pa_getpwuid_free(r);
+
+ return dir;
#else /* HAVE_PWD_H */
errno = ENOENT;