summaryrefslogtreecommitdiff
path: root/apps/codecs.c
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2011-04-27 03:08:23 +0000
committerMichael Sevakis <jethead71@rockbox.org>2011-04-27 03:08:23 +0000
commitc537d5958e8b421ac4f9bef6c8b9e7425a6cf167 (patch)
tree7ed36518fb6524da7bbd913ba7619b85b5d15d23 /apps/codecs.c
parentdcf0f8de4a37ff1d2ea510aef75fa67977a8bdcc (diff)
downloadrockbox-c537d5958e8b421ac4f9bef6c8b9e7425a6cf167.tar.gz
rockbox-c537d5958e8b421ac4f9bef6c8b9e7425a6cf167.zip
Commit FS#12069 - Playback rework - first stages. Gives as thorough as possible a treatment of codec management, track change and metadata logic as possible while maintaining fairly narrow focus and not rewriting everything all at once. Please see the rockbox-dev mail archive on 2011-04-25 (Playback engine rework) for a more thorough manifest of what was addressed. Plugins and codecs become incompatible.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29785 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/codecs.c')
-rw-r--r--apps/codecs.c96
1 files changed, 52 insertions, 44 deletions
diff --git a/apps/codecs.c b/apps/codecs.c
index 28e8c2a1c0..25ace4969b 100644
--- a/apps/codecs.c
+++ b/apps/codecs.c
@@ -79,13 +79,10 @@ static int open(const char* pathname, int flags, ...)
79#endif 79#endif
80struct codec_api ci = { 80struct codec_api ci = {
81 81
82 0, /* filesize */ 82 0, /* filesize */
83 0, /* curpos */ 83 0, /* curpos */
84 NULL, /* id3 */ 84 NULL, /* id3 */
85 NULL, /* taginfo_ready */ 85 ERR_HANDLE_NOT_FOUND, /* audio_hid */
86 false, /* stop_codec */
87 0, /* new_track */
88 0, /* seek_time */
89 NULL, /* struct dsp_config *dsp */ 86 NULL, /* struct dsp_config *dsp */
90 NULL, /* codec_get_buffer */ 87 NULL, /* codec_get_buffer */
91 NULL, /* pcmbuf_insert */ 88 NULL, /* pcmbuf_insert */
@@ -95,9 +92,9 @@ struct codec_api ci = {
95 NULL, /* advance_buffer */ 92 NULL, /* advance_buffer */
96 NULL, /* seek_buffer */ 93 NULL, /* seek_buffer */
97 NULL, /* seek_complete */ 94 NULL, /* seek_complete */
98 NULL, /* request_next_track */
99 NULL, /* set_offset */ 95 NULL, /* set_offset */
100 NULL, /* configure */ 96 NULL, /* configure */
97 NULL, /* get_command */
101 98
102 /* kernel/ system */ 99 /* kernel/ system */
103#if defined(CPU_ARM) && CONFIG_PLATFORM & PLATFORM_NATIVE 100#if defined(CPU_ARM) && CONFIG_PLATFORM & PLATFORM_NATIVE
@@ -174,10 +171,16 @@ void codec_get_full_path(char *path, const char *codec_root_fn)
174 CODECS_DIR, codec_root_fn); 171 CODECS_DIR, codec_root_fn);
175} 172}
176 173
177static void * codec_load_ram(void *handle, struct codec_api *api) 174/** codec loading and call interface **/
175static void *curr_handle = NULL;
176static struct codec_header *c_hdr = NULL;
177
178static int codec_load_ram(struct codec_api *api)
178{ 179{
179 struct codec_header *c_hdr = lc_get_header(handle); 180 struct lc_header *hdr;
180 struct lc_header *hdr = c_hdr ? &c_hdr->lc_hdr : NULL; 181
182 c_hdr = lc_get_header(curr_handle);
183 hdr = c_hdr ? &c_hdr->lc_hdr : NULL;
181 184
182 if (hdr == NULL 185 if (hdr == NULL
183 || (hdr->magic != CODEC_MAGIC 186 || (hdr->magic != CODEC_MAGIC
@@ -193,15 +196,17 @@ static void * codec_load_ram(void *handle, struct codec_api *api)
193 ) 196 )
194 { 197 {
195 logf("codec header error"); 198 logf("codec header error");
196 lc_close(handle); 199 lc_close(curr_handle);
197 return NULL; 200 curr_handle = NULL;
201 return CODEC_ERROR;
198 } 202 }
199 203
200 if (hdr->api_version > CODEC_API_VERSION 204 if (hdr->api_version > CODEC_API_VERSION
201 || hdr->api_version < CODEC_MIN_API_VERSION) { 205 || hdr->api_version < CODEC_MIN_API_VERSION) {
202 logf("codec api version error"); 206 logf("codec api version error");
203 lc_close(handle); 207 lc_close(curr_handle);
204 return NULL; 208 curr_handle = NULL;
209 return CODEC_ERROR;
205 } 210 }
206 211
207#if (CONFIG_PLATFORM & PLATFORM_NATIVE) 212#if (CONFIG_PLATFORM & PLATFORM_NATIVE)
@@ -212,63 +217,66 @@ static void * codec_load_ram(void *handle, struct codec_api *api)
212 217
213 *(c_hdr->api) = api; 218 *(c_hdr->api) = api;
214 219
215 return handle; 220 logf("Codec: calling entrypoint");
221 return c_hdr->entry_point(CODEC_LOAD);
216} 222}
217 223
218void * codec_load_buf(int hid, struct codec_api *api) 224int codec_load_buf(int hid, struct codec_api *api)
219{ 225{
220 int rc; 226 int rc = bufread(hid, CODEC_SIZE, codecbuf);
221 void *handle; 227
222 rc = bufread(hid, CODEC_SIZE, codecbuf);
223 if (rc < 0) { 228 if (rc < 0) {
224 logf("Codec: cannot read buf handle"); 229 logf("Codec: cannot read buf handle");
225 return NULL; 230 return CODEC_ERROR;
226 } 231 }
227 232
228 handle = lc_open_from_mem(codecbuf, rc); 233 curr_handle = lc_open_from_mem(codecbuf, rc);
229 234
230 if (handle == NULL) { 235 if (curr_handle == NULL) {
231 logf("error loading codec"); 236 logf("Codec: load error");
232 return NULL; 237 return CODEC_ERROR;
233 } 238 }
234 239
235 return codec_load_ram(handle, api); 240 return codec_load_ram(api);
236} 241}
237 242
238void * codec_load_file(const char *plugin, struct codec_api *api) 243int codec_load_file(const char *plugin, struct codec_api *api)
239{ 244{
240 char path[MAX_PATH]; 245 char path[MAX_PATH];
241 void *handle;
242 246
243 codec_get_full_path(path, plugin); 247 codec_get_full_path(path, plugin);
244 248
245 handle = lc_open(path, codecbuf, CODEC_SIZE); 249 curr_handle = lc_open(path, codecbuf, CODEC_SIZE);
246 250
247 if (handle == NULL) { 251 if (curr_handle == NULL) {
248 logf("Codec: cannot read file"); 252 logf("Codec: cannot read file");
249 return NULL; 253 return CODEC_ERROR;
250 } 254 }
251 255
252 return codec_load_ram(handle, api); 256 return codec_load_ram(api);
253} 257}
254 258
255int codec_begin(void *handle) 259int codec_run_proc(void)
256{ 260{
257 int status = CODEC_ERROR; 261 if (curr_handle == NULL) {
258 struct codec_header *c_hdr; 262 logf("Codec: no codec to run");
259 263 return CODEC_ERROR;
260 c_hdr = lc_get_header(handle);
261
262 if (c_hdr != NULL) {
263 logf("Codec: calling entry_point");
264 status = c_hdr->entry_point();
265 } 264 }
266 265
267 return status; 266 logf("Codec: entering run state");
267 return c_hdr->run_proc();
268} 268}
269 269
270void codec_close(void *handle) 270int codec_close(void)
271{ 271{
272 if (handle) 272 int status = CODEC_OK;
273 lc_close(handle); 273
274 if (curr_handle != NULL) {
275 logf("Codec: cleaning up");
276 status = c_hdr->entry_point(CODEC_UNLOAD);
277 lc_close(curr_handle);
278 curr_handle = NULL;
279 }
280
281 return status;
274} 282}