pcm: Make pcm_is_ready a per-sink property instead of a global.

rockbox-gerrit-noreply--- via rockbox-cvs <[email protected]>
Newsgroups gmane.comp.systems.archos.rockbox.cvs
Message-ID <[email protected]>
commit 759ef2767ab4dd1a48ddf6d833508a9fe88bd887
Author: Solomon Peachy <[email protected]>
Date:   Wed Mar 25 08:48:55 2026 -0400

    pcm:  Make pcm_is_ready a per-sink property instead of a global.
    
    All that matters is that the _current_ sink is ready, not all possible
    sinks.  When switching sinks we will need to ensure tehy are initialized
    before switching over.
    
    Change-Id: I341f7e9dcb4e2add4d0b292b68b69eb08dec0194

diff --git a/firmware/export/pcm_sink.h b/firmware/export/pcm_sink.h
index 27c0c31db1..77c64428f6 100644
--- a/firmware/export/pcm_sink.h
+++ b/firmware/export/pcm_sink.h
@@ -47,6 +47,7 @@ struct pcm_sink {
     /* runtime states */
     unsigned long pending_freq;
     unsigned long configured_freq;
+    unsigned long pcm_is_ready;
 };
 
 enum pcm_sink_ids {
diff --git a/firmware/pcm.c b/firmware/pcm.c
index 08383ace2d..766ec0491d 100644
--- a/firmware/pcm.c
+++ b/firmware/pcm.c
@@ -76,9 +76,6 @@
  *
  */
 
-/* 'true' when all stages of pcm initialization have completed */
-static bool pcm_is_ready = false;
-
 static struct pcm_sink* sinks[1] = {
     [PCM_SINK_BUILTIN] = &builtin_pcm_sink,
 };
@@ -142,7 +139,7 @@ void pcm_play_stop_int(void)
 
 static void pcm_wait_for_init(void)
 {
-    while (!pcm_is_ready)
+    while (!sinks[cur_sink]->pcm_is_ready)
         sleep(0);
 }
 
@@ -251,9 +248,11 @@ void pcm_init(void)
     logf("pcm_init");
 
     for(size_t i = 0; i < ARRAYLEN(sinks); i += 1) {
-        sinks[i]->pending_freq = sinks[i]->caps.default_freq;
-        sinks[i]->configured_freq = -1UL;
-        sinks[i]->ops.init();
+        struct pcm_sink* sink = sinks[i];
+        sink->pending_freq = sink->caps.default_freq;
+        sink->configured_freq = -1UL;
+        sink->pcm_is_ready = false;
+        sink->ops.init();
     }
 }
 
@@ -263,15 +262,15 @@ void pcm_postinit(void)
     logf("pcm_postinit");
 
     for(size_t i = 0; i < ARRAYLEN(sinks); i += 1) {
-        sinks[i]->ops.postinit();
+        struct pcm_sink* sink = sinks[i];
+        sink->ops.postinit();
+        sink->pcm_is_ready = true;
     }
-
-    pcm_is_ready = true;
 }
 
 bool pcm_is_initialized(void)
 {
-    return pcm_is_ready;
+    return sinks[cur_sink]->pcm_is_ready;
 }
 
 enum pcm_sink_ids pcm_current_sink(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.