From 0e9bc01ee4698df730a808eba7db7f5fc99f42e9 Mon Sep 17 00:00:00 2001 From: jonno Date: Wed, 18 Jul 2007 14:43:00 +0000 Subject: [PATCH] start of a codec thread. doesnt work. for some reason ci is being set to 0x0 instead of api :'( git-svn-id: svn://jdgordon.mine.nu/mob@59 9862a28c-4e93-4879-ac26-10afcf840a8f --- merge.patch | 206 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 198 insertions(+), 8 deletions(-) diff --git a/merge.patch b/merge.patch index 659703a..1e02ae9 100644 --- a/merge.patch +++ b/merge.patch @@ -1,3 +1,171 @@ +Index: apps/codecs.c +=================================================================== +--- apps/codecs.c (revision 13913) ++++ apps/codecs.c (working copy) +@@ -47,6 +47,7 @@ + #include "mp3data.h" + #include "powermgmt.h" + #include "system.h" ++#include "thread.h" + #include "sound.h" + #include "splash.h" + #include "general.h" +@@ -202,7 +203,7 @@ + + hdr = sim_codec_load_ram(codecptr, size, ptr2, bufwrap, &pd); + api->discard_codec(); +- ++debugf("%x\n", api); + if (pd == NULL) + return CODEC_ERROR; + +@@ -253,3 +254,93 @@ + + return codec_load_ram(codecbuf, (size_t)rc, NULL, 0, api); + } ++ ++/****** CODEC thread stuff ********/ ++enum codec_thread_messages { ++ CODEC_LOAD_HANDLE, /* data == handle of the file */ ++}; ++ ++static int current_handle; ++size_t codec_read_filebuf(void *ptr, size_t size) ++{ ++ char *data; ++ int read; ++ while ((read = bufread(current_handle, size, &data)) == -2) /* wait for data */ ++ yield(); ++ DEBUGF("%d\n", read); ++ bufadvance(current_handle, read); ++ memcpy(ptr, data, read); ++ return read; ++} ++ ++static struct event_queue codec_queue;// NOCACHEBSS_ATTR; ++static long codec_stack[(DEFAULT_STACK_SIZE + 0x2000)/sizeof(long)];// IBSS_ATTR; ++static const char codec_thread_name[] = "codec"; ++void codec_load_handle(int handle) ++{ ++ queue_post(&codec_queue, CODEC_LOAD_HANDLE, handle); ++} ++int track_handle; ++static void codec_thread(void) ++{ ++ struct event ev; ++ int rc; ++ while (1) ++ { ++ queue_wait(&codec_queue, &ev); ++ ++ switch (ev.id) { ++ case CODEC_LOAD_HANDLE: ++ DEBUGF("codec < CODEC_LOAD_HANDLE %d\n", ev.data); ++ rc = 0; ++ ssize_t read; ++ do { ++ char *data; ++ read = bufgetdata(ev.data,CODEC_SIZE-rc, &data); ++ if (read == -2) ++ { ++ yield(); ++ continue; ++ } ++ else ++ { ++ bufadvance(ev.data, read); ++ DEBUGF("%d %d\n", rc, read); ++ if (read == 0) ++ { ++ DEBUGF("blaa\n"); ++ bufclose(ev.data); ++ current_handle = track_handle; ++ codec_load_ram(codecbuf, (size_t)rc, NULL, 0, &ci); ++ break; ++ } ++ memcpy(&codecbuf[rc], data, read); ++ rc += read; ++ bufadvance(ev.data, read); ++ } ++ } while (1); ++ /* else error */ ++ break; ++ ++#ifndef SIMULATOR ++ case SYS_USB_CONNECTED: ++ DEBUGF("codec < SYS_USB_CONNECTED"); ++ queue_clear(&codec_queue); ++ usb_acknowledge(SYS_USB_CONNECTED_ACK); ++ usb_wait_for_disconnect(&codec_queue); ++ break; ++#endif ++ ++ default: ++ DEBUGF("codec < default"); ++ } ++ } ++} ++ ++void codec_thread_init(void) ++{ ++ ci.read_filebuf = codec_read_filebuf; ++ create_thread( codec_thread, codec_stack, sizeof(codec_stack), ++ codec_thread_name IF_PRIO(, PRIORITY_PLAYBACK) ++ IF_COP(, CPU, true)); ++} +Index: apps/codecs.h +=================================================================== +--- apps/codecs.h (revision 13913) ++++ apps/codecs.h (working copy) +@@ -286,4 +286,6 @@ + /* defined by the codec */ + enum codec_status codec_start(struct codec_api* rockbox); + ++void codec_thread_init(void); ++void codec_load_handle(int handle); + #endif +Index: apps/playback.c +=================================================================== +--- apps/playback.c (revision 13913) ++++ apps/playback.c (working copy) +@@ -3802,14 +3802,15 @@ + /* audio_reset_buffer must to know the size of voice buffer so init + talk first */ + talk_init(); +- ++#if 0 + /* Create the threads late now that we shouldn't be yielding again before + returning */ + codec_thread_p = create_thread( + codec_thread, codec_stack, sizeof(codec_stack), + codec_thread_name IF_PRIO(, PRIORITY_PLAYBACK) + IF_COP(, CPU, true)); +- ++#endif ++ codec_thread_init(); + create_thread(audio_thread, audio_stack, sizeof(audio_stack), + audio_thread_name IF_PRIO(, PRIORITY_BUFFERING) + IF_COP(, CPU, false)); +@@ -3840,4 +3841,19 @@ + eq_hw_enable(global_settings.eq_hw_enabled); + #endif + audio_set_buffer_margin(global_settings.buffer_margin); ++ ++ /* test time! */ ++ int codec_handle = bufopen(CODECS_DIR "/wav.codec", 0); ++ extern int track_handle; ++ int fd = open("/a.wav", O_RDONLY); ++ get_metadata(&tracks[0],fd,"/a.wav",v1first); ++ close(fd); ++ ci.id3 = &tracks[0].id3; ++ ci.id3->offset = 0; ++ ci.stop_codec = 0; ++ ci.taginfo_ready = 1; ++ track_handle = bufopen("/a.wav",0); ++ yield(); ++ codec_load_handle(codec_handle); ++ + } /* audio_init */ Index: apps/SOURCES =================================================================== --- apps/SOURCES (revision 13913) @@ -14,7 +182,7 @@ Index: apps/buffering.c =================================================================== --- apps/buffering.c (revision 0) +++ apps/buffering.c (revision 0) -@@ -0,0 +1,710 @@ +@@ -0,0 +1,717 @@ +#include "config.h" +#include +#include @@ -22,6 +190,7 @@ Index: apps/buffering.c +#include +#include "buffering.h" + ++#include "ata.h" +#include "system.h" +#include "thread.h" +#include "file.h" @@ -47,7 +216,9 @@ Index: apps/buffering.c +#include "playback.h" +#include "pcmbuf.h" +#include "buffer.h" -+ ++#ifdef SIMULATOR ++#define ata_disk_is_active() 1 ++#endif +#define GUARD_SIZE (32*1024) + +/* amount of data to read in one read() call */ @@ -309,14 +480,14 @@ Index: apps/buffering.c + + if (h->offset) + lseek(h->fd, h->offset, SEEK_SET); -+ h->filesize = filesize(fd); ++ h->filesize = filesize(h->fd); + h->filerem = h->filesize - h->offset; + h->data = buf_widx; -+ h->data_len = size; ++ h->data_len = h->filerem; + h->available = 0; + h->state = STATE_UNKNOWN; + -+ buf_widx = RINGBUF_ADD(buf_widx, size); ++ buf_widx = RINGBUF_ADD(buf_widx, h->filerem); /* is this line correct? */ + } + + if (h->filerem == 0) { @@ -483,7 +654,7 @@ Index: apps/buffering.c +{ + DEBUGF("bufopen: %s (offset: %ld)\n", file, offset); + int fd = -1; -+ struct memory_handle *h = add_handle(&size); ++ struct memory_handle *h = add_handle(NULL); + if (!h) + { + DEBUGF("failed to add handle\n"); @@ -497,7 +668,7 @@ Index: apps/buffering.c + h->available = 0; + h->state = STATE_UNKNOWN; + -+ if (!ata_is_active()) ++ if (!ata_disk_is_active()) + return h->id; + + fd = open(file, O_RDONLY); @@ -519,6 +690,7 @@ Index: apps/buffering.c + buf_widx = RINGBUF_ADD(buf_widx, size); + + DEBUGF("added handle : %d\n", h->id); ++ buffer_handle(h); + return h->id; +} + @@ -618,11 +790,14 @@ Index: apps/buffering.c + if (!h) + return -1; + ++ DEBUGF("bufgetdata: %d %d\n", h->available, h->filerem); + if (h->available == 0 && h->filerem > 0) + return -2; -+ + if (h->available == 0 && h->filerem == 0) ++ { ++ DEBUGF("sadlkfjhasldkhflasd\n"); + return 0; ++ } + + ssize_t ret; + @@ -808,6 +983,21 @@ Index: apps/buffering.h +void buffering_enable(bool enable); + +#endif +Index: apps/codecs/wav.c +=================================================================== +--- apps/codecs/wav.c (revision 13913) ++++ apps/codecs/wav.c (working copy) +@@ -236,7 +236,10 @@ + } + + while (!*ci->taginfo_ready && !ci->stop_codec) ++ { ++ DEBUGF("sleep\n"); + ci->sleep(1); ++ } + + codec_set_replaygain(ci->id3); + Index: apps/main.c =================================================================== --- apps/main.c (revision 13913) -- 2.11.4.GIT