summaryrefslogtreecommitdiff
path: root/apps/codecs/a52_rm.c
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2011-04-27 03:08:23 +0000
committerMichael Sevakis <jethead71@rockbox.org>2011-04-27 03:08:23 +0000
commitc537d5958e8b421ac4f9bef6c8b9e7425a6cf167 (patch)
tree7ed36518fb6524da7bbd913ba7619b85b5d15d23 /apps/codecs/a52_rm.c
parentdcf0f8de4a37ff1d2ea510aef75fa67977a8bdcc (diff)
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
Diffstat (limited to 'apps/codecs/a52_rm.c')
-rw-r--r--apps/codecs/a52_rm.c77
1 files changed, 43 insertions, 34 deletions
diff --git a/apps/codecs/a52_rm.c b/apps/codecs/a52_rm.c
index f5e4923292..c1930aa7b4 100644
--- a/apps/codecs/a52_rm.c
+++ b/apps/codecs/a52_rm.c
@@ -124,36 +124,44 @@ static void a52_decode_data(uint8_t *start, uint8_t *end)
}
}
-
/* 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, 28);
+ }
+ else if (reason == CODEC_UNLOAD) {
+ if (state)
+ a52_free(state);
+ }
+
+ return CODEC_OK;
+}
+
+/* this is called for each file to process */
+enum codec_status codec_run(void)
{
size_t n;
uint8_t *filebuf;
- int retval, consumed, packet_offset;
+ int consumed, packet_offset;
int playback_on = -1;
size_t resume_offset;
-
- /* Generic codec initialisation */
- ci->configure(DSP_SET_STEREO_MODE, STEREO_NONINTERLEAVED);
- ci->configure(DSP_SET_SAMPLE_DEPTH, 28);
-
-next_track:
- retval = CODEC_OK;
+ intptr_t param;
+ enum codec_command_action action = CODEC_ACTION_NULL;
if (codec_init()) {
- retval = CODEC_ERROR;
- goto exit;
+ return CODEC_ERROR;
}
- if (codec_wait_taginfo() != 0)
- goto request_next_track;
-
resume_offset = ci->id3->offset;
ci->configure(DSP_SWITCH_FREQUENCY, ci->id3->frequency);
codec_set_replaygain(ci->id3);
+ ci->seek_buffer(ci->id3->first_frame_offset);
+
/* Intializations */
state = a52_init(0);
ci->memset(&rmctx,0,sizeof(RMContext));
@@ -165,26 +173,34 @@ next_track:
resume_offset -= rmctx.data_offset + DATA_HEADER_SIZE;
/* put number of subpackets to skip in resume_offset */
resume_offset /= (rmctx.block_align + PACKET_HEADER_SIZE);
- ci->seek_time = (int)resume_offset * ((rmctx.block_align * 8 * 1000)/rmctx.bit_rate);
+ param = (int)resume_offset * ((rmctx.block_align * 8 * 1000)/rmctx.bit_rate);
+ action = CODEC_ACTION_SEEK_TIME;
+ }
+ else {
+ /* Seek to the first packet */
+ ci->advance_buffer(rmctx.data_offset + DATA_HEADER_SIZE );
}
-
- /* Seek to the first packet */
- ci->advance_buffer(rmctx.data_offset + DATA_HEADER_SIZE );
/* The main decoding loop */
while((unsigned)rmctx.audio_pkt_cnt < rmctx.nb_packets) {
- ci->yield();
- if (ci->stop_codec || ci->new_track)
+ if (action == CODEC_ACTION_NULL)
+ action = ci->get_command(&param);
+
+ if (action == CODEC_ACTION_HALT)
break;
- if (ci->seek_time) {
- packet_offset = ci->seek_time / ((rmctx.block_align*8*1000)/rmctx.bit_rate);
- ci->seek_buffer(rmctx.data_offset + DATA_HEADER_SIZE + packet_offset*(rmctx.block_align + PACKET_HEADER_SIZE));
+ if (action == CODEC_ACTION_SEEK_TIME) {
+ packet_offset = param / ((rmctx.block_align*8*1000)/rmctx.bit_rate);
+ ci->seek_buffer(rmctx.data_offset + DATA_HEADER_SIZE +
+ packet_offset*(rmctx.block_align + PACKET_HEADER_SIZE));
rmctx.audio_pkt_cnt = packet_offset;
- samplesdone = (rmctx.sample_rate/1000 * ci->seek_time);
+ samplesdone = (rmctx.sample_rate/1000 * param);
+ ci->set_elapsed(samplesdone/(frequency/1000));
ci->seek_complete();
}
+ action = CODEC_ACTION_NULL;
+
filebuf = ci->request_buffer(&n, rmctx.block_align + PACKET_HEADER_SIZE);
consumed = rm_get_packet(&filebuf, &rmctx, &pkt);
@@ -195,8 +211,7 @@ next_track:
return CODEC_ERROR;
}
else {
- retval = CODEC_OK;
- goto exit;
+ break;
}
}
@@ -205,11 +220,5 @@ next_track:
ci->advance_buffer(pkt.length);
}
-request_next_track:
- if (ci->request_next_track())
- goto next_track;
-
-exit:
- a52_free(state);
- return retval;
+ return CODEC_OK;
}