Remove stray function prototype used only for long-ago-removed codec swapping. Functi...
[kugel-rb.git] / apps / buffering.h
blob6e17b65d8c824ffb7712a7cbecaeb77b6d42ae1b
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2007 Nicolas Pennequin
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #ifndef _BUFFERING_H_
23 #define _BUFFERING_H_
25 #include <sys/types.h>
26 #include <stdbool.h>
27 #include "appevents.h"
30 enum data_type {
31 TYPE_CODEC,
32 TYPE_PACKET_AUDIO,
33 TYPE_ATOMIC_AUDIO,
34 TYPE_ID3,
35 TYPE_CUESHEET,
36 TYPE_BITMAP,
37 TYPE_BUFFER,
38 TYPE_UNKNOWN,
41 /* Error return values */
42 #define ERR_HANDLE_NOT_FOUND -1
43 #define ERR_BUFFER_FULL -2
44 #define ERR_INVALID_VALUE -3
45 #define ERR_FILE_ERROR -4
46 #define ERR_HANDLE_NOT_DONE -5
49 /* Initialise the buffering subsystem */
50 void buffering_init(void);
52 /* Reset the buffering system */
53 bool buffering_reset(char *buf, size_t buflen);
56 /***************************************************************************
57 * MAIN BUFFERING API CALLS
58 * ========================
60 * bufopen : Reserve space in the buffer for a given file
61 * bufalloc : Open a new handle from data that needs to be copied from memory
62 * bufclose : Close an open handle
63 * bufseek : Set handle reading index, relatively to the start of the file
64 * bufadvance: Move handle reading index, relatively to current position
65 * bufread : Copy data from a handle to a buffer
66 * bufgetdata: Obtain a pointer for linear access to a "size" amount of data
67 * bufgettail: Out-of-band get the last size bytes of a handle.
68 * bufcuttail: Out-of-band remove the trailing 'size' bytes of a handle.
70 * NOTE: bufread and bufgetdata will block the caller until the requested
71 * amount of data is ready (unless EOF is reached).
72 * NOTE: Tail operations are only legal when the end of the file is buffered.
73 ****************************************************************************/
75 #define BUF_MAX_HANDLES 256
77 int bufopen(const char *file, size_t offset, enum data_type type,
78 void *user_data);
79 int bufalloc(const void *src, size_t size, enum data_type type);
80 bool bufclose(int handle_id);
81 int bufseek(int handle_id, size_t newpos);
82 int bufadvance(int handle_id, off_t offset);
83 ssize_t bufread(int handle_id, size_t size, void *dest);
84 ssize_t bufgetdata(int handle_id, size_t size, void **data);
85 ssize_t bufgettail(int handle_id, size_t size, void **data);
86 ssize_t bufcuttail(int handle_id, size_t size);
89 /***************************************************************************
90 * SECONDARY FUNCTIONS
91 * ===================
93 * buf_get_offset: Get a handle offset from a pointer
94 * buf_handle_offset: Get the offset of the first buffered byte from the file
95 * buf_request_buffer_handle: Request buffering of a handle
96 * buf_set_base_handle: Tell the buffering thread which handle is currently read
97 * buf_used: Total amount of buffer space used (including allocated space)
98 ****************************************************************************/
100 ssize_t buf_get_offset(int handle_id, void *ptr);
101 ssize_t buf_handle_offset(int handle_id);
102 void buf_request_buffer_handle(int handle_id);
103 void buf_set_base_handle(int handle_id);
104 size_t buf_used(void);
108 /* Settings */
109 enum {
110 BUFFERING_SET_WATERMARK = 1,
111 BUFFERING_SET_CHUNKSIZE,
113 void buf_set_watermark(size_t bytes);
115 /* Debugging */
116 struct buffering_debug {
117 int num_handles;
118 size_t buffered_data;
119 size_t wasted_space;
120 size_t data_rem;
121 size_t useful_data;
122 size_t watermark;
124 void buffering_get_debugdata(struct buffering_debug *dbgdata);
126 #endif