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>
43 #include "buffering.h"
44 #include "mp3_playback.h"
45 #include "backlight.h"
49 #include "powermgmt.h"
59 #define PREFIX(_x_) sim_ ## _x_
65 #if CONFIG_CODEC == SWCODEC
66 unsigned char codecbuf
[CODEC_SIZE
];
68 void *sim_codec_load_ram(char* codecptr
, int size
, void **pd
);
69 void sim_codec_close(void *pd
);
71 #define sim_codec_close(x)
72 extern unsigned char codecbuf
[];
77 extern void* plugin_get_audio_buffer(size_t *buffer_size
);
79 struct codec_api ci
= {
84 NULL
, /* taginfo_ready */
85 false, /* stop_codec */
88 NULL
, /* struct dsp_config *dsp */
89 NULL
, /* codec_get_buffer */
90 NULL
, /* pcmbuf_insert */
91 NULL
, /* set_elapsed */
92 NULL
, /* read_filebuf */
93 NULL
, /* request_buffer */
94 NULL
, /* advance_buffer */
95 NULL
, /* advance_buffer_loc */
96 NULL
, /* seek_buffer */
97 NULL
, /* seek_complete */
98 NULL
, /* request_next_track */
99 NULL
, /* discard_codec */
100 NULL
, /* set_offset */
101 NULL
, /* configure */
116 #ifdef CACHE_FUNCTIONS_AS_CALL
121 /* strings and memory */
133 #if defined(DEBUG) || defined(SIMULATOR)
136 #ifdef ROCKBOX_HAS_LOGF
146 __cyg_profile_func_enter
,
147 __cyg_profile_func_exit
,
150 #if defined(HAVE_RECORDING) && !defined(SIMULATOR)
151 false, /* stop_encoder */
152 0, /* enc_codec_loaded */
161 (open_func
)PREFIX(open
),
166 round_value_to_list32
,
170 /* new stuff at the end, sort into place next time
171 the API gets incompatible */
175 void codec_get_full_path(char *path
, const char *codec_root_fn
)
177 snprintf(path
, MAX_PATH
-1, CODECS_DIR
"/%s." CODEC_EXTENSION
,
181 static int codec_load_ram(int size
, struct codec_api
*api
)
183 struct codec_header
*hdr
;
186 hdr
= (struct codec_header
*)codecbuf
;
188 if (size
<= (signed)sizeof(struct codec_header
)
189 || (hdr
->magic
!= CODEC_MAGIC
190 #ifdef HAVE_RECORDING
191 && hdr
->magic
!= CODEC_ENC_MAGIC
194 || hdr
->target_id
!= TARGET_ID
195 || hdr
->load_addr
!= codecbuf
196 || hdr
->end_addr
> codecbuf
+ CODEC_SIZE
)
198 logf("codec header error");
202 codec_size
= hdr
->end_addr
- codecbuf
;
204 #else /* SIMULATOR */
207 hdr
= sim_codec_load_ram(codecbuf
, size
, &pd
);
213 || (hdr
->magic
!= CODEC_MAGIC
214 #ifdef HAVE_RECORDING
215 && hdr
->magic
!= CODEC_ENC_MAGIC
218 || hdr
->target_id
!= TARGET_ID
) {
223 codec_size
= codecbuf
- codecbuf
;
225 #endif /* SIMULATOR */
226 if (hdr
->api_version
> CODEC_API_VERSION
227 || hdr
->api_version
< CODEC_MIN_API_VERSION
) {
233 status
= hdr
->entry_point(api
);
240 int codec_load_buf(unsigned int hid
, struct codec_api
*api
)
243 rc
= bufread(hid
, CODEC_SIZE
, codecbuf
);
245 logf("error loading codec");
248 api
->discard_codec();
249 return codec_load_ram(rc
, api
);
252 int codec_load_file(const char *plugin
, struct codec_api
*api
)
258 codec_get_full_path(path
, plugin
);
260 fd
= open(path
, O_RDONLY
);
262 logf("Codec load error:%d", fd
);
263 splashf(HZ
*2, "Couldn't load codec: %s", path
);
267 rc
= read(fd
, &codecbuf
[0], CODEC_SIZE
);
270 logf("Codec read error");
274 return codec_load_ram((size_t)rc
, api
);