[1298] | 1 | |
---|
[1276] | 2 | |
---|
| 3 | /* |
---|
[1284] | 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009 |
---|
[1276] | 5 | * |
---|
| 6 | * This file is part of libroar 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 | * libroar 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 | * NOTE for everyone want's to change something and send patches: |
---|
| 24 | * read README and HACKING! There a addition information on |
---|
| 25 | * the license of this document you need to read before you send |
---|
| 26 | * any patches. |
---|
| 27 | * |
---|
| 28 | * NOTE for uses of non-GPL (LGPL,...) software using libesd, libartsc |
---|
| 29 | * or libpulse*: |
---|
| 30 | * The libs libroaresd, libroararts and libroarpulse link this lib |
---|
| 31 | * and are therefore GPL. Because of this it may be illigal to use |
---|
| 32 | * them with any software that uses libesd, libartsc or libpulse*. |
---|
| 33 | */ |
---|
| 34 | |
---|
| 35 | #include "libroar.h" |
---|
| 36 | |
---|
[1298] | 37 | int roar_vio_open_magic (struct roar_vio_calls * calls, struct roar_vio_calls * dst, int * codec); |
---|
| 38 | int roar_vio_magic_close (struct roar_vio_calls * vio); |
---|
| 39 | |
---|
| 40 | ssize_t roar_vio_magic_read (struct roar_vio_calls * vio, void *buf, size_t count) { |
---|
| 41 | struct roar_vio_magic * self = (struct roar_vio_magic *)(vio->inst); |
---|
[1299] | 42 | struct roar_buffer * inp; |
---|
[1298] | 43 | void * calls; |
---|
| 44 | size_t len; |
---|
| 45 | |
---|
| 46 | if (self == NULL) |
---|
| 47 | return -1; |
---|
| 48 | |
---|
| 49 | if ( roar_stack_get_cur(&(self->vios), &calls) == -1 ) |
---|
| 50 | return -1; |
---|
| 51 | |
---|
[1299] | 52 | inp = &(self->inp); |
---|
| 53 | |
---|
| 54 | if ( roar_buffer_get_len(inp, &len) == -1 ) |
---|
[1298] | 55 | return -1; |
---|
| 56 | |
---|
| 57 | if ( len ) { |
---|
| 58 | len = len > count ? count : len; |
---|
[1299] | 59 | if ( roar_buffer_shift_out(&inp, buf, &len) == -1 ) |
---|
[1298] | 60 | return -1; |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | count -= len; |
---|
| 64 | buf += len; |
---|
| 65 | |
---|
| 66 | if ( count ) { |
---|
| 67 | if ( (count = roar_vio_read((struct roar_vio_calls*) calls, buf, count)) == -1 ) |
---|
| 68 | return len; |
---|
| 69 | |
---|
| 70 | return len+count; |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | return len; |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | ssize_t roar_vio_magic_write (struct roar_vio_calls * vio, void *buf, size_t count) { |
---|
| 77 | struct roar_vio_magic * self = (struct roar_vio_magic *)(vio->inst); |
---|
| 78 | void * calls; |
---|
| 79 | |
---|
| 80 | if (self == NULL) |
---|
| 81 | return -1; |
---|
| 82 | |
---|
| 83 | if ( roar_stack_get_cur(&(self->vios), &calls) == -1 ) |
---|
| 84 | return -1; |
---|
| 85 | |
---|
| 86 | return roar_vio_write((struct roar_vio_calls*)calls, buf, count); |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | off_t roar_vio_magic_lseek (struct roar_vio_calls * vio, off_t offset, int whence) { |
---|
| 90 | struct roar_vio_magic * self = (struct roar_vio_magic *)(vio->inst); |
---|
| 91 | void * calls; |
---|
| 92 | |
---|
| 93 | if (self == NULL) |
---|
| 94 | return -1; |
---|
| 95 | |
---|
| 96 | if ( roar_stack_get_cur(&(self->vios), &calls) == -1 ) |
---|
| 97 | return -1; |
---|
| 98 | |
---|
| 99 | return roar_vio_lseek((struct roar_vio_calls*)calls, offset, whence); |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | int roar_vio_magic_nonblock(struct roar_vio_calls * vio, int state) { |
---|
| 103 | struct roar_vio_magic * self = (struct roar_vio_magic *)(vio->inst); |
---|
| 104 | void * calls; |
---|
| 105 | |
---|
| 106 | if (self == NULL) |
---|
| 107 | return -1; |
---|
| 108 | |
---|
| 109 | if ( roar_stack_get_cur(&(self->vios), &calls) == -1 ) |
---|
| 110 | return -1; |
---|
| 111 | |
---|
| 112 | return roar_vio_nonblock((struct roar_vio_calls*)calls, state); |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | int roar_vio_magic_sync (struct roar_vio_calls * vio) { |
---|
| 116 | struct roar_vio_magic * self = (struct roar_vio_magic *)(vio->inst); |
---|
| 117 | void * calls; |
---|
| 118 | |
---|
| 119 | if (self == NULL) |
---|
| 120 | return -1; |
---|
| 121 | |
---|
| 122 | if ( roar_stack_get_cur(&(self->vios), &calls) == -1 ) |
---|
| 123 | return -1; |
---|
| 124 | |
---|
| 125 | return roar_vio_sync((struct roar_vio_calls*)calls); |
---|
| 126 | } |
---|
| 127 | |
---|
[1276] | 128 | //ll |
---|