summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2016-01-30 10:56:11 +0100
committerBent Bisballe Nyeng <deva@aasimon.org>2016-01-30 10:56:11 +0100
commitac1d5566d30b107fdea934ac704720242ef59a7c (patch)
treeed46cdc2ebc66612ade9bbac5f41097698cef042
parentaa635eb8da9804488513d1f3d422e4810e611bb8 (diff)
parent22715c84cc861ba6ce7e9caa5d214bb3f006679d (diff)
Merge branch 'diskstreaming_review_chaot' into diskstreaming
-rw-r--r--.gitignore5
-rw-r--r--src/audiocacheeventhandler.cc29
-rw-r--r--src/audiocacheeventhandler.h3
-rw-r--r--src/audiocachefile.cc26
-rw-r--r--src/audiocachefile.h2
-rw-r--r--test/audiocachefiletest.cc6
6 files changed, 35 insertions, 36 deletions
diff --git a/.gitignore b/.gitignore
index 362c682..9372e7d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -38,6 +38,11 @@ test/engine
test/gui
test/lv2
test/resource
+test/audiocache
+test/audiocacheeventhandler
+test/audiocachefile
+test/audiocacheidmanager
+test/configfile
drumgizmo-*.tar.gz
tst
vst/Makefile.mingw32
diff --git a/src/audiocacheeventhandler.cc b/src/audiocacheeventhandler.cc
index 6ec68b5..788cac6 100644
--- a/src/audiocacheeventhandler.cc
+++ b/src/audiocacheeventhandler.cc
@@ -41,7 +41,7 @@ enum class EventType {
class CacheEvent {
public:
- EventType eventType;
+ EventType event_type;
// For close event:
cacheid_t id;
@@ -105,8 +105,7 @@ void AudioCacheEventHandler::setThreaded(bool threaded)
{
start();
}
-
- if(!threaded && running)
+ else if(!threaded && running)
{
stop();
}
@@ -135,7 +134,7 @@ void AudioCacheEventHandler::pushLoadNextEvent(AudioCacheFile* afile,
volatile bool* ready)
{
CacheEvent cache_event;
- cache_event.eventType = EventType::LoadNext;
+ cache_event.event_type = EventType::LoadNext;
cache_event.pos = pos;
cache_event.afile = afile;
@@ -154,7 +153,7 @@ void AudioCacheEventHandler::pushLoadNextEvent(AudioCacheFile* afile,
void AudioCacheEventHandler::pushCloseEvent(cacheid_t id)
{
CacheEvent cache_event;
- cache_event.eventType = EventType::Close;
+ cache_event.event_type = EventType::Close;
cache_event.id = id;
pushEvent(cache_event);
@@ -172,17 +171,17 @@ void AudioCacheEventHandler::setChunkSize(size_t chunksize)
return;
}
- DEBUG(cache, "1)\n");
+ DEBUG(cache, "setChunkSize 1\n");
// Remove all events from event queue.
clearEvents();
- DEBUG(cache, "2)\n");
+ DEBUG(cache, "setChunkSize 2\n");
// Skip all active cacheids and make their buffers point at nodata.
id_manager.disableActive();
- DEBUG(cache, "3)\n");
+ DEBUG(cache, "setChunkSize 3\n");
this->chunksize = chunksize;
}
@@ -203,7 +202,7 @@ void AudioCacheEventHandler::clearEvents()
// Iterate all events ignoring load events and handling close events.
for(auto& event : eventqueue)
{
- if(event.eventType == EventType::Close)
+ if(event.event_type == EventType::Close)
{
handleCloseCache(event.id); // This method does not lock.
}
@@ -224,21 +223,21 @@ void AudioCacheEventHandler::handleCloseEvent(CacheEvent& cache_event)
handleCloseCache(cache_event.id);
}
-void AudioCacheEventHandler::handleCloseCache(cacheid_t cacheid)
+void AudioCacheEventHandler::handleCloseCache(cacheid_t id)
{
- auto& cache = id_manager.getCache(cacheid);
+ auto& cache = id_manager.getCache(id);
files.releaseFile(cache.afile->getFilename());
delete[] cache.front;
delete[] cache.back;
- id_manager.releaseID(cacheid);
+ id_manager.releaseID(id);
}
void AudioCacheEventHandler::handleEvent(CacheEvent& cache_event)
{
- switch(cache_event.eventType)
+ switch(cache_event.event_type)
{
case EventType::LoadNext:
handleLoadNextEvent(cache_event);
@@ -291,11 +290,11 @@ void AudioCacheEventHandler::pushEvent(CacheEvent& cache_event)
bool found = false;
- if(cache_event.eventType == EventType::LoadNext)
+ if(cache_event.event_type == EventType::LoadNext)
{
for(auto& queued_event : eventqueue)
{
- if((queued_event.eventType == EventType::LoadNext) &&
+ if((queued_event.event_type == EventType::LoadNext) &&
(cache_event.afile->getFilename() ==
queued_event.afile->getFilename()) &&
(cache_event.pos == queued_event.pos))
diff --git a/src/audiocacheeventhandler.h b/src/audiocacheeventhandler.h
index 473a010..f00a080 100644
--- a/src/audiocacheeventhandler.h
+++ b/src/audiocacheeventhandler.h
@@ -27,7 +27,6 @@
#pragma once
#include <list>
-#include <vector>
#include <mutex>
#include "thread.h"
@@ -88,7 +87,7 @@ protected:
void handleCloseEvent(CacheEvent& cache_event);
//! Close decrease the file ref and release the cache id.
- void handleCloseCache(cacheid_t cacheid);
+ void handleCloseCache(cacheid_t id);
void handleEvent(CacheEvent& cache_event);
diff --git a/src/audiocachefile.cc b/src/audiocachefile.cc
index 91fcecf..7b05bfc 100644
--- a/src/audiocachefile.cc
+++ b/src/audiocachefile.cc
@@ -130,25 +130,20 @@ AudioCacheFile& AudioCacheFiles::getFile(const std::string& filename)
{
std::lock_guard<std::mutex> lock(mutex);
- AudioCacheFile* cache_audio_file = nullptr;
-
auto it = audiofiles.find(filename);
if(it == audiofiles.end())
{
- cache_audio_file = new AudioCacheFile(filename, read_buffer);
- audiofiles.insert(std::make_pair(filename, cache_audio_file));
- }
- else
- {
- cache_audio_file = it->second;
+ // Construct a new AudioCacheFile in place. The in place construction is relevant.
+ it = audiofiles.emplace(std::piecewise_construct, std::make_tuple(filename),
+ std::make_tuple(filename, std::ref(read_buffer))).first;
}
- assert(cache_audio_file);
+ auto& cache_audio_file = it->second;
// Increase ref count.
- ++cache_audio_file->ref;
+ ++cache_audio_file.ref;
- return *cache_audio_file;
+ return cache_audio_file;
}
void AudioCacheFiles::releaseFile(const std::string& filename)
@@ -162,14 +157,13 @@ void AudioCacheFiles::releaseFile(const std::string& filename)
return; // not open
}
- auto audiofile = it->second;
+ auto& audiofile = it->second;
- assert(audiofile->ref); // If ref is not > 0 it shouldn't be in the map.
+ assert(audiofile.ref); // If ref is not > 0 it shouldn't be in the map.
- --audiofile->ref;
- if(audiofile->ref == 0)
+ --audiofile.ref;
+ if(audiofile.ref == 0)
{
- delete audiofile;
audiofiles.erase(it);
}
}
diff --git a/src/audiocachefile.h b/src/audiocachefile.h
index 8e40a2e..343133e 100644
--- a/src/audiocachefile.h
+++ b/src/audiocachefile.h
@@ -95,7 +95,7 @@ public:
void releaseFile(const std::string& filename);
protected:
- std::map<std::string, AudioCacheFile*> audiofiles;
+ std::map<std::string, AudioCacheFile> audiofiles;
std::mutex mutex;
std::vector<sample_t> read_buffer;
};
diff --git a/test/audiocachefiletest.cc b/test/audiocachefiletest.cc
index b7839b7..6f84ba2 100644
--- a/test/audiocachefiletest.cc
+++ b/test/audiocachefiletest.cc
@@ -39,12 +39,14 @@ public:
//void release(const std::string& filename);
int getRef(const std::string& filename)
{
- if(audiofiles.find(filename) == audiofiles.end())
+ auto it = audiofiles.find(filename);
+
+ if(it == audiofiles.end())
{
return -1;
}
- return audiofiles[filename]->ref;
+ return (it->second).ref;
}
};