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)
49 /* Messages available to communicate with the buffering thread */
51 Q_BUFFER_HANDLE
= 1, /* Request buffering of a handle */
52 Q_RESET_HANDLE
, /* (internal) Request resetting of a handle to its
53 offset (the offset has to be set beforehand) */
56 struct event_queue buffering_queue
;
57 struct queue_sender_list buffering_queue_sender_list
;
59 /* Initialise the buffering subsystem */
60 bool buffering_init(char *filebuf
, size_t filebuflen
);
62 /* Amount of buffer space used */
65 /* Reserve space in the buffer for a file */
66 int bufopen(char *file
, size_t offset
, enum data_type type
);
68 /* Open a new handle from data that needs to be copied from memory */
69 int bufalloc(void *src
, size_t size
, enum data_type type
);
72 int bufclose(int handle_id
);
74 /* Set reading index in handle, relatively to the start of the file */
75 int bufseek(int handle_id
, size_t newpos
);
77 /* Advance the reading index in a handle, relatively to its current position */
78 int bufadvance(int handle_id
, off_t offset
);
80 /* Copy data from a handle to a buffer */
81 ssize_t
bufread(int handle_id
, size_t size
, void *dest
);
83 /* Obtain a pointer for linear access to a "size" amount of data */
84 ssize_t
bufgetdata(int handle_id
, size_t size
, void **data
);
86 /* Get a buffer offset from a pointer */
87 ssize_t
get_offset(int handle_id
, void *ptr
);