From 95298a955846d59a7758076a56df12f9996fc0bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Hohensohn?= Date: Fri, 30 Jan 2004 22:30:40 +0000 Subject: [PATCH] mp3 playback "engine" now in plugin API, rocks can make sound git-svn-id: svn://svn.rockbox.org/rockbox/trunk@4285 a1c6a512-1295-4272-9138-f99709370657 --- apps/plugin.c | 32 ++++++++++++++++++++++++++++++++ apps/plugin.h | 21 +++++++++++++++++++-- firmware/export/mp3_playback.h | 3 ++- firmware/mp3_playback.c | 6 ++++++ 4 files changed, 59 insertions(+), 3 deletions(-) diff --git a/apps/plugin.c b/apps/plugin.c index e91cba0512..e010ebe841 100644 --- a/apps/plugin.c +++ b/apps/plugin.c @@ -34,6 +34,9 @@ #include "lang.h" #include "keyboard.h" #include "mpeg.h" +#include "buffer.h" +#include "mp3_playback.h" +#include "backlight.h" #ifdef HAVE_LCD_BITMAP #include "widgets.h" @@ -58,6 +61,7 @@ static unsigned char pluginbuf[PLUGIN_BUFFER_SIZE]; #else extern unsigned char pluginbuf[]; +extern void bitswap(unsigned char *data, int length); #endif static bool plugin_loaded = false; @@ -163,6 +167,19 @@ static struct plugin_api rockbox_api = { lcd_blit, #endif yield, + + plugin_get_mp3_buffer, + mpeg_sound_set, +#ifndef SIMULATOR + mp3_play_init, + mp3_play_data, + mp3_play_pause, + mp3_play_stop, + mp3_is_playing, + bitswap, +#endif + &global_settings, + backlight_set_timeout, }; int plugin_load(char* plugin, void* parameter) @@ -294,6 +311,21 @@ void* plugin_get_buffer(int* buffer_size) return &pluginbuf[buffer_pos]; } +/* Returns a pointer to the mp3 buffer. + Playback gets stopped, to avoid conflicts. */ +void* plugin_get_mp3_buffer(int* buffer_size) +{ +#ifdef SIMULATOR + static unsigned char buf[1700*1024]; + *buffer_size = sizeof(buf); + return buf; +#else + mpeg_stop(); + *buffer_size = mp3end - mp3buf; + return mp3buf; +#endif +} + static int plugin_test(int api_version, int model, int memsize) { if (api_version < PLUGIN_MIN_API_VERSION || diff --git a/apps/plugin.h b/apps/plugin.h index b46d9a7a1c..be08091eba 100644 --- a/apps/plugin.h +++ b/apps/plugin.h @@ -41,9 +41,11 @@ #include "lcd.h" #include "id3.h" #include "mpeg.h" +#include "mp3_playback.h" +#include "settings.h" /* increase this every time the api struct changes */ -#define PLUGIN_API_VERSION 9 +#define PLUGIN_API_VERSION 10 /* update this to latest version if a change to the api struct breaks backwards compatibility */ @@ -181,18 +183,33 @@ struct plugin_api { int (*atoi)(const char *str); struct tm* (*get_time)(void); void* (*plugin_get_buffer)(int* buffer_size); - /* new stuff */ + + /* new stuff, sort in next time the API gets broken! */ #ifndef HAVE_LCD_CHARCELLS unsigned char* lcd_framebuffer; /* performance function */ void (*lcd_blit) (unsigned char* p_data, int x, int y, int width, int height, int stride); #endif void (*yield)(void); + + void* (*plugin_get_mp3_buffer)(int* buffer_size); + void (*mpeg_sound_set)(int setting, int value); +#ifndef SIMULATOR + void (*mp3_play_init)(void); + void (*mp3_play_data)(unsigned char* start, int size, void (*get_more)(unsigned char** start, int* size)); + void (*mp3_play_pause)(bool play); + void (*mp3_play_stop)(void); + bool (*mp3_is_playing)(void); + void (*bitswap)(unsigned char *data, int length); +#endif + struct user_settings* global_settings; + void (*backlight_set_timeout)(unsigned int index); }; /* defined by the plugin loader (plugin.c) */ int plugin_load(char* plugin, void* parameter); void* plugin_get_buffer(int *buffer_size); +void* plugin_get_mp3_buffer(int *buffer_size); /* defined by the plugin */ enum plugin_status plugin_start(struct plugin_api* rockbox, void* parameter) diff --git a/firmware/export/mp3_playback.h b/firmware/export/mp3_playback.h index 3c190f2691..15f53472bc 100644 --- a/firmware/export/mp3_playback.h +++ b/firmware/export/mp3_playback.h @@ -46,7 +46,7 @@ void mpeg_set_pitch(int percent); void demand_irq_enable(bool on); #endif -/* new functions, to be exported to plugin API */ +/* new functions, exported to plugin API */ void mp3_play_init(void); void mp3_play_data(unsigned char* start, int size, void (*get_more)(unsigned char** start, int* size) /* callback fn */ @@ -55,6 +55,7 @@ void mp3_play_pause(bool play); void mp3_play_stop(void); long mp3_get_playtime(void); void mp3_reset_playtime(void); +bool mp3_is_playing(void); #define SOUND_VOLUME 0 diff --git a/firmware/mp3_playback.c b/firmware/mp3_playback.c index fe16676624..422a0e6822 100644 --- a/firmware/mp3_playback.c +++ b/firmware/mp3_playback.c @@ -1086,4 +1086,10 @@ void mp3_reset_playtime(void) playstart_tick = current_tick; } + +bool mp3_is_playing(void) +{ + return playing; +} + #endif /* #ifndef SIMULATOR */