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/speex.c | 61 ++++++++++++++++++++--------------------------------- 1 file changed, 23 insertions(+), 38 deletions(-) (limited to 'apps/codecs/speex.c') diff --git a/apps/codecs/speex.c b/apps/codecs/speex.c index 7a1efa9753..e394efc3d5 100644 --- a/apps/codecs/speex.c +++ b/apps/codecs/speex.c @@ -367,11 +367,12 @@ static void *process_header(spx_ogg_packet *op, return st; } -/* this is the codec entry point */ -enum codec_status codec_main(void) +/* this is called for each file to process */ +enum codec_status codec_run(void) { + int error = CODEC_ERROR; + SpeexBits bits; - int error; int eof = 0; spx_ogg_sync_state oy; spx_ogg_page og; @@ -383,7 +384,7 @@ enum codec_status codec_main(void) int eos = 0; SpeexStereoState *stereo; int channels = -1; - int rate = 0, samplerate = 0; + int samplerate = 0; int extra_headers = 0; int stream_init = 0; int page_nb_packets, frame_size, packet_count = 0; @@ -392,26 +393,22 @@ enum codec_status codec_main(void) unsigned long strtoffset = 0; void *st = NULL; int j = 0; + intptr_t param; memset(&bits, 0, sizeof(bits)); memset(&oy, 0, sizeof(oy)); /* 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; } + ci->seek_buffer(0); + stereo = speex_stereo_state_init(); spx_ogg_sync_init(&oy); spx_ogg_alloc_buffer(&oy,2*CHUNKSIZE); - if (codec_wait_taginfo() != 0) - goto done; - strtoffset = ci->id3->offset; samplerate = ci->id3->frequency; @@ -419,30 +416,32 @@ next_track: eof = 0; while (!eof) { - ci->yield(); - if (ci->stop_codec || ci->new_track) + enum codec_command_action action = ci->get_command(¶m); + + if (action == CODEC_ACTION_HALT) break; /*seek (seeks to the page before the position) */ - if (ci->seek_time) { + if (action == CODEC_ACTION_SEEK_TIME) { if(samplerate!=0&&packet_count>1){ LOGF("Speex seek page:%lld,%lld,%ld,%lld,%d\n", - ((spx_int64_t)ci->seek_time/1000) * + ((spx_int64_t)param/1000) * (spx_int64_t)samplerate, - page_granule, ci->seek_time, + page_granule, param, (page_granule/samplerate)*1000, samplerate); - speex_seek_page_granule(((spx_int64_t)ci->seek_time/1000) * + speex_seek_page_granule(((spx_int64_t)param/1000) * (spx_int64_t)samplerate, page_granule, &oy, headerssize); - ci->seek_complete(); } + + ci->set_elapsed(param); + ci->seek_complete(); } next_page: /*Get the ogg buffer for writing*/ if(get_more_data(&oy)<1){/*read error*/ - error=CODEC_ERROR; goto done; } @@ -477,8 +476,7 @@ next_page: nframes=1; if (!st){ - error=CODEC_ERROR; - goto exit; + goto done; } ci->configure(DSP_SET_FREQUENCY, ci->id3->frequency); @@ -557,31 +555,18 @@ next_page: } done: - if (ci->request_next_track()) { - - /* Clean things up for the next track */ + /* Clean things up for the next track */ + speex_bits_destroy(&bits); + if (st) if (st) speex_decoder_destroy(st); - if (stream_init == 1) - spx_ogg_stream_reset(&os); - - spx_ogg_sync_reset(&oy); - - cur_granule = stream_init = rate = samplerate = headerssize - = packet_count = eos = 0; - - goto next_track; - } - -exit: - speex_bits_destroy(&bits); - if (stream_init) spx_ogg_stream_destroy(&os); spx_ogg_sync_destroy(&oy); +exit: return error; } -- cgit v1.2.3