mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-10-29 05:40:23 -04:00
implement proper refcounting in polyplib
split polyplib to multiple modules add some prelimenary documentation add doxygen support git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@123 fefdeb5f-60dc-0310-8127-8f9354f1896f
This commit is contained in:
parent
1c2ec47cf1
commit
22cb23eedb
45 changed files with 2853 additions and 12800 deletions
|
|
@ -41,4 +41,7 @@ homepage: all dist
|
|||
distcleancheck:
|
||||
@:
|
||||
|
||||
.PHONY: homepage distcleancheck
|
||||
doxygen:
|
||||
$(MAKE) -C doxygen
|
||||
|
||||
.PHONY: homepage distcleancheck doxygen
|
||||
|
|
|
|||
|
|
@ -84,5 +84,5 @@ AM_CONDITIONAL([USE_LYNX], [test "x$lynx" = xyes])
|
|||
|
||||
AM_CONDITIONAL(BUILD_LIBPOLYPCORE, false)
|
||||
|
||||
AC_CONFIG_FILES([Makefile polyp/Makefile polyplib.pc polyplib-simple.pc polyplib-mainloop.pc polyplib-error.pc doc/Makefile doc/README.html doc/cli.html doc/daemon.html doc/modules.html])
|
||||
AC_CONFIG_FILES([Makefile polyp/Makefile polyplib.pc polyplib-simple.pc polyplib-mainloop.pc polyplib-error.pc doc/Makefile doc/README.html doc/cli.html doc/daemon.html doc/modules.html doxygen/Makefile doxygen/doxygen.conf])
|
||||
AC_OUTPUT
|
||||
|
|
|
|||
11
doxygen/Makefile.am
Normal file
11
doxygen/Makefile.am
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
# $Id$
|
||||
|
||||
noinst_DATA=html
|
||||
|
||||
html: doxygen.conf
|
||||
doxygen $<
|
||||
|
||||
clean-local:
|
||||
rm -rf html
|
||||
|
||||
.PHONY: all html
|
||||
1153
doxygen/doxygen.conf.in
Normal file
1153
doxygen/doxygen.conf.in
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -25,12 +25,19 @@ polypincludedir=$(includedir)/polyp
|
|||
|
||||
EXTRA_DIST = polypaudio.pa depmod.py
|
||||
bin_PROGRAMS = polypaudio pacat pactl
|
||||
noinst_PROGRAMS = pacat-simple parec-simple mainloop-test mainloop-test-glib
|
||||
noinst_PROGRAMS = mainloop-test mainloop-test-glib pacat-simple parec-simple
|
||||
|
||||
polypinclude_HEADERS=polyplib.h \
|
||||
polyplib-def.h \
|
||||
polyplib-simple.h \
|
||||
polyplib-error.h \
|
||||
polyplib-stream.h \
|
||||
polyplib-context.h \
|
||||
polyplib-introspect.h \
|
||||
polyplib-subscribe.h \
|
||||
polyplib-operation.h \
|
||||
polyplib-scache.h \
|
||||
cdecl.h \
|
||||
mainloop-api.h \
|
||||
mainloop.h \
|
||||
mainloop-signal.h \
|
||||
|
|
@ -72,10 +79,11 @@ pkglib_LTLIBRARIES=libiochannel.la \
|
|||
module-x11-bell.la
|
||||
|
||||
lib_LTLIBRARIES=libpolyp.la \
|
||||
libpolyp-simple.la \
|
||||
libpolyp-error.la \
|
||||
libpolyp-mainloop.la \
|
||||
libpolyp-mainloop-glib.la
|
||||
libpolyp-mainloop-glib.la \
|
||||
libpolyp-simple.la
|
||||
|
||||
|
||||
polypaudio_SOURCES = idxset.c idxset.h \
|
||||
queue.c queue.h \
|
||||
|
|
@ -261,7 +269,7 @@ module_x11_bell_la_SOURCES = module-x11-bell.c
|
|||
module_x11_bell_la_LDFLAGS = -module -avoid-version
|
||||
module_x11_bell_la_LIBADD = $(AM_LIBADD) -lX11 -L/usr/X11R6/lib
|
||||
|
||||
libpolyp_la_SOURCES = polyplib.c polyplib.h \
|
||||
libpolyp_la_SOURCES = polyplib.h \
|
||||
polyplib-def.h \
|
||||
tagstruct.c tagstruct.h \
|
||||
iochannel.c iochannel.h \
|
||||
|
|
@ -281,7 +289,14 @@ libpolyp_la_SOURCES = polyplib.c polyplib.h \
|
|||
socket-util.c socket-util.h \
|
||||
native-common.h \
|
||||
sample.c sample.h \
|
||||
xmalloc.c xmalloc.h
|
||||
xmalloc.c xmalloc.h \
|
||||
polyplib-operation.c polyplib-operation.h \
|
||||
polyplib-context.c polyplib-context.h \
|
||||
polyplib-stream.c polyplib-stream.h \
|
||||
polyplib-introspect.c polyplib-introspect.h \
|
||||
polyplib-scache.c polyplib-scache.h \
|
||||
polyplib-subscribe.c polyplib-subscribe.h \
|
||||
cdecl.h
|
||||
libpolyp_la_CFLAGS = $(AM_CFLAGS)
|
||||
|
||||
libpolyp_mainloop_la_SOURCES = mainloop-api.h mainloop-api.c \
|
||||
|
|
|
|||
21
polyp/cdecl.h
Normal file
21
polyp/cdecl.h
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
#ifndef foocdeclhfoo
|
||||
#define foocdeclhfoo
|
||||
|
||||
/** \file
|
||||
* C++ compatibility support */
|
||||
|
||||
#ifdef __cplusplus
|
||||
/** If using C++ this macro enables C mode, otherwise does nothing */
|
||||
#define PA_C_DECL_BEGIN extern "C" {
|
||||
/** If using C++ this macros switches back to C++ mode, otherwise does nothing */
|
||||
#define PA_C_DECL_END }
|
||||
|
||||
#else
|
||||
/** If using C++ this macro enables C mode, otherwise does nothing */
|
||||
#define PA_C_DECL_BEGIN
|
||||
/** If using C++ this macros switches back to C++ mode, otherwise does nothing */
|
||||
#define PA_C_DECL_END
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
@ -4,20 +4,26 @@
|
|||
#include <glib.h>
|
||||
|
||||
#include "mainloop-api.h"
|
||||
#include "cdecl.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/** \file
|
||||
* GLIB main loop support */
|
||||
|
||||
PA_C_DECL_BEGIN
|
||||
|
||||
/** \struct pa_glib_mainloop
|
||||
* A GLIB main loop object */
|
||||
struct pa_glib_mainloop;
|
||||
|
||||
/** Create a new GLIB main loop object for the specified GLIB main loop context. If c is NULL the default context is used. */
|
||||
struct pa_glib_mainloop *pa_glib_mainloop_new(GMainContext *c);
|
||||
|
||||
/** Free the GLIB main loop object */
|
||||
void pa_glib_mainloop_free(struct pa_glib_mainloop* g);
|
||||
|
||||
/** Return the abstract main loop API vtable for the GLIB main loop object */
|
||||
struct pa_mainloop_api* pa_glib_mainloop_get_api(struct pa_glib_mainloop *g);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
PA_C_DECL_BEGIN
|
||||
|
||||
#endif
|
||||
|
|
|
|||
39
polyp/llist.h
Normal file
39
polyp/llist.h
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
#ifndef foollistfoo
|
||||
#define foollistfoo
|
||||
|
||||
#define PA_LLIST_HEAD(t,name) t *name
|
||||
|
||||
#define PA_LLIST_FIELDS(t) t *next, *prev;
|
||||
|
||||
#define PA_LLIST_HEAD_INIT(t,item) do { (item) = NULL; } while(0)
|
||||
|
||||
#define PA_LLIST_INIT(t,item) do { \
|
||||
t *_item = (item); \
|
||||
assert(_item); \
|
||||
_item->prev = _item->next = NULL; \
|
||||
} while(0)
|
||||
|
||||
#define PA_LLIST_PREPEND(t,head,item) do { \
|
||||
t **_head = &(head), *_item = (item); \
|
||||
assert(_item); \
|
||||
if ((_item->next = *_head)) \
|
||||
_item->next->prev = _item; \
|
||||
_item->prev = NULL; \
|
||||
*_head = _item; \
|
||||
} while (0)
|
||||
|
||||
#define PA_LLIST_REMOVE(t,head,item) do { \
|
||||
t **_head = &(head), *_item = (item); \
|
||||
assert(_item); \
|
||||
if (_item->next) \
|
||||
_item->next->prev = _item->prev; \
|
||||
if (_item->prev) \
|
||||
_item->prev->next = _item->next; \
|
||||
else {\
|
||||
assert(*_head == _item); \
|
||||
*_head = _item->next; \
|
||||
} \
|
||||
_item->next = _item->prev = NULL; \
|
||||
} while(0)
|
||||
|
||||
#endif
|
||||
|
|
@ -22,26 +22,37 @@
|
|||
USA.
|
||||
***/
|
||||
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#include "cdecl.h"
|
||||
|
||||
PA_C_DECL_BEGIN
|
||||
|
||||
/** A bitmask for IO events */
|
||||
enum pa_io_event_flags {
|
||||
PA_IO_EVENT_NULL = 0,
|
||||
PA_IO_EVENT_INPUT = 1,
|
||||
PA_IO_EVENT_OUTPUT = 2,
|
||||
PA_IO_EVENT_HANGUP = 4,
|
||||
PA_IO_EVENT_ERROR = 8,
|
||||
PA_IO_EVENT_NULL = 0, /**< No event */
|
||||
PA_IO_EVENT_INPUT = 1, /**< Input event */
|
||||
PA_IO_EVENT_OUTPUT = 2, /**< Output event */
|
||||
PA_IO_EVENT_HANGUP = 4, /**< Hangup event */
|
||||
PA_IO_EVENT_ERROR = 8, /**< Error event */
|
||||
};
|
||||
|
||||
/** \struct pa_io_event
|
||||
* An IO event source object */
|
||||
struct pa_io_event;
|
||||
|
||||
/** \struct pa_defer_event
|
||||
* A deferred event source object. Events of this type are triggered once in every main loop iteration */
|
||||
struct pa_defer_event;
|
||||
|
||||
/** \struct pa_time_event
|
||||
* A timer event source object */
|
||||
struct pa_time_event;
|
||||
|
||||
/** An abstract mainloop API vtable */
|
||||
struct pa_mainloop_api {
|
||||
/** A pointer to some private, arbitrary data of the main loop implementation */
|
||||
void *userdata;
|
||||
|
||||
/* IO sources */
|
||||
|
|
@ -56,20 +67,25 @@ struct pa_mainloop_api {
|
|||
void (*time_free)(struct pa_time_event* e);
|
||||
void (*time_set_destroy)(struct pa_time_event *e, void (*callback) (struct pa_mainloop_api*a, struct pa_time_event *e, void *userdata));
|
||||
|
||||
/* Deferred sources */
|
||||
/** Create a new deferred event source object */
|
||||
struct pa_defer_event* (*defer_new)(struct pa_mainloop_api*a, void (*callback) (struct pa_mainloop_api*a, struct pa_defer_event* e, void *userdata), void *userdata);
|
||||
|
||||
/** Enable or disable a deferred event source temporarily */
|
||||
void (*defer_enable)(struct pa_defer_event* e, int b);
|
||||
|
||||
/** Free a deferred event source object */
|
||||
void (*defer_free)(struct pa_defer_event* e);
|
||||
|
||||
/** Set a function that is called when the deferred event source is destroyed. Use this to free the userdata argument if required */
|
||||
void (*defer_set_destroy)(struct pa_defer_event *e, void (*callback) (struct pa_mainloop_api*a, struct pa_defer_event *e, void *userdata));
|
||||
|
||||
/* Exit mainloop */
|
||||
/** Exit the main loop and return the specfied retval*/
|
||||
void (*quit)(struct pa_mainloop_api*a, int retval);
|
||||
};
|
||||
|
||||
/** Run the specified callback function once from the main loop using an anonymous defer event. */
|
||||
void pa_mainloop_api_once(struct pa_mainloop_api*m, void (*callback)(struct pa_mainloop_api*m, void *userdata), void *userdata);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
PA_C_DECL_END
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -23,6 +23,9 @@
|
|||
***/
|
||||
|
||||
#include "mainloop-api.h"
|
||||
#include "cdecl.h"
|
||||
|
||||
PA_C_DECL_BEGIN
|
||||
|
||||
struct pa_mainloop;
|
||||
|
||||
|
|
@ -34,4 +37,6 @@ int pa_mainloop_run(struct pa_mainloop *m, int *retval);
|
|||
|
||||
struct pa_mainloop_api* pa_mainloop_get_api(struct pa_mainloop*m);
|
||||
|
||||
PA_C_DECL_END
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ struct pa_memblock *pa_memblock_new(size_t length) {
|
|||
b->ref = 1;
|
||||
b->length = length;
|
||||
b->data = b+1;
|
||||
b->free_cb = NULL;
|
||||
memblock_count++;
|
||||
memblock_total += length;
|
||||
return b;
|
||||
|
|
@ -50,6 +51,7 @@ struct pa_memblock *pa_memblock_new_fixed(void *d, size_t length) {
|
|||
b->ref = 1;
|
||||
b->length = length;
|
||||
b->data = d;
|
||||
b->free_cb = NULL;
|
||||
memblock_count++;
|
||||
memblock_total += length;
|
||||
return b;
|
||||
|
|
@ -61,6 +63,21 @@ struct pa_memblock *pa_memblock_new_dynamic(void *d, size_t length) {
|
|||
b->ref = 1;
|
||||
b->length = length;
|
||||
b->data = d;
|
||||
b->free_cb = NULL;
|
||||
memblock_count++;
|
||||
memblock_total += length;
|
||||
return b;
|
||||
}
|
||||
|
||||
struct pa_memblock *pa_memblock_new_user(void *d, size_t length, void (*free_cb)(void *p)) {
|
||||
struct pa_memblock *b;
|
||||
assert(d && length && free_cb);
|
||||
b = pa_xmalloc(sizeof(struct pa_memblock));
|
||||
b->type = PA_MEMBLOCK_USER;
|
||||
b->ref = 1;
|
||||
b->length = length;
|
||||
b->data = d;
|
||||
b->free_cb = free_cb;
|
||||
memblock_count++;
|
||||
memblock_total += length;
|
||||
return b;
|
||||
|
|
@ -74,31 +91,28 @@ struct pa_memblock* pa_memblock_ref(struct pa_memblock*b) {
|
|||
|
||||
void pa_memblock_unref(struct pa_memblock*b) {
|
||||
assert(b && b->ref >= 1);
|
||||
b->ref--;
|
||||
|
||||
if (b->ref == 0) {
|
||||
if (b->type == PA_MEMBLOCK_DYNAMIC)
|
||||
pa_xfree(b->data);
|
||||
|
||||
if ((--(b->ref)) == 0) {
|
||||
memblock_count--;
|
||||
memblock_total -= b->length;
|
||||
|
||||
if (b->type == PA_MEMBLOCK_USER) {
|
||||
assert(b->free_cb);
|
||||
b->free_cb(b->data);
|
||||
} else if (b->type == PA_MEMBLOCK_DYNAMIC)
|
||||
pa_xfree(b->data);
|
||||
|
||||
pa_xfree(b);
|
||||
}
|
||||
}
|
||||
|
||||
void pa_memblock_unref_fixed(struct pa_memblock *b) {
|
||||
void *d;
|
||||
|
||||
assert(b && b->ref >= 1);
|
||||
assert(b && b->ref >= 1 && b->type == PA_MEMBLOCK_FIXED);
|
||||
|
||||
if (b->ref == 1) {
|
||||
if (b->ref == 1)
|
||||
pa_memblock_unref(b);
|
||||
return;
|
||||
} else {
|
||||
d = pa_xmalloc(b->length);
|
||||
memcpy(d, b->data, b->length);
|
||||
b->data = d;
|
||||
else {
|
||||
b->data = pa_xmemdup(b->data, b->length);
|
||||
b->type = PA_MEMBLOCK_DYNAMIC;
|
||||
b->ref--;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,18 +25,20 @@
|
|||
#include <sys/types.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
enum pa_memblock_type { PA_MEMBLOCK_FIXED, PA_MEMBLOCK_APPENDED, PA_MEMBLOCK_DYNAMIC };
|
||||
enum pa_memblock_type { PA_MEMBLOCK_FIXED, PA_MEMBLOCK_APPENDED, PA_MEMBLOCK_DYNAMIC, PA_MEMBLOCK_USER };
|
||||
|
||||
struct pa_memblock {
|
||||
enum pa_memblock_type type;
|
||||
unsigned ref;
|
||||
size_t length;
|
||||
void *data;
|
||||
void (*free_cb)(void *p);
|
||||
};
|
||||
|
||||
struct pa_memblock *pa_memblock_new(size_t length);
|
||||
struct pa_memblock *pa_memblock_new_fixed(void *data, size_t length);
|
||||
struct pa_memblock *pa_memblock_new_dynamic(void *data, size_t length);
|
||||
struct pa_memblock *pa_memblock_new_user(void *data, size_t length, void (*free_cb)(void *p));
|
||||
|
||||
void pa_memblock_unref(struct pa_memblock*b);
|
||||
struct pa_memblock* pa_memblock_ref(struct pa_memblock*b);
|
||||
|
|
|
|||
|
|
@ -64,6 +64,9 @@ enum {
|
|||
|
||||
PA_COMMAND_SUBSCRIBE,
|
||||
PA_COMMAND_SUBSCRIBE_EVENT,
|
||||
|
||||
PA_COMMAND_SET_SINK_VOLUME,
|
||||
PA_COMMAND_SET_SINK_INPUT_VOLUME,
|
||||
|
||||
PA_COMMAND_MAX
|
||||
};
|
||||
|
|
@ -90,13 +93,14 @@ enum {
|
|||
#define PA_NATIVE_COOKIE_FILE ".polypaudio-cookie"
|
||||
|
||||
enum pa_subscription_mask {
|
||||
PA_SUBSCRIPTION_FACILITY_SINK = 1,
|
||||
PA_SUBSCRIPTION_FACILITY_SOURCE = 2,
|
||||
PA_SUBSCRIPTION_FACILITY_SINK_INPUT = 4,
|
||||
PA_SUBSCRIPTION_FACILITY_SOURCE_OUTPUT = 8,
|
||||
PA_SUBSCRIPTION_FACILITY_MODULE = 16,
|
||||
PA_SUBSCRIPTION_FACILITY_CLIENT = 32,
|
||||
PA_SUBSCRIPTION_FACILITY_SAMPLE_CACHE = 64,
|
||||
PA_SUBSCRIPTION_MASK_NULL = 0,
|
||||
PA_SUBSCRIPTION_MASK_SINK = 1,
|
||||
PA_SUBSCRIPTION_MASK_SOURCE = 2,
|
||||
PA_SUBSCRIPTION_MASK_SINK_INPUT = 4,
|
||||
PA_SUBSCRIPTION_MASK_SOURCE_OUTPUT = 8,
|
||||
PA_SUBSCRIPTION_MASK_MODULE = 16,
|
||||
PA_SUBSCRIPTION_MASK_CLIENT = 32,
|
||||
PA_SUBSCRIPTION_MASK_SAMPLE_CACHE = 64,
|
||||
};
|
||||
|
||||
enum pa_subscription_event_type {
|
||||
|
|
|
|||
152
polyp/pacat.c
152
polyp/pacat.c
|
|
@ -52,18 +52,6 @@ static void quit(int ret) {
|
|||
mainloop_api->quit(mainloop_api, ret);
|
||||
}
|
||||
|
||||
static void context_die_callback(struct pa_context *c, void *userdata) {
|
||||
assert(c);
|
||||
fprintf(stderr, "Connection to server shut down, exiting.\n");
|
||||
quit(1);
|
||||
}
|
||||
|
||||
static void stream_die_callback(struct pa_stream *s, void *userdata) {
|
||||
assert(s);
|
||||
fprintf(stderr, "Stream deleted, exiting.\n");
|
||||
quit(1);
|
||||
}
|
||||
|
||||
static void do_stream_write(size_t length) {
|
||||
size_t l;
|
||||
assert(length);
|
||||
|
|
@ -75,7 +63,7 @@ static void do_stream_write(size_t length) {
|
|||
if (l > buffer_length)
|
||||
l = buffer_length;
|
||||
|
||||
pa_stream_write(stream, buffer+buffer_index, l);
|
||||
pa_stream_write(stream, buffer+buffer_index, l, NULL);
|
||||
buffer_length -= l;
|
||||
buffer_index += l;
|
||||
|
||||
|
|
@ -115,63 +103,97 @@ static void stream_read_callback(struct pa_stream *s, const void*data, size_t le
|
|||
buffer_index = 0;
|
||||
}
|
||||
|
||||
static void stream_complete_callback(struct pa_stream*s, int success, void *userdata) {
|
||||
static void stream_state_callback(struct pa_stream *s, void *userdata) {
|
||||
assert(s);
|
||||
|
||||
if (!success) {
|
||||
fprintf(stderr, "Stream creation failed: %s\n", pa_strerror(pa_context_errno(pa_stream_get_context(s))));
|
||||
quit(1);
|
||||
return;
|
||||
}
|
||||
switch (pa_stream_get_state(s)) {
|
||||
case PA_STREAM_CREATING:
|
||||
break;
|
||||
|
||||
fprintf(stderr, "Stream created.\n");
|
||||
case PA_STREAM_READY:
|
||||
fprintf(stderr, "Stream successfully created\n");
|
||||
break;
|
||||
|
||||
case PA_STREAM_TERMINATED:
|
||||
quit(0);
|
||||
break;
|
||||
|
||||
case PA_STREAM_FAILED:
|
||||
default:
|
||||
fprintf(stderr, "Stream errror: %s\n", pa_strerror(pa_context_errno(pa_stream_get_context(s))));
|
||||
quit(1);
|
||||
}
|
||||
}
|
||||
|
||||
static void context_complete_callback(struct pa_context *c, int success, void *userdata) {
|
||||
static void context_state_callback(struct pa_context *c, void *userdata) {
|
||||
static const struct pa_sample_spec ss = {
|
||||
.format = PA_SAMPLE_S16LE,
|
||||
.rate = 44100,
|
||||
.channels = 2
|
||||
};
|
||||
|
||||
assert(c);
|
||||
|
||||
switch (pa_context_get_state(c)) {
|
||||
case PA_CONTEXT_CONNECTING:
|
||||
case PA_CONTEXT_AUTHORIZING:
|
||||
case PA_CONTEXT_SETTING_NAME:
|
||||
break;
|
||||
|
||||
assert(c && !stream);
|
||||
case PA_CONTEXT_READY:
|
||||
|
||||
assert(c && !stream);
|
||||
fprintf(stderr, "Connection established.\n");
|
||||
|
||||
if (!success) {
|
||||
fprintf(stderr, "Connection failed: %s\n", pa_strerror(pa_context_errno(c)));
|
||||
goto fail;
|
||||
stream = pa_stream_new(c, "pacat", &ss);
|
||||
assert(stream);
|
||||
|
||||
pa_stream_set_state_callback(stream, stream_state_callback, NULL);
|
||||
pa_stream_set_write_callback(stream, stream_write_callback, NULL);
|
||||
pa_stream_set_read_callback(stream, stream_read_callback, NULL);
|
||||
|
||||
if (mode == PLAYBACK)
|
||||
pa_stream_connect_playback(stream, NULL, NULL);
|
||||
else
|
||||
pa_stream_connect_record(stream, NULL, NULL);
|
||||
|
||||
break;
|
||||
|
||||
case PA_CONTEXT_TERMINATED:
|
||||
quit(0);
|
||||
break;
|
||||
|
||||
case PA_CONTEXT_FAILED:
|
||||
default:
|
||||
fprintf(stderr, "Connection failure: %s\n", pa_strerror(pa_context_errno(c)));
|
||||
quit(1);
|
||||
}
|
||||
|
||||
fprintf(stderr, "Connection established.\n");
|
||||
|
||||
if (!(stream = pa_stream_new(c, mode == PLAYBACK ? PA_STREAM_PLAYBACK : PA_STREAM_RECORD, NULL, "pacat", &ss, NULL, stream_complete_callback, NULL))) {
|
||||
fprintf(stderr, "pa_stream_new() failed: %s\n", pa_strerror(pa_context_errno(c)));
|
||||
goto fail;
|
||||
}
|
||||
|
||||
pa_stream_set_die_callback(stream, stream_die_callback, NULL);
|
||||
pa_stream_set_write_callback(stream, stream_write_callback, NULL);
|
||||
pa_stream_set_read_callback(stream, stream_read_callback, NULL);
|
||||
|
||||
return;
|
||||
|
||||
fail:
|
||||
quit(1);
|
||||
}
|
||||
|
||||
static void context_drain_complete(struct pa_context*c, void *userdata) {
|
||||
quit(0);
|
||||
pa_context_disconnect(c);
|
||||
}
|
||||
|
||||
static void stream_drain_complete(struct pa_stream*s, void *userdata) {
|
||||
static void stream_drain_complete(struct pa_stream*s, int success, void *userdata) {
|
||||
struct pa_operation *o;
|
||||
|
||||
if (!success) {
|
||||
fprintf(stderr, "Failed to drain stream: %s\n", pa_strerror(pa_context_errno(context)));
|
||||
quit(1);
|
||||
}
|
||||
|
||||
fprintf(stderr, "Playback stream drained.\n");
|
||||
|
||||
pa_stream_free(stream);
|
||||
pa_stream_disconnect(stream);
|
||||
pa_stream_unref(stream);
|
||||
stream = NULL;
|
||||
|
||||
if (pa_context_drain(context, context_drain_complete, NULL) < 0)
|
||||
quit(0);
|
||||
else
|
||||
if (!(o = pa_context_drain(context, context_drain_complete, NULL)))
|
||||
pa_context_disconnect(context);
|
||||
else {
|
||||
pa_operation_unref(o);
|
||||
fprintf(stderr, "Draining connection to server.\n");
|
||||
}
|
||||
}
|
||||
|
||||
static void stdin_callback(struct pa_mainloop_api*a, struct pa_io_event *e, int fd, enum pa_io_event_flags f, void *userdata) {
|
||||
|
|
@ -184,7 +206,7 @@ static void stdin_callback(struct pa_mainloop_api*a, struct pa_io_event *e, int
|
|||
return;
|
||||
}
|
||||
|
||||
if (!stream || !pa_stream_is_ready(stream) || !(l = w = pa_stream_writable_size(stream)))
|
||||
if (!stream || pa_stream_get_state(stream) != PA_STREAM_READY || !(l = w = pa_stream_writable_size(stream)))
|
||||
l = 4096;
|
||||
|
||||
buffer = malloc(l);
|
||||
|
|
@ -192,7 +214,7 @@ static void stdin_callback(struct pa_mainloop_api*a, struct pa_io_event *e, int
|
|||
if ((r = read(fd, buffer, l)) <= 0) {
|
||||
if (r == 0) {
|
||||
fprintf(stderr, "Got EOF.\n");
|
||||
pa_stream_drain(stream, stream_drain_complete, NULL);
|
||||
pa_operation_unref(pa_stream_drain(stream, stream_drain_complete, NULL));
|
||||
} else {
|
||||
fprintf(stderr, "read() failed: %s\n", strerror(errno));
|
||||
quit(1);
|
||||
|
|
@ -259,10 +281,11 @@ static void stream_get_latency_callback(struct pa_stream *s, uint32_t latency, v
|
|||
}
|
||||
|
||||
static void sigusr1_signal_callback(struct pa_mainloop_api*m, struct pa_signal_event *e, int sig, void *userdata) {
|
||||
if (mode == PLAYBACK) {
|
||||
fprintf(stderr, "Got SIGUSR1, requesting latency.\n");
|
||||
pa_stream_get_latency(stream, stream_get_latency_callback, NULL);
|
||||
}
|
||||
if (mode != PLAYBACK)
|
||||
return;
|
||||
|
||||
fprintf(stderr, "Got SIGUSR1, requesting latency.\n");
|
||||
pa_operation_unref(pa_stream_get_latency(stream, stream_get_latency_callback, NULL));
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
|
@ -306,12 +329,9 @@ int main(int argc, char *argv[]) {
|
|||
goto quit;
|
||||
}
|
||||
|
||||
if (pa_context_connect(context, NULL, context_complete_callback, NULL) < 0) {
|
||||
fprintf(stderr, "pa_context_connext() failed.\n");
|
||||
goto quit;
|
||||
}
|
||||
|
||||
pa_context_set_die_callback(context, context_die_callback, NULL);
|
||||
pa_context_set_state_callback(context, context_state_callback, NULL);
|
||||
|
||||
pa_context_connect(context, NULL);
|
||||
|
||||
if (pa_mainloop_run(m, &ret) < 0) {
|
||||
fprintf(stderr, "pa_mainloop_run() failed.\n");
|
||||
|
|
@ -320,15 +340,21 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
quit:
|
||||
if (stream)
|
||||
pa_stream_free(stream);
|
||||
if (context)
|
||||
pa_context_free(context);
|
||||
pa_stream_unref(stream);
|
||||
|
||||
if (context)
|
||||
pa_context_unref(context);
|
||||
|
||||
if (stdio_event) {
|
||||
assert(mainloop_api);
|
||||
mainloop_api->io_free(stdio_event);
|
||||
}
|
||||
|
||||
if (m) {
|
||||
pa_signal_done();
|
||||
pa_mainloop_free(m);
|
||||
}
|
||||
|
||||
|
||||
if (buffer)
|
||||
free(buffer);
|
||||
|
||||
|
|
|
|||
148
polyp/pactl.c
148
polyp/pactl.c
|
|
@ -68,31 +68,27 @@ static void quit(int ret) {
|
|||
mainloop_api->quit(mainloop_api, ret);
|
||||
}
|
||||
|
||||
static void context_die_callback(struct pa_context *c, void *userdata) {
|
||||
assert(c);
|
||||
fprintf(stderr, "Connection to server shut down, exiting.\n");
|
||||
quit(1);
|
||||
}
|
||||
|
||||
static void context_drain_complete(struct pa_context *c, void *userdata) {
|
||||
assert(c);
|
||||
fprintf(stderr, "Connection to server shut down, exiting.\n");
|
||||
quit(0);
|
||||
pa_context_disconnect(c);
|
||||
}
|
||||
|
||||
static void drain(void) {
|
||||
if (pa_context_drain(context, context_drain_complete, NULL) < 0)
|
||||
quit(0);
|
||||
struct pa_operation *o;
|
||||
if (!(o = pa_context_drain(context, context_drain_complete, NULL)))
|
||||
pa_context_disconnect(context);
|
||||
else
|
||||
pa_operation_unref(o);
|
||||
}
|
||||
|
||||
static void stat_callback(struct pa_context *c, uint32_t blocks, uint32_t total, void *userdata) {
|
||||
if (blocks == (uint32_t) -1) {
|
||||
static void stat_callback(struct pa_context *c, const struct pa_stat_info *i, void *userdata) {
|
||||
if (!i) {
|
||||
fprintf(stderr, "Failed to get statistics: %s\n", pa_strerror(pa_context_errno(c)));
|
||||
quit(1);
|
||||
return;
|
||||
}
|
||||
|
||||
fprintf(stderr, "Currently in use: %u blocks containing %u bytes total.\n", blocks, total);
|
||||
fprintf(stderr, "Currently in use: %u blocks containing %u bytes total.\n", i->memblock_count, i->memblock_total);
|
||||
drain();
|
||||
}
|
||||
|
||||
|
|
@ -116,22 +112,23 @@ static void remove_sample_callback(struct pa_context *c, int success, void *user
|
|||
drain();
|
||||
}
|
||||
|
||||
static void stream_die_callback(struct pa_stream *s, void *userdata) {
|
||||
assert(s);
|
||||
fprintf(stderr, "Stream deleted, exiting.\n");
|
||||
quit(1);
|
||||
}
|
||||
|
||||
static void finish_sample_callback(struct pa_stream *s, int success, void *userdata) {
|
||||
static void stream_state_callback(struct pa_stream *s, void *userdata) {
|
||||
assert(s);
|
||||
|
||||
if (!success) {
|
||||
fprintf(stderr, "Failed to upload sample: %s\n", pa_strerror(pa_context_errno(context)));
|
||||
quit(1);
|
||||
return;
|
||||
switch (pa_stream_get_state(s)) {
|
||||
case PA_STREAM_CREATING:
|
||||
case PA_STREAM_READY:
|
||||
break;
|
||||
|
||||
case PA_STREAM_TERMINATED:
|
||||
drain();
|
||||
break;
|
||||
|
||||
case PA_STREAM_FAILED:
|
||||
default:
|
||||
fprintf(stderr, "Failed to upload sample: %s\n", pa_strerror(pa_context_errno(pa_stream_get_context(s))));
|
||||
quit(1);
|
||||
}
|
||||
|
||||
drain();
|
||||
}
|
||||
|
||||
static void stream_write_callback(struct pa_stream *s, size_t length, void *userdata) {
|
||||
|
|
@ -151,58 +148,55 @@ static void stream_write_callback(struct pa_stream *s, size_t length, void *user
|
|||
quit(1);
|
||||
}
|
||||
|
||||
pa_stream_write(s, d, length);
|
||||
free(d);
|
||||
pa_stream_write(s, d, length, free);
|
||||
|
||||
sample_length -= length;
|
||||
|
||||
if (sample_length <= 0) {
|
||||
pa_stream_set_write_callback(sample_stream, NULL, NULL);
|
||||
pa_stream_finish_sample(sample_stream, finish_sample_callback, NULL);
|
||||
pa_stream_finish_upload(sample_stream);
|
||||
}
|
||||
}
|
||||
|
||||
static void upload_callback(struct pa_stream *s, int success, void *userdata) {
|
||||
if (!success) {
|
||||
fprintf(stderr, "Failed to upload sample: %s\n", pa_strerror(pa_context_errno(context)));
|
||||
quit(1);
|
||||
}
|
||||
}
|
||||
|
||||
static void context_complete_callback(struct pa_context *c, int success, void *userdata) {
|
||||
static void context_state_callback(struct pa_context *c, void *userdata) {
|
||||
assert(c);
|
||||
switch (pa_context_get_state(c)) {
|
||||
case PA_CONTEXT_CONNECTING:
|
||||
case PA_CONTEXT_AUTHORIZING:
|
||||
case PA_CONTEXT_SETTING_NAME:
|
||||
break;
|
||||
|
||||
if (!success) {
|
||||
fprintf(stderr, "Connection failed: %s\n", pa_strerror(pa_context_errno(c)));
|
||||
goto fail;
|
||||
case PA_CONTEXT_READY:
|
||||
if (action == STAT)
|
||||
pa_operation_unref(pa_context_stat(c, stat_callback, NULL));
|
||||
else if (action == PLAY_SAMPLE)
|
||||
pa_operation_unref(pa_context_play_sample(c, process_argv[2], NULL, 0x100, play_sample_callback, NULL));
|
||||
else if (action == REMOVE_SAMPLE)
|
||||
pa_operation_unref(pa_context_remove_sample(c, process_argv[2], remove_sample_callback, NULL));
|
||||
else if (action == UPLOAD_SAMPLE) {
|
||||
|
||||
sample_stream = pa_stream_new(c, sample_name, &sample_spec);
|
||||
assert(sample_stream);
|
||||
|
||||
pa_stream_set_state_callback(sample_stream, stream_state_callback, NULL);
|
||||
pa_stream_set_write_callback(sample_stream, stream_write_callback, NULL);
|
||||
pa_stream_connect_upload(sample_stream, sample_length);
|
||||
} else {
|
||||
assert(action == EXIT);
|
||||
pa_context_exit_daemon(c);
|
||||
drain();
|
||||
}
|
||||
break;
|
||||
|
||||
case PA_CONTEXT_TERMINATED:
|
||||
quit(0);
|
||||
break;
|
||||
|
||||
case PA_CONTEXT_FAILED:
|
||||
default:
|
||||
fprintf(stderr, "Connection failure: %s\n", pa_strerror(pa_context_errno(c)));
|
||||
quit(1);
|
||||
}
|
||||
|
||||
fprintf(stderr, "Connection established.\n");
|
||||
|
||||
if (action == STAT)
|
||||
pa_context_stat(c, stat_callback, NULL);
|
||||
else if (action == PLAY_SAMPLE)
|
||||
pa_context_play_sample(c, process_argv[2], NULL, 0x100, play_sample_callback, NULL);
|
||||
else if (action == REMOVE_SAMPLE)
|
||||
pa_context_remove_sample(c, process_argv[2], remove_sample_callback, NULL);
|
||||
else if (action == UPLOAD_SAMPLE) {
|
||||
if (!(sample_stream = pa_context_upload_sample(c, sample_name, &sample_spec, sample_length, upload_callback, NULL))) {
|
||||
fprintf(stderr, "Failed to upload sample: %s\n", pa_strerror(pa_context_errno(c)));
|
||||
goto fail;
|
||||
}
|
||||
|
||||
pa_stream_set_die_callback(sample_stream, stream_die_callback, NULL);
|
||||
pa_stream_set_write_callback(sample_stream, stream_write_callback, NULL);
|
||||
} else {
|
||||
assert(action == EXIT);
|
||||
pa_context_exit(c);
|
||||
drain();
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
fail:
|
||||
quit(1);
|
||||
}
|
||||
|
||||
static void exit_signal_callback(struct pa_mainloop_api *m, struct pa_signal_event *e, int sig, void *userdata) {
|
||||
|
|
@ -234,12 +228,15 @@ int main(int argc, char *argv[]) {
|
|||
sample_name = argv[3];
|
||||
else {
|
||||
char *f = strrchr(argv[2], '/');
|
||||
size_t n;
|
||||
if (f)
|
||||
f++;
|
||||
else
|
||||
f = argv[2];
|
||||
|
||||
strncpy(sample_name = tmp, f, strcspn(f, "."));
|
||||
n = strcspn(f, ".");
|
||||
strncpy(sample_name = tmp, f, n);
|
||||
tmp[n] = 0;
|
||||
}
|
||||
|
||||
memset(&sfinfo, 0, sizeof(sfinfo));
|
||||
|
|
@ -292,12 +289,8 @@ int main(int argc, char *argv[]) {
|
|||
goto quit;
|
||||
}
|
||||
|
||||
if (pa_context_connect(context, NULL, context_complete_callback, NULL) < 0) {
|
||||
fprintf(stderr, "pa_context_connext() failed.\n");
|
||||
goto quit;
|
||||
}
|
||||
|
||||
pa_context_set_die_callback(context, context_die_callback, NULL);
|
||||
pa_context_set_state_callback(context, context_state_callback, NULL);
|
||||
pa_context_connect(context, NULL);
|
||||
|
||||
if (pa_mainloop_run(m, &ret) < 0) {
|
||||
fprintf(stderr, "pa_mainloop_run() failed.\n");
|
||||
|
|
@ -305,8 +298,11 @@ int main(int argc, char *argv[]) {
|
|||
}
|
||||
|
||||
quit:
|
||||
if (sample_stream)
|
||||
pa_stream_unref(sample_stream);
|
||||
|
||||
if (context)
|
||||
pa_context_free(context);
|
||||
pa_context_unref(context);
|
||||
|
||||
if (m) {
|
||||
pa_signal_done();
|
||||
|
|
@ -315,6 +311,6 @@ quit:
|
|||
|
||||
if (sndfile)
|
||||
sf_close(sndfile);
|
||||
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,5 +1,5 @@
|
|||
#ifndef foopolyplibhfoo
|
||||
#define foopolyplibhfoo
|
||||
#ifndef foopolyplibcontexthfoo
|
||||
#define foopolyplibcontexthfoo
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
|
|
@ -22,157 +22,71 @@
|
|||
USA.
|
||||
***/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "sample.h"
|
||||
#include "polyplib-def.h"
|
||||
#include "mainloop-api.h"
|
||||
#include "cdecl.h"
|
||||
#include "polyplib-operation.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
//extern "C" {
|
||||
#endif
|
||||
/** \file
|
||||
* Connection contexts */
|
||||
|
||||
PA_C_DECL_BEGIN
|
||||
|
||||
/** The state of a connection context */
|
||||
enum pa_context_state {
|
||||
PA_CONTEXT_UNCONNECTED, /**< The context hasn't been connected yet */
|
||||
PA_CONTEXT_CONNECTING, /**< A connection is being established */
|
||||
PA_CONTEXT_AUTHORIZING, /**< The client is authorizing itself to the daemon */
|
||||
PA_CONTEXT_SETTING_NAME, /**< The client is passing its application name to the daemon */
|
||||
PA_CONTEXT_READY, /**< The connection is established, the context is ready to execute operations */
|
||||
PA_CONTEXT_FAILED, /**< The connection failed or was disconnected */
|
||||
PA_CONTEXT_TERMINATED /**< The connect was terminated cleanly */
|
||||
};
|
||||
|
||||
/** \struct pa_context
|
||||
* A connection context to a daemon */
|
||||
struct pa_context;
|
||||
struct pa_stream;
|
||||
|
||||
/** Instantiate a new connection context with an abstract mainloop API
|
||||
* and an application name */
|
||||
struct pa_context *pa_context_new(struct pa_mainloop_api *mainloop, const char *name);
|
||||
|
||||
/** Decrease the reference counter of the context by one */
|
||||
void pa_context_unref(struct pa_context *c);
|
||||
|
||||
/** Increase the reference counter of the context by one */
|
||||
struct pa_context* pa_context_ref(struct pa_context *c);
|
||||
|
||||
int pa_context_connect(struct pa_context *c, const char *server, void (*complete) (struct pa_context*c, int success, void *userdata), void *userdata);
|
||||
int pa_context_drain(struct pa_context *c, void (*complete) (struct pa_context*c, void *userdata), void *userdata);
|
||||
void pa_context_set_die_callback(struct pa_context *c, void (*cb)(struct pa_context *c, void *userdata), void *userdata);
|
||||
/** Set a callback function that is called whenever the context status changes */
|
||||
void pa_context_set_state_callback(struct pa_context *c, void (*cb)(struct pa_context *c, void *userdata), void *userdata);
|
||||
|
||||
int pa_context_is_dead(struct pa_context *c);
|
||||
int pa_context_is_ready(struct pa_context *c);
|
||||
/** Return the error number of the last failed operation */
|
||||
int pa_context_errno(struct pa_context *c);
|
||||
|
||||
/** Return non-zero if some data is pending to be written to the connection */
|
||||
int pa_context_is_pending(struct pa_context *c);
|
||||
|
||||
struct pa_stream* pa_stream_new(struct pa_context *c, enum pa_stream_direction dir, const char *dev, const char *name, const struct pa_sample_spec *ss, const struct pa_buffer_attr *attr, void (*complete) (struct pa_stream*s, int success, void *userdata), void *userdata);
|
||||
void pa_stream_unref(struct pa_stream *s);
|
||||
struct pa_stream *pa_stream_ref(struct pa_stream *s);
|
||||
/** Return the current context status */
|
||||
enum pa_context_state pa_context_get_state(struct pa_context *c);
|
||||
|
||||
void pa_stream_drain(struct pa_stream *s, void (*complete) (struct pa_stream*s, void *userdata), void *userdata);
|
||||
/** Connect the context to the specified server. If server is NULL,
|
||||
connect to the default server. This routine may but will not always
|
||||
return synchronously on error. Use pa_context_set_state_callback() to
|
||||
be notified when the connection is established */
|
||||
int pa_context_connect(struct pa_context *c, const char *server);
|
||||
|
||||
void pa_stream_set_die_callback(struct pa_stream *s, void (*cb)(struct pa_stream *s, void *userdata), void *userdata);
|
||||
/** Terminate the context connection immediately */
|
||||
void pa_context_disconnect(struct pa_context *c);
|
||||
|
||||
void pa_stream_set_write_callback(struct pa_stream *p, void (*cb)(struct pa_stream *p, size_t length, void *userdata), void *userdata);
|
||||
void pa_stream_write(struct pa_stream *p, const void *data, size_t length);
|
||||
size_t pa_stream_writable_size(struct pa_stream *p);
|
||||
/** Drain the context. If there is nothing to drain, the function returns NULL */
|
||||
struct pa_operation* pa_context_drain(struct pa_context *c, void (*cb) (struct pa_context*c, void *userdata), void *userdata);
|
||||
|
||||
void pa_stream_set_read_callback(struct pa_stream *p, void (*cb)(struct pa_stream *p, const void*data, size_t length, void *userdata), void *userdata);
|
||||
/** Tell the daemon to exit. No operation object is returned as the
|
||||
* connection is terminated when the daemon quits, thus this operation
|
||||
* would never complete. */
|
||||
void pa_context_exit_daemon(struct pa_context *c);
|
||||
|
||||
int pa_stream_is_dead(struct pa_stream *p);
|
||||
int pa_stream_is_ready(struct pa_stream*p);
|
||||
|
||||
void pa_stream_get_latency(struct pa_stream *p, void (*cb)(struct pa_stream *p, uint32_t latency, void *userdata), void *userdata);
|
||||
|
||||
struct pa_context* pa_stream_get_context(struct pa_stream *p);
|
||||
|
||||
uint32_t pa_stream_get_index(struct pa_stream *s);
|
||||
|
||||
struct pa_stream* pa_context_upload_sample(struct pa_context *c, const char *name, const struct pa_sample_spec *ss, size_t length, void (*cb) (struct pa_stream*s, int success, void *userdata), void *userdata);
|
||||
void pa_stream_finish_sample(struct pa_stream *p, void (*cb)(struct pa_stream*s, int success, void *userdata), void *userdata);
|
||||
|
||||
void pa_context_play_sample(struct pa_context *c, const char *name, const char *dev, uint32_t volume, void (*cb)(struct pa_context *c, int success, void *userdata), void *userdata);
|
||||
void pa_context_remove_sample(struct pa_context *c, const char *name, void (*cb)(struct pa_context *c, int success, void *userdata), void *userdata);
|
||||
|
||||
struct pa_sink_info {
|
||||
const char *name;
|
||||
uint32_t index;
|
||||
const char *description;
|
||||
struct pa_sample_spec sample_spec;
|
||||
uint32_t owner_module;
|
||||
uint32_t volume;
|
||||
uint32_t monitor_source;
|
||||
const char *monitor_source_name;
|
||||
uint32_t latency;
|
||||
};
|
||||
|
||||
void pa_context_get_sink_info_by_name(struct pa_context *c, const char *name, void (*cb)(struct pa_context *c, const struct pa_sink_info *i, int is_last, void *userdata), void *userdata);
|
||||
void pa_context_get_sink_info_by_index(struct pa_context *c, uint32_t id, void (*cb)(struct pa_context *c, const struct pa_sink_info *i, int is_last, void *userdata), void *userdata);
|
||||
void pa_context_get_sink_info_list(struct pa_context *c, void (*cb)(struct pa_context *c, const struct pa_sink_info *i, int is_last, void *userdata), void *userdata);
|
||||
|
||||
struct pa_source_info {
|
||||
const char *name;
|
||||
uint32_t index;
|
||||
const char *description;
|
||||
struct pa_sample_spec sample_spec;
|
||||
uint32_t owner_module;
|
||||
uint32_t monitor_of_sink;
|
||||
const char *monitor_of_sink_name;
|
||||
};
|
||||
|
||||
void pa_context_get_source_info_by_name(struct pa_context *c, const char *name, void (*cb)(struct pa_context *c, const struct pa_source_info *i, int is_last, void *userdata), void *userdata);
|
||||
void pa_context_get_source_info_by_index(struct pa_context *c, uint32_t id, void (*cb)(struct pa_context *c, const struct pa_source_info *i, int is_last, void *userdata), void *userdata);
|
||||
void pa_context_get_source_info_list(struct pa_context *c, void (*cb)(struct pa_context *c, const struct pa_source_info *i, int is_last, void *userdata), void *userdata);
|
||||
|
||||
struct pa_server_info {
|
||||
const char *user_name;
|
||||
const char *host_name;
|
||||
const char *server_version;
|
||||
const char *server_name;
|
||||
struct pa_sample_spec sample_spec;
|
||||
};
|
||||
|
||||
void pa_context_get_server_info(struct pa_context *c, void (*cb)(struct pa_context *c, const struct pa_server_info*i, void *userdata), void *userdata);
|
||||
|
||||
struct pa_module_info {
|
||||
uint32_t index;
|
||||
const char*name, *argument;
|
||||
uint32_t n_used, auto_unload;
|
||||
};
|
||||
|
||||
void pa_context_get_module_info(struct pa_context *c, uint32_t index, void (*cb)(struct pa_context *c, const struct pa_module_info*i, int is_last, void *userdata), void *userdata);
|
||||
void pa_context_get_module_info_list(struct pa_context *c, void (*cb)(struct pa_context *c, const struct pa_module_info*i, int is_last, void *userdata), void *userdata);
|
||||
|
||||
struct pa_client_info {
|
||||
uint32_t index;
|
||||
const char *name;
|
||||
uint32_t owner_module;
|
||||
const char *protocol_name;
|
||||
};
|
||||
|
||||
void pa_context_get_client_info(struct pa_context *c, uint32_t index, void (*cb)(struct pa_context *c, const struct pa_client_info*i, int is_last, void *userdata), void *userdata);
|
||||
void pa_context_get_client_info_list(struct pa_context *c, void (*cb)(struct pa_context *c, const struct pa_client_info*i, int is_last, void *userdata), void *userdata);
|
||||
|
||||
struct pa_sink_input_info {
|
||||
uint32_t index;
|
||||
const char *name;
|
||||
uint32_t owner_module;
|
||||
uint32_t owner_client;
|
||||
uint32_t sink;
|
||||
struct pa_sample_spec sample_spec;
|
||||
uint32_t volume;
|
||||
uint32_t latency;
|
||||
};
|
||||
|
||||
void pa_context_get_sink_input_info(struct pa_context *c, uint32_t index, void (*cb)(struct pa_context *c, const struct pa_sink_input_info*i, int is_last, void *userdata), void *userdata);
|
||||
void pa_context_get_sink_input_info_list(struct pa_context *c, void (*cb)(struct pa_context *c, const struct pa_sink_input_info*i, int is_last, void *userdata), void *userdata);
|
||||
|
||||
struct pa_source_output_info {
|
||||
uint32_t index;
|
||||
const char *name;
|
||||
uint32_t owner_module;
|
||||
uint32_t owner_client;
|
||||
uint32_t source;
|
||||
struct pa_sample_spec sample_spec;
|
||||
};
|
||||
|
||||
void pa_context_get_source_output_info(struct pa_context *c, uint32_t index, void (*cb)(struct pa_context *c, const struct pa_source_output_info*i, int is_last, void *userdata), void *userdata);
|
||||
void pa_context_get_source_output_info_list(struct pa_context *c, void (*cb)(struct pa_context *c, const struct pa_source_output_info*i, int is_last, void *userdata), void *userdata);
|
||||
|
||||
void pa_context_set_sink_volume(struct pa_context *c, uint32_t index, uint32_t volume, void (*cb)(struct pa_context *c, int success, void *userdata), void *userdata);
|
||||
void pa_context_set_sink_input_volume(struct pa_context *c, uint32_t index, uint32_t volume, void (*cb)(struct pa_context *c, int success, void *userdata), void *userdata);
|
||||
|
||||
void pa_context_exit(struct pa_context *c);
|
||||
void pa_context_stat(struct pa_context *c, void (*cb)(struct pa_context *c, uint32_t count, uint32_t total, void *userdata), void *userdata);
|
||||
|
||||
void pa_context_subscribe(struct pa_context *c, enum pa_subscription_mask m, void (*cb)(struct pa_context *c, enum pa_subscription_event_type t, uint32_t index, void *userdata), void *userdata);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
PA_C_DECL_END
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -23,14 +23,13 @@
|
|||
***/
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "native-common.h"
|
||||
#include "cdecl.h"
|
||||
|
||||
PA_C_DECL_BEGIN
|
||||
|
||||
enum pa_stream_direction {
|
||||
PA_STREAM_NODIRECTION,
|
||||
PA_STREAM_PLAYBACK,
|
||||
PA_STREAM_RECORD,
|
||||
PA_STREAM_UPLOAD
|
||||
|
|
@ -43,9 +42,9 @@ struct pa_buffer_attr {
|
|||
uint32_t minreq;
|
||||
uint32_t fragsize;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#define PA_INVALID_INDEX ((uint32_t) -1)
|
||||
|
||||
PA_C_DECL_END
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -23,15 +23,13 @@
|
|||
***/
|
||||
|
||||
#include <inttypes.h>
|
||||
#include "cdecl.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
PA_C_DECL_BEGIN;
|
||||
|
||||
/** Return a human readable error message for the specified numeric error code */
|
||||
const char* pa_strerror(uint32_t error);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
PA_C_DECL_END;
|
||||
|
||||
#endif
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
|
@ -1,5 +1,5 @@
|
|||
#ifndef foopolyplibhfoo
|
||||
#define foopolyplibhfoo
|
||||
#ifndef foopolyplibintrospecthfoo
|
||||
#define foopolyplibintrospecthfoo
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
|
|
@ -22,61 +22,13 @@
|
|||
USA.
|
||||
***/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "sample.h"
|
||||
#include "polyplib-def.h"
|
||||
#include "mainloop-api.h"
|
||||
#include "polyplib-operation.h"
|
||||
#include "polyplib-context.h"
|
||||
#include "cdecl.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
//extern "C" {
|
||||
#endif
|
||||
|
||||
struct pa_context;
|
||||
struct pa_stream;
|
||||
|
||||
struct pa_context *pa_context_new(struct pa_mainloop_api *mainloop, const char *name);
|
||||
void pa_context_unref(struct pa_context *c);
|
||||
struct pa_context* pa_context_ref(struct pa_context *c);
|
||||
|
||||
int pa_context_connect(struct pa_context *c, const char *server, void (*complete) (struct pa_context*c, int success, void *userdata), void *userdata);
|
||||
int pa_context_drain(struct pa_context *c, void (*complete) (struct pa_context*c, void *userdata), void *userdata);
|
||||
void pa_context_set_die_callback(struct pa_context *c, void (*cb)(struct pa_context *c, void *userdata), void *userdata);
|
||||
|
||||
int pa_context_is_dead(struct pa_context *c);
|
||||
int pa_context_is_ready(struct pa_context *c);
|
||||
int pa_context_errno(struct pa_context *c);
|
||||
|
||||
int pa_context_is_pending(struct pa_context *c);
|
||||
|
||||
struct pa_stream* pa_stream_new(struct pa_context *c, enum pa_stream_direction dir, const char *dev, const char *name, const struct pa_sample_spec *ss, const struct pa_buffer_attr *attr, void (*complete) (struct pa_stream*s, int success, void *userdata), void *userdata);
|
||||
void pa_stream_unref(struct pa_stream *s);
|
||||
struct pa_stream *pa_stream_ref(struct pa_stream *s);
|
||||
|
||||
void pa_stream_drain(struct pa_stream *s, void (*complete) (struct pa_stream*s, void *userdata), void *userdata);
|
||||
|
||||
void pa_stream_set_die_callback(struct pa_stream *s, void (*cb)(struct pa_stream *s, void *userdata), void *userdata);
|
||||
|
||||
void pa_stream_set_write_callback(struct pa_stream *p, void (*cb)(struct pa_stream *p, size_t length, void *userdata), void *userdata);
|
||||
void pa_stream_write(struct pa_stream *p, const void *data, size_t length);
|
||||
size_t pa_stream_writable_size(struct pa_stream *p);
|
||||
|
||||
void pa_stream_set_read_callback(struct pa_stream *p, void (*cb)(struct pa_stream *p, const void*data, size_t length, void *userdata), void *userdata);
|
||||
|
||||
int pa_stream_is_dead(struct pa_stream *p);
|
||||
int pa_stream_is_ready(struct pa_stream*p);
|
||||
|
||||
void pa_stream_get_latency(struct pa_stream *p, void (*cb)(struct pa_stream *p, uint32_t latency, void *userdata), void *userdata);
|
||||
|
||||
struct pa_context* pa_stream_get_context(struct pa_stream *p);
|
||||
|
||||
uint32_t pa_stream_get_index(struct pa_stream *s);
|
||||
|
||||
struct pa_stream* pa_context_upload_sample(struct pa_context *c, const char *name, const struct pa_sample_spec *ss, size_t length, void (*cb) (struct pa_stream*s, int success, void *userdata), void *userdata);
|
||||
void pa_stream_finish_sample(struct pa_stream *p, void (*cb)(struct pa_stream*s, int success, void *userdata), void *userdata);
|
||||
|
||||
void pa_context_play_sample(struct pa_context *c, const char *name, const char *dev, uint32_t volume, void (*cb)(struct pa_context *c, int success, void *userdata), void *userdata);
|
||||
void pa_context_remove_sample(struct pa_context *c, const char *name, void (*cb)(struct pa_context *c, int success, void *userdata), void *userdata);
|
||||
PA_C_DECL_BEGIN
|
||||
|
||||
struct pa_sink_info {
|
||||
const char *name;
|
||||
|
|
@ -90,9 +42,9 @@ struct pa_sink_info {
|
|||
uint32_t latency;
|
||||
};
|
||||
|
||||
void pa_context_get_sink_info_by_name(struct pa_context *c, const char *name, void (*cb)(struct pa_context *c, const struct pa_sink_info *i, int is_last, void *userdata), void *userdata);
|
||||
void pa_context_get_sink_info_by_index(struct pa_context *c, uint32_t id, void (*cb)(struct pa_context *c, const struct pa_sink_info *i, int is_last, void *userdata), void *userdata);
|
||||
void pa_context_get_sink_info_list(struct pa_context *c, void (*cb)(struct pa_context *c, const struct pa_sink_info *i, int is_last, void *userdata), void *userdata);
|
||||
struct pa_operation* pa_context_get_sink_info_by_name(struct pa_context *c, const char *name, void (*cb)(struct pa_context *c, const struct pa_sink_info *i, int is_last, void *userdata), void *userdata);
|
||||
struct pa_operation* pa_context_get_sink_info_by_index(struct pa_context *c, uint32_t id, void (*cb)(struct pa_context *c, const struct pa_sink_info *i, int is_last, void *userdata), void *userdata);
|
||||
struct pa_operation* pa_context_get_sink_info_list(struct pa_context *c, void (*cb)(struct pa_context *c, const struct pa_sink_info *i, int is_last, void *userdata), void *userdata);
|
||||
|
||||
struct pa_source_info {
|
||||
const char *name;
|
||||
|
|
@ -104,9 +56,9 @@ struct pa_source_info {
|
|||
const char *monitor_of_sink_name;
|
||||
};
|
||||
|
||||
void pa_context_get_source_info_by_name(struct pa_context *c, const char *name, void (*cb)(struct pa_context *c, const struct pa_source_info *i, int is_last, void *userdata), void *userdata);
|
||||
void pa_context_get_source_info_by_index(struct pa_context *c, uint32_t id, void (*cb)(struct pa_context *c, const struct pa_source_info *i, int is_last, void *userdata), void *userdata);
|
||||
void pa_context_get_source_info_list(struct pa_context *c, void (*cb)(struct pa_context *c, const struct pa_source_info *i, int is_last, void *userdata), void *userdata);
|
||||
struct pa_operation* pa_context_get_source_info_by_name(struct pa_context *c, const char *name, void (*cb)(struct pa_context *c, const struct pa_source_info *i, int is_last, void *userdata), void *userdata);
|
||||
struct pa_operation* pa_context_get_source_info_by_index(struct pa_context *c, uint32_t id, void (*cb)(struct pa_context *c, const struct pa_source_info *i, int is_last, void *userdata), void *userdata);
|
||||
struct pa_operation* pa_context_get_source_info_list(struct pa_context *c, void (*cb)(struct pa_context *c, const struct pa_source_info *i, int is_last, void *userdata), void *userdata);
|
||||
|
||||
struct pa_server_info {
|
||||
const char *user_name;
|
||||
|
|
@ -116,7 +68,7 @@ struct pa_server_info {
|
|||
struct pa_sample_spec sample_spec;
|
||||
};
|
||||
|
||||
void pa_context_get_server_info(struct pa_context *c, void (*cb)(struct pa_context *c, const struct pa_server_info*i, void *userdata), void *userdata);
|
||||
struct pa_operation* pa_context_get_server_info(struct pa_context *c, void (*cb)(struct pa_context *c, const struct pa_server_info*i, void *userdata), void *userdata);
|
||||
|
||||
struct pa_module_info {
|
||||
uint32_t index;
|
||||
|
|
@ -124,8 +76,8 @@ struct pa_module_info {
|
|||
uint32_t n_used, auto_unload;
|
||||
};
|
||||
|
||||
void pa_context_get_module_info(struct pa_context *c, uint32_t index, void (*cb)(struct pa_context *c, const struct pa_module_info*i, int is_last, void *userdata), void *userdata);
|
||||
void pa_context_get_module_info_list(struct pa_context *c, void (*cb)(struct pa_context *c, const struct pa_module_info*i, int is_last, void *userdata), void *userdata);
|
||||
struct pa_operation* pa_context_get_module_info(struct pa_context *c, uint32_t index, void (*cb)(struct pa_context *c, const struct pa_module_info*i, int is_last, void *userdata), void *userdata);
|
||||
struct pa_operation* pa_context_get_module_info_list(struct pa_context *c, void (*cb)(struct pa_context *c, const struct pa_module_info*i, int is_last, void *userdata), void *userdata);
|
||||
|
||||
struct pa_client_info {
|
||||
uint32_t index;
|
||||
|
|
@ -134,8 +86,8 @@ struct pa_client_info {
|
|||
const char *protocol_name;
|
||||
};
|
||||
|
||||
void pa_context_get_client_info(struct pa_context *c, uint32_t index, void (*cb)(struct pa_context *c, const struct pa_client_info*i, int is_last, void *userdata), void *userdata);
|
||||
void pa_context_get_client_info_list(struct pa_context *c, void (*cb)(struct pa_context *c, const struct pa_client_info*i, int is_last, void *userdata), void *userdata);
|
||||
struct pa_operation* pa_context_get_client_info(struct pa_context *c, uint32_t index, void (*cb)(struct pa_context *c, const struct pa_client_info*i, int is_last, void *userdata), void *userdata);
|
||||
struct pa_operation* pa_context_get_client_info_list(struct pa_context *c, void (*cb)(struct pa_context *c, const struct pa_client_info*i, int is_last, void *userdata), void *userdata);
|
||||
|
||||
struct pa_sink_input_info {
|
||||
uint32_t index;
|
||||
|
|
@ -148,8 +100,8 @@ struct pa_sink_input_info {
|
|||
uint32_t latency;
|
||||
};
|
||||
|
||||
void pa_context_get_sink_input_info(struct pa_context *c, uint32_t index, void (*cb)(struct pa_context *c, const struct pa_sink_input_info*i, int is_last, void *userdata), void *userdata);
|
||||
void pa_context_get_sink_input_info_list(struct pa_context *c, void (*cb)(struct pa_context *c, const struct pa_sink_input_info*i, int is_last, void *userdata), void *userdata);
|
||||
struct pa_operation* pa_context_get_sink_input_info(struct pa_context *c, uint32_t index, void (*cb)(struct pa_context *c, const struct pa_sink_input_info*i, int is_last, void *userdata), void *userdata);
|
||||
struct pa_operation* pa_context_get_sink_input_info_list(struct pa_context *c, void (*cb)(struct pa_context *c, const struct pa_sink_input_info*i, int is_last, void *userdata), void *userdata);
|
||||
|
||||
struct pa_source_output_info {
|
||||
uint32_t index;
|
||||
|
|
@ -160,19 +112,20 @@ struct pa_source_output_info {
|
|||
struct pa_sample_spec sample_spec;
|
||||
};
|
||||
|
||||
void pa_context_get_source_output_info(struct pa_context *c, uint32_t index, void (*cb)(struct pa_context *c, const struct pa_source_output_info*i, int is_last, void *userdata), void *userdata);
|
||||
void pa_context_get_source_output_info_list(struct pa_context *c, void (*cb)(struct pa_context *c, const struct pa_source_output_info*i, int is_last, void *userdata), void *userdata);
|
||||
struct pa_operation* pa_context_get_source_output_info(struct pa_context *c, uint32_t index, void (*cb)(struct pa_context *c, const struct pa_source_output_info*i, int is_last, void *userdata), void *userdata);
|
||||
struct pa_operation* pa_context_get_source_output_info_list(struct pa_context *c, void (*cb)(struct pa_context *c, const struct pa_source_output_info*i, int is_last, void *userdata), void *userdata);
|
||||
|
||||
void pa_context_set_sink_volume(struct pa_context *c, uint32_t index, uint32_t volume, void (*cb)(struct pa_context *c, int success, void *userdata), void *userdata);
|
||||
void pa_context_set_sink_input_volume(struct pa_context *c, uint32_t index, uint32_t volume, void (*cb)(struct pa_context *c, int success, void *userdata), void *userdata);
|
||||
struct pa_operation* pa_context_set_sink_volume_by_index(struct pa_context *c, uint32_t index, uint32_t volume, void (*cb)(struct pa_context *c, int success, void *userdata), void *userdata);
|
||||
struct pa_operation* pa_context_set_sink_volume_by_name(struct pa_context *c, const char *name, uint32_t volume, void (*cb)(struct pa_context *c, int success, void *userdata), void *userdata);
|
||||
struct pa_operation* pa_context_set_sink_input_volume(struct pa_context *c, uint32_t index, uint32_t volume, void (*cb)(struct pa_context *c, int success, void *userdata), void *userdata);
|
||||
|
||||
void pa_context_exit(struct pa_context *c);
|
||||
void pa_context_stat(struct pa_context *c, void (*cb)(struct pa_context *c, uint32_t count, uint32_t total, void *userdata), void *userdata);
|
||||
struct pa_stat_info {
|
||||
uint32_t memblock_count;
|
||||
uint32_t memblock_total;
|
||||
};
|
||||
|
||||
void pa_context_subscribe(struct pa_context *c, enum pa_subscription_mask m, void (*cb)(struct pa_context *c, enum pa_subscription_event_type t, uint32_t index, void *userdata), void *userdata);
|
||||
struct pa_operation* pa_context_stat(struct pa_context *c, void (*cb)(struct pa_context *c, const struct pa_stat_info *i, void *userdata), void *userdata);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
PA_C_DECL_END
|
||||
|
||||
#endif
|
||||
|
|
|
|||
78
polyp/polyplib-operation.c
Normal file
78
polyp/polyplib-operation.c
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
#include <assert.h>
|
||||
|
||||
#include "xmalloc.h"
|
||||
#include "polyplib-internal.h"
|
||||
#include "polyplib-operation.h"
|
||||
|
||||
struct pa_operation *pa_operation_new(struct pa_context *c, struct pa_stream *s) {
|
||||
struct pa_operation *o;
|
||||
assert(c);
|
||||
|
||||
o = pa_xmalloc(sizeof(struct pa_operation));
|
||||
o->ref = 1;
|
||||
o->context = pa_context_ref(c);
|
||||
o->stream = s ? pa_stream_ref(s) : NULL;
|
||||
|
||||
o->state = PA_OPERATION_RUNNING;
|
||||
o->userdata = NULL;
|
||||
o->callback = NULL;
|
||||
|
||||
PA_LLIST_PREPEND(struct pa_operation, o->context->operations, o);
|
||||
return pa_operation_ref(o);
|
||||
}
|
||||
|
||||
struct pa_operation *pa_operation_ref(struct pa_operation *o) {
|
||||
assert(o && o->ref >= 1);
|
||||
o->ref++;
|
||||
return o;
|
||||
}
|
||||
|
||||
void pa_operation_unref(struct pa_operation *o) {
|
||||
assert(o && o->ref >= 1);
|
||||
|
||||
if ((--(o->ref)) == 0) {
|
||||
assert(!o->context);
|
||||
assert(!o->stream);
|
||||
free(o);
|
||||
}
|
||||
}
|
||||
|
||||
static void operation_set_state(struct pa_operation *o, enum pa_operation_state st) {
|
||||
assert(o && o->ref >= 1);
|
||||
|
||||
if (st == o->state)
|
||||
return;
|
||||
|
||||
if (!o->context)
|
||||
return;
|
||||
|
||||
o->state = st;
|
||||
|
||||
if ((o->state == PA_OPERATION_DONE) || (o->state == PA_OPERATION_CANCELED)) {
|
||||
PA_LLIST_REMOVE(struct pa_operation, o->context->operations, o);
|
||||
pa_context_unref(o->context);
|
||||
if (o->stream)
|
||||
pa_stream_unref(o->stream);
|
||||
o->context = NULL;
|
||||
o->stream = NULL;
|
||||
o->callback = NULL;
|
||||
o->userdata = NULL;
|
||||
|
||||
pa_operation_unref(o);
|
||||
}
|
||||
}
|
||||
|
||||
void pa_operation_cancel(struct pa_operation *o) {
|
||||
assert(o && o->ref >= 1);
|
||||
operation_set_state(o, PA_OPERATION_CANCELED);
|
||||
}
|
||||
|
||||
void pa_operation_done(struct pa_operation *o) {
|
||||
assert(o && o->ref >= 1);
|
||||
operation_set_state(o, PA_OPERATION_DONE);
|
||||
}
|
||||
|
||||
enum pa_operation_state pa_operation_get_state(struct pa_operation *o) {
|
||||
assert(o && o->ref >= 1);
|
||||
return o->state;
|
||||
}
|
||||
56
polyp/polyplib-operation.h
Normal file
56
polyp/polyplib-operation.h
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
#ifndef foopolypliboperationhfoo
|
||||
#define foopolypliboperationhfoo
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/***
|
||||
This file is part of polypaudio.
|
||||
|
||||
polypaudio is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published
|
||||
by the Free Software Foundation; either version 2 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
polypaudio is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with polypaudio; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
USA.
|
||||
***/
|
||||
|
||||
#include "cdecl.h"
|
||||
|
||||
/** \file
|
||||
* Asynchronous operations */
|
||||
|
||||
PA_C_DECL_BEGIN
|
||||
|
||||
enum pa_operation_state {
|
||||
PA_OPERATION_RUNNING, /**< The operation is still running */
|
||||
PA_OPERATION_DONE, /**< The operation has been completed */
|
||||
PA_OPERATION_CANCELED, /**< The operation has been canceled */
|
||||
};
|
||||
|
||||
/** \struct pa_operation
|
||||
* An asynchronous operation object */
|
||||
struct pa_operation;
|
||||
|
||||
/** Increase the reference count by one */
|
||||
struct pa_operation *pa_operation_ref(struct pa_operation *o);
|
||||
|
||||
/** Decrease the reference count by one */
|
||||
void pa_operation_unref(struct pa_operation *o);
|
||||
|
||||
/** Cancel the operation. Beware! This will not necessarily cancel the execution of the operation on the server side. */
|
||||
void pa_operation_cancel(struct pa_operation *o);
|
||||
|
||||
/** Return the current status of the operation */
|
||||
enum pa_operation_state pa_operation_get_state(struct pa_operation *o);
|
||||
|
||||
PA_C_DECL_END
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,178 +0,0 @@
|
|||
#ifndef foopolyplibhfoo
|
||||
#define foopolyplibhfoo
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/***
|
||||
This file is part of polypaudio.
|
||||
|
||||
polypaudio is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published
|
||||
by the Free Software Foundation; either version 2 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
polypaudio is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with polypaudio; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
USA.
|
||||
***/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "sample.h"
|
||||
#include "polyplib-def.h"
|
||||
#include "mainloop-api.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
//extern "C" {
|
||||
#endif
|
||||
|
||||
struct pa_context;
|
||||
struct pa_stream;
|
||||
|
||||
struct pa_context *pa_context_new(struct pa_mainloop_api *mainloop, const char *name);
|
||||
void pa_context_unref(struct pa_context *c);
|
||||
struct pa_context* pa_context_ref(struct pa_context *c);
|
||||
|
||||
int pa_context_connect(struct pa_context *c, const char *server, void (*complete) (struct pa_context*c, int success, void *userdata), void *userdata);
|
||||
int pa_context_drain(struct pa_context *c, void (*complete) (struct pa_context*c, void *userdata), void *userdata);
|
||||
void pa_context_set_die_callback(struct pa_context *c, void (*cb)(struct pa_context *c, void *userdata), void *userdata);
|
||||
|
||||
int pa_context_is_dead(struct pa_context *c);
|
||||
int pa_context_is_ready(struct pa_context *c);
|
||||
int pa_context_errno(struct pa_context *c);
|
||||
|
||||
int pa_context_is_pending(struct pa_context *c);
|
||||
|
||||
struct pa_stream* pa_stream_new(struct pa_context *c, enum pa_stream_direction dir, const char *dev, const char *name, const struct pa_sample_spec *ss, const struct pa_buffer_attr *attr, void (*complete) (struct pa_stream*s, int success, void *userdata), void *userdata);
|
||||
void pa_stream_unref(struct pa_stream *s);
|
||||
struct pa_stream *pa_stream_ref(struct pa_stream *s);
|
||||
|
||||
void pa_stream_drain(struct pa_stream *s, void (*complete) (struct pa_stream*s, void *userdata), void *userdata);
|
||||
|
||||
void pa_stream_set_die_callback(struct pa_stream *s, void (*cb)(struct pa_stream *s, void *userdata), void *userdata);
|
||||
|
||||
void pa_stream_set_write_callback(struct pa_stream *p, void (*cb)(struct pa_stream *p, size_t length, void *userdata), void *userdata);
|
||||
void pa_stream_write(struct pa_stream *p, const void *data, size_t length);
|
||||
size_t pa_stream_writable_size(struct pa_stream *p);
|
||||
|
||||
void pa_stream_set_read_callback(struct pa_stream *p, void (*cb)(struct pa_stream *p, const void*data, size_t length, void *userdata), void *userdata);
|
||||
|
||||
int pa_stream_is_dead(struct pa_stream *p);
|
||||
int pa_stream_is_ready(struct pa_stream*p);
|
||||
|
||||
void pa_stream_get_latency(struct pa_stream *p, void (*cb)(struct pa_stream *p, uint32_t latency, void *userdata), void *userdata);
|
||||
|
||||
struct pa_context* pa_stream_get_context(struct pa_stream *p);
|
||||
|
||||
uint32_t pa_stream_get_index(struct pa_stream *s);
|
||||
|
||||
struct pa_stream* pa_context_upload_sample(struct pa_context *c, const char *name, const struct pa_sample_spec *ss, size_t length, void (*cb) (struct pa_stream*s, int success, void *userdata), void *userdata);
|
||||
void pa_stream_finish_sample(struct pa_stream *p, void (*cb)(struct pa_stream*s, int success, void *userdata), void *userdata);
|
||||
|
||||
void pa_context_play_sample(struct pa_context *c, const char *name, const char *dev, uint32_t volume, void (*cb)(struct pa_context *c, int success, void *userdata), void *userdata);
|
||||
void pa_context_remove_sample(struct pa_context *c, const char *name, void (*cb)(struct pa_context *c, int success, void *userdata), void *userdata);
|
||||
|
||||
struct pa_sink_info {
|
||||
const char *name;
|
||||
uint32_t index;
|
||||
const char *description;
|
||||
struct pa_sample_spec sample_spec;
|
||||
uint32_t owner_module;
|
||||
uint32_t volume;
|
||||
uint32_t monitor_source;
|
||||
const char *monitor_source_name;
|
||||
uint32_t latency;
|
||||
};
|
||||
|
||||
void pa_context_get_sink_info_by_name(struct pa_context *c, const char *name, void (*cb)(struct pa_context *c, const struct pa_sink_info *i, int is_last, void *userdata), void *userdata);
|
||||
void pa_context_get_sink_info_by_index(struct pa_context *c, uint32_t id, void (*cb)(struct pa_context *c, const struct pa_sink_info *i, int is_last, void *userdata), void *userdata);
|
||||
void pa_context_get_sink_info_list(struct pa_context *c, void (*cb)(struct pa_context *c, const struct pa_sink_info *i, int is_last, void *userdata), void *userdata);
|
||||
|
||||
struct pa_source_info {
|
||||
const char *name;
|
||||
uint32_t index;
|
||||
const char *description;
|
||||
struct pa_sample_spec sample_spec;
|
||||
uint32_t owner_module;
|
||||
uint32_t monitor_of_sink;
|
||||
const char *monitor_of_sink_name;
|
||||
};
|
||||
|
||||
void pa_context_get_source_info_by_name(struct pa_context *c, const char *name, void (*cb)(struct pa_context *c, const struct pa_source_info *i, int is_last, void *userdata), void *userdata);
|
||||
void pa_context_get_source_info_by_index(struct pa_context *c, uint32_t id, void (*cb)(struct pa_context *c, const struct pa_source_info *i, int is_last, void *userdata), void *userdata);
|
||||
void pa_context_get_source_info_list(struct pa_context *c, void (*cb)(struct pa_context *c, const struct pa_source_info *i, int is_last, void *userdata), void *userdata);
|
||||
|
||||
struct pa_server_info {
|
||||
const char *user_name;
|
||||
const char *host_name;
|
||||
const char *server_version;
|
||||
const char *server_name;
|
||||
struct pa_sample_spec sample_spec;
|
||||
};
|
||||
|
||||
void pa_context_get_server_info(struct pa_context *c, void (*cb)(struct pa_context *c, const struct pa_server_info*i, void *userdata), void *userdata);
|
||||
|
||||
struct pa_module_info {
|
||||
uint32_t index;
|
||||
const char*name, *argument;
|
||||
uint32_t n_used, auto_unload;
|
||||
};
|
||||
|
||||
void pa_context_get_module_info(struct pa_context *c, uint32_t index, void (*cb)(struct pa_context *c, const struct pa_module_info*i, int is_last, void *userdata), void *userdata);
|
||||
void pa_context_get_module_info_list(struct pa_context *c, void (*cb)(struct pa_context *c, const struct pa_module_info*i, int is_last, void *userdata), void *userdata);
|
||||
|
||||
struct pa_client_info {
|
||||
uint32_t index;
|
||||
const char *name;
|
||||
uint32_t owner_module;
|
||||
const char *protocol_name;
|
||||
};
|
||||
|
||||
void pa_context_get_client_info(struct pa_context *c, uint32_t index, void (*cb)(struct pa_context *c, const struct pa_client_info*i, int is_last, void *userdata), void *userdata);
|
||||
void pa_context_get_client_info_list(struct pa_context *c, void (*cb)(struct pa_context *c, const struct pa_client_info*i, int is_last, void *userdata), void *userdata);
|
||||
|
||||
struct pa_sink_input_info {
|
||||
uint32_t index;
|
||||
const char *name;
|
||||
uint32_t owner_module;
|
||||
uint32_t owner_client;
|
||||
uint32_t sink;
|
||||
struct pa_sample_spec sample_spec;
|
||||
uint32_t volume;
|
||||
uint32_t latency;
|
||||
};
|
||||
|
||||
void pa_context_get_sink_input_info(struct pa_context *c, uint32_t index, void (*cb)(struct pa_context *c, const struct pa_sink_input_info*i, int is_last, void *userdata), void *userdata);
|
||||
void pa_context_get_sink_input_info_list(struct pa_context *c, void (*cb)(struct pa_context *c, const struct pa_sink_input_info*i, int is_last, void *userdata), void *userdata);
|
||||
|
||||
struct pa_source_output_info {
|
||||
uint32_t index;
|
||||
const char *name;
|
||||
uint32_t owner_module;
|
||||
uint32_t owner_client;
|
||||
uint32_t source;
|
||||
struct pa_sample_spec sample_spec;
|
||||
};
|
||||
|
||||
void pa_context_get_source_output_info(struct pa_context *c, uint32_t index, void (*cb)(struct pa_context *c, const struct pa_source_output_info*i, int is_last, void *userdata), void *userdata);
|
||||
void pa_context_get_source_output_info_list(struct pa_context *c, void (*cb)(struct pa_context *c, const struct pa_source_output_info*i, int is_last, void *userdata), void *userdata);
|
||||
|
||||
void pa_context_set_sink_volume(struct pa_context *c, uint32_t index, uint32_t volume, void (*cb)(struct pa_context *c, int success, void *userdata), void *userdata);
|
||||
void pa_context_set_sink_input_volume(struct pa_context *c, uint32_t index, uint32_t volume, void (*cb)(struct pa_context *c, int success, void *userdata), void *userdata);
|
||||
|
||||
void pa_context_exit(struct pa_context *c);
|
||||
void pa_context_stat(struct pa_context *c, void (*cb)(struct pa_context *c, uint32_t count, uint32_t total, void *userdata), void *userdata);
|
||||
|
||||
void pa_context_subscribe(struct pa_context *c, enum pa_subscription_mask m, void (*cb)(struct pa_context *c, enum pa_subscription_event_type t, uint32_t index, void *userdata), void *userdata);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,5 +1,5 @@
|
|||
#ifndef foopolyplibhfoo
|
||||
#define foopolyplibhfoo
|
||||
#ifndef foopolyplibscachehfoo
|
||||
#define foopolyplibscachehfoo
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
|
|
@ -24,155 +24,27 @@
|
|||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "sample.h"
|
||||
#include "polyplib-def.h"
|
||||
#include "mainloop-api.h"
|
||||
#include "polyplib-context.h"
|
||||
#include "polyplib-stream.h"
|
||||
#include "cdecl.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
//extern "C" {
|
||||
#endif
|
||||
/** \file
|
||||
* All sample cache related routines */
|
||||
|
||||
struct pa_context;
|
||||
struct pa_stream;
|
||||
PA_C_DECL_BEGIN
|
||||
|
||||
struct pa_context *pa_context_new(struct pa_mainloop_api *mainloop, const char *name);
|
||||
void pa_context_unref(struct pa_context *c);
|
||||
struct pa_context* pa_context_ref(struct pa_context *c);
|
||||
/** Make this stream a sample upload stream */
|
||||
void pa_stream_connect_upload(struct pa_stream *s, size_t length);
|
||||
|
||||
int pa_context_connect(struct pa_context *c, const char *server, void (*complete) (struct pa_context*c, int success, void *userdata), void *userdata);
|
||||
int pa_context_drain(struct pa_context *c, void (*complete) (struct pa_context*c, void *userdata), void *userdata);
|
||||
void pa_context_set_die_callback(struct pa_context *c, void (*cb)(struct pa_context *c, void *userdata), void *userdata);
|
||||
/** Finish the sample upload, the stream name will become the sample name. You cancel a sample upload by issuing pa_stream_disconnect() */
|
||||
void pa_stream_finish_upload(struct pa_stream *s);
|
||||
|
||||
int pa_context_is_dead(struct pa_context *c);
|
||||
int pa_context_is_ready(struct pa_context *c);
|
||||
int pa_context_errno(struct pa_context *c);
|
||||
/** Play a sample from the sample cache to the specified device. If the latter is NULL use the default sink. Returns an operation object */
|
||||
struct pa_operation* pa_context_play_sample(struct pa_context *c, const char *name, const char *dev, uint32_t volume, void (*cb)(struct pa_context *c, int success, void *userdata), void *userdata);
|
||||
|
||||
int pa_context_is_pending(struct pa_context *c);
|
||||
/** Remove a sample from the sample cache. Returns an operation object which may be used to cancel the operation while it is running */
|
||||
struct pa_operation* pa_context_remove_sample(struct pa_context *c, const char *name, void (*cb)(struct pa_context *c, int success, void *userdata), void *userdata);
|
||||
|
||||
struct pa_stream* pa_stream_new(struct pa_context *c, enum pa_stream_direction dir, const char *dev, const char *name, const struct pa_sample_spec *ss, const struct pa_buffer_attr *attr, void (*complete) (struct pa_stream*s, int success, void *userdata), void *userdata);
|
||||
void pa_stream_unref(struct pa_stream *s);
|
||||
struct pa_stream *pa_stream_ref(struct pa_stream *s);
|
||||
|
||||
void pa_stream_drain(struct pa_stream *s, void (*complete) (struct pa_stream*s, void *userdata), void *userdata);
|
||||
|
||||
void pa_stream_set_die_callback(struct pa_stream *s, void (*cb)(struct pa_stream *s, void *userdata), void *userdata);
|
||||
|
||||
void pa_stream_set_write_callback(struct pa_stream *p, void (*cb)(struct pa_stream *p, size_t length, void *userdata), void *userdata);
|
||||
void pa_stream_write(struct pa_stream *p, const void *data, size_t length);
|
||||
size_t pa_stream_writable_size(struct pa_stream *p);
|
||||
|
||||
void pa_stream_set_read_callback(struct pa_stream *p, void (*cb)(struct pa_stream *p, const void*data, size_t length, void *userdata), void *userdata);
|
||||
|
||||
int pa_stream_is_dead(struct pa_stream *p);
|
||||
int pa_stream_is_ready(struct pa_stream*p);
|
||||
|
||||
void pa_stream_get_latency(struct pa_stream *p, void (*cb)(struct pa_stream *p, uint32_t latency, void *userdata), void *userdata);
|
||||
|
||||
struct pa_context* pa_stream_get_context(struct pa_stream *p);
|
||||
|
||||
uint32_t pa_stream_get_index(struct pa_stream *s);
|
||||
|
||||
struct pa_stream* pa_context_upload_sample(struct pa_context *c, const char *name, const struct pa_sample_spec *ss, size_t length, void (*cb) (struct pa_stream*s, int success, void *userdata), void *userdata);
|
||||
void pa_stream_finish_sample(struct pa_stream *p, void (*cb)(struct pa_stream*s, int success, void *userdata), void *userdata);
|
||||
|
||||
void pa_context_play_sample(struct pa_context *c, const char *name, const char *dev, uint32_t volume, void (*cb)(struct pa_context *c, int success, void *userdata), void *userdata);
|
||||
void pa_context_remove_sample(struct pa_context *c, const char *name, void (*cb)(struct pa_context *c, int success, void *userdata), void *userdata);
|
||||
|
||||
struct pa_sink_info {
|
||||
const char *name;
|
||||
uint32_t index;
|
||||
const char *description;
|
||||
struct pa_sample_spec sample_spec;
|
||||
uint32_t owner_module;
|
||||
uint32_t volume;
|
||||
uint32_t monitor_source;
|
||||
const char *monitor_source_name;
|
||||
uint32_t latency;
|
||||
};
|
||||
|
||||
void pa_context_get_sink_info_by_name(struct pa_context *c, const char *name, void (*cb)(struct pa_context *c, const struct pa_sink_info *i, int is_last, void *userdata), void *userdata);
|
||||
void pa_context_get_sink_info_by_index(struct pa_context *c, uint32_t id, void (*cb)(struct pa_context *c, const struct pa_sink_info *i, int is_last, void *userdata), void *userdata);
|
||||
void pa_context_get_sink_info_list(struct pa_context *c, void (*cb)(struct pa_context *c, const struct pa_sink_info *i, int is_last, void *userdata), void *userdata);
|
||||
|
||||
struct pa_source_info {
|
||||
const char *name;
|
||||
uint32_t index;
|
||||
const char *description;
|
||||
struct pa_sample_spec sample_spec;
|
||||
uint32_t owner_module;
|
||||
uint32_t monitor_of_sink;
|
||||
const char *monitor_of_sink_name;
|
||||
};
|
||||
|
||||
void pa_context_get_source_info_by_name(struct pa_context *c, const char *name, void (*cb)(struct pa_context *c, const struct pa_source_info *i, int is_last, void *userdata), void *userdata);
|
||||
void pa_context_get_source_info_by_index(struct pa_context *c, uint32_t id, void (*cb)(struct pa_context *c, const struct pa_source_info *i, int is_last, void *userdata), void *userdata);
|
||||
void pa_context_get_source_info_list(struct pa_context *c, void (*cb)(struct pa_context *c, const struct pa_source_info *i, int is_last, void *userdata), void *userdata);
|
||||
|
||||
struct pa_server_info {
|
||||
const char *user_name;
|
||||
const char *host_name;
|
||||
const char *server_version;
|
||||
const char *server_name;
|
||||
struct pa_sample_spec sample_spec;
|
||||
};
|
||||
|
||||
void pa_context_get_server_info(struct pa_context *c, void (*cb)(struct pa_context *c, const struct pa_server_info*i, void *userdata), void *userdata);
|
||||
|
||||
struct pa_module_info {
|
||||
uint32_t index;
|
||||
const char*name, *argument;
|
||||
uint32_t n_used, auto_unload;
|
||||
};
|
||||
|
||||
void pa_context_get_module_info(struct pa_context *c, uint32_t index, void (*cb)(struct pa_context *c, const struct pa_module_info*i, int is_last, void *userdata), void *userdata);
|
||||
void pa_context_get_module_info_list(struct pa_context *c, void (*cb)(struct pa_context *c, const struct pa_module_info*i, int is_last, void *userdata), void *userdata);
|
||||
|
||||
struct pa_client_info {
|
||||
uint32_t index;
|
||||
const char *name;
|
||||
uint32_t owner_module;
|
||||
const char *protocol_name;
|
||||
};
|
||||
|
||||
void pa_context_get_client_info(struct pa_context *c, uint32_t index, void (*cb)(struct pa_context *c, const struct pa_client_info*i, int is_last, void *userdata), void *userdata);
|
||||
void pa_context_get_client_info_list(struct pa_context *c, void (*cb)(struct pa_context *c, const struct pa_client_info*i, int is_last, void *userdata), void *userdata);
|
||||
|
||||
struct pa_sink_input_info {
|
||||
uint32_t index;
|
||||
const char *name;
|
||||
uint32_t owner_module;
|
||||
uint32_t owner_client;
|
||||
uint32_t sink;
|
||||
struct pa_sample_spec sample_spec;
|
||||
uint32_t volume;
|
||||
uint32_t latency;
|
||||
};
|
||||
|
||||
void pa_context_get_sink_input_info(struct pa_context *c, uint32_t index, void (*cb)(struct pa_context *c, const struct pa_sink_input_info*i, int is_last, void *userdata), void *userdata);
|
||||
void pa_context_get_sink_input_info_list(struct pa_context *c, void (*cb)(struct pa_context *c, const struct pa_sink_input_info*i, int is_last, void *userdata), void *userdata);
|
||||
|
||||
struct pa_source_output_info {
|
||||
uint32_t index;
|
||||
const char *name;
|
||||
uint32_t owner_module;
|
||||
uint32_t owner_client;
|
||||
uint32_t source;
|
||||
struct pa_sample_spec sample_spec;
|
||||
};
|
||||
|
||||
void pa_context_get_source_output_info(struct pa_context *c, uint32_t index, void (*cb)(struct pa_context *c, const struct pa_source_output_info*i, int is_last, void *userdata), void *userdata);
|
||||
void pa_context_get_source_output_info_list(struct pa_context *c, void (*cb)(struct pa_context *c, const struct pa_source_output_info*i, int is_last, void *userdata), void *userdata);
|
||||
|
||||
void pa_context_set_sink_volume(struct pa_context *c, uint32_t index, uint32_t volume, void (*cb)(struct pa_context *c, int success, void *userdata), void *userdata);
|
||||
void pa_context_set_sink_input_volume(struct pa_context *c, uint32_t index, uint32_t volume, void (*cb)(struct pa_context *c, int success, void *userdata), void *userdata);
|
||||
|
||||
void pa_context_exit(struct pa_context *c);
|
||||
void pa_context_stat(struct pa_context *c, void (*cb)(struct pa_context *c, uint32_t count, uint32_t total, void *userdata), void *userdata);
|
||||
|
||||
void pa_context_subscribe(struct pa_context *c, enum pa_subscription_mask m, void (*cb)(struct pa_context *c, enum pa_subscription_event_type t, uint32_t index, void *userdata), void *userdata);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
PA_C_DECL_END
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -49,15 +49,28 @@ struct pa_simple {
|
|||
static void read_callback(struct pa_stream *s, const void*data, size_t length, void *userdata);
|
||||
|
||||
static int check_error(struct pa_simple *p, int *perror) {
|
||||
enum pa_context_state cst;
|
||||
enum pa_stream_state sst;
|
||||
assert(p);
|
||||
|
||||
if (pa_context_is_dead(p->context) || (p->stream && pa_stream_is_dead(p->stream))) {
|
||||
if (perror)
|
||||
*perror = pa_context_errno(p->context);
|
||||
return -1;
|
||||
}
|
||||
if ((cst = pa_context_get_state(p->context)) == PA_CONTEXT_FAILED)
|
||||
goto fail;
|
||||
|
||||
assert(cst != PA_CONTEXT_TERMINATED);
|
||||
|
||||
if (p->stream) {
|
||||
if ((sst = pa_stream_get_state(p->stream)) == PA_STREAM_FAILED)
|
||||
goto fail;
|
||||
|
||||
assert(sst != PA_STREAM_TERMINATED);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
fail:
|
||||
if (perror)
|
||||
*perror = pa_context_errno(p->context);
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int iterate(struct pa_simple *p, int block, int *perror) {
|
||||
|
|
@ -96,7 +109,7 @@ struct pa_simple* pa_simple_new(
|
|||
|
||||
struct pa_simple *p;
|
||||
int error = PA_ERROR_INTERNAL;
|
||||
assert(ss);
|
||||
assert(ss && (dir == PA_STREAM_PLAYBACK || dir == PA_STREAM_RECORD));
|
||||
|
||||
p = pa_xmalloc(sizeof(struct pa_simple));
|
||||
p->context = NULL;
|
||||
|
|
@ -110,23 +123,25 @@ struct pa_simple* pa_simple_new(
|
|||
|
||||
if (!(p->context = pa_context_new(pa_mainloop_get_api(p->mainloop), name)))
|
||||
goto fail;
|
||||
|
||||
if (pa_context_connect(p->context, server, NULL, NULL) < 0) {
|
||||
error = pa_context_errno(p->context);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
pa_context_connect(p->context, server);
|
||||
|
||||
/* Wait until the context is ready */
|
||||
while (!pa_context_is_ready(p->context)) {
|
||||
while (pa_context_get_state(p->context) != PA_CONTEXT_READY) {
|
||||
if (iterate(p, 1, &error) < 0)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (!(p->stream = pa_stream_new(p->context, dir, dev, stream_name, ss, attr, NULL, NULL)))
|
||||
if (!(p->stream = pa_stream_new(p->context, stream_name, ss)))
|
||||
goto fail;
|
||||
|
||||
if (dir == PA_STREAM_PLAYBACK)
|
||||
pa_stream_connect_playback(p->stream, dev, attr);
|
||||
else
|
||||
pa_stream_connect_record(p->stream, dev, attr);
|
||||
|
||||
/* Wait until the stream is ready */
|
||||
while (!pa_stream_is_ready(p->stream)) {
|
||||
while (pa_stream_get_state(p->stream) != PA_STREAM_READY) {
|
||||
if (iterate(p, 1, &error) < 0)
|
||||
goto fail;
|
||||
}
|
||||
|
|
@ -148,10 +163,10 @@ void pa_simple_free(struct pa_simple *s) {
|
|||
pa_xfree(s->read_data);
|
||||
|
||||
if (s->stream)
|
||||
pa_stream_free(s->stream);
|
||||
pa_stream_unref(s->stream);
|
||||
|
||||
if (s->context)
|
||||
pa_context_free(s->context);
|
||||
pa_context_unref(s->context);
|
||||
|
||||
if (s->mainloop)
|
||||
pa_mainloop_free(s->mainloop);
|
||||
|
|
@ -172,7 +187,7 @@ int pa_simple_write(struct pa_simple *p, const void*data, size_t length, int *pe
|
|||
if (l > length)
|
||||
l = length;
|
||||
|
||||
pa_stream_write(p->stream, data, l);
|
||||
pa_stream_write(p->stream, data, l, NULL);
|
||||
data += l;
|
||||
length -= l;
|
||||
}
|
||||
|
|
@ -193,8 +208,7 @@ static void read_callback(struct pa_stream *s, const void*data, size_t length, v
|
|||
pa_xfree(p->read_data);
|
||||
}
|
||||
|
||||
p->read_data = pa_xmalloc(p->read_length = length);
|
||||
memcpy(p->read_data, data, length);
|
||||
p->read_data = pa_xmemdup(data, p->read_length = length);
|
||||
p->read_index = 0;
|
||||
}
|
||||
|
||||
|
|
@ -235,23 +249,31 @@ int pa_simple_read(struct pa_simple *p, void*data, size_t length, int *perror) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void drain_complete(struct pa_stream *s, void *userdata) {
|
||||
static void drain_complete(struct pa_stream *s, int success, void *userdata) {
|
||||
struct pa_simple *p = userdata;
|
||||
assert(s && p);
|
||||
p->drained = 1;
|
||||
p->drained = success ? 1 : -1;
|
||||
}
|
||||
|
||||
int pa_simple_drain(struct pa_simple *p, int *perror) {
|
||||
struct pa_operation *o;
|
||||
|
||||
assert(p && p->direction == PA_STREAM_PLAYBACK);
|
||||
p->drained = 0;
|
||||
pa_stream_drain(p->stream, drain_complete, p);
|
||||
o = pa_stream_drain(p->stream, drain_complete, p);
|
||||
|
||||
while (!p->drained) {
|
||||
if (iterate(p, 1, perror) < 0) {
|
||||
pa_stream_drain(p->stream, NULL, NULL);
|
||||
pa_operation_cancel(o);
|
||||
pa_operation_unref(o);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
pa_operation_unref(o);
|
||||
|
||||
if (p->drained < 0 && perror)
|
||||
*perror = pa_context_errno(p->context);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,24 +26,41 @@
|
|||
|
||||
#include "sample.h"
|
||||
#include "polyplib-def.h"
|
||||
#include "cdecl.h"
|
||||
|
||||
/** \file
|
||||
* A simple but limited synchronous playback and recording API. */
|
||||
|
||||
PA_C_DECL_BEGIN
|
||||
|
||||
/** \struct pa_simple
|
||||
* A simple connection object */
|
||||
struct pa_simple;
|
||||
|
||||
/** Create a new connection to the server */
|
||||
struct pa_simple* pa_simple_new(
|
||||
const char *server,
|
||||
const char *name,
|
||||
enum pa_stream_direction dir,
|
||||
const char *dev,
|
||||
const char *stream_name,
|
||||
const struct pa_sample_spec *ss,
|
||||
const struct pa_buffer_attr *attr,
|
||||
int *error);
|
||||
const char *server, /**< Server name, or NULL for default */
|
||||
const char *name, /**< A descriptive name for this client (application name, ...) */
|
||||
enum pa_stream_direction dir, /**< Open this stream for recording or playback? */
|
||||
const char *dev, /**< Sink (resp. source) name, or NULL for default */
|
||||
const char *stream_name, /**< A descriptive name for this client (application name, song title, ...) */
|
||||
const struct pa_sample_spec *ss, /**< The sample type to use */
|
||||
const struct pa_buffer_attr *attr, /**< Buffering attributes, or NULL for default */
|
||||
int *error /**< A pointer where the error code is stored when the routine returns NULL. It is OK to pass NULL here. */
|
||||
);
|
||||
|
||||
/** Close and free the connection to the server. The connection objects becomes invalid when this is called. */
|
||||
void pa_simple_free(struct pa_simple *s);
|
||||
|
||||
/** Write some data to the server */
|
||||
int pa_simple_write(struct pa_simple *s, const void*data, size_t length, int *error);
|
||||
|
||||
/** Wait until all data already written is played by the daemon */
|
||||
int pa_simple_drain(struct pa_simple *s, int *error);
|
||||
|
||||
/** Read some data from the server */
|
||||
int pa_simple_read(struct pa_simple *s, void*data, size_t length, int *error);
|
||||
|
||||
PA_C_DECL_END
|
||||
|
||||
#endif
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,5 +1,5 @@
|
|||
#ifndef foopolyplibhfoo
|
||||
#define foopolyplibhfoo
|
||||
#ifndef foopolyplibstreamhfoo
|
||||
#define foopolyplibstreamhfoo
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
|
|
@ -26,153 +26,79 @@
|
|||
|
||||
#include "sample.h"
|
||||
#include "polyplib-def.h"
|
||||
#include "mainloop-api.h"
|
||||
#include "cdecl.h"
|
||||
#include "polyplib-operation.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
//extern "C" {
|
||||
#endif
|
||||
/** \file
|
||||
* Audio streams for input, output and sample upload */
|
||||
|
||||
struct pa_context;
|
||||
PA_C_DECL_BEGIN
|
||||
|
||||
/** The state of a stream */
|
||||
enum pa_stream_state {
|
||||
PA_STREAM_DISCONNECTED, /**< The stream is not yet connected to any sink or source */
|
||||
PA_STREAM_CREATING, /**< The stream is being created */
|
||||
PA_STREAM_READY, /**< The stream is established, you may pass audio data to it now */
|
||||
PA_STREAM_FAILED, /**< An error occured that made the stream invalid */
|
||||
PA_STREAM_TERMINATED, /**< The stream has been terminated cleanly */
|
||||
};
|
||||
|
||||
/** \struct pa_stream
|
||||
* A stream for playback or recording */
|
||||
struct pa_stream;
|
||||
|
||||
struct pa_context *pa_context_new(struct pa_mainloop_api *mainloop, const char *name);
|
||||
void pa_context_unref(struct pa_context *c);
|
||||
struct pa_context* pa_context_ref(struct pa_context *c);
|
||||
/** Create a new, unconnected stream with the specified name and sample type */
|
||||
struct pa_stream* pa_stream_new(struct pa_context *c, const char *name, const struct pa_sample_spec *ss);
|
||||
|
||||
int pa_context_connect(struct pa_context *c, const char *server, void (*complete) (struct pa_context*c, int success, void *userdata), void *userdata);
|
||||
int pa_context_drain(struct pa_context *c, void (*complete) (struct pa_context*c, void *userdata), void *userdata);
|
||||
void pa_context_set_die_callback(struct pa_context *c, void (*cb)(struct pa_context *c, void *userdata), void *userdata);
|
||||
|
||||
int pa_context_is_dead(struct pa_context *c);
|
||||
int pa_context_is_ready(struct pa_context *c);
|
||||
int pa_context_errno(struct pa_context *c);
|
||||
|
||||
int pa_context_is_pending(struct pa_context *c);
|
||||
|
||||
struct pa_stream* pa_stream_new(struct pa_context *c, enum pa_stream_direction dir, const char *dev, const char *name, const struct pa_sample_spec *ss, const struct pa_buffer_attr *attr, void (*complete) (struct pa_stream*s, int success, void *userdata), void *userdata);
|
||||
/** Decrease the reference counter by one */
|
||||
void pa_stream_unref(struct pa_stream *s);
|
||||
|
||||
/** Increase the reference counter by one */
|
||||
struct pa_stream *pa_stream_ref(struct pa_stream *s);
|
||||
|
||||
void pa_stream_drain(struct pa_stream *s, void (*complete) (struct pa_stream*s, void *userdata), void *userdata);
|
||||
|
||||
void pa_stream_set_die_callback(struct pa_stream *s, void (*cb)(struct pa_stream *s, void *userdata), void *userdata);
|
||||
|
||||
void pa_stream_set_write_callback(struct pa_stream *p, void (*cb)(struct pa_stream *p, size_t length, void *userdata), void *userdata);
|
||||
void pa_stream_write(struct pa_stream *p, const void *data, size_t length);
|
||||
size_t pa_stream_writable_size(struct pa_stream *p);
|
||||
|
||||
void pa_stream_set_read_callback(struct pa_stream *p, void (*cb)(struct pa_stream *p, const void*data, size_t length, void *userdata), void *userdata);
|
||||
|
||||
int pa_stream_is_dead(struct pa_stream *p);
|
||||
int pa_stream_is_ready(struct pa_stream*p);
|
||||
|
||||
void pa_stream_get_latency(struct pa_stream *p, void (*cb)(struct pa_stream *p, uint32_t latency, void *userdata), void *userdata);
|
||||
/** Return the current state of the stream */
|
||||
enum pa_stream_state pa_stream_get_state(struct pa_stream *p);
|
||||
|
||||
/** Return the context this stream is attached to */
|
||||
struct pa_context* pa_stream_get_context(struct pa_stream *p);
|
||||
|
||||
/** Return the device (sink input or source output) index this stream is connected to */
|
||||
uint32_t pa_stream_get_index(struct pa_stream *s);
|
||||
|
||||
struct pa_stream* pa_context_upload_sample(struct pa_context *c, const char *name, const struct pa_sample_spec *ss, size_t length, void (*cb) (struct pa_stream*s, int success, void *userdata), void *userdata);
|
||||
void pa_stream_finish_sample(struct pa_stream *p, void (*cb)(struct pa_stream*s, int success, void *userdata), void *userdata);
|
||||
/** Connect the stream to a sink */
|
||||
void pa_stream_connect_playback(struct pa_stream *s, const char *dev, const struct pa_buffer_attr *attr);
|
||||
|
||||
void pa_context_play_sample(struct pa_context *c, const char *name, const char *dev, uint32_t volume, void (*cb)(struct pa_context *c, int success, void *userdata), void *userdata);
|
||||
void pa_context_remove_sample(struct pa_context *c, const char *name, void (*cb)(struct pa_context *c, int success, void *userdata), void *userdata);
|
||||
/** Connect the stream to a source */
|
||||
void pa_stream_connect_record(struct pa_stream *s, const char *dev, const struct pa_buffer_attr *attr);
|
||||
|
||||
struct pa_sink_info {
|
||||
const char *name;
|
||||
uint32_t index;
|
||||
const char *description;
|
||||
struct pa_sample_spec sample_spec;
|
||||
uint32_t owner_module;
|
||||
uint32_t volume;
|
||||
uint32_t monitor_source;
|
||||
const char *monitor_source_name;
|
||||
uint32_t latency;
|
||||
};
|
||||
/** Disconnect a stream from a source/sink */
|
||||
void pa_stream_disconnect(struct pa_stream *s);
|
||||
|
||||
void pa_context_get_sink_info_by_name(struct pa_context *c, const char *name, void (*cb)(struct pa_context *c, const struct pa_sink_info *i, int is_last, void *userdata), void *userdata);
|
||||
void pa_context_get_sink_info_by_index(struct pa_context *c, uint32_t id, void (*cb)(struct pa_context *c, const struct pa_sink_info *i, int is_last, void *userdata), void *userdata);
|
||||
void pa_context_get_sink_info_list(struct pa_context *c, void (*cb)(struct pa_context *c, const struct pa_sink_info *i, int is_last, void *userdata), void *userdata);
|
||||
/** Write some data to the server (for playback sinks), if free_cb is
|
||||
* non-NULL this routine is called when all data has been written out
|
||||
* and an internal reference to the specified data is kept, the data
|
||||
* is not copied. If NULL, the data is copied into an internal
|
||||
* buffer. */
|
||||
void pa_stream_write(struct pa_stream *p, const void *data, size_t length, void (*free_cb)(void *p));
|
||||
|
||||
struct pa_source_info {
|
||||
const char *name;
|
||||
uint32_t index;
|
||||
const char *description;
|
||||
struct pa_sample_spec sample_spec;
|
||||
uint32_t owner_module;
|
||||
uint32_t monitor_of_sink;
|
||||
const char *monitor_of_sink_name;
|
||||
};
|
||||
/** Return the amount of bytes that may be written using pa_stream_write() */
|
||||
size_t pa_stream_writable_size(struct pa_stream *p);
|
||||
|
||||
void pa_context_get_source_info_by_name(struct pa_context *c, const char *name, void (*cb)(struct pa_context *c, const struct pa_source_info *i, int is_last, void *userdata), void *userdata);
|
||||
void pa_context_get_source_info_by_index(struct pa_context *c, uint32_t id, void (*cb)(struct pa_context *c, const struct pa_source_info *i, int is_last, void *userdata), void *userdata);
|
||||
void pa_context_get_source_info_list(struct pa_context *c, void (*cb)(struct pa_context *c, const struct pa_source_info *i, int is_last, void *userdata), void *userdata);
|
||||
/** Drain a playback stream */
|
||||
struct pa_operation* pa_stream_drain(struct pa_stream *s, void (*cb) (struct pa_stream*s, int success, void *userdata), void *userdata);
|
||||
|
||||
struct pa_server_info {
|
||||
const char *user_name;
|
||||
const char *host_name;
|
||||
const char *server_version;
|
||||
const char *server_name;
|
||||
struct pa_sample_spec sample_spec;
|
||||
};
|
||||
/** Get the playback latency of a stream */
|
||||
struct pa_operation* pa_stream_get_latency(struct pa_stream *p, void (*cb)(struct pa_stream *p, uint32_t latency, void *userdata), void *userdata);
|
||||
|
||||
void pa_context_get_server_info(struct pa_context *c, void (*cb)(struct pa_context *c, const struct pa_server_info*i, void *userdata), void *userdata);
|
||||
/** Set the callback function that is called whenever the state of the stream changes */
|
||||
void pa_stream_set_state_callback(struct pa_stream *s, void (*cb)(struct pa_stream *s, void *userdata), void *userdata);
|
||||
|
||||
struct pa_module_info {
|
||||
uint32_t index;
|
||||
const char*name, *argument;
|
||||
uint32_t n_used, auto_unload;
|
||||
};
|
||||
/** Set the callback function that is called when new data may be written to the stream */
|
||||
void pa_stream_set_write_callback(struct pa_stream *p, void (*cb)(struct pa_stream *p, size_t length, void *userdata), void *userdata);
|
||||
|
||||
void pa_context_get_module_info(struct pa_context *c, uint32_t index, void (*cb)(struct pa_context *c, const struct pa_module_info*i, int is_last, void *userdata), void *userdata);
|
||||
void pa_context_get_module_info_list(struct pa_context *c, void (*cb)(struct pa_context *c, const struct pa_module_info*i, int is_last, void *userdata), void *userdata);
|
||||
/** Set the callback function that is called when new data is available from the stream */
|
||||
void pa_stream_set_read_callback(struct pa_stream *p, void (*cb)(struct pa_stream *p, const void*data, size_t length, void *userdata), void *userdata);
|
||||
|
||||
struct pa_client_info {
|
||||
uint32_t index;
|
||||
const char *name;
|
||||
uint32_t owner_module;
|
||||
const char *protocol_name;
|
||||
};
|
||||
|
||||
void pa_context_get_client_info(struct pa_context *c, uint32_t index, void (*cb)(struct pa_context *c, const struct pa_client_info*i, int is_last, void *userdata), void *userdata);
|
||||
void pa_context_get_client_info_list(struct pa_context *c, void (*cb)(struct pa_context *c, const struct pa_client_info*i, int is_last, void *userdata), void *userdata);
|
||||
|
||||
struct pa_sink_input_info {
|
||||
uint32_t index;
|
||||
const char *name;
|
||||
uint32_t owner_module;
|
||||
uint32_t owner_client;
|
||||
uint32_t sink;
|
||||
struct pa_sample_spec sample_spec;
|
||||
uint32_t volume;
|
||||
uint32_t latency;
|
||||
};
|
||||
|
||||
void pa_context_get_sink_input_info(struct pa_context *c, uint32_t index, void (*cb)(struct pa_context *c, const struct pa_sink_input_info*i, int is_last, void *userdata), void *userdata);
|
||||
void pa_context_get_sink_input_info_list(struct pa_context *c, void (*cb)(struct pa_context *c, const struct pa_sink_input_info*i, int is_last, void *userdata), void *userdata);
|
||||
|
||||
struct pa_source_output_info {
|
||||
uint32_t index;
|
||||
const char *name;
|
||||
uint32_t owner_module;
|
||||
uint32_t owner_client;
|
||||
uint32_t source;
|
||||
struct pa_sample_spec sample_spec;
|
||||
};
|
||||
|
||||
void pa_context_get_source_output_info(struct pa_context *c, uint32_t index, void (*cb)(struct pa_context *c, const struct pa_source_output_info*i, int is_last, void *userdata), void *userdata);
|
||||
void pa_context_get_source_output_info_list(struct pa_context *c, void (*cb)(struct pa_context *c, const struct pa_source_output_info*i, int is_last, void *userdata), void *userdata);
|
||||
|
||||
void pa_context_set_sink_volume(struct pa_context *c, uint32_t index, uint32_t volume, void (*cb)(struct pa_context *c, int success, void *userdata), void *userdata);
|
||||
void pa_context_set_sink_input_volume(struct pa_context *c, uint32_t index, uint32_t volume, void (*cb)(struct pa_context *c, int success, void *userdata), void *userdata);
|
||||
|
||||
void pa_context_exit(struct pa_context *c);
|
||||
void pa_context_stat(struct pa_context *c, void (*cb)(struct pa_context *c, uint32_t count, uint32_t total, void *userdata), void *userdata);
|
||||
|
||||
void pa_context_subscribe(struct pa_context *c, enum pa_subscription_mask m, void (*cb)(struct pa_context *c, enum pa_subscription_event_type t, uint32_t index, void *userdata), void *userdata);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
PA_C_DECL_END
|
||||
|
||||
#endif
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,5 +1,5 @@
|
|||
#ifndef foopolyplibhfoo
|
||||
#define foopolyplibhfoo
|
||||
#ifndef foopolyplibsubscribehfoo
|
||||
#define foopolyplibsubscribehfoo
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
|
|
@ -22,157 +22,17 @@
|
|||
USA.
|
||||
***/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "sample.h"
|
||||
#include "polyplib-def.h"
|
||||
#include "mainloop-api.h"
|
||||
#include "polyplib-context.h"
|
||||
#include "cdecl.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
//extern "C" {
|
||||
#endif
|
||||
PA_C_DECL_BEGIN
|
||||
|
||||
struct pa_context;
|
||||
struct pa_stream;
|
||||
struct pa_operation* pa_context_subscribe(struct pa_context *c, enum pa_subscription_mask m, void (*cb)(struct pa_context *c, int success, void *userdata), void *userdata);
|
||||
void pa_context_set_subscribe_callback(struct pa_context *c, void (*cb)(struct pa_context *c, enum pa_subscription_event_type t, uint32_t index, void *userdata), void *userdata);
|
||||
|
||||
struct pa_context *pa_context_new(struct pa_mainloop_api *mainloop, const char *name);
|
||||
void pa_context_unref(struct pa_context *c);
|
||||
struct pa_context* pa_context_ref(struct pa_context *c);
|
||||
|
||||
int pa_context_connect(struct pa_context *c, const char *server, void (*complete) (struct pa_context*c, int success, void *userdata), void *userdata);
|
||||
int pa_context_drain(struct pa_context *c, void (*complete) (struct pa_context*c, void *userdata), void *userdata);
|
||||
void pa_context_set_die_callback(struct pa_context *c, void (*cb)(struct pa_context *c, void *userdata), void *userdata);
|
||||
|
||||
int pa_context_is_dead(struct pa_context *c);
|
||||
int pa_context_is_ready(struct pa_context *c);
|
||||
int pa_context_errno(struct pa_context *c);
|
||||
|
||||
int pa_context_is_pending(struct pa_context *c);
|
||||
|
||||
struct pa_stream* pa_stream_new(struct pa_context *c, enum pa_stream_direction dir, const char *dev, const char *name, const struct pa_sample_spec *ss, const struct pa_buffer_attr *attr, void (*complete) (struct pa_stream*s, int success, void *userdata), void *userdata);
|
||||
void pa_stream_unref(struct pa_stream *s);
|
||||
struct pa_stream *pa_stream_ref(struct pa_stream *s);
|
||||
|
||||
void pa_stream_drain(struct pa_stream *s, void (*complete) (struct pa_stream*s, void *userdata), void *userdata);
|
||||
|
||||
void pa_stream_set_die_callback(struct pa_stream *s, void (*cb)(struct pa_stream *s, void *userdata), void *userdata);
|
||||
|
||||
void pa_stream_set_write_callback(struct pa_stream *p, void (*cb)(struct pa_stream *p, size_t length, void *userdata), void *userdata);
|
||||
void pa_stream_write(struct pa_stream *p, const void *data, size_t length);
|
||||
size_t pa_stream_writable_size(struct pa_stream *p);
|
||||
|
||||
void pa_stream_set_read_callback(struct pa_stream *p, void (*cb)(struct pa_stream *p, const void*data, size_t length, void *userdata), void *userdata);
|
||||
|
||||
int pa_stream_is_dead(struct pa_stream *p);
|
||||
int pa_stream_is_ready(struct pa_stream*p);
|
||||
|
||||
void pa_stream_get_latency(struct pa_stream *p, void (*cb)(struct pa_stream *p, uint32_t latency, void *userdata), void *userdata);
|
||||
|
||||
struct pa_context* pa_stream_get_context(struct pa_stream *p);
|
||||
|
||||
uint32_t pa_stream_get_index(struct pa_stream *s);
|
||||
|
||||
struct pa_stream* pa_context_upload_sample(struct pa_context *c, const char *name, const struct pa_sample_spec *ss, size_t length, void (*cb) (struct pa_stream*s, int success, void *userdata), void *userdata);
|
||||
void pa_stream_finish_sample(struct pa_stream *p, void (*cb)(struct pa_stream*s, int success, void *userdata), void *userdata);
|
||||
|
||||
void pa_context_play_sample(struct pa_context *c, const char *name, const char *dev, uint32_t volume, void (*cb)(struct pa_context *c, int success, void *userdata), void *userdata);
|
||||
void pa_context_remove_sample(struct pa_context *c, const char *name, void (*cb)(struct pa_context *c, int success, void *userdata), void *userdata);
|
||||
|
||||
struct pa_sink_info {
|
||||
const char *name;
|
||||
uint32_t index;
|
||||
const char *description;
|
||||
struct pa_sample_spec sample_spec;
|
||||
uint32_t owner_module;
|
||||
uint32_t volume;
|
||||
uint32_t monitor_source;
|
||||
const char *monitor_source_name;
|
||||
uint32_t latency;
|
||||
};
|
||||
|
||||
void pa_context_get_sink_info_by_name(struct pa_context *c, const char *name, void (*cb)(struct pa_context *c, const struct pa_sink_info *i, int is_last, void *userdata), void *userdata);
|
||||
void pa_context_get_sink_info_by_index(struct pa_context *c, uint32_t id, void (*cb)(struct pa_context *c, const struct pa_sink_info *i, int is_last, void *userdata), void *userdata);
|
||||
void pa_context_get_sink_info_list(struct pa_context *c, void (*cb)(struct pa_context *c, const struct pa_sink_info *i, int is_last, void *userdata), void *userdata);
|
||||
|
||||
struct pa_source_info {
|
||||
const char *name;
|
||||
uint32_t index;
|
||||
const char *description;
|
||||
struct pa_sample_spec sample_spec;
|
||||
uint32_t owner_module;
|
||||
uint32_t monitor_of_sink;
|
||||
const char *monitor_of_sink_name;
|
||||
};
|
||||
|
||||
void pa_context_get_source_info_by_name(struct pa_context *c, const char *name, void (*cb)(struct pa_context *c, const struct pa_source_info *i, int is_last, void *userdata), void *userdata);
|
||||
void pa_context_get_source_info_by_index(struct pa_context *c, uint32_t id, void (*cb)(struct pa_context *c, const struct pa_source_info *i, int is_last, void *userdata), void *userdata);
|
||||
void pa_context_get_source_info_list(struct pa_context *c, void (*cb)(struct pa_context *c, const struct pa_source_info *i, int is_last, void *userdata), void *userdata);
|
||||
|
||||
struct pa_server_info {
|
||||
const char *user_name;
|
||||
const char *host_name;
|
||||
const char *server_version;
|
||||
const char *server_name;
|
||||
struct pa_sample_spec sample_spec;
|
||||
};
|
||||
|
||||
void pa_context_get_server_info(struct pa_context *c, void (*cb)(struct pa_context *c, const struct pa_server_info*i, void *userdata), void *userdata);
|
||||
|
||||
struct pa_module_info {
|
||||
uint32_t index;
|
||||
const char*name, *argument;
|
||||
uint32_t n_used, auto_unload;
|
||||
};
|
||||
|
||||
void pa_context_get_module_info(struct pa_context *c, uint32_t index, void (*cb)(struct pa_context *c, const struct pa_module_info*i, int is_last, void *userdata), void *userdata);
|
||||
void pa_context_get_module_info_list(struct pa_context *c, void (*cb)(struct pa_context *c, const struct pa_module_info*i, int is_last, void *userdata), void *userdata);
|
||||
|
||||
struct pa_client_info {
|
||||
uint32_t index;
|
||||
const char *name;
|
||||
uint32_t owner_module;
|
||||
const char *protocol_name;
|
||||
};
|
||||
|
||||
void pa_context_get_client_info(struct pa_context *c, uint32_t index, void (*cb)(struct pa_context *c, const struct pa_client_info*i, int is_last, void *userdata), void *userdata);
|
||||
void pa_context_get_client_info_list(struct pa_context *c, void (*cb)(struct pa_context *c, const struct pa_client_info*i, int is_last, void *userdata), void *userdata);
|
||||
|
||||
struct pa_sink_input_info {
|
||||
uint32_t index;
|
||||
const char *name;
|
||||
uint32_t owner_module;
|
||||
uint32_t owner_client;
|
||||
uint32_t sink;
|
||||
struct pa_sample_spec sample_spec;
|
||||
uint32_t volume;
|
||||
uint32_t latency;
|
||||
};
|
||||
|
||||
void pa_context_get_sink_input_info(struct pa_context *c, uint32_t index, void (*cb)(struct pa_context *c, const struct pa_sink_input_info*i, int is_last, void *userdata), void *userdata);
|
||||
void pa_context_get_sink_input_info_list(struct pa_context *c, void (*cb)(struct pa_context *c, const struct pa_sink_input_info*i, int is_last, void *userdata), void *userdata);
|
||||
|
||||
struct pa_source_output_info {
|
||||
uint32_t index;
|
||||
const char *name;
|
||||
uint32_t owner_module;
|
||||
uint32_t owner_client;
|
||||
uint32_t source;
|
||||
struct pa_sample_spec sample_spec;
|
||||
};
|
||||
|
||||
void pa_context_get_source_output_info(struct pa_context *c, uint32_t index, void (*cb)(struct pa_context *c, const struct pa_source_output_info*i, int is_last, void *userdata), void *userdata);
|
||||
void pa_context_get_source_output_info_list(struct pa_context *c, void (*cb)(struct pa_context *c, const struct pa_source_output_info*i, int is_last, void *userdata), void *userdata);
|
||||
|
||||
void pa_context_set_sink_volume(struct pa_context *c, uint32_t index, uint32_t volume, void (*cb)(struct pa_context *c, int success, void *userdata), void *userdata);
|
||||
void pa_context_set_sink_input_volume(struct pa_context *c, uint32_t index, uint32_t volume, void (*cb)(struct pa_context *c, int success, void *userdata), void *userdata);
|
||||
|
||||
void pa_context_exit(struct pa_context *c);
|
||||
void pa_context_stat(struct pa_context *c, void (*cb)(struct pa_context *c, uint32_t count, uint32_t total, void *userdata), void *userdata);
|
||||
|
||||
void pa_context_subscribe(struct pa_context *c, enum pa_subscription_mask m, void (*cb)(struct pa_context *c, enum pa_subscription_event_type t, uint32_t index, void *userdata), void *userdata);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
PA_C_DECL_END
|
||||
|
||||
#endif
|
||||
|
|
|
|||
1550
polyp/polyplib.c
1550
polyp/polyplib.c
File diff suppressed because it is too large
Load diff
156
polyp/polyplib.h
156
polyp/polyplib.h
|
|
@ -22,157 +22,13 @@
|
|||
USA.
|
||||
***/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "mainloop-api.h"
|
||||
#include "sample.h"
|
||||
#include "polyplib-def.h"
|
||||
#include "mainloop-api.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
//extern "C" {
|
||||
#endif
|
||||
|
||||
struct pa_context;
|
||||
struct pa_stream;
|
||||
|
||||
struct pa_context *pa_context_new(struct pa_mainloop_api *mainloop, const char *name);
|
||||
void pa_context_unref(struct pa_context *c);
|
||||
struct pa_context* pa_context_ref(struct pa_context *c);
|
||||
|
||||
int pa_context_connect(struct pa_context *c, const char *server, void (*complete) (struct pa_context*c, int success, void *userdata), void *userdata);
|
||||
int pa_context_drain(struct pa_context *c, void (*complete) (struct pa_context*c, void *userdata), void *userdata);
|
||||
void pa_context_set_die_callback(struct pa_context *c, void (*cb)(struct pa_context *c, void *userdata), void *userdata);
|
||||
|
||||
int pa_context_is_dead(struct pa_context *c);
|
||||
int pa_context_is_ready(struct pa_context *c);
|
||||
int pa_context_errno(struct pa_context *c);
|
||||
|
||||
int pa_context_is_pending(struct pa_context *c);
|
||||
|
||||
struct pa_stream* pa_stream_new(struct pa_context *c, enum pa_stream_direction dir, const char *dev, const char *name, const struct pa_sample_spec *ss, const struct pa_buffer_attr *attr, void (*complete) (struct pa_stream*s, int success, void *userdata), void *userdata);
|
||||
void pa_stream_unref(struct pa_stream *s);
|
||||
struct pa_stream *pa_stream_ref(struct pa_stream *s);
|
||||
|
||||
void pa_stream_drain(struct pa_stream *s, void (*complete) (struct pa_stream*s, void *userdata), void *userdata);
|
||||
|
||||
void pa_stream_set_die_callback(struct pa_stream *s, void (*cb)(struct pa_stream *s, void *userdata), void *userdata);
|
||||
|
||||
void pa_stream_set_write_callback(struct pa_stream *p, void (*cb)(struct pa_stream *p, size_t length, void *userdata), void *userdata);
|
||||
void pa_stream_write(struct pa_stream *p, const void *data, size_t length);
|
||||
size_t pa_stream_writable_size(struct pa_stream *p);
|
||||
|
||||
void pa_stream_set_read_callback(struct pa_stream *p, void (*cb)(struct pa_stream *p, const void*data, size_t length, void *userdata), void *userdata);
|
||||
|
||||
int pa_stream_is_dead(struct pa_stream *p);
|
||||
int pa_stream_is_ready(struct pa_stream*p);
|
||||
|
||||
void pa_stream_get_latency(struct pa_stream *p, void (*cb)(struct pa_stream *p, uint32_t latency, void *userdata), void *userdata);
|
||||
|
||||
struct pa_context* pa_stream_get_context(struct pa_stream *p);
|
||||
|
||||
uint32_t pa_stream_get_index(struct pa_stream *s);
|
||||
|
||||
struct pa_stream* pa_context_upload_sample(struct pa_context *c, const char *name, const struct pa_sample_spec *ss, size_t length, void (*cb) (struct pa_stream*s, int success, void *userdata), void *userdata);
|
||||
void pa_stream_finish_sample(struct pa_stream *p, void (*cb)(struct pa_stream*s, int success, void *userdata), void *userdata);
|
||||
|
||||
void pa_context_play_sample(struct pa_context *c, const char *name, const char *dev, uint32_t volume, void (*cb)(struct pa_context *c, int success, void *userdata), void *userdata);
|
||||
void pa_context_remove_sample(struct pa_context *c, const char *name, void (*cb)(struct pa_context *c, int success, void *userdata), void *userdata);
|
||||
|
||||
struct pa_sink_info {
|
||||
const char *name;
|
||||
uint32_t index;
|
||||
const char *description;
|
||||
struct pa_sample_spec sample_spec;
|
||||
uint32_t owner_module;
|
||||
uint32_t volume;
|
||||
uint32_t monitor_source;
|
||||
const char *monitor_source_name;
|
||||
uint32_t latency;
|
||||
};
|
||||
|
||||
void pa_context_get_sink_info_by_name(struct pa_context *c, const char *name, void (*cb)(struct pa_context *c, const struct pa_sink_info *i, int is_last, void *userdata), void *userdata);
|
||||
void pa_context_get_sink_info_by_index(struct pa_context *c, uint32_t id, void (*cb)(struct pa_context *c, const struct pa_sink_info *i, int is_last, void *userdata), void *userdata);
|
||||
void pa_context_get_sink_info_list(struct pa_context *c, void (*cb)(struct pa_context *c, const struct pa_sink_info *i, int is_last, void *userdata), void *userdata);
|
||||
|
||||
struct pa_source_info {
|
||||
const char *name;
|
||||
uint32_t index;
|
||||
const char *description;
|
||||
struct pa_sample_spec sample_spec;
|
||||
uint32_t owner_module;
|
||||
uint32_t monitor_of_sink;
|
||||
const char *monitor_of_sink_name;
|
||||
};
|
||||
|
||||
void pa_context_get_source_info_by_name(struct pa_context *c, const char *name, void (*cb)(struct pa_context *c, const struct pa_source_info *i, int is_last, void *userdata), void *userdata);
|
||||
void pa_context_get_source_info_by_index(struct pa_context *c, uint32_t id, void (*cb)(struct pa_context *c, const struct pa_source_info *i, int is_last, void *userdata), void *userdata);
|
||||
void pa_context_get_source_info_list(struct pa_context *c, void (*cb)(struct pa_context *c, const struct pa_source_info *i, int is_last, void *userdata), void *userdata);
|
||||
|
||||
struct pa_server_info {
|
||||
const char *user_name;
|
||||
const char *host_name;
|
||||
const char *server_version;
|
||||
const char *server_name;
|
||||
struct pa_sample_spec sample_spec;
|
||||
};
|
||||
|
||||
void pa_context_get_server_info(struct pa_context *c, void (*cb)(struct pa_context *c, const struct pa_server_info*i, void *userdata), void *userdata);
|
||||
|
||||
struct pa_module_info {
|
||||
uint32_t index;
|
||||
const char*name, *argument;
|
||||
uint32_t n_used, auto_unload;
|
||||
};
|
||||
|
||||
void pa_context_get_module_info(struct pa_context *c, uint32_t index, void (*cb)(struct pa_context *c, const struct pa_module_info*i, int is_last, void *userdata), void *userdata);
|
||||
void pa_context_get_module_info_list(struct pa_context *c, void (*cb)(struct pa_context *c, const struct pa_module_info*i, int is_last, void *userdata), void *userdata);
|
||||
|
||||
struct pa_client_info {
|
||||
uint32_t index;
|
||||
const char *name;
|
||||
uint32_t owner_module;
|
||||
const char *protocol_name;
|
||||
};
|
||||
|
||||
void pa_context_get_client_info(struct pa_context *c, uint32_t index, void (*cb)(struct pa_context *c, const struct pa_client_info*i, int is_last, void *userdata), void *userdata);
|
||||
void pa_context_get_client_info_list(struct pa_context *c, void (*cb)(struct pa_context *c, const struct pa_client_info*i, int is_last, void *userdata), void *userdata);
|
||||
|
||||
struct pa_sink_input_info {
|
||||
uint32_t index;
|
||||
const char *name;
|
||||
uint32_t owner_module;
|
||||
uint32_t owner_client;
|
||||
uint32_t sink;
|
||||
struct pa_sample_spec sample_spec;
|
||||
uint32_t volume;
|
||||
uint32_t latency;
|
||||
};
|
||||
|
||||
void pa_context_get_sink_input_info(struct pa_context *c, uint32_t index, void (*cb)(struct pa_context *c, const struct pa_sink_input_info*i, int is_last, void *userdata), void *userdata);
|
||||
void pa_context_get_sink_input_info_list(struct pa_context *c, void (*cb)(struct pa_context *c, const struct pa_sink_input_info*i, int is_last, void *userdata), void *userdata);
|
||||
|
||||
struct pa_source_output_info {
|
||||
uint32_t index;
|
||||
const char *name;
|
||||
uint32_t owner_module;
|
||||
uint32_t owner_client;
|
||||
uint32_t source;
|
||||
struct pa_sample_spec sample_spec;
|
||||
};
|
||||
|
||||
void pa_context_get_source_output_info(struct pa_context *c, uint32_t index, void (*cb)(struct pa_context *c, const struct pa_source_output_info*i, int is_last, void *userdata), void *userdata);
|
||||
void pa_context_get_source_output_info_list(struct pa_context *c, void (*cb)(struct pa_context *c, const struct pa_source_output_info*i, int is_last, void *userdata), void *userdata);
|
||||
|
||||
void pa_context_set_sink_volume(struct pa_context *c, uint32_t index, uint32_t volume, void (*cb)(struct pa_context *c, int success, void *userdata), void *userdata);
|
||||
void pa_context_set_sink_input_volume(struct pa_context *c, uint32_t index, uint32_t volume, void (*cb)(struct pa_context *c, int success, void *userdata), void *userdata);
|
||||
|
||||
void pa_context_exit(struct pa_context *c);
|
||||
void pa_context_stat(struct pa_context *c, void (*cb)(struct pa_context *c, uint32_t count, uint32_t total, void *userdata), void *userdata);
|
||||
|
||||
void pa_context_subscribe(struct pa_context *c, enum pa_subscription_mask m, void (*cb)(struct pa_context *c, enum pa_subscription_event_type t, uint32_t index, void *userdata), void *userdata);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#include "polyplib-context.h"
|
||||
#include "polyplib-stream.h"
|
||||
#include "polyplib-introspect.h"
|
||||
#include "polyplib-subscribe.h"
|
||||
#include "polyplib-scache.h"
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -135,10 +135,3 @@ void pa_volume_memchunk(struct pa_memchunk*c, const struct pa_sample_spec *spec,
|
|||
}
|
||||
}
|
||||
|
||||
uint32_t pa_volume_multiply(uint32_t a, uint32_t b) {
|
||||
uint64_t p = a;
|
||||
p *= b;
|
||||
p /= PA_VOLUME_NORM;
|
||||
|
||||
return (uint32_t) p;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,8 +26,6 @@
|
|||
#include "memblock.h"
|
||||
#include "memchunk.h"
|
||||
|
||||
#define PA_VOLUME_NORM (0x100)
|
||||
#define PA_VOLUME_MUTE (0)
|
||||
|
||||
struct pa_memblock *pa_silence_memblock(struct pa_memblock* b, const struct pa_sample_spec *spec);
|
||||
void pa_silence_memchunk(struct pa_memchunk *c, const struct pa_sample_spec *spec);
|
||||
|
|
@ -43,6 +41,4 @@ size_t pa_mix(struct pa_mix_info channels[], unsigned nchannels, void *data, siz
|
|||
|
||||
void pa_volume_memchunk(struct pa_memchunk*c, const struct pa_sample_spec *spec, uint32_t volume);
|
||||
|
||||
uint32_t pa_volume_multiply(uint32_t a, uint32_t b);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -96,3 +96,11 @@ void pa_sample_snprint(char *s, size_t l, const struct pa_sample_spec *spec) {
|
|||
assert(pa_sample_spec_valid(spec));
|
||||
snprintf(s, l, "%s %uch %uHz", table[spec->format], spec->channels, spec->rate);
|
||||
}
|
||||
|
||||
uint32_t pa_volume_multiply(uint32_t a, uint32_t b) {
|
||||
uint64_t p = a;
|
||||
p *= b;
|
||||
p /= PA_VOLUME_NORM;
|
||||
|
||||
return (uint32_t) p;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,9 +25,9 @@
|
|||
#include <inttypes.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#include "cdecl.h"
|
||||
|
||||
PA_C_DECL_BEGIN
|
||||
|
||||
enum pa_sample_format {
|
||||
PA_SAMPLE_U8,
|
||||
|
|
@ -49,10 +49,11 @@ enum pa_sample_format {
|
|||
#endif
|
||||
#define PA_SAMPLE_FLOAT32 PA_SAMPLE_FLOAT32NE
|
||||
|
||||
/** A sample format and attribute specification */
|
||||
struct pa_sample_spec {
|
||||
enum pa_sample_format format;
|
||||
uint32_t rate;
|
||||
uint8_t channels;
|
||||
enum pa_sample_format format; /**< The sample format */
|
||||
uint32_t rate; /**< The sample rate. (e.g. 44100) */
|
||||
uint8_t channels; /**< Audio channels. (1 for mono, 2 for stereo, ...) */
|
||||
};
|
||||
|
||||
size_t pa_bytes_per_second(const struct pa_sample_spec *spec);
|
||||
|
|
@ -64,8 +65,10 @@ int pa_sample_spec_equal(const struct pa_sample_spec*a, const struct pa_sample_s
|
|||
#define PA_SAMPLE_SNPRINT_MAX_LENGTH 32
|
||||
void pa_sample_snprint(char *s, size_t l, const struct pa_sample_spec *spec);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#define PA_VOLUME_NORM (0x100)
|
||||
#define PA_VOLUME_MUTE (0)
|
||||
uint32_t pa_volume_multiply(uint32_t a, uint32_t b);
|
||||
|
||||
PA_C_DECL_END
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -120,7 +120,7 @@ static int do_connect(struct pa_socket_client *c, const struct sockaddr *sa, soc
|
|||
|
||||
if ((r = connect(c->fd, sa, len)) < 0) {
|
||||
if (errno != EINPROGRESS) {
|
||||
fprintf(stderr, "connect(): %s\n", strerror(errno));
|
||||
/*fprintf(stderr, "connect(): %s\n", strerror(errno));*/
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@
|
|||
***/
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include "mainloop-api.h"
|
||||
#include "iochannel.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -48,6 +48,4 @@ int pa_tagstruct_get_arbitrary(struct pa_tagstruct *t, const void **p, size_t le
|
|||
int pa_tagstruct_eof(struct pa_tagstruct*t);
|
||||
const uint8_t* pa_tagstruct_data(struct pa_tagstruct*t, size_t *l);
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -52,25 +52,36 @@ void *pa_xrealloc(void *ptr, size_t size) {
|
|||
return p;
|
||||
}
|
||||
|
||||
void* pa_xmemdup(const void *p, size_t l) {
|
||||
if (!p)
|
||||
return NULL;
|
||||
else {
|
||||
char *r = pa_xmalloc(l);
|
||||
memcpy(r, p, l);
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
char *pa_xstrdup(const char *s) {
|
||||
if (!s)
|
||||
return NULL;
|
||||
else {
|
||||
char *r = strdup(s);
|
||||
if (!r)
|
||||
oom();
|
||||
|
||||
return r;
|
||||
}
|
||||
return pa_xmemdup(s, strlen(s)+1);
|
||||
}
|
||||
|
||||
char *pa_xstrndup(const char *s, size_t l) {
|
||||
if (!s)
|
||||
return NULL;
|
||||
else {
|
||||
char *r = strndup(s, l);
|
||||
if (!r)
|
||||
oom();
|
||||
char *r;
|
||||
size_t t = strlen(s);
|
||||
|
||||
if (t > l)
|
||||
t = l;
|
||||
|
||||
r = pa_xmemdup(s, t+1);
|
||||
r[t] = 0;
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,4 +12,6 @@ void *pa_xrealloc(void *ptr, size_t size);
|
|||
char *pa_xstrdup(const char *s);
|
||||
char *pa_xstrndup(const char *s, size_t l);
|
||||
|
||||
void* pa_xmemdup(const void *p, size_t l);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue