From c9df8fd87ba80a3c0d719e76ca68cb829a505b11 Mon Sep 17 00:00:00 2001 From: Steve Bavin Date: Fri, 28 Mar 2008 11:24:24 +0000 Subject: 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 --- apps/buffering.c | 63 +++++++++++++++-------------- apps/codecs.h | 20 +++++----- apps/debug_menu.c | 1 + apps/gui/gwps-common.c | 3 ++ apps/menus/playback_menu.c | 6 ++- apps/menus/settings_menu.c | 5 ++- apps/pcmbuf.c | 6 +-- apps/pcmbuf.h | 2 +- apps/playback.c | 99 +++++++++++++++++++++++----------------------- apps/playback.h | 22 ++++++++++- apps/plugin.h | 4 +- apps/plugins/test_codec.c | 16 ++++---- apps/settings.c | 1 + apps/voice_thread.c | 3 +- firmware/export/audio.h | 30 +++----------- firmware/mpeg.c | 6 +-- uisimulator/common/stubs.c | 2 +- 17 files changed, 154 insertions(+), 135 deletions(-) diff --git a/apps/buffering.c b/apps/buffering.c index d49669777b..d891382d81 100644 --- a/apps/buffering.c +++ b/apps/buffering.c @@ -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 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) { /* 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 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); if (fd < 0) 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); bool can_wrap = type==TYPE_PACKET_AUDIO || type==TYPE_CODEC; - if (offset > size) - offset = 0; + if (adjusted_offset > size) + 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) { 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); - h->offset = offset; + h->offset = adjusted_offset; h->ridx = buf_widx; h->data = buf_widx; h->type = type; @@ -923,7 +925,7 @@ int bufopen(const char *file, size_t offset, const enum data_type type) else #endif { - h->filerem = size - offset; + h->filerem = size - adjusted_offset; h->filesize = size; h->available = 0; 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). 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) 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 */ size_t read = buffer_len - h->ridx; memcpy(dest, &buffer[h->ridx], read); - memcpy(dest+read, buffer, size - read); + memcpy(dest+read, buffer, adjusted_size - read); } 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. @@ -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 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; + size_t adjusted_size = size; - h = prep_bufdata(handle_id, &size, true); + h = prep_bufdata(handle_id, &adjusted_size, true); if (!h) 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 : use the guard buffer to provide the requested amount of data. */ - size_t copy_n = h->ridx + size - buffer_len; - /* prep_bufdata ensures size <= buffer_len - h->ridx + GUARD_BUFSIZE, + size_t copy_n = h->ridx + adjusted_size - buffer_len; + /* prep_bufdata ensures adjusted_size <= buffer_len - h->ridx + GUARD_BUFSIZE, so copy_n <= GUARD_BUFSIZE */ 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) *data = &buffer[h->ridx]; - return size; + return adjusted_size; } 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; } -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); @@ -1192,16 +1197,16 @@ ssize_t bufcuttail(const int handle_id, size_t size) if (h->filerem) return ERR_HANDLE_NOT_DONE; - if (h->available < size) - size = h->available; + if (h->available < adjusted_size) + adjusted_size = h->available; - h->available -= size; - h->filesize -= size; - h->widx = RINGBUF_SUB(h->widx, size); + h->available -= adjusted_size; + h->filesize -= adjusted_size; + h->widx = RINGBUF_SUB(h->widx, adjusted_size); if (h == cur_handle) buf_widx = h->widx; - return size; + return adjusted_size; } diff --git a/apps/codecs.h b/apps/codecs.h index fb5675fd84..85b73a4953 100644 --- a/apps/codecs.h +++ b/apps/codecs.h @@ -126,28 +126,28 @@ struct codec_api { void* (*get_codec_memory)(size_t *size); /* Insert PCM data into audio buffer for playback. Playback will start 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). */ - void (*set_elapsed)(unsigned int value); + void (*set_elapsed)(const unsigned int value); /* Read next amount bytes from file buffer to . 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 amount of data. tells the buffer system how much data it should try to allocate. If is 0, 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 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. */ void (*advance_buffer_loc)(void *ptr); /* Seek file buffer to position 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. */ void (*seek_complete)(void); /* 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 track is available and changed. If return value is false, 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 */ void (*discard_codec)(void); - void (*set_offset)(size_t value); + void (*set_offset)(const size_t value); /* Configure different codec buffer parameters. */ - void (*configure)(int setting, intptr_t value); + void (*configure)(const int setting, const intptr_t value); /* kernel/ system */ - void (*PREFIX(sleep))(int ticks); + void (*PREFIX(sleep))(const int ticks); void (*yield)(void); #if NUM_CORES > 1 diff --git a/apps/debug_menu.c b/apps/debug_menu.c index d21dc032a8..5c8a7f965f 100644 --- a/apps/debug_menu.c +++ b/apps/debug_menu.c @@ -77,6 +77,7 @@ #if CONFIG_CODEC == SWCODEC #include "pcmbuf.h" #include "buffering.h" +#include "playback.h" #if defined(HAVE_SPDIF_OUT) || defined(HAVE_SPDIF_IN) #include "spdif.h" #endif diff --git a/apps/gui/gwps-common.c b/apps/gui/gwps-common.c index a6bb917a5a..234cd62a64 100644 --- a/apps/gui/gwps-common.c +++ b/apps/gui/gwps-common.c @@ -54,6 +54,9 @@ #include "action.h" #include "cuesheet.h" #include "playlist.h" +#if CONFIG_CODEC == SWCODEC +#include "playback.h" +#endif #if (LCD_DEPTH > 1) || (defined(HAVE_LCD_REMOTE) && (LCD_REMOTE_DEPTH > 1)) #include "backdrop.h" diff --git a/apps/menus/playback_menu.c b/apps/menus/playback_menu.c index b7aa1ae47f..1e07ef3781 100644 --- a/apps/menus/playback_menu.c +++ b/apps/menus/playback_menu.c @@ -33,7 +33,11 @@ #include "dsp.h" #include "scrobbler.h" #include "audio.h" -#include "cuesheet.h" +#include "cuesheet.h" +#if CONFIG_CODEC == SWCODEC +#include "playback.h" +#endif + #if CONFIG_CODEC == SWCODEC int setcrossfadeonexit_callback(int action,const struct menu_item_ex *this_item) diff --git a/apps/menus/settings_menu.c b/apps/menus/settings_menu.c index c55695333c..9d816c99b1 100644 --- a/apps/menus/settings_menu.c +++ b/apps/menus/settings_menu.c @@ -34,7 +34,10 @@ #include "splash.h" #include "talk.h" #include "sprintf.h" -#include "powermgmt.h" +#include "powermgmt.h" +#if CONFIG_CODEC == SWCODEC +#include "playback.h" +#endif #ifdef HAVE_RTC_ALARM #include "alarm_menu.h" #endif diff --git a/apps/pcmbuf.c b/apps/pcmbuf.c index 8f16c90523..b9587d08dd 100644 --- a/apps/pcmbuf.c +++ b/apps/pcmbuf.c @@ -82,7 +82,7 @@ static char *fadebuf IDATA_ATTR; static char *voicebuf 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 */ 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; } @@ -938,7 +938,7 @@ void pcmbuf_write_complete(int count) } #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; diff --git a/apps/pcmbuf.h b/apps/pcmbuf.h index 06362452c0..9263285a6b 100644 --- a/apps/pcmbuf.h +++ b/apps/pcmbuf.h @@ -63,7 +63,7 @@ bool pcmbuf_is_lowdata(void); void pcmbuf_play_start(void); bool pcmbuf_crossfade_init(bool manual_skip); 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); unsigned int pcmbuf_get_latency(void); void pcmbuf_set_low_latency(bool state); diff --git a/apps/playback.c b/apps/playback.c index 421783e0f7..4fd27ce72e 100644 --- a/apps/playback.c +++ b/apps/playback.c @@ -249,7 +249,7 @@ static size_t buffer_margin = 0; /* Buffer margin aka anti-skip buffer (A/C-) * /* Multiple threads */ /* 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 */ 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. * 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 */ queue_post(&pcmbuf_queue, id, data); @@ -313,7 +313,7 @@ static void pcmbuf_queue_clear(void) /* --- Helper functions --- */ -static struct mp3entry *bufgetid3(int handle_id) +static struct mp3entry *bufgetid3(const int handle_id) { if (handle_id < 0) return NULL; @@ -384,7 +384,7 @@ void audio_hard_stop(void) #endif } -bool audio_restore_playback(int type) +bool audio_restore_playback(const int 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; @@ -621,7 +621,7 @@ bool audio_has_changed_track(void) return false; } -void audio_play(long offset) +void audio_play(const long offset) { logf("audio_play"); @@ -710,7 +710,7 @@ void audio_pre_ff_rewind(void) 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"); queue_post(&audio_queue, Q_AUDIO_FF_REWIND, newpos); @@ -753,7 +753,7 @@ int audio_get_file_pos(void) } #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}; buffer_margin = lookup[setting]; @@ -762,8 +762,8 @@ void audio_set_buffer_margin(int setting) } #endif -/* Take nescessary steps to enable or disable the crossfade setting */ -void audio_set_crossfade(int enable) +/* Take necessary steps to enable or disable the crossfade setting */ +void audio_set_crossfade(const int enable) { size_t offset; bool was_playing; @@ -805,7 +805,7 @@ void audio_set_crossfade(int enable) /* --- 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; @@ -817,7 +817,7 @@ static void set_filebuf_watermark(int seconds, size_t max) buf_set_watermark(bytes); } -const char * get_codec_filename(int cod_spec) +const char *get_codec_filename(const int cod_spec) { const char *fname; @@ -849,13 +849,14 @@ const char * get_codec_filename(int cod_spec) /* --- Codec thread --- */ 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 }; - 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; char *dest; @@ -879,8 +880,8 @@ static bool codec_pcmbuf_insert_callback( return true; /* Input size has grown, no error, just don't write more than length */ - if (inp_count > count) - inp_count = count; + if (inp_count > remaining) + inp_count = remaining; 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); - count -= inp_count; + remaining -= inp_count; } 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 user/PCM/WPS) track, so that the progressbar reaches the end. 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(size_t size) +static void codec_pcmbuf_position_callback(const size_t size) ICODE_ATTR; +static void codec_pcmbuf_position_callback(const size_t size) { /* This is called from an ISR, so be quick */ 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; } -static void codec_set_elapsed_callback(unsigned int value) +static void codec_set_elapsed_callback(const unsigned int value) { unsigned int latency; 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; @@ -955,14 +956,14 @@ static void codec_set_offset_callback(size_t value) 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); ci.curpos += amount; } /* 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; @@ -982,7 +983,7 @@ static size_t codec_filebuf_callback(void *ptr, size_t size) return copy_n; } /* 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; ssize_t ret; @@ -1021,7 +1022,7 @@ static int get_codec_base_type(int 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_set_offset_callback(ci.curpos); @@ -1088,7 +1089,7 @@ static int codec_get_file_pos(void) 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; @@ -1114,7 +1115,7 @@ static void codec_seek_complete_callback(void) 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"); @@ -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) { case CODEC_SET_FILEBUF_WATERMARK: @@ -1178,7 +1179,7 @@ static inline void codec_crossfade_track_change(void) 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). */ if (was_manual) @@ -1485,7 +1486,7 @@ static void audio_update_trackinfo(void) 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; logf("buffering_audio_callback"); @@ -1549,7 +1550,7 @@ static bool audio_release_tracks(void) return true; } -static bool audio_loadcodec(bool start_play) +static bool audio_loadcodec(const bool start_play) { int prev_track; 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 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; char msgbuf[80]; @@ -1714,8 +1715,9 @@ static bool audio_load_track(int offset, bool start_play) tracks[track_widx].filesize = filesize(fd); - if ((unsigned)offset > tracks[track_widx].filesize) - offset = 0; + int adjusted_offset = offset; + if ((unsigned)adjusted_offset > tracks[track_widx].filesize) + adjusted_offset = 0; /* Set default values */ if (start_play) @@ -1827,17 +1829,17 @@ static bool audio_load_track(int offset, bool start_play) case AFMT_MPA_L1: case AFMT_MPA_L2: case AFMT_MPA_L3: - if (offset > 0) { - file_offset = offset; - track_id3->offset = offset; + if (adjusted_offset > 0) { + file_offset = adjusted_offset; + track_id3->offset = adjusted_offset; audio_set_elapsed(track_id3); } break; case AFMT_WAVPACK: if (offset > 0) { - file_offset = offset; - track_id3->offset = offset; + file_offset = adjusted_offset; + track_id3->offset = adjusted_offset; track_id3->elapsed = track_id3->length / 2; } break; @@ -1850,8 +1852,8 @@ static bool audio_load_track(int offset, bool start_play) case AFMT_AAC: case AFMT_MPC: case AFMT_APE: - if (offset > 0) - track_id3->offset = offset; + if (adjusted_offset > 0) + track_id3->offset = adjusted_offset; break; case AFMT_NSF: @@ -1890,7 +1892,7 @@ static bool audio_load_track(int offset, bool start_play) 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; 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. */ playlist_update_resume_info(audio_current_track()); + continue_buffering = audio_load_track(offset, start_play); do { - continue_buffering = audio_load_track(offset, start_play); - start_play = false; - offset = 0; sleep(1); if (queue_peek(&audio_queue, &ev)) { if (ev.id != Q_AUDIO_FILL_BUFFER) @@ -1929,6 +1929,7 @@ static void audio_fill_file_buffer(bool start_play, size_t offset) } break; } + continue_buffering = audio_load_track(0, false); } while (continue_buffering); if (!had_next_track && audio_next_track()) @@ -2193,7 +2194,7 @@ static void audio_stop_playback(void) 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; @@ -2286,7 +2287,7 @@ static void audio_new_playlist(void) } /* 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); @@ -2298,7 +2299,7 @@ static void audio_initiate_track_change(long direction) } /* 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; dir_skip = true; diff --git a/apps/playback.h b/apps/playback.h index 748a4fe871..b65c572145 100644 --- a/apps/playback.h +++ b/apps/playback.h @@ -38,14 +38,32 @@ #define MAX_TRACK_MASK (MAX_TRACK-1) /* Functions */ -const char * get_codec_filename(int cod_spec); +const char *get_codec_filename(const int cod_spec); 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 */ extern void audio_next_dir(void); extern void audio_prev_dir(void); #else -# define audio_next_dir() +#define audio_next_dir() #define audio_prev_dir() #endif diff --git a/apps/plugin.h b/apps/plugin.h index 27fcffb69c..d6aed5d4c7 100644 --- a/apps/plugin.h +++ b/apps/plugin.h @@ -521,13 +521,13 @@ struct plugin_api { int (*playlist_amount)(void); int (*playlist_resume)(void); 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_pause)(void); void (*audio_resume)(void); void (*audio_next)(void); void (*audio_prev)(void); - void (*audio_ff_rewind)(long newtime); + void (*audio_ff_rewind)(const long newtime); struct mp3entry* (*audio_next_track)(void); int (*audio_status)(void); bool (*audio_has_changed_track)(void); diff --git a/apps/plugins/test_codec.c b/apps/plugins/test_codec.c index f33d83fb15..7390318152 100644 --- a/apps/plugins/test_codec.c +++ b/apps/plugins/test_codec.c @@ -197,7 +197,7 @@ static void* get_codec_memory(size_t *size) } /* 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 */ (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). */ -static void set_elapsed(unsigned int value) +static void set_elapsed(const unsigned int value) { elapsed = value; } @@ -318,7 +318,7 @@ static void set_elapsed(unsigned int value) /* Read next amount bytes from file buffer to . 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) { @@ -336,7 +336,7 @@ static size_t read_filebuf(void *ptr, size_t size) amount of data. tells the buffer system how much data it should try to allocate. If is 0, 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); @@ -345,7 +345,7 @@ static void* request_buffer(size_t *realsize, size_t reqsize) /* Advance file buffer position by amount of bytes. */ -static void advance_buffer(size_t amount) +static void advance_buffer(const size_t amount) { ci.curpos += amount; } @@ -359,7 +359,7 @@ static void advance_buffer_loc(void *ptr) /* Seek file buffer to position beginning of file. */ -static bool seek_buffer(size_t newpos) +static bool seek_buffer(const size_t newpos) { ci.curpos = newpos; return true; @@ -374,7 +374,7 @@ static void seek_complete(void) /* 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. */ (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; diff --git a/apps/settings.c b/apps/settings.c index d4f14079b1..6e1aa3eaec 100644 --- a/apps/settings.c +++ b/apps/settings.c @@ -81,6 +81,7 @@ struct system_status global_status; #if CONFIG_CODEC == SWCODEC #include "pcmbuf.h" #include "dsp.h" +#include "playback.h" #ifdef HAVE_RECORDING #include "enc_config.h" #endif diff --git a/apps/voice_thread.c b/apps/voice_thread.c index 6e70f43cc5..98b9cafc83 100644 --- a/apps/voice_thread.c +++ b/apps/voice_thread.c @@ -22,7 +22,8 @@ #include "voice_thread.h" #include "talk.h" #include "dsp.h" -#include "audio.h" +#include "audio.h" +#include "playback.h" #include "pcmbuf.h" #include "codecs/libspeex/speex/speex.h" diff --git a/firmware/export/audio.h b/firmware/export/audio.h index c39fca428c..49ff4c168a 100644 --- a/firmware/export/audio.h +++ b/firmware/export/audio.h @@ -77,49 +77,31 @@ struct audio_debug }; void audio_init(void); -void audio_wait_for_init(void); -void audio_play(long offset); +void audio_play(const long offset); void audio_stop(void); void audio_pause(void); void audio_resume(void); void audio_next(void); void audio_prev(void); int audio_status(void); -#if CONFIG_CODEC == SWCODEC -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_ff_rewind(const long newtime); 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_next_track(void); bool audio_has_changed_track(void); void audio_get_debugdata(struct audio_debug *dbgdata); -void audio_set_crossfade(int type); #ifndef HAVE_FLASH_STORAGE -void audio_set_buffer_margin(int seconds); +void audio_set_buffer_margin(const int seconds); #endif unsigned int audio_error(void); void audio_error_clear(void); int audio_get_file_pos(void); void audio_beep(int duration); 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 */ enum rec_channel_modes diff --git a/firmware/mpeg.c b/firmware/mpeg.c index 11cbcdcb68..78824cfe36 100644 --- a/firmware/mpeg.c +++ b/firmware/mpeg.c @@ -533,7 +533,7 @@ static void recalculate_watermark(int bitrate) } #ifndef HAVE_FLASH_STORAGE -void audio_set_buffer_margin(int seconds) +void audio_set_buffer_margin(const int seconds) { low_watermark_margin = seconds; } @@ -2627,7 +2627,7 @@ void audio_set_recording_options(struct audio_recording_options *options) #endif /* SIMULATOR */ #endif /* CONFIG_CODEC == MAS3587F */ -void audio_play(long offset) +void audio_play(const long offset) { #ifdef SIMULATOR char* trackname; @@ -2768,7 +2768,7 @@ void audio_prev(void) #endif /* SIMULATOR */ } -void audio_ff_rewind(long newtime) +void audio_ff_rewind(const long newtime) { #ifndef SIMULATOR queue_post(&mpeg_queue, MPEG_FF_REWIND, newtime); diff --git a/uisimulator/common/stubs.c b/uisimulator/common/stubs.c index c40d10082c..81f3697802 100644 --- a/uisimulator/common/stubs.c +++ b/uisimulator/common/stubs.c @@ -33,7 +33,7 @@ extern char having_new_lcd; #if CONFIG_CODEC != SWCODEC -void audio_set_buffer_margin(int seconds) +void audio_set_buffer_margin(const int seconds) { (void)seconds; } -- cgit v1.2.3