1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 Björn Stenberg
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
25 #include <timefuncs.h>
42 #include "mp3_playback.h"
44 #include "backlight.h"
48 #include "powermgmt.h"
55 #if CONFIG_CODEC == SWCODEC
56 unsigned char codecbuf
[CODEC_SIZE
];
58 void *sim_codec_load_ram(char* codecptr
, int size
,
59 void* ptr2
, int bufwrap
, void **pd
);
60 void sim_codec_close(void *pd
);
62 #define sim_codec_close(x)
63 extern unsigned char codecbuf
[];
66 extern void* plugin_get_audio_buffer(int *buffer_size
);
68 struct codec_api ci_voice
;
70 struct codec_api ci
= {
75 NULL
, /* taginfo_ready */
76 false, /* stop_codec */
79 NULL
, /* get_codec_memory */
80 NULL
, /* pcmbuf_insert */
81 NULL
, /* pcmbuf_insert_split */
82 NULL
, /* set_elapsed */
83 NULL
, /* read_filebuf */
84 NULL
, /* request_buffer */
85 NULL
, /* advance_buffer */
86 NULL
, /* advance_buffer_loc */
87 NULL
, /* seek_buffer */
88 NULL
, /* seek_complete */
89 NULL
, /* mp3_get_filepos */
90 NULL
, /* request_next_track */
91 NULL
, /* discard_codec */
92 NULL
, /* set_offset */
98 (open_func
)PREFIX(open
),
102 (creat_func
)PREFIX(creat
),
124 default_event_handler
,
125 default_event_handler_ex
,
126 create_thread_on_core
,
128 reset_poweroff_timer
,
132 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
137 /* strings and memory */
166 /* playback control */
177 audio_has_changed_track
,
179 audio_flush_and_reload_tracks
,
189 plugin_get_audio_buffer
,
191 #if defined(DEBUG) || defined(SIMULATOR)
194 #ifdef ROCKBOX_HAS_LOGF
212 #if defined(HAVE_RECORDING) && !defined(SIMULATOR)
218 enc_wavbuf_near_empty
,
220 &enc_set_header_callback
,
223 /* new stuff at the end, sort into place next time
224 the API gets incompatible */
228 void codec_get_full_path(char *path
, const char *codec_fn
)
230 /* Create full codec path */
231 snprintf(path
, MAX_PATH
-1, CODECS_DIR
"/%s", codec_fn
);
234 int codec_load_ram(char* codecptr
, int size
, void* ptr2
, int bufwrap
,
235 struct codec_api
*api
)
237 struct codec_header
*hdr
;
242 if ((char *)&codecbuf
[0] != codecptr
) {
243 /* zero out codec buffer to ensure a properly zeroed bss area */
244 memset(codecbuf
, 0, CODEC_SIZE
);
246 size
= MIN(size
, CODEC_SIZE
);
247 copy_n
= MIN(size
, bufwrap
);
248 memcpy(codecbuf
, codecptr
, copy_n
);
249 if (size
- copy_n
> 0) {
250 memcpy(&codecbuf
[copy_n
], ptr2
, size
- copy_n
);
252 api
->discard_codec();
254 hdr
= (struct codec_header
*)codecbuf
;
256 if (size
<= (signed)sizeof(struct codec_header
)
257 || hdr
->magic
!= CODEC_MAGIC
258 || hdr
->target_id
!= TARGET_ID
259 || hdr
->load_addr
!= codecbuf
260 || hdr
->end_addr
> codecbuf
+ CODEC_SIZE
)
262 logf("codec header error");
265 #else /* SIMULATOR */
268 hdr
= sim_codec_load_ram(codecptr
, size
, ptr2
, bufwrap
, &pd
);
269 api
->discard_codec();
275 || hdr
->magic
!= CODEC_MAGIC
276 || hdr
->target_id
!= TARGET_ID
) {
280 #endif /* SIMULATOR */
281 if (hdr
->api_version
> CODEC_API_VERSION
282 || hdr
->api_version
< CODEC_MIN_API_VERSION
) {
288 status
= hdr
->entry_point(api
);
295 int codec_load_file(const char *plugin
, struct codec_api
*api
)
302 codec_get_full_path(path
, plugin
);
304 /* zero out codec buffer to ensure a properly zeroed bss area */
305 memset(codecbuf
, 0, CODEC_SIZE
);
307 fd
= open(path
, O_RDONLY
);
309 snprintf(msgbuf
, sizeof(msgbuf
)-1, "Couldn't load codec: %s", path
);
310 logf("Codec load error:%d", fd
);
311 gui_syncsplash(HZ
*2, true, msgbuf
);
315 rc
= read(fd
, &codecbuf
[0], CODEC_SIZE
);
318 logf("Codec read error");
322 return codec_load_ram(codecbuf
, (size_t)rc
, NULL
, 0, api
);