source: roaraudio/roard/driver_pulsesimple.c @ 5012:b263759832f1

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

Updated drivers to use new sync stream selection logic correctly (Closes: #136)

File size: 4.0 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
37//    pa_sample_format_t format;     /**< The sample format */
38
39 switch (info->codec) {
40  case ROAR_CODEC_ALAW:
41    ss.format = PA_SAMPLE_ALAW;
42   break;
43  case ROAR_CODEC_MULAW:
44    ss.format = PA_SAMPLE_ULAW;
45   break;
46  case ROAR_CODEC_PCM_S_LE:
47    switch (info->bits) {
48     case 16:
49       ss.format = PA_SAMPLE_S16LE;
50      break;
51     default:
52       return -1;
53      break;
54    }
55   break;
56  case ROAR_CODEC_PCM_S_BE:
57    switch (info->bits) {
58     case 16:
59       ss.format = PA_SAMPLE_S16BE;
60      break;
61     default:
62       return -1;
63      break;
64    }
65   break;
66  case ROAR_CODEC_PCM_U_LE:
67  case ROAR_CODEC_PCM_U_BE:
68  case ROAR_CODEC_PCM_U_PDP:
69    if ( info->bits == 8 ) {
70     ss.format = PA_SAMPLE_U8;
71    } else {
72     return -1;
73    }
74   break;
75  default:
76    return -1;
77   break;
78 }
79
80 ss.rate     = info->rate;
81 ss.channels = info->channels;
82
83 if ( (self = roar_mm_malloc(sizeof(struct driver_pulsesimple))) == NULL )
84  return -1;
85
86 self->handle = pa_simple_new(device, "roard", dir, subdev, "RoarAudio Sound Server", &ss, NULL, NULL, &pulseerror);
87
88 if ( self->handle == NULL ) {
89  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));
90  roar_mm_free(self);
91  ROAR_DBG("driver_pulsesimple_open(inst=%p, device='%s', info=%p, fh=%i, sstream=%p) = -1", inst, device, info, fh, sstream);
92  return -1;
93 }
94
95 memset(inst, 0, sizeof(struct roar_vio_calls));
96
97 inst->inst     = self;
98 inst->close    = driver_pulsesimple_close;
99 inst->write    = driver_pulsesimple_write;
100 inst->sync     = driver_pulsesimple_sync;
101 inst->ctl      = driver_pulsesimple_ctl;
102 inst->nonblock = driver_dummy_nonblock;
103
104 return 0;
105}
106
107int     driver_pulsesimple_close        (struct roar_vio_calls * vio) {
108 struct driver_pulsesimple * self = vio->inst;
109
110 ROAR_DBG("driver_pulsesimple_close(vio=%p) = ?", vio);
111
112 pa_simple_free(self->handle);
113
114 roar_mm_free(self);
115
116 return 0;
117}
118
119ssize_t driver_pulsesimple_write        (struct roar_vio_calls * vio, void *buf, size_t count) {
120 struct driver_pulsesimple * self = vio->inst;
121
122 ROAR_DBG("driver_pulsesimple_write(vio=%p, buf=%p, count=%llu) = ?", vio, buf, (long long unsigned int)count);
123
124 return pa_simple_write(self->handle, buf, count, NULL) == 0 ? count : -1;
125}
126
127int     driver_pulsesimple_sync         (struct roar_vio_calls * vio) {
128 struct driver_pulsesimple * self = vio->inst;
129
130 ROAR_DBG("driver_pulsesimple_sync(vio=%p) = ?", vio);
131
132 return pa_simple_drain(self->handle, NULL);
133}
134
135int     driver_pulsesimple_ctl          (struct roar_vio_calls * vio, int cmd, void * data) {
136 struct driver_pulsesimple * self = vio->inst;
137
138 (void)self;
139
140 ROAR_DBG("driver_pulsesimple_ctl(vio=%p) = ?", vio);
141
142 return -1;
143}
144
145#endif
146
147//ll
Note: See TracBrowser for help on using the repository browser.