apps: cleanly disable codec buffering when not supported

Move HAVE_CODEC_BUFFERING to config.h, and disable all
related code on targets that don't support the feature,
ie. hosted targets that can't implement lc_open_from_mem().

Change-Id: I0d2a43900cd05b1a80c3cee519f8ad7b26e39fe7
This commit is contained in:
Aidan MacDonald 2026-01-04 14:08:34 +00:00 committed by Solomon Peachy
parent 3d0888875e
commit 3d281c2ea3
5 changed files with 13 additions and 14 deletions

View file

@ -474,12 +474,14 @@ static void load_codec(const struct codec_load_info *ev_data)
dsp_configure(ci.dsp, DSP_RESET, 0); dsp_configure(ci.dsp, DSP_RESET, 0);
} }
#if defined(HAVE_CODEC_BUFFERING)
if (data.hid >= 0) if (data.hid >= 0)
{ {
/* First try buffer load */ /* First try buffer load */
status = codec_load_buf(data.hid, &ci); status = codec_load_buf(data.hid, &ci);
bufclose(data.hid); bufclose(data.hid);
} }
#endif /* HAVE_CODEC_BUFFERING */
if (status < 0) if (status < 0)
{ {

View file

@ -225,6 +225,7 @@ static int codec_load_ram(struct codec_api *api)
return c_hdr->entry_point(CODEC_LOAD); return c_hdr->entry_point(CODEC_LOAD);
} }
#if defined(HAVE_CODEC_BUFFERING)
int codec_load_buf(int hid, struct codec_api *api) int codec_load_buf(int hid, struct codec_api *api)
{ {
int rc = bufread(hid, CODEC_SIZE, codecbuf); int rc = bufread(hid, CODEC_SIZE, codecbuf);
@ -243,6 +244,7 @@ int codec_load_buf(int hid, struct codec_api *api)
return codec_load_ram(api); return codec_load_ram(api);
} }
#endif /* HAVE_CODEC_BUFFERING */
int codec_load_file(const char *plugin, struct codec_api *api) int codec_load_file(const char *plugin, struct codec_api *api)
{ {

View file

@ -78,11 +78,6 @@
/* Internal support for voice playback */ /* Internal support for voice playback */
#define PLAYBACK_VOICE #define PLAYBACK_VOICE
#if CONFIG_PLATFORM & PLATFORM_NATIVE
/* Application builds don't support direct code loading */
#define HAVE_CODEC_BUFFERING
#endif
/* Amount of guess-space to allow for codecs that must hunt and peck /* Amount of guess-space to allow for codecs that must hunt and peck
* for their correct seek target, 32k seems a good size */ * for their correct seek target, 32k seems a good size */
#define AUDIO_REBUFFER_GUESS_SIZE (1024*32) #define AUDIO_REBUFFER_GUESS_SIZE (1024*32)
@ -494,14 +489,6 @@ static void id3_write_locked(enum audio_id3_types id3_num,
/** --- Track info --- **/ /** --- Track info --- **/
#ifdef HAVE_CODEC_BUFFERING
static void track_info_close_handle(int *hidp)
{
bufclose(*hidp);
*hidp = ERR_HANDLE_NOT_FOUND;
}
#endif /* HAVE_CODEC_BUFFERING */
/* Invalidate all members to initial values - does not close handles or sync */ /* Invalidate all members to initial values - does not close handles or sync */
static void track_info_wipe(struct track_info *infop) static void track_info_wipe(struct track_info *infop)
{ {
@ -1669,7 +1656,8 @@ static bool audio_init_codec(struct track_info *track_infop,
/* Close any buffered codec (we could have skipped directly to a /* Close any buffered codec (we could have skipped directly to a
format transistion that is the same format as the current track format transistion that is the same format as the current track
and the buffered one is no longer needed) */ and the buffered one is no longer needed) */
track_info_close_handle(&track_infop->codec_hid); bufclose(track_infop->codec_hid);
track_infop->codec_hid = ERR_HANDLE_NOT_FOUND;
track_info_sync(track_infop); track_info_sync(track_infop);
#endif /* HAVE_CODEC_BUFFERING */ #endif /* HAVE_CODEC_BUFFERING */
return true; return true;

View file

@ -689,6 +689,11 @@ Lyre prototype 1 */
# endif # endif
#endif #endif
/* Codec buffering requires the ability to load code from RAM */
#if CONFIG_PLATFORM & PLATFORM_NATIVE
# define HAVE_CODEC_BUFFERING
#endif
/* setup basic macros from capability masks */ /* setup basic macros from capability masks */
#include "config_caps.h" #include "config_caps.h"

View file

@ -282,7 +282,9 @@ void codec_get_full_path(char *path, const char *codec_root_fn);
void *codec_get_buffer_callback(size_t *size); void *codec_get_buffer_callback(size_t *size);
/* defined by the codec loader (codec.c) */ /* defined by the codec loader (codec.c) */
#if defined(HAVE_CODEC_BUFFERING)
int codec_load_buf(int hid, struct codec_api *api); int codec_load_buf(int hid, struct codec_api *api);
#endif /* HAVE_CODEC_BUFFERING */
int codec_load_file(const char* codec, struct codec_api *api); int codec_load_file(const char* codec, struct codec_api *api);
int codec_run_proc(void); int codec_run_proc(void);
int codec_close(void); int codec_close(void);