summaryrefslogtreecommitdiff
path: root/apps/codecs/smaf.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/smaf.c
parentdcf0f8de4a37ff1d2ea510aef75fa67977a8bdcc (diff)
downloadrockbox-c537d5958e8b421ac4f9bef6c8b9e7425a6cf167.zip
rockbox-c537d5958e8b421ac4f9bef6c8b9e7425a6cf167.tar.gz
rockbox-c537d5958e8b421ac4f9bef6c8b9e7425a6cf167.tar.bz2
rockbox-c537d5958e8b421ac4f9bef6c8b9e7425a6cf167.tar.xz
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/smaf.c')
-rw-r--r--apps/codecs/smaf.c82
1 files changed, 40 insertions, 42 deletions
diff --git a/apps/codecs/smaf.c b/apps/codecs/smaf.c
index 3e8a413..9211daa 100644
--- a/apps/codecs/smaf.c
+++ b/apps/codecs/smaf.c
@@ -332,9 +332,20 @@ static uint8_t *read_buffer(size_t *realsize)
return buffer;
}
-enum codec_status codec_main(void)
+/* this is the codec entry point */
+enum codec_status codec_main(enum codec_entry_call_reason reason)
+{
+ if (reason == CODEC_LOAD) {
+ /* Generic codec initialisation */
+ ci->configure(DSP_SET_SAMPLE_DEPTH, PCM_OUTPUT_DEPTH-1);
+ }
+
+ return CODEC_OK;
+}
+
+/* this is called for each file to process */
+enum codec_status codec_run(void)
{
- int status;
uint32_t decodedsamples;
size_t n;
int bufcount;
@@ -342,20 +353,10 @@ enum codec_status codec_main(void)
uint8_t *smafbuf;
off_t firstblockposn; /* position of the first block in file */
const struct pcm_codec *codec;
-
- /* Generic codec initialisation */
- ci->configure(DSP_SET_SAMPLE_DEPTH, PCM_OUTPUT_DEPTH-1);
+ intptr_t param;
-next_track:
- status = CODEC_OK;
-
- if (codec_init()) {
- status = CODEC_ERROR;
- goto exit;
- }
-
- if (codec_wait_taginfo() != 0)
- goto done;
+ if (codec_init())
+ return CODEC_ERROR;
codec_set_replaygain(ci->id3);
@@ -365,24 +366,22 @@ next_track:
decodedsamples = 0;
codec = 0;
+ ci->seek_buffer(0);
if (!parse_header(&format, &firstblockposn))
{
- status = CODEC_ERROR;
- goto done;
+ return CODEC_ERROR;
}
codec = get_codec(format.formattag);
if (codec == 0)
{
DEBUGF("CODEC_ERROR: unsupport audio format: 0x%x\n", (int)format.formattag);
- status = CODEC_ERROR;
- goto done;
+ return CODEC_ERROR;
}
if (!codec->set_format(&format))
{
- status = CODEC_ERROR;
- goto done;
+ return CODEC_ERROR;
}
/* check chunksize */
@@ -392,8 +391,7 @@ next_track:
if (format.chunksize == 0)
{
DEBUGF("CODEC_ERROR: chunksize is 0\n");
- status = CODEC_ERROR;
- goto done;
+ return CODEC_ERROR;
}
ci->configure(DSP_SWITCH_FREQUENCY, ci->id3->frequency);
@@ -404,12 +402,10 @@ next_track:
ci->configure(DSP_SET_STEREO_MODE, STEREO_MONO);
} else {
DEBUGF("CODEC_ERROR: more than 2 channels unsupported\n");
- status = CODEC_ERROR;
- goto done;
+ return CODEC_ERROR;
}
ci->seek_buffer(firstblockposn);
- ci->seek_complete();
/* make sure we're at the correct offset */
if (bytesdone > (uint32_t) firstblockposn)
@@ -419,13 +415,13 @@ next_track:
PCM_SEEK_POS, &read_buffer);
if (newpos->pos > format.numbytes)
- goto done;
+ return CODEC_OK;
+
if (ci->seek_buffer(firstblockposn + newpos->pos))
{
bytesdone = newpos->pos;
decodedsamples = newpos->samples;
}
- ci->seek_complete();
}
else
{
@@ -437,23 +433,32 @@ next_track:
endofstream = 0;
while (!endofstream) {
- ci->yield();
- if (ci->stop_codec || ci->new_track)
+ enum codec_command_action action = ci->get_command(&param);
+
+ if (action == CODEC_ACTION_HALT)
break;
- if (ci->seek_time) {
- struct pcm_pos *newpos = codec->get_seek_pos(ci->seek_time, PCM_SEEK_TIME,
+ if (action == CODEC_ACTION_SEEK_TIME) {
+ struct pcm_pos *newpos = codec->get_seek_pos(param, PCM_SEEK_TIME,
&read_buffer);
if (newpos->pos > format.numbytes)
+ {
+ ci->set_elapsed(ci->id3->length);
+ ci->seek_complete();
break;
+ }
+
if (ci->seek_buffer(firstblockposn + newpos->pos))
{
bytesdone = newpos->pos;
decodedsamples = newpos->samples;
}
+
+ ci->set_elapsed(decodedsamples*1000LL/ci->id3->frequency);
ci->seek_complete();
}
+
smafbuf = (uint8_t *)ci->request_buffer(&n, format.chunksize);
if (n == 0)
@@ -464,11 +469,10 @@ next_track:
endofstream = 1;
}
- status = codec->decode(smafbuf, n, samples, &bufcount);
- if (status == CODEC_ERROR)
+ if (codec->decode(smafbuf, n, samples, &bufcount) == CODEC_ERROR)
{
DEBUGF("codec error\n");
- goto done;
+ return CODEC_ERROR;
}
ci->pcmbuf_insert(samples, NULL, bufcount);
@@ -482,11 +486,5 @@ next_track:
ci->set_elapsed(decodedsamples*1000LL/ci->id3->frequency);
}
-done:
- if (ci->request_next_track())
- goto next_track;
-
-exit:
- return status;
+ return CODEC_OK;
}
-