SWCODEC Recording Codecs: Fix problems with hanging recording screen (chiefly on x5) when no voice file present and source is not FMRadio. Caused by extra audio stops causing encoder to unload prematurely. Fix is to have separate stop flags for each codec type to prevent collisions. Also now safe to plug into USB when recording and encoder will stay loaded and not be stopped by the call to audio_stop_playback. Additional discovery: playback will not be able to restart after a USB plug during recording. Probably an old bug. I recommend in the future that recording have higher priority on system resources than playback and playback be denied access explicitly if recording requires them. Codec API becomes incompatible so do full updates.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12579 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Michael Sevakis 2007-03-04 04:16:53 +00:00
parent a61a7fa7ae
commit 598629c3bf
7 changed files with 19 additions and 29 deletions

View file

@ -215,14 +215,15 @@ struct codec_api ci = {
#endif
#if defined(HAVE_RECORDING) && !defined(SIMULATOR)
false,
false, /* stop_encoder */
0, /* enc_codec_loaded */
enc_get_inputs,
enc_set_parameters,
enc_get_chunk,
enc_finish_chunk,
enc_pcm_buf_near_empty,
enc_get_pcm_data,
enc_unget_pcm_data
enc_unget_pcm_data,
#endif
/* new stuff at the end, sort into place next time

View file

@ -90,12 +90,12 @@
#define CODEC_ENC_MAGIC 0x52454E43 /* RENC */
/* increase this every time the api struct changes */
#define CODEC_API_VERSION 14
#define CODEC_API_VERSION 15
/* update this to latest version if a change to the api struct breaks
backwards compatibility (and please take the opportunity to sort in any
new function which are "waiting" at the end of the function table) */
#define CODEC_MIN_API_VERSION 14
#define CODEC_MIN_API_VERSION 15
/* codec return codes */
enum codec_status {
@ -303,6 +303,7 @@ struct codec_api {
#endif
#if defined(HAVE_RECORDING) && !defined(SIMULATOR)
volatile bool stop_encoder;
volatile int enc_codec_loaded; /* <0=error, 0=pending, >0=ok */
void (*enc_get_inputs)(struct enc_inputs *inputs);
void (*enc_set_parameters)(struct enc_parameters *params);

View file

@ -354,7 +354,7 @@ enum codec_status codec_main(void)
#endif
/* main encoding loop */
while(!ci->stop_codec)
while(!ci->stop_encoder)
{
uint32_t *src;
@ -362,7 +362,7 @@ enum codec_status codec_main(void)
{
struct enc_chunk_hdr *chunk;
if (ci->stop_codec)
if (ci->stop_encoder)
break;
#ifdef HAVE_ADJUSTABLE_CPU_FREQ

View file

@ -2482,7 +2482,7 @@ enum codec_status codec_main(void)
#endif
/* main encoding loop */
while (!ci->stop_codec)
while (!ci->stop_encoder)
{
char *buffer;
@ -2490,7 +2490,7 @@ enum codec_status codec_main(void)
{
struct enc_chunk_hdr *chunk;
if (ci->stop_codec)
if (ci->stop_encoder)
break;
#ifdef HAVE_ADJUSTABLE_CPU_FREQ

View file

@ -342,7 +342,7 @@ enum codec_status codec_main(void)
#endif
/* main encoding loop */
while(!ci->stop_codec)
while(!ci->stop_encoder)
{
uint32_t *src;
@ -350,7 +350,7 @@ enum codec_status codec_main(void)
{
struct enc_chunk_hdr *chunk;
if (ci->stop_codec)
if (ci->stop_encoder)
break;
#ifdef HAVE_ADJUSTABLE_CPU_FREQ

View file

@ -408,7 +408,7 @@ enum codec_status codec_main(void)
#endif
/* main encoding loop */
while(!ci->stop_codec)
while(!ci->stop_encoder)
{
uint8_t *src;
@ -419,7 +419,7 @@ enum codec_status codec_main(void)
uint8_t *dst;
uint8_t *src_end;
if(ci->stop_codec)
if(ci->stop_encoder)
break;
abort_chunk = true;
@ -455,7 +455,7 @@ enum codec_status codec_main(void)
chunk->num_pcm += PCM_SAMP_PER_CHUNK/4;
ci->yield();
/* could've been stopped in some way */
abort_chunk = ci->stop_codec ||
abort_chunk = ci->stop_encoder ||
(chunk->flags & CHUNKF_ABORT);
}

View file

@ -138,10 +138,6 @@ enum {
#if MEM > 8
Q_AUDIO_FILL_BUFFER_IF_ACTIVE_ATA,
#endif
#ifdef AUDIO_HAVE_RECORDING
Q_AUDIO_LOAD_ENCODER,
#endif
#if 0
Q_CODEC_REQUEST_PENDING,
#endif
@ -525,8 +521,8 @@ bool audio_load_encoder(int afmt)
audio_remove_encoder();
ci.enc_codec_loaded = 0; /* clear any previous error condition */
LOGFQUEUE("audio > Q_AUDIO_LOAD_ENCODER");
queue_post(&audio_queue, Q_AUDIO_LOAD_ENCODER, (intptr_t)enc_fn);
LOGFQUEUE("codec > Q_ENCODER_LOAD_DISK");
queue_post(&codec_queue, Q_ENCODER_LOAD_DISK, (intptr_t)enc_fn);
while (ci.enc_codec_loaded == 0)
yield();
@ -547,7 +543,7 @@ void audio_remove_encoder(void)
if (ci.enc_codec_loaded <= 0)
return;
ci.stop_codec = true;
ci.stop_encoder = true;
while (ci.enc_codec_loaded > 0)
yield();
#endif
@ -2003,7 +1999,7 @@ static void codec_thread(void)
#endif
logf("loading encoder");
set_current_codec(CODEC_IDX_AUDIO);
ci.stop_codec = false;
ci.stop_encoder = false;
status = codec_load_file((const char *)ev.data, &ci);
#ifdef PLAYBACK_VOICE
mutex_unlock(&mutex_codecthread);
@ -3691,14 +3687,6 @@ static void audio_thread(void)
playlist_update_resume_info(audio_current_track());
break ;
#ifdef AUDIO_HAVE_RECORDING
case Q_AUDIO_LOAD_ENCODER:
LOGFQUEUE("audio < Q_AUDIO_LOAD_ENCODER");
LOGFQUEUE("audio > codec Q_ENCODER_LOAD_DISK");
queue_post(&codec_queue, Q_ENCODER_LOAD_DISK, ev.data);
break;
#endif
#ifndef SIMULATOR
case SYS_USB_CONNECTED:
LOGFQUEUE("audio < SYS_USB_CONNECTED");