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 */
78 NULL
, /* get_codec_memory */
79 NULL
, /* pcmbuf_insert */
80 NULL
, /* pcmbuf_insert_split */
81 NULL
, /* set_elapsed */
82 NULL
, /* read_filebuf */
83 NULL
, /* request_buffer */
84 NULL
, /* advance_buffer */
85 NULL
, /* advance_buffer_loc */
86 NULL
, /* seek_buffer */
87 NULL
, /* seek_complete */
88 NULL
, /* mp3_get_filepos */
89 NULL
, /* request_next_track */
90 NULL
, /* discard_codec */
91 NULL
, /* set_offset */
97 (open_func
)PREFIX(open
),
101 (creat_func
)PREFIX(creat
),
123 default_event_handler
,
124 default_event_handler_ex
,
127 reset_poweroff_timer
,
131 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
136 /* strings and memory */
165 /* playback control */
176 audio_has_changed_track
,
178 audio_flush_and_reload_tracks
,
188 plugin_get_audio_buffer
,
190 #if defined(DEBUG) || defined(SIMULATOR)
193 #ifdef ROCKBOX_HAS_LOGF
211 /* new stuff at the end, sort into place next time
212 the API gets incompatible */
216 int codec_load_ram(char* codecptr
, int size
, void* ptr2
, int bufwrap
,
217 struct codec_api
*api
)
219 struct codec_header
*hdr
;
224 if ((char *)&codecbuf
[0] != codecptr
) {
225 /* zero out codec buffer to ensure a properly zeroed bss area */
226 memset(codecbuf
, 0, CODEC_SIZE
);
228 size
= MIN(size
, CODEC_SIZE
);
229 copy_n
= MIN(size
, bufwrap
);
230 memcpy(codecbuf
, codecptr
, copy_n
);
231 if (size
- copy_n
> 0) {
232 memcpy(&codecbuf
[copy_n
], ptr2
, size
- copy_n
);
234 api
->discard_codec();
236 hdr
= (struct codec_header
*)codecbuf
;
238 if (size
<= (signed)sizeof(struct codec_header
)
239 || hdr
->magic
!= CODEC_MAGIC
240 || hdr
->target_id
!= TARGET_ID
241 || hdr
->load_addr
!= codecbuf
242 || hdr
->end_addr
> codecbuf
+ CODEC_SIZE
)
244 logf("codec header error");
247 #else /* SIMULATOR */
250 hdr
= sim_codec_load_ram(codecptr
, size
, ptr2
, bufwrap
, &pd
);
255 || hdr
->magic
!= CODEC_MAGIC
256 || hdr
->target_id
!= TARGET_ID
) {
260 #endif /* SIMULATOR */
261 if (hdr
->api_version
> CODEC_API_VERSION
262 || hdr
->api_version
< CODEC_MIN_API_VERSION
) {
268 status
= hdr
->entry_point(api
);
275 int codec_load_file(const char *plugin
, struct codec_api
*api
)
281 /* zero out codec buffer to ensure a properly zeroed bss area */
282 memset(codecbuf
, 0, CODEC_SIZE
);
284 fd
= open(plugin
, O_RDONLY
);
286 snprintf(msgbuf
, sizeof(msgbuf
)-1, "Couldn't load codec: %s", plugin
);
287 logf("Codec load error:%d", fd
);
288 gui_syncsplash(HZ
*2, true, msgbuf
);
292 rc
= read(fd
, &codecbuf
[0], CODEC_SIZE
);
295 logf("Codec read error");
299 return codec_load_ram(codecbuf
, (size_t)rc
, NULL
, 0, api
);