source: roaraudio/roard/driver_artsc.c @ 5108:44e0633255a1

Last change on this file since 5108:44e0633255a1 was 5108:44e0633255a1, checked in by phi, 11 years ago

"The aRtsc driver is obsolete/broken, use another!"

File size: 4.9 KB
Line 
1//driver_artsc.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2011
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#ifdef ROAR_HAVE_LIBARTSC
29
30#define INIT     +1
31#define SHUTDOWN -1
32
33static int driver_artsc_init_shutdown (int action) {
34 static int state = 0;
35
36 if ( action != INIT && action != SHUTDOWN )
37  return -1;
38
39 if ( state == 0 && action == INIT ) {
40  if ( arts_init() != 0 )
41   return -1;
42 } else if ( state == 1 && action == SHUTDOWN ) {
43  arts_free();
44 }
45
46 state += action;
47
48 return 0;
49}
50
51int     driver_artsc_open_vio(struct roar_vio_calls * inst, char * device, struct roar_audio_info * info, int fh, struct roar_stream_server * sstream) {
52 struct roar_artsc * self = NULL;
53 int autoconfig           = 0;
54
55 (void)sstream;
56
57 ROAR_WARN("The aRtsc driver is obsolete/broken, use another!");
58 ROAR_DBG("driver_artsc_open_vio(*) = ?");
59
60 if ( fh != -1 || device != NULL )
61  return -1;
62
63 if ( sstream != NULL ) {
64  autoconfig = streams_get_flag(ROAR_STREAM(sstream)->id, ROAR_FLAG_AUTOCONF);
65 }
66
67 ROAR_DBG("driver_artsc_open_vio(*) = ?");
68
69 self = roar_mm_malloc(sizeof(struct roar_artsc));
70
71 if ( self == NULL )
72  return -1;
73
74 memset(self, 0, sizeof(struct roar_artsc));
75
76 ROAR_DBG("driver_artsc_open_vio(*) = ?");
77
78 if ( driver_artsc_init_shutdown(INIT) == -1 ) {
79  roar_mm_free(self);
80  return -1;
81 }
82
83 ROAR_DBG("driver_artsc_open_vio(*) = ?");
84
85 if ( info->codec != ROAR_CODEC_DEFAULT ) {
86  if ( autoconfig ) {
87   info->codec = ROAR_CODEC_DEFAULT;
88  } else {
89   return -1;
90  }
91 }
92
93 if ( info->bits != 16 ) {
94  if ( autoconfig ) {
95   info->bits = 16;
96  }
97 }
98
99 self->info   = info;
100 self->stream = arts_play_stream(info->rate, info->bits, info->channels, "roard");
101
102 ROAR_DBG("driver_artsc_open_vio(*) = ?");
103
104 if ( self->stream == NULL && autoconfig ) {
105  info->bits   = 16;
106  self->stream = arts_play_stream(info->rate, info->bits, info->channels, "roard");
107 }
108
109 ROAR_DBG("driver_artsc_open_vio(*) = ?");
110
111 if ( self->stream == NULL ) {
112  roar_mm_free(self);
113  driver_artsc_init_shutdown(SHUTDOWN);
114  ROAR_DBG("driver_artsc_open_vio(*) = -1");
115  return -1;
116 }
117
118 ROAR_DBG("driver_artsc_open_vio(*) = ?");
119
120 memset(inst, 0, sizeof(struct roar_vio_calls));
121
122 inst->inst     = (void*) self;
123 inst->write    = driver_artsc_write;
124 inst->close    = driver_artsc_close;
125 inst->ctl      = driver_artsc_ctl;
126 inst->nonblock = driver_artsc_nonblock;
127
128 ROAR_DBG("driver_artsc_open_vio(*) = 0");
129 return 0;
130}
131
132ssize_t driver_artsc_write   (struct roar_vio_calls * vio, void *buf, size_t count) {
133 struct roar_artsc * self = vio->inst;
134 int ret;
135
136 ROAR_DBG("driver_artsc_write(*) = ?");
137
138 ret = arts_write(self->stream, buf, count);
139
140 if ( ret >= 0 ) {
141  ROAR_DBG("driver_artsc_write(*) = %i", ret);
142  return ret;
143 }
144
145 ROAR_DBG("driver_artsc_write(*) = -1");
146 return -1;
147}
148
149int     driver_artsc_close   (struct roar_vio_calls * vio) {
150 struct roar_artsc * self = vio->inst;
151
152 arts_close_stream(self->stream);
153
154 roar_mm_free(self);
155
156 return driver_artsc_init_shutdown(SHUTDOWN);
157}
158
159int     driver_artsc_nonblock(struct roar_vio_calls * vio, int state) {
160 struct roar_artsc * self = vio->inst;
161 int ret;
162
163 switch (state) {
164  case ROAR_SOCKET_NONBLOCK:
165    ret = arts_stream_set(self->stream, ARTS_P_BLOCKING, 0);
166    if ( ret == 0 )
167     return 0;
168   break;
169  case ROAR_SOCKET_BLOCK:
170    ret = arts_stream_set(self->stream, ARTS_P_BLOCKING, 1);
171    if ( ret == 1 )
172     return 0;
173   break;
174 }
175
176 return -1;
177}
178
179int     driver_artsc_ctl     (struct roar_vio_calls * vio, int cmd, void * data) {
180 struct roar_artsc * self = vio->inst;
181 ssize_t bps;
182 int ret;
183 uint_least32_t tmp;
184
185 switch (cmd) {
186  case ROAR_VIO_CTL_GET_DBLKSIZE:
187    ret = arts_stream_get(self->stream, ARTS_P_PACKET_SIZE);
188    if ( ret > 0 ) {
189     *(uint_least32_t *)data = ret;
190     return 0;
191    }
192   break;
193  case ROAR_VIO_CTL_GET_DELAY:
194    ret = arts_stream_get(self->stream, ARTS_P_TOTAL_LATENCY);
195    if ( ret < 0 )
196     return -1;
197    bps = roar_info2bitspersec(self->info);
198    if ( bps < 0 )
199     return -1;
200
201    tmp  = bps / (ssize_t)8;
202    tmp *= ret;
203    tmp /= (uint_least32_t)1000;
204
205    *(uint_least32_t *)data = tmp;
206
207    return 0;
208  default:
209    return -1;
210 }
211
212 return -1;
213}
214
215#endif
216
217//ll
Note: See TracBrowser for help on using the repository browser.