source: roaraudio/roard/driver_esd.c @ 3358:7f9d211148e0

Last change on this file since 3358:7f9d211148e0 was 2367:bdbcf1c16820, checked in by phi, 15 years ago

added server stream para to all drivers

File size: 2.9 KB
Line 
1//driver_esd.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008
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, 675 Mass Ave, Cambridge, MA 02139, USA.
22 *
23 */
24
25#include "roard.h"
26#ifdef ROAR_HAVE_ESD
27
28/*
29 We could use inst as our fh directly. But esd works with unsigned at 8 bits and
30 signed at 16 bits per sample. (why???) so we need to convert because we get signed at both,
31 8 and 16 bits per sample. so we use inst as an array of two ints: 0: fh, 1: are we in 8 bit mode?
32*/
33
34int driver_esd_open_sysio(DRIVER_USERDATA_T * inst, char * device, struct roar_audio_info * info) {
35 esd_format_t format = ESD_STREAM | ESD_PLAY;
36 char name[80] = "roard";
37 int * di = malloc(sizeof(int)*2);
38
39 if ( di == NULL )
40  return -1;
41
42 *inst = (DRIVER_USERDATA_T)di;
43
44 format |= info->bits     == 16 ? ESD_BITS16 : ESD_BITS8;
45 format |= info->channels ==  2 ? ESD_STEREO : ESD_MONO;
46
47 di[1] = info->bits == 8;
48
49 di[0] = esd_play_stream_fallback(format, info->rate, device, name);
50
51 shutdown(di[0], SHUT_RD);
52
53 if ( di[0] == -1 ) {
54  free(di);
55  *inst = NULL;
56  return -1;
57 }
58
59 return 0;
60}
61
62int driver_esd_open_vio(struct roar_vio_calls * inst, char * device, struct roar_audio_info * info, int fh, struct roar_stream_server * sstream) {
63
64 if ( fh != -1 )
65  return -1;
66
67 inst->read     = driver_esd_read;
68 inst->write    = driver_esd_write;
69 inst->nonblock = driver_esd_nonblock;
70 inst->sync     = driver_esd_sync;
71
72 return driver_esd_open_sysio(&(inst->inst), device, info);
73}
74
75int driver_esd_close(DRIVER_USERDATA_T   inst) {
76 int fh;
77
78 inst = ((struct roar_vio_calls *)inst)->inst;
79
80 fh = *(int*)inst;
81
82 free((void*)inst);
83
84 return esd_close(fh);
85}
86
87ssize_t driver_esd_write(struct roar_vio_calls * inst, void * buf, size_t len) {
88 int * di = (int*)((struct roar_vio_calls *)inst)->inst;
89
90 if ( di[1] )
91  roar_conv_codec_s2u8(buf, buf, len);
92
93 return write(di[0], buf, len);
94}
95
96ssize_t driver_esd_read(struct roar_vio_calls * inst, void * buf, size_t len) {
97 return read(*(int*)((struct roar_vio_calls *)inst)->inst, buf, len);
98}
99
100int driver_esd_nonblock(struct roar_vio_calls * vio, int state) {
101 return roar_socket_nonblock(*(int*)vio->inst, state);
102}
103
104int driver_esd_sync    (struct roar_vio_calls * vio) {
105 return ROAR_FDATASYNC(*(int*)vio->inst);
106}
107
108#endif
109//ll
Note: See TracBrowser for help on using the repository browser.