summaryrefslogtreecommitdiff
path: root/apps/plugins/test_codec.c
diff options
context:
space:
mode:
authorDave Chapman <dave@dchapman.com>2007-05-07 22:30:23 +0000
committerDave Chapman <dave@dchapman.com>2007-05-07 22:30:23 +0000
commitf4a9dab4d161a8f59800656417baf38e6f163f9d (patch)
treeab2b89c90480e1dbae5c83ece53a3ab7c116adf0 /apps/plugins/test_codec.c
parent173b611921db2d353d977dc617a8288345f5e6ed (diff)
downloadrockbox-f4a9dab4d161a8f59800656417baf38e6f163f9d.zip
rockbox-f4a9dab4d161a8f59800656417baf38e6f163f9d.tar.gz
rockbox-f4a9dab4d161a8f59800656417baf38e6f163f9d.tar.bz2
rockbox-f4a9dab4d161a8f59800656417baf38e6f163f9d.tar.xz
Use a separate thread in test_codec, with the same (IRAM) stack as the main codec thread. Add a function to the plugin API to steal the codec thread, which test_codec copies and then restores. Now libmad can be benchmarked.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@13347 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/test_codec.c')
-rw-r--r--apps/plugins/test_codec.c75
1 files changed, 54 insertions, 21 deletions
diff --git a/apps/plugins/test_codec.c b/apps/plugins/test_codec.c
index 56d59b3..6fe717b 100644
--- a/apps/plugins/test_codec.c
+++ b/apps/plugins/test_codec.c
@@ -30,11 +30,11 @@ static char str[40];
/* Our local implementation of the codec API */
static struct codec_api ci;
-
static struct track_info track;
-
static bool taginfo_ready = true;
+static volatile unsigned int elapsed;
+static volatile bool codec_playing;
/* Returns buffer to malloc array. Only codeclib should need this. */
static void* get_codec_memory(size_t *size)
@@ -44,7 +44,6 @@ static void* get_codec_memory(size_t *size)
return codec_mallocbuf;
}
-
/* Insert PCM data into audio buffer for playback. Playback will start
automatically. */
static bool pcmbuf_insert(const void *ch1, const void *ch2, int count)
@@ -58,18 +57,10 @@ static bool pcmbuf_insert(const void *ch1, const void *ch2, int count)
}
-static unsigned int prev_value = 0;
-
/* Set song position in WPS (value in ms). */
static void set_elapsed(unsigned int value)
{
- if ((value - prev_value) > 2000)
- {
- rb->snprintf(str,sizeof(str),"%d of %d",value,(int)track.id3.length);
- rb->lcd_puts(0,0,str);
- rb->lcd_update();
- prev_value = value;
- }
+ elapsed = value;
}
@@ -230,17 +221,36 @@ static void init_ci(void)
#endif
}
+static void codec_thread(void)
+{
+ const char* codecname;
+ int res;
+
+ codecname = rb->get_codec_filename(track.id3.codectype);
+
+ /* Load the codec and start decoding. */
+ res = rb->codec_load_file(codecname,&ci);
+
+ /* Signal to the main thread that we are done */
+ codec_playing = false;
+
+ /* Commit suicide */
+ rb->remove_thread(NULL);
+}
+
/* plugin entry point */
enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
{
size_t n;
int fd;
- const char* codecname;
- int res;
unsigned long starttick;
unsigned long ticks;
unsigned long speed;
unsigned long duration;
+ unsigned char* codec_stack;
+ unsigned char* codec_stack_copy;
+ size_t codec_stack_size;
+ struct thread_entry* codecthread_id;
rb = api;
@@ -250,10 +260,16 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
return PLUGIN_ERROR;
}
+ rb->steal_codec_stack(&codec_stack,&codec_stack_size);
+
codec_mallocbuf = rb->plugin_get_audio_buffer(&audiosize);
- audiobuf = codec_mallocbuf + 512*1024;
- audiosize -= 512*1024;
-
+ codec_stack_copy = codec_mallocbuf + 512*1024;
+ audiobuf = codec_stack_copy + codec_stack_size;
+ audiosize -= 512*1024 + codec_stack_size;
+
+ /* Backup the codec thread's stack */
+ rb->memcpy(codec_stack_copy,codec_stack,codec_stack_size);
+
fd = rb->open(parameter,O_RDONLY);
if (fd < 0)
{
@@ -298,8 +314,6 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
ci.new_track = 0;
ci.seek_time = 0;
- codecname = rb->get_codec_filename(track.id3.codectype);
-
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
rb->cpu_boost(true);
#endif
@@ -311,9 +325,24 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
starttick = *rb->current_tick;
- /* Load the codec and start decoding. */
- res = rb->codec_load_file(codecname,&ci);
+ codec_playing = true;
+ if ((codecthread_id = rb->create_thread(codec_thread,
+ (uint8_t*)codec_stack, codec_stack_size, "testcodec" IF_PRIO(,PRIORITY_PLAYBACK)
+ IF_COP(, CPU, false))) == NULL)
+ {
+ rb->splash(HZ, "Cannot create codec thread!");
+ goto exit;
+ }
+
+ /* Wait for codec thread to die */
+ while (codec_playing)
+ {
+ rb->sleep(HZ);
+ rb->snprintf(str,sizeof(str),"%d of %d",elapsed,(int)track.id3.length);
+ rb->lcd_puts(0,0,str);
+ rb->lcd_update();
+ }
/* Display benchmark information */
@@ -337,6 +366,10 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
while (rb->button_get(true) != BUTTON_SELECT);
+exit:
+ /* Restore the codec thread's stack */
+ rb->memcpy(codec_stack, codec_stack_copy, codec_stack_size);
+
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
rb->cpu_boost(false);
#endif