1 | //simple.c: |
---|
2 | |
---|
3 | #include "libroar.h" |
---|
4 | |
---|
5 | int roar_simple_connect (struct roar_connection * con, char * server, char * name) { |
---|
6 | |
---|
7 | ROAR_DBG("roar_simple_connect(*): trying to connect..."); |
---|
8 | |
---|
9 | if ( roar_connect(con, server) == -1 ) { |
---|
10 | ROAR_DBG("roar_simple_connect(*): roar_connect() faild!"); |
---|
11 | return -1; |
---|
12 | } |
---|
13 | |
---|
14 | if ( roar_identify(con, name) == -1 ) { |
---|
15 | ROAR_DBG("roar_simple_connect(*): roar_identify() faild!"); |
---|
16 | return -1; |
---|
17 | } |
---|
18 | |
---|
19 | if ( roar_auth(con) == -1 ) { |
---|
20 | ROAR_DBG("roar_simple_connect(*): roar_auth() faild!"); |
---|
21 | return -1; |
---|
22 | } |
---|
23 | |
---|
24 | return 0; |
---|
25 | } |
---|
26 | |
---|
27 | int roar_simple_stream(int rate, int channels, int bits, int codec, char * server, int dir, char * name) { |
---|
28 | struct roar_connection con; |
---|
29 | struct roar_stream s; |
---|
30 | |
---|
31 | if ( roar_simple_connect(&con, server, name) == -1 ) { |
---|
32 | ROAR_DBG("roar_simple_play(*): roar_simple_connect() faild!"); |
---|
33 | return -1; |
---|
34 | } |
---|
35 | |
---|
36 | if ( roar_stream_new(&s, rate, channels, bits, codec) == -1 ) { |
---|
37 | roar_disconnect(&con); |
---|
38 | return -1; |
---|
39 | } |
---|
40 | |
---|
41 | if ( roar_stream_connect(&con, &s, dir) == -1 ) { |
---|
42 | roar_disconnect(&con); |
---|
43 | return -1; |
---|
44 | } |
---|
45 | |
---|
46 | if ( roar_stream_exec(&con, &s) == -1 ) { |
---|
47 | roar_disconnect(&con); |
---|
48 | return -1; |
---|
49 | } |
---|
50 | |
---|
51 | if ( dir == ROAR_DIR_PLAY ) { |
---|
52 | shutdown(con.fh, SHUT_RD); |
---|
53 | } else if ( dir == ROAR_DIR_MONITOR || dir == ROAR_DIR_RECORD ) { |
---|
54 | shutdown(con.fh, SHUT_WR); |
---|
55 | } |
---|
56 | |
---|
57 | return con.fh; |
---|
58 | } |
---|
59 | |
---|
60 | int roar_simple_new_stream (struct roar_connection * con, int rate, int channels, int bits, int codec, int dir) { |
---|
61 | struct roar_stream s; |
---|
62 | struct roar_message mes; |
---|
63 | char file[80]; |
---|
64 | int fh = -1, listen; |
---|
65 | static int count = 0; |
---|
66 | |
---|
67 | sprintf(file, "/tmp/.libroar-simple-stream.%i-%i", getpid(), count++); |
---|
68 | |
---|
69 | if ( (listen = roar_socket_listen(ROAR_SOCKET_TYPE_UNIX, file, 0)) == -1 ) { |
---|
70 | return -1; |
---|
71 | } |
---|
72 | |
---|
73 | if ( roar_stream_new(&s, rate, channels, bits, codec) == -1 ) { |
---|
74 | return -1; |
---|
75 | } |
---|
76 | |
---|
77 | if ( roar_stream_connect(con, &s, dir) == -1 ) { |
---|
78 | return -1; |
---|
79 | } |
---|
80 | |
---|
81 | if ( roar_stream_connect_to_ask(con, &s, ROAR_SOCKET_TYPE_UNIX, file, 0) != -1 ) { |
---|
82 | |
---|
83 | if ( (fh = accept(listen, NULL, NULL)) != -1 ) { |
---|
84 | if ( dir == ROAR_DIR_PLAY ) { |
---|
85 | shutdown(fh, SHUT_RD); |
---|
86 | } else if ( dir == ROAR_DIR_MONITOR || dir == ROAR_DIR_RECORD ) { |
---|
87 | shutdown(fh, SHUT_WR); |
---|
88 | } |
---|
89 | } |
---|
90 | if ( roar_recv_message(con, &mes, NULL) == -1 ) { |
---|
91 | close(fh); |
---|
92 | fh = -1; |
---|
93 | } else if ( mes.cmd != ROAR_CMD_OK ) { |
---|
94 | close(fh); |
---|
95 | fh = -1; |
---|
96 | } |
---|
97 | } |
---|
98 | |
---|
99 | close(listen); |
---|
100 | unlink(file); |
---|
101 | |
---|
102 | return fh; |
---|
103 | } |
---|
104 | |
---|
105 | int roar_simple_play(int rate, int channels, int bits, int codec, char * server, char * name) { |
---|
106 | return roar_simple_stream(rate, channels, bits, codec, server, ROAR_DIR_PLAY, name); |
---|
107 | } |
---|
108 | |
---|
109 | int roar_simple_monitor(int rate, int channels, int bits, int codec, char * server, char * name) { |
---|
110 | return roar_simple_stream(rate, channels, bits, codec, server, ROAR_DIR_MONITOR, name); |
---|
111 | } |
---|
112 | |
---|
113 | int roar_simple_record(int rate, int channels, int bits, int codec, char * server, char * name) { |
---|
114 | return roar_simple_stream(rate, channels, bits, codec, server, ROAR_DIR_RECORD, name); |
---|
115 | } |
---|
116 | |
---|
117 | int roar_simple_filter(int rate, int channels, int bits, int codec, char * server, char * name) { |
---|
118 | return roar_simple_stream(rate, channels, bits, codec, server, ROAR_DIR_FILTER, name); |
---|
119 | } |
---|
120 | |
---|
121 | |
---|
122 | int roar_simple_close(int fh) { |
---|
123 | return close(fh); |
---|
124 | } |
---|
125 | |
---|
126 | int roar_simple_get_standby (int fh) { |
---|
127 | struct roar_connection con; |
---|
128 | |
---|
129 | con.fh = fh; |
---|
130 | |
---|
131 | return roar_get_standby(&con); |
---|
132 | } |
---|
133 | |
---|
134 | //ll |
---|