source: roaraudio/roard/driver_artsc.c @ 4809:5eeb1a175740

Last change on this file since 4809:5eeb1a175740 was 4809:5eeb1a175740, checked in by phi, 11 years ago
  • Added aRts (artsc) driver to roard.
File size: 3.8 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
54 (void)sstream;
55
56 if ( fh != -1 || device != NULL )
57  return -1;
58
59 self = roar_mm_malloc(sizeof(struct roar_artsc));
60
61 if ( self == NULL )
62  return -1;
63
64 memset(self, 0, sizeof(struct roar_artsc));
65
66 if ( driver_artsc_init_shutdown(INIT) == -1 ) {
67  roar_mm_free(self);
68  return -1;
69 }
70
71 info->codec = ROAR_CODEC_DEFAULT;
72
73 self->info   = info;
74 self->stream = arts_play_stream(info->rate, info->bits, info->channels, "roard");
75
76 if ( self->stream == NULL ) {
77  roar_mm_free(self);
78  driver_artsc_init_shutdown(SHUTDOWN);
79  return -1;
80 }
81
82 memset(inst, 0, sizeof(struct roar_vio_calls));
83
84 inst->inst     = (void*) self;
85 inst->write    = driver_artsc_write;
86 inst->close    = driver_artsc_close;
87 inst->ctl      = driver_artsc_ctl;
88 inst->nonblock = driver_artsc_nonblock;
89
90 return 0;
91}
92
93ssize_t driver_artsc_write   (struct roar_vio_calls * vio, void *buf, size_t count) {
94 struct roar_artsc * self = vio->inst;
95 int ret = arts_write(self->stream, buf, count);
96
97 if ( ret >= 0 )
98  return ret;
99
100 return -1;
101}
102
103int     driver_artsc_close   (struct roar_vio_calls * vio) {
104 struct roar_artsc * self = vio->inst;
105
106 arts_close_stream(self->stream);
107
108 roar_mm_free(self);
109
110 return driver_artsc_init_shutdown(SHUTDOWN);
111}
112
113int     driver_artsc_nonblock(struct roar_vio_calls * vio, int state) {
114 struct roar_artsc * self = vio->inst;
115 int ret;
116
117 switch (state) {
118  case ROAR_SOCKET_NONBLOCK:
119    ret = arts_stream_set(self->stream, ARTS_P_BLOCKING, 0);
120    if ( ret == 0 )
121     return 0;
122   break;
123  case ROAR_SOCKET_BLOCK:
124    ret = arts_stream_set(self->stream, ARTS_P_BLOCKING, 1);
125    if ( ret == 1 )
126     return 0;
127   break;
128 }
129
130 return -1;
131}
132
133int     driver_artsc_ctl     (struct roar_vio_calls * vio, int cmd, void * data) {
134 struct roar_artsc * self = vio->inst;
135 ssize_t bps;
136 int ret;
137 uint_least32_t tmp;
138
139 switch (cmd) {
140  case ROAR_VIO_CTL_GET_DBLKSIZE:
141    ret = arts_stream_get(self->stream, ARTS_P_PACKET_SIZE);
142    if ( ret > 0 ) {
143     *(uint_least32_t *)data = ret;
144     return 0;
145    }
146   break;
147  case ROAR_VIO_CTL_GET_DELAY:
148    ret = arts_stream_get(self->stream, ARTS_P_TOTAL_LATENCY);
149    if ( ret < 0 )
150     return -1;
151    bps = roar_info2bitspersec(self->info);
152    if ( bps < 0 )
153     return -1;
154
155    tmp  = bps / (ssize_t)8;
156    tmp *= ret;
157    tmp /= (uint_least32_t)1000;
158
159    *(uint_least32_t *)data = tmp;
160
161    return 0;
162  default:
163    return -1;
164 }
165
166 return -1;
167}
168
169#endif
170
171//ll
Note: See TracBrowser for help on using the repository browser.