Update software recording engine to latest codec interface.

Basically, just give it a good rewrite.

Software codec recording can be implemented in a more straightforward
and simple manner and made more robust through the better codec
control now available.

Encoded audio buffer uses a packed format instead of fixed-size
chunks and uses smaller data headers leading to more efficient usage.
The greatest benefit is with a VBR format like wavpack which needs
to request a maximum size but only actually ends up committing part
of that request.

No guard buffers are used for either PCM or encoded audio. PCM is
read into the codec's provided buffer and mono conversion done at
that time in the core if required. Any highly-specialized sample
conversion is still done within the codec itself, such as 32-bit
(wavpack) or interleaved mono (mp3).

There is no longer a separate filename array. All metadata goes
onto the main encoded audio buffer, eliminating any predermined
file limit on the buffer as well as not wasting the space for
unused path queue slots.

The core and codec interface is less awkward and a bit more sensible.
Some less useful interface features were removed. Threads are kept
on narrow code paths ie. the audio thread never calls encoding
functions and the codec thread never calls file functions as before.

Codecs no longer call file functions directly. Writes are buffered
in the core and data written to storage in larger chunks to speed up
flushing of data. In fact, codecs are no longer aware of the stream
being a file at all and have no access to the fd.

SPDIF frequency detection no longer requires a restart of recording
or plugging the source before entering the screen. It will poll
for changes and update when stopped or prerecording (which does
discard now-invalid prerecorded data).

I've seen to it that writing a proper header on full disk works
when the format makes it reasonably practical to do so. Other cases
may have incorrect data sizes but sample info will be in tact. File
left that way may play anyway.

mp3_enc.codec acquires the ability to write 'Info' headers with LAME
tags to make it gapless (bonus).

Change-Id: I670685166d5eb32ef58ef317f50b8af766ceb653
Reviewed-on: http://gerrit.rockbox.org/493
Reviewed-by: Michael Sevakis <jethead71@rockbox.org>
Tested-by: Michael Sevakis <jethead71@rockbox.org>
This commit is contained in:
Michael Sevakis 2013-06-22 16:41:16 -04:00
parent a9ea1a4269
commit 4888131972
16 changed files with 2821 additions and 2949 deletions

View file

@ -249,7 +249,7 @@ static void codec_pcmbuf_insert_callback(
return; /* No input remains and DSP purged */
}
}
}
}
}
/* helper function, not a callback */
@ -365,10 +365,14 @@ static enum codec_command_action
queue_peek(&codec_queue, &ev); /* Find out what it is */
long id = ev.id;
intptr_t id = ev.id;
switch (id)
{
case Q_NULL:
LOGFQUEUE("codec < Q_NULL");
break;
case Q_CODEC_RUN: /* Already running */
LOGFQUEUE("codec < Q_CODEC_RUN");
break;
@ -388,8 +392,25 @@ static enum codec_command_action
break;
case Q_CODEC_STOP: /* Must only return 0 in main loop */
LOGFQUEUE("codec < Q_CODEC_STOP");
dsp_configure(ci.dsp, DSP_FLUSH, 0); /* Discontinuity */
LOGFQUEUE("codec < Q_CODEC_STOP: %ld", ev.data);
#ifdef HAVE_RECORDING
if (type_is_encoder(codec_type))
{
/* Stream finish request (soft stop)? */
if (ev.data && param)
{
/* ev.data is pointer to size */
*param = ev.data;
action = CODEC_ACTION_STREAM_FINISH;
break;
}
}
else
#endif /* HAVE_RECORDING */
{
dsp_configure(ci.dsp, DSP_FLUSH, 0); /* Discontinuity */
}
return CODEC_ACTION_HALT; /* Leave in queue */
default: /* This is in error in this context. */
@ -459,7 +480,8 @@ static void load_codec(const struct codec_load_info *ev_data)
}
}
if (status >= 0)
/* Types must agree */
if (status >= 0 && encoder == !!codec_get_enc_callback())
{
codec_type = data.afmt;
codec_queue_ack(Q_CODEC_LOAD);
@ -558,7 +580,7 @@ static void NORETURN_ATTR codec_thread(void)
{
struct queue_event ev;
while (1)
while (1)
{
cancel_cpu_boost();
@ -685,10 +707,33 @@ bool codec_pause(void)
void codec_stop(void)
{
/* Wait until it's in the main loop */
LOGFQUEUE("audio >| codec Q_CODEC_STOP");
LOGFQUEUE("audio >| codec Q_CODEC_STOP: 0");
while (codec_queue_send(Q_CODEC_STOP, 0) != Q_NULL);
}
#ifdef HAVE_RECORDING
/* Tells codec to take final encoding step and then exit -
Returns minimum buffer size required or 0 if complete */
size_t codec_finish_stream(void)
{
size_t size = 0;
LOGFQUEUE("audio >| codec Q_CODEC_STOP: &size");
if (codec_queue_send(Q_CODEC_STOP, (intptr_t)&size) != Q_NULL)
{
/* Sync to keep size in scope and get response */
LOGFQUEUE("audio >| codec Q_NULL");
codec_queue_send(Q_NULL, 0);
if (size == 0)
codec_stop(); /* Replied with 0 size */
}
/* else thread running in the main loop */
return size;
}
#endif /* HAVE_RECORDING */
/* Call the codec's exit routine and close all references */
void codec_unload(void)
{