Hide the buffering thread and queue inside buffering.c
[Rockbox.git] / apps / buffering.h
blobf206b113c86e58a85fed4dcdc69b946138159a83
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
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 ****************************************************************************/
20 #ifndef _BUFFERING_H_
21 #define _BUFFERING_H_
23 #include <sys/types.h>
24 #include <stdbool.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 {
38 int num_handles;
39 size_t buffered_data;
40 size_t wasted_space;
41 size_t data_rem;
44 enum data_type {
45 TYPE_CODEC,
46 TYPE_AUDIO,
47 TYPE_STREAM,
48 TYPE_ID3,
49 TYPE_CUESHEET,
50 TYPE_IMAGE,
51 TYPE_BUFFER,
52 TYPE_UNKNOWN,
55 /* Initialise the buffering subsystem */
56 bool buffering_init(char *filebuf, size_t filebuflen);
58 /* Amount of buffer space used */
59 size_t bufused(void);
61 /* Reserve space in the buffer for a file */
62 int bufopen(char *file, size_t offset, enum data_type type);
64 /* Open a new handle from data that needs to be copied from memory */
65 int bufalloc(void *src, size_t size, enum data_type type);
67 /* Close a handle */
68 int bufclose(int handle_id);
70 /* Set reading index in handle, relatively to the start of the file */
71 int bufseek(int handle_id, size_t newpos);
73 /* Advance the reading index in a handle, relatively to its current position */
74 int bufadvance(int handle_id, off_t offset);
76 /* Copy data from a handle to a buffer */
77 ssize_t bufread(int handle_id, size_t size, void *dest);
79 /* Obtain a pointer for linear access to a "size" amount of data */
80 ssize_t bufgetdata(int handle_id, size_t size, void **data);
82 /* Get a buffer offset from a pointer */
83 ssize_t get_offset(int handle_id, void *ptr);
85 void request_buffer_handle(int handle_id);
87 void buffering_get_debugdata(struct buffering_debug *dbgdata);
89 #endif