source: roaraudio/roard/driver_pulsesimple.c @ 5056:b31e60545552

Last change on this file since 5056:b31e60545552 was 5056:b31e60545552, checked in by phi, 11 years ago

support auto reconf bits=32->16 in case not supported (See: #48)

File size: 4.6 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 inst->nonblock = driver_dummy_nonblock;
130
131 return 0;
132}
133
134int     driver_pulsesimple_close        (struct roar_vio_calls * vio) {
135 struct driver_pulsesimple * self = vio->inst;
136
137 ROAR_DBG("driver_pulsesimple_close(vio=%p) = ?", vio);
138
139 pa_simple_free(self->handle);
140
141 roar_mm_free(self);
142
143 return 0;
144}
145
146ssize_t driver_pulsesimple_write        (struct roar_vio_calls * vio, void *buf, size_t count) {
147 struct driver_pulsesimple * self = vio->inst;
148
149 ROAR_DBG("driver_pulsesimple_write(vio=%p, buf=%p, count=%llu) = ?", vio, buf, (long long unsigned int)count);
150
151 return pa_simple_write(self->handle, buf, count, NULL) == 0 ? count : -1;
152}
153
154int     driver_pulsesimple_sync         (struct roar_vio_calls * vio) {
155 struct driver_pulsesimple * self = vio->inst;
156
157 ROAR_DBG("driver_pulsesimple_sync(vio=%p) = ?", vio);
158
159 return pa_simple_drain(self->handle, NULL);
160}
161
162int     driver_pulsesimple_ctl          (struct roar_vio_calls * vio, int cmd, void * data) {
163 struct driver_pulsesimple * self = vio->inst;
164
165 (void)self;
166
167 ROAR_DBG("driver_pulsesimple_ctl(vio=%p) = ?", vio);
168
169 return -1;
170}
171
172#endif
173
174//ll
Note: See TracBrowser for help on using the repository browser.