1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 Björn Stenberg
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
27 #include <timefuncs.h>
30 #include "string-extra.h"
31 #include "load_code.h"
42 #include "buffering.h"
43 #include "mp3_playback.h"
44 #include "backlight.h"
48 #include "powermgmt.h"
57 #if (CONFIG_PLATFORM & (PLATFORM_SDL|PLATFORM_MAEMO))
58 #define PREFIX(_x_) sim_ ## _x_
60 #define PREFIX(_x_) _x_
63 #if (CONFIG_PLATFORM & PLATFORM_HOSTED)
64 #if CONFIG_CODEC == SWCODEC
65 unsigned char codecbuf
[CODEC_SIZE
];
71 extern void* plugin_get_audio_buffer(size_t *buffer_size
);
73 #if (CONFIG_PLATFORM & PLATFORM_NATIVE) && defined(HAVE_RECORDING)
75 static int open(const char* pathname
, int flags
, ...)
77 return file_open(pathname
, flags
);
80 struct codec_api ci
= {
85 NULL
, /* taginfo_ready */
86 false, /* stop_codec */
89 NULL
, /* struct dsp_config *dsp */
90 NULL
, /* codec_get_buffer */
91 NULL
, /* pcmbuf_insert */
92 NULL
, /* set_elapsed */
93 NULL
, /* read_filebuf */
94 NULL
, /* request_buffer */
95 NULL
, /* advance_buffer */
96 NULL
, /* advance_buffer_loc */
97 NULL
, /* seek_buffer */
98 NULL
, /* seek_complete */
99 NULL
, /* request_next_track */
100 NULL
, /* discard_codec */
101 NULL
, /* set_offset */
102 NULL
, /* configure */
105 #if defined(CPU_ARM) && CONFIG_PLATFORM & PLATFORM_NATIVE
123 /* strings and memory */
134 #if defined(DEBUG) || defined(SIMULATOR)
137 #ifdef ROCKBOX_HAS_LOGF
147 __cyg_profile_func_enter
,
148 __cyg_profile_func_exit
,
151 #ifdef HAVE_RECORDING
152 false, /* stop_encoder */
153 0, /* enc_codec_loaded */
162 (open_func
)PREFIX(open
),
164 (read_func
)PREFIX(read
),
166 (write_func
)PREFIX(write
),
167 round_value_to_list32
,
169 #endif /* HAVE_RECORDING */
171 /* new stuff at the end, sort into place next time
172 the API gets incompatible */
175 void codec_get_full_path(char *path
, const char *codec_root_fn
)
177 snprintf(path
, MAX_PATH
-1, "%s/%s." CODEC_EXTENSION
,
178 CODECS_DIR
, codec_root_fn
);
181 static int codec_load_ram(void *handle
, struct codec_api
*api
)
183 struct codec_header
*c_hdr
= lc_get_header(handle
);
184 struct lc_header
*hdr
= c_hdr
? &c_hdr
->lc_hdr
: NULL
;
188 || (hdr
->magic
!= CODEC_MAGIC
189 #ifdef HAVE_RECORDING
190 && hdr
->magic
!= CODEC_ENC_MAGIC
193 || hdr
->target_id
!= TARGET_ID
194 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
195 || hdr
->load_addr
!= codecbuf
196 || hdr
->end_addr
> codecbuf
+ CODEC_SIZE
200 logf("codec header error");
205 if (hdr
->api_version
> CODEC_API_VERSION
206 || hdr
->api_version
< CODEC_MIN_API_VERSION
) {
207 logf("codec api version error");
212 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
213 codec_size
= hdr
->end_addr
- codecbuf
;
219 status
= c_hdr
->entry_point();
226 int codec_load_buf(unsigned int hid
, struct codec_api
*api
)
230 rc
= bufread(hid
, CODEC_SIZE
, codecbuf
);
232 logf("error loading codec");
235 handle
= lc_open_from_mem(codecbuf
, rc
);
238 logf("error loading codec");
242 api
->discard_codec();
243 return codec_load_ram(handle
, api
);
246 int codec_load_file(const char *plugin
, struct codec_api
*api
)
251 codec_get_full_path(path
, plugin
);
253 handle
= lc_open(path
, codecbuf
, CODEC_SIZE
);
255 if (handle
== NULL
) {
256 logf("Codec load error");
257 splashf(HZ
*2, "Couldn't load codec: %s", path
);
261 return codec_load_ram(handle
, api
);