[2235] | 1 | //raw.c: |
---|
| 2 | |
---|
| 3 | /* |
---|
| 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009 |
---|
| 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 | |
---|
[2237] | 27 | int raw_check_stream (int id) { |
---|
[2240] | 28 | struct roar_stream * s; |
---|
| 29 | struct roar_stream_server * ss; |
---|
| 30 | struct roar_buffer * buf; |
---|
| 31 | void * data; |
---|
| 32 | ssize_t len; |
---|
| 33 | |
---|
| 34 | if ( g_streams[id] == NULL ) |
---|
| 35 | return -1; |
---|
| 36 | |
---|
| 37 | ROAR_DBG("raw_check_stream(id=%i) = ?", id); |
---|
| 38 | |
---|
| 39 | s = ROAR_STREAM(ss = g_streams[id]); |
---|
| 40 | |
---|
| 41 | if ( s->pos_rel_id == -1 ) |
---|
| 42 | return -1; |
---|
| 43 | |
---|
| 44 | if ( roar_buffer_new(&buf, RAW_READ_LEN) == -1 ) |
---|
| 45 | return -1; |
---|
| 46 | |
---|
| 47 | if ( roar_buffer_get_data(buf, &data) == -1 ) { |
---|
| 48 | roar_buffer_free(buf); |
---|
| 49 | return -1; |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | if ( (len = stream_vio_s_read(ss, data, RAW_READ_LEN)) < 1 ) { |
---|
[2244] | 53 | // this is len=0 -> eof OR len=-1 -> error |
---|
| 54 | streams_delete(id); |
---|
[2240] | 55 | roar_buffer_free(buf); |
---|
| 56 | return -1; |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | if ( stream_vio_write(s->pos_rel_id, data, len) != len ) { |
---|
| 60 | // we are that hard here as this is needed to ensure data integrety |
---|
| 61 | streams_delete(s->pos_rel_id); |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | roar_buffer_free(buf); |
---|
| 65 | |
---|
| 66 | return 0; |
---|
[2237] | 67 | } |
---|
| 68 | |
---|
[2235] | 69 | //ll |
---|