From 4db3e8965270dfe813a14c5ee9bcd0b645eb2edf Mon Sep 17 00:00:00 2001 From: Michael Sevakis Date: Thu, 1 Sep 2011 12:15:43 +0000 Subject: [PATCH] Shuffle some functions around so that interfacing with playback.c in particular isn't required. Though playback does finish the audio init, pcm doesn't care who does it. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30403 a1c6a512-1295-4272-9138-f99709370657 --- apps/playback.c | 13 ++------ apps/playback.h | 1 - apps/radio/radio.c | 2 +- apps/recorder/recording.c | 2 +- firmware/export/pcm-internal.h | 1 + firmware/export/pcm.h | 1 + firmware/pcm.c | 31 +++++++++++++++++++ firmware/target/arm/as3525/pcm-as3525.c | 2 +- .../arm/imx31/gigabeat-s/pcm-gigabeat-s.c | 2 +- firmware/target/arm/pcm-pp.c | 2 +- firmware/target/arm/pcm-telechips.c | 10 +++--- firmware/target/arm/pnx0101/pcm-pnx0101.c | 2 +- .../arm/s3c2440/gigabeat-fx/pcm-meg-fx.c | 2 +- .../arm/s3c2440/mini2440/pcm-mini2440.c | 2 +- firmware/target/arm/s5l8700/pcm-s5l8700.c | 2 +- firmware/target/arm/s5l8702/pcm-s5l8702.c | 2 +- .../creative-zvm/pcm-creativezvm.c | 2 +- .../arm/tms320dm320/mrobe-500/pcm-mr500.c | 2 +- firmware/target/coldfire/pcm-coldfire.c | 2 +- firmware/target/hosted/android/pcm-android.c | 2 +- firmware/target/hosted/maemo/pcm-gstreamer.c | 2 +- firmware/target/hosted/sdl/pcm-sdl.c | 2 +- .../target/mips/ingenic_jz47xx/pcm-jz4740.c | 2 +- 23 files changed, 57 insertions(+), 34 deletions(-) diff --git a/apps/playback.c b/apps/playback.c index 9fd25b975d..dbe28dd1c4 100644 --- a/apps/playback.c +++ b/apps/playback.c @@ -183,8 +183,7 @@ static struct albumart_slot /* Buffer and thread state tracking */ static enum filling_state { - STATE_BOOT = 0, /* audio thread is not ready yet */ - STATE_IDLE, /* audio is stopped: nothing to do */ + STATE_IDLE = 0, /* audio is stopped: nothing to do */ STATE_FILLING, /* adding tracks to the buffer */ STATE_FULL, /* can't add any more tracks */ STATE_END_OF_PLAYLIST, /* all remaining tracks have been added */ @@ -194,7 +193,7 @@ static enum filling_state #if (CONFIG_PLATFORM & PLATFORM_NATIVE) STATE_USB, /* USB mode, ignore most messages */ #endif -} filling = STATE_BOOT; +} filling = STATE_IDLE; /* Track info - holds information about each track in the buffer */ struct track_info @@ -2917,8 +2916,6 @@ static void audio_thread(void) pcm_postinit(); - filling = STATE_IDLE; - while (1) { switch (filling) @@ -3717,12 +3714,6 @@ unsigned long audio_prev_elapsed(void) return prev_track_elapsed; } -/* Is the audio thread ready to accept commands? */ -bool audio_is_thread_ready(void) -{ - return filling != STATE_BOOT; -} - /* Return total file buffer length after accounting for the talk buf */ size_t audio_get_filebuflen(void) { diff --git a/apps/playback.h b/apps/playback.h index 793055f98c..6e57c03fad 100644 --- a/apps/playback.h +++ b/apps/playback.h @@ -70,7 +70,6 @@ struct bufopen_bitmap_data { #endif /* Functions */ -bool audio_is_thread_ready(void); int audio_track_count(void); long audio_filebufused(void); void audio_pre_ff_rewind(void); diff --git a/apps/radio/radio.c b/apps/radio/radio.c index 1a77709f9c..4524707289 100644 --- a/apps/radio/radio.c +++ b/apps/radio/radio.c @@ -418,7 +418,7 @@ void radio_screen(void) /* turn on radio */ #if CONFIG_CODEC == SWCODEC /* This should be done before touching audio settings */ - while (!audio_is_thread_ready()) + while (!pcm_is_initialized()) sleep(0); audio_set_input_source(AUDIO_SRC_FMRADIO, diff --git a/apps/recorder/recording.c b/apps/recorder/recording.c index 453b2fc42d..d706899b1c 100644 --- a/apps/recorder/recording.c +++ b/apps/recorder/recording.c @@ -1074,7 +1074,7 @@ bool recording_screen(bool no_source) #if CONFIG_CODEC == SWCODEC /* This should be done before touching audio settings */ - while (!audio_is_thread_ready()) + while (!pcm_is_initialized()) sleep(0); /* recording_menu gets messed up: so prevent manus talking */ diff --git a/firmware/export/pcm-internal.h b/firmware/export/pcm-internal.h index bae6a368fa..16e2aeae4d 100644 --- a/firmware/export/pcm-internal.h +++ b/firmware/export/pcm-internal.h @@ -66,6 +66,7 @@ extern volatile bool pcm_paused; void pcm_play_dma_lock(void); void pcm_play_dma_unlock(void); void pcm_play_dma_init(void) INIT_ATTR; +void pcm_play_dma_postinit(void); void pcm_play_dma_start(const void *addr, size_t size); void pcm_play_dma_stop(void); void pcm_play_dma_pause(bool pause); diff --git a/firmware/export/pcm.h b/firmware/export/pcm.h index 22c5ef350e..fb6581b119 100644 --- a/firmware/export/pcm.h +++ b/firmware/export/pcm.h @@ -76,6 +76,7 @@ void pcm_play_unlock(void); void pcm_init(void) INIT_ATTR; void pcm_postinit(void); +bool pcm_is_initialized(void); /* This is for playing "raw" PCM data */ void pcm_play_data(pcm_play_callback_type get_more, diff --git a/firmware/pcm.c b/firmware/pcm.c index c2ebc67687..b0a91fb64e 100644 --- a/firmware/pcm.c +++ b/firmware/pcm.c @@ -43,6 +43,7 @@ * Semi-private - * pcm_play_get_more_callback * pcm_play_dma_init + * pcm_play_dma_postinit * pcm_play_dma_start * pcm_play_dma_stop * pcm_play_dma_pause @@ -79,6 +80,9 @@ * */ +/* 'true' when all stages of pcm initialization have completed */ +static bool pcm_is_ready = false; + /* the registered callback function to ask for more mp3 data */ static pcm_play_callback_type pcm_callback_for_more SHAREDBSS_ATTR = NULL; void (* pcm_play_dma_started)(void) SHAREDBSS_ATTR = NULL; @@ -105,6 +109,12 @@ static void pcm_play_stopped(void) pcm_playing = false; } +static void pcm_wait_for_init(void) +{ + while (!pcm_is_ready) + sleep(0); +} + /** * Perform peak calculation on a buffer of packed 16-bit samples. * @@ -230,6 +240,23 @@ void pcm_init(void) pcm_play_dma_init(); } +/* Finish delayed init */ +void pcm_postinit(void) +{ + logf("pcm_postinit"); + + logf(" pcm_play_dma_postinit"); + + pcm_play_dma_postinit(); + + pcm_is_ready = true; +} + +bool pcm_is_initialized(void) +{ + return pcm_is_ready; +} + /* Common code to pcm_play_data and pcm_play_pause */ static void pcm_play_data_start(unsigned char *start, size_t size) { @@ -402,6 +429,8 @@ void pcm_apply_settings(void) { logf("pcm_apply_settings"); + pcm_wait_for_init(); + if (pcm_sampr != pcm_curr_sampr) { logf(" pcm_dma_apply_settings"); @@ -487,6 +516,8 @@ void pcm_init_recording(void) { logf("pcm_init_recording"); + pcm_wait_for_init(); + /* Stop the beasty before attempting recording */ mixer_reset(); diff --git a/firmware/target/arm/as3525/pcm-as3525.c b/firmware/target/arm/as3525/pcm-as3525.c index a89a47d400..f82b373ade 100644 --- a/firmware/target/arm/as3525/pcm-as3525.c +++ b/firmware/target/arm/as3525/pcm-as3525.c @@ -181,7 +181,7 @@ void pcm_play_dma_init(void) audiohw_preinit(); } -void pcm_postinit(void) +void pcm_play_dma_postinit(void) { audiohw_postinit(); } diff --git a/firmware/target/arm/imx31/gigabeat-s/pcm-gigabeat-s.c b/firmware/target/arm/imx31/gigabeat-s/pcm-gigabeat-s.c index 1f6eef435a..65571a4ee2 100644 --- a/firmware/target/arm/imx31/gigabeat-s/pcm-gigabeat-s.c +++ b/firmware/target/arm/imx31/gigabeat-s/pcm-gigabeat-s.c @@ -247,7 +247,7 @@ void pcm_play_dma_init(void) audiohw_init(); } -void pcm_postinit(void) +void pcm_play_dma_postinit(void) { audiohw_postinit(); } diff --git a/firmware/target/arm/pcm-pp.c b/firmware/target/arm/pcm-pp.c index 704296d407..c35a824a25 100644 --- a/firmware/target/arm/pcm-pp.c +++ b/firmware/target/arm/pcm-pp.c @@ -527,7 +527,7 @@ void pcm_play_dma_init(void) IISCONFIG |= IIS_TXFIFOEN; } -void pcm_postinit(void) +void void pcm_play_dma_postinit(void) { audiohw_postinit(); } diff --git a/firmware/target/arm/pcm-telechips.c b/firmware/target/arm/pcm-telechips.c index aff43171f6..ae4aa5ef38 100644 --- a/firmware/target/arm/pcm-telechips.c +++ b/firmware/target/arm/pcm-telechips.c @@ -57,11 +57,6 @@ struct dma_data dma_play_data SHAREDBSS_ATTR = .state = 0 }; -void pcm_postinit(void) -{ - audiohw_postinit(); -} - const void * pcm_play_dma_get_peak_buffer(int *count) { unsigned long addr = (unsigned long)dma_play_data.p; @@ -110,6 +105,11 @@ void pcm_play_dma_init(void) #endif } +void pcm_play_dma_postinit(void) +{ + audiohw_postinit(); +} + void pcm_dma_apply_settings(void) { } diff --git a/firmware/target/arm/pnx0101/pcm-pnx0101.c b/firmware/target/arm/pnx0101/pcm-pnx0101.c index d4c17454ed..89d56af374 100644 --- a/firmware/target/arm/pnx0101/pcm-pnx0101.c +++ b/firmware/target/arm/pnx0101/pcm-pnx0101.c @@ -190,7 +190,7 @@ void pcm_init(void) DMAR10(1) |= 1; } -void pcm_postinit(void) +void pcm_play_dma_postinit(void) { audiohw_postinit(); } diff --git a/firmware/target/arm/s3c2440/gigabeat-fx/pcm-meg-fx.c b/firmware/target/arm/s3c2440/gigabeat-fx/pcm-meg-fx.c index 33194ae5d9..b133639e12 100644 --- a/firmware/target/arm/s3c2440/gigabeat-fx/pcm-meg-fx.c +++ b/firmware/target/arm/s3c2440/gigabeat-fx/pcm-meg-fx.c @@ -94,7 +94,7 @@ void pcm_play_dma_init(void) bitset32(&INTMOD, DMA2_MASK); } -void pcm_postinit(void) +void pcm_play_dma_postinit(void) { audiohw_postinit(); } diff --git a/firmware/target/arm/s3c2440/mini2440/pcm-mini2440.c b/firmware/target/arm/s3c2440/mini2440/pcm-mini2440.c index 0c69c1e6d3..20332c12f8 100644 --- a/firmware/target/arm/s3c2440/mini2440/pcm-mini2440.c +++ b/firmware/target/arm/s3c2440/mini2440/pcm-mini2440.c @@ -120,7 +120,7 @@ void pcm_play_dma_init(void) bitset32(&INTMOD, DMA2_MASK); } -void pcm_postinit(void) +void pcm_play_dma_postinit(void) { audiohw_postinit(); } diff --git a/firmware/target/arm/s5l8700/pcm-s5l8700.c b/firmware/target/arm/s5l8700/pcm-s5l8700.c index 14c515ec47..6d733e0ff1 100644 --- a/firmware/target/arm/s5l8700/pcm-s5l8700.c +++ b/firmware/target/arm/s5l8700/pcm-s5l8700.c @@ -262,7 +262,7 @@ void pcm_play_dma_init(void) audiohw_preinit(); } -void pcm_postinit(void) +void pcm_play_dma_postinit(void) { audiohw_postinit(); } diff --git a/firmware/target/arm/s5l8702/pcm-s5l8702.c b/firmware/target/arm/s5l8702/pcm-s5l8702.c index dbadf3bac0..c3df77f14f 100644 --- a/firmware/target/arm/s5l8702/pcm-s5l8702.c +++ b/firmware/target/arm/s5l8702/pcm-s5l8702.c @@ -152,7 +152,7 @@ void pcm_play_dma_init(void) audiohw_preinit(); } -void pcm_postinit(void) +void pcm_play_dma_postinit(void) { audiohw_postinit(); } diff --git a/firmware/target/arm/tms320dm320/creative-zvm/pcm-creativezvm.c b/firmware/target/arm/tms320dm320/creative-zvm/pcm-creativezvm.c index 5ec62cf876..1fda5fe045 100644 --- a/firmware/target/arm/tms320dm320/creative-zvm/pcm-creativezvm.c +++ b/firmware/target/arm/tms320dm320/creative-zvm/pcm-creativezvm.c @@ -44,7 +44,7 @@ void pcm_play_dma_init(void) // dsp_init(); } -void pcm_postinit(void) +void pcm_play_dma_postinit(void) { audiohw_postinit(); diff --git a/firmware/target/arm/tms320dm320/mrobe-500/pcm-mr500.c b/firmware/target/arm/tms320dm320/mrobe-500/pcm-mr500.c index 90c342e868..c507428c57 100644 --- a/firmware/target/arm/tms320dm320/mrobe-500/pcm-mr500.c +++ b/firmware/target/arm/tms320dm320/mrobe-500/pcm-mr500.c @@ -35,7 +35,7 @@ */ static void *start; -void pcm_postinit(void) +void pcm_play_dma_postinit(void) { /* Configure clock divider */ tsc2100_writereg(CONTROL_PAGE2, TSPP1_ADDRESS, 0x1120); diff --git a/firmware/target/coldfire/pcm-coldfire.c b/firmware/target/coldfire/pcm-coldfire.c index 85eeaec815..e95d445337 100644 --- a/firmware/target/coldfire/pcm-coldfire.c +++ b/firmware/target/coldfire/pcm-coldfire.c @@ -203,7 +203,7 @@ void pcm_play_dma_init(void) #endif } /* pcm_play_dma_init */ -void pcm_postinit(void) +void pcm_play_dma_postinit(void) { audiohw_postinit(); iis_play_reset(); diff --git a/firmware/target/hosted/android/pcm-android.c b/firmware/target/hosted/android/pcm-android.c index 6492a779f2..4e58707d0a 100644 --- a/firmware/target/hosted/android/pcm-android.c +++ b/firmware/target/hosted/android/pcm-android.c @@ -206,7 +206,7 @@ void pcm_play_dma_init(void) write_method = e->GetMethodID(env_ptr, RockboxPCM_class, "write", "([BII)I"); } -void pcm_postinit(void) +void pcm_play_dma_postinit(void) { } diff --git a/firmware/target/hosted/maemo/pcm-gstreamer.c b/firmware/target/hosted/maemo/pcm-gstreamer.c index 6e049dbbff..d6879ea083 100644 --- a/firmware/target/hosted/maemo/pcm-gstreamer.c +++ b/firmware/target/hosted/maemo/pcm-gstreamer.c @@ -397,7 +397,7 @@ void pcm_shutdown_gstreamer(void) g_main_loop_unref (pcm_loop); } -void pcm_postinit(void) +void pcm_play_dma_postinit(void) { } diff --git a/firmware/target/hosted/sdl/pcm-sdl.c b/firmware/target/hosted/sdl/pcm-sdl.c index dfdd90f29b..020928d572 100644 --- a/firmware/target/hosted/sdl/pcm-sdl.c +++ b/firmware/target/hosted/sdl/pcm-sdl.c @@ -410,7 +410,7 @@ void pcm_play_dma_init(void) pcm_dma_apply_settings_nolock(); } -void pcm_postinit(void) +void pcm_play_dma_postinit(void) { } diff --git a/firmware/target/mips/ingenic_jz47xx/pcm-jz4740.c b/firmware/target/mips/ingenic_jz47xx/pcm-jz4740.c index cfc3c9ef8e..1ed413c9ae 100644 --- a/firmware/target/mips/ingenic_jz47xx/pcm-jz4740.c +++ b/firmware/target/mips/ingenic_jz47xx/pcm-jz4740.c @@ -33,7 +33,7 @@ ** Playback DMA transfer **/ -void pcm_postinit(void) +void pcm_play_dma_postinit(void) { audiohw_postinit();