Index: apps/codecs/vorbis.c =================================================================== --- apps/codecs/vorbis.c (revision 29341) +++ apps/codecs/vorbis.c (working copy) @@ -136,10 +136,12 @@ #endif next_track: + error = CODEC_OK; + ogg_malloc_init(); - while (!*ci->taginfo_ready && !ci->stop_codec) - ci->sleep(1); + if (codec_wait_taginfo() != 0) + goto done; /* Create a decoder instance */ callbacks.read_func = read_handler; @@ -233,8 +235,7 @@ ci->set_elapsed(ov_time_tell(&vf)); } } - error = CODEC_OK; - + done: #if 0 /* defined(SIMULATOR) */ { Index: apps/codecs/au.c =================================================================== --- apps/codecs/au.c (revision 29341) +++ apps/codecs/au.c (working copy) @@ -108,7 +108,7 @@ /* this is the codec entry point */ enum codec_status codec_main(void) { - int status = CODEC_OK; + int status; struct pcm_format format; uint32_t bytesdone, decodedsamples; size_t n; @@ -124,14 +124,16 @@ ci->configure(DSP_SET_SAMPLE_DEPTH, PCM_OUTPUT_DEPTH-1); next_track: + status = CODEC_OK; + if (codec_init()) { DEBUGF("codec_init() error\n"); status = CODEC_ERROR; goto exit; } - while (!*ci->taginfo_ready && !ci->stop_codec) - ci->sleep(1); + if (codec_wait_taginfo() != 0) + goto done; codec_set_replaygain(ci->id3); @@ -304,7 +306,6 @@ endofstream = 1; ci->set_elapsed(decodedsamples*1000LL/ci->id3->frequency); } - status = CODEC_OK; done: if (ci->request_next_track()) Index: apps/codecs/ape.c =================================================================== --- apps/codecs/ape.c (revision 29341) +++ apps/codecs/ape.c (working copy) @@ -149,23 +149,22 @@ /* Generic codec initialisation */ ci->configure(DSP_SET_SAMPLE_DEPTH, APE_OUTPUT_DEPTH-1); - next_track: - +next_track: retval = CODEC_OK; - /* Remember the resume position - when the codec is opened, the - playback engine will reset it. */ - resume_offset = ci->id3->offset; - if (codec_init()) { LOGF("APE: Error initialising codec\n"); retval = CODEC_ERROR; goto exit; } - while (!*ci->taginfo_ready && !ci->stop_codec) - ci->sleep(1); + if (codec_wait_taginfo() != 0) + goto done; + /* Remember the resume position - when the codec is opened, the + playback engine will reset it. */ + resume_offset = ci->id3->offset; + inbuffer = ci->request_buffer(&bytesleft, INPUT_CHUNKSIZE); /* Read the file headers to populate the ape_ctx struct */ @@ -319,8 +318,6 @@ currentframe++; } - retval = CODEC_OK; - done: LOGF("APE: Decoded %lu samples\n",(unsigned long)samplesdone); Index: apps/codecs/aiff.c =================================================================== --- apps/codecs/aiff.c (revision 29341) +++ apps/codecs/aiff.c (working copy) @@ -63,7 +63,7 @@ enum codec_status codec_main(void) { - int status = CODEC_OK; + int status; struct pcm_format format; uint32_t bytesdone, decodedsamples; uint32_t num_sample_frames = 0; @@ -82,13 +82,15 @@ ci->configure(DSP_SET_SAMPLE_DEPTH, PCM_OUTPUT_DEPTH-1); next_track: + status = CODEC_OK; + if (codec_init()) { status = CODEC_ERROR; goto exit; } - while (!*ci->taginfo_ready && !ci->stop_codec) - ci->sleep(1); + if (codec_wait_taginfo() != 0) + goto done; codec_set_replaygain(ci->id3); Index: apps/codecs/flac.c =================================================================== --- apps/codecs/flac.c (revision 29341) +++ apps/codecs/flac.c (working copy) @@ -433,19 +433,20 @@ /* Generic codec initialisation */ ci->configure(DSP_SET_SAMPLE_DEPTH, FLAC_OUTPUT_DEPTH-1); - next_track: +next_track: + retval = CODEC_OK; - /* Need to save offset for later use (cleared indirectly by flac_init) */ - samplesdone=ci->id3->offset; - if (codec_init()) { LOGF("FLAC: Error initialising codec\n"); retval = CODEC_ERROR; goto exit; } - while (!*ci->taginfo_ready && !ci->stop_codec) - ci->sleep(1); + if (codec_wait_taginfo() != 0) + goto done; + + /* Need to save offset for later use (cleared indirectly by flac_init) */ + samplesdone = ci->id3->offset; if (!flac_init(&fc,ci->id3->first_frame_offset)) { LOGF("FLAC: Error initialising codec\n"); Index: apps/codecs/raac.c =================================================================== --- apps/codecs/raac.c (revision 29341) +++ apps/codecs/raac.c (working copy) @@ -56,7 +56,7 @@ uint32_t s = 0; /* sample rate */ unsigned char c = 0; /* channels */ int playback_on = -1; - size_t resume_offset = ci->id3->offset; + size_t resume_offset; /* Generic codec initialisation */ ci->configure(DSP_SET_STEREO_MODE, STEREO_NONINTERLEAVED); @@ -70,9 +70,11 @@ return CODEC_ERROR; } - while (!*ci->taginfo_ready && !ci->stop_codec) - ci->sleep(1); + if (codec_wait_taginfo() != 0) + goto done; + resume_offset = ci->id3->offset; + ci->memset(&rmctx,0,sizeof(RMContext)); ci->memset(&pkt,0,sizeof(RMPacket)); init_rm(&rmctx); @@ -224,8 +226,6 @@ ci->advance_buffer(pkt.length); } - err = CODEC_OK; - done: if (ci->request_next_track()) goto next_track; Index: apps/codecs/atrac3_rm.c =================================================================== --- apps/codecs/atrac3_rm.c (revision 29341) +++ apps/codecs/atrac3_rm.c (working copy) @@ -51,16 +51,19 @@ uint32_t packet_count; int scrambling_unit_size, num_units, elapsed = 0; int playback_on = -1; - size_t resume_offset = ci->id3->offset; + size_t resume_offset; next_track: if (codec_init()) { DEBUGF("codec init failed\n"); return CODEC_ERROR; } - while (!*ci->taginfo_ready && !ci->stop_codec) - ci->sleep(1); + if (codec_wait_taginfo() != 0) + goto done; + + resume_offset = ci->id3->offset; + codec_set_replaygain(ci->id3); ci->memset(&rmctx,0,sizeof(RMContext)); ci->memset(&pkt,0,sizeof(RMPacket)); Index: apps/codecs/adx.c =================================================================== --- apps/codecs/adx.c (revision 29341) +++ apps/codecs/adx.c (working copy) @@ -78,8 +78,8 @@ ch1_1=ch1_2=ch2_1=ch2_2=0; /* wait for track info to load */ - while (!*ci->taginfo_ready && !ci->stop_codec) - ci->sleep(1); + if (codec_wait_taginfo() != 0) + goto request_next_track; codec_set_replaygain(ci->id3); @@ -385,6 +385,7 @@ 1000LL/avgbytespersec); } +request_next_track: if (ci->request_next_track()) goto next_track; Index: apps/codecs/vox.c =================================================================== --- apps/codecs/vox.c (revision 29341) +++ apps/codecs/vox.c (working copy) @@ -46,7 +46,7 @@ /* this is the codec entry point */ enum codec_status codec_main(void) { - int status = CODEC_OK; + int status; uint32_t decodedsamples; size_t n; int bufcount; @@ -59,14 +59,16 @@ ci->configure(DSP_SET_SAMPLE_DEPTH, PCM_OUTPUT_DEPTH-1); next_track: + status = CODEC_OK; + if (codec_init()) { DEBUGF("codec_init() error\n"); status = CODEC_ERROR; goto exit; } - while (!*ci->taginfo_ready && !ci->stop_codec) - ci->sleep(1); + if (codec_wait_taginfo() != 0) + goto done; codec_set_replaygain(ci->id3); @@ -189,7 +191,6 @@ endofstream = 1; ci->set_elapsed(decodedsamples*1000LL/ci->id3->frequency); } - status = CODEC_OK; done: if (ci->request_next_track()) Index: apps/codecs/mpa.c =================================================================== --- apps/codecs/mpa.c (revision 29341) +++ apps/codecs/mpa.c (working copy) @@ -325,15 +325,14 @@ return CODEC_ERROR; next_track: - status = CODEC_OK; /* Reinitializing seems to be necessary to avoid playback quircks when seeking. */ init_mad(); file_end = 0; - while (!*ci->taginfo_ready && !ci->stop_codec) - ci->sleep(1); + if (codec_wait_taginfo() != 0) + goto request_next_track; ci->configure(DSP_SWITCH_FREQUENCY, ci->id3->frequency); current_frequency = ci->id3->frequency; @@ -505,6 +504,7 @@ framelength - stop_skip); } +request_next_track: if (ci->request_next_track()) goto next_track; Index: apps/codecs/mpc.c =================================================================== --- apps/codecs/mpc.c (revision 29341) +++ apps/codecs/mpc.c (working copy) @@ -64,7 +64,7 @@ mpc_streaminfo info; mpc_frame_info frame; mpc_demux *demux = NULL; - int retval = CODEC_OK; + int retval; frame.buffer = sample_buffer; @@ -78,15 +78,17 @@ reader.tell = tell_impl; reader.get_size = get_size_impl; -next_track: +next_track: + retval = CODEC_OK; + if (codec_init()) { retval = CODEC_ERROR; goto exit; } - while (!*ci->taginfo_ready && !ci->stop_codec) - ci->sleep(1); + if (codec_wait_taginfo() != 0) + goto done; /* Initialize demux/decoder. */ demux = mpc_demux_init(&reader); Index: apps/codecs/speex.c =================================================================== --- apps/codecs/speex.c (revision 29341) +++ apps/codecs/speex.c (working copy) @@ -371,7 +371,7 @@ enum codec_status codec_main(void) { SpeexBits bits; - int error = 0; + int error; int eof = 0; spx_ogg_sync_state oy; spx_ogg_page og; @@ -395,17 +395,19 @@ /* Ogg handling still uses mallocs, so reset the malloc buffer per track */ next_track: + error = CODEC_OK; if (codec_init()) { error = CODEC_ERROR; goto exit; } stereo = speex_stereo_state_init(); + + if (codec_wait_taginfo() != 0) + goto done; + strtoffset = ci->id3->offset; - while (!*ci->taginfo_ready && !ci->stop_codec) - ci->sleep(1); - spx_ogg_sync_init(&oy); spx_ogg_alloc_buffer(&oy,2*CHUNKSIZE); @@ -569,8 +571,6 @@ goto next_track; } - error = CODEC_OK; - exit: speex_bits_destroy(&bits); Index: apps/codecs/aac.c =================================================================== --- apps/codecs/aac.c (revision 29341) +++ apps/codecs/aac.c (working copy) @@ -78,8 +78,8 @@ goto exit; } - while (!*ci->taginfo_ready && !ci->stop_codec) - ci->sleep(1); + if (codec_wait_taginfo() != 0) + goto done; file_offset = ci->id3->offset; @@ -304,8 +304,6 @@ i++; } - err = CODEC_OK; - done: LOGF("AAC: Decoded %lu samples\n", (unsigned long)sound_samples_done); Index: apps/codecs/lib/codeclib.c =================================================================== --- apps/codecs/lib/codeclib.c (revision 29341) +++ apps/codecs/lib/codeclib.c (working copy) @@ -49,6 +49,19 @@ ci->configure(DSP_SET_ALBUM_PEAK, id3->album_peak); } +/* Note: codec really needs its own private metdata copy for the current + track being processed in order to be stable. */ +int codec_wait_taginfo(void) +{ + while (!*ci->taginfo_ready && !ci->stop_codec && !ci->new_track) + ci->sleep(0); + if (ci->stop_codec) + return -1; + if (ci->new_track) + return 1; + return 0; +} + /* Various "helper functions" common to all the xxx2wav decoder plugins */ Index: apps/codecs/lib/codeclib.h =================================================================== --- apps/codecs/lib/codeclib.h (revision 29341) +++ apps/codecs/lib/codeclib.h (working copy) @@ -157,6 +157,7 @@ int codec_init(void); void codec_set_replaygain(struct mp3entry* id3); +int codec_wait_taginfo(void); /* 0 = success */ #ifdef RB_PROFILE void __cyg_profile_func_enter(void *this_fn, void *call_site) Index: apps/codecs/spc.c =================================================================== --- apps/codecs/spc.c (revision 29341) +++ apps/codecs/spc.c (working copy) @@ -553,8 +553,8 @@ ci->configure(DSP_SET_STEREO_MODE, STEREO_NONINTERLEAVED); /* wait for track info to load */ - while (!*ci->taginfo_ready && !ci->stop_codec) - ci->yield(); + if (codec_wait_taginfo() != 0) + continue; codec_set_replaygain(ci->id3); Index: apps/codecs/tta.c =================================================================== --- apps/codecs/tta.c (revision 29341) +++ apps/codecs/tta.c (working copy) @@ -37,7 +37,7 @@ enum codec_status codec_main(void) { tta_info info; - int status = CODEC_OK; + int status; unsigned int decodedsamples; int endofstream; int new_pos = 0; @@ -47,6 +47,8 @@ ci->configure(DSP_SET_SAMPLE_DEPTH, TTA_OUTPUT_DEPTH - 1); next_track: + status = CODEC_OK; + if (codec_init()) { DEBUGF("codec_init() error\n"); @@ -54,8 +56,8 @@ goto exit; } - while (!*ci->taginfo_ready && !ci->stop_codec) - ci->sleep(1); + if (codec_wait_taginfo() != 0) + goto done; if (set_tta_info(&info) < 0 || player_init(&info) < 0) { @@ -117,7 +119,7 @@ endofstream = 1; ci->set_elapsed((uint64_t)info.LENGTH * 1000 * decodedsamples / info.DATALENGTH); } - status = CODEC_OK; + done: player_stop(); if (ci->request_next_track()) Index: apps/codecs/alac.c =================================================================== --- apps/codecs/alac.c (revision 29341) +++ apps/codecs/alac.c (working copy) @@ -48,6 +48,7 @@ ci->configure(DSP_SET_SAMPLE_DEPTH, ALAC_OUTPUT_DEPTH-1); next_track: + retval = CODEC_OK; /* Clean and initialize decoder structures */ memset(&demux_res , 0, sizeof(demux_res)); @@ -57,8 +58,8 @@ goto exit; } - while (!*ci->taginfo_ready && !ci->stop_codec) - ci->sleep(1); + if (codec_wait_taginfo() != 0) + goto done; ci->configure(DSP_SWITCH_FREQUENCY, ci->id3->frequency); codec_set_replaygain(ci->id3); @@ -145,7 +146,6 @@ i++; } - retval = CODEC_OK; done: LOGF("ALAC: Decoded %lu samples\n",(unsigned long)samplesdone); Index: apps/codecs/wmapro.c =================================================================== --- apps/codecs/wmapro.c (revision 29341) +++ apps/codecs/wmapro.c (working copy) @@ -48,16 +48,18 @@ next_track: + retval = CODEC_OK; /* Wait for the metadata to be read */ - while (!*ci->taginfo_ready && !ci->stop_codec) - ci->sleep(1); + if (codec_wait_taginfo() != 0) + goto done; + /* Remember the resume position */ + resume_offset = ci->id3->offset; + +restart_track: retval = CODEC_OK; - /* Remember the resume position */ - resume_offset = ci->id3->offset; - restart_track: if (codec_init()) { LOGF("(WMA PRO) Error: Error initialising codec\n"); retval = CODEC_ERROR; @@ -149,7 +151,6 @@ /* Advance to the next logical packet */ ci->advance_buffer(packetlength); } - retval = CODEC_OK; done: if (ci->request_next_track()) Index: apps/codecs/wav64.c =================================================================== --- apps/codecs/wav64.c (revision 29341) +++ apps/codecs/wav64.c (working copy) @@ -161,7 +161,7 @@ /* this is the codec entry point */ enum codec_status codec_main(void) { - int status = CODEC_OK; + int status; uint32_t decodedsamples; size_t n; int bufcount; @@ -176,14 +176,16 @@ ci->configure(DSP_SET_SAMPLE_DEPTH, PCM_OUTPUT_DEPTH-1); next_track: + status = CODEC_OK; + if (codec_init()) { DEBUGF("codec_init() error\n"); status = CODEC_ERROR; goto exit; } - while (!*ci->taginfo_ready && !ci->stop_codec) - ci->sleep(1); + if (codec_wait_taginfo() != 0) + goto done; codec_set_replaygain(ci->id3); Index: apps/codecs/atrac3_oma.c =================================================================== --- apps/codecs/atrac3_oma.c (revision 29341) +++ apps/codecs/atrac3_oma.c (working copy) @@ -40,16 +40,19 @@ int datasize, res, frame_counter, total_frames, seek_frame_offset; uint8_t *bit_buffer; int elapsed = 0; - size_t resume_offset = ci->id3->offset; + size_t resume_offset; next_track: if (codec_init()) { DEBUGF("codec init failed\n"); return CODEC_ERROR; } - while (!*ci->taginfo_ready && !ci->stop_codec) - ci->sleep(1); + if (codec_wait_taginfo() != 0) + goto done; + + resume_offset = ci->id3->offset; + codec_set_replaygain(ci->id3); ci->memset(&q,0,sizeof(ATRAC3Context)); Index: apps/codecs/wmavoice.c =================================================================== --- apps/codecs/wmavoice.c (revision 29341) +++ apps/codecs/wmavoice.c (working copy) @@ -70,16 +70,17 @@ next_track: + retval = CODEC_OK; /* Wait for the metadata to be read */ - while (!*ci->taginfo_ready && !ci->stop_codec) - ci->sleep(1); + if (codec_wait_taginfo() != 0) + goto done; + /* Remember the resume position */ + resume_offset = ci->id3->offset; +restart_track: retval = CODEC_OK; - /* Remember the resume position */ - resume_offset = ci->id3->offset; - restart_track: if (codec_init()) { LOGF("(WMA Voice) Error: Error initialising codec\n"); retval = CODEC_ERROR; @@ -184,7 +185,6 @@ /* Advance to the next logical packet */ ci->advance_buffer(packetlength); } - retval = CODEC_OK; done: if (ci->request_next_track()) Index: apps/codecs/mod.c =================================================================== --- apps/codecs/mod.c (revision 29341) +++ apps/codecs/mod.c (working copy) @@ -1232,8 +1232,8 @@ return CODEC_ERROR; } - while (!*ci->taginfo_ready && !ci->stop_codec) - ci->sleep(1); + if (codec_wait_taginfo() != 0) + goto request_next_track; codec_set_replaygain(ci->id3); @@ -1305,6 +1305,7 @@ } +request_next_track: if (ci->request_next_track()) goto next_track; Index: apps/codecs/sid.c =================================================================== --- apps/codecs/sid.c (revision 29341) +++ apps/codecs/sid.c (working copy) @@ -1220,8 +1220,8 @@ return CODEC_ERROR; } - while (!*ci->taginfo_ready && !ci->stop_codec) - ci->sleep(1); + if (codec_wait_taginfo() != 0) + goto request_next_track; codec_set_replaygain(ci->id3); @@ -1306,6 +1306,7 @@ ci->pcmbuf_insert(samples, NULL, CHUNK_SIZE); } +request_next_track: if (ci->request_next_track()) goto next_track; Index: apps/codecs/shorten.c =================================================================== --- apps/codecs/shorten.c (revision 29341) +++ apps/codecs/shorten.c (working copy) @@ -57,8 +57,8 @@ return CODEC_ERROR; } - while (!*ci->taginfo_ready) - ci->yield(); + if (codec_wait_taginfo() != 0) + goto request_next_track; codec_set_replaygain(ci->id3); @@ -153,6 +153,7 @@ sc.bitindex = sc.gb.index - 8*consumed; } +request_next_track: if (ci->request_next_track()) goto next_track; Index: apps/codecs/asap.c =================================================================== --- apps/codecs/asap.c (revision 29341) +++ apps/codecs/asap.c (working copy) @@ -44,8 +44,8 @@ return CODEC_ERROR; } - while (!*ci->taginfo_ready && !ci->stop_codec) - ci->sleep(1); + if (codec_wait_taginfo() != 0) + goto request_next_track; codec_set_replaygain(ci->id3); @@ -130,6 +130,7 @@ break; } +request_next_track: if (ci->request_next_track()) goto next_track; Index: apps/codecs/wma.c =================================================================== --- apps/codecs/wma.c (revision 29341) +++ apps/codecs/wma.c (working copy) @@ -46,19 +46,22 @@ ci->configure(DSP_SET_SAMPLE_DEPTH, 29); next_track: + retval = CODEC_OK; + /* Proper reset of the decoder context. */ memset(&wmadec, 0, sizeof(wmadec)); /* Wait for the metadata to be read */ - while (!*ci->taginfo_ready && !ci->stop_codec) - ci->sleep(1); + if (codec_wait_taginfo() != 0) + goto done; - retval = CODEC_OK; - /* Remember the resume position - when the codec is opened, the playback engine will reset it. */ resume_offset = ci->id3->offset; + restart_track: + retval = CODEC_OK; + if (codec_init()) { LOGF("WMA: Error initialising codec\n"); retval = CODEC_ERROR; @@ -176,7 +179,6 @@ ci->advance_buffer(packetlength); } - retval = CODEC_OK; done: /*LOGF("WMA: Decoded %ld samples\n",elapsedtime*wfx.rate/1000);*/ Index: apps/codecs/a52_rm.c =================================================================== --- apps/codecs/a52_rm.c (revision 29341) +++ apps/codecs/a52_rm.c (working copy) @@ -132,21 +132,25 @@ uint8_t *filebuf; int retval, consumed, packet_offset; int playback_on = -1; - size_t resume_offset = ci->id3->offset; + size_t resume_offset; /* Generic codec initialisation */ ci->configure(DSP_SET_STEREO_MODE, STEREO_NONINTERLEAVED); ci->configure(DSP_SET_SAMPLE_DEPTH, 28); next_track: + retval = CODEC_OK; + if (codec_init()) { retval = CODEC_ERROR; goto exit; } - while (!ci->taginfo_ready) - ci->yield(); + if (codec_wait_taginfo() != 0) + goto request_next_track; + resume_offset = ci->id3->offset; + ci->configure(DSP_SWITCH_FREQUENCY, ci->id3->frequency); codec_set_replaygain(ci->id3); @@ -201,8 +205,7 @@ ci->advance_buffer(pkt.length); } - retval = CODEC_OK; - +request_next_track: if (ci->request_next_track()) goto next_track; Index: apps/codecs/nsf.c =================================================================== --- apps/codecs/nsf.c (revision 29341) +++ apps/codecs/nsf.c (working copy) @@ -4344,9 +4344,9 @@ /* wait for track info to load */ - while (!*ci->taginfo_ready && !ci->stop_codec) - ci->sleep(1); - + if (codec_wait_taginfo() != 0) + goto request_next_track; + codec_set_replaygain(ci->id3); /* Read the entire file */ @@ -4448,7 +4448,8 @@ } print_timers(last_path,track); - + +request_next_track: if (ci->request_next_track()) { if (ci->global_settings->repeat_mode==REPEAT_ONE) { /* in repeat one mode just advance to the next track */ Index: apps/codecs/smaf.c =================================================================== --- apps/codecs/smaf.c (revision 29341) +++ apps/codecs/smaf.c (working copy) @@ -334,7 +334,7 @@ enum codec_status codec_main(void) { - int status = CODEC_OK; + int status; uint32_t decodedsamples; size_t n; int bufcount; @@ -347,13 +347,15 @@ ci->configure(DSP_SET_SAMPLE_DEPTH, PCM_OUTPUT_DEPTH-1); next_track: + status = CODEC_OK; + if (codec_init()) { status = CODEC_ERROR; goto exit; } - while (!*ci->taginfo_ready && !ci->stop_codec) - ci->sleep(1); + if (codec_wait_taginfo() != 0) + goto done; codec_set_replaygain(ci->id3); @@ -479,7 +481,6 @@ ci->set_elapsed(decodedsamples*1000LL/ci->id3->frequency); } - status = CODEC_OK; done: if (ci->request_next_track()) Index: apps/codecs/a52.c =================================================================== --- apps/codecs/a52.c (revision 29341) +++ apps/codecs/a52.c (working copy) @@ -128,13 +128,15 @@ ci->configure(DSP_SET_SAMPLE_DEPTH, 28); next_track: + retval = CODEC_OK; + if (codec_init()) { retval = CODEC_ERROR; goto exit; } - while (!ci->taginfo_ready) - ci->yield(); + if (codec_wait_taginfo() != 0) + goto request_next_track; ci->configure(DSP_SWITCH_FREQUENCY, ci->id3->frequency); codec_set_replaygain(ci->id3); @@ -176,8 +178,8 @@ a52_decode_data(filebuf, filebuf + n); ci->advance_buffer(n); } - retval = CODEC_OK; +request_next_track: if (ci->request_next_track()) goto next_track; Index: apps/codecs/cook.c =================================================================== --- apps/codecs/cook.c (revision 29341) +++ apps/codecs/cook.c (working copy) @@ -47,16 +47,19 @@ uint16_t fs,sps,h; uint32_t packet_count; int scrambling_unit_size, num_units; - size_t resume_offset = ci->id3->offset; + size_t resume_offset; next_track: if (codec_init()) { DEBUGF("codec init failed\n"); return CODEC_ERROR; } - while (!*ci->taginfo_ready && !ci->stop_codec) - ci->sleep(1); + if (codec_wait_taginfo() != 0) + goto done; + + resume_offset = ci->id3->offset; + codec_set_replaygain(ci->id3); ci->memset(&rmctx,0,sizeof(RMContext)); ci->memset(&pkt,0,sizeof(RMPacket)); Index: apps/codecs/wavpack.c =================================================================== --- apps/codecs/wavpack.c (revision 29341) +++ apps/codecs/wavpack.c (working copy) @@ -46,15 +46,16 @@ /* Generic codec initialisation */ ci->configure(DSP_SET_SAMPLE_DEPTH, 28); - next_track: +next_track: + retval = CODEC_OK; if (codec_init()) { retval = CODEC_ERROR; goto exit; } - while (!*ci->taginfo_ready && !ci->stop_codec) - ci->sleep(1); + if (codec_wait_taginfo() != 0) + goto done; /* Create a decoder instance */ wpc = WavpackOpenFileInput (read_callback, error); @@ -121,7 +122,6 @@ ci->set_elapsed (WavpackGetSampleIndex (wpc) / sr_100 * 10); ci->yield (); } - retval = CODEC_OK; done: if (ci->request_next_track()) Index: apps/codecs/wav.c =================================================================== --- apps/codecs/wav.c (revision 29341) +++ apps/codecs/wav.c (working copy) @@ -153,7 +153,7 @@ /* this is the codec entry point */ enum codec_status codec_main(void) { - int status = CODEC_OK; + int status; uint32_t decodedsamples; size_t n; int bufcount; @@ -168,14 +168,16 @@ ci->configure(DSP_SET_SAMPLE_DEPTH, PCM_OUTPUT_DEPTH-1); next_track: + status = CODEC_OK; + if (codec_init()) { DEBUGF("codec_init() error\n"); status = CODEC_ERROR; goto exit; } - while (!*ci->taginfo_ready && !ci->stop_codec) - ci->sleep(1); + if (codec_wait_taginfo() != 0) + goto done; codec_set_replaygain(ci->id3); @@ -437,7 +439,6 @@ endofstream = 1; ci->set_elapsed(decodedsamples*1000LL/ci->id3->frequency); } - status = CODEC_OK; done: if (ci->request_next_track())