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/wavpack_enc.c | 112 +++++++++++++++++++++++----------------------- 1 file changed, 57 insertions(+), 55 deletions(-) (limited to 'apps/codecs/wavpack_enc.c') diff --git a/apps/codecs/wavpack_enc.c b/apps/codecs/wavpack_enc.c index d908e284be..730cf0734b 100644 --- a/apps/codecs/wavpack_enc.c +++ b/apps/codecs/wavpack_enc.c @@ -389,77 +389,79 @@ static bool init_encoder(void) return true; } /* init_encoder */ -enum codec_status codec_main(void) +/* this is the codec entry point */ +enum codec_status codec_main(enum codec_entry_call_reason reason) { - /* initialize params and config */ - if (!init_encoder()) - return CODEC_ERROR; + if (reason == CODEC_LOAD) { + /* initialize params and config */ + if (!init_encoder()) + return CODEC_ERROR; + } + else if (reason == CODEC_UNLOAD) { + /* reset parameters to initial state */ + ci->enc_set_parameters(NULL); + } + return CODEC_OK; +} + +/* this is called for each file to process */ +enum codec_status codec_run(void) +{ /* main encoding loop */ - while(!ci->stop_codec) + while(ci->get_command(NULL) != CODEC_ACTION_HALT) { - uint8_t *src; + uint8_t *src = (uint8_t *)ci->enc_get_pcm_data(PCM_CHUNK_SIZE); + struct enc_chunk_hdr *chunk; + bool abort_chunk; + uint8_t *dst; + uint8_t *src_end; - while ((src = ci->enc_get_pcm_data(PCM_CHUNK_SIZE)) != NULL) - { - struct enc_chunk_hdr *chunk; - bool abort_chunk; - uint8_t *dst; - uint8_t *src_end; - - if(ci->stop_codec) - break; - - abort_chunk = true; + if(src == NULL) + continue; - chunk = ci->enc_get_chunk(); + chunk = ci->enc_get_chunk(); - /* reset counts and pointer */ - chunk->enc_size = 0; - chunk->num_pcm = 0; - chunk->enc_data = NULL; + /* reset counts and pointer */ + chunk->enc_size = 0; + chunk->num_pcm = 0; + chunk->enc_data = NULL; - dst = ENC_CHUNK_SKIP_HDR(dst, chunk); + dst = ENC_CHUNK_SKIP_HDR(dst, chunk); - WavpackStartBlock(wpc, dst, dst + data_size); + WavpackStartBlock(wpc, dst, dst + data_size); - chunk_to_int32((uint32_t*)src); - src = input_buffer; - src_end = src + input_size; + chunk_to_int32((uint32_t*)src); + src = input_buffer; + src_end = src + input_size; - /* encode chunk in four steps yielding between each */ - do + /* encode chunk in four steps yielding between each */ + do + { + abort_chunk = true; + if (WavpackPackSamples(wpc, (int32_t *)src, + PCM_SAMP_PER_CHUNK/4)) { - if (WavpackPackSamples(wpc, (int32_t *)src, - PCM_SAMP_PER_CHUNK/4)) - { - chunk->num_pcm += PCM_SAMP_PER_CHUNK/4; - ci->yield(); - /* could've been stopped in some way */ - abort_chunk = ci->stop_codec || - (chunk->flags & CHUNKF_ABORT); - } - - src += input_step; + chunk->num_pcm += PCM_SAMP_PER_CHUNK/4; + ci->yield(); + /* could've been stopped in some way */ + abort_chunk = chunk->flags & CHUNKF_ABORT; } - while (!abort_chunk && src < src_end); - if (!abort_chunk) - { - chunk->enc_data = dst; - if (chunk->num_pcm < PCM_SAMP_PER_CHUNK) - ci->enc_unget_pcm_data(PCM_CHUNK_SIZE - chunk->num_pcm*4); - /* finish the chunk and store chunk size info */ - chunk->enc_size = WavpackFinishBlock(wpc); - ci->enc_finish_chunk(); - } + src += input_step; } + while (!abort_chunk && src < src_end); - ci->yield(); + if (!abort_chunk) + { + chunk->enc_data = dst; + if (chunk->num_pcm < PCM_SAMP_PER_CHUNK) + ci->enc_unget_pcm_data(PCM_CHUNK_SIZE - chunk->num_pcm*4); + /* finish the chunk and store chunk size info */ + chunk->enc_size = WavpackFinishBlock(wpc); + ci->enc_finish_chunk(); + } } - /* reset parameters to initial state */ - ci->enc_set_parameters(NULL); - return CODEC_OK; -} /* codec_start */ +} -- cgit v1.2.3