diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2016-03-13 17:32:24 +0100 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2016-03-13 17:32:24 +0100 |
commit | 28b5df96c2fc89652c724e48ad1ce352228450c6 (patch) | |
tree | ce74a6e1bf401bd666949cfa1c5324306d7fc3d2 /src/audiocacheeventhandler.cc | |
parent | 08a929d3d32e50e7787428d130289c0f5fc2ff42 (diff) |
Only open AudioCacheFile if needed.
Diffstat (limited to 'src/audiocacheeventhandler.cc')
-rw-r--r-- | src/audiocacheeventhandler.cc | 40 |
1 files changed, 23 insertions, 17 deletions
diff --git a/src/audiocacheeventhandler.cc b/src/audiocacheeventhandler.cc index c639242..916b04d 100644 --- a/src/audiocacheeventhandler.cc +++ b/src/audiocacheeventhandler.cc @@ -213,6 +213,8 @@ void AudioCacheEventHandler::clearEvents() void AudioCacheEventHandler::handleLoadNextEvent(CacheEvent& cache_event) { + assert(cache_event.afile); // Assert that we have an audio file + cache_event.afile->readChunk(cache_event.channels, cache_event.pos, chunksize); } @@ -227,7 +229,11 @@ void AudioCacheEventHandler::handleCloseCache(cacheid_t id) { auto& cache = id_manager.getCache(id); - files.releaseFile(cache.afile->getFilename()); + // Only close the file if we have also opened it. + if(cache.afile) + { + files.releaseFile(cache.afile->getFilename()); + } delete[] cache.front; delete[] cache.back; @@ -267,12 +273,6 @@ void AudioCacheEventHandler::thread_main() eventqueue.pop_front(); mutex.unlock(); - // TODO: Skip event if cache_event.pos < cache.pos - //if(!cache_event.active) - //{ - // continue; - //} - handleEvent(cache_event); } } @@ -294,17 +294,23 @@ void AudioCacheEventHandler::pushEvent(CacheEvent& cache_event) { for(auto& queued_event : eventqueue) { - if((queued_event.event_type == EventType::LoadNext) && - (cache_event.afile->getFilename() == - queued_event.afile->getFilename()) && - (cache_event.pos == queued_event.pos)) + if(queued_event.event_type == EventType::LoadNext) { - // Append channel and buffer to the existing event. - queued_event.channels.insert(queued_event.channels.end(), - cache_event.channels.begin(), - cache_event.channels.end()); - found = true; - break; + + assert(cache_event.afile); // Assert that we have an audio file + assert(queued_event.afile); // Assert that we have an audio file + + if((cache_event.afile->getFilename() == + queued_event.afile->getFilename()) && + (cache_event.pos == queued_event.pos)) + { + // Append channel and buffer to the existing event. + queued_event.channels.insert(queued_event.channels.end(), + cache_event.channels.begin(), + cache_event.channels.end()); + found = true; + break; + } } } } |