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|PLATFORM_PANDORA))
58 #define PREFIX(_x_) sim_ ## _x_
60 #define PREFIX(_x_) _x_
63 #if (CONFIG_PLATFORM & PLATFORM_HOSTED)
64 /* For PLATFORM_HOSTED this buffer must be define here. */
65 static unsigned char codecbuf
[CODEC_SIZE
];
67 /* For PLATFORM_NATIVE this buffer is defined in *.lds files. */
68 extern unsigned char codecbuf
[];
71 static size_t codec_size
;
73 extern void* plugin_get_audio_buffer(size_t *buffer_size
);
75 #if (CONFIG_PLATFORM & PLATFORM_NATIVE) && defined(HAVE_RECORDING)
77 static int open(const char* pathname
, int flags
, ...)
79 return file_open(pathname
, flags
);
82 struct codec_api ci
= {
87 ERR_HANDLE_NOT_FOUND
, /* audio_hid */
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
, /* seek_buffer */
96 NULL
, /* seek_complete */
97 NULL
, /* set_offset */
99 NULL
, /* get_command */
102 #if defined(CPU_ARM) && CONFIG_PLATFORM & PLATFORM_NATIVE
120 /* strings and memory */
131 #if defined(DEBUG) || defined(SIMULATOR)
134 #ifdef ROCKBOX_HAS_LOGF
144 __cyg_profile_func_enter
,
145 __cyg_profile_func_exit
,
148 #ifdef HAVE_RECORDING
157 (open_func
)PREFIX(open
),
159 (read_func
)PREFIX(read
),
161 (write_func
)PREFIX(write
),
162 round_value_to_list32
,
164 #endif /* HAVE_RECORDING */
166 /* new stuff at the end, sort into place next time
167 the API gets incompatible */
170 void codec_get_full_path(char *path
, const char *codec_root_fn
)
172 snprintf(path
, MAX_PATH
-1, "%s/%s." CODEC_EXTENSION
,
173 CODECS_DIR
, codec_root_fn
);
176 /* Returns pointer to and size of free codec RAM. Aligns to CACHEALIGN_SIZE. */
177 void *codec_get_buffer_callback(size_t *size
)
179 void *buf
= &codecbuf
[codec_size
];
180 ssize_t s
= CODEC_SIZE
- codec_size
;
186 ALIGN_BUFFER(buf
, *size
, CACHEALIGN_SIZE
);
191 /** codec loading and call interface **/
192 static void *curr_handle
= NULL
;
193 static struct codec_header
*c_hdr
= NULL
;
195 static int codec_load_ram(struct codec_api
*api
)
197 struct lc_header
*hdr
;
199 c_hdr
= lc_get_header(curr_handle
);
200 hdr
= c_hdr
? &c_hdr
->lc_hdr
: NULL
;
203 || (hdr
->magic
!= CODEC_MAGIC
204 #ifdef HAVE_RECORDING
205 && hdr
->magic
!= CODEC_ENC_MAGIC
208 || hdr
->target_id
!= TARGET_ID
209 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
210 || hdr
->load_addr
!= codecbuf
211 || hdr
->end_addr
> codecbuf
+ CODEC_SIZE
215 logf("codec header error");
216 lc_close(curr_handle
);
221 if (hdr
->api_version
> CODEC_API_VERSION
222 || hdr
->api_version
< CODEC_MIN_API_VERSION
) {
223 logf("codec api version error");
224 lc_close(curr_handle
);
229 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
230 codec_size
= hdr
->end_addr
- codecbuf
;
237 logf("Codec: calling entrypoint");
238 return c_hdr
->entry_point(CODEC_LOAD
);
241 int codec_load_buf(int hid
, struct codec_api
*api
)
243 int rc
= bufread(hid
, CODEC_SIZE
, codecbuf
);
246 logf("Codec: cannot read buf handle");
250 curr_handle
= lc_open_from_mem(codecbuf
, rc
);
252 if (curr_handle
== NULL
) {
253 logf("Codec: load error");
257 return codec_load_ram(api
);
260 int codec_load_file(const char *plugin
, struct codec_api
*api
)
264 codec_get_full_path(path
, plugin
);
266 curr_handle
= lc_open(path
, codecbuf
, CODEC_SIZE
);
268 if (curr_handle
== NULL
) {
269 logf("Codec: cannot read file");
273 return codec_load_ram(api
);
276 int codec_run_proc(void)
278 if (curr_handle
== NULL
) {
279 logf("Codec: no codec to run");
283 logf("Codec: entering run state");
284 return c_hdr
->run_proc();
287 int codec_close(void)
289 int status
= CODEC_OK
;
291 if (curr_handle
!= NULL
) {
292 logf("Codec: cleaning up");
293 status
= c_hdr
->entry_point(CODEC_UNLOAD
);
294 lc_close(curr_handle
);