summaryrefslogtreecommitdiffstats
path: root/src/simple.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2004-07-06 00:08:44 +0000
committerLennart Poettering <lennart@poettering.net>2004-07-06 00:08:44 +0000
commitf8cbde54dab2783e2c6ba699dfaee9ef51b1e098 (patch)
tree7bdcc21f3b25d521207d19c8ca26eb26229b6bb7 /src/simple.c
parent722c2c8c8785d215ec3ec8757168b82c9600f4a3 (diff)
auth support in esound and native
AUTH and SET_NAME operatins in native simple library git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@51 fefdeb5f-60dc-0310-8127-8f9354f1896f
Diffstat (limited to 'src/simple.c')
-rw-r--r--src/simple.c70
1 files changed, 37 insertions, 33 deletions
diff --git a/src/simple.c b/src/simple.c
index a90d22bd..c1d1e96c 100644
--- a/src/simple.c
+++ b/src/simple.c
@@ -1,23 +1,19 @@
+#include <assert.h>
+#include <stdlib.h>
+
#include "simple.h"
#include "polyp.h"
#include "mainloop.h"
+#include "polyp-error.h"
struct pa_simple {
- struct mainloop *mainloop;
+ struct pa_mainloop *mainloop;
struct pa_context *context;
struct pa_stream *stream;
- size_t requested;
int dead;
};
-static void playback_callback(struct pa_stream *p, size_t length, void *userdata) {
- struct pa_stream *sp = userdata;
- assert(p && length && sp);
-
- sp->requested = length;
-}
-
struct pa_simple* pa_simple_new(
const char *server,
const char *name,
@@ -25,9 +21,11 @@ struct pa_simple* pa_simple_new(
const char *dev,
const char *stream_name,
const struct pa_sample_spec *ss,
- const struct pa_buffer_attr *attr) {
+ const struct pa_buffer_attr *attr,
+ int *perror) {
struct pa_simple *p;
+ int error = PA_ERROR_INTERNAL;
assert(ss);
p = malloc(sizeof(struct pa_simple));
@@ -36,39 +34,43 @@ struct pa_simple* pa_simple_new(
p->stream = NULL;
p->mainloop = pa_mainloop_new();
assert(p->mainloop);
- p->requested = 0;
p->dead = 0;
if (!(p->context = pa_context_new(pa_mainloop_get_api(p->mainloop), name)))
goto fail;
- if (pa_context_connect(c, server, NULL, NULL) < 0)
+ if (pa_context_connect(p->context, server, NULL, NULL) < 0) {
+ error = pa_context_errno(p->context);
goto fail;
+ }
- while (!pa_context_is_ready(c)) {
- if (pa_context_is_dead(c))
+ while (!pa_context_is_ready(p->context)) {
+ if (pa_context_is_dead(p->context)) {
+ error = pa_context_errno(p->context);
goto fail;
+ }
- if (mainloop_iterate(p->mainloop) < 0)
+ if (pa_mainloop_iterate(p->mainloop, 1, NULL) < 0)
goto fail;
}
- if (!(p->stream = pa_stream_new(p->context, dir, sink, stream_name, ss, attr, NULL, NULL)))
+ if (!(p->stream = pa_stream_new(p->context, dir, dev, stream_name, ss, attr, NULL, NULL)))
goto fail;
- while (!pa_stream_is_ready(c)) {
- if (pa_stream_is_dead(c))
+ while (!pa_stream_is_ready(p->stream)) {
+ if (pa_stream_is_dead(p->stream)) {
+ error = pa_context_errno(p->context);
goto fail;
+ }
- if (mainloop_iterate(p->mainloop) < 0)
+ if (pa_mainloop_iterate(p->mainloop, 1, NULL) < 0)
goto fail;
}
- pa_stream_set_write_callback(p->stream, playback_callback, p);
-
return p;
fail:
+ *perror = error;
pa_simple_free(p);
return NULL;
}
@@ -83,38 +85,40 @@ void pa_simple_free(struct pa_simple *s) {
pa_context_free(s->context);
if (s->mainloop)
- mainloop_free(s->mainloop);
+ pa_mainloop_free(s->mainloop);
free(s);
}
-int pa_simple_write(struct pa_simple *s, const void*data, size_t length) {
- assert(s && data);
+int pa_simple_write(struct pa_simple *p, const void*data, size_t length, int *perror) {
+ assert(p && data);
while (length > 0) {
size_t l;
- while (!s->requested) {
- if (pa_context_is_dead(c))
+ while (!(l = pa_stream_writable_size(p->stream))) {
+ if (pa_context_is_dead(p->context)) {
+ *perror = pa_context_errno(p->context);
return -1;
+ }
- if (mainloop_iterate(s->mainloop) < 0)
+ if (pa_mainloop_iterate(p->mainloop, 1, NULL) < 0) {
+ *perror = PA_ERROR_INTERNAL;
return -1;
+ }
}
- l = length;
- if (l > s->requested)
- l = s->requested;
+ if (l > length)
+ l = length;
- pa_stream_write(s->stream, data, l);
+ pa_stream_write(p->stream, data, l);
data += l;
length -= l;
- s->requested = -l;
}
return 0;
}
-int pa_simple_read(struct pa_simple *s, const void*data, size_t length) {
+int pa_simple_read(struct pa_simple *s, void*data, size_t length, int *perror) {
assert(0);
}