source: roaraudio/libroarsndio/stream.c @ 2020:7c9ac451037b

Last change on this file since 2020:7c9ac451037b was 2020:7c9ac451037b, checked in by phi, 15 years ago

info to inform devel that code needs to be changed in order to do full VIO.

File size: 2.7 KB
Line 
1//stream.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009
5 *  The code (may) include prototypes and comments (and maybe
6 *  other code fragements) from EsounD.
7 *  They are mostly copyrighted by Eric B. Mitchell (aka 'Ricdude)
8 *  <ericmit@ix.netcom.com>. For more information see AUTHORS.esd.
9 *
10 *  This file is part of libroaresd a part of RoarAudio,
11 *  a cross-platform sound system for both, home and professional use.
12 *  See README for details.
13 *
14 *  This file is free software; you can redistribute it and/or modify
15 *  it under the terms of the GNU General Public License version 3
16 *  as published by the Free Software Foundation.
17 *
18 *  RoarAudio is distributed in the hope that it will be useful,
19 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
20 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 *  GNU General Public License for more details.
22 *
23 *  You should have received a copy of the GNU General Public License
24 *  along with this software; see the file COPYING.  If not, write to
25 *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
26 *
27 *  NOTE for everyone want's to change something and send patches:
28 *  read README and HACKING! There a addition information on
29 *  the license of this document you need to read before you send
30 *  any patches.
31 */
32
33#define ROAR_USE_OWN_SNDIO_HDL
34#include "libroarsndio.h"
35
36#define _i(x) (hdl->info.x)
37int    sio_start  (struct sio_hdl * hdl) {
38 int fh;
39
40 // TODO: FIXME: use full VIO support here, not fh->vio!
41
42 if ( hdl == NULL )
43  return 0;
44
45 if ( hdl->stream_opened )
46  return 0;
47
48 if ( (fh = roar_simple_new_stream_obj(&(hdl->con), &(hdl->stream), _i(rate), _i(channels), _i(bits), _i(codec), ROAR_DIR_PLAY)) == -1 )
49  return 0;
50
51 if ( roar_vio_open_fh_socket(&(hdl->svio), fh) == -1 ) {
52  close(fh);
53  return 0;
54 }
55
56 hdl->stream_opened = 1;
57
58 return 1;
59}
60#undef _i
61
62int    sio_stop   (struct sio_hdl * hdl) {
63
64 if ( hdl == NULL )
65  return 0;
66
67 if ( !hdl->stream_opened )
68  return 0;
69
70 roar_vio_close(&(hdl->svio));
71
72 hdl->stream_opened = -1;
73
74 return 1;
75}
76
77size_t sio_read   (struct sio_hdl * hdl, void * addr, size_t nbytes) {
78 ssize_t ret;
79
80 if ( hdl == NULL )
81  return 0;
82
83 if ( !hdl->stream_opened )
84  return 0;
85
86 if ( (ret = roar_vio_read(&(hdl->svio), addr, nbytes)) < 0 )
87  return 0;
88
89 return ret;
90}
91size_t sio_write  (struct sio_hdl * hdl, void * addr, size_t nbytes) {
92 ssize_t ret;
93
94 if ( hdl == NULL )
95  return 0;
96
97 if ( !hdl->stream_opened )
98  return 0;
99
100 if ( (ret = roar_vio_write(&(hdl->svio), addr, nbytes)) < 0 )
101  return 0;
102
103 if ( hdl->on_move != NULL ) {
104  hdl->on_move(hdl->on_move_arg, 8*ret/(hdl->info.channels * hdl->info.bits));
105 }
106
107 return ret;
108}
109
110//ll
Note: See TracBrowser for help on using the repository browser.