summaryrefslogtreecommitdiff
path: root/src/cachemanager.cc
diff options
context:
space:
mode:
authorJonas Suhr Christensen <jsc@umbraculum.org>2015-04-10 16:28:03 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2016-01-20 13:22:07 +0100
commit99db25aae3c8f06b9bb1a17865e344cfe559b47e (patch)
tree31a894019a7514e9f9deb95e431880e61eb966b9 /src/cachemanager.cc
parent88cc4f41efcca827c22aab09e83efe729c89bc9b (diff)
Added unit test shell for cachemanager. Added cache manager logic - still needing audio related code.
Diffstat (limited to 'src/cachemanager.cc')
-rw-r--r--src/cachemanager.cc107
1 files changed, 105 insertions, 2 deletions
diff --git a/src/cachemanager.cc b/src/cachemanager.cc
index 2e9eab9..5e2adf0 100644
--- a/src/cachemanager.cc
+++ b/src/cachemanager.cc
@@ -3,8 +3,8 @@
* cachemanager.cc
*
* Fri Apr 10 10:39:24 CEST 2015
- * Copyright 2015 Bent Bisballe Nyeng
- * deva@aasimon.org
+ * Copyright 2015 Jonas Suhr Christensen
+ * jsc@umbraculum.org
****************************************************************************/
/*
@@ -26,3 +26,106 @@
*/
#include "cachemanager.h"
+#include <stdio.h>
+
+CacheManager::CacheManager()
+{
+}
+
+CacheManager::~CacheManager()
+{
+ wait_stop();
+}
+
+void CacheManager::init(int poolsize)
+{
+ id2cache.resize(poolsize);
+ for(int i = 0; i < poolsize; i++) {
+ availableids.push_back(i);
+ }
+
+ running = true;
+ run();
+}
+
+// Invariant: initial_samples_needed < preloaded audio data
+sample_t *CacheManager::open(AudioFile *file, int initial_samples_needed, int channel, cacheid_t &id)
+{
+ // What if no free ids is available?
+ m_ids.lock();
+ id = availableids.front();
+ availableids.pop_front();
+ m_ids.unlock();
+
+ cache_t c;
+ c.file = file;
+ c.channel = channel;
+ c.pos = initial_samples_needed;
+ // Allocate buffers
+ // Increase audio ref count
+
+ id2cache[id] = c;
+
+ event_t e;
+ e.id = id;
+ pushEvent(e);
+
+ return file->data;
+}
+
+void CacheManager::close(cacheid_t id)
+{
+ m_ids.lock();
+ availableids.push_back(id);
+ m_ids.unlock();
+
+ // Clean cache_t mapped to event
+ // Clean event list for other events mapped to this id?
+ // Maybe we need an event for this, that we can push in front of eventqueue (con: we dont read from disk when doing this stuff).
+ // Decrement audiofile ref count
+}
+
+sample_t *CacheManager::next(cacheid_t id, size_t &size)
+{
+ sample_t *s = NULL;
+ return s;
+}
+
+void CacheManager::loadNext(cacheid_t id)
+{
+ printf("Loading next...\n");
+
+ // If more is left of file
+ if(false) {
+ event_t e;
+ e.id = id;
+ pushEvent(e);
+ }
+}
+
+void CacheManager::thread_main()
+{
+ while(running) {
+ sem.wait();
+
+ m_events.lock();
+ if(eventqueue.empty()) {
+ event_t e = eventqueue.front();
+ eventqueue.pop_front();
+ m_events.unlock();
+
+ loadNext(e.id);
+ }
+ else {
+ m_events.unlock();
+ }
+ }
+}
+
+void CacheManager::pushEvent(event_t e)
+{
+ // Check that if event should be merged (Maybe by event queue (ie. push in front).
+ m_events.lock();
+ eventqueue.push_back(e);
+ m_events.unlock();
+}