forked from mia/Aegisub
Add progress support back to HD Audio Cache with the new ProgressSink from libaegisub. Currently AudioProviderFactory::GetProvider() takes the ProgressSinkFactory however this should probably be moved up to the constructor for AudioProviderFactory. We'll see what the best option is when the others come around it's trivial to change.
Originally committed to SVN as r5347.
This commit is contained in:
parent
8240d3e6b6
commit
c0cf0c6a06
4 changed files with 16 additions and 20 deletions
26
aegisub/libmedia/cache/audio_hd.cpp
vendored
26
aegisub/libmedia/cache/audio_hd.cpp
vendored
|
@ -37,26 +37,19 @@
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#ifndef AGI_PRE
|
#ifndef AGI_PRE
|
||||||
//#include <wx/filefn.h>
|
|
||||||
//#include <wx/filename.h>
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "audio_hd.h"
|
|
||||||
//#include "compat.h"
|
|
||||||
//#include "dialog_progress.h"
|
|
||||||
//#include "frame_main.h"
|
|
||||||
//#include "main.h"
|
|
||||||
//#include "standard_paths.h"
|
|
||||||
//#include "utils.h"
|
|
||||||
|
|
||||||
#include <libaegisub/io.h>
|
#include <libaegisub/io.h>
|
||||||
|
|
||||||
|
#include "audio_hd.h"
|
||||||
|
|
||||||
|
|
||||||
namespace media {
|
namespace media {
|
||||||
|
|
||||||
/// @brief Constructor
|
/// @brief Constructor
|
||||||
/// @param source
|
/// @param source
|
||||||
///
|
///
|
||||||
HDAudioProvider::HDAudioProvider(AudioProvider *src) {
|
HDAudioProvider::HDAudioProvider(AudioProvider *src, agi::ProgressSinkFactory *progress_factory) {
|
||||||
std::auto_ptr<AudioProvider> source(src);
|
std::auto_ptr<AudioProvider> source(src);
|
||||||
// Copy parameters
|
// Copy parameters
|
||||||
bytes_per_sample = source->GetBytesPerSample();
|
bytes_per_sample = source->GetBytesPerSample();
|
||||||
|
@ -84,9 +77,9 @@ HDAudioProvider::HDAudioProvider(AudioProvider *src) {
|
||||||
if (!file_cache.is_open()) throw AudioOpenError("Unable to write to audio disk cache.");
|
if (!file_cache.is_open()) throw AudioOpenError("Unable to write to audio disk cache.");
|
||||||
|
|
||||||
// Start progress
|
// Start progress
|
||||||
volatile bool canceled = false;
|
ProgressSink *progress = progress_factory->create_progress_sink("Reading to Hard Disk cache");
|
||||||
// DialogProgress *progress = new DialogProgress(AegisubApp::Get()->frame,_T("Load audio"),&canceled,_T("Reading to Hard Disk cache"),0,num_samples);
|
|
||||||
// progress->Show();
|
volatile bool canceled = progress->get_cancelled();
|
||||||
|
|
||||||
// Write to disk
|
// Write to disk
|
||||||
int block = 4096;
|
int block = 4096;
|
||||||
|
@ -95,7 +88,7 @@ HDAudioProvider::HDAudioProvider(AudioProvider *src) {
|
||||||
if (block+i > num_samples) block = num_samples - i;
|
if (block+i > num_samples) block = num_samples - i;
|
||||||
source->GetAudio(data,i,block);
|
source->GetAudio(data,i,block);
|
||||||
file_cache.write(data,block * channels * bytes_per_sample);
|
file_cache.write(data,block * channels * bytes_per_sample);
|
||||||
// progress->SetProgress(i,num_samples);
|
progress->set_progress(i,num_samples);
|
||||||
}
|
}
|
||||||
file_cache.seekp(0);
|
file_cache.seekp(0);
|
||||||
|
|
||||||
|
@ -105,7 +98,8 @@ HDAudioProvider::HDAudioProvider(AudioProvider *src) {
|
||||||
delete[] data;
|
delete[] data;
|
||||||
throw agi::UserCancelException("Audio loading cancelled by user");
|
throw agi::UserCancelException("Audio loading cancelled by user");
|
||||||
}
|
}
|
||||||
// progress->Destroy();
|
|
||||||
|
delete progress;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Destructor
|
/// @brief Destructor
|
||||||
|
|
3
aegisub/libmedia/cache/audio_hd.h
vendored
3
aegisub/libmedia/cache/audio_hd.h
vendored
|
@ -38,6 +38,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <libaegisub/mutex.h>
|
#include <libaegisub/mutex.h>
|
||||||
|
|
||||||
#include "libmedia/audio.h"
|
#include "libmedia/audio.h"
|
||||||
|
|
||||||
namespace media {
|
namespace media {
|
||||||
|
@ -66,7 +67,7 @@ class HDAudioProvider : public AudioProvider {
|
||||||
static std::string DiskCacheName();
|
static std::string DiskCacheName();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
HDAudioProvider(AudioProvider *source);
|
HDAudioProvider(AudioProvider *source, agi::ProgressSinkFactory *progress_factory);
|
||||||
~HDAudioProvider();
|
~HDAudioProvider();
|
||||||
|
|
||||||
bool AreSamplesNativeEndian() const { return samples_native_endian; }
|
bool AreSamplesNativeEndian() const { return samples_native_endian; }
|
||||||
|
|
|
@ -108,7 +108,7 @@ void AudioProvider::GetAudioWithVolume(void *buf, int64_t start, int64_t count,
|
||||||
/// @param cache
|
/// @param cache
|
||||||
/// @return
|
/// @return
|
||||||
///
|
///
|
||||||
AudioProvider *AudioProviderFactory::GetProvider(std::string filename, int cache) {
|
AudioProvider *AudioProviderFactory::GetProvider(std::string filename, agi::ProgressSinkFactory *progress_factory, int cache) {
|
||||||
AudioProvider *provider = NULL;
|
AudioProvider *provider = NULL;
|
||||||
bool found = false;
|
bool found = false;
|
||||||
std::string msg;
|
std::string msg;
|
||||||
|
@ -172,7 +172,7 @@ AudioProvider *AudioProviderFactory::GetProvider(std::string filename, int cache
|
||||||
if (cache == 1) return new RAMAudioProvider(provider);
|
if (cache == 1) return new RAMAudioProvider(provider);
|
||||||
|
|
||||||
// Convert to HD
|
// Convert to HD
|
||||||
if (cache == 2) return new HDAudioProvider(provider);
|
if (cache == 2) return new HDAudioProvider(provider, progress_factory);
|
||||||
|
|
||||||
throw AudioOpenError("Unknown caching method");
|
throw AudioOpenError("Unknown caching method");
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <libaegisub/exception.h>
|
#include <libaegisub/exception.h>
|
||||||
|
#include <libaegisub/progress.h>
|
||||||
#include <libmedia/factory_manager.h>
|
#include <libmedia/factory_manager.h>
|
||||||
|
|
||||||
namespace media {
|
namespace media {
|
||||||
|
@ -98,7 +99,7 @@ public:
|
||||||
class AudioProviderFactory : public Factory1<AudioProvider, std::string> {
|
class AudioProviderFactory : public Factory1<AudioProvider, std::string> {
|
||||||
public:
|
public:
|
||||||
static void RegisterProviders();
|
static void RegisterProviders();
|
||||||
static AudioProvider *GetProvider(std::string filename, int cache=-1);
|
static AudioProvider *GetProvider(std::string filename, agi::ProgressSinkFactory *progress_factory, int cache=-1);
|
||||||
};
|
};
|
||||||
|
|
||||||
DEFINE_BASE_EXCEPTION_NOINNER(AudioProviderError, agi::Exception);
|
DEFINE_BASE_EXCEPTION_NOINNER(AudioProviderError, agi::Exception);
|
||||||
|
|
Loading…
Reference in a new issue