2005-06-22 19:41:30 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
2008-05-05 10:32:46 +00:00
|
|
|
* Copyright (C) 2002 Björn Stenberg
|
2005-06-22 19:41:30 +00:00
|
|
|
*
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2005-06-27 21:23:03 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
2005-06-22 19:41:30 +00:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
2008-04-28 16:18:04 +00:00
|
|
|
#include <stdlib.h>
|
2005-06-22 19:41:30 +00:00
|
|
|
#include <timefuncs.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include "debug.h"
|
|
|
|
#include "button.h"
|
|
|
|
#include "dir.h"
|
|
|
|
#include "file.h"
|
|
|
|
#include "kernel.h"
|
|
|
|
#include "sprintf.h"
|
|
|
|
#include "screens.h"
|
|
|
|
#include "misc.h"
|
|
|
|
#include "mas.h"
|
|
|
|
#include "codecs.h"
|
|
|
|
#include "lang.h"
|
|
|
|
#include "keyboard.h"
|
|
|
|
#include "mpeg.h"
|
|
|
|
#include "buffer.h"
|
2007-11-02 14:06:48 +00:00
|
|
|
#include "buffering.h"
|
2005-06-22 19:41:30 +00:00
|
|
|
#include "mp3_playback.h"
|
|
|
|
#include "backlight.h"
|
|
|
|
#include "ata.h"
|
|
|
|
#include "talk.h"
|
|
|
|
#include "mp3data.h"
|
|
|
|
#include "powermgmt.h"
|
|
|
|
#include "system.h"
|
|
|
|
#include "sound.h"
|
2005-11-16 15:12:15 +00:00
|
|
|
#include "splash.h"
|
2006-11-06 18:07:30 +00:00
|
|
|
#include "general.h"
|
2005-11-16 15:12:15 +00:00
|
|
|
|
2007-10-24 22:06:36 +00:00
|
|
|
#define LOGF_ENABLE
|
|
|
|
#include "logf.h"
|
|
|
|
|
2005-06-22 19:41:30 +00:00
|
|
|
#ifdef SIMULATOR
|
2005-08-29 21:15:27 +00:00
|
|
|
#if CONFIG_CODEC == SWCODEC
|
2005-08-20 11:13:19 +00:00
|
|
|
unsigned char codecbuf[CODEC_SIZE];
|
2005-06-22 19:41:30 +00:00
|
|
|
#endif
|
2007-11-02 14:06:48 +00:00
|
|
|
void *sim_codec_load_ram(char* codecptr, int size, void **pd);
|
2006-03-02 01:08:38 +00:00
|
|
|
void sim_codec_close(void *pd);
|
2005-06-22 19:41:30 +00:00
|
|
|
#else
|
|
|
|
#define sim_codec_close(x)
|
|
|
|
extern unsigned char codecbuf[];
|
|
|
|
#endif
|
|
|
|
|
2007-04-21 18:38:25 +00:00
|
|
|
extern void* plugin_get_audio_buffer(size_t *buffer_size);
|
2005-06-22 19:41:30 +00:00
|
|
|
|
2005-06-22 21:16:28 +00:00
|
|
|
struct codec_api ci = {
|
2005-06-22 19:41:30 +00:00
|
|
|
|
|
|
|
0, /* filesize */
|
|
|
|
0, /* curpos */
|
|
|
|
NULL, /* id3 */
|
|
|
|
NULL, /* taginfo_ready */
|
|
|
|
false, /* stop_codec */
|
2006-04-15 02:03:11 +00:00
|
|
|
0, /* new_track */
|
2005-06-22 19:41:30 +00:00
|
|
|
0, /* seek_time */
|
2008-03-25 02:34:12 +00:00
|
|
|
NULL, /* struct dsp_config *dsp */
|
2006-04-15 02:03:11 +00:00
|
|
|
NULL, /* get_codec_memory */
|
|
|
|
NULL, /* pcmbuf_insert */
|
|
|
|
NULL, /* set_elapsed */
|
|
|
|
NULL, /* read_filebuf */
|
|
|
|
NULL, /* request_buffer */
|
|
|
|
NULL, /* advance_buffer */
|
|
|
|
NULL, /* advance_buffer_loc */
|
|
|
|
NULL, /* seek_buffer */
|
|
|
|
NULL, /* seek_complete */
|
|
|
|
NULL, /* request_next_track */
|
|
|
|
NULL, /* discard_codec */
|
|
|
|
NULL, /* set_offset */
|
|
|
|
NULL, /* configure */
|
2005-06-22 19:41:30 +00:00
|
|
|
|
|
|
|
/* kernel/ system */
|
|
|
|
PREFIX(sleep),
|
|
|
|
yield,
|
|
|
|
|
2008-03-25 02:34:12 +00:00
|
|
|
#if NUM_CORES > 1
|
|
|
|
create_thread,
|
|
|
|
thread_thaw,
|
|
|
|
thread_wait,
|
|
|
|
semaphore_init,
|
|
|
|
semaphore_wait,
|
|
|
|
semaphore_release,
|
|
|
|
event_init,
|
|
|
|
event_wait,
|
|
|
|
event_set_state,
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CACHE_FUNCTIONS_AS_CALL
|
|
|
|
flush_icache,
|
|
|
|
invalidate_icache,
|
|
|
|
#endif
|
|
|
|
|
2005-06-22 19:41:30 +00:00
|
|
|
/* strings and memory */
|
|
|
|
strcpy,
|
|
|
|
strncpy,
|
|
|
|
strlen,
|
|
|
|
strcmp,
|
2007-05-07 11:09:45 +00:00
|
|
|
strcat,
|
2005-06-22 19:41:30 +00:00
|
|
|
memset,
|
|
|
|
memcpy,
|
2006-03-24 13:43:15 +00:00
|
|
|
memmove,
|
2005-06-22 19:41:30 +00:00
|
|
|
memcmp,
|
2006-01-18 00:05:14 +00:00
|
|
|
memchr,
|
2005-06-22 19:41:30 +00:00
|
|
|
|
|
|
|
#if defined(DEBUG) || defined(SIMULATOR)
|
|
|
|
debugf,
|
2006-01-18 00:05:14 +00:00
|
|
|
#endif
|
|
|
|
#ifdef ROCKBOX_HAS_LOGF
|
|
|
|
logf,
|
2005-06-22 19:41:30 +00:00
|
|
|
#endif
|
2007-05-07 11:09:45 +00:00
|
|
|
|
|
|
|
(qsort_func)qsort,
|
2005-06-22 19:41:30 +00:00
|
|
|
&global_settings,
|
|
|
|
|
2006-01-18 20:54:13 +00:00
|
|
|
#ifdef RB_PROFILE
|
|
|
|
profile_thread,
|
|
|
|
profstop,
|
|
|
|
profile_func_enter,
|
|
|
|
profile_func_exit,
|
|
|
|
#endif
|
2005-06-22 19:41:30 +00:00
|
|
|
|
2006-08-28 22:38:41 +00:00
|
|
|
#if defined(HAVE_RECORDING) && !defined(SIMULATOR)
|
2007-03-04 04:16:53 +00:00
|
|
|
false, /* stop_encoder */
|
|
|
|
0, /* enc_codec_loaded */
|
2006-08-28 22:38:41 +00:00
|
|
|
enc_get_inputs,
|
|
|
|
enc_set_parameters,
|
2006-11-06 18:07:30 +00:00
|
|
|
enc_get_chunk,
|
|
|
|
enc_finish_chunk,
|
|
|
|
enc_get_pcm_data,
|
2007-03-04 04:16:53 +00:00
|
|
|
enc_unget_pcm_data,
|
2007-05-07 11:09:45 +00:00
|
|
|
|
|
|
|
/* file */
|
|
|
|
(open_func)PREFIX(open),
|
|
|
|
close,
|
|
|
|
(read_func)read,
|
|
|
|
PREFIX(lseek),
|
|
|
|
(write_func)write,
|
|
|
|
round_value_to_list32,
|
|
|
|
|
2006-08-28 22:38:41 +00:00
|
|
|
#endif
|
|
|
|
|
2006-02-03 00:12:11 +00:00
|
|
|
/* new stuff at the end, sort into place next time
|
|
|
|
the API gets incompatible */
|
|
|
|
|
2005-06-22 19:41:30 +00:00
|
|
|
};
|
|
|
|
|
2006-11-06 18:07:30 +00:00
|
|
|
void codec_get_full_path(char *path, const char *codec_root_fn)
|
2006-08-28 22:38:41 +00:00
|
|
|
{
|
2006-11-06 18:07:30 +00:00
|
|
|
snprintf(path, MAX_PATH-1, CODECS_DIR "/%s." CODEC_EXTENSION,
|
|
|
|
codec_root_fn);
|
2006-08-28 22:38:41 +00:00
|
|
|
}
|
|
|
|
|
2007-11-02 14:06:48 +00:00
|
|
|
static int codec_load_ram(int size, struct codec_api *api)
|
2005-06-22 19:41:30 +00:00
|
|
|
{
|
2006-01-18 00:05:14 +00:00
|
|
|
struct codec_header *hdr;
|
2005-06-22 19:41:30 +00:00
|
|
|
int status;
|
2005-07-10 16:33:03 +00:00
|
|
|
#ifndef SIMULATOR
|
2006-01-18 00:05:14 +00:00
|
|
|
hdr = (struct codec_header *)codecbuf;
|
2005-06-22 19:41:30 +00:00
|
|
|
|
2006-01-18 08:34:32 +00:00
|
|
|
if (size <= (signed)sizeof(struct codec_header)
|
2006-11-06 18:07:30 +00:00
|
|
|
|| (hdr->magic != CODEC_MAGIC
|
|
|
|
#ifdef HAVE_RECORDING
|
|
|
|
&& hdr->magic != CODEC_ENC_MAGIC
|
|
|
|
#endif
|
|
|
|
)
|
2006-01-18 00:05:14 +00:00
|
|
|
|| hdr->target_id != TARGET_ID
|
|
|
|
|| hdr->load_addr != codecbuf
|
2006-01-21 08:17:40 +00:00
|
|
|
|| hdr->end_addr > codecbuf + CODEC_SIZE)
|
|
|
|
{
|
|
|
|
logf("codec header error");
|
2006-01-18 00:05:14 +00:00
|
|
|
return CODEC_ERROR;
|
|
|
|
}
|
2005-07-10 16:33:03 +00:00
|
|
|
#else /* SIMULATOR */
|
2006-03-02 01:08:38 +00:00
|
|
|
void *pd;
|
2005-07-10 16:33:03 +00:00
|
|
|
|
2007-11-02 14:06:48 +00:00
|
|
|
hdr = sim_codec_load_ram(codecbuf, size, &pd);
|
2006-06-21 19:14:18 +00:00
|
|
|
|
2006-03-02 01:08:38 +00:00
|
|
|
if (pd == NULL)
|
2005-07-10 16:33:03 +00:00
|
|
|
return CODEC_ERROR;
|
2006-01-18 00:05:14 +00:00
|
|
|
|
|
|
|
if (hdr == NULL
|
2007-11-02 14:20:44 +00:00
|
|
|
|| (hdr->magic != CODEC_MAGIC
|
2007-11-02 14:06:48 +00:00
|
|
|
#ifdef HAVE_RECORDING
|
|
|
|
&& hdr->magic != CODEC_ENC_MAGIC
|
|
|
|
#endif
|
2007-11-02 14:20:44 +00:00
|
|
|
)
|
2006-01-18 08:34:32 +00:00
|
|
|
|| hdr->target_id != TARGET_ID) {
|
2006-01-18 00:05:14 +00:00
|
|
|
sim_codec_close(pd);
|
|
|
|
return CODEC_ERROR;
|
|
|
|
}
|
2005-07-10 16:33:03 +00:00
|
|
|
#endif /* SIMULATOR */
|
2006-01-18 00:05:14 +00:00
|
|
|
if (hdr->api_version > CODEC_API_VERSION
|
|
|
|
|| hdr->api_version < CODEC_MIN_API_VERSION) {
|
|
|
|
sim_codec_close(pd);
|
|
|
|
return CODEC_ERROR;
|
|
|
|
}
|
2005-07-10 16:33:03 +00:00
|
|
|
|
2005-06-22 19:41:30 +00:00
|
|
|
invalidate_icache();
|
2006-01-18 00:05:14 +00:00
|
|
|
status = hdr->entry_point(api);
|
|
|
|
|
2005-07-10 16:33:03 +00:00
|
|
|
sim_codec_close(pd);
|
2006-01-18 00:05:14 +00:00
|
|
|
|
2005-06-22 19:41:30 +00:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2007-11-03 17:55:29 +00:00
|
|
|
int codec_load_buf(unsigned int hid, struct codec_api *api) {
|
2007-11-02 14:06:48 +00:00
|
|
|
int rc;
|
2007-11-03 17:55:29 +00:00
|
|
|
rc = bufread(hid, CODEC_SIZE, codecbuf);
|
2007-11-02 14:06:48 +00:00
|
|
|
if (rc < 0) {
|
|
|
|
logf("error loading codec");
|
|
|
|
return CODEC_ERROR;
|
|
|
|
}
|
|
|
|
api->discard_codec();
|
2007-11-03 17:55:29 +00:00
|
|
|
return codec_load_ram(rc, api);
|
2007-11-02 14:06:48 +00:00
|
|
|
}
|
|
|
|
|
2005-08-20 11:13:19 +00:00
|
|
|
int codec_load_file(const char *plugin, struct codec_api *api)
|
2005-06-22 19:41:30 +00:00
|
|
|
{
|
|
|
|
char msgbuf[80];
|
2006-08-28 22:38:41 +00:00
|
|
|
char path[MAX_PATH];
|
2005-06-22 19:41:30 +00:00
|
|
|
int fd;
|
|
|
|
int rc;
|
2006-08-28 22:38:41 +00:00
|
|
|
|
|
|
|
codec_get_full_path(path, plugin);
|
2005-06-22 19:41:30 +00:00
|
|
|
|
2006-08-28 22:38:41 +00:00
|
|
|
fd = open(path, O_RDONLY);
|
2005-06-22 19:41:30 +00:00
|
|
|
if (fd < 0) {
|
2006-08-28 22:38:41 +00:00
|
|
|
snprintf(msgbuf, sizeof(msgbuf)-1, "Couldn't load codec: %s", path);
|
2005-06-22 19:41:30 +00:00
|
|
|
logf("Codec load error:%d", fd);
|
2007-03-16 21:56:08 +00:00
|
|
|
gui_syncsplash(HZ*2, msgbuf);
|
2005-06-22 19:41:30 +00:00
|
|
|
return fd;
|
|
|
|
}
|
|
|
|
|
2005-06-27 21:23:03 +00:00
|
|
|
rc = read(fd, &codecbuf[0], CODEC_SIZE);
|
2005-06-22 19:41:30 +00:00
|
|
|
close(fd);
|
|
|
|
if (rc <= 0) {
|
|
|
|
logf("Codec read error");
|
|
|
|
return CODEC_ERROR;
|
|
|
|
}
|
2005-07-10 16:33:03 +00:00
|
|
|
|
2007-11-02 14:06:48 +00:00
|
|
|
return codec_load_ram((size_t)rc, api);
|
2005-06-22 19:41:30 +00:00
|
|
|
}
|