2007-10-25 21:27:45 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 Nicolas Pennequin
|
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2007-10-25 21:27:45 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef _BUFFERING_H_
|
|
|
|
#define _BUFFERING_H_
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <stdbool.h>
|
2011-12-19 20:12:52 +00:00
|
|
|
#include "config.h"
|
2008-10-16 10:38:03 +00:00
|
|
|
#include "appevents.h"
|
2007-10-25 21:27:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
enum data_type {
|
2011-04-27 03:08:23 +00:00
|
|
|
TYPE_UNKNOWN = 0, /* invalid type indicator */
|
|
|
|
TYPE_ID3,
|
2007-10-25 21:27:45 +00:00
|
|
|
TYPE_CODEC,
|
2007-11-02 14:06:48 +00:00
|
|
|
TYPE_PACKET_AUDIO,
|
|
|
|
TYPE_ATOMIC_AUDIO,
|
2007-10-25 21:27:45 +00:00
|
|
|
TYPE_CUESHEET,
|
2007-11-11 12:29:37 +00:00
|
|
|
TYPE_BITMAP,
|
2007-10-25 21:27:45 +00:00
|
|
|
};
|
|
|
|
|
2007-10-28 15:54:10 +00:00
|
|
|
/* Error return values */
|
2007-10-29 14:15:59 +00:00
|
|
|
#define ERR_HANDLE_NOT_FOUND -1
|
|
|
|
#define ERR_BUFFER_FULL -2
|
|
|
|
#define ERR_INVALID_VALUE -3
|
|
|
|
#define ERR_FILE_ERROR -4
|
2007-11-28 04:58:16 +00:00
|
|
|
#define ERR_HANDLE_NOT_DONE -5
|
2011-02-09 20:27:23 +00:00
|
|
|
#define ERR_UNSUPPORTED_TYPE -6
|
2013-08-26 20:49:53 +00:00
|
|
|
#define ERR_WRONG_THREAD -7
|
2007-10-25 21:27:45 +00:00
|
|
|
|
|
|
|
/* Initialise the buffering subsystem */
|
2011-12-19 20:12:52 +00:00
|
|
|
void buffering_init(void) INIT_ATTR;
|
2007-10-27 04:16:41 +00:00
|
|
|
|
|
|
|
/* Reset the buffering system */
|
2008-03-28 12:51:33 +00:00
|
|
|
bool buffering_reset(char *buf, size_t buflen);
|
2007-10-25 21:27:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
* MAIN BUFFERING API CALLS
|
|
|
|
* ========================
|
|
|
|
*
|
|
|
|
* bufopen : Reserve space in the buffer for a given file
|
|
|
|
* bufalloc : Open a new handle from data that needs to be copied from memory
|
|
|
|
* bufclose : Close an open handle
|
|
|
|
* bufseek : Set handle reading index, relatively to the start of the file
|
|
|
|
* bufadvance: Move handle reading index, relatively to current position
|
2011-04-27 03:08:23 +00:00
|
|
|
* bufftell : Return the handle's file read position
|
2007-10-25 21:27:45 +00:00
|
|
|
* bufread : Copy data from a handle to a buffer
|
|
|
|
* bufgetdata: Obtain a pointer for linear access to a "size" amount of data
|
2007-11-28 04:58:16 +00:00
|
|
|
* bufgettail: Out-of-band get the last size bytes of a handle.
|
|
|
|
* bufcuttail: Out-of-band remove the trailing 'size' bytes of a handle.
|
2007-11-02 19:13:03 +00:00
|
|
|
*
|
|
|
|
* NOTE: bufread and bufgetdata will block the caller until the requested
|
|
|
|
* amount of data is ready (unless EOF is reached).
|
2007-11-28 04:58:16 +00:00
|
|
|
* NOTE: Tail operations are only legal when the end of the file is buffered.
|
2007-10-25 21:27:45 +00:00
|
|
|
****************************************************************************/
|
|
|
|
|
2007-11-03 02:54:34 +00:00
|
|
|
#define BUF_MAX_HANDLES 256
|
|
|
|
|
2009-10-16 19:14:41 +00:00
|
|
|
int bufopen(const char *file, size_t offset, enum data_type type,
|
|
|
|
void *user_data);
|
2008-03-28 12:51:33 +00:00
|
|
|
int bufalloc(const void *src, size_t size, enum data_type type);
|
|
|
|
bool bufclose(int handle_id);
|
|
|
|
int bufseek(int handle_id, size_t newpos);
|
|
|
|
int bufadvance(int handle_id, off_t offset);
|
2011-04-27 03:08:23 +00:00
|
|
|
off_t bufftell(int handle_id);
|
2008-03-28 12:51:33 +00:00
|
|
|
ssize_t bufread(int handle_id, size_t size, void *dest);
|
|
|
|
ssize_t bufgetdata(int handle_id, size_t size, void **data);
|
|
|
|
ssize_t bufgettail(int handle_id, size_t size, void **data);
|
|
|
|
ssize_t bufcuttail(int handle_id, size_t size);
|
2007-10-25 21:27:45 +00:00
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
* SECONDARY FUNCTIONS
|
|
|
|
* ===================
|
|
|
|
*
|
2011-04-27 03:08:23 +00:00
|
|
|
* buf_handle_data_type: return the handle's data type
|
|
|
|
* buf_is_handle: is the handle valid?
|
|
|
|
* buf_pin_handle: Disallow/allow handle movement. Handle may still be removed.
|
2007-10-25 21:27:45 +00:00
|
|
|
* buf_handle_offset: Get the offset of the first buffered byte from the file
|
|
|
|
* buf_set_base_handle: Tell the buffering thread which handle is currently read
|
2011-04-27 03:08:23 +00:00
|
|
|
* buf_length: Total size of ringbuffer
|
2007-10-25 21:27:45 +00:00
|
|
|
* buf_used: Total amount of buffer space used (including allocated space)
|
2011-04-27 03:08:23 +00:00
|
|
|
* buf_back_off_storage: tell buffering thread to take it easy
|
2007-10-25 21:27:45 +00:00
|
|
|
****************************************************************************/
|
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
enum data_type buf_handle_data_type(int handle_id);
|
|
|
|
ssize_t buf_handle_remaining(int handle_id);
|
|
|
|
bool buf_is_handle(int handle_id);
|
2008-03-28 12:51:33 +00:00
|
|
|
ssize_t buf_handle_offset(int handle_id);
|
|
|
|
void buf_set_base_handle(int handle_id);
|
2011-04-27 03:08:23 +00:00
|
|
|
size_t buf_length(void);
|
2007-10-25 21:27:45 +00:00
|
|
|
size_t buf_used(void);
|
2011-04-27 03:08:23 +00:00
|
|
|
bool buf_pin_handle(int handle_id, bool pin);
|
|
|
|
bool buf_signal_handle(int handle_id, bool signal);
|
2007-10-25 21:27:45 +00:00
|
|
|
|
|
|
|
/* Settings */
|
2007-11-05 17:48:21 +00:00
|
|
|
void buf_set_watermark(size_t bytes);
|
2011-04-27 03:08:23 +00:00
|
|
|
size_t buf_get_watermark(void);
|
2007-10-25 21:27:45 +00:00
|
|
|
|
|
|
|
/* Debugging */
|
|
|
|
struct buffering_debug {
|
|
|
|
int num_handles;
|
|
|
|
size_t buffered_data;
|
|
|
|
size_t data_rem;
|
|
|
|
size_t useful_data;
|
2009-02-23 22:55:48 +00:00
|
|
|
size_t watermark;
|
2007-10-25 21:27:45 +00:00
|
|
|
};
|
|
|
|
void buffering_get_debugdata(struct buffering_debug *dbgdata);
|
|
|
|
|
|
|
|
#endif
|