source: roaraudio/libroar/vio_buffer_store.c @ 3994:a091e41bf711

Last change on this file since 3994:a091e41bf711 was 3994:a091e41bf711, checked in by phi, 14 years ago

added buffer_store VIO

File size: 4.2 KB
Line 
1//vio_buffer_store.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010
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, 51 Franklin Street, Fifth Floor,
22 *  Boston, MA 02110-1301, USA.
23 *
24 *  NOTE for everyone want's to change something and send patches:
25 *  read README and HACKING! There a addition information on
26 *  the license of this document you need to read before you send
27 *  any patches.
28 *
29 *  NOTE for uses of non-GPL (LGPL,...) software using libesd, libartsc
30 *  or libpulse*:
31 *  The libs libroaresd, libroararts and libroarpulse link this lib
32 *  and are therefore GPL. Because of this it may be illigal to use
33 *  them with any software that uses libesd, libartsc or libpulse*.
34 */
35
36#include "libroar.h"
37
38int     roar_vio_open_buffer_store    (struct roar_vio_calls * calls, struct roar_vio_buffer_store ** inst) {
39 struct roar_vio_buffer_store * self;
40
41 if ( calls == NULL )
42  return -1;
43
44 self = roar_mm_malloc(sizeof(struct roar_vio_buffer_store));
45
46 if ( self == NULL )
47  return -1;
48
49 memset(self, 0, sizeof(struct roar_vio_buffer_store));
50
51 memset(calls, 0, sizeof(struct roar_vio_calls));
52
53 calls->inst     = self;
54 calls->close    = roar_vio_buffer_store_close;
55 calls->nonblock = roar_vio_buffer_store_nonblock;
56 calls->sync     = roar_vio_buffer_store_sync;
57 calls->ctl      = roar_vio_buffer_store_ctl;
58 calls->write    = roar_vio_buffer_store_write;
59 calls->read     = roar_vio_buffer_store_read;
60 calls->lseek    = roar_vio_buffer_store_lseek;
61
62 return 0;
63}
64
65int     roar_vio_buffer_store_close   (struct roar_vio_calls * vio) {
66 struct roar_vio_buffer_store * self = vio->inst;
67 int ret = 0;
68
69 if ( self->in != NULL )
70  if ( roar_buffer_free(self->in) != 0 )
71   ret = -1;
72
73 if ( self->out != NULL )
74  if ( roar_buffer_free(self->out) != 0 )
75   ret = -1;
76
77 return ret;
78}
79
80ssize_t roar_vio_buffer_store_read    (struct roar_vio_calls * vio, void *buf, size_t count) {
81 struct roar_vio_buffer_store * self = vio->inst;
82
83 if ( count == 0 )
84  return 0;
85
86 if ( buf == NULL )
87  return -1;
88
89 if ( self->out == NULL )
90  return 0;
91
92 if ( roar_buffer_shift_out(&(self->out), buf, &count) == -1 )
93  return -1;
94
95 return count;
96}
97
98ssize_t roar_vio_buffer_store_write   (struct roar_vio_calls * vio, void *buf, size_t count) {
99 struct roar_vio_buffer_store * self = vio->inst;
100 struct roar_buffer * nbuf;
101 void * data;
102
103 if ( count == 0 )
104  return 0;
105
106 if ( buf == NULL )
107  return -1;
108
109 if ( roar_buffer_new_data(&nbuf, count, &data) == -1 )
110  return -1;
111
112 memcpy(data, buf, count);
113
114 if ( self->in == NULL ) {
115  self->in = nbuf;
116 } else {
117  if ( roar_buffer_add(self->in, nbuf) == -1 ) {
118   roar_buffer_free(nbuf);
119   return -1;
120  }
121 }
122
123 return count;
124}
125
126off_t   roar_vio_buffer_store_lseek   (struct roar_vio_calls * vio, off_t offset, int whence) {
127 // TODO: implement support to seek forward as wide as the buffer allows us to seek.
128 return (off_t)-1;
129}
130
131int     roar_vio_buffer_store_nonblock(struct roar_vio_calls * vio, int state) {
132 return 0; // if we are in nonblock or not is the same for us.
133}
134
135int     roar_vio_buffer_store_sync    (struct roar_vio_calls * vio) {
136 return 0; // we are always sync.
137}
138
139int     roar_vio_buffer_store_ctl     (struct roar_vio_calls * vio, int cmd, void * data) {
140 if (vio == NULL || cmd == -1)
141  return -1;
142
143 ROAR_DBG("roar_vio_buffer_store_ctl(vio=%p, cmd=0x%.8x, data=%p) = ?", vio, cmd, data);
144
145 switch (cmd) {
146  case ROAR_VIO_CTL_GET_NAME:
147    if ( data == NULL )
148     return -1;
149
150    *(char**)data = "buffer_store";
151    return 0;
152   break;
153 }
154
155 return -1;
156}
157
158//ll
Note: See TracBrowser for help on using the repository browser.