source: roaraudio/libroar/ltm.c @ 4269:5d6d888aefac

Last change on this file since 4269:5d6d888aefac was 4269:5d6d888aefac, checked in by phi, 14 years ago

implemented parts of LTM

File size: 4.9 KB
Line 
1//ltm.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010
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_ltm_numbits(int f) {
39 int found = 0;
40
41 while (f) {
42  if ( f & 0x1 )
43   found++;
44
45  f >>= 1;
46 }
47
48 return found;
49}
50
51static int roar_ltm_pack_req(int mt, int window,
52                             int * streams, size_t slen,
53                             struct roar_message * mes, char ** buf,
54                             int regtype) {
55 uint16_t * data;
56 size_t i;
57
58 if ( mt == 0 || streams == NULL || slen == 0 || mes == NULL || buf == NULL ) {
59  roar_errno = ROAR_ERROR_INVAL;
60  return -1;
61 }
62
63 memset(mes, 0, sizeof(struct roar_message));
64
65 switch (regtype) {
66  case ROAR_LTM_SST_REGISTER:
67  case ROAR_LTM_SST_UNREGISTER:
68    mes->cmd = ROAR_CMD_SET_STREAM_PARA;
69   break;
70  case ROAR_LTM_SST_GET_RAW:
71    mes->cmd = ROAR_CMD_GET_STREAM_PARA;
72   break;
73  default:
74    roar_errno = ROAR_ERROR_NOTSUP;
75    return -1;
76   break;
77 }
78
79 if ( slen == 1 ) {
80  mes->stream  = *streams;
81  mes->datalen = 6 * 2;
82 } else {
83  mes->stream = -1;
84  mes->datalen = (6 + slen) * 2;
85 }
86
87 if ( mes->datalen > LIBROAR_BUFFER_MSGDATA ) {
88  roar_errno = ROAR_ERROR_NOTSUP;
89  return -1;
90 }
91
92 *buf = NULL;
93
94 data = (uint16_t*)mes->data;
95
96 data[0] = 0;
97 data[1] = ROAR_STREAM_PARA_LTM;
98 data[2] = regtype;
99 data[3] = window;
100 data[4] = 0;
101 data[5] = mt;
102
103 for (i = 0; i < slen; i++) {
104  data[6+i] = streams[i];
105 }
106
107 for (i = 0; i < (mes->datalen/2); i++) {
108  data[i] = ROAR_HOST2NET16(data[i]);
109 }
110
111 return 0;
112}
113
114static int roar_ltm_regunreg(struct roar_connection * con, int mt, int window, int * streams, size_t slen, int type) {
115 struct roar_message mes;
116 char * buf = NULL;
117 int    ret;
118
119 if ( roar_ltm_pack_req(mt, window, streams, slen, &mes, &buf, type) == -1 )
120  return -1;
121
122 ret = roar_req(con, &mes, &buf);
123
124 if ( buf != NULL )
125  free(buf);
126
127 if ( ret != -1 ) {
128  if ( mes.cmd != ROAR_CMD_OK )
129   ret = -1;
130 }
131
132 return ret;
133}
134
135int roar_ltm_register(struct roar_connection * con, int mt, int window, int * streams, size_t slen) {
136 return roar_ltm_regunreg(con, mt, window, streams, slen, ROAR_LTM_SST_REGISTER);
137}
138int roar_ltm_unregister(struct roar_connection * con, int mt, int window, int * streams, size_t slen) {
139 return roar_ltm_regunreg(con, mt, window, streams, slen, ROAR_LTM_SST_UNREGISTER);
140}
141
142ssize_t roar_ltm_get_raw(struct roar_connection * con,
143                         int mt, int window,
144                         int * streams, size_t slen,
145                         void * buf, size_t * buflen, int64_t ** array) {
146 int bits = roar_ltm_numbits(mt);
147 int64_t * buffer = buf;
148 size_t i;
149
150 if ( buflen == NULL ) {
151  roar_errno = ROAR_ERROR_INVAL;
152  return -1;
153 }
154
155 if ( slen == 0 ) {
156  *buflen = 0;
157  return bits;
158 }
159
160 if ( con == NULL || streams == NULL || buf == NULL || array == NULL ) {
161  roar_errno = ROAR_ERROR_INVAL;
162  return -1;
163 }
164
165 if ( *buflen < (bits * slen) ) {
166  roar_errno = ROAR_ERROR_INVAL;
167  return -1;
168 }
169
170 for (i = 0; i < slen; i++) {
171  array[i] = &(buffer[bits*i]);
172 }
173
174 roar_errno = ROAR_ERROR_NOSYS;
175 return -1;
176}
177
178int64_t roar_ltm_extract(int64_t * buf, size_t len, int mt, int req) {
179 int have, need;
180
181 roar_err_clear();
182
183 have = roar_ltm_numbits(req);
184
185 need = roar_ltm_numbits(mt);
186
187 if ( have != 1 || (mt & req) != req || len != (size_t)need || buf == NULL ) {
188  roar_errno = ROAR_ERROR_INVAL;
189  return 0;
190 }
191
192 while (req && (req & 0x1) == 0) {
193  if ( mt & 0x1 )
194   buf++;
195
196  mt  <<= 1;
197  req <<= 1;
198 }
199
200 return *buf;
201}
202
203int64_t roar_ltm_extract1(int64_t * buf, size_t len, int mt, int req) {
204 roar_err_clear();
205
206 if ( buf == NULL || len != 1 || mt != req ) {
207  roar_errno = ROAR_ERROR_INVAL;
208  return 0;
209 }
210
211 return *buf;
212}
213
214//ll
Note: See TracBrowser for help on using the repository browser.