1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2007 Nicolas Pennequin
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
23 #include <sys/types.h>
27 /* default point to start buffer refill */
28 #define AUDIO_DEFAULT_WATERMARK (1024*512)
29 /* amount of data to read in one read() call */
30 #define AUDIO_DEFAULT_FILECHUNK (1024*32)
31 /* point at which the file buffer will fight for CPU time */
32 #define AUDIO_FILEBUF_CRITICAL (1024*128)
33 /* amount of guess-space to allow for codecs that must hunt and peck
34 * for their correct seeek target, 32k seems a good size */
35 #define AUDIO_REBUFFER_GUESS_SIZE (1024*32)
37 struct buffering_debug
{
56 /* Initialise the buffering subsystem */
57 bool buffering_init(char *filebuf
, size_t filebuflen
);
59 /* Amount of buffer space used */
62 size_t useful_data(int start_handle_id
);
64 /* Reserve space in the buffer for a file */
65 int bufopen(char *file
, size_t offset
, enum data_type type
);
67 /* Open a new handle from data that needs to be copied from memory */
68 int bufalloc(void *src
, size_t size
, enum data_type type
);
71 int bufclose(int handle_id
);
73 /* Set reading index in handle, relatively to the start of the file */
74 int bufseek(int handle_id
, size_t newpos
);
76 /* Advance the reading index in a handle, relatively to its current position */
77 int bufadvance(int handle_id
, off_t offset
);
79 /* Copy data from a handle to a buffer */
80 ssize_t
bufread(int handle_id
, size_t size
, void *dest
);
82 /* Obtain a pointer for linear access to a "size" amount of data */
83 ssize_t
bufgetdata(int handle_id
, size_t size
, void **data
);
85 /* Get a buffer offset from a pointer */
86 ssize_t
get_offset(int handle_id
, void *ptr
);
88 ssize_t
handleoffset(int handle_id
);
90 void request_buffer_handle(int handle_id
);
92 void buffering_get_debugdata(struct buffering_debug
*dbgdata
);