Update the LV24020 FM driver so that it can be used on the D2. Register read/write...
[Rockbox.git] / apps / buffering.h
blobcd705cec25712f1a794699e26006243dab955a81
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>
25 #include "events.h"
28 enum data_type {
29 TYPE_CODEC,
30 TYPE_PACKET_AUDIO,
31 TYPE_ATOMIC_AUDIO,
32 TYPE_ID3,
33 TYPE_CUESHEET,
34 TYPE_BITMAP,
35 TYPE_BUFFER,
36 TYPE_UNKNOWN,
39 enum callback_event {
40 EVENT_BUFFER_LOW = (EVENT_CLASS_BUFFERING|1),
41 EVENT_HANDLE_REBUFFER,
42 EVENT_HANDLE_CLOSED,
43 EVENT_HANDLE_MOVED,
44 EVENT_HANDLE_FINISHED,
47 /* Error return values */
48 #define ERR_HANDLE_NOT_FOUND -1
49 #define ERR_BUFFER_FULL -2
50 #define ERR_INVALID_VALUE -3
51 #define ERR_FILE_ERROR -4
52 #define ERR_HANDLE_NOT_DONE -5
55 /* Initialise the buffering subsystem */
56 void buffering_init(void);
58 /* Reset the buffering system */
59 bool buffering_reset(char *buf, size_t buflen);
62 /***************************************************************************
63 * MAIN BUFFERING API CALLS
64 * ========================
66 * bufopen : Reserve space in the buffer for a given file
67 * bufalloc : Open a new handle from data that needs to be copied from memory
68 * bufclose : Close an open handle
69 * bufseek : Set handle reading index, relatively to the start of the file
70 * bufadvance: Move handle reading index, relatively to current position
71 * bufread : Copy data from a handle to a buffer
72 * bufgetdata: Obtain a pointer for linear access to a "size" amount of data
73 * bufgettail: Out-of-band get the last size bytes of a handle.
74 * bufcuttail: Out-of-band remove the trailing 'size' bytes of a handle.
76 * NOTE: bufread and bufgetdata will block the caller until the requested
77 * amount of data is ready (unless EOF is reached).
78 * NOTE: Tail operations are only legal when the end of the file is buffered.
79 ****************************************************************************/
81 #define BUF_MAX_HANDLES 256
83 int bufopen(const char *file, size_t offset, enum data_type type);
84 int bufalloc(const void *src, size_t size, enum data_type type);
85 bool bufclose(int handle_id);
86 int bufseek(int handle_id, size_t newpos);
87 int bufadvance(int handle_id, off_t offset);
88 ssize_t bufread(int handle_id, size_t size, void *dest);
89 ssize_t bufgetdata(int handle_id, size_t size, void **data);
90 ssize_t bufgettail(int handle_id, size_t size, void **data);
91 ssize_t bufcuttail(int handle_id, size_t size);
94 /***************************************************************************
95 * SECONDARY FUNCTIONS
96 * ===================
98 * buf_get_offset: Get a handle offset from a pointer
99 * buf_handle_offset: Get the offset of the first buffered byte from the file
100 * buf_request_buffer_handle: Request buffering of a handle
101 * buf_set_base_handle: Tell the buffering thread which handle is currently read
102 * buf_used: Total amount of buffer space used (including allocated space)
103 ****************************************************************************/
105 ssize_t buf_get_offset(int handle_id, void *ptr);
106 ssize_t buf_handle_offset(int handle_id);
107 void buf_request_buffer_handle(int handle_id);
108 void buf_set_base_handle(int handle_id);
109 size_t buf_used(void);
113 /* Settings */
114 enum {
115 BUFFERING_SET_WATERMARK = 1,
116 BUFFERING_SET_CHUNKSIZE,
118 void buf_set_watermark(size_t bytes);
121 /* Debugging */
122 struct buffering_debug {
123 int num_handles;
124 size_t buffered_data;
125 size_t wasted_space;
126 size_t data_rem;
127 size_t useful_data;
129 void buffering_get_debugdata(struct buffering_debug *dbgdata);
131 #endif