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 | char buf[8] = {0, 0, 0, 0, 0, 1, 0, 0}; |
---|
38 | |
---|
39 | if ( emul_rsound_lastcon == -1 ) { |
---|
40 | emul_rsound_lastcon = fh; |
---|
41 | return -2; |
---|
42 | } else { |
---|
43 | emul_rsound_lastcon = -1; |
---|
44 | |
---|
45 | client = clients_new(); |
---|
46 | |
---|
47 | if ( client == -1 ) |
---|
48 | return -1; |
---|
49 | |
---|
50 | if ( clients_set_fh(client, fh) == -1 ) { |
---|
51 | ROAR_ERR("net_get_new_client(void): Can not set client's fh"); |
---|
52 | |
---|
53 | clients_delete(client); |
---|
54 | close(oldfh); |
---|
55 | close(fh); |
---|
56 | |
---|
57 | ROAR_DBG("net_get_new_client(void) = -1"); |
---|
58 | return -1; |
---|
59 | } |
---|
60 | |
---|
61 | if ( emul_rsound_new_client(client, oldfh) == -1 ) { |
---|
62 | clients_delete(client); |
---|
63 | return -1; |
---|
64 | } |
---|
65 | |
---|
66 | ROAR_NETWORK_WRITE(oldfh, buf, 8); |
---|
67 | |
---|
68 | return client; |
---|
69 | } |
---|
70 | |
---|
71 | return -1; |
---|
72 | } |
---|
73 | |
---|
74 | int emul_rsound_new_client (int client, int data) { |
---|
75 | struct roar_stream_server * ss; |
---|
76 | struct roar_stream * s; |
---|
77 | struct roar_client * c; |
---|
78 | int stream; |
---|
79 | |
---|
80 | if ( clients_get(client, &c) == -1 ) { |
---|
81 | return -1; |
---|
82 | } |
---|
83 | |
---|
84 | if ((stream = streams_new()) == -1 ) { |
---|
85 | clients_delete(client); |
---|
86 | return -1; |
---|
87 | } |
---|
88 | |
---|
89 | if ( streams_get(stream, &ss) == -1 ) { |
---|
90 | streams_delete(stream); |
---|
91 | clients_delete(client); |
---|
92 | return -1; |
---|
93 | } |
---|
94 | |
---|
95 | s = ROAR_STREAM(ss); |
---|
96 | |
---|
97 | if ( client_stream_add(client, stream) == -1 ) { |
---|
98 | streams_delete(stream); |
---|
99 | clients_delete(client); |
---|
100 | return -1; |
---|
101 | } |
---|
102 | |
---|
103 | memcpy(&(s->info), g_sa, sizeof(struct roar_audio_info)); |
---|
104 | |
---|
105 | ss->codec_orgi = s->info.codec = ROAR_CODEC_DEFAULT; |
---|
106 | |
---|
107 | if ( streams_set_dir(stream, ROAR_DIR_PLAY, 1) == -1 ) { |
---|
108 | clients_delete(client); |
---|
109 | return -1; |
---|
110 | } |
---|
111 | |
---|
112 | /* |
---|
113 | if ( client_stream_exec(client, stream) == -1 ) { |
---|
114 | clients_delete(client); |
---|
115 | return -1; |
---|
116 | } |
---|
117 | */ |
---|
118 | |
---|
119 | if ( client_stream_set_fh(client, stream, data) == -1 ) { |
---|
120 | streams_delete(stream); |
---|
121 | clients_delete(client); |
---|
122 | return -1; |
---|
123 | } |
---|
124 | |
---|
125 | return 0; |
---|
126 | } |
---|
127 | |
---|
128 | #endif |
---|
129 | |
---|
130 | //ll |
---|