A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd
at master 71 lines 2.5 kB view raw
1/*************************************************************************** 2* __________ __ ___. 3* Open \______ \ ____ ____ | | _\_ |__ _______ ___ 4* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / 5* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 6* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 7* \/ \/ \/ \/ \/ 8* $Id$ 9* 10* Copyright (C) 2023 William Wilgus 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 _CHUNKALLOC_H_ 23#define _CHUNKALLOC_H_ 24#include <stdbool.h> 25#include <string.h> 26#include "config.h" 27#include "buflib.h" 28 29#define CHUNK_ALLOC_INVALID ((size_t)-1) 30 31 32struct chunk_alloc_header 33{ 34 struct buflib_context *context; /* buflib context for all allocations */ 35 int chunk_handle; /* data handle of buflib allocated array of struct chunk */ 36 37 size_t chunk_bytes_total; /* total bytes in current chunk */ 38 size_t chunk_bytes_free; /* free bytes in current chunk */ 39 size_t chunk_size; /* default chunk size */ 40 size_t count; /* total chunks possible */ 41 size_t current; /* current chunk in use */ 42 43 struct { 44 int handle; 45 size_t min_offset; 46 size_t max_offset; 47 } cached_chunk; 48}; 49 50void chunk_alloc_free(struct chunk_alloc_header *hdr); 51 52bool chunk_alloc_init(struct chunk_alloc_header *hdr, 53 struct buflib_context *ctx, 54 size_t chunk_size, size_t max_chunks); 55 56bool chunk_realloc(struct chunk_alloc_header *hdr, 57 size_t chunk_size, size_t max_chunks); 58 59void chunk_alloc_finalize(struct chunk_alloc_header *hdr); 60 61size_t chunk_alloc(struct chunk_alloc_header *hdr, size_t size); /* Returns offset */ 62 63void* chunk_get_data(struct chunk_alloc_header *hdr, size_t offset); /* Returns data */ 64 65void chunk_put_data(struct chunk_alloc_header *hdr, void* data, size_t offset); 66 67static inline bool chunk_alloc_is_initialized(struct chunk_alloc_header *hdr) 68{ 69 return (hdr->chunk_handle > 0); 70} 71#endif