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/wma.c | 77 +++++++++++++++++++++++++++---------------------------- 1 file changed, 38 insertions(+), 39 deletions(-) (limited to 'apps/codecs/wma.c') diff --git a/apps/codecs/wma.c b/apps/codecs/wma.c index 1b46813444..c327fafb5a 100644 --- a/apps/codecs/wma.c +++ b/apps/codecs/wma.c @@ -29,53 +29,52 @@ CODEC_HEADER static WMADecodeContext wmadec; /* 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_SAMPLE_DEPTH, 29); + } + + return CODEC_OK; +} + +/* this is called for each file to process */ +enum codec_status codec_run(void) { uint32_t elapsedtime; - int retval; asf_waveformatex_t wfx; size_t resume_offset; int i; - int wmares, res; + int wmares; + int res = 0; uint8_t* audiobuf; int audiobufsize; int packetlength = 0; int errcount = 0; - - /* Generic codec initialisation */ - ci->configure(DSP_SET_SAMPLE_DEPTH, 29); - -next_track: - retval = CODEC_OK; + intptr_t param; /* Proper reset of the decoder context. */ memset(&wmadec, 0, sizeof(wmadec)); - /* Wait for the metadata to be read */ - 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; - goto exit; + return CODEC_ERROR; } /* Copy the format metadata we've stored in the id3 TOC field. This saves us from parsing it again here. */ memcpy(&wfx, ci->id3->toc, sizeof(wfx)); + ci->seek_buffer(ci->id3->first_frame_offset); if (wma_decode_init(&wmadec,&wfx) < 0) { LOGF("WMA: Unsupported or corrupt file\n"); - retval = CODEC_ERROR; - goto exit; + return CODEC_ERROR; } if (resume_offset > ci->id3->first_frame_offset) @@ -101,34 +100,35 @@ restart_track: codec_set_replaygain(ci->id3); /* The main decoding loop */ - - res = 1; while (res >= 0) { - ci->yield(); - if (ci->stop_codec || ci->new_track) { - goto done; - } + enum codec_command_action action = ci->get_command(¶m); + + if (action == CODEC_ACTION_HALT) + break; /* Deal with any pending seek requests */ - if (ci->seek_time){ + if (action == CODEC_ACTION_SEEK_TIME) { - if (ci->seek_time == 1) { + if (param == 0) { + ci->set_elapsed(0); ci->seek_complete(); goto restart_track; /* Pretend you never saw this... */ } - elapsedtime = asf_seek(ci->seek_time, &wfx); + elapsedtime = asf_seek(param, &wfx); if (elapsedtime < 1){ + ci->set_elapsed(0); ci->seek_complete(); - goto next_track; + break; } /*DEBUGF("Seek returned %d\n", (int)elapsedtime);*/ - ci->set_elapsed(elapsedtime); /*flush the wma decoder state*/ wmadec.last_superframe_len = 0; wmadec.last_bitoffset = 0; + + ci->set_elapsed(elapsedtime); ci->seek_complete(); } errcount = 0; @@ -140,10 +140,15 @@ new_packet: * times. If we succeed, the error counter will be reset. */ + if (res == ASF_ERROR_EOF) { + /* File ended - not an error */ + break; + } + errcount++; DEBUGF("read_packet error %d, errcount %d\n",wmares, errcount); if (errcount > 5) { - goto done; + return CODEC_ERROR; } else { ci->advance_buffer(packetlength); goto new_packet; @@ -163,7 +168,7 @@ new_packet: errcount++; DEBUGF("WMA decode error %d, errcount %d\n",wmares, errcount); if (errcount > 5) { - goto done; + return CODEC_ERROR; } else { ci->advance_buffer(packetlength); goto new_packet; @@ -173,18 +178,12 @@ new_packet: elapsedtime += (wmares*10)/(wfx.rate/100); ci->set_elapsed(elapsedtime); } - ci->yield(); } } ci->advance_buffer(packetlength); } -done: /*LOGF("WMA: Decoded %ld samples\n",elapsedtime*wfx.rate/1000);*/ - - if (ci->request_next_track()) - goto next_track; -exit: - return retval; + return CODEC_OK; } -- cgit v1.2.3