X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=platform%2Fcommon%2Fmp3_helix.c;h=b278529819a7c11b6c53b577b3da0de6a124e693;hb=refs%2Fremotes%2Fgithub%2Fmaster;hp=62e91897804680577ee9d7e9ce8d11ba46abd6cb;hpb=fc11dd059b5c7369a51ddcca532505b588bd0030;p=picodrive.git diff --git a/platform/common/mp3_helix.c b/platform/common/mp3_helix.c index 62e91897..f3650bf2 100644 --- a/platform/common/mp3_helix.c +++ b/platform/common/mp3_helix.c @@ -9,21 +9,31 @@ #include #include +#include #include -#include -#include "helix/pub/mp3dec.h" +/*#include "helix/pub/mp3dec.h"*/ #include "mp3.h" -#include "lprintf.h" -static HMP3Decoder mp3dec; +#ifndef _MP3DEC_H +typedef void *HMP3Decoder; +#define ERR_MP3_INDATA_UNDERFLOW -1 +#define ERR_MP3_MAINDATA_UNDERFLOW -2 +#endif + +static void *mp3dec; static unsigned char mp3_input_buffer[2 * 1024]; #ifdef __GP2X__ -#define mp3_update mp3_update_local -#define mp3_start_play mp3_start_play_local +#define mp3dec_decode _mp3dec_decode +#define mp3dec_start _mp3dec_start #endif +static void *libhelix; +HMP3Decoder (*p_MP3InitDecoder)(void); +void (*p_MP3FreeDecoder)(HMP3Decoder); +int (*p_MP3Decode)(HMP3Decoder, unsigned char **, int *, short *, int); + int mp3dec_decode(FILE *f, int *file_pos, int file_len) { unsigned char *readPtr; @@ -31,6 +41,7 @@ int mp3dec_decode(FILE *f, int *file_pos, int file_len) int offset; // mp3 frame offset from readPtr int had_err; int err = 0; + int retry = 3; do { @@ -51,7 +62,7 @@ int mp3dec_decode(FILE *f, int *file_pos, int file_len) bytesLeft -= offset; had_err = err; - err = MP3Decode(mp3dec, &readPtr, &bytesLeft, cdda_out_buffer, 0); + err = p_MP3Decode(mp3dec, &readPtr, &bytesLeft, cdda_out_buffer, 0); if (err) { if (err == ERR_MP3_MAINDATA_UNDERFLOW && !had_err) { // just need another frame @@ -79,17 +90,38 @@ int mp3dec_decode(FILE *f, int *file_pos, int file_len) } *file_pos += readPtr - mp3_input_buffer; } - while (0); + while (err && --retry > 0); - return 0; + return !!err; } -int mp3dec_start(void) +int mp3dec_start(FILE *f, int fpos_start) { + if (libhelix == NULL) { + libhelix = dlopen("./libhelix.so", RTLD_NOW); + if (libhelix == NULL) { + lprintf("mp3dec: load libhelix.so: %s\n", dlerror()); + return -1; + } + + p_MP3InitDecoder = dlsym(libhelix, "MP3InitDecoder"); + p_MP3FreeDecoder = dlsym(libhelix, "MP3FreeDecoder"); + p_MP3Decode = dlsym(libhelix, "MP3Decode"); + + if (p_MP3InitDecoder == NULL || p_MP3FreeDecoder == NULL + || p_MP3Decode == NULL) + { + lprintf("mp3dec: missing symbol(s) in libhelix.so\n"); + dlclose(libhelix); + libhelix = NULL; + return -1; + } + } + // must re-init decoder for new track if (mp3dec) - MP3FreeDecoder(mp3dec); - mp3dec = MP3InitDecoder(); + p_MP3FreeDecoder(mp3dec); + mp3dec = p_MP3InitDecoder(); return (mp3dec == 0) ? -1 : 0; }