1
0
Fork 0
forked from len0rd/rockbox

The const police raid playback.c, should be no change to behaviour.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@16860 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Steve Bavin 2008-03-28 11:24:24 +00:00
parent f54def9dd5
commit c9df8fd87b
17 changed files with 154 additions and 135 deletions

View file

@ -225,7 +225,7 @@ buf_ridx == buf_widx means the buffer is empty.
only potential side effect is to allocate space for the cur_handle only potential side effect is to allocate space for the cur_handle
if it returns NULL. if it returns NULL.
*/ */
static struct memory_handle *add_handle(size_t data_size, const bool can_wrap, static struct memory_handle *add_handle(const size_t data_size, const bool can_wrap,
const bool alloc_all) const bool alloc_all)
{ {
/* gives each handle a unique id */ /* gives each handle a unique id */
@ -873,8 +873,10 @@ management functions for all the actual handle management work.
return value: <0 if the file cannot be opened, or one file already return value: <0 if the file cannot be opened, or one file already
queued to be opened, otherwise the handle for the file in the buffer queued to be opened, otherwise the handle for the file in the buffer
*/ */
int bufopen(const char *file, size_t offset, const enum data_type type) int bufopen(const char *file, const size_t offset, const enum data_type type)
{ {
size_t adjusted_offset = offset;
int fd = open(file, O_RDONLY); int fd = open(file, O_RDONLY);
if (fd < 0) if (fd < 0)
return ERR_FILE_ERROR; return ERR_FILE_ERROR;
@ -882,10 +884,10 @@ int bufopen(const char *file, size_t offset, const enum data_type type)
size_t size = filesize(fd); size_t size = filesize(fd);
bool can_wrap = type==TYPE_PACKET_AUDIO || type==TYPE_CODEC; bool can_wrap = type==TYPE_PACKET_AUDIO || type==TYPE_CODEC;
if (offset > size) if (adjusted_offset > size)
offset = 0; adjusted_offset = 0;
struct memory_handle *h = add_handle(size-offset, can_wrap, false); struct memory_handle *h = add_handle(size-adjusted_offset, can_wrap, false);
if (!h) if (!h)
{ {
DEBUGF("bufopen: failed to add handle\n"); DEBUGF("bufopen: failed to add handle\n");
@ -894,7 +896,7 @@ int bufopen(const char *file, size_t offset, const enum data_type type)
} }
strncpy(h->path, file, MAX_PATH); strncpy(h->path, file, MAX_PATH);
h->offset = offset; h->offset = adjusted_offset;
h->ridx = buf_widx; h->ridx = buf_widx;
h->data = buf_widx; h->data = buf_widx;
h->type = type; h->type = type;
@ -923,7 +925,7 @@ int bufopen(const char *file, size_t offset, const enum data_type type)
else else
#endif #endif
{ {
h->filerem = size - offset; h->filerem = size - adjusted_offset;
h->filesize = size; h->filesize = size;
h->available = 0; h->available = 0;
h->widx = buf_widx; h->widx = buf_widx;
@ -1094,27 +1096,28 @@ static struct memory_handle *prep_bufdata(const int handle_id, size_t *size,
Return the number of bytes copied or < 0 for failure (handle not found). Return the number of bytes copied or < 0 for failure (handle not found).
The caller is blocked until the requested amount of data is available. The caller is blocked until the requested amount of data is available.
*/ */
ssize_t bufread(const int handle_id, size_t size, void *dest) ssize_t bufread(const int handle_id, const size_t size, void *dest)
{ {
const struct memory_handle *h; const struct memory_handle *h;
size_t adjusted_size = size;
h = prep_bufdata(handle_id, &size, false); h = prep_bufdata(handle_id, &adjusted_size, false);
if (!h) if (!h)
return ERR_HANDLE_NOT_FOUND; return ERR_HANDLE_NOT_FOUND;
if (h->ridx + size > buffer_len) if (h->ridx + adjusted_size > buffer_len)
{ {
/* the data wraps around the end of the buffer */ /* the data wraps around the end of the buffer */
size_t read = buffer_len - h->ridx; size_t read = buffer_len - h->ridx;
memcpy(dest, &buffer[h->ridx], read); memcpy(dest, &buffer[h->ridx], read);
memcpy(dest+read, buffer, size - read); memcpy(dest+read, buffer, adjusted_size - read);
} }
else else
{ {
memcpy(dest, &buffer[h->ridx], size); memcpy(dest, &buffer[h->ridx], adjusted_size);
} }
return size; return adjusted_size;
} }
/* Update the "data" pointer to make the handle's data available to the caller. /* Update the "data" pointer to make the handle's data available to the caller.
@ -1126,20 +1129,21 @@ ssize_t bufread(const int handle_id, size_t size, void *dest)
The guard buffer may be used to provide the requested size. This means it's The guard buffer may be used to provide the requested size. This means it's
unsafe to request more than the size of the guard buffer. unsafe to request more than the size of the guard buffer.
*/ */
ssize_t bufgetdata(const int handle_id, size_t size, void **data) ssize_t bufgetdata(const int handle_id, const size_t size, void **data)
{ {
const struct memory_handle *h; const struct memory_handle *h;
size_t adjusted_size = size;
h = prep_bufdata(handle_id, &size, true); h = prep_bufdata(handle_id, &adjusted_size, true);
if (!h) if (!h)
return ERR_HANDLE_NOT_FOUND; return ERR_HANDLE_NOT_FOUND;
if (h->ridx + size > buffer_len) if (h->ridx + adjusted_size > buffer_len)
{ {
/* the data wraps around the end of the buffer : /* the data wraps around the end of the buffer :
use the guard buffer to provide the requested amount of data. */ use the guard buffer to provide the requested amount of data. */
size_t copy_n = h->ridx + size - buffer_len; size_t copy_n = h->ridx + adjusted_size - buffer_len;
/* prep_bufdata ensures size <= buffer_len - h->ridx + GUARD_BUFSIZE, /* prep_bufdata ensures adjusted_size <= buffer_len - h->ridx + GUARD_BUFSIZE,
so copy_n <= GUARD_BUFSIZE */ so copy_n <= GUARD_BUFSIZE */
memcpy(guard_buffer, (const unsigned char *)buffer, copy_n); memcpy(guard_buffer, (const unsigned char *)buffer, copy_n);
} }
@ -1147,7 +1151,7 @@ ssize_t bufgetdata(const int handle_id, size_t size, void **data)
if (data) if (data)
*data = &buffer[h->ridx]; *data = &buffer[h->ridx];
return size; return adjusted_size;
} }
ssize_t bufgettail(const int handle_id, const size_t size, void **data) ssize_t bufgettail(const int handle_id, const size_t size, void **data)
@ -1180,9 +1184,10 @@ ssize_t bufgettail(const int handle_id, const size_t size, void **data)
return size; return size;
} }
ssize_t bufcuttail(const int handle_id, size_t size) ssize_t bufcuttail(const int handle_id, const size_t size)
{ {
struct memory_handle *h; struct memory_handle *h;
size_t adjusted_size = size;
h = find_handle(handle_id); h = find_handle(handle_id);
@ -1192,16 +1197,16 @@ ssize_t bufcuttail(const int handle_id, size_t size)
if (h->filerem) if (h->filerem)
return ERR_HANDLE_NOT_DONE; return ERR_HANDLE_NOT_DONE;
if (h->available < size) if (h->available < adjusted_size)
size = h->available; adjusted_size = h->available;
h->available -= size; h->available -= adjusted_size;
h->filesize -= size; h->filesize -= adjusted_size;
h->widx = RINGBUF_SUB(h->widx, size); h->widx = RINGBUF_SUB(h->widx, adjusted_size);
if (h == cur_handle) if (h == cur_handle)
buf_widx = h->widx; buf_widx = h->widx;
return size; return adjusted_size;
} }

View file

@ -126,28 +126,28 @@ struct codec_api {
void* (*get_codec_memory)(size_t *size); void* (*get_codec_memory)(size_t *size);
/* Insert PCM data into audio buffer for playback. Playback will start /* Insert PCM data into audio buffer for playback. Playback will start
automatically. */ automatically. */
bool (*pcmbuf_insert)(const void *ch1, const void *ch2, int count); bool (*pcmbuf_insert)(const void *ch1, const void *ch2, const int count);
/* Set song position in WPS (value in ms). */ /* Set song position in WPS (value in ms). */
void (*set_elapsed)(unsigned int value); void (*set_elapsed)(const unsigned int value);
/* Read next <size> amount bytes from file buffer to <ptr>. /* Read next <size> amount bytes from file buffer to <ptr>.
Will return number of bytes read or 0 if end of file. */ Will return number of bytes read or 0 if end of file. */
size_t (*read_filebuf)(void *ptr, size_t size); size_t (*read_filebuf)(void *ptr, const size_t size);
/* Request pointer to file buffer which can be used to read /* Request pointer to file buffer which can be used to read
<realsize> amount of data. <reqsize> tells the buffer system <realsize> amount of data. <reqsize> tells the buffer system
how much data it should try to allocate. If <realsize> is 0, how much data it should try to allocate. If <realsize> is 0,
end of file is reached. */ end of file is reached. */
void* (*request_buffer)(size_t *realsize, size_t reqsize); void* (*request_buffer)(size_t *realsize, const size_t reqsize);
/* Advance file buffer position by <amount> amount of bytes. */ /* Advance file buffer position by <amount> amount of bytes. */
void (*advance_buffer)(size_t amount); void (*advance_buffer)(const size_t amount);
/* Advance file buffer to a pointer location inside file buffer. */ /* Advance file buffer to a pointer location inside file buffer. */
void (*advance_buffer_loc)(void *ptr); void (*advance_buffer_loc)(void *ptr);
/* Seek file buffer to position <newpos> beginning of file. */ /* Seek file buffer to position <newpos> beginning of file. */
bool (*seek_buffer)(size_t newpos); bool (*seek_buffer)(const size_t newpos);
/* Codec should call this function when it has done the seeking. */ /* Codec should call this function when it has done the seeking. */
void (*seek_complete)(void); void (*seek_complete)(void);
/* Calculate mp3 seek position from given time data in ms. */ /* Calculate mp3 seek position from given time data in ms. */
off_t (*mp3_get_filepos)(int newtime); off_t (*mp3_get_filepos)(const int newtime);
/* Request file change from file buffer. Returns true is next /* Request file change from file buffer. Returns true is next
track is available and changed. If return value is false, track is available and changed. If return value is false,
codec should exit immediately with PLUGIN_OK status. */ codec should exit immediately with PLUGIN_OK status. */
@ -155,12 +155,12 @@ struct codec_api {
/* Free the buffer area of the current codec after its loaded */ /* Free the buffer area of the current codec after its loaded */
void (*discard_codec)(void); void (*discard_codec)(void);
void (*set_offset)(size_t value); void (*set_offset)(const size_t value);
/* Configure different codec buffer parameters. */ /* Configure different codec buffer parameters. */
void (*configure)(int setting, intptr_t value); void (*configure)(const int setting, const intptr_t value);
/* kernel/ system */ /* kernel/ system */
void (*PREFIX(sleep))(int ticks); void (*PREFIX(sleep))(const int ticks);
void (*yield)(void); void (*yield)(void);
#if NUM_CORES > 1 #if NUM_CORES > 1

View file

@ -77,6 +77,7 @@
#if CONFIG_CODEC == SWCODEC #if CONFIG_CODEC == SWCODEC
#include "pcmbuf.h" #include "pcmbuf.h"
#include "buffering.h" #include "buffering.h"
#include "playback.h"
#if defined(HAVE_SPDIF_OUT) || defined(HAVE_SPDIF_IN) #if defined(HAVE_SPDIF_OUT) || defined(HAVE_SPDIF_IN)
#include "spdif.h" #include "spdif.h"
#endif #endif

View file

@ -54,6 +54,9 @@
#include "action.h" #include "action.h"
#include "cuesheet.h" #include "cuesheet.h"
#include "playlist.h" #include "playlist.h"
#if CONFIG_CODEC == SWCODEC
#include "playback.h"
#endif
#if (LCD_DEPTH > 1) || (defined(HAVE_LCD_REMOTE) && (LCD_REMOTE_DEPTH > 1)) #if (LCD_DEPTH > 1) || (defined(HAVE_LCD_REMOTE) && (LCD_REMOTE_DEPTH > 1))
#include "backdrop.h" #include "backdrop.h"

View file

@ -34,6 +34,10 @@
#include "scrobbler.h" #include "scrobbler.h"
#include "audio.h" #include "audio.h"
#include "cuesheet.h" #include "cuesheet.h"
#if CONFIG_CODEC == SWCODEC
#include "playback.h"
#endif
#if CONFIG_CODEC == SWCODEC #if CONFIG_CODEC == SWCODEC
int setcrossfadeonexit_callback(int action,const struct menu_item_ex *this_item) int setcrossfadeonexit_callback(int action,const struct menu_item_ex *this_item)

View file

@ -35,6 +35,9 @@
#include "talk.h" #include "talk.h"
#include "sprintf.h" #include "sprintf.h"
#include "powermgmt.h" #include "powermgmt.h"
#if CONFIG_CODEC == SWCODEC
#include "playback.h"
#endif
#ifdef HAVE_RTC_ALARM #ifdef HAVE_RTC_ALARM
#include "alarm_menu.h" #include "alarm_menu.h"
#endif #endif

View file

@ -82,7 +82,7 @@ static char *fadebuf IDATA_ATTR;
static char *voicebuf IDATA_ATTR; static char *voicebuf IDATA_ATTR;
static void (*pcmbuf_event_handler)(void) IDATA_ATTR; static void (*pcmbuf_event_handler)(void) IDATA_ATTR;
static void (*position_callback)(size_t size) IDATA_ATTR; static void (*position_callback)(const size_t size) IDATA_ATTR;
/* Crossfade related state */ /* Crossfade related state */
static bool crossfade_enabled; static bool crossfade_enabled;
@ -188,7 +188,7 @@ static void pcmbuf_callback(unsigned char** start, size_t* size)
} }
} }
void pcmbuf_set_position_callback(void (*callback)(size_t size)) void pcmbuf_set_position_callback(void (*callback)(const size_t size))
{ {
position_callback = callback; position_callback = callback;
} }
@ -938,7 +938,7 @@ void pcmbuf_write_complete(int count)
} }
#if 0 #if 0
bool pcmbuf_insert_buffer(char *buf, int count) bool pcmbuf_insert_buffer(char *buf, const int count)
{ {
size_t length = (size_t)(unsigned int)count << 2; size_t length = (size_t)(unsigned int)count << 2;

View file

@ -63,7 +63,7 @@ bool pcmbuf_is_lowdata(void);
void pcmbuf_play_start(void); void pcmbuf_play_start(void);
bool pcmbuf_crossfade_init(bool manual_skip); bool pcmbuf_crossfade_init(bool manual_skip);
void pcmbuf_set_event_handler(void (*callback)(void)); void pcmbuf_set_event_handler(void (*callback)(void));
void pcmbuf_set_position_callback(void (*callback)(size_t size)); void pcmbuf_set_position_callback(void (*callback)(const size_t size));
size_t pcmbuf_free(void); size_t pcmbuf_free(void);
unsigned int pcmbuf_get_latency(void); unsigned int pcmbuf_get_latency(void);
void pcmbuf_set_low_latency(bool state); void pcmbuf_set_low_latency(bool state);

View file

@ -249,7 +249,7 @@ static size_t buffer_margin = 0; /* Buffer margin aka anti-skip buffer (A/C-) *
/* Multiple threads */ /* Multiple threads */
/* Set the watermark to trigger buffer fill (A/C) FIXME */ /* Set the watermark to trigger buffer fill (A/C) FIXME */
static void set_filebuf_watermark(int seconds, size_t max); static void set_filebuf_watermark(const int seconds, const size_t max);
/* Audio thread */ /* Audio thread */
static struct event_queue audio_queue NOCACHEBSS_ATTR; static struct event_queue audio_queue NOCACHEBSS_ATTR;
@ -277,7 +277,7 @@ static struct event_queue pcmbuf_queue NOCACHEBSS_ATTR;
/* Function to be called by pcm buffer callbacks. /* Function to be called by pcm buffer callbacks.
* Permissible Context(s): Audio interrupt * Permissible Context(s): Audio interrupt
*/ */
static void pcmbuf_callback_queue_post(long id, intptr_t data) static void pcmbuf_callback_queue_post(const long id, intptr_t data)
{ {
/* No lock since we're already in audio interrupt context */ /* No lock since we're already in audio interrupt context */
queue_post(&pcmbuf_queue, id, data); queue_post(&pcmbuf_queue, id, data);
@ -313,7 +313,7 @@ static void pcmbuf_queue_clear(void)
/* --- Helper functions --- */ /* --- Helper functions --- */
static struct mp3entry *bufgetid3(int handle_id) static struct mp3entry *bufgetid3(const int handle_id)
{ {
if (handle_id < 0) if (handle_id < 0)
return NULL; return NULL;
@ -384,7 +384,7 @@ void audio_hard_stop(void)
#endif #endif
} }
bool audio_restore_playback(int type) bool audio_restore_playback(const int type)
{ {
switch (type) switch (type)
{ {
@ -401,7 +401,7 @@ bool audio_restore_playback(int type)
} }
} }
unsigned char *audio_get_buffer(bool talk_buf, size_t *buffer_size) unsigned char *audio_get_buffer(const bool talk_buf, size_t *buffer_size)
{ {
unsigned char *buf, *end; unsigned char *buf, *end;
@ -621,7 +621,7 @@ bool audio_has_changed_track(void)
return false; return false;
} }
void audio_play(long offset) void audio_play(const long offset)
{ {
logf("audio_play"); logf("audio_play");
@ -710,7 +710,7 @@ void audio_pre_ff_rewind(void)
queue_post(&audio_queue, Q_AUDIO_PRE_FF_REWIND, 0); queue_post(&audio_queue, Q_AUDIO_PRE_FF_REWIND, 0);
} }
void audio_ff_rewind(long newpos) void audio_ff_rewind(const long newpos)
{ {
LOGFQUEUE("audio > audio Q_AUDIO_FF_REWIND"); LOGFQUEUE("audio > audio Q_AUDIO_FF_REWIND");
queue_post(&audio_queue, Q_AUDIO_FF_REWIND, newpos); queue_post(&audio_queue, Q_AUDIO_FF_REWIND, newpos);
@ -753,7 +753,7 @@ int audio_get_file_pos(void)
} }
#ifndef HAVE_FLASH_STORAGE #ifndef HAVE_FLASH_STORAGE
void audio_set_buffer_margin(int setting) void audio_set_buffer_margin(const int setting)
{ {
static const int lookup[] = {5, 15, 30, 60, 120, 180, 300, 600}; static const int lookup[] = {5, 15, 30, 60, 120, 180, 300, 600};
buffer_margin = lookup[setting]; buffer_margin = lookup[setting];
@ -762,8 +762,8 @@ void audio_set_buffer_margin(int setting)
} }
#endif #endif
/* Take nescessary steps to enable or disable the crossfade setting */ /* Take necessary steps to enable or disable the crossfade setting */
void audio_set_crossfade(int enable) void audio_set_crossfade(const int enable)
{ {
size_t offset; size_t offset;
bool was_playing; bool was_playing;
@ -805,7 +805,7 @@ void audio_set_crossfade(int enable)
/* --- Routines called from multiple threads --- */ /* --- Routines called from multiple threads --- */
static void set_filebuf_watermark(int seconds, size_t max) static void set_filebuf_watermark(const int seconds, const size_t max)
{ {
size_t bytes; size_t bytes;
@ -817,7 +817,7 @@ static void set_filebuf_watermark(int seconds, size_t max)
buf_set_watermark(bytes); buf_set_watermark(bytes);
} }
const char * get_codec_filename(int cod_spec) const char *get_codec_filename(const int cod_spec)
{ {
const char *fname; const char *fname;
@ -849,13 +849,14 @@ const char * get_codec_filename(int cod_spec)
/* --- Codec thread --- */ /* --- Codec thread --- */
static bool codec_pcmbuf_insert_callback( static bool codec_pcmbuf_insert_callback(
const void *ch1, const void *ch2, int count) const void *ch1, const void *ch2, const int count)
{ {
const char *src[2] = { ch1, ch2 }; const char *src[2] = { ch1, ch2 };
while (count > 0) int remaining = count;
while (remaining > 0)
{ {
int out_count = dsp_output_count(ci.dsp, count); int out_count = dsp_output_count(ci.dsp, remaining);
int inp_count; int inp_count;
char *dest; char *dest;
@ -879,8 +880,8 @@ static bool codec_pcmbuf_insert_callback(
return true; return true;
/* Input size has grown, no error, just don't write more than length */ /* Input size has grown, no error, just don't write more than length */
if (inp_count > count) if (inp_count > remaining)
inp_count = count; inp_count = remaining;
out_count = dsp_process(ci.dsp, dest, src, inp_count); out_count = dsp_process(ci.dsp, dest, src, inp_count);
@ -889,7 +890,7 @@ static bool codec_pcmbuf_insert_callback(
pcmbuf_write_complete(out_count); pcmbuf_write_complete(out_count);
count -= inp_count; remaining -= inp_count;
} }
return true; return true;
@ -905,8 +906,8 @@ static void* codec_get_memory_callback(size_t *size)
"elapsed" value of the previous (to the codec, but current to the "elapsed" value of the previous (to the codec, but current to the
user/PCM/WPS) track, so that the progressbar reaches the end. user/PCM/WPS) track, so that the progressbar reaches the end.
During that transition, the WPS will display prevtrack_id3. */ During that transition, the WPS will display prevtrack_id3. */
static void codec_pcmbuf_position_callback(size_t size) ICODE_ATTR; static void codec_pcmbuf_position_callback(const size_t size) ICODE_ATTR;
static void codec_pcmbuf_position_callback(size_t size) static void codec_pcmbuf_position_callback(const size_t size)
{ {
/* This is called from an ISR, so be quick */ /* This is called from an ISR, so be quick */
unsigned int time = size * 1000 / 4 / NATIVE_FREQUENCY + unsigned int time = size * 1000 / 4 / NATIVE_FREQUENCY +
@ -921,7 +922,7 @@ static void codec_pcmbuf_position_callback(size_t size)
prevtrack_id3.elapsed = time; prevtrack_id3.elapsed = time;
} }
static void codec_set_elapsed_callback(unsigned int value) static void codec_set_elapsed_callback(const unsigned int value)
{ {
unsigned int latency; unsigned int latency;
if (ci.seek_time) if (ci.seek_time)
@ -941,7 +942,7 @@ static void codec_set_elapsed_callback(unsigned int value)
} }
} }
static void codec_set_offset_callback(size_t value) static void codec_set_offset_callback(const size_t value)
{ {
unsigned int latency; unsigned int latency;
@ -955,14 +956,14 @@ static void codec_set_offset_callback(size_t value)
curtrack_id3.offset = value - latency; curtrack_id3.offset = value - latency;
} }
static void codec_advance_buffer_counters(size_t amount) static void codec_advance_buffer_counters(const size_t amount)
{ {
bufadvance(CUR_TI->audio_hid, amount); bufadvance(CUR_TI->audio_hid, amount);
ci.curpos += amount; ci.curpos += amount;
} }
/* copy up-to size bytes into ptr and return the actual size copied */ /* copy up-to size bytes into ptr and return the actual size copied */
static size_t codec_filebuf_callback(void *ptr, size_t size) static size_t codec_filebuf_callback(void *ptr, const size_t size)
{ {
ssize_t copy_n; ssize_t copy_n;
@ -982,7 +983,7 @@ static size_t codec_filebuf_callback(void *ptr, size_t size)
return copy_n; return copy_n;
} /* codec_filebuf_callback */ } /* codec_filebuf_callback */
static void* codec_request_buffer_callback(size_t *realsize, size_t reqsize) static void* codec_request_buffer_callback(size_t *realsize, const size_t reqsize)
{ {
size_t copy_n = reqsize; size_t copy_n = reqsize;
ssize_t ret; ssize_t ret;
@ -1021,7 +1022,7 @@ static int get_codec_base_type(int type)
return type; return type;
} }
static void codec_advance_buffer_callback(size_t amount) static void codec_advance_buffer_callback(const size_t amount)
{ {
codec_advance_buffer_counters(amount); codec_advance_buffer_counters(amount);
codec_set_offset_callback(ci.curpos); codec_set_offset_callback(ci.curpos);
@ -1088,7 +1089,7 @@ static int codec_get_file_pos(void)
return pos; return pos;
} }
static off_t codec_mp3_get_filepos_callback(int newtime) static off_t codec_mp3_get_filepos_callback(const int newtime)
{ {
off_t newpos; off_t newpos;
@ -1114,7 +1115,7 @@ static void codec_seek_complete_callback(void)
ci.seek_time = 0; ci.seek_time = 0;
} }
static bool codec_seek_buffer_callback(size_t newpos) static bool codec_seek_buffer_callback(const size_t newpos)
{ {
logf("codec_seek_buffer_callback"); logf("codec_seek_buffer_callback");
@ -1128,7 +1129,7 @@ static bool codec_seek_buffer_callback(size_t newpos)
} }
} }
static void codec_configure_callback(int setting, intptr_t value) static void codec_configure_callback(const int setting, const intptr_t value)
{ {
switch (setting) { switch (setting) {
case CODEC_SET_FILEBUF_WATERMARK: case CODEC_SET_FILEBUF_WATERMARK:
@ -1178,7 +1179,7 @@ static inline void codec_crossfade_track_change(void)
codec_track_changed(); codec_track_changed();
} }
static void codec_track_skip_done(bool was_manual) static void codec_track_skip_done(const bool was_manual)
{ {
/* Manual track change (always crossfade or flush audio). */ /* Manual track change (always crossfade or flush audio). */
if (was_manual) if (was_manual)
@ -1485,7 +1486,7 @@ static void audio_update_trackinfo(void)
ci.taginfo_ready = &CUR_TI->taginfo_ready; ci.taginfo_ready = &CUR_TI->taginfo_ready;
} }
static void buffering_audio_callback(enum callback_event ev, int value) static void buffering_audio_callback(const enum callback_event ev, const int value)
{ {
(void)value; (void)value;
logf("buffering_audio_callback"); logf("buffering_audio_callback");
@ -1549,7 +1550,7 @@ static bool audio_release_tracks(void)
return true; return true;
} }
static bool audio_loadcodec(bool start_play) static bool audio_loadcodec(const bool start_play)
{ {
int prev_track; int prev_track;
char codec_path[MAX_PATH]; /* Full path to codec */ char codec_path[MAX_PATH]; /* Full path to codec */
@ -1667,7 +1668,7 @@ static void audio_set_elapsed(struct mp3entry* id3)
/* Load one track by making the appropriate bufopen calls. Return true if /* Load one track by making the appropriate bufopen calls. Return true if
everything required was loaded correctly, false if not. */ everything required was loaded correctly, false if not. */
static bool audio_load_track(int offset, bool start_play) static bool audio_load_track(const int offset, const bool start_play)
{ {
const char *trackname; const char *trackname;
char msgbuf[80]; char msgbuf[80];
@ -1714,8 +1715,9 @@ static bool audio_load_track(int offset, bool start_play)
tracks[track_widx].filesize = filesize(fd); tracks[track_widx].filesize = filesize(fd);
if ((unsigned)offset > tracks[track_widx].filesize) int adjusted_offset = offset;
offset = 0; if ((unsigned)adjusted_offset > tracks[track_widx].filesize)
adjusted_offset = 0;
/* Set default values */ /* Set default values */
if (start_play) if (start_play)
@ -1827,17 +1829,17 @@ static bool audio_load_track(int offset, bool start_play)
case AFMT_MPA_L1: case AFMT_MPA_L1:
case AFMT_MPA_L2: case AFMT_MPA_L2:
case AFMT_MPA_L3: case AFMT_MPA_L3:
if (offset > 0) { if (adjusted_offset > 0) {
file_offset = offset; file_offset = adjusted_offset;
track_id3->offset = offset; track_id3->offset = adjusted_offset;
audio_set_elapsed(track_id3); audio_set_elapsed(track_id3);
} }
break; break;
case AFMT_WAVPACK: case AFMT_WAVPACK:
if (offset > 0) { if (offset > 0) {
file_offset = offset; file_offset = adjusted_offset;
track_id3->offset = offset; track_id3->offset = adjusted_offset;
track_id3->elapsed = track_id3->length / 2; track_id3->elapsed = track_id3->length / 2;
} }
break; break;
@ -1850,8 +1852,8 @@ static bool audio_load_track(int offset, bool start_play)
case AFMT_AAC: case AFMT_AAC:
case AFMT_MPC: case AFMT_MPC:
case AFMT_APE: case AFMT_APE:
if (offset > 0) if (adjusted_offset > 0)
track_id3->offset = offset; track_id3->offset = adjusted_offset;
break; break;
case AFMT_NSF: case AFMT_NSF:
@ -1890,7 +1892,7 @@ static bool audio_load_track(int offset, bool start_play)
return true; return true;
} }
static void audio_fill_file_buffer(bool start_play, size_t offset) static void audio_fill_file_buffer(const bool start_play, const size_t offset)
{ {
struct queue_event ev; struct queue_event ev;
bool had_next_track = audio_next_track() != NULL; bool had_next_track = audio_next_track() != NULL;
@ -1914,10 +1916,8 @@ static void audio_fill_file_buffer(bool start_play, size_t offset)
/* Save the current resume position once. */ /* Save the current resume position once. */
playlist_update_resume_info(audio_current_track()); playlist_update_resume_info(audio_current_track());
continue_buffering = audio_load_track(offset, start_play);
do { do {
continue_buffering = audio_load_track(offset, start_play);
start_play = false;
offset = 0;
sleep(1); sleep(1);
if (queue_peek(&audio_queue, &ev)) { if (queue_peek(&audio_queue, &ev)) {
if (ev.id != Q_AUDIO_FILL_BUFFER) if (ev.id != Q_AUDIO_FILL_BUFFER)
@ -1929,6 +1929,7 @@ static void audio_fill_file_buffer(bool start_play, size_t offset)
} }
break; break;
} }
continue_buffering = audio_load_track(0, false);
} while (continue_buffering); } while (continue_buffering);
if (!had_next_track && audio_next_track()) if (!had_next_track && audio_next_track())
@ -2193,7 +2194,7 @@ static void audio_stop_playback(void)
memset(&curtrack_id3, 0, sizeof(struct mp3entry)); memset(&curtrack_id3, 0, sizeof(struct mp3entry));
} }
static void audio_play_start(size_t offset) static void audio_play_start(const size_t offset)
{ {
int i; int i;
@ -2286,7 +2287,7 @@ static void audio_new_playlist(void)
} }
/* Called on manual track skip */ /* Called on manual track skip */
static void audio_initiate_track_change(long direction) static void audio_initiate_track_change(const long direction)
{ {
logf("audio_initiate_track_change(%ld)", direction); logf("audio_initiate_track_change(%ld)", direction);
@ -2298,7 +2299,7 @@ static void audio_initiate_track_change(long direction)
} }
/* Called on manual dir skip */ /* Called on manual dir skip */
static void audio_initiate_dir_change(long direction) static void audio_initiate_dir_change(const long direction)
{ {
playlist_end = false; playlist_end = false;
dir_skip = true; dir_skip = true;

View file

@ -38,14 +38,32 @@
#define MAX_TRACK_MASK (MAX_TRACK-1) #define MAX_TRACK_MASK (MAX_TRACK-1)
/* Functions */ /* Functions */
const char * get_codec_filename(int cod_spec); const char *get_codec_filename(const int cod_spec);
void voice_wait(void); void voice_wait(void);
void audio_wait_for_init(void);
int audio_track_count(void);
long audio_filebufused(void);
void audio_pre_ff_rewind(void);
void audio_set_crossfade(const int type);
void audio_hard_stop(void); /* Stops audio from serving playback */
enum
{
AUDIO_WANT_PLAYBACK = 0,
AUDIO_WANT_VOICE,
};
bool audio_restore_playback(const int type); /* Restores the audio buffer to handle the requested playback */
#ifdef HAVE_ALBUMART
int audio_current_aa_hid(void);
#endif
#if CONFIG_CODEC == SWCODEC /* This #ifdef is better here than gui/gwps.c */ #if CONFIG_CODEC == SWCODEC /* This #ifdef is better here than gui/gwps.c */
extern void audio_next_dir(void); extern void audio_next_dir(void);
extern void audio_prev_dir(void); extern void audio_prev_dir(void);
#else #else
# define audio_next_dir() #define audio_next_dir()
#define audio_prev_dir() #define audio_prev_dir()
#endif #endif

View file

@ -521,13 +521,13 @@ struct plugin_api {
int (*playlist_amount)(void); int (*playlist_amount)(void);
int (*playlist_resume)(void); int (*playlist_resume)(void);
int (*playlist_start)(int start_index, int offset); int (*playlist_start)(int start_index, int offset);
void (*PREFIX(audio_play))(long offset); void (*PREFIX(audio_play))(const long offset);
void (*audio_stop)(void); void (*audio_stop)(void);
void (*audio_pause)(void); void (*audio_pause)(void);
void (*audio_resume)(void); void (*audio_resume)(void);
void (*audio_next)(void); void (*audio_next)(void);
void (*audio_prev)(void); void (*audio_prev)(void);
void (*audio_ff_rewind)(long newtime); void (*audio_ff_rewind)(const long newtime);
struct mp3entry* (*audio_next_track)(void); struct mp3entry* (*audio_next_track)(void);
int (*audio_status)(void); int (*audio_status)(void);
bool (*audio_has_changed_track)(void); bool (*audio_has_changed_track)(void);

View file

@ -197,7 +197,7 @@ static void* get_codec_memory(size_t *size)
} }
/* Null output */ /* Null output */
static bool pcmbuf_insert_null(const void *ch1, const void *ch2, int count) static bool pcmbuf_insert_null(const void *ch1, const void *ch2, const int count)
{ {
/* Always successful - just discard data */ /* Always successful - just discard data */
(void)ch1; (void)ch1;
@ -310,7 +310,7 @@ static bool pcmbuf_insert_wav(const void *ch1, const void *ch2, int count)
/* Set song position in WPS (value in ms). */ /* Set song position in WPS (value in ms). */
static void set_elapsed(unsigned int value) static void set_elapsed(const unsigned int value)
{ {
elapsed = value; elapsed = value;
} }
@ -318,7 +318,7 @@ static void set_elapsed(unsigned int value)
/* Read next <size> amount bytes from file buffer to <ptr>. /* Read next <size> amount bytes from file buffer to <ptr>.
Will return number of bytes read or 0 if end of file. */ Will return number of bytes read or 0 if end of file. */
static size_t read_filebuf(void *ptr, size_t size) static size_t read_filebuf(void *ptr, const size_t size)
{ {
if (ci.curpos > (off_t)track.filesize) if (ci.curpos > (off_t)track.filesize)
{ {
@ -336,7 +336,7 @@ static size_t read_filebuf(void *ptr, size_t size)
<realsize> amount of data. <reqsize> tells the buffer system <realsize> amount of data. <reqsize> tells the buffer system
how much data it should try to allocate. If <realsize> is 0, how much data it should try to allocate. If <realsize> is 0,
end of file is reached. */ end of file is reached. */
static void* request_buffer(size_t *realsize, size_t reqsize) static void* request_buffer(size_t *realsize, const size_t reqsize)
{ {
*realsize = MIN(track.filesize-ci.curpos,reqsize); *realsize = MIN(track.filesize-ci.curpos,reqsize);
@ -345,7 +345,7 @@ static void* request_buffer(size_t *realsize, size_t reqsize)
/* Advance file buffer position by <amount> amount of bytes. */ /* Advance file buffer position by <amount> amount of bytes. */
static void advance_buffer(size_t amount) static void advance_buffer(const size_t amount)
{ {
ci.curpos += amount; ci.curpos += amount;
} }
@ -359,7 +359,7 @@ static void advance_buffer_loc(void *ptr)
/* Seek file buffer to position <newpos> beginning of file. */ /* Seek file buffer to position <newpos> beginning of file. */
static bool seek_buffer(size_t newpos) static bool seek_buffer(const size_t newpos)
{ {
ci.curpos = newpos; ci.curpos = newpos;
return true; return true;
@ -374,7 +374,7 @@ static void seek_complete(void)
/* Calculate mp3 seek position from given time data in ms. */ /* Calculate mp3 seek position from given time data in ms. */
static off_t mp3_get_filepos(int newtime) static off_t mp3_get_filepos(const int newtime)
{ {
/* We don't ask the codec to seek, so no need to implement this. */ /* We don't ask the codec to seek, so no need to implement this. */
(void)newtime; (void)newtime;
@ -399,7 +399,7 @@ static void discard_codec(void)
} }
static void set_offset(size_t value) static void set_offset(const size_t value)
{ {
/* ??? */ /* ??? */
(void)value; (void)value;

View file

@ -81,6 +81,7 @@ struct system_status global_status;
#if CONFIG_CODEC == SWCODEC #if CONFIG_CODEC == SWCODEC
#include "pcmbuf.h" #include "pcmbuf.h"
#include "dsp.h" #include "dsp.h"
#include "playback.h"
#ifdef HAVE_RECORDING #ifdef HAVE_RECORDING
#include "enc_config.h" #include "enc_config.h"
#endif #endif

View file

@ -23,6 +23,7 @@
#include "talk.h" #include "talk.h"
#include "dsp.h" #include "dsp.h"
#include "audio.h" #include "audio.h"
#include "playback.h"
#include "pcmbuf.h" #include "pcmbuf.h"
#include "codecs/libspeex/speex/speex.h" #include "codecs/libspeex/speex/speex.h"

View file

@ -77,49 +77,31 @@ struct audio_debug
}; };
void audio_init(void); void audio_init(void);
void audio_wait_for_init(void); void audio_play(const long offset);
void audio_play(long offset);
void audio_stop(void); void audio_stop(void);
void audio_pause(void); void audio_pause(void);
void audio_resume(void); void audio_resume(void);
void audio_next(void); void audio_next(void);
void audio_prev(void); void audio_prev(void);
int audio_status(void); int audio_status(void);
#if CONFIG_CODEC == SWCODEC void audio_ff_rewind(const long newtime);
int audio_track_count(void); /* SWCODEC only */
long audio_filebufused(void); /* SWCODEC only */
void audio_pre_ff_rewind(void); /* SWCODEC only */
#endif /* CONFIG_CODEC == SWCODEC */
void audio_ff_rewind(long newtime);
void audio_flush_and_reload_tracks(void); void audio_flush_and_reload_tracks(void);
#ifdef HAVE_ALBUMART
int audio_current_aa_hid(void);
#endif
struct mp3entry* audio_current_track(void); struct mp3entry* audio_current_track(void);
struct mp3entry* audio_next_track(void); struct mp3entry* audio_next_track(void);
bool audio_has_changed_track(void); bool audio_has_changed_track(void);
void audio_get_debugdata(struct audio_debug *dbgdata); void audio_get_debugdata(struct audio_debug *dbgdata);
void audio_set_crossfade(int type);
#ifndef HAVE_FLASH_STORAGE #ifndef HAVE_FLASH_STORAGE
void audio_set_buffer_margin(int seconds); void audio_set_buffer_margin(const int seconds);
#endif #endif
unsigned int audio_error(void); unsigned int audio_error(void);
void audio_error_clear(void); void audio_error_clear(void);
int audio_get_file_pos(void); int audio_get_file_pos(void);
void audio_beep(int duration); void audio_beep(int duration);
void audio_init_playback(void); void audio_init_playback(void);
/* Required call when audio buffer is require for some other purpose */
unsigned char *audio_get_buffer(bool talk_buf, size_t *buffer_size);
/* Stops audio from serving playback */
void audio_hard_stop(void);
/* Retores the audio buffer to handle the requested playback */
enum
{
AUDIO_WANT_PLAYBACK = 0,
AUDIO_WANT_VOICE,
};
bool audio_restore_playback(int type); /* Required call when audio buffer is required for some other purpose */
unsigned char *audio_get_buffer(const bool talk_buf, size_t *buffer_size);
/* only implemented in playback.c, but called from firmware */
/* channel modes */ /* channel modes */
enum rec_channel_modes enum rec_channel_modes

View file

@ -533,7 +533,7 @@ static void recalculate_watermark(int bitrate)
} }
#ifndef HAVE_FLASH_STORAGE #ifndef HAVE_FLASH_STORAGE
void audio_set_buffer_margin(int seconds) void audio_set_buffer_margin(const int seconds)
{ {
low_watermark_margin = seconds; low_watermark_margin = seconds;
} }
@ -2627,7 +2627,7 @@ void audio_set_recording_options(struct audio_recording_options *options)
#endif /* SIMULATOR */ #endif /* SIMULATOR */
#endif /* CONFIG_CODEC == MAS3587F */ #endif /* CONFIG_CODEC == MAS3587F */
void audio_play(long offset) void audio_play(const long offset)
{ {
#ifdef SIMULATOR #ifdef SIMULATOR
char* trackname; char* trackname;
@ -2768,7 +2768,7 @@ void audio_prev(void)
#endif /* SIMULATOR */ #endif /* SIMULATOR */
} }
void audio_ff_rewind(long newtime) void audio_ff_rewind(const long newtime)
{ {
#ifndef SIMULATOR #ifndef SIMULATOR
queue_post(&mpeg_queue, MPEG_FF_REWIND, newtime); queue_post(&mpeg_queue, MPEG_FF_REWIND, newtime);

View file

@ -33,7 +33,7 @@
extern char having_new_lcd; extern char having_new_lcd;
#if CONFIG_CODEC != SWCODEC #if CONFIG_CODEC != SWCODEC
void audio_set_buffer_margin(int seconds) void audio_set_buffer_margin(const int seconds)
{ {
(void)seconds; (void)seconds;
} }