1 | //emul_rsound.c: |
---|
2 | |
---|
3 | /* |
---|
4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010 |
---|
5 | * |
---|
6 | * This file is part of roard a part of RoarAudio, |
---|
7 | * a cross-platform sound system for both, home and professional use. |
---|
8 | * See README for details. |
---|
9 | * |
---|
10 | * This file is free software; you can redistribute it and/or modify |
---|
11 | * it under the terms of the GNU General Public License version 3 |
---|
12 | * as published by the Free Software Foundation. |
---|
13 | * |
---|
14 | * RoarAudio is distributed in the hope that it will be useful, |
---|
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
17 | * GNU General Public License for more details. |
---|
18 | * |
---|
19 | * You should have received a copy of the GNU General Public License |
---|
20 | * along with this software; see the file COPYING. If not, write to |
---|
21 | * the Free Software Foundation, 51 Franklin Street, Fifth Floor, |
---|
22 | * Boston, MA 02110-1301, USA. |
---|
23 | * |
---|
24 | */ |
---|
25 | |
---|
26 | #include "roard.h" |
---|
27 | |
---|
28 | #ifndef ROAR_WITHOUT_DCOMP_EMUL_RSOUND |
---|
29 | |
---|
30 | static int emul_rsound_lastcon = -1; |
---|
31 | |
---|
32 | int emul_rsound_new_client (int client, int data); |
---|
33 | |
---|
34 | int emul_rsound_on_connect (int fh, struct roard_listen * lsock) { |
---|
35 | int oldfh = emul_rsound_lastcon; |
---|
36 | int client; |
---|
37 | union { |
---|
38 | int32_t i[2]; |
---|
39 | char c[8]; |
---|
40 | } buf; |
---|
41 | |
---|
42 | if ( emul_rsound_lastcon == -1 ) { |
---|
43 | emul_rsound_lastcon = fh; |
---|
44 | return -2; |
---|
45 | } else { |
---|
46 | emul_rsound_lastcon = -1; |
---|
47 | |
---|
48 | client = clients_new(); |
---|
49 | |
---|
50 | if ( client == -1 ) |
---|
51 | return -1; |
---|
52 | |
---|
53 | if ( clients_set_fh(client, fh) == -1 ) { |
---|
54 | ROAR_ERR("net_get_new_client(void): Can not set client's fh"); |
---|
55 | |
---|
56 | clients_delete(client); |
---|
57 | close(oldfh); |
---|
58 | close(fh); |
---|
59 | |
---|
60 | ROAR_DBG("net_get_new_client(void) = -1"); |
---|
61 | return -1; |
---|
62 | } |
---|
63 | |
---|
64 | if ( emul_rsound_new_client(client, oldfh) == -1 ) { |
---|
65 | clients_delete(client); |
---|
66 | return -1; |
---|
67 | } |
---|
68 | |
---|
69 | buf.i[0] = ROAR_HOST2NET32(0); |
---|
70 | buf.i[1] = ROAR_HOST2NET32(512); |
---|
71 | |
---|
72 | ROAR_NETWORK_WRITE(oldfh, buf.c, 8); |
---|
73 | |
---|
74 | return client; |
---|
75 | } |
---|
76 | |
---|
77 | return -1; |
---|
78 | } |
---|
79 | |
---|
80 | int emul_rsound_new_client (int client, int data) { |
---|
81 | struct roar_stream_server * ss; |
---|
82 | struct roar_stream * s; |
---|
83 | struct roar_client * c; |
---|
84 | int stream; |
---|
85 | |
---|
86 | if ( clients_get(client, &c) == -1 ) { |
---|
87 | return -1; |
---|
88 | } |
---|
89 | |
---|
90 | if ((stream = streams_new()) == -1 ) { |
---|
91 | clients_delete(client); |
---|
92 | return -1; |
---|
93 | } |
---|
94 | |
---|
95 | if ( streams_get(stream, &ss) == -1 ) { |
---|
96 | streams_delete(stream); |
---|
97 | clients_delete(client); |
---|
98 | return -1; |
---|
99 | } |
---|
100 | |
---|
101 | s = ROAR_STREAM(ss); |
---|
102 | |
---|
103 | if ( client_stream_add(client, stream) == -1 ) { |
---|
104 | streams_delete(stream); |
---|
105 | clients_delete(client); |
---|
106 | return -1; |
---|
107 | } |
---|
108 | |
---|
109 | memcpy(&(s->info), g_sa, sizeof(struct roar_audio_info)); |
---|
110 | |
---|
111 | ss->codec_orgi = s->info.codec = ROAR_CODEC_RIFF_WAVE; |
---|
112 | |
---|
113 | if ( streams_set_dir(stream, ROAR_DIR_PLAY, 1) == -1 ) { |
---|
114 | clients_delete(client); |
---|
115 | return -1; |
---|
116 | } |
---|
117 | |
---|
118 | /* |
---|
119 | if ( client_stream_exec(client, stream) == -1 ) { |
---|
120 | clients_delete(client); |
---|
121 | return -1; |
---|
122 | } |
---|
123 | */ |
---|
124 | |
---|
125 | if ( client_stream_set_fh(client, stream, data) == -1 ) { |
---|
126 | streams_delete(stream); |
---|
127 | clients_delete(client); |
---|
128 | return -1; |
---|
129 | } |
---|
130 | |
---|
131 | return 0; |
---|
132 | } |
---|
133 | |
---|
134 | #endif |
---|
135 | |
---|
136 | //ll |
---|