source: roaraudio/libroar/vio_buffer_store.c @ 5231:8b30ddb689b8

Last change on this file since 5231:8b30ddb689b8 was 4708:c9d40761088a, checked in by phi, 13 years ago

updated copyright statements

File size: 4.5 KB
Line 
1//vio_buffer_store.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010-2011
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 if ( inst != NULL )
54  *inst = self;
55
56 calls->inst     = self;
57 calls->close    = roar_vio_buffer_store_close;
58 calls->nonblock = roar_vio_buffer_store_nonblock;
59 calls->sync     = roar_vio_buffer_store_sync;
60 calls->ctl      = roar_vio_buffer_store_ctl;
61 calls->write    = roar_vio_buffer_store_write;
62 calls->read     = roar_vio_buffer_store_read;
63 calls->lseek    = roar_vio_buffer_store_lseek;
64
65 return 0;
66}
67
68int     roar_vio_buffer_store_close   (struct roar_vio_calls * vio) {
69 struct roar_vio_buffer_store * self = vio->inst;
70 int ret = 0;
71
72 if ( self->in != NULL )
73  if ( roar_buffer_free(self->in) != 0 )
74   ret = -1;
75
76 if ( self->out != NULL )
77  if ( roar_buffer_free(self->out) != 0 )
78   ret = -1;
79
80 return ret;
81}
82
83ssize_t roar_vio_buffer_store_read    (struct roar_vio_calls * vio, void *buf, size_t count) {
84 struct roar_vio_buffer_store * self = vio->inst;
85
86 ROAR_DBG("roar_vio_buffer_store_read(vio=%p, buf=%p, count=%llu) = ?", vio, buf, (long long unsigned int)count);
87
88 if ( count == 0 )
89  return 0;
90
91 if ( buf == NULL )
92  return -1;
93
94 if ( self->out == NULL )
95  return 0;
96
97 ROAR_DBG("roar_vio_buffer_store_read(vio=%p, buf=%p, count=%llu) = ?", vio, buf, (long long unsigned int)count);
98
99 if ( roar_buffer_shift_out(&(self->out), buf, &count) == -1 )
100  return -1;
101
102 ROAR_DBG("roar_vio_buffer_store_read(*) = %llu", (long long unsigned int)count);
103
104 return count;
105}
106
107ssize_t roar_vio_buffer_store_write   (struct roar_vio_calls * vio, void *buf, size_t count) {
108 struct roar_vio_buffer_store * self = vio->inst;
109 struct roar_buffer * nbuf;
110 void * data;
111
112 if ( count == 0 )
113  return 0;
114
115 if ( buf == NULL )
116  return -1;
117
118 if ( roar_buffer_new_data(&nbuf, count, &data) == -1 )
119  return -1;
120
121 memcpy(data, buf, count);
122
123 if ( self->in == NULL ) {
124  self->in = nbuf;
125 } else {
126  if ( roar_buffer_add(self->in, nbuf) == -1 ) {
127   roar_buffer_free(nbuf);
128   return -1;
129  }
130 }
131
132 return count;
133}
134
135off_t   roar_vio_buffer_store_lseek   (struct roar_vio_calls * vio, off_t offset, int whence) {
136 // TODO: implement support to seek forward as wide as the buffer allows us to seek.
137 return (off_t)-1;
138}
139
140int     roar_vio_buffer_store_nonblock(struct roar_vio_calls * vio, int state) {
141 return 0; // if we are in nonblock or not is the same for us.
142}
143
144int     roar_vio_buffer_store_sync    (struct roar_vio_calls * vio) {
145 return 0; // we are always sync.
146}
147
148int     roar_vio_buffer_store_ctl     (struct roar_vio_calls * vio, int cmd, void * data) {
149 if (vio == NULL || cmd == -1)
150  return -1;
151
152 ROAR_DBG("roar_vio_buffer_store_ctl(vio=%p, cmd=0x%.8x, data=%p) = ?", vio, cmd, data);
153
154 switch (cmd) {
155  case ROAR_VIO_CTL_GET_NAME:
156    if ( data == NULL )
157     return -1;
158
159    *(char**)data = "buffer_store";
160    return 0;
161   break;
162 }
163
164 return -1;
165}
166
167//ll
Note: See TracBrowser for help on using the repository browser.