Further fixes to audio/video provider selection

- Fix selection not aborting when the preferred provider returns null
- Fix the default video provider being "ffmpegsource" (lowercase)
  instead of "FFmpegSource", which would trip up provider selection
- More generally, make sure the preferred video provider actually exists
  and fall back to the default (FFmpegSource) if not.

Fixes arch1t3cht/Aegisub#23 .
Fixes arch1t3cht/Aegisub#61 .
Fixes arch1t3cht/Aegisub#83 .
This commit is contained in:
arch1t3cht 2023-10-15 22:27:21 +02:00
parent 02567c2265
commit dd3016a89d
4 changed files with 26 additions and 10 deletions

View File

@ -70,6 +70,11 @@ std::unique_ptr<agi::AudioProvider> SelectAudioProvider(fs::path const& filename
Path const& path_helper,
BackgroundRunner *br) {
auto preferred = OPT_GET("Audio/Provider")->GetString();
if (!std::any_of(std::begin(providers), std::end(providers), [&](factory provider) { return provider.name == preferred; })) {
preferred = OPT_GET("Audio/Provider")->GetDefaultString();
}
auto sorted = GetSorted(boost::make_iterator_range(std::begin(providers), std::end(providers)), preferred);
RearrangeWithPriority(sorted, filename);
@ -84,9 +89,12 @@ std::unique_ptr<agi::AudioProvider> SelectAudioProvider(fs::path const& filename
std::string err;
try {
auto provider = factory->create(filename, br);
if (!provider) continue;
LOG_I("audio_provider") << "Using audio provider: " << factory->name;
return provider;
if (!provider) {
err = "Failed to create provider."; // Some generic error message here
} else {
LOG_I("audio_provider") << "Using audio provider: " << factory->name;
return provider;
}
}
catch (AudioDataNotFound const& ex) {
found_file = true;

View File

@ -66,7 +66,7 @@
"Next Line on Commit" : true,
"Player" : "",
"Plays When Stepping Video" : false,
"Provider" : "ffmpegsource",
"Provider" : "FFmpegSource",
"Renderer" : {
"Spectrum" : {
"Cutoff" : 0,
@ -660,7 +660,7 @@
"Last Script Resolution Mismatch Choice" : 2,
"Open Audio" : true,
"Overscan Mask" : false,
"Provider" : "ffmpegsource",
"Provider" : "FFmpegSource",
"Script Resolution Mismatch" : 1,
"Slider" : {
"Fast Jump Step" : 10,

View File

@ -66,7 +66,7 @@
"Next Line on Commit" : true,
"Player" : "",
"Plays When Stepping Video" : false,
"Provider" : "ffmpegsource",
"Provider" : "FFmpegSource",
"Renderer" : {
"Spectrum" : {
"Cutoff" : 0,
@ -660,7 +660,7 @@
"Last Script Resolution Mismatch Choice" : 2,
"Open Audio" : true,
"Overscan Mask" : false,
"Provider" : "ffmpegsource",
"Provider" : "FFmpegSource",
"Script Resolution Mismatch" : 1,
"Slider" : {
"Fast Jump Step" : 10,

View File

@ -69,6 +69,11 @@ std::vector<std::string> VideoProviderFactory::GetClasses() {
std::unique_ptr<VideoProvider> VideoProviderFactory::GetProvider(agi::fs::path const& filename, std::string const& colormatrix, agi::BackgroundRunner *br) {
auto preferred = OPT_GET("Video/Provider")->GetString();
if (!std::any_of(std::begin(providers), std::end(providers), [&](factory provider) { return provider.name == preferred; })) {
preferred = OPT_GET("Audio/Provider")->GetDefaultString();
}
auto sorted = GetSorted(boost::make_iterator_range(std::begin(providers), std::end(providers)), preferred);
RearrangeWithPriority(sorted, filename);
@ -89,9 +94,12 @@ std::unique_ptr<VideoProvider> VideoProviderFactory::GetProvider(agi::fs::path c
std::string err;
try {
auto provider = factory->create(filename, colormatrix, br);
if (!provider) continue;
LOG_I("manager/video/provider") << factory->name << ": opened " << filename;
return finalize_provider(std::move(provider));
if (!provider) {
err = "Failed to create provider."; // Some generic error message here
} else {
LOG_I("manager/video/provider") << factory->name << ": opened " << filename;
return finalize_provider(std::move(provider));
}
}
catch (VideoNotSupported const& ex) {
found = true;