apps: cleanly disable codec buffering when not supported

rockbox-gerrit-noreply--- via rockbox-cvs <[email protected]>
Newsgroups gmane.comp.systems.archos.rockbox.cvs
Message-ID <[email protected]>
commit 3d281c2ea390db8b85549a11a09dffdc183a2ac8
Author: Aidan MacDonald <[email protected]>
Date:   Sun Jan 4 14:08:34 2026 +0000

    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

diff --git a/apps/codec_thread.c b/apps/codec_thread.c
index 40c064e86b..f3c95abdd3 100644
--- a/apps/codec_thread.c
+++ b/apps/codec_thread.c
@@ -474,12 +474,14 @@ static void load_codec(const struct codec_load_info *ev_data)
         dsp_configure(ci.dsp, DSP_RESET, 0);
     }
 
+#if defined(HAVE_CODEC_BUFFERING)
     if (data.hid >= 0)
     {
         /* First try buffer load */
         status = codec_load_buf(data.hid, &ci);
         bufclose(data.hid);
     }
+#endif /* HAVE_CODEC_BUFFERING */
 
     if (status < 0)
     {
diff --git a/apps/codecs.c b/apps/codecs.c
index 575497b16c..e943191563 100644
--- a/apps/codecs.c
+++ b/apps/codecs.c
@@ -225,6 +225,7 @@ static int codec_load_ram(struct codec_api *api)
     return c_hdr->entry_point(CODEC_LOAD);
 }
 
+#if defined(HAVE_CODEC_BUFFERING)
 int codec_load_buf(int hid, struct codec_api *api)
 {
     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);
 }
+#endif /* HAVE_CODEC_BUFFERING */
 
 int codec_load_file(const char *plugin, struct codec_api *api)
 {
diff --git a/apps/playback.c b/apps/playback.c
index f8971cca8c..22c19c4755 100644
--- a/apps/playback.c
+++ b/apps/playback.c
@@ -78,11 +78,6 @@
 /* Internal support for voice playback */
 #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
  * for their correct seek target, 32k seems a good size */
 #define AUDIO_REBUFFER_GUESS_SIZE    (1024*32)
@@ -494,14 +489,6 @@ static void id3_write_locked(enum audio_id3_types id3_num,
 
 /** --- 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 */
 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
                format transistion that is the same format as the current track
                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);
 #endif /* HAVE_CODEC_BUFFERING */
             return true;
diff --git a/firmware/export/config.h b/firmware/export/config.h
index fd5527932a..65bf9c164f 100644
--- a/firmware/export/config.h
+++ b/firmware/export/config.h
@@ -689,6 +689,11 @@ Lyre prototype 1 */
 # 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 */
 #include "config_caps.h"
 
diff --git a/lib/rbcodec/codecs/codecs.h b/lib/rbcodec/codecs/codecs.h
index 7c3a301335..5e977c6f13 100644
--- a/lib/rbcodec/codecs/codecs.h
+++ b/lib/rbcodec/codecs/codecs.h
@@ -282,7 +282,9 @@ void codec_get_full_path(char *path, const char *codec_root_fn);
 void *codec_get_buffer_callback(size_t *size);
 
 /* defined by the codec loader (codec.c) */
+#if defined(HAVE_CODEC_BUFFERING)
 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_run_proc(void);
 int codec_close(void);
-- 
rockbox-cvs mailing list
[email protected]
https://lists.haxx.se/mailman/listinfo/rockbox-cvs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.