mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-03 09:01:50 -05:00
make the protocol plugins make use of modargs
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@62 fefdeb5f-60dc-0310-8127-8f9354f1896f
This commit is contained in:
parent
a96ed347a3
commit
216591d95e
17 changed files with 275 additions and 79 deletions
|
|
@ -106,6 +106,8 @@ int pa_authkey_load_from_home(const char *fn, void *data, size_t length) {
|
|||
char *home;
|
||||
char path[PATH_MAX];
|
||||
|
||||
assert(fn && data && length);
|
||||
|
||||
if (!(home = getenv("HOME")))
|
||||
return -2;
|
||||
|
||||
|
|
@ -113,3 +115,12 @@ int pa_authkey_load_from_home(const char *fn, void *data, size_t length) {
|
|||
|
||||
return pa_authkey_load(path, data, length);
|
||||
}
|
||||
|
||||
int pa_authkey_load_auto(const char *fn, void *data, size_t length) {
|
||||
assert(fn && data && length);
|
||||
|
||||
if (*fn == '/')
|
||||
return pa_authkey_load(fn, data, length);
|
||||
else
|
||||
return pa_authkey_load_from_home(fn, data, length);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,5 +5,6 @@
|
|||
|
||||
int pa_authkey_load(const char *path, void *data, size_t len);
|
||||
int pa_authkey_load_from_home(const char *fn, void *data, size_t length);
|
||||
int pa_authkey_load_auto(const char *fn, void *data, size_t length);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -7,6 +7,9 @@
|
|||
#include "modargs.h"
|
||||
#include "idxset.h"
|
||||
#include "sample-util.h"
|
||||
#include "namereg.h"
|
||||
#include "sink.h"
|
||||
#include "source.h"
|
||||
|
||||
struct pa_modargs;
|
||||
|
||||
|
|
@ -220,3 +223,37 @@ int pa_modargs_get_sample_spec(struct pa_modargs *ma, struct pa_sample_spec *rss
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pa_modargs_get_source_index(struct pa_modargs *ma, struct pa_core *c, uint32_t *index) {
|
||||
const char *t;
|
||||
assert(ma && index);
|
||||
|
||||
if (!(t = pa_modargs_get_value(ma, "source", NULL)))
|
||||
*index = PA_IDXSET_INVALID;
|
||||
else {
|
||||
struct pa_source *source;
|
||||
if (!(source = pa_namereg_get(c, t, PA_NAMEREG_SOURCE)))
|
||||
return -1;
|
||||
|
||||
*index = source->index;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pa_modargs_get_sink_index(struct pa_modargs *ma, struct pa_core *c, uint32_t *index) {
|
||||
const char *t;
|
||||
assert(ma && index);
|
||||
|
||||
if (!(t = pa_modargs_get_value(ma, "sink", NULL)))
|
||||
*index = PA_IDXSET_INVALID;
|
||||
else {
|
||||
struct pa_sink *sink;
|
||||
if (!(sink = pa_namereg_get(c, t, PA_NAMEREG_SINK)))
|
||||
return -1;
|
||||
|
||||
*index = sink->index;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include <inttypes.h>
|
||||
#include "sample.h"
|
||||
#include "core.h"
|
||||
|
||||
struct pa_modargs;
|
||||
|
||||
|
|
@ -14,5 +15,7 @@ int pa_modargs_get_value_u32(struct pa_modargs *ma, const char *key, uint32_t *v
|
|||
|
||||
int pa_modargs_get_sample_spec(struct pa_modargs *ma, struct pa_sample_spec *ss);
|
||||
|
||||
int pa_modargs_get_source_index(struct pa_modargs *ma, struct pa_core *c, uint32_t *index);
|
||||
int pa_modargs_get_sink_index(struct pa_modargs *ma, struct pa_core *c, uint32_t *index);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -18,8 +18,13 @@ int pa_module_init(struct pa_core *c, struct pa_module*m) {
|
|||
struct pa_iochannel *io;
|
||||
assert(c && m);
|
||||
|
||||
if (m->argument) {
|
||||
fprintf(stderr, __FILE__": module doesn't accept arguments.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pa_stdio_acquire() < 0) {
|
||||
fprintf(stderr, "STDIN/STDUSE already used\n");
|
||||
fprintf(stderr, __FILE__": STDIN/STDUSE already in use.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,29 +9,31 @@
|
|||
#include "socket-server.h"
|
||||
#include "socket-util.h"
|
||||
#include "util.h"
|
||||
#include "modargs.h"
|
||||
|
||||
#ifdef USE_PROTOCOL_SIMPLE
|
||||
#include "protocol-simple.h"
|
||||
#define protocol_new pa_protocol_simple_new
|
||||
#define protocol_free pa_protocol_simple_free
|
||||
#define IPV4_PORT 4711
|
||||
#define UNIX_SOCKET_DIR "/tmp/polypaudio"
|
||||
#define UNIX_SOCKET "/tmp/polypaudio/simple"
|
||||
#define MODULE_ARGUMENTS "rate", "format", "channels", "sink", "source", "playback", "record",
|
||||
#else
|
||||
#ifdef USE_PROTOCOL_CLI
|
||||
#include "protocol-cli.h"
|
||||
#define protocol_new pa_protocol_cli_new
|
||||
#define protocol_free pa_protocol_cli_free
|
||||
#define IPV4_PORT 4712
|
||||
#define UNIX_SOCKET_DIR "/tmp/polypaudio"
|
||||
#define UNIX_SOCKET "/tmp/polypaudio/cli"
|
||||
#define MODULE_ARGUMENTS
|
||||
#else
|
||||
#ifdef USE_PROTOCOL_NATIVE
|
||||
#include "protocol-native.h"
|
||||
#define protocol_new pa_protocol_native_new
|
||||
#define protocol_free pa_protocol_native_free
|
||||
#define IPV4_PORT 4713
|
||||
#define UNIX_SOCKET_DIR "/tmp/polypaudio"
|
||||
#define UNIX_SOCKET "/tmp/polypaudio/native"
|
||||
#define MODULE_ARGUMENTS "public", "cookie",
|
||||
#else
|
||||
#ifdef USE_PROTOCOL_ESOUND
|
||||
#include "protocol-esound.h"
|
||||
|
|
@ -39,8 +41,8 @@
|
|||
#define protocol_new pa_protocol_esound_new
|
||||
#define protocol_free pa_protocol_esound_free
|
||||
#define IPV4_PORT ESD_DEFAULT_PORT
|
||||
#define UNIX_SOCKET_DIR ESD_UNIX_SOCKET_DIR
|
||||
#define UNIX_SOCKET ESD_UNIX_SOCKET_NAME
|
||||
#define MODULE_ARGUMENTS "sink", "source", "public", "cookie",
|
||||
#else
|
||||
#error "Broken build system"
|
||||
#endif
|
||||
|
|
@ -48,43 +50,75 @@
|
|||
#endif
|
||||
#endif
|
||||
|
||||
int pa_module_init(struct pa_core *c, struct pa_module*m) {
|
||||
struct pa_socket_server *s;
|
||||
assert(c && m);
|
||||
|
||||
static const char* const valid_modargs[] = {
|
||||
MODULE_ARGUMENTS
|
||||
#ifdef USE_TCP_SOCKETS
|
||||
if (!(s = pa_socket_server_new_ipv4(c->mainloop, INADDR_ANY, IPV4_PORT)))
|
||||
return -1;
|
||||
"port",
|
||||
"loopback",
|
||||
#else
|
||||
if (pa_make_secure_dir(UNIX_SOCKET_DIR) < 0) {
|
||||
fprintf(stderr, "Failed to create secure socket directory.\n");
|
||||
return -1;
|
||||
"socket",
|
||||
#endif
|
||||
NULL
|
||||
};
|
||||
|
||||
struct pa_socket_server *create_socket_server(struct pa_core *c, struct pa_modargs *ma) {
|
||||
struct pa_socket_server *s;
|
||||
#ifdef USE_TCP_SOCKETS
|
||||
uint32_t loopback = 0, port = IPV4_PORT;
|
||||
|
||||
if (pa_modargs_get_value_u32(ma, "loopback", &loopback) < 0) {
|
||||
fprintf(stderr, "loopback= expects a numerical argument.\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
{
|
||||
int r;
|
||||
if ((r = pa_unix_socket_remove_stale(UNIX_SOCKET)) < 0) {
|
||||
fprintf(stderr, "Failed to remove stale UNIX socket '%s': %s\n", UNIX_SOCKET, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (r)
|
||||
fprintf(stderr, "Removed stale UNIX socket '%s'.", UNIX_SOCKET);
|
||||
if (pa_modargs_get_value_u32(ma, "port", &port) < 0) {
|
||||
fprintf(stderr, "port= expects a numerical argument.\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!(s = pa_socket_server_new_unix(c->mainloop, UNIX_SOCKET))) {
|
||||
rmdir(UNIX_SOCKET_DIR);
|
||||
if (!(s = pa_socket_server_new_ipv4(c->mainloop, loopback ? INADDR_LOOPBACK : INADDR_ANY, port)))
|
||||
return NULL;
|
||||
#else
|
||||
int r;
|
||||
const char *p;
|
||||
|
||||
p = pa_modargs_get_value(ma, "socket", UNIX_SOCKET);
|
||||
assert(p);
|
||||
|
||||
if (pa_unix_socket_make_secure_dir(p) < 0) {
|
||||
fprintf(stderr, "Failed to create secure socket directory.\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ((r = pa_unix_socket_remove_stale(p)) < 0) {
|
||||
fprintf(stderr, "Failed to remove stale UNIX socket '%s': %s\n", p, strerror(errno));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (r)
|
||||
fprintf(stderr, "Removed stale UNIX socket '%s'.", p);
|
||||
|
||||
if (!(s = pa_socket_server_new_unix(c->mainloop, p)))
|
||||
return NULL;
|
||||
|
||||
#endif
|
||||
return s;
|
||||
}
|
||||
|
||||
int pa_module_init(struct pa_core *c, struct pa_module*m) {
|
||||
struct pa_socket_server *s;
|
||||
struct pa_modargs *ma;
|
||||
assert(c && m);
|
||||
|
||||
if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
|
||||
fprintf(stderr, "Failed to parse module arguments\n");
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef USE_PROTOCOL_SIMPLE
|
||||
m->userdata = pa_protocol_simple_new(c, s, m, PA_PROTOCOL_SIMPLE_PLAYBACK);
|
||||
#else
|
||||
m->userdata = protocol_new(c, s, m);
|
||||
#endif
|
||||
if (!(s = create_socket_server(c, ma)))
|
||||
return -1;
|
||||
|
||||
if (!m->userdata) {
|
||||
if (!(m->userdata = protocol_new(c, s, m, ma))) {
|
||||
pa_socket_server_free(s);
|
||||
return -1;
|
||||
}
|
||||
|
|
@ -96,8 +130,4 @@ void pa_module_done(struct pa_core *c, struct pa_module*m) {
|
|||
assert(c && m);
|
||||
|
||||
protocol_free(m->userdata);
|
||||
|
||||
#ifndef USE_TCP_SOCKETS
|
||||
rmdir(UNIX_SOCKET_DIR);
|
||||
#endif
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ static void on_connection(struct pa_socket_server*s, struct pa_iochannel *io, vo
|
|||
pa_idxset_put(p->connections, c, NULL);
|
||||
}
|
||||
|
||||
struct pa_protocol_cli* pa_protocol_cli_new(struct pa_core *core, struct pa_socket_server *server, struct pa_module *m) {
|
||||
struct pa_protocol_cli* pa_protocol_cli_new(struct pa_core *core, struct pa_socket_server *server, struct pa_module *m, struct pa_modargs *ma) {
|
||||
struct pa_protocol_cli* p;
|
||||
assert(core && server);
|
||||
|
||||
|
|
|
|||
|
|
@ -4,10 +4,11 @@
|
|||
#include "core.h"
|
||||
#include "socket-server.h"
|
||||
#include "module.h"
|
||||
#include "modargs.h"
|
||||
|
||||
struct pa_protocol_cli;
|
||||
|
||||
struct pa_protocol_cli* pa_protocol_cli_new(struct pa_core *core, struct pa_socket_server *server, struct pa_module *m);
|
||||
struct pa_protocol_cli* pa_protocol_cli_new(struct pa_core *core, struct pa_socket_server *server, struct pa_module *m, struct pa_modargs *ma);
|
||||
void pa_protocol_cli_free(struct pa_protocol_cli *n);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
#include "authkey.h"
|
||||
|
||||
#define COOKIE_FILE ".esd_auth"
|
||||
#define DEFAULT_COOKIE_FILE ".esd_auth"
|
||||
|
||||
#define PLAYBACK_BUFFER_SECONDS (.5)
|
||||
#define PLAYBACK_BUFFER_FRAGMENTS (10)
|
||||
|
|
@ -774,14 +774,24 @@ static void on_connection(struct pa_socket_server*s, struct pa_iochannel *io, vo
|
|||
|
||||
/*** entry points ***/
|
||||
|
||||
struct pa_protocol_esound* pa_protocol_esound_new(struct pa_core*core, struct pa_socket_server *server, struct pa_module *m) {
|
||||
struct pa_protocol_esound* pa_protocol_esound_new(struct pa_core*core, struct pa_socket_server *server, struct pa_module *m, struct pa_modargs *ma) {
|
||||
uint32_t source_index, sink_index;
|
||||
struct pa_protocol_esound *p;
|
||||
assert(core && server);
|
||||
assert(core && server && ma);
|
||||
|
||||
if (pa_modargs_get_source_index(ma, core, &source_index) < 0) {
|
||||
fprintf(stderr, __FILE__": source does not exist.\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (pa_modargs_get_sink_index(ma, core, &sink_index) < 0) {
|
||||
fprintf(stderr, __FILE__": sink does not exist.\n");
|
||||
return NULL;
|
||||
}
|
||||
p = malloc(sizeof(struct pa_protocol_esound));
|
||||
assert(p);
|
||||
|
||||
if (pa_authkey_load_from_home(COOKIE_FILE, p->esd_key, sizeof(p->esd_key)) < 0) {
|
||||
if (pa_authkey_load_auto(pa_modargs_get_value(ma, "cookie", DEFAULT_COOKIE_FILE), p->esd_key, sizeof(p->esd_key)) < 0) {
|
||||
free(p);
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -793,7 +803,8 @@ struct pa_protocol_esound* pa_protocol_esound_new(struct pa_core*core, struct pa
|
|||
p->core = core;
|
||||
p->connections = pa_idxset_new(NULL, NULL);
|
||||
assert(p->connections);
|
||||
p->sink_index = p->source_index = PA_IDXSET_INVALID;
|
||||
p->sink_index = sink_index;
|
||||
p->source_index = source_index;
|
||||
p->n_player = 0;
|
||||
|
||||
return p;
|
||||
|
|
|
|||
|
|
@ -4,10 +4,11 @@
|
|||
#include "core.h"
|
||||
#include "socket-server.h"
|
||||
#include "module.h"
|
||||
#include "modargs.h"
|
||||
|
||||
struct pa_protocol_esound;
|
||||
|
||||
struct pa_protocol_esound* pa_protocol_esound_new(struct pa_core*core, struct pa_socket_server *server, struct pa_module *m);
|
||||
struct pa_protocol_esound* pa_protocol_esound_new(struct pa_core*core, struct pa_socket_server *server, struct pa_module *m, struct pa_modargs *ma);
|
||||
void pa_protocol_esound_free(struct pa_protocol_esound *p);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -736,20 +736,26 @@ static void on_connection(struct pa_socket_server*s, struct pa_iochannel *io, vo
|
|||
|
||||
/*** module entry points ***/
|
||||
|
||||
struct pa_protocol_native* pa_protocol_native_new(struct pa_core *core, struct pa_socket_server *server, struct pa_module *m) {
|
||||
struct pa_protocol_native* pa_protocol_native_new(struct pa_core *core, struct pa_socket_server *server, struct pa_module *m, struct pa_modargs *ma) {
|
||||
struct pa_protocol_native *p;
|
||||
assert(core && server);
|
||||
uint32_t public;
|
||||
assert(core && server && ma);
|
||||
|
||||
if (pa_modargs_get_value_u32(ma, "public", &public) < 0) {
|
||||
fprintf(stderr, __FILE__": public= expects numeric argument.\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
p = malloc(sizeof(struct pa_protocol_native));
|
||||
assert(p);
|
||||
|
||||
if (pa_authkey_load_from_home(PA_NATIVE_COOKIE_FILE, p->auth_cookie, sizeof(p->auth_cookie)) < 0) {
|
||||
if (pa_authkey_load_from_home(pa_modargs_get_value(ma, "cookie", PA_NATIVE_COOKIE_FILE), p->auth_cookie, sizeof(p->auth_cookie)) < 0) {
|
||||
free(p);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
p->module = m;
|
||||
p->public = 1;
|
||||
p->public = public;
|
||||
p->server = server;
|
||||
p->core = core;
|
||||
p->connections = pa_idxset_new(NULL, NULL);
|
||||
|
|
|
|||
|
|
@ -4,10 +4,11 @@
|
|||
#include "core.h"
|
||||
#include "socket-server.h"
|
||||
#include "module.h"
|
||||
#include "modargs.h"
|
||||
|
||||
struct pa_protocol_native;
|
||||
|
||||
struct pa_protocol_native* pa_protocol_native_new(struct pa_core*core, struct pa_socket_server *server, struct pa_module *m);
|
||||
struct pa_protocol_native* pa_protocol_native_new(struct pa_core*core, struct pa_socket_server *server, struct pa_module *m, struct pa_modargs *ma);
|
||||
void pa_protocol_native_free(struct pa_protocol_native *n);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
#include "protocol-simple.h"
|
||||
#include "client.h"
|
||||
#include "sample-util.h"
|
||||
#include "namereg.h"
|
||||
|
||||
struct connection {
|
||||
struct pa_protocol_simple *protocol;
|
||||
|
|
@ -31,8 +32,13 @@ struct pa_protocol_simple {
|
|||
struct pa_core *core;
|
||||
struct pa_socket_server*server;
|
||||
struct pa_idxset *connections;
|
||||
enum pa_protocol_simple_mode mode;
|
||||
enum {
|
||||
RECORD = 1,
|
||||
PLAYBACK = 2,
|
||||
DUPLEX = 3
|
||||
} mode;
|
||||
struct pa_sample_spec sample_spec;
|
||||
uint32_t sink_index, source_index;
|
||||
};
|
||||
|
||||
#define PLAYBACK_BUFFER_SECONDS (.5)
|
||||
|
|
@ -263,14 +269,15 @@ static void on_connection(struct pa_socket_server*s, struct pa_iochannel *io, vo
|
|||
c->client->kill = client_kill_cb;
|
||||
c->client->userdata = c;
|
||||
|
||||
if (p->mode & PA_PROTOCOL_SIMPLE_PLAYBACK) {
|
||||
if (p->mode & PLAYBACK) {
|
||||
struct pa_sink *sink;
|
||||
size_t l;
|
||||
|
||||
if (!(sink = pa_sink_get_default(p->core))) {
|
||||
fprintf(stderr, "Failed to get default sink.\n");
|
||||
goto fail;
|
||||
}
|
||||
if (!(sink = pa_idxset_get_by_index(p->core->sinks, p->sink_index)))
|
||||
if (!(sink = pa_sink_get_default(p->core))) {
|
||||
fprintf(stderr, "Failed to get sink.\n");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
c->sink_input = pa_sink_input_new(sink, c->client->name, &p->sample_spec);
|
||||
if (!c->sink_input) {
|
||||
|
|
@ -293,15 +300,15 @@ static void on_connection(struct pa_socket_server*s, struct pa_iochannel *io, vo
|
|||
c->playback.fragment_size = l/10;
|
||||
}
|
||||
|
||||
|
||||
if (p->mode & PA_PROTOCOL_SIMPLE_RECORD) {
|
||||
if (p->mode & RECORD) {
|
||||
struct pa_source *source;
|
||||
size_t l;
|
||||
|
||||
if (!(source = pa_source_get_default(p->core))) {
|
||||
fprintf(stderr, "Failed to get default source.\n");
|
||||
goto fail;
|
||||
}
|
||||
if (!(source = pa_idxset_get_by_index(p->core->sources, p->source_index)))
|
||||
if (!(source = pa_source_get_default(p->core))) {
|
||||
fprintf(stderr, "Failed to get source.\n");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
c->source_output = pa_source_output_new(source, c->client->name, &p->sample_spec);
|
||||
if (!c->source_output) {
|
||||
|
|
@ -334,22 +341,62 @@ fail:
|
|||
connection_free(c);
|
||||
}
|
||||
|
||||
struct pa_protocol_simple* pa_protocol_simple_new(struct pa_core *core, struct pa_socket_server *server, struct pa_module *m, enum pa_protocol_simple_mode mode) {
|
||||
struct pa_protocol_simple* p;
|
||||
assert(core && server && mode <= PA_PROTOCOL_SIMPLE_DUPLEX && mode > 0);
|
||||
struct pa_protocol_simple* pa_protocol_simple_new(struct pa_core *core, struct pa_socket_server *server, struct pa_module *m, struct pa_modargs *ma) {
|
||||
struct pa_protocol_simple* p = NULL;
|
||||
uint32_t enable;
|
||||
assert(core && server && ma);
|
||||
|
||||
p = malloc(sizeof(struct pa_protocol_simple));
|
||||
assert(p);
|
||||
memset(p, 0, sizeof(struct pa_protocol_simple));
|
||||
|
||||
p->module = m;
|
||||
p->core = core;
|
||||
p->server = server;
|
||||
p->connections = pa_idxset_new(NULL, NULL);
|
||||
p->mode = mode;
|
||||
p->sample_spec = PA_DEFAULT_SAMPLE_SPEC;
|
||||
|
||||
if (pa_modargs_get_sample_spec(ma, &p->sample_spec) < 0) {
|
||||
fprintf(stderr, "Failed to parse sample type specification.\n");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (pa_modargs_get_source_index(ma, core, &p->source_index) < 0) {
|
||||
fprintf(stderr, __FILE__": source does not exist.\n");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (pa_modargs_get_sink_index(ma, core, &p->sink_index) < 0) {
|
||||
fprintf(stderr, __FILE__": sink does not exist.\n");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
enable = 0;
|
||||
if (pa_modargs_get_value_u32(ma, "record", &enable) < 0) {
|
||||
fprintf(stderr, __FILE__": record= expects a numeric argument.\n");
|
||||
goto fail;
|
||||
}
|
||||
p->mode = enable ? RECORD : 0;
|
||||
|
||||
enable = 1;
|
||||
if (pa_modargs_get_value_u32(ma, "playback", &enable) < 0) {
|
||||
fprintf(stderr, __FILE__": playback= expects a numeric argument.\n");
|
||||
goto fail;
|
||||
}
|
||||
p->mode |= enable ? PLAYBACK : 0;
|
||||
|
||||
if ((p->mode & (RECORD|PLAYBACK)) == 0) {
|
||||
fprintf(stderr, __FILE__": neither playback nor recording enabled for protocol.\n");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
pa_socket_server_set_callback(p->server, on_connection, p);
|
||||
|
||||
return p;
|
||||
|
||||
fail:
|
||||
if (p)
|
||||
pa_protocol_simple_free(p);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -357,12 +404,15 @@ void pa_protocol_simple_free(struct pa_protocol_simple *p) {
|
|||
struct connection *c;
|
||||
assert(p);
|
||||
|
||||
while((c = pa_idxset_first(p->connections, NULL)))
|
||||
connection_free(c);
|
||||
if (p->connections) {
|
||||
while((c = pa_idxset_first(p->connections, NULL)))
|
||||
connection_free(c);
|
||||
|
||||
pa_idxset_free(p->connections, NULL, NULL);
|
||||
}
|
||||
|
||||
pa_idxset_free(p->connections, NULL, NULL);
|
||||
|
||||
pa_socket_server_free(p->server);
|
||||
if (p->server)
|
||||
pa_socket_server_free(p->server);
|
||||
free(p);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,16 +4,11 @@
|
|||
#include "socket-server.h"
|
||||
#include "module.h"
|
||||
#include "core.h"
|
||||
#include "modargs.h"
|
||||
|
||||
struct pa_protocol_simple;
|
||||
|
||||
enum pa_protocol_simple_mode {
|
||||
PA_PROTOCOL_SIMPLE_RECORD = 1,
|
||||
PA_PROTOCOL_SIMPLE_PLAYBACK = 2,
|
||||
PA_PROTOCOL_SIMPLE_DUPLEX = 3
|
||||
};
|
||||
|
||||
struct pa_protocol_simple* pa_protocol_simple_new(struct pa_core *core, struct pa_socket_server *server, struct pa_module *m, enum pa_protocol_simple_mode mode);
|
||||
struct pa_protocol_simple* pa_protocol_simple_new(struct pa_core *core, struct pa_socket_server *server, struct pa_module *m, struct pa_modargs *ma);
|
||||
void pa_protocol_simple_free(struct pa_protocol_simple *n);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@
|
|||
#include <netinet/ip.h>
|
||||
|
||||
#include "socket-util.h"
|
||||
#include "util.h"
|
||||
|
||||
void pa_socket_peer_to_string(int fd, char *c, size_t l) {
|
||||
struct stat st;
|
||||
|
|
@ -150,3 +151,41 @@ int pa_unix_socket_remove_stale(const char *fn) {
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pa_unix_socket_make_secure_dir(const char *fn) {
|
||||
int ret = -1;
|
||||
char *slash, *dir = strdup(fn);
|
||||
assert(dir);
|
||||
|
||||
if (!(slash = strrchr(dir, '/')))
|
||||
goto finish;
|
||||
*slash = 0;
|
||||
|
||||
if (pa_make_secure_dir(dir) < 0)
|
||||
goto finish;
|
||||
|
||||
ret = 0;
|
||||
|
||||
finish:
|
||||
free(dir);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int pa_unix_socket_remove_secure_dir(const char *fn) {
|
||||
int ret = -1;
|
||||
char *slash, *dir = strdup(fn);
|
||||
assert(dir);
|
||||
|
||||
if (!(slash = strrchr(dir, '/')))
|
||||
goto finish;
|
||||
*slash = 0;
|
||||
|
||||
if (rmdir(dir) < 0)
|
||||
goto finish;
|
||||
|
||||
ret = 0;
|
||||
|
||||
finish:
|
||||
free(dir);
|
||||
return ret;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,4 +14,7 @@ int pa_socket_set_rcvbuf(int fd, size_t l);
|
|||
int pa_unix_socket_is_stale(const char *fn);
|
||||
int pa_unix_socket_remove_stale(const char *fn);
|
||||
|
||||
int pa_unix_socket_make_secure_dir(const char *fn);
|
||||
int pa_unix_socket_remove_secure_dir(const char *fn);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
4
src/todo
4
src/todo
|
|
@ -1,7 +1,9 @@
|
|||
- native library/protocol:
|
||||
more functions (esp. latency)
|
||||
|
||||
- make all modules use modargs.c
|
||||
- make all modules use modargs.c:
|
||||
module-oss.c
|
||||
module-oss-mmap.c
|
||||
- cmdline
|
||||
- daemonizing
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue