source: roaraudio/roard/driver_pulsesimple.c @ 5278:b3e0dd3f3141

Last change on this file since 5278:b3e0dd3f3141 was 5278:b3e0dd3f3141, checked in by phi, 12 years ago

last parts of merging _nonblock into _ctl and fixed sizeof(cmd) of _ctls

File size: 4.8 KB
Line 
1//driver_pulsesimple.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010-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_LIBPULSE
29
30int     driver_pulsesimple_open         (struct roar_vio_calls * inst, char * device, struct roar_audio_info * info, int fh, struct roar_stream_server * sstream) {
31 struct driver_pulsesimple * self;
32 const char                * subdev = NULL;
33 int                         pulseerror = -1;
34 pa_stream_direction_t dir = PA_STREAM_PLAYBACK;
35 pa_sample_spec        ss;
36 int autoconfig = 0;
37 int needauto   = 0;
38
39//    pa_sample_format_t format;     /**< The sample format */
40
41 if ( fh != -1 )
42  return -1;
43
44 if ( sstream != NULL ) {
45  autoconfig = streams_get_flag(ROAR_STREAM(sstream)->id, ROAR_FLAG_AUTOCONF);
46 }
47
48 switch (info->codec) {
49  case ROAR_CODEC_ALAW:
50    ss.format = PA_SAMPLE_ALAW;
51   break;
52  case ROAR_CODEC_MULAW:
53    ss.format = PA_SAMPLE_ULAW;
54   break;
55  case ROAR_CODEC_PCM_S_LE:
56    switch (info->bits) {
57     case 16:
58       ss.format = PA_SAMPLE_S16LE;
59      break;
60     default:
61       needauto = 1;
62      break;
63    }
64   break;
65  case ROAR_CODEC_PCM_S_BE:
66    switch (info->bits) {
67     case 16:
68       ss.format = PA_SAMPLE_S16BE;
69      break;
70     default:
71       needauto = 1;
72      break;
73    }
74   break;
75  case ROAR_CODEC_PCM_U_LE:
76  case ROAR_CODEC_PCM_U_BE:
77  case ROAR_CODEC_PCM_U_PDP:
78    if ( info->bits == 8 ) {
79     ss.format = PA_SAMPLE_U8;
80    } else {
81     needauto = 1;
82    }
83   break;
84  default:
85    needauto = 1;
86   break;
87 }
88
89 if ( needauto ) {
90  if ( !autoconfig ) {
91   return -1;
92  }
93
94  info->bits = 16;
95  info->codec = ROAR_CODEC_DEFAULT;
96  ss.format = PA_SAMPLE_S16NE;
97 }
98
99 ss.rate     = info->rate;
100 ss.channels = info->channels;
101
102 if ( (self = roar_mm_malloc(sizeof(struct driver_pulsesimple))) == NULL )
103  return -1;
104
105 self->handle = pa_simple_new(device, "roard", dir, subdev, "RoarAudio Sound Server", &ss, NULL, NULL, &pulseerror);
106
107 if ( self->handle == NULL && autoconfig ) {
108  info->bits = 16;
109  info->codec = ROAR_CODEC_DEFAULT;
110  ss.format = PA_SAMPLE_S16NE;
111
112  self->handle = pa_simple_new(device, "roard", dir, subdev, "RoarAudio Sound Server", &ss, NULL, NULL, &pulseerror);
113 }
114
115 if ( self->handle == NULL ) {
116  ROAR_ERR("driver_pulsesimple_open(inst=%p, device='%s', info=%p, fh=%i, sstream=%p): can not open device: %s", inst, device, info, fh, sstream, pa_strerror(pulseerror));
117  roar_mm_free(self);
118  ROAR_DBG("driver_pulsesimple_open(inst=%p, device='%s', info=%p, fh=%i, sstream=%p) = -1", inst, device, info, fh, sstream);
119  return -1;
120 }
121
122 memset(inst, 0, sizeof(struct roar_vio_calls));
123
124 inst->inst     = self;
125 inst->close    = driver_pulsesimple_close;
126 inst->write    = driver_pulsesimple_write;
127 inst->sync     = driver_pulsesimple_sync;
128 inst->ctl      = driver_pulsesimple_ctl;
129
130 return 0;
131}
132
133int     driver_pulsesimple_close        (struct roar_vio_calls * vio) {
134 struct driver_pulsesimple * self = vio->inst;
135
136 ROAR_DBG("driver_pulsesimple_close(vio=%p) = ?", vio);
137
138 pa_simple_free(self->handle);
139
140 roar_mm_free(self);
141
142 return 0;
143}
144
145ssize_t driver_pulsesimple_write        (struct roar_vio_calls * vio, void *buf, size_t count) {
146 struct driver_pulsesimple * self = vio->inst;
147
148 ROAR_DBG("driver_pulsesimple_write(vio=%p, buf=%p, count=%llu) = ?", vio, buf, (long long unsigned int)count);
149
150 return pa_simple_write(self->handle, buf, count, NULL) == 0 ? count : -1;
151}
152
153int     driver_pulsesimple_sync         (struct roar_vio_calls * vio) {
154 struct driver_pulsesimple * self = vio->inst;
155
156 ROAR_DBG("driver_pulsesimple_sync(vio=%p) = ?", vio);
157
158 return pa_simple_drain(self->handle, NULL);
159}
160
161int     driver_pulsesimple_ctl          (struct roar_vio_calls * vio, roar_vio_ctl_t cmd, void * data) {
162 struct driver_pulsesimple * self = vio->inst;
163
164 (void)self;
165
166 ROAR_DBG("driver_pulsesimple_ctl(vio=%p) = ?", vio);
167
168 switch (cmd) {
169  case ROAR_VIO_CTL_NONBLOCK:
170    if ( *(int*)data == ROAR_SOCKET_BLOCK )
171     return 0;
172    roar_err_set(ROAR_ERROR_NOTSUP);
173    return -1;
174   break;
175 }
176
177 roar_err_set(ROAR_ERROR_NOSYS);
178 return -1;
179}
180
181#endif
182
183//ll
Note: See TracBrowser for help on using the repository browser.