From 85e40257dc65e3542b785898ddf60482e2d1ab0c Mon Sep 17 00:00:00 2001 From: Michael Sevakis Date: Sun, 20 Feb 2011 15:27:10 +0000 Subject: Enforce that codecs wait for their metadata in a proper-ish and consistent manner. Sort of a halfway patch; best would be to give them an internal copy of the current track information which lasts unaltered by playback until a track switch or unload. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29348 a1c6a512-1295-4272-9138-f99709370657 --- apps/codecs/a52.c | 8 +++++--- apps/codecs/a52_rm.c | 13 ++++++++----- apps/codecs/aac.c | 6 ++---- apps/codecs/adx.c | 5 +++-- apps/codecs/aiff.c | 8 +++++--- apps/codecs/alac.c | 6 +++--- apps/codecs/ape.c | 17 +++++++---------- apps/codecs/asap.c | 5 +++-- apps/codecs/atrac3_oma.c | 9 ++++++--- apps/codecs/atrac3_rm.c | 9 ++++++--- apps/codecs/au.c | 9 +++++---- apps/codecs/cook.c | 9 ++++++--- apps/codecs/flac.c | 13 +++++++------ apps/codecs/lib/codeclib.c | 13 +++++++++++++ apps/codecs/lib/codeclib.h | 1 + apps/codecs/mod.c | 5 +++-- apps/codecs/mpa.c | 6 +++--- apps/codecs/mpc.c | 10 ++++++---- apps/codecs/nsf.c | 9 +++++---- apps/codecs/raac.c | 10 +++++----- apps/codecs/shorten.c | 5 +++-- apps/codecs/sid.c | 5 +++-- apps/codecs/smaf.c | 9 +++++---- apps/codecs/spc.c | 4 ++-- apps/codecs/speex.c | 12 ++++++------ apps/codecs/tta.c | 10 ++++++---- apps/codecs/vorbis.c | 9 +++++---- apps/codecs/vox.c | 9 +++++---- apps/codecs/wav.c | 9 +++++---- apps/codecs/wav64.c | 8 +++++--- apps/codecs/wavpack.c | 8 ++++---- apps/codecs/wma.c | 12 +++++++----- apps/codecs/wmapro.c | 13 +++++++------ apps/codecs/wmavoice.c | 12 ++++++------ 34 files changed, 171 insertions(+), 125 deletions(-) (limited to 'apps') diff --git a/apps/codecs/a52.c b/apps/codecs/a52.c index d399e91627..00fdeea309 100644 --- a/apps/codecs/a52.c +++ b/apps/codecs/a52.c @@ -128,13 +128,15 @@ enum codec_status codec_main(void) 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 @@ next_track: a52_decode_data(filebuf, filebuf + n); ci->advance_buffer(n); } - retval = CODEC_OK; +request_next_track: if (ci->request_next_track()) goto next_track; diff --git a/apps/codecs/a52_rm.c b/apps/codecs/a52_rm.c index bc6c129ad2..f5e4923292 100644 --- a/apps/codecs/a52_rm.c +++ b/apps/codecs/a52_rm.c @@ -132,20 +132,24 @@ enum codec_status codec_main(void) 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 @@ next_track: ci->advance_buffer(pkt.length); } - retval = CODEC_OK; - +request_next_track: if (ci->request_next_track()) goto next_track; diff --git a/apps/codecs/aac.c b/apps/codecs/aac.c index 34239864d1..309c05da38 100644 --- a/apps/codecs/aac.c +++ b/apps/codecs/aac.c @@ -78,8 +78,8 @@ next_track: 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 @@ next_track: i++; } - err = CODEC_OK; - done: LOGF("AAC: Decoded %lu samples\n", (unsigned long)sound_samples_done); diff --git a/apps/codecs/adx.c b/apps/codecs/adx.c index 2ef2091a66..832b94797b 100644 --- a/apps/codecs/adx.c +++ b/apps/codecs/adx.c @@ -78,8 +78,8 @@ next_track: 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 @@ next_track: 1000LL/avgbytespersec); } +request_next_track: if (ci->request_next_track()) goto next_track; diff --git a/apps/codecs/aiff.c b/apps/codecs/aiff.c index 4a127c7e0e..d4cf8660dd 100644 --- a/apps/codecs/aiff.c +++ b/apps/codecs/aiff.c @@ -63,7 +63,7 @@ static const struct pcm_codec *get_codec(uint32_t formattag) 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 @@ enum codec_status codec_main(void) 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); diff --git a/apps/codecs/alac.c b/apps/codecs/alac.c index 003d222f00..3721f04f1f 100644 --- a/apps/codecs/alac.c +++ b/apps/codecs/alac.c @@ -48,6 +48,7 @@ enum codec_status codec_main(void) 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 @@ enum codec_status codec_main(void) 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 @@ enum codec_status codec_main(void) i++; } - retval = CODEC_OK; done: LOGF("ALAC: Decoded %lu samples\n",(unsigned long)samplesdone); diff --git a/apps/codecs/ape.c b/apps/codecs/ape.c index 06e8842d01..11d973ab26 100644 --- a/apps/codecs/ape.c +++ b/apps/codecs/ape.c @@ -149,22 +149,21 @@ enum codec_status codec_main(void) /* 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); @@ -319,8 +318,6 @@ frame_start: currentframe++; } - retval = CODEC_OK; - done: LOGF("APE: Decoded %lu samples\n",(unsigned long)samplesdone); diff --git a/apps/codecs/asap.c b/apps/codecs/asap.c index bcb47a717d..9447c738d2 100644 --- a/apps/codecs/asap.c +++ b/apps/codecs/asap.c @@ -44,8 +44,8 @@ next_track: 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 @@ next_track: break; } +request_next_track: if (ci->request_next_track()) goto next_track; diff --git a/apps/codecs/atrac3_oma.c b/apps/codecs/atrac3_oma.c index 2085466ed5..73f3ad29fd 100644 --- a/apps/codecs/atrac3_oma.c +++ b/apps/codecs/atrac3_oma.c @@ -40,15 +40,18 @@ enum codec_status codec_main(void) 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)); diff --git a/apps/codecs/atrac3_rm.c b/apps/codecs/atrac3_rm.c index 6c559ec868..6a77d24283 100644 --- a/apps/codecs/atrac3_rm.c +++ b/apps/codecs/atrac3_rm.c @@ -51,15 +51,18 @@ enum codec_status codec_main(void) 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)); diff --git a/apps/codecs/au.c b/apps/codecs/au.c index 1e6af25924..3f9436c9e7 100644 --- a/apps/codecs/au.c +++ b/apps/codecs/au.c @@ -108,7 +108,7 @@ static int convert_au_format(unsigned int encoding, struct pcm_format *fmt) /* 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 @@ enum codec_status codec_main(void) 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 @@ next_track: endofstream = 1; ci->set_elapsed(decodedsamples*1000LL/ci->id3->frequency); } - status = CODEC_OK; done: if (ci->request_next_track()) diff --git a/apps/codecs/cook.c b/apps/codecs/cook.c index 7e77c33e1d..015618986c 100644 --- a/apps/codecs/cook.c +++ b/apps/codecs/cook.c @@ -47,15 +47,18 @@ enum codec_status codec_main(void) 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)); diff --git a/apps/codecs/flac.c b/apps/codecs/flac.c index e8b7f9ad83..89d14b98a7 100644 --- a/apps/codecs/flac.c +++ b/apps/codecs/flac.c @@ -433,19 +433,20 @@ enum codec_status codec_main(void) /* 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"); diff --git a/apps/codecs/lib/codeclib.c b/apps/codecs/lib/codeclib.c index 5af4e01fff..af0894c498 100644 --- a/apps/codecs/lib/codeclib.c +++ b/apps/codecs/lib/codeclib.c @@ -49,6 +49,19 @@ void codec_set_replaygain(struct mp3entry* id3) 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 */ diff --git a/apps/codecs/lib/codeclib.h b/apps/codecs/lib/codeclib.h index b7685ebbcb..41b466ed1f 100644 --- a/apps/codecs/lib/codeclib.h +++ b/apps/codecs/lib/codeclib.h @@ -157,6 +157,7 @@ static inline unsigned int bs_generic(unsigned int v, int mode) 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) diff --git a/apps/codecs/mod.c b/apps/codecs/mod.c index 3e2e4284de..4ace721a1e 100644 --- a/apps/codecs/mod.c +++ b/apps/codecs/mod.c @@ -1232,8 +1232,8 @@ next_track: 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 @@ next_track: } +request_next_track: if (ci->request_next_track()) goto next_track; diff --git a/apps/codecs/mpa.c b/apps/codecs/mpa.c index d3a09ce4fc..d3da63b430 100644 --- a/apps/codecs/mpa.c +++ b/apps/codecs/mpa.c @@ -325,15 +325,14 @@ enum codec_status codec_main(void) 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 @@ next_track: framelength - stop_skip); } +request_next_track: if (ci->request_next_track()) goto next_track; diff --git a/apps/codecs/mpc.c b/apps/codecs/mpc.c index 1d83449838..187c37e597 100644 --- a/apps/codecs/mpc.c +++ b/apps/codecs/mpc.c @@ -64,7 +64,7 @@ enum codec_status codec_main(void) 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 @@ enum codec_status codec_main(void) 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); diff --git a/apps/codecs/nsf.c b/apps/codecs/nsf.c index f596f9dc68..2f37da81d2 100644 --- a/apps/codecs/nsf.c +++ b/apps/codecs/nsf.c @@ -4344,9 +4344,9 @@ next_track: /* 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 @@ init_nsf: } 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 */ diff --git a/apps/codecs/raac.c b/apps/codecs/raac.c index 3fcdca24c9..22d4b4b8b5 100644 --- a/apps/codecs/raac.c +++ b/apps/codecs/raac.c @@ -56,7 +56,7 @@ enum codec_status codec_main(void) 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,8 +70,10 @@ next_track: 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)); @@ -224,8 +226,6 @@ seek_start: ci->advance_buffer(pkt.length); } - err = CODEC_OK; - done: if (ci->request_next_track()) goto next_track; diff --git a/apps/codecs/shorten.c b/apps/codecs/shorten.c index 7595ca30c7..83a9c34da8 100644 --- a/apps/codecs/shorten.c +++ b/apps/codecs/shorten.c @@ -57,8 +57,8 @@ next_track: 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 @@ seek_start: sc.bitindex = sc.gb.index - 8*consumed; } +request_next_track: if (ci->request_next_track()) goto next_track; diff --git a/apps/codecs/sid.c b/apps/codecs/sid.c index 455bdbc28a..52c1289fff 100644 --- a/apps/codecs/sid.c +++ b/apps/codecs/sid.c @@ -1220,8 +1220,8 @@ next_track: 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 @@ next_track: ci->pcmbuf_insert(samples, NULL, CHUNK_SIZE); } +request_next_track: if (ci->request_next_track()) goto next_track; diff --git a/apps/codecs/smaf.c b/apps/codecs/smaf.c index 6763e95001..3e8a41387d 100644 --- a/apps/codecs/smaf.c +++ b/apps/codecs/smaf.c @@ -334,7 +334,7 @@ static uint8_t *read_buffer(size_t *realsize) enum codec_status codec_main(void) { - int status = CODEC_OK; + int status; uint32_t decodedsamples; size_t n; int bufcount; @@ -347,13 +347,15 @@ enum codec_status codec_main(void) 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 @@ next_track: ci->set_elapsed(decodedsamples*1000LL/ci->id3->frequency); } - status = CODEC_OK; done: if (ci->request_next_track()) diff --git a/apps/codecs/spc.c b/apps/codecs/spc.c index 3a06a228ef..d4ed741f7e 100644 --- a/apps/codecs/spc.c +++ b/apps/codecs/spc.c @@ -553,8 +553,8 @@ enum codec_status codec_main(void) 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); diff --git a/apps/codecs/speex.c b/apps/codecs/speex.c index 2a02ccb4b5..e38a04495c 100644 --- a/apps/codecs/speex.c +++ b/apps/codecs/speex.c @@ -371,7 +371,7 @@ static void *process_header(spx_ogg_packet *op, 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,16 +395,18 @@ enum codec_status codec_main(void) /* 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(); - strtoffset = ci->id3->offset; - while (!*ci->taginfo_ready && !ci->stop_codec) - ci->sleep(1); + if (codec_wait_taginfo() != 0) + goto done; + + strtoffset = ci->id3->offset; spx_ogg_sync_init(&oy); spx_ogg_alloc_buffer(&oy,2*CHUNKSIZE); @@ -569,8 +571,6 @@ done: goto next_track; } - error = CODEC_OK; - exit: speex_bits_destroy(&bits); diff --git a/apps/codecs/tta.c b/apps/codecs/tta.c index 2d531315a2..1d0846ea61 100644 --- a/apps/codecs/tta.c +++ b/apps/codecs/tta.c @@ -37,7 +37,7 @@ static int32_t samples[PCM_BUFFER_LENGTH * 2] IBSS_ATTR; 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 @@ enum codec_status codec_main(void) 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 @@ next_track: 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 @@ next_track: endofstream = 1; ci->set_elapsed((uint64_t)info.LENGTH * 1000 * decodedsamples / info.DATALENGTH); } - status = CODEC_OK; + done: player_stop(); if (ci->request_next_track()) diff --git a/apps/codecs/vorbis.c b/apps/codecs/vorbis.c index cb621e8a55..17cc4a03f9 100644 --- a/apps/codecs/vorbis.c +++ b/apps/codecs/vorbis.c @@ -136,10 +136,12 @@ enum codec_status codec_main(void) #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 @@ next_track: ci->set_elapsed(ov_time_tell(&vf)); } } - error = CODEC_OK; - + done: #if 0 /* defined(SIMULATOR) */ { diff --git a/apps/codecs/vox.c b/apps/codecs/vox.c index ff5d571e8d..c7f39342c3 100644 --- a/apps/codecs/vox.c +++ b/apps/codecs/vox.c @@ -46,7 +46,7 @@ static uint8_t *read_buffer(size_t *realsize) /* 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 @@ enum codec_status codec_main(void) 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 @@ next_track: endofstream = 1; ci->set_elapsed(decodedsamples*1000LL/ci->id3->frequency); } - status = CODEC_OK; done: if (ci->request_next_track()) diff --git a/apps/codecs/wav.c b/apps/codecs/wav.c index e286f4dc6a..e179470f27 100644 --- a/apps/codecs/wav.c +++ b/apps/codecs/wav.c @@ -153,7 +153,7 @@ static uint8_t *read_buffer(size_t *realsize) /* 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 @@ enum codec_status codec_main(void) 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 @@ next_track: endofstream = 1; ci->set_elapsed(decodedsamples*1000LL/ci->id3->frequency); } - status = CODEC_OK; done: if (ci->request_next_track()) diff --git a/apps/codecs/wav64.c b/apps/codecs/wav64.c index c06f78c802..9dbdab8368 100644 --- a/apps/codecs/wav64.c +++ b/apps/codecs/wav64.c @@ -161,7 +161,7 @@ static uint8_t *read_buffer(size_t *realsize) /* 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 @@ enum codec_status codec_main(void) 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); diff --git a/apps/codecs/wavpack.c b/apps/codecs/wavpack.c index c85c254580..d27a9fb621 100644 --- a/apps/codecs/wavpack.c +++ b/apps/codecs/wavpack.c @@ -46,15 +46,16 @@ enum codec_status codec_main(void) /* 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 @@ enum codec_status codec_main(void) ci->set_elapsed (WavpackGetSampleIndex (wpc) / sr_100 * 10); ci->yield (); } - retval = CODEC_OK; done: if (ci->request_next_track()) diff --git a/apps/codecs/wma.c b/apps/codecs/wma.c index e740373cfc..1b46813444 100644 --- a/apps/codecs/wma.c +++ b/apps/codecs/wma.c @@ -46,19 +46,22 @@ enum codec_status codec_main(void) 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); - - retval = CODEC_OK; + 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; + restart_track: + retval = CODEC_OK; + if (codec_init()) { LOGF("WMA: Error initialising codec\n"); retval = CODEC_ERROR; @@ -176,7 +179,6 @@ new_packet: ci->advance_buffer(packetlength); } - retval = CODEC_OK; done: /*LOGF("WMA: Decoded %ld samples\n",elapsedtime*wfx.rate/1000);*/ diff --git a/apps/codecs/wmapro.c b/apps/codecs/wmapro.c index 75bbd24cda..c02dddeeb3 100644 --- a/apps/codecs/wmapro.c +++ b/apps/codecs/wmapro.c @@ -48,16 +48,18 @@ enum codec_status codec_main(void) next_track: + retval = CODEC_OK; /* Wait for the metadata to be read */ - while (!*ci->taginfo_ready && !ci->stop_codec) - ci->sleep(1); - - retval = CODEC_OK; + if (codec_wait_taginfo() != 0) + goto done; /* Remember the resume position */ resume_offset = ci->id3->offset; - restart_track: + +restart_track: + retval = CODEC_OK; + if (codec_init()) { LOGF("(WMA PRO) Error: Error initialising codec\n"); retval = CODEC_ERROR; @@ -149,7 +151,6 @@ next_track: /* Advance to the next logical packet */ ci->advance_buffer(packetlength); } - retval = CODEC_OK; done: if (ci->request_next_track()) diff --git a/apps/codecs/wmavoice.c b/apps/codecs/wmavoice.c index 904af23b99..ddf66828f1 100644 --- a/apps/codecs/wmavoice.c +++ b/apps/codecs/wmavoice.c @@ -70,16 +70,17 @@ enum codec_status codec_main(void) next_track: + retval = CODEC_OK; /* Wait for the metadata to be read */ - while (!*ci->taginfo_ready && !ci->stop_codec) - ci->sleep(1); - - retval = CODEC_OK; + if (codec_wait_taginfo() != 0) + goto done; /* Remember the resume position */ resume_offset = ci->id3->offset; - restart_track: +restart_track: + retval = CODEC_OK; + if (codec_init()) { LOGF("(WMA Voice) Error: Error initialising codec\n"); retval = CODEC_ERROR; @@ -184,7 +185,6 @@ new_packet: /* Advance to the next logical packet */ ci->advance_buffer(packetlength); } - retval = CODEC_OK; done: if (ci->request_next_track()) -- cgit v1.2.3