diff options
author | Brandon Low <lostlogic@rockbox.org> | 2006-01-18 20:22:03 +0000 |
---|---|---|
committer | Brandon Low <lostlogic@rockbox.org> | 2006-01-18 20:22:03 +0000 |
commit | 1060e447f83128a78dfaa8d59ba0baa642d15a4d (patch) | |
tree | 9af0876f9c5d0ad5cb8bfc2adc7b1653c43013ff /apps | |
parent | 3ded3cea756d8290372b808884837931a7e8cf1a (diff) |
Part of the profiling patch to use a consistent return path in all codecs to facilitate 'on exit' functionality
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8374 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps')
-rw-r--r-- | apps/codecs/a52.c | 11 | ||||
-rw-r--r-- | apps/codecs/aac.c | 22 | ||||
-rw-r--r-- | apps/codecs/alac.c | 17 | ||||
-rw-r--r-- | apps/codecs/flac.c | 16 | ||||
-rw-r--r-- | apps/codecs/mpa.c | 7 | ||||
-rw-r--r-- | apps/codecs/mpc.c | 33 | ||||
-rw-r--r-- | apps/codecs/shorten.c | 14 | ||||
-rw-r--r-- | apps/codecs/vorbis.c | 14 | ||||
-rw-r--r-- | apps/codecs/wav.c | 55 | ||||
-rw-r--r-- | apps/codecs/wavpack.c | 17 |
10 files changed, 141 insertions, 65 deletions
diff --git a/apps/codecs/a52.c b/apps/codecs/a52.c index f12fce1027..ff8fe0afea 100644 --- a/apps/codecs/a52.c +++ b/apps/codecs/a52.c @@ -129,6 +129,7 @@ enum codec_status codec_start(struct codec_api *api) long n; unsigned char *filebuf; int sample_loc; + int retval; /* Generic codec initialisation */ ci = api; @@ -147,8 +148,10 @@ enum codec_status codec_start(struct codec_api *api) ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (long *)(1024*128)); next_track: - if (codec_init(api)) - return CODEC_ERROR; + if (codec_init(api)) { + retval = CODEC_ERROR; + goto exit; + } while (!ci->taginfo_ready) ci->yield(); @@ -184,6 +187,8 @@ next_track: } if (ci->request_next_track()) goto next_track; + retval = CODEC_OK; +exit: a52_free(state); - return CODEC_OK; + return retval; } diff --git a/apps/codecs/aac.c b/apps/codecs/aac.c index baa3935175..06a0e16527 100644 --- a/apps/codecs/aac.c +++ b/apps/codecs/aac.c @@ -72,7 +72,8 @@ enum codec_status codec_start(struct codec_api* api) if (codec_init(api)) { LOGF("FAAD: Error initialising codec\n"); - return CODEC_ERROR; + err = CODEC_ERROR; + goto exit; } while (!rb->taginfo_ready) @@ -86,7 +87,8 @@ enum codec_status codec_start(struct codec_api* api) * the movie data, which can be used directly by the decoder */ if (!qtmovie_read(&input_stream, &demux_res)) { LOGF("FAAD: Error initialising file\n"); - return CODEC_ERROR; + err = CODEC_ERROR; + goto exit; } /* initialise the sound converter */ @@ -95,7 +97,8 @@ enum codec_status codec_start(struct codec_api* api) if (!hDecoder) { LOGF("FAAD: Error opening decoder\n"); - return CODEC_ERROR; + err = CODEC_ERROR; + goto exit; } NeAACDecConfigurationPtr conf = NeAACDecGetCurrentConfiguration(hDecoder); @@ -108,7 +111,8 @@ enum codec_status codec_start(struct codec_api* api) err = NeAACDecInit2(hDecoder, demux_res.codecdata,demux_res.codecdata_len, &s, &c); if (err) { LOGF("FAAD: Error initialising decoder: %d, type=%d\n", err,hDecoder->object_type); - return CODEC_ERROR; + err = CODEC_ERROR; + goto exit; } ci->id3->frequency=s; @@ -137,7 +141,8 @@ enum codec_status codec_start(struct codec_api* api) if (!get_sample_info(&demux_res, i, &sample_duration, &sample_byte_size)) { LOGF("AAC: Error in get_sample_info\n"); - return CODEC_ERROR; + err = CODEC_ERROR; + goto exit; } /* Request the required number of bytes from the input buffer */ @@ -150,7 +155,8 @@ enum codec_status codec_start(struct codec_api* api) decoder struct directly */ if (frameInfo.error > 0) { LOGF("FAAD: decoding error \"%s\"\n", NeAACDecGetErrorMessage(frameInfo.error)); - return CODEC_ERROR; + err = CODEC_ERROR; + goto exit; } /* Get the number of decoded samples */ @@ -182,5 +188,7 @@ enum codec_status codec_start(struct codec_api* api) if (ci->request_next_track()) goto next_track; - return CODEC_OK; + err = CODEC_OK; +exit: + return err; } diff --git a/apps/codecs/alac.c b/apps/codecs/alac.c index 7ca70ce83c..a1c4f41683 100644 --- a/apps/codecs/alac.c +++ b/apps/codecs/alac.c @@ -50,6 +50,7 @@ enum codec_status codec_start(struct codec_api* api) unsigned int i; unsigned char* buffer; alac_file alac; + int retval; /* Generic codec initialisation */ rb = api; @@ -72,7 +73,8 @@ enum codec_status codec_start(struct codec_api* api) if (codec_init(api)) { LOGF("ALAC: Error initialising codec\n"); - return CODEC_ERROR; + retval = CODEC_ERROR; + goto exit; } while (!rb->taginfo_ready) @@ -86,7 +88,8 @@ enum codec_status codec_start(struct codec_api* api) * the movie data, which can be used directly by the decoder */ if (!qtmovie_read(&input_stream, &demux_res)) { LOGF("ALAC: Error initialising file\n"); - return CODEC_ERROR; + retval = CODEC_ERROR; + goto exit; } /* initialise the sound converter */ @@ -117,14 +120,16 @@ enum codec_status codec_start(struct codec_api* api) if (!get_sample_info(&demux_res, i, &sample_duration, &sample_byte_size)) { LOGF("ALAC: Error in get_sample_info\n"); - return CODEC_ERROR; + retval = CODEC_ERROR; + goto exit; } /* Request the required number of bytes from the input buffer */ buffer=ci->request_buffer((long*)&n,sample_byte_size); if (n!=sample_byte_size) { - return CODEC_ERROR; + retval = CODEC_ERROR; + goto exit; } /* Decode one block - returned samples will be host-endian */ @@ -157,5 +162,7 @@ enum codec_status codec_start(struct codec_api* api) if (ci->request_next_track()) goto next_track; - return CODEC_OK; + retval = CODEC_OK; +exit: + return retval; } diff --git a/apps/codecs/flac.c b/apps/codecs/flac.c index a96963dd80..4782c95d55 100644 --- a/apps/codecs/flac.c +++ b/apps/codecs/flac.c @@ -226,6 +226,7 @@ enum codec_status codec_start(struct codec_api* api) int consumed; int res; int frame; + int retval; /* Generic codec initialisation */ rb = api; @@ -243,17 +244,19 @@ enum codec_status codec_start(struct codec_api* api) ci->configure(DSP_DITHER, (bool *)false); ci->configure(DSP_SET_STEREO_MODE, (long *)STEREO_NONINTERLEAVED); ci->configure(DSP_SET_SAMPLE_DEPTH, (int *)(FLAC_OUTPUT_DEPTH-1)); - + next_track: if (codec_init(api)) { LOGF("FLAC: Error initialising codec\n"); - return CODEC_ERROR; + retval = CODEC_ERROR; + goto exit; } if (!flac_init(&fc,ci->id3->first_frame_offset)) { LOGF("FLAC: Error initialising codec\n"); - return CODEC_ERROR; + retval = CODEC_ERROR; + goto exit; } while (!*ci->taginfo_ready) @@ -284,7 +287,8 @@ enum codec_status codec_start(struct codec_api* api) if((res=flac_decode_frame(&fc,decoded0,decoded1,buf, bytesleft,ci->yield)) < 0) { LOGF("FLAC: Frame %d, error %d\n",frame,res); - return CODEC_ERROR; + retval = CODEC_ERROR; + goto exit; } consumed=fc.gb.index/8; frame++; @@ -309,5 +313,7 @@ enum codec_status codec_start(struct codec_api* api) if (ci->request_next_track()) goto next_track; - return CODEC_OK; + retval = CODEC_OK; +exit: + return retval; } diff --git a/apps/codecs/mpa.c b/apps/codecs/mpa.c index 3c57f3f33f..3ee2b352f1 100644 --- a/apps/codecs/mpa.c +++ b/apps/codecs/mpa.c @@ -75,7 +75,7 @@ void recalc_samplecount(void) /* this is the codec entry point */ enum codec_status codec_start(struct codec_api *api) { - int status = 0; + int status = CODEC_OK; long size; int file_end; int frame_skip; /* samples to skip current frame */ @@ -193,7 +193,7 @@ next_track: continue; } else { /* Some other unrecoverable error */ - status = 1; + status = CODEC_ERROR; break; } break; @@ -264,5 +264,6 @@ next_track: if (ci->request_next_track()) goto next_track; - return CODEC_OK; + + return status; } diff --git a/apps/codecs/mpc.c b/apps/codecs/mpc.c index 1d1ed3a8b7..67c0eaa3de 100644 --- a/apps/codecs/mpc.c +++ b/apps/codecs/mpc.c @@ -83,6 +83,7 @@ enum codec_status codec_start(struct codec_api *api) unsigned status; mpc_reader reader; mpc_streaminfo info; + int retval; #ifdef USE_IRAM ci->memcpy(iramstart, iramcopy, iramend - iramstart); @@ -111,13 +112,17 @@ enum codec_status codec_start(struct codec_api *api) reader.data = ci; next_track: - if (codec_init(api)) - return CODEC_ERROR; + if (codec_init(api)) { + retval = CODEC_ERROR; + goto exit; + } /* read file's streaminfo data */ mpc_streaminfo_init(&info); - if (mpc_streaminfo_read(&info, &reader) != ERROR_CODE_OK) - return CODEC_ERROR; + if (mpc_streaminfo_read(&info, &reader) != ERROR_CODE_OK) { + retval = CODEC_ERROR; + goto exit; + } frequency = info.sample_freq; ci->configure(DSP_SET_FREQUENCY, (long *)info.sample_freq); @@ -128,14 +133,18 @@ next_track: ci->configure(DSP_SET_STEREO_MODE, (long *)STEREO_NONINTERLEAVED); else if (info.channels == 1) ci->configure(DSP_SET_STEREO_MODE, (long *)STEREO_MONO); - else - return CODEC_ERROR; + else { + retval = CODEC_ERROR; + goto exit; + } codec_set_replaygain(ci->id3); /* instantiate a decoder with our file reader */ mpc_decoder_setup(&decoder, &reader); - if (!mpc_decoder_initialize(&decoder, &info)) - return CODEC_ERROR; + if (!mpc_decoder_initialize(&decoder, &info)) { + retval = CODEC_ERROR; + goto exit; + } /* This is the decoding loop. */ samplesdone = 0; @@ -169,7 +178,8 @@ next_track: status = mpc_decoder_decode(&decoder, sample_buffer, NULL, NULL); ci->yield(); if (status == (unsigned)(-1)) { /* decode error */ - return CODEC_ERROR; + retval = CODEC_ERROR; + goto exit; } else { while (!ci->pcmbuf_insert_split(sample_buffer, sample_buffer + MPC_FRAME_LENGTH, @@ -182,6 +192,9 @@ next_track: if (ci->request_next_track()) goto next_track; - return CODEC_OK; + + retval = CODEC_OK; +exit: + return retval; } diff --git a/apps/codecs/shorten.c b/apps/codecs/shorten.c index ffbd42a9ff..290686e968 100644 --- a/apps/codecs/shorten.c +++ b/apps/codecs/shorten.c @@ -50,6 +50,7 @@ enum codec_status codec_start(struct codec_api* api) int8_t *buf; int cur_chan, consumed, res; long bytesleft; + int retval; /* Generic codec initialisation */ rb = api; @@ -72,7 +73,8 @@ next_track: /* Codec initialization */ if (codec_init(api)) { LOGF("Shorten: Error initialising codec\n"); - return CODEC_ERROR; + retval = CODEC_ERROR; + goto exit; } while (!*ci->taginfo_ready) @@ -92,7 +94,8 @@ next_track: res = shorten_init(&sc, (unsigned char *)buf, bytesleft); if (res < 0) { LOGF("shorten_init error: %d\n", res); - return CODEC_ERROR; + retval = CODEC_ERROR; + goto exit; } ci->id3->frequency = sc.sample_rate; @@ -169,7 +172,8 @@ seek_start: break; } else if (res < 0) { LOGF("shorten_decode_frame error: \n", res); - return CODEC_ERROR; + retval = CODEC_ERROR; + goto exit; } consumed = sc.gb.index/8; @@ -183,5 +187,7 @@ seek_start: if (ci->request_next_track()) goto next_track; - return CODEC_OK; + retval = CODEC_OK; +exit: + return retval; } diff --git a/apps/codecs/vorbis.c b/apps/codecs/vorbis.c index fdd7a952d4..e77ecada0c 100644 --- a/apps/codecs/vorbis.c +++ b/apps/codecs/vorbis.c @@ -145,11 +145,11 @@ enum codec_status codec_start(struct codec_api *api) */ rb->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (long *)(1024*256)); - /* We need to flush reserver memory every track load. */ next_track: if (codec_init(rb)) { - return CODEC_ERROR; + error = CODEC_ERROR; + goto exit; } while (!*rb->taginfo_ready && !rb->stop_codec) @@ -195,7 +195,8 @@ next_track: vf.links = 1; } else { //rb->logf("ov_open: %d", error); - return CODEC_ERROR; + error = CODEC_ERROR; + goto exit; } if (rb->id3->offset) { @@ -224,7 +225,8 @@ next_track: /* Change DSP and buffer settings for this bitstream */ if (current_section != previous_section) { if (!vorbis_set_codec_parameters(&vf)) { - return CODEC_ERROR; + error = CODEC_ERROR; + goto exit; } else { previous_section = current_section; } @@ -255,6 +257,8 @@ next_track: goto next_track; } - return CODEC_OK; + error = CODEC_OK; +exit: + return error; } diff --git a/apps/codecs/wav.c b/apps/codecs/wav.c index 1dda2c3d58..ca4b4750f4 100644 --- a/apps/codecs/wav.c +++ b/apps/codecs/wav.c @@ -248,7 +248,8 @@ enum codec_status codec_start(struct codec_api* api) next_track: if (codec_init(api)) { - return CODEC_ERROR; + i = CODEC_ERROR; + goto exit; } while (!*ci->taginfo_ready) @@ -257,10 +258,12 @@ enum codec_status codec_start(struct codec_api* api) /* assume the WAV header is less than 1024 bytes */ buf=ci->request_buffer((long *)&n,1024); if (n<44) { - return CODEC_ERROR; + i = CODEC_ERROR; + goto exit; } if ((memcmp(buf,"RIFF",4)!=0) || (memcmp(&buf[8],"WAVE",4)!=0)) { - return CODEC_ERROR; + i = CODEC_ERROR; + goto exit; } buf += 12; @@ -275,7 +278,8 @@ enum codec_status codec_start(struct codec_api* api) if (memcmp(buf,"fmt ",4)==0) { if (i<16) { DEBUGF("CODEC_ERROR: 'fmt ' chunk size=%lu < 16\n",i); - return CODEC_ERROR; + i = CODEC_ERROR; + goto exit; } /* wFormatTag */ formattag=buf[8]|(buf[9]<<8); @@ -302,7 +306,8 @@ enum codec_status codec_start(struct codec_api* api) if (size < 2) { DEBUGF("CODEC_ERROR: dvi_adpcm is missing " "SamplesPerBlock value\n"); - return CODEC_ERROR; + i = CODEC_ERROR; + goto exit; } samplesperblock = buf[26]|(buf[27]<<8); } @@ -310,7 +315,8 @@ enum codec_status codec_start(struct codec_api* api) if (size < 22) { DEBUGF("CODEC_ERROR: WAVE_FORMAT_EXTENSIBLE is " "missing extension\n"); - return CODEC_ERROR; + i = CODEC_ERROR; + goto exit; } /* wValidBitsPerSample */ bitspersample = buf[26]|(buf[27]<<8); @@ -340,18 +346,21 @@ enum codec_status codec_start(struct codec_api* api) buf += i+8; if (n < (i+8)) { DEBUGF("CODEC_ERROR: WAVE header size > 1024\n"); - return CODEC_ERROR; + i = CODEC_ERROR; + goto exit; } n -= i+8; } if (channels == 0) { DEBUGF("CODEC_ERROR: 'fmt ' chunk not found or 0-channels file\n"); - return CODEC_ERROR; + i = CODEC_ERROR; + goto exit; } if (numbytes == 0) { DEBUGF("CODEC_ERROR: 'data' chunk not found or has zero-length\n"); - return CODEC_ERROR; + i = CODEC_ERROR; + goto exit; } if (formattag != WAVE_FORMAT_PCM && totalsamples == 0) { /* This is non-fatal for some formats */ @@ -361,19 +370,22 @@ enum codec_status codec_start(struct codec_api* api) formattag == IBM_FORMAT_ALAW || formattag == IBM_FORMAT_MULAW) { if (bitspersample != 8) { DEBUGF("CODEC_ERROR: alaw and mulaw must have 8 bitspersample\n"); - return CODEC_ERROR; + i = CODEC_ERROR; + goto exit; } bytespersample = channels; } if ( formattag == WAVE_FORMAT_DVI_ADPCM && bitspersample != 4 && bitspersample != 3) { DEBUGF("CODEC_ERROR: dvi_adpcm must have 3 or 4 bitspersample\n"); - return CODEC_ERROR; + i = CODEC_ERROR; + goto exit; } if (formattag == WAVE_FORMAT_PCM && bitspersample > 32) { DEBUGF("CODEC_ERROR: pcm with more than 32 bitspersample " "is unsupported\n"); - return CODEC_ERROR; + i = CODEC_ERROR; + goto exit; } ci->configure(CODEC_DSP_ENABLE, (bool *)true); @@ -395,7 +407,8 @@ enum codec_status codec_start(struct codec_api* api) ci->configure(DSP_SET_STEREO_MODE, (int *)STEREO_MONO); } else { DEBUGF("CODEC_ERROR: more than 2 channels\n"); - return CODEC_ERROR; + i = CODEC_ERROR; + goto exit; } if (totalsamples == 0) { @@ -408,7 +421,8 @@ enum codec_status codec_start(struct codec_api* api) } else { DEBUGF("CODEC_ERROR: cannot compute totalsamples\n"); - return CODEC_ERROR; + i = CODEC_ERROR; + goto exit; } } @@ -519,15 +533,18 @@ enum codec_status codec_start(struct codec_api* api) int16_samples+i*samplesperblock*channels, &decodedsize) != CODEC_OK) - return CODEC_ERROR; + i = CODEC_ERROR; + goto exit; if (decodedsize != samplesperblock) - return CODEC_ERROR; + i = CODEC_ERROR; + goto exit; } wavbufsize = nblocks*samplesperblock*channels*2; } else { DEBUGF("CODEC_ERROR: unsupported format %x\n", formattag); - return CODEC_ERROR; + i = CODEC_ERROR; + goto exit; } while (!ci->pcmbuf_insert((char*)int16_samples, wavbufsize)) { @@ -546,7 +563,9 @@ enum codec_status codec_start(struct codec_api* api) if (ci->request_next_track()) goto next_track; - return CODEC_OK; + i = CODEC_OK; +exit: + return i; } static enum codec_status diff --git a/apps/codecs/wavpack.c b/apps/codecs/wavpack.c index 2804d3ef72..19c7581e29 100644 --- a/apps/codecs/wavpack.c +++ b/apps/codecs/wavpack.c @@ -52,6 +52,7 @@ enum codec_status codec_start(struct codec_api* api) WavpackContext *wpc; char error [80]; int bps, nchans, sr_100; + int retval; /* Generic codec initialisation */ ci = api; @@ -70,8 +71,10 @@ enum codec_status codec_start(struct codec_api* api) next_track: - if (codec_init(api)) - return CODEC_ERROR; + if (codec_init(api)) { + retval = CODEC_ERROR; + goto exit; + } while (!*ci->taginfo_ready && !ci->stop_codec) ci->sleep(1); @@ -94,8 +97,10 @@ enum codec_status codec_start(struct codec_api* api) /* Create a decoder instance */ wpc = WavpackOpenFileInput (read_callback, error); - if (!wpc) - return CODEC_ERROR; + if (!wpc) { + retval = CODEC_ERROR; + goto exit; + } bps = WavpackGetBytesPerSample (wpc); nchans = WavpackGetReducedChannels (wpc); @@ -206,5 +211,7 @@ enum codec_status codec_start(struct codec_api* api) if (ci->request_next_track()) goto next_track; - return CODEC_OK; + retval = CODEC_OK; +exit: + return retval; } |