forked from mia/Aegisub
Extract some duplicated code
This commit is contained in:
parent
470f85d365
commit
dbe9bcfdad
3 changed files with 46 additions and 44 deletions
|
@ -38,6 +38,7 @@
|
||||||
|
|
||||||
#include "audio_controller.h"
|
#include "audio_controller.h"
|
||||||
#include "dialog_progress.h"
|
#include "dialog_progress.h"
|
||||||
|
#include "factory_manager.h"
|
||||||
#include "frame_main.h"
|
#include "frame_main.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "options.h"
|
#include "options.h"
|
||||||
|
@ -47,6 +48,8 @@
|
||||||
#include <libaegisub/log.h>
|
#include <libaegisub/log.h>
|
||||||
#include <libaegisub/util.h>
|
#include <libaegisub/util.h>
|
||||||
|
|
||||||
|
#include <boost/range/iterator_range.hpp>
|
||||||
|
|
||||||
void AudioProvider::GetAudioWithVolume(void *buf, int64_t start, int64_t count, double volume) const {
|
void AudioProvider::GetAudioWithVolume(void *buf, int64_t start, int64_t count, double volume) const {
|
||||||
GetAudio(buf, start, count);
|
GetAudio(buf, start, count);
|
||||||
|
|
||||||
|
@ -112,10 +115,9 @@ std::unique_ptr<AudioProvider> CreateHDAudioProvider(std::unique_ptr<AudioProvid
|
||||||
std::unique_ptr<AudioProvider> CreateRAMAudioProvider(std::unique_ptr<AudioProvider> source_provider, agi::BackgroundRunner *br);
|
std::unique_ptr<AudioProvider> CreateRAMAudioProvider(std::unique_ptr<AudioProvider> source_provider, agi::BackgroundRunner *br);
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
using factory_fn = std::unique_ptr<AudioProvider> (*)(agi::fs::path const&);
|
|
||||||
struct factory {
|
struct factory {
|
||||||
const char *name;
|
const char *name;
|
||||||
factory_fn create;
|
std::unique_ptr<AudioProvider> (*create)(agi::fs::path const&);
|
||||||
bool hidden;
|
bool hidden;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -132,30 +134,12 @@ namespace {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> AudioProviderFactory::GetClasses() {
|
std::vector<std::string> AudioProviderFactory::GetClasses() {
|
||||||
std::vector<std::string> list;
|
return ::GetClasses(boost::make_iterator_range(std::begin(providers), std::end(providers)));
|
||||||
for (auto const& provider : providers) {
|
|
||||||
if (!provider.hidden)
|
|
||||||
list.push_back(provider.name);
|
|
||||||
}
|
|
||||||
return list;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<AudioProvider> AudioProviderFactory::GetProvider(agi::fs::path const& filename) {
|
std::unique_ptr<AudioProvider> AudioProviderFactory::GetProvider(agi::fs::path const& filename) {
|
||||||
auto preferred = OPT_GET("Audio/Provider")->GetString();
|
auto preferred = OPT_GET("Audio/Provider")->GetString();
|
||||||
std::vector<const factory *> sorted;
|
auto sorted = GetSorted(boost::make_iterator_range(std::begin(providers), std::end(providers)), preferred);
|
||||||
auto preferred_insertion_point = sorted.end();
|
|
||||||
for (auto const& provider : providers) {
|
|
||||||
if (provider.hidden)
|
|
||||||
sorted.push_back(&provider);
|
|
||||||
else if (preferred_insertion_point == sorted.end()) {
|
|
||||||
sorted.push_back(&provider);
|
|
||||||
preferred_insertion_point = prev(sorted.end());
|
|
||||||
}
|
|
||||||
else if (preferred == provider.name)
|
|
||||||
sorted.insert(preferred_insertion_point, &provider);
|
|
||||||
else
|
|
||||||
sorted.push_back(&provider);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::unique_ptr<AudioProvider> provider;
|
std::unique_ptr<AudioProvider> provider;
|
||||||
bool found_file = false;
|
bool found_file = false;
|
||||||
|
|
|
@ -73,3 +73,37 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
template<typename Container>
|
||||||
|
std::vector<std::string> GetClasses(Container const& c) {
|
||||||
|
std::vector<std::string> list;
|
||||||
|
for (auto const& provider : c) {
|
||||||
|
if (!provider.hidden)
|
||||||
|
list.push_back(provider.name);
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Container>
|
||||||
|
auto GetSorted(Container const& c, std::string const& preferred) -> std::vector<decltype(&*c.begin())> {
|
||||||
|
std::vector<decltype(&*c.begin())> sorted;
|
||||||
|
sorted.reserve(std::distance(c.begin(), c.end()));
|
||||||
|
size_t end_of_hidden = 0;
|
||||||
|
bool any_hidden = false;
|
||||||
|
for (auto const& provider : c) {
|
||||||
|
if (provider.hidden) {
|
||||||
|
sorted.push_back(&provider);
|
||||||
|
any_hidden = true;
|
||||||
|
}
|
||||||
|
else if (any_hidden && end_of_hidden == 0) {
|
||||||
|
end_of_hidden = sorted.size();
|
||||||
|
sorted.push_back(&provider);
|
||||||
|
}
|
||||||
|
else if (preferred == provider.name)
|
||||||
|
sorted.insert(sorted.begin() + end_of_hidden, &provider);
|
||||||
|
else
|
||||||
|
sorted.push_back(&provider);
|
||||||
|
}
|
||||||
|
return sorted;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
|
|
||||||
#include "video_provider_manager.h"
|
#include "video_provider_manager.h"
|
||||||
|
|
||||||
|
#include "factory_manager.h"
|
||||||
#include "include/aegisub/video_provider.h"
|
#include "include/aegisub/video_provider.h"
|
||||||
#include "options.h"
|
#include "options.h"
|
||||||
|
|
||||||
|
@ -25,6 +26,8 @@
|
||||||
#include <libaegisub/log.h>
|
#include <libaegisub/log.h>
|
||||||
#include <libaegisub/util.h>
|
#include <libaegisub/util.h>
|
||||||
|
|
||||||
|
#include <boost/range/iterator_range.hpp>
|
||||||
|
|
||||||
std::unique_ptr<VideoProvider> CreateDummyVideoProvider(agi::fs::path const&, std::string const&);
|
std::unique_ptr<VideoProvider> CreateDummyVideoProvider(agi::fs::path const&, std::string const&);
|
||||||
std::unique_ptr<VideoProvider> CreateYUV4MPEGVideoProvider(agi::fs::path const&, std::string const&);
|
std::unique_ptr<VideoProvider> CreateYUV4MPEGVideoProvider(agi::fs::path const&, std::string const&);
|
||||||
std::unique_ptr<VideoProvider> CreateFFmpegSourceVideoProvider(agi::fs::path const&, std::string const&);
|
std::unique_ptr<VideoProvider> CreateFFmpegSourceVideoProvider(agi::fs::path const&, std::string const&);
|
||||||
|
@ -33,10 +36,9 @@ std::unique_ptr<VideoProvider> CreateAvisynthVideoProvider(agi::fs::path const&,
|
||||||
std::unique_ptr<VideoProvider> CreateCacheVideoProvider(std::unique_ptr<VideoProvider>);
|
std::unique_ptr<VideoProvider> CreateCacheVideoProvider(std::unique_ptr<VideoProvider>);
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
using factory_fn = std::unique_ptr<VideoProvider> (*)(agi::fs::path const&, std::string const&);
|
|
||||||
struct factory {
|
struct factory {
|
||||||
const char *name;
|
const char *name;
|
||||||
factory_fn create;
|
std::unique_ptr<VideoProvider> (*create)(agi::fs::path const&, std::string const&);
|
||||||
bool hidden;
|
bool hidden;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -53,30 +55,12 @@ namespace {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> VideoProviderFactory::GetClasses() {
|
std::vector<std::string> VideoProviderFactory::GetClasses() {
|
||||||
std::vector<std::string> list;
|
return ::GetClasses(boost::make_iterator_range(std::begin(providers), std::end(providers)));
|
||||||
for (auto const& provider : providers) {
|
|
||||||
if (!provider.hidden)
|
|
||||||
list.push_back(provider.name);
|
|
||||||
}
|
|
||||||
return list;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<VideoProvider> VideoProviderFactory::GetProvider(agi::fs::path const& filename, std::string const& colormatrix) {
|
std::unique_ptr<VideoProvider> VideoProviderFactory::GetProvider(agi::fs::path const& filename, std::string const& colormatrix) {
|
||||||
auto preferred = OPT_GET("Video/Provider")->GetString();
|
auto preferred = OPT_GET("Video/Provider")->GetString();
|
||||||
std::vector<const factory *> sorted;
|
auto sorted = GetSorted(boost::make_iterator_range(std::begin(providers), std::end(providers)), preferred);
|
||||||
auto preferred_insertion_point = sorted.end();
|
|
||||||
for (auto const& provider : providers) {
|
|
||||||
if (provider.hidden)
|
|
||||||
sorted.push_back(&provider);
|
|
||||||
else if (preferred_insertion_point == sorted.end()) {
|
|
||||||
sorted.push_back(&provider);
|
|
||||||
preferred_insertion_point = prev(sorted.end());
|
|
||||||
}
|
|
||||||
else if (preferred == provider.name)
|
|
||||||
sorted.insert(preferred_insertion_point, &provider);
|
|
||||||
else
|
|
||||||
sorted.push_back(&provider);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool found = false;
|
bool found = false;
|
||||||
bool supported = false;
|
bool supported = false;
|
||||||
|
|
Loading…
Reference in a new issue