summaryrefslogtreecommitdiff
path: root/apps/buffering.h
diff options
context:
space:
mode:
Diffstat (limited to 'apps/buffering.h')
-rw-r--r--apps/buffering.h120
1 files changed, 120 insertions, 0 deletions
diff --git a/apps/buffering.h b/apps/buffering.h
new file mode 100644
index 0000000000..a5ad1e283b
--- /dev/null
+++ b/apps/buffering.h
@@ -0,0 +1,120 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2007 Nicolas Pennequin
11 *
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.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19
20#ifndef _BUFFERING_H_
21#define _BUFFERING_H_
22
23#include <sys/types.h>
24#include <stdbool.h>
25
26
27enum data_type {
28 TYPE_CODEC,
29 TYPE_AUDIO,
30 TYPE_STREAM,
31 TYPE_ID3,
32 TYPE_CUESHEET,
33 TYPE_IMAGE,
34 TYPE_BUFFER,
35 TYPE_UNKNOWN,
36};
37
38
39/* Initialise the buffering subsystem */
40bool buffering_init(char *buf, size_t buflen);
41
42
43/***************************************************************************
44 * MAIN BUFFERING API CALLS
45 * ========================
46 *
47 * bufopen : Reserve space in the buffer for a given file
48 * bufalloc : Open a new handle from data that needs to be copied from memory
49 * bufclose : Close an open handle
50 * bufseek : Set handle reading index, relatively to the start of the file
51 * bufadvance: Move handle reading index, relatively to current position
52 * bufread : Copy data from a handle to a buffer
53 * bufgetdata: Obtain a pointer for linear access to a "size" amount of data
54 ****************************************************************************/
55
56int bufopen(const char *file, size_t offset, enum data_type type);
57int bufalloc(const void *src, size_t size, enum data_type type);
58bool bufclose(int handle_id);
59int bufseek(int handle_id, size_t newpos);
60int bufadvance(int handle_id, off_t offset);
61ssize_t bufread(int handle_id, size_t size, void *dest);
62ssize_t bufgetdata(int handle_id, size_t size, void **data);
63
64
65/***************************************************************************
66 * SECONDARY FUNCTIONS
67 * ===================
68 *
69 * buf_get_offset: Get a handle offset from a pointer
70 * buf_handle_offset: Get the offset of the first buffered byte from the file
71 * buf_request_buffer_handle: Request buffering of a handle
72 * buf_set_base_handle: Tell the buffering thread which handle is currently read
73 * buf_used: Total amount of buffer space used (including allocated space)
74 ****************************************************************************/
75
76ssize_t buf_get_offset(int handle_id, void *ptr);
77ssize_t buf_handle_offset(int handle_id);
78void buf_request_buffer_handle(int handle_id);
79void buf_set_base_handle(int handle_id);
80size_t buf_used(void);
81
82
83/***************************************************************************
84 * CALLBACK UTILITIES
85 * ==================
86 *
87 * register_buffer_low_callback, unregister_buffer_low_callback:
88 *
89 * Register/Unregister callback functions that will get executed when the buffer
90 * goes below the low watermark. They are executed once, then forgotten.
91 *
92 * NOTE: The callbacks are called from the buffering thread, so don't make them
93 * do too much. Ideally they should just post an event to a queue and return.
94 ****************************************************************************/
95
96#define MAX_BUF_CALLBACKS 4
97typedef void (*buffer_low_callback)(void);
98bool register_buffer_low_callback(buffer_low_callback func);
99void unregister_buffer_low_callback(buffer_low_callback func);
100
101/* Settings */
102enum {
103 BUFFERING_SET_WATERMARK = 1,
104 BUFFERING_SET_CHUNKSIZE,
105 BUFFERING_SET_PRESEEK,
106};
107void buf_set_conf(int setting, size_t value);
108
109
110/* Debugging */
111struct buffering_debug {
112 int num_handles;
113 size_t buffered_data;
114 size_t wasted_space;
115 size_t data_rem;
116 size_t useful_data;
117};
118void buffering_get_debugdata(struct buffering_debug *dbgdata);
119
120#endif