Android: Partly revert r29569 and only call the new getJavaEnvironment() when needed.
[maemo-rb.git] / apps / codecs.c
blob28e8c2a1c01ef5b2eee9918df6143cf258043942
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
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 ****************************************************************************/
21 #include "config.h"
23 #include <stdbool.h>
24 #include <string.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <timefuncs.h>
28 #include <ctype.h>
29 #include <stdarg.h>
30 #include "string-extra.h"
31 #include "load_code.h"
32 #include "debug.h"
33 #include "button.h"
34 #include "dir.h"
35 #include "file.h"
36 #include "kernel.h"
37 #include "screens.h"
38 #include "misc.h"
39 #include "codecs.h"
40 #include "lang.h"
41 #include "keyboard.h"
42 #include "buffering.h"
43 #include "mp3_playback.h"
44 #include "backlight.h"
45 #include "storage.h"
46 #include "talk.h"
47 #include "mp3data.h"
48 #include "powermgmt.h"
49 #include "system.h"
50 #include "sound.h"
51 #include "splash.h"
52 #include "general.h"
54 #define LOGF_ENABLE
55 #include "logf.h"
57 #if (CONFIG_PLATFORM & (PLATFORM_SDL|PLATFORM_MAEMO|PLATFORM_PANDORA))
58 #define PREFIX(_x_) sim_ ## _x_
59 #else
60 #define PREFIX(_x_) _x_
61 #endif
63 #if (CONFIG_PLATFORM & PLATFORM_HOSTED)
64 #if CONFIG_CODEC == SWCODEC
65 unsigned char codecbuf[CODEC_SIZE];
66 #endif
67 #endif
69 size_t codec_size;
71 extern void* plugin_get_audio_buffer(size_t *buffer_size);
73 #if (CONFIG_PLATFORM & PLATFORM_NATIVE) && defined(HAVE_RECORDING)
74 #undef open
75 static int open(const char* pathname, int flags, ...)
77 return file_open(pathname, flags);
79 #endif
80 struct codec_api ci = {
82 0, /* filesize */
83 0, /* curpos */
84 NULL, /* id3 */
85 NULL, /* taginfo_ready */
86 false, /* stop_codec */
87 0, /* new_track */
88 0, /* seek_time */
89 NULL, /* struct dsp_config *dsp */
90 NULL, /* codec_get_buffer */
91 NULL, /* pcmbuf_insert */
92 NULL, /* set_elapsed */
93 NULL, /* read_filebuf */
94 NULL, /* request_buffer */
95 NULL, /* advance_buffer */
96 NULL, /* seek_buffer */
97 NULL, /* seek_complete */
98 NULL, /* request_next_track */
99 NULL, /* set_offset */
100 NULL, /* configure */
102 /* kernel/ system */
103 #if defined(CPU_ARM) && CONFIG_PLATFORM & PLATFORM_NATIVE
104 __div0,
105 #endif
106 sleep,
107 yield,
109 #if NUM_CORES > 1
110 create_thread,
111 thread_thaw,
112 thread_wait,
113 semaphore_init,
114 semaphore_wait,
115 semaphore_release,
116 #endif
118 cpucache_flush,
119 cpucache_invalidate,
121 /* strings and memory */
122 strcpy,
123 strlen,
124 strcmp,
125 strcat,
126 memset,
127 memcpy,
128 memmove,
129 memcmp,
130 memchr,
131 strcasestr,
132 #if defined(DEBUG) || defined(SIMULATOR)
133 debugf,
134 #endif
135 #ifdef ROCKBOX_HAS_LOGF
136 logf,
137 #endif
139 (qsort_func)qsort,
140 &global_settings,
142 #ifdef RB_PROFILE
143 profile_thread,
144 profstop,
145 __cyg_profile_func_enter,
146 __cyg_profile_func_exit,
147 #endif
149 #ifdef HAVE_RECORDING
150 enc_get_inputs,
151 enc_set_parameters,
152 enc_get_chunk,
153 enc_finish_chunk,
154 enc_get_pcm_data,
155 enc_unget_pcm_data,
157 /* file */
158 (open_func)PREFIX(open),
159 PREFIX(close),
160 (read_func)PREFIX(read),
161 PREFIX(lseek),
162 (write_func)PREFIX(write),
163 round_value_to_list32,
165 #endif /* HAVE_RECORDING */
167 /* new stuff at the end, sort into place next time
168 the API gets incompatible */
171 void codec_get_full_path(char *path, const char *codec_root_fn)
173 snprintf(path, MAX_PATH-1, "%s/%s." CODEC_EXTENSION,
174 CODECS_DIR, codec_root_fn);
177 static void * codec_load_ram(void *handle, struct codec_api *api)
179 struct codec_header *c_hdr = lc_get_header(handle);
180 struct lc_header *hdr = c_hdr ? &c_hdr->lc_hdr : NULL;
182 if (hdr == NULL
183 || (hdr->magic != CODEC_MAGIC
184 #ifdef HAVE_RECORDING
185 && hdr->magic != CODEC_ENC_MAGIC
186 #endif
188 || hdr->target_id != TARGET_ID
189 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
190 || hdr->load_addr != codecbuf
191 || hdr->end_addr > codecbuf + CODEC_SIZE
192 #endif
195 logf("codec header error");
196 lc_close(handle);
197 return NULL;
200 if (hdr->api_version > CODEC_API_VERSION
201 || hdr->api_version < CODEC_MIN_API_VERSION) {
202 logf("codec api version error");
203 lc_close(handle);
204 return NULL;
207 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
208 codec_size = hdr->end_addr - codecbuf;
209 #else
210 codec_size = 0;
211 #endif
213 *(c_hdr->api) = api;
215 return handle;
218 void * codec_load_buf(int hid, struct codec_api *api)
220 int rc;
221 void *handle;
222 rc = bufread(hid, CODEC_SIZE, codecbuf);
223 if (rc < 0) {
224 logf("Codec: cannot read buf handle");
225 return NULL;
228 handle = lc_open_from_mem(codecbuf, rc);
230 if (handle == NULL) {
231 logf("error loading codec");
232 return NULL;
235 return codec_load_ram(handle, api);
238 void * codec_load_file(const char *plugin, struct codec_api *api)
240 char path[MAX_PATH];
241 void *handle;
243 codec_get_full_path(path, plugin);
245 handle = lc_open(path, codecbuf, CODEC_SIZE);
247 if (handle == NULL) {
248 logf("Codec: cannot read file");
249 return NULL;
252 return codec_load_ram(handle, api);
255 int codec_begin(void *handle)
257 int status = CODEC_ERROR;
258 struct codec_header *c_hdr;
260 c_hdr = lc_get_header(handle);
262 if (c_hdr != NULL) {
263 logf("Codec: calling entry_point");
264 status = c_hdr->entry_point();
267 return status;
270 void codec_close(void *handle)
272 if (handle)
273 lc_close(handle);