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"
43 #include "backlight.h"
47 #include "powermgmt.h"
54 #if CONFIG_CODEC == SWCODEC
55 unsigned char codecbuf
[CODEC_SIZE
];
57 void *sim_codec_load_ram(char* codecptr
, int size
,
58 void* ptr2
, int bufwrap
, void **pd
);
59 void sim_codec_close(void *pd
);
61 #define sim_codec_close(x)
62 extern unsigned char codecbuf
[];
65 extern void* plugin_get_audio_buffer(int *buffer_size
);
67 struct codec_api ci_voice
;
69 struct codec_api ci
= {
74 NULL
, /* taginfo_ready */
75 false, /* stop_codec */
76 false, /* reload_codec */
96 (open_func
)PREFIX(open
),
100 (creat_func
)PREFIX(creat
),
122 default_event_handler
,
123 default_event_handler_ex
,
126 reset_poweroff_timer
,
130 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
135 /* strings and memory */
164 /* playback control */
175 audio_has_changed_track
,
177 audio_flush_and_reload_tracks
,
187 plugin_get_audio_buffer
,
189 #if defined(DEBUG) || defined(SIMULATOR)
192 #ifdef ROCKBOX_HAS_LOGF
210 /* new stuff at the end, sort into place next time
211 the API gets incompatible */
215 int codec_load_ram(char* codecptr
, int size
, void* ptr2
, int bufwrap
,
216 struct codec_api
*api
)
218 struct codec_header
*hdr
;
223 if ((char *)&codecbuf
[0] != codecptr
) {
224 /* zero out codec buffer to ensure a properly zeroed bss area */
225 memset(codecbuf
, 0, CODEC_SIZE
);
227 size
= MIN(size
, CODEC_SIZE
);
228 copy_n
= MIN(size
, bufwrap
);
229 memcpy(codecbuf
, codecptr
, copy_n
);
230 if (size
- copy_n
> 0) {
231 memcpy(&codecbuf
[copy_n
], ptr2
, size
- copy_n
);
234 hdr
= (struct codec_header
*)codecbuf
;
236 if (size
<= (signed)sizeof(struct codec_header
)
237 || hdr
->magic
!= CODEC_MAGIC
238 || hdr
->target_id
!= TARGET_ID
239 || hdr
->load_addr
!= codecbuf
240 || hdr
->end_addr
> codecbuf
+ CODEC_SIZE
)
242 logf("codec header error");
245 #else /* SIMULATOR */
248 hdr
= sim_codec_load_ram(codecptr
, size
, ptr2
, bufwrap
, &pd
);
253 || hdr
->magic
!= CODEC_MAGIC
254 || hdr
->target_id
!= TARGET_ID
) {
258 #endif /* SIMULATOR */
259 if (hdr
->api_version
> CODEC_API_VERSION
260 || hdr
->api_version
< CODEC_MIN_API_VERSION
) {
266 status
= hdr
->entry_point(api
);
273 int codec_load_file(const char *plugin
, struct codec_api
*api
)
279 /* zero out codec buffer to ensure a properly zeroed bss area */
280 memset(codecbuf
, 0, CODEC_SIZE
);
282 fd
= open(plugin
, O_RDONLY
);
284 snprintf(msgbuf
, sizeof(msgbuf
)-1, "Couldn't load codec: %s", plugin
);
285 logf("Codec load error:%d", fd
);
286 gui_syncsplash(HZ
*2, true, msgbuf
);
290 rc
= read(fd
, &codecbuf
[0], CODEC_SIZE
);
293 logf("Codec read error");
297 return codec_load_ram(codecbuf
, (size_t)rc
, NULL
, 0, api
);