4 This file is part of polypaudio.
6 polypaudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published
8 by the Free Software Foundation; either version 2 of the License,
9 or (at your option) any later version.
11 polypaudio is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with polypaudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
30 #include <arpa/inet.h>
34 #include "socket-server.h"
35 #include "socket-util.h"
39 #ifdef USE_PROTOCOL_SIMPLE
40 #include "protocol-simple.h"
41 #define protocol_new pa_protocol_simple_new
42 #define protocol_free pa_protocol_simple_free
43 #define IPV4_PORT 4711
44 #define UNIX_SOCKET "/tmp/polypaudio/simple"
45 #define MODULE_ARGUMENTS "rate", "format", "channels", "sink", "source", "playback", "record",
47 #ifdef USE_PROTOCOL_CLI
48 #include "protocol-cli.h"
49 #define protocol_new pa_protocol_cli_new
50 #define protocol_free pa_protocol_cli_free
51 #define IPV4_PORT 4712
52 #define UNIX_SOCKET "/tmp/polypaudio/cli"
53 #define MODULE_ARGUMENTS
55 #ifdef USE_PROTOCOL_NATIVE
56 #include "protocol-native.h"
57 #define protocol_new pa_protocol_native_new
58 #define protocol_free pa_protocol_native_free
59 #define IPV4_PORT 4713
60 #define UNIX_SOCKET "/tmp/polypaudio/native"
61 #define MODULE_ARGUMENTS "public", "cookie",
63 #ifdef USE_PROTOCOL_ESOUND
64 #include "protocol-esound.h"
66 #define protocol_new pa_protocol_esound_new
67 #define protocol_free pa_protocol_esound_free
68 #define IPV4_PORT ESD_DEFAULT_PORT
69 #define UNIX_SOCKET ESD_UNIX_SOCKET_NAME
70 #define MODULE_ARGUMENTS "sink", "source", "public", "cookie",
72 #error "Broken build system"
78 static const char* const valid_modargs[] = {
80 #ifdef USE_TCP_SOCKETS
89 static struct pa_socket_server *create_socket_server(struct pa_core *c, struct pa_modargs *ma) {
90 struct pa_socket_server *s;
91 #ifdef USE_TCP_SOCKETS
92 uint32_t loopback = 0, port = IPV4_PORT;
94 if (pa_modargs_get_value_u32(ma, "loopback", &loopback) < 0) {
95 fprintf(stderr, "loopback= expects a numerical argument.\n");
99 if (pa_modargs_get_value_u32(ma, "port", &port) < 0) {
100 fprintf(stderr, "port= expects a numerical argument.\n");
104 if (!(s = pa_socket_server_new_ipv4(c->mainloop, loopback ? INADDR_LOOPBACK : INADDR_ANY, port)))
110 p = pa_modargs_get_value(ma, "socket", UNIX_SOCKET);
113 if (pa_unix_socket_make_secure_dir(p) < 0) {
114 fprintf(stderr, "Failed to create secure socket directory.\n");
118 if ((r = pa_unix_socket_remove_stale(p)) < 0) {
119 fprintf(stderr, "Failed to remove stale UNIX socket '%s': %s\n", p, strerror(errno));
124 fprintf(stderr, "Removed stale UNIX socket '%s'.", p);
126 if (!(s = pa_socket_server_new_unix(c->mainloop, p)))
133 int pa_module_init(struct pa_core *c, struct pa_module*m) {
134 struct pa_socket_server *s;
135 struct pa_modargs *ma = NULL;
139 if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
140 fprintf(stderr, "Failed to parse module arguments\n");
144 if (!(s = create_socket_server(c, ma)))
147 if (!(m->userdata = protocol_new(c, s, m, ma))) {
148 pa_socket_server_free(s);
161 void pa_module_done(struct pa_core *c, struct pa_module*m) {
164 protocol_free(m->userdata);