source: roaraudio/libroar/simple.c @ 6052:d48765b2475e

Last change on this file since 6052:d48765b2475e was 6052:d48765b2475e, checked in by phi, 9 years ago

updated copyright headers

File size: 5.4 KB
Line 
1//simple.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2015
5 *
6 *  This file is part of libroar 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 *  libroar 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 *  NOTE for everyone want's to change something and send patches:
25 *  read README and HACKING! There a addition information on
26 *  the license of this document you need to read before you send
27 *  any patches.
28 *
29 *  NOTE for uses of non-GPL (LGPL,...) software using libesd, libartsc
30 *  or libpulse*:
31 *  The libs libroaresd, libroararts and libroarpulse link this lib
32 *  and are therefore GPL. Because of this it may be illigal to use
33 *  them with any software that uses libesd, libartsc or libpulse*.
34 */
35
36#include "libroar.h"
37
38static int roar_simple_stream_obj  (struct roar_stream * s, uint32_t rate, uint32_t channels, uint32_t bits, uint32_t codec, const char * server, int dir, const char * name, int mixer);
39
40int roar_simple_connect (struct roar_connection * con, const char * server, const char * name) {
41 return roar_simple_connect2(con, server, name, 0, 0);
42}
43
44int roar_simple_connect2(struct roar_connection * con, const char * server, const char * name, int flags, uint_least32_t timeout) {
45
46 ROAR_DBG("roar_simple_connect(*): trying to connect...");
47
48 if ( roar_connect(con, server, flags, timeout) == -1 ) {
49  ROAR_DBG("roar_simple_connect(*): roar_connect() faild: %s", roar_errorstring);
50  return -1;
51 }
52
53 if ( roar_identify(con, name) == -1 ) {
54  ROAR_DBG("roar_simple_connect(*): roar_identify() faild: %s", roar_errorstring);
55  return -1;
56 }
57
58 if ( roar_auth(con) == -1 ) {
59  ROAR_DBG("roar_simple_connect(*): roar_auth() faild: %s", roar_errorstring);
60  return -1;
61 }
62
63 return 0;
64}
65
66static int roar_simple_stream_obj  (struct roar_stream * s, uint32_t rate, uint32_t channels, uint32_t bits, uint32_t codec, const char * server, int dir, const char * name, int mixer) {
67 struct roar_connection con;
68 int ret;
69 int safe_error;
70
71 roar_debug_warn_sysio("roar_simple_stream_obj", NULL, NULL);
72
73 if ( roar_simple_connect(&con, server, name) == -1 ) {
74  ROAR_DBG("roar_simple_stream_obj(*): roar_simple_connect() faild!");
75  ROAR_ERR("roar_simple_stream_obj(*): Can not connect to server");
76  return -1;
77 }
78
79 if ( roar_stream_new(s, rate, channels, bits, codec) == -1 ) {
80  safe_error = roar_error;
81  roar_disconnect(&con);
82  roar_err_set(safe_error);
83  return -1;
84 }
85
86 if ( roar_stream_connect(&con, s, dir, mixer) == -1 ) {
87  safe_error = roar_error;
88  roar_disconnect(&con);
89  roar_err_set(safe_error);
90  return -1;
91 }
92
93 if ( roar_stream_exec(&con, s) == -1 ) {
94  safe_error = roar_error;
95  roar_disconnect(&con);
96  roar_err_set(safe_error);
97  return -1;
98 }
99
100 roar_libroar_nowarn();
101 if ( (ret = roar_get_connection_fh(&con)) == -1 ) {
102  safe_error = roar_error;
103  roar_libroar_warn();
104  roar_disconnect(&con);
105  roar_err_set(safe_error);
106  return -1;
107 }
108 roar_libroar_warn();
109
110 if ( dir == ROAR_DIR_PLAY ) {
111  (void)ROAR_SHUTDOWN(ret, SHUT_RD);
112 } else if ( dir == ROAR_DIR_MONITOR || dir == ROAR_DIR_RECORD ) {
113  (void)ROAR_SHUTDOWN(ret, SHUT_WR);
114 }
115
116 return ret;
117}
118
119int roar_simple_new_stream_attachexeced_obj (struct roar_connection * con, struct roar_stream * s, uint32_t rate, uint32_t channels, uint32_t bits, uint32_t codec, int dir, int mixer) {
120 int fh;
121
122 if ( (fh = roar_simple_stream_obj(s, rate, channels, bits, codec, roar_get_connection_server(con),
123                                   dir, "libroar temp stream", mixer)) == -1 )
124  return -1;
125
126 if ( roar_stream_attach_simple(con, s, roar_get_clientid(con)) == -1 ) {
127#ifdef ROAR_HAVE_IO_POSIX
128  close(fh);
129#endif /* no else as we return -1 anyway */
130  return -1;
131 }
132
133 s->fh = fh;
134
135 return fh;
136}
137
138int roar_simple_play_file(const char * file, const char * server, const char * name) {
139 roar_vs_t * vss;
140 int err;
141
142 vss = roar_vs_new_from_file(server, name, file, &err);
143
144 if ( vss == NULL ) {
145  roar_err_set(err);
146  return -1;
147 }
148
149 if ( roar_vs_run(vss, &err) == -1 ) {
150  roar_vs_close(vss, ROAR_VS_TRUE, NULL);
151  roar_err_set(err);
152  return -1;
153 }
154
155 roar_vs_sync(vss, ROAR_VS_WAIT, NULL);
156 roar_vs_close(vss, ROAR_VS_FALSE, NULL);
157
158 return 0;
159}
160
161int roar_simple_connect_virtual(struct roar_connection * con, struct roar_stream * s, int parent, int dir) {
162 struct roar_stream parent_stream;
163
164 if ( con == NULL || s == NULL || parent < 0 )
165  return -1;
166
167 if ( dir == -1 ) {
168  if ( roar_get_stream(con, &parent_stream, parent) == -1 )
169   return -1;
170
171  if ( (dir = roar_stream_get_dir(&parent_stream)) == -1 )
172   return -1;
173 }
174
175 if ( roar_stream_set_rel_id(s, parent) == -1 )
176  return -1;
177
178 if ( roar_stream_connect(con, s, dir, -1) == -1 )
179  return -1;
180
181 if ( roar_stream_set_flags(con, s, ROAR_FLAG_VIRTUAL, ROAR_SET_FLAG) == -1 ) {
182  roar_kick(con, ROAR_OT_STREAM, roar_stream_get_id(s));
183  return -1;
184 }
185
186 return 0;
187}
188
189//ll
Note: See TracBrowser for help on using the repository browser.