summaryrefslogtreecommitdiff
path: root/src/cachemanager.h
diff options
context:
space:
mode:
authorJonas Suhr Christensen <jsc@umbraculum.org>2015-04-11 12:55:14 +0200
committerJonas Suhr Christensen <jsc@umbraculum.org>2015-04-11 12:55:14 +0200
commitaad47c980590f8f3a039a92a62f9d93f8755e060 (patch)
tree2b8c4d0b986fea0aebe9b5af21ffec0adea83278 /src/cachemanager.h
parentac5125e6eb16ec769b4fa541366898e0ebc83923 (diff)
parent9380bfd197d25712b08be41c0fc91e11ea364a94 (diff)
Merge branch 'diskstreaming' of http://git.drumgizmo.org/drumgizmo into diskstreaming
Conflicts: src/cachemanager.h Fixed conflicts.
Diffstat (limited to 'src/cachemanager.h')
-rw-r--r--src/cachemanager.h97
1 files changed, 73 insertions, 24 deletions
diff --git a/src/cachemanager.h b/src/cachemanager.h
index 6a60880..d2af6bf 100644
--- a/src/cachemanager.h
+++ b/src/cachemanager.h
@@ -44,42 +44,91 @@
class AudioFile;
typedef int cacheid_t;
+
+//TODO:
+// 1: Move nodata initialisation to init method.
+// 2: Make semaphore in thread to block init call until thread has been started.
+
+//// next
+// Pre: preloaded contains 2 x framesize. chunk size is framesize.
+// allocate 2 chunks and copy initial_samples_needed to first buffer from
+// preloaded data and enough to fill up the second buffer from preloaded
+// returns the first buffer and its size in &size.
+// get id from "free stack" and store pointers to buffers in id vector.
+// event: open sndfile handle (if not already open) and increase refcount
+
+//// next
+// Return which ever buffer is the front, swap them and add event to load the
+// next chunk.
+
+//// close
+// decrement file handle refcounter and close file if it is 0.
+// free the 2 buffers
+// (do not erase from the id vector), push index to
+// "free stack" for reuse.
+
class CacheManager : public Thread {
public:
+ /**
+ * Empty constructor...
+ */
CacheManager();
+
+ /**
+ * Destroy object and stop thread if needed.
+ */
~CacheManager();
+ /**
+ * Initialise cache manager and allocate needed resources
+ * This method starts the cache manager thread.
+ * This method blocks until the thread has been started.
+ * @param poolsize The maximum number of parellel events supported.
+ */
void init(size_t poolsize);
- void deinit();
-
- void thread_main();
- // Pre: preloaded contains 2 x framesize. chunk size is framesize.
- // allocate 2 chunks and copy initial_samples_needed to first buffer from
- // preloaded data and enough to fill up the second buffer from preloaded
- // returns the first buffer and its size in &size.
- // get id from "free stack" and store pointers to buffers in id vector.
- // event: open sndfile handle (if not already open) and increase refcount
- sample_t *open(AudioFile *file, size_t initial_samples_needed, int channel, cacheid_t &new_id);
+ /**
+ * Stop thread and clean up resources.
+ * This method blocks until the thread has stopped.
+ */
+ void deinit();
- // Return which ever buffer is the front, swap them and add event to load the
- // next chunk.
+ /**
+ * Register new cache entry.
+ * Prepares an entry in the cache manager for future disk streaming.
+ * @param file A pointer to the file which is to be streamed from.
+ * @param initial_samples_needed The number of samples needed in the first
+ * read that is not nessecarily of framesize. This is the number of samples
+ * from the input event offset to the end of the frame in which it resides.
+ * initial_samples_needed <= framesize.
+ * @param channel The channel to which the cache id will be bound.
+ * @param [out] new_id The newly created cache id.
+ * @return A pointer to the first buffer containing the
+ * 'initial_samples_needed' number of samples.
+ */
+ sample_t *open(AudioFile *file, size_t initial_samples_needed, int channel,
+ cacheid_t &new_id);
+
+ /**
+ * Get next buffer.
+ * Returns the next buffer for reading based on cache id.
+ * This function will (if needed) schedule a new disk read to make sure that
+ * data is available in the next call to this method.
+ * @param id The cache id to read from.
+ * @param [out] size The size of the returned buffer.
+ * @return A pointer to the buffer.
+ */
sample_t *next(cacheid_t id, size_t &size);
- // decrement file handle refcounter and close file if it is 0.
- // free the 2 buffers
- // (do not erase from the id vector), push index to
- // "free stack" for reuse.
+ /**
+ * Unregister cache entry.
+ * Close associated file handles and free associated buffers.
+ * @param id The cache id to close.
+ */
void close(cacheid_t id);
- // id vector:
- // {
- // AudioFile*
- // channel
- // buffer1, buffer2
- // position
- // (ready?)
- // }
+ ///! Internal thread main method - needs to be public.
+ void thread_main();
private: