Skip to content
This repository has been archived by the owner on May 12, 2024. It is now read-only.

Commit

Permalink
[Shinon] Fixes:
Browse files Browse the repository at this point in the history
 - Use same audio hash path for multiple files to prevent hard disk fill ups
 - Do not hardcode DPI Icon but use user preferences instead.
  • Loading branch information
Ristellise committed Oct 25, 2021
1 parent fa42f53 commit 862fd2a
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 7 deletions.
12 changes: 8 additions & 4 deletions libaegisub/audio/provider_hd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <ctime>
#include <thread>


namespace {
using namespace agi;

Expand All @@ -49,18 +50,21 @@ class HDAudioProvider final : public AudioProviderWrapper {
}
}

fs::path CacheFilename(fs::path const& dir) {
fs::path CacheFilename(fs::path dir, int hash) {
// Check free space
if ((uint64_t)num_samples * bytes_per_sample * channels > fs::FreeSpace(dir))
throw AudioProviderError("Not enough free disk space in " + dir.string() + " to cache the audio");

return "audio";
std::stringstream hexstream;
hexstream << std::hex << hash;
if (!fs::DirectoryExists(dir))
fs::CreateDirectory(dir);
return std::string("aegisub-audio-") + hexstream.str() + ".cache";
}

public:
HDAudioProvider(std::unique_ptr<AudioProvider> src, agi::fs::path const& dir)
: AudioProviderWrapper(std::move(src))
, file(dir / CacheFilename(dir), num_samples * bytes_per_sample* channels)
, file(dir / CacheFilename(dir, this->GetHash()), num_samples* bytes_per_sample* channels)
{
decoded_samples = 0;
decoder = std::thread([&] {
Expand Down
3 changes: 3 additions & 0 deletions libaegisub/include/libaegisub/audio/provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class AudioProvider {
int sample_rate = 0;
int bytes_per_sample = 0;
bool float_samples = false;
int audioHash = 0;

virtual void FillBuffer(void *buf, int64_t start, int64_t count) const = 0;
virtual void FillBufferInt16Mono(int16_t* buf, int64_t start, int64_t count, bool asAmplitude=false) const;
Expand All @@ -53,6 +54,7 @@ class AudioProvider {
int GetBytesPerSample() const { return bytes_per_sample; }
int GetChannels() const { return channels; }
bool AreSamplesFloat() const { return float_samples; }
int GetHash() const { return audioHash; }

/// Does this provider benefit from external caching?
virtual bool NeedsCache() const { return false; }
Expand All @@ -72,6 +74,7 @@ class AudioProviderWrapper : public AudioProvider {
sample_rate = source->GetSampleRate();
bytes_per_sample = source->GetBytesPerSample();
float_samples = source->AreSamplesFloat();
audioHash = source->GetHash();
}
};

Expand Down
2 changes: 2 additions & 0 deletions src/audio_provider_ffmpegsource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include <libaegisub/fs.h>
#include <libaegisub/make_unique.h>

#include <functional>
#include <map>

namespace {
Expand Down Expand Up @@ -76,6 +77,7 @@ FFmpegSourceAudioProvider::FFmpegSourceAudioProvider(agi::fs::path const& filena
SetLogLevel();

LoadAudio(filename);
audioHash = std::hash<std::string>{}(filename.filename().string());
}
catch (agi::EnvironmentError const& err) {
throw agi::AudioProviderError(err.GetMessage());
Expand Down
2 changes: 1 addition & 1 deletion src/preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ void Advanced_Audio(wxTreebook *book, Preferences *parent) {

p->OptionAdd(ffms, _("Always index all audio tracks"), "Provider/FFmpegSource/Index All Tracks");
wxControl* stereo = p->OptionAdd(ffms, _("Downmix to stereo"), "Provider/Audio/FFmpegSource/Downmix");
stereo->SetToolTip("Reduces memory usage on surround audio, but may cause audio tracks to sound blank in specific circumstances. This will not affect audio with 2 channels or lesser.");
stereo->SetToolTip("Reduces memory usage on surround audio, but may cause audio tracks to sound blank in specific circumstances.\nThis will not affect audio with 2 channels or fewer.");
#endif

#ifdef WITH_PORTAUDIO
Expand Down
4 changes: 2 additions & 2 deletions src/toolbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ namespace {
, ht_context(std::move(ht_context))
, retina_helper(parent)
#ifdef __WXMSW__
, icon_size(parent->FromDIP(16))
, icon_size(parent->FromDIP(OPT_GET("App/Toolbar Icon Size")->GetInt()))
#else
, icon_size(OPT_GET("App/Toolbar Icon Size")->GetInt())
#endif
Expand All @@ -191,7 +191,7 @@ namespace {
, retina_helper(parent)
#ifndef __WXMAC__
#ifdef __WXMSW__
, icon_size(parent->FromDIP(16))
, icon_size(parent->FromDIP(OPT_GET("App/Toolbar Icon Size")->GetInt()))
#else
, icon_size(OPT_GET("App/Toolbar Icon Size")->GetInt())
#endif
Expand Down

0 comments on commit 862fd2a

Please sign in to comment.