mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-02 09:01:46 -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
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue