mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-10-29 05:40:23 -04:00
update simple API
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@193 fefdeb5f-60dc-0310-8127-8f9354f1896f
This commit is contained in:
parent
f05a4ac806
commit
b772564a4e
7 changed files with 153 additions and 11 deletions
1
doc/todo
1
doc/todo
|
|
@ -18,6 +18,7 @@
|
||||||
- fix or work around libtool bug
|
- fix or work around libtool bug
|
||||||
- merge pa_context_connect_*
|
- merge pa_context_connect_*
|
||||||
- input latency
|
- input latency
|
||||||
|
- check if all mainloop stuff works still
|
||||||
|
|
||||||
** later ***
|
** later ***
|
||||||
- xmlrpc/http
|
- xmlrpc/http
|
||||||
|
|
|
||||||
|
|
@ -93,7 +93,7 @@ char *pa_sink_list_to_string(struct pa_core *c) {
|
||||||
assert(sink->monitor_source);
|
assert(sink->monitor_source);
|
||||||
pa_strbuf_printf(
|
pa_strbuf_printf(
|
||||||
s,
|
s,
|
||||||
" %c index: %u\n\tname: <%s>\n\tvolume: <0x%04x> (%0.2fdB)\n\tlatency: <%f usec>\n\tmonitor_source: <%u>\n\tsample_spec: <%s>\n",
|
" %c index: %u\n\tname: <%s>\n\tvolume: <0x%04x> (%0.2fdB)\n\tlatency: <%0.0f usec>\n\tmonitor_source: <%u>\n\tsample_spec: <%s>\n",
|
||||||
c->default_sink_name && !strcmp(sink->name, c->default_sink_name) ? '*' : ' ',
|
c->default_sink_name && !strcmp(sink->name, c->default_sink_name) ? '*' : ' ',
|
||||||
sink->index, sink->name,
|
sink->index, sink->name,
|
||||||
(unsigned) sink->volume,
|
(unsigned) sink->volume,
|
||||||
|
|
@ -189,7 +189,7 @@ char *pa_sink_input_list_to_string(struct pa_core *c) {
|
||||||
pa_sample_spec_snprint(ss, sizeof(ss), &i->sample_spec);
|
pa_sample_spec_snprint(ss, sizeof(ss), &i->sample_spec);
|
||||||
assert(i->sink);
|
assert(i->sink);
|
||||||
pa_strbuf_printf(
|
pa_strbuf_printf(
|
||||||
s, " index: %u\n\tname: <%s>\n\tsink: <%u>\n\tvolume: <0x%04x> (%0.2fdB)\n\tlatency: <%f usec>\n\tsample_spec: <%s>\n",
|
s, " index: %u\n\tname: <%s>\n\tsink: <%u>\n\tvolume: <0x%04x> (%0.2fdB)\n\tlatency: <%0.0f usec>\n\tsample_spec: <%s>\n",
|
||||||
i->index,
|
i->index,
|
||||||
i->name,
|
i->name,
|
||||||
i->sink->index,
|
i->sink->index,
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,17 @@ int main(int argc, char*argv[]) {
|
||||||
uint8_t buf[BUFSIZE];
|
uint8_t buf[BUFSIZE];
|
||||||
ssize_t r;
|
ssize_t r;
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
pa_usec_t latency;
|
||||||
|
|
||||||
|
if ((latency = pa_simple_get_playback_latency(s, &error)) == (pa_usec_t) -1) {
|
||||||
|
fprintf(stderr, __FILE__": pa_simple_get_playback_latency() failed: %s\n", pa_strerror(error));
|
||||||
|
goto finish;
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf(stderr, "%0.0f usec \r", (float)latency);
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Read some data ... */
|
/* Read some data ... */
|
||||||
if ((r = read(STDIN_FILENO, buf, sizeof(buf))) <= 0) {
|
if ((r = read(STDIN_FILENO, buf, sizeof(buf))) <= 0) {
|
||||||
if (r == 0) /* EOF */
|
if (r == 0) /* EOF */
|
||||||
|
|
|
||||||
|
|
@ -41,10 +41,11 @@ struct pa_simple {
|
||||||
struct pa_stream *stream;
|
struct pa_stream *stream;
|
||||||
enum pa_stream_direction direction;
|
enum pa_stream_direction direction;
|
||||||
|
|
||||||
int dead, drained;
|
int dead;
|
||||||
|
|
||||||
void *read_data;
|
void *read_data;
|
||||||
size_t read_index, read_length;
|
size_t read_index, read_length;
|
||||||
|
pa_usec_t latency;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void read_callback(struct pa_stream *s, const void*data, size_t length, void *userdata);
|
static void read_callback(struct pa_stream *s, const void*data, size_t length, void *userdata);
|
||||||
|
|
@ -71,6 +72,9 @@ static int check_error(struct pa_simple *p, int *perror) {
|
||||||
fail:
|
fail:
|
||||||
if (perror)
|
if (perror)
|
||||||
*perror = pa_context_errno(p->context);
|
*perror = pa_context_errno(p->context);
|
||||||
|
|
||||||
|
p->dead = 1;
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -121,6 +125,7 @@ struct pa_simple* pa_simple_new(
|
||||||
p->direction = dir;
|
p->direction = dir;
|
||||||
p->read_data = NULL;
|
p->read_data = NULL;
|
||||||
p->read_index = p->read_length = 0;
|
p->read_index = p->read_length = 0;
|
||||||
|
p->latency = 0;
|
||||||
|
|
||||||
if (!(p->context = pa_context_new(pa_mainloop_get_api(p->mainloop), name)))
|
if (!(p->context = pa_context_new(pa_mainloop_get_api(p->mainloop), name)))
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
@ -178,6 +183,13 @@ void pa_simple_free(struct pa_simple *s) {
|
||||||
int pa_simple_write(struct pa_simple *p, const void*data, size_t length, int *perror) {
|
int pa_simple_write(struct pa_simple *p, const void*data, size_t length, int *perror) {
|
||||||
assert(p && data && p->direction == PA_STREAM_PLAYBACK);
|
assert(p && data && p->direction == PA_STREAM_PLAYBACK);
|
||||||
|
|
||||||
|
if (p->dead) {
|
||||||
|
if (perror)
|
||||||
|
*perror = pa_context_errno(p->context);
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
while (length > 0) {
|
while (length > 0) {
|
||||||
size_t l;
|
size_t l;
|
||||||
|
|
||||||
|
|
@ -216,6 +228,13 @@ static void read_callback(struct pa_stream *s, const void*data, size_t length, v
|
||||||
int pa_simple_read(struct pa_simple *p, void*data, size_t length, int *perror) {
|
int pa_simple_read(struct pa_simple *p, void*data, size_t length, int *perror) {
|
||||||
assert(p && data && p->direction == PA_STREAM_RECORD);
|
assert(p && data && p->direction == PA_STREAM_RECORD);
|
||||||
|
|
||||||
|
if (p->dead) {
|
||||||
|
if (perror)
|
||||||
|
*perror = pa_context_errno(p->context);
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
while (length > 0) {
|
while (length > 0) {
|
||||||
if (p->read_data) {
|
if (p->read_data) {
|
||||||
size_t l = length;
|
size_t l = length;
|
||||||
|
|
@ -250,20 +269,27 @@ int pa_simple_read(struct pa_simple *p, void*data, size_t length, int *perror) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void drain_complete(struct pa_stream *s, int success, void *userdata) {
|
static void drain_or_flush_complete(struct pa_stream *s, int success, void *userdata) {
|
||||||
struct pa_simple *p = userdata;
|
struct pa_simple *p = userdata;
|
||||||
assert(s && p);
|
assert(s && p);
|
||||||
p->drained = success ? 1 : -1;
|
if (!success)
|
||||||
|
p->dead = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int pa_simple_drain(struct pa_simple *p, int *perror) {
|
int pa_simple_drain(struct pa_simple *p, int *perror) {
|
||||||
struct pa_operation *o;
|
struct pa_operation *o;
|
||||||
|
|
||||||
assert(p && p->direction == PA_STREAM_PLAYBACK);
|
assert(p && p->direction == PA_STREAM_PLAYBACK);
|
||||||
p->drained = 0;
|
|
||||||
o = pa_stream_drain(p->stream, drain_complete, p);
|
|
||||||
|
|
||||||
while (!p->drained) {
|
if (p->dead) {
|
||||||
|
if (perror)
|
||||||
|
*perror = pa_context_errno(p->context);
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
o = pa_stream_drain(p->stream, drain_or_flush_complete, p);
|
||||||
|
|
||||||
|
while (pa_operation_get_state(o) == PA_OPERATION_RUNNING) {
|
||||||
if (iterate(p, 1, perror) < 0) {
|
if (iterate(p, 1, perror) < 0) {
|
||||||
pa_operation_cancel(o);
|
pa_operation_cancel(o);
|
||||||
pa_operation_unref(o);
|
pa_operation_unref(o);
|
||||||
|
|
@ -273,8 +299,78 @@ int pa_simple_drain(struct pa_simple *p, int *perror) {
|
||||||
|
|
||||||
pa_operation_unref(o);
|
pa_operation_unref(o);
|
||||||
|
|
||||||
if (p->drained < 0 && perror)
|
if (p->dead && perror)
|
||||||
*perror = pa_context_errno(p->context);
|
*perror = pa_context_errno(p->context);
|
||||||
|
|
||||||
return 0;
|
return p->dead ? -1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void latency_complete(struct pa_stream *s, const struct pa_latency_info *l, void *userdata) {
|
||||||
|
struct pa_simple *p = userdata;
|
||||||
|
assert(s && p);
|
||||||
|
|
||||||
|
if (!l)
|
||||||
|
p->dead = 1;
|
||||||
|
else
|
||||||
|
p->latency = l->buffer_usec + l->sink_usec + l->transport_usec;
|
||||||
|
}
|
||||||
|
|
||||||
|
pa_usec_t pa_simple_get_playback_latency(struct pa_simple *p, int *perror) {
|
||||||
|
struct pa_operation *o;
|
||||||
|
assert(p && p->direction == PA_STREAM_PLAYBACK);
|
||||||
|
|
||||||
|
if (p->dead) {
|
||||||
|
if (perror)
|
||||||
|
*perror = pa_context_errno(p->context);
|
||||||
|
|
||||||
|
return (pa_usec_t) -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
p->latency = 0;
|
||||||
|
o = pa_stream_get_latency(p->stream, latency_complete, p);
|
||||||
|
|
||||||
|
while (pa_operation_get_state(o) == PA_OPERATION_RUNNING) {
|
||||||
|
|
||||||
|
if (iterate(p, 1, perror) < 0) {
|
||||||
|
pa_operation_cancel(o);
|
||||||
|
pa_operation_unref(o);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pa_operation_unref(o);
|
||||||
|
|
||||||
|
if (p->dead && perror)
|
||||||
|
*perror = pa_context_errno(p->context);
|
||||||
|
|
||||||
|
return p->dead ? (pa_usec_t) -1 : p->latency;
|
||||||
|
}
|
||||||
|
|
||||||
|
int pa_simple_flush(struct pa_simple *p, int *perror) {
|
||||||
|
struct pa_operation *o;
|
||||||
|
assert(p && p->direction == PA_STREAM_PLAYBACK);
|
||||||
|
|
||||||
|
if (p->dead) {
|
||||||
|
if (perror)
|
||||||
|
*perror = pa_context_errno(p->context);
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
o = pa_stream_flush(p->stream, drain_or_flush_complete, p);
|
||||||
|
|
||||||
|
while (pa_operation_get_state(o) == PA_OPERATION_RUNNING) {
|
||||||
|
if (iterate(p, 1, perror) < 0) {
|
||||||
|
pa_operation_cancel(o);
|
||||||
|
pa_operation_unref(o);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pa_operation_unref(o);
|
||||||
|
|
||||||
|
if (p->dead && perror)
|
||||||
|
*perror = pa_context_errno(p->context);
|
||||||
|
|
||||||
|
return p->dead ? -1 : 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -69,6 +69,12 @@ int pa_simple_drain(struct pa_simple *s, int *error);
|
||||||
/** Read some data from the server */
|
/** Read some data from the server */
|
||||||
int pa_simple_read(struct pa_simple *s, void*data, size_t length, int *error);
|
int pa_simple_read(struct pa_simple *s, void*data, size_t length, int *error);
|
||||||
|
|
||||||
|
/** Return the playback latency. \since 0.5 */
|
||||||
|
pa_usec_t pa_simple_get_playback_latency(struct pa_simple *s, int *perror);
|
||||||
|
|
||||||
|
/** Flush the playback buffer. \since 0.5 */
|
||||||
|
int pa_simple_flush(struct pa_simple *s, int *perror);
|
||||||
|
|
||||||
PA_C_DECL_END
|
PA_C_DECL_END
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
25
polyp/util.c
25
polyp/util.c
|
|
@ -39,6 +39,7 @@
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <sched.h>
|
#include <sched.h>
|
||||||
#include <sys/resource.h>
|
#include <sys/resource.h>
|
||||||
|
#include <limits.h>
|
||||||
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "xmalloc.h"
|
#include "xmalloc.h"
|
||||||
|
|
@ -322,3 +323,27 @@ int pa_fd_set_cloexec(int fd, int b) {
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *pa_get_binary_name(char *s, size_t l) {
|
||||||
|
char path[PATH_MAX];
|
||||||
|
int i;
|
||||||
|
assert(s && l);
|
||||||
|
|
||||||
|
/* This works on Linux only */
|
||||||
|
|
||||||
|
snprintf(path, sizeof(path), "/proc/%u/exe", (unsigned) getpid());
|
||||||
|
if ((i = readlink(path, s, l-1)) < 0)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
s[i] = 0;
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *pa_path_get_filename(const char *p) {
|
||||||
|
char *fn;
|
||||||
|
|
||||||
|
if ((fn = strrchr(p, '/')))
|
||||||
|
return fn+1;
|
||||||
|
|
||||||
|
return (char*) p;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,9 @@ char *pa_vsprintf_malloc(const char *format, va_list ap);
|
||||||
|
|
||||||
char *pa_get_user_name(char *s, size_t l);
|
char *pa_get_user_name(char *s, size_t l);
|
||||||
char *pa_get_host_name(char *s, size_t l);
|
char *pa_get_host_name(char *s, size_t l);
|
||||||
|
char *pa_get_binary_name(char *s, size_t l);
|
||||||
|
|
||||||
|
char *pa_path_get_filename(const char *p);
|
||||||
|
|
||||||
pa_usec_t pa_timeval_diff(const struct timeval *a, const struct timeval *b);
|
pa_usec_t pa_timeval_diff(const struct timeval *a, const struct timeval *b);
|
||||||
int pa_timeval_cmp(const struct timeval *a, const struct timeval *b);
|
int pa_timeval_cmp(const struct timeval *a, const struct timeval *b);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue