From c537d5958e8b421ac4f9bef6c8b9e7425a6cf167 Mon Sep 17 00:00:00 2001 From: Michael Sevakis Date: Wed, 27 Apr 2011 03:08:23 +0000 Subject: Commit FS#12069 - Playback rework - first stages. Gives as thorough as possible a treatment of codec management, track change and metadata logic as possible while maintaining fairly narrow focus and not rewriting everything all at once. Please see the rockbox-dev mail archive on 2011-04-25 (Playback engine rework) for a more thorough manifest of what was addressed. Plugins and codecs become incompatible. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29785 a1c6a512-1295-4272-9138-f99709370657 --- apps/codecs/aac.c | 62 ++++++++++++++++++++++++------------------------------- 1 file changed, 27 insertions(+), 35 deletions(-) (limited to 'apps/codecs/aac.c') diff --git a/apps/codecs/aac.c b/apps/codecs/aac.c index 5638dc49a9..90cf0438ce 100644 --- a/apps/codecs/aac.c +++ b/apps/codecs/aac.c @@ -33,7 +33,19 @@ CODEC_HEADER #define FAAD_BYTE_BUFFER_SIZE (2048-12) /* this is the codec entry point */ -enum codec_status codec_main(void) +enum codec_status codec_main(enum codec_entry_call_reason reason) +{ + if (reason == CODEC_LOAD) { + /* Generic codec initialisation */ + ci->configure(DSP_SET_STEREO_MODE, STEREO_NONINTERLEAVED); + ci->configure(DSP_SET_SAMPLE_DEPTH, 29); + } + + return CODEC_OK; +} + +/* this is called for each file to process */ +enum codec_status codec_run(void) { /* Note that when dealing with QuickTime/MPEG4 files, terminology is * a bit confusing. Files with sound are split up in chunks, where @@ -59,25 +71,15 @@ enum codec_status codec_main(void) uint32_t sbr_fac = 1; unsigned char c = 0; void *ret; - - /* Generic codec initialisation */ - ci->configure(DSP_SET_STEREO_MODE, STEREO_NONINTERLEAVED); - ci->configure(DSP_SET_SAMPLE_DEPTH, 29); - -next_track: - err = CODEC_OK; + intptr_t param; /* Clean and initialize decoder structures */ memset(&demux_res , 0, sizeof(demux_res)); if (codec_init()) { LOGF("FAAD: Codec init error\n"); - err = CODEC_ERROR; - goto exit; + return CODEC_ERROR; } - if (codec_wait_taginfo() != 0) - goto done; - file_offset = ci->id3->offset; ci->configure(DSP_SWITCH_FREQUENCY, ci->id3->frequency); @@ -85,12 +87,13 @@ next_track: stream_create(&input_stream,ci); + ci->seek_buffer(ci->id3->first_frame_offset); + /* if qtmovie_read returns successfully, the stream is up to * the movie data, which can be used directly by the decoder */ if (!qtmovie_read(&input_stream, &demux_res)) { LOGF("FAAD: File init error\n"); - err = CODEC_ERROR; - goto done; + return CODEC_ERROR; } /* initialise the sound converter */ @@ -98,8 +101,7 @@ next_track: if (!decoder) { LOGF("FAAD: Decode open error\n"); - err = CODEC_ERROR; - goto done; + return CODEC_ERROR; } NeAACDecConfigurationPtr conf = NeAACDecGetCurrentConfiguration(decoder); @@ -109,8 +111,7 @@ next_track: err = NeAACDecInit2(decoder, demux_res.codecdata, demux_res.codecdata_len, &s, &c); if (err) { LOGF("FAAD: DecInit: %d, %d\n", err, decoder->object_type); - err = CODEC_ERROR; - goto done; + return CODEC_ERROR; } #ifdef SBR_DEC @@ -150,20 +151,19 @@ next_track: /* The main decoding loop */ while (i < demux_res.num_sample_byte_sizes) { - ci->yield(); + enum codec_command_action action = ci->get_command(¶m); - if (ci->stop_codec || ci->new_track) { + if (action == CODEC_ACTION_HALT) break; - } /* Deal with any pending seek requests */ - if (ci->seek_time) { + if (action == CODEC_ACTION_SEEK_TIME) { /* Seek to the desired time position. Important: When seeking in SBR * upsampling files the seek_time must be divided by 2 when calling * m4a_seek and the resulting sound_samples_done must be expanded * by a factor 2. This is done via using sbr_fac. */ if (m4a_seek(&demux_res, &input_stream, - ((ci->seek_time-1)/10/sbr_fac)*(ci->id3->frequency/100), + (param/10/sbr_fac)*(ci->id3->frequency/100), &sound_samples_done, (int*) &i)) { sound_samples_done *= sbr_fac; elapsed_time = (sound_samples_done * 10) / (ci->id3->frequency / 100); @@ -194,8 +194,7 @@ next_track: else if (file_offset == 0) { LOGF("AAC: get_sample_offset error\n"); - err = CODEC_ERROR; - goto done; + return CODEC_ERROR; } /* Request the required number of bytes from the input buffer */ @@ -207,8 +206,7 @@ next_track: /* NeAACDecDecode may sometimes return NULL without setting error. */ if (ret == NULL || frame_info.error > 0) { LOGF("FAAD: decode error '%s'\n", NeAACDecGetErrorMessage(frame_info.error)); - err = CODEC_ERROR; - goto done; + return CODEC_ERROR; } /* Advance codec buffer (no need to call set_offset because of this) */ @@ -251,12 +249,6 @@ next_track: i++; } -done: LOGF("AAC: Decoded %lu samples\n", (unsigned long)sound_samples_done); - - if (ci->request_next_track()) - goto next_track; - -exit: - return err; + return CODEC_OK; } -- cgit v1.2.3