source: roaraudio/libroarsndio/stream.c @ 2353:c085b03ad123

Last change on this file since 2353:c085b03ad123 was 2051:6486bbc371a2, checked in by phi, 15 years ago

win32 fix

File size: 3.1 KB
RevLine 
[1563]1//stream.c:
[1559]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
[1571]33#define ROAR_USE_OWN_SNDIO_HDL
[1559]34#include "libroarsndio.h"
35
[1567]36#define _i(x) (hdl->info.x)
[1563]37int    sio_start  (struct sio_hdl * hdl) {
[2051]38#ifndef ROAR_TARGET_WIN32
[2019]39 int fh;
[2051]40#endif
[2019]41
[2020]42 // TODO: FIXME: use full VIO support here, not fh->vio!
43
[1567]44 if ( hdl == NULL )
45  return 0;
46
[2019]47 if ( hdl->stream_opened )
48  return 0;
49
[2051]50#ifndef ROAR_TARGET_WIN32
[2019]51 if ( (fh = roar_simple_new_stream_obj(&(hdl->con), &(hdl->stream), _i(rate), _i(channels), _i(bits), _i(codec), ROAR_DIR_PLAY)) == -1 )
[1567]52  return 0;
53
[2022]54 ROAR_DBG("sio_start(hdl=%p): rate=%i, channels=%i, bits=%i, codec=%i", hdl, _i(rate), _i(channels), _i(bits), _i(codec));
55
[2019]56 if ( roar_vio_open_fh_socket(&(hdl->svio), fh) == -1 ) {
57  close(fh);
[1567]58  return 0;
[2019]59 }
[2051]60#else
61 if ( roar_stream_new_by_id(&(hdl->stream), -1) == -1 )
62  return 0;
63
64 if (roar_vio_simple_stream(&(hdl->svio),  _i(rate), _i(channels), _i(bits), _i(codec), NULL, ROAR_DIR_PLAY, "libroarsndio(win32)") == -1 ) {
65  return 0;
66 }
67#endif
[2019]68
69 hdl->stream_opened = 1;
[1567]70
71 return 1;
[1563]72}
[1567]73#undef _i
[1563]74
75int    sio_stop   (struct sio_hdl * hdl) {
76
77 if ( hdl == NULL )
78  return 0;
79
[2019]80 if ( !hdl->stream_opened )
[1563]81  return 0;
82
[2019]83 roar_vio_close(&(hdl->svio));
[1563]84
[2019]85 hdl->stream_opened = -1;
[1563]86
87 return 1;
88}
89
90size_t sio_read   (struct sio_hdl * hdl, void * addr, size_t nbytes) {
91 ssize_t ret;
92
93 if ( hdl == NULL )
94  return 0;
95
[2019]96 if ( !hdl->stream_opened )
[1563]97  return 0;
98
[2019]99 if ( (ret = roar_vio_read(&(hdl->svio), addr, nbytes)) < 0 )
[1563]100  return 0;
101
102 return ret;
103}
104size_t sio_write  (struct sio_hdl * hdl, void * addr, size_t nbytes) {
105 ssize_t ret;
106
107 if ( hdl == NULL )
108  return 0;
109
[2019]110 if ( !hdl->stream_opened )
[1563]111  return 0;
112
[2019]113 if ( (ret = roar_vio_write(&(hdl->svio), addr, nbytes)) < 0 )
[1563]114  return 0;
115
[1577]116 if ( hdl->on_move != NULL ) {
117  hdl->on_move(hdl->on_move_arg, 8*ret/(hdl->info.channels * hdl->info.bits));
118 }
119
[1563]120 return ret;
121}
122
[1559]123//ll
Note: See TracBrowser for help on using the repository browser.