A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita
audio
rust
zig
deno
mpris
rockbox
mpd
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2007 Nicolas Pennequin
11 *
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.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#ifndef _BUFFERING_H_
23#define _BUFFERING_H_
24
25#include <sys/types.h>
26#include <stdbool.h>
27#include "config.h"
28#include "appevents.h"
29
30
31enum data_type {
32 TYPE_UNKNOWN = 0, /* invalid type indicator */
33 TYPE_ID3,
34 TYPE_CODEC,
35 TYPE_PACKET_AUDIO,
36 TYPE_ATOMIC_AUDIO,
37 TYPE_CUESHEET,
38 TYPE_BITMAP,
39 TYPE_RAW_ATOMIC,
40};
41
42/* Error return values */
43#define ERR_HANDLE_NOT_FOUND -1
44#define ERR_BUFFER_FULL -2
45#define ERR_INVALID_VALUE -3
46#define ERR_FILE_ERROR -4
47#define ERR_HANDLE_NOT_DONE -5
48#define ERR_UNSUPPORTED_TYPE -6
49#define ERR_BITMAP_TOO_LARGE -7
50
51/* Initialise the buffering subsystem */
52void buffering_init(void) INIT_ATTR;
53
54/* Reset the buffering system */
55bool buffering_reset(char *buf, size_t buflen);
56
57
58/***************************************************************************
59 * MAIN BUFFERING API CALLS
60 * ========================
61 *
62 * bufopen : Reserve space in the buffer for a given file
63 * bufalloc : Open a new handle from data that needs to be copied from memory
64 * bufclose : Close an open handle
65 * bufseek : Set handle reading index, relatively to the start of the file
66 * bufadvance: Move handle reading index, relatively to current position
67 * bufftell : Return the handle's file read position
68 * bufread : Copy data from a handle to a buffer
69 * bufgetdata: Obtain a pointer for linear access to a "size" amount of data
70 *
71 * NOTE: bufread and bufgetdata will block the caller until the requested
72 * amount of data is ready (unless EOF is reached).
73 * NOTE: Tail operations are only legal when the end of the file is buffered.
74 ****************************************************************************/
75
76int bufopen(const char *file, off_t offset, enum data_type type,
77 void *user_data);
78int bufalloc(const void *src, size_t size, enum data_type type);
79bool bufclose(int handle_id);
80int bufseek(int handle_id, size_t newpos);
81int bufadvance(int handle_id, off_t offset);
82off_t bufftell(int handle_id);
83ssize_t bufread(int handle_id, size_t size, void *dest);
84off_t bufstripsize(int handle_id, off_t size);
85ssize_t bufgetdata(int handle_id, size_t size, void **data);
86
87/***************************************************************************
88 * SECONDARY FUNCTIONS
89 * ===================
90 *
91 * buf_handle_data_type: return the handle's data type
92 * buf_is_handle: is the handle valid?
93 * buf_pin_handle: Disallow/allow handle movement. Handle may still be removed.
94 * buf_handle_offset: Get the offset of the first buffered byte from the file
95 * buf_set_base_handle: Tell the buffering thread which handle is currently read
96 * buf_length: Total size of ringbuffer
97 * buf_used: Total amount of buffer space used (including allocated space)
98 * buf_back_off_storage: tell buffering thread to take it easy
99 ****************************************************************************/
100
101bool buf_is_handle(int handle_id);
102int buf_handle_data_type(int handle_id);
103off_t buf_filesize(int handle_id);
104off_t buf_handle_offset(int handle_id);
105off_t buf_handle_remaining(int handle_id);
106bool buf_pin_handle(int handle_id, bool pin);
107bool buf_signal_handle(int handle_id, bool signal);
108
109size_t buf_length(void);
110size_t buf_used(void);
111
112/* Settings */
113void buf_set_base_handle(int handle_id);
114void buf_set_watermark(size_t bytes);
115size_t buf_get_watermark(void);
116
117/* Debugging */
118struct buffering_debug {
119 int num_handles;
120 size_t buffered_data;
121 size_t data_rem;
122 size_t useful_data;
123 size_t watermark;
124};
125void buffering_get_debugdata(struct buffering_debug *dbgdata);
126
127#endif